tenjin-cli 0.1.0-alpha.24 → 0.1.0-alpha.25

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 (114) hide show
  1. package/README.md +5 -1
  2. package/dist/{chunk-H5UR3GFJ.js → chunk-3ZYPVSIU.js} +56 -31
  3. package/dist/chunk-3ZYPVSIU.js.map +1 -0
  4. package/dist/chunk-7EKYXMUO.js +7536 -0
  5. package/dist/chunk-7EKYXMUO.js.map +1 -0
  6. package/dist/chunk-AKWGE6JQ.js +49 -0
  7. package/dist/chunk-AKWGE6JQ.js.map +1 -0
  8. package/dist/{chunk-RCJ64OXH.js → chunk-CEMXMUIU.js} +3 -3
  9. package/dist/{chunk-XZUGRTSV.js → chunk-CKDD554V.js} +2 -2
  10. package/dist/{hook-command-GMIDXVFK.js → chunk-CP7O6M55.js} +190 -40
  11. package/dist/chunk-CP7O6M55.js.map +1 -0
  12. package/dist/{chunk-UBOFYC6J.js → chunk-DRXDTITB.js} +1821 -141
  13. package/dist/chunk-DRXDTITB.js.map +1 -0
  14. package/dist/{chunk-EP5P2STS.js → chunk-EACMJEF3.js} +201 -8
  15. package/dist/chunk-EACMJEF3.js.map +1 -0
  16. package/dist/{chunk-GPLSNGKX.js → chunk-EG7P4SM6.js} +4 -4
  17. package/dist/{chunk-RGVOODF4.js → chunk-EL56RW2J.js} +164 -7463
  18. package/dist/chunk-EL56RW2J.js.map +1 -0
  19. package/dist/{chunk-KC24CYGV.js → chunk-EOGJKIOG.js} +6 -8
  20. package/dist/{chunk-KC24CYGV.js.map → chunk-EOGJKIOG.js.map} +1 -1
  21. package/dist/{chunk-ZMFDMALH.js → chunk-GT6W3VJM.js} +2 -2
  22. package/dist/{chunk-TMLCEPCD.js → chunk-HII5HOQV.js} +3 -5
  23. package/dist/chunk-HII5HOQV.js.map +1 -0
  24. package/dist/{chunk-UXSF7IFD.js → chunk-IYLECN4D.js} +3 -3
  25. package/dist/{chunk-SQSKVKX6.js → chunk-KGTQRJGS.js} +17 -8
  26. package/dist/chunk-KGTQRJGS.js.map +1 -0
  27. package/dist/chunk-LFZJM56J.js +159 -0
  28. package/dist/chunk-LFZJM56J.js.map +1 -0
  29. package/dist/{chunk-YZTIYDWU.js → chunk-NTYQHAIM.js} +2 -2
  30. package/dist/{chunk-IIE65SJC.js → chunk-NYPFOHSJ.js} +4 -4
  31. package/dist/{chunk-ZNZGBUV6.js → chunk-ODH7UXIS.js} +8 -7
  32. package/dist/chunk-ODH7UXIS.js.map +1 -0
  33. package/dist/{chunk-NSDZESRS.js → chunk-OZ3LWLCI.js} +3 -3
  34. package/dist/{chunk-XRW4N23F.js → chunk-SCAE6PW6.js} +4 -4
  35. package/dist/{chunk-O2WN732M.js → chunk-UDWGT4FX.js} +2 -2
  36. package/dist/chunk-VYONGSMQ.js +119 -0
  37. package/dist/chunk-VYONGSMQ.js.map +1 -0
  38. package/dist/{chunk-P22ZWXFX.js → chunk-XICKN3CH.js} +49 -4
  39. package/dist/chunk-XICKN3CH.js.map +1 -0
  40. package/dist/chunk-YHKXNYTB.js +105 -0
  41. package/dist/chunk-YHKXNYTB.js.map +1 -0
  42. package/dist/{chunk-W2ARIOAZ.js → chunk-YSW57KUT.js} +8 -10
  43. package/dist/{chunk-W2ARIOAZ.js.map → chunk-YSW57KUT.js.map} +1 -1
  44. package/dist/{chunk-FFL5M5BC.js → chunk-YTM7OURD.js} +2 -2
  45. package/dist/{cli-GGNOQQEB.js → cli-4WMGZPBP.js} +27 -28
  46. package/dist/{cli-GGNOQQEB.js.map → cli-4WMGZPBP.js.map} +1 -1
  47. package/dist/{config-XUUFICXK.js → config-VU6U7QOU.js} +9 -8
  48. package/dist/{doctor-3LGF6CWI.js → doctor-26JS2SG3.js} +123 -31
  49. package/dist/doctor-26JS2SG3.js.map +1 -0
  50. package/dist/{fund-3URFMBMN.js → fund-JJN3FRRF.js} +13 -14
  51. package/dist/fund-JJN3FRRF.js.map +1 -0
  52. package/dist/hook-command-S2V4UNB3.js +28 -0
  53. package/dist/index.js +3 -3
  54. package/dist/{install-FRTG4KHF.js → install-GXQ33J4G.js} +19 -16
  55. package/dist/{install-identity-WNXSYP6N.js → install-identity-HFQUXPSI.js} +6 -7
  56. package/dist/{install-wallet-MXLJJP3N.js → install-wallet-27LTEHBI.js} +8 -9
  57. package/dist/{install-wallet-MXLJJP3N.js.map → install-wallet-27LTEHBI.js.map} +1 -1
  58. package/dist/{mcp-O2WJ3QBW.js → mcp-AHCZVD2U.js} +596 -75
  59. package/dist/mcp-AHCZVD2U.js.map +1 -0
  60. package/dist/{pay-43WUYTW5.js → pay-3TCOPGCX.js} +14 -13
  61. package/dist/{payments-7UTMMTIO.js → payments-H3LSBGSL.js} +6 -7
  62. package/dist/{payments-7UTMMTIO.js.map → payments-H3LSBGSL.js.map} +1 -1
  63. package/dist/{send-ALHG2RXT.js → send-LKCLN5GA.js} +9 -11
  64. package/dist/{send-ALHG2RXT.js.map → send-LKCLN5GA.js.map} +1 -1
  65. package/dist/{status-CFPNHB6R.js → status-2FDGI4LQ.js} +7 -9
  66. package/dist/{status-CFPNHB6R.js.map → status-2FDGI4LQ.js.map} +1 -1
  67. package/dist/{status-line-FJ6N7MKJ.js → status-line-QKDJYZGV.js} +4 -5
  68. package/dist/{status-line-FJ6N7MKJ.js.map → status-line-QKDJYZGV.js.map} +1 -1
  69. package/dist/{status-line-wiring-GXFNXHPE.js → status-line-wiring-ZDBYHNYR.js} +6 -4
  70. package/dist/{uninstall-5P2GFYBY.js → uninstall-ZXWABDHS.js} +33 -29
  71. package/dist/uninstall-ZXWABDHS.js.map +1 -0
  72. package/dist/{update-QJ5YHJ7I.js → update-HEIWVOP5.js} +17 -6
  73. package/dist/update-HEIWVOP5.js.map +1 -0
  74. package/dist/{wallet-6OJPGNEV.js → wallet-T7JYWI6O.js} +8 -9
  75. package/dist/wallet-T7JYWI6O.js.map +1 -0
  76. package/docs/agent-permissions.md +6 -3
  77. package/package.json +7 -6
  78. package/dist/chunk-EP5P2STS.js.map +0 -1
  79. package/dist/chunk-H5UR3GFJ.js.map +0 -1
  80. package/dist/chunk-O2JYBOUO.js +0 -47
  81. package/dist/chunk-O2JYBOUO.js.map +0 -1
  82. package/dist/chunk-P22ZWXFX.js.map +0 -1
  83. package/dist/chunk-RGVOODF4.js.map +0 -1
  84. package/dist/chunk-S2NRVRPF.js +0 -171
  85. package/dist/chunk-S2NRVRPF.js.map +0 -1
  86. package/dist/chunk-SQSKVKX6.js.map +0 -1
  87. package/dist/chunk-TMLCEPCD.js.map +0 -1
  88. package/dist/chunk-UBOFYC6J.js.map +0 -1
  89. package/dist/chunk-YXLG7Q6Q.js +0 -140
  90. package/dist/chunk-YXLG7Q6Q.js.map +0 -1
  91. package/dist/chunk-ZNZGBUV6.js.map +0 -1
  92. package/dist/doctor-3LGF6CWI.js.map +0 -1
  93. package/dist/fund-3URFMBMN.js.map +0 -1
  94. package/dist/hook-command-GMIDXVFK.js.map +0 -1
  95. package/dist/mcp-O2WJ3QBW.js.map +0 -1
  96. package/dist/uninstall-5P2GFYBY.js.map +0 -1
  97. package/dist/update-QJ5YHJ7I.js.map +0 -1
  98. /package/dist/{chunk-RCJ64OXH.js.map → chunk-CEMXMUIU.js.map} +0 -0
  99. /package/dist/{chunk-XZUGRTSV.js.map → chunk-CKDD554V.js.map} +0 -0
  100. /package/dist/{chunk-GPLSNGKX.js.map → chunk-EG7P4SM6.js.map} +0 -0
  101. /package/dist/{chunk-ZMFDMALH.js.map → chunk-GT6W3VJM.js.map} +0 -0
  102. /package/dist/{chunk-UXSF7IFD.js.map → chunk-IYLECN4D.js.map} +0 -0
  103. /package/dist/{chunk-YZTIYDWU.js.map → chunk-NTYQHAIM.js.map} +0 -0
  104. /package/dist/{chunk-IIE65SJC.js.map → chunk-NYPFOHSJ.js.map} +0 -0
  105. /package/dist/{chunk-NSDZESRS.js.map → chunk-OZ3LWLCI.js.map} +0 -0
  106. /package/dist/{chunk-XRW4N23F.js.map → chunk-SCAE6PW6.js.map} +0 -0
  107. /package/dist/{chunk-O2WN732M.js.map → chunk-UDWGT4FX.js.map} +0 -0
  108. /package/dist/{chunk-FFL5M5BC.js.map → chunk-YTM7OURD.js.map} +0 -0
  109. /package/dist/{config-XUUFICXK.js.map → config-VU6U7QOU.js.map} +0 -0
  110. /package/dist/{install-FRTG4KHF.js.map → hook-command-S2V4UNB3.js.map} +0 -0
  111. /package/dist/{install-identity-WNXSYP6N.js.map → install-GXQ33J4G.js.map} +0 -0
  112. /package/dist/{pay-43WUYTW5.js.map → install-identity-HFQUXPSI.js.map} +0 -0
  113. /package/dist/{status-line-wiring-GXFNXHPE.js.map → pay-3TCOPGCX.js.map} +0 -0
  114. /package/dist/{wallet-6OJPGNEV.js.map → status-line-wiring-ZDBYHNYR.js.map} +0 -0
