tenjin-cli 0.1.0-alpha.33 → 0.1.0-alpha.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (495) hide show
  1. package/NOTICE.md +110 -0
  2. package/README.md +87 -81
  3. package/dist/{_esm-BIN7VY2L.js → _esm-2KST7HQ7.js} +7 -7
  4. package/dist/alive-5TV22PNF.js +51 -0
  5. package/dist/auth-XI7BJFLW.js +47 -0
  6. package/dist/{auto-update-Y24UL56V.js → auto-update-7L24KDWA.js} +4 -5
  7. package/dist/balance-DFHC6XEU.js +71 -0
  8. package/dist/{ccip-DHDFKTQV.js → ccip-HOW3DZYF.js} +4 -4
  9. package/dist/chunk-24XKUN2S.js +202 -0
  10. package/dist/chunk-24XKUN2S.js.map +1 -0
  11. package/dist/chunk-2L7TDGLV.js +56 -0
  12. package/dist/chunk-2L7TDGLV.js.map +1 -0
  13. package/dist/{chunk-C2Q76BVM.js → chunk-2U7H35IP.js} +29 -7
  14. package/dist/chunk-2U7H35IP.js.map +1 -0
  15. package/dist/chunk-2W4DQQUU.js +176 -0
  16. package/dist/chunk-2W4DQQUU.js.map +1 -0
  17. package/dist/{chunk-LRW6S53P.js → chunk-34SAECKZ.js} +35 -11
  18. package/dist/chunk-34SAECKZ.js.map +1 -0
  19. package/dist/{chunk-2I4QTOLB.js → chunk-3MZ7DYRO.js} +1 -1
  20. package/dist/chunk-3MZ7DYRO.js.map +1 -0
  21. package/dist/{chunk-RVPYTUP4.js → chunk-3Y2EHT4F.js} +13 -9
  22. package/dist/chunk-3Y2EHT4F.js.map +1 -0
  23. package/dist/chunk-3Y6BHIN6.js +169 -0
  24. package/dist/chunk-3Y6BHIN6.js.map +1 -0
  25. package/dist/{chunk-4K7TQHNP.js → chunk-3YPL6T3P.js} +17 -33
  26. package/dist/chunk-3YPL6T3P.js.map +1 -0
  27. package/dist/{chunk-E7SW44LM.js → chunk-44MVIRZH.js} +121 -6
  28. package/dist/chunk-44MVIRZH.js.map +1 -0
  29. package/dist/chunk-45MMSBHA.js +321 -0
  30. package/dist/chunk-45MMSBHA.js.map +1 -0
  31. package/dist/{chunk-3FMZGI7I.js → chunk-4CE6TMI5.js} +1 -1
  32. package/dist/chunk-4CE6TMI5.js.map +1 -0
  33. package/dist/{chunk-QXP3Z3JN.js → chunk-4MBCJFY4.js} +35 -3
  34. package/dist/chunk-4MBCJFY4.js.map +1 -0
  35. package/dist/chunk-4TPL54KW.js +227 -0
  36. package/dist/chunk-4TPL54KW.js.map +1 -0
  37. package/dist/chunk-54ELBTKE.js +1615 -0
  38. package/dist/chunk-54ELBTKE.js.map +1 -0
  39. package/dist/{chunk-NDGZDTSJ.js → chunk-5F4OB5B3.js} +115 -57
  40. package/dist/chunk-5F4OB5B3.js.map +1 -0
  41. package/dist/chunk-5HN4KVQU.js +3348 -0
  42. package/dist/chunk-5HN4KVQU.js.map +1 -0
  43. package/dist/{chunk-ZDZERB6L.js → chunk-5J4E5GYI.js} +572 -407
  44. package/dist/chunk-5J4E5GYI.js.map +1 -0
  45. package/dist/{chunk-ZNNXRNFD.js → chunk-5N4GGUBN.js} +48 -6
  46. package/dist/chunk-5N4GGUBN.js.map +1 -0
  47. package/dist/chunk-5USBZ2MU.js +58 -0
  48. package/dist/chunk-5USBZ2MU.js.map +1 -0
  49. package/dist/chunk-64WOMNYR.js +183 -0
  50. package/dist/chunk-64WOMNYR.js.map +1 -0
  51. package/dist/{chunk-ILNIZ5I2.js → chunk-65RS4LQS.js} +1825 -1715
  52. package/dist/chunk-65RS4LQS.js.map +1 -0
  53. package/dist/{chunk-IE7P2BZE.js → chunk-6QMDUDF2.js} +3 -3
  54. package/dist/{chunk-IADZOXKN.js → chunk-7SLOTLO7.js} +19 -697
  55. package/dist/chunk-7SLOTLO7.js.map +1 -0
  56. package/dist/{chunk-WFSPCCVW.js → chunk-7V25UAQO.js} +99 -99
  57. package/dist/{chunk-WFSPCCVW.js.map → chunk-7V25UAQO.js.map} +1 -1
  58. package/dist/chunk-BGA4DO5M.js +719 -0
  59. package/dist/chunk-BGA4DO5M.js.map +1 -0
  60. package/dist/chunk-BVP7YK2J.js +706 -0
  61. package/dist/chunk-BVP7YK2J.js.map +1 -0
  62. package/dist/chunk-C265QIMJ.js +83 -0
  63. package/dist/chunk-C265QIMJ.js.map +1 -0
  64. package/dist/{chunk-XQJXNMSB.js → chunk-CRG54LEB.js} +1 -1
  65. package/dist/chunk-CRG54LEB.js.map +1 -0
  66. package/dist/{chunk-KG3D7FIF.js → chunk-CZJOMUBP.js} +2 -2
  67. package/dist/{chunk-36RVGZNY.js → chunk-D6M3ZK66.js} +22 -39
  68. package/dist/chunk-D6M3ZK66.js.map +1 -0
  69. package/dist/{chunk-3UCIG4TG.js → chunk-DI4QAGRZ.js} +1 -11
  70. package/dist/chunk-DI4QAGRZ.js.map +1 -0
  71. package/dist/{chunk-JKKAIPTU.js → chunk-DIH2G3YG.js} +47 -10
  72. package/dist/chunk-DIH2G3YG.js.map +1 -0
  73. package/dist/chunk-DJ36BM62.js +78 -0
  74. package/dist/chunk-DJ36BM62.js.map +1 -0
  75. package/dist/chunk-DTEWAVNE.js +114 -0
  76. package/dist/chunk-DTEWAVNE.js.map +1 -0
  77. package/dist/chunk-F2KJAJ7T.js +13 -0
  78. package/dist/chunk-F2KJAJ7T.js.map +1 -0
  79. package/dist/{chunk-BF4XHEQK.js → chunk-F3QPGYOY.js} +6 -6
  80. package/dist/chunk-F3QPGYOY.js.map +1 -0
  81. package/dist/{chunk-3GNJXKIT.js → chunk-F43CV6UC.js} +2 -2
  82. package/dist/{chunk-J57UC3DD.js → chunk-FKVJKLPI.js} +3 -3
  83. package/dist/{chunk-V2LQLN5H.js → chunk-FYFHH7V5.js} +59 -8
  84. package/dist/{chunk-V2LQLN5H.js.map → chunk-FYFHH7V5.js.map} +1 -1
  85. package/dist/chunk-GAJC4BQZ.js +1096 -0
  86. package/dist/chunk-GAJC4BQZ.js.map +1 -0
  87. package/dist/{chunk-DOQGNFHM.js → chunk-GH5UKMZD.js} +2 -12
  88. package/dist/{chunk-DOQGNFHM.js.map → chunk-GH5UKMZD.js.map} +1 -1
  89. package/dist/{chunk-WYXUQGOL.js → chunk-HAZAN4UM.js} +7 -6
  90. package/dist/chunk-HAZAN4UM.js.map +1 -0
  91. package/dist/chunk-HI5XQOX2.js +393 -0
  92. package/dist/chunk-HI5XQOX2.js.map +1 -0
  93. package/dist/chunk-HKGUKAQW.js +488 -0
  94. package/dist/chunk-HKGUKAQW.js.map +1 -0
  95. package/dist/{chunk-SO3XRZPX.js → chunk-HPRVFJPM.js} +6 -6
  96. package/dist/{chunk-L6JEXB3E.js → chunk-HQR4BWKX.js} +3 -131
  97. package/dist/chunk-HQR4BWKX.js.map +1 -0
  98. package/dist/chunk-HZKANST2.js +177 -0
  99. package/dist/chunk-HZKANST2.js.map +1 -0
  100. package/dist/{chunk-UUGOUOVT.js → chunk-I557SAOM.js} +8 -2
  101. package/dist/chunk-I557SAOM.js.map +1 -0
  102. package/dist/{chunk-TC2WZLSC.js → chunk-IGLWLH73.js} +8 -7
  103. package/dist/chunk-IGLWLH73.js.map +1 -0
  104. package/dist/chunk-ILWCKCOI.js +58 -0
  105. package/dist/chunk-ILWCKCOI.js.map +1 -0
  106. package/dist/{chunk-2GP3HRYK.js → chunk-INSIW65E.js} +182 -182
  107. package/dist/{chunk-MPZUYCAP.js → chunk-IULCDMVG.js} +12 -1
  108. package/dist/chunk-IULCDMVG.js.map +1 -0
  109. package/dist/{chunk-INTFHMU4.js → chunk-IVNSUAVC.js} +25 -26
  110. package/dist/chunk-IVNSUAVC.js.map +1 -0
  111. package/dist/chunk-JDQZCREI.js +87 -0
  112. package/dist/chunk-JDQZCREI.js.map +1 -0
  113. package/dist/chunk-JHFFUVON.js +1050 -0
  114. package/dist/chunk-JHFFUVON.js.map +1 -0
  115. package/dist/{chunk-RL5UUDT4.js → chunk-JNUKLSMZ.js} +3 -3
  116. package/dist/chunk-JTILUN4W.js +2933 -0
  117. package/dist/chunk-JTILUN4W.js.map +1 -0
  118. package/dist/{chunk-OJNTCYQQ.js → chunk-JTX3BUDK.js} +37 -53
  119. package/dist/chunk-JTX3BUDK.js.map +1 -0
  120. package/dist/{chunk-X5ZBP3IY.js → chunk-JUUBBBY5.js} +2 -2
  121. package/dist/chunk-JUUBBBY5.js.map +1 -0
  122. package/dist/chunk-JWAK7JQB.js +15 -0
  123. package/dist/chunk-JWAK7JQB.js.map +1 -0
  124. package/dist/{chunk-UXZONNEQ.js → chunk-K5KNGC4I.js} +34 -31
  125. package/dist/chunk-K5KNGC4I.js.map +1 -0
  126. package/dist/chunk-KAQ4Q3TO.js +135 -0
  127. package/dist/chunk-KAQ4Q3TO.js.map +1 -0
  128. package/dist/chunk-KFVJYLVL.js +125 -0
  129. package/dist/chunk-KFVJYLVL.js.map +1 -0
  130. package/dist/chunk-KGUE5AVX.js +69 -0
  131. package/dist/chunk-KGUE5AVX.js.map +1 -0
  132. package/dist/{chunk-FVIGCDSV.js → chunk-KLDMLWXT.js} +11 -85
  133. package/dist/chunk-KLDMLWXT.js.map +1 -0
  134. package/dist/chunk-KNKDMTHU.js +453 -0
  135. package/dist/chunk-KNKDMTHU.js.map +1 -0
  136. package/dist/chunk-LDA6TAYQ.js +95 -0
  137. package/dist/chunk-LDA6TAYQ.js.map +1 -0
  138. package/dist/chunk-LWSSIZOY.js +347 -0
  139. package/dist/chunk-LWSSIZOY.js.map +1 -0
  140. package/dist/{chunk-ZURZHELF.js → chunk-MAHNZA6C.js} +158 -41
  141. package/dist/chunk-MAHNZA6C.js.map +1 -0
  142. package/dist/chunk-MEWZCIA6.js +220 -0
  143. package/dist/chunk-MEWZCIA6.js.map +1 -0
  144. package/dist/{chunk-2SNUOHAT.js → chunk-MEZJ3I63.js} +49 -1
  145. package/dist/chunk-MEZJ3I63.js.map +1 -0
  146. package/dist/chunk-MJDO4EXD.js +353 -0
  147. package/dist/chunk-MJDO4EXD.js.map +1 -0
  148. package/dist/chunk-NJA6NT3A.js +6595 -0
  149. package/dist/chunk-NJA6NT3A.js.map +1 -0
  150. package/dist/{chunk-LHHMV4GU.js → chunk-NVSKJPRC.js} +1 -1
  151. package/dist/{chunk-LHHMV4GU.js.map → chunk-NVSKJPRC.js.map} +1 -1
  152. package/dist/{chunk-4YOZGGTZ.js → chunk-OC7K2DVZ.js} +5 -5
  153. package/dist/chunk-OC7K2DVZ.js.map +1 -0
  154. package/dist/chunk-ODRPASFP.js +2078 -0
  155. package/dist/chunk-ODRPASFP.js.map +1 -0
  156. package/dist/chunk-OJJFANO6.js +133 -0
  157. package/dist/chunk-OJJFANO6.js.map +1 -0
  158. package/dist/{chunk-JNJWBTU2.js → chunk-OQWPRFAC.js} +332 -882
  159. package/dist/chunk-OQWPRFAC.js.map +1 -0
  160. package/dist/chunk-P4I7BFNJ.js +11 -0
  161. package/dist/chunk-P4I7BFNJ.js.map +1 -0
  162. package/dist/{chunk-SNNSAGMT.js → chunk-P6YQWIT2.js} +4058 -4039
  163. package/dist/chunk-P6YQWIT2.js.map +1 -0
  164. package/dist/{chunk-JRGFKVAZ.js → chunk-PETQ5WEA.js} +2 -2
  165. package/dist/{chunk-HMWYAUA6.js → chunk-Q6RSJCXB.js} +29 -69
  166. package/dist/chunk-Q6RSJCXB.js.map +1 -0
  167. package/dist/{chunk-U3IKUGRP.js → chunk-QKEUKBRK.js} +17 -23
  168. package/dist/chunk-QKEUKBRK.js.map +1 -0
  169. package/dist/{chunk-2RWB7RKE.js → chunk-QKYUCITR.js} +174 -5814
  170. package/dist/chunk-QKYUCITR.js.map +1 -0
  171. package/dist/chunk-QQDPRTLP.js +127 -0
  172. package/dist/chunk-QQDPRTLP.js.map +1 -0
  173. package/dist/chunk-QQYCYAKI.js +79 -0
  174. package/dist/chunk-QQYCYAKI.js.map +1 -0
  175. package/dist/chunk-R4KDH477.js +1064 -0
  176. package/dist/chunk-R4KDH477.js.map +1 -0
  177. package/dist/chunk-R5TR2DIK.js +119 -0
  178. package/dist/chunk-R5TR2DIK.js.map +1 -0
  179. package/dist/chunk-R62PKTAG.js +66 -0
  180. package/dist/chunk-R62PKTAG.js.map +1 -0
  181. package/dist/{chunk-BFDQ4WNW.js → chunk-RFZA7PSM.js} +4 -5
  182. package/dist/chunk-RFZA7PSM.js.map +1 -0
  183. package/dist/chunk-RGCPELQN.js +219 -0
  184. package/dist/chunk-RGCPELQN.js.map +1 -0
  185. package/dist/chunk-RGVCOG2S.js +910 -0
  186. package/dist/chunk-RGVCOG2S.js.map +1 -0
  187. package/dist/chunk-SOLNJ3AZ.js +209 -0
  188. package/dist/chunk-SOLNJ3AZ.js.map +1 -0
  189. package/dist/chunk-TFT2X7SH.js +77 -0
  190. package/dist/chunk-TFT2X7SH.js.map +1 -0
  191. package/dist/chunk-TUCKEEXE.js +2 -0
  192. package/dist/chunk-TVWCLUBI.js +293 -0
  193. package/dist/chunk-TVWCLUBI.js.map +1 -0
  194. package/dist/chunk-U4TRWSVE.js +78 -0
  195. package/dist/chunk-U4TRWSVE.js.map +1 -0
  196. package/dist/chunk-UIB33QQP.js +379 -0
  197. package/dist/chunk-UIB33QQP.js.map +1 -0
  198. package/dist/chunk-V6GIVALQ.js +1889 -0
  199. package/dist/chunk-V6GIVALQ.js.map +1 -0
  200. package/dist/chunk-VHXCPXUS.js +366 -0
  201. package/dist/chunk-VHXCPXUS.js.map +1 -0
  202. package/dist/{chunk-HGZEPQUT.js → chunk-VU6GMWF6.js} +17 -8
  203. package/dist/chunk-VU6GMWF6.js.map +1 -0
  204. package/dist/chunk-VWZYE3NC.js +8415 -0
  205. package/dist/chunk-VWZYE3NC.js.map +1 -0
  206. package/dist/{chunk-AGMVASXZ.js → chunk-W2GXIARJ.js} +88 -11
  207. package/dist/chunk-W2GXIARJ.js.map +1 -0
  208. package/dist/chunk-W4G3K3V7.js +288 -0
  209. package/dist/chunk-W4G3K3V7.js.map +1 -0
  210. package/dist/chunk-W74LJ5OT.js +588 -0
  211. package/dist/chunk-W74LJ5OT.js.map +1 -0
  212. package/dist/chunk-W7ELYLYK.js +233 -0
  213. package/dist/chunk-W7ELYLYK.js.map +1 -0
  214. package/dist/{chunk-BPMWXTFX.js → chunk-WFZX352D.js} +7 -7
  215. package/dist/chunk-WXA3WTPF.js +20 -0
  216. package/dist/chunk-WXA3WTPF.js.map +1 -0
  217. package/dist/chunk-XRGFH7FI.js +454 -0
  218. package/dist/chunk-XRGFH7FI.js.map +1 -0
  219. package/dist/chunk-XSCGUO2U.js +330 -0
  220. package/dist/chunk-XSCGUO2U.js.map +1 -0
  221. package/dist/chunk-XWROSMI5.js +1039 -0
  222. package/dist/chunk-XWROSMI5.js.map +1 -0
  223. package/dist/chunk-Y2EXZ47H.js +40 -0
  224. package/dist/chunk-Y2EXZ47H.js.map +1 -0
  225. package/dist/chunk-YJGEVBKZ.js +47 -0
  226. package/dist/chunk-YJGEVBKZ.js.map +1 -0
  227. package/dist/{chunk-6CMM6YCB.js → chunk-YWWMISDY.js} +2 -2
  228. package/dist/{chunk-WXA2BWTE.js → chunk-ZCT5DJ3G.js} +2 -48
  229. package/dist/chunk-ZCT5DJ3G.js.map +1 -0
  230. package/dist/chunk-ZEYA2WWX.js +982 -0
  231. package/dist/chunk-ZEYA2WWX.js.map +1 -0
  232. package/dist/chunk-ZRC7Z5X3.js +82 -0
  233. package/dist/chunk-ZRC7Z5X3.js.map +1 -0
  234. package/dist/{chunk-3AIHRXKO.js → chunk-ZS7JIUJ3.js} +12 -10
  235. package/dist/chunk-ZS7JIUJ3.js.map +1 -0
  236. package/dist/{clack-EZ7TDWQU.js → clack-Q4RNC5VE.js} +2 -6
  237. package/dist/{claude-cli-2YKABJJZ.js → claude-cli-GIIHOBGT.js} +4 -2
  238. package/dist/claude-install-BAUSJMW3.js +64 -0
  239. package/dist/{cli-E36SPKBW.js → cli-QY4KKA3D.js} +632 -150
  240. package/dist/cli-QY4KKA3D.js.map +1 -0
  241. package/dist/client-3YQKORVK.js +710 -0
  242. package/dist/client-3YQKORVK.js.map +1 -0
  243. package/dist/{codex-event-ZO2GEFE6.js → codex-event-EUTCAOTQ.js} +3 -5
  244. package/dist/{codex-host-KECJVTA2.js → codex-host-ZON3S6HU.js} +7 -7
  245. package/dist/{codex-install-HQZDGFXW.js → codex-install-HZV2DOAB.js} +242 -88
  246. package/dist/codex-install-HZV2DOAB.js.map +1 -0
  247. package/dist/config-QZOBMTEL.js +57 -0
  248. package/dist/config-names-Z5NZD5R2.js +224 -0
  249. package/dist/config-names-Z5NZD5R2.js.map +1 -0
  250. package/dist/config-rules-YOYHS6YL.js +55 -0
  251. package/dist/config-subagents-WQV2ZAD5.js +362 -0
  252. package/dist/config-subagents-WQV2ZAD5.js.map +1 -0
  253. package/dist/connect-YDWTYU4B.js +1020 -0
  254. package/dist/connect-YDWTYU4B.js.map +1 -0
  255. package/dist/core-0a66n3e7-TTP554XV.js +127 -0
  256. package/dist/core-0a66n3e7-TTP554XV.js.map +1 -0
  257. package/dist/core-0bmnpbz2-C2JIRVZO.js +10790 -0
  258. package/dist/core-0bmnpbz2-C2JIRVZO.js.map +1 -0
  259. package/dist/core-9je8ee1j-74DGHWPV.js +30 -0
  260. package/dist/core-9je8ee1j-74DGHWPV.js.map +1 -0
  261. package/dist/core-wadgcjfh-TSZFQZGH.js +666 -0
  262. package/dist/core-wadgcjfh-TSZFQZGH.js.map +1 -0
  263. package/dist/core-zg882d22-LKV5DZYW.js +37 -0
  264. package/dist/core-zg882d22-LKV5DZYW.js.map +1 -0
  265. package/dist/decision-QSKHOGCO.js +145 -0
  266. package/dist/{doctor-I6XQEKWD.js → doctor-ZWJXRD75.js} +162 -148
  267. package/dist/doctor-ZWJXRD75.js.map +1 -0
  268. package/dist/{env-proxy-R6ZMLQTT.js → env-proxy-XLSLHBKQ.js} +2 -2
  269. package/dist/{ethersCompat-Df4a6QIZ-X6YZWAML.js → ethersCompat-Df4a6QIZ-K3DMHR6Y.js} +5 -5
  270. package/dist/explicit-ME2NRADQ.js +371 -0
  271. package/dist/explicit-ME2NRADQ.js.map +1 -0
  272. package/dist/flush-stdio-NYIJ3QXT.js +18 -0
  273. package/dist/fund-VF7TLDJH.js +722 -0
  274. package/dist/fund-VF7TLDJH.js.map +1 -0
  275. package/dist/hook-command-VZ27MGWO.js +49 -0
  276. package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
  277. package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +2 -2
  278. package/dist/hosts/claude/tenjin/hooks/hook-data.ts +152 -0
  279. package/dist/hosts/claude/tenjin/hooks/hooks.json +7 -0
  280. package/dist/hosts/claude/tenjin/hooks/model-viewer.tsx +2987 -0
  281. package/dist/hosts/claude/tenjin/hooks/register.tsx +527 -56
  282. package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +14 -4
  283. package/dist/hosts/claude/tenjin/types/index.d.ts +144 -1
  284. package/dist/{hosts-DVQJ32QC.js → hosts-3EMTVM4H.js} +7 -6
  285. package/dist/index.js +18 -15
  286. package/dist/index.js.map +1 -1
  287. package/dist/install-ZA7L2UF3.js +115 -0
  288. package/dist/install-funding-JDGYTF72.js +30 -0
  289. package/dist/install-identity-FFAYEFLX.js +30 -0
  290. package/dist/{install-wallet-5M4OTYLX.js → install-wallet-2SFOVE3Q.js} +68 -53
  291. package/dist/install-wallet-2SFOVE3Q.js.map +1 -0
  292. package/dist/mcp-36S6MK3C.js +67642 -0
  293. package/dist/mcp-36S6MK3C.js.map +1 -0
  294. package/dist/new-install-5L4GY3LN.js +51 -0
  295. package/dist/{package-IJFGMWEV.js → package-BONDXSV3.js} +2 -2
  296. package/dist/{passphrase-IFTDS3CU.js → passphrase-T4ULBN4M.js} +16 -12
  297. package/dist/{paths-XCSAKISU.js → paths-O2KDWZ76.js} +18 -28
  298. package/dist/pay-CMV5KL74.js +74 -0
  299. package/dist/{payments-HFPPWHTV.js → payments-Z6UBZL4Z.js} +36 -26
  300. package/dist/payments-Z6UBZL4Z.js.map +1 -0
  301. package/dist/reclaim-subagent-credit-ABSF67SJ.js +105 -0
  302. package/dist/reclaim-subagent-credit-ABSF67SJ.js.map +1 -0
  303. package/dist/{redact-D7ASVWKL.js → redact-LOTHE5TS.js} +2 -8
  304. package/dist/redact-LOTHE5TS.js.map +1 -0
  305. package/dist/routing-quote-AHLAREXR.js +40 -0
  306. package/dist/routing-quote-AHLAREXR.js.map +1 -0
  307. package/dist/run-JH7ELYAM.js +88 -0
  308. package/dist/run-JH7ELYAM.js.map +1 -0
  309. package/dist/runtime-2GX4ALJP.js +410 -0
  310. package/dist/runtime-2GX4ALJP.js.map +1 -0
  311. package/dist/runtime-activate-IDQ2NCSP.js +39 -0
  312. package/dist/runtime-activate-IDQ2NCSP.js.map +1 -0
  313. package/dist/{runtime-fetch-ZSSSK72Y.js → runtime-fetch-6LOBHBEN.js} +4 -4
  314. package/dist/runtime-fetch-6LOBHBEN.js.map +1 -0
  315. package/dist/runtime-launchers-YAPKCBHV.js +31 -0
  316. package/dist/runtime-launchers-YAPKCBHV.js.map +1 -0
  317. package/dist/{runtime-layout-WIDILZ6K.js → runtime-layout-QHZQJV7C.js} +5 -4
  318. package/dist/runtime-layout-QHZQJV7C.js.map +1 -0
  319. package/dist/runtime-place-4POL4KK4.js +37 -0
  320. package/dist/runtime-place-4POL4KK4.js.map +1 -0
  321. package/dist/runtime-provenance-MNJGVBV2.js +12 -0
  322. package/dist/runtime-provenance-MNJGVBV2.js.map +1 -0
  323. package/dist/{secp256k1-ZZZT2CAX.js → secp256k1-N5P2GVGF.js} +3 -3
  324. package/dist/secp256k1-N5P2GVGF.js.map +1 -0
  325. package/dist/{send-GCVEAQKL.js → send-ELXFKEKY.js} +35 -32
  326. package/dist/send-ELXFKEKY.js.map +1 -0
  327. package/dist/status-FXUFWJDM.js +404 -0
  328. package/dist/status-FXUFWJDM.js.map +1 -0
  329. package/dist/{status-line-OPCXDHL2.js → status-line-IH5JBWBC.js} +51 -43
  330. package/dist/status-line-IH5JBWBC.js.map +1 -0
  331. package/dist/streamableHttp-CP2ZQBIK.js +768 -0
  332. package/dist/streamableHttp-CP2ZQBIK.js.map +1 -0
  333. package/dist/{uninstall-BAWRBXXQ.js → uninstall-LJZUKM4D.js} +76 -76
  334. package/dist/uninstall-LJZUKM4D.js.map +1 -0
  335. package/dist/update-EUIX72IX.js +68 -0
  336. package/dist/update-EUIX72IX.js.map +1 -0
  337. package/dist/usage-EKDC7LUC.js +180 -0
  338. package/dist/usage-EKDC7LUC.js.map +1 -0
  339. package/dist/{usdc-VG4CIOUK.js → usdc-YIHK2OMC.js} +8 -12
  340. package/dist/usdc-YIHK2OMC.js.map +1 -0
  341. package/dist/{viemAdapter-By13KInL-DOFTEIJV.js → viemAdapter-By13KInL-PRLSIESK.js} +5 -5
  342. package/dist/viemAdapter-By13KInL-PRLSIESK.js.map +1 -0
  343. package/dist/wallet-HSW757W6.js +80 -0
  344. package/dist/wallet-HSW757W6.js.map +1 -0
  345. package/dist/wallet-kdf-worker.mjs +1433 -818
  346. package/docs/agent-permissions.md +88 -155
  347. package/docs/router-reference.md +236 -0
  348. package/docs/safety-model.md +31 -33
  349. package/docs/subagents-internals.md +97 -0
  350. package/docs/subagents.md +348 -0
  351. package/docs/troubleshooting.md +10 -6
  352. package/package.json +12 -8
  353. package/scripts/installers/install.sh +7 -1
  354. package/dist/alive-GSOWKUOY.js +0 -38
  355. package/dist/chunk-2I4QTOLB.js.map +0 -1
  356. package/dist/chunk-2M2VPI2E.js +0 -560
  357. package/dist/chunk-2M2VPI2E.js.map +0 -1
  358. package/dist/chunk-2RWB7RKE.js.map +0 -1
  359. package/dist/chunk-2SNUOHAT.js.map +0 -1
  360. package/dist/chunk-3623BLPV.js +0 -184
  361. package/dist/chunk-3623BLPV.js.map +0 -1
  362. package/dist/chunk-36RVGZNY.js.map +0 -1
  363. package/dist/chunk-3AIHRXKO.js.map +0 -1
  364. package/dist/chunk-3FMZGI7I.js.map +0 -1
  365. package/dist/chunk-3UCIG4TG.js.map +0 -1
  366. package/dist/chunk-4K7TQHNP.js.map +0 -1
  367. package/dist/chunk-4LMUQMBH.js +0 -29
  368. package/dist/chunk-4LMUQMBH.js.map +0 -1
  369. package/dist/chunk-4USCZ2NI.js +0 -228
  370. package/dist/chunk-4USCZ2NI.js.map +0 -1
  371. package/dist/chunk-4YOZGGTZ.js.map +0 -1
  372. package/dist/chunk-62KNUYWD.js +0 -111
  373. package/dist/chunk-62KNUYWD.js.map +0 -1
  374. package/dist/chunk-A5GKIG5O.js +0 -2037
  375. package/dist/chunk-A5GKIG5O.js.map +0 -1
  376. package/dist/chunk-AGMVASXZ.js.map +0 -1
  377. package/dist/chunk-BF4XHEQK.js.map +0 -1
  378. package/dist/chunk-BFDQ4WNW.js.map +0 -1
  379. package/dist/chunk-C2Q76BVM.js.map +0 -1
  380. package/dist/chunk-CEXSOI5R.js +0 -808
  381. package/dist/chunk-CEXSOI5R.js.map +0 -1
  382. package/dist/chunk-E7SW44LM.js.map +0 -1
  383. package/dist/chunk-EDJWHDDL.js +0 -33
  384. package/dist/chunk-EDJWHDDL.js.map +0 -1
  385. package/dist/chunk-FVIGCDSV.js.map +0 -1
  386. package/dist/chunk-GTTUCOPD.js +0 -105
  387. package/dist/chunk-GTTUCOPD.js.map +0 -1
  388. package/dist/chunk-HDPUXS3Z.js +0 -122
  389. package/dist/chunk-HDPUXS3Z.js.map +0 -1
  390. package/dist/chunk-HGGWCP7W.js +0 -120
  391. package/dist/chunk-HGGWCP7W.js.map +0 -1
  392. package/dist/chunk-HGZEPQUT.js.map +0 -1
  393. package/dist/chunk-HMWYAUA6.js.map +0 -1
  394. package/dist/chunk-IADZOXKN.js.map +0 -1
  395. package/dist/chunk-ILNIZ5I2.js.map +0 -1
  396. package/dist/chunk-INTFHMU4.js.map +0 -1
  397. package/dist/chunk-JKKAIPTU.js.map +0 -1
  398. package/dist/chunk-JNJWBTU2.js.map +0 -1
  399. package/dist/chunk-KM7RY2ZS.js +0 -246
  400. package/dist/chunk-KM7RY2ZS.js.map +0 -1
  401. package/dist/chunk-KOGZDMHO.js +0 -21
  402. package/dist/chunk-KOGZDMHO.js.map +0 -1
  403. package/dist/chunk-L6JEXB3E.js.map +0 -1
  404. package/dist/chunk-LRW6S53P.js.map +0 -1
  405. package/dist/chunk-LXAYUOXI.js +0 -511
  406. package/dist/chunk-LXAYUOXI.js.map +0 -1
  407. package/dist/chunk-MEFB5KHA.js +0 -59
  408. package/dist/chunk-MEFB5KHA.js.map +0 -1
  409. package/dist/chunk-MPZUYCAP.js.map +0 -1
  410. package/dist/chunk-NDGZDTSJ.js.map +0 -1
  411. package/dist/chunk-OJNTCYQQ.js.map +0 -1
  412. package/dist/chunk-P3LFTKE7.js +0 -58
  413. package/dist/chunk-P3LFTKE7.js.map +0 -1
  414. package/dist/chunk-QXP3Z3JN.js.map +0 -1
  415. package/dist/chunk-RVPYTUP4.js.map +0 -1
  416. package/dist/chunk-SNNSAGMT.js.map +0 -1
  417. package/dist/chunk-TC2WZLSC.js.map +0 -1
  418. package/dist/chunk-TKPF35W6.js +0 -29
  419. package/dist/chunk-TKPF35W6.js.map +0 -1
  420. package/dist/chunk-U3IKUGRP.js.map +0 -1
  421. package/dist/chunk-UUGOUOVT.js.map +0 -1
  422. package/dist/chunk-UXZONNEQ.js.map +0 -1
  423. package/dist/chunk-WXA2BWTE.js.map +0 -1
  424. package/dist/chunk-WYXUQGOL.js.map +0 -1
  425. package/dist/chunk-X5ZBP3IY.js.map +0 -1
  426. package/dist/chunk-XKESD27X.js +0 -10
  427. package/dist/chunk-XKESD27X.js.map +0 -1
  428. package/dist/chunk-XQJXNMSB.js.map +0 -1
  429. package/dist/chunk-Y527D4TV.js +0 -56
  430. package/dist/chunk-Y527D4TV.js.map +0 -1
  431. package/dist/chunk-ZDZERB6L.js.map +0 -1
  432. package/dist/chunk-ZNNXRNFD.js.map +0 -1
  433. package/dist/chunk-ZURZHELF.js.map +0 -1
  434. package/dist/cli-E36SPKBW.js.map +0 -1
  435. package/dist/codex-install-HQZDGFXW.js.map +0 -1
  436. package/dist/config-HY2E4GGW.js +0 -55
  437. package/dist/doctor-I6XQEKWD.js.map +0 -1
  438. package/dist/fund-2QRO7OJL.js +0 -378
  439. package/dist/fund-2QRO7OJL.js.map +0 -1
  440. package/dist/hook-command-2UBCSZG6.js +0 -43
  441. package/dist/install-ILUX5C4A.js +0 -107
  442. package/dist/install-identity-TZKGY6LQ.js +0 -31
  443. package/dist/install-wallet-5M4OTYLX.js.map +0 -1
  444. package/dist/mcp-LE4DUS22.js +0 -14127
  445. package/dist/mcp-LE4DUS22.js.map +0 -1
  446. package/dist/pay-WCG3IH4R.js +0 -55
  447. package/dist/payments-HFPPWHTV.js.map +0 -1
  448. package/dist/plugin-registration-PZFI5GZW.js +0 -68
  449. package/dist/runtime-UZOKSUZX.js +0 -1321
  450. package/dist/runtime-UZOKSUZX.js.map +0 -1
  451. package/dist/send-GCVEAQKL.js.map +0 -1
  452. package/dist/status-HCVAOCN7.js +0 -150
  453. package/dist/status-HCVAOCN7.js.map +0 -1
  454. package/dist/status-line-OPCXDHL2.js.map +0 -1
  455. package/dist/uninstall-BAWRBXXQ.js.map +0 -1
  456. package/dist/update-CACXLQLR.js +0 -56
  457. package/dist/wallet-QL4UUXEZ.js +0 -55
  458. /package/dist/{_esm-BIN7VY2L.js.map → _esm-2KST7HQ7.js.map} +0 -0
  459. /package/dist/{alive-GSOWKUOY.js.map → alive-5TV22PNF.js.map} +0 -0
  460. /package/dist/{auto-update-Y24UL56V.js.map → auth-XI7BJFLW.js.map} +0 -0
  461. /package/dist/{ccip-DHDFKTQV.js.map → auto-update-7L24KDWA.js.map} +0 -0
  462. /package/dist/{clack-EZ7TDWQU.js.map → balance-DFHC6XEU.js.map} +0 -0
  463. /package/dist/{claude-cli-2YKABJJZ.js.map → ccip-HOW3DZYF.js.map} +0 -0
  464. /package/dist/{chunk-IE7P2BZE.js.map → chunk-6QMDUDF2.js.map} +0 -0
  465. /package/dist/{chunk-KG3D7FIF.js.map → chunk-CZJOMUBP.js.map} +0 -0
  466. /package/dist/{chunk-3GNJXKIT.js.map → chunk-F43CV6UC.js.map} +0 -0
  467. /package/dist/{chunk-J57UC3DD.js.map → chunk-FKVJKLPI.js.map} +0 -0
  468. /package/dist/{chunk-SO3XRZPX.js.map → chunk-HPRVFJPM.js.map} +0 -0
  469. /package/dist/{chunk-2GP3HRYK.js.map → chunk-INSIW65E.js.map} +0 -0
  470. /package/dist/{chunk-RL5UUDT4.js.map → chunk-JNUKLSMZ.js.map} +0 -0
  471. /package/dist/{chunk-JRGFKVAZ.js.map → chunk-PETQ5WEA.js.map} +0 -0
  472. /package/dist/{codex-event-ZO2GEFE6.js.map → chunk-TUCKEEXE.js.map} +0 -0
  473. /package/dist/{chunk-BPMWXTFX.js.map → chunk-WFZX352D.js.map} +0 -0
  474. /package/dist/{chunk-6CMM6YCB.js.map → chunk-YWWMISDY.js.map} +0 -0
  475. /package/dist/{codex-host-KECJVTA2.js.map → clack-Q4RNC5VE.js.map} +0 -0
  476. /package/dist/{config-HY2E4GGW.js.map → claude-cli-GIIHOBGT.js.map} +0 -0
  477. /package/dist/{env-proxy-R6ZMLQTT.js.map → claude-install-BAUSJMW3.js.map} +0 -0
  478. /package/dist/{ethersCompat-Df4a6QIZ-X6YZWAML.js.map → codex-event-EUTCAOTQ.js.map} +0 -0
  479. /package/dist/{hook-command-2UBCSZG6.js.map → codex-host-ZON3S6HU.js.map} +0 -0
  480. /package/dist/{hosts-DVQJ32QC.js.map → config-QZOBMTEL.js.map} +0 -0
  481. /package/dist/{install-ILUX5C4A.js.map → config-rules-YOYHS6YL.js.map} +0 -0
  482. /package/dist/{install-identity-TZKGY6LQ.js.map → decision-QSKHOGCO.js.map} +0 -0
  483. /package/dist/{package-IJFGMWEV.js.map → env-proxy-XLSLHBKQ.js.map} +0 -0
  484. /package/dist/{passphrase-IFTDS3CU.js.map → ethersCompat-Df4a6QIZ-K3DMHR6Y.js.map} +0 -0
  485. /package/dist/{paths-XCSAKISU.js.map → flush-stdio-NYIJ3QXT.js.map} +0 -0
  486. /package/dist/{pay-WCG3IH4R.js.map → hook-command-VZ27MGWO.js.map} +0 -0
  487. /package/dist/{plugin-registration-PZFI5GZW.js.map → hosts-3EMTVM4H.js.map} +0 -0
  488. /package/dist/{redact-D7ASVWKL.js.map → install-ZA7L2UF3.js.map} +0 -0
  489. /package/dist/{runtime-fetch-ZSSSK72Y.js.map → install-funding-JDGYTF72.js.map} +0 -0
  490. /package/dist/{runtime-layout-WIDILZ6K.js.map → install-identity-FFAYEFLX.js.map} +0 -0
  491. /package/dist/{secp256k1-ZZZT2CAX.js.map → new-install-5L4GY3LN.js.map} +0 -0
  492. /package/dist/{update-CACXLQLR.js.map → package-BONDXSV3.js.map} +0 -0
  493. /package/dist/{usdc-VG4CIOUK.js.map → passphrase-T4ULBN4M.js.map} +0 -0
  494. /package/dist/{viemAdapter-By13KInL-DOFTEIJV.js.map → paths-O2KDWZ76.js.map} +0 -0
  495. /package/dist/{wallet-QL4UUXEZ.js.map → pay-CMV5KL74.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/router/specs.ts","../src/router/settings-check.ts","../src/router/untaken.ts"],"sourcesContent":["import { createHash, randomUUID } from 'node:crypto';\nimport { constants } from 'node:fs';\nimport { lstat, open, opendir, rm } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { z } from 'zod';\nimport { writeFileAtomic, writeFileAtomicExclusive } from '../lib/atomic-json';\nimport {\n AccountOfferSpecSchema,\n ChoicesSchema,\n OfferSpecSchema,\n type AccountOfferSpec,\n type Choices,\n type OfferSpec,\n} from './decision';\nimport { SettingsHashSchema } from './settings-wire';\n\n/**\n * THE REQUEST SPECS AN OFFER CARRIED, kept on this machine by the offer's id. The\n * hook that shows a line stores the spec of every service the line names; the\n * `request` tool, which runs in the MCP server's own process and never sees\n * the hook, reads one back by the id the agent passes. One file per id, named\n * by the id's SHA-256, so a read is one open and needs no session.\n *\n * Best effort on the write, like every record the hooks keep: with no spec\n * stored, `request({id})` says none is kept and asks for the query its line\n * named. A spec is the server's own answer, re-parsed on the way back in, and\n * it lives as long as the server keeps the offer's id.\n */\n\nconst SPECS_DIR = join('progress', 'specs');\nconst RESULTS_DIR = 'results';\n/** A spec holds a service's whole input schema; far larger than any record. */\nconst MAX_SPEC_BYTES = 128 * 1024;\n/** The server's decision expiry: past it, the id's outcome report and an\n * `{id, query}` fallback find no row. */\nexport const SPEC_TTL_MS = 15 * 60_000;\n/** A saved result outlives its offer: the agent opens it later in the session,\n * or in the next step of a chain. A day covers a working session. */\nexport const RESULT_TTL_MS = 24 * 60 * 60_000;\n\nconst digest = (value: string): string => createHash('sha256').update(value).digest('hex');\n\nfunction specPath(dataDir: string, id: string): string {\n return join(dataDir, SPECS_DIR, `${digest(id)}.json`);\n}\n\n/** The field of a kept spec that names the one input a row may show. */\nexport const SHOWN_KEY = 'shown';\n\n/**\n * A SPEC AS THIS MACHINE KEEPS IT: the server's spec and the `settingsHash`\n * of the answer that carried it, which names the rules that offer was decided\n * under. Absent when that answer echoed none. The check before every call\n * compares it with the hash of the rules saved now (`settings-check.ts`).\n */\nexport const KeptSpecSchema = OfferSpecSchema.extend({\n settingsHash: SettingsHashSchema.optional(),\n});\nexport type KeptSpec = z.infer<typeof KeptSpecSchema>;\n\n/** Past this many characters an input is a prompt, not the key of a lookup. */\nexport const SHOWN_INPUT_MAX_CHARS = 80;\n\n/**\n * WHICH INPUT A ROW MAY SHOW FOR A SERVICE, decided here so the mod reads a\n * field name and nothing else (`shown`, kept in the spec's own file). Only\n * a lookup's identifying input: the field the catalog says takes a search's\n * query or a fetch's URL (`holds`), else the service's first required string\n * field (a company or person name, an expression). Never for a service the\n * catalog marks as producing media (`output: \"media\"`: image, video, audio,\n * music, speech), whose input is a prompt.\n */\nexport function shownInputField(\n spec: Pick<OfferSpec, 'output' | 'holds' | 'input'>,\n): string | null {\n if (spec.output === 'media') return null;\n const held = spec.holds?.WebSearch ?? spec.holds?.WebFetch;\n if (held !== undefined) return held;\n const properties = spec.input.properties;\n if (properties === null || typeof properties !== 'object') return null;\n const isString = (name: string) =>\n (properties as Record<string, { type?: unknown }>)[name]?.type === 'string';\n const required = Array.isArray(spec.input.required)\n ? spec.input.required.filter((name): name is string => typeof name === 'string')\n : [];\n return required.find(isString) ?? Object.keys(properties).find(isString) ?? null;\n}\n\n/**\n * The input a row shows for this call, or undefined: the field\n * {@link shownInputField} names, when its value is a short single key. The\n * mod applies the same cap to the value it reads.\n */\nexport function shownInput(\n spec: Pick<OfferSpec, 'output' | 'holds' | 'input'>,\n input: Record<string, unknown>,\n): string | undefined {\n const field = shownInputField(spec);\n if (field === null) return undefined;\n const value = input[field];\n if (typeof value !== 'string') return undefined;\n const text = value.trim();\n return text.length > 0 && Array.from(text).length <= SHOWN_INPUT_MAX_CHARS ? text : undefined;\n}\n\n/** The field of a kept spec that names the account offer it was offered in\n * place of, after that account refused (`accounts/run.ts`). */\nconst REPLACES_KEY = 'replaces';\n\n/**\n * Store each spec under its id, and drop expired ones. Never throws. Ages are\n * file mtimes, so they are read against the real clock, never a caller's.\n * `replaces`: the account offer these were offered in place of, which a run of\n * one of them settles, so that offer never runs too.\n */\nexport async function storeSpecs(\n dataDir: string,\n specs: readonly OfferSpec[] | undefined,\n settingsHash?: string,\n opts: { replaces?: string } = {},\n): Promise<void> {\n if (specs === undefined || specs.length === 0) return;\n for (const spec of specs) {\n try {\n await writeKept(\n dataDir,\n spec,\n settingsHash,\n opts.replaces !== undefined ? { [REPLACES_KEY]: opts.replaces } : {},\n );\n } catch {\n // The tool falls back to the server for this id; a row shows no input.\n }\n }\n await prune(join(dataDir, SPECS_DIR), SPEC_TTL_MS, Date.now());\n}\n\n/**\n * Write one kept spec under its id. `shown` rides beside it for the mod, with\n * `beside` (what a kind of spec keeps of its own), and both are dropped on\n * read; the answer's settings hash is this offer's own, never a later one.\n * Throws.\n */\nasync function writeKept(\n dataDir: string,\n spec: OfferSpec | AccountOfferSpec,\n settingsHash: string | undefined,\n beside: Record<string, unknown>,\n): Promise<void> {\n const kept: Record<string, unknown> = {\n ...spec,\n [SHOWN_KEY]: shownInputField(spec),\n ...beside,\n };\n delete kept.settingsHash;\n if (settingsHash !== undefined) kept.settingsHash = settingsHash;\n await writeFileAtomic(specPath(dataDir, spec.id), JSON.stringify(kept), {\n mode: 0o600,\n dirMode: 0o700,\n });\n}\n\n/** The spec stored for this id, with the settings hash it was decided under,\n * or null: none, expired, damaged or not ours. */\nexport async function readSpec(dataDir: string, id: string): Promise<KeptSpec | null> {\n return (await readKept(dataDir, id, (kept) => paidSpecOf(kept, id)))?.spec ?? null;\n}\n\n/**\n * The file kept for this id, read once and handed to `read`, or null: none,\n * expired, over its bound or damaged. O_NOFOLLOW: the directory is the\n * user's, and a planted symlink must not turn this read into a read of\n * something else. Never throws.\n */\nasync function readKept<T>(\n dataDir: string,\n id: string,\n read: (kept: Record<string, unknown>) => T | null,\n): Promise<T | null> {\n const file = await open(specPath(dataDir, id), constants.O_RDONLY | constants.O_NOFOLLOW).catch(\n () => undefined,\n );\n if (file === undefined) return null;\n try {\n const stat = await file.stat();\n if (Date.now() - stat.mtimeMs > SPEC_TTL_MS || stat.size > MAX_SPEC_BYTES) return null;\n const kept: unknown = JSON.parse(await file.readFile('utf8'));\n if (kept === null || typeof kept !== 'object' || Array.isArray(kept)) return null;\n return read(kept as Record<string, unknown>);\n } catch {\n return null;\n } finally {\n await file.close().catch(() => undefined);\n }\n}\n\n/** A kept file as a spec the balance pays, with the account offer it\n * replaces, when it does; null when it is not one. */\nfunction paidSpecOf(\n kept: Record<string, unknown>,\n id: string,\n): { spec: KeptSpec; replaces?: string } | null {\n const replaces = kept[REPLACES_KEY];\n const fields = { ...kept };\n delete fields[SHOWN_KEY];\n delete fields[REPLACES_KEY];\n const parsed = KeptSpecSchema.safeParse(fields);\n if (!parsed.success || parsed.data.id !== id) return null;\n return {\n spec: parsed.data,\n ...(typeof replaces === 'string' && replaces.length > 0 ? { replaces } : {}),\n };\n}\n\n/** An account spec as this machine keeps it: with the settings hash its\n * answer echoed, as every kept spec has. */\nexport type KeptAccountSpec = AccountOfferSpec & { settingsHash?: string };\n\n/**\n * KEEP AN OFFER LED BY THE USER'S OWN ACCOUNT (plan 37): its spec and the\n * settings hash its answer echoed. Never throws.\n */\nexport async function storeAccountOffer(\n dataDir: string,\n lead: AccountOfferSpec,\n settingsHash: string | undefined,\n): Promise<void> {\n try {\n await writeKept(dataDir, lead, settingsHash, {});\n } catch {\n // `request({id})` says no spec is kept, and the agent asks again.\n }\n await prune(join(dataDir, SPECS_DIR), SPEC_TTL_MS, Date.now());\n}\n\n/** What is kept for an id: a spec the balance pays, with the account offer\n * it was offered in place of, or one on the user's own account. */\nexport type KeptAny =\n | { spec: KeptSpec; account?: undefined; replaces?: string }\n | { spec: KeptAccountSpec; account: true };\n\n/** Either kind of spec kept for this id, or null. Callers that run only a\n * spec the balance pays read {@link readSpec}, which never returns the other. */\nexport async function readKeptSpec(dataDir: string, id: string): Promise<KeptAny | null> {\n return readKept(dataDir, id, (kept) => paidSpecOf(kept, id) ?? accountSpecOf(kept, id));\n}\n\n/** A kept file as a spec on the user's own account, or null. */\nfunction accountSpecOf(\n kept: Record<string, unknown>,\n id: string,\n): Extract<KeptAny, { account: true }> | null {\n const hash = SettingsHashSchema.optional().safeParse(kept.settingsHash);\n const fields = { ...kept };\n for (const key of [SHOWN_KEY, 'settingsHash']) delete fields[key];\n const account = AccountOfferSpecSchema.safeParse(fields);\n if (!account.success || account.data.id !== id || !hash.success) return null;\n return {\n spec: { ...account.data, ...(hash.data !== undefined ? { settingsHash: hash.data } : {}) },\n account: true,\n };\n}\n\n/** What the hook kept of a choice set: the set, and the line it came with. */\nexport interface KeptChoices {\n choices: Choices;\n hint: string;\n}\n\nexport const KeptChoicesSchema = z.strictObject({\n choices: ChoicesSchema,\n hint: z.string().max(2_000),\n});\n\nfunction choicesPath(dataDir: string, id: string): string {\n return join(dataDir, SPECS_DIR, `${digest(id)}.choices.json`);\n}\n\n/**\n * KEEP AN OFFER'S CHOICE SET by the offer's id, beside its specs and for as\n * long: `request({id, choice})` reads it back to find the option's own id, or\n * every option's for `all`. Never throws; with none kept, a choice is refused\n * and the agent asks again.\n */\nexport async function storeChoices(\n dataDir: string,\n id: string,\n kept: KeptChoices | undefined,\n): Promise<void> {\n if (kept === undefined) return;\n try {\n await writeFileAtomic(choicesPath(dataDir, id), JSON.stringify(kept), {\n mode: 0o600,\n dirMode: 0o700,\n });\n } catch {\n // The choice is refused, and the agent asks again.\n }\n await prune(join(dataDir, SPECS_DIR), SPEC_TTL_MS, Date.now());\n}\n\n/** The choice set kept for this id, or null: none, expired, damaged or not ours. */\nexport async function readChoices(dataDir: string, id: string): Promise<KeptChoices | null> {\n const file = await open(\n choicesPath(dataDir, id),\n constants.O_RDONLY | constants.O_NOFOLLOW,\n ).catch(() => undefined);\n if (file === undefined) return null;\n try {\n const stat = await file.stat();\n if (Date.now() - stat.mtimeMs > SPEC_TTL_MS || stat.size > MAX_SPEC_BYTES) return null;\n const parsed = KeptChoicesSchema.safeParse(JSON.parse(await file.readFile('utf8')));\n return parsed.success ? parsed.data : null;\n } catch {\n return null;\n } finally {\n await file.close().catch(() => undefined);\n }\n}\n\nfunction labelPath(dataDir: string, id: string): string {\n return join(dataDir, SPECS_DIR, `${digest(id)}.label.json`);\n}\n\n/**\n * KEEP A FREE OFFER'S NAME by its id, beside its specs and for as long: a\n * free lookup carries no spec (the docs lookup has none), so this is the one\n * place the mod finds the name its row draws before the call has run. Written\n * for every free line the CLI shows. Never throws; with none kept, the row\n * draws nothing.\n */\nexport async function storeLabel(dataDir: string, id: string, label: string): Promise<void> {\n try {\n await writeFileAtomic(labelPath(dataDir, id), JSON.stringify({ id, label }), {\n mode: 0o600,\n dirMode: 0o700,\n });\n } catch {\n // The row draws nothing.\n }\n await prune(join(dataDir, SPECS_DIR), SPEC_TTL_MS, Date.now());\n}\n\n/**\n * What an earlier call with a spec's id left. `paid`: money left for it.\n * `possibly_paid`: a payment was signed and may have left, but the call ended\n * without saying how much (a spend ledger that could not be written, say).\n * `running`: a call claimed it and has not ended, or its process died, so it\n * may have paid. `unrecorded`: this call could not record its claim.\n */\nexport type EarlierPayment =\n | { state: 'paid'; at: string; amountAtomic: string; txHash?: string }\n | { state: 'possibly_paid'; at: string }\n | { state: 'running'; at?: string }\n /** It ran on the user's own account (plan 37), or may have. */\n | { state: 'account'; at: string }\n /** The account refused, and the offer Tenjin made in its place ran under\n * the offer id `to`: this offer's job is that one's. */\n | { state: 'switched'; at: string; to: string }\n | { state: 'unrecorded' };\n\nconst PaymentSchema = z.discriminatedUnion('state', [\n z.strictObject({\n state: z.literal('paid'),\n at: z.string().max(40),\n amountAtomic: z.string().regex(/^\\d+$/),\n txHash: z.string().max(100).optional(),\n owner: z.string().max(64).optional(),\n }),\n z.strictObject({\n state: z.literal('possibly_paid'),\n at: z.string().max(40),\n owner: z.string().max(64).optional(),\n }),\n z.strictObject({ state: z.literal('running'), at: z.string().max(40) }),\n z.strictObject({ state: z.literal('account'), at: z.string().max(40) }),\n z.strictObject({\n state: z.literal('switched'),\n at: z.string().max(40),\n to: z.string().max(200),\n }),\n]);\n\nfunction paymentPath(dataDir: string, id: string): string {\n return join(dataDir, SPECS_DIR, `${digest(id)}.paid.json`);\n}\n\n/**\n * CLAIM THE ONE PAYMENT A SPEC ALLOWS, before anything is signed: an exclusive\n * create beside the spec, so a retry or a second call with the same id cannot\n * pay again. Null when the claim is this call's; otherwise what an earlier call\n * left, and this one pays nothing. A claim that cannot be written refuses too:\n * the record is the only proof a payment has not already left.\n */\nexport async function claimSpecPayment(\n dataDir: string,\n id: string,\n now: number = Date.now(),\n): Promise<EarlierPayment | null> {\n const path = paymentPath(dataDir, id);\n try {\n await writeFileAtomicExclusive(\n path,\n JSON.stringify({ state: 'running', at: new Date(now).toISOString() }),\n { mode: 0o600, dirMode: 0o700 },\n );\n return null;\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'EEXIST') return { state: 'unrecorded' };\n }\n const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => undefined);\n if (file === undefined) return { state: 'running' };\n try {\n const parsed = PaymentSchema.safeParse(JSON.parse(await file.readFile('utf8')));\n return parsed.success ? parsed.data : { state: 'running' };\n } catch {\n return { state: 'running' };\n } finally {\n await file.close().catch(() => undefined);\n }\n}\n\n/**\n * How the claimed call ended. Money that left is recorded against the id. The\n * claim is dropped when nothing was signed, so a fixed input can still run.\n * Otherwise a signed payment whose amount the call never learned (it failed\n * after the authorization left) stays claimed as possibly paid, and the id\n * never signs again. A record that cannot be written leaves the claim\n * standing, which refuses too. Returns the owner token the record was\n * written under, for {@link releaseSpecClaim}; undefined when no record was\n * written.\n */\nexport async function settleSpecPayment(\n dataDir: string,\n id: string,\n left: { amountAtomic: bigint; txHash?: string; signed: boolean },\n now: number = Date.now(),\n): Promise<string | undefined> {\n const path = paymentPath(dataDir, id);\n if (!left.signed && left.amountAtomic === 0n) {\n await rm(path, { force: true }).catch(() => undefined);\n return undefined;\n }\n const at = new Date(now).toISOString();\n const owner = randomUUID();\n const record =\n left.amountAtomic > 0n\n ? {\n state: 'paid',\n at,\n amountAtomic: left.amountAtomic.toString(),\n ...(left.txHash !== undefined ? { txHash: left.txHash } : {}),\n owner,\n }\n : { state: 'possibly_paid', at, owner };\n return writeFileAtomic(path, JSON.stringify(record), { mode: 0o600, dirMode: 0o700 }).then(\n () => owner,\n () => undefined,\n );\n}\n\n/**\n * DROP A CLAIM ONLY WHILE IT IS STILL THE ONE THIS RUN WROTE: a short\n * wallet's reopened quote (`runApproveTool`) frees its offers for the rerun.\n * A claim another session or a later run created carries another owner, or\n * none, and stays. Only the claim's holder ever rewrites its file, and no one\n * can create one while it exists, so a matching owner is this run's record.\n */\nexport async function releaseSpecClaim(dataDir: string, id: string, owner: string): Promise<void> {\n const path = paymentPath(dataDir, id);\n const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => undefined);\n if (file === undefined) return;\n let mine: boolean;\n try {\n const parsed = PaymentSchema.safeParse(JSON.parse(await file.readFile('utf8')));\n mine = parsed.success && 'owner' in parsed.data && parsed.data.owner === owner;\n } catch {\n mine = false;\n } finally {\n await file.close().catch(() => undefined);\n }\n if (mine) await rm(path, { force: true }).catch(() => undefined);\n}\n\n/**\n * How a claimed call on the user's own account ended. One that ran, or may\n * have (its billing call went out), keeps the claim, so the same id never\n * sends it again; so does one whose job the offer made in its place took over\n * (`to`, that offer's id), which may have run and paid. One refused before\n * anything ran on either frees the id for a retry after a reconnect or a fixed\n * input. Never throws.\n */\nexport async function settleAccountRun(\n dataDir: string,\n id: string,\n ran: boolean | { to: string },\n now: number = Date.now(),\n): Promise<void> {\n const path = paymentPath(dataDir, id);\n if (ran === false) {\n await rm(path, { force: true }).catch(() => undefined);\n return;\n }\n const at = new Date(now).toISOString();\n const record = ran === true ? { state: 'account', at } : { state: 'switched', at, to: ran.to };\n await writeFileAtomic(path, JSON.stringify(record), { mode: 0o600, dirMode: 0o700 }).catch(\n () => undefined,\n );\n}\n\n/**\n * THE WHOLE BODY A SPEC'S CALL RETURNED, kept by the offer's id while the\n * agent is handed only the fields the spec promises, so nothing it paid for is\n * out of reach. The caller passes only a body it could project, which is\n * bounded by the result cap. The path, or null when it could not be written,\n * and the caller then hands back the whole body instead. Never throws.\n */\nexport async function storeFullResult(\n dataDir: string,\n id: string,\n body: string,\n): Promise<string | null> {\n const path = join(dataDir, RESULTS_DIR, `${digest(id)}.json`);\n try {\n await writeFileAtomic(path, body, { mode: 0o600, dirMode: 0o700 });\n } catch {\n return null;\n }\n // Housekeeping never holds up a paid result: the prune runs after the path\n // is handed back, and it swallows its own errors.\n void prune(join(dataDir, RESULTS_DIR), RESULT_TTL_MS, Date.now());\n return path;\n}\n\nasync function prune(dir: string, ttlMs: number, now: number): Promise<void> {\n try {\n // Every entry: a directory with many files is the one that most needs its\n // expired files gone.\n const directory = await opendir(dir);\n for await (const entry of directory) {\n if (!entry.isFile()) continue;\n const path = join(dir, entry.name);\n const stat = await lstat(path).catch(() => undefined);\n if (stat === undefined || now - stat.mtimeMs > ttlMs) {\n await rm(path, { force: true }).catch(() => undefined);\n }\n }\n } catch {\n // Housekeeping only.\n }\n}\n","import { personalSettingsAt, type WireState } from './settings';\n\n/**\n * THE CHECK BEFORE EVERY CALL (plan 36). An offer runs only under the rules\n * it was decided under: the hash its answer echoed (`settingsHash`, kept with\n * each spec) must equal the hash of the rules saved now. A different hash\n * means the user changed their settings after the offer, so a provider they\n * just blocked can never be paid on an old offer. An answer that echoed no\n * hash, while the user has any rule saved, came from a router that did not\n * apply them. Either way the call is refused before any provider request,\n * signing or credential, and the agent is told to ask again; nothing here\n * routes again on its own. With no rules saved and no hash, a call runs as it\n * always did.\n *\n * Local only: the global file, read now, so a change from another process\n * applies to the very next call. The CLI keeps no copy of the rule logic:\n * comparing two hashes is the whole check.\n */\n\nexport type SettingsRefusalCode =\n 'settings_changed' | 'settings_unconfirmed' | 'settings_unreadable';\n\nexport interface SettingsRefusal {\n code: SettingsRefusalCode;\n reason: string;\n nextStep: string;\n}\n\nconst ASK_AGAIN =\n 'Call request again with the query (request({query})) for an offer under the current settings.';\n\n/**\n * Null when every hash in `decided` (one per offer about to run, `undefined`\n * for an answer that echoed none) still names the rules saved now; else why\n * not. A whole group is checked at once, so a compare set never shrinks into\n * a different charge: one stale member refuses them all.\n */\nexport async function settingsRefusal(\n dataDir: string,\n decided: readonly (string | undefined)[],\n): Promise<SettingsRefusal | null> {\n const now = await rulesNow(dataDir);\n if ('problem' in now) return UNREADABLE;\n for (const hash of decided) {\n const refusal = hashRefusal(now.wire, hash);\n if (refusal !== null) return refusal;\n }\n return null;\n}\n\n/** The rules saved now as every call sends them, the `settings` field. */\nexport type ReadableWire = Extract<WireState, { status: 'ok' }>;\n\n/**\n * The rules saved now, read once, for a caller that checks more than one\n * thing against them: as every call sends them, or why they can't be read\n * (the read's own error, or the problem `tenjin config` names). A caller\n * refuses the second with {@link UNREADABLE}, or in its own words.\n */\nexport async function rulesNow(\n dataDir: string,\n): Promise<{ wire: ReadableWire } | { problem: string }> {\n let now: Awaited<ReturnType<typeof personalSettingsAt>>;\n try {\n now = await personalSettingsAt(dataDir);\n } catch (err) {\n return { problem: err instanceof Error ? err.message : String(err) };\n }\n return now.wire.status === 'invalid' ? { problem: now.wire.problem } : { wire: now.wire };\n}\n\n/**\n * THE RULE ITSELF, for one hash an answer echoed (`undefined` for none) against\n * the rules saved now: null when it names them, or when it is absent and no\n * rule is saved; else why not. Pure, so the hooks hold an answer to the same\n * rule before they offer from it.\n */\nexport function hashRefusal(wire: ReadableWire, hash: string | undefined): SettingsRefusal | null {\n if (hash === undefined) {\n if (!wire.hasRules) return null;\n return {\n code: 'settings_unconfirmed',\n reason:\n \"Tenjin's router did not confirm it applied your Tenjin settings to this offer, so it was not run and nothing was sent or paid.\",\n nextStep: `${ASK_AGAIN} If Tenjin keeps answering without your settings, use your own tools for this.`,\n };\n }\n if (hash !== wire.settings.hash) {\n return {\n code: 'settings_changed',\n reason:\n 'Your Tenjin settings changed after this offer was made, so it was not run and nothing was sent or paid.',\n nextStep: ASK_AGAIN,\n };\n }\n return null;\n}\n\n/** Rules this build cannot read: nothing runs, and `tenjin config` names why. */\nexport const UNREADABLE: SettingsRefusal = {\n code: 'settings_unreadable',\n reason: \"Your saved Tenjin rules can't be read, so Tenjin offers nothing.\",\n nextStep:\n '`tenjin config` shows the problem and `tenjin config reset --all` clears them; run either if the user asks.',\n};\n","import { createHash } from 'node:crypto';\nimport { constants } from 'node:fs';\nimport { open, opendir, rm } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { writeFileAtomic } from '../lib/atomic-json';\nimport type { CommandContext } from '../context';\nimport { reportSpecOutcome, type IgnoredReason } from './decision';\nimport { HARNESSES, type Harness } from './names';\nimport { SPEC_TTL_MS } from './specs';\n\n/**\n * THE OFFERS A HOST WAS SHOWN AND HAS NOT TAKEN, kept so the server hears\n * when one is ignored (the outcome status `ignored`). The hook that shows an\n * offer's line keeps it here ({@link noteShown}); the `request` tool drops it\n * as soon as a call names any id that line offered ({@link markTaken}); and\n * the next routed hook leg claims, once each, every offer whose 15 minutes ran\n * out (`expired`) and, before a native WebSearch or WebFetch, every offer the\n * same agent in the same session still holds (`native_after_offer`)\n * ({@link claimIgnored}).\n *\n * ONE FILE PER OFFER, FOR THE WHOLE MACHINE, so the last offers of a session\n * that ended are reported by the next leg of any session: no hook runs at a\n * session's end. A claim deletes the file, which only one of two racing legs\n * can do, so each id is reported once. Best effort throughout, like every\n * record the hooks keep: a lost file is one count fewer, and a report is the\n * outcome report's own fire-and-forget telemetry, with no text in it.\n */\n\nconst UNTAKEN_DIR = join('progress', 'untaken');\nconst FILE_RE = /^[a-f0-9]{64}\\.json$/;\n/** The server's id alphabet (`IdSchema`). */\nconst ID_RE = /^[A-Za-z0-9_-]{8,64}$/;\n/** A line names its own id, its specs' and a choice set's: far fewer than this. */\nconst MAX_IDS = 16;\n/** Above this many files a claim leaves the rest for the next leg. */\nconst MAX_ENTRIES = 256;\nconst MAX_ENTRY_BYTES = 4_096;\n\nconst digest = (value: string): string => createHash('sha256').update(value).digest('hex');\n\n/** What is kept of one shown offer. */\nexport interface ShownOffer {\n /** The line's own id, which a report names. */\n id: string;\n /** Every id the line offered, its own first: a call naming any one takes it. */\n ids: string[];\n harness: Harness;\n /** {@link offerScope}: whose native call ignores it. Absent for an offer\n * appended to a delegated task, which only the subagent could take. */\n scope?: string;\n}\n\ninterface Entry extends ShownOffer {\n version: 1;\n at: number;\n}\n\n/** The agent an offer was shown to, in its session: a native call from the\n * same agent in the same session, while it is untaken, ignored it. */\nexport function offerScope(session: string, agentId: string | undefined): string {\n return digest(JSON.stringify([session, agentId ?? '']));\n}\n\n/** Keep a shown offer until it is taken or reported. Never throws. */\nexport async function noteShown(\n dataDir: string,\n offer: ShownOffer,\n now: number = Date.now(),\n): Promise<void> {\n if (!ID_RE.test(offer.id)) return;\n const ids = [...new Set([offer.id, ...offer.ids.filter((id) => ID_RE.test(id))])].slice(\n 0,\n MAX_IDS,\n );\n const entry: Entry = { version: 1, at: now, ...offer, ids };\n await writeFileAtomic(\n join(dataDir, UNTAKEN_DIR, `${digest(offer.id)}.json`),\n JSON.stringify(entry),\n {\n mode: 0o600,\n dirMode: 0o700,\n },\n ).catch(() => undefined);\n}\n\n/**\n * A `request` call named this id: the offer it came from is taken, not ignored.\n * A line's own id names its file; any other id it offered is found by reading\n * every file, with no cap, since one left behind would be reported ignored.\n */\nexport async function markTaken(dataDir: string, id: string): Promise<void> {\n const own = join(dataDir, UNTAKEN_DIR, `${digest(id)}.json`);\n if ((await readEntry(own))?.ids.includes(id) === true) {\n await rm(own, { force: true }).catch(() => undefined);\n return;\n }\n for (const { path, entry } of await entries(dataDir, Infinity)) {\n if (entry?.ids.includes(id) === true) await rm(path, { force: true }).catch(() => undefined);\n }\n}\n\n/** One offer to report as ignored. */\nexport interface Ignored {\n id: string;\n harness: Harness;\n reason: IgnoredReason;\n}\n\n/**\n * CLAIM EVERY OFFER THAT IS NOW IGNORED, deleting each one's file so no other\n * leg reports it: those past their 15 minutes, and with `nativeScope`, those\n * shown to that agent before this leg began. A file that is not a whole entry\n * is removed. Never throws.\n */\nexport async function claimIgnored(\n dataDir: string,\n o: { now: number; nativeScope?: string },\n): Promise<Ignored[]> {\n const claimed: Ignored[] = [];\n for (const { path, entry } of await entries(dataDir)) {\n if (entry === null) {\n await rm(path, { force: true }).catch(() => undefined);\n continue;\n }\n const reason: IgnoredReason | null =\n o.now - entry.at > SPEC_TTL_MS\n ? 'expired'\n : o.nativeScope !== undefined && entry.scope === o.nativeScope && entry.at <= o.now\n ? 'native_after_offer'\n : null;\n if (reason === null) continue;\n // Only the leg whose delete lands reports it.\n const won = await rm(path).then(\n () => true,\n () => false,\n );\n if (won) claimed.push({ id: entry.id, harness: entry.harness, reason });\n }\n return claimed;\n}\n\n/** Tell the server about each claimed offer, without waiting on any of it. */\nexport function reportIgnored(\n claimed: readonly Ignored[],\n deps: { ctx: CommandContext; baseUrl: string; fetchImpl?: typeof fetch },\n): Promise<void> {\n return Promise.all(\n claimed.map(({ id, harness, reason }) =>\n reportSpecOutcome(\n { id, status: 'ignored', reason },\n {\n ctx: deps.ctx,\n baseUrl: deps.baseUrl,\n harness,\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n },\n ),\n ),\n ).then(() => undefined);\n}\n\n/** The files here, up to `limit`, each with its entry, or null for one that\n * is not a whole entry. */\nasync function entries(\n dataDir: string,\n limit = MAX_ENTRIES,\n): Promise<{ path: string; entry: Entry | null }[]> {\n const dir = join(dataDir, UNTAKEN_DIR);\n const found: { path: string; entry: Entry | null }[] = [];\n try {\n const listing = await opendir(dir);\n for await (const item of listing) {\n if (!item.isFile() || !FILE_RE.test(item.name)) continue;\n const path = join(dir, item.name);\n found.push({ path, entry: await readEntry(path) });\n if (found.length >= limit) break;\n }\n } catch {\n // None kept yet, or not readable: nothing to report.\n }\n return found;\n}\n\n/** One entry, every field checked again: what is on disk is input. */\nasync function readEntry(path: string): Promise<Entry | null> {\n // O_NOFOLLOW: the directory is the user's, and a planted symlink must not\n // turn this read into a read of something else.\n const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => undefined);\n if (file === undefined) return null;\n try {\n if ((await file.stat()).size > MAX_ENTRY_BYTES) return null;\n const row = JSON.parse(await file.readFile('utf8')) as Record<string, unknown>;\n const { at, id, ids, harness, scope } = row;\n if (row.version !== 1 || typeof at !== 'number' || !Number.isFinite(at)) return null;\n if (typeof id !== 'string' || !ID_RE.test(id)) return null;\n if (!Array.isArray(ids) || !ids.every((v) => typeof v === 'string')) return null;\n if (!(HARNESSES as readonly unknown[]).includes(harness)) return null;\n if (scope !== undefined && (typeof scope !== 'string' || !/^[a-f0-9]{64}$/.test(scope))) {\n return null;\n }\n return {\n version: 1,\n at,\n id,\n ids: ids as string[],\n harness: harness as Harness,\n ...(scope !== undefined ? { scope } : {}),\n };\n } catch {\n return null;\n } finally {\n await file.close().catch(() => undefined);\n }\n}\n"],"mappings":";;;;;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,EAAE,EAAG,QAAO;AAChF,QAAI,OAAO,OAAO,YAAY,CAAC,MAAM,KAAK,EAAE,EAAG,QAAO;AACtD,QAAI,CAAC,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,OAAO,MAAM,QAAQ,EAAG,QAAO;AAC5E,QAAI,CAAE,UAAiC,SAAS,OAAO,EAAG,QAAO;AACjE,QAAI,UAAU,WAAc,OAAO,UAAU,YAAY,CAAC,iBAAiB,KAAK,KAAK,IAAI;AACvF,aAAO;AAAA,IACT;AACA,WAAO;AAAA,MACL,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAI,UAAU,SAAY,EAAE,MAAM,IAAI,CAAC;AAAA,IACzC;AAAA,EACF,QAAQ;AACN,WAAO;AAAA,EACT,UAAE;AACA,UAAM,KAAK,MAAM,EAAE,MAAM,MAAM,MAAS;AAAA,EAC1C;AACF;","names":["createHash","constants","open","opendir","rm","join","join","digest","createHash","rm","opendir","open","constants"]}
@@ -1,13 +1,13 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
2
  import {
3
3
  hasCode
4
- } from "./chunk-2I4QTOLB.js";
5
- import {
6
- external_exports
7
- } from "./chunk-SNNSAGMT.js";
4
+ } from "./chunk-3MZ7DYRO.js";
8
5
  import {
9
6
  spendLedgerPath
10
- } from "./chunk-OJNTCYQQ.js";
7
+ } from "./chunk-JTX3BUDK.js";
8
+ import {
9
+ external_exports
10
+ } from "./chunk-P6YQWIT2.js";
11
11
 
12
12
  // src/lib/spend-ledger.ts
13
13
  import { readFile } from "node:fs/promises";
@@ -111,4 +111,4 @@ export {
111
111
  readLedger,
112
112
  readSpendSummary
113
113
  };
114
- //# sourceMappingURL=chunk-SO3XRZPX.js.map
114
+ //# sourceMappingURL=chunk-HPRVFJPM.js.map
@@ -1,18 +1,7 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- MOD_FILES,
4
- OWNER_MARKER,
5
- PLUGIN_FILES
6
- } from "./chunk-LRW6S53P.js";
7
- import {
8
- PLUGIN_NAME
9
- } from "./chunk-MPZUYCAP.js";
10
- import {
11
- writeFileAtomic
12
- } from "./chunk-7WEQQJLG.js";
13
2
  import {
14
3
  CliError
15
- } from "./chunk-3UCIG4TG.js";
4
+ } from "./chunk-DI4QAGRZ.js";
16
5
 
