tenjin-cli 0.1.0-alpha.34 → 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 (332) hide show
  1. package/NOTICE.md +30 -0
  2. package/README.md +20 -18
  3. package/dist/{_esm-MMYV66AX.js → _esm-2KST7HQ7.js} +4 -4
  4. package/dist/{alive-VOIL5W3I.js → alive-5TV22PNF.js} +13 -13
  5. package/dist/{auth-UHD3QFX4.js → auth-XI7BJFLW.js} +4 -4
  6. package/dist/balance-DFHC6XEU.js +71 -0
  7. package/dist/{ccip-CS7K5QRQ.js → ccip-HOW3DZYF.js} +3 -3
  8. package/dist/{chunk-RJ5HRPAZ.js → chunk-24XKUN2S.js} +68 -10
  9. package/dist/chunk-24XKUN2S.js.map +1 -0
  10. package/dist/chunk-2L7TDGLV.js +56 -0
  11. package/dist/chunk-2L7TDGLV.js.map +1 -0
  12. package/dist/{chunk-PZHBPGDE.js → chunk-34SAECKZ.js} +34 -10
  13. package/dist/chunk-34SAECKZ.js.map +1 -0
  14. package/dist/{chunk-EQZ2CCWC.js → chunk-3Y2EHT4F.js} +5 -2
  15. package/dist/chunk-3Y2EHT4F.js.map +1 -0
  16. package/dist/{chunk-FSYH7J75.js → chunk-3Y6BHIN6.js} +3 -3
  17. package/dist/{chunk-FZZWTDWP.js → chunk-3YPL6T3P.js} +6 -6
  18. package/dist/{chunk-JEZMWJEF.js → chunk-44MVIRZH.js} +4 -4
  19. package/dist/{chunk-27FIHFXF.js → chunk-45MMSBHA.js} +5 -5
  20. package/dist/{chunk-QXP3Z3JN.js → chunk-4MBCJFY4.js} +35 -3
  21. package/dist/chunk-4MBCJFY4.js.map +1 -0
  22. package/dist/chunk-4TPL54KW.js +227 -0
  23. package/dist/chunk-4TPL54KW.js.map +1 -0
  24. package/dist/{chunk-7JB6SYJX.js → chunk-54ELBTKE.js} +2 -2
  25. package/dist/{chunk-6J64MQFD.js → chunk-5F4OB5B3.js} +21 -15
  26. package/dist/chunk-5F4OB5B3.js.map +1 -0
  27. package/dist/{chunk-PYVQ74D5.js → chunk-5HN4KVQU.js} +189 -117
  28. package/dist/chunk-5HN4KVQU.js.map +1 -0
  29. package/dist/{chunk-VFKPIIV2.js → chunk-5J4E5GYI.js} +35 -32
  30. package/dist/chunk-5J4E5GYI.js.map +1 -0
  31. package/dist/chunk-5USBZ2MU.js +58 -0
  32. package/dist/chunk-5USBZ2MU.js.map +1 -0
  33. package/dist/chunk-64WOMNYR.js +183 -0
  34. package/dist/chunk-64WOMNYR.js.map +1 -0
  35. package/dist/{chunk-APWELUI7.js → chunk-65RS4LQS.js} +57 -43
  36. package/dist/chunk-65RS4LQS.js.map +1 -0
  37. package/dist/{chunk-HWZO6HYZ.js → chunk-6QMDUDF2.js} +3 -3
  38. package/dist/{chunk-FNBGRKS6.js → chunk-7V25UAQO.js} +2 -2
  39. package/dist/chunk-BGA4DO5M.js +719 -0
  40. package/dist/chunk-BGA4DO5M.js.map +1 -0
  41. package/dist/chunk-BVP7YK2J.js +706 -0
  42. package/dist/chunk-BVP7YK2J.js.map +1 -0
  43. package/dist/chunk-C265QIMJ.js +83 -0
  44. package/dist/chunk-C265QIMJ.js.map +1 -0
  45. package/dist/{chunk-MXN2ZEUB.js → chunk-D6M3ZK66.js} +2 -2
  46. package/dist/chunk-D6M3ZK66.js.map +1 -0
  47. package/dist/chunk-DJ36BM62.js +78 -0
  48. package/dist/chunk-DJ36BM62.js.map +1 -0
  49. package/dist/{chunk-JOKPBYXP.js → chunk-DTEWAVNE.js} +2 -2
  50. package/dist/chunk-F2KJAJ7T.js +13 -0
  51. package/dist/chunk-F2KJAJ7T.js.map +1 -0
  52. package/dist/{chunk-KAILF7QA.js → chunk-F43CV6UC.js} +2 -2
  53. package/dist/{chunk-ACO7ZCR2.js → chunk-FKVJKLPI.js} +2 -2
  54. package/dist/{chunk-43HLS2HM.js → chunk-FYFHH7V5.js} +54 -3
  55. package/dist/{chunk-43HLS2HM.js.map → chunk-FYFHH7V5.js.map} +1 -1
  56. package/dist/{chunk-2F5JUAHZ.js → chunk-GAJC4BQZ.js} +3 -3
  57. package/dist/{chunk-L7N73ZAW.js → chunk-HAZAN4UM.js} +2 -2
  58. package/dist/{chunk-6QJZA6EX.js → chunk-HI5XQOX2.js} +2 -2
  59. package/dist/{chunk-BOENA6XR.js → chunk-HKGUKAQW.js} +6 -6
  60. package/dist/{chunk-LJSCGIYH.js → chunk-HPRVFJPM.js} +2 -2
  61. package/dist/{chunk-OO6FIBL7.js → chunk-HZKANST2.js} +3 -6
  62. package/dist/chunk-HZKANST2.js.map +1 -0
  63. package/dist/{chunk-UVDJ5SSQ.js → chunk-I557SAOM.js} +8 -2
  64. package/dist/chunk-I557SAOM.js.map +1 -0
  65. package/dist/{chunk-SDUOJRSV.js → chunk-IGLWLH73.js} +3 -3
  66. package/dist/{chunk-3AKH7ODX.js → chunk-INSIW65E.js} +5 -5
  67. package/dist/{chunk-PNHNXUSL.js → chunk-IULCDMVG.js} +12 -1
  68. package/dist/chunk-IULCDMVG.js.map +1 -0
  69. package/dist/{chunk-JF4T4HCQ.js → chunk-IVNSUAVC.js} +10 -5
  70. package/dist/chunk-IVNSUAVC.js.map +1 -0
  71. package/dist/chunk-JDQZCREI.js +87 -0
  72. package/dist/chunk-JDQZCREI.js.map +1 -0
  73. package/dist/{chunk-2P3NJTHE.js → chunk-JHFFUVON.js} +23 -23
  74. package/dist/{chunk-7JVARP5R.js → chunk-JTILUN4W.js} +55 -29
  75. package/dist/{chunk-7JVARP5R.js.map → chunk-JTILUN4W.js.map} +1 -1
  76. package/dist/{chunk-2TO5F6CT.js → chunk-K5KNGC4I.js} +8 -8
  77. package/dist/{chunk-HUWTFKEM.js → chunk-KAQ4Q3TO.js} +3 -3
  78. package/dist/{chunk-E6VP6MQM.js → chunk-KGUE5AVX.js} +4 -4
  79. package/dist/chunk-KGUE5AVX.js.map +1 -0
  80. package/dist/{chunk-GS5RZF7U.js → chunk-KLDMLWXT.js} +2 -2
  81. package/dist/{chunk-HN2EN6P4.js → chunk-KNKDMTHU.js} +5 -5
  82. package/dist/chunk-LDA6TAYQ.js +95 -0
  83. package/dist/chunk-LDA6TAYQ.js.map +1 -0
  84. package/dist/chunk-LWSSIZOY.js +347 -0
  85. package/dist/chunk-LWSSIZOY.js.map +1 -0
  86. package/dist/{chunk-5VWQSCDO.js → chunk-MAHNZA6C.js} +89 -9
  87. package/dist/chunk-MAHNZA6C.js.map +1 -0
  88. package/dist/{chunk-46HAB26L.js → chunk-MEWZCIA6.js} +56 -9
  89. package/dist/chunk-MEWZCIA6.js.map +1 -0
  90. package/dist/{chunk-R2KMLONN.js → chunk-MJDO4EXD.js} +4 -4
  91. package/dist/{chunk-IHVUE3XF.js → chunk-NJA6NT3A.js} +3 -3
  92. package/dist/{chunk-TSIID2LV.js → chunk-ODRPASFP.js} +375 -1166
  93. package/dist/chunk-ODRPASFP.js.map +1 -0
  94. package/dist/{chunk-S3JKF3IK.js → chunk-OJJFANO6.js} +3 -3
  95. package/dist/{chunk-56SOPRM2.js → chunk-OQWPRFAC.js} +344 -4
  96. package/dist/chunk-OQWPRFAC.js.map +1 -0
  97. package/dist/{chunk-QEZZDIQT.js → chunk-P6YQWIT2.js} +4053 -4039
  98. package/dist/chunk-P6YQWIT2.js.map +1 -0
  99. package/dist/{chunk-GGGEGMWC.js → chunk-Q6RSJCXB.js} +9 -9
  100. package/dist/{chunk-OTIUEUIS.js → chunk-QKEUKBRK.js} +7 -7
  101. package/dist/{chunk-X52BVGCJ.js → chunk-QQDPRTLP.js} +5 -5
  102. package/dist/chunk-QQYCYAKI.js +79 -0
  103. package/dist/chunk-QQYCYAKI.js.map +1 -0
  104. package/dist/chunk-R4KDH477.js +1064 -0
  105. package/dist/chunk-R4KDH477.js.map +1 -0
  106. package/dist/{chunk-6AQSUBNR.js → chunk-RGCPELQN.js} +2 -2
  107. package/dist/{chunk-AXODGQ23.js → chunk-RGVCOG2S.js} +9 -2
  108. package/dist/{chunk-AXODGQ23.js.map → chunk-RGVCOG2S.js.map} +1 -1
  109. package/dist/chunk-SOLNJ3AZ.js +209 -0
  110. package/dist/chunk-SOLNJ3AZ.js.map +1 -0
  111. package/dist/{chunk-LQ33RLHL.js → chunk-TFT2X7SH.js} +3 -3
  112. package/dist/chunk-TVWCLUBI.js +293 -0
  113. package/dist/chunk-TVWCLUBI.js.map +1 -0
  114. package/dist/{chunk-VH7JMLTG.js → chunk-UIB33QQP.js} +25 -16
  115. package/dist/chunk-UIB33QQP.js.map +1 -0
  116. package/dist/chunk-V6GIVALQ.js +1889 -0
  117. package/dist/chunk-V6GIVALQ.js.map +1 -0
  118. package/dist/{chunk-IVHGQNIN.js → chunk-VHXCPXUS.js} +8 -8
  119. package/dist/{chunk-7DW7GAM6.js → chunk-VU6GMWF6.js} +2 -2
  120. package/dist/chunk-VWZYE3NC.js +8415 -0
  121. package/dist/chunk-VWZYE3NC.js.map +1 -0
  122. package/dist/{chunk-3X4GOMXT.js → chunk-W2GXIARJ.js} +12 -7
  123. package/dist/chunk-W2GXIARJ.js.map +1 -0
  124. package/dist/chunk-W4G3K3V7.js +288 -0
  125. package/dist/chunk-W4G3K3V7.js.map +1 -0
  126. package/dist/{chunk-FHXTEVO7.js → chunk-W74LJ5OT.js} +21 -28
  127. package/dist/chunk-W74LJ5OT.js.map +1 -0
  128. package/dist/{chunk-FOEPH67T.js → chunk-W7ELYLYK.js} +1 -74
  129. package/dist/chunk-W7ELYLYK.js.map +1 -0
  130. package/dist/{chunk-YU3DLVSQ.js → chunk-XSCGUO2U.js} +5 -5
  131. package/dist/{chunk-EPCIJLLU.js → chunk-XWROSMI5.js} +9 -9
  132. package/dist/{chunk-HMT6L65V.js → chunk-YJGEVBKZ.js} +4 -4
  133. package/dist/{chunk-7U3P4PB7.js → chunk-ZEYA2WWX.js} +4 -4
  134. package/dist/chunk-ZEYA2WWX.js.map +1 -0
  135. package/dist/chunk-ZRC7Z5X3.js +82 -0
  136. package/dist/chunk-ZRC7Z5X3.js.map +1 -0
  137. package/dist/{chunk-I47ARU5G.js → chunk-ZS7JIUJ3.js} +2 -2
  138. package/dist/{claude-cli-2YKABJJZ.js → claude-cli-GIIHOBGT.js} +4 -2
  139. package/dist/claude-install-BAUSJMW3.js +64 -0
  140. package/dist/{cli-BFDKEX53.js → cli-QY4KKA3D.js} +116 -49
  141. package/dist/cli-QY4KKA3D.js.map +1 -0
  142. package/dist/{client-XMWEKXX7.js → client-3YQKORVK.js} +4 -4
  143. package/dist/{codex-host-B6NAUWL6.js → codex-host-ZON3S6HU.js} +5 -5
  144. package/dist/{codex-install-GTGO5FYN.js → codex-install-HZV2DOAB.js} +62 -47
  145. package/dist/codex-install-HZV2DOAB.js.map +1 -0
  146. package/dist/{config-THJANIU5.js → config-QZOBMTEL.js} +18 -18
  147. package/dist/{config-names-JU54HYWY.js → config-names-Z5NZD5R2.js} +18 -18
  148. package/dist/{config-rules-VNU23RL4.js → config-rules-YOYHS6YL.js} +19 -19
  149. package/dist/config-subagents-WQV2ZAD5.js +362 -0
  150. package/dist/config-subagents-WQV2ZAD5.js.map +1 -0
  151. package/dist/{connect-HPWS7U63.js → connect-YDWTYU4B.js} +28 -27
  152. package/dist/{connect-HPWS7U63.js.map → connect-YDWTYU4B.js.map} +1 -1
  153. package/dist/core-0a66n3e7-TTP554XV.js +127 -0
  154. package/dist/core-0a66n3e7-TTP554XV.js.map +1 -0
  155. package/dist/core-0bmnpbz2-C2JIRVZO.js +10790 -0
  156. package/dist/core-0bmnpbz2-C2JIRVZO.js.map +1 -0
  157. package/dist/core-9je8ee1j-74DGHWPV.js +30 -0
  158. package/dist/core-9je8ee1j-74DGHWPV.js.map +1 -0
  159. package/dist/core-wadgcjfh-TSZFQZGH.js +666 -0
  160. package/dist/core-wadgcjfh-TSZFQZGH.js.map +1 -0
  161. package/dist/core-zg882d22-LKV5DZYW.js +37 -0
  162. package/dist/core-zg882d22-LKV5DZYW.js.map +1 -0
  163. package/dist/{decision-JIIHDTOF.js → decision-QSKHOGCO.js} +6 -6
  164. package/dist/{doctor-4MMHBRDU.js → doctor-ZWJXRD75.js} +67 -66
  165. package/dist/doctor-ZWJXRD75.js.map +1 -0
  166. package/dist/{explicit-AGENAX6E.js → explicit-ME2NRADQ.js} +45 -42
  167. package/dist/{explicit-AGENAX6E.js.map → explicit-ME2NRADQ.js.map} +1 -1
  168. package/dist/flush-stdio-NYIJ3QXT.js +18 -0
  169. package/dist/{fund-MLXUH24Q.js → fund-VF7TLDJH.js} +110 -34
  170. package/dist/fund-VF7TLDJH.js.map +1 -0
  171. package/dist/{hook-command-UB7FOEUL.js → hook-command-VZ27MGWO.js} +21 -20
  172. package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
  173. package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +2 -2
  174. package/dist/hosts/claude/tenjin/hooks/hook-data.ts +152 -0
  175. package/dist/hosts/claude/tenjin/hooks/hooks.json +7 -0
  176. package/dist/hosts/claude/tenjin/hooks/model-viewer.tsx +2987 -0
  177. package/dist/hosts/claude/tenjin/hooks/register.tsx +265 -30
  178. package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +14 -4
  179. package/dist/hosts/claude/tenjin/types/index.d.ts +133 -0
  180. package/dist/{hosts-WNQKYKP2.js → hosts-3EMTVM4H.js} +5 -3
  181. package/dist/index.js +16 -13
  182. package/dist/index.js.map +1 -1
  183. package/dist/{install-Q5SHHEDH.js → install-ZA7L2UF3.js} +34 -30
  184. package/dist/{install-funding-EGSW2KEP.js → install-funding-JDGYTF72.js} +9 -13
  185. package/dist/{install-identity-OID43B4D.js → install-identity-FFAYEFLX.js} +8 -8
  186. package/dist/{install-wallet-TZFWY5GK.js → install-wallet-2SFOVE3Q.js} +48 -33
  187. package/dist/{install-wallet-TZFWY5GK.js.map → install-wallet-2SFOVE3Q.js.map} +1 -1
  188. package/dist/mcp-36S6MK3C.js +67642 -0
  189. package/dist/mcp-36S6MK3C.js.map +1 -0
  190. package/dist/new-install-5L4GY3LN.js +51 -0
  191. package/dist/{package-NRHU7HBR.js → package-BONDXSV3.js} +2 -2
  192. package/dist/{passphrase-3JEVW5XG.js → passphrase-T4ULBN4M.js} +4 -4
  193. package/dist/{pay-I47AIUQR.js → pay-CMV5KL74.js} +37 -30
  194. package/dist/{payments-A5FNI5GN.js → payments-Z6UBZL4Z.js} +10 -10
  195. package/dist/reclaim-subagent-credit-ABSF67SJ.js +105 -0
  196. package/dist/reclaim-subagent-credit-ABSF67SJ.js.map +1 -0
  197. package/dist/{routing-quote-QQW2I5MH.js → routing-quote-AHLAREXR.js} +16 -18
  198. package/dist/{run-4SHEOBIU.js → run-JH7ELYAM.js} +41 -38
  199. package/dist/{runtime-BABJMHY7.js → runtime-2GX4ALJP.js} +12 -12
  200. package/dist/{runtime-activate-N6VLQI2C.js → runtime-activate-IDQ2NCSP.js} +9 -9
  201. package/dist/{runtime-launchers-GMAUICRW.js → runtime-launchers-YAPKCBHV.js} +7 -7
  202. package/dist/{runtime-place-DOEWFTF3.js → runtime-place-4POL4KK4.js} +3 -3
  203. package/dist/{send-ECXS6JEO.js → send-ELXFKEKY.js} +17 -17
  204. package/dist/{status-AHE5HSR7.js → status-FXUFWJDM.js} +89 -36
  205. package/dist/status-FXUFWJDM.js.map +1 -0
  206. package/dist/{status-line-63XFJAXR.js → status-line-IH5JBWBC.js} +11 -11
  207. package/dist/{streamableHttp-Z3YF6LTQ.js → streamableHttp-CP2ZQBIK.js} +4 -4
  208. package/dist/{uninstall-YGQPRCVY.js → uninstall-LJZUKM4D.js} +42 -38
  209. package/dist/{uninstall-YGQPRCVY.js.map → uninstall-LJZUKM4D.js.map} +1 -1
  210. package/dist/{update-GTLMLFA3.js → update-EUIX72IX.js} +34 -30
  211. package/dist/{usage-FCWP2CHO.js → usage-EKDC7LUC.js} +13 -13
  212. package/dist/{usdc-25RNBYYR.js → usdc-YIHK2OMC.js} +5 -5
  213. package/dist/{viemAdapter-By13KInL-3CG63XDX.js → viemAdapter-By13KInL-PRLSIESK.js} +2 -2
  214. package/dist/viemAdapter-By13KInL-PRLSIESK.js.map +1 -0
  215. package/dist/wallet-HSW757W6.js +80 -0
  216. package/dist/wallet-HSW757W6.js.map +1 -0
  217. package/docs/agent-permissions.md +19 -11
  218. package/docs/router-reference.md +21 -12
  219. package/docs/safety-model.md +4 -2
  220. package/docs/subagents-internals.md +97 -0
  221. package/docs/subagents.md +348 -0
  222. package/package.json +4 -1
  223. package/dist/balance-RQW5T5FB.js +0 -55
  224. package/dist/chunk-3X4GOMXT.js.map +0 -1
  225. package/dist/chunk-46HAB26L.js.map +0 -1
  226. package/dist/chunk-56SOPRM2.js.map +0 -1
  227. package/dist/chunk-5VWQSCDO.js.map +0 -1
  228. package/dist/chunk-6J64MQFD.js.map +0 -1
  229. package/dist/chunk-7U3P4PB7.js.map +0 -1
  230. package/dist/chunk-APWELUI7.js.map +0 -1
  231. package/dist/chunk-E6VP6MQM.js.map +0 -1
  232. package/dist/chunk-EQZ2CCWC.js.map +0 -1
  233. package/dist/chunk-FHXTEVO7.js.map +0 -1
  234. package/dist/chunk-FOEPH67T.js.map +0 -1
  235. package/dist/chunk-IVXPIIZJ.js +0 -91
  236. package/dist/chunk-IVXPIIZJ.js.map +0 -1
  237. package/dist/chunk-JF4T4HCQ.js.map +0 -1
  238. package/dist/chunk-LPQNZKSG.js +0 -269
  239. package/dist/chunk-LPQNZKSG.js.map +0 -1
  240. package/dist/chunk-MXN2ZEUB.js.map +0 -1
  241. package/dist/chunk-OO6FIBL7.js.map +0 -1
  242. package/dist/chunk-PNHNXUSL.js.map +0 -1
  243. package/dist/chunk-PYVQ74D5.js.map +0 -1
  244. package/dist/chunk-PZHBPGDE.js.map +0 -1
  245. package/dist/chunk-QEZZDIQT.js.map +0 -1
  246. package/dist/chunk-QXP3Z3JN.js.map +0 -1
  247. package/dist/chunk-RJ5HRPAZ.js.map +0 -1
  248. package/dist/chunk-TSIID2LV.js.map +0 -1
  249. package/dist/chunk-UVDJ5SSQ.js.map +0 -1
  250. package/dist/chunk-VFKPIIV2.js.map +0 -1
  251. package/dist/chunk-VH7JMLTG.js.map +0 -1
  252. package/dist/claude-install-7CVYQ73E.js +0 -60
  253. package/dist/cli-BFDKEX53.js.map +0 -1
  254. package/dist/codex-install-GTGO5FYN.js.map +0 -1
  255. package/dist/doctor-4MMHBRDU.js.map +0 -1
  256. package/dist/fund-MLXUH24Q.js.map +0 -1
  257. package/dist/mcp-CC3H7LFO.js +0 -3655
  258. package/dist/mcp-CC3H7LFO.js.map +0 -1
  259. package/dist/status-AHE5HSR7.js.map +0 -1
  260. package/dist/wallet-CJGEHP2Q.js +0 -64
  261. /package/dist/{_esm-MMYV66AX.js.map → _esm-2KST7HQ7.js.map} +0 -0
  262. /package/dist/{alive-VOIL5W3I.js.map → alive-5TV22PNF.js.map} +0 -0
  263. /package/dist/{auth-UHD3QFX4.js.map → auth-XI7BJFLW.js.map} +0 -0
  264. /package/dist/{balance-RQW5T5FB.js.map → balance-DFHC6XEU.js.map} +0 -0
  265. /package/dist/{ccip-CS7K5QRQ.js.map → ccip-HOW3DZYF.js.map} +0 -0
  266. /package/dist/{chunk-FSYH7J75.js.map → chunk-3Y6BHIN6.js.map} +0 -0
  267. /package/dist/{chunk-FZZWTDWP.js.map → chunk-3YPL6T3P.js.map} +0 -0
  268. /package/dist/{chunk-JEZMWJEF.js.map → chunk-44MVIRZH.js.map} +0 -0
  269. /package/dist/{chunk-27FIHFXF.js.map → chunk-45MMSBHA.js.map} +0 -0
  270. /package/dist/{chunk-7JB6SYJX.js.map → chunk-54ELBTKE.js.map} +0 -0
  271. /package/dist/{chunk-HWZO6HYZ.js.map → chunk-6QMDUDF2.js.map} +0 -0
  272. /package/dist/{chunk-FNBGRKS6.js.map → chunk-7V25UAQO.js.map} +0 -0
  273. /package/dist/{chunk-JOKPBYXP.js.map → chunk-DTEWAVNE.js.map} +0 -0
  274. /package/dist/{chunk-KAILF7QA.js.map → chunk-F43CV6UC.js.map} +0 -0
  275. /package/dist/{chunk-ACO7ZCR2.js.map → chunk-FKVJKLPI.js.map} +0 -0
  276. /package/dist/{chunk-2F5JUAHZ.js.map → chunk-GAJC4BQZ.js.map} +0 -0
  277. /package/dist/{chunk-L7N73ZAW.js.map → chunk-HAZAN4UM.js.map} +0 -0
  278. /package/dist/{chunk-6QJZA6EX.js.map → chunk-HI5XQOX2.js.map} +0 -0
  279. /package/dist/{chunk-BOENA6XR.js.map → chunk-HKGUKAQW.js.map} +0 -0
  280. /package/dist/{chunk-LJSCGIYH.js.map → chunk-HPRVFJPM.js.map} +0 -0
  281. /package/dist/{chunk-SDUOJRSV.js.map → chunk-IGLWLH73.js.map} +0 -0
  282. /package/dist/{chunk-3AKH7ODX.js.map → chunk-INSIW65E.js.map} +0 -0
  283. /package/dist/{chunk-2P3NJTHE.js.map → chunk-JHFFUVON.js.map} +0 -0
  284. /package/dist/{chunk-2TO5F6CT.js.map → chunk-K5KNGC4I.js.map} +0 -0
  285. /package/dist/{chunk-HUWTFKEM.js.map → chunk-KAQ4Q3TO.js.map} +0 -0
  286. /package/dist/{chunk-GS5RZF7U.js.map → chunk-KLDMLWXT.js.map} +0 -0
  287. /package/dist/{chunk-HN2EN6P4.js.map → chunk-KNKDMTHU.js.map} +0 -0
  288. /package/dist/{chunk-R2KMLONN.js.map → chunk-MJDO4EXD.js.map} +0 -0
  289. /package/dist/{chunk-IHVUE3XF.js.map → chunk-NJA6NT3A.js.map} +0 -0
  290. /package/dist/{chunk-S3JKF3IK.js.map → chunk-OJJFANO6.js.map} +0 -0
  291. /package/dist/{chunk-GGGEGMWC.js.map → chunk-Q6RSJCXB.js.map} +0 -0
  292. /package/dist/{chunk-OTIUEUIS.js.map → chunk-QKEUKBRK.js.map} +0 -0
  293. /package/dist/{chunk-X52BVGCJ.js.map → chunk-QQDPRTLP.js.map} +0 -0
  294. /package/dist/{chunk-6AQSUBNR.js.map → chunk-RGCPELQN.js.map} +0 -0
  295. /package/dist/{chunk-LQ33RLHL.js.map → chunk-TFT2X7SH.js.map} +0 -0
  296. /package/dist/{chunk-IVHGQNIN.js.map → chunk-VHXCPXUS.js.map} +0 -0
  297. /package/dist/{chunk-7DW7GAM6.js.map → chunk-VU6GMWF6.js.map} +0 -0
  298. /package/dist/{chunk-YU3DLVSQ.js.map → chunk-XSCGUO2U.js.map} +0 -0
  299. /package/dist/{chunk-EPCIJLLU.js.map → chunk-XWROSMI5.js.map} +0 -0
  300. /package/dist/{chunk-HMT6L65V.js.map → chunk-YJGEVBKZ.js.map} +0 -0
  301. /package/dist/{chunk-I47ARU5G.js.map → chunk-ZS7JIUJ3.js.map} +0 -0
  302. /package/dist/{claude-cli-2YKABJJZ.js.map → claude-cli-GIIHOBGT.js.map} +0 -0
  303. /package/dist/{claude-install-7CVYQ73E.js.map → claude-install-BAUSJMW3.js.map} +0 -0
  304. /package/dist/{client-XMWEKXX7.js.map → client-3YQKORVK.js.map} +0 -0
  305. /package/dist/{codex-host-B6NAUWL6.js.map → codex-host-ZON3S6HU.js.map} +0 -0
  306. /package/dist/{config-THJANIU5.js.map → config-QZOBMTEL.js.map} +0 -0
  307. /package/dist/{config-names-JU54HYWY.js.map → config-names-Z5NZD5R2.js.map} +0 -0
  308. /package/dist/{config-rules-VNU23RL4.js.map → config-rules-YOYHS6YL.js.map} +0 -0
  309. /package/dist/{decision-JIIHDTOF.js.map → decision-QSKHOGCO.js.map} +0 -0
  310. /package/dist/{hook-command-UB7FOEUL.js.map → flush-stdio-NYIJ3QXT.js.map} +0 -0
  311. /package/dist/{hosts-WNQKYKP2.js.map → hook-command-VZ27MGWO.js.map} +0 -0
  312. /package/dist/{install-Q5SHHEDH.js.map → hosts-3EMTVM4H.js.map} +0 -0
  313. /package/dist/{install-funding-EGSW2KEP.js.map → install-ZA7L2UF3.js.map} +0 -0
  314. /package/dist/{install-identity-OID43B4D.js.map → install-funding-JDGYTF72.js.map} +0 -0
  315. /package/dist/{package-NRHU7HBR.js.map → install-identity-FFAYEFLX.js.map} +0 -0
  316. /package/dist/{passphrase-3JEVW5XG.js.map → new-install-5L4GY3LN.js.map} +0 -0
  317. /package/dist/{pay-I47AIUQR.js.map → package-BONDXSV3.js.map} +0 -0
  318. /package/dist/{routing-quote-QQW2I5MH.js.map → passphrase-T4ULBN4M.js.map} +0 -0
  319. /package/dist/{run-4SHEOBIU.js.map → pay-CMV5KL74.js.map} +0 -0
  320. /package/dist/{payments-A5FNI5GN.js.map → payments-Z6UBZL4Z.js.map} +0 -0
  321. /package/dist/{runtime-activate-N6VLQI2C.js.map → routing-quote-AHLAREXR.js.map} +0 -0
  322. /package/dist/{runtime-launchers-GMAUICRW.js.map → run-JH7ELYAM.js.map} +0 -0
  323. /package/dist/{runtime-BABJMHY7.js.map → runtime-2GX4ALJP.js.map} +0 -0
  324. /package/dist/{runtime-place-DOEWFTF3.js.map → runtime-activate-IDQ2NCSP.js.map} +0 -0
  325. /package/dist/{update-GTLMLFA3.js.map → runtime-launchers-YAPKCBHV.js.map} +0 -0
  326. /package/dist/{usdc-25RNBYYR.js.map → runtime-place-4POL4KK4.js.map} +0 -0
  327. /package/dist/{send-ECXS6JEO.js.map → send-ELXFKEKY.js.map} +0 -0
  328. /package/dist/{status-line-63XFJAXR.js.map → status-line-IH5JBWBC.js.map} +0 -0
  329. /package/dist/{streamableHttp-Z3YF6LTQ.js.map → streamableHttp-CP2ZQBIK.js.map} +0 -0
  330. /package/dist/{viemAdapter-By13KInL-3CG63XDX.js.map → update-EUIX72IX.js.map} +0 -0
  331. /package/dist/{usage-FCWP2CHO.js.map → usage-EKDC7LUC.js.map} +0 -0
  332. /package/dist/{wallet-CJGEHP2Q.js.map → usdc-YIHK2OMC.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/router/decision.ts"],"sourcesContent":["import { z } from 'zod';\nimport { isLoopbackHost } from '../lib/destination';\nimport { fetchFailureToCliError, httpRequest, MAX_BINARY_BODY_BYTES } from '../lib/http';\nimport type { FetchJsonFailure, HttpRequestOptions, HttpResult } from '../lib/http';\nimport type { CommandContext } from '../context';\nimport type { Packet } from './context';\nimport type { Harness } from './names';\nimport {\n BUILT_IN_SOURCE,\n SETTINGS_ACCEPT,\n SettingsHashSchema,\n TargetIdSchema,\n type WireSettings,\n} from './settings-wire';\n\n/**\n * ONE ROUTING PATH, ONE DECISION PER LOOKUP. Every routing call, the hook's\n * and the `request` tool's, goes to the paid route ({@link ROUTE_PAID_PATH}).\n * Inside `tenjin mcp` the payer sends it through the stock x402 client and\n * pays the routing fee its 402 quotes ({@link DecisionRoute},\n * `routing-payer.ts`); a call it cannot pay is skipped, with no request to any\n * other route. One whose channel needs a deposit waits for the payer's\n * background top-up inside its budget first. The free route ({@link ROUTER_PATH}) keeps only what stays free:\n * browse, a browse row's spec and the outcome report.\n *\n * The backend answers with what it would do and what the provider charges,\n * and the provider is paid by `runPay`, from a spec, under the local spend\n * policy. The bounded packet travels with the hook request and the backend\n * keeps it against the decision id until that id expires. What this client\n * keeps is each offer's spec, by its id (`specs.ts`).\n */\n\n/** The free route: browse, a browse row's spec, and the outcome report. */\nexport const ROUTER_PATH = '/api/x402-router';\n/** The paid route, behind x402: every routing call. */\nexport const ROUTE_PAID_PATH = '/api/x402-router/route';\n\n/**\n * The request the server builds and this client sends verbatim. Query assembly,\n * body encoding and header choice are the server's; what stays here is every\n * check that decides whether to send it at all.\n */\nconst RequestSchema = z.object({\n url: z.string().min(1).max(16_384),\n method: z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']),\n headers: z.record(z.string(), z.string()),\n body: z\n .string()\n .max(256 * 1024)\n .optional(),\n});\n\nconst ContractSchema = z.object({\n /** Flat, for display and for the result check; never re-encoded into a call:\n * the server built `request` from them and this client sends that verbatim. */\n arguments: z.record(z.string(), z.unknown()).optional(),\n resultSchema: z.record(z.string(), z.unknown()).optional(),\n request: RequestSchema,\n});\nexport type DecisionContract = z.infer<typeof ContractSchema>;\n\n/**\n * What stopped an outcome this client cannot execute, in terms the host can act\n * on: a stable reason code, the stage that stopped, the fields or scope choices\n * the user can supply, and one concrete next action.\n */\nconst DiagnosticsSchema = z.object({\n reasonCode: z.string().min(1).max(64),\n stage: z.string().min(1).max(32),\n missing: z.array(z.string().max(200)).max(60),\n nextAction: z.string().max(500),\n});\nexport type DecisionDiagnostics = z.infer<typeof DiagnosticsSchema>;\n\n/**\n * ONE VARIANT PER ANSWER, DISCRIMINATED ON THE ACTION. Optional fields made\n * every shape legal: an `execute` with no contract parsed and came back to the\n * host as a routine `needs_input`, and a non-execute with no diagnostics\n * parsed with nothing to act on. Each of those is drift the shared fixtures\n * exist to catch, so each is a parse failure that names itself.\n *\n * A TOLERANT READER, AND ONLY THAT (RFC 9413). A field this build does not\n * know is dropped, never a failure: a server that adds one reaches every\n * released client without a release or a deploy order. A field it does know\n * keeps its type, its bounds and its checks, and a job's `pollUrl` or\n * `running` naming the keys of both its arms is still refused (an answer's\n * own arms are told apart by `action`). An offer that a client\n * must understand to run says so in `requires` ({@link withoutUnmet}).\n *\n * The two calls ask different questions and get different answers, so they get\n * different parsers. The HOOK asks whether a paid lookup is worth offering: an\n * id, or a reason it is not. The TOOL asks for the decision: the capability,\n * its price and the contract together, so a caller cannot approve one offer and\n * receive another.\n */\nconst IdSchema = z\n .string()\n .regex(/^[A-Za-z0-9_-]{8,64}$/)\n .describe(\n 'The turn id, an OPAQUE HANDLE: it is the one piece of server text this ' +\n 'client puts in a model-facing line, so the alphabet is pinned here ' +\n 'rather than escaped later.',\n );\n\n/** Every non-execute answer carries these, beside the action they explain. */\nconst RefusedSchema = z.object({\n reason: z.string().max(2_000).optional(),\n diagnostics: DiagnosticsSchema,\n});\n\n/**\n * WHAT THE SERVICE IS, AND WHAT IT DOES. The hook answer used to be an id and\n * nothing else, so the line the host injected could only say \"a paid lookup is\n * available\", which a model follows 8 to 20 times in 40 where a line naming the\n * task and the service is followed 40 in 40. The gate knows which capability\n * serves the category it chose, so it now says so; the CONTRACT is still not\n * here, because the task the host will run does not exist yet.\n */\n/** A display name the server gives a capability, sent because this build\n * lists `label`. Shown exactly as given; absent, a surface says\n * {@link UNLABELLED}. */\nconst LabelSchema = z.string().min(1).max(32);\n\n/** What a surface names a lookup whose decision carries no `label`. */\nexport const UNLABELLED = 'Tenjin lookup';\n\n/**\n * WHAT AN OFFER NEEDS THIS CLIENT TO UNDERSTAND, in the `accepts` vocabulary,\n * on an offering answer or on any spec: a must-understand list, like JWS\n * `crit` (RFC 7515 §4.1.11). The tolerant reader drops a field it does not\n * know, which is right for a field a client may ignore and wrong for one that\n * changes what a call is (a header it must send, a new kind of payment). Such\n * an offer names that feature here, and a build without it skips that offer\n * alone, by name, rather than run it half understood ({@link withoutUnmet}).\n * The same bounds as `accepts`, with the alphabet pinned: a token is named\n * in the model's text when its offer is skipped.\n */\nconst RequiresSchema = z\n .array(z.string().regex(/^[a-z][a-z0-9_-]{0,31}$/))\n .max(16)\n .optional();\n\nconst CapabilityFields = {\n capabilityId: z.string().min(1).max(200),\n category: z.string().min(1).max(64),\n /** The service's own name, not the x402 reseller in front of it. */\n provider: z.string().min(1).max(120),\n label: LabelSchema.optional(),\n capabilityDescription: z.string().min(1).max(500),\n /** What the provider charges, atomic USDC. The `request` tool refuses a live\n * 402 above it; `gateSpend` still caps the amount actually signed. */\n providerPriceAtomic: z.string().regex(/^\\d+$/),\n requires: RequiresSchema,\n};\n\n/**\n * STRUCTURE, NEVER WORDING. A hint lands in the model's context verbatim, so\n * its shape is checked the way the id's alphabet is: one line, no control\n * characters, and it has to be the call it claims to be, naming the id this\n * same answer carries. A hint that fails any of these is a protocol error and\n * the turn falls back to the generic line; nothing here rewrites a word of a\n * hint that passes. Both offering arms, `execute` and `discovered`, hold it.\n */\nfunction checkHint(decision: { id: string; hint: string }, ctx: z.RefinementCtx): void {\n if (/[\\p{Cc}\\p{Cf}]/u.test(decision.hint)) {\n ctx.addIssue({ code: 'custom', path: ['hint'], message: 'a hint is one plain line' });\n }\n if (!decision.hint.includes('request({')) {\n ctx.addIssue({ code: 'custom', path: ['hint'], message: 'a hint names the call to make' });\n }\n if (!decision.hint.includes(decision.id)) {\n ctx.addIssue({\n code: 'custom',\n path: ['hint'],\n message: \"a hint carries this answer's own id\",\n });\n }\n}\n\n/**\n * A PAY-PER-CALL SERVICE NOBODY CURATED. When a Tenjin list service does the\n * task the gate picked, or no task fits and a listed x402 service could do the\n * step, the server names that one service: who sells it, where, for how much,\n * and the input it takes. A Tenjin list service arrives here under its catalog\n * id, because this build sends `catalog`. The candidate is the seller's own\n * listing, so every field is data for the host to judge, never an instruction;\n * the host builds the `input` and the tool call pays through the same `runPay`\n * path and caps as a curated lookup.\n */\nconst DiscoveredCandidateSchema = z.object({\n source: z.string().min(1).max(64),\n provider: z.string().min(1).max(120),\n url: z.string().min(1).max(2_048),\n method: z.enum(['GET', 'POST']),\n description: z.string().max(500),\n providerPriceAtomic: z.string().regex(/^\\d+$/),\n network: z.string().min(1).max(64),\n payTo: z.string().min(1).max(200),\n input: z.object({\n location: z.enum(['body', 'query']),\n schema: z.record(z.string(), z.unknown()),\n }),\n});\n\n/** A key that belongs to another arm of the same union. The tolerant reader\n * drops a key it does not know; this one it knows, so an object naming the\n * keys of both arms is refused rather than read as whichever arm is first. */\nconst OtherArm = z.never().optional();\n\n/** A field name a job reads from an answer or writes into a poll body. */\nconst JobField = z.string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,63}$/);\n\n/** A body field whose value names a state: Treza's `status: \"running\"`. */\nconst JobFieldStateSchema = z.object({\n field: JobField,\n values: z.array(z.string().min(1).max(64)).min(1).max(8),\n});\n\n/** A poll body value naming a field of the call's input or of the submit's\n * answer; any other value is sent as written. */\nexport const POLL_REFERENCE = /^\\$(input|result)\\.([A-Za-z_][A-Za-z0-9_]{0,63})$/;\n\n/**\n * HOW A CALL WHOSE SELLER ANSWERS BEFORE THE RESULT IS READY IS FINISHED, sent\n * on a spec only because this build asks for it (`accepts: [\"jobs\"]`): where\n * the status is (a field or header of the submit's answer, or one fixed URL),\n * how a poll is sent, what says it is still running or failed, how often and\n * how long to poll, and how many hours the job can be resumed. `always`: the\n * seller never answers inline. A poll never carries a payment: the take's one\n * payment is its submit. It signs in only to answer the seller's own sign-in\n * challenge (`jobs.ts`). Every field is the server's: the poll and complete\n * URLs are still checked here against the submit's host (`jobs.ts`).\n */\nexport const JobSchema = z\n .object({\n pollUrl: z.union([\n z\n .object({\n field: JobField.optional(),\n header: z\n .string()\n .regex(/^[A-Za-z0-9-]{1,64}$/)\n .optional(),\n fixed: OtherArm,\n })\n .refine((at) => at.field !== undefined || at.header !== undefined, 'a field or a header'),\n z.object({ fixed: z.string().min(1).max(2_048), field: OtherArm, header: OtherArm }),\n ]),\n /** Sent once like a poll after the result is saved, never after a save\n * that failed: it frees the seller's copy (AiSpace's `/complete`). Its\n * answer is ignored. */\n completeUrl: z.object({ fixed: z.string().min(1).max(2_048) }).optional(),\n pollMethod: z.enum(['GET', 'POST']),\n pollBody: z\n .record(JobField, z.unknown())\n .refine(\n (body) =>\n Object.values(body).every(\n (value) =>\n typeof value !== 'string' || !value.startsWith('$') || POLL_REFERENCE.test(value),\n ),\n 'a $ value is $input.<field> or $result.<field>',\n )\n .optional(),\n running: z.union([\n z.object({\n httpStatus: z.array(z.number().int().min(200).max(299)).min(1).max(8),\n field: OtherArm,\n values: OtherArm,\n }),\n JobFieldStateSchema.extend({ httpStatus: OtherArm }),\n ]),\n failed: JobFieldStateSchema.optional(),\n everyS: z.number().int().min(1).max(30),\n maxWaitS: z.number().int().min(1).max(600),\n keepH: z.number().int().min(1).max(48),\n always: z.literal(true).optional(),\n })\n .refine((job) => !job.pollBody || job.pollMethod === 'POST', 'only a POST poll has a body');\nexport type Job = z.infer<typeof JobSchema>;\n\n/** A spec's `timeoutS` ceiling: the paid leg's own (`MAX_PAID_LEG_TIMEOUT_MS`\n * in `commands/pay.ts`), so no spec can hold a call longer than a seller's\n * 402 already may. */\nexport const MAX_SPEC_TIMEOUT_S = 120;\n\n/**\n * A REQUEST SPEC: the offered service's real contract, sent beside the line only\n * because this build asks for it (`accepts: [\"spec\"]`). The hook stores it by\n * the offer's id; `request({id})` shows it and `request({id, input})` fills its\n * request and pays the provider directly, with no second decision. Every field\n * is the server's, and so is checked like the rest of the answer: the payee and\n * price still meet the live 402 and the spend policy in `runPay`.\n */\nexport const ToolSpecSchema = z.object({\n capabilityId: z.string().min(1).max(200),\n provider: z.string().min(1).max(120),\n /** The display name, on a catalog service's spec; a Bazaar spec has none. */\n label: LabelSchema.optional(),\n /** The input field that takes a pending search's query or fetch's URL. */\n holds: z\n .object({\n WebSearch: z.string().min(1).max(64).optional(),\n WebFetch: z.string().min(1).max(64).optional(),\n })\n .optional(),\n /** What a paid result is. `media` means its files (bytes, links or inline\n * base64) are saved locally; absent on a Bazaar spec. */\n output: z.enum(['json', 'text', 'media']).optional(),\n description: z.string().min(1).max(500),\n priceAtomic: z.string().regex(/^\\d+$/),\n priceVaries: z.boolean(),\n maxAmountAtomic: z.string().regex(/^\\d+$/),\n payTo: z.string().min(1).max(200),\n network: z.string().min(1).max(64),\n asset: z.string().min(1).max(200),\n request: z.object({\n method: z.enum(['GET', 'POST']),\n url: z.string().min(1).max(2_048),\n fields: z.record(z.string(), z.enum(['path', 'query', 'body'])),\n location: z.enum(['query', 'body']),\n /** Fixed request headers the catalog decides for this service (a\n * provider's beta opt-in, say), never the agent. The call refuses a name\n * this client signs or sets itself; `accept` and `content-type` stay its own. */\n headers: z\n .record(z.string().min(1).max(64), z.string().min(1).max(1_024))\n .refine((headers) => Object.keys(headers).length <= 8, 'at most 8 headers')\n .optional(),\n }),\n input: z.record(z.string(), z.unknown()),\n pinned: z.record(z.string(), z.unknown()),\n example: z.record(z.string(), z.unknown()).optional(),\n returns: z.string().min(1).max(200).optional(),\n returnsExample: z.unknown().optional(),\n resultSchema: z.record(z.string(), z.unknown()).optional(),\n /** The fields the result promises (type, properties, items, required). The\n * agent is handed only these; the whole body is saved to a file. */\n outputSchema: z.record(z.string(), z.unknown()).optional(),\n /** How a call answered before its result is ready is finished. */\n job: JobSchema.optional(),\n /** A media service that runs several takes of one call: `count` up to `max`. */\n takes: z.object({ max: z.number().int().min(2).max(5) }).optional(),\n requires: RequiresSchema,\n /** The provider call's own deadline in seconds: the unpaid probe's, and\n * the least the paid leg waits. Absent, the CLI's `--timeout`. */\n timeoutS: z.number().int().min(1).max(MAX_SPEC_TIMEOUT_S).optional(),\n /** The largest file the call may bring back, in bytes: a binary result,\n * and each file a media result links to, though not yet a job's polled\n * result. Absent, and at most, the {@link MAX_BINARY_BODY_BYTES} every\n * call had. */\n maxBytes: z.number().int().min(1).max(MAX_BINARY_BODY_BYTES).optional(),\n});\nexport type ToolSpec = z.infer<typeof ToolSpecSchema>;\n\nexport const OfferSpecSchema = ToolSpecSchema.extend({ id: IdSchema });\nexport type OfferSpec = z.infer<typeof OfferSpecSchema>;\n\n/** One spec per service the line names: the offer, any other service it\n * lists, and each option of a choice set. */\nconst SpecsSchema = z.array(OfferSpecSchema).min(1).max(8).optional();\n\n/*\n * A SERVICE ON A CONNECTED ACCOUNT (plan 37), with the bounds tenjin's\n * `wire.ts` holds it to: one MCP tool call this client makes on the user's\n * own account, which the user's plan pays. Sent only to a build that lists\n * `mcp`, and only for an account its `settings.sources` names. It carries no\n * URL, no credential and no price: this client calls the server it connected\n * for `source`, so no answer can send a user's token anywhere else.\n */\n\n/** The `accepts` token for a call on a connected account. */\nexport const MCP_ACCEPT = 'mcp';\n\n/** A connected account's id, which this client keeps its sign-in under: the\n * vault `sources/<id>.json` and the OS-store account `source:<id>:<folder>`.\n * Narrower than a target id, so no file system, shell or keychain command\n * line reads it as anything else. */\nexport const ACCOUNT_ID = /^[a-z0-9][a-z0-9-]{0,47}$/;\n\n/** Whether `id` is an account's: never the built-in source, which is never\n * connected. */\nexport function isAccountId(id: string): boolean {\n return ACCOUNT_ID.test(id) && id !== BUILT_IN_SOURCE;\n}\n\n/** A tool name as the MCP specification bounds it. */\nexport const McpToolSchema = z.string().regex(/^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/);\n\n/** The most an account call, its follow-up included, may serialize to. */\nexport const ACCOUNT_CALL_MAX_BYTES = 8 * 1024;\n\n/** How a tool's answer is read: its `structuredContent`; the JSON its text\n * items hold, joined in order; or its content items as they come. */\nexport const ACCOUNT_RESULTS = ['structured', 'json-text', 'content'] as const;\n\nconst RESULT_PATH = '[A-Za-z_][A-Za-z0-9_]{0,63}(?:\\\\.[A-Za-z_][A-Za-z0-9_]{0,63}){0,3}';\n/** An argument value that is exactly `{field}` is that input field's value, of\n * its own JSON type; one that is exactly `{result.<path>}`, in a follow-up\n * only, is the value at that path in the first call's result. Every other\n * value is sent as written: that is how a map pins a tool's settings. */\nexport const INPUT_PLACEHOLDER = /^\\{([A-Za-z_][A-Za-z0-9_]{0,63})\\}$/;\nexport const RESULT_PLACEHOLDER = new RegExp(`^\\\\{result\\\\.(${RESULT_PATH})\\\\}$`);\n\n/** A value at a path of a tool's result, and the values that mean a state. */\nconst AccountStateSchema = z.object({\n path: z.string().regex(new RegExp(`^${RESULT_PATH}$`)),\n values: z.array(z.string().min(1).max(64)).min(1).max(8),\n});\n\nconst AccountCallFields = {\n tool: McpToolSchema,\n /** The tool's `arguments`, a template (above). */\n args: z.record(z.string(), z.unknown()),\n result: z.enum(ACCOUNT_RESULTS),\n};\n\n/** A status call, sent every `everyS` seconds until its own result leaves\n * `running`; `failed` ends the call. `maxWaitS` counts from the first call. */\nconst AccountPollSchema = z.object({\n ...AccountCallFields,\n running: AccountStateSchema,\n failed: AccountStateSchema.optional(),\n everyS: z.number().int().min(1).max(30),\n maxWaitS: z.number().int().min(1).max(600),\n});\n\n/** The follow-up that fetches the result, when the first call does not hold\n * it: always, or only `when` the first result is in that state. The call\n * that bills is sent once and never again because its job is still running;\n * only `poll` repeats. */\nconst AccountStepSchema = z.object({\n when: AccountStateSchema.optional(),\n poll: AccountPollSchema.optional(),\n ...AccountCallFields,\n});\n\nexport const AccountCallSchema = z.object({\n ...AccountCallFields,\n next: AccountStepSchema.optional(),\n});\nexport type AccountCall = z.infer<typeof AccountCallSchema>;\n\nconst AccountSpecFields = z.object({\n capabilityId: z.string().min(1).max(200),\n provider: z.string().min(1).max(120),\n label: LabelSchema.optional(),\n holds: z\n .object({\n WebSearch: z.string().min(1).max(64).optional(),\n WebFetch: z.string().min(1).max(64).optional(),\n })\n .optional(),\n output: z.enum(['json', 'text', 'media']).optional(),\n description: z.string().min(1).max(500),\n /** The connected account the call runs on: this client attaches the\n * credential it holds for it, and only while it is connected here. */\n source: z.string().regex(ACCOUNT_ID),\n /** The call on the account, in place of a paid spec's price and request. */\n mcp: AccountCallSchema,\n input: z.record(z.string(), z.unknown()),\n pinned: z.record(z.string(), z.unknown()),\n example: z.record(z.string(), z.unknown()).optional(),\n returns: z.string().min(1).max(200).optional(),\n returnsExample: z.unknown().optional(),\n resultSchema: z.record(z.string(), z.unknown()).optional(),\n outputSchema: z.record(z.string(), z.unknown()).optional(),\n requires: RequiresSchema,\n // A paid spec's own keys: an object naming them is no account spec.\n priceAtomic: OtherArm,\n request: OtherArm,\n payTo: OtherArm,\n});\n\n/** Every string in a template that is exactly a placeholder. */\nfunction placeholders(value: unknown): string[] {\n if (typeof value === 'string')\n return INPUT_PLACEHOLDER.test(value) || RESULT_PLACEHOLDER.test(value) ? [value] : [];\n if (Array.isArray(value)) return value.flatMap(placeholders);\n if (value && typeof value === 'object') return Object.values(value).flatMap(placeholders);\n return [];\n}\n\nfunction accountSpecProblems(spec: z.infer<typeof AccountSpecFields>, ctx: z.RefinementCtx): void {\n const issue = (message: string, path: (string | number)[]) =>\n ctx.addIssue({ code: 'custom', message, path });\n const { mcp } = spec;\n if (spec.source === BUILT_IN_SOURCE)\n issue(`an account service is never on ${BUILT_IN_SOURCE}`, ['source']);\n if (!(spec.requires ?? []).includes(MCP_ACCEPT))\n issue(`an account spec requires ${MCP_ACCEPT}`, ['requires']);\n if (Buffer.byteLength(JSON.stringify(mcp), 'utf8') > ACCOUNT_CALL_MAX_BYTES)\n issue(`the call must serialize to at most ${ACCOUNT_CALL_MAX_BYTES} bytes`, ['mcp']);\n // The first call bills, so a poll or follow-up never sends it again.\n if (mcp.next?.poll?.tool === mcp.tool)\n issue('the poll never repeats the call that bills', ['mcp', 'next', 'poll', 'tool']);\n if (mcp.next?.tool === mcp.tool)\n issue('the follow-up never repeats the call that bills', ['mcp', 'next', 'tool']);\n const properties = spec.input.properties;\n const fields = new Set(\n properties && typeof properties === 'object' ? Object.keys(properties) : [],\n );\n const calls: [(string | number)[], Record<string, unknown>, boolean][] = [\n [['mcp', 'args'], mcp.args, false],\n ];\n if (mcp.next?.poll) calls.push([['mcp', 'next', 'poll', 'args'], mcp.next.poll.args, true]);\n if (mcp.next) calls.push([['mcp', 'next', 'args'], mcp.next.args, true]);\n for (const [path, args, followUp] of calls)\n for (const value of placeholders(args)) {\n const field = INPUT_PLACEHOLDER.exec(value)?.[1];\n if (field === undefined && !followUp) issue('only a follow-up reads the first result', path);\n if (field !== undefined && !fields.has(field))\n issue(`${value} names no field of the input`, path);\n }\n}\n\n/** An account service's spec, as a lookup's `spec` answer carries it. */\nexport const AccountSpecSchema = AccountSpecFields.superRefine(accountSpecProblems);\nexport type AccountSpec = z.infer<typeof AccountSpecSchema>;\n\n/** An account service's spec under the offer id the agent calls it with. */\nexport const AccountOfferSpecSchema = AccountSpecFields.extend({ id: IdSchema }).superRefine(\n accountSpecProblems,\n);\nexport type AccountOfferSpec = z.infer<typeof AccountOfferSpecSchema>;\n\n/** Any spec an offer id can hold: paid from the balance, or a call on an account. */\nexport type AnyOfferSpec = OfferSpec | AccountOfferSpec;\n\nexport const isAccountSpec = <T extends object>(spec: T): spec is T & AccountSpec =>\n 'mcp' in spec && 'source' in spec;\n\n/** The specs on an `execute`, whose lead may be an account service's. */\nconst ExecuteSpecsSchema = z\n .array(z.union([OfferSpecSchema, AccountOfferSpecSchema]))\n .min(1)\n .max(8)\n .optional();\n\n/** Words this client shows the model itself, in its own line: one plain line. */\nconst PlainLine = (max: number) =>\n z\n .string()\n .min(1)\n .max(max)\n .refine((text) => !/[\\p{Cc}\\p{Cf}]/u.test(text), 'one plain line');\n\n/**\n * SERVICES THE USER PICKS BETWEEN, OR RUNS ALL OF. Sent only beside a\n * discovered offer, to a build that lists `catalog` in `accepts`. Each option\n * is a real offer: its own id, its own spec in `specs`, and its own one\n * payment, so `request({id, choice})` runs exactly the spec\n * `request({id: option.id})` would. `all` runs every option side by side, one\n * payment each. The set is the server's data: changing it is a deploy there,\n * not a release here. `input` names the open fields the options share, the\n * only ones an `all` call may carry.\n */\nexport const ChoicesSchema = z.object({\n group: PlainLine(64),\n default: PlainLine(64),\n input: z.array(PlainLine(64)).min(1).max(16),\n options: z\n .array(\n z.object({\n key: PlainLine(64),\n label: PlainLine(120),\n strength: PlainLine(300),\n id: IdSchema,\n }),\n )\n .min(2)\n .max(4),\n all: z.object({ totalAtomic: z.string().regex(/^\\d+$/) }),\n});\nexport type Choices = z.infer<typeof ChoicesSchema>;\n\n/** The word that runs every option, so no option may take it as its key. */\nexport const ALL_CHOICES = 'all';\n\n/**\n * A CHOICE NAMES ONLY WHAT THIS ANSWER CARRIES: each key and id once, `all`\n * free for the whole set, a spec for every option, and the default option is\n * the offer this answer's id already names. A set that breaks any of these is\n * a protocol error, and the turn falls back like any unreadable answer.\n */\nfunction checkChoices(\n decision: { id: string; specs?: { id: string }[] | undefined; choices?: Choices | undefined },\n ctx: z.RefinementCtx,\n): void {\n const { choices } = decision;\n if (choices === undefined) return;\n const issue = (message: string) => ctx.addIssue({ code: 'custom', path: ['choices'], message });\n const keys = choices.options.map((option) => option.key);\n const ids = choices.options.map((option) => option.id);\n if (new Set(keys).size !== keys.length) issue('each choice key is named once');\n if (new Set(ids).size !== ids.length) issue('each choice id is named once');\n if (keys.includes(ALL_CHOICES)) issue(`\"${ALL_CHOICES}\" runs every choice, so it is no key`);\n const specIds = new Set((decision.specs ?? []).map((spec) => spec.id));\n if (ids.some((id) => !specIds.has(id))) issue('every choice carries its spec');\n const fallback = choices.options.find((option) => option.key === choices.default);\n if (fallback === undefined) issue('the default is one of the choices');\n else if (fallback.id !== decision.id) issue(\"the default choice is this answer's own offer\");\n}\n\n/** One call's input, serialized, bounded as the server bounds it. */\nexport const MAX_INPUT_BYTES = 16 * 1024;\n\n/**\n * THE NATIVE CALL'S OWN INPUT, on a hook answer for a pending WebSearch or\n * WebFetch to a client that sends `settings`, only while the user turned on\n * automatic use and the pick fits its provider scope: the offer id to run\n * and the complete input the server built from that call's own query or URL\n * through the spec's `holds`. Run unchanged in the native call's place,\n * through the ordinary executor and the check before every call, or not at\n * all; never edited, merged or parsed here (`swap.ts`).\n */\nexport const BoundSchema = z.object({\n id: IdSchema,\n input: z\n .record(z.string(), z.unknown())\n .refine(\n (input) => Buffer.byteLength(JSON.stringify(input), 'utf8') <= MAX_INPUT_BYTES,\n `bound input must serialize to at most ${MAX_INPUT_BYTES} bytes`,\n ),\n});\nexport type Bound = z.infer<typeof BoundSchema>;\n\n/** The same answer on both calls: the hook's offer, and the tool's answer\n * when a query with no id found a service nobody curated. */\nconst DiscoveredSchema = z\n .object({\n action: z.literal('discovered'),\n id: IdSchema,\n candidate: DiscoveredCandidateSchema,\n /** THE LINE, FINISHED, as on `execute`: it carries the seller's\n * description and the input it takes. */\n hint: z.string().min(1).max(2_000),\n specs: SpecsSchema,\n choices: ChoicesSchema.optional(),\n requires: RequiresSchema,\n bound: BoundSchema.optional(),\n })\n .superRefine(checkHint)\n .superRefine(checkChoices);\n\n/**\n * AN ACCOUNT LEAD IS OFFERED ALONE, as a service this client runs on its own\n * connection: no endpoint, no balance price, in place of a native call only\n * through `bound` as any lead. Every other `execute` is as it always was, with\n * the URL it pays.\n */\nfunction checkExecute(\n decision: {\n id: string;\n capabilityId: string;\n providerPriceAtomic: string;\n endpoint?: string | undefined;\n specs?: AnyOfferSpec[] | undefined;\n delivery?: 'offer' | 'augment' | 'note' | undefined;\n augmentUrl?: string | undefined;\n },\n ctx: z.RefinementCtx,\n): void {\n const issue = (message: string, path: (string | number)[]) =>\n ctx.addIssue({ code: 'custom', message, path });\n const specs = decision.specs ?? [];\n const lead = specs.find(({ id }) => id === decision.id);\n if (!lead || !isAccountSpec(lead)) {\n if (specs.some((spec) => isAccountSpec(spec)))\n issue('an account service is only ever the lead', ['specs']);\n if (decision.endpoint === undefined) issue('an execute names the URL it pays', ['endpoint']);\n return;\n }\n if (specs.length > 1) issue('an account lead is offered alone', ['specs']);\n if (decision.endpoint !== undefined)\n issue('an account lead names no endpoint: this client calls its own account', ['endpoint']);\n if (decision.capabilityId !== lead.capabilityId)\n issue('the listing names the lead', ['capabilityId']);\n if (decision.providerPriceAtomic !== '0')\n issue('the balance pays an account lead nothing', ['providerPriceAtomic']);\n if (decision.delivery === 'augment' || decision.augmentUrl !== undefined)\n issue('an account lead is an offer', ['delivery']);\n}\n\nconst HookDecisionSchema = z.discriminatedUnion('action', [\n z\n .object({\n action: z.literal('execute'),\n id: IdSchema,\n ...CapabilityFields,\n /** The x402 URL a lookup would pay, for the line the server writes. An\n * account lead has none: this client calls the account it connected. */\n endpoint: z.string().min(1).max(2_048).optional(),\n /** What to pass in `query`, in the service's own terms. */\n usage: z.string().min(1).max(300),\n /**\n * THE LINE, FINISHED. The server writes it with the real id in it and, on a\n * native call, the exact search or URL that was denied. The client injects\n * it and composes nothing, which is why there is no hint builder here any\n * more: two sides writing the same sentence is how they drift. The same\n * bound as a discovered line's.\n */\n hint: z.string().min(1).max(2_000),\n specs: ExecuteSpecsSchema,\n /**\n * HOW THE OFFER IS DELIVERED, sent because this build lists `fields`.\n * `note` is the free docs lookup before a search, for a client that\n * also lists `note`: the line comes after the search. `augment` is the\n * same offer for a client that does not, with the `augmentUrl` that\n * client fetches. `offer` is every other line. This build shows only a\n * `note` after a search; any other free offer before one, `augment`\n * included, runs silent.\n */\n delivery: z.enum(['offer', 'augment', 'note']).optional(),\n augmentUrl: z.string().url().max(2_048).optional(),\n bound: BoundSchema.optional(),\n })\n .superRefine(checkHint)\n .superRefine(checkExecute),\n DiscoveredSchema,\n RefusedSchema.extend({ action: z.literal('native') }),\n RefusedSchema.extend({ action: z.literal('needs_input') }),\n]);\n\nconst ToolDecisionSchema = z.discriminatedUnion('action', [\n z.object({\n action: z.literal('execute'),\n ...CapabilityFields,\n contract: ContractSchema,\n }),\n /**\n * A query with no id, answered with the spec of the service the server\n * picked under a fresh `id`: kept like a hook's, and never run in the same\n * call. `hint` is the line, with the skeleton of the next call:\n * `request({id, input: {...}})` with the required fields. What it needs\n * this client to understand is its spec's `requires`.\n */\n z\n .object({\n action: z.literal('spec'),\n id: IdSchema,\n spec: z.union([ToolSpecSchema, AccountSpecSchema]),\n hint: z.string().min(1).max(2_000),\n })\n .superRefine(checkHint),\n DiscoveredSchema,\n RefusedSchema.extend({ action: z.literal('native') }),\n RefusedSchema.extend({ action: z.literal('needs_input') }),\n]);\n\nfunction envelope<T extends z.ZodTypeAny>(decision: T) {\n return z.object({\n schemaVersion: z.literal(1),\n routerVersion: z.string().min(1).max(64),\n /**\n * The request's own settings hash, verbatim, on an answer the server\n * decided under the user's rules (to a client that lists `settings` in\n * `accepts`). The check before every call compares it with the rules\n * saved now (`settings-check.ts`); it names a rule set and authorizes\n * nothing.\n */\n settingsHash: SettingsHashSchema.optional(),\n decision,\n /** A plain sentence about the CALL, such as an id that had expired. Never a\n * failure: the decision beside it ran anyway. */\n note: z.string().max(500).optional(),\n jev: z.object({ calls: z.number(), latencyMs: z.number() }).optional(),\n });\n}\n\nconst HookResponseSchema = envelope(HookDecisionSchema);\nconst ToolResponseSchema = envelope(ToolDecisionSchema);\n\n/**\n * ONE ROW OF THE TOOL LIST, as the free browse answers it: the tool's id, its\n * display name (a list entry's upstream name runs to 120 characters), what it\n * does, its price as the server writes it, and its kind. Read like every\n * answer here, with the server's own bounds. The id is the one field the model\n * sends back, so its alphabet is pinned; the text is flattened to one line\n * where it is shown (`tool.ts`).\n */\nconst BrowseRowSchema = z.object({\n id: z\n .string()\n .min(1)\n .max(200)\n .regex(/^[A-Za-z0-9._:-]+$/),\n label: z.string().min(1).max(120),\n does: z.string().min(1).max(500),\n price: z.string().min(1).max(32),\n free: z.boolean(),\n kind: z.string().min(1).max(120),\n});\nexport type BrowseRow = z.infer<typeof BrowseRowSchema>;\n\nconst BrowseResponseSchema = z.object({\n schemaVersion: z.literal(1),\n routerVersion: z.string().min(1).max(64),\n rows: z.array(BrowseRowSchema).max(200),\n});\nexport type BrowseResponse = z.infer<typeof BrowseResponseSchema>;\n\nconst Labelled = { id: TargetIdSchema, label: z.string().min(1).max(120) };\n\n/** How an account signs in: `oauth` is the MCP sign-in, `key` a pasted key\n * sent as `Authorization: <keyScheme> <key>`. */\nexport const SIGN_IN = ['oauth', 'key'] as const;\nexport type SignIn = (typeof SIGN_IN)[number];\nexport const KEY_SCHEMES = ['Bearer', 'Key'] as const;\nexport type KeyScheme = (typeof KEY_SCHEMES)[number];\n\n/** Where a connected account is called. A user's token goes here, so it is\n * https, with no credentials, query, fragment or trailing slash to make it\n * another server or carry anything else. One the user typed (`typed`) may\n * also be http on this machine (`localhost`, 127.0.0.0/8, `[::1]`); the\n * router's never is. */\nexport function isAccountUrl(value: string, opts: { typed?: boolean } = {}): boolean {\n const url = URL.canParse(value) ? new URL(value) : undefined;\n return (\n url !== undefined &&\n (url.protocol === 'https:' ||\n (opts.typed === true && url.protocol === 'http:' && isLoopbackHost(url.hostname))) &&\n !url.username &&\n !url.password &&\n !value.includes('?') &&\n !value.includes('#') &&\n !value.endsWith('/')\n );\n}\n\nconst twice = (keys: readonly string[]) => new Set(keys).size !== keys.length;\n\n/**\n * HOW THIS CLIENT CONNECTS AN ACCOUNT, on a source row of the identities read\n * because this build lists `mcp`: its MCP server, the sign-ins it takes, how a\n * pasted key is sent, and every tool its maps call, which the free\n * connect-time `tools/list` must hold for those maps to run on this machine.\n * `tenjin` never has one.\n */\nexport const ConnectableSchema = z\n .object({\n mcpUrl: z\n .string()\n .max(2_048)\n .refine(\n (value) => isAccountUrl(value),\n 'an https URL with no credentials, query, fragment or trailing slash',\n ),\n signIn: z.array(z.enum(SIGN_IN)).min(1).max(2),\n keyScheme: z.enum(KEY_SCHEMES).optional(),\n expectTools: z.array(McpToolSchema).min(1).max(64),\n })\n .superRefine((connectable, ctx) => {\n const issue = (message: string, path: string[]) =>\n ctx.addIssue({ code: 'custom', message, path });\n if (twice(connectable.signIn)) issue('each sign-in is listed once', ['signIn']);\n if (connectable.signIn.includes('key') !== (connectable.keyScheme !== undefined))\n issue('a key sign-in says how the key is sent, and only it does', ['keyScheme']);\n if (twice(connectable.expectTools)) issue('each tool is listed once', ['expectTools']);\n });\nexport type Connectable = z.infer<typeof ConnectableSchema>;\n\n/**\n * EVERY ID A SETTING CAN NAME, free: the categories with their tasks, the\n * tasks, providers, sellers, services (with the task, providers and seller\n * each is identified by) and sources, each with its label. `tenjin config`\n * resolves a typed name against it and names saved rules by it; it never\n * decides with it. Built by the server from its catalog, with no gate, no\n * model and no payment. Read tolerantly like every answer here.\n */\nconst IdentitiesResponseSchema = z.object({\n schemaVersion: z.literal(1),\n routerVersion: z.string().min(1).max(64),\n categories: z.array(z.object({ ...Labelled, tasks: z.array(TargetIdSchema).max(256) })).max(256),\n /** `speed`: a task the speed preference changes (it has a speed criterion). */\n tasks: z\n .array(\n z.object({\n ...Labelled,\n category: TargetIdSchema.optional(),\n speed: z.literal(true).optional(),\n }),\n )\n .max(1_024),\n providers: z.array(z.object(Labelled)).max(2_048),\n sellers: z.array(z.object(Labelled)).max(2_048),\n services: z\n .array(\n z.object({\n ...Labelled,\n task: TargetIdSchema.optional(),\n providers: z.array(TargetIdSchema).max(16),\n seller: TargetIdSchema.optional(),\n }),\n )\n .max(4_096),\n /** `connectable`, for a build that lists `mcp`: an account this client can\n * connect, never `tenjin`. */\n sources: z\n .array(\n z\n .object({ ...Labelled, connectable: ConnectableSchema.optional() })\n .refine(\n ({ id, connectable }) => connectable === undefined || isAccountId(id),\n 'only an account id is connectable, never tenjin',\n ),\n )\n .max(64),\n});\nexport type IdentitiesResponse = z.infer<typeof IdentitiesResponseSchema>;\n\n/** A hook answer reread from disk (`decided.ts`), held to the same schema as\n * the router's: anything else reads as absent. */\nexport function parseHookResponse(value: unknown): HookResponse | undefined {\n const parsed = HookResponseSchema.safeParse(value);\n return parsed.success ? parsed.data : undefined;\n}\n\n/** The identities read reread from disk (`identities.ts`), held to the same\n * schema as the router's answer: anything else reads as absent. */\nexport function parseIdentities(value: unknown): IdentitiesResponse | undefined {\n const parsed = IdentitiesResponseSchema.safeParse(value);\n return parsed.success ? parsed.data : undefined;\n}\n\nexport type HookResponse = z.infer<typeof HookResponseSchema>;\nexport type ToolResponse = z.infer<typeof ToolResponseSchema>;\nexport type HookDecision = HookResponse['decision'];\nexport type ToolDecision = ToolResponse['decision'];\n\n/** The reason code of an offer this build skipped for a feature it lacks. */\nexport const REQUIRES_UNMET = 'requires_unmet';\n\n/** An offer skipped for features this build lacks, named by its id. */\nexport interface SkippedOffer {\n id: string;\n missing: string[];\n}\n\n/**\n * A BACKSTOP, NOT A FILTER. The server sends only `requires` tokens a client\n * lists in `accepts`, so a client meets an unmet one only when that rule was\n * broken, and then it fails safe. A spec whose `requires` names a feature this\n * build lacks is dropped. When the answer's line names what was dropped (the\n * answer's own offer, through its `requires`, its own spec or a `spec`\n * answer's spec; another spec whose id the line carries; or any option of its\n * choice set), the line can no longer be shown as written, so the whole\n * answer becomes a `native` that names the missing features: a named skip,\n * never a guess. A dropped spec the line does not name is only dropped.\n */\nexport function withoutUnmet<T extends HookDecision | ToolDecision>(\n decision: T,\n): { decision: T; skipped: SkippedOffer[] } {\n if (decision.action === 'native' || decision.action === 'needs_input') {\n return { decision, skipped: [] };\n }\n const specs = 'specs' in decision ? (decision.specs ?? []) : [];\n const own = [\n ...unmetRequires('requires' in decision ? decision.requires : undefined),\n ...(decision.action === 'spec' ? unmetRequires(decision.spec.requires) : []),\n ...('id' in decision ? unmetRequires(specs.find((s) => s.id === decision.id)?.requires) : []),\n ];\n if (own.length > 0) {\n const missing = [...new Set(own)];\n const id = 'id' in decision ? decision.id : decision.capabilityId;\n return { decision: unmetRefusal(missing) as T, skipped: [{ id, missing }] };\n }\n const skipped = specs.flatMap((spec) => {\n const missing = unmetRequires(spec.requires);\n return missing.length > 0 ? [{ id: spec.id, missing }] : [];\n });\n if (skipped.length === 0) return { decision, skipped };\n const options = new Set(\n decision.action === 'discovered' ? (decision.choices?.options ?? []).map((o) => o.id) : [],\n );\n const hint = 'hint' in decision ? decision.hint : '';\n if (skipped.some((s) => options.has(s.id) || hint.includes(s.id))) {\n const missing = [...new Set(skipped.flatMap((s) => s.missing))];\n return { decision: unmetRefusal(missing) as T, skipped };\n }\n const gone = new Set(skipped.map((s) => s.id));\n return {\n decision: { ...decision, specs: specs.filter((spec) => !gone.has(spec.id)) } as T,\n skipped,\n };\n}\n\nfunction unmetRefusal(missing: string[]) {\n const named = missing.map((token) => `\\`${token}\\``).join(', ');\n return {\n action: 'native' as const,\n reason: `This offer needs ${named}, which this build of tenjin-cli does not have, so it was skipped and no provider was paid.`,\n diagnostics: {\n reasonCode: REQUIRES_UNMET,\n stage: 'client',\n missing,\n nextAction:\n 'Use your own tools for this one. A newer tenjin-cli (`tenjin update`) can run it.',\n },\n };\n}\n\n/** Which call this is, and therefore which answer is legal for it. */\nexport type CallKind = 'hook' | 'tool' | 'browse';\n\n/**\n * What this client can act on beyond the curated answers, sent on every call.\n * Each token names one kind of feature this build parses and runs, and the\n * server ignores a token it does not know, so the list only ever grows.\n * `label` takes each catalog service's display name on its spec and both\n * `execute` answers, and the offer line that starts at it. `fields` takes\n * each spec's `holds` and `output`, and the hook `execute`'s `delivery` and\n * `augmentUrl`. `note` asks for `delivery: \"note\"` on the free docs lookup\n * before a search, whose line this build shows after the search, in place of\n * the `augment` an older build fetched. `catalog` takes Tenjin's reviewed\n * list of third-party services as\n * `discovered` offers under their catalog ids, with each spec's `holds` and\n * `output`, and `choices`, a set of options the user picks between or runs\n * all of, beside a discovered offer from a compare group. A build that sends\n * `discovered` in its place gets the same services under their\n * `discovered:tenjin:` ids. `spec` asks for each offered service's request\n * spec beside its line, and for the picked service's spec in place of a\n * decision on a query with no id, which only a build that runs them can\n * take. `jobs` asks for each spec's `job`,\n * for the services that never answer inline, and for `count` on a media\n * offer's line. `headers` asks for a spec's `request.headers`, the fixed\n * headers the catalog sets on a service's call (a provider's beta opt-in),\n * with the pins those headers unlock: `buildSpecRequest` sends them. A build\n * without a token would drop the field as unknown, so a spec that cannot run\n * without it lists the token in `requires`. `tolerant` says this build reads\n * every answer as a tolerant reader and honors `requires` ({@link withoutUnmet}).\n * Once the server reads it (tenjin R2), it sends a new field, `requires`\n * included, only to a client that lists it, and today's shape to one that\n * does not, which is every release from before it and reads strictly. `bazaar` widens discovery to the open\n * Bazaar and is sent only while `experimental.bazaar` is on.\n */\nexport const CLIENT_ACCEPTS: readonly string[] = [\n 'catalog',\n 'spec',\n 'label',\n 'fields',\n 'jobs',\n 'headers',\n 'note',\n 'tolerant',\n];\nexport const BAZAAR_ACCEPT = 'bazaar';\nexport const FREE_QUERY_ACCEPT = 'free-query';\n\n/** Every feature this build has, which a `requires` list is read against:\n * `bazaar` included, which it runs whether or not it asks for one. */\nconst CLIENT_FEATURES: ReadonlySet<string> = new Set([\n ...CLIENT_ACCEPTS,\n BAZAAR_ACCEPT,\n FREE_QUERY_ACCEPT,\n SETTINGS_ACCEPT,\n MCP_ACCEPT,\n]);\n\n/** The features a `requires` list names that this build lacks; none when it\n * has them all. */\nexport function unmetRequires(requires: readonly string[] | undefined): string[] {\n return (requires ?? []).filter((token) => !CLIENT_FEATURES.has(token));\n}\n\n/** The `accepts` this build sends, with the open Bazaar or without it, and\n * `settings` beside the `settings` field, which every production routing\n * call carries (also when the user has no rules). `mcp` rides with it: a\n * call on a connected account is offered only for an account the\n * settings' `sources` names, so it means nothing without them. It takes a\n * spec whose call is an MCP tool call on that account, the `execute` that\n * offers one with no `endpoint`, `connectable` on the identities read, and\n * the `{refused}` re-ask ({@link requestRefused}). */\nexport function acceptsFor(bazaar: boolean, settings = false): string[] {\n return [\n ...CLIENT_ACCEPTS,\n ...(bazaar ? [BAZAAR_ACCEPT] : []),\n ...(settings ? [SETTINGS_ACCEPT, MCP_ACCEPT] : []),\n ];\n}\n\n/**\n * The exact body the hook call sends, spelled once and pinned to the shared\n * fixtures. The route ignores a field it does not know (the tolerant\n * contract), so a new optional field reaches a server that predates it as\n * nothing at all.\n *\n * `improve: true` rides only while the person has turned on \"Help improve\n * routing\" (`router.improve`): the server then keeps this call's sealed packet\n * beside its decision row, with no expiry, until they turn it off. Absent, it\n * keeps nothing past the id's 15 minutes.\n *\n * ONE BODY FOR BOTH HOOKS. Which hook is asking is not a field: the route reads\n * it from `packet.pendingCall`, which the native hook sets and the prompt hook\n * does not. A `source` beside the packet was the `/prepare` route's shape, and\n * that route is gone. `sessionId` is the harness's own session id, which the\n * server uses only so one session is not offered the same discovered service\n * twice.\n */\nexport function buildHookBody(\n packet: Packet,\n extras: {\n sessionId?: string;\n accepts?: readonly string[];\n harness?: Harness;\n improve?: boolean;\n budgetMs?: number;\n settings?: WireSettings;\n } = {},\n): Record<string, unknown> {\n return {\n schemaVersion: 1,\n ...(extras.sessionId !== undefined ? { sessionId: extras.sessionId } : {}),\n ...(extras.accepts !== undefined ? { accepts: [...extras.accepts] } : {}),\n ...(extras.harness !== undefined ? { harness: extras.harness } : {}),\n ...(extras.budgetMs !== undefined ? { budgetMs: extras.budgetMs } : {}),\n packet,\n ...(extras.improve === true ? { improve: true } : {}),\n // A SIBLING OF THE PACKET, never inside it: the packet is what the\n // server's model reads, and the user's settings are for code alone.\n ...(extras.settings !== undefined ? { settings: extras.settings } : {}),\n };\n}\n\n/** The exact body the tool call sends. `id` is the offer the query is for,\n * sent only for an offer with no spec kept; `gateHint` is evidence, never\n * authority; `improve` as on the hook body. */\nexport function buildToolBody(request: {\n query?: string;\n id?: string;\n gateHint?: GateHint;\n accepts?: readonly string[];\n harness?: Harness;\n improve?: boolean;\n settings?: WireSettings;\n}): Record<string, unknown> {\n return {\n schemaVersion: 1,\n ...(request.query !== undefined ? { query: request.query } : {}),\n ...(request.id !== undefined ? { id: request.id } : {}),\n ...(request.gateHint !== undefined ? { gateHint: request.gateHint } : {}),\n ...(request.accepts !== undefined ? { accepts: [...request.accepts] } : {}),\n ...(request.harness !== undefined ? { harness: request.harness } : {}),\n ...(request.improve === true ? { improve: true } : {}),\n ...(request.settings !== undefined ? { settings: request.settings } : {}),\n };\n}\n\n/**\n * THE RE-ASK AFTER AN ACCOUNT REFUSED (plan 37, review round 1): the usual\n * envelope with `refused`, the id of the offer the account refused, and no\n * query. The server routes that offer's own turn again with the account left\n * out for this one answer, under the settings sent, and answers as it answers\n * a query: an offer, or native.\n */\nexport function buildRefusedBody(request: {\n refused: string;\n accepts: readonly string[];\n harness?: Harness;\n settings?: WireSettings;\n}): Record<string, unknown> {\n return {\n schemaVersion: 1,\n refused: request.refused,\n accepts: [...request.accepts],\n ...(request.harness !== undefined ? { harness: request.harness } : {}),\n ...(request.settings !== undefined ? { settings: request.settings } : {}),\n };\n}\n\n/** The free browse of the tool list: `browse` is the need, or `\"\"` for every\n * tool by kind. No gate call and no Jev on the server. */\nexport function buildBrowseBody(request: {\n browse: string;\n accepts: readonly string[];\n harness?: Harness;\n settings?: WireSettings;\n}): Record<string, unknown> {\n return {\n schemaVersion: 1,\n browse: request.browse,\n accepts: [...request.accepts],\n ...(request.harness !== undefined ? { harness: request.harness } : {}),\n ...(request.settings !== undefined ? { settings: request.settings } : {}),\n };\n}\n\n/** A browse row's spec, or a query bound to that selected free tool. */\nexport function buildToolSpecBody(request: {\n tool: string;\n query?: string;\n accepts: readonly string[];\n harness?: Harness;\n settings?: WireSettings;\n}): Record<string, unknown> {\n return {\n schemaVersion: 1,\n tool: request.tool,\n ...(request.query !== undefined ? { query: request.query } : {}),\n accepts: [...request.accepts],\n ...(request.harness !== undefined ? { harness: request.harness } : {}),\n ...(request.settings !== undefined ? { settings: request.settings } : {}),\n };\n}\n\n/** The free identities read: every id a setting can name. No settings and\n * no harness ride on it: its answer is the same for every client. */\nexport function buildIdentitiesBody(): Record<string, unknown> {\n return { schemaVersion: 1, identities: true, accepts: acceptsFor(false, true) };\n}\n\n/**\n * THE PAID ROUTE'S `warm` CALL, a channel deposit's carrier. The payer's\n * background top-up sends it and nothing else does: the batch-settlement spec\n * has no deposit-only payload, so the deposit rides a paid request the server\n * answers in code, with no gate and nothing stored, and settles at $0.\n */\nexport function buildWarmBody(\n extras: { accepts?: readonly string[]; harness?: Harness } = {},\n): Record<string, unknown> {\n return {\n schemaVersion: 1,\n warm: true,\n ...(extras.accepts !== undefined ? { accepts: [...extras.accepts] } : {}),\n ...(extras.harness !== undefined ? { harness: extras.harness } : {}),\n };\n}\n\n/** The `warm` answer, read tolerantly like every answer: no decision. */\nconst WarmResponseSchema = z.object({\n schemaVersion: z.literal(1),\n routerVersion: z.string().min(1).max(64),\n warm: z.literal(true),\n});\n\n/** Whether a body is the `warm` answer. A router without the form answers\n * anything else: a 400 for an unknown field, or a decision. */\nexport function isWarmAnswer(body: unknown): boolean {\n return WarmResponseSchema.safeParse(body).success;\n}\n\n/** The parsers, exposed so the shared wire fixtures are checked against the\n * same schemas production parses with rather than against a copy of them. */\nexport function parseForTests(\n kind: CallKind,\n value: unknown,\n): { success: boolean; data?: unknown } {\n const parsed = schemaFor(kind).safeParse(value);\n return parsed.success ? { success: true, data: parsed.data } : { success: false };\n}\n\nfunction schemaFor(kind: CallKind) {\n return kind === 'hook'\n ? HookResponseSchema\n : kind === 'tool'\n ? ToolResponseSchema\n : BrowseResponseSchema;\n}\n\n/**\n * The gate's own reading of this turn, travelling as EVIDENCE for the lookup it\n * was produced for. The backend may refine or reject it, and it authorizes no\n * money: the local spend policy does that. Optional on both call forms.\n */\nexport interface GateHint {\n category: string;\n turnId: string;\n lookupId: string;\n}\n\nexport interface DecisionDeps {\n ctx: CommandContext;\n baseUrl: string;\n /** `experimental.bazaar`: add {@link BAZAAR_ACCEPT}, so a service from the\n * open Bazaar may come back. Off by default: curated and the Tenjin list. */\n acceptsBazaar?: boolean;\n /**\n * The host asking. Automatic routing avoids services the host already covers;\n * explicit browsing and selection retain every runnable service. Absent is\n * `claude`, and every production caller sends it.\n */\n harness?: Harness;\n fetchImpl?: typeof fetch;\n /** Overrides the per-call deadline; the hook passes its own, smaller one. */\n timeoutMs?: number;\n /** The payer, inside `tenjin mcp`: it sends the call and pays the routing\n * fee with the stock x402 client. Absent, the call goes unpaid. */\n route?: DecisionRoute;\n /** `router.improve`: the person turned on \"Help improve routing\", so the\n * call says `improve: true`. Off by default. */\n improve?: boolean;\n /**\n * The user's settings as the wire carries them, resolved from the global\n * file on every call (`routerSettings`) and never cached: sent with\n * `settings` in `accepts` on every routing form. Absent only in tests and\n * the free identities read.\n */\n settings?: WireSettings;\n}\n\n/** One decision's payment transport; do not share it between concurrent decisions.\n * `send` throws {@link RouteSkipped} when it has\n * no usable answer for the call, which then is skipped, or read as the\n * transport failure it carries in `unreached`. */\nexport interface DecisionRoute {\n send: (url: string, options: HttpRequestOptions) => Promise<HttpResult>;\n /** What this route's own calls deposited into the routing channel and the\n * router took (only on a router with no `warm` form), 0n for none: the\n * caller says so once, where it is read. */\n deposited?: () => bigint;\n /** What the payer's background top-ups deposited since this was last\n * read, 0n for none, and taken by the read. Only a hook leg reads it, so\n * the person is told, in its `systemMessage`. */\n toppedUp?: () => bigint;\n /** The most recent call completed a signed routing payment successfully.\n * Free answers, background top-ups and payments still settling do not count. */\n paid?: () => boolean;\n /** The most the last call's signed payment could charge: the fee its 402 stated, 0n when\n * nothing was signed. */\n authorized?: () => bigint;\n}\n\n/** The paid route gave this call no answer: the wallet locked, low or over\n * its spend limits, the fee quoted above the ceiling, the channel busy or\n * being topped up, or the payment failed. */\nexport class RouteSkipped extends Error {\n /** `unreached`: the paid call could not reach the router\n * ({@link isUnreachable}), so the call reads as that transport failure.\n * `quotedAtomic`: the fee the router quoted, when the payer read one.\n * `answered`: the router answered a request of this call (its 402, say). */\n readonly unreached: FetchJsonFailure | undefined;\n readonly quotedAtomic: bigint | undefined;\n readonly answered: boolean;\n constructor(\n readonly why: string,\n opts: { unreached?: FetchJsonFailure; quotedAtomic?: bigint; answered?: boolean } = {},\n ) {\n super(`routing fee not paid: ${why}`);\n this.unreached = opts.unreached;\n this.quotedAtomic = opts.quotedAtomic;\n this.answered = opts.answered === true;\n }\n}\n\n/** Another session's call was in flight on the wallet's routing channel. */\nexport const CHANNEL_BUSY = 'channel_busy';\n/** The paid call got no answer, a refused payment or a server error. */\nexport const PAYMENT_FAILED = 'payment_failed';\n/** The payment went out and the call's budget ran out before its answer:\n * no fault. `tenjin mcp` lets the request finish, so it is recorded. */\nexport const DEADLINE_AFTER_PAYMENT_SENT = 'deadline_after_payment_sent';\n/** The route asked for the fee, and this call had no payer to pay it. */\nexport const NO_PAYER = 'no_payer';\n/** The channel needed a deposit, and this process's background top-up did\n * not land inside the call's budget: no fault. The next call pays from it if\n * it lands, or gets its refusal if it was refused. */\nexport const TOPPING_UP = 'topping_up';\n/** The background top-up got no usable answer: the router rate-limited it,\n * or no connection reached it. No fault, as on any routing call, and never\n * the machine-wide unreachable pause: the call it served reached the router.\n * The top-up is tried again after its backoff. */\nexport const TOP_UP_UNAVAILABLE = 'top_up_unavailable';\n/** The channel needed a deposit, which only the background top-up makes, and\n * this process's could not make it now (another session's top-up of the same\n * wallet is in flight, or the channel was busy): no fault. */\nexport const DEPOSIT_DEFERRED = 'deposit_deferred';\n\nexport type DecisionOutcome<T> =\n /** `skipped`: offers in it this build cannot run, already taken out\n * ({@link withoutUnmet}). */\n | { status: 'decided'; decision: T; skipped?: SkippedOffer[] }\n /** No routing answer: the turn goes without one. */\n | {\n status: 'failed';\n reason: string;\n errorCode?: string;\n /** The router could not be reached at all ({@link isUnreachable}). */\n unreachable?: true;\n /** No answer came back at all: a transport failure or a timeout. */\n noAnswer?: true;\n }\n /** The routing fee was not paid ({@link RouteSkipped}, {@link NO_PAYER}):\n * nothing was routed, and the native tool runs. `quotedAtomic`: the fee\n * the router quoted, when the payer read one. `answered`: the router\n * answered first, so it is reachable. */\n | { status: 'skipped'; why: string; quotedAtomic?: bigint; answered?: true };\n\n/**\n * ONE ROUTING CALL, IN TWO FORMS, ON THE PAID ROUTE. The hook sends\n * `{ packet }`: the backend runs the gate, and on `execute` stores that packet\n * under an id and answers with each offered service's spec. The tool sends\n * `{ query }`, which the backend answers with the spec of the service its gate\n * picks, or `{ query, id }` for the free docs offer, which has no spec and is\n * bound from the query. Every provider call is built here, from a spec, or for\n * the docs lookup by the backend from the query.\n *\n * ONE REQUEST, PAID OR SKIPPED. A call the payer cannot pay is `skipped` at\n * once: no second request, on any route. With no payer the call goes unpaid,\n * and a route that asks for the fee (a 402) is a skip with {@link NO_PAYER};\n * a route that charges nothing (the fee off, in development) answers it.\n */\nexport async function requestDecision(\n kind: 'hook',\n request: { packet: Packet; sessionId?: string },\n deps: DecisionDeps,\n): Promise<DecisionOutcome<HookResponse>>;\nexport async function requestDecision(\n kind: 'tool',\n request: { query: string; id?: string; gateHint?: GateHint },\n deps: DecisionDeps,\n): Promise<DecisionOutcome<ToolResponse>>;\nexport async function requestDecision(\n kind: CallKind,\n request: {\n query?: string;\n packet?: Packet;\n sessionId?: string;\n id?: string;\n gateHint?: GateHint;\n },\n deps: DecisionDeps,\n): Promise<DecisionOutcome<HookResponse | ToolResponse>> {\n const url = new URL(ROUTE_PAID_PATH, deps.baseUrl).toString();\n const timeoutMs = deps.timeoutMs ?? deps.ctx.flags.timeout;\n const options: HttpRequestOptions = {\n method: 'POST',\n timeoutMs,\n blockRedirects: true,\n jsonBody:\n kind === 'hook'\n ? buildHookBody(request.packet as Packet, {\n ...(request.sessionId !== undefined ? { sessionId: request.sessionId } : {}),\n accepts: acceptsFor(deps.acceptsBazaar === true, deps.settings !== undefined),\n harness: deps.harness ?? 'claude',\n improve: deps.improve === true,\n budgetMs: Math.min(5_000, Math.max(0, timeoutMs)),\n ...(deps.settings !== undefined ? { settings: deps.settings } : {}),\n })\n : buildToolBody({\n ...(request.query !== undefined ? { query: request.query } : {}),\n ...(request.id !== undefined ? { id: request.id } : {}),\n ...(request.gateHint !== undefined ? { gateHint: request.gateHint } : {}),\n accepts: acceptsFor(deps.acceptsBazaar === true, deps.settings !== undefined),\n harness: deps.harness ?? 'claude',\n improve: deps.improve === true,\n ...(deps.settings !== undefined ? { settings: deps.settings } : {}),\n }),\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n };\n return kind === 'hook'\n ? sendPaid(url, options, HookResponseSchema, deps)\n : sendPaid(url, options, ToolResponseSchema, deps);\n}\n\n/**\n * `{refused}` ON THE PAID ROUTE, paid or skipped like a query\n * ({@link requestDecision}), and answered the same way: an offer, or native.\n * It needs `mcp`, which rides with the settings.\n */\nexport async function requestRefused(\n refused: string,\n deps: DecisionDeps,\n): Promise<DecisionOutcome<ToolResponse>> {\n const url = new URL(ROUTE_PAID_PATH, deps.baseUrl).toString();\n return sendPaid(\n url,\n {\n method: 'POST',\n timeoutMs: deps.timeoutMs ?? deps.ctx.flags.timeout,\n blockRedirects: true,\n jsonBody: buildRefusedBody({\n refused,\n accepts: acceptsFor(deps.acceptsBazaar === true, deps.settings !== undefined),\n harness: deps.harness ?? 'claude',\n ...(deps.settings !== undefined ? { settings: deps.settings } : {}),\n }),\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n },\n ToolResponseSchema,\n deps,\n );\n}\n\n/** One request on the paid route: sent by the payer, or unpaid with none. */\nasync function sendPaid<R extends HookResponse | ToolResponse>(\n url: string,\n options: HttpRequestOptions,\n schema: z.ZodType<R>,\n deps: Pick<DecisionDeps, 'route'>,\n): Promise<DecisionOutcome<R>> {\n let response: HttpResult;\n try {\n response = await (deps.route?.send ?? httpRequest)(url, options);\n } catch (err) {\n if (!(err instanceof RouteSkipped)) throw err;\n if (err.unreached !== undefined) return readOffer(err.unreached, schema);\n return {\n status: 'skipped',\n why: err.why,\n ...(err.quotedAtomic !== undefined ? { quotedAtomic: err.quotedAtomic } : {}),\n ...(err.answered ? { answered: true as const } : {}),\n };\n }\n if (deps.route === undefined && response.ok && response.status === 402) {\n return { status: 'skipped', why: NO_PAYER, answered: true };\n }\n return readOffer(response, schema);\n}\n\n/**\n * THE TWO FREE READS OF THE TOOL LIST. `{browse}` lists the tools that fit a\n * need (or all of them, by kind, for `\"\"`), and `{tool}` answers a browse\n * row's id with that tool's spec under a fresh offer id, exactly as a query\n * with no id is answered. Neither makes a gate call on the server, neither is\n * charged the routing fee, and neither pays anything here, so both always take\n * the free route: `deps.route` is never read.\n */\nexport async function requestBrowse(\n browse: string,\n deps: Omit<DecisionDeps, 'route'>,\n): Promise<DecisionOutcome<BrowseResponse>> {\n return readDecision(\n await httpRequest(new URL(ROUTER_PATH, deps.baseUrl).toString(), {\n method: 'POST',\n timeoutMs: deps.timeoutMs ?? deps.ctx.flags.timeout,\n blockRedirects: true,\n jsonBody: buildBrowseBody({\n browse,\n accepts: acceptsFor(deps.acceptsBazaar === true, deps.settings !== undefined),\n harness: deps.harness ?? 'claude',\n ...(deps.settings !== undefined ? { settings: deps.settings } : {}),\n }),\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n }),\n BrowseResponseSchema,\n );\n}\n\n/** `{tool}` reads a spec; `{tool, query}` binds a free lookup without paid routing. */\nexport async function requestToolSpec(\n tool: string,\n deps: Omit<DecisionDeps, 'route'>,\n query?: string,\n): Promise<DecisionOutcome<ToolResponse>> {\n return readOffer(\n await httpRequest(new URL(ROUTER_PATH, deps.baseUrl).toString(), {\n method: 'POST',\n timeoutMs: deps.timeoutMs ?? deps.ctx.flags.timeout,\n blockRedirects: true,\n jsonBody: buildToolSpecBody({\n tool,\n ...(query !== undefined ? { query } : {}),\n accepts: [\n ...acceptsFor(deps.acceptsBazaar === true, deps.settings !== undefined),\n FREE_QUERY_ACCEPT,\n ],\n harness: deps.harness ?? 'claude',\n ...(deps.settings !== undefined ? { settings: deps.settings } : {}),\n }),\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n }),\n ToolResponseSchema,\n );\n}\n\n/**\n * EVERY ID A SETTING CAN NAME, ALWAYS FREE: no gate, no model, no payment, so\n * it takes the free route whatever `deps.route` says. `tenjin config` resolves\n * a typed name against it before it writes anything.\n */\nexport async function requestIdentities(\n deps: Pick<DecisionDeps, 'ctx' | 'baseUrl' | 'fetchImpl' | 'timeoutMs'>,\n): Promise<DecisionOutcome<IdentitiesResponse>> {\n return readDecision(\n await httpRequest(new URL(ROUTER_PATH, deps.baseUrl).toString(), {\n method: 'POST',\n timeoutMs: deps.timeoutMs ?? deps.ctx.flags.timeout,\n blockRedirects: true,\n jsonBody: buildIdentitiesBody(),\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n }),\n IdentitiesResponseSchema,\n );\n}\n\n/** Why a call from a spec stopped before anything was signed: the input did\n * not fit, the live terms were not the spec's, the provider answered\n * something else, it could not be reached, or the wallet could not pay. */\nexport type UnpaidReason = 'input' | 'terms' | 'provider' | 'unreachable' | 'wallet';\n\n/** How a call run from a request spec ended, for the server's offer-to-call\n * count. No text: the id, the outcome, the provider's status and the time. */\nexport interface SpecOutcome {\n id: string;\n /** `unpaid`: stopped before anything was signed, which the server never\n * counts as the offer taken. `running`: paid, and the seller was still\n * rendering when the call ended. */\n status: 'fulfilled' | 'unverified' | 'failed' | 'needs_approval' | 'unpaid' | 'running';\n /** On `unpaid` only, where the server requires it. */\n reason?: UnpaidReason;\n httpStatus?: number;\n ms?: number;\n /** The path that made the call, when it was not an ordinary request:\n * `swap`, a native search or fetch answered in place. */\n via?: 'swap';\n}\n\n/**\n * Why a shown offer was never taken. `expired`: its 15 minutes ran out with no\n * `request` call naming it. `native_after_offer`: the same agent in the same\n * session made a native WebSearch or WebFetch call while it was still untaken.\n */\nexport type IgnoredReason = 'expired' | 'native_after_offer';\n\n/** An offer the host was shown and did not take: its id and why, no text. */\nexport interface IgnoredOutcome {\n id: string;\n status: 'ignored';\n reason: IgnoredReason;\n}\n\n/** The outcome report's own deadline: it is telemetry and never holds a result. */\nexport const OUTCOME_TIMEOUT_MS = 3_000;\n\n/**\n * TELL THE SERVER A SPEC WAS USED. The client called and paid the provider\n * itself, so this is the only word the server gets that its offer was taken,\n * or that a call for it stopped before payment and why, or that it was shown\n * and never taken. Never throws and never waits on anything the caller needs:\n * a lost report costs one count.\n */\nexport async function reportSpecOutcome(\n outcome: SpecOutcome | IgnoredOutcome,\n deps: Pick<DecisionDeps, 'ctx' | 'baseUrl' | 'fetchImpl' | 'harness'>,\n): Promise<void> {\n try {\n await httpRequest(new URL(ROUTER_PATH, deps.baseUrl).toString(), {\n method: 'POST',\n timeoutMs: OUTCOME_TIMEOUT_MS,\n blockRedirects: true,\n jsonBody: buildOutcomeBody(outcome, deps.harness ?? 'claude'),\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n });\n } catch {\n // Telemetry only.\n }\n}\n\n/**\n * The exact body of an outcome report, pinned to the shared fixtures. Built\n * field by field, so it NEVER CARRIES `result`: a paid call that ran is not a\n * call that helped, and the useful rate comes from labelled samples, not from\n * this client's say-so. The server keeps reading `result` from custom setups.\n */\nexport function buildOutcomeBody(\n outcome: SpecOutcome | IgnoredOutcome,\n harness?: Harness,\n): Record<string, unknown> {\n const spec: Partial<SpecOutcome> = outcome.status === 'ignored' ? {} : outcome;\n return {\n schemaVersion: 1,\n id: outcome.id,\n ...(harness !== undefined ? { harness } : {}),\n status: outcome.status,\n ...(outcome.reason !== undefined ? { reason: outcome.reason } : {}),\n ...(spec.httpStatus !== undefined ? { httpStatus: spec.httpStatus } : {}),\n ...(spec.ms !== undefined ? { ms: Math.max(0, Math.round(spec.ms)) } : {}),\n ...(spec.via !== undefined ? { via: spec.via } : {}),\n };\n}\n\n/**\n * The `forget` form, pinned to the shared fixture: delete every packet the\n * server kept for this install. The install is the `tenjin-install-id` header\n * the transport already sends to Tenjin's origins, so the body names nothing.\n */\nexport function buildForgetBody(): Record<string, unknown> {\n return { schemaVersion: 1, forget: 'samples' };\n}\n\n/**\n * ASK THE SERVER TO DELETE WHAT \"HELP IMPROVE ROUTING\" KEPT, on the free\n * route, under the outcome report's short deadline. Never throws: the answer\n * is whether it was done, or why not, for the caller to say.\n */\nexport async function requestForget(\n deps: Pick<DecisionDeps, 'baseUrl' | 'fetchImpl'>,\n): Promise<{ ok: true } | { ok: false; reason: string }> {\n try {\n const response = await httpRequest(new URL(ROUTER_PATH, deps.baseUrl).toString(), {\n method: 'POST',\n timeoutMs: OUTCOME_TIMEOUT_MS,\n blockRedirects: true,\n jsonBody: buildForgetBody(),\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n });\n if (!response.ok) return { ok: false, reason: fetchFailureToCliError(response).message };\n if (response.status >= 200 && response.status < 300) return { ok: true };\n return { ok: false, reason: `the router endpoint answered ${response.status}` };\n } catch (err) {\n return { ok: false, reason: err instanceof Error ? err.message : String(err) };\n }\n}\n\nfunction readDecision<T extends z.ZodTypeAny>(\n response: HttpResult,\n schema: T,\n): DecisionOutcome<z.infer<T>> {\n // A transport failure says its own reason.\n if (!response.ok) {\n return {\n status: 'failed',\n reason: fetchFailureToCliError(response).message,\n ...(isUnreachable(response) ? { unreachable: true as const } : {}),\n ...(response.status === undefined ? { noAnswer: true as const } : {}),\n };\n }\n if (response.status < 200 || response.status >= 300) {\n const named = errorOf(response.json);\n return {\n status: 'failed',\n // The backend's own code and message, never a bare status line: a typed\n // refusal the host could act on was arriving as \"answered 400\".\n reason:\n named === null\n ? `The router endpoint answered ${response.status}.`\n : `The router endpoint answered ${response.status} (${named.code}): ${named.message}`,\n ...(named !== null ? { errorCode: named.code } : {}),\n };\n }\n const parsed = schema.safeParse(response.json);\n if (!parsed.success) {\n return { status: 'failed', reason: 'The router returned a decision this build cannot read.' };\n }\n return { status: 'decided', decision: parsed.data as z.infer<T> };\n}\n\n/** A hook or tool answer, read, with each offer this build cannot run taken\n * out ({@link withoutUnmet}). */\nfunction readOffer<R extends HookResponse | ToolResponse>(\n response: HttpResult,\n schema: z.ZodType<R>,\n): DecisionOutcome<R> {\n const read = readDecision(response, schema);\n if (read.status !== 'decided') return read;\n const { decision, skipped } = withoutUnmet(read.decision.decision);\n return {\n ...read,\n decision: { ...read.decision, decision },\n ...(skipped.length > 0 ? { skipped } : {}),\n };\n}\n\n/** `{ error: { code, message } }`, the envelope every Tenjin route answers a\n * refusal with. Anything else reads as no code rather than as a guess. */\nfunction errorOf(body: unknown): { code: string; message: string } | null {\n if (body === null || typeof body !== 'object') return null;\n const error = (body as { error?: unknown }).error;\n if (error === null || typeof error !== 'object') return null;\n const { code, message } = error as { code?: unknown; message?: unknown };\n if (typeof code !== 'string' || code.length === 0 || code.length > 64) return null;\n const text = typeof message === 'string' ? message.slice(0, 500) : '';\n return { code, message: text };\n}\n\n/** A dropped socket, which a fresh connection usually gets past. */\nconst RESET_CODES = new Set(['ECONNRESET', 'UND_ERR_SOCKET']);\n\n/**\n * A ROUTER THAT CANNOT BE REACHED: the transport named the layer that refused\n * the connection (DNS, TLS, a refused connection, a proxy refusing the tunnel)\n * and no status came back. Never the call's own timeout: that is the gate's\n * few seconds, and a slow decision or a cold start must not take the router\n * away from every session. Never a status, even with a body that failed to\n * read, and never a reset socket, which a fresh connection usually gets past.\n */\nexport function isUnreachable(failure: FetchJsonFailure): boolean {\n return (\n failure.kind === 'network' &&\n failure.status === undefined &&\n failure.transport !== undefined &&\n !RESET_CODES.has(failure.transport.code ?? '')\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiCO,IAAM,cAAc;AAEpB,IAAM,kBAAkB;AAO/B,IAAM,gBAAgB,iBAAE,OAAO;AAAA,EAC7B,KAAK,iBAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,KAAM;AAAA,EACjC,QAAQ,iBAAE,KAAK,CAAC,OA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model-limits.ts
4
+ var MODEL_ROUTE_BODY_BYTES = 16384;
5
+ var MODEL_ROUTE_ENVELOPE_BYTES = 64;
6
+ var MODEL_NATIVE_TEXT_BYTES = 256e3;
7
+ var MODEL_OUTPUT_TOKENS = 65536;
8
+ var MODEL_OUTPUT_FLOOR_TOKENS = 8192;
9
+ var MODEL_OUTPUT_TOKENS_MAX = 256e3;
10
+ function offeredOutputTokens(decision) {
11
+ const offered = decision.maxOutputTokens;
12
+ if (typeof offered !== "number" || !Number.isSafeInteger(offered) || offered <= 0)
13
+ throw new Error("The offer names no output cap");
14
+ return Math.min(offered, MODEL_OUTPUT_TOKENS_MAX);
15
+ }
16
+ var MODEL_CONTEXT_TOKENS = 1048576;
17
+ var COMPACT_HEADROOM_TOKENS = 65536;
18
+ function compactWindowTokens(outputCap) {
19
+ return Math.floor(
20
+ Math.min(
21
+ MODEL_CONTEXT_TOKENS * 0.8,
22
+ MODEL_CONTEXT_TOKENS - outputCap - COMPACT_HEADROOM_TOKENS
23
+ )
24
+ );
25
+ }
26
+ var MODEL_PAID_CALL_MARGIN_MS = 6e4;
27
+ function paidCallTimeoutMs(decision) {
28
+ const offered = decision.maxCallDurationMs;
29
+ if (typeof offered !== "number" || !Number.isSafeInteger(offered) || offered < 0)
30
+ throw new Error("The offer names no call deadline");
31
+ return Math.min(offered + MODEL_PAID_CALL_MARGIN_MS, 2 ** 31 - 1);
32
+ }
33
+ var QUOTE_BYTES_PER_INPUT_TOKEN = 3;
34
+ function modelPeakQuoteAtomic(bytes, outputTokens) {
35
+ const usage = (BigInt(Math.min(1048576, Math.ceil(bytes / QUOTE_BYTES_PER_INPUT_TOKEN) + 4096)) * 300n + BigInt(outputTokens) * 1200n + 999n) / 1000n;
36
+ return usage + (usage * 5n + 99n) / 100n;
37
+ }
38
+ function outputTokensPaidBy(atomic) {
39
+ return Number((atomic * 100000n + 125999n) / 126000n);
40
+ }
41
+ function fittingOutputTokens(bytes, asked, remaining) {
42
+ if (asked <= MODEL_OUTPUT_FLOOR_TOKENS || modelPeakQuoteAtomic(bytes, asked) <= remaining)
43
+ return asked;
44
+ let fits = MODEL_OUTPUT_FLOOR_TOKENS;
45
+ let over = asked;
46
+ while (over - fits > 1) {
47
+ const middle = Math.floor((fits + over) / 2);
48
+ if (modelPeakQuoteAtomic(bytes, middle) <= remaining) fits = middle;
49
+ else over = middle;
50
+ }
51
+ return fits;
52
+ }
53
+ var MODEL_MINIMUM_CALL_ATOMIC = modelPeakQuoteAtomic(0, MODEL_OUTPUT_TOKENS);
54
+ var MODEL_FLOOR_CALL_ATOMIC = modelPeakQuoteAtomic(0, MODEL_OUTPUT_FLOOR_TOKENS);
55
+ var usdOfAtomic = (atomic) => "$" + (Number(atomic) / 1e6).toFixed(6);
56
+ var MODEL_RESPONSE_ENVELOPE_BYTES = 45e5;
57
+ var MODEL_MESSAGES_RESULT_BYTES = 2e6;
58
+ var MODEL_MESSAGES_RESULT_BYTES_MAX = 4e6;
59
+ var MODEL_MESSAGES_MAX_TOOLS = 256;
60
+
61
+ export {
62
+ MODEL_ROUTE_BODY_BYTES,
63
+ MODEL_ROUTE_ENVELOPE_BYTES,
64
+ MODEL_NATIVE_TEXT_BYTES,
65
+ MODEL_OUTPUT_TOKENS,
66
+ MODEL_OUTPUT_FLOOR_TOKENS,
67
+ MODEL_OUTPUT_TOKENS_MAX,
68
+ offeredOutputTokens,
69
+ compactWindowTokens,
70
+ paidCallTimeoutMs,
71
+ modelPeakQuoteAtomic,
72
+ outputTokensPaidBy,
73
+ fittingOutputTokens,
74
+ MODEL_MINIMUM_CALL_ATOMIC,
75
+ MODEL_FLOOR_CALL_ATOMIC,
76
+ usdOfAtomic,
77
+ MODEL_RESPONSE_ENVELOPE_BYTES,
78
+ MODEL_MESSAGES_RESULT_BYTES,
79
+ MODEL_MESSAGES_RESULT_BYTES_MAX,
80
+ MODEL_MESSAGES_MAX_TOOLS
81
+ };
82
+ //# sourceMappingURL=chunk-ZRC7Z5X3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/router/model-limits.ts"],"sourcesContent":["export const MODEL_ROUTE_BODY_BYTES = 16_384;\nexport const MODEL_ROUTE_ENVELOPE_BYTES = 64;\nexport const MODEL_NATIVE_TEXT_BYTES = 256_000;\n/** The output cap a side request keeps (the auto-mode classifier's own, a search): the\n * least a worker's own turn asks for by default. */\nexport const MODEL_OUTPUT_TOKENS = 65_536;\n/**\n * The least output a call is stepped down to when the job's ceiling cannot hold more. The\n * router accepts any `max_tokens` from 1 (its contract), so this is Tenjin's own floor: a\n * reply of this size is still useful, and the call still goes on when little is left.\n */\nexport const MODEL_OUTPUT_FLOOR_TOKENS = 8_192;\n/** The DeepSeek harness's output cap per request, and the most this CLI asks for: Claude\n * Code 2.1.325 and 2.1.328 took a reply of that many reported tokens whole. */\nexport const MODEL_OUTPUT_TOKENS_MAX = 256_000;\n/**\n * THE OUTPUT CAP OF A JOB'S MODEL CALLS: what its router's offer says its Messages endpoint\n * accepts (`maxOutputTokens`), up to 256,000, the DeepSeek harness's cap (operator ruling\n * 2026-11-18). The offer always names it; an offer that does not is invalid and the call\n * stays native.\n */\nexport function offeredOutputTokens(decision: Record<string, unknown>): number {\n const offered = decision.maxOutputTokens;\n if (typeof offered !== 'number' || !Number.isSafeInteger(offered) || offered <= 0)\n throw new Error('The offer names no output cap');\n return Math.min(offered, MODEL_OUTPUT_TOKENS_MAX);\n}\n/** The context of the DeepSeek model a worker runs on. */\nexport const MODEL_CONTEXT_TOKENS = 1_048_576;\n/** The room the DeepSeek harness leaves above its compaction trigger for a request's own overhead. */\nconst COMPACT_HEADROOM_TOKENS = 65_536;\n/**\n * WHERE A WORKER COMPACTS ITS CONVERSATION, as the DeepSeek harness's `compaction-basic`\n * does at its defaults (read in its source, `config.ts`): `floor(min(0.8 * window, window -\n * reply cap - 65,536 headroom))`, with the reply cap of the job's own calls. 838,860 at\n * 65,536, 727,040 at 256,000. A fixed value leaves a reply that is allowed to be longer\n * without room: 786,432 and a 256,000 reply is 1,042,432 of 1,048,576.\n * This is the WINDOW Claude Code reads from `CLAUDE_CODE_AUTO_COMPACT_WINDOW`. It takes\n * `min(its max output tokens, 20,000) + 13,000` off the window (read in 2.1.327), so compaction\n * fires 33,000 tokens earlier than this value: about 805,860 and 694,040.\n */\nexport function compactWindowTokens(outputCap: number): number {\n return Math.floor(\n Math.min(\n MODEL_CONTEXT_TOKENS * 0.8,\n MODEL_CONTEXT_TOKENS - outputCap - COMPACT_HEADROOM_TOKENS,\n ),\n );\n}\n/**\n * THE MINUTE THE CLIENT LEAVES over the deadline an offer names, so the router's own cut\n * arrives before the client's. A client that gave up first would end a call the router is\n * still serving, and its charge would be uncertain.\n */\nconst MODEL_PAID_CALL_MARGIN_MS = 60_000;\n/**\n * THE WAIT FOR ONE PAID CALL ON THIS JOB'S ROUTER: the `maxCallDurationMs` its offer names\n * (a non-negative integer, the router's total deadline for one call) plus the margin. A\n * router that allows longer is waited on longer, one that allows less is not waited on past\n * its word. The offer always names it; an offer that does not is invalid.\n */\nexport function paidCallTimeoutMs(decision: Record<string, unknown>): number {\n const offered = decision.maxCallDurationMs;\n if (typeof offered !== 'number' || !Number.isSafeInteger(offered) || offered < 0)\n throw new Error('The offer names no call deadline');\n // Clamped to the longest wait a timer holds: a longer one would fire after 1 ms.\n return Math.min(offered + MODEL_PAID_CALL_MARGIN_MS, 2 ** 31 - 1);\n}\n/** Request-body bytes the router counts as one input token in a quote. Mirrors the router. */\nconst QUOTE_BYTES_PER_INPUT_TOKEN = 3;\n/**\n * The router's peak Messages quote, as its `quoteAtomic` makes it (tariff\n * deepseek-flash-1017-2026-11-13): one input token for each 3 bytes of request body (rounded\n * up) plus 4096 framing, at most the 1,048,576-token context, at 300 per thousand, the\n * requested output at 1,200 per thousand, rounded up, then the 5% proxy fee rounded up.\n */\nexport function modelPeakQuoteAtomic(bytes: number, outputTokens: number): bigint {\n const usage =\n (BigInt(Math.min(1_048_576, Math.ceil(bytes / QUOTE_BYTES_PER_INPUT_TOKEN) + 4096)) * 300n +\n BigInt(outputTokens) * 1200n +\n 999n) /\n 1000n;\n return usage + (usage * 5n + 99n) / 100n;\n}\n/**\n * How many output tokens `atomic` pays for at the quote's output rate (1,200 per thousand\n * plus the 5% proxy fee), rounded up: what a call lowers its limit by to take back `atomic`\n * of a quote that is too high.\n */\nexport function outputTokensPaidBy(atomic: bigint): number {\n return Number((atomic * 100_000n + 125_999n) / 126_000n);\n}\n/**\n * THE LARGEST OUTPUT CAP, FROM `asked` DOWN, WHOSE PEAK QUOTE FITS `remaining` of a job's\n * ceiling for a request of `bytes`. A quote reserves the input (each 3 bytes of body counted as a\n * token, at the full input rate, up to the context) and the output a call asks for, so near\n * the end of a job's ceiling the call asks for less output and the job goes on. Never below\n * 8,192: under that the call's quote is above what is left and the budget rule decides.\n */\nexport function fittingOutputTokens(bytes: number, asked: number, remaining: bigint): number {\n if (asked <= MODEL_OUTPUT_FLOOR_TOKENS || modelPeakQuoteAtomic(bytes, asked) <= remaining)\n return asked;\n let fits = MODEL_OUTPUT_FLOOR_TOKENS;\n let over = asked;\n while (over - fits > 1) {\n const middle = Math.floor((fits + over) / 2);\n if (modelPeakQuoteAtomic(bytes, middle) <= remaining) fits = middle;\n else over = middle;\n }\n return fits;\n}\n/**\n * The least job ceiling Tenjin offers a job under, and the floor configuration refuses below:\n * one call at 65,536 output tokens with no body, so a job can pay a normal call and its fee.\n */\nexport const MODEL_MINIMUM_CALL_ATOMIC = modelPeakQuoteAtomic(0, MODEL_OUTPUT_TOKENS);\n/** The least a call can reserve: no body, the 8,192 output tokens it steps down to. */\nexport const MODEL_FLOOR_CALL_ATOMIC = modelPeakQuoteAtomic(0, MODEL_OUTPUT_FLOOR_TOKENS);\n/** A floor in dollars as the CLI prints it: `$0.083866`. */\nexport const usdOfAtomic = (atomic: bigint): string => '$' + (Number(atomic) / 1e6).toFixed(6);\n/** Full hosted POST receipt or owner-GET JSON envelope, including escaped wire and metadata. */\nexport const MODEL_RESPONSE_ENVELOPE_BYTES = 4_500_000;\n/** The smallest result size a router's offer may name, and the smallest a call may state:\n * the floor the router's own contract takes. */\nexport const MODEL_MESSAGES_RESULT_BYTES = 2_000_000;\n/** The largest this CLI reads from a router whose offer says it honours a stated size. */\nexport const MODEL_MESSAGES_RESULT_BYTES_MAX = 4_000_000;\n/** The router refuses a Messages request that offers more tools than this. */\nexport const MODEL_MESSAGES_MAX_TOOLS = 256;\n"],"mappings":";;;AAAO,IAAM,yBAAyB;AAC/B,IAAM,6BAA6B;AACnC,IAAM,0BAA0B;AAGhC,IAAM,sBAAsB;AAM5B,IAAM,4BAA4B;AAGlC,IAAM,0BAA0B;AAOhC,SAAS,oBAAoB,UAA2C;AAC7E,QAAM,UAAU,SAAS;AACzB,MAAI,OAAO,YAAY,YAAY,CAAC,OAAO,cAAc,OAAO,KAAK,WAAW;AAC9E,UAAM,IAAI,MAAM,+BAA+B;AACjD,SAAO,KAAK,IAAI,SAAS,uBAAuB;AAClD;AAEO,IAAM,uBAAuB;AAEpC,IAAM,0BAA0B;AAWzB,SAAS,oBAAoB,WAA2B;AAC7D,SAAO,KAAK;AAAA,IACV,KAAK;AAAA,MACH,uBAAuB;AAAA,MACvB,uBAAuB,YAAY;AAAA,IACrC;AAAA,EACF;AACF;AAMA,IAAM,4BAA4B;AAO3B,SAAS,kBAAkB,UAA2C;AAC3E,QAAM,UAAU,SAAS;AACzB,MAAI,OAAO,YAAY,YAAY,CAAC,OAAO,cAAc,OAAO,KAAK,UAAU;AAC7E,UAAM,IAAI,MAAM,kCAAkC;AAEpD,SAAO,KAAK,IAAI,UAAU,2BAA2B,KAAK,KAAK,CAAC;AAClE;AAEA,IAAM,8BAA8B;AAO7B,SAAS,qBAAqB,OAAe,cAA8B;AAChF,QAAM,SACH,OAAO,KAAK,IAAI,SAAW,KAAK,KAAK,QAAQ,2BAA2B,IAAI,IAAI,CAAC,IAAI,OACpF,OAAO,YAAY,IAAI,QACvB,QACF;AACF,SAAO,SAAS,QAAQ,KAAK,OAAO;AACtC;AAMO,SAAS,mBAAmB,QAAwB;AACzD,SAAO,QAAQ,SAAS,UAAW,WAAY,OAAQ;AACzD;AAQO,SAAS,oBAAoB,OAAe,OAAe,WAA2B;AAC3F,MAAI,SAAS,6BAA6B,qBAAqB,OAAO,KAAK,KAAK;AAC9E,WAAO;AACT,MAAI,OAAO;AACX,MAAI,OAAO;AACX,SAAO,OAAO,OAAO,GAAG;AACtB,UAAM,SAAS,KAAK,OAAO,OAAO,QAAQ,CAAC;AAC3C,QAAI,qBAAqB,OAAO,MAAM,KAAK,UAAW,QAAO;AAAA,QACxD,QAAO;AAAA,EACd;AACA,SAAO;AACT;AAKO,IAAM,4BAA4B,qBAAqB,GAAG,mBAAmB;AAE7E,IAAM,0BAA0B,qBAAqB,GAAG,yBAAyB;AAEjF,IAAM,cAAc,CAAC,WAA2B,OAAO,OAAO,MAAM,IAAI,KAAK,QAAQ,CAAC;AAEtF,IAAM,gCAAgC;AAGtC,IAAM,8BAA8B;AAEpC,IAAM,kCAAkC;AAExC,IAAM,2BAA2B;","names":[]}
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-JTX3BUDK.js";
11
11
  import {
12
12
  external_exports
13
- } from "./chunk-QEZZDIQT.js";
13
+ } from "./chunk-P6YQWIT2.js";
14
14
  import {
15
15
  CliError
16
16
  } from "./chunk-DI4QAGRZ.js";
@@ -71,4 +71,4 @@ export {
71
71
  readPassphraseRecord,
72
72
  writePassphraseRecord
73
73
  };
74
- //# sourceMappingURL=chunk-I47ARU5G.js.map
74
+ //# sourceMappingURL=chunk-ZS7JIUJ3.js.map
@@ -9,10 +9,11 @@ import {
9
9
  meetsFloor,
10
10
  parseClaudeVersion,
11
11
  readClaudeCode,
12
+ readClaudeCodeCached,
12
13
  runClaude,
13
14
  userMcpFile,
14
15
  userSettingsPath
15
- } from "./chunk-QXP3Z3JN.js";
16
+ } from "./chunk-4MBCJFY4.js";
16
17
  import "./chunk-ZXTAQYNA.js";
17
18
  export {
18
19
  CLAUDE_CODE_FLOOR,
@@ -24,8 +25,9 @@ export {
24
25
  meetsFloor,
25
26
  parseClaudeVersion,
26
27
  readClaudeCode,
28
+ readClaudeCodeCached,
27
29
  runClaude,
28
30
  userMcpFile,
29
31
  userSettingsPath
30
32
  };
31
- //# sourceMappingURL=claude-cli-2YKABJJZ.js.map
33
+ //# sourceMappingURL=claude-cli-GIIHOBGT.js.map
@@ -0,0 +1,64 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ claudeInstallAt,
4
+ settingsInstallPaths
5
+ } from "./chunk-65RS4LQS.js";
6
+ import "./chunk-QKEUKBRK.js";
7
+ import "./chunk-Y2EXZ47H.js";
8
+ import "./chunk-F43CV6UC.js";
9
+ import "./chunk-HQR4BWKX.js";
10
+ import "./chunk-OJJFANO6.js";
11
+ import "./chunk-34SAECKZ.js";
12
+ import "./chunk-I557SAOM.js";
13
+ import "./chunk-IULCDMVG.js";
14
+ import "./chunk-WXA3WTPF.js";
15
+ import "./chunk-QQDPRTLP.js";
16
+ import "./chunk-P4I7BFNJ.js";
17
+ import "./chunk-4MBCJFY4.js";
18
+ import "./chunk-OC7K2DVZ.js";
19
+ import "./chunk-5F4OB5B3.js";
20
+ import "./chunk-ZS7JIUJ3.js";
21
+ import "./chunk-JWAK7JQB.js";
22
+ import "./chunk-4TPL54KW.js";
23
+ import "./chunk-ZRC7Z5X3.js";
24
+ import "./chunk-QQYCYAKI.js";
25
+ import "./chunk-LDA6TAYQ.js";
26
+ import "./chunk-W74LJ5OT.js";
27
+ import "./chunk-KNKDMTHU.js";
28
+ import "./chunk-3Y6BHIN6.js";
29
+ import "./chunk-R62PKTAG.js";
30
+ import "./chunk-HAZAN4UM.js";
31
+ import "./chunk-KGUE5AVX.js";
32
+ import "./chunk-2W4DQQUU.js";
33
+ import "./chunk-KLDMLWXT.js";
34
+ import "./chunk-HZKANST2.js";
35
+ import "./chunk-MEZJ3I63.js";
36
+ import "./chunk-ILWCKCOI.js";
37
+ import "./chunk-RFZA7PSM.js";
38
+ import "./chunk-JUUBBBY5.js";
39
+ import "./chunk-GH5UKMZD.js";
40
+ import "./chunk-5N4GGUBN.js";
41
+ import "./chunk-W2GXIARJ.js";
42
+ import "./chunk-TFT2X7SH.js";
43
+ import "./chunk-DTEWAVNE.js";
44
+ import "./chunk-UIB33QQP.js";
45
+ import "./chunk-7WEQQJLG.js";
46
+ import "./chunk-ZCT5DJ3G.js";
47
+ import "./chunk-3MZ7DYRO.js";
48
+ import "./chunk-JTX3BUDK.js";
49
+ import "./chunk-ZEYA2WWX.js";
50
+ import "./chunk-DIH2G3YG.js";
51
+ import "./chunk-D6M3ZK66.js";
52
+ import "./chunk-RGCPELQN.js";
53
+ import "./chunk-CRG54LEB.js";
54
+ import "./chunk-TUCKEEXE.js";
55
+ import "./chunk-P6YQWIT2.js";
56
+ import "./chunk-DI4QAGRZ.js";
57
+ import "./chunk-3Y2EHT4F.js";
58
+ import "./chunk-4CE6TMI5.js";
59
+ import "./chunk-ZXTAQYNA.js";
60
+ export {
61
+ claudeInstallAt,
62
+ settingsInstallPaths
63
+ };
64
+ //# sourceMappingURL=claude-install-BAUSJMW3.js.map