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

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 (267) hide show
  1. package/NOTICE.md +54 -7
  2. package/README.md +41 -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-25TJPVBF.js +353 -0
  7. package/dist/chunk-25TJPVBF.js.map +1 -0
  8. package/dist/chunk-2BKS2FVE.js +93 -0
  9. package/dist/chunk-2BKS2FVE.js.map +1 -0
  10. package/dist/chunk-2QYORQBF.js +55 -0
  11. package/dist/chunk-2QYORQBF.js.map +1 -0
  12. package/dist/{chunk-NIKXHWOL.js → chunk-2U5ZVEV3.js} +16 -16
  13. package/dist/chunk-2U5ZVEV3.js.map +1 -0
  14. package/dist/{chunk-HPJGOLTN.js → chunk-3AJS6LLN.js} +13 -8
  15. package/dist/chunk-3AJS6LLN.js.map +1 -0
  16. package/dist/{chunk-KINZ23CV.js → chunk-3AUDA53C.js} +4740 -23
  17. package/dist/chunk-3AUDA53C.js.map +1 -0
  18. package/dist/{chunk-MJZZTKCC.js → chunk-56MOAIP5.js} +5 -10
  19. package/dist/chunk-56MOAIP5.js.map +1 -0
  20. package/dist/{chunk-U5S527PP.js → chunk-5IEP5EGE.js} +3 -3
  21. package/dist/chunk-5X4SZ5BF.js +227 -0
  22. package/dist/chunk-5X4SZ5BF.js.map +1 -0
  23. package/dist/chunk-7WEQQJLG.js +68 -0
  24. package/dist/chunk-7WEQQJLG.js.map +1 -0
  25. package/dist/{chunk-7FK2UN2T.js → chunk-AWQPGIR6.js} +65 -67
  26. package/dist/{chunk-7FK2UN2T.js.map → chunk-AWQPGIR6.js.map} +1 -1
  27. package/dist/{chunk-ZFJJ3EXC.js → chunk-BBVUVBUO.js} +516 -185
  28. package/dist/chunk-BBVUVBUO.js.map +1 -0
  29. package/dist/{chunk-JBIKAAT3.js → chunk-BFFM2WFK.js} +8 -8
  30. package/dist/chunk-BFFM2WFK.js.map +1 -0
  31. package/dist/{chunk-KYQVEKP5.js → chunk-BPMWXTFX.js} +8 -8
  32. package/dist/chunk-DMZZLPZN.js +205 -0
  33. package/dist/chunk-DMZZLPZN.js.map +1 -0
  34. package/dist/{chunk-47PP7TAG.js → chunk-EGELTSPU.js} +1356 -1356
  35. package/dist/chunk-EGELTSPU.js.map +1 -0
  36. package/dist/chunk-GULLJQXA.js +698 -0
  37. package/dist/chunk-GULLJQXA.js.map +1 -0
  38. package/dist/{chunk-S5RYMCV6.js → chunk-HPWO4O6S.js} +3 -3
  39. package/dist/chunk-HVRC33OL.js +174 -0
  40. package/dist/chunk-HVRC33OL.js.map +1 -0
  41. package/dist/{chunk-W6R3HAAG.js → chunk-JRGFKVAZ.js} +2 -2
  42. package/dist/{chunk-XJN5WUKL.js → chunk-KG3D7FIF.js} +2 -2
  43. package/dist/chunk-L3PVMIYQ.js +10328 -0
  44. package/dist/chunk-L3PVMIYQ.js.map +1 -0
  45. package/dist/{chunk-QW2Q2KAH.js → chunk-LHHMV4GU.js} +2 -2
  46. package/dist/{chunk-ZOBNS7CX.js → chunk-MEFB5KHA.js} +4 -18
  47. package/dist/chunk-MEFB5KHA.js.map +1 -0
  48. package/dist/{chunk-M2O56UK7.js → chunk-N35E6CM2.js} +293 -163
  49. package/dist/chunk-N35E6CM2.js.map +1 -0
  50. package/dist/chunk-OCBHUHWB.js +69 -0
  51. package/dist/chunk-OCBHUHWB.js.map +1 -0
  52. package/dist/chunk-OIM4HLN6.js +1405 -0
  53. package/dist/chunk-OIM4HLN6.js.map +1 -0
  54. package/dist/{chunk-VYOJOX4Z.js → chunk-OJLYNM4Z.js} +54 -33
  55. package/dist/chunk-OJLYNM4Z.js.map +1 -0
  56. package/dist/{chunk-POJRB2AE.js → chunk-POUWHWID.js} +2 -2
  57. package/dist/chunk-PZEN5PHN.js +285 -0
  58. package/dist/chunk-PZEN5PHN.js.map +1 -0
  59. package/dist/chunk-SKAHDQH7.js +1785 -0
  60. package/dist/chunk-SKAHDQH7.js.map +1 -0
  61. package/dist/{chunk-KZAAWQNP.js → chunk-TTNESUPQ.js} +3 -3
  62. package/dist/chunk-U5DXNFJC.js +137 -0
  63. package/dist/chunk-U5DXNFJC.js.map +1 -0
  64. package/dist/chunk-USS336NF.js +165 -0
  65. package/dist/chunk-USS336NF.js.map +1 -0
  66. package/dist/{chunk-UO22YNY4.js → chunk-WH7OWT6G.js} +49 -1
  67. package/dist/chunk-WH7OWT6G.js.map +1 -0
  68. package/dist/chunk-WXC57XGG.js +29 -0
  69. package/dist/chunk-WXC57XGG.js.map +1 -0
  70. package/dist/{chunk-YLYINX2H.js → chunk-XZKD7DIF.js} +3 -3
  71. package/dist/{chunk-CPCX67TI.js → chunk-YEETV6IW.js} +1079 -1039
  72. package/dist/chunk-YEETV6IW.js.map +1 -0
  73. package/dist/{chunk-OLWTRUTS.js → chunk-YJHHCWM3.js} +35 -16
  74. package/dist/chunk-YJHHCWM3.js.map +1 -0
  75. package/dist/{cli-KKRKBU5T.js → cli-M3XCSOU6.js} +289 -374
  76. package/dist/cli-M3XCSOU6.js.map +1 -0
  77. package/dist/config-MXOX7XDR.js +41 -0
  78. package/dist/{dist-U4M6QCKE.js → dist-3LOO6M4U.js} +10 -10
  79. package/dist/doctor-LU4YIZWM.js +349 -0
  80. package/dist/doctor-LU4YIZWM.js.map +1 -0
  81. package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
  82. package/dist/{chunk-KAJZHIQ4.js → fund-A54P2QFK.js} +80 -24
  83. package/dist/fund-A54P2QFK.js.map +1 -0
  84. package/dist/hook-command-U6KWPEDQ.js +377 -0
  85. package/dist/hook-command-U6KWPEDQ.js.map +1 -0
  86. package/dist/index.js +8 -3
  87. package/dist/index.js.map +1 -1
  88. package/dist/install-XUM2XSHW.js +53 -0
  89. package/dist/install-wallet-QIOFORTX.js +105 -0
  90. package/dist/install-wallet-QIOFORTX.js.map +1 -0
  91. package/dist/{run-XYTQ5TWQ.js → mcp-HJC2PLRV.js} +3727 -10670
  92. package/dist/mcp-HJC2PLRV.js.map +1 -0
  93. package/dist/paths-P2N4JTDZ.js +49 -0
  94. package/dist/pay-SBXZEPEP.js +37 -0
  95. package/dist/redact-46ZHF2NH.js +17 -0
  96. package/dist/{secp256k1-XRPVBC6V.js → secp256k1-ZZZT2CAX.js} +3 -3
  97. package/dist/{send-G746D7PQ.js → send-ASD2ZXJD.js} +28 -29
  98. package/dist/send-ASD2ZXJD.js.map +1 -0
  99. package/dist/{chunk-QZ6ROAJU.js → skill-placement-NFVHY6A3.js} +157 -11
  100. package/dist/skill-placement-NFVHY6A3.js.map +1 -0
  101. package/dist/status-T2SDB57A.js +63 -0
  102. package/dist/status-T2SDB57A.js.map +1 -0
  103. package/dist/status-line-CGPUSDMC.js +71 -0
  104. package/dist/status-line-CGPUSDMC.js.map +1 -0
  105. package/dist/status-line-wiring-BYPHTYZE.js +30 -0
  106. package/dist/tenjin-daemon.mjs +20060 -0
  107. package/dist/tenjin-shim.mjs +251 -0
  108. package/dist/tenjin-vitest-reporter.mjs +49 -0
  109. package/dist/uninstall-FKYZHAM3.js +144 -0
  110. package/dist/uninstall-FKYZHAM3.js.map +1 -0
  111. package/dist/{update-R76LHOZW.js → update-ANJ2AOTN.js} +133 -16
  112. package/dist/update-ANJ2AOTN.js.map +1 -0
  113. package/dist/{viemAdapter-By13KInL-TUQJBMHM.js → viemAdapter-By13KInL-X2VY6CY3.js} +5 -5
  114. package/dist/wallet-PWAHVKWW.js +31 -0
  115. package/dist/wallet-kdf-worker.mjs +980 -0
  116. package/docs/agent-permissions.md +65 -354
  117. package/docs/safety-model.md +16 -6
  118. package/package.json +8 -7
  119. package/LICENSE +0 -21
  120. package/dist/buy-VIRNSYGN.js +0 -47
  121. package/dist/chunk-2MYQN7HM.js +0 -247
  122. package/dist/chunk-2MYQN7HM.js.map +0 -1
  123. package/dist/chunk-2RF2GIJQ.js +0 -1188
  124. package/dist/chunk-2RF2GIJQ.js.map +0 -1
  125. package/dist/chunk-3GL2Z5QK.js +0 -57
  126. package/dist/chunk-3GL2Z5QK.js.map +0 -1
  127. package/dist/chunk-47PP7TAG.js.map +0 -1
  128. package/dist/chunk-4CQIDQOT.js +0 -167
  129. package/dist/chunk-4CQIDQOT.js.map +0 -1
  130. package/dist/chunk-4KG27W2S.js +0 -614
  131. package/dist/chunk-4KG27W2S.js.map +0 -1
  132. package/dist/chunk-5QQTYWEU.js +0 -199
  133. package/dist/chunk-5QQTYWEU.js.map +0 -1
  134. package/dist/chunk-65DTCCJ7.js +0 -21
  135. package/dist/chunk-65DTCCJ7.js.map +0 -1
  136. package/dist/chunk-A5DKHMUN.js +0 -173
  137. package/dist/chunk-A5DKHMUN.js.map +0 -1
  138. package/dist/chunk-B63XPWQ4.js +0 -246
  139. package/dist/chunk-B63XPWQ4.js.map +0 -1
  140. package/dist/chunk-CAR6FHK6.js +0 -105
  141. package/dist/chunk-CAR6FHK6.js.map +0 -1
  142. package/dist/chunk-CPCX67TI.js.map +0 -1
  143. package/dist/chunk-CQBVCYI2.js +0 -162
  144. package/dist/chunk-CQBVCYI2.js.map +0 -1
  145. package/dist/chunk-DBU5CXBV.js +0 -4731
  146. package/dist/chunk-DBU5CXBV.js.map +0 -1
  147. package/dist/chunk-DHJD77OW.js +0 -81
  148. package/dist/chunk-DHJD77OW.js.map +0 -1
  149. package/dist/chunk-EDZSNPE5.js +0 -35
  150. package/dist/chunk-EDZSNPE5.js.map +0 -1
  151. package/dist/chunk-EFWZPUTC.js +0 -65
  152. package/dist/chunk-EFWZPUTC.js.map +0 -1
  153. package/dist/chunk-EPFL6CTE.js +0 -448
  154. package/dist/chunk-EPFL6CTE.js.map +0 -1
  155. package/dist/chunk-GHLVXVZD.js +0 -142
  156. package/dist/chunk-GHLVXVZD.js.map +0 -1
  157. package/dist/chunk-H3SOOJ2I.js +0 -580
  158. package/dist/chunk-H3SOOJ2I.js.map +0 -1
  159. package/dist/chunk-HPJGOLTN.js.map +0 -1
  160. package/dist/chunk-HRGBS2PA.js +0 -203
  161. package/dist/chunk-HRGBS2PA.js.map +0 -1
  162. package/dist/chunk-ITUXPJIS.js +0 -314
  163. package/dist/chunk-ITUXPJIS.js.map +0 -1
  164. package/dist/chunk-JBIKAAT3.js.map +0 -1
  165. package/dist/chunk-KAJZHIQ4.js.map +0 -1
  166. package/dist/chunk-KINZ23CV.js.map +0 -1
  167. package/dist/chunk-LRYV3SK7.js +0 -235
  168. package/dist/chunk-LRYV3SK7.js.map +0 -1
  169. package/dist/chunk-M2O56UK7.js.map +0 -1
  170. package/dist/chunk-MJZZTKCC.js.map +0 -1
  171. package/dist/chunk-NIKXHWOL.js.map +0 -1
  172. package/dist/chunk-OKDRDT74.js +0 -209
  173. package/dist/chunk-OKDRDT74.js.map +0 -1
  174. package/dist/chunk-OKYSNAS3.js +0 -2144
  175. package/dist/chunk-OKYSNAS3.js.map +0 -1
  176. package/dist/chunk-OLWTRUTS.js.map +0 -1
  177. package/dist/chunk-QQ6ELLSA.js +0 -143
  178. package/dist/chunk-QQ6ELLSA.js.map +0 -1
  179. package/dist/chunk-QZ6ROAJU.js.map +0 -1
  180. package/dist/chunk-R7RSCBI7.js +0 -794
  181. package/dist/chunk-R7RSCBI7.js.map +0 -1
  182. package/dist/chunk-SGK2B724.js +0 -67
  183. package/dist/chunk-SGK2B724.js.map +0 -1
  184. package/dist/chunk-U6VPKMGC.js +0 -390
  185. package/dist/chunk-U6VPKMGC.js.map +0 -1
  186. package/dist/chunk-UHTVXQ2O.js +0 -140
  187. package/dist/chunk-UHTVXQ2O.js.map +0 -1
  188. package/dist/chunk-UO22YNY4.js.map +0 -1
  189. package/dist/chunk-US456VUI.js +0 -149
  190. package/dist/chunk-US456VUI.js.map +0 -1
  191. package/dist/chunk-V44J2MXV.js +0 -400
  192. package/dist/chunk-V44J2MXV.js.map +0 -1
  193. package/dist/chunk-VJQKL3YH.js +0 -216
  194. package/dist/chunk-VJQKL3YH.js.map +0 -1
  195. package/dist/chunk-VJSQSLBM.js +0 -1442
  196. package/dist/chunk-VJSQSLBM.js.map +0 -1
  197. package/dist/chunk-VYOJOX4Z.js.map +0 -1
  198. package/dist/chunk-WY2K35OL.js +0 -269
  199. package/dist/chunk-WY2K35OL.js.map +0 -1
  200. package/dist/chunk-ZFJJ3EXC.js.map +0 -1
  201. package/dist/chunk-ZOBNS7CX.js.map +0 -1
  202. package/dist/cli-KKRKBU5T.js.map +0 -1
  203. package/dist/config-JMRUNYE6.js +0 -37
  204. package/dist/discover-B5HF6SHM.js +0 -102
  205. package/dist/discover-B5HF6SHM.js.map +0 -1
  206. package/dist/doctor-ZBG7X66D.js +0 -32
  207. package/dist/edit-PZJIILQE.js +0 -40
  208. package/dist/fund-EUDH5KPA.js +0 -40
  209. package/dist/inspect-QC6WEQPN.js +0 -37
  210. package/dist/install-GNK2W3PI.js +0 -972
  211. package/dist/install-GNK2W3PI.js.map +0 -1
  212. package/dist/outcome-KSGWZHUS.js +0 -24
  213. package/dist/pay-BC4UICPA.js +0 -361
  214. package/dist/pay-BC4UICPA.js.map +0 -1
  215. package/dist/publish-LXWFDIKF.js +0 -42
  216. package/dist/read-JMNUQ56P.js +0 -160
  217. package/dist/read-JMNUQ56P.js.map +0 -1
  218. package/dist/run-XYTQ5TWQ.js.map +0 -1
  219. package/dist/search-TSQAB45E.js +0 -25
  220. package/dist/secp256k1-XRPVBC6V.js.map +0 -1
  221. package/dist/send-G746D7PQ.js.map +0 -1
  222. package/dist/session-JBKWMJ24.js +0 -89
  223. package/dist/session-JBKWMJ24.js.map +0 -1
  224. package/dist/skill-heal-WKD67SLJ.js +0 -92
  225. package/dist/skill-heal-WKD67SLJ.js.map +0 -1
  226. package/dist/skill-placement-RIU4AMC2.js +0 -20
  227. package/dist/skill-placement-RIU4AMC2.js.map +0 -1
  228. package/dist/uninstall-5E263VTS.js +0 -73
  229. package/dist/uninstall-5E263VTS.js.map +0 -1
  230. package/dist/update-R76LHOZW.js.map +0 -1
  231. package/dist/usdc-4VCDHFWX.js +0 -38
  232. package/dist/usdc-4VCDHFWX.js.map +0 -1
  233. package/dist/viemAdapter-By13KInL-TUQJBMHM.js.map +0 -1
  234. package/dist/wallet-TQ7D5EQ7.js +0 -41
  235. package/dist/wallet-TQ7D5EQ7.js.map +0 -1
  236. package/dist/wallet-ZAVXWLWP.js +0 -32
  237. package/dist/wallet-ZAVXWLWP.js.map +0 -1
  238. package/docs/command-reference.md +0 -303
  239. package/skills/tenjin/SKILL.md +0 -373
  240. package/skills/tenjin-pay/SKILL.md +0 -76
  241. package/skills/tenjin-publish/SKILL.md +0 -227
  242. package/skills/tenjin-publish/references/maintain.md +0 -39
  243. package/skills/tenjin-search/SKILL.md +0 -154
  244. package/skills/tenjin-search/references/permissions.md +0 -112
  245. /package/dist/{_esm-N4KAVXQR.js.map → _esm-CE7KNONL.js.map} +0 -0
  246. /package/dist/{buy-VIRNSYGN.js.map → ccip-7RMRLAGV.js.map} +0 -0
  247. /package/dist/{ccip-RPPPKTJR.js.map → ccip-NLCSCHKI.js.map} +0 -0
  248. /package/dist/{chunk-U5S527PP.js.map → chunk-5IEP5EGE.js.map} +0 -0
  249. /package/dist/{chunk-KYQVEKP5.js.map → chunk-BPMWXTFX.js.map} +0 -0
  250. /package/dist/{chunk-S5RYMCV6.js.map → chunk-HPWO4O6S.js.map} +0 -0
  251. /package/dist/{chunk-W6R3HAAG.js.map → chunk-JRGFKVAZ.js.map} +0 -0
  252. /package/dist/{chunk-XJN5WUKL.js.map → chunk-KG3D7FIF.js.map} +0 -0
  253. /package/dist/{chunk-QW2Q2KAH.js.map → chunk-LHHMV4GU.js.map} +0 -0
  254. /package/dist/{chunk-POJRB2AE.js.map → chunk-POUWHWID.js.map} +0 -0
  255. /package/dist/{chunk-KZAAWQNP.js.map → chunk-TTNESUPQ.js.map} +0 -0
  256. /package/dist/{chunk-YLYINX2H.js.map → chunk-XZKD7DIF.js.map} +0 -0
  257. /package/dist/{ccip-ZGGWQN4X.js.map → config-MXOX7XDR.js.map} +0 -0
  258. /package/dist/{dist-U4M6QCKE.js.map → dist-3LOO6M4U.js.map} +0 -0
  259. /package/dist/{config-JMRUNYE6.js.map → ethersCompat-Df4a6QIZ-THAVUGIJ.js.map} +0 -0
  260. /package/dist/{doctor-ZBG7X66D.js.map → install-XUM2XSHW.js.map} +0 -0
  261. /package/dist/{edit-PZJIILQE.js.map → paths-P2N4JTDZ.js.map} +0 -0
  262. /package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js.map → pay-SBXZEPEP.js.map} +0 -0
  263. /package/dist/{fund-EUDH5KPA.js.map → redact-46ZHF2NH.js.map} +0 -0
  264. /package/dist/{inspect-QC6WEQPN.js.map → secp256k1-ZZZT2CAX.js.map} +0 -0
  265. /package/dist/{outcome-KSGWZHUS.js.map → status-line-wiring-BYPHTYZE.js.map} +0 -0
  266. /package/dist/{publish-LXWFDIKF.js.map → viemAdapter-By13KInL-X2VY6CY3.js.map} +0 -0
  267. /package/dist/{search-TSQAB45E.js.map → wallet-PWAHVKWW.js.map} +0 -0