17
6
  // src/lib/install-location.ts
18
7
  import { existsSync, realpathSync, statSync } from "node:fs";
@@ -166,128 +155,11 @@ function realpathOrNull(p) {
166
155
  }
167
156
  }
168
157
 
169
- // src/router/plugin-folder.ts
170
- import { lstat, readdir, readFile, rm, rmdir } from "node:fs/promises";
171
- import { dirname as dirname2, join as join2, relative, sep as sep2 } from "node:path";
172
- var FOLDER_NAME = "tenjin-router";
173
- async function readModSources(pluginDir) {
174
- const entries = await Promise.all(
175
- MOD_FILES.map(async (path) => [path, await readFile(join2(pluginDir, path), "utf8")])
176
- ).catch(() => null);
177
- return entries === null ? void 0 : Object.fromEntries(entries);
178
- }
179
- function pluginFolderPath(base) {
180
- return join2(base, "skills", FOLDER_NAME);
181
- }
182
- async function inspectPluginFolder(dir) {
183
- const entry = await lstat(dir).catch(() => null);
184
- if (entry === null) return "absent";
185
- if (!entry.isDirectory() || entry.isSymbolicLink()) return "foreign";
186
- try {
187
- const manifest = JSON.parse(
188
- await readFile(join2(dir, ".claude-plugin", "plugin.json"), "utf8")
189
- );
190
- const marked = manifest.metadata !== null && typeof manifest.metadata === "object" && OWNER_MARKER in manifest.metadata;
191
- return manifest.name === PLUGIN_NAME && marked ? "ours" : "foreign";
192
- } catch {
193
- return "foreign";
194
- }
195
- }
196
- async function linkedParent(dir, path) {
197
- const parents = [];
198
- for (let d = dirname2(path); d !== "."; d = dirname2(d)) parents.unshift(d);
199
- for (const parent of parents) {
200
- const entry = await lstat(join2(dir, parent)).catch(() => null);
201
- if (entry === null) return null;
202
- if (entry.isSymbolicLink() || !entry.isDirectory()) return parent;
203
- }
204
- return null;
205
- }
206
- async function writePluginFolder(dir, files) {
207
- const state = await inspectPluginFolder(dir);
208
- if (state === "foreign") {
209
- return {
210
- path: dir,
211
- state: "refused",
212
- reason: `${dir} exists and is not a folder this CLI wrote, so it was left as it is`
213
- };
214
- }
215
- for (const path of PLUGIN_FILES) {
216
- const linked = await linkedParent(dir, path);
217
- if (linked !== null) {
218
- return {
219
- path: dir,
220
- state: "refused",
221
- reason: `${join2(dir, linked)} is a link or not a folder, so nothing in ${dir} was written`
222
- };
223
- }
224
- }
225
- try {
226
- for (const path of PLUGIN_FILES) {
227
- const body = files[path];
228
- if (body === void 0) continue;
229
- await writeFileAtomic(join2(dir, path), body);
230
- }
231
- } catch (err) {
232
- return {
233
- path: dir,
234
- state: "refused",
235
- reason: err instanceof Error ? err.message : String(err)
236
- };
237
- }
238
- return { path: dir, state: "written" };
239
- }
240
- async function removePluginFolder(dir) {
241
- const state = await inspectPluginFolder(dir);
242
- if (state === "absent") return { path: dir, removed: false, left: [] };
243
- if (state === "foreign") {
244
- return {
245
- path: dir,
246
- removed: false,
247
- left: [],
248
- reason: `${dir} is not a folder this CLI wrote, so nothing in it was removed`
249
- };
250
- }
251
- for (const path of PLUGIN_FILES) {
252
- if (await linkedParent(dir, path) === null) await rm(join2(dir, path), { force: true });
253
- }
254
- const subdirs = [
255
- ...new Set(
256
- PLUGIN_FILES.flatMap((p) => {
257
- const out = [];
258
- for (let d = dirname2(p); d !== "."; d = dirname2(d)) out.push(d);
259
- return out;
260
- })
261
- )
262
- ].sort((a, b) => b.split("/").length - a.split("/").length);
263
- for (const sub of subdirs) await rmdir(join2(dir, sub)).catch(() => void 0);
264
- const left = await listFiles(dir);
265
- if (left.length === 0) await rmdir(dir).catch(() => void 0);
266
- return { path: dir, removed: true, left };
267
- }
268
- async function listFiles(dir) {
269
- const out = [];
270
- const walk = async (current) => {
271
- for (const entry of await readdir(current, { withFileTypes: true }).catch(() => [])) {
272
- const path = join2(current, entry.name);
273
- if (entry.isDirectory()) await walk(path);
274
- else out.push(relative(dir, path).split(sep2).join("/"));
275
- }
276
- };
277
- await walk(dir);
278
- return out.sort();
279
- }
280
-
281
158
  export {
282
159
  refuse,
283
160
  isSourceCheckout,
284
161
  classifyManager,
285
162
  MANAGERS,
286
- resolveManagerScript,
287
- readModSources,
288
- pluginFolderPath,
289
- inspectPluginFolder,
290
- writePluginFolder,
291
- removePluginFolder
163
+ resolveManagerScript
292
164
  };