@@ -2,10 +2,174 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
2
2
  import {
3
3
  fetchFailureToCliError,
4
4
  httpRequest
5
- } from "./chunk-RCJ64OXH.js";
5
+ } from "./chunk-CEMXMUIU.js";
6
6
  import {
7
7
  external_exports
8
- } from "./chunk-P22ZWXFX.js";
8
+ } from "./chunk-XICKN3CH.js";
9
+ import {
10
+ MCP_SERVER_NAME,
11
+ REQUEST_TOOL
12
+ } from "./chunk-TGLKKLQG.js";
13
+
14
+ // src/router/agent-tools.ts
15
+ import { readdir, readFile } from "node:fs/promises";
16
+ import { dirname, join, resolve } from "node:path";
17
+ var MCP_INHERITING_BUILTINS = /* @__PURE__ */ new Set([
18
+ "general-purpose",
19
+ "Explore",
20
+ "Plan"
21
+ ]);
22
+ var MAX_AGENT_FILE_BYTES = 256 * 1024;
23
+ var TYPE_RE = /^[A-Za-z0-9_.:-]{1,200}$/;
24
+ async function requestToolAccess(agentType, lookup) {
25
+ if (agentType === void 0 || !TYPE_RE.test(agentType)) return "unknown";
26
+ try {
27
+ const text = await findDefinition(agentType, lookup);
28
+ if (text !== null) return accessOf(text);
29
+ return MCP_INHERITING_BUILTINS.has(agentType) ? "allowed" : "unknown";
30
+ } catch {
31
+ return "unknown";
32
+ }
33
+ }
34
+ function accessOf(definition) {
35
+ const frontmatter = frontmatterOf(definition);
36
+ if (frontmatter === null) return "unknown";
37
+ const disallowed = listField(frontmatter, "disallowedTools");
38
+ if (disallowed !== void 0 && disallowed.some(namesRequestTool)) return "excluded";
39
+ const tools = listField(frontmatter, "tools");
40
+ if (tools === void 0) return "allowed";
41
+ return tools.some(namesRequestTool) ? "allowed" : "excluded";
42
+ }
43
+ function namesRequestTool(tool) {
44
+ if (tool === REQUEST_TOOL || tool === `mcp__${MCP_SERVER_NAME}`) return true;
45
+ return tool.endsWith("*") && REQUEST_TOOL.startsWith(tool.slice(0, -1));
46
+ }
47
+ async function agentsWithoutRequestTool(lookup) {
48
+ const found = [];
49
+ const seen = /* @__PURE__ */ new Set();
50
+ for (const directory of agentDirs(lookup)) {
51
+ for (const { name, text } of await definitionsIn(directory)) {
52
+ const type = nameOf(text) ?? name;
53
+ if (seen.has(type)) continue;
54
+ seen.add(type);
55
+ if (accessOf(text) === "excluded") found.push(type);
56
+ }
57
+ }
58
+ return found.sort();
59
+ }
60
+ async function findDefinition(agentType, lookup) {
61
+ for (const directory of agentDirs(lookup)) {
62
+ const text = await definitionIn(directory, agentType);
63
+ if (text !== null) return text;
64
+ }
65
+ const colon = agentType.indexOf(":");
66
+ if (colon > 0) {
67
+ const plugin = agentType.slice(0, colon);
68
+ const agent = agentType.slice(colon + 1);
69
+ for (const root of await pluginRoots(plugin, lookup.homeDir)) {
70
+ const text = await definitionIn(join(root, "agents"), agent);
71
+ if (text !== null) return text;
72
+ }
73
+ }
74
+ return null;
75
+ }
76
+ function agentDirs(lookup) {
77
+ const dirs = [];
78
+ if (lookup.cwd !== void 0 && lookup.cwd.length > 0) {
79
+ let current = resolve(lookup.cwd);
80
+ for (; ; ) {
81
+ dirs.push(join(current, ".claude", "agents"));
82
+ const parent = dirname(current);
83
+ if (parent === current) break;
84
+ current = parent;
85
+ }
86
+ }
87
+ const user = join(resolve(lookup.homeDir), ".claude", "agents");
88
+ return [...dirs.filter((d) => d !== user), user];
89
+ }
90
+ async function definitionIn(directory, agentType) {
91
+ const direct = await readBounded(join(directory, `${agentType}.md`));
92
+ if (direct !== null && (nameOf(direct) ?? agentType) === agentType) return direct;
93
+ for (const { text } of await definitionsIn(directory)) {
94
+ if (nameOf(text) === agentType) return text;
95
+ }
96
+ return null;
97
+ }
98
+ async function definitionsIn(directory) {
99
+ let names;
100
+ try {
101
+ names = (await readdir(directory)).filter((n) => n.endsWith(".md")).slice(0, 200);
102
+ } catch {
103
+ return [];
104
+ }
105
+ const out = [];
106
+ for (const file of names) {
107
+ const text = await readBounded(join(directory, file));
108
+ if (text !== null) out.push({ name: file.slice(0, -3), text });
109
+ }
110
+ return out;
111
+ }
112
+ async function pluginRoots(plugin, homeDir) {
113
+ const raw = await readBounded(join(homeDir, ".claude", "plugins", "installed_plugins.json"));
114
+ if (raw === null) return [];
115
+ const parsed = JSON.parse(raw);
116
+ const roots = [];
117
+ for (const [key, entries] of Object.entries(parsed.plugins ?? {})) {
118
+ if (key.split("@")[0] !== plugin || !Array.isArray(entries)) continue;
119
+ for (const entry of entries) {
120
+ const path = entry.installPath;
121
+ if (typeof path === "string" && path.length > 0) roots.push(path);
122
+ }
123
+ }
124
+ return roots;
125
+ }
126
+ async function readBounded(path) {
127
+ try {
128
+ const text = await readFile(path, "utf8");
129
+ return text.length > MAX_AGENT_FILE_BYTES ? null : text;
130
+ } catch {
131
+ return null;
132
+ }
133
+ }
134
+ function frontmatterOf(text) {
135
+ const lines = text.replace(/^\uFEFF/, "").split(/\r?\n/);
136
+ const open = lines.findIndex((l) => l.trim().length > 0);
137
+ if (open === -1 || lines[open]?.trim() !== "---") return null;
138
+ const end = lines.findIndex((l, i) => i > open && l.trim() === "---");
139
+ return end === -1 ? null : lines.slice(open + 1, end);
140
+ }
141
+ function nameOf(text) {
142
+ const frontmatter = frontmatterOf(text);
143
+ if (frontmatter === null) return null;
144
+ const line = frontmatter.find((l) => /^name\s*:/.test(l));
145
+ const value = line === void 0 ? "" : unquote(line.slice(line.indexOf(":") + 1).trim());
146
+ return value.length > 0 ? value : null;
147
+ }
148
+ function listField(frontmatter, key) {
149
+ const index = frontmatter.findIndex((l) => new RegExp(`^${key}\\s*:`).test(l));
150
+ if (index === -1) return void 0;
151
+ const line = frontmatter[index];
152
+ const inline = line.slice(line.indexOf(":") + 1).trim();
153
+ if (inline.length > 0) {
154
+ const body = inline.startsWith("[") && inline.endsWith("]") ? inline.slice(1, -1) : inline;
155
+ return body.split(",").map((part) => unquote(part.trim())).filter((part) => part.length > 0);
156
+ }
157
+ const items = [];
158
+ for (const next of frontmatter.slice(index + 1)) {
159
+ const item = /^\s+-\s*(.*)$/.exec(next);
160
+ if (item === null) {
161
+ if (next.trim().length === 0) continue;
162
+ break;
163
+ }
164
+ const value = unquote(item[1].trim());
165
+ if (value.length > 0) items.push(value);
166
+ }
167
+ return items;
168
+ }
169
+ function unquote(value) {
170
+ const quoted = /^(['"])(.*)\1$/.exec(value);
171
+ return quoted === null ? value : quoted[2];
172
+ }
9
173
 
10
174
  // src/router/decision.ts
11
175
  var ROUTER_PATH = "/api/x402-router";
@@ -194,8 +358,18 @@ function buildToolBody(request) {
194
358
  ...request.accepts !== void 0 ? { accepts: [...request.accepts] } : {}
195
359
  };
196
360
  }
361
+ var RouteSkipped = class extends Error {
362
+ constructor(why) {
363
+ super(`routing fee not paid: ${why}`);
364
+ this.why = why;
365
+ }
366
+ why;
367
+ };
368
+ var CHANNEL_BUSY = "channel_busy";
369
+ var PAID_PATH_ABSENT = "paid_path_absent";
370
+ var PAYMENT_FAILED = "payment_failed";
197
371
  async function requestDecision(kind, request, deps) {
198
- const url = new URL(ROUTER_PATH, deps.baseUrl).toString();
372
+ const url = new URL(deps.route?.path ?? ROUTER_PATH, deps.baseUrl).toString();
199
373
  const options = {
200
374
  method: "POST",
201
375
  timeoutMs: deps.timeoutMs ?? deps.ctx.flags.timeout,
@@ -211,10 +385,23 @@ async function requestDecision(kind, request, deps) {
211
385
  }),
212
386
  ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
213
387
  };
214
- return readDecision(
215
- await httpRequest(url, options),
216
- kind === "hook" ? HookResponseSchema : ToolResponseSchema
217
- );
388
+ const started = Date.now();
389
+ const schema = kind === "hook" ? HookResponseSchema : ToolResponseSchema;
390
+ let response;
391
+ try {
392
+ response = await (deps.route?.send ?? httpRequest)(url, options);
393
+ } catch (err) {
394
+ if (!(err instanceof RouteSkipped)) throw err;
395
+ const left = options.timeoutMs - (Date.now() - started);
396
+ if (left <= 0) return { status: "skipped", why: err.why };
397
+ response = await httpRequest(new URL(ROUTER_PATH, deps.baseUrl).toString(), {
398
+ ...options,
399
+ timeoutMs: left
400
+ });
401
+ const free = readDecision(response, schema);
402
+ return free.status === "skipped" ? free : { ...free, freePath: err.why };
403
+ }
404
+ return readDecision(response, schema);
218
405
  }
