tenjin-cli 0.1.0-alpha.15 → 0.1.0-alpha.17

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 (278) hide show
  1. package/NOTICE.md +54 -7
  2. package/README.md +43 -310
  3. package/dist/{_esm-N4KAVXQR.js → _esm-CE7KNONL.js} +9 -10
  4. package/dist/{ccip-ZGGWQN4X.js → ccip-7RMRLAGV.js} +4 -4
  5. package/dist/{ccip-RPPPKTJR.js → ccip-NLCSCHKI.js} +5 -5
  6. package/dist/chunk-2BKS2FVE.js +93 -0
  7. package/dist/chunk-2BKS2FVE.js.map +1 -0
  8. package/dist/chunk-2G2WLVHB.js +102 -0
  9. package/dist/chunk-2G2WLVHB.js.map +1 -0
  10. package/dist/chunk-2I4QTOLB.js +11 -0
  11. package/dist/chunk-2I4QTOLB.js.map +1 -0
  12. package/dist/chunk-2JGT3KDW.js +172 -0
  13. package/dist/chunk-2JGT3KDW.js.map +1 -0
  14. package/dist/chunk-2QYORQBF.js +55 -0
  15. package/dist/chunk-2QYORQBF.js.map +1 -0
  16. package/dist/chunk-35M3VITA.js +102 -0
  17. package/dist/chunk-35M3VITA.js.map +1 -0
  18. package/dist/{chunk-KINZ23CV.js → chunk-3AUDA53C.js} +4740 -23
  19. package/dist/chunk-3AUDA53C.js.map +1 -0
  20. package/dist/{chunk-MJZZTKCC.js → chunk-56MOAIP5.js} +5 -10
  21. package/dist/chunk-56MOAIP5.js.map +1 -0
  22. package/dist/{chunk-U5S527PP.js → chunk-5IEP5EGE.js} +3 -3
  23. package/dist/chunk-5QHHRMRA.js +227 -0
  24. package/dist/chunk-5QHHRMRA.js.map +1 -0
  25. package/dist/{chunk-JBIKAAT3.js → chunk-5UDD5VSY.js} +8 -8
  26. package/dist/chunk-5UDD5VSY.js.map +1 -0
  27. package/dist/chunk-7QKHZQKW.js +1680 -0
  28. package/dist/chunk-7QKHZQKW.js.map +1 -0
  29. package/dist/{chunk-ZFJJ3EXC.js → chunk-AR7U7BRG.js} +550 -182
  30. package/dist/chunk-AR7U7BRG.js.map +1 -0
  31. package/dist/chunk-AUKDYPPX.js +130 -0
  32. package/dist/chunk-AUKDYPPX.js.map +1 -0
  33. package/dist/{chunk-7FK2UN2T.js → chunk-AWQPGIR6.js} +65 -67
  34. package/dist/{chunk-7FK2UN2T.js.map → chunk-AWQPGIR6.js.map} +1 -1
  35. package/dist/{chunk-KYQVEKP5.js → chunk-BPMWXTFX.js} +8 -8
  36. package/dist/{chunk-47PP7TAG.js → chunk-EGELTSPU.js} +1356 -1356
  37. package/dist/chunk-EGELTSPU.js.map +1 -0
  38. package/dist/{chunk-S5RYMCV6.js → chunk-HPWO4O6S.js} +3 -3
  39. package/dist/chunk-J5INH7WB.js +299 -0
  40. package/dist/chunk-J5INH7WB.js.map +1 -0
  41. package/dist/chunk-JLEF5WHM.js +132 -0
  42. package/dist/chunk-JLEF5WHM.js.map +1 -0
  43. package/dist/{chunk-W6R3HAAG.js → chunk-JRGFKVAZ.js} +2 -2
  44. package/dist/{chunk-XJN5WUKL.js → chunk-KG3D7FIF.js} +2 -2
  45. package/dist/chunk-KK4YGYTV.js +808 -0
  46. package/dist/chunk-KK4YGYTV.js.map +1 -0
  47. package/dist/{chunk-CPCX67TI.js → chunk-KUBEYXSO.js} +1076 -1038
  48. package/dist/chunk-KUBEYXSO.js.map +1 -0
  49. package/dist/{chunk-QW2Q2KAH.js → chunk-LHHMV4GU.js} +2 -2
  50. package/dist/{chunk-NIKXHWOL.js → chunk-LJ4DMVFI.js} +16 -16
  51. package/dist/chunk-LJ4DMVFI.js.map +1 -0
  52. package/dist/{chunk-ZOBNS7CX.js → chunk-MEFB5KHA.js} +4 -18
  53. package/dist/chunk-MEFB5KHA.js.map +1 -0
  54. package/dist/{chunk-HPJGOLTN.js → chunk-MRGADYDD.js} +13 -8
  55. package/dist/chunk-MRGADYDD.js.map +1 -0
  56. package/dist/{chunk-M2O56UK7.js → chunk-N35E6CM2.js} +293 -163
  57. package/dist/chunk-N35E6CM2.js.map +1 -0
  58. package/dist/chunk-O4ZNKFRU.js +366 -0
  59. package/dist/chunk-O4ZNKFRU.js.map +1 -0
  60. package/dist/chunk-PDA2BVFY.js +244 -0
  61. package/dist/chunk-PDA2BVFY.js.map +1 -0
  62. package/dist/{chunk-POJRB2AE.js → chunk-POUWHWID.js} +2 -2
  63. package/dist/chunk-QDD2RN7G.js +10238 -0
  64. package/dist/chunk-QDD2RN7G.js.map +1 -0
  65. package/dist/chunk-S2NRVRPF.js +171 -0
  66. package/dist/chunk-S2NRVRPF.js.map +1 -0
  67. package/dist/chunk-TGLKKLQG.js +11 -0
  68. package/dist/chunk-TGLKKLQG.js.map +1 -0
  69. package/dist/chunk-TP4D47BY.js +127 -0
  70. package/dist/chunk-TP4D47BY.js.map +1 -0
  71. package/dist/{chunk-KZAAWQNP.js → chunk-TTNESUPQ.js} +3 -3
  72. package/dist/{chunk-UO22YNY4.js → chunk-U2DZISAH.js} +43 -1
  73. package/dist/chunk-U2DZISAH.js.map +1 -0
  74. package/dist/chunk-WGQVJM56.js +165 -0
  75. package/dist/chunk-WGQVJM56.js.map +1 -0
  76. package/dist/{chunk-OLWTRUTS.js → chunk-WLMJE3GJ.js} +35 -16
  77. package/dist/chunk-WLMJE3GJ.js.map +1 -0
  78. package/dist/chunk-WS4JA6TC.js +137 -0
  79. package/dist/chunk-WS4JA6TC.js.map +1 -0
  80. package/dist/chunk-WXC57XGG.js +29 -0
  81. package/dist/chunk-WXC57XGG.js.map +1 -0
  82. package/dist/{chunk-YLYINX2H.js → chunk-XZKD7DIF.js} +3 -3
  83. package/dist/chunk-XZOEUYMX.js +1784 -0
  84. package/dist/chunk-XZOEUYMX.js.map +1 -0
  85. package/dist/{cli-KKRKBU5T.js → cli-VHYYYYXM.js} +303 -374
  86. package/dist/cli-VHYYYYXM.js.map +1 -0
  87. package/dist/config-5ADBAAXU.js +42 -0
  88. package/dist/{dist-U4M6QCKE.js → dist-3LOO6M4U.js} +10 -10
  89. package/dist/doctor-Q35VQW3S.js +436 -0
  90. package/dist/doctor-Q35VQW3S.js.map +1 -0
  91. package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
  92. package/dist/{chunk-KAJZHIQ4.js → fund-GDDPL2BB.js} +81 -24
  93. package/dist/fund-GDDPL2BB.js.map +1 -0
  94. package/dist/hook-command-PBERPRE3.js +763 -0
  95. package/dist/hook-command-PBERPRE3.js.map +1 -0
  96. package/dist/index.js +8 -3
  97. package/dist/index.js.map +1 -1
  98. package/dist/install-OKDKGUXM.js +60 -0
  99. package/dist/install-wallet-SI4LZ73K.js +106 -0
  100. package/dist/install-wallet-SI4LZ73K.js.map +1 -0
  101. package/dist/{run-XYTQ5TWQ.js → mcp-XX3WRQEZ.js} +3766 -10677
  102. package/dist/mcp-XX3WRQEZ.js.map +1 -0
  103. package/dist/paths-P2N4JTDZ.js +49 -0
  104. package/dist/pay-3SYKHKWJ.js +39 -0
  105. package/dist/redact-6W23GGJC.js +15 -0
  106. package/dist/{secp256k1-XRPVBC6V.js → secp256k1-ZZZT2CAX.js} +3 -3
  107. package/dist/{send-G746D7PQ.js → send-LQRKTEJT.js} +29 -29
  108. package/dist/send-LQRKTEJT.js.map +1 -0
  109. package/dist/{chunk-QZ6ROAJU.js → skill-placement-JMDPSKE6.js} +155 -10
  110. package/dist/skill-placement-JMDPSKE6.js.map +1 -0
  111. package/dist/status-FFC6FO72.js +64 -0
  112. package/dist/status-FFC6FO72.js.map +1 -0
  113. package/dist/status-line-SAXSU6CR.js +87 -0
  114. package/dist/status-line-SAXSU6CR.js.map +1 -0
  115. package/dist/status-line-wiring-L2WYIYBM.js +29 -0
  116. package/dist/tenjin-daemon.mjs +20421 -0
  117. package/dist/tenjin-shim.mjs +251 -0
  118. package/dist/tenjin-vitest-reporter.mjs +49 -0
  119. package/dist/uninstall-OACH27UV.js +147 -0
  120. package/dist/uninstall-OACH27UV.js.map +1 -0
  121. package/dist/{update-R76LHOZW.js → update-4W6EKLGZ.js} +132 -16
  122. package/dist/update-4W6EKLGZ.js.map +1 -0
  123. package/dist/{viemAdapter-By13KInL-TUQJBMHM.js → viemAdapter-By13KInL-X2VY6CY3.js} +5 -5
  124. package/dist/wallet-BMEXRR3P.js +32 -0
  125. package/dist/wallet-kdf-worker.mjs +980 -0
  126. package/docs/agent-permissions.md +71 -352
  127. package/docs/safety-model.md +16 -6
  128. package/package.json +8 -7
  129. package/LICENSE +0 -21
  130. package/dist/buy-VIRNSYGN.js +0 -47
  131. package/dist/chunk-2MYQN7HM.js +0 -247
  132. package/dist/chunk-2MYQN7HM.js.map +0 -1
  133. package/dist/chunk-2RF2GIJQ.js +0 -1188
  134. package/dist/chunk-2RF2GIJQ.js.map +0 -1
  135. package/dist/chunk-3GL2Z5QK.js +0 -57
  136. package/dist/chunk-3GL2Z5QK.js.map +0 -1
  137. package/dist/chunk-47PP7TAG.js.map +0 -1
  138. package/dist/chunk-4CQIDQOT.js +0 -167
  139. package/dist/chunk-4CQIDQOT.js.map +0 -1
  140. package/dist/chunk-4KG27W2S.js +0 -614
  141. package/dist/chunk-4KG27W2S.js.map +0 -1
  142. package/dist/chunk-5QQTYWEU.js +0 -199
  143. package/dist/chunk-5QQTYWEU.js.map +0 -1
  144. package/dist/chunk-65DTCCJ7.js +0 -21
  145. package/dist/chunk-65DTCCJ7.js.map +0 -1
  146. package/dist/chunk-A5DKHMUN.js +0 -173
  147. package/dist/chunk-A5DKHMUN.js.map +0 -1
  148. package/dist/chunk-B63XPWQ4.js +0 -246
  149. package/dist/chunk-B63XPWQ4.js.map +0 -1
  150. package/dist/chunk-CAR6FHK6.js +0 -105
  151. package/dist/chunk-CAR6FHK6.js.map +0 -1
  152. package/dist/chunk-CPCX67TI.js.map +0 -1
  153. package/dist/chunk-CQBVCYI2.js +0 -162
  154. package/dist/chunk-CQBVCYI2.js.map +0 -1
  155. package/dist/chunk-DBU5CXBV.js +0 -4731
  156. package/dist/chunk-DBU5CXBV.js.map +0 -1
  157. package/dist/chunk-DHJD77OW.js +0 -81
  158. package/dist/chunk-DHJD77OW.js.map +0 -1
  159. package/dist/chunk-EDZSNPE5.js +0 -35
  160. package/dist/chunk-EDZSNPE5.js.map +0 -1
  161. package/dist/chunk-EFWZPUTC.js +0 -65
  162. package/dist/chunk-EFWZPUTC.js.map +0 -1
  163. package/dist/chunk-EPFL6CTE.js +0 -448
  164. package/dist/chunk-EPFL6CTE.js.map +0 -1
  165. package/dist/chunk-GHLVXVZD.js +0 -142
  166. package/dist/chunk-GHLVXVZD.js.map +0 -1
  167. package/dist/chunk-H3SOOJ2I.js +0 -580
  168. package/dist/chunk-H3SOOJ2I.js.map +0 -1
  169. package/dist/chunk-HPJGOLTN.js.map +0 -1
  170. package/dist/chunk-HRGBS2PA.js +0 -203
  171. package/dist/chunk-HRGBS2PA.js.map +0 -1
  172. package/dist/chunk-ITUXPJIS.js +0 -314
  173. package/dist/chunk-ITUXPJIS.js.map +0 -1
  174. package/dist/chunk-JBIKAAT3.js.map +0 -1
  175. package/dist/chunk-KAJZHIQ4.js.map +0 -1
  176. package/dist/chunk-KINZ23CV.js.map +0 -1
  177. package/dist/chunk-LRYV3SK7.js +0 -235
  178. package/dist/chunk-LRYV3SK7.js.map +0 -1
  179. package/dist/chunk-M2O56UK7.js.map +0 -1
  180. package/dist/chunk-MJZZTKCC.js.map +0 -1
  181. package/dist/chunk-NIKXHWOL.js.map +0 -1
  182. package/dist/chunk-OKDRDT74.js +0 -209
  183. package/dist/chunk-OKDRDT74.js.map +0 -1
  184. package/dist/chunk-OKYSNAS3.js +0 -2144
  185. package/dist/chunk-OKYSNAS3.js.map +0 -1
  186. package/dist/chunk-OLWTRUTS.js.map +0 -1
  187. package/dist/chunk-QQ6ELLSA.js +0 -143
  188. package/dist/chunk-QQ6ELLSA.js.map +0 -1
  189. package/dist/chunk-QZ6ROAJU.js.map +0 -1
  190. package/dist/chunk-R7RSCBI7.js +0 -794
  191. package/dist/chunk-R7RSCBI7.js.map +0 -1
  192. package/dist/chunk-SGK2B724.js +0 -67
  193. package/dist/chunk-SGK2B724.js.map +0 -1
  194. package/dist/chunk-U6VPKMGC.js +0 -390
  195. package/dist/chunk-U6VPKMGC.js.map +0 -1
  196. package/dist/chunk-UHTVXQ2O.js +0 -140
  197. package/dist/chunk-UHTVXQ2O.js.map +0 -1
  198. package/dist/chunk-UO22YNY4.js.map +0 -1
  199. package/dist/chunk-US456VUI.js +0 -149
  200. package/dist/chunk-US456VUI.js.map +0 -1
  201. package/dist/chunk-V44J2MXV.js +0 -400
  202. package/dist/chunk-V44J2MXV.js.map +0 -1
  203. package/dist/chunk-VJQKL3YH.js +0 -216
  204. package/dist/chunk-VJQKL3YH.js.map +0 -1
  205. package/dist/chunk-VJSQSLBM.js +0 -1442
  206. package/dist/chunk-VJSQSLBM.js.map +0 -1
  207. package/dist/chunk-VYOJOX4Z.js +0 -165
  208. package/dist/chunk-VYOJOX4Z.js.map +0 -1
  209. package/dist/chunk-WY2K35OL.js +0 -269
  210. package/dist/chunk-WY2K35OL.js.map +0 -1
  211. package/dist/chunk-ZFJJ3EXC.js.map +0 -1
  212. package/dist/chunk-ZOBNS7CX.js.map +0 -1
  213. package/dist/cli-KKRKBU5T.js.map +0 -1
  214. package/dist/config-JMRUNYE6.js +0 -37
  215. package/dist/discover-B5HF6SHM.js +0 -102
  216. package/dist/discover-B5HF6SHM.js.map +0 -1
  217. package/dist/doctor-ZBG7X66D.js +0 -32
  218. package/dist/edit-PZJIILQE.js +0 -40
  219. package/dist/fund-EUDH5KPA.js +0 -40
  220. package/dist/inspect-QC6WEQPN.js +0 -37
  221. package/dist/install-GNK2W3PI.js +0 -972
  222. package/dist/install-GNK2W3PI.js.map +0 -1
  223. package/dist/outcome-KSGWZHUS.js +0 -24
  224. package/dist/pay-BC4UICPA.js +0 -361
  225. package/dist/pay-BC4UICPA.js.map +0 -1
  226. package/dist/publish-LXWFDIKF.js +0 -42
  227. package/dist/read-JMNUQ56P.js +0 -160
  228. package/dist/read-JMNUQ56P.js.map +0 -1
  229. package/dist/run-XYTQ5TWQ.js.map +0 -1
  230. package/dist/search-TSQAB45E.js +0 -25
  231. package/dist/secp256k1-XRPVBC6V.js.map +0 -1
  232. package/dist/send-G746D7PQ.js.map +0 -1
  233. package/dist/session-JBKWMJ24.js +0 -89
  234. package/dist/session-JBKWMJ24.js.map +0 -1
  235. package/dist/skill-heal-WKD67SLJ.js +0 -92
  236. package/dist/skill-heal-WKD67SLJ.js.map +0 -1
  237. package/dist/skill-placement-RIU4AMC2.js +0 -20
  238. package/dist/skill-placement-RIU4AMC2.js.map +0 -1
  239. package/dist/uninstall-5E263VTS.js +0 -73
  240. package/dist/uninstall-5E263VTS.js.map +0 -1
  241. package/dist/update-R76LHOZW.js.map +0 -1
  242. package/dist/usdc-4VCDHFWX.js +0 -38
  243. package/dist/usdc-4VCDHFWX.js.map +0 -1
  244. package/dist/viemAdapter-By13KInL-TUQJBMHM.js.map +0 -1
  245. package/dist/wallet-TQ7D5EQ7.js +0 -41
  246. package/dist/wallet-TQ7D5EQ7.js.map +0 -1
  247. package/dist/wallet-ZAVXWLWP.js +0 -32
  248. package/dist/wallet-ZAVXWLWP.js.map +0 -1
  249. package/docs/command-reference.md +0 -303
  250. package/skills/tenjin/SKILL.md +0 -373
  251. package/skills/tenjin-pay/SKILL.md +0 -76
  252. package/skills/tenjin-publish/SKILL.md +0 -227
  253. package/skills/tenjin-publish/references/maintain.md +0 -39
  254. package/skills/tenjin-search/SKILL.md +0 -154
  255. package/skills/tenjin-search/references/permissions.md +0 -112
  256. /package/dist/{_esm-N4KAVXQR.js.map → _esm-CE7KNONL.js.map} +0 -0
  257. /package/dist/{buy-VIRNSYGN.js.map → ccip-7RMRLAGV.js.map} +0 -0
  258. /package/dist/{ccip-RPPPKTJR.js.map → ccip-NLCSCHKI.js.map} +0 -0
  259. /package/dist/{chunk-U5S527PP.js.map → chunk-5IEP5EGE.js.map} +0 -0
  260. /package/dist/{chunk-KYQVEKP5.js.map → chunk-BPMWXTFX.js.map} +0 -0
  261. /package/dist/{chunk-S5RYMCV6.js.map → chunk-HPWO4O6S.js.map} +0 -0
  262. /package/dist/{chunk-W6R3HAAG.js.map → chunk-JRGFKVAZ.js.map} +0 -0
  263. /package/dist/{chunk-XJN5WUKL.js.map → chunk-KG3D7FIF.js.map} +0 -0
  264. /package/dist/{chunk-QW2Q2KAH.js.map → chunk-LHHMV4GU.js.map} +0 -0
  265. /package/dist/{chunk-POJRB2AE.js.map → chunk-POUWHWID.js.map} +0 -0
  266. /package/dist/{chunk-KZAAWQNP.js.map → chunk-TTNESUPQ.js.map} +0 -0
  267. /package/dist/{chunk-YLYINX2H.js.map → chunk-XZKD7DIF.js.map} +0 -0
  268. /package/dist/{ccip-ZGGWQN4X.js.map → config-5ADBAAXU.js.map} +0 -0
  269. /package/dist/{dist-U4M6QCKE.js.map → dist-3LOO6M4U.js.map} +0 -0
  270. /package/dist/{config-JMRUNYE6.js.map → ethersCompat-Df4a6QIZ-THAVUGIJ.js.map} +0 -0
  271. /package/dist/{doctor-ZBG7X66D.js.map → install-OKDKGUXM.js.map} +0 -0
  272. /package/dist/{edit-PZJIILQE.js.map → paths-P2N4JTDZ.js.map} +0 -0
  273. /package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js.map → pay-3SYKHKWJ.js.map} +0 -0
  274. /package/dist/{fund-EUDH5KPA.js.map → redact-6W23GGJC.js.map} +0 -0
  275. /package/dist/{inspect-QC6WEQPN.js.map → secp256k1-ZZZT2CAX.js.map} +0 -0
  276. /package/dist/{outcome-KSGWZHUS.js.map → status-line-wiring-L2WYIYBM.js.map} +0 -0
  277. /package/dist/{publish-LXWFDIKF.js.map → viemAdapter-By13KInL-X2VY6CY3.js.map} +0 -0
  278. /package/dist/{search-TSQAB45E.js.map → wallet-BMEXRR3P.js.map} +0 -0