293
- //# sourceMappingURL=chunk-L6JEXB3E.js.map
165
+ //# sourceMappingURL=chunk-HQR4BWKX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/install-location.ts"],"sourcesContent":["import { existsSync, realpathSync, statSync } from 'node:fs';\nimport { delimiter, dirname, join, sep } from 'node:path';\nimport { CliError } from './errors';\n\n/**\n * WHERE this build is installed, and what that implies about replacing it.\n *\n * Its own module because it answers a different question from the command that\n * uses it: \"what IS this install\" rather than \"how do I replace it\". The\n * refusal set is the load-bearing part, and it got re-cut in three consecutive\n * reviews while it was expressed positionally inside the command body.\n */\n\n/** Managers a global install can be handed back to. yarn is deliberately absent\n * from the delegable set: see the yarn entry in REFUSALS. */\nexport type Delegable = 'npm' | 'pnpm' | 'bun';\n\n/**\n * One reason `npm install -g` would not actually replace THIS build.\n *\n * Each entry carries the three properties that decide WHEN it is evaluated,\n * because expressing them by where the line sat is what made this set get\n * re-cut three times: a missing entry, then a copy on the wrong side of the\n * fetch, then a duplicate that could not run. Declaring them means adding a\n * refusal is a matter of answering three questions, not of guessing a position.\n */\ninterface Refusal {\n /** Does this install location refuse? Pure filesystem, never the network. */\n test: (moduleDir: string) => boolean;\n error: (spec: string, moduleDir: string) => CliError;\n /**\n * Does the fix string name the version the registry just resolved? This is\n * also what decides whether the entry may run BEFORE the fetch: one that does\n * not need a version is evaluated first, so an offline user in a checkout is\n * told they are in a checkout rather than told to go debug their network.\n */\n needsVersion: boolean;\n /**\n * Does it apply to `--check`? Everything here is a reason not to WRITE, and\n * `--check` only reports, so today nothing does. An entry that ever answers\n * yes is one whose test says the REPORT would be wrong, not the install.\n */\n appliesToCheck: boolean;\n}\n\n/**\n * Ordered most-specific first: a checkout and an npx cache are recognizable\n * before any question of which manager or which tree, and the manager entry\n * precedes the global/local one because a pnpm or bun store has its own layout\n * that `isGlobalTree` is not written for.\n */\nexport const REFUSALS: readonly Refusal[] = [\n {\n test: isSourceCheckout,\n error: () =>\n new CliError('REFUSED', 'tenjin-cli is running from a source checkout, not an install', {\n fix: 'Update the checkout instead: git pull && pnpm install',\n }),\n needsVersion: false,\n appliesToCheck: false,\n },\n {\n test: (moduleDir) => moduleDir.split(sep).includes('_npx'),\n error: (spec) =>\n new CliError('REFUSED', 'tenjin-cli is running from the npx cache, not an install', {\n // Writing a global here would \"succeed\" and change nothing: the next\n // `npx tenjin` still resolves its own cached copy.\n fix: `npx fetches its own copy every time. To keep one: npm i -g ${spec}`,\n }),\n needsVersion: true,\n appliesToCheck: false,\n },\n {\n // The ONLY manager still refused. `yarn global add` is yarn-1 only, and\n // berry dropped global installs altogether, so there is no one command this\n // can drive across the versions a user might have. Every other manager is\n // delegated to rather than refused (see MANAGERS).\n test: (moduleDir) => classifyManager(moduleDir) === 'yarn',\n error: (spec) =>\n new CliError(\n 'REFUSED',\n 'This tenjin-cli was installed with yarn, whose global install exists only in yarn 1',\n { fix: `yarn global add ${spec}` },\n ),\n needsVersion: true,\n appliesToCheck: false,\n },\n {\n // Scoped to npm on purpose: the prefix-vs-project-root test is written for\n // npm's layout. pnpm's global store and bun's global dir both keep a\n // package.json beside `node_modules`, so an unscoped test would read either\n // as a project-local install and refuse the very case we now delegate.\n test: (moduleDir) => classifyManager(moduleDir) === 'npm' && !isGlobalTree(moduleDir),\n error: (spec) =>\n new CliError(\n 'REFUSED',\n 'This tenjin-cli is a project-local dependency, not a global install',\n {\n fix: `Update it where it is declared: npm i ${spec}`,\n },\n ),\n needsVersion: true,\n appliesToCheck: false,\n },\n];\n\n/**\n * Evaluate the refusal set, once per stage. `spec` is null before the registry\n * has been asked and the resolved `tenjin-cli@<version>` after, which is what\n * selects the eligible entries: every entry runs in exactly one stage, so no\n * refusal can be reached twice or, as in round three, be written twice and\n * reached once.\n */\nexport function refuse(moduleDir: string, opts: { check: boolean; spec: string | null }): void {\n for (const entry of REFUSALS) {\n if (opts.check && !entry.appliesToCheck) continue;\n if (entry.needsVersion !== (opts.spec !== null)) continue;\n if (entry.test(moduleDir)) throw entry.error(opts.spec ?? '', moduleDir);\n }\n}\n\n/**\n * The published package ships `dist/` and `docs/` with no `src/` beside them\n * (the `files` array), so a `src/` next to the nearest package.json means a\n * checkout, whose version number says nothing about what HEAD holds.\n */\nexport function isSourceCheckout(moduleDir: string): boolean {\n let dir = moduleDir;\n for (let i = 0; i < 8; i += 1) {\n if (existsSync(join(dir, 'package.json'))) return existsSync(join(dir, 'src'));\n const parent = dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n return false;\n}\n\n/**\n * Is this a GLOBAL npm tree? A global install sits under a prefix directory that\n * is not itself a package (`<prefix>/lib/node_modules/tenjin-cli` on POSIX,\n * `<prefix>\\node_modules\\tenjin-cli` on win32), while a project-local one sits\n * under the project root, which by definition has a package.json. That parent is\n * the whole test, which is why it holds for homebrew, nvm, volta and a\n * user-set `npm config prefix` alike without this code enumerating any of them.\n */\nexport function isGlobalTree(moduleDir: string): boolean {\n const segs = moduleDir.split(sep);\n const i = segs.lastIndexOf('node_modules');\n if (i <= 0) return false;\n return !existsSync(join(segs.slice(0, i).join(sep), 'package.json'));\n}\n\n/**\n * Which package manager owns this install, read off the on-disk path. Node\n * resolved the bin symlink before loading us, so the segments name the real\n * store: pnpm's virtual store keeps a literal `.pnpm` segment (or\n * `pnpm/global` for older layouts), bun installs under `.bun`, yarn under\n * `.yarn` or `yarn/global`. Everything else is treated as npm's tree; that\n * covers nvm and volta, both of which route `npm i -g` correctly.\n */\nexport function classifyManager(moduleDir: string): Delegable | 'yarn' {\n const segs = moduleDir.split(sep);\n const pair = (a: string, b: string): boolean => segs.includes(a) && segs.includes(b);\n if (segs.includes('.pnpm') || pair('pnpm', 'global')) return 'pnpm';\n if (segs.includes('.bun')) return 'bun';\n if (segs.includes('.yarn') || pair('yarn', 'global')) return 'yarn';\n return 'npm';\n}\n\n/**\n * How to perform a global install with each manager we delegate to.\n *\n * `scriptSuffixes` is what a PATH shim may resolve to that Node can run\n * directly, which is how win32 is served without a shell: npm and pnpm ship as\n * JS, so the child becomes `node <script>`. An empty list means the binary is\n * native (bun), where spawning it by name already works on every platform.\n */\nexport const MANAGERS: Record<\n Delegable,\n {\n bin: string;\n scriptSuffixes: readonly string[];\n /** Ships beside the running node, as npm does inside the Node distribution. */\n besideNode: boolean;\n args: (spec: string) => string[];\n manual: (spec: string) => string;\n }\n> = {\n npm: {\n bin: 'npm',\n scriptSuffixes: ['npm-cli.js'],\n besideNode: true,\n args: (spec) => ['install', '-g', '--ignore-scripts', spec],\n manual: (spec) => `npm i -g ${spec}`,\n },\n pnpm: {\n bin: 'pnpm',\n // corepack's shim resolves to `pnpm.js`, a standalone install to `pnpm.cjs`.\n scriptSuffixes: ['.cjs', '.js'],\n besideNode: false,\n args: (spec) => ['add', '-g', '--ignore-scripts', spec],\n manual: (spec) => `pnpm add -g ${spec}`,\n },\n bun: {\n bin: 'bun',\n scriptSuffixes: [],\n besideNode: false,\n // No --ignore-scripts: bun's flag surface for it is not stable across the\n // versions in the wild, and an unknown flag would fail the install outright.\n args: (spec) => ['add', '-g', spec],\n manual: (spec) => `bun add -g ${spec}`,\n },\n};\n\n/**\n * npm's own entry script, so the child can be `node npm-cli.js` rather than the\n * `npm` shim.\n *\n * On win32 the shim is `npm.cmd`, which Node refuses to spawn without\n * `shell: true`, and `shell: true` is exactly what this command must not do —\n * it would hand back the argv safety the pinned version buys.\n *\n * Deliberately NOT \"npm ships inside the Node distribution\". That is a property\n * of the installer, not of Node: Homebrew's plain `node` formula keeps only\n * corepack in the keg and puts npm at the brew prefix, so a probe relative to\n * `process.execPath` alone returns null on one of the most common macOS setups.\n * So the layout is searched, not assumed — beside the running binary first\n * (official tarball and installer, nvm, volta, versioned brew kegs), then off\n * PATH, where on POSIX the `npm` shim is itself a symlink to `npm-cli.js` and on\n * win32 `npm.cmd` has `node_modules` beside it. Still null when npm cannot be\n * found at all; the caller then falls back to the bare shim, which works\n * everywhere but win32 and fails closed there into UPDATE_FAILED carrying the\n * manual command.\n */\nexport function resolveNpmCli(\n execPath: string,\n env: NodeJS.ProcessEnv = process.env,\n): string | null {\n return resolveManagerScript('npm', execPath, env);\n}\n\n/**\n * The JS entry script for `manager`, or null when it has none to find (a native\n * binary, or a shim this cannot see through). Null means \"spawn the bare name\",\n * which works everywhere but win32 and fails closed there.\n */\nexport function resolveManagerScript(\n manager: Delegable,\n execPath: string,\n env: NodeJS.ProcessEnv = process.env,\n): string | null {\n const plan = MANAGERS[manager];\n if (plan.scriptSuffixes.length === 0) return null;\n const beside = plan.besideNode ? scriptNear(dirname(execPath), plan.bin) : null;\n return beside ?? scriptOnPath(plan.bin, plan.scriptSuffixes, env);\n}\n\n/** A manager's script relative to a directory holding `node` or its own shim. */\nfunction scriptNear(dir: string, bin: string): string | null {\n const candidates = [\n join(dir, 'node_modules', bin, 'bin', `${bin}-cli.js`),\n join(dir, '..', 'lib', 'node_modules', bin, 'bin', `${bin}-cli.js`),\n ];\n return candidates.find(isFile) ?? null;\n}\n\n/**\n * Walk PATH for the manager's shim and turn it into its script. Probes the\n * PATHEXT extensions on win32: the real file there is `npm.cmd`, never a bare\n * `npm`.\n */\nfunction scriptOnPath(\n bin: string,\n suffixes: readonly string[],\n env: NodeJS.ProcessEnv,\n): string | 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 if (!isFile(join(part, `${bin}${ext}`))) continue;\n // POSIX package managers link the shim straight at the script, which is\n // what makes this layout-independent rather than a longer guess list.\n //\n // The endsWith is a CORRECTNESS check, not a security guard: it asks \"did\n // this symlink land on npm's script or on something else\", and a shim\n // pointed elsewhere returns null, which falls back to spawning that same\n // retargeted shim anyway. PATH poisoning is out of scope by construction —\n // an attacker ahead of npm on PATH owns every tool the user runs, and the\n // pre-existing fallback `spawn('npm', ...)` resolved through the same PATH.\n const real = realpathOrNull(join(part, `${bin}${ext}`));\n if (real !== null && suffixes.some((suffix) => real.endsWith(suffix))) return real;\n const near = scriptNear(part, bin);\n if (near !== null) return near;\n }\n }\n return null;\n}\n\nfunction isFile(p: string): boolean {\n try {\n return statSync(p).isFile();\n } catch {\n return false;\n }\n}\n\nfunction realpathOrNull(p: string): string | null {\n try {\n return realpathSync(p);\n } catch {\n return null;\n }\n}\n"],"mappings":";;;;;;AAAA,SAAS,YAAY,cAAc,gBAAgB;AACnD,SAAS,WAAW,SAAS,MAAM,WAAW;AAkDvC,IAAM,WAA+B;AAAA,EAC1C;AAAA,IACE,MAAM;AAAA,IACN,OAAO,MACL,IAAI,SAAS,WAAW,gEAAgE;AAAA,MACtF,KAAK;AAAA,IACP,CAAC;AAAA,IACH,cAAc;AAAA,IACd,gBAAgB;AAAA,EAClB;AAAA,EACA;AAAA,IACE,MAAM,CAAC,cAAc,UAAU,MAAM,GAAG,EAAE,SAAS,MAAM;AAAA,IACzD,OAAO,CAAC,SACN,IAAI,SAAS,WAAW,4DAA4D;AAAA;AAAA;AAAA,MAGlF,KAAK,8DAA8D,IAAI;AAAA,IACzE,CAAC;AAAA,IACH,cAAc;AAAA,IACd,gBAAgB;AAAA,EAClB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKE,MAAM,CAAC,cAAc,gBAAgB,SAAS,MAAM;AAAA,IACpD,OAAO,CAAC,SACN,IAAI;AAAA,MACF;AAAA,MACA;AAAA,MACA,EAAE,KAAK,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;AAAA,IACrD,KAAK,KAAK,MAAM,OAAO,gBAAgB,KAAK,OAAO,GAAG,GAAG,SAAS;AAAA,EACpE;AACA,SAAO,WAAW,KAAK,MAAM,KAAK;AACpC;AAOA,SAAS,aACP,KACA,UACA,KACe;AACf,QAAM,OACJ,QAAQ,aAAa,UACjB,CAAC,IAAI,IAAI,IAAI,WAAW,uBAAuB,MAAM,GAAG,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,IACrF,CAAC,EAAE;AACT,aAAW,SAAS,IAAI,QAAQ,IAAI,MAAM,SAAS,GAAG;AACpD,QAAI,KAAK,WAAW,EAAG;AACvB,eAAW,OAAO,MAAM;AACtB,UAAI,CAAC,OAAO,KAAK,MAAM,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC,EAAG;AAUzC,YAAM,OAAO,eAAe,KAAK,MAAM,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC;AACtD,UAAI,SAAS,QAAQ,SAAS,KAAK,CAAC,WAAW,KAAK,SAAS,MAAM,CAAC,EAAG,QAAO;AAC9E,YAAM,OAAO,WAAW,MAAM,GAAG;AACjC,UAAI,SAAS,KAAM,QAAO;AAAA,IAC5B;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,OAAO,GAAoB;AAClC,MAAI;AACF,WAAO,SAAS,CAAC,EAAE,OAAO;AAAA,EAC5B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,eAAe,GAA0B;AAChD,MAAI;AACF,WAAO,aAAa,CAAC;AAAA,EACvB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,177 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ atomicToUsd,
4
+ evaluateSpendPolicy,
5
+ formatUsdDisplay
6
+ } from "./chunk-MEZJ3I63.js";
7
+ import {
8
+ WALLET_REASONS,
9
+ agentFixFor
10
+ } from "./chunk-RFZA7PSM.js";
11
+ import {
12
+ DEPOSIT_DEFERRED,
13
+ NO_PAYER,
14
+ TOPPING_UP,
15
+ TOP_UP_UNAVAILABLE
16
+ } from "./chunk-ZEYA2WWX.js";
17
+
18
+ // src/router/fee.ts
19
+ import { join } from "node:path";
20
+ var ROUTING_FEE_CEILING_ATOMIC = 250000n;
21
+ var LEGACY_ROUTING_QUOTE_ATOMIC = 3000n;
22
+ var FEE_ABOVE_CEILING = "fee_above_ceiling";
23
+ var CHANNEL_DEPOSIT_ATOMIC = 50000n;
24
+ var MAX_CHANNEL_DEPOSIT_ATOMIC = 250000n;
25
+ var ROUTING_WALLET_RESERVE_ATOMIC = 10000n;
26
+ var SMALL_CHANNEL_DEPOSIT_ATOMIC = 10000n;
27
+ var SMALL_WALLET_THRESHOLD_ATOMIC = 100000n;
28
+ function routingDepositAtomic(o) {
29
+ const least = (a, b) => b < a ? b : a;
30
+ const target = least(least(o.suggestedAtomic, o.perCallAtomic), o.maxAtomic);
31
+ if (o.balanceAtomic === null) return target;
32
+ if (o.balanceAtomic >= SMALL_WALLET_THRESHOLD_ATOMIC && o.balanceAtomic >= target + ROUTING_WALLET_RESERVE_ATOMIC)
33
+ return target;
34
+ const smaller = least(
35
+ target,
36
+ o.neededAtomic > SMALL_CHANNEL_DEPOSIT_ATOMIC ? o.neededAtomic : SMALL_CHANNEL_DEPOSIT_ATOMIC
37
+ );
38
+ const available = o.balanceAtomic - ROUTING_WALLET_RESERVE_ATOMIC;
39
+ const amount = least(smaller, available);
40
+ return amount > 0n && amount >= o.neededAtomic ? amount : 0n;
41
+ }
42
+ var SUGGESTED_FUND_USD = "5";
43
+ var FUNDING_LINE = `Add funds with \`tenjin fund ${SUGGESTED_FUND_USD}\`, or send USDC from a crypto wallet with \`tenjin fund --usdc\`.`;
44
+ var FUND_COMMAND_LINE = "Add funds with `tenjin fund`, or ask your agent.";
45
+ var NEED_PRICE_MAX_ATOMIC = 100000000n;
46
+ var NEED_LABEL_MAX = 60;
47
+ function fundForCommand(label, priceAtomic) {
48
+ const wholePrice = (priceAtomic + 999999n) / 1000000n;
49
+ const amount = wholePrice > BigInt(SUGGESTED_FUND_USD) ? wholePrice.toString() : SUGGESTED_FUND_USD;
50
+ const safe = [
51
+ ...label.replace(/[^\p{L}\p{N} .,:'()/+&-]/gu, " ").replace(/\s+/g, " ").trim()
52
+ ].slice(0, NEED_LABEL_MAX).join("").trim();
53
+ const named = safe.length > 0 && priceAtomic > 0n && priceAtomic <= NEED_PRICE_MAX_ATOMIC ? ` --for "${safe}" --price ${atomicToUsd(priceAtomic.toString())}` : "";
54
+ return `tenjin fund ${amount}${named}`;
55
+ }
56
+ function shortOfFunds(o) {
57
+ const subject = o.label !== void 0 ? `This ${o.label}` : `A call to ${o.provider}`;
58
+ return `${subject} costs $${usd(o.priceAtomic)}, more than your Tenjin balance. Ask the person once to add funds; on yes, run \`${fundForCommand(o.label ?? o.provider, o.priceAtomic)}\`.`;
59
+ }
60
+ var ROUTING_DEPOSIT_KEY = "routing-deposit:";
61
+ var REFUSED = {
62
+ not_allowlisted: "not_allowlisted",
63
+ session_budget_exceeded: "budget_reached",
64
+ above_auto_spend: "limit_below_deposit"
65
+ };
66
+ function refusedWhy(reason) {
67
+ return REFUSED[reason] ?? reason;
68
+ }
69
+ function feeRefusal(policy, host, feeAtomic) {
70
+ const evaluation = evaluateSpendPolicy(
71
+ { ...policy, sessionBudgetAtomic: policy.sessionBudgetAtomic === 0n ? 0n : null },
72
+ { mode: "automatic", amountAtomic: feeAtomic, creator: host, sessionSpentAtomic: 0n }
73
+ );
74
+ return evaluation.decision === "allow" ? null : refusedWhy(evaluation.reason);
75
+ }
76
+ var WALLET_UNPAID = Object.fromEntries(
77
+ Object.entries(WALLET_REASONS).map(([key, { reason, fix }]) => [key, { reason, fix }])
78
+ );
79
+ var UNPAID = {
80
+ wallet_low: {
81
+ // The least a wallet routes with ({@link routingDepositAtomic}): the
82
+ // reserve kept for provider payments plus a deposit of one fixed quote,
83
+ // $0.013. A dearer answer needs more, so the line says "at least".
84
+ reason: `the wallet holds less than Tenjin needs to set aside for routing (at least $${usd(ROUTING_WALLET_RESERVE_ATOMIC + LEGACY_ROUTING_QUOTE_ATOMIC)})`,
85
+ fix: `Add funds with \`tenjin fund ${SUGGESTED_FUND_USD}\`.`
86
+ },
87
+ ...WALLET_UNPAID,
88
+ // A SPEND LIMIT IS NEVER A FUNDING PROBLEM: adding money cannot help, so
89
+ // these never point at checkout. They say the balance is not the cause and
90
+ // name the setting that is.
91
+ limit_below_deposit: {
92
+ reason: "the per-call spend limit cannot cover the routing fee or its deposit",
93
+ fix: "Your balance is fine; this is the per-call limit. Choose an amount that covers the routing fee or its deposit with `tenjin config set maxAutoSpend <usd>`."
94
+ },
95
+ budget_reached: {
96
+ reason: "today's spend limit is used up",
97
+ fix: "Your balance is fine, and adding funds would not help. The limit frees up as the 24 hours pass, or raise it with `tenjin config set sessionBudget <usd>`."
98
+ },
99
+ not_allowlisted: {
100
+ reason: "allowlistCreators does not include the router",
101
+ fix: "Run `tenjin doctor`."
102
+ },
103
+ payment_failed: {
104
+ reason: "the routing payment failed",
105
+ fix: "Run `tenjin doctor`."
106
+ },
107
+ [FEE_ABOVE_CEILING]: {
108
+ reason: "the router asks more per call than this install agreed to pay",
109
+ fix: "Your usual tools still work."
110
+ },
111
+ [NO_PAYER]: {
112
+ reason: "the router charges it, and this session cannot pay it",
113
+ fix: "Run `tenjin doctor`."
114
+ }
115
+ };
116
+ var NO_FAULT = /* @__PURE__ */ new Set([
117
+ "channel_busy",
118
+ "busy",
119
+ "no_call",
120
+ "deadline_after_payment_sent",
121
+ "unlock_timeout",
122
+ "balance_unreadable",
123
+ TOPPING_UP,
124
+ DEPOSIT_DEFERRED,
125
+ TOP_UP_UNAVAILABLE
126
+ ]);
127
+ function unpaid(why) {
128
+ if (NO_FAULT.has(why)) return null;
129
+ return UNPAID[why] ?? UNPAID["payment_failed"];
130
+ }
131
+ function depositSentence(amountAtomic) {
132
+ return `Tenjin set aside $${usd(amountAtomic)} for routing. It counts toward your spend limits.`;
133
+ }
134
+ var WALLET_LOW_SENTENCE = "Your balance was too low for this routing fee. Free routing still works.";
135
+ var PERSON_FIX = {
136
+ limit_below_deposit: "Your balance is fine; this is the per-call limit. Ask your agent to raise it.",
137
+ budget_reached: "Your balance is fine, and adding funds would not help. The limit frees up as the 24 hours pass, or ask your agent to raise it."
138
+ };
139
+ function unpaidSentence(why, reader = "person", quotedAtomic) {
140
+ const u = unpaid(why);
141
+ if (u === null) return null;
142
+ if (why === "wallet_low") return WALLET_LOW_SENTENCE;
143
+ const fix = reader === "agent" ? agentFixFor(why, u.fix) : PERSON_FIX[why] ?? u.fix;
144
+ const reason = why === FEE_ABOVE_CEILING && quotedAtomic !== void 0 ? `the router quoted $${usd(quotedAtomic)} a call, more than this install agreed to pay` : u.reason;
145
+ return `Tenjin could not pay the routing fee (${reason}). Free routing still works. ${fix}`;
146
+ }
147
+ var ADDRESS_RE = /^0x[0-9a-f]{40}$/;
148
+ function payerDir(dataDir, payer) {
149
+ const name = payer.toLowerCase();
150
+ if (!ADDRESS_RE.test(name)) throw new Error(`not a wallet address: ${payer}`);
151
+ return join(dataDir, "router", "fee", name);
152
+ }
153
+ function usd(atomic) {
154
+ return formatUsdDisplay(atomic.toString());
155
+ }
156
+
157
+ export {
158
+ ROUTING_FEE_CEILING_ATOMIC,
159
+ LEGACY_ROUTING_QUOTE_ATOMIC,
160
+ FEE_ABOVE_CEILING,
161
+ CHANNEL_DEPOSIT_ATOMIC,
162
+ MAX_CHANNEL_DEPOSIT_ATOMIC,
163
+ routingDepositAtomic,
164
+ SUGGESTED_FUND_USD,
165
+ FUNDING_LINE,
166
+ FUND_COMMAND_LINE,
167
+ shortOfFunds,
168
+ ROUTING_DEPOSIT_KEY,
169
+ refusedWhy,
170
+ feeRefusal,
171
+ unpaid,
172
+ depositSentence,
173
+ unpaidSentence,
174
+ payerDir,
175
+ usd
176
+ };
177
+ //# sourceMappingURL=chunk-HZKANST2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/router/fee.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { atomicToUsd, formatUsdDisplay } from '../lib/money';\nimport { evaluateSpendPolicy, type PolicyReason, type SpendPolicy } from '../lib/policy';\nimport {\n DEPOSIT_DEFERRED,\n NO_PAYER,\n TOP_UP_UNAVAILABLE,\n TOPPING_UP,\n type DecisionRoute,\n} from './decision';\nimport { agentFixFor, WALLET_REASONS } from './wallet-reasons';\n\n/**\n * THE ROUTING FEE, WITHOUT ANYTHING THAT PAYS. Every routing call goes to the\n * paid route and pays the fee its 402 quotes over x402 `batch-settlement`, and\n * the stock SDK client in `tenjin mcp` does all of it (`routing-payer.ts`).\n * Nothing else pays it: a call without that payer is skipped when the route\n * asks for it.\n *\n * THE SERVER QUOTES, THIS CLIENT CAPS. The fee is the server's to set, so no\n * fee amount lives here: only the ceiling a quote must not pass, like\n * EIP-1559's `maxFeePerGas`, and the spend limits that bound it beside that.\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\n/**\n * THE ROUTING FEE CEILING, atomic USDC ($0.25): the most one routing answer\n * pays, and the most one routing deposit holds ({@link MAX_CHANNEL_DEPOSIT_ATOMIC}).\n * The router quotes each answer its own fee, usually far below this; a quote\n * at or below it is paid inside the spend limits, and one above it is not\n * paid at all ({@link FEE_ABOVE_CEILING}). It is a limit, not a price.\n */\nexport const ROUTING_FEE_CEILING_ATOMIC = 250_000n;\n/**\n * THE ROUTER'S FIXED QUOTE ($0.003), which it still offers beside a per-answer\n * quote for the CLIs released before per-answer quotes. This client pays it\n * only when it is the 402's only routing offer (`routing-quote.ts`). An\n * estimate with no 402 in hand (doctor's funded-enough check, the fund line\n * under an empty wallet) sizes from it.\n */\nexport const LEGACY_ROUTING_QUOTE_ATOMIC = 3_000n;\n/** The skip reason for a quote above {@link ROUTING_FEE_CEILING_ATOMIC}. */\nexport const FEE_ABOVE_CEILING = 'fee_above_ceiling';\n/** The deposit hint ($0.05) when a 402 carries no `extra.minDeposit`: the\n * production server's own, and the one doctor sizes from with no 402. */\nexport const CHANNEL_DEPOSIT_ATOMIC = 50_000n;\n/** Tenjin's maximum deposit per top-up ($0.25), independent of the SDK's larger bound. */\nexport const MAX_CHANNEL_DEPOSIT_ATOMIC = 250_000n;\n/** Keep this much USDC outside the routing channel for provider payments. */\nexport const ROUTING_WALLET_RESERVE_ATOMIC = 10_000n;\n/** Buffered top-up for a wallet that cannot fit the normal SDK target. */\nexport const SMALL_CHANNEL_DEPOSIT_ATOMIC = 10_000n;\n/** Below ten cents liquid, use the small deposit even when the buffer fits. */\nexport const SMALL_WALLET_THRESHOLD_ATOMIC = 100_000n;\n\n/** Use the SDK target when it fits at ten cents or more; otherwise use the\n * small target, raised for a larger voucher deficit. Shrink to the balance\n * above the reserve; zero refuses less than the deficit. Null is doctor's estimate. */\nexport function routingDepositAtomic(o: {\n suggestedAtomic: bigint;\n neededAtomic: bigint;\n balanceAtomic: bigint | null;\n perCallAtomic: bigint;\n maxAtomic: bigint;\n}): bigint {\n const least = (a: bigint, b: bigint) => (b < a ? b : a);\n const target = least(least(o.suggestedAtomic, o.perCallAtomic), o.maxAtomic);\n if (o.balanceAtomic === null) return target;\n if (\n o.balanceAtomic >= SMALL_WALLET_THRESHOLD_ATOMIC &&\n o.balanceAtomic >= target + ROUTING_WALLET_RESERVE_ATOMIC\n )\n return target;\n const smaller = least(\n target,\n o.neededAtomic > SMALL_CHANNEL_DEPOSIT_ATOMIC ? o.neededAtomic : SMALL_CHANNEL_DEPOSIT_ATOMIC,\n );\n const available = o.balanceAtomic - ROUTING_WALLET_RESERVE_ATOMIC;\n const amount = least(smaller, available);\n return amount > 0n && amount >= o.neededAtomic ? amount : 0n;\n}\n\n/**\n * The top-up every \"add funds\" hint names, in USD: the checkout's Apple\n * Pay and Google Pay minimum, which covers the routing deposit and a few\n * hundred lookups. `tenjin fund` sends it to the checkout as a preset.\n */\nexport const SUGGESTED_FUND_USD = '5';\n/** The funding line a new wallet is told, after `tenjin wallet create`. */\nexport const FUNDING_LINE = `Add funds with \\`tenjin fund ${SUGGESTED_FUND_USD}\\`, or send USDC from a crypto wallet with \\`tenjin fund --usdc\\`.`;\n/** The funding line under a balance of exactly $0, in `tenjin balance` and `tenjin status`. */\nexport const FUND_COMMAND_LINE = 'Add funds with `tenjin fund`, or ask your agent.';\n\n/** The most a fund link's `need` may name as its price (the link route's bound). */\nconst NEED_PRICE_MAX_ATOMIC = 100_000_000n;\n/** A `--for` label: the link route takes 1 to 60 characters. */\nconst NEED_LABEL_MAX = 60;\n\n/**\n * THE COMMAND THAT OPENS CHECKOUT FOR ONE WAITING CALL: `tenjin fund 5 --for\n * \"X post read\" --price 0.006`, so the checkout page says what the money is\n * for. The amount is the suggested top-up, or the price in whole dollars when\n * that is more. The label keeps only characters that are inert inside double\n * quotes in any shell.\n */\nexport function fundForCommand(label: string, priceAtomic: bigint): string {\n const wholePrice = (priceAtomic + 999_999n) / 1_000_000n;\n const amount =\n wholePrice > BigInt(SUGGESTED_FUND_USD) ? wholePrice.toString() : SUGGESTED_FUND_USD;\n const safe = [\n ...label\n .replace(/[^\\p{L}\\p{N} .,:'()/+&-]/gu, ' ')\n .replace(/\\s+/g, ' ')\n .trim(),\n ]\n .slice(0, NEED_LABEL_MAX)\n .join('')\n .trim();\n const named =\n safe.length > 0 && priceAtomic > 0n && priceAtomic <= NEED_PRICE_MAX_ATOMIC\n ? ` --for \"${safe}\" --price ${atomicToUsd(priceAtomic.toString())}`\n : '';\n return `tenjin fund ${amount}${named}`;\n}\n\n/**\n * A PAID CALL REFUSED FOR LOW FUNDS, said with what the money is for: \"This X\n * post read costs $0.006, more than your Tenjin balance. Ask the person once\n * to add funds; on yes, run `tenjin fund 5 --for \"X post read\" --price\n * 0.006`.\" That command opens checkout with the call named on the page. A\n * service with no display label is named by its provider (\"A call to\n * BlockRun costs …\").\n */\nexport function shortOfFunds(o: {\n label?: string | undefined;\n provider: string;\n priceAtomic: bigint;\n}): string {\n const subject = o.label !== undefined ? `This ${o.label}` : `A call to ${o.provider}`;\n return `${subject} costs $${usd(o.priceAtomic)}, more than your Tenjin balance. Ask the person once to add funds; on yes, run \\`${fundForCommand(o.label ?? o.provider, o.priceAtomic)}\\`.`;\n}\n/** The spend ledger key a deposit's exposure is recorded under, before its id. */\nexport const ROUTING_DEPOSIT_KEY = 'routing-deposit:';\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, at the amount quoted: the per-call\n * limit, the creator allowlist (the router's host) and an explicit zero daily\n * limit. It is never refused for the day's running total, which the deposit\n * already consumed. Null when those checks allow the fee.\n */\nexport function feeRefusal(policy: SpendPolicy, host: string, feeAtomic: bigint): string | null {\n const evaluation = evaluateSpendPolicy(\n { ...policy, sessionBudgetAtomic: policy.sessionBudgetAtomic === 0n ? 0n : null },\n { mode: 'automatic', amountAtomic: feeAtomic, creator: host, sessionSpentAtomic: 0n },\n );\n return evaluation.decision === 'allow' ? null : refusedWhy(evaluation.reason);\n}\n\n/** The payer's route for a call to the router at `baseUrl`. `tenjin mcp`\n * passes its payer's; absent, a call goes unpaid. */\nexport type RouteFor = (baseUrl: string) => DecisionRoute;\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 `no_payer`, when the route asked for the fee and\n * nothing could pay it). Null for a reason that is no fault and needs no\n * fix: another session's call on the channel, or a call queued past its own\n * budget, or a payment still out when the call's\n * budget ran out (it finishes in the background), or an unlock that did not\n * finish inside the call's budget (it keeps running, and the next call gets\n * its answer), or a balance read before a deposit that failed or ran out of\n * time (nothing was signed or sent), or a deposit the background top-up has\n * not made yet.\n *\n * THE WALLET'S OWN REASONS ARE `WALLET_REASONS`, spread in rather than written\n * twice, so a notice names the same cause in the same words as doctor. They\n * carry the PERSON `fix`, never `agentFix`: this sentence goes in the hook's\n * `systemMessage`, which the harness shows the person (B1, decision 15), and a\n * fix that names `tenjin wallet repair` says it asks in their own terminal.\n */\nconst WALLET_UNPAID: Record<string, { reason: string; fix: string }> = Object.fromEntries(\n Object.entries(WALLET_REASONS).map(([key, { reason, fix }]) => [key, { reason, fix }]),\n);\nconst UNPAID: Record<string, { reason: string; fix: string }> = {\n wallet_low: {\n // The least a wallet routes with ({@link routingDepositAtomic}): the\n // reserve kept for provider payments plus a deposit of one fixed quote,\n // $0.013. A dearer answer needs more, so the line says \"at least\".\n reason: `the wallet holds less than Tenjin needs to set aside for routing (at least $${usd(ROUTING_WALLET_RESERVE_ATOMIC + LEGACY_ROUTING_QUOTE_ATOMIC)})`,\n fix: `Add funds with \\`tenjin fund ${SUGGESTED_FUND_USD}\\`.`,\n },\n ...WALLET_UNPAID,\n // A SPEND LIMIT IS NEVER A FUNDING PROBLEM: adding money cannot help, so\n // these never point at checkout. They say the balance is not the cause and\n // name the setting that is.\n limit_below_deposit: {\n reason: 'the per-call spend limit cannot cover the routing fee or its deposit',\n fix: 'Your balance is fine; this is the per-call limit. Choose an amount that covers the routing fee or its deposit with `tenjin config set maxAutoSpend <usd>`.',\n },\n budget_reached: {\n reason: \"today's spend limit is used up\",\n fix: 'Your balance is fine, and adding funds would not help. The limit frees up as the 24 hours pass, or raise it with `tenjin config set sessionBudget <usd>`.',\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_ABOVE_CEILING]: {\n reason: 'the router asks more per call than this install agreed to pay',\n fix: 'Your usual tools still work.',\n },\n [NO_PAYER]: {\n reason: 'the router charges it, and this session cannot pay it',\n fix: 'Run `tenjin doctor`.',\n },\n};\nconst NO_FAULT = new Set([\n 'channel_busy',\n 'busy',\n 'no_call',\n 'deadline_after_payment_sent',\n 'unlock_timeout',\n 'balance_unreadable',\n TOPPING_UP,\n DEPOSIT_DEFERRED,\n TOP_UP_UNAVAILABLE,\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/**\n * The deposit notice, on the next hook after a background top-up or on the\n * routing call that carried it. Each fee is the router's own quote, and the\n * deposit counts toward spend limits once, when it is sent ({@link feeRefusal}).\n */\nexport function depositSentence(amountAtomic: bigint): string {\n return `Tenjin set aside $${usd(amountAtomic)} for routing. It counts toward your spend limits.`;\n}\n\n/**\n * What a call the wallet could not fund says. Routing has not stopped: an\n * answer that needs no payment can still come, so the line says only that\n * this answer went unpaid, and opens no checkout (explicit balance, payment\n * and doctor results keep `unpaid().fix`).\n */\nexport const WALLET_LOW_SENTENCE =\n 'Your balance was too low for this routing fee. Free routing still works.';\n\n/**\n * The one line the user sees, once per session and reason, when a call was not\n * paid. Its reader picks the fix (B1): the person's by default; for the model\n * (the `request` tool's text) a wallet unlock reason's `agentFix`, which asks\n * the person to act and never for the passphrase, and any other reason's own.\n * A quote above the ceiling names the price quoted, when the payer read one.\n */\n/**\n * A spend limit, as the person reads it in chat: their agent raises it, so they\n * never get a command they did not type. The agent reader keeps the command.\n */\nconst PERSON_FIX: Partial<Record<string, string>> = {\n limit_below_deposit:\n 'Your balance is fine; this is the per-call limit. Ask your agent to raise it.',\n budget_reached:\n 'Your balance is fine, and adding funds would not help. The limit frees up as the 24 hours pass, or ask your agent to raise it.',\n};\n\nexport function unpaidSentence(\n why: string,\n reader: 'person' | 'agent' = 'person',\n quotedAtomic?: bigint,\n): string | null {\n const u = unpaid(why);\n if (u === null) return null;\n if (why === 'wallet_low') return WALLET_LOW_SENTENCE;\n const fix = reader === 'agent' ? agentFixFor(why, u.fix) : (PERSON_FIX[why] ?? u.fix);\n const reason =\n why === FEE_ABOVE_CEILING && quotedAtomic !== undefined\n ? `the router quoted $${usd(quotedAtomic)} a call, more than this install agreed to pay`\n : u.reason;\n return `Tenjin could not pay the routing fee (${reason}). Free routing still works. ${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"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY;AAkCd,IAAM,6BAA6B;AAQnC,IAAM,8BAA8B;AAEpC,IAAM,oBAAoB;AAG1B,IAAM,yBAAyB;AAE/B,IAAM,6BAA6B;AAEnC,IAAM,gCAAgC;AAEtC,IAAM,+BAA+B;AAErC,IAAM,gCAAgC;AAKtC,SAAS,qBAAqB,GAM1B;AACT,QAAM,QAAQ,CAAC,GAAW,MAAe,IAAI,IAAI,IAAI;AACrD,QAAM,SAAS,MAAM,MAAM,EAAE,iBAAiB,EAAE,aAAa,GAAG,EAAE,SAAS;AAC3E,MAAI,EAAE,kBAAkB,KAAM,QAAO;AACrC,MACE,EAAE,iBAAiB,iCACnB,EAAE,iBAAiB,SAAS;AAE5B,WAAO;AACT,QAAM,UAAU;AAAA,IACd;AAAA,IACA,EAAE,eAAe,+BAA+B,EAAE,eAAe;AAAA,EACnE;AACA,QAAM,YAAY,EAAE,gBAAgB;AACpC,QAAM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AA8C;AAAA,EAClD,qBACE;AAAA,EACF,gBACE;AACJ;AAEO,SAAS,eACd,KACA,SAA6B,UAC7B,cACe;AACf,QAAM,IAAI,OAAO,GAAG;AACpB,MAAI,MAAM,KAAM,QAAO;AACvB,MAAI,QAAQ,aAAc,QAAO;AACjC,QAAM,MAAM,WAAW,UAAU,YAAY,KAAK,EAAE,GAAG,IAAK,WAAW,GAAG,KAAK,EAAE;AACjF,QAAM,SACJ,QAAQ,qBAAqB,iBAAiB,SAC1C,sBAAsB,IAAI,YAAY,CAAC,kDACvC,EAAE;AACR,SAAO,yCAAyC,MAAM,gCAAgC,GAAG;AAC3F;AAEA,IAAM,aAAa;AAIZ,SAAS,SAAS,SAAiB,OAAuB;AAC/D,QAAM,OAAO,MAAM,YAAY;AAC/B,MAAI,CAAC,WAAW,KAAK,IAAI,EAAG,OAAM,IAAI,MAAM,yBAAyB,KAAK,EAAE;AAC5E,SAAO,KAAK,SAAS,UAAU,OAAO,IAAI;AAC5C;AAGO,SAAS,IAAI,QAAwB;AAC1C,SAAO,iBAAiB,OAAO,SAAS,CAAC;AAC3C;","names":[]}
@@ -3,7 +3,13 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
3
3
  // src/router/hook-tool.ts
4
4
  var HOOK_KINDS = ["prompt", "native", "shortfall", "agent", "ask", "answer"];
5
5
  var HOOK_TOOL = "hook";
6
- var COMMON = ["hook_event_name", "session_id", "transcript_path", "cwd"];
6
+ var COMMON = [
7
+ "hook_event_name",
8
+ "session_id",
9
+ "transcript_path",
10
+ "cwd",
11
+ "permission_mode"
12
+ ];
7
13
  var CALL = ["tool_name", "tool_input", "tool_use_id", "agent_id", "agent_type"];
8
14
  var FIELDS = {
9
15
  prompt: [...COMMON, "prompt"],
@@ -81,4 +87,4 @@ export {
81
87
  CODEX_HOOK_TOOL_FIELDS,
82
88
  codexEventFromToolInput
83
89
  };
84
- //# sourceMappingURL=chunk-UUGOUOVT.js.map
90
+ //# sourceMappingURL=chunk-I557SAOM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/router/hook-tool.ts"],"sourcesContent":["/**\n * THE HOOK EVENT, CARRIED BY AN `mcp_tool` ENTRY. Claude Code calls the `hook`\n * tool of the session's own `tenjin mcp` for each routing leg, with the event's\n * fields substituted into the entry's `input` (`${session_id}` and so on): a\n * string field arrives as written, an object one (`tool_input`,\n * `tool_response`) as its JSON text, a boolean as `true` or `false`, and a\n * field the event lacks as an empty string. This turns that back into the\n * event the handlers already read, and spells the `input` `install` writes.\n */\n\n/** The routing legs, one per hook entry `install` writes. */\nexport const HOOK_KINDS = ['prompt', 'native', 'shortfall', 'agent', 'ask', 'answer'] as const;\nexport type HookKind = (typeof HOOK_KINDS)[number];\n\n/** The tool `tenjin mcp` registers for the hook entries. */\nexport const HOOK_TOOL = 'hook';\n\n/** The event fields each leg reads, as Claude Code names them. */\nconst COMMON = [\n 'hook_event_name',\n 'session_id',\n 'transcript_path',\n 'cwd',\n 'permission_mode',\n] as const;\nconst CALL = ['tool_name', 'tool_input', 'tool_use_id', 'agent_id', 'agent_type'] as const;\n\nconst FIELDS: Record<HookKind, readonly string[]> = {\n prompt: [...COMMON, 'prompt'],\n native: [...COMMON, ...CALL],\n agent: [...COMMON, ...CALL],\n ask: [...COMMON, ...CALL],\n answer: [...COMMON, ...CALL, 'tool_response'],\n shortfall: [...COMMON, ...CALL, 'tool_response', 'error', 'is_interrupt'],\n};\n\n/** Fields whose value is an object or a boolean, sent as JSON text. */\nconst JSON_FIELDS = new Set(['tool_input', 'tool_response', 'is_interrupt']);\n\n/** The `input` of one leg's `mcp_tool` entry. */\nexport function hookToolInput(kind: HookKind): Record<string, string> {\n return Object.fromEntries([\n ['kind', kind],\n ...FIELDS[kind].map((field) => [field, `\\${${field}}`]),\n ]);\n}\n\n/** Every field any leg sends, for the tool's input schema. */\nexport const HOOK_TOOL_FIELDS: readonly string[] = [...new Set(Object.values(FIELDS).flat())];\n\n/**\n * The harness event from the tool's arguments: empty fields dropped (the\n * event did not carry them), the JSON ones parsed back. A JSON field that does\n * not parse is kept as the string it is.\n */\nexport function eventFromToolInput(args: Record<string, unknown>): Record<string, unknown> {\n const event: Record<string, unknown> = {};\n for (const field of HOOK_TOOL_FIELDS) {\n const value = args[field];\n if (typeof value !== 'string' || value.length === 0) continue;\n if (!JSON_FIELDS.has(field)) {\n event[field] = value;\n continue;\n }\n try {\n event[field] = JSON.parse(value) as unknown;\n } catch {\n event[field] = value;\n }\n }\n return event;\n}\n\n/**\n * THE SAME EVENT, CARRIED BY A CODEX `mcp_tool` ENTRY (Codex 0.149 and later).\n * Codex substitutes `${field}` from the event too, with two differences\n * (openai/codex `hooks/src/engine/mcp_runner.rs`): a whole placeholder keeps\n * the field's JSON type, so `tool_input` arrives as an object and a null\n * `transcript_path` as null; and a field the event lacks fails the hook. So\n * each leg names only the fields Codex always sends for its event, and the\n * optional `agent_id` is never one of them: the call's `threadId` metadata\n * tells a subagent's leg apart instead (`admitCodexHookEvent`).\n */\nexport const CODEX_HOOK_KINDS = ['prompt', 'native', 'shortfall'] as const;\nexport type CodexHookKind = (typeof CODEX_HOOK_KINDS)[number];\n\nconst CODEX_COMMON = [\n 'hook_event_name',\n 'session_id',\n 'turn_id',\n 'transcript_path',\n 'cwd',\n] as const;\nconst CODEX_CALL = ['tool_name', 'tool_input', 'tool_use_id'] as const;\n\nconst CODEX_FIELDS: Record<CodexHookKind, readonly string[]> = {\n prompt: [...CODEX_COMMON, 'prompt'],\n native: [...CODEX_COMMON, ...CODEX_CALL],\n shortfall: [...CODEX_COMMON, ...CODEX_CALL, 'tool_response'],\n};\n\n/** The `input` of one Codex leg's `mcp_tool` entry. */\nexport function codexHookToolInput(kind: CodexHookKind): Record<string, string> {\n return Object.fromEntries([\n ['kind', kind],\n ...CODEX_FIELDS[kind].map((field) => [field, `\\${${field}}`]),\n ]);\n}\n\n/** Every field any Codex leg sends, for the tool's input schema. */\nexport const CODEX_HOOK_TOOL_FIELDS: readonly string[] = [\n ...new Set(Object.values(CODEX_FIELDS).flat()),\n];\n\n/** The Codex event from the tool's arguments, each field as Codex typed it; nulls dropped. */\nexport function codexEventFromToolInput(args: Record<string, unknown>): Record<string, unknown> {\n const event: Record<string, unknown> = {};\n for (const field of CODEX_HOOK_TOOL_FIELDS) {\n const value = args[field];\n if (value !== undefined && value !== null) event[field] = value;\n }\n return event;\n}\n"],"mappings":";;;AAWO,IAAM,aAAa,CAAC,UAAU,UAAU,aAAa,SAAS,OAAO,QAAQ;AAI7E,IAAM,YAAY;AAGzB,IAAM,SAAS;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,IAAM,OAAO,CAAC,aAAa,cAAc,eAAe,YAAY,YAAY;AAEhF,IAAM,SAA8C;AAAA,EAClD,QAAQ,CAAC,GAAG,QAAQ,QAAQ;AAAA,EAC5B,QAAQ,CAAC,GAAG,QAAQ,GAAG,IAAI;AAAA,EAC3B,OAAO,CAAC,GAAG,QAAQ,GAAG,IAAI;AAAA,EAC1B,KAAK,CAAC,GAAG,QAAQ,GAAG,IAAI;AAAA,EACxB,QAAQ,CAAC,GAAG,QAAQ,GAAG,MAAM,eAAe;AAAA,EAC5C,WAAW,CAAC,GAAG,QAAQ,GAAG,MAAM,iBAAiB,SAAS,cAAc;AAC1E;AAGA,IAAM,cAAc,oBAAI,IAAI,CAAC,cAAc,iBAAiB,cAAc,CAAC;AAGpE,SAAS,cAAc,MAAwC;AACpE,SAAO,OAAO,YAAY;AAAA,IACxB,CAAC,QAAQ,IAAI;AAAA,IACb,GAAG,OAAO,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,OAAO,MAAM,KAAK,GAAG,CAAC;AAAA,EACxD,CAAC;AACH;AAGO,IAAM,mBAAsC,CAAC,GAAG,IAAI,IAAI,OAAO,OAAO,MAAM,EAAE,KAAK,CAAC,CAAC;AAOrF,SAAS,mBAAmB,MAAwD;AACzF,QAAM,QAAiC,CAAC;AACxC,aAAW,SAAS,kBA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from "./chunk-7V25UAQO.js";
13
13
  import {
14
14
  InvalidAddressError,
15
15
  concatHex,
@@ -20,10 +20,10 @@ import {
20
20
  hexToNumber,
21
21
  isAddress,
22
22
  toHex
23
- } from "./chunk-2GP3HRYK.js";
23
+ } from "./chunk-INSIW65E.js";
24
24
  import {
25
25
  USDC_ADDRESS
26
- } from "./chunk-WXA2BWTE.js";
26
+ } from "./chunk-ZCT5DJ3G.js";
27
27
 
28
28
  // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.6.7/node_modules/viem/_esm/op-stack/contracts.js
29
29
  var contracts = {
@@ -199,9 +199,11 @@ var basePreconf = /* @__PURE__ */ defineChain({
199
199
 
200
200
  // src/lib/usdc.ts
201
201
  var USDC_ADDRESS2 = USDC_ADDRESS;
202
- var USDC_DECIMALS = 6;
203
202
  async function getUsdcBalance(address, rpcUrl) {
204
- const client = createPublicClient({ chain: base, transport: http(rpcUrl) });
203
+ const client = createPublicClient({
204
+ chain: base,
205
+ transport: http(rpcUrl, { timeout: 2e3, retryCount: 0 })
206
+ });
205
207
  return client.readContract({
206
208
  address: USDC_ADDRESS2,
207
209
  abi: erc20Abi,
@@ -308,7 +310,6 @@ function assertUnderCap(field, value, cap) {
308
310
 
309
311
  export {
310
312
  USDC_ADDRESS2 as USDC_ADDRESS,
311
- USDC_DECIMALS,
312
313
  getUsdcBalance,
313
314
  SEND_GAS_CAP,
314
315
  SEND_MAX_FEE_PER_GAS_CAP,
@@ -319,4 +320,4 @@ export {
319
320
  prepareUsdcSend,
320
321
  broadcastUsdcSend
321
322
  };
322
- //# sourceMappingURL=chunk-TC2WZLSC.js.map
323
+ //# sourceMappingURL=chunk-IGLWLH73.js.map