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
@@ -1,103 +1,123 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
2
  import {
3
- isPublicAddress
4
- } from "./chunk-JKKAIPTU.js";
3
+ claimIgnored,
4
+ hashRefusal,
5
+ noteShown,
6
+ offerScope,
7
+ reportIgnored,
8
+ storeAccountOffer,
9
+ storeChoices,
10
+ storeLabel,
11
+ storeSpecs
12
+ } from "./chunk-HKGUKAQW.js";
5
13
  import {
6
14
  codexRouterEvent,
7
15
  codexSession
8
- } from "./chunk-P3LFTKE7.js";
16
+ } from "./chunk-KFVJYLVL.js";
17
+ import {
18
+ requestToolAccess
19
+ } from "./chunk-LWSSIZOY.js";
20
+ import {
21
+ termsNotice
22
+ } from "./chunk-Y2EXZ47H.js";
23
+ import {
24
+ launchedByPlugin,
25
+ requestToolName
26
+ } from "./chunk-IULCDMVG.js";
27
+ import {
28
+ GATE_TIMEOUT_MS,
29
+ UNPAID_GATE_TIMEOUT_MS
30
+ } from "./chunk-F2KJAJ7T.js";
9
31
  import {
10
32
  UNREACHABLE_BACKOFF_MS,
33
+ canSign,
11
34
  clearRouterMemo,
12
35
  readRouterMemo,
13
- requestToolAccess,
14
36
  writeRouterMemo
15
- } from "./chunk-4USCZ2NI.js";
16
- import {
17
- canPayProvider,
18
- canSign
19
- } from "./chunk-62KNUYWD.js";
37
+ } from "./chunk-64WOMNYR.js";
20
38
  import {
21
39
  readSpendSummary,
22
40
  spentOf
23
- } from "./chunk-SO3XRZPX.js";
41
+ } from "./chunk-HPRVFJPM.js";
24
42
  import {
25
- ChoicesSchema,
26
- OfferSpecSchema,
27
- ROUTER_PATH,
28
- requestDecision
29
- } from "./chunk-LXAYUOXI.js";
43
+ firstNoticeFor,
44
+ noticeCleared,
45
+ noticeFor,
46
+ readWalletFacts,
47
+ sessionServedByPlugin,
48
+ settleCurrent
49
+ } from "./chunk-5F4OB5B3.js";
30
50
  import {
31
- FEE_REQUIRED,
32
51
  depositSentence,
33
- isFeeRequired,
34
52
  unpaidSentence
35
- } from "./chunk-HDPUXS3Z.js";
53
+ } from "./chunk-HZKANST2.js";
36
54
  import {
37
- evaluateSpendPolicy
38
- } from "./chunk-2SNUOHAT.js";
55
+ evaluateSpendPolicy,
56
+ toMoney
57
+ } from "./chunk-MEZJ3I63.js";
39
58
  import {
40
- launchedByPlugin,
41
- requestToolName
42
- } from "./chunk-MPZUYCAP.js";
59
+ readJsonFile,
60
+ writePrivate
61
+ } from "./chunk-ILWCKCOI.js";
62
+ import {
63
+ WALLET_UNLOCKED,
64
+ agentFixFor
65
+ } from "./chunk-RFZA7PSM.js";
43
66
  import {
44
67
  mask
45
- } from "./chunk-IADZOXKN.js";
68
+ } from "./chunk-7SLOTLO7.js";
46
69
  import {
70
+ DECIDED_PREFIX,
47
71
  bindDecision,
48
72
  claimNote,
49
73
  claimRedirect,
74
+ markHandedBack,
50
75
  markNoted,
51
76
  markOffered,
52
77
  newCallId,
53
78
  noteOf,
54
79
  noteSession,
80
+ promptOfferKey,
55
81
  pruneProgress,
56
82
  pruneSessions,
57
83
  redirectClaimed,
58
84
  sessionDir,
59
85
  wasOffered,
60
86
  writeProgress
61
- } from "./chunk-C2Q76BVM.js";
87
+ } from "./chunk-2U7H35IP.js";
62
88
  import {
89
+ accountLacks,
63
90
  routerSettings
64
- } from "./chunk-AGMVASXZ.js";
91
+ } from "./chunk-W2GXIARJ.js";
65
92
  import {
93
+ pathExists,
94
+ projectRoot,
66
95
  resolveContextSettings
67
- } from "./chunk-KM7RY2ZS.js";
68
- import {
69
- parseUsdToAtomic,
70
- toMoney
71
- } from "./chunk-Y527D4TV.js";
72
- import {
73
- noticeCleared,
74
- noticeFor,
75
- readWalletFacts,
76
- sessionServedByPlugin,
77
- settleCurrent
78
- } from "./chunk-NDGZDTSJ.js";
79
- import {
80
- WALLET_UNLOCKED,
81
- agentFixFor
82
- } from "./chunk-BFDQ4WNW.js";
96
+ } from "./chunk-DTEWAVNE.js";
83
97
  import {
84
98
  loadRawConfig,
85
99
  resolveExperimentalBazaar,
86
100
  resolveSettings
87
- } from "./chunk-2M2VPI2E.js";
101
+ } from "./chunk-UIB33QQP.js";
88
102
  import {
89
- rememberingBalanceReader
90
- } from "./chunk-WXA2BWTE.js";
103
+ REQUIRES_UNMET,
104
+ ROUTE_PAID_PATH,
105
+ isAccountSpec,
106
+ parseHookResponse,
107
+ requestDecision
108
+ } from "./chunk-ZEYA2WWX.js";
91
109
  import {
92
- external_exports
93
- } from "./chunk-SNNSAGMT.js";
110
+ isPublicAddress
111
+ } from "./chunk-DIH2G3YG.js";
94
112
  import {
95
- writeFileAtomic,
96
- writeFileAtomicExclusive
97
- } from "./chunk-7WEQQJLG.js";
113
+ sha256Hex
114
+ } from "./chunk-RGCPELQN.js";
115
+ import {
116
+ external_exports
117
+ } from "./chunk-P6YQWIT2.js";
98
118
 
99
119
  // src/router/hooks.ts
100
- import { homedir } from "node:os";
120
+ import { homedir as homedir2 } from "node:os";
101
121
 
102
122
  // src/router/context.ts
103
123
  import { open } from "node:fs/promises";
@@ -153,6 +173,7 @@ var MAX_MESSAGE_CHARS = 16e3;
153
173
  var MAX_TRANSCRIPT_BYTES = 4e6;
154
174
  var MAX_LITERAL_URLS = 8;
155
175
  var MAX_LITERAL_URL_CHARS = 2e3;
176
+ var MAX_QUOTED = 8;
156
177
  var MAX_PENDING_CHARS = 4e3;
157
178
  var MAX_OUTCOME_ERROR_CHARS = 1e3;
158
179
  var MASK_MARGIN = 4096;
@@ -187,6 +208,14 @@ function fit(packet) {
187
208
  }
188
209
  while (next.literalUrls.length > 0 && size(next) > MAX_PACKET_BYTES) {
189
210
  next.literalUrls = next.literalUrls.slice(0, -1);
211
+ const own = next.ownUrls?.filter((url) => next.literalUrls.includes(url)) ?? [];
212
+ if (own.length > 0) next.ownUrls = own;
213
+ else delete next.ownUrls;
214
+ }
215
+ while ((next.current.quoted?.length ?? 0) > 0 && size(next) > MAX_PACKET_BYTES) {
216
+ const quoted = next.current.quoted.slice(0, -1);
217
+ const { role, text } = next.current;
218
+ next.current = quoted.length > 0 ? { role, text, quoted } : { role, text };
190
219
  }
191
220
  while (size(next) > MAX_PACKET_BYTES && next.current.text.length > 1) {
192
221
  const over = size(next) - MAX_PACKET_BYTES;
@@ -195,18 +224,27 @@ function fit(packet) {
195
224
  }
196
225
  return next;
197
226
  }
