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

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 (270) hide show
  1. package/README.md +45 -26
  2. package/dist/{_esm-MEXZI5DL.js → _esm-BIN7VY2L.js} +128 -132
  3. package/dist/{alive-J64H46HI.js → alive-GSOWKUOY.js} +13 -6
  4. package/dist/auto-update-Y24UL56V.js +24 -0
  5. package/dist/{ccip-7RMRLAGV.js → ccip-DHDFKTQV.js} +2 -2
  6. package/dist/{chunk-TTNESUPQ.js → chunk-2GP3HRYK.js} +2120 -193
  7. package/dist/chunk-2GP3HRYK.js.map +1 -0
  8. package/dist/chunk-2M2VPI2E.js +560 -0
  9. package/dist/chunk-2M2VPI2E.js.map +1 -0
  10. package/dist/{chunk-D65GNPS3.js → chunk-2RWB7RKE.js} +288 -108
  11. package/dist/chunk-2RWB7RKE.js.map +1 -0
  12. package/dist/{chunk-AGZ7PJKY.js → chunk-36RVGZNY.js} +22 -5
  13. package/dist/chunk-36RVGZNY.js.map +1 -0
  14. package/dist/chunk-3AIHRXKO.js +72 -0
  15. package/dist/chunk-3AIHRXKO.js.map +1 -0
  16. package/dist/{chunk-S4SAZ7OD.js → chunk-3FMZGI7I.js} +12 -2
  17. package/dist/{chunk-S4SAZ7OD.js.map → chunk-3FMZGI7I.js.map} +1 -1
  18. package/dist/chunk-3GNJXKIT.js +198 -0
  19. package/dist/chunk-3GNJXKIT.js.map +1 -0
  20. package/dist/{chunk-UQUOVWBG.js → chunk-4K7TQHNP.js} +7 -7
  21. package/dist/{chunk-A36LQPHV.js → chunk-4LMUQMBH.js} +1 -1
  22. package/dist/{chunk-A36LQPHV.js.map → chunk-4LMUQMBH.js.map} +1 -1
  23. package/dist/{chunk-KXQ4UIP7.js → chunk-4USCZ2NI.js} +2 -2
  24. package/dist/chunk-4YOZGGTZ.js +247 -0
  25. package/dist/chunk-4YOZGGTZ.js.map +1 -0
  26. package/dist/chunk-62KNUYWD.js +111 -0
  27. package/dist/chunk-62KNUYWD.js.map +1 -0
  28. package/dist/{chunk-POUWHWID.js → chunk-6CMM6YCB.js} +3 -3
  29. package/dist/{chunk-POUWHWID.js.map → chunk-6CMM6YCB.js.map} +1 -1
  30. package/dist/{chunk-5MARFNSB.js → chunk-A5GKIG5O.js} +49 -30
  31. package/dist/chunk-A5GKIG5O.js.map +1 -0
  32. package/dist/{chunk-YFPY4ONH.js → chunk-AGMVASXZ.js} +4 -4
  33. package/dist/chunk-BF4XHEQK.js +116 -0
  34. package/dist/chunk-BF4XHEQK.js.map +1 -0
  35. package/dist/chunk-BFDQ4WNW.js +119 -0
  36. package/dist/chunk-BFDQ4WNW.js.map +1 -0
  37. package/dist/{chunk-P4NH7OUK.js → chunk-C2Q76BVM.js} +49 -50
  38. package/dist/chunk-C2Q76BVM.js.map +1 -0
  39. package/dist/chunk-CEXSOI5R.js +808 -0
  40. package/dist/chunk-CEXSOI5R.js.map +1 -0
  41. package/dist/{chunk-QSCPK4F5.js → chunk-E7SW44LM.js} +4 -11
  42. package/dist/chunk-E7SW44LM.js.map +1 -0
  43. package/dist/chunk-EDJWHDDL.js +33 -0
  44. package/dist/chunk-EDJWHDDL.js.map +1 -0
  45. package/dist/chunk-F3ED5WTR.js +13 -0
  46. package/dist/chunk-F3ED5WTR.js.map +1 -0
  47. package/dist/{chunk-K72RURN3.js → chunk-FVIGCDSV.js} +2 -2
  48. package/dist/chunk-FVIGCDSV.js.map +1 -0
  49. package/dist/{chunk-5K5W4S66.js → chunk-GTTUCOPD.js} +2 -2
  50. package/dist/{chunk-4ZZO6ULA.js → chunk-HDPUXS3Z.js} +19 -48
  51. package/dist/chunk-HDPUXS3Z.js.map +1 -0
  52. package/dist/{chunk-LEFIX6RS.js → chunk-HGGWCP7W.js} +31 -11
  53. package/dist/chunk-HGGWCP7W.js.map +1 -0
  54. package/dist/{chunk-ORWL5BSN.js → chunk-HGZEPQUT.js} +2 -2
  55. package/dist/chunk-HMWYAUA6.js +478 -0
  56. package/dist/chunk-HMWYAUA6.js.map +1 -0
  57. package/dist/{chunk-7QKHZQKW.js → chunk-IADZOXKN.js} +39 -6
  58. package/dist/chunk-IADZOXKN.js.map +1 -0
  59. package/dist/{chunk-7Q5FDF65.js → chunk-IE7P2BZE.js} +3 -3
  60. package/dist/{chunk-77TCKDEC.js → chunk-ILNIZ5I2.js} +788 -508
  61. package/dist/chunk-ILNIZ5I2.js.map +1 -0
  62. package/dist/{hosts-FWZOV26H.js → chunk-INTFHMU4.js} +79 -24
  63. package/dist/chunk-INTFHMU4.js.map +1 -0
  64. package/dist/{chunk-6E5R45ZO.js → chunk-J57UC3DD.js} +4 -4
  65. package/dist/{chunk-6E5R45ZO.js.map → chunk-J57UC3DD.js.map} +1 -1
  66. package/dist/chunk-JNJWBTU2.js +3497 -0
  67. package/dist/chunk-JNJWBTU2.js.map +1 -0
  68. package/dist/{chunk-7WU4OPLP.js → chunk-KM7RY2ZS.js} +5 -3
  69. package/dist/{chunk-7WU4OPLP.js.map → chunk-KM7RY2ZS.js.map} +1 -1
  70. package/dist/chunk-L6JEXB3E.js +293 -0
  71. package/dist/chunk-L6JEXB3E.js.map +1 -0
  72. package/dist/chunk-LRW6S53P.js +450 -0
  73. package/dist/chunk-LRW6S53P.js.map +1 -0
  74. package/dist/{chunk-UKY4CHNC.js → chunk-LXAYUOXI.js} +24 -11
  75. package/dist/chunk-LXAYUOXI.js.map +1 -0
  76. package/dist/{chunk-WJXLQXJY.js → chunk-MPZUYCAP.js} +4 -1
  77. package/dist/{chunk-WJXLQXJY.js.map → chunk-MPZUYCAP.js.map} +1 -1
  78. package/dist/chunk-NDGZDTSJ.js +393 -0
  79. package/dist/chunk-NDGZDTSJ.js.map +1 -0
  80. package/dist/{chunk-SJLTEINJ.js → chunk-OJNTCYQQ.js} +17 -1
  81. package/dist/chunk-OJNTCYQQ.js.map +1 -0
  82. package/dist/{chunk-OHRR5OYM.js → chunk-P3LFTKE7.js} +5 -10
  83. package/dist/chunk-P3LFTKE7.js.map +1 -0
  84. package/dist/{chunk-XZKD7DIF.js → chunk-RL5UUDT4.js} +3 -3
  85. package/dist/{chunk-XZKD7DIF.js.map → chunk-RL5UUDT4.js.map} +1 -1
  86. package/dist/{chunk-5C32RLTA.js → chunk-RVPYTUP4.js} +20 -5
  87. package/dist/chunk-RVPYTUP4.js.map +1 -0
  88. package/dist/{chunk-YVFXE7RR.js → chunk-SNNSAGMT.js} +7279 -2627
  89. package/dist/chunk-SNNSAGMT.js.map +1 -0
  90. package/dist/{chunk-WK7F3B2E.js → chunk-SO3XRZPX.js} +3 -3
  91. package/dist/{chunk-R5LCN54M.js → chunk-TC2WZLSC.js} +13 -17
  92. package/dist/{chunk-R5LCN54M.js.map → chunk-TC2WZLSC.js.map} +1 -1
  93. package/dist/{chunk-B7HUUJOK.js → chunk-TKPF35W6.js} +3 -3
  94. package/dist/{chunk-KXVP2VKA.js → chunk-U3IKUGRP.js} +32 -33
  95. package/dist/chunk-U3IKUGRP.js.map +1 -0
  96. package/dist/{chunk-AKWGE6JQ.js → chunk-UUGOUOVT.js} +37 -2
  97. package/dist/chunk-UUGOUOVT.js.map +1 -0
  98. package/dist/{chunk-2XLC3AEX.js → chunk-UXZONNEQ.js} +536 -510
  99. package/dist/chunk-UXZONNEQ.js.map +1 -0
  100. package/dist/{chunk-7ZRL2LBQ.js → chunk-V2LQLN5H.js} +6 -6
  101. package/dist/{chunk-NEFNKLBE.js → chunk-WFSPCCVW.js} +1536 -423
  102. package/dist/chunk-WFSPCCVW.js.map +1 -0
  103. package/dist/{chunk-27EPWVOY.js → chunk-WXA2BWTE.js} +7 -3
  104. package/dist/chunk-WXA2BWTE.js.map +1 -0
  105. package/dist/chunk-WYXUQGOL.js +191 -0
  106. package/dist/chunk-WYXUQGOL.js.map +1 -0
  107. package/dist/chunk-X5ZBP3IY.js +97 -0
  108. package/dist/chunk-X5ZBP3IY.js.map +1 -0
  109. package/dist/{chunk-MNXS2U45.js → chunk-ZDZERB6L.js} +206 -297
  110. package/dist/chunk-ZDZERB6L.js.map +1 -0
  111. package/dist/chunk-ZNNXRNFD.js +113 -0
  112. package/dist/chunk-ZNNXRNFD.js.map +1 -0
  113. package/dist/{chunk-FW75G2W4.js → chunk-ZURZHELF.js} +5 -5
  114. package/dist/{cli-D5OE3URZ.js → cli-E36SPKBW.js} +145 -64
  115. package/dist/{cli-D5OE3URZ.js.map → cli-E36SPKBW.js.map} +1 -1
  116. package/dist/{codex-event-PPNVRRDH.js → codex-event-ZO2GEFE6.js} +2 -2
  117. package/dist/{codex-host-2RJOJW2B.js → codex-host-KECJVTA2.js} +7 -6
  118. package/dist/codex-install-HQZDGFXW.js +436 -0
  119. package/dist/codex-install-HQZDGFXW.js.map +1 -0
  120. package/dist/{config-ZD4OB2DO.js → config-HY2E4GGW.js} +21 -17
  121. package/dist/doctor-I6XQEKWD.js +1323 -0
  122. package/dist/doctor-I6XQEKWD.js.map +1 -0
  123. package/dist/{env-proxy-XL4P73MZ.js → env-proxy-R6ZMLQTT.js} +6 -2
  124. package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js → ethersCompat-Df4a6QIZ-X6YZWAML.js} +3 -3
  125. package/dist/{fund-5ITKQGYF.js → fund-2QRO7OJL.js} +43 -37
  126. package/dist/{fund-5ITKQGYF.js.map → fund-2QRO7OJL.js.map} +1 -1
  127. package/dist/hook-command-2UBCSZG6.js +43 -0
  128. package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
  129. package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +2 -2
  130. package/dist/hosts/claude/tenjin/hooks/register.tsx +51 -11
  131. package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +82 -0
  132. package/dist/hosts/claude/tenjin/types/index.d.ts +2 -1
  133. package/dist/hosts/codex/tenjin/.mcp.json +3 -0
  134. package/dist/hosts/codex/tenjin/hooks/hooks.json +51 -5
  135. package/dist/hosts-DVQJ32QC.js +38 -0
  136. package/dist/index.js +32 -11
  137. package/dist/index.js.map +1 -1
  138. package/dist/install-ILUX5C4A.js +107 -0
  139. package/dist/{install-identity-K7EJIQFP.js → install-identity-TZKGY6LQ.js} +11 -10
  140. package/dist/install-wallet-5M4OTYLX.js +281 -0
  141. package/dist/install-wallet-5M4OTYLX.js.map +1 -0
  142. package/dist/isows-native-Q2UDIVPT.js +9 -0
  143. package/dist/isows-native-Q2UDIVPT.js.map +1 -0
  144. package/dist/{mcp-3LIJSSJB.js → mcp-LE4DUS22.js} +785 -211
  145. package/dist/mcp-LE4DUS22.js.map +1 -0
  146. package/dist/{mine.wasm-6PIT3DK6.js → mine.wasm-QFAHIFPY.js} +2 -2
  147. package/dist/{mine.wasm-6PIT3DK6.js.map → mine.wasm-QFAHIFPY.js.map} +1 -1
  148. package/dist/{package-ZKQFDWLE.js → package-IJFGMWEV.js} +4 -2
  149. package/dist/passphrase-IFTDS3CU.js +44 -0
  150. package/dist/{paths-POPTXJO6.js → paths-XCSAKISU.js} +10 -2
  151. package/dist/{pay-WHBERZ3W.js → pay-WCG3IH4R.js} +29 -29
  152. package/dist/{payments-KVICEKD2.js → payments-HFPPWHTV.js} +15 -14
  153. package/dist/{payments-KVICEKD2.js.map → payments-HFPPWHTV.js.map} +1 -1
  154. package/dist/plugin-registration-PZFI5GZW.js +68 -0
  155. package/dist/{redact-6W23GGJC.js → redact-D7ASVWKL.js} +2 -2
  156. package/dist/runtime-UZOKSUZX.js +1321 -0
  157. package/dist/runtime-UZOKSUZX.js.map +1 -0
  158. package/dist/runtime-fetch-ZSSSK72Y.js +23 -0
  159. package/dist/runtime-layout-WIDILZ6K.js +25 -0
  160. package/dist/{send-7G7Y7DLN.js → send-GCVEAQKL.js} +24 -22
  161. package/dist/{send-7G7Y7DLN.js.map → send-GCVEAQKL.js.map} +1 -1
  162. package/dist/{status-OF7RH5HM.js → status-HCVAOCN7.js} +55 -25
  163. package/dist/status-HCVAOCN7.js.map +1 -0
  164. package/dist/{status-line-XOUE6MPL.js → status-line-OPCXDHL2.js} +10 -9
  165. package/dist/{status-line-XOUE6MPL.js.map → status-line-OPCXDHL2.js.map} +1 -1
  166. package/dist/uninstall-BAWRBXXQ.js +481 -0
  167. package/dist/uninstall-BAWRBXXQ.js.map +1 -0
  168. package/dist/update-CACXLQLR.js +56 -0
  169. package/dist/update-CACXLQLR.js.map +1 -0
  170. package/dist/{usdc-OGOGEHV2.js → usdc-VG4CIOUK.js} +6 -8
  171. package/dist/usdc-VG4CIOUK.js.map +1 -0
  172. package/dist/{viemAdapter-By13KInL-S3DA7DFW.js → viemAdapter-By13KInL-DOFTEIJV.js} +3 -3
  173. package/dist/viemAdapter-By13KInL-DOFTEIJV.js.map +1 -0
  174. package/dist/wallet-QL4UUXEZ.js +55 -0
  175. package/dist/wallet-QL4UUXEZ.js.map +1 -0
  176. package/dist/wallet-kdf-worker.mjs +8 -8
  177. package/docs/agent-permissions.md +50 -28
  178. package/docs/safety-model.md +1 -1
  179. package/docs/troubleshooting.md +72 -1
  180. package/package.json +17 -4
  181. package/scripts/installers/install.ps1 +67 -0
  182. package/scripts/installers/install.sh +68 -0
  183. package/dist/_esm-C5CRWCYU.js +0 -3737
  184. package/dist/_esm-C5CRWCYU.js.map +0 -1
  185. package/dist/ccip-NLCSCHKI.js +0 -19
  186. package/dist/chunk-27EPWVOY.js.map +0 -1
  187. package/dist/chunk-2XLC3AEX.js.map +0 -1
  188. package/dist/chunk-4ZZO6ULA.js.map +0 -1
  189. package/dist/chunk-5C32RLTA.js.map +0 -1
  190. package/dist/chunk-5IEP5EGE.js +0 -5332
  191. package/dist/chunk-5IEP5EGE.js.map +0 -1
  192. package/dist/chunk-5MARFNSB.js.map +0 -1
  193. package/dist/chunk-77TCKDEC.js.map +0 -1
  194. package/dist/chunk-7EKYXMUO.js +0 -7536
  195. package/dist/chunk-7EKYXMUO.js.map +0 -1
  196. package/dist/chunk-7QKHZQKW.js.map +0 -1
  197. package/dist/chunk-AGZ7PJKY.js.map +0 -1
  198. package/dist/chunk-AKWGE6JQ.js.map +0 -1
  199. package/dist/chunk-BL3332HQ.js +0 -7611
  200. package/dist/chunk-BL3332HQ.js.map +0 -1
  201. package/dist/chunk-D65GNPS3.js.map +0 -1
  202. package/dist/chunk-EGELTSPU.js +0 -2865
  203. package/dist/chunk-EGELTSPU.js.map +0 -1
  204. package/dist/chunk-GA7JETVM.js +0 -150
  205. package/dist/chunk-GA7JETVM.js.map +0 -1
  206. package/dist/chunk-I3EQFHCD.js +0 -175
  207. package/dist/chunk-I3EQFHCD.js.map +0 -1
  208. package/dist/chunk-K3I7C2MO.js +0 -1185
  209. package/dist/chunk-K3I7C2MO.js.map +0 -1
  210. package/dist/chunk-K72RURN3.js.map +0 -1
  211. package/dist/chunk-KXVP2VKA.js.map +0 -1
  212. package/dist/chunk-LEFIX6RS.js.map +0 -1
  213. package/dist/chunk-MNXS2U45.js.map +0 -1
  214. package/dist/chunk-NEFNKLBE.js.map +0 -1
  215. package/dist/chunk-OHRR5OYM.js.map +0 -1
  216. package/dist/chunk-P4NH7OUK.js.map +0 -1
  217. package/dist/chunk-QSCPK4F5.js.map +0 -1
  218. package/dist/chunk-SJLTEINJ.js.map +0 -1
  219. package/dist/chunk-TTNESUPQ.js.map +0 -1
  220. package/dist/chunk-UKY4CHNC.js.map +0 -1
  221. package/dist/chunk-V6BSF6OC.js +0 -260
  222. package/dist/chunk-V6BSF6OC.js.map +0 -1
  223. package/dist/chunk-YVFXE7RR.js.map +0 -1
  224. package/dist/codex-install-UUZ6QMBQ.js +0 -221
  225. package/dist/codex-install-UUZ6QMBQ.js.map +0 -1
  226. package/dist/doctor-KBR34Q4B.js +0 -601
  227. package/dist/doctor-KBR34Q4B.js.map +0 -1
  228. package/dist/hook-command-4TYCHHRL.js +0 -39
  229. package/dist/hosts-FWZOV26H.js.map +0 -1
  230. package/dist/install-XWGE4Q7L.js +0 -77
  231. package/dist/install-wallet-XQ6XFZV4.js +0 -117
  232. package/dist/install-wallet-XQ6XFZV4.js.map +0 -1
  233. package/dist/mcp-3LIJSSJB.js.map +0 -1
  234. package/dist/plugin-registration-5TIA564H.js +0 -54
  235. package/dist/status-OF7RH5HM.js.map +0 -1
  236. package/dist/uninstall-JXUAFNDB.js +0 -158
  237. package/dist/uninstall-JXUAFNDB.js.map +0 -1
  238. package/dist/update-ZKUERSO2.js +0 -44
  239. package/dist/wallet-2HA6W4R4.js +0 -43
  240. /package/dist/{_esm-MEXZI5DL.js.map → _esm-BIN7VY2L.js.map} +0 -0
  241. /package/dist/{alive-J64H46HI.js.map → alive-GSOWKUOY.js.map} +0 -0
  242. /package/dist/{ccip-7RMRLAGV.js.map → auto-update-Y24UL56V.js.map} +0 -0
  243. /package/dist/{ccip-NLCSCHKI.js.map → ccip-DHDFKTQV.js.map} +0 -0
  244. /package/dist/{chunk-UQUOVWBG.js.map → chunk-4K7TQHNP.js.map} +0 -0
  245. /package/dist/{chunk-KXQ4UIP7.js.map → chunk-4USCZ2NI.js.map} +0 -0
  246. /package/dist/{chunk-YFPY4ONH.js.map → chunk-AGMVASXZ.js.map} +0 -0
  247. /package/dist/{chunk-5K5W4S66.js.map → chunk-GTTUCOPD.js.map} +0 -0
  248. /package/dist/{chunk-ORWL5BSN.js.map → chunk-HGZEPQUT.js.map} +0 -0
  249. /package/dist/{chunk-7Q5FDF65.js.map → chunk-IE7P2BZE.js.map} +0 -0
  250. /package/dist/{chunk-WK7F3B2E.js.map → chunk-SO3XRZPX.js.map} +0 -0
  251. /package/dist/{chunk-B7HUUJOK.js.map → chunk-TKPF35W6.js.map} +0 -0
  252. /package/dist/{chunk-7ZRL2LBQ.js.map → chunk-V2LQLN5H.js.map} +0 -0
  253. /package/dist/{chunk-FW75G2W4.js.map → chunk-ZURZHELF.js.map} +0 -0
  254. /package/dist/{codex-event-PPNVRRDH.js.map → codex-event-ZO2GEFE6.js.map} +0 -0
  255. /package/dist/{codex-host-2RJOJW2B.js.map → codex-host-KECJVTA2.js.map} +0 -0
  256. /package/dist/{config-ZD4OB2DO.js.map → config-HY2E4GGW.js.map} +0 -0
  257. /package/dist/{env-proxy-XL4P73MZ.js.map → env-proxy-R6ZMLQTT.js.map} +0 -0
  258. /package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js.map → ethersCompat-Df4a6QIZ-X6YZWAML.js.map} +0 -0
  259. /package/dist/{hook-command-4TYCHHRL.js.map → hook-command-2UBCSZG6.js.map} +0 -0
  260. /package/dist/{install-XWGE4Q7L.js.map → hosts-DVQJ32QC.js.map} +0 -0
  261. /package/dist/{install-identity-K7EJIQFP.js.map → install-ILUX5C4A.js.map} +0 -0
  262. /package/dist/{package-ZKQFDWLE.js.map → install-identity-TZKGY6LQ.js.map} +0 -0
  263. /package/dist/{paths-POPTXJO6.js.map → package-IJFGMWEV.js.map} +0 -0
  264. /package/dist/{pay-WHBERZ3W.js.map → passphrase-IFTDS3CU.js.map} +0 -0
  265. /package/dist/{plugin-registration-5TIA564H.js.map → paths-XCSAKISU.js.map} +0 -0
  266. /package/dist/{redact-6W23GGJC.js.map → pay-WCG3IH4R.js.map} +0 -0
  267. /package/dist/{update-ZKUERSO2.js.map → plugin-registration-PZFI5GZW.js.map} +0 -0
  268. /package/dist/{usdc-OGOGEHV2.js.map → redact-D7ASVWKL.js.map} +0 -0
  269. /package/dist/{viemAdapter-By13KInL-S3DA7DFW.js.map → runtime-fetch-ZSSSK72Y.js.map} +0 -0
  270. /package/dist/{wallet-2HA6W4R4.js.map → runtime-layout-WIDILZ6K.js.map} +0 -0