@@ -1,81 +0,0 @@
1
- import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- installSkill
4
- } from "./chunk-QZ6ROAJU.js";
5
- import {
6
- emitWriteNotice
7
- } from "./chunk-OLWTRUTS.js";
8
- import {
9
- resolveHermesHomeLenient
10
- } from "./chunk-OKYSNAS3.js";
11
- import {
12
- OPTIONAL_PAY_SKILL,
13
- SKILL_NAMES,
14
- readSkillFile,
15
- resolveSkillsSource,
16
- skillFrontmatterName,
17
- skillsDirsFor
18
- } from "./chunk-2MYQN7HM.js";
19
-
20
- // src/lib/skill-placement.ts
21
- import { lstatSync } from "fs";
22
- import { readdir, rm, rmdir } from "fs/promises";
23
- import { homedir } from "os";
24
- import { isAbsolute, join } from "path";
25
- import { fileURLToPath } from "url";
26
- async function placeOptionalSkill(name, skillsDir, skillsSource, present) {
27
- const skillDir = join(skillsDir, name);
28
- if (present) {
29
- const { status } = await installSkill(join(skillsSource, name), skillDir, false, name);
30
- return { changed: status !== "up-to-date" };
31
- }
32
- if (lstatSync(skillDir, { throwIfNoEntry: false })?.isDirectory() !== true) {
33
- return { changed: false };
34
- }
35
- const path = join(skillDir, "SKILL.md");
36
- const read = await readSkillFile(path);
37
- if (read.kind === "absent") return { changed: false };
38
- if (read.kind !== "ok" || skillFrontmatterName(read.bytes.toString("utf8")) !== name) {
39
- return { changed: false };
40
- }
41
- await rm(path, { force: true });
42
- const rest = await readdir(skillDir).catch(() => null);
43
- if (rest !== null && rest.length === 0) await rmdir(skillDir).catch(() => void 0);
44
- return { changed: true };
45
- }
46
- async function syncBazaarSkill(enabled, deps) {
47
- const home = deps.homeDir ?? homedir();
48
- if (!isAbsolute(home)) return;
49
- let source;
50
- try {
51
- source = deps.skillsSourceDir ?? resolveSkillsSource(fileURLToPath(new URL(".", import.meta.url)));
52
- } catch {
53
- return;
54
- }
55
- const env = deps.env ?? process.env;
56
- const touched = [];
57
- for (const dir of skillsDirsFor(home, resolveHermesHomeLenient(home, env).home)) {
58
- try {
59
- if (lstatSync(dir, { throwIfNoEntry: false })?.isDirectory() !== true) continue;
60
- const consented = SKILL_NAMES.some(
61
- (name) => lstatSync(join(dir, name, "SKILL.md"), { throwIfNoEntry: false })?.isFile() === true
62
- );
63
- if (!consented) continue;
64
- const { changed } = await placeOptionalSkill(OPTIONAL_PAY_SKILL, dir, source, enabled);
65
- if (changed) touched.push(join(dir, OPTIONAL_PAY_SKILL));
66
- } catch {
67
- }
68
- }
69
- if (touched.length > 0) {
70
- emitWriteNotice(
71
- deps.io,
72
- `${enabled ? "Installed" : "Removed"} ${touched.join(" and ")} to match bazaarPay.`
73
- );
74
- }
75
- }
76
-
77
- export {
78
- placeOptionalSkill,
79
- syncBazaarSkill
80
- };
81
- //# sourceMappingURL=chunk-DHJD77OW.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/skill-placement.ts"],"sourcesContent":["import { lstatSync } from 'node:fs';\nimport { readdir, rm, rmdir } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { isAbsolute, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { emitWriteNotice } from './output';\nimport type { Io } from './output';\nimport { readSkillFile, skillFrontmatterName, skillsDirsFor } from './skill-wiring';\nimport { installSkill } from './skill-writer';\nimport { OPTIONAL_PAY_SKILL, SKILL_NAMES, resolveSkillsSource } from './skills-source';\nimport { resolveHermesHomeLenient } from './hermes';\n\n/**\n * Optional skills, where PRESENCE is the whole mechanism: the tenjin-pay skill\n * is on disk exactly while the `bazaarPay` toggle is on, so an agent is never\n * taught a lane the operator turned off, and turning the lane on is what makes\n * the teaching appear. No conditional content, no markers: the unit of\n * consent stays the one the whole pipeline already has, a skill directory.\n *\n * Removal follows `uninstall`'s rules exactly (lib/uninstall removeSkills):\n * only a SKILL.md whose frontmatter still claims our name is ours to delete,\n * and the directory goes only when our file was the only thing in it, so an\n * operator's own files beside it survive a toggle-off.\n */\n\n/** Ensure `name` is present or absent under one skills directory. */\nexport async function placeOptionalSkill(\n name: string,\n skillsDir: string,\n skillsSource: string,\n present: boolean,\n): Promise<{ changed: boolean }> {\n const skillDir = join(skillsDir, name);\n if (present) {\n const { status } = await installSkill(join(skillsSource, name), skillDir, false, name);\n return { changed: status !== 'up-to-date' };\n }\n if (lstatSync(skillDir, { throwIfNoEntry: false })?.isDirectory() !== true) {\n return { changed: false };\n }\n const path = join(skillDir, 'SKILL.md');\n const read = await readSkillFile(path);\n if (read.kind === 'absent') return { changed: false };\n if (read.kind !== 'ok' || skillFrontmatterName(read.bytes.toString('utf8')) !== name) {\n return { changed: false }; // not ours to delete for sitting at our path\n }\n await rm(path, { force: true });\n const rest = await readdir(skillDir).catch(() => null);\n if (rest !== null && rest.length === 0) await rmdir(skillDir).catch(() => undefined);\n return { changed: true };\n}\n\n/**\n * The `config set bazaarPay` twin of the heal: converge the tenjin-pay skill's\n * presence with the toggle across every skills directory a tenjin skill is\n * already wired into (presence of any shipped skill is the operator's consent\n * to a directory; an unwired directory is never created). Operator act, so\n * failures degrade per directory and doctor reports what remains.\n */\nexport async function syncBazaarSkill(\n enabled: boolean,\n deps: { io: Io; homeDir?: string; skillsSourceDir?: string; env?: NodeJS.ProcessEnv },\n): Promise<void> {\n const home = deps.homeDir ?? homedir();\n if (!isAbsolute(home)) return;\n let source: string;\n try {\n source =\n deps.skillsSourceDir ?? resolveSkillsSource(fileURLToPath(new URL('.', import.meta.url)));\n } catch {\n return; // no readable source: nothing safe to write, nothing to remove FROM\n }\n const env = deps.env ?? process.env;\n // Lenient, like `skill-heal` and `uninstall`: a stray relative HERMES_HOME must\n // not stop an operator's own `config set bazaarPay`. Resolving it at all is\n // what puts the Hermes skills directory in scope for the sync.\n const touched: string[] = [];\n for (const dir of skillsDirsFor(home, resolveHermesHomeLenient(home, env).home)) {\n try {\n if (lstatSync(dir, { throwIfNoEntry: false })?.isDirectory() !== true) continue;\n const consented = SKILL_NAMES.some(\n (name) =>\n lstatSync(join(dir, name, 'SKILL.md'), { throwIfNoEntry: false })?.isFile() === true,\n );\n if (!consented) continue;\n const { changed } = await placeOptionalSkill(OPTIONAL_PAY_SKILL, dir, source, enabled);\n if (changed) touched.push(join(dir, OPTIONAL_PAY_SKILL));\n } catch {\n // This directory keeps what it has; `tenjin doctor` reports the drift.\n }\n }\n if (touched.length > 0) {\n emitWriteNotice(\n deps.io,\n `${enabled ? 'Installed' : 'Removed'} ${touched.join(' and ')} to match bazaarPay.`,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,SAAS,IAAI,aAAa;AACnC,SAAS,eAAe;AACxB,SAAS,YAAY,YAAY;AACjC,SAAS,qBAAqB;AAsB9B,eAAsB,mBACpB,MACA,WACA,cACA,SAC+B;AAC/B,QAAM,WAAW,KAAK,WAAW,IAAI;AACrC,MAAI,SAAS;AACX,UAAM,EAAE,OAAO,IAAI,MAAM,aAAa,KAAK,cAAc,IAAI,GAAG,UAAU,OAAO,IAAI;AACrF,WAAO,EAAE,SAAS,WAAW,aAAa;AAAA,EAC5C;AACA,MAAI,UAAU,UAAU,EAAE,gBAAgB,MAAM,CAAC,GAAG,YAAY,MAAM,MAAM;AAC1E,WAAO,EAAE,SAAS,MAAM;AAAA,EAC1B;AACA,QAAM,OAAO,KAAK,UAAU,UAAU;AACtC,QAAM,OAAO,MAAM,cAAc,IAAI;AACrC,MAAI,KAAK,SAAS,SAAU,QAAO,EAAE,SAAS,MAAM;AACpD,MAAI,KAAK,SAAS,QAAQ,qBAAqB,KAAK,MAAM,SAAS,MAAM,CAAC,MAAM,MAAM;AACpF,WAAO,EAAE,SAAS,MAAM;AAAA,EAC1B;AACA,QAAM,GAAG,MAAM,EAAE,OAAO,KAAK,CAAC;AAC9B,QAAM,OAAO,MAAM,QAAQ,QAAQ,EAAE,MAAM,MAAM,IAAI;AACrD,MAAI,SAAS,QAAQ,KAAK,WAAW,EAAG,OAAM,MAAM,QAAQ,EAAE,MAAM,MAAM,MAAS;AACnF,SAAO,EAAE,SAAS,KAAK;AACzB;AASA,eAAsB,gBACpB,SACA,MACe;AACf,QAAM,OAAO,KAAK,WAAW,QAAQ;AACrC,MAAI,CAAC,WAAW,IAAI,EAAG;AACvB,MAAI;AACJ,MAAI;AACF,aACE,KAAK,mBAAmB,oBAAoB,cAAc,IAAI,IAAI,KAAK,YAAY,GAAG,CAAC,CAAC;AAAA,EAC5F,QAAQ;AACN;AAAA,EACF;AACA,QAAM,MAAM,KAAK,OAAO,QAAQ;AAIhC,QAAM,UAAoB,CAAC;AAC3B,aAAW,OAAO,cAAc,MAAM,yBAAyB,MAAM,GAAG,EAAE,IAAI,GAAG;AAC/E,QAAI;AACF,UAAI,UAAU,KAAK,EAAE,gBAAgB,MAAM,CAAC,GAAG,YAAY,MAAM,KAAM;AACvE,YAAM,YAAY,YAAY;AAAA,QAC5B,CAAC,SACC,UAAU,KAAK,KAAK,MAAM,UAAU,GAAG,EAAE,gBAAgB,MAAM,CAAC,GAAG,OAAO,MAAM;AAAA,MACpF;AACA,UAAI,CAAC,UAAW;AAChB,YAAM,EAAE,QAAQ,IAAI,MAAM,mBAAmB,oBAAoB,KAAK,QAAQ,OAAO;AACrF,UAAI,QAAS,SAAQ,KAAK,KAAK,KAAK,kBAAkB,CAAC;AAAA,IACzD,QAAQ;AAAA,IAER;AAAA,EACF;AACA,MAAI,QAAQ,SAAS,GAAG;AACtB;AAAA,MACE,KAAK;AAAA,MACL,GAAG,UAAU,cAAc,SAAS,IAAI,QAAQ,KAAK,OAAO,CAAC;AAAA,IAC/D;AAAA,EACF;AACF;","names":[]}
@@ -1,35 +0,0 @@
1
- import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- CliError
4
- } from "./chunk-ZFJJ3EXC.js";
5
-
6
- // src/lib/url.ts
7
- function trimSlash(url) {
8
- return url.replace(/\/+$/, "");
9
- }
10
- function tryOriginOf(url) {
11
- let parsed;
12
- try {
13
- parsed = new URL(url);
14
- } catch {
15
- return null;
16
- }
17
- if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;
18
- return parsed.origin;
19
- }
20
- function originOf(url) {
21
- const origin = tryOriginOf(url);
22
- if (origin === null) {
23
- throw new CliError("USAGE", `Invalid base URL: ${JSON.stringify(url)}`, {
24
- fix: "Set an absolute http(s) base URL: `tenjin config set baseUrl <url>`."
25
- });
26
- }
27
- return origin;
28
- }
29
-
30
- export {
31
- trimSlash,
32
- tryOriginOf,
33
- originOf
34
- };
35
- //# sourceMappingURL=chunk-EDZSNPE5.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/url.ts"],"sourcesContent":["import { CliError } from './errors';\n\n/** Drop trailing slashes from a base URL so `${base}/path` never doubles a slash. */\nexport function trimSlash(url: string): string {\n return url.replace(/\\/+$/, '');\n}\n\n/**\n * The `scheme://host[:port]` of an http(s) URL, or null if it is not one.\n *\n * Non-http schemes are rejected rather than passed through, and that is the whole\n * reason this is not a one-line `new URL(url).origin`: for any non-special\n * scheme the WHATWG origin is the opaque string `\"null\"`, so `foo://tenjin.blog`\n * and `bar://evil.example` compare EQUAL. This value binds a wallet-derived\n * credential to one deployment, so an equal-comparing sentinel is exactly the\n * failure it exists to prevent — the same shape as the unparseable case, just\n * spelled differently.\n */\nexport function tryOriginOf(url: string): string | null {\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n return null;\n }\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return null;\n return parsed.origin;\n}\n\n/**\n * `tryOriginOf` for callers that cannot proceed without an origin. Throws USAGE\n * rather than returning a sentinel; anything that must survive a bad base URL\n * (diagnostics, above all) uses `tryOriginOf` and handles the null.\n */\nexport function originOf(url: string): string {\n const origin = tryOriginOf(url);\n if (origin === null) {\n throw new CliError('USAGE', `Invalid base URL: ${JSON.stringify(url)}`, {\n fix: 'Set an absolute http(s) base URL: `tenjin config set baseUrl <url>`.',\n });\n }\n return origin;\n}\n"],"mappings":";;;;;;AAGO,SAAS,UAAU,KAAqB;AAC7C,SAAO,IAAI,QAAQ,QAAQ,EAAE;AAC/B;AAaO,SAAS,YAAY,KAA4B;AACtD,MAAI;AACJ,MAAI;AACF,aAAS,IAAI,IAAI,GAAG;AAAA,EACtB,QAAQ;AACN,WAAO;AAAA,EACT;AACA,MAAI,OAAO,aAAa,WAAW,OAAO,aAAa,SAAU,QAAO;AACxE,SAAO,OAAO;AAChB;AAOO,SAAS,SAAS,KAAqB;AAC5C,QAAM,SAAS,YAAY,GAAG;AAC9B,MAAI,WAAW,MAAM;AACnB,UAAM,IAAI,SAAS,SAAS,qBAAqB,KAAK,UAAU,GAAG,CAAC,IAAI;AAAA,MACtE,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AACA,SAAO;AACT;","names":[]}
@@ -1,65 +0,0 @@
1
- import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- CliError
4
- } from "./chunk-ZFJJ3EXC.js";
5
-
6
- // src/lib/ids.ts
7
- var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
8
- var SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
9
- var ATOMIC_RE = /^\d{1,39}$/;
10
-
11
- // src/lib/money.ts
12
- var USDC_DECIMALS = 6;
13
- function parseUsdToAtomic(input) {
14
- const trimmed = input.trim();
15
- if (!/^\d+(\.\d+)?$/.test(trimmed)) {
16
- throw new CliError("USAGE", `Invalid USD amount: ${JSON.stringify(input)}`, {
17
- fix: "Pass a non-negative decimal like 0.25 or 5."
18
- });
19
- }
20
- const [whole, frac = ""] = trimmed.split(".");
21
- if (frac.length > USDC_DECIMALS) {
22
- throw new CliError(
23
- "USAGE",
24
- `USD amount ${JSON.stringify(input)} has more than 6 decimal places`,
25
- {
26
- fix: "USDC supports at most 6 decimal places (micro-dollars)."
27
- }
28
- );
29
- }
30
- const atomic = BigInt(`${whole}${frac.padEnd(USDC_DECIMALS, "0")}`);
31
- return atomic.toString();
32
- }
33
- function atomicToUsd(atomic) {
34
- const trimmed = atomic.trim();
35
- if (!/^\d+$/.test(trimmed)) {
36
- throw new CliError("INTERNAL", `Malformed atomic amount: ${JSON.stringify(atomic)}`);
37
- }
38
- const value = BigInt(trimmed);
39
- const base = 10n ** BigInt(USDC_DECIMALS);
40
- const whole = value / base;
41
- const frac = (value % base).toString().padStart(USDC_DECIMALS, "0").replace(/0+$/, "");
42
- return frac.length > 0 ? `${whole}.${frac}` : whole.toString();
43
- }
44
- function isPaidPrice(atomic) {
45
- if (!ATOMIC_RE.test(atomic)) return null;
46
- return /[1-9]/.test(atomic);
47
- }
48
- function toMoney(atomic) {
49
- return { atomic, usd: atomicToUsd(atomic) };
50
- }
51
- function formatUsdDisplay(atomic) {
52
- const [whole, frac = ""] = atomicToUsd(atomic).split(".");
53
- return `${whole}.${frac.padEnd(2, "0")}`;
54
- }
55
-
56
- export {
57
- UUID_RE,
58
- SLUG_RE,
59
- ATOMIC_RE,
60
- parseUsdToAtomic,
61
- isPaidPrice,
62
- toMoney,
63
- formatUsdDisplay
64
- };
65
- //# sourceMappingURL=chunk-EFWZPUTC.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/ids.ts","../src/lib/money.ts"],"sourcesContent":["/**\n * The shared identity patterns for server-controlled values that become file\n * paths, URL segments, or terminal output. One definition so a future change\n * (e.g. accepting uppercase ids) cannot be applied in one command and missed in\n * another. SLUG_RE must match the server's slugify charset (lib/posts.ts:\n * lowercase a-z0-9 groups joined by single hyphens, no leading/trailing hyphen).\n */\nexport const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\nexport const SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n/** A non-negative atomic USDC integer string (6-decimal base units). */\nexport const ATOMIC_RE = /^\\d{1,39}$/;\n","import { CliError } from './errors';\nimport { ATOMIC_RE } from './ids';\nimport type { Money } from '../schemas';\n\n/** USDC is a 6-decimal token; one dollar is 1_000_000 atomic units. */\nconst USDC_DECIMALS = 6;\n\n/**\n * Decimal USD at the CLI edge -> atomic USDC string (O1). Accepts \"0\", \"0.25\",\n * \"5\"; rejects negatives, non-numeric input, and more than 6 decimal places as\n * USAGE so a fat-fingered amount fails loudly instead of truncating money.\n * String math throughout — a float would lose precision at the 6th decimal.\n */\nexport function parseUsdToAtomic(input: string): string {\n const trimmed = input.trim();\n if (!/^\\d+(\\.\\d+)?$/.test(trimmed)) {\n throw new CliError('USAGE', `Invalid USD amount: ${JSON.stringify(input)}`, {\n fix: 'Pass a non-negative decimal like 0.25 or 5.',\n });\n }\n const [whole, frac = ''] = trimmed.split('.');\n if (frac.length > USDC_DECIMALS) {\n throw new CliError(\n 'USAGE',\n `USD amount ${JSON.stringify(input)} has more than 6 decimal places`,\n {\n fix: 'USDC supports at most 6 decimal places (micro-dollars).',\n },\n );\n }\n const atomic = BigInt(`${whole}${frac.padEnd(USDC_DECIMALS, '0')}`);\n return atomic.toString();\n}\n\n/**\n * Atomic USDC string -> decimal USD string, trailing zeros trimmed (\"250000\" ->\n * \"0.25\", \"5000000\" -> \"5\", \"0\" -> \"0\"). Throws INTERNAL on a malformed atomic\n * value: atomic strings come from validated config or on-chain reads, so a bad\n * one is a bug, not user input.\n */\nexport function atomicToUsd(atomic: string): string {\n const trimmed = atomic.trim();\n if (!/^\\d+$/.test(trimmed)) {\n throw new CliError('INTERNAL', `Malformed atomic amount: ${JSON.stringify(atomic)}`);\n }\n const value = BigInt(trimmed);\n const base = 10n ** BigInt(USDC_DECIMALS);\n const whole = value / base;\n const frac = (value % base).toString().padStart(USDC_DECIMALS, '0').replace(/0+$/, '');\n return frac.length > 0 ? `${whole}.${frac}` : whole.toString();\n}\n\n/**\n * Whether an atomic price would actually cost something: true paid, false free,\n * null when the string is not an atomic amount at all and so cannot answer.\n *\n * A Tenjin piece may be priced at zero and is then delivered by `read` with no\n * payment, so \"there is a price field\" and \"there is a purchase to make\" are\n * different questions. The third state is not decoration: only the wire schema\n * enforces ATOMIC_RE, and the local search store types `price` as a bare string,\n * so a hand-edited or half-written entry can hold \"-1\" or \"0.1\". Those must not\n * read as \"free\", or corrupt local data would start refusing honest reports.\n * Never throws, which is why the check is a regex and not a BigInt compare.\n *\n * Matched against the RAW string, with no trimming. The contract carries the\n * canonical form and nothing else, so \" 0 \" did not come off the wire; padding is\n * evidence the value was edited, and normalizing it away would launder a corrupt\n * entry into a confident \"free\" and hand back the false refusal this avoids.\n */\nexport function isPaidPrice(atomic: string): boolean | null {\n if (!ATOMIC_RE.test(atomic)) return null;\n return /[1-9]/.test(atomic);\n}\n\n/** Dual-form money object for machine output. */\nexport function toMoney(atomic: string): Money {\n return { atomic, usd: atomicToUsd(atomic) };\n}\n\n/**\n * Canonical USD for human COPY (a price a person reads): always at least two\n * decimals (\"0.10\", \"5.00\"), keeping any finer precision below a cent\n * (\"0.000001\"). Distinct from `atomicToUsd`, which trims to the shortest exact\n * form for machine output; use this only where a dollar amount is shown to a human.\n */\nexport function formatUsdDisplay(atomic: string): string {\n const [whole, frac = ''] = atomicToUsd(atomic).split('.');\n return `${whole}.${frac.padEnd(2, '0')}`;\n}\n"],"mappings":";;;;;;AAOO,IAAM,UAAU;AAChB,IAAM,UAAU;AAEhB,IAAM,YAAY;;;ACLzB,IAAM,gBAAgB;AAQf,SAAS,iBAAiB,OAAuB;AACtD,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,CAAC,gBAAgB,KAAK,OAAO,GAAG;AAClC,UAAM,IAAI,SAAS,SAAS,uBAAuB,KAAK,UAAU,KAAK,CAAC,IAAI;AAAA,MAC1E,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AACA,QAAM,CAAC,OAAO,OAAO,EAAE,IAAI,QAAQ,MAAM,GAAG;AAC5C,MAAI,KAAK,SAAS,eAAe;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,MACA,cAAc,KAAK,UAAU,KAAK,CAAC;AAAA,MACnC;AAAA,QACE,KAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AACA,QAAM,SAAS,OAAO,GAAG,KAAK,GAAG,KAAK,OAAO,eAAe,GAAG,CAAC,EAAE;AAClE,SAAO,OAAO,SAAS;AACzB;AAQO,SAAS,YAAY,QAAwB;AAClD,QAAM,UAAU,OAAO,KAAK;AAC5B,MAAI,CAAC,QAAQ,KAAK,OAAO,GAAG;AAC1B,UAAM,IAAI,SAAS,YAAY,4BAA4B,KAAK,UAAU,MAAM,CAAC,EAAE;AAAA,EACrF;AACA,QAAM,QAAQ,OAAO,OAAO;AAC5B,QAAM,OAAO,OAAO,OAAO,aAAa;AACxC,QAAM,QAAQ,QAAQ;AACtB,QAAM,QAAQ,QAAQ,MAAM,SAAS,EAAE,SAAS,eAAe,GAAG,EAAE,QAAQ,OAAO,EAAE;AACrF,SAAO,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,MAAM,SAAS;AAC/D;AAmBO,SAAS,YAAY,QAAgC;AAC1D,MAAI,CAAC,UAAU,KAAK,MAAM,EAAG,QAAO;AACpC,SAAO,QAAQ,KAAK,MAAM;AAC5B;AAGO,SAAS,QAAQ,QAAuB;AAC7C,SAAO,EAAE,QAAQ,KAAK,YAAY,MAAM,EAAE;AAC5C;AAQO,SAAS,iBAAiB,QAAwB;AACvD,QAAM,CAAC,OAAO,OAAO,EAAE,IAAI,YAAY,MAAM,EAAE,MAAM,GAAG;AACxD,SAAO,GAAG,KAAK,IAAI,KAAK,OAAO,GAAG,GAAG,CAAC;AACxC;","names":[]}
@@ -1,448 +0,0 @@
1
- import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- HTTPFacilitatorClient
4
- } from "./chunk-DBU5CXBV.js";
5
- import {
6
- writeFileAtomic
7
- } from "./chunk-ZFJJ3EXC.js";
8
- import {
9
- getAddress
10
- } from "./chunk-47PP7TAG.js";
11
-
12
- // src/lib/bazaar.ts
13
- import { readFile } from "fs/promises";
14
- import { join } from "path";
15
-
16
- // node_modules/.pnpm/@x402+extensions@2.17.0_typescript@6.0.3/node_modules/@x402/extensions/dist/esm/chunk-KKZBRP7D.mjs
17
- var BAZAAR = { key: "bazaar" };
18
- var BRACKET_PARAM_REGEX = /\[([^\]]+)\]/;
19
- var BRACKET_PARAM_REGEX_ALL = /\[([^\]]+)\]/g;
20
- var COLON_PARAM_REGEX = /:([a-zA-Z_][a-zA-Z0-9_]*)/;
21
- function isHTTPRequestContext(ctx) {
22
- return ctx !== null && typeof ctx === "object" && "method" in ctx && "adapter" in ctx;
23
- }
24
- function normalizeWildcardPattern(pattern) {
25
- if (!pattern.includes("*")) {
26
- return pattern;
27
- }
28
- let counter = 0;
29
- return pattern.split("/").map((seg) => {
30
- if (seg === "*") {
31
- counter++;
32
- return `:var${counter}`;
33
- }
34
- return seg;
35
- }).join("/");
36
- }
37
- function extractDynamicRouteInfo(routePattern, urlPath) {
38
- const hasBracket = BRACKET_PARAM_REGEX.test(routePattern);
39
- const hasColon = COLON_PARAM_REGEX.test(routePattern);
40
- if (!hasBracket && !hasColon) {
41
- return null;
42
- }
43
- const normalizedPattern = hasBracket ? routePattern.replace(BRACKET_PARAM_REGEX_ALL, ":$1") : routePattern;
44
- const pathParams = extractPathParams(normalizedPattern, urlPath, false);
45
- return { routeTemplate: normalizedPattern, pathParams };
46
- }
47
- function extractPathParams(routePattern, urlPath, isBracket) {
48
- const paramNames = [];
49
- const splitRegex = isBracket ? BRACKET_PARAM_REGEX : COLON_PARAM_REGEX;
50
- const parts = routePattern.split(splitRegex);
51
- const regexParts = [];
52
- parts.forEach((part, i) => {
53
- if (i % 2 === 0) {
54
- regexParts.push(part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
55
- } else {
56
- paramNames.push(part);
57
- regexParts.push("([^/]+)");
58
- }
59
- });
60
- const regex = new RegExp(`^${regexParts.join("")}$`);
61
- const match = urlPath.match(regex);
62
- if (!match) return {};
63
- const result = {};
64
- paramNames.forEach((name, idx) => {
65
- result[name] = match[idx + 1];
66
- });
67
- return result;
68
- }
69
- var bazaarResourceServerExtension = {
70
- key: BAZAAR.key,
71
- enrichDeclaration: (declaration, transportContext) => {
72
- if (!isHTTPRequestContext(transportContext)) {
73
- return declaration;
74
- }
75
- const extension = declaration;
76
- if (extension.info?.input?.type === "mcp") {
77
- return declaration;
78
- }
79
- const method = transportContext.method;
80
- const existingInputProps = extension.schema?.properties?.input?.properties || {};
81
- const updatedInputProps = {
82
- ...existingInputProps,
83
- method: {
84
- type: "string",
85
- enum: [method]
86
- }
87
- };
88
- const enrichedResult = {
89
- ...extension,
90
- info: {
91
- ...extension.info || {},
92
- input: {
93
- ...extension.info?.input || {},
94
- method
95
- }
96
- },
97
- schema: {
98
- ...extension.schema || {},
99
- properties: {
100
- ...extension.schema?.properties || {},
101
- input: {
102
- ...extension.schema?.properties?.input || {},
103
- properties: updatedInputProps,
104
- required: [
105
- ...extension.schema?.properties?.input?.required || [],
106
- ...!(extension.schema?.properties?.input?.required || []).includes("method") ? ["method"] : []
107
- ]
108
- }
109
- }
110
- }
111
- };
112
- const rawRoutePattern = transportContext.routePattern;
113
- const routePattern = rawRoutePattern ? normalizeWildcardPattern(rawRoutePattern) : void 0;
114
- const dynamicRoute = routePattern ? extractDynamicRouteInfo(routePattern, transportContext.adapter.getPath()) : null;
115
- if (dynamicRoute) {
116
- const inputSchemaProps = enrichedResult.schema?.properties?.input?.properties || {};
117
- const hasPathParamsInSchema = "pathParams" in inputSchemaProps;
118
- return {
119
- ...enrichedResult,
120
- routeTemplate: dynamicRoute.routeTemplate,
121
- info: {
122
- ...enrichedResult.info,
123
- input: { ...enrichedResult.info.input, pathParams: dynamicRoute.pathParams }
124
- },
125
- ...!hasPathParamsInSchema ? {
126
- schema: {
127
- ...enrichedResult.schema,
128
- properties: {
129
- ...enrichedResult.schema?.properties,
130
- input: {
131
- ...enrichedResult.schema?.properties?.input,
132
- properties: {
133
- ...inputSchemaProps,
134
- pathParams: { type: "object" }
135
- }
136
- }
137
- }
138
- }
139
- } : {}
140
- };
141
- }
142
- return enrichedResult;
143
- }
144
- };
145
- var UNICODE_CONTROL_REGEX = new RegExp("\\p{Cc}", "u");
146
- var VALID_QUERY_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "DELETE"]);
147
- var VALID_BODY_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
148
- var VALID_METHODS = /* @__PURE__ */ new Set([...VALID_QUERY_METHODS, ...VALID_BODY_METHODS]);
149
- function withBazaar(client2) {
150
- const existingExtensions = client2.extensions ?? {};
151
- const extended = client2;
152
- extended.extensions = {
153
- ...existingExtensions,
154
- bazaar: {
155
- async listResources(params) {
156
- let headers = {
157
- "Content-Type": "application/json"
158
- };
159
- const authHeaders = await client2.createAuthHeaders("bazaar");
160
- headers = { ...headers, ...authHeaders.headers };
161
- const queryParams = new URLSearchParams();
162
- if (params?.type !== void 0) {
163
- queryParams.set("type", params.type);
164
- }
165
- if (params?.payTo !== void 0) {
166
- queryParams.set("payTo", params.payTo);
167
- }
168
- if (params?.scheme !== void 0) {
169
- queryParams.set("scheme", params.scheme);
170
- }
171
- if (params?.network !== void 0) {
172
- queryParams.set("network", params.network);
173
- }
174
- if (params?.extensions !== void 0) {
175
- queryParams.set("extensions", params.extensions);
176
- }
177
- if (params?.limit !== void 0) {
178
- queryParams.set("limit", params.limit.toString());
179
- }
180
- if (params?.offset !== void 0) {
181
- queryParams.set("offset", params.offset.toString());
182
- }
183
- const queryString = queryParams.toString();
184
- const endpoint = `${client2.url}/discovery/resources${queryString ? `?${queryString}` : ""}`;
185
- const response = await fetch(endpoint, {
186
- method: "GET",
187
- headers
188
- });
189
- if (!response.ok) {
190
- const errorText = await response.text().catch(() => response.statusText);
191
- throw new Error(
192
- `Facilitator listDiscoveryResources failed (${response.status}): ${errorText}`
193
- );
194
- }
195
- return await response.json();
196
- },
197
- async search(params) {
198
- let headers = {
199
- "Content-Type": "application/json"
200
- };
201
- const authHeaders = await client2.createAuthHeaders("bazaar");
202
- headers = { ...headers, ...authHeaders.headers };
203
- const queryParams = new URLSearchParams();
204
- queryParams.set("query", params.query);
205
- if (params.type !== void 0) {
206
- queryParams.set("type", params.type);
207
- }
208
- if (params.payTo !== void 0) {
209
- queryParams.set("payTo", params.payTo);
210
- }
211
- if (params.scheme !== void 0) {
212
- queryParams.set("scheme", params.scheme);
213
- }
214
- if (params.network !== void 0) {
215
- queryParams.set("network", params.network);
216
- }
217
- if (params.extensions !== void 0) {
218
- queryParams.set("extensions", params.extensions);
219
- }
220
- if (params.limit !== void 0) {
221
- queryParams.set("limit", params.limit.toString());
222
- }
223
- if (params.cursor !== void 0) {
224
- queryParams.set("cursor", params.cursor);
225
- }
226
- const endpoint = `${client2.url}/discovery/search?${queryParams.toString()}`;
227
- const response = await fetch(endpoint, {
228
- method: "GET",
229
- headers
230
- });
231
- if (!response.ok) {
232
- const errorText = await response.text().catch(() => response.statusText);
233
- throw new Error(
234
- `Facilitator searchDiscoveryResources failed (${response.status}): ${errorText}`
235
- );
236
- }
237
- return await response.json();
238
- }
239
- }
240
- };
241
- return extended;
242
- }
243
-
244
- // src/lib/bazaar.ts
245
- var PAGE_LIMIT = 100;
246
- var SEARCH_LIMIT = 20;
247
- function client(registry) {
248
- return withBazaar(new HTTPFacilitatorClient({ url: registry }));
249
- }
250
- async function withTimeout(work, timeoutMs, what) {
251
- let timer;
252
- try {
253
- return await Promise.race([
254
- work,
255
- new Promise((_, reject) => {
256
- timer = setTimeout(
257
- () => reject(new Error(`${what} timed out after ${timeoutMs}ms`)),
258
- timeoutMs
259
- );
260
- })
261
- ]);
262
- } finally {
263
- clearTimeout(timer);
264
- }
265
- }
266
- function toResource(item, registry) {
267
- return {
268
- url: item.resource,
269
- registry,
270
- ...item.description !== void 0 ? { description: item.description } : {},
271
- accepts: item.accepts,
272
- ...item.lastUpdated !== void 0 ? { lastUpdated: item.lastUpdated } : {}
273
- };
274
- }
275
- async function sweepRegistries(registries, opts) {
276
- const resources = [];
277
- const errors = [];
278
- let skippedNonHttp = 0;
279
- for (const registry of registries) {
280
- try {
281
- const bazaar = client(registry).extensions.bazaar;
282
- const items = opts.query !== void 0 ? (await withTimeout(
283
- bazaar.search({ query: opts.query, limit: SEARCH_LIMIT }),
284
- opts.timeoutMs,
285
- `search on ${registry}`
286
- )).resources : (await withTimeout(
287
- bazaar.listResources({ type: "http", limit: PAGE_LIMIT }),
288
- opts.timeoutMs,
289
- `listing ${registry}`
290
- )).items;
291
- for (const item of items) {
292
- if (item.type !== "http") {
293
- skippedNonHttp += 1;
294
- continue;
295
- }
296
- resources.push(toResource(item, registry));
297
- }
298
- } catch (err) {
299
- errors.push({ registry, message: err instanceof Error ? err.message : String(err) });
300
- }
301
- }
302
- return { resources, errors, skippedNonHttp };
303
- }
304
- var LISTING_STORE_FILE = "bazaar-listings.json";
305
- var LISTING_TTL_MS = 24 * 60 * 60 * 1e3;
306
- var LISTING_STORE_CAP = 1e3;
307
- function listingStorePath(dataDir) {
308
- return join(dataDir, LISTING_STORE_FILE);
309
- }
310
- function isStoredListing(value) {
311
- if (typeof value !== "object" || value === null) return false;
312
- const listing = value;
313
- return typeof listing.url === "string" && typeof listing.registry === "string" && typeof listing.fetchedAt === "string" && Array.isArray(listing.accepts);
314
- }
315
- async function loadListingStore(dataDir) {
316
- try {
317
- const raw = JSON.parse(await readFile(listingStorePath(dataDir), "utf8"));
318
- const listings = raw?.listings;
319
- return { listings: Array.isArray(listings) ? listings.filter(isStoredListing) : [] };
320
- } catch {
321
- return { listings: [] };
322
- }
323
- }
324
- async function saveSweepListings(dataDir, resources, now = Date.now) {
325
- const store = await loadListingStore(dataDir);
326
- const fetchedAt = new Date(now()).toISOString();
327
- const fresh = resources.map((r) => ({
328
- url: r.url,
329
- registry: r.registry,
330
- accepts: r.accepts,
331
- fetchedAt
332
- }));
333
- const seen = new Set(fresh.map((l) => `${l.registry} ${l.url}`));
334
- const kept = store.listings.filter((l) => !seen.has(`${l.registry} ${l.url}`));
335
- await writeFileAtomic(
336
- listingStorePath(dataDir),
337
- JSON.stringify({ listings: [...fresh, ...kept].slice(0, LISTING_STORE_CAP) }, null, 2)
338
- );
339
- }
340
- async function storedListingsFor(dataDir, url, now) {
341
- const store = await loadListingStore(dataDir);
342
- return store.listings.filter((l) => {
343
- if (!sameResourceUrl(l.url, url)) return false;
344
- const age = now() - Date.parse(l.fetchedAt);
345
- return age >= 0 && age < LISTING_TTL_MS;
346
- });
347
- }
348
- function sameResourceUrl(listed, requested) {
349
- const identity = (u) => {
350
- try {
351
- const parsed = new URL(u);
352
- const path = parsed.pathname.endsWith("/") ? parsed.pathname.slice(0, -1) : parsed.pathname;
353
- return `${parsed.origin}${path}`;
354
- } catch {
355
- return null;
356
- }
357
- };
358
- const a = identity(listed);
359
- return a !== null && a === identity(requested);
360
- }
361
- async function verifyAgainstRegistries(registries, url, live, timeoutMs, opts = {}) {
362
- const errors = [];
363
- let mismatch;
364
- if (opts.dataDir !== void 0) {
365
- for (const listing of await storedListingsFor(opts.dataDir, url, opts.now ?? Date.now)) {
366
- if (!registries.includes(listing.registry)) continue;
367
- const detail = acceptsMismatch(listing.accepts, live);
368
- if (detail === null) return { outcome: "verified", registry: listing.registry };
369
- mismatch ??= { registry: listing.registry, detail };
370
- }
371
- }
372
- for (const registry of registries) {
373
- try {
374
- const bazaar = client(registry).extensions.bazaar;
375
- const listed = await withTimeout(
376
- bazaar.listResources({ type: "http", payTo: live.payTo, limit: PAGE_LIMIT }),
377
- timeoutMs,
378
- `listing ${registry}`
379
- );
380
- const matches = listed.items.filter(
381
- (item) => item.type === "http" && sameResourceUrl(item.resource, url)
382
- );
383
- if (matches.length === 0) continue;
384
- for (const item of matches) {
385
- const detail = acceptsMismatch(item.accepts, live);
386
- if (detail === null) return { outcome: "verified", registry };
387
- mismatch ??= { registry, detail };
388
- }
389
- } catch (err) {
390
- errors.push({ registry, message: err instanceof Error ? err.message : String(err) });
391
- }
392
- }
393
- if (mismatch !== void 0) return { outcome: "mismatch", ...mismatch };
394
- if (errors.length === registries.length && registries.length > 0) {
395
- return { outcome: "unavailable", errors };
396
- }
397
- return { outcome: "unlisted" };
398
- }
399
- function acceptsMismatch(advertised, live) {
400
- let closest = "the listing advertises no payment terms";
401
- for (const adv of advertised) {
402
- if (adv.scheme !== live.scheme) {
403
- closest = `advertised scheme ${adv.scheme}, live ${live.scheme}`;
404
- continue;
405
- }
406
- if (adv.network !== live.network) {
407
- closest = `advertised network ${adv.network}, live ${live.network}`;
408
- continue;
409
- }
410
- if (!sameAddress(adv.asset, live.asset)) {
411
- closest = `advertised asset ${adv.asset}, live ${live.asset}`;
412
- continue;
413
- }
414
- if (!sameAddress(adv.payTo, live.payTo)) {
415
- closest = `advertised payTo ${adv.payTo}, live ${live.payTo}`;
416
- continue;
417
- }
418
- let advertisedAmount;
419
- let liveAmount;
420
- try {
421
- advertisedAmount = BigInt(adv.amount);
422
- liveAmount = BigInt(live.amount);
423
- } catch {
424
- closest = "a non-integer amount in the listing or the live 402";
425
- continue;
426
- }
427
- if (liveAmount > advertisedAmount) {
428
- closest = `live amount ${live.amount} exceeds the advertised ${adv.amount}`;
429
- continue;
430
- }
431
- return null;
432
- }
433
- return closest;
434
- }
435
- function sameAddress(a, b) {
436
- try {
437
- return getAddress(a) === getAddress(b);
438
- } catch {
439
- return false;
440
- }
441
- }
442
-
443
- export {
444
- sweepRegistries,
445
- saveSweepListings,
446
- verifyAgainstRegistries
447
- };
448
- //# sourceMappingURL=chunk-EPFL6CTE.js.map