198
- function seal(packet) {
227
+ function seal(packet, opts = {}) {
199
228
  const pending = packet.pendingCall;
200
229
  const subject = pending === void 0 ? "" : subjectOf(pending);
201
230
  const sealedSubject = maskWithin(subject, MAX_PENDING_CHARS);
202
231
  const bound = (text) => maskWithin(text, MAX_MESSAGE_CHARS).text;
203
232
  const sealedCurrent = maskWithin(packet.current.text, MAX_MESSAGE_CHARS);
204
233
  const current = sealedCurrent.text;
234
+ const quoted = (packet.current.quoted ?? []).slice(0, MAX_QUOTED).map(bound).filter((block) => block.length > 0);
205
235
  const outcome = packet.nativeOutcome;
236
+ const literalUrls = packet.literalUrls.filter((url) => !isLocalTarget(url)).map(mask).filter((url) => url.length <= MAX_LITERAL_URL_CHARS);
237
+ const ownHosts = new Set((opts.ownHosts ?? []).map((host) => host.toLowerCase()));
238
+ const ownUrls = literalUrls.filter((url) => ownHosts.has(hostnameOf(url))).slice(0, MAX_LITERAL_URLS);
206
239
  const sealed = fit({
207
- current: { role: packet.current.role, text: current.length > 0 ? current : "(no task text)" },
240
+ current: {
241
+ role: packet.current.role,
242
+ text: current.length > 0 ? current : "(no task text)",
243
+ ...quoted.length > 0 ? { quoted } : {}
244
+ },
208
245
  history: packet.history.slice(-MAX_HISTORY).map((message) => ({ role: message.role, text: bound(message.text) })).filter((message) => message.text.length > 0),
209
- literalUrls: packet.literalUrls.filter((url) => !isLocalTarget(url)).map(mask).filter((url) => url.length <= MAX_LITERAL_URL_CHARS),
246
+ literalUrls,
247
+ ...ownUrls.length > 0 ? { ownUrls } : {},
210
248
  historyStatus: packet.historyStatus,
211
249
  ...pending === void 0 ? {} : { pendingCall: withSubject(pending, sealedSubject.text) },
212
250
  ...outcome === void 0 ? {} : {
@@ -230,6 +268,13 @@ function maskWithin(text, max) {
230
268
  const limit = window.length < text.length ? Math.min(max, masked.length - MASK_MARGIN) : max;
231
269
  return { text: masked.slice(0, Math.max(0, limit)), changed: masked !== window };
232
270
  }
271
+ function hostnameOf(raw) {
272
+ try {
273
+ return new URL(raw).hostname.toLowerCase();
274
+ } catch {
275
+ return "";
276
+ }
277
+ }
233
278
  var LOCAL_NAME = /(?:^|\.)(?:localhost|local)$/i;
234
279
  function isLocalTarget(raw) {
235
280
  let url;
@@ -243,17 +288,83 @@ function isLocalTarget(raw) {
243
288
  if (LOCAL_NAME.test(host)) return true;
244
289
  return isIP(host) !== 0 && !isPublicAddress(host);
245
290
  }
246
- async function buildPromptPacket(transcriptPath, sessionId, prompt, harness = "claude") {
291
+ async function buildPromptPacket(transcriptPath, sessionId, prompt, harness = "claude", opts = {}) {
247
292
  const trimmed = prompt.trim();
248
293
  const text = trimmed.length > 0 ? trimmed : "(empty prompt)";
249
- const read = await readHistory(transcriptPath, { sessionId, harness });
294
+ const session = await readHistory(transcriptPath, { sessionId, harness });
295
+ const own = opts.agentId === void 0 || harness === "codex" || session === null ? null : await readHistory(subagentTranscriptPath(transcriptPath, sessionId, opts.agentId), {
296
+ sessionId,
297
+ agentId: opts.agentId
298
+ });
299
+ const read = own === null ? session : [...session, ...own];
300
+ const current = { role: "user", text };
250
301
  return {
251
- current: { role: "user", text },
302
+ current: opts.delegated === true ? current : withPasted(current, harness),
252
303
  history: read ?? [],
253
304
  literalUrls: literalUrlsIn(text),
254
305
  historyStatus: read === null ? "unavailable" : "ok"
255
306
  };
256
307
  }
308
+ function splitPasted(text, harness) {
309
+ if (harness === "claude") return splitClaudePastes(text);
310
+ const lines = text.split("\n");
311
+ const start = lines.indexOf(PASTED_HEADER);
312
+ const request = lines.indexOf(REQUEST_HEADER, start + 1);
313
+ if (start === -1 || request === -1) return null;
314
+ const after = lines.slice(start + 1, request).findIndex((line) => line.startsWith("# "));
315
+ const end = after === -1 ? request : start + 1 + after;
316
+ const quoted = [];
317
+ for (const line of lines.slice(start + 1, end)) {
318
+ if (line.trim().length === 0) continue;
319
+ const entry = PASTED_ENTRY.exec(line);
320
+ if (entry === null) return null;
321
+ quoted.push(entry[1]);
322
+ }
323
+ const words = lines.slice(request + 1).join("\n").trim();
324
+ if (quoted.length === 0 || words.length === 0) return null;
325
+ const others = [...lines.slice(0, start), ...lines.slice(end, request)].join("\n").trim();
326
+ const rest = [lines.slice(0, start).join("\n").trim(), lines.slice(end).join("\n").trim()].filter((part) => part.length > 0).join("\n\n");
327
+ return { text: others.length === 0 ? words : rest, quoted };
328
+ }
329
+ var CLAUDE_OPEN = /<pasted_content id="([0-9a-f]{4})">\n/g;
330
+ var CLAUDE_TAG = /<\/?pasted_content\b/g;
331
+ function splitClaudePastes(text) {
332
+ const words = [];
333
+ const quoted = [];
334
+ const tags = [];
335
+ let from = 0;
336
+ for (const open2 of text.matchAll(CLAUDE_OPEN)) {
337
+ if (open2.index < from) return null;
338
+ const close = `
339
+ </pasted_content id="${open2[1]}">`;
340
+ const bodyAt = open2.index + open2[0].length;
341
+ const closeAt = text.indexOf(close, bodyAt - 1);
342
+ if (closeAt === -1) return null;
343
+ let start = open2.index;
344
+ for (let n = 0; n < 2 && start > from && text[start - 1] === "\n"; n++) start--;
345
+ let end = closeAt + close.length;
346
+ tags.push(open2.index, closeAt + 1);
347
+ for (let n = 0; n < 2 && text[end] === "\n"; n++) end++;
348
+ words.push(text.slice(from, start));
349
+ quoted.push(text.slice(bodyAt, Math.max(bodyAt, closeAt)));
350
+ from = end;
351
+ }
352
+ words.push(text.slice(from));
353
+ const every = [...text.matchAll(CLAUDE_TAG)].map((tag) => tag.index);
354
+ if (quoted.length === 0 || every.length !== tags.length) return null;
355
+ if (!every.every((at, i) => at === tags[i])) return null;
356
+ const rest = words.map((part) => part.trim()).filter((part) => part.length > 0).join("\n");
357
+ if (rest.length === 0 || quoted.every((block) => block.trim().length === 0)) return null;
358
+ return { text: rest, quoted };
359
+ }
360
+ var PASTED_HEADER = "# Files pasted by the user:";
361
+ var REQUEST_HEADER = "## My request:";
362
+ var PASTED_ENTRY = /^## "(.+)": \S.*$/;
363
+ function withPasted(message, harness) {
364
+ const pasted = splitPasted(message.text, harness);
365
+ if (pasted === null || pasted.quoted.length > MAX_QUOTED) return message;
366
+ return { role: message.role, ...pasted };
367
+ }
257
368
  async function buildNativePacket(transcriptPath, sessionId, pending, opts = {}) {
258
369
  const { agentId, nativeOutcome, harness = "claude" } = opts;
259
370
  const subject = subjectOf(pending);
@@ -266,7 +377,7 @@ async function buildNativePacket(transcriptPath, sessionId, pending, opts = {})
266
377
  const lastUser = messages.map((message, index) => ({ message, index })).filter((entry) => entry.message.role === "user");
267
378
  const current = lastUser.at(-1);
268
379
  return {
269
- current: current?.message ?? { role: "user", text: subject },
380
+ current: current === void 0 ? { role: "user", text: subject } : withPasted(current.message, harness),
270
381
  history: current === void 0 ? messages : messages.slice(0, current.index),
271
382
  literalUrls: literalUrlsIn(`${current?.message.text ?? ""}
272
383
  ${subject}`),
@@ -292,10 +403,10 @@ async function readHistory(path, scope) {
292
403
  return null;
293
404
  }
294
405
  try {
295
- const stat = await file.stat();
296
- if (!stat.isFile()) return null;
297
- tail = stat.size > MAX_TRANSCRIPT_BYTES;
298
- const read = tail ? await readTail(file, stat.size) : await readHead(file);
406
+ const stat2 = await file.stat();
407
+ if (!stat2.isFile()) return null;
408
+ tail = stat2.size > MAX_TRANSCRIPT_BYTES;
409
+ const read = tail ? await readTail(file, stat2.size) : await readHead(file);
299
410
  if (read === null) return null;
300
411
  raw = read;
301
412
  } catch {
@@ -420,186 +531,34 @@ function textOf(message) {
420
531
  return parts.join("\n");
421
532
  }
422
533
 
423
- // src/router/specs.ts
424
- import { createHash } from "node:crypto";
425
- import { constants } from "node:fs";
426
- import { lstat, open as open2, opendir, rm } from "node:fs/promises";
534
+ // src/router/decided.ts
535
+ import { rm } from "node:fs/promises";
427
536
  import { join as join2 } from "node:path";
428
- var SPECS_DIR = join2("progress", "specs");
429
- var RESULTS_DIR = "results";
430
- var MAX_SPEC_BYTES = 128 * 1024;
431
- var SPEC_TTL_MS = 15 * 6e4;
432
- var RESULT_TTL_MS = 24 * 60 * 6e4;
433
- var digest = (value) => createHash("sha256").update(value).digest("hex");
434
- function specPath(dataDir, id) {
435
- return join2(dataDir, SPECS_DIR, `${digest(id)}.json`);
436
- }
437
- var SHOWN_KEY = "shown";
438
- function shownInputField(spec) {
439
- if (spec.output === "media") return null;
440
- const held = spec.holds?.WebSearch ?? spec.holds?.WebFetch;
441
- if (held !== void 0) return held;
442
- const properties = spec.input.properties;
443
- if (properties === null || typeof properties !== "object") return null;
444
- const isString = (name) => properties[name]?.type === "string";
445
- const required = Array.isArray(spec.input.required) ? spec.input.required.filter((name) => typeof name === "string") : [];
446
- return required.find(isString) ?? Object.keys(properties).find(isString) ?? null;
447
- }
448
- async function storeSpecs(dataDir, specs) {
449
- if (specs === void 0 || specs.length === 0) return;
450
- for (const spec of specs) {
451
- try {
452
- const kept = { ...spec, [SHOWN_KEY]: shownInputField(spec) };
453
- await writeFileAtomic(specPath(dataDir, spec.id), JSON.stringify(kept), {
454
- mode: 384,
455
- dirMode: 448
456
- });
457
- } catch {
458
- }
459
- }
460
- await prune(join2(dataDir, SPECS_DIR), SPEC_TTL_MS, Date.now());
537
+ var DECIDED_TTL_MS = 6e4;
538
+ var MAX_DECIDED_BYTES = 1024 * 1024;
539
+ function decidedPath(dataDir, sessionId, toolUseId) {
540
+ return join2(sessionDir(dataDir, sessionId), `${DECIDED_PREFIX}${sha256Hex(toolUseId)}.json`);
461
541
  }
462
- async function readSpec(dataDir, id) {
463
- const path = specPath(dataDir, id);
464
- const file = await open2(path, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => void 0);
465
- if (file === void 0) return null;
542
+ async function keepDecided(dataDir, sessionId, toolUseId, target, { answer, unpaid }, now = Date.now()) {
466
543
  try {
467
- const stat = await file.stat();
468
- if (Date.now() - stat.mtimeMs > SPEC_TTL_MS || stat.size > MAX_SPEC_BYTES) return null;
469
- const kept = JSON.parse(await file.readFile("utf8"));
470
- delete kept[SHOWN_KEY];
471
- const parsed = OfferSpecSchema.safeParse(kept);
472
- return parsed.success && parsed.data.id === id ? parsed.data : null;
473
- } catch {
474
- return null;
475
- } finally {
476
- await file.close().catch(() => void 0);
477
- }
478
- }
479
- var KeptChoicesSchema = external_exports.strictObject({
480
- choices: ChoicesSchema,
481
- hint: external_exports.string().max(2e3)
482
- });
483
- function choicesPath(dataDir, id) {
484
- return join2(dataDir, SPECS_DIR, `${digest(id)}.choices.json`);
485
- }
486
- async function storeChoices(dataDir, id, kept) {
487
- if (kept === void 0) return;
488
- try {
489
- await writeFileAtomic(choicesPath(dataDir, id), JSON.stringify(kept), {
490
- mode: 384,
491
- dirMode: 448
492
- });
493
- } catch {
494
- }
495
- await prune(join2(dataDir, SPECS_DIR), SPEC_TTL_MS, Date.now());
496
- }
497
- async function readChoices(dataDir, id) {
498
- const file = await open2(
499
- choicesPath(dataDir, id),
500
- constants.O_RDONLY | constants.O_NOFOLLOW
501
- ).catch(() => void 0);
502
- if (file === void 0) return null;
503
- try {
504
- const stat = await file.stat();
505
- if (Date.now() - stat.mtimeMs > SPEC_TTL_MS || stat.size > MAX_SPEC_BYTES) return null;
506
- const parsed = KeptChoicesSchema.safeParse(JSON.parse(await file.readFile("utf8")));
507
- return parsed.success ? parsed.data : null;
508
- } catch {
509
- return null;
510
- } finally {
511
- await file.close().catch(() => void 0);
512
- }
513
- }
514
- function labelPath(dataDir, id) {
515
- return join2(dataDir, SPECS_DIR, `${digest(id)}.label.json`);
516
- }
517
- async function storeLabel(dataDir, id, label) {
518
- try {
519
- await writeFileAtomic(labelPath(dataDir, id), JSON.stringify({ id, label }), {
520
- mode: 384,
521
- dirMode: 448
522
- });
523
- } catch {
524
- }
525
- await prune(join2(dataDir, SPECS_DIR), SPEC_TTL_MS, Date.now());
526
- }
527
- var PaymentSchema = external_exports.discriminatedUnion("state", [
528
- external_exports.strictObject({
529
- state: external_exports.literal("paid"),
530
- at: external_exports.string().max(40),
531
- amountAtomic: external_exports.string().regex(/^\d+$/),
532
- txHash: external_exports.string().max(100).optional()
533
- }),
534
- external_exports.strictObject({ state: external_exports.literal("possibly_paid"), at: external_exports.string().max(40) }),
535
- external_exports.strictObject({ state: external_exports.literal("running"), at: external_exports.string().max(40) })
536
- ]);
537
- function paymentPath(dataDir, id) {
538
- return join2(dataDir, SPECS_DIR, `${digest(id)}.paid.json`);
539
- }
540
- async function claimSpecPayment(dataDir, id, now = Date.now()) {
541
- const path = paymentPath(dataDir, id);
542
- try {
543
- await writeFileAtomicExclusive(
544
- path,
545
- JSON.stringify({ state: "running", at: new Date(now).toISOString() }),
546
- { mode: 384, dirMode: 448 }
544
+ await writePrivate(
545
+ decidedPath(dataDir, sessionId, toolUseId),
546
+ JSON.stringify({ version: 1, at: now, target, answer, unpaid })
547
547
  );
548
- return null;
549
- } catch (err) {
550
- if (err.code !== "EEXIST") return { state: "unrecorded" };
551
- }
552
- const file = await open2(path, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => void 0);
553
- if (file === void 0) return { state: "running" };
554
- try {
555
- const parsed = PaymentSchema.safeParse(JSON.parse(await file.readFile("utf8")));
556
- return parsed.success ? parsed.data : { state: "running" };
557
- } catch {
558
- return { state: "running" };
559
- } finally {
560
- await file.close().catch(() => void 0);
561
- }
562
- }
563
- async function settleSpecPayment(dataDir, id, left, now = Date.now()) {
564
- const path = paymentPath(dataDir, id);
565
- if (!left.signed && left.amountAtomic === 0n) {
566
- await rm(path, { force: true }).catch(() => void 0);
567
- return;
568
- }
569
- const at = new Date(now).toISOString();
570
- const record2 = left.amountAtomic > 0n ? {
571
- state: "paid",
572
- at,
573
- amountAtomic: left.amountAtomic.toString(),
574
- ...left.txHash !== void 0 ? { txHash: left.txHash } : {}
575
- } : { state: "possibly_paid", at };
576
- await writeFileAtomic(path, JSON.stringify(record2), { mode: 384, dirMode: 448 }).catch(
577
- () => void 0
578
- );
579
- }
580
- async function storeFullResult(dataDir, id, body) {
581
- const path = join2(dataDir, RESULTS_DIR, `${digest(id)}.json`);
582
- try {
583
- await writeFileAtomic(path, body, { mode: 384, dirMode: 448 });
584
548
  } catch {
585
- return null;
586
549
  }
587
- void prune(join2(dataDir, RESULTS_DIR), RESULT_TTL_MS, Date.now());
588
- return path;
589
550
  }
590
- async function prune(dir, ttlMs, now) {
591
- try {
592
- const directory = await opendir(dir);
593
- for await (const entry of directory) {
594
- if (!entry.isFile()) continue;
595
- const path = join2(dir, entry.name);
596
- const stat = await lstat(path).catch(() => void 0);
597
- if (stat === void 0 || now - stat.mtimeMs > ttlMs) {
598
- await rm(path, { force: true }).catch(() => void 0);
599
- }
600
- }
601
- } catch {
602
- }
551
+ async function takeDecided(dataDir, sessionId, toolUseId, target, now = Date.now()) {
552
+ const path = decidedPath(dataDir, sessionId, toolUseId);
553
+ const row = await readJsonFile(path, MAX_DECIDED_BYTES);
554
+ if (row === null) return void 0;
555
+ await rm(path, { force: true }).catch(() => void 0);
556
+ if (row.version !== 1 || typeof row.at !== "number" || row.target !== target) return void 0;
557
+ if (now - row.at > DECIDED_TTL_MS || row.at > now + DECIDED_TTL_MS) return void 0;
558
+ const unpaid = typeof row.unpaid === "string" ? { unpaid: row.unpaid } : {};
559
+ if (row.answer === null) return { answer: null, ...unpaid };
560
+ const answer = parseHookResponse(row.answer);
561
+ return answer === void 0 ? void 0 : { answer, ...unpaid };
603
562
  }
604
563
 
605
564
  // src/router/fetch-result.ts
@@ -650,9 +609,66 @@ function savedPdfOf(result, sessionId) {
650
609
  return SAVED_PDF_NAME_RE.exec(path)?.[1] === sessionId ? path : null;
651
610
  }
652
611
 
653
- // src/router/gate.ts
654
- var GATE_TIMEOUT_MS = 3500;
655
- var DEPOSIT_GATE_TIMEOUT_MS = 4500;
612
+ // src/router/own-urls.ts
613
+ import { readFile, stat } from "node:fs/promises";
614
+ import { homedir } from "node:os";
615
+ import { join as join3, resolve } from "node:path";
616
+ var HARNESS_HOSTS = { claude: ["claude.ai"], codex: [] };
617
+ var MAX_CONFIG_BYTES = 64 * 1024;
618
+ async function ownHostsFor(packet, cwd, harness, homeDir = homedir()) {
619
+ if (packet.literalUrls.length === 0) return [];
620
+ return [...await remoteHosts(cwd, homeDir), ...HARNESS_HOSTS[harness]];
621
+ }
622
+ async function remoteHosts(cwd, homeDir = homedir()) {
623
+ try {
624
+ const root = await projectRoot(cwd, homeDir);
625
+ const dotGit = join3(root, ".git");
626
+ if (!await pathExists(dotGit)) return [];
627
+ const path = await configPath(dotGit);
628
+ if ((await stat(path)).size > MAX_CONFIG_BYTES) return [];
629
+ return remoteHostsIn(await readFile(path, "utf8"));
630
+ } catch {
631
+ return [];
632
+ }
633
+ }
634
+ async function configPath(dotGit) {
635
+ if ((await stat(dotGit)).isDirectory()) return join3(dotGit, "config");
636
+ const line = /^gitdir:\s*(.+?)\s*$/m.exec(await readFile(dotGit, "utf8"));
637
+ if (line === null) throw new Error("not a gitdir file");
638
+ const gitdir = resolve(dotGit, "..", line[1]);
639
+ const common = await readFile(join3(gitdir, "commondir"), "utf8").then(
640
+ (text) => resolve(gitdir, text.trim()),
641
+ () => gitdir
642
+ );
643
+ return join3(common, "config");
644
+ }
645
+ function remoteHostsIn(config) {
646
+ const hosts = /* @__PURE__ */ new Set();
647
+ let inRemote = false;
648
+ for (const raw of config.split("\n")) {
649
+ const line = raw.trim();
650
+ if (line.startsWith("[")) {
651
+ inRemote = /^\[remote\s+"[^"]*"\]$/.test(line);
652
+ continue;
653
+ }
654
+ const url = inRemote ? /^url\s*=\s*"?([^"]+?)"?\s*$/.exec(line)?.[1] : void 0;
655
+ const host = url === void 0 ? null : hostOfRemote(url);
656
+ if (host !== null) hosts.add(host);
657
+ }
658
+ return [...hosts];
659
+ }
660
+ function hostOfRemote(remote) {
661
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(remote)) {
662
+ try {
663
+ const host = new URL(remote).hostname.toLowerCase();
664
+ return host.length > 0 ? host : null;
665
+ } catch {
666
+ return null;
667
+ }
668
+ }
669
+ const scp = /^(?:[^@/]+@)?([^:/\\]+):(?!\/\/)/.exec(remote);
670
+ return scp?.[1] !== void 0 && scp[1].includes(".") ? scp[1].toLowerCase() : null;
671
+ }
656
672
 
657
673
  // src/router/hooks.ts
658
674
  var PromptEventSchema = external_exports.object({
@@ -902,11 +918,10 @@ function resolveBaseUrl(deps, config) {
902
918
  if (deps.baseUrl !== void 0) return deps.baseUrl;
903
919
  return resolveSettings({ config, flags: {}, env: deps.env ?? process.env }).baseUrl.value;
904
920
  }
905
- var BALANCE_TIMEOUT_MS = 1e3;
906
921
  function gateDeadline(deps) {
907
- return (deps.now?.() ?? Date.now()) + (deps.timeoutMs ?? GATE_TIMEOUT_MS);
922
+ return (deps.now?.() ?? Date.now()) + (deps.timeoutMs ?? (deps.route ? GATE_TIMEOUT_MS : UNPAID_GATE_TIMEOUT_MS));
908
923
  }
909
- async function spendShortfall(decision, deps, deadline) {
924
+ async function spendShortfall(decision, deps, _deadline) {
910
925
  const price = `$${toMoney(decision.providerPriceAtomic).usd}`;
911
926
  const approval = (detail) => ({
912
927
  withheld: "offer needs approval",
@@ -925,46 +940,15 @@ async function spendShortfall(decision, deps, deadline) {
925
940
  });
926
941
  policy = evaluation.decision !== "allow" ? approval(
927
942
  evaluation.reason === "above_auto_spend" ? `is above this machine's automatic per-call limit ($${toMoney(settings.policy.maxAutoSpendAtomic.toString()).usd})` : "needs approval under this machine's spend limits"
928
- ) : { rpcUrl: settings.rpcUrl };
943
+ ) : null;
929
944
  } catch {
930
945
  policy = approval("needs approval under this machine's spend limits");
931
946
  }
932
- if (BigInt(decision.providerPriceAtomic) === 0n) return "rpcUrl" in policy ? null : policy;
947
+ if (BigInt(decision.providerPriceAtomic) === 0n) return policy;
933
948
  const facts = await readWalletFacts(deps.dataDir, deps.env ?? process.env);
934
949
  const sign = deps.signer?.() ?? canSign(facts);
935
950
  if (sign.status === "blocked") return cannotSign(sign);
936
- if (!("rpcUrl" in policy)) return policy;
937
- const { rpcUrl } = policy;
938
- let balance = null;
939
- if (facts.address !== null && facts.envKey !== "valid") {
940
- const readBalance = rememberingBalanceReader(deps.dataDir, {
941
- ...deps.now !== void 0 ? { now: deps.now } : {}
942
- });
943
- balance = await readBalance(facts.address, rpcUrl, {
944
- timeoutMs: Math.min(BALANCE_TIMEOUT_MS, deadline - (deps.now?.() ?? Date.now())),
945
- ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
946
- });
947
- if (balance === null) {
948
- (deps.warn ?? ((line) => process.stderr.write(`${line}
949
- `)))(
950
- `tenjin hook: the wallet's USDC balance could not be read from ${new URL(rpcUrl).host}, so the spend policy alone decides`
951
- );
952
- }
953
- }
954
- const v = canPayProvider(
955
- { policy: { decision: "allow" }, sign, balanceAtomic: balance },
956
- BigInt(decision.providerPriceAtomic)
957
- );
958
- if (v.status !== "blocked" || v.reason === "needs_approval") return null;
959
- if (v.reason === "wallet_short") {
960
- if (balance === null) return null;
961
- const short = BigInt(decision.providerPriceAtomic) - balance;
962
- return {
963
- withheld: "wallet needs USDC",
964
- note: `Note: the wallet holds $${toMoney(balance.toString()).usd}, $${toMoney(short.toString()).usd} short of its ${price}; fund it with \`tenjin wallet fund\`.`
965
- };
966
- }
967
- return cannotSign(v);
951
+ return policy;
968
952
  }
969
953
  function cannotSign(v) {
970
954
  return {
@@ -974,7 +958,14 @@ function cannotSign(v) {
974
958
  };
975
959
  }
976
960
  async function vetOffer(offer, deps, deadline, canAskUser) {
977
- const shortfall = await spendShortfall(termsOf(offer), deps, deadline);
961
+ const lead = accountLeadOf(offer);
962
+ if (lead !== void 0) {
963
+ if (await accountLacks(deps.dataDir, lead)) return { withheld: "account lacks this job" };
964
+ return { offer };
965
+ }
966
+ const terms = termsOf(offer);
967
+ if (terms.endpoint === void 0) return { withheld: "no endpoint to pay" };
968
+ const shortfall = await spendShortfall({ ...terms, endpoint: terms.endpoint }, deps, deadline);
978
969
  if (shortfall === null) {
979
970
  const note = await overCapNote(offer, deps, canAskUser);
980
971
  return { offer: note === null ? offer : { ...offer, hint: `${offer.hint} ${note}` } };
@@ -984,19 +975,8 @@ async function vetOffer(offer, deps, deadline, canAskUser) {
984
975
  }
985
976
  return { withheld: shortfall.withheld };
986
977
  }
987
- var LISTED_PRICE_RE = /about \$(\d+(?:\.\d+)?)(?= per call|: request\(| \(price can vary)|\$(\d+(?:\.\d+)?)(?=\): request\(| via https?:\/\/)/g;
988
- var QUOTED_RE = /"(?:[^"\\]|\\.)*"/g;
989
978
  function listedPrices(offer) {
990
- if (offer.specs !== void 0) {
991
- return offer.specs.filter((spec) => spec.id !== offer.id).map((spec) => BigInt(spec.priceAtomic));
992
- }
993
- return [...offer.hint.replace(QUOTED_RE, '""').matchAll(LISTED_PRICE_RE)].flatMap((match) => {
994
- try {
995
- return [BigInt(parseUsdToAtomic(match[1] ?? match[2]))];
996
- } catch {
997
- return [];
998
- }
999
- });
979
+ return (offer.specs ?? []).filter((spec) => spec.id !== offer.id).flatMap((spec) => isAccountSpec(spec) ? [] : [BigInt(spec.priceAtomic)]);
1000
980
  }
1001
981
  function listedUsd(atomic) {
1002
982
  const [whole, fraction = ""] = toMoney(atomic.toString()).usd.split(".");
@@ -1018,7 +998,7 @@ async function overCapNote(offer, deps, canAskUser) {
1018
998
  return `Note: ${prices} ${over.length > 1 ? "are" : "is"} above this machine's automatic per-call limit ($${toMoney(cap.toString()).usd}), so request returns needs_approval for ${which}; ` + (canAskUser ? "prefer one within the limit." : "use one within the limit.");
1019
999
  }
1020
1000
  function agentLookup(cwd, deps) {
1021
- return { ...cwd !== void 0 ? { cwd } : {}, homeDir: deps.homeDir ?? homedir() };
1001
+ return { ...cwd !== void 0 ? { cwd } : {}, homeDir: deps.homeDir ?? homedir2() };
1022
1002
  }
1023
1003
  function hookContext(deps) {
1024
1004
  return {
@@ -1042,44 +1022,60 @@ async function offerOnUserText(event, text, hookEventName, deps) {
1042
1022
  if (skipped !== null) return { response: null, skipped };
1043
1023
  const router = await routerFor(event.cwd, deps);
1044
1024
  if (router === null) return { response: null };
1045
- const sealed = seal(
1046
- scoped(
1047
- await buildPromptPacket(event.transcriptPath, event.sessionId, text, hostOf(deps)),
1048
- router.settings
1049
- )
1025
+ await sweepUntaken(deps, router);
1026
+ const sealed = await sealHere(
1027
+ await buildPromptPacket(event.transcriptPath, event.sessionId, text, hostOf(deps)),
1028
+ router,
1029
+ event.cwd,
1030
+ deps
1050
1031
  );
1051
- const footer = await openFooter(deps, event.sessionId, "prompt");
1032
+ const footer = await openFooter(deps, event.sessionId, "prompt", {});
1052
1033
  const deadline = gateDeadline(deps);
1053
- const outcome = await decide(
1054
- sealed,
1055
- deps,
1056
- router.config,
1057
- event.sessionId,
1058
- deadline,
1059
- footer.unpaid
1060
- );
1034
+ const outcome = await decide(sealed, deps, router, event.sessionId, deadline, footer);
1061
1035
  if (!isOffer(outcome)) {
1062
1036
  await footer.close(outcome);
1063
- return { response: null, ...outcome !== null ? { action: outcome.action } : {} };
1037
+ return {
1038
+ ...injection(hookEventName),
1039
+ ...outcome !== null ? { action: outcome.action } : {}
1040
+ };
1064
1041
  }
1065
1042
  const vetted = await vetOffer(outcome, deps, deadline, true);
1066
1043
  if (vetted.withheld !== void 0) {
1067
1044
  await footer.close(outcome, { withheld: vetted.withheld });
1068
- return { response: null, action: outcome.action, withheld: true };
1045
+ return { ...injection(hookEventName), action: outcome.action, withheld: true };
1069
1046
  }
1070
1047
  await footer.close(outcome);
1048
+ if (hookEventName === "UserPromptSubmit") {
1049
+ await markOffered(
1050
+ deps.dataDir,
1051
+ localSession(event.sessionId, deps),
1052
+ promptOfferKey(text),
1053
+ offeredTerms(vetted.offer),
1054
+ deps.now?.()
1055
+ );
1056
+ }
1071
1057
  return {
1072
1058
  action: outcome.action,
1073
1059
  id: outcome.id,
1074
1060
  ...injection(hookEventName, attributed(vetted.offer.hint, hostOf(deps)))
1075
1061
  };
1076
1062
  }
1077
- function injection(hookEventName, line) {
1078
- return { response: { hookSpecificOutput: { hookEventName, additionalContext: line } } };
1063
+ function injection(hookEventName, ...lines) {
1064
+ const said = lines.filter((line) => line !== void 0);
1065
+ if (said.length === 0) return { response: null };
1066
+ return {
1067
+ response: { hookSpecificOutput: { hookEventName, additionalContext: said.join("\n\n") } }
1068
+ };
1079
1069
  }
1080
1070
  function isOffer(decision) {
1081
1071
  return decision?.action === "execute" || decision?.action === "discovered";
1082
1072
  }
1073
+ function accountLeadOf(decision) {
1074
+ if (decision?.action !== "execute") return void 0;
1075
+ const lead = (decision.specs ?? []).find(({ id }) => id === decision.id);
1076
+ return lead !== void 0 && isAccountSpec(lead) ? lead : void 0;
1077
+ }
1078
+ var isAccountOffer = (decision) => accountLeadOf(decision) !== void 0;
1083
1079
  function termsOf(offer) {
1084
1080
  if (offer.action === "execute") return offer;
1085
1081
  const { candidate } = offer;
@@ -1090,56 +1086,31 @@ function termsOf(offer) {
1090
1086
  };
1091
1087
  }
1092
1088
  function isFree(offer) {
1093
- return offer.action === "execute" && offer.providerPriceAtomic === "0";
1089
+ return offer.action === "execute" && offer.providerPriceAtomic === "0" && !isAccountOffer(offer);
1094
1090
  }
1095
1091
  async function routeNativeCall(event, pending, deps, opts = {}) {
1096
1092
  const { nativeOutcome, repeated } = opts;
1097
1093
  const router = await routerFor(event.cwd, deps);
1098
1094
  if (router === null) return { offer: null, outcome: { response: null } };
1095
+ await sweepUntaken(
1096
+ deps,
1097
+ router,
1098
+ opts.native === true ? offerScope(localSession(event.sessionId, deps), event.agentId) : void 0
1099
+ );
1099
1100
  if (event.agentId !== void 0 && await requestToolAccess(event.agentType, agentLookup(event.cwd, deps)) !== "allowed") {
1100
1101
  return { offer: null, outcome: { response: null, noRequestTool: true } };
1101
1102
  }
1102
1103
  if (opts.redirected !== void 0 && await opts.redirected()) {
1103
- const footer2 = await openFooter(deps, event.sessionId, opts.operation ?? "search");
1104
+ const footer2 = await openFooter(deps, event.sessionId, opts.operation ?? "search", event);
1104
1105
  await footer2.close(null, { withheld: "already redirected once" });
1105
1106
  return { offer: null, outcome: { response: null, alreadyRedirected: true } };
1106
1107
  }
1107
- const sealed = seal(
1108
- scoped(
1109
- await buildNativePacket(event.transcriptPath, event.sessionId, pending, {
1110
- ...event.agentId !== void 0 ? { agentId: event.agentId } : {},
1111
- ...nativeOutcome !== void 0 ? { nativeOutcome } : {},
1112
- harness: hostOf(deps)
1113
- }),
1114
- router.settings
1115
- )
1116
- );
1117
- const { packet } = sealed;
1118
- if (sealed.localTarget) return { offer: null, outcome: { response: null } };
1119
- if (sealed.subjectChanged) {
1120
- (deps.warn ?? ((line) => process.stderr.write(`${line}
1121
- `)))(
1122
- "tenjin hook: the native call carries a credential-shaped value, so it is not routed"
1123
- );
1124
- return { offer: null, outcome: { response: null } };
1125
- }
1126
- if (packet.historyStatus !== "ok") {
1127
- (deps.warn ?? ((line) => process.stderr.write(`${line}
1128
- `)))(
1129
- "tenjin hook: this session's transcript could not be read, so no paid lookup is offered"
1130
- );
1131
- return { offer: null, outcome: { response: null } };
1132
- }
1133
- const footer = await openFooter(deps, event.sessionId, opts.operation ?? "search");
1108
+ const { recorded } = opts;
1109
+ const sealed = recorded === void 0 ? await sealNative(event, pending, router, deps, nativeOutcome) : void 0;
1110
+ if (sealed === null) return { offer: null, outcome: { response: null } };
1111
+ const footer = await openFooter(deps, event.sessionId, opts.operation ?? "search", event);
1134
1112
  const deadline = gateDeadline(deps);
1135
- const outcome = await decide(
1136
- sealed,
1137
- deps,
1138
- router.config,
1139
- event.sessionId,
1140
- deadline,
1141
- footer.unpaid
1142
- );
1113
+ const outcome = sealed !== void 0 ? await decide(sealed, deps, router, event.sessionId, deadline, footer) : fromRecorded(recorded, router, footer, deps);
1143
1114
  if (!isOffer(outcome)) {
1144
1115
  await footer.close(outcome);
1145
1116
  return {
@@ -1148,7 +1119,7 @@ async function routeNativeCall(event, pending, deps, opts = {}) {
1148
1119
  };
1149
1120
  }
1150
1121
  if (opts.passFree === true && isFree(outcome)) {
1151
- const close = (shown) => footer.close(outcome, shown ? void 0 : { withheld: "free lookup, call runs" });
1122
+ const close = (noted) => footer.close(outcome, noted ? { noted: true } : { withheld: "free lookup, call runs" });
1152
1123
  return { offer: outcome, free: true, close };
1153
1124
  }
1154
1125
  const vetted = await vetOffer(
@@ -1171,6 +1142,111 @@ async function routeNativeCall(event, pending, deps, opts = {}) {
1171
1142
  await footer.close(outcome);
1172
1143
  return { offer: vetted.offer };
1173
1144
  }
1145
+ async function sealNative(event, pending, router, deps, nativeOutcome) {
1146
+ const warn = deps.warn ?? ((line) => process.stderr.write(`${line}
1147
+ `));
1148
+ const sealed = await sealHere(
1149
+ await buildNativePacket(event.transcriptPath, event.sessionId, pending, {
1150
+ ...event.agentId !== void 0 ? { agentId: event.agentId } : {},
1151
+ ...nativeOutcome !== void 0 ? { nativeOutcome } : {},
1152
+ harness: hostOf(deps)
1153
+ }),
1154
+ router,
1155
+ event.cwd,
1156
+ deps
1157
+ );
1158
+ if (sealed.localTarget) return null;
1159
+ if (sealed.subjectChanged) {
1160
+ warn("tenjin hook: the native call carries a credential-shaped value, so it is not routed");
1161
+ return null;
1162
+ }
1163
+ if (sealed.packet.historyStatus !== "ok") {
1164
+ warn("tenjin hook: this session's transcript could not be read, so no paid lookup is offered");
1165
+ return null;
1166
+ }
1167
+ return sealed;
1168
+ }
1169
+ function fromRecorded(recorded, router, footer, deps) {
1170
+ if (recorded.unpaid !== void 0) footer.unpaid(recorded.unpaid);
1171
+ const { answer } = recorded;
1172
+ if (answer === null) return null;
1173
+ const warn = deps.warn ?? ((line) => process.stderr.write(`${line}
1174
+ `));
1175
+ if (!decidedUnder(answer, router, warn)) return null;
1176
+ footer.answered(answer);
1177
+ return answer.decision;
1178
+ }
1179
+ async function decideSwap(raw, deps) {
1180
+ if (hostOf(deps) !== "claude") return { handback: "this host cannot run a pick in place" };
1181
+ const event = decodeEvent(raw);
1182
+ if (event?.kind !== "native" || event.pending === null || event.toolUseId === void 0) {
1183
+ return { handback: "not a search or fetch Tenjin routes" };
1184
+ }
1185
+ const { pending, toolUseId } = event;
1186
+ if (pending.tool !== "WebSearch" && pending.tool !== "WebFetch") {
1187
+ return { handback: "not a search or fetch Tenjin routes" };
1188
+ }
1189
+ if (event.agentId !== void 0) return { handback: "a subagent call" };
1190
+ const router = await routerFor(event.cwd, deps);
1191
+ if (router === null) return { handback: "Tenjin is off here" };
1192
+ if (router.settings.nativeReplacement.mode !== "when-routed")
1193
+ return { handback: "automatic use is off" };
1194
+ const tool = pending.tool;
1195
+ const session = localSession(event.sessionId, deps);
1196
+ const target = redirectTarget(pending);
1197
+ const targets = [...new Set((event.targets ?? [pending]).map(redirectTarget))];
1198
+ for (const t of targets) {
1199
+ if (await redirectClaimed(deps.dataDir, session, void 0, t, deps.now?.())) {
1200
+ return { handback: "already routed once" };
1201
+ }
1202
+ }
1203
+ const sealed = await sealNative(event, pending, router, deps);
1204
+ if (sealed === null) return { handback: "not routed" };
1205
+ const footer = await openFooter(deps, event.sessionId, "search", event);
1206
+ const deadline = gateDeadline(deps);
1207
+ let kept = { answer: null };
1208
+ const outcome = await decide(sealed, deps, router, event.sessionId, deadline, {
1209
+ unpaid: (why) => {
1210
+ kept = { ...kept, unpaid: why };
1211
+ footer.unpaid(why);
1212
+ },
1213
+ answered: (answer) => {
1214
+ kept = { ...kept, answer };
1215
+ footer.answered(answer);
1216
+ }
1217
+ });
1218
+ await keepDecided(deps.dataDir, session, toolUseId, target, kept, deps.now?.());
1219
+ const back = async (why) => {
1220
+ await footer.close(outcome, isOffer(outcome) ? { withheld: why } : void 0);
1221
+ return { handback: why };
1222
+ };
1223
+ if (!isOffer(outcome)) return back("no paid lookup fits");
1224
+ const { bound } = outcome;
1225
+ const spec = bound === void 0 ? void 0 : outcome.specs?.find(({ id }) => id === bound.id);
1226
+ if (bound === void 0 || spec === void 0 || isFree(outcome) || outcome.action === "discovered" && outcome.choices !== void 0) {
1227
+ return back("no input to run in place");
1228
+ }
1229
+ const vetted = await vetOffer(outcome, deps, deadline, false);
1230
+ if (vetted.withheld !== void 0) return back(vetted.withheld);
1231
+ await footer.close(outcome);
1232
+ const now = () => deps.now?.() ?? Date.now();
1233
+ const terms = { ...offeredTerms(outcome), swap: true };
1234
+ return {
1235
+ offer: outcome,
1236
+ bound,
1237
+ spec,
1238
+ tool,
1239
+ claim: async () => {
1240
+ if (!await claimRedirect(deps.dataDir, session, void 0, target, now())) return false;
1241
+ await Promise.all(
1242
+ targets.filter((t) => t !== target).map((t) => claimRedirect(deps.dataDir, session, void 0, t, now()))
1243
+ );
1244
+ await markOffered(deps.dataDir, session, toolUseId, terms, now());
1245
+ return true;
1246
+ },
1247
+ unmark: () => markHandedBack(deps.dataDir, session, toolUseId, now())
1248
+ };
1249
+ }
1174
1250
  async function runNativeHook(raw, deps) {
1175
1251
  const event = eventOf(raw, deps);
1176
1252
  if (event?.kind !== "native" || event.pending === null) return { response: null };
@@ -1178,8 +1254,11 @@ async function runNativeHook(raw, deps) {
1178
1254
  const targets = [...new Set((event.targets ?? [event.pending]).map(redirectTarget))];
1179
1255
  const session = localSession(event.sessionId, deps);
1180
1256
  const claim = (t) => claimRedirect(deps.dataDir, session, event.agentId, t, deps.now?.());
1257
+ const recorded = event.toolUseId !== void 0 && event.agentId === void 0 ? await takeDecided(deps.dataDir, session, event.toolUseId, target, deps.now?.()) : void 0;
1181
1258
  const routed = await routeNativeCall(event, event.pending, deps, {
1259
+ ...recorded !== void 0 ? { recorded } : {},
1182
1260
  passFree: true,
1261
+ native: true,
1183
1262
  repeated: async () => {
1184
1263
  if (!await claim(target)) return true;
1185
1264
  await Promise.all(targets.filter((t) => t !== target).map(claim));
@@ -1199,7 +1278,13 @@ async function runNativeHook(raw, deps) {
1199
1278
  const { pending, toolUseId } = event;
1200
1279
  const now = deps.now?.() ?? Date.now();
1201
1280
  const { id, hint } = routed.offer;
1202
- const noted = pending.tool === "WebSearch" && routed.offer.delivery === "note" && toolUseId !== void 0 && await claimNote(deps.dataDir, session, event.agentId, pending.query, now) && await markNoted(deps.dataDir, session, toolUseId, { offerId: id, line: hint }, now);
1281
+ const noted = pending.tool === "WebSearch" && routed.offer.delivery === "note" && toolUseId !== void 0 && await claimNote(deps.dataDir, session, event.agentId, pending.query, now) && await markNoted(
1282
+ deps.dataDir,
1283
+ session,
1284
+ toolUseId,
1285
+ { offerId: id, line: hint, ids: offeredIds(routed.offer) },
1286
+ now
1287
+ );
1203
1288
  await routed.close(noted);
1204
1289
  return {
1205
1290
  response: null,
@@ -1232,7 +1317,8 @@ function offeredTerms(offer) {
1232
1317
  return {
1233
1318
  offerId: offer.id,
1234
1319
  ...label !== void 0 ? { label } : {},
1235
- priceAtomic: termsOf(offer).providerPriceAtomic
1320
+ // An account's call costs the balance nothing: no price to show.
1321
+ ...isAccountOffer(offer) ? {} : { priceAtomic: termsOf(offer).providerPriceAtomic }
1236
1322
  };
1237
1323
  }
1238
1324
  function redirect(offer, host, oneBlock = ONE_BLOCK) {
@@ -1289,6 +1375,16 @@ async function runShortfallHook(raw, deps) {
1289
1375
  );
1290
1376
  if (note !== null) {
1291
1377
  if (event.interrupted === true) return { response: null };
1378
+ await noteShown(
1379
+ deps.dataDir,
1380
+ {
1381
+ id: note.offerId,
1382
+ ids: note.ids ?? [],
1383
+ harness: hostOf(deps),
1384
+ scope: offerScope(localSession(event.sessionId, deps), event.agentId)
1385
+ },
1386
+ deps.now?.()
1387
+ );
1292
1388
  return {
1293
1389
  response: {
1294
1390
  hookSpecificOutput: {
@@ -1329,7 +1425,9 @@ async function offerOnShortfall(event, deps) {
1329
1425
  return { response: null, nativeOutcome, alreadyOffered: true };
1330
1426
  }
1331
1427
  const routed = await routeNativeCall(event, pending, deps, { nativeOutcome });
1332
- if (routed.offer === null) return { ...routed.outcome, nativeOutcome };
1428
+ if (routed.offer === null) {
1429
+ return { ...routed.outcome, nativeOutcome };
1430
+ }
1333
1431
  return {
1334
1432
  response: {
1335
1433
  hookSpecificOutput: {
@@ -1351,11 +1449,17 @@ async function runDelegationHook(raw, deps) {
1351
1449
  if (task === null || task.trim().length === 0) return { response: null };
1352
1450
  const router = await routerFor(event.cwd, deps);
1353
1451
  if (router === null) return { response: null };
1452
+ await sweepUntaken(deps, router);
1354
1453
  if (await requestToolAccess(event.subagentType, agentLookup(event.cwd, deps)) !== "allowed") {
1355
1454
  return { response: null, noRequestTool: true };
1356
1455
  }
1357
- const sealed = seal(
1358
- scoped(await buildPromptPacket(event.transcriptPath, event.sessionId, task), router.settings)
1456
+ const sealed = await sealHere(
1457
+ await buildPromptPacket(event.transcriptPath, event.sessionId, task, hostOf(deps), {
1458
+ delegated: true
1459
+ }),
1460
+ router,
1461
+ event.cwd,
1462
+ deps
1359
1463
  );
1360
1464
  if (sealed.localUrl) return { response: null };
1361
1465
  if (sealed.currentChanged) {
@@ -1366,16 +1470,9 @@ async function runDelegationHook(raw, deps) {
1366
1470
  return { response: null };
1367
1471
  }
1368
1472
  if (sealed.packet.historyStatus !== "ok") return { response: null };
1369
- const footer = await openFooter(deps, event.sessionId, "delegate");
1473
+ const footer = await openFooter(deps, event.sessionId, "delegate", null);
1370
1474
  const deadline = gateDeadline(deps);
1371
- const outcome = await decide(
1372
- sealed,
1373
- deps,
1374
- router.config,
1375
- event.sessionId,
1376
- deadline,
1377
- footer.unpaid
1378
- );
1475
+ const outcome = await decide(sealed, deps, router, event.sessionId, deadline, footer);
1379
1476
  if (!isOffer(outcome)) {
1380
1477
  await footer.close(outcome);
1381
1478
  return { response: null, ...outcome !== null ? { action: outcome.action } : {} };
@@ -1403,7 +1500,7 @@ ${delegationOffer(outcome.hint)}`
1403
1500
  id: outcome.id
1404
1501
  };
1405
1502
  }
1406
- async function openFooter(deps, sessionId, operation) {
1503
+ async function openFooter(deps, sessionId, operation, shownTo) {
1407
1504
  sessionId = localSession(sessionId, deps);
1408
1505
  const now = () => deps.now?.() ?? Date.now();
1409
1506
  const directory = sessionDir(deps.dataDir, sessionId);
@@ -1418,10 +1515,14 @@ async function openFooter(deps, sessionId, operation) {
1418
1515
  await pruneProgress(directory, now());
1419
1516
  await pruneSessions(deps.dataDir, now());
1420
1517
  let unpaid;
1518
+ let settingsHash;
1421
1519
  return {
1422
1520
  unpaid: (why) => {
1423
1521
  unpaid = why;
1424
1522
  },
1523
+ answered: (answer) => {
1524
+ settingsHash = answer.settingsHash;
1525
+ },
1425
1526
  close: async (decision, opts) => {
1426
1527
  const withheld = opts?.withheld;
1427
1528
  await writeProgress(
@@ -1436,7 +1537,29 @@ async function openFooter(deps, sessionId, operation) {
1436
1537
  );
1437
1538
  if (withheld === void 0 && isOffer(decision)) {
1438
1539
  await bindDecision(deps.dataDir, sessionId, decision.id, now());
1439
- await storeSpecs(deps.dataDir, decision.specs);
1540
+ if (opts?.noted !== true) {
1541
+ await noteShown(
1542
+ deps.dataDir,
1543
+ {
1544
+ id: decision.id,
1545
+ ids: offeredIds(decision),
1546
+ harness: hostOf(deps),
1547
+ ...shownTo !== null ? { scope: offerScope(sessionId, shownTo.agentId) } : {}
1548
+ },
1549
+ now()
1550
+ );
1551
+ }
1552
+ const lead = accountLeadOf(decision);
1553
+ if (lead !== void 0) {
1554
+ await storeAccountOffer(deps.dataDir, lead, settingsHash);
1555
+ } else {
1556
+ const specs = decision.specs ?? [];
1557
+ await storeSpecs(
1558
+ deps.dataDir,
1559
+ specs.filter((spec) => !isAccountSpec(spec)),
1560
+ settingsHash
1561
+ );
1562
+ }
1440
1563
  if (isFree(decision) && decision.label !== void 0) {
1441
1564
  await storeLabel(deps.dataDir, decision.id, decision.label);
1442
1565
  }
@@ -1450,16 +1573,40 @@ async function openFooter(deps, sessionId, operation) {
1450
1573
  }
1451
1574
  };
1452
1575
  }
1576
+ function offeredIds(offer) {
1577
+ return [
1578
+ offer.id,
1579
+ ...(offer.specs ?? []).map((spec) => spec.id),
1580
+ ...offer.action === "discovered" ? (offer.choices?.options ?? []).map((o) => o.id) : []
1581
+ ];
1582
+ }
1583
+ async function sweepUntaken(deps, router, nativeScope) {
1584
+ const claimed = await claimIgnored(deps.dataDir, {
1585
+ now: deps.now?.() ?? Date.now(),
1586
+ ...nativeScope !== void 0 ? { nativeScope } : {}
1587
+ });
1588
+ if (claimed.length === 0) return;
1589
+ void reportIgnored(claimed, {
1590
+ ctx: hookContext(deps),
1591
+ baseUrl: resolveBaseUrl(deps, router.config),
1592
+ ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
1593
+ });
1594
+ }
1453
1595
  function hookOutcome(decision, unpaid) {
1596
+ if (isAccountOffer(decision)) return `account lookup offered (${decision.provider})`;
1454
1597
  if (isOffer(decision)) return `paid lookup offered (${termsOf(decision).provider})`;
1455
1598
  if (unpaid !== void 0 && (decision === null || decision.action === "native")) {
1456
1599
  return `fee unpaid: ${unpaid}`;
1457
1600
  }
1458
1601
  if (decision === null) return "native tools (router unavailable)";
1602
+ if (decision.action === "native" && decision.diagnostics.reasonCode === REQUIRES_UNMET) {
1603
+ return "native tools (offer needs newer tenjin)";
1604
+ }
1459
1605
  if (decision.action === "native") return "native tools (router chose native)";
1460
1606
  return "needs input";
1461
1607
  }
1462
- async function decide({ packet }, deps, config, sessionId, deadline, unpaid) {
1608
+ async function decide({ packet }, deps, router, sessionId, deadline, footer) {
1609
+ const { config } = router;
1463
1610
  const baseUrl = resolveBaseUrl(deps, config);
1464
1611
  const warn = deps.warn ?? ((line) => process.stderr.write(`${line}
1465
1612
  `));
@@ -1470,7 +1617,7 @@ async function decide({ packet }, deps, config, sessionId, deadline, unpaid) {
1470
1617
  warn(`tenjin hook: ${baseUrl} did not answer a moment ago, so the native tool runs (${left}s)`);
1471
1618
  return null;
1472
1619
  }
1473
- const route = await deps.route?.(baseUrl) ?? null;
1620
+ const route = deps.route?.(baseUrl);
1474
1621
  const outcome = await requestDecision(
1475
1622
  "hook",
1476
1623
  { packet, sessionId },
@@ -1479,32 +1626,36 @@ async function decide({ packet }, deps, config, sessionId, deadline, unpaid) {
1479
1626
  baseUrl,
1480
1627
  acceptsBazaar: resolveExperimentalBazaar(config).value === "on",
1481
1628
  harness: hostOf(deps),
1629
+ improve: router.settings.improve.value,
1482
1630
  timeoutMs: Math.max(0, deadline - now),
1631
+ // THE SAVED RULES RIDE BESIDE THE PACKET on every call, read for this
1632
+ // event: `routerFor` already refused rules this build cannot read.
1633
+ settings: router.wire.settings,
1483
1634
  ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {},
1484
- ...route !== null ? { route } : {}
1635
+ ...route !== void 0 ? { route } : {}
1485
1636
  }
1486
1637
  );
1487
- const deposited = route?.deposited?.() ?? 0n;
1488
- if (deposited > 0n) deps.notice?.(depositSentence(deposited));
1489
- const why = outcome.status === "skipped" ? outcome.why : outcome.freePath ?? (outcome.status === "decided" && isFeeRequired(outcome.decision) ? FEE_REQUIRED : void 0);
1490
- if (why !== void 0) unpaid?.(why);
1491
- const memoed = deps.route !== void 0 && route === null;
1492
- if (why !== void 0 && !(memoed && why === FEE_REQUIRED)) {
1493
- await tellOnce(deps, sessionId, why, now);
1494
- }
1495
- if (route !== null && outcome.status === "decided" && outcome.freePath === void 0) {
1496
- const cleared = await noticeCleared(deps.dataDir, sessionId, now).catch(() => null);
1497
- if (cleared !== null) deps.notice?.(cleared);
1638
+ for (const { id, missing } of outcome.status === "decided" ? outcome.skipped ?? [] : []) {
1639
+ warn(
1640
+ `tenjin hook: offer ${id} needs ${missing.join(", ")}, which this build lacks, so it was skipped`
1641
+ );
1498
1642
  }
1499
- if (outcome.status === "decided" && isFeeRequired(outcome.decision)) {
1500
- await clearRouterMemo(deps.dataDir, "paid-path-absent", baseUrl);
1643
+ if (route !== void 0 && deps.notice !== void 0) {
1644
+ const terms = await termsNotice(deps.dataDir);
1645
+ if (terms !== null) deps.notice(terms);
1501
1646
  }
1647
+ const deposited = (route?.deposited?.() ?? 0n) + (route?.toppedUp?.() ?? 0n);
1648
+ if (deposited > 0n) deps.notice?.(depositSentence(deposited));
1502
1649
  if (outcome.status === "skipped") {
1650
+ if (outcome.answered === true) await clearRouterMemo(deps.dataDir, "unreachable", baseUrl);
1651
+ footer.unpaid(outcome.why);
1652
+ await tellOnce(deps, sessionId, outcome.why, now, outcome.quotedAtomic);
1503
1653
  warn(`tenjin hook: the routing fee was not paid (${outcome.why}), so the native tool runs`);
1504
1654
  return null;
1505
1655
  }
1506
- if (outcome.freePath !== void 0) {
1507
- warn(`tenjin hook: the routing fee was not paid (${outcome.freePath}), so the free path ran`);
1656
+ if (outcome.status === "decided" && route?.paid?.() === true) {
1657
+ const cleared = await noticeCleared(deps.dataDir, sessionId, now).catch(() => null);
1658
+ if (cleared !== null) deps.notice?.(cleared);
1508
1659
  }
1509
1660
  if (outcome.status === "failed" && outcome.unreachable === true) {
1510
1661
  await writeRouterMemo(deps.dataDir, "unreachable", baseUrl, {
@@ -1516,13 +1667,22 @@ async function decide({ packet }, deps, config, sessionId, deadline, unpaid) {
1516
1667
  await clearRouterMemo(deps.dataDir, "unreachable", baseUrl);
1517
1668
  }
1518
1669
  if (outcome.status === "failed") {
1519
- warn(`tenjin hook: ${baseUrl}${route?.path ?? ROUTER_PATH} ${outcome.reason}`);
1670
+ warn(`tenjin hook: ${baseUrl}${ROUTE_PAID_PATH} ${outcome.reason}`);
1520
1671
  return null;
1521
1672
  }
1673
+ if (!decidedUnder(outcome.decision, router, warn)) return null;
1674
+ footer.answered(outcome.decision);
1522
1675
  return outcome.decision.decision;
1523
1676
  }
1524
- async function tellOnce(deps, sessionId, why, now) {
1525
- const sentence = unpaidSentence(why);
1677
+ function decidedUnder(answer, router, warn) {
1678
+ if (hashRefusal(router.wire, answer.settingsHash) === null) return true;
1679
+ warn(
1680
+ "tenjin hook: the router did not confirm it applied your Tenjin settings, so no lookup is offered"
1681
+ );
1682
+ return false;
1683
+ }
1684
+ async function tellOnce(deps, sessionId, why, now, quotedAtomic) {
1685
+ const sentence = unpaidSentence(why, "person", quotedAtomic);
1526
1686
  if (sentence === null || deps.notice === void 0) return;
1527
1687
  const told = await noticeFor(deps.dataDir, sessionId, why, now).catch(() => "quiet");
1528
1688
  if (told === "tell") deps.notice(sentence);
@@ -1556,12 +1716,24 @@ async function routerFor(cwd, deps) {
1556
1716
  { cwd: cwd ?? process.cwd(), dataDir: deps.dataDir, config },
1557
1717
  { warn: (line) => warn(`tenjin hook: ${line}`) }
1558
1718
  );
1559
- return settings.enabled.value ? { settings, config } : null;
1719
+ if (!settings.enabled.value) return null;
1720
+ if (settings.wire.status === "invalid") {
1721
+ warn(
1722
+ `tenjin hook: your Tenjin settings can't be read (${settings.wire.problem}), so nothing is routed`
1723
+ );
1724
+ return null;
1725
+ }
1726
+ return { settings, wire: settings.wire, config };
1560
1727
  } catch (err) {
1561
1728
  warn(`tenjin hook: ${err instanceof Error ? err.message : String(err)}, so the router is off`);
1562
1729
  return null;
1563
1730
  }
1564
1731
  }
1732
+ async function sealHere(packet, router, cwd, deps) {
1733
+ const inScope = scoped(packet, router.settings);
1734
+ const ownHosts = await ownHostsFor(inScope, cwd ?? process.cwd(), hostOf(deps), deps.homeDir);
1735
+ return seal(inScope, ownHosts.length > 0 ? { ownHosts } : {});
1736
+ }
1565
1737
  function scoped(packet, router) {
1566
1738
  return router.context.value === "turn" ? { ...packet, history: [] } : packet;
1567
1739
  }
@@ -1578,17 +1750,18 @@ function localSession(sessionId, deps) {
1578
1750
  // src/router/hook-command.ts
1579
1751
  var MAX_EVENT_BYTES = 1e6;
1580
1752
  var STDIN_TIMEOUT_MS = 1e3;
1581
- async function runHookCommand(kind, io, deps) {
1582
- let response;
1753
+ var STALE_HOOK_LINE = "Tenjin's hooks in this setup are from an older version and no longer route; your usual tools still work. Ask your agent to set Tenjin up again, updating Claude Code or Codex first if Tenjin needs a newer one.";
1754
+ async function runHookCommand(io, deps) {
1755
+ let response = null;
1583
1756
  try {
1584
- const raw = await (deps.readEvent ?? readStdin)();
1585
- const event = JSON.parse(raw);
1586
- if (deps.harness === "codex") {
1587
- const { codexResponse } = await import("./codex-event-ZO2GEFE6.js");
1588
- response = codexResponse(await runHookKind(kind, event, deps));
1589
- } else {
1590
- if (!launchedByPlugin(deps.env) && await sessionServedByPlugin(deps.dataDir, event)) return;
1591
- response = await runHookKind(kind, event, deps);
1757
+ const event = JSON.parse(await (deps.readEvent ?? readStdin)());
1758
+ if (deps.harness !== "codex" && !launchedByPlugin(deps.env) && await sessionServedByPlugin(deps.dataDir, event)) {
1759
+ return;
1760
+ }
1761
+ const sessionId = sessionIdOf(event);
1762
+ if (sessionId === null) return;
1763
+ if (await firstNoticeFor(deps.dataDir, sessionId, deps.now?.() ?? Date.now())) {
1764
+ response = { systemMessage: STALE_HOOK_LINE };
1592
1765
  }
1593
1766
  } catch {
1594
1767
  response = null;
@@ -1634,13 +1807,13 @@ function withNotices(response, notices) {
1634
1807
  return response === null || typeof response !== "object" ? { systemMessage } : { ...response, systemMessage };
1635
1808
  }
1636
1809
  async function readStdin() {
1637
- return new Promise((resolve, reject) => {
1810
+ return new Promise((resolve2, reject) => {
1638
1811
  const chunks = [];
1639
1812
  let size = 0;
1640
1813
  const timer = setTimeout(() => reject(new Error("no harness event")), STDIN_TIMEOUT_MS);
1641
1814
  const done = (value) => {
1642
1815
  clearTimeout(timer);
1643
- resolve(value);
1816
+ resolve2(value);
1644
1817
  };
1645
1818
  process.stdin.on("data", (chunk) => {
1646
1819
  size += chunk.length;
@@ -1660,18 +1833,10 @@ async function readStdin() {
1660
1833
  }
1661
1834
 
1662
1835
  export {
1663
- storeSpecs,
1664
- readSpec,
1665
- KeptChoicesSchema,
1666
- storeChoices,
1667
- readChoices,
1668
- claimSpecPayment,
1669
- settleSpecPayment,
1670
- storeFullResult,
1671
- GATE_TIMEOUT_MS,
1672
- DEPOSIT_GATE_TIMEOUT_MS,
1673
- STDIN_TIMEOUT_MS,
1836
+ buildPromptPacket,
1837
+ decideSwap,
1838
+ STALE_HOOK_LINE,
1674
1839
  runHookCommand,
1675
1840
  runHookKind
1676
1841
  };
1677
- //# sourceMappingURL=chunk-ZDZERB6L.js.map
1842
+ //# sourceMappingURL=chunk-5J4E5GYI.js.map