@@ -1,216 +0,0 @@
1
- import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- SLUG_RE,
4
- UUID_RE
5
- } from "./chunk-EFWZPUTC.js";
6
- import {
7
- findStoredCandidate
8
- } from "./chunk-A5DKHMUN.js";
9
- import {
10
- isSameDeployment
11
- } from "./chunk-2MYQN7HM.js";
12
- import {
13
- CliError,
14
- external_exports,
15
- writeFileAtomic
16
- } from "./chunk-ZFJJ3EXC.js";
17
-
18
- // src/lib/library.ts
19
- import { createHash } from "crypto";
20
- import { readFile, readdir } from "fs/promises";
21
- import { isAbsolute, join, relative, resolve } from "path";
22
- var ReceiptSchema = external_exports.object({
23
- schemaVersion: external_exports.literal(1),
24
- resourceId: external_exports.string(),
25
- slug: external_exports.string(),
26
- title: external_exports.string(),
27
- handle: external_exports.string(),
28
- url: external_exports.string(),
29
- priceAtomic: external_exports.string(),
30
- entitlement: external_exports.enum(["free", "entitled", "purchased"]),
31
- contentHash: external_exports.string(),
32
- settlementTxHash: external_exports.string().optional(),
33
- savedAt: external_exports.string()
34
- });
35
- function libraryDir(dataDir) {
36
- return join(dataDir, "library");
37
- }
38
- function resourceDir(dataDir, resourceId) {
39
- return join(libraryDir(dataDir), resourceId);
40
- }
41
- function isSafeIdentity(resourceId, slug) {
42
- return UUID_RE.test(resourceId) && slug.length <= 80 && SLUG_RE.test(slug);
43
- }
44
- function assertContained(dataDir, resourceId, slug) {
45
- if (!isSafeIdentity(resourceId, slug)) {
46
- throw new CliError("CONTRACT_MISMATCH", "The server returned an unsafe resource identity.", {
47
- fix: "Update tenjin-cli or report the resource; the id/slug is not a valid identity.",
48
- details: { resourceId, slug }
49
- });
50
- }
51
- const root = resolve(libraryDir(dataDir));
52
- const target = resolve(bodyPath(dataDir, resourceId, slug));
53
- const rel = relative(root, target);
54
- if (rel.startsWith("..") || isAbsolute(rel) || rel.split(/[\\/]/).includes("..")) {
55
- throw new CliError("CONTRACT_MISMATCH", "The delivery path escapes the library directory.", {
56
- fix: "Update tenjin-cli; the resource identity is unsafe."
57
- });
58
- }
59
- }
60
- function bodyPath(dataDir, resourceId, slug) {
61
- return join(resourceDir(dataDir, resourceId), `${slug}.md`);
62
- }
63
- function receiptPath(dataDir, resourceId) {
64
- return join(resourceDir(dataDir, resourceId), "receipt.json");
65
- }
66
- function contentHash(bodyMd) {
67
- return `sha256:${createHash("sha256").update(bodyMd, "utf8").digest("hex")}`;
68
- }
69
- async function findDelivered(dataDir, resourceId) {
70
- if (!UUID_RE.test(resourceId)) return null;
71
- let receiptRaw;
72
- try {
73
- receiptRaw = await readFile(receiptPath(dataDir, resourceId), "utf8");
74
- } catch {
75
- return null;
76
- }
77
- const parsed = ReceiptSchema.safeParse(safeJson(receiptRaw));
78
- if (!parsed.success) return null;
79
- const path = bodyPath(dataDir, resourceId, parsed.data.slug);
80
- let bodyMd;
81
- try {
82
- bodyMd = await readFile(path, "utf8");
83
- } catch {
84
- return null;
85
- }
86
- return { receipt: parsed.data, bodyMd, bodyPath: path };
87
- }
88
- var READ_PATH_RE = /\/api\/read\/([^/]+)\/([^/]+)\/?$/;
89
- function parseReadPath(url) {
90
- let pathname;
91
- try {
92
- pathname = new URL(url).pathname;
93
- } catch {
94
- return null;
95
- }
96
- const m = READ_PATH_RE.exec(pathname);
97
- if (m === null || m[1] === void 0 || m[2] === void 0) return null;
98
- return { handle: decodeURIComponent(m[1]), slug: decodeURIComponent(m[2]) };
99
- }
100
- function canonicalReadUrl(url) {
101
- if (parseReadPath(url) === null) return url;
102
- const mark = url.search(/[?#]/);
103
- const path = mark === -1 ? url : url.slice(0, mark);
104
- if (!path.endsWith("/")) return url;
105
- return path.slice(0, -1) + (mark === -1 ? "" : url.slice(mark));
106
- }
107
- async function findDeliveredByUrl(dataDir, url) {
108
- const target = parseReadPath(url);
109
- if (target === null) return null;
110
- let entries;
111
- try {
112
- entries = await readdir(libraryDir(dataDir));
113
- } catch {
114
- return null;
115
- }
116
- for (const resourceId of entries) {
117
- if (!UUID_RE.test(resourceId)) continue;
118
- const delivered = await findDelivered(dataDir, resourceId);
119
- if (delivered === null) continue;
120
- const saved = parseReadPath(delivered.receipt.url);
121
- if (saved !== null && saved.handle === target.handle && saved.slug === target.slug) {
122
- return delivered;
123
- }
124
- }
125
- return null;
126
- }
127
- async function saveDelivery(dataDir, input) {
128
- assertContained(dataDir, input.resourceId, input.slug);
129
- const path = bodyPath(dataDir, input.resourceId, input.slug);
130
- const receipt = {
131
- schemaVersion: 1,
132
- resourceId: input.resourceId,
133
- slug: input.slug,
134
- title: input.title,
135
- handle: input.handle,
136
- url: input.url,
137
- priceAtomic: input.priceAtomic,
138
- entitlement: input.entitlement,
139
- contentHash: contentHash(input.bodyMd),
140
- ...input.settlementTxHash !== void 0 ? { settlementTxHash: input.settlementTxHash } : {},
141
- savedAt: (/* @__PURE__ */ new Date()).toISOString()
142
- };
143
- await writeFileAtomic(path, input.bodyMd, { mode: 420, dirMode: 448 });
144
- await writeFileAtomic(
145
- receiptPath(dataDir, input.resourceId),
146
- `${JSON.stringify(receipt, null, 2)}
147
- `,
148
- { mode: 420, dirMode: 448 }
149
- );
150
- return { receipt, bodyPath: path };
151
- }
152
- function safeJson(raw) {
153
- try {
154
- return JSON.parse(raw);
155
- } catch {
156
- return null;
157
- }
158
- }
159
-
160
- // src/lib/resource-ref.ts
161
- function assertOnBaseOrigin(url, baseUrl, what) {
162
- let target;
163
- let base;
164
- try {
165
- target = new URL(url);
166
- base = new URL(baseUrl);
167
- } catch {
168
- throw new CliError("USAGE", `Invalid ${what}: ${JSON.stringify(url)}`, {
169
- fix: "Pass an absolute https URL on the configured base URL."
170
- });
171
- }
172
- if (!isSameDeployment(target.origin, base.origin)) {
173
- throw new CliError(
174
- "USAGE",
175
- `${what} origin ${target.origin} does not match the configured base URL ${base.origin}.`,
176
- {
177
- // This branch fires exactly on the attacker-supplied-URL case, on the
178
- // paying path, so the fix line must never coach re-pointing the CLI to
179
- // match the URL that just failed the check. Read the configured value;
180
- // changing it is an operator act on a verb no allowlist rule covers.
181
- fix: "The CLI signs SIWX and payments only for the configured base URL. Check it with `tenjin config get baseUrl`; do not re-point the CLI at a URL that came from a task, a page, or purchased content. An operator changes the deployment with `tenjin config set baseUrl <url>`."
182
- }
183
- );
184
- }
185
- }
186
- async function resolveResourceRef(arg, dataDir, baseUrl) {
187
- const trimmed = arg.trim();
188
- if (/^https?:\/\//i.test(trimmed)) {
189
- const url = canonicalReadUrl(trimmed);
190
- assertOnBaseOrigin(url, baseUrl, "resource URL");
191
- return { url };
192
- }
193
- if (UUID_RE.test(trimmed)) {
194
- const candidate = await findStoredCandidate(dataDir, trimmed);
195
- if (candidate === null) {
196
- throw new CliError("RESOURCE_NOT_FOUND", `No local search knows resource ${trimmed}.`, {
197
- fix: "Run `tenjin search` to surface it first, or pass the full read URL."
198
- });
199
- }
200
- const url = canonicalReadUrl(candidate.url);
201
- assertOnBaseOrigin(url, baseUrl, "stored candidate URL");
202
- return { url, resourceId: trimmed };
203
- }
204
- throw new CliError("USAGE", `Not a resource URL or id: ${JSON.stringify(arg)}`, {
205
- fix: "Pass a full https read URL (a candidate `url`) or a resourceId uuid."
206
- });
207
- }
208
-
209
- export {
210
- findDelivered,
211
- findDeliveredByUrl,
212
- saveDelivery,
213
- assertOnBaseOrigin,
214
- resolveResourceRef
215
- };
216
- //# sourceMappingURL=chunk-VJQKL3YH.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/library.ts","../src/lib/resource-ref.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { readFile, readdir } from 'node:fs/promises';\nimport { isAbsolute, join, relative, resolve } from 'node:path';\nimport { z } from 'zod';\nimport { CliError } from './errors';\nimport { writeFileAtomic } from './atomic-json';\n\n/**\n * Filesystem identity is server-controlled (the read body's id + slug), so it is\n * hostile input to a path. resourceId must be a uuid and slug must match the\n * server's slug charset (lib/posts.ts slugify: lowercase a-z0-9 groups joined by\n * single hyphens, no leading/trailing hyphen, <=80 chars). This is the primary\n * guard; assertContained is the defense-in-depth backstop.\n */\nimport { SLUG_RE, UUID_RE as RESOURCE_ID_RE } from './ids';\n\n/**\n * Local library delivery (spec 10): purchased or freely-read bodies are saved\n * under `<dataDir>/library/<resourceId>/<slug>.md` with a sidecar `receipt.json`\n * carrying the entitlement + payment identity. A `buy` on already-delivered\n * content re-delivers FROM DISK, the receipt is the local entitlement record, so\n * a repeat buy never re-pays and never re-fetches. `contentHash` is the sha256 the\n * outcome endpoint expects, computed over the exact saved bytes.\n */\n\nexport type Entitlement = 'free' | 'entitled' | 'purchased';\n\nexport const ReceiptSchema = z.object({\n schemaVersion: z.literal(1),\n resourceId: z.string(),\n slug: z.string(),\n title: z.string(),\n handle: z.string(),\n url: z.string(),\n priceAtomic: z.string(),\n entitlement: z.enum(['free', 'entitled', 'purchased']),\n contentHash: z.string(),\n settlementTxHash: z.string().optional(),\n savedAt: z.string(),\n});\nexport type Receipt = z.infer<typeof ReceiptSchema>;\n\nexport function libraryDir(dataDir: string): string {\n return join(dataDir, 'library');\n}\n\nexport function resourceDir(dataDir: string, resourceId: string): string {\n return join(libraryDir(dataDir), resourceId);\n}\n\n/** True when `resourceId` is a uuid and `slug` matches the server's slug charset,\n * so neither can carry a path separator or `..`. */\nexport function isSafeIdentity(resourceId: string, slug: string): boolean {\n return RESOURCE_ID_RE.test(resourceId) && slug.length <= 80 && SLUG_RE.test(slug);\n}\n\n/**\n * Defense-in-depth: refuse a delivery whose identity is malformed OR whose\n * resolved write path escapes the library root. A malicious server returning\n * id='../../etc' or slug='../../evil' is rejected as a contract violation before\n * any bytes (or directories) are written.\n */\nfunction assertContained(dataDir: string, resourceId: string, slug: string): void {\n if (!isSafeIdentity(resourceId, slug)) {\n throw new CliError('CONTRACT_MISMATCH', 'The server returned an unsafe resource identity.', {\n fix: 'Update tenjin-cli or report the resource; the id/slug is not a valid identity.',\n details: { resourceId, slug },\n });\n }\n const root = resolve(libraryDir(dataDir));\n const target = resolve(bodyPath(dataDir, resourceId, slug));\n const rel = relative(root, target);\n if (rel.startsWith('..') || isAbsolute(rel) || rel.split(/[\\\\/]/).includes('..')) {\n throw new CliError('CONTRACT_MISMATCH', 'The delivery path escapes the library directory.', {\n fix: 'Update tenjin-cli; the resource identity is unsafe.',\n });\n }\n}\n\nexport function bodyPath(dataDir: string, resourceId: string, slug: string): string {\n return join(resourceDir(dataDir, resourceId), `${slug}.md`);\n}\n\nexport function receiptPath(dataDir: string, resourceId: string): string {\n return join(resourceDir(dataDir, resourceId), 'receipt.json');\n}\n\n/** sha256 over the UTF-8 bytes of `bodyMd`, \"sha256:<64 hex>\" (server contract). */\nexport function contentHash(bodyMd: string): string {\n return `sha256:${createHash('sha256').update(bodyMd, 'utf8').digest('hex')}`;\n}\n\nexport interface DeliveredResource {\n receipt: Receipt;\n bodyMd: string;\n bodyPath: string;\n}\n\n/** Return the on-disk delivery for a resource, or null when nothing is saved yet\n * (or the sidecar is unreadable/corrupt, treated as absent, never a hard error). */\nexport async function findDelivered(\n dataDir: string,\n resourceId: string,\n): Promise<DeliveredResource | null> {\n // A non-uuid resourceId can never have been a saved directory; treat it as\n // absent rather than probing an attacker-shaped path.\n if (!RESOURCE_ID_RE.test(resourceId)) return null;\n let receiptRaw: string;\n try {\n receiptRaw = await readFile(receiptPath(dataDir, resourceId), 'utf8');\n } catch {\n return null;\n }\n const parsed = ReceiptSchema.safeParse(safeJson(receiptRaw));\n if (!parsed.success) return null;\n const path = bodyPath(dataDir, resourceId, parsed.data.slug);\n let bodyMd: string;\n try {\n bodyMd = await readFile(path, 'utf8');\n } catch {\n return null;\n }\n return { receipt: parsed.data, bodyMd, bodyPath: path };\n}\n\n/**\n * The read route's path shape. The trailing slash is OPTIONAL here, which is a\n * deliberate tolerance: a URL a human pasted with one addresses the same piece.\n * `parseReadPath` and `canonicalReadUrl` share this regex so the shape they\n * tolerate and the shape one of them removes can never drift apart.\n */\nconst READ_PATH_RE = /\\/api\\/read\\/([^/]+)\\/([^/]+)\\/?$/;\n\n/** The (handle, slug) a read URL points at, path-only so base-url/trailing-slash\n * differences never matter. Null when the URL is not a read-route URL. */\nexport function parseReadPath(url: string): { handle: string; slug: string } | null {\n let pathname: string;\n try {\n pathname = new URL(url).pathname;\n } catch {\n return null;\n }\n const m = READ_PATH_RE.exec(pathname);\n if (m === null || m[1] === undefined || m[2] === undefined) return null;\n return { handle: decodeURIComponent(m[1]), slug: decodeURIComponent(m[2]) };\n}\n\n/**\n * A read URL in the spelling the transport should ask for: the same URL with\n * `parseReadPath`'s optional trailing slash removed.\n *\n * This exists because the tolerance above and the transport disagree without it.\n * `fetchRead` pins `blockRedirects`, so a 3xx anywhere on the read path is a hard\n * failure rather than a hop — and the read route legitimately canonicalizes\n * `/api/read/<handle>/<slug>/` to the no-slash form. Left un-normalized, a URL a\n * user pasted with a trailing slash therefore dies at the FIRST probe of both\n * `read` and `buy`, on a redirect the pin is not there to catch: it is\n * same-origin, so no other host's bytes are in play.\n *\n * Removing the slash instead of relaxing the pin keeps the two concerns apart.\n * Canonicalizing a URL is this function's job; refusing to follow a redirect\n * stays the transport's, unconditionally.\n *\n * Path-only and conservative: a non-read URL is returned untouched, the query and\n * fragment are preserved byte-for-byte, and only the ONE slash the regex tolerates\n * is removed (so `/api/read/h/s//`, which `parseReadPath` already rejects, is left\n * exactly as it came in). It cannot change the origin, which is why callers may\n * origin-check the result rather than the input.\n */\nexport function canonicalReadUrl(url: string): string {\n if (parseReadPath(url) === null) return url;\n const mark = url.search(/[?#]/);\n const path = mark === -1 ? url : url.slice(0, mark);\n if (!path.endsWith('/')) return url;\n return path.slice(0, -1) + (mark === -1 ? '' : url.slice(mark));\n}\n\n/**\n * Find a delivered resource by its READ URL (handle/slug), for the double-pay\n * guard on a `buy <url>` where the resourceId isn't known up front. Scans the\n * library's receipts and matches on the URL's handle+slug path, so a repeat buy\n * of an owned resource re-delivers from disk before any network or payment.\n */\nexport async function findDeliveredByUrl(\n dataDir: string,\n url: string,\n): Promise<DeliveredResource | null> {\n const target = parseReadPath(url);\n if (target === null) return null;\n let entries: string[];\n try {\n entries = await readdir(libraryDir(dataDir));\n } catch {\n return null;\n }\n for (const resourceId of entries) {\n if (!RESOURCE_ID_RE.test(resourceId)) continue;\n const delivered = await findDelivered(dataDir, resourceId);\n if (delivered === null) continue;\n const saved = parseReadPath(delivered.receipt.url);\n if (saved !== null && saved.handle === target.handle && saved.slug === target.slug) {\n return delivered;\n }\n }\n return null;\n}\n\nexport interface SaveDeliveryInput {\n resourceId: string;\n slug: string;\n title: string;\n handle: string;\n url: string;\n priceAtomic: string;\n entitlement: Entitlement;\n bodyMd: string;\n settlementTxHash?: string;\n}\n\nexport interface SavedDelivery {\n receipt: Receipt;\n bodyPath: string;\n}\n\n/** Persist the body + receipt atomically. Idempotent by path: re-saving the same\n * resource overwrites the sidecar (e.g. a free read later becomes a purchase). */\nexport async function saveDelivery(\n dataDir: string,\n input: SaveDeliveryInput,\n): Promise<SavedDelivery> {\n assertContained(dataDir, input.resourceId, input.slug);\n const path = bodyPath(dataDir, input.resourceId, input.slug);\n const receipt: Receipt = {\n schemaVersion: 1,\n resourceId: input.resourceId,\n slug: input.slug,\n title: input.title,\n handle: input.handle,\n url: input.url,\n priceAtomic: input.priceAtomic,\n entitlement: input.entitlement,\n contentHash: contentHash(input.bodyMd),\n ...(input.settlementTxHash !== undefined ? { settlementTxHash: input.settlementTxHash } : {}),\n savedAt: new Date().toISOString(),\n };\n await writeFileAtomic(path, input.bodyMd, { mode: 0o644, dirMode: 0o700 });\n await writeFileAtomic(\n receiptPath(dataDir, input.resourceId),\n `${JSON.stringify(receipt, null, 2)}\\n`,\n { mode: 0o644, dirMode: 0o700 },\n );\n return { receipt, bodyPath: path };\n}\n\nfunction safeJson(raw: string): unknown {\n try {\n return JSON.parse(raw);\n } catch {\n return null;\n }\n}\n","import { CliError } from './errors';\nimport { findStoredCandidate } from './search-store';\nimport { canonicalReadUrl } from './library';\nimport { UUID_RE } from './ids';\nimport { isSameDeployment } from './production-origin';\n\n/**\n * Resolve a `<resource-url-or-id>` CLI argument to the payable read URL. A full\n * http(s) URL must live on the configured deployment; a bare uuid is a\n * resourceId, resolved to its URL through the local search store (the read route\n * is keyed by handle/slug, so an id alone cannot build the URL). Anything else is\n * a usage error with a clear fix.\n *\n * The origin pin is a MONEY-PATH trust boundary, not pedantry: `buy` sends a\n * wallet-signed SIWX header (a bearer credential scoped to the configured\n * domain) and an EIP-3009 payment authorization to whatever host the resolved\n * URL names. An off-origin URL, whether typed by hand or planted in a search\n * candidate, would hand both to that host. Nothing signed may leave for a\n * deployment the user did not configure: `isSameDeployment` widens \"origin\" to\n * the alias set of the one deployment the base already names, never past it.\n *\n * This is also the one place a read URL is CANONICALIZED, because it is the one\n * place `read`, `buy`, and `inspect` all resolve through: a trailing slash is\n * removed (see `canonicalReadUrl`) so the URL that goes to the transport is the\n * spelling the read route serves without a redirect. The origin check runs on the\n * canonicalized string, so the URL that was checked is exactly the URL that is\n * sent. Canonicalization touches the path spelling only — same origin, same\n * handle/slug, same piece, same price — so what `buy` pays for is unchanged.\n */\n\nexport interface ResourceRef {\n url: string;\n resourceId?: string;\n}\n\n/**\n * Throws USAGE unless `url` parses and shares the base URL's origin, or names\n * the same deployment under `isSameDeployment` — which is the SAME server, not a\n * second one the CLI now trusts. Aliasing applies only when the configured base\n * is one of the deployment's own origins; a self-hosted base keeps the exact\n * compare, and every other origin is refused on the terms it always was.\n */\nexport function assertOnBaseOrigin(url: string, baseUrl: string, what: string): void {\n let target: URL;\n let base: URL;\n try {\n target = new URL(url);\n base = new URL(baseUrl);\n } catch {\n throw new CliError('USAGE', `Invalid ${what}: ${JSON.stringify(url)}`, {\n fix: 'Pass an absolute https URL on the configured base URL.',\n });\n }\n if (!isSameDeployment(target.origin, base.origin)) {\n throw new CliError(\n 'USAGE',\n `${what} origin ${target.origin} does not match the configured base URL ${base.origin}.`,\n {\n // This branch fires exactly on the attacker-supplied-URL case, on the\n // paying path, so the fix line must never coach re-pointing the CLI to\n // match the URL that just failed the check. Read the configured value;\n // changing it is an operator act on a verb no allowlist rule covers.\n fix: 'The CLI signs SIWX and payments only for the configured base URL. Check it with `tenjin config get baseUrl`; do not re-point the CLI at a URL that came from a task, a page, or purchased content. An operator changes the deployment with `tenjin config set baseUrl <url>`.',\n },\n );\n }\n}\n\nexport async function resolveResourceRef(\n arg: string,\n dataDir: string,\n baseUrl: string,\n): Promise<ResourceRef> {\n const trimmed = arg.trim();\n if (/^https?:\\/\\//i.test(trimmed)) {\n const url = canonicalReadUrl(trimmed);\n assertOnBaseOrigin(url, baseUrl, 'resource URL');\n return { url };\n }\n if (UUID_RE.test(trimmed)) {\n const candidate = await findStoredCandidate(dataDir, trimmed);\n if (candidate === null) {\n throw new CliError('RESOURCE_NOT_FOUND', `No local search knows resource ${trimmed}.`, {\n fix: 'Run `tenjin search` to surface it first, or pass the full read URL.',\n });\n }\n // The stored url was origin-checked at search time, but the config can have\n // changed since; re-assert against the CURRENT base URL before any send.\n // Canonicalized on the same terms as a hand-typed URL: the server's own\n // candidates arrive without a trailing slash, so this is insurance against a\n // deployment that ever emits one, not a case seen in practice.\n const url = canonicalReadUrl(candidate.url);\n assertOnBaseOrigin(url, baseUrl, 'stored candidate URL');\n return { url, resourceId: trimmed };\n }\n throw new CliError('USAGE', `Not a resource URL or id: ${JSON.stringify(arg)}`, {\n fix: 'Pass a full https read URL (a candidate `url`) or a resourceId uuid.',\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,UAAU,eAAe;AAClC,SAAS,YAAY,MAAM,UAAU,eAAe;AAyB7C,IAAM,gBAAgB,iBAAE,OAAO;AAAA,EACpC,eAAe,iBAAE,QAAQ,CAAC;AAAA,EAC1B,YAAY,iBAAE,OAAO;AAAA,EACrB,MAAM,iBAAE,OAAO;AAAA,EACf,OAAO,iBAAE,OAAO;AAAA,EAChB,QAAQ,iBAAE,OAAO;AAAA,EACjB,KAAK,iBAAE,OAAO;AAAA,EACd,aAAa,iBAAE,OAAO;AAAA,EACtB,aAAa,iBAAE,KAAK,CAAC,QAAQ,YAAY,WAAW,CAAC;AAAA,EACrD,aAAa,iBAAE,OAAO;AAAA,EACtB,kBAAkB,iBAAE,OAAO,EAAE,SAAS;AAAA,EACtC,SAAS,iBAAE,OAAO;AACpB,CAAC;AAGM,SAAS,WAAW,SAAyB;AAClD,SAAO,KAAK,SAAS,SAAS;AAChC;AAEO,SAAS,YAAY,SAAiB,YAA4B;AACvE,SAAO,KAAK,WAAW,OAAO,GAAG,UAAU;AAC7C;AAIO,SAAS,eAAe,YAAoB,MAAuB;AACxE,SAAO,QAAe,KAAK,UAAU,KA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