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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (495) hide show
  1. package/NOTICE.md +110 -0
  2. package/README.md +87 -81
  3. package/dist/{_esm-BIN7VY2L.js → _esm-2KST7HQ7.js} +7 -7
  4. package/dist/alive-5TV22PNF.js +51 -0
  5. package/dist/auth-XI7BJFLW.js +47 -0
  6. package/dist/{auto-update-Y24UL56V.js → auto-update-7L24KDWA.js} +4 -5
  7. package/dist/balance-DFHC6XEU.js +71 -0
  8. package/dist/{ccip-DHDFKTQV.js → ccip-HOW3DZYF.js} +4 -4
  9. package/dist/chunk-24XKUN2S.js +202 -0
  10. package/dist/chunk-24XKUN2S.js.map +1 -0
  11. package/dist/chunk-2L7TDGLV.js +56 -0
  12. package/dist/chunk-2L7TDGLV.js.map +1 -0
  13. package/dist/{chunk-C2Q76BVM.js → chunk-2U7H35IP.js} +29 -7
  14. package/dist/chunk-2U7H35IP.js.map +1 -0
  15. package/dist/chunk-2W4DQQUU.js +176 -0
  16. package/dist/chunk-2W4DQQUU.js.map +1 -0
  17. package/dist/{chunk-LRW6S53P.js → chunk-34SAECKZ.js} +35 -11
  18. package/dist/chunk-34SAECKZ.js.map +1 -0
  19. package/dist/{chunk-2I4QTOLB.js → chunk-3MZ7DYRO.js} +1 -1
  20. package/dist/chunk-3MZ7DYRO.js.map +1 -0
  21. package/dist/{chunk-RVPYTUP4.js → chunk-3Y2EHT4F.js} +13 -9
  22. package/dist/chunk-3Y2EHT4F.js.map +1 -0
  23. package/dist/chunk-3Y6BHIN6.js +169 -0
  24. package/dist/chunk-3Y6BHIN6.js.map +1 -0
  25. package/dist/{chunk-4K7TQHNP.js → chunk-3YPL6T3P.js} +17 -33
  26. package/dist/chunk-3YPL6T3P.js.map +1 -0
  27. package/dist/{chunk-E7SW44LM.js → chunk-44MVIRZH.js} +121 -6
  28. package/dist/chunk-44MVIRZH.js.map +1 -0
  29. package/dist/chunk-45MMSBHA.js +321 -0
  30. package/dist/chunk-45MMSBHA.js.map +1 -0
  31. package/dist/{chunk-3FMZGI7I.js → chunk-4CE6TMI5.js} +1 -1
  32. package/dist/chunk-4CE6TMI5.js.map +1 -0
  33. package/dist/{chunk-QXP3Z3JN.js → chunk-4MBCJFY4.js} +35 -3
  34. package/dist/chunk-4MBCJFY4.js.map +1 -0
  35. package/dist/chunk-4TPL54KW.js +227 -0
  36. package/dist/chunk-4TPL54KW.js.map +1 -0
  37. package/dist/chunk-54ELBTKE.js +1615 -0
  38. package/dist/chunk-54ELBTKE.js.map +1 -0
  39. package/dist/{chunk-NDGZDTSJ.js → chunk-5F4OB5B3.js} +115 -57
  40. package/dist/chunk-5F4OB5B3.js.map +1 -0
  41. package/dist/chunk-5HN4KVQU.js +3348 -0
  42. package/dist/chunk-5HN4KVQU.js.map +1 -0
  43. package/dist/{chunk-ZDZERB6L.js → chunk-5J4E5GYI.js} +572 -407
  44. package/dist/chunk-5J4E5GYI.js.map +1 -0
  45. package/dist/{chunk-ZNNXRNFD.js → chunk-5N4GGUBN.js} +48 -6
  46. package/dist/chunk-5N4GGUBN.js.map +1 -0
  47. package/dist/chunk-5USBZ2MU.js +58 -0
  48. package/dist/chunk-5USBZ2MU.js.map +1 -0
  49. package/dist/chunk-64WOMNYR.js +183 -0
  50. package/dist/chunk-64WOMNYR.js.map +1 -0
  51. package/dist/{chunk-ILNIZ5I2.js → chunk-65RS4LQS.js} +1825 -1715
  52. package/dist/chunk-65RS4LQS.js.map +1 -0
  53. package/dist/{chunk-IE7P2BZE.js → chunk-6QMDUDF2.js} +3 -3
  54. package/dist/{chunk-IADZOXKN.js → chunk-7SLOTLO7.js} +19 -697
  55. package/dist/chunk-7SLOTLO7.js.map +1 -0
  56. package/dist/{chunk-WFSPCCVW.js → chunk-7V25UAQO.js} +99 -99
  57. package/dist/{chunk-WFSPCCVW.js.map → chunk-7V25UAQO.js.map} +1 -1
  58. package/dist/chunk-BGA4DO5M.js +719 -0
  59. package/dist/chunk-BGA4DO5M.js.map +1 -0
  60. package/dist/chunk-BVP7YK2J.js +706 -0
  61. package/dist/chunk-BVP7YK2J.js.map +1 -0
  62. package/dist/chunk-C265QIMJ.js +83 -0
  63. package/dist/chunk-C265QIMJ.js.map +1 -0
  64. package/dist/{chunk-XQJXNMSB.js → chunk-CRG54LEB.js} +1 -1
  65. package/dist/chunk-CRG54LEB.js.map +1 -0
  66. package/dist/{chunk-KG3D7FIF.js → chunk-CZJOMUBP.js} +2 -2
  67. package/dist/{chunk-36RVGZNY.js → chunk-D6M3ZK66.js} +22 -39
  68. package/dist/chunk-D6M3ZK66.js.map +1 -0
  69. package/dist/{chunk-3UCIG4TG.js → chunk-DI4QAGRZ.js} +1 -11
  70. package/dist/chunk-DI4QAGRZ.js.map +1 -0
  71. package/dist/{chunk-JKKAIPTU.js → chunk-DIH2G3YG.js} +47 -10
  72. package/dist/chunk-DIH2G3YG.js.map +1 -0
  73. package/dist/chunk-DJ36BM62.js +78 -0
  74. package/dist/chunk-DJ36BM62.js.map +1 -0
  75. package/dist/chunk-DTEWAVNE.js +114 -0
  76. package/dist/chunk-DTEWAVNE.js.map +1 -0
  77. package/dist/chunk-F2KJAJ7T.js +13 -0
  78. package/dist/chunk-F2KJAJ7T.js.map +1 -0
  79. package/dist/{chunk-BF4XHEQK.js → chunk-F3QPGYOY.js} +6 -6
  80. package/dist/chunk-F3QPGYOY.js.map +1 -0
  81. package/dist/{chunk-3GNJXKIT.js → chunk-F43CV6UC.js} +2 -2
  82. package/dist/{chunk-J57UC3DD.js → chunk-FKVJKLPI.js} +3 -3
  83. package/dist/{chunk-V2LQLN5H.js → chunk-FYFHH7V5.js} +59 -8
  84. package/dist/{chunk-V2LQLN5H.js.map → chunk-FYFHH7V5.js.map} +1 -1
  85. package/dist/chunk-GAJC4BQZ.js +1096 -0
  86. package/dist/chunk-GAJC4BQZ.js.map +1 -0
  87. package/dist/{chunk-DOQGNFHM.js → chunk-GH5UKMZD.js} +2 -12
  88. package/dist/{chunk-DOQGNFHM.js.map → chunk-GH5UKMZD.js.map} +1 -1
  89. package/dist/{chunk-WYXUQGOL.js → chunk-HAZAN4UM.js} +7 -6
  90. package/dist/chunk-HAZAN4UM.js.map +1 -0
  91. package/dist/chunk-HI5XQOX2.js +393 -0
  92. package/dist/chunk-HI5XQOX2.js.map +1 -0
  93. package/dist/chunk-HKGUKAQW.js +488 -0
  94. package/dist/chunk-HKGUKAQW.js.map +1 -0
  95. package/dist/{chunk-SO3XRZPX.js → chunk-HPRVFJPM.js} +6 -6
  96. package/dist/{chunk-L6JEXB3E.js → chunk-HQR4BWKX.js} +3 -131
  97. package/dist/chunk-HQR4BWKX.js.map +1 -0
  98. package/dist/chunk-HZKANST2.js +177 -0
  99. package/dist/chunk-HZKANST2.js.map +1 -0
  100. package/dist/{chunk-UUGOUOVT.js → chunk-I557SAOM.js} +8 -2
  101. package/dist/chunk-I557SAOM.js.map +1 -0
  102. package/dist/{chunk-TC2WZLSC.js → chunk-IGLWLH73.js} +8 -7
  103. package/dist/chunk-IGLWLH73.js.map +1 -0
  104. package/dist/chunk-ILWCKCOI.js +58 -0
  105. package/dist/chunk-ILWCKCOI.js.map +1 -0
  106. package/dist/{chunk-2GP3HRYK.js → chunk-INSIW65E.js} +182 -182
  107. package/dist/{chunk-MPZUYCAP.js → chunk-IULCDMVG.js} +12 -1
  108. package/dist/chunk-IULCDMVG.js.map +1 -0
  109. package/dist/{chunk-INTFHMU4.js → chunk-IVNSUAVC.js} +25 -26
  110. package/dist/chunk-IVNSUAVC.js.map +1 -0
  111. package/dist/chunk-JDQZCREI.js +87 -0
  112. package/dist/chunk-JDQZCREI.js.map +1 -0
  113. package/dist/chunk-JHFFUVON.js +1050 -0
  114. package/dist/chunk-JHFFUVON.js.map +1 -0
  115. package/dist/{chunk-RL5UUDT4.js → chunk-JNUKLSMZ.js} +3 -3
  116. package/dist/chunk-JTILUN4W.js +2933 -0
  117. package/dist/chunk-JTILUN4W.js.map +1 -0
  118. package/dist/{chunk-OJNTCYQQ.js → chunk-JTX3BUDK.js} +37 -53
  119. package/dist/chunk-JTX3BUDK.js.map +1 -0
  120. package/dist/{chunk-X5ZBP3IY.js → chunk-JUUBBBY5.js} +2 -2
  121. package/dist/chunk-JUUBBBY5.js.map +1 -0
  122. package/dist/chunk-JWAK7JQB.js +15 -0
  123. package/dist/chunk-JWAK7JQB.js.map +1 -0
  124. package/dist/{chunk-UXZONNEQ.js → chunk-K5KNGC4I.js} +34 -31
  125. package/dist/chunk-K5KNGC4I.js.map +1 -0
  126. package/dist/chunk-KAQ4Q3TO.js +135 -0
  127. package/dist/chunk-KAQ4Q3TO.js.map +1 -0
  128. package/dist/chunk-KFVJYLVL.js +125 -0
  129. package/dist/chunk-KFVJYLVL.js.map +1 -0
  130. package/dist/chunk-KGUE5AVX.js +69 -0
  131. package/dist/chunk-KGUE5AVX.js.map +1 -0
  132. package/dist/{chunk-FVIGCDSV.js → chunk-KLDMLWXT.js} +11 -85
  133. package/dist/chunk-KLDMLWXT.js.map +1 -0
  134. package/dist/chunk-KNKDMTHU.js +453 -0
  135. package/dist/chunk-KNKDMTHU.js.map +1 -0
  136. package/dist/chunk-LDA6TAYQ.js +95 -0
  137. package/dist/chunk-LDA6TAYQ.js.map +1 -0
  138. package/dist/chunk-LWSSIZOY.js +347 -0
  139. package/dist/chunk-LWSSIZOY.js.map +1 -0
  140. package/dist/{chunk-ZURZHELF.js → chunk-MAHNZA6C.js} +158 -41
  141. package/dist/chunk-MAHNZA6C.js.map +1 -0
  142. package/dist/chunk-MEWZCIA6.js +220 -0
  143. package/dist/chunk-MEWZCIA6.js.map +1 -0
  144. package/dist/{chunk-2SNUOHAT.js → chunk-MEZJ3I63.js} +49 -1
  145. package/dist/chunk-MEZJ3I63.js.map +1 -0
  146. package/dist/chunk-MJDO4EXD.js +353 -0
  147. package/dist/chunk-MJDO4EXD.js.map +1 -0
  148. package/dist/chunk-NJA6NT3A.js +6595 -0
  149. package/dist/chunk-NJA6NT3A.js.map +1 -0
  150. package/dist/{chunk-LHHMV4GU.js → chunk-NVSKJPRC.js} +1 -1
  151. package/dist/{chunk-LHHMV4GU.js.map → chunk-NVSKJPRC.js.map} +1 -1
  152. package/dist/{chunk-4YOZGGTZ.js → chunk-OC7K2DVZ.js} +5 -5
  153. package/dist/chunk-OC7K2DVZ.js.map +1 -0
  154. package/dist/chunk-ODRPASFP.js +2078 -0
  155. package/dist/chunk-ODRPASFP.js.map +1 -0
  156. package/dist/chunk-OJJFANO6.js +133 -0
  157. package/dist/chunk-OJJFANO6.js.map +1 -0
  158. package/dist/{chunk-JNJWBTU2.js → chunk-OQWPRFAC.js} +332 -882
  159. package/dist/chunk-OQWPRFAC.js.map +1 -0
  160. package/dist/chunk-P4I7BFNJ.js +11 -0
  161. package/dist/chunk-P4I7BFNJ.js.map +1 -0
  162. package/dist/{chunk-SNNSAGMT.js → chunk-P6YQWIT2.js} +4058 -4039
  163. package/dist/chunk-P6YQWIT2.js.map +1 -0
  164. package/dist/{chunk-JRGFKVAZ.js → chunk-PETQ5WEA.js} +2 -2
  165. package/dist/{chunk-HMWYAUA6.js → chunk-Q6RSJCXB.js} +29 -69
  166. package/dist/chunk-Q6RSJCXB.js.map +1 -0
  167. package/dist/{chunk-U3IKUGRP.js → chunk-QKEUKBRK.js} +17 -23
  168. package/dist/chunk-QKEUKBRK.js.map +1 -0
  169. package/dist/{chunk-2RWB7RKE.js → chunk-QKYUCITR.js} +174 -5814
  170. package/dist/chunk-QKYUCITR.js.map +1 -0
  171. package/dist/chunk-QQDPRTLP.js +127 -0
  172. package/dist/chunk-QQDPRTLP.js.map +1 -0
  173. package/dist/chunk-QQYCYAKI.js +79 -0
  174. package/dist/chunk-QQYCYAKI.js.map +1 -0
  175. package/dist/chunk-R4KDH477.js +1064 -0
  176. package/dist/chunk-R4KDH477.js.map +1 -0
  177. package/dist/chunk-R5TR2DIK.js +119 -0
  178. package/dist/chunk-R5TR2DIK.js.map +1 -0
  179. package/dist/chunk-R62PKTAG.js +66 -0
  180. package/dist/chunk-R62PKTAG.js.map +1 -0
  181. package/dist/{chunk-BFDQ4WNW.js → chunk-RFZA7PSM.js} +4 -5
  182. package/dist/chunk-RFZA7PSM.js.map +1 -0
  183. package/dist/chunk-RGCPELQN.js +219 -0
  184. package/dist/chunk-RGCPELQN.js.map +1 -0
  185. package/dist/chunk-RGVCOG2S.js +910 -0
  186. package/dist/chunk-RGVCOG2S.js.map +1 -0
  187. package/dist/chunk-SOLNJ3AZ.js +209 -0
  188. package/dist/chunk-SOLNJ3AZ.js.map +1 -0
  189. package/dist/chunk-TFT2X7SH.js +77 -0
  190. package/dist/chunk-TFT2X7SH.js.map +1 -0
  191. package/dist/chunk-TUCKEEXE.js +2 -0
  192. package/dist/chunk-TVWCLUBI.js +293 -0
  193. package/dist/chunk-TVWCLUBI.js.map +1 -0
  194. package/dist/chunk-U4TRWSVE.js +78 -0
  195. package/dist/chunk-U4TRWSVE.js.map +1 -0
  196. package/dist/chunk-UIB33QQP.js +379 -0
  197. package/dist/chunk-UIB33QQP.js.map +1 -0
  198. package/dist/chunk-V6GIVALQ.js +1889 -0
  199. package/dist/chunk-V6GIVALQ.js.map +1 -0
  200. package/dist/chunk-VHXCPXUS.js +366 -0
  201. package/dist/chunk-VHXCPXUS.js.map +1 -0
  202. package/dist/{chunk-HGZEPQUT.js → chunk-VU6GMWF6.js} +17 -8
  203. package/dist/chunk-VU6GMWF6.js.map +1 -0
  204. package/dist/chunk-VWZYE3NC.js +8415 -0
  205. package/dist/chunk-VWZYE3NC.js.map +1 -0
  206. package/dist/{chunk-AGMVASXZ.js → chunk-W2GXIARJ.js} +88 -11
  207. package/dist/chunk-W2GXIARJ.js.map +1 -0
  208. package/dist/chunk-W4G3K3V7.js +288 -0
  209. package/dist/chunk-W4G3K3V7.js.map +1 -0
  210. package/dist/chunk-W74LJ5OT.js +588 -0
  211. package/dist/chunk-W74LJ5OT.js.map +1 -0
  212. package/dist/chunk-W7ELYLYK.js +233 -0
  213. package/dist/chunk-W7ELYLYK.js.map +1 -0
  214. package/dist/{chunk-BPMWXTFX.js → chunk-WFZX352D.js} +7 -7
  215. package/dist/chunk-WXA3WTPF.js +20 -0
  216. package/dist/chunk-WXA3WTPF.js.map +1 -0
  217. package/dist/chunk-XRGFH7FI.js +454 -0
  218. package/dist/chunk-XRGFH7FI.js.map +1 -0
  219. package/dist/chunk-XSCGUO2U.js +330 -0
  220. package/dist/chunk-XSCGUO2U.js.map +1 -0
  221. package/dist/chunk-XWROSMI5.js +1039 -0
  222. package/dist/chunk-XWROSMI5.js.map +1 -0
  223. package/dist/chunk-Y2EXZ47H.js +40 -0
  224. package/dist/chunk-Y2EXZ47H.js.map +1 -0
  225. package/dist/chunk-YJGEVBKZ.js +47 -0
  226. package/dist/chunk-YJGEVBKZ.js.map +1 -0
  227. package/dist/{chunk-6CMM6YCB.js → chunk-YWWMISDY.js} +2 -2
  228. package/dist/{chunk-WXA2BWTE.js → chunk-ZCT5DJ3G.js} +2 -48
  229. package/dist/chunk-ZCT5DJ3G.js.map +1 -0
  230. package/dist/chunk-ZEYA2WWX.js +982 -0
  231. package/dist/chunk-ZEYA2WWX.js.map +1 -0
  232. package/dist/chunk-ZRC7Z5X3.js +82 -0
  233. package/dist/chunk-ZRC7Z5X3.js.map +1 -0
  234. package/dist/{chunk-3AIHRXKO.js → chunk-ZS7JIUJ3.js} +12 -10
  235. package/dist/chunk-ZS7JIUJ3.js.map +1 -0
  236. package/dist/{clack-EZ7TDWQU.js → clack-Q4RNC5VE.js} +2 -6
  237. package/dist/{claude-cli-2YKABJJZ.js → claude-cli-GIIHOBGT.js} +4 -2
  238. package/dist/claude-install-BAUSJMW3.js +64 -0
  239. package/dist/{cli-E36SPKBW.js → cli-QY4KKA3D.js} +632 -150
  240. package/dist/cli-QY4KKA3D.js.map +1 -0
  241. package/dist/client-3YQKORVK.js +710 -0
  242. package/dist/client-3YQKORVK.js.map +1 -0
  243. package/dist/{codex-event-ZO2GEFE6.js → codex-event-EUTCAOTQ.js} +3 -5
  244. package/dist/{codex-host-KECJVTA2.js → codex-host-ZON3S6HU.js} +7 -7
  245. package/dist/{codex-install-HQZDGFXW.js → codex-install-HZV2DOAB.js} +242 -88
  246. package/dist/codex-install-HZV2DOAB.js.map +1 -0
  247. package/dist/config-QZOBMTEL.js +57 -0
  248. package/dist/config-names-Z5NZD5R2.js +224 -0
  249. package/dist/config-names-Z5NZD5R2.js.map +1 -0
  250. package/dist/config-rules-YOYHS6YL.js +55 -0
  251. package/dist/config-subagents-WQV2ZAD5.js +362 -0
  252. package/dist/config-subagents-WQV2ZAD5.js.map +1 -0
  253. package/dist/connect-YDWTYU4B.js +1020 -0
  254. package/dist/connect-YDWTYU4B.js.map +1 -0
  255. package/dist/core-0a66n3e7-TTP554XV.js +127 -0
  256. package/dist/core-0a66n3e7-TTP554XV.js.map +1 -0
  257. package/dist/core-0bmnpbz2-C2JIRVZO.js +10790 -0
  258. package/dist/core-0bmnpbz2-C2JIRVZO.js.map +1 -0
  259. package/dist/core-9je8ee1j-74DGHWPV.js +30 -0
  260. package/dist/core-9je8ee1j-74DGHWPV.js.map +1 -0
  261. package/dist/core-wadgcjfh-TSZFQZGH.js +666 -0
  262. package/dist/core-wadgcjfh-TSZFQZGH.js.map +1 -0
  263. package/dist/core-zg882d22-LKV5DZYW.js +37 -0
  264. package/dist/core-zg882d22-LKV5DZYW.js.map +1 -0
  265. package/dist/decision-QSKHOGCO.js +145 -0
  266. package/dist/{doctor-I6XQEKWD.js → doctor-ZWJXRD75.js} +162 -148
  267. package/dist/doctor-ZWJXRD75.js.map +1 -0
  268. package/dist/{env-proxy-R6ZMLQTT.js → env-proxy-XLSLHBKQ.js} +2 -2
  269. package/dist/{ethersCompat-Df4a6QIZ-X6YZWAML.js → ethersCompat-Df4a6QIZ-K3DMHR6Y.js} +5 -5
  270. package/dist/explicit-ME2NRADQ.js +371 -0
  271. package/dist/explicit-ME2NRADQ.js.map +1 -0
  272. package/dist/flush-stdio-NYIJ3QXT.js +18 -0
  273. package/dist/fund-VF7TLDJH.js +722 -0
  274. package/dist/fund-VF7TLDJH.js.map +1 -0
  275. package/dist/hook-command-VZ27MGWO.js +49 -0
  276. package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
  277. package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +2 -2
  278. package/dist/hosts/claude/tenjin/hooks/hook-data.ts +152 -0
  279. package/dist/hosts/claude/tenjin/hooks/hooks.json +7 -0
  280. package/dist/hosts/claude/tenjin/hooks/model-viewer.tsx +2987 -0
  281. package/dist/hosts/claude/tenjin/hooks/register.tsx +527 -56
  282. package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +14 -4
  283. package/dist/hosts/claude/tenjin/types/index.d.ts +144 -1
  284. package/dist/{hosts-DVQJ32QC.js → hosts-3EMTVM4H.js} +7 -6
  285. package/dist/index.js +18 -15
  286. package/dist/index.js.map +1 -1
  287. package/dist/install-ZA7L2UF3.js +115 -0
  288. package/dist/install-funding-JDGYTF72.js +30 -0
  289. package/dist/install-identity-FFAYEFLX.js +30 -0
  290. package/dist/{install-wallet-5M4OTYLX.js → install-wallet-2SFOVE3Q.js} +68 -53
  291. package/dist/install-wallet-2SFOVE3Q.js.map +1 -0
  292. package/dist/mcp-36S6MK3C.js +67642 -0
  293. package/dist/mcp-36S6MK3C.js.map +1 -0
  294. package/dist/new-install-5L4GY3LN.js +51 -0
  295. package/dist/{package-IJFGMWEV.js → package-BONDXSV3.js} +2 -2
  296. package/dist/{passphrase-IFTDS3CU.js → passphrase-T4ULBN4M.js} +16 -12
  297. package/dist/{paths-XCSAKISU.js → paths-O2KDWZ76.js} +18 -28
  298. package/dist/pay-CMV5KL74.js +74 -0
  299. package/dist/{payments-HFPPWHTV.js → payments-Z6UBZL4Z.js} +36 -26
  300. package/dist/payments-Z6UBZL4Z.js.map +1 -0
  301. package/dist/reclaim-subagent-credit-ABSF67SJ.js +105 -0
  302. package/dist/reclaim-subagent-credit-ABSF67SJ.js.map +1 -0
  303. package/dist/{redact-D7ASVWKL.js → redact-LOTHE5TS.js} +2 -8
  304. package/dist/redact-LOTHE5TS.js.map +1 -0
  305. package/dist/routing-quote-AHLAREXR.js +40 -0
  306. package/dist/routing-quote-AHLAREXR.js.map +1 -0
  307. package/dist/run-JH7ELYAM.js +88 -0
  308. package/dist/run-JH7ELYAM.js.map +1 -0
  309. package/dist/runtime-2GX4ALJP.js +410 -0
  310. package/dist/runtime-2GX4ALJP.js.map +1 -0
  311. package/dist/runtime-activate-IDQ2NCSP.js +39 -0
  312. package/dist/runtime-activate-IDQ2NCSP.js.map +1 -0
  313. package/dist/{runtime-fetch-ZSSSK72Y.js → runtime-fetch-6LOBHBEN.js} +4 -4
  314. package/dist/runtime-fetch-6LOBHBEN.js.map +1 -0
  315. package/dist/runtime-launchers-YAPKCBHV.js +31 -0
  316. package/dist/runtime-launchers-YAPKCBHV.js.map +1 -0
  317. package/dist/{runtime-layout-WIDILZ6K.js → runtime-layout-QHZQJV7C.js} +5 -4
  318. package/dist/runtime-layout-QHZQJV7C.js.map +1 -0
  319. package/dist/runtime-place-4POL4KK4.js +37 -0
  320. package/dist/runtime-place-4POL4KK4.js.map +1 -0
  321. package/dist/runtime-provenance-MNJGVBV2.js +12 -0
  322. package/dist/runtime-provenance-MNJGVBV2.js.map +1 -0
  323. package/dist/{secp256k1-ZZZT2CAX.js → secp256k1-N5P2GVGF.js} +3 -3
  324. package/dist/secp256k1-N5P2GVGF.js.map +1 -0
  325. package/dist/{send-GCVEAQKL.js → send-ELXFKEKY.js} +35 -32
  326. package/dist/send-ELXFKEKY.js.map +1 -0
  327. package/dist/status-FXUFWJDM.js +404 -0
  328. package/dist/status-FXUFWJDM.js.map +1 -0
  329. package/dist/{status-line-OPCXDHL2.js → status-line-IH5JBWBC.js} +51 -43
  330. package/dist/status-line-IH5JBWBC.js.map +1 -0
  331. package/dist/streamableHttp-CP2ZQBIK.js +768 -0
  332. package/dist/streamableHttp-CP2ZQBIK.js.map +1 -0
  333. package/dist/{uninstall-BAWRBXXQ.js → uninstall-LJZUKM4D.js} +76 -76
  334. package/dist/uninstall-LJZUKM4D.js.map +1 -0
  335. package/dist/update-EUIX72IX.js +68 -0
  336. package/dist/update-EUIX72IX.js.map +1 -0
  337. package/dist/usage-EKDC7LUC.js +180 -0
  338. package/dist/usage-EKDC7LUC.js.map +1 -0
  339. package/dist/{usdc-VG4CIOUK.js → usdc-YIHK2OMC.js} +8 -12
  340. package/dist/usdc-YIHK2OMC.js.map +1 -0
  341. package/dist/{viemAdapter-By13KInL-DOFTEIJV.js → viemAdapter-By13KInL-PRLSIESK.js} +5 -5
  342. package/dist/viemAdapter-By13KInL-PRLSIESK.js.map +1 -0
  343. package/dist/wallet-HSW757W6.js +80 -0
  344. package/dist/wallet-HSW757W6.js.map +1 -0
  345. package/dist/wallet-kdf-worker.mjs +1433 -818
  346. package/docs/agent-permissions.md +88 -155
  347. package/docs/router-reference.md +236 -0
  348. package/docs/safety-model.md +31 -33
  349. package/docs/subagents-internals.md +97 -0
  350. package/docs/subagents.md +348 -0
  351. package/docs/troubleshooting.md +10 -6
  352. package/package.json +12 -8
  353. package/scripts/installers/install.sh +7 -1
  354. package/dist/alive-GSOWKUOY.js +0 -38
  355. package/dist/chunk-2I4QTOLB.js.map +0 -1
  356. package/dist/chunk-2M2VPI2E.js +0 -560
  357. package/dist/chunk-2M2VPI2E.js.map +0 -1
  358. package/dist/chunk-2RWB7RKE.js.map +0 -1
  359. package/dist/chunk-2SNUOHAT.js.map +0 -1
  360. package/dist/chunk-3623BLPV.js +0 -184
  361. package/dist/chunk-3623BLPV.js.map +0 -1
  362. package/dist/chunk-36RVGZNY.js.map +0 -1
  363. package/dist/chunk-3AIHRXKO.js.map +0 -1
  364. package/dist/chunk-3FMZGI7I.js.map +0 -1
  365. package/dist/chunk-3UCIG4TG.js.map +0 -1
  366. package/dist/chunk-4K7TQHNP.js.map +0 -1
  367. package/dist/chunk-4LMUQMBH.js +0 -29
  368. package/dist/chunk-4LMUQMBH.js.map +0 -1
  369. package/dist/chunk-4USCZ2NI.js +0 -228
  370. package/dist/chunk-4USCZ2NI.js.map +0 -1
  371. package/dist/chunk-4YOZGGTZ.js.map +0 -1
  372. package/dist/chunk-62KNUYWD.js +0 -111
  373. package/dist/chunk-62KNUYWD.js.map +0 -1
  374. package/dist/chunk-A5GKIG5O.js +0 -2037
  375. package/dist/chunk-A5GKIG5O.js.map +0 -1
  376. package/dist/chunk-AGMVASXZ.js.map +0 -1
  377. package/dist/chunk-BF4XHEQK.js.map +0 -1
  378. package/dist/chunk-BFDQ4WNW.js.map +0 -1
  379. package/dist/chunk-C2Q76BVM.js.map +0 -1
  380. package/dist/chunk-CEXSOI5R.js +0 -808
  381. package/dist/chunk-CEXSOI5R.js.map +0 -1
  382. package/dist/chunk-E7SW44LM.js.map +0 -1
  383. package/dist/chunk-EDJWHDDL.js +0 -33
  384. package/dist/chunk-EDJWHDDL.js.map +0 -1
  385. package/dist/chunk-FVIGCDSV.js.map +0 -1
  386. package/dist/chunk-GTTUCOPD.js +0 -105
  387. package/dist/chunk-GTTUCOPD.js.map +0 -1
  388. package/dist/chunk-HDPUXS3Z.js +0 -122
  389. package/dist/chunk-HDPUXS3Z.js.map +0 -1
  390. package/dist/chunk-HGGWCP7W.js +0 -120
  391. package/dist/chunk-HGGWCP7W.js.map +0 -1
  392. package/dist/chunk-HGZEPQUT.js.map +0 -1
  393. package/dist/chunk-HMWYAUA6.js.map +0 -1
  394. package/dist/chunk-IADZOXKN.js.map +0 -1
  395. package/dist/chunk-ILNIZ5I2.js.map +0 -1
  396. package/dist/chunk-INTFHMU4.js.map +0 -1
  397. package/dist/chunk-JKKAIPTU.js.map +0 -1
  398. package/dist/chunk-JNJWBTU2.js.map +0 -1
  399. package/dist/chunk-KM7RY2ZS.js +0 -246
  400. package/dist/chunk-KM7RY2ZS.js.map +0 -1
  401. package/dist/chunk-KOGZDMHO.js +0 -21
  402. package/dist/chunk-KOGZDMHO.js.map +0 -1
  403. package/dist/chunk-L6JEXB3E.js.map +0 -1
  404. package/dist/chunk-LRW6S53P.js.map +0 -1
  405. package/dist/chunk-LXAYUOXI.js +0 -511
  406. package/dist/chunk-LXAYUOXI.js.map +0 -1
  407. package/dist/chunk-MEFB5KHA.js +0 -59
  408. package/dist/chunk-MEFB5KHA.js.map +0 -1
  409. package/dist/chunk-MPZUYCAP.js.map +0 -1
  410. package/dist/chunk-NDGZDTSJ.js.map +0 -1
  411. package/dist/chunk-OJNTCYQQ.js.map +0 -1
  412. package/dist/chunk-P3LFTKE7.js +0 -58
  413. package/dist/chunk-P3LFTKE7.js.map +0 -1
  414. package/dist/chunk-QXP3Z3JN.js.map +0 -1
  415. package/dist/chunk-RVPYTUP4.js.map +0 -1
  416. package/dist/chunk-SNNSAGMT.js.map +0 -1
  417. package/dist/chunk-TC2WZLSC.js.map +0 -1
  418. package/dist/chunk-TKPF35W6.js +0 -29
  419. package/dist/chunk-TKPF35W6.js.map +0 -1
  420. package/dist/chunk-U3IKUGRP.js.map +0 -1
  421. package/dist/chunk-UUGOUOVT.js.map +0 -1
  422. package/dist/chunk-UXZONNEQ.js.map +0 -1
  423. package/dist/chunk-WXA2BWTE.js.map +0 -1
  424. package/dist/chunk-WYXUQGOL.js.map +0 -1
  425. package/dist/chunk-X5ZBP3IY.js.map +0 -1
  426. package/dist/chunk-XKESD27X.js +0 -10
  427. package/dist/chunk-XKESD27X.js.map +0 -1
  428. package/dist/chunk-XQJXNMSB.js.map +0 -1
  429. package/dist/chunk-Y527D4TV.js +0 -56
  430. package/dist/chunk-Y527D4TV.js.map +0 -1
  431. package/dist/chunk-ZDZERB6L.js.map +0 -1
  432. package/dist/chunk-ZNNXRNFD.js.map +0 -1
  433. package/dist/chunk-ZURZHELF.js.map +0 -1
  434. package/dist/cli-E36SPKBW.js.map +0 -1
  435. package/dist/codex-install-HQZDGFXW.js.map +0 -1
  436. package/dist/config-HY2E4GGW.js +0 -55
  437. package/dist/doctor-I6XQEKWD.js.map +0 -1
  438. package/dist/fund-2QRO7OJL.js +0 -378
  439. package/dist/fund-2QRO7OJL.js.map +0 -1
  440. package/dist/hook-command-2UBCSZG6.js +0 -43
  441. package/dist/install-ILUX5C4A.js +0 -107
  442. package/dist/install-identity-TZKGY6LQ.js +0 -31
  443. package/dist/install-wallet-5M4OTYLX.js.map +0 -1
  444. package/dist/mcp-LE4DUS22.js +0 -14127
  445. package/dist/mcp-LE4DUS22.js.map +0 -1
  446. package/dist/pay-WCG3IH4R.js +0 -55
  447. package/dist/payments-HFPPWHTV.js.map +0 -1
  448. package/dist/plugin-registration-PZFI5GZW.js +0 -68
  449. package/dist/runtime-UZOKSUZX.js +0 -1321
  450. package/dist/runtime-UZOKSUZX.js.map +0 -1
  451. package/dist/send-GCVEAQKL.js.map +0 -1
  452. package/dist/status-HCVAOCN7.js +0 -150
  453. package/dist/status-HCVAOCN7.js.map +0 -1
  454. package/dist/status-line-OPCXDHL2.js.map +0 -1
  455. package/dist/uninstall-BAWRBXXQ.js.map +0 -1
  456. package/dist/update-CACXLQLR.js +0 -56
  457. package/dist/wallet-QL4UUXEZ.js +0 -55
  458. /package/dist/{_esm-BIN7VY2L.js.map → _esm-2KST7HQ7.js.map} +0 -0
  459. /package/dist/{alive-GSOWKUOY.js.map → alive-5TV22PNF.js.map} +0 -0
  460. /package/dist/{auto-update-Y24UL56V.js.map → auth-XI7BJFLW.js.map} +0 -0
  461. /package/dist/{ccip-DHDFKTQV.js.map → auto-update-7L24KDWA.js.map} +0 -0
  462. /package/dist/{clack-EZ7TDWQU.js.map → balance-DFHC6XEU.js.map} +0 -0
  463. /package/dist/{claude-cli-2YKABJJZ.js.map → ccip-HOW3DZYF.js.map} +0 -0
  464. /package/dist/{chunk-IE7P2BZE.js.map → chunk-6QMDUDF2.js.map} +0 -0
  465. /package/dist/{chunk-KG3D7FIF.js.map → chunk-CZJOMUBP.js.map} +0 -0
  466. /package/dist/{chunk-3GNJXKIT.js.map → chunk-F43CV6UC.js.map} +0 -0
  467. /package/dist/{chunk-J57UC3DD.js.map → chunk-FKVJKLPI.js.map} +0 -0
  468. /package/dist/{chunk-SO3XRZPX.js.map → chunk-HPRVFJPM.js.map} +0 -0
  469. /package/dist/{chunk-2GP3HRYK.js.map → chunk-INSIW65E.js.map} +0 -0
  470. /package/dist/{chunk-RL5UUDT4.js.map → chunk-JNUKLSMZ.js.map} +0 -0
  471. /package/dist/{chunk-JRGFKVAZ.js.map → chunk-PETQ5WEA.js.map} +0 -0
  472. /package/dist/{codex-event-ZO2GEFE6.js.map → chunk-TUCKEEXE.js.map} +0 -0
  473. /package/dist/{chunk-BPMWXTFX.js.map → chunk-WFZX352D.js.map} +0 -0
  474. /package/dist/{chunk-6CMM6YCB.js.map → chunk-YWWMISDY.js.map} +0 -0
  475. /package/dist/{codex-host-KECJVTA2.js.map → clack-Q4RNC5VE.js.map} +0 -0
  476. /package/dist/{config-HY2E4GGW.js.map → claude-cli-GIIHOBGT.js.map} +0 -0
  477. /package/dist/{env-proxy-R6ZMLQTT.js.map → claude-install-BAUSJMW3.js.map} +0 -0
  478. /package/dist/{ethersCompat-Df4a6QIZ-X6YZWAML.js.map → codex-event-EUTCAOTQ.js.map} +0 -0
  479. /package/dist/{hook-command-2UBCSZG6.js.map → codex-host-ZON3S6HU.js.map} +0 -0
  480. /package/dist/{hosts-DVQJ32QC.js.map → config-QZOBMTEL.js.map} +0 -0
  481. /package/dist/{install-ILUX5C4A.js.map → config-rules-YOYHS6YL.js.map} +0 -0
  482. /package/dist/{install-identity-TZKGY6LQ.js.map → decision-QSKHOGCO.js.map} +0 -0
  483. /package/dist/{package-IJFGMWEV.js.map → env-proxy-XLSLHBKQ.js.map} +0 -0
  484. /package/dist/{passphrase-IFTDS3CU.js.map → ethersCompat-Df4a6QIZ-K3DMHR6Y.js.map} +0 -0
  485. /package/dist/{paths-XCSAKISU.js.map → flush-stdio-NYIJ3QXT.js.map} +0 -0
  486. /package/dist/{pay-WCG3IH4R.js.map → hook-command-VZ27MGWO.js.map} +0 -0
  487. /package/dist/{plugin-registration-PZFI5GZW.js.map → hosts-3EMTVM4H.js.map} +0 -0
  488. /package/dist/{redact-D7ASVWKL.js.map → install-ZA7L2UF3.js.map} +0 -0
  489. /package/dist/{runtime-fetch-ZSSSK72Y.js.map → install-funding-JDGYTF72.js.map} +0 -0
  490. /package/dist/{runtime-layout-WIDILZ6K.js.map → install-identity-FFAYEFLX.js.map} +0 -0
  491. /package/dist/{secp256k1-ZZZT2CAX.js.map → new-install-5L4GY3LN.js.map} +0 -0
  492. /package/dist/{update-CACXLQLR.js.map → package-BONDXSV3.js.map} +0 -0
  493. /package/dist/{usdc-VG4CIOUK.js.map → passphrase-T4ULBN4M.js.map} +0 -0
  494. /package/dist/{viemAdapter-By13KInL-DOFTEIJV.js.map → paths-O2KDWZ76.js.map} +0 -0
  495. /package/dist/{wallet-QL4UUXEZ.js.map → pay-CMV5KL74.js.map} +0 -0
