tenjin-cli 0.1.0-alpha.3 → 0.1.0-alpha.30

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 (246) hide show
  1. package/NOTICE.md +54 -7
  2. package/README.md +149 -264
  3. package/dist/{_esm-FEASBWRP.js → _esm-CE7KNONL.js} +9 -10
  4. package/dist/alive-3J3CHOQP.js +21 -0
  5. package/dist/{ccip-NQXCEK2U.js → ccip-7RMRLAGV.js} +4 -4
  6. package/dist/{ccip-XR5NE5QK.js → ccip-NLCSCHKI.js} +5 -5
  7. package/dist/chunk-2SNUOHAT.js +75 -0
  8. package/dist/chunk-2SNUOHAT.js.map +1 -0
  9. package/dist/chunk-3O2BQIF6.js +2227 -0
  10. package/dist/chunk-3O2BQIF6.js.map +1 -0
  11. package/dist/{chunk-ZMHYXMO6.js → chunk-5IEP5EGE.js} +3 -3
  12. package/dist/chunk-5LJCEMFD.js +12700 -0
  13. package/dist/chunk-5LJCEMFD.js.map +1 -0
  14. package/dist/chunk-6W5GYG3W.js +128 -0
  15. package/dist/chunk-6W5GYG3W.js.map +1 -0
  16. package/dist/chunk-7EKYXMUO.js +7536 -0
  17. package/dist/chunk-7EKYXMUO.js.map +1 -0
  18. package/dist/chunk-7QKHZQKW.js +1680 -0
  19. package/dist/chunk-7QKHZQKW.js.map +1 -0
  20. package/dist/chunk-A36LQPHV.js +29 -0
  21. package/dist/chunk-A36LQPHV.js.map +1 -0
  22. package/dist/chunk-AEG2PXBP.js +192 -0
  23. package/dist/chunk-AEG2PXBP.js.map +1 -0
  24. package/dist/chunk-AKWGE6JQ.js +49 -0
  25. package/dist/chunk-AKWGE6JQ.js.map +1 -0
  26. package/dist/chunk-AWFUPKTM.js +238 -0
  27. package/dist/chunk-AWFUPKTM.js.map +1 -0
  28. package/dist/{chunk-UGX7YPX2.js → chunk-AWQPGIR6.js} +7 -9
  29. package/dist/{chunk-UGX7YPX2.js.map → chunk-AWQPGIR6.js.map} +1 -1
  30. package/dist/{chunk-5CLSD5YN.js → chunk-BPMWXTFX.js} +2 -2
  31. package/dist/chunk-EBVIKMCH.js +108 -0
  32. package/dist/chunk-EBVIKMCH.js.map +1 -0
  33. package/dist/{chunk-YALGASEU.js → chunk-EGELTSPU.js} +2 -2
  34. package/dist/{chunk-S3IGX57D.js → chunk-EL56RW2J.js} +166 -7237
  35. package/dist/chunk-EL56RW2J.js.map +1 -0
  36. package/dist/chunk-HE2MS4QO.js +256 -0
  37. package/dist/chunk-HE2MS4QO.js.map +1 -0
  38. package/dist/{chunk-CYOF7ROH.js → chunk-HPWO4O6S.js} +3 -3
  39. package/dist/chunk-IOODYAXL.js +324 -0
  40. package/dist/chunk-IOODYAXL.js.map +1 -0
  41. package/dist/chunk-JMM6YE7J.js +2174 -0
  42. package/dist/chunk-JMM6YE7J.js.map +1 -0
  43. package/dist/{chunk-QVX5MWJZ.js → chunk-JRGFKVAZ.js} +2 -2
  44. package/dist/{chunk-HIVZG55D.js → chunk-KG3D7FIF.js} +2 -2
  45. package/dist/chunk-KHE6L6TD.js +416 -0
  46. package/dist/chunk-KHE6L6TD.js.map +1 -0
  47. package/dist/chunk-KOGZDMHO.js +21 -0
  48. package/dist/chunk-KOGZDMHO.js.map +1 -0
  49. package/dist/chunk-KYFZTGMC.js +237 -0
  50. package/dist/chunk-KYFZTGMC.js.map +1 -0
  51. package/dist/chunk-LFZJM56J.js +159 -0
  52. package/dist/chunk-LFZJM56J.js.map +1 -0
  53. package/dist/chunk-LHHMV4GU.js +27 -0
  54. package/dist/chunk-LHHMV4GU.js.map +1 -0
  55. package/dist/{chunk-YBMMV4Y4.js → chunk-MEFB5KHA.js} +13 -5
  56. package/dist/chunk-MEFB5KHA.js.map +1 -0
  57. package/dist/{chunk-NCE5NSN6.js → chunk-N35E6CM2.js} +140 -10
  58. package/dist/chunk-N35E6CM2.js.map +1 -0
  59. package/dist/chunk-NZIP4PA2.js +114 -0
  60. package/dist/chunk-NZIP4PA2.js.map +1 -0
  61. package/dist/chunk-O2FRQ2L2.js +168 -0
  62. package/dist/chunk-O2FRQ2L2.js.map +1 -0
  63. package/dist/chunk-OK2TDZQU.js +404 -0
  64. package/dist/chunk-OK2TDZQU.js.map +1 -0
  65. package/dist/chunk-ORWL5BSN.js +269 -0
  66. package/dist/chunk-ORWL5BSN.js.map +1 -0
  67. package/dist/{chunk-Z6MFJV5Z.js → chunk-OSYTBCUC.js} +850 -499
  68. package/dist/chunk-OSYTBCUC.js.map +1 -0
  69. package/dist/chunk-P7LABKCW.js +90 -0
  70. package/dist/chunk-P7LABKCW.js.map +1 -0
  71. package/dist/chunk-PAYV4XUA.js +151 -0
  72. package/dist/chunk-PAYV4XUA.js.map +1 -0
  73. package/dist/{chunk-ZABPQJ3M.js → chunk-POUWHWID.js} +2 -2
  74. package/dist/chunk-QUVVWYJW.js +112 -0
  75. package/dist/chunk-QUVVWYJW.js.map +1 -0
  76. package/dist/chunk-RAULEAZ6.js +228 -0
  77. package/dist/chunk-RAULEAZ6.js.map +1 -0
  78. package/dist/chunk-S4SAZ7OD.js +30 -0
  79. package/dist/chunk-S4SAZ7OD.js.map +1 -0
  80. package/dist/chunk-SJLTEINJ.js +117 -0
  81. package/dist/chunk-SJLTEINJ.js.map +1 -0
  82. package/dist/chunk-SPAVAYSW.js +125 -0
  83. package/dist/chunk-SPAVAYSW.js.map +1 -0
  84. package/dist/chunk-TTBKWWTV.js +1605 -0
  85. package/dist/chunk-TTBKWWTV.js.map +1 -0
  86. package/dist/{chunk-RRN3YTK7.js → chunk-TTNESUPQ.js} +3 -3
  87. package/dist/chunk-U6YQ6FRI.js +378 -0
  88. package/dist/chunk-U6YQ6FRI.js.map +1 -0
  89. package/dist/chunk-VFMQTSXG.js +29 -0
  90. package/dist/chunk-VFMQTSXG.js.map +1 -0
  91. package/dist/chunk-VUFAK2LW.js +115 -0
  92. package/dist/chunk-VUFAK2LW.js.map +1 -0
  93. package/dist/chunk-VZGAONSJ.js +194 -0
  94. package/dist/chunk-VZGAONSJ.js.map +1 -0
  95. package/dist/{chunk-OYMYCW7J.js → chunk-WO5BJNIB.js} +682 -53
  96. package/dist/chunk-WO5BJNIB.js.map +1 -0
  97. package/dist/chunk-WVUSXNIE.js +39 -0
  98. package/dist/chunk-WVUSXNIE.js.map +1 -0
  99. package/dist/chunk-XKESD27X.js +10 -0
  100. package/dist/chunk-XKESD27X.js.map +1 -0
  101. package/dist/{chunk-HSDCI7OV.js → chunk-XZKD7DIF.js} +3 -3
  102. package/dist/{chunk-XJIW7USF.js → chunk-YFQOA5AU.js} +118 -9
  103. package/dist/chunk-YFQOA5AU.js.map +1 -0
  104. package/dist/chunk-YHKXNYTB.js +105 -0
  105. package/dist/chunk-YHKXNYTB.js.map +1 -0
  106. package/dist/{cli-SBXI5AMS.js → cli-O5SN7ZJ4.js} +382 -214
  107. package/dist/cli-O5SN7ZJ4.js.map +1 -0
  108. package/dist/config-OJQI27LT.js +45 -0
  109. package/dist/dist-3LOO6M4U.js +2842 -0
  110. package/dist/dist-3LOO6M4U.js.map +1 -0
  111. package/dist/doctor-IQQJHGGM.js +590 -0
  112. package/dist/doctor-IQQJHGGM.js.map +1 -0
  113. package/dist/env-proxy-XL4P73MZ.js +15 -0
  114. package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
  115. package/dist/fund-WEV6DMTD.js +365 -0
  116. package/dist/fund-WEV6DMTD.js.map +1 -0
  117. package/dist/hook-command-D2P3ILRV.js +32 -0
  118. package/dist/hosts/claude/.claude-plugin/marketplace.json +19 -0
  119. package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +14 -0
  120. package/dist/hosts/claude/tenjin/.mcp.json +12 -0
  121. package/dist/hosts/claude/tenjin/hooks/hooks.json +221 -0
  122. package/dist/index.js +21 -2
  123. package/dist/index.js.map +1 -1
  124. package/dist/install-TUCRF32I.js +60 -0
  125. package/dist/install-identity-WHPNMNMQ.js +26 -0
  126. package/dist/install-wallet-MA27FTQ5.js +113 -0
  127. package/dist/install-wallet-MA27FTQ5.js.map +1 -0
  128. package/dist/mcp-QML7ZMPH.js +13427 -0
  129. package/dist/mcp-QML7ZMPH.js.map +1 -0
  130. package/dist/package-LGKYOEPV.js +37 -0
  131. package/dist/package-LGKYOEPV.js.map +1 -0
  132. package/dist/paths-POPTXJO6.js +61 -0
  133. package/dist/paths-POPTXJO6.js.map +1 -0
  134. package/dist/pay-2C2UBBXJ.js +51 -0
  135. package/dist/pay-2C2UBBXJ.js.map +1 -0
  136. package/dist/payments-C44QUFXU.js +106 -0
  137. package/dist/payments-C44QUFXU.js.map +1 -0
  138. package/dist/redact-6W23GGJC.js +15 -0
  139. package/dist/redact-6W23GGJC.js.map +1 -0
  140. package/dist/{secp256k1-N3ZHU7LB.js → secp256k1-ZZZT2CAX.js} +3 -3
  141. package/dist/secp256k1-ZZZT2CAX.js.map +1 -0
  142. package/dist/send-KVJX4XIR.js +222 -0
  143. package/dist/send-KVJX4XIR.js.map +1 -0
  144. package/dist/status-S7C3WMSH.js +115 -0
  145. package/dist/status-S7C3WMSH.js.map +1 -0
  146. package/dist/status-line-YR2T5HC4.js +86 -0
  147. package/dist/status-line-YR2T5HC4.js.map +1 -0
  148. package/dist/uninstall-HY6LKIIT.js +149 -0
  149. package/dist/uninstall-HY6LKIIT.js.map +1 -0
  150. package/dist/update-OJV22LR3.js +36 -0
  151. package/dist/update-OJV22LR3.js.map +1 -0
  152. package/dist/usdc-JK4RRFFQ.js +39 -0
  153. package/dist/usdc-JK4RRFFQ.js.map +1 -0
  154. package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js → viemAdapter-By13KInL-X2VY6CY3.js} +5 -5
  155. package/dist/viemAdapter-By13KInL-X2VY6CY3.js.map +1 -0
  156. package/dist/wallet-PD2IMZDU.js +39 -0
  157. package/dist/wallet-PD2IMZDU.js.map +1 -0
  158. package/dist/wallet-kdf-worker.mjs +980 -0
  159. package/docs/agent-permissions.md +180 -0
  160. package/docs/safety-model.md +59 -0
  161. package/docs/troubleshooting.md +13 -0
  162. package/package.json +28 -19
  163. package/LICENSE +0 -21
  164. package/dist/buy-EE6SEXP6.js +0 -1598
  165. package/dist/buy-EE6SEXP6.js.map +0 -1
  166. package/dist/candidate-ERMSYYQZ.js +0 -127
  167. package/dist/candidate-ERMSYYQZ.js.map +0 -1
  168. package/dist/chunk-3OV7E5G5.js +0 -18
  169. package/dist/chunk-3OV7E5G5.js.map +0 -1
  170. package/dist/chunk-4ONXEEQL.js +0 -152
  171. package/dist/chunk-4ONXEEQL.js.map +0 -1
  172. package/dist/chunk-662MSGZB.js +0 -286
  173. package/dist/chunk-662MSGZB.js.map +0 -1
  174. package/dist/chunk-7KUW4MJD.js +0 -59
  175. package/dist/chunk-7KUW4MJD.js.map +0 -1
  176. package/dist/chunk-AWPAWHNX.js +0 -333
  177. package/dist/chunk-AWPAWHNX.js.map +0 -1
  178. package/dist/chunk-DXTQ3CSI.js +0 -171
  179. package/dist/chunk-DXTQ3CSI.js.map +0 -1
  180. package/dist/chunk-ESPNTPQ2.js +0 -207
  181. package/dist/chunk-ESPNTPQ2.js.map +0 -1
  182. package/dist/chunk-FJPLRISB.js +0 -79
  183. package/dist/chunk-FJPLRISB.js.map +0 -1
  184. package/dist/chunk-GO75V3NZ.js +0 -160
  185. package/dist/chunk-GO75V3NZ.js.map +0 -1
  186. package/dist/chunk-JPHG2JW3.js +0 -96
  187. package/dist/chunk-JPHG2JW3.js.map +0 -1
  188. package/dist/chunk-MUBUQVC3.js +0 -67
  189. package/dist/chunk-MUBUQVC3.js.map +0 -1
  190. package/dist/chunk-NCE5NSN6.js.map +0 -1
  191. package/dist/chunk-OYMYCW7J.js.map +0 -1
  192. package/dist/chunk-RY4XKNV3.js +0 -140
  193. package/dist/chunk-RY4XKNV3.js.map +0 -1
  194. package/dist/chunk-S3IGX57D.js.map +0 -1
  195. package/dist/chunk-TLCMMYLY.js +0 -126
  196. package/dist/chunk-TLCMMYLY.js.map +0 -1
  197. package/dist/chunk-UO22YNY4.js +0 -69
  198. package/dist/chunk-UO22YNY4.js.map +0 -1
  199. package/dist/chunk-XHC6FCGZ.js +0 -261
  200. package/dist/chunk-XHC6FCGZ.js.map +0 -1
  201. package/dist/chunk-XJIW7USF.js.map +0 -1
  202. package/dist/chunk-YBMMV4Y4.js.map +0 -1
  203. package/dist/chunk-YN5SHIXQ.js +0 -126
  204. package/dist/chunk-YN5SHIXQ.js.map +0 -1
  205. package/dist/chunk-Z52RA3NC.js +0 -137
  206. package/dist/chunk-Z52RA3NC.js.map +0 -1
  207. package/dist/chunk-Z6MFJV5Z.js.map +0 -1
  208. package/dist/cli-SBXI5AMS.js.map +0 -1
  209. package/dist/config-VELDKLHY.js +0 -21
  210. package/dist/doctor-T3KWNNP2.js +0 -20
  211. package/dist/inspect-LMKOXE4Y.js +0 -96
  212. package/dist/inspect-LMKOXE4Y.js.map +0 -1
  213. package/dist/install-LEX3ENQ6.js +0 -387
  214. package/dist/install-LEX3ENQ6.js.map +0 -1
  215. package/dist/lookup-ZPN2Q67N.js +0 -129
  216. package/dist/lookup-ZPN2Q67N.js.map +0 -1
  217. package/dist/outcome-N7TAK6WR.js +0 -66
  218. package/dist/outcome-N7TAK6WR.js.map +0 -1
  219. package/dist/publish-BKBQQAW4.js +0 -1478
  220. package/dist/publish-BKBQQAW4.js.map +0 -1
  221. package/dist/usdc-JIAJW4SV.js +0 -22
  222. package/dist/wallet-CWEMYVIH.js +0 -179
  223. package/dist/wallet-CWEMYVIH.js.map +0 -1
  224. package/dist/wallet-PA54CRBL.js +0 -30
  225. package/skills/tenjin/SKILL.md +0 -199
  226. package/skills/tenjin-publish/SKILL.md +0 -111
  227. package/skills/tenjin-search/SKILL.md +0 -133
  228. /package/dist/{_esm-FEASBWRP.js.map → _esm-CE7KNONL.js.map} +0 -0
  229. /package/dist/{ccip-NQXCEK2U.js.map → alive-3J3CHOQP.js.map} +0 -0
  230. /package/dist/{ccip-XR5NE5QK.js.map → ccip-7RMRLAGV.js.map} +0 -0
  231. /package/dist/{config-VELDKLHY.js.map → ccip-NLCSCHKI.js.map} +0 -0
  232. /package/dist/{chunk-ZMHYXMO6.js.map → chunk-5IEP5EGE.js.map} +0 -0
  233. /package/dist/{chunk-5CLSD5YN.js.map → chunk-BPMWXTFX.js.map} +0 -0
  234. /package/dist/{chunk-YALGASEU.js.map → chunk-EGELTSPU.js.map} +0 -0
  235. /package/dist/{chunk-CYOF7ROH.js.map → chunk-HPWO4O6S.js.map} +0 -0
  236. /package/dist/{chunk-QVX5MWJZ.js.map → chunk-JRGFKVAZ.js.map} +0 -0
  237. /package/dist/{chunk-HIVZG55D.js.map → chunk-KG3D7FIF.js.map} +0 -0
  238. /package/dist/{chunk-ZABPQJ3M.js.map → chunk-POUWHWID.js.map} +0 -0
  239. /package/dist/{chunk-RRN3YTK7.js.map → chunk-TTNESUPQ.js.map} +0 -0
  240. /package/dist/{chunk-HSDCI7OV.js.map → chunk-XZKD7DIF.js.map} +0 -0
  241. /package/dist/{doctor-T3KWNNP2.js.map → config-OJQI27LT.js.map} +0 -0
  242. /package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js.map → env-proxy-XL4P73MZ.js.map} +0 -0
  243. /package/dist/{secp256k1-N3ZHU7LB.js.map → ethersCompat-Df4a6QIZ-THAVUGIJ.js.map} +0 -0
  244. /package/dist/{usdc-JIAJW4SV.js.map → hook-command-D2P3ILRV.js.map} +0 -0
  245. /package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js.map → install-TUCRF32I.js.map} +0 -0
  246. /package/dist/{wallet-PA54CRBL.js.map → install-identity-WHPNMNMQ.js.map} +0 -0