@@ -4,10 +4,10 @@ import {
4
4
  } from "./chunk-7WEQQJLG.js";
5
5
  import {
6
6
  balanceCachePath
7
- } from "./chunk-SJLTEINJ.js";
7
+ } from "./chunk-OJNTCYQQ.js";
8
8
 
9
9
  // src/lib/usdc-balance.ts
10
- import { readFile } from "node:fs/promises";
10
+ import { readFile, rm } from "node:fs/promises";
11
11
  var USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
12
12
  var BALANCE_OF_SELECTOR = "0x70a08231";
13
13
  var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
@@ -64,6 +64,9 @@ function sameUrl(a, b) {
64
64
  }
65
65
  }
66
66
  var LAST_KNOWN_BALANCE_MS = 6e4;
67
+ async function forgetRememberedBalance(dataDir) {
68
+ await rm(balanceCachePath(dataDir), { force: true }).catch(() => void 0);
69
+ }
67
70
  function rememberingBalanceReader(dataDir, opts = {}) {
68
71
  const read = opts.read ?? readUsdcBalanceWithFallback;
69
72
  const now = opts.now ?? Date.now;
@@ -103,6 +106,7 @@ export {
103
106
  readUsdcBalance,
104
107
  DEFAULT_RPC_URL,
105
108
  readUsdcBalanceWithFallback,
109
+ forgetRememberedBalance,
106
110
  rememberingBalanceReader
107
111
  };
108
- //# sourceMappingURL=chunk-27EPWVOY.js.map
112
+ //# sourceMappingURL=chunk-WXA2BWTE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/usdc-balance.ts"],"sourcesContent":["/**\n * Base USDC's address and one `balanceOf` over plain JSON-RPC. No viem on\n * purpose: the router hooks read a balance before they redirect a call, and\n * their chunk graph must stay free of it (`src/router/dist-chunks.test.ts`).\n * One `eth_call` needs nothing viem adds. `usdc.ts` keeps the viem client for\n * the send path and re-exports the address from here.\n */\n\nimport { readFile, rm } from 'node:fs/promises';\nimport { writeFileAtomic } from './atomic-json';\nimport { balanceCachePath } from './paths';\n\n// Values mirror the app's lib/chain.ts Base mainnet entry (chain 8453).\nexport const USDC_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';\n\n/** `balanceOf(address)`: the first four bytes of its keccak-256. */\nconst BALANCE_OF_SELECTOR = '0x70a08231';\nconst ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;\n/** One ABI word: what `balanceOf` returns. */\nconst WORD_RE = /^0x[0-9a-fA-F]{64}$/;\n\n/**\n * The address's USDC balance in atomic units, or null when it could not be\n * read inside `timeoutMs`: a transport failure, a non-2xx, an RPC error, or an\n * answer that is not one word. Never throws, so the caller picks which way an\n * unreadable balance falls.\n */\nexport async function readUsdcBalance(\n address: string,\n rpcUrl: string,\n opts: { timeoutMs: number; fetchImpl?: typeof fetch },\n): Promise<bigint | null> {\n if (!ADDRESS_RE.test(address) || opts.timeoutMs <= 0) return null;\n try {\n const res = await (opts.fetchImpl ?? fetch)(rpcUrl, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'eth_call',\n params: [\n {\n to: USDC_ADDRESS,\n data: `${BALANCE_OF_SELECTOR}${address.slice(2).toLowerCase().padStart(64, '0')}`,\n },\n 'latest',\n ],\n }),\n signal: AbortSignal.timeout(opts.timeoutMs),\n });\n if (!res.ok) return null;\n const result = ((await res.json()) as { result?: unknown } | null)?.result;\n return typeof result === 'string' && WORD_RE.test(result) ? BigInt(result) : null;\n } catch {\n return null;\n }\n}\n\n/** Base's public RPC: the shipped `rpcUrl` default (`CONFIG_DEFAULTS`). */\nexport const DEFAULT_RPC_URL = 'https://mainnet.base.org';\n\n/**\n * Public Base RPCs a balance read on the DEFAULT `rpcUrl` falls back to, in\n * order, only after it fails. mainnet.base.org rate-limits a busy IP\n * (`-32016 over rate limit`): four paid lookups across two research runs were\n * refused with `balance_unavailable` before signing, while these two answered\n * every read. They see the wallet's address only when the default did not\n * answer, as the default sees it on every read.\n */\nexport const FALLBACK_RPC_URLS: readonly string[] = [\n 'https://base-rpc.publicnode.com',\n 'https://base.drpc.org',\n];\n\n/**\n * {@link readUsdcBalance} from `rpcUrl` first and, when that is the default,\n * then from each of {@link FALLBACK_RPC_URLS} until one answers, all inside the\n * one `timeoutMs`. Every RPC but the last gets half of what is left, so one\n * that hangs still leaves the others time to answer.\n *\n * AN RPC THE USER CONFIGURED IS THE ONLY ONE ASKED. Choosing one can be about\n * privacy, and the public RPCs would see the wallet's address; a read that\n * fails there fails, as it did before the fallbacks.\n */\nexport async function readUsdcBalanceWithFallback(\n address: string,\n rpcUrl: string,\n opts: { timeoutMs: number; fetchImpl?: typeof fetch },\n): Promise<bigint | null> {\n const urls = sameUrl(rpcUrl, DEFAULT_RPC_URL) ? [rpcUrl, ...FALLBACK_RPC_URLS] : [rpcUrl];\n const deadline = Date.now() + opts.timeoutMs;\n for (const [index, url] of urls.entries()) {\n const left = deadline - Date.now();\n if (left <= 0) return null;\n const timeoutMs = index === urls.length - 1 ? left : Math.ceil(left / 2);\n const balance = await readUsdcBalance(address, url, { ...opts, timeoutMs });\n if (balance !== null) return balance;\n }\n return null;\n}\n\nfunction sameUrl(a: string, b: string): boolean {\n try {\n return new URL(a).href === new URL(b).href;\n } catch {\n return a === b;\n }\n}\n\n/**\n * How long the hooks remember a balance read. Base's public RPC refuses the\n * sixth `eth_call` in a second, which a burst of parallel lookups reaches, and\n * each hook then waited on a failed read. A minute carries a burst past that;\n * the hooks' read only decides whether to offer.\n */\nexport const LAST_KNOWN_BALANCE_MS = 60_000;\n\n/** An explicit balance check or observed funding makes a hook's cached balance obsolete. */\nexport async function forgetRememberedBalance(dataDir: string): Promise<void> {\n await rm(balanceCachePath(dataDir), { force: true }).catch(() => undefined);\n}\n\n/**\n * {@link readUsdcBalanceWithFallback} for the router hooks, which returns the\n * last read it made for this address while it is under\n * {@link LAST_KNOWN_BALANCE_MS} old, without asking an RPC, and reads the chain\n * otherwise. A read that fails on every RPC is null, never the remembered\n * balance. The RPC URL is never stored, since it can embed a key.\n *\n * NEVER FOR A PAYMENT. `tenjin pay` reads the signer's balance live\n * immediately before signing (docs/agent-permissions.md): a minute-old balance\n * can be one the wallet has since spent.\n */\nexport function rememberingBalanceReader(\n dataDir: string,\n opts: { now?: () => number; read?: typeof readUsdcBalance } = {},\n): typeof readUsdcBalance {\n const read = opts.read ?? readUsdcBalanceWithFallback;\n const now = opts.now ?? Date.now;\n const path = balanceCachePath(dataDir);\n return async (address, rpcUrl, readOpts) => {\n const remembered = await recallBalance(path, address, now());\n if (remembered !== null) return remembered;\n const live = await read(address, rpcUrl, readOpts);\n if (live === null) return null;\n const record = {\n version: 1,\n address: address.toLowerCase(),\n atomic: live.toString(),\n at: now(),\n };\n try {\n await writeFileAtomic(path, JSON.stringify(record), { mode: 0o600, dirMode: 0o700 });\n } catch {\n // A cache that cannot be written is a cache that is not used.\n }\n return live;\n };\n}\n\n/** The remembered balance for this address while it is fresh, else null. */\nasync function recallBalance(path: string, address: string, now: number): Promise<bigint | null> {\n try {\n const row = JSON.parse(await readFile(path, 'utf8')) as Record<string, unknown> | null;\n if (\n row?.version !== 1 ||\n row.address !== address.toLowerCase() ||\n typeof row.atomic !== 'string' ||\n !/^\\d{1,40}$/.test(row.atomic) ||\n typeof row.at !== 'number' ||\n now - row.at < 0 ||\n now - row.at > LAST_KNOWN_BALANCE_MS\n ) {\n return null;\n }\n return BigInt(row.atomic);\n } catch {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;AAQA,SAAS,UAAU,UAAU;AAKtB,IAAM,eAAe;AAG5B,IAAM,sBAAsB;AAC5B,IAAM,aAAa;AAEnB,IAAM,UAAU;AAQhB,eAAsB,gBACpB,SACA,QACA,MACwB;AACxB,MAAI,CAAC,WAAW,KAAK,OAAO,KAAK,KAAK,aAAa,EAAG,QAAO;AAC7D,MAAI;AACF,UAAM,MAAM,OAAO,KAAK,aAAa,OAAO,QAAQ;AAAA,MAClD,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU;AAAA,QACnB,SAAS;AAAA,QACT,IAAI;AAAA,QACJ,QAAQ;AAAA,QACR,QAAQ;AAAA,UACN;AAAA,YACE,IAAI;AAAA,YACJ,MAAM,GAAG,mBAAmB,GAAG,QAAQ,MAAM,CAAC,EAAE,YAAY,EAAE,SAAS,IAAI,GAAG,CAAC;AAAA,UACjF;AAAA,UACA;AAAA,QACF;AAAA,MACF,CAAC;AAAA,MACD,QAAQ,YAAY,QAAQ,KAAK,SAAS;AAAA,IAC5C,CAAC;AACD,QAAI,C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AAQ,aAAa;AAC1C,UAAM,aAAa,MAAM,cAAc,MAAM,SAAS,IAAI,CAAC;AAC3D,QAAI,eAAe,KAAM,QAAO;AAChC,UAAM,OAAO,MAAM,KAAK,SAAS,QAAQ,QAAQ;AACjD,QAAI,SAAS,KAAM,QAAO;AAC1B,UAAM,SAAS;AAAA,MACb,SAAS;AAAA,MACT,SAAS,QAAQ,YAAY;AAAA,MAC7B,QAAQ,KAAK,SAAS;AAAA,MACtB,IAAI,IAAI;AAAA,IACV;AACA,QAAI;AACF,YAAM,gBAAgB,MAAM,KAAK,UAAU,MAAM,GAAG,EAAE,MAAM,KAAO,SAAS,IAAM,CAAC;AAAA,IACrF,QAAQ;AAAA,IAER;AACA,WAAO;AAAA,EACT;AACF;AAGA,eAAe,cAAc,MAAc,SAAiB,KAAqC;AAC/F,MAAI;AACF,UAAM,MAAM,KAAK,MAAM,MAAM,SAAS,MAAM,MAAM,CAAC;AACnD,QACE,KAAK,YAAY,KACjB,IAAI,YAAY,QAAQ,YAAY,KACpC,OAAO,IAAI,WAAW,YACtB,CAAC,aAAa,KAAK,IAAI,MAAM,KAC7B,OAAO,IAAI,OAAO,YAClB,MAAM,IAAI,KAAK,KACf,MAAM,IAAI,KAAK,uBACf;AACA,aAAO;AAAA,IACT;AACA,WAAO,OAAO,IAAI,MAAM;AAAA,EAC1B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,191 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ hasCode
4
+ } from "./chunk-2I4QTOLB.js";
5
+ import {
6
+ external_exports
7
+ } from "./chunk-SNNSAGMT.js";
8
+ import {
9
+ writeFileAtomic
10
+ } from "./chunk-7WEQQJLG.js";
11
+
12
+ // src/router/router-observation.ts
13
+ import { readFile, readdir, rm } from "node:fs/promises";
14
+ import { rmSync } from "node:fs";
15
+ import { join } from "node:path";
16
+ var SIGNING_SOURCES = [
17
+ "key-env",
18
+ "passphrase-env",
19
+ "keychain",
20
+ "secret-service",
21
+ "dpapi",
22
+ "file",
23
+ "legacy"
24
+ ];
25
+ var ObservationSchema = external_exports.object({
26
+ version: external_exports.literal(1),
27
+ pid: external_exports.number().int().positive(),
28
+ startedAt: external_exports.number(),
29
+ at: external_exports.number(),
30
+ cliVersion: external_exports.string(),
31
+ harness: external_exports.enum(["claude", "codex"]),
32
+ launchedByPlugin: external_exports.boolean(),
33
+ cwd: external_exports.string(),
34
+ address: external_exports.string().nullable(),
35
+ servedSession: external_exports.boolean(),
36
+ env: external_exports.object({ passphraseSet: external_exports.boolean(), keySet: external_exports.boolean() }),
37
+ sign: external_exports.object({
38
+ status: external_exports.enum(["ready", "blocked", "unknown", "pending"]),
39
+ reason: external_exports.string().optional(),
40
+ detail: external_exports.string().optional(),
41
+ fix: external_exports.string().optional(),
42
+ source: external_exports.enum(SIGNING_SOURCES).optional()
43
+ }),
44
+ routing: external_exports.object({
45
+ status: external_exports.enum(["ready", "blocked", "unknown"]),
46
+ reason: external_exports.string().optional(),
47
+ at: external_exports.number()
48
+ }).optional()
49
+ });
50
+ var UnlockRecordSchema = external_exports.object({
51
+ version: external_exports.literal(1),
52
+ address: external_exports.string(),
53
+ status: external_exports.enum(["ready", "blocked", "unknown", "awaiting_confirmation"]),
54
+ reason: external_exports.string().optional(),
55
+ at: external_exports.number(),
56
+ inputs: external_exports.object({
57
+ envPassphraseSet: external_exports.boolean(),
58
+ envKeySet: external_exports.boolean(),
59
+ walletMtimeMs: external_exports.number().nullable(),
60
+ sidecarMtimeMs: external_exports.number().nullable(),
61
+ cliVersion: external_exports.string()
62
+ }).optional()
63
+ });
64
+ var UnlockStateSchema = external_exports.object({
65
+ version: external_exports.literal(1),
66
+ wallets: external_exports.record(external_exports.string(), external_exports.unknown())
67
+ });
68
+ var OBSERVATION_NAME = /^(\d+)\.json$/;
69
+ var START_SLACK_MS = 2e3;
70
+ function liveDir(dataDir) {
71
+ return join(dataDir, "router", "live");
72
+ }
73
+ function observationPath(dataDir, pid) {
74
+ return join(liveDir(dataDir), `${pid}.json`);
75
+ }
76
+ function unlockStatePath(dataDir) {
77
+ return join(dataDir, "router", "unlock-state.json");
78
+ }
79
+ async function writeObservation(dataDir, obs) {
80
+ try {
81
+ await writeFileAtomic(observationPath(dataDir, obs.pid), JSON.stringify(obs) + "\n", {
82
+ mode: 384,
83
+ dirMode: 448
84
+ });
85
+ } catch {
86
+ }
87
+ }
88
+ function removeObservationSync(dataDir, pid) {
89
+ try {
90
+ rmSync(observationPath(dataDir, pid), { force: true });
91
+ } catch {
92
+ }
93
+ }
94
+ async function pruneDeadObservations(dataDir, isAlive = pidAlive) {
95
+ const dir = liveDir(dataDir);
96
+ const names = await readdir(dir).catch(() => []);
97
+ for (const name of names) {
98
+ const match = OBSERVATION_NAME.exec(name);
99
+ if (match === null) continue;
100
+ if (isAlive(Number(match[1]))) continue;
101
+ await rm(join(dir, name), { force: true }).catch(() => void 0);
102
+ }
103
+ }
104
+ async function readObservations(dataDir) {
105
+ const dir = liveDir(dataDir);
106
+ const names = await readdir(dir).catch(() => []);
107
+ const out = [];
108
+ for (const name of names.sort()) {
109
+ const match = OBSERVATION_NAME.exec(name);
110
+ if (match === null) continue;
111
+ try {
112
+ const parsed = ObservationSchema.safeParse(
113
+ JSON.parse(await readFile(join(dir, name), "utf8"))
114
+ );
115
+ if (parsed.success && parsed.data.pid === Number(match[1])) {
116
+ out.push(parsed.data);
117
+ }
118
+ } catch {
119
+ }
120
+ }
121
+ return out;
122
+ }
123
+ function servedObservations(obs) {
124
+ return obs.filter((o) => o.harness === "claude" && o.servedSession === true);
125
+ }
126
+ function liveObservations(obs, routers, alive = pidAlive) {
127
+ if (routers === null) return obs.filter((o) => alive(o.pid));
128
+ return obs.filter((o) => {
129
+ const router = routers.find((r) => r.pid === o.pid);
130
+ if (router === void 0) return false;
131
+ return router.startedAt === null || Math.abs(router.startedAt - o.startedAt) <= START_SLACK_MS;
132
+ });
133
+ }
134
+ function pidAlive(pid) {
135
+ if (!Number.isInteger(pid) || pid <= 0) return false;
136
+ try {
137
+ process.kill(pid, 0);
138
+ return true;
139
+ } catch (err) {
140
+ return hasCode(err, "EPERM");
141
+ }
142
+ }
143
+ async function readUnlockWallets(dataDir) {
144
+ try {
145
+ const parsed = UnlockStateSchema.safeParse(
146
+ JSON.parse(await readFile(unlockStatePath(dataDir), "utf8"))
147
+ );
148
+ return parsed.success ? parsed.data.wallets : null;
149
+ } catch {
150
+ return null;
151
+ }
152
+ }
153
+ async function readUnlockRecord(dataDir, address) {
154
+ const wallets = await readUnlockWallets(dataDir);
155
+ if (wallets === null) return null;
156
+ const parsed = UnlockRecordSchema.safeParse(wallets[address.toLowerCase()]);
157
+ return parsed.success ? parsed.data : null;
158
+ }
159
+ async function writeUnlockRecord(dataDir, rec) {
160
+ try {
161
+ const wallets = { ...await readUnlockWallets(dataDir) ?? {} };
162
+ wallets[rec.address.toLowerCase()] = rec;
163
+ await writeFileAtomic(
164
+ unlockStatePath(dataDir),
165
+ JSON.stringify({ version: 1, wallets }, null, 2) + "\n",
166
+ { mode: 384, dirMode: 448 }
167
+ );
168
+ } catch {
169
+ }
170
+ }
171
+ async function markUnlockPending(dataDir, address, now = Date.now()) {
172
+ await writeUnlockRecord(dataDir, {
173
+ version: 1,
174
+ address,
175
+ status: "awaiting_confirmation",
176
+ at: now
177
+ });
178
+ }
179
+
180
+ export {
181
+ writeObservation,
182
+ removeObservationSync,
183
+ pruneDeadObservations,
184
+ readObservations,
185
+ servedObservations,
186
+ liveObservations,
187
+ readUnlockRecord,
188
+ writeUnlockRecord,
189
+ markUnlockPending
190
+ };
191
+ //# sourceMappingURL=chunk-WYXUQGOL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/router/router-observation.ts"],"sourcesContent":["import { readFile, readdir, rm } from 'node:fs/promises';\nimport { rmSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { z } from 'zod';\nimport { writeFileAtomic } from '../lib/atomic-json';\nimport { hasCode } from '../lib/errno';\nimport type { SigningSource } from '../lib/wallet-unlock';\n\n/**\n * WHAT THE RUNNING `tenjin mcp` SAW, for the processes that cannot ask it.\n * Doctor runs in a shell, `alive` and the hooks run as their own processes,\n * and none of them can see the router Claude Code started: its environment,\n * its keychain answer, its verdict. So the router writes them down:\n *\n * <dataDir>/router/live/<pid>.json one per running `tenjin mcp`; removed on exit\n * <dataDir>/router/unlock-state.json the latest unlock verdict per address;\n * survives the process\n *\n * Both are 0600 in a 0700 directory, and neither ever holds a passphrase, a\n * key, an env VALUE or a store's stdout: only whether a variable is set, the\n * address, the cwd and verdicts.\n *\n * A HEALTH-CHECK ROUTER IS NOT A SESSION (B2). `claude mcp get` and `claude mcp\n * list` start a `tenjin mcp` that serves no hook. Its observation says\n * `servedSession: false` until it serves a hook call carrying a valid\n * session_id, and every reader that means \"the running Claude session\" keeps\n * only `servedSession: true` ({@link servedObservations}). Only a served\n * router reads or writes unlock-state.\n *\n * Hook-safe: node, zod and `lib/atomic-json` only. Every reader treats any\n * I/O error as \"absent\", and the writers swallow theirs: these files are\n * advisory, and a router must never fail a lookup because it could not\n * describe itself.\n */\n\nexport interface RouterObservation {\n version: 1;\n pid: number;\n startedAt: number;\n at: number;\n cliVersion: string;\n harness: 'claude' | 'codex';\n launchedByPlugin: boolean;\n cwd: string;\n address: string | null;\n /** B2: false until this router has served a hook call carrying a valid session_id. Readers that mean\n * \"the running Claude session\" ignore false. */\n servedSession: boolean;\n env: { passphraseSet: boolean; keySet: boolean };\n sign: {\n status: 'ready' | 'blocked' | 'unknown' | 'pending';\n reason?: string;\n detail?: string;\n fix?: string;\n source?: SigningSource;\n };\n routing?: { status: 'ready' | 'blocked' | 'unknown'; reason?: string; at: number };\n}\n\nexport interface UnlockInputs {\n envPassphraseSet: boolean;\n envKeySet: boolean;\n walletMtimeMs: number | null;\n sidecarMtimeMs: number | null;\n cliVersion: string;\n}\n\nexport interface UnlockRecord {\n version: 1;\n address: string;\n status: 'ready' | 'blocked' | 'unknown' | 'awaiting_confirmation';\n reason?: string;\n at: number;\n inputs?: UnlockInputs;\n}\n\nconst SIGNING_SOURCES = [\n 'key-env',\n 'passphrase-env',\n 'keychain',\n 'secret-service',\n 'dpapi',\n 'file',\n 'legacy',\n] as const;\n\nconst ObservationSchema = z.object({\n version: z.literal(1),\n pid: z.number().int().positive(),\n startedAt: z.number(),\n at: z.number(),\n cliVersion: z.string(),\n harness: z.enum(['claude', 'codex']),\n launchedByPlugin: z.boolean(),\n cwd: z.string(),\n address: z.string().nullable(),\n servedSession: z.boolean(),\n env: z.object({ passphraseSet: z.boolean(), keySet: z.boolean() }),\n sign: z.object({\n status: z.enum(['ready', 'blocked', 'unknown', 'pending']),\n reason: z.string().optional(),\n detail: z.string().optional(),\n fix: z.string().optional(),\n source: z.enum(SIGNING_SOURCES).optional(),\n }),\n routing: z\n .object({\n status: z.enum(['ready', 'blocked', 'unknown']),\n reason: z.string().optional(),\n at: z.number(),\n })\n .optional(),\n});\n\nconst UnlockRecordSchema = z.object({\n version: z.literal(1),\n address: z.string(),\n status: z.enum(['ready', 'blocked', 'unknown', 'awaiting_confirmation']),\n reason: z.string().optional(),\n at: z.number(),\n inputs: z\n .object({\n envPassphraseSet: z.boolean(),\n envKeySet: z.boolean(),\n walletMtimeMs: z.number().nullable(),\n sidecarMtimeMs: z.number().nullable(),\n cliVersion: z.string(),\n })\n .optional(),\n});\n\n/** The envelope; records are checked one at a time so one bad entry hides only itself. */\nconst UnlockStateSchema = z.object({\n version: z.literal(1),\n wallets: z.record(z.string(), z.unknown()),\n});\n\nconst OBSERVATION_NAME = /^(\\d+)\\.json$/;\n/** How far a ps start time may sit from the observation's before the pid is another process. */\nconst START_SLACK_MS = 2000;\n\n/** Where the running routers' observations live. */\nexport function liveDir(dataDir: string): string {\n return join(dataDir, 'router', 'live');\n}\n\nfunction observationPath(dataDir: string, pid: number): string {\n return join(liveDir(dataDir), `${pid}.json`);\n}\n\nfunction unlockStatePath(dataDir: string): string {\n return join(dataDir, 'router', 'unlock-state.json');\n}\n\n/** Write this router's observation. Swallows errors: it is advisory. */\nexport async function writeObservation(dataDir: string, obs: RouterObservation): Promise<void> {\n try {\n await writeFileAtomic(observationPath(dataDir, obs.pid), JSON.stringify(obs) + '\\n', {\n mode: 0o600,\n dirMode: 0o700,\n });\n } catch {\n // A router that cannot describe itself still routes.\n }\n}\n\n/** Remove a router's observation, synchronously, for the process 'exit' handler. */\nexport function removeObservationSync(dataDir: string, pid: number): void {\n try {\n rmSync(observationPath(dataDir, pid), { force: true });\n } catch {\n // Nothing to do at exit; pruneDeadObservations clears it later.\n }\n}\n\n/**\n * Unlink the observations whose pid is no longer alive: a router killed\n * without running its exit handler (SIGKILL, a crash) leaves its file behind.\n */\nexport async function pruneDeadObservations(\n dataDir: string,\n isAlive: (pid: number) => boolean = pidAlive,\n): Promise<void> {\n const dir = liveDir(dataDir);\n const names = await readdir(dir).catch(() => [] as string[]);\n for (const name of names) {\n const match = OBSERVATION_NAME.exec(name);\n if (match === null) continue;\n if (isAlive(Number(match[1]))) continue;\n await rm(join(dir, name), { force: true }).catch(() => undefined);\n }\n}\n\n/**\n * Every well-formed observation on disk, shape-checked, with no liveness\n * filter (see {@link liveObservations}). Dropped: a file not named\n * `<digits>.json`, one whose `pid` is not its name, any version but 1, a\n * malformed shape, and one without a boolean `servedSession` (B2: an\n * observation that cannot say whether it served a session is not one).\n */\nexport async function readObservations(dataDir: string): Promise<RouterObservation[]> {\n const dir = liveDir(dataDir);\n const names = await readdir(dir).catch(() => [] as string[]);\n const out: RouterObservation[] = [];\n for (const name of names.sort()) {\n const match = OBSERVATION_NAME.exec(name);\n if (match === null) continue;\n try {\n const parsed = ObservationSchema.safeParse(\n JSON.parse(await readFile(join(dir, name), 'utf8')),\n );\n if (parsed.success && parsed.data.pid === Number(match[1])) {\n out.push(parsed.data as RouterObservation);\n }\n } catch {\n // Unreadable or not JSON: absent.\n }\n }\n return out;\n}\n\n/** The observations that count as a running Claude session: harness 'claude' and servedSession true (B2). */\nexport function servedObservations(obs: RouterObservation[]): RouterObservation[] {\n return obs.filter((o) => o.harness === 'claude' && o.servedSession === true);\n}\n\n/**\n * Keep the observations whose router is still running.\n *\n * With a ps snapshot, the pid must be a listed router (the snapshot lists only\n * live, non-zombie routers) whose start time is within 2 s of the\n * observation's own: a pid the OS has since handed to another router is not\n * this one. A listed router whose start time ps could not give (null) is kept\n * on the pid alone. Without a snapshot (null: ps could not run), `alive`.\n */\nexport function liveObservations(\n obs: RouterObservation[],\n routers: Array<{ pid: number; startedAt: number | null }> | null,\n alive: (pid: number) => boolean = pidAlive,\n): RouterObservation[] {\n if (routers === null) return obs.filter((o) => alive(o.pid));\n return obs.filter((o) => {\n const router = routers.find((r) => r.pid === o.pid);\n if (router === undefined) return false;\n return router.startedAt === null || Math.abs(router.startedAt - o.startedAt) <= START_SLACK_MS;\n });\n}\n\n/**\n * Whether a process with this pid exists: `kill(pid, 0)` sends nothing and\n * only checks. EPERM means it exists under another user, so it counts as\n * alive; ESRCH (and anything else) as gone. Never true for a pid that is not\n * a positive integer, since `kill(0, …)` addresses the whole process group.\n */\nexport function pidAlive(pid: number): boolean {\n if (!Number.isInteger(pid) || pid <= 0) return false;\n try {\n process.kill(pid, 0);\n return true;\n } catch (err) {\n return hasCode(err, 'EPERM');\n }\n}\n\nasync function readUnlockWallets(dataDir: string): Promise<Record<string, unknown> | null> {\n try {\n const parsed = UnlockStateSchema.safeParse(\n JSON.parse(await readFile(unlockStatePath(dataDir), 'utf8')),\n );\n return parsed.success ? parsed.data.wallets : null;\n } catch {\n return null;\n }\n}\n\n/** The latest unlock record for `address` (any case), or null. */\nexport async function readUnlockRecord(\n dataDir: string,\n address: string,\n): Promise<UnlockRecord | null> {\n const wallets = await readUnlockWallets(dataDir);\n if (wallets === null) return null;\n const parsed = UnlockRecordSchema.safeParse(wallets[address.toLowerCase()]);\n return parsed.success ? (parsed.data as UnlockRecord) : null;\n}\n\n/**\n * Record `rec` under its lowercase address, keeping every other address's\n * record. Swallows errors: unlock-state is advisory, and a repair that saved\n * the passphrase must not fail because this file could not be written. Two\n * routers writing at once can lose one update; the next verdict rewrites it.\n */\nexport async function writeUnlockRecord(dataDir: string, rec: UnlockRecord): Promise<void> {\n try {\n const wallets = { ...((await readUnlockWallets(dataDir)) ?? {}) };\n wallets[rec.address.toLowerCase()] = rec;\n await writeFileAtomic(\n unlockStatePath(dataDir),\n JSON.stringify({ version: 1, wallets }, null, 2) + '\\n',\n { mode: 0o600, dirMode: 0o700 },\n );\n } catch {\n // Advisory: see above.\n }\n}\n\n/**\n * After `tenjin wallet repair`: the next served router's verdict for this\n * address decides whether \"Tenjin wallet unlocked.\" is said (decision 14).\n */\nexport async function markUnlockPending(\n dataDir: string,\n address: string,\n now: number = Date.now(),\n): Promise<void> {\n await writeUnlockRecord(dataDir, {\n version: 1,\n address,\n status: 'awaiting_confirmation',\n at: now,\n });\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,UAAU,SAAS,UAAU;AACtC,SAAS,cAAc;AACvB,SAAS,YAAY;AA0ErB,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,oBAAoB,iBAAE,OAAO;AAAA,EACjC,SAAS,iBAAE,QAAQ,CAAC;AAAA,EACpB,KAAK,iBAAE,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,EAC/B,WAAW,iBAAE,OAAO;AAAA,EACpB,IAAI,iBAAE,OAAO;AAAA,EACb,YAAY,iBAAE,OAAO;AAAA,EACrB,SAAS,iBAAE,KAAK,CAAC,UAAU,OAAO,CAAC;AAAA,EACnC,kBAAkB,iBAAE,QAAQ;AAAA,EAC5B,KAAK,iBAAE,OAAO;AAAA,EACd,SAAS,iBAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,eAAe,iBAAE,QAAQ;AAAA,EACzB,KAAK,iBAAE,OAAO,EAAE,eAA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AQ;AACN,WAAO;AAAA,EACT;AACF;AAGA,eAAsB,iBACpB,SACA,SAC8B;AAC9B,QAAM,UAAU,MAAM,kBAAkB,OAAO;AAC/C,MAAI,YAAY,KAAM,QAAO;AAC7B,QAAM,SAAS,mBAAmB,UAAU,QAAQ,QAAQ,YAAY,CAAC,CAAC;AAC1E,SAAO,OAAO,UAAW,OAAO,OAAwB;AAC1D;AAQA,eAAsB,kBAAkB,SAAiB,KAAkC;AACzF,MAAI;AACF,UAAM,UAAU,EAAE,GAAK,MAAM,kBAAkB,OAAO,KAAM,CAAC,EAAG;AAChE,YAAQ,IAAI,QAAQ,YAAY,CAAC,IAAI;AACrC,UAAM;AAAA,MACJ,gBAAgB,OAAO;AAAA,MACvB,KAAK,UAAU,EAAE,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC,IAAI;AAAA,MACnD,EAAE,MAAM,KAAO,SAAS,IAAM;AAAA,IAChC;AAAA,EACF,QAAQ;AAAA,EAER;AACF;AAMA,eAAsB,kBACpB,SACA,SACA,MAAc,KAAK,IAAI,GACR;AACf,QAAM,kBAAkB,SAAS;AAAA,IAC/B,SAAS;AAAA,IACT;AAAA,IACA,QAAQ;AAAA,IACR,IAAI;AAAA,EACN,CAAC;AACH;","names":[]}
@@ -0,0 +1,97 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ CliError
4
+ } from "./chunk-3UCIG4TG.js";
5
+
6
+ // src/lib/wallet-unlock.ts
7
+ var UNLOCK_REASONS = /* @__PURE__ */ new Set([
8
+ "no_wallet",
9
+ "wallet_corrupt",
10
+ "env_key_invalid",
11
+ "passphrase_missing",
12
+ "passphrase_wrong",
13
+ "env_passphrase_wrong",
14
+ "keychain_locked",
15
+ "unlock_timeout"
16
+ ]);
17
+ var PASSPHRASE_LABELS = /* @__PURE__ */ new Set([
18
+ "env",
19
+ "keychain",
20
+ "secret-service",
21
+ "dpapi",
22
+ "file",
23
+ "legacy",
24
+ "prompt"
25
+ ]);
26
+ var DEFINITE_UNLOCK = /* @__PURE__ */ new Set([
27
+ "no_wallet",
28
+ "wallet_corrupt",
29
+ "env_key_invalid",
30
+ "passphrase_missing",
31
+ "passphrase_wrong",
32
+ "env_passphrase_wrong"
33
+ ]);
34
+ var ENV_PASSPHRASE_WRONG = "TENJIN_WALLET_PASSPHRASE is set but wrong; remove it.";
35
+ var REPAIR_CLAUSE = "(it asks for the passphrase in your terminal; never paste it into chat)";
36
+ var REPAIR_IN_TERMINAL = `Run \`tenjin wallet repair\` yourself ${REPAIR_CLAUSE}.`;
37
+ var KEYCHAIN_LOCKED_FIX = "Unlock your keychain (or log in to the desktop session) and retry.";
38
+ function FILE_STORE_FAILED_FIX(path) {
39
+ const dir = path.replace(/[/\\][^/\\]*$/, "") || "/";
40
+ return `Tenjin could not save the passphrase to ${path}; check that ${dir} is writable.`;
41
+ }
42
+ var KEYCHAIN_WAIT_LINE = "Waiting for the keychain\u2026";
43
+ function NO_KEYRING_LINE(path) {
44
+ return `No keyring reachable from this session; passphrase saved to ${path} (readable only by you).`;
45
+ }
46
+ var PRIVATE_KEY_RE = /^0x[0-9a-f]{64}$/i;
47
+ function unlockDetails(reason, source) {
48
+ return { unlock: source === void 0 ? { reason } : { reason, source } };
49
+ }
50
+ function isUnlockDetails(value) {
51
+ if (typeof value !== "object" || value === null) return false;
52
+ const { reason, source } = value;
53
+ if (typeof reason !== "string" || !UNLOCK_REASONS.has(reason)) return false;
54
+ return source === void 0 || typeof source === "string" && PASSPHRASE_LABELS.has(source);
55
+ }
56
+ function detailsOf(err) {
57
+ if (!(err instanceof CliError)) return void 0;
58
+ const unlock = err.details?.unlock;
59
+ return isUnlockDetails(unlock) ? unlock : void 0;
60
+ }
61
+ function classifyUnlockError(err) {
62
+ const unlock = detailsOf(err);
63
+ if (unlock !== void 0) {
64
+ return {
65
+ reason: unlock.reason,
66
+ definite: DEFINITE_UNLOCK.has(unlock.reason),
67
+ ...unlock.source !== void 0 ? { source: unlock.source } : {}
68
+ };
69
+ }
70
+ if (err instanceof CliError && err.code === "WALLET_MISSING") {
71
+ return { reason: "no_wallet", definite: true };
72
+ }
73
+ const name = err?.name;
74
+ if (name === "AbortError" || name === "TimeoutError") {
75
+ return { reason: "unlock_timeout", definite: false };
76
+ }
77
+ return { reason: "wallet_locked", definite: false };
78
+ }
79
+ function unlockReasonOf(err) {
80
+ return detailsOf(err)?.reason ?? null;
81
+ }
82
+
83
+ export {
84
+ DEFINITE_UNLOCK,
85
+ ENV_PASSPHRASE_WRONG,
86
+ REPAIR_CLAUSE,
87
+ REPAIR_IN_TERMINAL,
88
+ KEYCHAIN_LOCKED_FIX,
89
+ FILE_STORE_FAILED_FIX,
90
+ KEYCHAIN_WAIT_LINE,
91
+ NO_KEYRING_LINE,
92
+ PRIVATE_KEY_RE,
93
+ unlockDetails,
94
+ classifyUnlockError,
95
+ unlockReasonOf
96
+ };
97
+ //# sourceMappingURL=chunk-X5ZBP3IY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/wallet-unlock.ts"],"sourcesContent":["import { CliError } from './errors';\n\n/**\n * WHY A WALLET COULD NOT SIGN, AS ONE VOCABULARY. The wallet layer throws with\n * it, the routing payer skips with it, the hooks gate and word notices with it,\n * and doctor renders it, so every surface names the same cause the same way.\n *\n * HOOK-SAFE ON PURPOSE: it imports `./errors` and nothing else. `tenjin hook`,\n * `alive` and the status line read these reasons, and their chunk graph must\n * stay free of `src/lib/wallet/`, viem, ox and the x402 SDK\n * (`src/router/dist-chunks.test.ts`). That is why the reasons live here and not\n * beside the wallet code that produces them.\n *\n * Six reasons are DEFINITE (this wallet cannot sign until a person fixes\n * something) and two are not (`keychain_locked`, `unlock_timeout`: the store or\n * the clock did not answer, which says nothing about the wallet). Only a\n * definite reason may withhold an offer or skip a routing attempt.\n */\nexport type UnlockReason =\n | 'no_wallet'\n | 'wallet_corrupt'\n | 'env_key_invalid'\n | 'passphrase_missing'\n | 'passphrase_wrong'\n | 'env_passphrase_wrong'\n | 'keychain_locked'\n | 'unlock_timeout';\n\nconst UNLOCK_REASONS: ReadonlySet<string> = new Set<UnlockReason>([\n 'no_wallet',\n 'wallet_corrupt',\n 'env_key_invalid',\n 'passphrase_missing',\n 'passphrase_wrong',\n 'env_passphrase_wrong',\n 'keychain_locked',\n 'unlock_timeout',\n]);\n\n/** A store that keeps a wallet's passphrase across sessions: the platform's own\n * credential store, or the 0600 file where there is none. */\nexport type DurableStore = 'keychain' | 'secret-service' | 'dpapi' | 'file';\n\n/** Where a passphrase came from, for messages; 'legacy' = the pre-per-wallet shared slot. */\nexport type PassphraseLabel = 'env' | DurableStore | 'legacy' | 'prompt';\n\nconst PASSPHRASE_LABELS: ReadonlySet<string> = new Set<PassphraseLabel>([\n 'env',\n 'keychain',\n 'secret-service',\n 'dpapi',\n 'file',\n 'legacy',\n 'prompt',\n]);\n\n/**\n * What actually produced a signature, as doctor, install and the router report\n * it. Defined here rather than in `src/router/eligibility.ts` (which re-exports\n * it) because `src/lib/wallet/provider.ts` needs it too, and lib must not\n * import router.\n */\nexport type SigningSource = 'key-env' | 'passphrase-env' | DurableStore | 'legacy';\n\n/** The cause a wallet throw site attaches as `CliError.details.unlock`. */\nexport interface UnlockDetails {\n reason: UnlockReason;\n source?: PassphraseLabel;\n}\n\n/** Every reason except the two that say the store or the clock did not answer. */\nexport const DEFINITE_UNLOCK: ReadonlySet<UnlockReason> = new Set<UnlockReason>([\n 'no_wallet',\n 'wallet_corrupt',\n 'env_key_invalid',\n 'passphrase_missing',\n 'passphrase_wrong',\n 'env_passphrase_wrong',\n]);\n\n/** Said once when TENJIN_WALLET_PASSPHRASE did not open the wallet and a saved\n * passphrase did: the wallet works, the variable is the thing to remove. */\nexport const ENV_PASSPHRASE_WRONG = 'TENJIN_WALLET_PASSPHRASE is set but wrong; remove it.';\n\n/**\n * Carried by every person-facing string that names `tenjin wallet repair` (B1,\n * decision 15). A passphrase never goes on a command line or into chat: repair\n * asks for it at a hidden prompt, and this clause tells the person so before an\n * agent can suggest otherwise.\n */\nexport const REPAIR_CLAUSE =\n '(it asks for the passphrase in your terminal; never paste it into chat)';\n\n/** The person's fix for a wallet whose saved passphrase is gone or wrong. */\nexport const REPAIR_IN_TERMINAL =\n `Run \\`tenjin wallet repair\\` yourself ${REPAIR_CLAUSE}.` as const;\n\n/**\n * The only fix for a keychain that exists but did not answer (S3). It never\n * points at the plaintext file or at another passphrase: a locked keychain is\n * unlocked, not routed around.\n */\nexport const KEYCHAIN_LOCKED_FIX =\n 'Unlock your keychain (or log in to the desktop session) and retry.';\n\n/**\n * A failed FILE-store write at create or repair (decision 6). Never used for an\n * OS store: there is no keychain to unlock when the file could not be written.\n */\nexport function FILE_STORE_FAILED_FIX(path: string): string {\n // The file's own folder (`TENJIN_DATA_DIR` moves it), cut by hand: this module imports nothing.\n const dir = path.replace(/[/\\\\][^/\\\\]*$/, '') || '/';\n return `Tenjin could not save the passphrase to ${path}; check that ${dir} is writable.`;\n}\n\n/** Shown once when create or repair has waited on the keychain for a second at a terminal. */\nexport const KEYCHAIN_WAIT_LINE = 'Waiting for the keychain…';\n\n/** Why a passphrase went to the 0600 file: no OS store answered the probe as present (S4). */\nexport function NO_KEYRING_LINE(path: string): string {\n return `No keyring reachable from this session; passphrase saved to ${path} (readable only by you).`;\n}\n\n/**\n * THE one TENJIN_WALLET_KEY expression (S12): a 0x-prefixed 32-byte hex private\n * key, case-insensitive. Moved here from `src/lib/wallet/store.ts` unchanged, and\n * store.ts re-exports it, so the wallet layer's `loadCredential` and the\n * hook-safe `wallet-facts.ts` test exactly the same thing. Do not tighten it in\n * one place only: a key one accepts and the other rejects is a wallet doctor\n * calls fine and the hooks call broken.\n */\nexport const PRIVATE_KEY_RE = /^0x[0-9a-f]{64}$/i;\n\n/** `{ unlock: { reason, source } }`, the value every wallet throw site passes as CliError `details`. */\nexport function unlockDetails(\n reason: UnlockReason,\n source?: PassphraseLabel,\n): { unlock: UnlockDetails } {\n return { unlock: source === undefined ? { reason } : { reason, source } };\n}\n\n/** Whether `value` is a well-formed `details.unlock`: a known reason, and a known source if any. */\nfunction isUnlockDetails(value: unknown): value is UnlockDetails {\n if (typeof value !== 'object' || value === null) return false;\n const { reason, source } = value as { reason?: unknown; source?: unknown };\n if (typeof reason !== 'string' || !UNLOCK_REASONS.has(reason)) return false;\n return source === undefined || (typeof source === 'string' && PASSPHRASE_LABELS.has(source));\n}\n\n/** `details.unlock` of a CliError that carries a valid one, else undefined. */\nfunction detailsOf(err: unknown): UnlockDetails | undefined {\n if (!(err instanceof CliError)) return undefined;\n const unlock = (err.details as { unlock?: unknown } | null | undefined)?.unlock;\n return isUnlockDetails(unlock) ? unlock : undefined;\n}\n\n/**\n * WHAT AN UNLOCK FAILURE MEANS, for gating and wording. In order:\n * `details.unlock` when the thrower classified it; `WALLET_MISSING` is\n * `no_wallet`; an AbortError or TimeoutError is `unlock_timeout`. ANY other\n * error, an undetailed CliError included, is `wallet_locked`, which is never\n * definite: nobody said why, so nothing may be withheld on its account.\n *\n * It never matches on message text. A message is wording, free to change; a\n * reason that hung on it would turn a copy edit into a gating change.\n */\nexport function classifyUnlockError(err: unknown): {\n reason: UnlockReason | 'wallet_locked';\n definite: boolean;\n source?: PassphraseLabel;\n} {\n const unlock = detailsOf(err);\n if (unlock !== undefined) {\n return {\n reason: unlock.reason,\n definite: DEFINITE_UNLOCK.has(unlock.reason),\n ...(unlock.source !== undefined ? { source: unlock.source } : {}),\n };\n }\n if (err instanceof CliError && err.code === 'WALLET_MISSING') {\n return { reason: 'no_wallet', definite: true };\n }\n const name = (err as { name?: unknown } | null | undefined)?.name;\n // By name, not class: a DOMException from AbortSignal.timeout and a\n // hand-made Error named AbortError mean the same thing here.\n if (name === 'AbortError' || name === 'TimeoutError') {\n return { reason: 'unlock_timeout', definite: false };\n }\n return { reason: 'wallet_locked', definite: false };\n}\n\n/**\n * `details.unlock.reason` when `err` is a CliError carrying a valid\n * `details.unlock`; null for anything else (an undetailed WALLET_MISSING, an\n * AbortError, any other CliError or value).\n *\n * THE ONLY GATE for swapping a fix to its model-facing `agentFix` (B1). Not\n * {@link classifyUnlockError}: its `wallet_locked` fallback covers EVERY\n * undetailed error, a `REGISTRY_MISMATCH` or an HTTP failure included, and\n * swapping on it would replace those errors' own fixes with wallet advice.\n */\nexport function unlockReasonOf(err: unknown): UnlockReason | null {\n return detailsOf(err)?.reason ?? null;\n}\n"],"mappings":";;;;;;AA4BA,IAAM,iBAAsC,oBAAI,IAAkB;AAAA,EAChE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AASD,IAAM,oBAAyC,oBAAI,IAAqB;AAAA,EACtE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAiBM,IAAM,kBAA6C,oBAAI,IAAkB;AAAA,EAC9E;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAIM,IAAM,uBAAuB;AAQ7B,IAAM,gBACX;AAGK,IAAM,qBACX,yCAAyC,aAAa;AAOjD,IAAM,sBACX;AAMK,SAAS,sBAAsB,MAAsB;AAE1D,QAAM,MAAM,KAAK,QAAQ,iBAAiB,EAAE,KAAK;AACjD,SAAO,2CAA2C,IAAI,gBAAgB,GAAG;AAC3E;AAGO,IAAM,qBAAqB;AAG3B,SAAS,gBAAgB,MAAsB;AACpD,SAAO,+DAA+D,IAAI;AAC5E;AAUO,IAAM,iBAAiB;AAGvB,SAAS,cACd,QACA,QAC2B;AAC3B,SAAO,EAAE,QAAQ,WAAW,SAAY,EAAE,OAAO,IAAI,EAAE,QAAQ,OAAO,EAAE;AAC1E;AAGA,SAAS,gBAAgB,OAAwC;AAC/D,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AACxD,QAAM,EAAE,QAAQ,OAAO,IAAI;AAC3B,MAAI,OAAO,WAAW,Y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