@@ -0,0 +1,1020 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ AccountRefused,
4
+ accountFetch,
5
+ authHeader,
6
+ expiresAtOf,
7
+ openAccountSession,
8
+ said
9
+ } from "./chunk-VHXCPXUS.js";
10
+ import {
11
+ deleteVault,
12
+ readVault,
13
+ readVaultHeader,
14
+ restoreVault,
15
+ writeVault
16
+ } from "./chunk-XSCGUO2U.js";
17
+ import "./chunk-MAHNZA6C.js";
18
+ import {
19
+ answer
20
+ } from "./chunk-XWROSMI5.js";
21
+ import {
22
+ openInBrowser
23
+ } from "./chunk-U4TRWSVE.js";
24
+ import "./chunk-FYFHH7V5.js";
25
+ import "./chunk-HPRVFJPM.js";
26
+ import {
27
+ defaultExecFor,
28
+ hiddenPrompt
29
+ } from "./chunk-XRGFH7FI.js";
30
+ import "./chunk-JWAK7JQB.js";
31
+ import {
32
+ persist
33
+ } from "./chunk-W74LJ5OT.js";
34
+ import {
35
+ blockedBy,
36
+ describePrefer
37
+ } from "./chunk-KNKDMTHU.js";
38
+ import {
39
+ accountJobs,
40
+ accountServices,
41
+ cachedIdentities,
42
+ fetchIdentities
43
+ } from "./chunk-3Y6BHIN6.js";
44
+ import "./chunk-R62PKTAG.js";
45
+ import "./chunk-HAZAN4UM.js";
46
+ import "./chunk-KGUE5AVX.js";
47
+ import "./chunk-2W4DQQUU.js";
48
+ import {
49
+ emitWriteNotice,
50
+ sanitizeForTerminal
51
+ } from "./chunk-KLDMLWXT.js";
52
+ import "./chunk-HZKANST2.js";
53
+ import "./chunk-MEZJ3I63.js";
54
+ import "./chunk-ILWCKCOI.js";
55
+ import "./chunk-RFZA7PSM.js";
56
+ import "./chunk-JUUBBBY5.js";
57
+ import "./chunk-7SLOTLO7.js";
58
+ import "./chunk-W2GXIARJ.js";
59
+ import {
60
+ accountIdForUrl,
61
+ savedAccountOf
62
+ } from "./chunk-TFT2X7SH.js";
63
+ import "./chunk-DTEWAVNE.js";
64
+ import {
65
+ editSources,
66
+ loadRawConfig,
67
+ resolveSettings,
68
+ savedDescriptors
69
+ } from "./chunk-UIB33QQP.js";
70
+ import "./chunk-7WEQQJLG.js";
71
+ import "./chunk-ZCT5DJ3G.js";
72
+ import "./chunk-3MZ7DYRO.js";
73
+ import {
74
+ sourceKeyFilePath
75
+ } from "./chunk-JTX3BUDK.js";
76
+ import {
77
+ isAccountId,
78
+ isAccountUrl
79
+ } from "./chunk-ZEYA2WWX.js";
80
+ import {
81
+ isLoopbackHost
82
+ } from "./chunk-DIH2G3YG.js";
83
+ import "./chunk-D6M3ZK66.js";
84
+ import {
85
+ POLICY_VERSION,
86
+ SETTINGS_LIMITS,
87
+ SavedPolicySchema,
88
+ SavedPolicyShapeSchema,
89
+ hasRules,
90
+ scopeKey,
91
+ wirePolicy
92
+ } from "./chunk-RGCPELQN.js";
93
+ import {
94
+ PRODUCTION_ORIGIN
95
+ } from "./chunk-CRG54LEB.js";
96
+ import "./chunk-TUCKEEXE.js";
97
+ import "./chunk-P6YQWIT2.js";
98
+ import {
99
+ CliError
100
+ } from "./chunk-DI4QAGRZ.js";
101
+ import {
102
+ package_default
103
+ } from "./chunk-3Y2EHT4F.js";
104
+ import "./chunk-ZXTAQYNA.js";
105
+
106
+ // src/router/accounts/oauth.ts
107
+ import { randomBytes } from "node:crypto";
108
+
109
+ // src/router/accounts/loopback.ts
110
+ import { createServer } from "node:http";
111
+ var REDIRECT_PORTS = [28541, 28542, 28543];
112
+ var CALLBACK_PATH = "/callback";
113
+ var PAGE = (title, line) => `<!doctype html><html><head><meta charset="utf-8"><title>${title}</title></head><body style="font-family:system-ui,sans-serif;margin:3rem"><h1>${title}</h1><p>${line}</p></body></html>`;
114
+ var DONE = PAGE("Signed in", "Tenjin has the sign-in. You can close this tab.");
115
+ var DECLINED = PAGE("Not signed in", "Nothing was connected. You can close this tab.");
116
+ var STALE = PAGE("Not this sign-in", "This link is not from the sign-in Tenjin is waiting for.");
117
+ async function listen(server, port) {
118
+ return new Promise((resolve, reject) => {
119
+ const onError = (err) => {
120
+ server.removeListener("listening", onListening);
121
+ if (err.code === "EADDRINUSE" || err.code === "EACCES") resolve(null);
122
+ else reject(err);
123
+ };
124
+ const onListening = () => {
125
+ server.removeListener("error", onError);
126
+ resolve(server.address().port);
127
+ };
128
+ server.once("error", onError);
129
+ server.once("listening", onListening);
130
+ server.listen(port, "127.0.0.1");
131
+ });
132
+ }
133
+ async function openRedirect(opts) {
134
+ let deliver;
135
+ const expected = opts.state;
136
+ const early = [];
137
+ const handle = (req, res) => {
138
+ const url = new URL(req.url ?? "/", "http://127.0.0.1");
139
+ const answer2 = (status, body) => {
140
+ res.writeHead(status, {
141
+ "content-type": "text/html; charset=utf-8",
142
+ "cache-control": "no-store",
143
+ "referrer-policy": "no-referrer"
144
+ });
145
+ res.end(body);
146
+ };
147
+ if (req.method !== "GET" || url.pathname !== CALLBACK_PATH) return answer2(404, STALE);
148
+ const state = url.searchParams.get("state");
149
+ if (expected.length === 0 || state !== expected || early.length > 0) return answer2(400, STALE);
150
+ const code = url.searchParams.get("code");
151
+ const error = url.searchParams.get("error");
152
+ const result = code !== null && code.length > 0 && error === null ? { code } : { error: error !== null && /^[a-z_]{1,64}$/.test(error) ? error : "invalid_request" };
153
+ answer2(200, "code" in result ? DONE : DECLINED);
154
+ if (deliver !== void 0) deliver(result);
155
+ else early.push(result);
156
+ };
157
+ const server = createServer(handle);
158
+ server.unref();
159
+ let port = null;
160
+ for (const candidate of opts.ports ?? [0]) {
161
+ port = await listen(server, candidate);
162
+ if (port !== null) break;
163
+ }
164
+ if (port === null) {
165
+ server.close();
166
+ throw new CliError(
167
+ "REFUSED",
168
+ "Another sign-in is already waiting on this machine, so this one could not start. Nothing was saved.",
169
+ { fix: "Finish or cancel the other `tenjin connect`, then run this one again." }
170
+ );
171
+ }
172
+ const close = () => {
173
+ server.close();
174
+ server.closeAllConnections?.();
175
+ };
176
+ return {
177
+ redirectUrl: `http://127.0.0.1:${port}${CALLBACK_PATH}`,
178
+ close,
179
+ wait() {
180
+ return new Promise((resolve, reject) => {
181
+ const timer = setTimeout(() => {
182
+ deliver = void 0;
183
+ close();
184
+ reject(
185
+ new CliError("REFUSED", "The sign-in was not finished in time. Nothing was saved.", {
186
+ fix: "Run the command again and approve in the browser, or use `--paste` with a key."
187
+ })
188
+ );
189
+ }, opts.timeoutMs);
190
+ deliver = (result) => {
191
+ clearTimeout(timer);
192
+ deliver = void 0;
193
+ close();
194
+ resolve(result);
195
+ };
196
+ const first = early.shift();
197
+ if (first !== void 0) deliver(first);
198
+ });
199
+ }
200
+ };
201
+ }
202
+
203
+ // src/router/accounts/oauth.ts
204
+ var CLIENT_METADATA_URL = `${PRODUCTION_ORIGIN}/oauth/client-metadata.json`;
205
+ var REQUEST_TIMEOUT_MS = 1e4;
206
+ var SAID_CHARS = 200;
207
+ var ConnectProvider = class {
208
+ constructor(opts) {
209
+ this.opts = opts;
210
+ this.clientMetadataUrl = opts.clientMetadataUrl;
211
+ this.#state = opts.state;
212
+ this.#discovery = opts.discovery;
213
+ }
214
+ opts;
215
+ clientMetadataUrl;
216
+ #state;
217
+ #verifier;
218
+ #client;
219
+ #tokens;
220
+ #discovery;
221
+ get redirectUrl() {
222
+ return this.opts.redirectUrl;
223
+ }
224
+ /** What a dynamic registration sends: a public client on this redirect. */
225
+ get clientMetadata() {
226
+ return {
227
+ client_name: "Tenjin",
228
+ client_uri: PRODUCTION_ORIGIN,
229
+ redirect_uris: [this.opts.redirectUrl],
230
+ grant_types: ["authorization_code", "refresh_token"],
231
+ response_types: ["code"],
232
+ token_endpoint_auth_method: "none",
233
+ software_id: "tenjin-cli",
234
+ software_version: package_default.version
235
+ };
236
+ }
237
+ state() {
238
+ return this.#state;
239
+ }
240
+ clientInformation() {
241
+ return this.#client;
242
+ }
243
+ saveClientInformation(info) {
244
+ this.#client = info;
245
+ }
246
+ tokens() {
247
+ return this.#tokens;
248
+ }
249
+ saveTokens(tokens) {
250
+ this.#tokens = tokens;
251
+ }
252
+ redirectToAuthorization(url) {
253
+ return this.opts.onAuthorizationUrl(url);
254
+ }
255
+ saveCodeVerifier(verifier) {
256
+ this.#verifier = verifier;
257
+ }
258
+ codeVerifier() {
259
+ if (this.#verifier === void 0) throw new Error("no sign-in was started");
260
+ return this.#verifier;
261
+ }
262
+ invalidateCredentials(scope) {
263
+ if (scope === "all" || scope === "client") this.#client = void 0;
264
+ if (scope === "all" || scope === "tokens") this.#tokens = void 0;
265
+ if (scope === "all" || scope === "verifier") this.#verifier = void 0;
266
+ if (scope === "all" || scope === "discovery") this.#discovery = void 0;
267
+ }
268
+ saveDiscoveryState(state) {
269
+ this.#discovery = state;
270
+ }
271
+ discoveryState() {
272
+ return this.#discovery;
273
+ }
274
+ };
275
+ async function challenge(mcpUrl, fetchImpl) {
276
+ const { extractWWWAuthenticateParams } = await import("./auth-XI7BJFLW.js");
277
+ const res = await fetchImpl(mcpUrl, {
278
+ method: "POST",
279
+ headers: {
280
+ "content-type": "application/json",
281
+ accept: "application/json, text/event-stream"
282
+ },
283
+ body: JSON.stringify({
284
+ jsonrpc: "2.0",
285
+ id: 0,
286
+ method: "initialize",
287
+ params: {
288
+ protocolVersion: "2025-06-18",
289
+ capabilities: {},
290
+ clientInfo: { name: "tenjin", version: package_default.version }
291
+ }
292
+ }),
293
+ redirect: "manual",
294
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
295
+ });
296
+ await res.body?.cancel().catch(() => void 0);
297
+ if (res.status !== 401) return { status: res.status };
298
+ const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(res);
299
+ return {
300
+ status: res.status,
301
+ ...resourceMetadataUrl !== void 0 ? { resourceMetadataUrl } : {},
302
+ ...scope !== void 0 ? { scope } : {}
303
+ };
304
+ }
305
+ function cannotSignIn(label, id, why) {
306
+ return new CliError(
307
+ "REFUSED",
308
+ `Tenjin couldn't sign in to ${label}: ${why}. Nothing was saved.`,
309
+ {
310
+ fix: `If ${label} gives you an API key, the user can run \`tenjin connect ${id} --paste\` in their own terminal.`
311
+ }
312
+ );
313
+ }
314
+ async function signIn(account, deps) {
315
+ const { id, label, mcpUrl } = account;
316
+ const fetchImpl = deps.fetchImpl ?? accountFetch(account);
317
+ const fetchFn = (input, init) => fetchImpl(input, {
318
+ ...init,
319
+ signal: init?.signal ?? AbortSignal.timeout(REQUEST_TIMEOUT_MS)
320
+ });
321
+ let first;
322
+ try {
323
+ first = await challenge(mcpUrl, fetchImpl);
324
+ } catch (err) {
325
+ throw new CliError(
326
+ "NETWORK_ERROR",
327
+ `Tenjin couldn't reach ${label} (${said(err, SAID_CHARS)}). Nothing was saved.`,
328
+ {
329
+ fix: "Check the network and the address, then run the command again."
330
+ }
331
+ );
332
+ }
333
+ if (first.status >= 200 && first.status < 300)
334
+ throw cannotSignIn(label, id, "it answered without asking anyone to sign in");
335
+ if (first.status !== 401) throw cannotSignIn(label, id, `it answered ${first.status}`);
336
+ const sdk = await import("./auth-XI7BJFLW.js");
337
+ let info;
338
+ try {
339
+ info = await sdk.discoverOAuthServerInfo(mcpUrl, {
340
+ ...first.resourceMetadataUrl !== void 0 ? { resourceMetadataUrl: first.resourceMetadataUrl } : {},
341
+ fetchFn
342
+ });
343
+ } catch (err) {
344
+ throw cannotSignIn(label, id, `its sign-in could not be found (${said(err, SAID_CHARS)})`);
345
+ }
346
+ const metadata = info.authorizationServerMetadata;
347
+ const clientMetadataUrl = deps.clientMetadataUrl ?? CLIENT_METADATA_URL;
348
+ const byDocument = metadata?.client_id_metadata_document_supported === true;
349
+ if (metadata === void 0 || !byDocument && metadata.registration_endpoint === void 0)
350
+ throw cannotSignIn(label, id, "it doesn't offer a sign-in Tenjin can use");
351
+ const state = randomBytes(32).toString("base64url");
352
+ const redirect = await openRedirect({
353
+ state,
354
+ timeoutMs: deps.waitMs,
355
+ ...deps.ports !== void 0 ? { ports: deps.ports } : byDocument ? { ports: REDIRECT_PORTS } : {}
356
+ });
357
+ try {
358
+ const discovery = {
359
+ ...info,
360
+ ...first.resourceMetadataUrl !== void 0 ? { resourceMetadataUrl: first.resourceMetadataUrl.toString() } : {}
361
+ };
362
+ const provider = new ConnectProvider({
363
+ redirectUrl: redirect.redirectUrl,
364
+ state,
365
+ clientMetadataUrl,
366
+ discovery,
367
+ onAuthorizationUrl: async (url) => {
368
+ const local = url.protocol === "http:" && account.typed === true && isLoopbackHost(new URL(mcpUrl).hostname) && isLoopbackHost(url.hostname);
369
+ if (url.protocol !== "https:" && !local)
370
+ throw cannotSignIn(label, id, "its approval page is not an https address");
371
+ if (deps.approving !== void 0) deps.approving(label, url.href);
372
+ else {
373
+ deps.notice(`Approve Tenjin in your browser to connect ${label}:`);
374
+ deps.notice(` ${url.href}`);
375
+ }
376
+ if (await deps.open(url.href)) return;
377
+ if (!deps.interactive) {
378
+ throw new CliError(
379
+ "REFUSED",
380
+ `Tenjin couldn't open a browser here, so it can't sign in to ${label} from this session. Nothing was saved.`,
381
+ {
382
+ fix: `The user can run \`tenjin connect ${id}\` in their own terminal, or \`tenjin connect ${id} --paste\` with a key.`
383
+ }
384
+ );
385
+ }
386
+ deps.notice("Couldn't open a browser: open the link above on this machine.");
387
+ }
388
+ });
389
+ const options = {
390
+ serverUrl: mcpUrl,
391
+ ...first.scope !== void 0 ? { scope: first.scope } : {},
392
+ ...first.resourceMetadataUrl !== void 0 ? { resourceMetadataUrl: first.resourceMetadataUrl } : {},
393
+ fetchFn
394
+ };
395
+ let started;
396
+ try {
397
+ started = await sdk.auth(provider, options);
398
+ } catch (err) {
399
+ if (err instanceof CliError) throw err;
400
+ throw cannotSignIn(label, id, `the sign-in could not start (${said(err, SAID_CHARS)})`);
401
+ }
402
+ if (started === "REDIRECT") {
403
+ const back = await redirect.wait();
404
+ if ("error" in back) {
405
+ throw new CliError(
406
+ "REFUSED",
407
+ back.error === "access_denied" ? `The sign-in to ${label} was declined, so nothing was connected.` : `${label} did not finish the sign-in (${back.error}). Nothing was saved.`,
408
+ { fix: `Run \`tenjin connect ${id}\` again to try once more.` }
409
+ );
410
+ }
411
+ try {
412
+ await sdk.auth(provider, { ...options, authorizationCode: back.code });
413
+ } catch (err) {
414
+ throw cannotSignIn(label, id, `the sign-in was not accepted (${said(err, SAID_CHARS)})`);
415
+ }
416
+ }
417
+ const tokens = provider.tokens();
418
+ const client = provider.clientInformation();
419
+ const discovered = provider.discoveryState();
420
+ if (tokens === void 0 || client === void 0 || discovered === void 0)
421
+ throw cannotSignIn(label, id, "no sign-in came back");
422
+ return {
423
+ tokens,
424
+ obtainedAt: deps.now?.() ?? Date.now(),
425
+ clientInformation: client,
426
+ discoveryState: discovered
427
+ };
428
+ } finally {
429
+ redirect.close();
430
+ }
431
+ }
432
+ async function revokeSignIn(secret, server, fetchImpl = accountFetch(server)) {
433
+ const metadata = secret.discoveryState?.authorizationServerMetadata ?? {};
434
+ const endpoint = typeof metadata.revocation_endpoint === "string" ? metadata.revocation_endpoint : void 0;
435
+ if (endpoint === void 0 || !URL.canParse(endpoint) || !["https:", "http:"].includes(new URL(endpoint).protocol))
436
+ return "unsupported";
437
+ const clientId = secret.clientInformation?.client_id;
438
+ const tokens = ["refresh_token", "access_token"].flatMap((hint) => {
439
+ const token = secret.tokens?.[hint];
440
+ return typeof token === "string" && token.length > 0 ? [{ hint, token }] : [];
441
+ });
442
+ if (tokens.length === 0) return "unsupported";
443
+ let ok = true;
444
+ for (const { hint, token } of tokens) {
445
+ const body = new URLSearchParams({ token, token_type_hint: hint });
446
+ if (typeof clientId === "string") body.set("client_id", clientId);
447
+ try {
448
+ const res = await fetchImpl(endpoint, {
449
+ method: "POST",
450
+ headers: { "content-type": "application/x-www-form-urlencoded" },
451
+ body: body.toString(),
452
+ redirect: "manual",
453
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
454
+ });
455
+ await res.body?.cancel().catch(() => void 0);
456
+ if (res.status !== 200) ok = false;
457
+ } catch {
458
+ ok = false;
459
+ }
460
+ }
461
+ return ok ? "revoked" : "failed";
462
+ }
463
+
464
+ // src/commands/connect.ts
465
+ var SIGN_IN_WAIT_MS = 28e4;
466
+ var MAX_ACCOUNTS = SETTINGS_LIMITS.sources - 1;
467
+ var ACCOUNT_CHECKS = {
468
+ fal: { tool: "check_account_status", args: {} }
469
+ };
470
+ var WHOLE_ACCOUNT = /* @__PURE__ */ new Set(["apify"]);
471
+ function usage(message, fix, details) {
472
+ throw new CliError("USAGE", message, {
473
+ ...fix !== void 0 ? { fix } : {},
474
+ ...details !== void 0 ? { details } : {}
475
+ });
476
+ }
477
+ var looksLikeUrl = (text) => /^[a-z][a-z0-9+.-]*:\/\//i.test(text);
478
+ var folded = (text) => text.trim().toLowerCase();
479
+ async function baseUrlOf(ctx) {
480
+ const config = await loadRawConfig(ctx.dataDir);
481
+ return resolveSettings({ config, flags: { baseUrl: ctx.flags.baseUrl }, env: process.env }).baseUrl.value;
482
+ }
483
+ function accountUrlOf(url) {
484
+ const path = url.pathname.replace(/\/+$/, "");
485
+ return `${url.origin}${path}`;
486
+ }
487
+ function resolveAccount(target, identities, saved) {
488
+ const listed = identities.sources.flatMap(
489
+ (source) => source.connectable !== void 0 && isAccountId(source.id) ? [{ id: source.id, label: source.label, connectable: source.connectable }] : []
490
+ );
491
+ const fromRead = ({ id, label, connectable }) => ({
492
+ id,
493
+ label,
494
+ mcpUrl: connectable.mcpUrl,
495
+ signIn: connectable.signIn,
496
+ keyScheme: connectable.keyScheme ?? "Bearer",
497
+ expectTools: connectable.expectTools,
498
+ mapped: true
499
+ });
500
+ if (looksLikeUrl(target)) {
501
+ const raw = target.replace(/\/+$/, "");
502
+ const parsed = isAccountUrl(raw, { typed: true }) ? new URL(raw) : void 0;
503
+ const href = parsed !== void 0 ? accountUrlOf(parsed) : "";
504
+ if (parsed === void 0 || !isAccountUrl(href, { typed: true })) {
505
+ const plain = URL.canParse(raw) ? new URL(raw) : void 0;
506
+ if (plain?.protocol === "http:" && !isLoopbackHost(plain.hostname)) {
507
+ usage(
508
+ "Use https, or http only for localhost. Nothing was saved.",
509
+ "tenjin connect https://mcp.example.com/mcp"
510
+ );
511
+ }
512
+ usage(
513
+ "Connect takes an https address with no user name, password, query or fragment. Nothing was saved.",
514
+ "tenjin connect https://mcp.example.com/mcp"
515
+ );
516
+ }
517
+ const known2 = listed.find(({ connectable: c }) => c.mcpUrl === href);
518
+ if (known2 !== void 0) return fromRead(known2);
519
+ const id = accountIdForUrl(parsed);
520
+ const taken = new Set(identities.sources.map((source) => source.id));
521
+ const savedHere = saved.find((account) => account.id === id);
522
+ if (taken.has(id) || savedHere !== void 0 && savedHere.mcpUrl !== href) {
523
+ throw new CliError(
524
+ "REFUSED",
525
+ `Another account is already connected as ${parsed.hostname}, so this address wasn't connected.`,
526
+ { fix: `Disconnect it first with \`tenjin disconnect ${id}\`, then connect this address.` }
527
+ );
528
+ }
529
+ return {
530
+ id,
531
+ label: parsed.hostname,
532
+ mcpUrl: href,
533
+ signIn: ["oauth", "key"],
534
+ keyScheme: "Bearer",
535
+ expectTools: [],
536
+ mapped: false
537
+ };
538
+ }
539
+ const wanted = folded(target);
540
+ const named = listed.find(({ id, label }) => id === wanted || folded(label) === wanted);
541
+ if (named !== void 0) return fromRead(named);
542
+ const own = saved.find((account) => account.id === wanted || folded(account.label) === wanted);
543
+ if (own !== void 0 && own.mapped !== true) {
544
+ return {
545
+ id: own.id,
546
+ label: own.label,
547
+ mcpUrl: own.mcpUrl,
548
+ signIn: ["oauth", "key"],
549
+ keyScheme: own.keyScheme ?? "Bearer",
550
+ expectTools: [],
551
+ mapped: false
552
+ };
553
+ }
554
+ const known = listed.map(({ label }) => label);
555
+ usage(
556
+ `Tenjin doesn't know an account called "${target}". Nothing was saved.`,
557
+ known.length > 0 ? `Tenjin can connect ${new Intl.ListFormat("en", { type: "disjunction" }).format(known)}, or any MCP server by its https address.` : "Connect an MCP server by its https address: tenjin connect https://mcp.example.com/mcp",
558
+ { name: target, connectable: listed.map(({ id, label }) => ({ id, label })) }
559
+ );
560
+ }
561
+ function checkedKey(raw, account) {
562
+ const key = raw.trim();
563
+ if (key.length === 0) usage("No key was given, so nothing was saved.");
564
+ if (key.length > 4096 || !/^[\x21-\x7e]+$/.test(key))
565
+ usage(
566
+ `That doesn't look like a ${account.label} key: it has spaces or characters a key doesn't. Nothing was saved.`
567
+ );
568
+ if (account.keyScheme === "Key" && !/^[^:]+:[^:]+$/.test(key))
569
+ usage(`A ${account.label} key is written key_id:key_secret. Nothing was saved.`);
570
+ return key;
571
+ }
572
+ var ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
573
+ async function keyFrom(flags, account, deps) {
574
+ if (!account.signIn.includes("key")) {
575
+ usage(
576
+ `${account.label} connects with its own sign-in, not a key. Nothing was saved.`,
577
+ `tenjin connect ${account.id}`
578
+ );
579
+ }
580
+ if (flags.fromEnv !== void 0) {
581
+ if (!ENV_NAME.test(flags.fromEnv))
582
+ usage(`--from-env takes the name of an environment variable; got "${flags.fromEnv}".`);
583
+ const value = (deps.env ?? process.env)[flags.fromEnv];
584
+ if (value === void 0 || value.trim().length === 0)
585
+ usage(`${flags.fromEnv} is not set here, so nothing was saved.`);
586
+ return checkedKey(value, account);
587
+ }
588
+ const terminal = deps.stdinIsTTY ?? Boolean(process.stdin.isTTY);
589
+ if (!terminal) {
590
+ throw new CliError(
591
+ "REFUSED",
592
+ "--paste reads the key at a hidden prompt, which needs a terminal. Nothing was saved.",
593
+ {
594
+ fix: `Ask the user to run \`tenjin connect ${account.id} --paste\` in their own terminal. Never ask for a key in chat.`
595
+ }
596
+ );
597
+ }
598
+ const prompt = deps.prompt ?? hiddenPrompt(
599
+ () => new CliError("USAGE", "Key entry was cancelled, so nothing was saved.", {
600
+ fix: `Run \`tenjin connect ${account.id} --paste\` again.`
601
+ })
602
+ );
603
+ const label = account.keyScheme === "Key" ? `Paste your ${account.label} key as key_id:key_secret (it won't show): ` : `Paste your ${account.label} API key (it won't show): `;
604
+ return checkedKey(await prompt(label), account);
605
+ }
606
+ async function checkAccount(account, headers, byKey, deps) {
607
+ const open = deps.openSession ?? openAccountSession;
608
+ const refused = () => new CliError(
609
+ "REFUSED",
610
+ byKey ? `${account.label} didn't accept that key, so nothing was saved.` : `${account.label} didn't accept the sign-in, so nothing was saved.`,
611
+ { fix: `Check it and run \`tenjin connect ${account.id}${byKey ? " --paste" : ""}\` again.` }
612
+ );
613
+ let session;
614
+ try {
615
+ session = await open(account.mcpUrl, headers, {
616
+ ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {},
617
+ ...account.mapped ? {} : { typed: true }
618
+ });
619
+ const tools = await session.listTools();
620
+ const check = byKey ? ACCOUNT_CHECKS[account.id] : void 0;
621
+ if (check !== void 0) {
622
+ if (!tools.some(({ name }) => name === check.tool)) throw refused();
623
+ const result = await session.callTool(check.tool, check.args);
624
+ if (result.isError === true) throw refused();
625
+ }
626
+ const listed = new Set(tools.map(({ name }) => name));
627
+ return { missingTools: account.expectTools.filter((tool) => !listed.has(tool)) };
628
+ } catch (err) {
629
+ if (err instanceof CliError) throw err;
630
+ if (err instanceof AccountRefused) throw refused();
631
+ throw new CliError(
632
+ "NETWORK_ERROR",
633
+ `Tenjin couldn't list ${account.label}'s tools, so nothing was saved.`,
634
+ { fix: "Check the network, then run the command again." }
635
+ );
636
+ } finally {
637
+ await session?.close().catch(() => void 0);
638
+ }
639
+ }
640
+ function withPreference(existing, id, identities) {
641
+ const router = { ...existing.router ?? {} };
642
+ const raw = router.policy;
643
+ const parsed = raw === void 0 ? { success: true, data: { version: POLICY_VERSION } } : SavedPolicySchema.safeParse(raw);
644
+ if (!parsed.success) return { next: existing, outcome: "unreadable" };
645
+ const policy = parsed.data;
646
+ const target = { kind: "source", id };
647
+ if (blockedBy(target, policy, identities) !== void 0)
648
+ return { next: existing, outcome: "blocked" };
649
+ const prefer = policy.prefer ?? [];
650
+ const global = prefer.find(({ scope }) => scopeKey(scope) === "global");
651
+ if (global?.targets.some((t) => t.kind === "source" && t.id === id))
652
+ return { next: existing, outcome: "kept", rule: global, policy };
653
+ if (global !== void 0 && global.targets.length >= SETTINGS_LIMITS.targets)
654
+ return { next: existing, outcome: "full" };
655
+ const rule = global !== void 0 ? { ...global, targets: [...global.targets, target] } : { scope: { kind: "global" }, targets: [target] };
656
+ const after = {
657
+ ...policy,
658
+ prefer: global !== void 0 ? prefer.map((entry) => entry === global ? rule : entry) : [...prefer, rule]
659
+ };
660
+ if (!SavedPolicySchema.safeParse(after).success) return { next: existing, outcome: "full" };
661
+ return {
662
+ next: { ...existing, router: { ...router, policy: after } },
663
+ outcome: "added",
664
+ rule,
665
+ policy: after
666
+ };
667
+ }
668
+ function withDescriptor(existing, descriptor) {
669
+ return editSources(existing, (saved) => {
670
+ const before = savedAccountOf(saved.find((entry) => entry.id === descriptor.id));
671
+ const others = saved.filter((entry) => entry.id !== descriptor.id);
672
+ const kept = before?.onRefusal !== void 0 ? { onRefusal: before.onRefusal } : {};
673
+ return [...others, { ...descriptor, ...kept }];
674
+ });
675
+ }
676
+ var list = new Intl.ListFormat("en", { type: "conjunction" });
677
+ var NAMED_JOBS = 4;
678
+ function some(jobs) {
679
+ if (jobs.length <= NAMED_JOBS) return list.format(jobs);
680
+ return list.format([...jobs.slice(0, NAMED_JOBS - 1), `${jobs.length - NAMED_JOBS + 1} more`]);
681
+ }
682
+ function connectLines(account, identities, checked, preference, byKey) {
683
+ const { label } = account;
684
+ if (!account.mapped) {
685
+ return [
686
+ `Connected ${label} on this machine. Tenjin doesn't know this service's jobs yet, so it won't pick it on its own. Ask for it by name and Tenjin will run it.`,
687
+ `Your ${label} account pays for its calls, which don't count toward your Tenjin limits.`,
688
+ "Nothing about this service was sent to Tenjin."
689
+ ];
690
+ }
691
+ const jobs = accountJobs(account.id, identities);
692
+ const preferred = preference === "added" || preference === "kept";
693
+ const lines = [
694
+ jobs.length > 0 ? `${label} connected on this machine, for ${some(jobs)}.` : `${label} connected on this machine.`
695
+ ];
696
+ if (preferred) lines.push(`Tenjin will use your ${label} account first for those jobs.`);
697
+ else lines.push(`Tenjin can use your ${label} account for those jobs, without putting it first.`);
698
+ if (checked.missingTools.length > 0) {
699
+ lines.push(
700
+ `This ${label} account doesn't have ${list.format(checked.missingTools)}, so Tenjin leaves out the jobs that need ${checked.missingTools.length === 1 ? "it" : "them"} here.`
701
+ );
702
+ }
703
+ lines.push(
704
+ `Your ${label} plan pays for these calls, which don't count toward your Tenjin limits.`
705
+ );
706
+ lines.push(
707
+ WHOLE_ACCOUNT.has(account.id) && !byKey ? `${label}'s sign-in lets Tenjin act on your whole ${label} account. Tenjin only runs the jobs above and the ${label} services you ask for by name.` : `Tenjin can act on your ${label} account, and only runs the jobs above and the ${label} services you ask for by name.`
708
+ );
709
+ if (preference === "blocked")
710
+ lines.push(
711
+ `Tenjin won't offer your ${label} account on its own. You or your agent can still pick it by name.`
712
+ );
713
+ if (preference === "unreadable")
714
+ lines.push(`Your saved settings can't be read, so ${label} wasn't added to your preferences.`);
715
+ if (preference === "full")
716
+ lines.push(`Your account-wide preference is full, so ${label} wasn't added to it.`);
717
+ if (preferred)
718
+ lines.push(
719
+ `Say "don't prefer ${label}" to stop putting it first (\`tenjin config reset --source ${account.id} --preference\`), or "disconnect ${label}" to remove it.`
720
+ );
721
+ return lines;
722
+ }
723
+ function connectReply(account, identities, checked, preference) {
724
+ const { label } = account;
725
+ const billed = `billed to your ${label} plan, not your Tenjin balance.`;
726
+ if (!account.mapped) {
727
+ return {
728
+ done: `Connected ${label}`,
729
+ said: [
730
+ `Its calls are ${billed}`,
731
+ "Ask for it by name: Tenjin doesn't know its jobs, and its server isn't told about it."
732
+ ]
733
+ };
734
+ }
735
+ const tools = accountServices(account.id, identities).length;
736
+ const missing = checked.missingTools;
737
+ const use = preference === "blocked" ? `Ask for ${label} by name to use ${tools === 1 ? "it" : "them"}. \`tenjin status\` lists it.` : preference === "added" || preference === "kept" ? `Tenjin uses your ${label} first for these jobs.` : `Tenjin can use your ${label} for these jobs.`;
738
+ return {
739
+ done: `Connected ${label}`,
740
+ said: [
741
+ tools > 0 ? `${tools} ${tools === 1 ? "tool" : "tools"}, ${billed}` : `Its calls are ${billed}`,
742
+ use
743
+ ],
744
+ problems: [
745
+ ...missing.length > 0 ? [
746
+ `This ${label} account lacks ${list.format(missing)}, so jobs that need ${missing.length === 1 ? "it" : "them"} are left out.`
747
+ ] : [],
748
+ ...preference === "blocked" ? [`Your block on ${label} stays: Tenjin won't offer it on its own.`] : preference === "unreadable" ? [`Your saved settings can't be read, so ${label} wasn't put first.`] : preference === "full" ? [`Your account-wide preference is full, so ${label} wasn't put first.`] : []
749
+ ]
750
+ };
751
+ }
752
+ async function runConnect(target, flags, ctx, deps = {}) {
753
+ if (flags.paste === true && flags.fromEnv !== void 0)
754
+ usage("Use --paste or --from-env, not both.");
755
+ const name = target.trim();
756
+ if (name.length === 0)
757
+ usage("Say which account to connect: tenjin connect <name or https address>.");
758
+ const config = await loadRawConfig(ctx.dataDir);
759
+ const descriptors = savedDescriptors(config.router);
760
+ const saved = descriptors.flatMap((entry) => savedAccountOf(entry) ?? []);
761
+ const read = await fetchIdentities(ctx, {
762
+ baseUrl: await baseUrlOf(ctx),
763
+ ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
764
+ });
765
+ if (!read.ok) {
766
+ throw new CliError(
767
+ read.unreachable === true ? "API_UNREACHABLE" : "NETWORK_ERROR",
768
+ `Tenjin couldn't look up "${name}" right now, so nothing was connected. (${read.reason})`,
769
+ { fix: "Try again in a moment." }
770
+ );
771
+ }
772
+ const { identities } = read;
773
+ const account = resolveAccount(name, identities, saved);
774
+ if (descriptors.length >= MAX_ACCOUNTS && !saved.some(({ id }) => id === account.id)) {
775
+ throw new CliError(
776
+ "REFUSED",
777
+ `You already have ${MAX_ACCOUNTS} accounts connected, so ${account.label} wasn't connected.`,
778
+ { fix: "Disconnect one you no longer use with `tenjin disconnect <name>` first." }
779
+ );
780
+ }
781
+ const byKey = flags.paste === true || flags.fromEnv !== void 0;
782
+ let secret;
783
+ let headers;
784
+ let expiresAt;
785
+ if (byKey) {
786
+ const key = await keyFrom(flags, account, deps);
787
+ secret = { apiKey: key, keyScheme: account.keyScheme };
788
+ headers = authHeader(account.keyScheme, key);
789
+ } else {
790
+ if (!account.signIn.includes("oauth")) {
791
+ usage(
792
+ `${account.label} connects with a key. Nothing was saved.`,
793
+ `Ask the user to run \`tenjin connect ${account.id} --paste\` in their own terminal, or use --from-env with a variable that holds it.`
794
+ );
795
+ }
796
+ const human = ctx.io.isTTY && !ctx.flags.json;
797
+ const signInDeps = {
798
+ ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {},
799
+ open: deps.openUrl ?? ((url) => openInBrowser(url)),
800
+ notice: (line) => emitWriteNotice(ctx.io, line),
801
+ // AT A TERMINAL, one line while the browser opens and the link dim under
802
+ // it, whole, to copy; an agent keeps the two lines that name the link.
803
+ ...human ? {
804
+ approving: (label, url) => {
805
+ ctx.io.stderr.write(
806
+ `${sanitizeForTerminal(`Opening your browser to approve Tenjin for ${label}\u2026`)}
807
+ `
808
+ );
809
+ emitWriteNotice(ctx.io, ` If it didn't open: ${url}`);
810
+ }
811
+ } : {},
812
+ interactive: ctx.io.isTTY && (deps.stdinIsTTY ?? Boolean(process.stdin.isTTY)),
813
+ waitMs: deps.waitMs ?? SIGN_IN_WAIT_MS,
814
+ ...deps.ports !== void 0 ? { ports: deps.ports } : {},
815
+ ...deps.clientMetadataUrl !== void 0 ? { clientMetadataUrl: deps.clientMetadataUrl } : {},
816
+ ...deps.now !== void 0 ? { now: deps.now } : {}
817
+ };
818
+ const signed = await signIn({ ...account, typed: !account.mapped }, signInDeps);
819
+ if (human) ctx.io.stderr.write("\n");
820
+ secret = {
821
+ tokens: { ...signed.tokens },
822
+ obtainedAt: signed.obtainedAt,
823
+ clientInformation: { ...signed.clientInformation },
824
+ discoveryState: { ...signed.discoveryState }
825
+ };
826
+ headers = authHeader("Bearer", signed.tokens.access_token);
827
+ expiresAt = expiresAtOf(signed.tokens, signed.obtainedAt);
828
+ }
829
+ const checked = await checkAccount(account, headers, byKey, deps);
830
+ const now = deps.now?.() ?? Date.now();
831
+ const vaultDeps = {
832
+ dataDir: ctx.dataDir,
833
+ exec: deps.exec ?? defaultExecFor(),
834
+ interactive: ctx.io.isTTY,
835
+ ...deps.platform !== void 0 ? { platform: deps.platform } : {}
836
+ };
837
+ const { plainFile, previous } = await writeVault(
838
+ account.id,
839
+ account.label,
840
+ {
841
+ kind: byKey ? "key" : "oauth",
842
+ mcpUrl: account.mcpUrl,
843
+ ...account.mapped ? {} : { typed: true },
844
+ connectedAt: new Date(now).toISOString(),
845
+ ...expiresAt !== void 0 ? { expiresAt } : {},
846
+ state: "ok",
847
+ missingTools: checked.missingTools
848
+ },
849
+ secret,
850
+ vaultDeps
851
+ );
852
+ if (plainFile) {
853
+ emitWriteNotice(
854
+ ctx.io,
855
+ `This machine has no keychain, so the key that seals this sign-in is in ${sourceKeyFilePath(account.id, ctx.dataDir)}, readable only by you.`
856
+ );
857
+ }
858
+ const descriptor = {
859
+ id: account.id,
860
+ label: account.label,
861
+ mcpUrl: account.mcpUrl,
862
+ signIn: byKey ? "key" : "oauth",
863
+ ...byKey ? { keyScheme: account.keyScheme } : {},
864
+ // Only an account the identities read lists is named to the router, in
865
+ // every request's sources; one connected by its address alone stays on
866
+ // this machine. The tools its maps call run only through those jobs.
867
+ ...account.mapped ? { mapped: true, mappedTools: account.expectTools } : {}
868
+ };
869
+ let preference = "skipped";
870
+ let rule;
871
+ let policy;
872
+ try {
873
+ await persist(ctx.dataDir, (existing) => {
874
+ const next = withDescriptor(existing, descriptor);
875
+ if (flags.prefer === false || !account.mapped) {
876
+ preference = "skipped";
877
+ return next;
878
+ }
879
+ const preferred = withPreference(next, account.id, identities);
880
+ preference = preferred.outcome;
881
+ rule = preferred.rule;
882
+ policy = preferred.policy;
883
+ return preferred.next;
884
+ });
885
+ } catch (err) {
886
+ await (previous !== null ? restoreVault(account.id, previous, vaultDeps) : deleteVault(account.id, vaultDeps)).catch(() => void 0);
887
+ throw err;
888
+ }
889
+ const explanation = connectLines(account, identities, checked, preference, byKey);
890
+ return answer(
891
+ {
892
+ operation: "connect",
893
+ changed: true,
894
+ scope: "user",
895
+ explanation,
896
+ human: connectReply(account, identities, checked, preference),
897
+ ...rule !== void 0 && policy !== void 0 ? { effective: [describePrefer(rule, policy, identities)] } : {},
898
+ reset: `tenjin disconnect ${account.id}`,
899
+ extra: {
900
+ account: {
901
+ id: account.id,
902
+ label: account.label,
903
+ signIn: byKey ? "key" : "oauth",
904
+ mapped: account.mapped,
905
+ jobs: account.mapped ? accountJobs(account.id, identities) : [],
906
+ missingTools: checked.missingTools,
907
+ preference,
908
+ ...preference === "added" || preference === "kept" ? { undoPreference: `tenjin config reset --source ${account.id} --preference` } : {}
909
+ }
910
+ }
911
+ },
912
+ ctx,
913
+ {
914
+ ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {},
915
+ ...deps.cwd !== void 0 ? { cwd: deps.cwd } : {}
916
+ },
917
+ identities
918
+ );
919
+ }
920
+ function withoutAccount(existing, id) {
921
+ const next = editSources(existing, (saved) => saved.filter((entry) => entry.id !== id));
922
+ const router = { ...next.router ?? {} };
923
+ const raw = router.policy;
924
+ if (raw === void 0) return { next, policyKept: true };
925
+ const shape = SavedPolicyShapeSchema.safeParse(raw);
926
+ if (!shape.success) return { next, policyKept: false };
927
+ const prefer = (shape.data.prefer ?? []).flatMap((rule) => {
928
+ const targets = rule.targets.filter((t) => !(t.kind === "source" && t.id === id));
929
+ return targets.length === 0 ? [] : [{ ...rule, targets }];
930
+ });
931
+ const rules = wirePolicy({ ...shape.data, prefer });
932
+ if (hasRules(rules)) router.policy = { version: shape.data.version, ...rules };
933
+ else delete router.policy;
934
+ return { next: { ...next, router }, policyKept: true };
935
+ }
936
+ async function runDisconnect(target, ctx, deps = {}) {
937
+ const name = folded(target);
938
+ if (name.length === 0) usage("Say which account to disconnect: tenjin disconnect <name>.");
939
+ const config = await loadRawConfig(ctx.dataDir);
940
+ const saved = savedDescriptors(config.router).flatMap((e) => savedAccountOf(e) ?? []);
941
+ const own = saved.find((account) => account.id === name || folded(account.label) === name);
942
+ const id = own?.id ?? (isAccountId(name) ? name : void 0);
943
+ const vaultDeps = {
944
+ dataDir: ctx.dataDir,
945
+ exec: deps.exec ?? defaultExecFor(),
946
+ ...deps.platform !== void 0 ? { platform: deps.platform } : {}
947
+ };
948
+ const header = id !== void 0 ? await readVaultHeader(ctx.dataDir, id).catch(() => null) : null;
949
+ const label = own?.label ?? target.trim();
950
+ const identities = await cachedIdentities(ctx.dataDir);
951
+ const answerDeps = { ...deps.cwd !== void 0 ? { cwd: deps.cwd } : {} };
952
+ if (id === void 0 || own === void 0 && header === null) {
953
+ return answer(
954
+ {
955
+ operation: "disconnect",
956
+ changed: false,
957
+ scope: "user",
958
+ explanation: [`${label} isn't connected on this machine. Nothing changed.`],
959
+ human: { said: [`${label} isn't connected on this machine. Nothing changed.`] }
960
+ },
961
+ ctx,
962
+ answerDeps,
963
+ identities
964
+ );
965
+ }
966
+ let signedOut = "none";
967
+ if (header !== null) {
968
+ if (header.kind === "key") signedOut = "key";
969
+ else {
970
+ const read = await readVault(id, label, vaultDeps).catch(() => null);
971
+ signedOut = read?.status === "ok" ? await revokeSignIn(
972
+ read.secret,
973
+ { mcpUrl: read.header.mcpUrl, typed: read.header.typed === true },
974
+ deps.fetchImpl
975
+ ) : "failed";
976
+ }
977
+ }
978
+ await deleteVault(id, vaultDeps);
979
+ let policyKept = true;
980
+ await persist(ctx.dataDir, (existing) => {
981
+ const result = withoutAccount(existing, id);
982
+ policyKept = result.policyKept;
983
+ return result.next;
984
+ });
985
+ const explanation = [
986
+ signedOut === "revoked" ? `${label} is disconnected: Tenjin signed out of it and deleted the sign-in on this machine.` : signedOut === "key" ? `${label} is disconnected: Tenjin deleted your ${label} key from this machine. The key itself still works at ${label} until you delete it there.` : signedOut === "none" ? `${label} is disconnected on this machine.` : `${label} is disconnected: Tenjin deleted the sign-in on this machine, but couldn't sign out at ${label}. You can remove Tenjin's access in your ${label} account settings.`,
987
+ policyKept ? `It's no longer in your preferences. Your other settings and accounts stay as they are.` : `Your saved settings can't be read, so any preference for ${label} stays until they're fixed.`
988
+ ];
989
+ const human = {
990
+ done: `Disconnected ${label}`,
991
+ said: [
992
+ signedOut === "revoked" ? "Signed out and forgotten on this machine." : signedOut === "key" ? `Forgotten on this machine. The key still works at ${label} until you delete it there.` : signedOut === "none" ? "Forgotten on this machine." : `Forgotten on this machine, but Tenjin couldn't sign out at ${label}: remove its access in your ${label} settings.`
993
+ ],
994
+ ...policyKept ? {} : {
995
+ problems: [
996
+ `Your saved settings can't be read, so a preference for ${label} stays until they're fixed.`
997
+ ]
998
+ }
999
+ };
1000
+ return answer(
1001
+ {
1002
+ operation: "disconnect",
1003
+ changed: true,
1004
+ scope: "user",
1005
+ explanation,
1006
+ human,
1007
+ reset: `tenjin connect ${id}`,
1008
+ extra: { account: { id, label, signedOut } }
1009
+ },
1010
+ ctx,
1011
+ answerDeps,
1012
+ identities
1013
+ );
1014
+ }
1015
+ export {
1016
+ SIGN_IN_WAIT_MS,
1017
+ runConnect,
1018
+ runDisconnect
1019
+ };
1020
+ //# sourceMappingURL=connect-YDWTYU4B.js.map