@@ -1,127 +0,0 @@
1
- import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- createCandidate,
4
- dropCandidate,
5
- listCandidates
6
- } from "./chunk-TLCMMYLY.js";
7
- import {
8
- UUID_RE
9
- } from "./chunk-3OV7E5G5.js";
10
- import {
11
- sanitizeForTerminal
12
- } from "./chunk-Z52RA3NC.js";
13
- import {
14
- pathExists
15
- } from "./chunk-GO75V3NZ.js";
16
- import "./chunk-ESPNTPQ2.js";
17
- import "./chunk-2I4QTOLB.js";
18
- import "./chunk-UO22YNY4.js";
19
- import "./chunk-MUBUQVC3.js";
20
- import {
21
- CliError
22
- } from "./chunk-OYMYCW7J.js";
23
- import "./chunk-ZXTAQYNA.js";
24
-
25
- // src/commands/candidate.ts
26
- import { readFile } from "fs/promises";
27
- import { dirname, join, resolve } from "path";
28
- async function runCandidateAdd(args, ctx, deps = {}) {
29
- if (!UUID_RE.test(args.lookupId)) {
30
- throw new CliError("USAGE", `Invalid --lookup-id: ${JSON.stringify(args.lookupId)}.`, {
31
- fix: "Pass the lookupId from a prior `tenjin lookup` (a uuid)."
32
- });
33
- }
34
- if (args.question !== void 0 && args.question.length > 200) {
35
- throw new CliError("USAGE", "A candidate --question is at most 200 characters.", {
36
- fix: "Shorten the question to 200 characters or fewer."
37
- });
38
- }
39
- let draft;
40
- try {
41
- draft = await readFile(args.file, "utf8");
42
- } catch (err) {
43
- throw new CliError("USAGE", `Cannot read draft file ${JSON.stringify(args.file)}.`, {
44
- fix: "Pass a path to a readable Markdown file.",
45
- cause: err
46
- });
47
- }
48
- const cwd = deps.cwd ?? process.cwd();
49
- const sourceProject = await repoRootOrCwd(cwd);
50
- const created = (deps.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
51
- const record = await createCandidate(ctx.dataDir, {
52
- draft,
53
- lookupId: args.lookupId,
54
- ...args.question !== void 0 ? { question: args.question } : {},
55
- created,
56
- sourceProject
57
- });
58
- return {
59
- data: {
60
- id: record.id,
61
- path: record.dir,
62
- lookupId: record.meta.lookupId,
63
- ...record.meta.question !== void 0 ? { question: record.meta.question } : {},
64
- created: record.meta.created,
65
- sourceProject: record.meta.sourceProject
66
- },
67
- humanLines: [`Parked candidate ${record.id}`, ` ${record.dir}`]
68
- };
69
- }
70
- async function runCandidateList(ctx, deps = {}) {
71
- const now = deps.now?.() ?? /* @__PURE__ */ new Date();
72
- const records = await listCandidates(ctx.dataDir);
73
- const candidates = records.map((r) => ({
74
- id: r.id,
75
- lookupId: r.meta.lookupId,
76
- ...r.meta.question !== void 0 ? { question: r.meta.question } : {},
77
- created: r.meta.created,
78
- sourceProject: r.meta.sourceProject,
79
- path: r.dir
80
- }));
81
- const humanLines = records.length === 0 ? ["No pending candidates."] : records.map((r) => {
82
- const q = r.meta.question !== void 0 ? sanitizeForTerminal(r.meta.question) : "(no question)";
83
- return `${r.id} ${humanizeAge(r.meta.created, now)} ${q} [${sanitizeForTerminal(
84
- r.meta.sourceProject
85
- )}]`;
86
- });
87
- return { data: { candidates }, humanLines };
88
- }
89
- async function runCandidateDrop(args, ctx) {
90
- const dropped = await dropCandidate(ctx.dataDir, args.id);
91
- if (!dropped) {
92
- throw new CliError("USAGE", `No candidate with id ${JSON.stringify(args.id)}.`, {
93
- fix: "Run `tenjin candidate list` to see pending candidate ids."
94
- });
95
- }
96
- return {
97
- data: { id: args.id, dropped: true },
98
- humanLines: [`Dropped candidate ${args.id}.`]
99
- };
100
- }
101
- async function repoRootOrCwd(cwd) {
102
- let dir = resolve(cwd);
103
- for (; ; ) {
104
- if (await pathExists(join(dir, ".git"))) return dir;
105
- const parent = dirname(dir);
106
- if (parent === dir) return resolve(cwd);
107
- dir = parent;
108
- }
109
- }
110
- var MINUTE = 6e4;
111
- var HOUR = 60 * MINUTE;
112
- var DAY = 24 * HOUR;
113
- function humanizeAge(iso, now) {
114
- const then = Date.parse(iso);
115
- if (Number.isNaN(then)) return "just now";
116
- const ms = now.getTime() - then;
117
- if (ms < MINUTE) return "just now";
118
- if (ms < HOUR) return `${Math.floor(ms / MINUTE)}m ago`;
119
- if (ms < DAY) return `${Math.floor(ms / HOUR)}h ago`;
120
- return `${Math.floor(ms / DAY)}d ago`;
121
- }
122
- export {
123
- runCandidateAdd,
124
- runCandidateDrop,
125
- runCandidateList
126
- };
127
- //# sourceMappingURL=candidate-ERMSYYQZ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/candidate.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { dirname, join, resolve } from 'node:path';\nimport { CliError } from '../lib/errors';\nimport { createCandidate, dropCandidate, listCandidates } from '../lib/candidate-store';\nimport { UUID_RE } from '../lib/ids';\nimport { sanitizeForTerminal } from '../lib/output';\nimport { pathExists } from '../lib/settings';\nimport type { CommandContext, CommandResult } from '../context';\n\n/**\n * `tenjin candidate [add|list|drop]`: the D40 local store of parked publish\n * drafts. Entirely offline — a candidate never touches the network and never\n * uploads; only a later `tenjin publish --candidate <id>` sends it, under the\n * D38 consent scan. This module owns the command surface; lib/candidate-store.ts\n * owns the on-disk custody (0700 dirs, 0600 files, atomic meta commit).\n */\n\nexport interface CandidateAddArgs {\n file: string;\n lookupId: string;\n question?: string;\n}\n\nexport interface CandidateDeps {\n /** Clock seam so list ordering / age tests are deterministic. */\n now?: () => Date;\n /** cwd seam so sourceProject discovery is testable against a temp tree. */\n cwd?: string;\n}\n\nexport async function runCandidateAdd(\n args: CandidateAddArgs,\n ctx: CommandContext,\n deps: CandidateDeps = {},\n): Promise<CommandResult> {\n if (!UUID_RE.test(args.lookupId)) {\n throw new CliError('USAGE', `Invalid --lookup-id: ${JSON.stringify(args.lookupId)}.`, {\n fix: 'Pass the lookupId from a prior `tenjin lookup` (a uuid).',\n });\n }\n // Cap the question at the server's questionsAnswered item bound (200) at PARK\n // time, so a candidate can never be born unpublishable — it prefills the card's\n // questionsAnswered, which publish would otherwise reject only at write time.\n if (args.question !== undefined && args.question.length > 200) {\n throw new CliError('USAGE', 'A candidate --question is at most 200 characters.', {\n fix: 'Shorten the question to 200 characters or fewer.',\n });\n }\n\n let draft: string;\n try {\n draft = await readFile(args.file, 'utf8');\n } catch (err) {\n throw new CliError('USAGE', `Cannot read draft file ${JSON.stringify(args.file)}.`, {\n fix: 'Pass a path to a readable Markdown file.',\n cause: err,\n });\n }\n\n const cwd = deps.cwd ?? process.cwd();\n const sourceProject = await repoRootOrCwd(cwd);\n const created = (deps.now?.() ?? new Date()).toISOString();\n\n const record = await createCandidate(ctx.dataDir, {\n draft,\n lookupId: args.lookupId,\n ...(args.question !== undefined ? { question: args.question } : {}),\n created,\n sourceProject,\n });\n\n return {\n data: {\n id: record.id,\n path: record.dir,\n lookupId: record.meta.lookupId,\n ...(record.meta.question !== undefined ? { question: record.meta.question } : {}),\n created: record.meta.created,\n sourceProject: record.meta.sourceProject,\n },\n humanLines: [`Parked candidate ${record.id}`, ` ${record.dir}`],\n };\n}\n\nexport async function runCandidateList(\n ctx: CommandContext,\n deps: CandidateDeps = {},\n): Promise<CommandResult> {\n const now = deps.now?.() ?? new Date();\n const records = await listCandidates(ctx.dataDir);\n\n const candidates = records.map((r) => ({\n id: r.id,\n lookupId: r.meta.lookupId,\n ...(r.meta.question !== undefined ? { question: r.meta.question } : {}),\n created: r.meta.created,\n sourceProject: r.meta.sourceProject,\n path: r.dir,\n }));\n\n const humanLines =\n records.length === 0\n ? ['No pending candidates.']\n : records.map((r) => {\n const q =\n r.meta.question !== undefined ? sanitizeForTerminal(r.meta.question) : '(no question)';\n return `${r.id} ${humanizeAge(r.meta.created, now)} ${q} [${sanitizeForTerminal(\n r.meta.sourceProject,\n )}]`;\n });\n\n return { data: { candidates }, humanLines };\n}\n\nexport async function runCandidateDrop(\n args: { id: string },\n ctx: CommandContext,\n): Promise<CommandResult> {\n const dropped = await dropCandidate(ctx.dataDir, args.id);\n if (!dropped) {\n throw new CliError('USAGE', `No candidate with id ${JSON.stringify(args.id)}.`, {\n fix: 'Run `tenjin candidate list` to see pending candidate ids.',\n });\n }\n return {\n data: { id: args.id, dropped: true },\n humanLines: [`Dropped candidate ${args.id}.`],\n };\n}\n\n/**\n * The project a candidate was parked from: the nearest ancestor holding a `.git`\n * (inclusive), or the cwd when the add did not run inside a repo. Mirrors the\n * repo-root walk settings.ts uses to bound the `.tenjin.json` search.\n */\nasync function repoRootOrCwd(cwd: string): Promise<string> {\n let dir = resolve(cwd);\n for (;;) {\n if (await pathExists(join(dir, '.git'))) return dir;\n const parent = dirname(dir);\n if (parent === dir) return resolve(cwd);\n dir = parent;\n }\n}\n\nconst MINUTE = 60_000;\nconst HOUR = 60 * MINUTE;\nconst DAY = 24 * HOUR;\n\n/**\n * Compact relative age for the human list (\"just now\", \"5m ago\", \"3d ago\"). A\n * future or unparseable timestamp degrades to \"just now\" rather than throwing;\n * the ISO value is always carried verbatim in the JSON data for machines.\n */\nfunction humanizeAge(iso: string, now: Date): string {\n const then = Date.parse(iso);\n if (Number.isNaN(then)) return 'just now';\n const ms = now.getTime() - then;\n if (ms < MINUTE) return 'just now';\n if (ms < HOUR) return `${Math.floor(ms / MINUTE)}m ago`;\n if (ms < DAY) return `${Math.floor(ms / HOUR)}h ago`;\n return `${Math.floor(ms / DAY)}d ago`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,SAAS,MAAM,eAAe;AA6BvC,eAAsB,gBACpB,MACA,KACA,OAAsB,CAAC,GACC;AACxB,MAAI,CAAC,QAAQ,KAAK,KAAK,QAAQ,GAAG;AAChC,UAAM,IAAI,SAAS,SAAS,wBAAwB,KAAK,UAAU,KAAK,QAAQ,CAAC,KAAK;AAAA,MACpF,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AAIA,MAAI,KAAK,aAAa,UAAa,KAAK,SAAS,SAAS,KAAK;AAC7D,UAAM,IAAI,SAAS,SAAS,qDAAqD;AAAA,MAC/E,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AAEA,MAAI;AACJ,MAAI;AACF,YAAQ,MAAM,SAAS,KAAK,MAAM,MAAM;AAAA,EAC1C,SAAS,KAAK;AACZ,UAAM,IAAI,SAAS,SAAS,0BAA0B,KAAK,UAAU,KAAK,IAAI,CAAC,KAAK;AAAA,MAClF,KAAK;AAAA,MACL,OAAO;AAAA,IACT,CAAC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AO,GAAG,KAAK,MAAM,KAAK,GAAG,CAAC;AAChC;","names":[]}
@@ -1,18 +0,0 @@
1
- import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
-
3
- // src/lib/ids.ts
4
- import { randomUUID } from "crypto";
5
- var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
6
- var SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
7
- var ATOMIC_RE = /^\d{1,39}$/;
8
- function newId() {
9
- return randomUUID();
10
- }
11
-
12
- export {
13
- UUID_RE,
14
- SLUG_RE,
15
- ATOMIC_RE,
16
- newId
17
- };
18
- //# sourceMappingURL=chunk-3OV7E5G5.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/ids.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\n/**\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\n/**\n * Mint a fresh opaque id for a locally-created entity (a parked candidate). A v4\n * uuid: the same shape a lookupId takes, so UUID_RE validates it and a `drop\n * <id>` argument that reaches a filesystem path can't traverse out of the store.\n */\nexport function newId(): string {\n return randomUUID();\n}\n"],"mappings":";;;AAAA,SAAS,kBAAkB;AASpB,IAAM,UAAU;AAChB,IAAM,UAAU;AAEhB,IAAM,YAAY;AAOlB,SAAS,QAAgB;AAC9B,SAAO,WAAW;AACpB;","names":[]}
@@ -1,152 +0,0 @@
1
- import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- package_default
4
- } from "./chunk-FJPLRISB.js";
5
-
6
- // src/lib/http.ts
7
- async function fetchJson(url, opts) {
8
- const doFetch = opts.fetchImpl ?? fetch;
9
- const controller = new AbortController();
10
- let timedOut = false;
11
- const timer = setTimeout(() => {
12
- timedOut = true;
13
- controller.abort();
14
- }, opts.timeoutMs);
15
- try {
16
- let res;
17
- try {
18
- res = await doFetch(url, {
19
- signal: controller.signal,
20
- ...opts.headers !== void 0 ? { headers: opts.headers } : {}
21
- });
22
- } catch (err) {
23
- return timedOut ? timeoutFailure(url, opts.timeoutMs) : { ok: false, kind: "network", message: `Request to ${url} failed: ${errorMessage(err)}` };
24
- }
25
- const requestId = res.headers.get("x-request-id") ?? void 0;
26
- if (!res.ok) {
27
- return {
28
- ok: false,
29
- kind: "http",
30
- status: res.status,
31
- ...requestId !== void 0 ? { requestId } : {},
32
- message: `Request to ${url} failed with status ${res.status}`
33
- };
34
- }
35
- let json;
36
- try {
37
- json = await res.json();
38
- } catch (err) {
39
- if (timedOut) return timeoutFailure(url, opts.timeoutMs);
40
- if (err instanceof SyntaxError) {
41
- return {
42
- ok: false,
43
- kind: "invalid-json",
44
- status: res.status,
45
- ...requestId !== void 0 ? { requestId } : {},
46
- message: `Response from ${url} was not valid JSON`
47
- };
48
- }
49
- return {
50
- ok: false,
51
- kind: "network",
52
- status: res.status,
53
- ...requestId !== void 0 ? { requestId } : {},
54
- message: `Request to ${url} failed while reading the response body: ${errorMessage(err)}`
55
- };
56
- }
57
- return {
58
- ok: true,
59
- status: res.status,
60
- json,
61
- ...requestId !== void 0 ? { requestId } : {}
62
- };
63
- } finally {
64
- clearTimeout(timer);
65
- }
66
- }
67
- function timeoutFailure(url, timeoutMs) {
68
- return {
69
- ok: false,
70
- kind: "timeout",
71
- message: `Request to ${url} timed out after ${timeoutMs}ms`
72
- };
73
- }
74
- async function httpRequest(url, opts) {
75
- const doFetch = opts.fetchImpl ?? fetch;
76
- const controller = new AbortController();
77
- let timedOut = false;
78
- const timer = setTimeout(() => {
79
- timedOut = true;
80
- controller.abort();
81
- }, opts.timeoutMs);
82
- try {
83
- const headers = { ...opts.headers ?? {} };
84
- let body;
85
- if (opts.jsonBody !== void 0) {
86
- body = JSON.stringify(opts.jsonBody);
87
- headers["content-type"] = "application/json";
88
- }
89
- if (opts.method === "POST" || body !== void 0) headers["accept"] ??= "application/json";
90
- let res;
91
- try {
92
- res = await doFetch(url, {
93
- method: opts.method ?? "GET",
94
- headers,
95
- body,
96
- signal: controller.signal
97
- });
98
- } catch (err) {
99
- return timedOut ? timeoutFailure(url, opts.timeoutMs) : { ok: false, kind: "network", message: `Request to ${url} failed: ${errorMessage(err)}` };
100
- }
101
- const requestId = res.headers.get("x-request-id") ?? void 0;
102
- let text;
103
- try {
104
- text = await res.text();
105
- } catch (err) {
106
- if (timedOut) return timeoutFailure(url, opts.timeoutMs);
107
- return {
108
- ok: false,
109
- kind: "network",
110
- status: res.status,
111
- ...requestId !== void 0 ? { requestId } : {},
112
- message: `Request to ${url} failed while reading the response body: ${errorMessage(err)}`
113
- };
114
- }
115
- let json;
116
- if (text.length > 0) {
117
- try {
118
- json = JSON.parse(text);
119
- } catch {
120
- json = void 0;
121
- }
122
- }
123
- return {
124
- ok: true,
125
- status: res.status,
126
- header: (name) => res.headers.get(name) ?? void 0,
127
- json,
128
- ...requestId !== void 0 ? { requestId } : {}
129
- };
130
- } finally {
131
- clearTimeout(timer);
132
- }
133
- }
134
- function errorMessage(err) {
135
- return err instanceof Error ? err.message : String(err);
136
- }
137
-
138
- // src/lib/client-meta.ts
139
- var CLIENT_HEADER = `tenjin-cli/${package_default.version}`;
140
-
141
- // src/lib/url.ts
142
- function trimSlash(url) {
143
- return url.replace(/\/+$/, "");
144
- }
145
-
146
- export {
147
- fetchJson,
148
- httpRequest,
149
- CLIENT_HEADER,
150
- trimSlash
151
- };
152
- //# sourceMappingURL=chunk-4ONXEEQL.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/http.ts","../src/lib/client-meta.ts","../src/lib/url.ts"],"sourcesContent":["import { CliError } from './errors';\n\n/**\n * The single JSON client the whole CLI grows on: `doctor` uses it in B1, `lookup`\n * reuses it in B2. It never throws on a transport/protocol failure — it returns a\n * discriminated result so callers decide how each failure class maps to a check\n * or an error. `fetchImpl` is injectable so tests never touch the network.\n */\nexport interface FetchJsonOptions {\n /** Abort the request after this many milliseconds. */\n timeoutMs: number;\n /** Override global fetch (tests inject a stub returning canned Responses). */\n fetchImpl?: typeof fetch;\n /** Optional request headers (doctor sends the X-Tenjin-Client label). */\n headers?: Record<string, string>;\n}\n\n/** A successful 2xx whose body parsed as JSON. */\nexport interface FetchJsonSuccess {\n ok: true;\n status: number;\n json: unknown;\n /** The server's `x-request-id`, when it sent one — useful in error reports. */\n requestId?: string;\n}\n\n/**\n * A failed request, tagged by class so the caller maps it deliberately:\n * `network`/`timeout` (never reached the server or no answer), `http` (a non-2xx\n * status), `invalid-json` (2xx but the body was not JSON).\n */\nexport interface FetchJsonFailure {\n ok: false;\n kind: 'network' | 'timeout' | 'http' | 'invalid-json';\n status?: number;\n requestId?: string;\n message: string;\n}\n\nexport type FetchJsonResult = FetchJsonSuccess | FetchJsonFailure;\n\nexport async function fetchJson(url: string, opts: FetchJsonOptions): Promise<FetchJsonResult> {\n const doFetch = opts.fetchImpl ?? fetch;\n const controller = new AbortController();\n let timedOut = false;\n // The timer stays armed until the body is fully consumed (cleared in the outer\n // finally), so a server that sends headers then stalls the body still trips the\n // deadline instead of hanging forever on res.json().\n const timer = setTimeout(() => {\n timedOut = true;\n controller.abort();\n }, opts.timeoutMs);\n\n try {\n let res: Response;\n try {\n res = await doFetch(url, {\n signal: controller.signal,\n ...(opts.headers !== undefined ? { headers: opts.headers } : {}),\n });\n } catch (err) {\n // A timeout is a network failure the AbortController induced; distinguish it\n // from an organic one so the caller can say \"timed out\" rather than a raw\n // AbortError message.\n return timedOut\n ? timeoutFailure(url, opts.timeoutMs)\n : { ok: false, kind: 'network', message: `Request to ${url} failed: ${errorMessage(err)}` };\n }\n\n const requestId = res.headers.get('x-request-id') ?? undefined;\n\n if (!res.ok) {\n return {\n ok: false,\n kind: 'http',\n status: res.status,\n ...(requestId !== undefined ? { requestId } : {}),\n message: `Request to ${url} failed with status ${res.status}`,\n };\n }\n\n let json: unknown;\n try {\n json = await res.json();\n } catch (err) {\n // The body read can fail three ways. A timeout wins first: the abort fires\n // synchronously with `timedOut`, so any abort-induced rejection here is our\n // deadline. Otherwise a SyntaxError is a genuine parse failure (invalid\n // JSON); anything else is a transport failure mid-body (network).\n if (timedOut) return timeoutFailure(url, opts.timeoutMs);\n if (err instanceof SyntaxError) {\n return {\n ok: false,\n kind: 'invalid-json',\n status: res.status,\n ...(requestId !== undefined ? { requestId } : {}),\n message: `Response from ${url} was not valid JSON`,\n };\n }\n return {\n ok: false,\n kind: 'network',\n status: res.status,\n ...(requestId !== undefined ? { requestId } : {}),\n message: `Request to ${url} failed while reading the response body: ${errorMessage(err)}`,\n };\n }\n\n return {\n ok: true,\n status: res.status,\n json,\n ...(requestId !== undefined ? { requestId } : {}),\n };\n } finally {\n clearTimeout(timer);\n }\n}\n\nfunction timeoutFailure(url: string, timeoutMs: number): FetchJsonFailure {\n return {\n ok: false,\n kind: 'timeout',\n message: `Request to ${url} timed out after ${timeoutMs}ms`,\n };\n}\n\n/**\n * A full HTTP round trip that surfaces the STATUS, headers, and best-effort JSON\n * body for ANY status. Unlike fetchJson (2xx-only), the B2 read/pay flow needs\n * the body on a 402 (the leak-safe preview) and a 409 (the owned-re-pay gate),\n * and lookup/outcome need a 4xx validation envelope. A transport/timeout failure\n * still returns the discriminated FetchJsonFailure so callers map it uniformly.\n */\nexport interface HttpRequestOptions {\n method?: 'GET' | 'POST';\n timeoutMs: number;\n headers?: Record<string, string>;\n /** A JSON body (POST); serialized with a content-type header set automatically. */\n jsonBody?: unknown;\n fetchImpl?: typeof fetch;\n}\n\nexport interface HttpResponse {\n ok: true;\n status: number;\n /** Case-insensitive header lookup over the response. */\n header(name: string): string | undefined;\n /** Parsed JSON body, or undefined when the body was empty or not JSON. */\n json: unknown;\n requestId?: string;\n}\n\nexport type HttpResult = HttpResponse | FetchJsonFailure;\n\nexport async function httpRequest(url: string, opts: HttpRequestOptions): Promise<HttpResult> {\n const doFetch = opts.fetchImpl ?? fetch;\n const controller = new AbortController();\n let timedOut = false;\n const timer = setTimeout(() => {\n timedOut = true;\n controller.abort();\n }, opts.timeoutMs);\n\n try {\n const headers: Record<string, string> = { ...(opts.headers ?? {}) };\n let body: string | undefined;\n if (opts.jsonBody !== undefined) {\n body = JSON.stringify(opts.jsonBody);\n headers['content-type'] = 'application/json';\n }\n if (opts.method === 'POST' || body !== undefined) headers['accept'] ??= 'application/json';\n\n let res: Response;\n try {\n res = await doFetch(url, {\n method: opts.method ?? 'GET',\n headers,\n body,\n signal: controller.signal,\n });\n } catch (err) {\n return timedOut\n ? timeoutFailure(url, opts.timeoutMs)\n : { ok: false, kind: 'network', message: `Request to ${url} failed: ${errorMessage(err)}` };\n }\n\n const requestId = res.headers.get('x-request-id') ?? undefined;\n // Read the raw text once; parse best-effort. A non-JSON body (empty 202, an\n // HTML error page) yields `undefined` rather than a thrown parse, because a\n // 402/409 caller keys off the STATUS and only some statuses carry JSON.\n let text: string;\n try {\n text = await res.text();\n } catch (err) {\n if (timedOut) return timeoutFailure(url, opts.timeoutMs);\n return {\n ok: false,\n kind: 'network',\n status: res.status,\n ...(requestId !== undefined ? { requestId } : {}),\n message: `Request to ${url} failed while reading the response body: ${errorMessage(err)}`,\n };\n }\n let json: unknown;\n if (text.length > 0) {\n try {\n json = JSON.parse(text);\n } catch {\n json = undefined;\n }\n }\n return {\n ok: true,\n status: res.status,\n header: (name) => res.headers.get(name) ?? undefined,\n json,\n ...(requestId !== undefined ? { requestId } : {}),\n };\n } finally {\n clearTimeout(timer);\n }\n}\n\nexport interface FailureToCliErrorOptions {\n fix?: string;\n details?: unknown;\n}\n\n/**\n * Normalize a fetch failure into the CLI error contract: network/timeout are a\n * NETWORK_ERROR, an `http` status (server reachable but errored — commonly 5xx)\n * is API_UNREACHABLE, and a 2xx that failed to parse when JSON was required is a\n * CONTRACT_MISMATCH. Callers that need a check-specific code (doctor) build their\n * own CliError; this is the default B2's passthrough leans on.\n */\nexport function fetchFailureToCliError(\n failure: FetchJsonFailure,\n opts: FailureToCliErrorOptions = {},\n): CliError {\n const code =\n failure.kind === 'network' || failure.kind === 'timeout'\n ? 'NETWORK_ERROR'\n : failure.kind === 'invalid-json'\n ? 'CONTRACT_MISMATCH'\n : 'API_UNREACHABLE';\n return new CliError(code, failure.message, {\n ...(opts.fix !== undefined ? { fix: opts.fix } : {}),\n ...(opts.details !== undefined ? { details: opts.details } : {}),\n });\n}\n\nfunction errorMessage(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n","import pkg from '../../package.json';\n\n/**\n * The `X-Tenjin-Client` value on every B2 request (spec 09 §purchase-attribution):\n * the server classifies views/payments by this label, so a CLI lookup-flow\n * purchase is never mixed with a web checkout. Format `tenjin-cli/<version>`.\n */\nexport const CLIENT_HEADER = `tenjin-cli/${pkg.version}`;\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"],"mappings":";;;;;;AAyCA,eAAsB,UAAU,KAAa,MAAkD;AAC7F,QAAM,UAAU,KAAK,aAAa;AAClC,QAAM,aAAa,IAAI,gBAAgB;AACvC,MAAI,WAAW;AAIf,QAAM,QAAQ,WAAW,MAAM;AAC7B,eAAW;AACX,eAAW,MAAM;AAAA,EACnB,GAAG,KAAK,SAAS;AAEjB,MAAI;AACF,QAAI;AACJ,QAAI;AACF,YAAM,MAAM,QAAQ,KAAK;AAAA,QACvB,QAAQ,WAAW;AAAA,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C,SAAS,cAAc,GAAG,4CAA4C,aAAa,GAAG,CAAC;AAAA,MACzF;AAAA,IACF;AACA,QAAI;AACJ,QAAI,KAAK,SAAS,GAAG;AACnB,UAAI;AACF,eAAO,KAAK,MAAM,IAAI;AAAA,MACxB,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,QAAQ,IAAI;AAAA,MACZ,QAAQ,CAAC,SAAS,IAAI,QAAQ,IAAI,IAAI,KAAK;AAAA,MAC3C;AAAA,MACA,GAAI,cAAc,SAAY,EAAE,UAAU,IAAI,CAAC;AAAA,IACjD;AAAA,EACF,UAAE;AACA,iBAAa,KAAK;AAAA,EACpB;AACF;AA8BA,SAAS,aAAa,KAAsB;AAC1C,SAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AACxD;;;ACvPO,IAAM,gBAAgB,cAAc,gBAAI,OAAO;;;ACN/C,SAAS,UAAU,KAAqB;AAC7C,SAAO,IAAI,QAAQ,QAAQ,EAAE;AAC/B;","names":[]}
@@ -1,286 +0,0 @@
1
- import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- ATOMIC_RE,
4
- UUID_RE
5
- } from "./chunk-3OV7E5G5.js";
6
- import {
7
- CLIENT_HEADER,
8
- httpRequest,
9
- trimSlash
10
- } from "./chunk-4ONXEEQL.js";
11
- import {
12
- CliError,
13
- external_exports
14
- } from "./chunk-OYMYCW7J.js";
15
-
16
- // src/lib/agent-api.ts
17
- var FRESH_WITHIN_RE = /^P(\d+)[DWMY]$/;
18
- var CANONICAL_KEY_RE = /^[a-z][a-z0-9_]{0,31}$/;
19
- function buildLookupRequest(input) {
20
- const question = input.question.trim();
21
- if (question.length === 0 || question.length > 512) {
22
- throw new CliError("USAGE", "question must be 1 to 512 characters", {
23
- fix: "Pass a non-empty question under 512 characters."
24
- });
25
- }
26
- if (input.freshWithin !== void 0) {
27
- const digits = FRESH_WITHIN_RE.exec(input.freshWithin)?.[1];
28
- if (digits === void 0 || Number(digits) === 0) {
29
- throw new CliError("USAGE", `Invalid --fresh-within: ${JSON.stringify(input.freshWithin)}`, {
30
- fix: "Use a nonzero ISO-like window P<n>[DWMY], e.g. P30D, P2W, P1Y."
31
- });
32
- }
33
- }
34
- if (input.maxPrice !== void 0 && !ATOMIC_RE.test(input.maxPrice)) {
35
- throw new CliError("USAGE", `Invalid --max-price: ${JSON.stringify(input.maxPrice)}`, {
36
- fix: "Pass an atomic USDC integer, e.g. 100000 for $0.10."
37
- });
38
- }
39
- const limit = input.limit ?? 5;
40
- if (!Number.isInteger(limit) || limit < 1 || limit > 10) {
41
- throw new CliError("USAGE", `Invalid --limit: ${JSON.stringify(input.limit)}`, {
42
- fix: "Pass an integer between 1 and 10."
43
- });
44
- }
45
- if (input.appliesTo !== void 0) {
46
- const keys = Object.keys(input.appliesTo);
47
- if (keys.length > 8) {
48
- throw new CliError("USAGE", "Too many --applies-to keys (max 8).");
49
- }
50
- for (const [key, values] of Object.entries(input.appliesTo)) {
51
- if (!CANONICAL_KEY_RE.test(key)) {
52
- throw new CliError("USAGE", `Invalid appliesTo key: ${JSON.stringify(key)}`, {
53
- fix: "Keys must be canonical lowercase identifiers, e.g. products=Vercel."
54
- });
55
- }
56
- if (values.length === 0) {
57
- throw new CliError("USAGE", `appliesTo key ${JSON.stringify(key)} has no values`, {
58
- fix: "Give each --applies-to key at least one value."
59
- });
60
- }
61
- if (values.length > 20) {
62
- throw new CliError("USAGE", `Too many --applies-to values for ${key} (max 20).`);
63
- }
64
- for (const value of values) {
65
- if (value.length === 0 || value.length > 120) {
66
- throw new CliError(
67
- "USAGE",
68
- `Invalid --applies-to value for ${key}: must be 1 to 120 characters.`
69
- );
70
- }
71
- }
72
- }
73
- }
74
- return {
75
- schemaVersion: 1,
76
- question,
77
- ...input.freshWithin !== void 0 ? { freshWithin: input.freshWithin } : {},
78
- ...input.maxPrice !== void 0 ? { maxPrice: input.maxPrice } : {},
79
- ...input.appliesTo !== void 0 ? { appliesTo: input.appliesTo } : {},
80
- limit
81
- };
82
- }
83
- var lookupCandidateSchema = external_exports.object({
84
- resourceId: external_exports.string().regex(UUID_RE, "resourceId must be a uuid"),
85
- url: external_exports.string(),
86
- title: external_exports.string(),
87
- artifactType: external_exports.string(),
88
- price: external_exports.string().regex(ATOMIC_RE, "price must be an atomic integer string"),
89
- asOf: external_exports.string().nullable(),
90
- validUntil: external_exports.string().nullable(),
91
- temporalMode: external_exports.string(),
92
- appliesTo: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())),
93
- questionsAnswered: external_exports.array(external_exports.string()),
94
- tasksSupported: external_exports.array(external_exports.string()),
95
- scope: external_exports.string().nullable(),
96
- exclusions: external_exports.string().nullable(),
97
- matchReasons: external_exports.array(external_exports.string()),
98
- estimatedTokens: external_exports.number(),
99
- creator: external_exports.object({ handle: external_exports.string() }).passthrough()
100
- }).passthrough();
101
- var lookupResponseSchema = external_exports.object({
102
- schemaVersion: external_exports.literal(1),
103
- lookupId: external_exports.string().regex(UUID_RE, "lookupId must be a uuid"),
104
- decision: external_exports.enum(["CANDIDATES", "MISS"]),
105
- calibration: external_exports.string(),
106
- candidates: external_exports.array(lookupCandidateSchema).optional()
107
- });
108
- function apiFailure(url, result) {
109
- const code = result.kind === "network" || result.kind === "timeout" ? "NETWORK_ERROR" : "API_UNREACHABLE";
110
- return new CliError(code, `${url}: ${result.message}`, {
111
- fix: "Check --base-url and your network, then retry."
112
- });
113
- }
114
- function rateLimitError(url, header) {
115
- const retryAfter = header("retry-after");
116
- const seconds = retryAfter !== void 0 ? Number(retryAfter) : void 0;
117
- return new CliError("RATE_LIMITED", `${url}: rate limited by the server.`, {
118
- fix: seconds !== void 0 && Number.isFinite(seconds) ? `Retry after ${seconds}s.` : "Back off and retry shortly.",
119
- details: {
120
- ...seconds !== void 0 && Number.isFinite(seconds) ? { retryAfterSeconds: seconds } : {}
121
- }
122
- });
123
- }
124
- function serverErrorMessage(json) {
125
- if (typeof json === "object" && json !== null) {
126
- const rec = json;
127
- const err = rec.error;
128
- if (typeof err === "string") return err;
129
- if (typeof err === "object" && err !== null) {
130
- const m = err.message;
131
- if (typeof m === "string") return m;
132
- }
133
- if (typeof rec.message === "string") return rec.message;
134
- }
135
- return void 0;
136
- }
137
- async function postLookup(body, opts) {
138
- const url = `${trimSlash(opts.baseUrl)}/api/agent/lookup`;
139
- const res = await httpRequest(url, {
140
- method: "POST",
141
- timeoutMs: opts.timeoutMs,
142
- headers: {
143
- "x-tenjin-client": CLIENT_HEADER,
144
- ...opts.evalCohort === true ? { "x-tenjin-eval-cohort": "1" } : {}
145
- },
146
- jsonBody: body,
147
- fetchImpl: opts.fetchImpl
148
- });
149
- if (!res.ok) throw apiFailure(url, res);
150
- if (res.status === 429) throw rateLimitError(url, (n) => res.header(n));
151
- if (res.status !== 200) {
152
- throw new CliError(
153
- "API_UNREACHABLE",
154
- serverErrorMessage(res.json) ?? `Lookup failed (${res.status})`,
155
- {
156
- fix: "Retry; if it persists the lookup endpoint may be unavailable.",
157
- details: res.json
158
- }
159
- );
160
- }
161
- const parsed = lookupResponseSchema.safeParse(res.json);
162
- if (!parsed.success) {
163
- throw new CliError("CONTRACT_MISMATCH", "Lookup response did not match the expected contract", {
164
- fix: "Update tenjin-cli; the server contract may have changed.",
165
- details: parsed.error.issues
166
- });
167
- }
168
- return truncateResponse(parsed.data);
169
- }
170
- var CAND_BOUNDS = {
171
- title: 200,
172
- scope: 240,
173
- exclusions: 240,
174
- listItems: 4,
175
- listItemChars: 160,
176
- matchReasons: 3,
177
- matchReasonChars: 80,
178
- appliesToKeys: 6,
179
- appliesToValues: 5,
180
- appliesToValueChars: 80
181
- };
182
- function truncateResponse(res) {
183
- if (res.candidates === void 0) return res;
184
- return { ...res, candidates: res.candidates.map(truncateCandidate) };
185
- }
186
- function truncateCandidate(c) {
187
- const cap = (s, n) => s.length > n ? s.slice(0, n) : s;
188
- const capList = (list, items, chars) => list.slice(0, items).map((s) => cap(s, chars));
189
- const appliesTo = {};
190
- for (const key of Object.keys(c.appliesTo).slice(0, CAND_BOUNDS.appliesToKeys)) {
191
- appliesTo[cap(key, CAND_BOUNDS.appliesToValueChars)] = capList(
192
- c.appliesTo[key] ?? [],
193
- CAND_BOUNDS.appliesToValues,
194
- CAND_BOUNDS.appliesToValueChars
195
- );
196
- }
197
- return {
198
- ...c,
199
- title: cap(c.title, CAND_BOUNDS.title),
200
- scope: c.scope === null ? null : cap(c.scope, CAND_BOUNDS.scope),
201
- exclusions: c.exclusions === null ? null : cap(c.exclusions, CAND_BOUNDS.exclusions),
202
- questionsAnswered: capList(
203
- c.questionsAnswered,
204
- CAND_BOUNDS.listItems,
205
- CAND_BOUNDS.listItemChars
206
- ),
207
- tasksSupported: capList(c.tasksSupported, CAND_BOUNDS.listItems, CAND_BOUNDS.listItemChars),
208
- matchReasons: capList(c.matchReasons, CAND_BOUNDS.matchReasons, CAND_BOUNDS.matchReasonChars),
209
- appliesTo
210
- };
211
- }
212
- var OUTCOME_STATUSES = [
213
- "used",
214
- "partially_used",
215
- "rejected",
216
- "regenerated",
217
- "purchase_declined"
218
- ];
219
- var OUTCOME_STATUS_VALUES = OUTCOME_STATUSES;
220
- var CONTENT_HASH_RE = /^sha256:[0-9a-f]{64}$/;
221
- function buildOutcomeItem(input) {
222
- if (!OUTCOME_STATUS_VALUES.includes(input.status)) {
223
- throw new CliError("USAGE", `Invalid outcome status: ${JSON.stringify(input.status)}`, {
224
- fix: `Use one of: ${OUTCOME_STATUSES.join(", ")}.`
225
- });
226
- }
227
- if (input.resourceId !== void 0 && !UUID_RE.test(input.resourceId)) {
228
- throw new CliError("USAGE", `Invalid --resource id: ${JSON.stringify(input.resourceId)}`, {
229
- fix: "Pass the resourceId (a uuid) from a lookup candidate."
230
- });
231
- }
232
- if (input.contentHash !== void 0 && !CONTENT_HASH_RE.test(input.contentHash)) {
233
- throw new CliError("USAGE", `Invalid content hash: ${JSON.stringify(input.contentHash)}`, {
234
- fix: 'A content hash is "sha256:<64 hex>".'
235
- });
236
- }
237
- return {
238
- status: input.status,
239
- ...input.resourceId !== void 0 ? { resourceId: input.resourceId } : {},
240
- ...input.contentHash !== void 0 ? { contentHash: input.contentHash } : {}
241
- };
242
- }
243
- var LOOKUP_ID_RE = UUID_RE;
244
- async function postOutcomes(lookupId, items, opts) {
245
- if (!LOOKUP_ID_RE.test(lookupId)) {
246
- throw new CliError("USAGE", `Invalid lookup id: ${JSON.stringify(lookupId)}`, {
247
- fix: "Pass the lookupId from a prior lookup (or use --last)."
248
- });
249
- }
250
- if (items.length === 0 || items.length > 10) {
251
- throw new CliError("USAGE", "An outcome report carries 1 to 10 items", {
252
- fix: "Report between 1 and 10 outcomes per call."
253
- });
254
- }
255
- const url = `${trimSlash(opts.baseUrl)}/api/agent/lookups/${lookupId}/outcomes`;
256
- const res = await httpRequest(url, {
257
- method: "POST",
258
- timeoutMs: opts.timeoutMs,
259
- headers: { "x-tenjin-client": CLIENT_HEADER },
260
- jsonBody: items.length === 1 ? items[0] : items,
261
- fetchImpl: opts.fetchImpl
262
- });
263
- if (!res.ok) throw apiFailure(url, res);
264
- if (res.status === 429) throw rateLimitError(url, (n) => res.header(n));
265
- if (res.status !== 202) {
266
- throw new CliError(
267
- "API_UNREACHABLE",
268
- serverErrorMessage(res.json) ?? `Outcome report failed (${res.status})`,
269
- {
270
- fix: "Check the status vocabulary and lookup id, then retry.",
271
- details: res.json
272
- }
273
- );
274
- }
275
- const accepted = typeof res.json === "object" && res.json !== null && "accepted" in res.json ? Number(res.json.accepted) : items.length;
276
- return { accepted: Number.isFinite(accepted) ? accepted : items.length };
277
- }
278
-
279
- export {
280
- buildLookupRequest,
281
- rateLimitError,
282
- postLookup,
283
- buildOutcomeItem,
284
- postOutcomes
285
- };
286
- //# sourceMappingURL=chunk-662MSGZB.js.map