219
406
  var OUTCOME_TIMEOUT_MS = 3e3;
220
407
  async function reportSpecOutcome(outcome, deps) {
@@ -267,9 +454,15 @@ function errorOf(body) {
267
454
  }
268
455
 
269
456
  export {
457
+ requestToolAccess,
458
+ agentsWithoutRequestTool,
270
459
  ROUTER_PATH,
271
460
  OfferSpecSchema,
461
+ RouteSkipped,
462
+ CHANNEL_BUSY,
463
+ PAID_PATH_ABSENT,
464
+ PAYMENT_FAILED,
272
465
  requestDecision,
273
466
  reportSpecOutcome
274
467
  };
275
- //# sourceMappingURL=chunk-EP5P2STS.js.map
468
+ //# sourceMappingURL=chunk-EACMJEF3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/router/agent-tools.ts","../src/router/decision.ts"],"sourcesContent":["import { readdir, readFile } from 'node:fs/promises';\nimport { dirname, join, resolve } from 'node:path';\nimport { MCP_SERVER_NAME, REQUEST_TOOL } from './names';\n\n/**\n * CAN THIS SUBAGENT CALL `request` AT ALL? An offer to an agent whose definition\n * leaves the tool out is a line it cannot act on, and a router call spent to\n * write it. Claude Code defines a custom agent in a Markdown file whose\n * frontmatter may carry `tools:` (an allowlist) and `disallowedTools:`; this\n * reads that, and nothing else, and never writes to it.\n *\n * ONLY `allowed` IS ACTED ON. A subagent is redirected or offered a lookup\n * only when this KNOWS it can make the call: a definition whose tools cover\n * the request tool (or that has no `tools:` and so inherits everything), or a\n * built-in in {@link MCP_INHERITING_BUILTINS}. Every other built-in, and any\n * type with no definition this can find or read, is `unknown`, and `unknown`\n * gets no router call: `claude-code-guide` ships with Bash, Read, WebFetch and\n * WebSearch and no MCP tools, and denying its WebFetch would strand it exactly\n * as #377 reported.\n *\n * WHERE A DEFINITION LIVES, in the harness's own precedence: the project's\n * `.claude/agents` (from `cwd` up to the filesystem root, nearest first), then\n * `~/.claude/agents`, then an installed plugin's `agents/` for a `plugin:agent`\n * type. A file is found by its name first and by its frontmatter `name:`\n * second, because the type is the `name:` and the file name only usually\n * matches it.\n */\n\nexport type RequestToolAccess = 'allowed' | 'excluded' | 'unknown';\n\n/**\n * The built-in agent types that have no definition file and still inherit MCP\n * tools, so can call `mcp__x402__request`. From Claude Code's own Agent tool\n * listing (2.1.28x): `general-purpose` has every tool, and `Explore` and `Plan`\n * exclude only editing and agent tools, never MCP. Built-ins with a fixed tool\n * list, such as `claude-code-guide` (Bash, Read, WebFetch, WebSearch) and\n * `statusline-setup` (Read, Edit), are deliberately absent.\n */\nexport const MCP_INHERITING_BUILTINS: ReadonlySet<string> = new Set([\n 'general-purpose',\n 'Explore',\n 'Plan',\n]);\n\nexport interface AgentLookup {\n cwd?: string;\n homeDir: string;\n}\n\nconst MAX_AGENT_FILE_BYTES = 256 * 1024;\nconst TYPE_RE = /^[A-Za-z0-9_.:-]{1,200}$/;\n\nexport async function requestToolAccess(\n agentType: string | undefined,\n lookup: AgentLookup,\n): Promise<RequestToolAccess> {\n if (agentType === undefined || !TYPE_RE.test(agentType)) return 'unknown';\n try {\n const text = await findDefinition(agentType, lookup);\n if (text !== null) return accessOf(text);\n return MCP_INHERITING_BUILTINS.has(agentType) ? 'allowed' : 'unknown';\n } catch {\n return 'unknown';\n }\n}\n\n/** What one definition's frontmatter says about the request tool. */\nexport function accessOf(definition: string): RequestToolAccess {\n const frontmatter = frontmatterOf(definition);\n if (frontmatter === null) return 'unknown';\n const disallowed = listField(frontmatter, 'disallowedTools');\n if (disallowed !== undefined && disallowed.some(namesRequestTool)) return 'excluded';\n const tools = listField(frontmatter, 'tools');\n if (tools === undefined) return 'allowed';\n return tools.some(namesRequestTool) ? 'allowed' : 'excluded';\n}\n\n/**\n * Does one `tools:` or `disallowedTools:` entry cover the request tool? The\n * tool itself, the bare server, or any `*`-suffixed pattern the tool's name\n * starts with: `*`, `mcp__*`, `mcp__x402__*` and every prefix between.\n */\nfunction namesRequestTool(tool: string): boolean {\n if (tool === REQUEST_TOOL || tool === `mcp__${MCP_SERVER_NAME}`) return true;\n return tool.endsWith('*') && REQUEST_TOOL.startsWith(tool.slice(0, -1));\n}\n\n/**\n * Every custom agent this project and this user define whose tools leave the\n * request tool out, for `doctor` to name. Plugin agents are not listed: their\n * files are not the user's to edit.\n */\nexport async function agentsWithoutRequestTool(lookup: AgentLookup): Promise<string[]> {\n const found: string[] = [];\n const seen = new Set<string>();\n for (const directory of agentDirs(lookup)) {\n for (const { name, text } of await definitionsIn(directory)) {\n const type = nameOf(text) ?? name;\n if (seen.has(type)) continue;\n seen.add(type);\n if (accessOf(text) === 'excluded') found.push(type);\n }\n }\n return found.sort();\n}\n\nasync function findDefinition(agentType: string, lookup: AgentLookup): Promise<string | null> {\n for (const directory of agentDirs(lookup)) {\n const text = await definitionIn(directory, agentType);\n if (text !== null) return text;\n }\n const colon = agentType.indexOf(':');\n if (colon > 0) {\n const plugin = agentType.slice(0, colon);\n const agent = agentType.slice(colon + 1);\n for (const root of await pluginRoots(plugin, lookup.homeDir)) {\n const text = await definitionIn(join(root, 'agents'), agent);\n if (text !== null) return text;\n }\n }\n return null;\n}\n\nfunction agentDirs(lookup: AgentLookup): string[] {\n const dirs: string[] = [];\n if (lookup.cwd !== undefined && lookup.cwd.length > 0) {\n let current = resolve(lookup.cwd);\n for (;;) {\n dirs.push(join(current, '.claude', 'agents'));\n const parent = dirname(current);\n if (parent === current) break;\n current = parent;\n }\n }\n const user = join(resolve(lookup.homeDir), '.claude', 'agents');\n // The user's directory is also an ancestor of most projects; it counts once,\n // in its own place in the order.\n return [...dirs.filter((d) => d !== user), user];\n}\n\nasync function definitionIn(directory: string, agentType: string): Promise<string | null> {\n const direct = await readBounded(join(directory, `${agentType}.md`));\n if (direct !== null && (nameOf(direct) ?? agentType) === agentType) return direct;\n for (const { text } of await definitionsIn(directory)) {\n if (nameOf(text) === agentType) return text;\n }\n return null;\n}\n\nasync function definitionsIn(directory: string): Promise<{ name: string; text: string }[]> {\n let names: string[];\n try {\n names = (await readdir(directory)).filter((n) => n.endsWith('.md')).slice(0, 200);\n } catch {\n return [];\n }\n const out: { name: string; text: string }[] = [];\n for (const file of names) {\n const text = await readBounded(join(directory, file));\n if (text !== null) out.push({ name: file.slice(0, -3), text });\n }\n return out;\n}\n\n/** Install paths `installed_plugins.json` records for `<plugin>@<marketplace>`. */\nasync function pluginRoots(plugin: string, homeDir: string): Promise<string[]> {\n const raw = await readBounded(join(homeDir, '.claude', 'plugins', 'installed_plugins.json'));\n if (raw === null) return [];\n const parsed = JSON.parse(raw) as { plugins?: Record<string, unknown> };\n const roots: string[] = [];\n for (const [key, entries] of Object.entries(parsed.plugins ?? {})) {\n if (key.split('@')[0] !== plugin || !Array.isArray(entries)) continue;\n for (const entry of entries) {\n const path = (entry as { installPath?: unknown }).installPath;\n if (typeof path === 'string' && path.length > 0) roots.push(path);\n }\n }\n return roots;\n}\n\nasync function readBounded(path: string): Promise<string | null> {\n try {\n const text = await readFile(path, 'utf8');\n return text.length > MAX_AGENT_FILE_BYTES ? null : text;\n } catch {\n return null;\n }\n}\n\nfunction frontmatterOf(text: string): string[] | null {\n const lines = text.replace(/^\\uFEFF/, '').split(/\\r?\\n/);\n const open = lines.findIndex((l) => l.trim().length > 0);\n if (open === -1 || lines[open]?.trim() !== '---') return null;\n const end = lines.findIndex((l, i) => i > open && l.trim() === '---');\n return end === -1 ? null : lines.slice(open + 1, end);\n}\n\nfunction nameOf(text: string): string | null {\n const frontmatter = frontmatterOf(text);\n if (frontmatter === null) return null;\n const line = frontmatter.find((l) => /^name\\s*:/.test(l));\n const value = line === undefined ? '' : unquote(line.slice(line.indexOf(':') + 1).trim());\n return value.length > 0 ? value : null;\n}\n\n/**\n * A top-level list field in the three spellings agent files use: `a, b, c`,\n * `[a, b]`, or a block of `- a` lines. `undefined` when the key is absent.\n */\nfunction listField(frontmatter: string[], key: string): string[] | undefined {\n const index = frontmatter.findIndex((l) => new RegExp(`^${key}\\\\s*:`).test(l));\n if (index === -1) return undefined;\n const line = frontmatter[index]!;\n const inline = line.slice(line.indexOf(':') + 1).trim();\n if (inline.length > 0) {\n const body = inline.startsWith('[') && inline.endsWith(']') ? inline.slice(1, -1) : inline;\n return body\n .split(',')\n .map((part) => unquote(part.trim()))\n .filter((part) => part.length > 0);\n }\n const items: string[] = [];\n for (const next of frontmatter.slice(index + 1)) {\n const item = /^\\s+-\\s*(.*)$/.exec(next);\n if (item === null) {\n if (next.trim().length === 0) continue;\n break;\n }\n const value = unquote(item[1]!.trim());\n if (value.length > 0) items.push(value);\n }\n return items;\n}\n\nfunction unquote(value: string): string {\n const quoted = /^(['\"])(.*)\\1$/.exec(value);\n return quoted === null ? value : quoted[2]!;\n}\n","import { z } from 'zod';\nimport { fetchFailureToCliError, httpRequest } from '../lib/http';\nimport type { HttpRequestOptions, HttpResult } from '../lib/http';\nimport type { CommandContext } from '../context';\nimport type { Packet } from './context';\n\n/**\n * `POST /api/x402-router`: ONE DECISION PER LOOKUP. On the free path it costs\n * nothing. Inside `tenjin mcp`, while the server answers its paid path, the\n * same body goes to that path through the stock x402 client\n * ({@link DecisionRoute}, `routing-payer.ts`); a call that path cannot take\n * falls back to the free path. The rest of this note describes the free path,\n * which is unchanged.\n *\n * The routing decision costs nothing and nobody signs for it. The hook asks for\n * it from the user's own words, the backend answers with what it would do and\n * what the provider charges, and the only payment on the wire is the one\n * `runPay` makes to that provider. That deletes the router fee and everything\n * built to carry it: the 402 probe, the requirements cache, the stale-quote\n * retry, the settlement accounting and one Base settlement of about 1.5 s from\n * every paid lookup.\n *\n * The bounded packet travels with the hook request and the backend keeps it\n * against the decision id until that id expires. What this client keeps is\n * each offer's spec, by its id (`specs.ts`).\n */\n\nexport const ROUTER_PATH = '/api/x402-router';\n\n/**\n * The request the server builds and this client sends verbatim. Query assembly,\n * body encoding and header choice are the server's; what stays here is every\n * check that decides whether to send it at all.\n */\nconst RequestSchema = z.object({\n url: z.string().min(1).max(16_384),\n method: z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']),\n headers: z.record(z.string(), z.string()),\n body: z\n .string()\n .max(256 * 1024)\n .optional(),\n});\n\nconst ContractSchema = z.object({\n /** Flat, for display and for the result check; never re-encoded into a call:\n * the server built `request` from them and this client sends that verbatim. */\n arguments: z.record(z.string(), z.unknown()).optional(),\n resultSchema: z.record(z.string(), z.unknown()).optional(),\n request: RequestSchema,\n});\nexport type DecisionContract = z.infer<typeof ContractSchema>;\n\n/**\n * What stopped an outcome this client cannot execute, in terms the host can act\n * on: a stable reason code, the stage that stopped, the fields or scope choices\n * the user can supply, and one concrete next action.\n */\nconst DiagnosticsSchema = z.object({\n reasonCode: z.string().min(1).max(64),\n stage: z.string().min(1).max(32),\n missing: z.array(z.string().max(200)).max(60),\n nextAction: z.string().max(500),\n});\nexport type DecisionDiagnostics = z.infer<typeof DiagnosticsSchema>;\n\n/**\n * ONE VARIANT PER ANSWER, DISCRIMINATED ON THE ACTION. Optional fields made\n * every shape legal: an `execute` with no contract parsed and came back to the\n * host as a routine `needs_input`, a non-execute with no diagnostics parsed\n * with nothing to act on, and a hook answer carrying a contract parsed as\n * though the hook had quoted a price. Each of those is drift the shared\n * fixtures exist to catch, so each is now a parse failure that names itself.\n *\n * The two calls ask different questions and get different answers, so they get\n * different parsers. The HOOK asks whether a paid lookup is worth offering: an\n * id, or a reason it is not. The TOOL asks for the decision: the capability,\n * its price and the contract together, so a caller cannot approve one offer and\n * receive another.\n */\nconst IdSchema = z\n .string()\n .regex(/^[A-Za-z0-9_-]{8,64}$/)\n .describe(\n 'The turn id, an OPAQUE HANDLE: it is the one piece of server text this ' +\n 'client puts in a model-facing line, so the alphabet is pinned here ' +\n 'rather than escaped later.',\n );\n\n/** Every non-execute answer carries these, beside the action they explain. */\nconst RefusedSchema = z.strictObject({\n reason: z.string().max(2_000).optional(),\n diagnostics: DiagnosticsSchema,\n});\n\n/**\n * WHAT THE SERVICE IS, AND WHAT IT DOES. The hook answer used to be an id and\n * nothing else, so the line the host injected could only say \"a paid lookup is\n * available\", which a model follows 8 to 20 times in 40 where a line naming the\n * task and the service is followed 40 in 40. The gate knows which capability\n * serves the category it chose, so it now says so; the CONTRACT is still not\n * here, because the task the host will run does not exist yet.\n */\nconst CapabilityFields = {\n capabilityId: z.string().min(1).max(200),\n category: z.string().min(1).max(64),\n /** The service's own name, not the x402 reseller in front of it. */\n provider: z.string().min(1).max(120),\n capabilityDescription: z.string().min(1).max(500),\n /** What the provider charges, atomic USDC. The `request` tool refuses a live\n * 402 above it; `gateSpend` still caps the amount actually signed. */\n providerPriceAtomic: z.string().regex(/^\\d+$/),\n};\n\n/**\n * STRUCTURE, NEVER WORDING. A hint lands in the model's context verbatim, so\n * its shape is checked the way the id's alphabet is: one line, no control\n * characters, and it has to be the call it claims to be, naming the id this\n * same answer carries. A hint that fails any of these is a protocol error and\n * the turn falls back to the generic line; nothing here rewrites a word of a\n * hint that passes. Both offering arms, `execute` and `discovered`, hold it.\n */\nfunction checkHint(decision: { id: string; hint: string }, ctx: z.RefinementCtx): void {\n if (/[\\p{Cc}\\p{Cf}]/u.test(decision.hint)) {\n ctx.addIssue({ code: 'custom', path: ['hint'], message: 'a hint is one plain line' });\n }\n if (!decision.hint.includes('request({')) {\n ctx.addIssue({ code: 'custom', path: ['hint'], message: 'a hint names the call to make' });\n }\n if (!decision.hint.includes(decision.id)) {\n ctx.addIssue({\n code: 'custom',\n path: ['hint'],\n message: \"a hint carries this answer's own id\",\n });\n }\n}\n\n/**\n * A PAY-PER-CALL SERVICE NOBODY CURATED. When no capability in the catalog fits\n * but a listed x402 service could do the step, the server names that one\n * service: who sells it, where, for how much, and the input it takes. The\n * candidate is the seller's own listing, so every field is data for the host\n * to judge, never an instruction; the host builds the `input` and the tool\n * call pays through the same `runPay` path and caps as a curated lookup.\n */\nconst DiscoveredCandidateSchema = z.strictObject({\n source: z.string().min(1).max(64),\n provider: z.string().min(1).max(120),\n url: z.string().min(1).max(2_048),\n method: z.enum(['GET', 'POST']),\n description: z.string().max(500),\n providerPriceAtomic: z.string().regex(/^\\d+$/),\n network: z.string().min(1).max(64),\n payTo: z.string().min(1).max(200),\n input: z.strictObject({\n location: z.enum(['body', 'query']),\n schema: z.record(z.string(), z.unknown()),\n }),\n});\n\n/**\n * A REQUEST SPEC: the offered service's real contract, sent beside the line only\n * because this build asks for it (`accepts: [\"spec\"]`). The hook stores it by\n * the offer's id; `request({id})` shows it and `request({id, input})` fills its\n * request and pays the provider directly, with no second decision. Every field\n * is the server's, and so is checked like the rest of the answer: the payee and\n * price still meet the live 402 and the spend policy in `runPay`.\n */\nexport const ToolSpecSchema = z.strictObject({\n capabilityId: z.string().min(1).max(200),\n provider: z.string().min(1).max(120),\n description: z.string().min(1).max(500),\n priceAtomic: z.string().regex(/^\\d+$/),\n priceVaries: z.boolean(),\n maxAmountAtomic: z.string().regex(/^\\d+$/),\n payTo: z.string().min(1).max(200),\n network: z.string().min(1).max(64),\n asset: z.string().min(1).max(200),\n request: z.strictObject({\n method: z.enum(['GET', 'POST']),\n url: z.string().min(1).max(2_048),\n fields: z.record(z.string(), z.enum(['path', 'query', 'body'])),\n location: z.enum(['query', 'body']),\n }),\n input: z.record(z.string(), z.unknown()),\n pinned: z.record(z.string(), z.unknown()),\n example: z.record(z.string(), z.unknown()).optional(),\n returns: z.string().min(1).max(200).optional(),\n returnsExample: z.unknown().optional(),\n resultSchema: z.record(z.string(), z.unknown()).optional(),\n /** The fields the result promises (type, properties, items, required). The\n * agent is handed only these; the whole body is saved to a file. */\n outputSchema: z.record(z.string(), z.unknown()).optional(),\n});\nexport type ToolSpec = z.infer<typeof ToolSpecSchema>;\n\nexport const OfferSpecSchema = ToolSpecSchema.extend({ id: IdSchema });\nexport type OfferSpec = z.infer<typeof OfferSpecSchema>;\n\n/** One spec per service the line names: the offer and any alternative. */\nconst SpecsSchema = z.array(OfferSpecSchema).min(1).max(4).optional();\n\n/** The same answer on both calls: the hook's offer, and the tool's fallback\n * when a query with no id found no curated capability. */\nconst DiscoveredSchema = z\n .strictObject({\n action: z.literal('discovered'),\n id: IdSchema,\n candidate: DiscoveredCandidateSchema,\n /** THE LINE, FINISHED, as on `execute`: it carries the seller's\n * description and the input it takes. */\n hint: z.string().min(1).max(2_000),\n specs: SpecsSchema,\n })\n .superRefine(checkHint);\n\nconst HookDecisionSchema = z.discriminatedUnion('action', [\n z\n .strictObject({\n action: z.literal('execute'),\n id: IdSchema,\n ...CapabilityFields,\n /** The x402 URL a lookup would pay, for the line the server writes. */\n endpoint: z.string().min(1).max(2_048),\n /** What to pass in `query`, in the service's own terms. */\n usage: z.string().min(1).max(300),\n /**\n * THE LINE, FINISHED. The server writes it with the real id in it and, on a\n * native call, the exact search or URL that was denied. The client injects\n * it and composes nothing, which is why there is no hint builder here any\n * more: two sides writing the same sentence is how they drift. The same\n * bound as a discovered line's.\n */\n hint: z.string().min(1).max(2_000),\n specs: SpecsSchema,\n })\n .superRefine(checkHint),\n DiscoveredSchema,\n RefusedSchema.extend({ action: z.literal('native') }),\n RefusedSchema.extend({ action: z.literal('needs_input') }),\n]);\n\nconst ToolDecisionSchema = z.discriminatedUnion('action', [\n z.strictObject({\n action: z.literal('execute'),\n ...CapabilityFields,\n contract: ContractSchema,\n }),\n /**\n * A query with no id, answered with the spec of the service the server\n * picked under a fresh `id`: kept like a hook's, and never run in the same\n * call. `hint` is the line, with the skeleton of the next call:\n * `request({id, input: {...}})` with the required fields. `input` is what a\n * router from before the binder's removal still sends on a bound pick: it\n * is accepted so that answer parses, and never read, so it never runs.\n */\n z\n .strictObject({\n action: z.literal('spec'),\n id: IdSchema,\n spec: ToolSpecSchema,\n hint: z.string().min(1).max(2_000),\n input: z.record(z.string(), z.unknown()).optional(),\n })\n .superRefine(checkHint),\n DiscoveredSchema,\n RefusedSchema.extend({ action: z.literal('native') }),\n RefusedSchema.extend({ action: z.literal('needs_input') }),\n]);\n\nfunction envelope<T extends z.ZodTypeAny>(decision: T) {\n return z.strictObject({\n schemaVersion: z.literal(1),\n routerVersion: z.string().min(1).max(64),\n decision,\n /** A plain sentence about the CALL, such as an id that had expired. Never a\n * failure: the decision beside it ran anyway. */\n note: z.string().max(500).optional(),\n jev: z.object({ calls: z.number(), latencyMs: z.number() }).optional(),\n });\n}\n\nconst HookResponseSchema = envelope(HookDecisionSchema);\nconst ToolResponseSchema = envelope(ToolDecisionSchema);\n\nexport type HookResponse = z.infer<typeof HookResponseSchema>;\nexport type ToolResponse = z.infer<typeof ToolResponseSchema>;\nexport type HookDecision = HookResponse['decision'];\nexport type ToolDecision = ToolResponse['decision'];\n\n/** Which call this is, and therefore which answer is legal for it. */\nexport type CallKind = 'hook' | 'tool';\n\n/**\n * What this client can act on beyond the curated answers, sent on both calls.\n * `discovered` is Tenjin's reviewed list of third-party services, on for every\n * build that parses it; the server answers that arm only to a request that\n * lists it, so an older build never sees one. `spec` asks for each offered\n * service's request spec beside its line, and for the picked service's spec in\n * place of a decision on a query with no id, which only a build that parses\n * them can take: the decision schemas are strict. `bazaar` widens discovery\n * to the open Bazaar and is sent only while `experimental.bazaar` is on.\n */\nexport const CLIENT_ACCEPTS: readonly string[] = ['discovered', 'spec'];\nexport const BAZAAR_ACCEPT = 'bazaar';\n\n/** The `accepts` this build sends, with the open Bazaar or without it. */\nexport function acceptsFor(bazaar: boolean): string[] {\n return bazaar ? [...CLIENT_ACCEPTS, BAZAAR_ACCEPT] : [...CLIENT_ACCEPTS];\n}\n\n/**\n * The exact body the hook call sends, spelled once and pinned to the shared\n * fixtures. The route reads it with a strict object, so an extra field is a\n * 400, and a 400 is a turn with no hint.\n *\n * ONE BODY FOR BOTH HOOKS. Which hook is asking is not a field: the route reads\n * it from `packet.pendingCall`, which the native hook sets and the prompt hook\n * does not. A `source` beside the packet was the `/prepare` route's shape, and\n * that route is gone. `sessionId` is the harness's own session id, which the\n * server uses only so one session is not offered the same discovered service\n * twice.\n */\nexport function buildHookBody(\n packet: Packet,\n extras: { sessionId?: string; accepts?: readonly string[] } = {},\n): Record<string, unknown> {\n return {\n schemaVersion: 1,\n ...(extras.sessionId !== undefined ? { sessionId: extras.sessionId } : {}),\n ...(extras.accepts !== undefined ? { accepts: [...extras.accepts] } : {}),\n packet,\n };\n}\n\n/** The exact body the tool call sends. `id` is the offer the query is for,\n * sent only for an offer with no spec kept; `gateHint` is evidence, never\n * authority. */\nexport function buildToolBody(request: {\n query?: string;\n id?: string;\n gateHint?: GateHint;\n accepts?: readonly string[];\n}): Record<string, unknown> {\n return {\n schemaVersion: 1,\n ...(request.query !== undefined ? { query: request.query } : {}),\n ...(request.id !== undefined ? { id: request.id } : {}),\n ...(request.gateHint !== undefined ? { gateHint: request.gateHint } : {}),\n ...(request.accepts !== undefined ? { accepts: [...request.accepts] } : {}),\n };\n}\n\n/** The parsers, exposed so the shared wire fixtures are checked against the\n * same schemas production parses with rather than against a copy of them. */\nexport function parseForTests(kind: CallKind, value: unknown): { success: boolean } {\n const schema = kind === 'hook' ? HookResponseSchema : ToolResponseSchema;\n return { success: schema.safeParse(value).success };\n}\n\n/**\n * The gate's own reading of this turn, travelling as EVIDENCE for the lookup it\n * was produced for. The backend may refine or reject it, and it authorizes no\n * money: the local spend policy does that. Optional on both call forms.\n */\nexport interface GateHint {\n category: string;\n turnId: string;\n lookupId: string;\n}\n\nexport interface DecisionDeps {\n ctx: CommandContext;\n baseUrl: string;\n /** `experimental.bazaar`: add {@link BAZAAR_ACCEPT}, so a service from the\n * open Bazaar may come back. Off by default: curated and the Tenjin list. */\n acceptsBazaar?: boolean;\n fetchImpl?: typeof fetch;\n /** Overrides the per-call deadline; the hook passes its own, smaller one. */\n timeoutMs?: number;\n /** The paid path, when `tenjin mcp` takes it: the body goes to `path` and is\n * sent by `send`, which pays the routing fee with the stock x402 client.\n * Absent is the free path. */\n route?: DecisionRoute;\n}\n\n/** How a routing call reaches the paid path. `send` throws\n * {@link RouteSkipped} when it has no paid answer for the call, which then\n * takes the free path. */\nexport interface DecisionRoute {\n path: string;\n send: (url: string, options: HttpRequestOptions) => Promise<HttpResult>;\n}\n\n/** The paid path gave this call no answer: the wallet locked, low or over\n * its spend limits, the channel busy, or the payment failed. */\nexport class RouteSkipped extends Error {\n constructor(readonly why: string) {\n super(`routing fee not paid: ${why}`);\n }\n}\n\n/** Another session's call was in flight on the wallet's routing channel. */\nexport const CHANNEL_BUSY = 'channel_busy';\n/** The server answered no paid path. */\nexport const PAID_PATH_ABSENT = 'paid_path_absent';\n/** The paid call got no answer, a refused payment or a server error. */\nexport const PAYMENT_FAILED = 'payment_failed';\n\nexport type DecisionOutcome<T> =\n /** `freePath`: the paid path skipped the call for this reason and it went\n * to the free path instead, unpaid. */\n | { status: 'decided'; decision: T; freePath?: string }\n /** On the free path nothing was paid and nothing could be, so a failure here\n * costs the turn a routing answer and nothing else. */\n | { status: 'failed'; reason: string; errorCode?: string; freePath?: string }\n /** The paid path gave no answer ({@link RouteSkipped}) and no time was left\n * for the free path: the native tool runs. */\n | { status: 'skipped'; why: string };\n\n/**\n * ONE FREE CALL, IN TWO FORMS. The hook sends `{ packet }`: the backend runs\n * the gate, and on `execute` stores that packet under an id and answers with\n * each offered service's spec. The tool sends `{ query }`, which the backend\n * answers with the spec of the service its gate picks, or `{ query, id }` for\n * the free docs offer, which has no spec and is bound from the query. Every\n * provider call is built here, from a spec, or for the docs lookup by the\n * backend from the query.\n */\nexport async function requestDecision(\n kind: 'hook',\n request: { packet: Packet; sessionId?: string },\n deps: DecisionDeps,\n): Promise<DecisionOutcome<HookResponse>>;\nexport async function requestDecision(\n kind: 'tool',\n request: { query: string; id?: string; gateHint?: GateHint },\n deps: DecisionDeps,\n): Promise<DecisionOutcome<ToolResponse>>;\nexport async function requestDecision(\n kind: CallKind,\n request: {\n query?: string;\n packet?: Packet;\n sessionId?: string;\n id?: string;\n gateHint?: GateHint;\n },\n deps: DecisionDeps,\n): Promise<DecisionOutcome<HookResponse | ToolResponse>> {\n const url = new URL(deps.route?.path ?? ROUTER_PATH, deps.baseUrl).toString();\n const options: HttpRequestOptions = {\n method: 'POST',\n timeoutMs: deps.timeoutMs ?? deps.ctx.flags.timeout,\n blockRedirects: true,\n jsonBody:\n kind === 'hook'\n ? buildHookBody(request.packet as Packet, {\n ...(request.sessionId !== undefined ? { sessionId: request.sessionId } : {}),\n accepts: acceptsFor(deps.acceptsBazaar === true),\n })\n : buildToolBody({\n ...(request.query !== undefined ? { query: request.query } : {}),\n ...(request.id !== undefined ? { id: request.id } : {}),\n ...(request.gateHint !== undefined ? { gateHint: request.gateHint } : {}),\n accepts: acceptsFor(deps.acceptsBazaar === true),\n }),\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n };\n const started = Date.now();\n const schema = kind === 'hook' ? HookResponseSchema : ToolResponseSchema;\n let response: HttpResult;\n try {\n response = await (deps.route?.send ?? httpRequest)(url, options);\n } catch (err) {\n if (!(err instanceof RouteSkipped)) throw err;\n const left = options.timeoutMs - (Date.now() - started);\n if (left <= 0) return { status: 'skipped', why: err.why };\n // A CALL THE PAID PATH COULD NOT TAKE STILL ROUTES, on the free path,\n // unpaid, inside what is left of its budget, and says why.\n response = await httpRequest(new URL(ROUTER_PATH, deps.baseUrl).toString(), {\n ...options,\n timeoutMs: left,\n });\n const free = readDecision(response, schema);\n return free.status === 'skipped' ? free : { ...free, freePath: err.why };\n }\n return readDecision(response, schema);\n}\n\n/** How a call run from a request spec ended, for the server's offer-to-call\n * count. No text: the id, the outcome, the provider's status and the time. */\nexport interface SpecOutcome {\n id: string;\n status: 'fulfilled' | 'unverified' | 'failed' | 'needs_approval';\n httpStatus?: number;\n ms?: number;\n}\n\n/** The outcome report's own deadline: it is telemetry and never holds a result. */\nexport const OUTCOME_TIMEOUT_MS = 3_000;\n\n/**\n * TELL THE SERVER A SPEC WAS USED. The client called and paid the provider\n * itself, so this is the only word the server gets that its offer was taken.\n * Never throws and never waits on anything the caller needs: a lost report\n * costs one count.\n */\nexport async function reportSpecOutcome(\n outcome: SpecOutcome,\n deps: Pick<DecisionDeps, 'ctx' | 'baseUrl' | 'fetchImpl'>,\n): Promise<void> {\n try {\n await httpRequest(new URL(ROUTER_PATH, deps.baseUrl).toString(), {\n method: 'POST',\n timeoutMs: OUTCOME_TIMEOUT_MS,\n blockRedirects: true,\n jsonBody: buildOutcomeBody(outcome),\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n });\n } catch {\n // Telemetry only.\n }\n}\n\n/** The exact body of an outcome report, pinned to the shared fixtures. */\nexport function buildOutcomeBody(outcome: SpecOutcome): Record<string, unknown> {\n return {\n schemaVersion: 1,\n id: outcome.id,\n status: outcome.status,\n ...(outcome.httpStatus !== undefined ? { httpStatus: outcome.httpStatus } : {}),\n ...(outcome.ms !== undefined ? { ms: Math.max(0, Math.round(outcome.ms)) } : {}),\n };\n}\n\nfunction readDecision<T extends z.ZodTypeAny>(\n response: HttpResult,\n schema: T,\n): DecisionOutcome<z.infer<T>> {\n // A transport failure says its own reason; nothing was paid either way,\n // because there is nothing to pay for on this route.\n if (!response.ok) return { status: 'failed', reason: fetchFailureToCliError(response).message };\n if (response.status < 200 || response.status >= 300) {\n const named = errorOf(response.json);\n return {\n status: 'failed',\n // The backend's own code and message, never a bare status line: a typed\n // refusal the host could act on was arriving as \"answered 400\".\n reason:\n named === null\n ? `The router endpoint answered ${response.status}.`\n : `The router endpoint answered ${response.status} (${named.code}): ${named.message}`,\n ...(named !== null ? { errorCode: named.code } : {}),\n };\n }\n const parsed = schema.safeParse(response.json);\n if (!parsed.success) {\n return { status: 'failed', reason: 'The router returned a decision this build cannot read.' };\n }\n return { status: 'decided', decision: parsed.data as z.infer<T> };\n}\n\n/** `{ error: { code, message } }`, the envelope every Tenjin route answers a\n * refusal with. Anything else reads as no code rather than as a guess. */\nfunction errorOf(body: unknown): { code: string; message: string } | null {\n if (body === null || typeof body !== 'object') return null;\n const error = (body as { error?: unknown }).error;\n if (error === null || typeof error !== 'object') return null;\n const { code, message } = error as { code?: unknown; message?: unknown };\n if (typeof code !== 'string' || code.length === 0 || code.length > 64) return null;\n const text = typeof message === 'string' ? message.slice(0, 500) : '';\n return { code, message: text };\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,SAAS,gBAAgB;AAClC,SAAS,SAAS,MAAM,eAAe;AAqChC,IAAM,0BAA+C,oBAAI,IAAI;AAAA,EAClE;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAOD,IAAM,uBAAuB,MAAM;AACnC,IAAM,UAAU;AAEhB,eAAsB,kBACpB,WACA,QAC4B;AAC5B,MAAI,cAAc,UAAa,CAAC,QAAQ,KAAK,SAAS,EAAG,QAAO;AAChE,MAAI;AACF,UAAM,OAAO,MAAM,eAAe,WAAW,MAAM;AACnD,QAAI,SAAS,KAAM,QAAO,SAAS,IAAI;AACvC,WAAO,wBAAwB,IAAI,SAAS,IAAI,YAAY;AAAA,EAC9D,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGO,SAAS,SAAS,YAAuC;AAC9D,QAAM,cAAc,cAAc,UAAU;AAC5C,MAAI,gBAAgB,KAAM,QAAO;AACjC,QAAM,aAAa,UAAU,aAAa,iBAAiB;AAC3D,MAAI,eAAe,UAAa,WAAW,KAAK,gBAA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,MAAM,QAAQ,IAAI;AAC1B,MAAI,OAAO,SAAS,YAAY,KAAK,WAAW,KAAK,KAAK,SAAS,GAAI,QAAO;AAC9E,QAAM,OAAO,OAAO,YAAY,WAAW,QAAQ,MAAM,GAAG,GAAG,IAAI;AACnE,SAAO,EAAE,MAAM,SAAS,KAAK;AAC/B;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
2
  import {
3
3
  createLocalSpendAuthorizer
4
- } from "./chunk-XZUGRTSV.js";
4
+ } from "./chunk-CKDD554V.js";
5
5
  import {
6
6
  hashAuthorization,
7
7
  hashMessage,
@@ -45,13 +45,13 @@ import {
45
45
  } from "./chunk-BPMWXTFX.js";
46
46
  import {
47
47
  emitNotice
48
- } from "./chunk-O2WN732M.js";
48
+ } from "./chunk-UDWGT4FX.js";
49
49
  import {
50
50
  hasCode
51
51
  } from "./chunk-2I4QTOLB.js";
52
52
  import {
53
53
  external_exports
54
- } from "./chunk-P22ZWXFX.js";
54
+ } from "./chunk-XICKN3CH.js";
55
55
  import {
56
56
  CliError,
57
57
  fsyncDir,
@@ -1678,4 +1678,4 @@ export {
1678
1678
  @noble/ciphers/esm/utils.js:
1679
1679
  (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
1680
1680
  */
1681
- //# sourceMappingURL=chunk-GPLSNGKX.js.map
1681
+ //# sourceMappingURL=chunk-EG7P4SM6.js.map