@tangle-network/agent-eval 0.20.8 → 0.20.10

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.
@@ -83,13 +83,21 @@ var ErrorResponseSchema = z.object({
83
83
  }).openapi("ErrorResponse");
84
84
  var WIRE_VERSION = "1.0.0";
85
85
  function hashRubric(rubric) {
86
- const stable = JSON.stringify(rubric, Object.keys(rubric).sort());
86
+ const stable = stableStringify(rubric);
87
87
  let h = 5381;
88
88
  for (let i = 0; i < stable.length; i++) {
89
89
  h = h * 33 ^ stable.charCodeAt(i);
90
90
  }
91
91
  return `${rubric.name}@${(h >>> 0).toString(16).padStart(8, "0")}`;
92
92
  }
93
+ function stableStringify(value) {
94
+ if (Array.isArray(value)) return `[${value.map((item) => stableStringify(item)).join(",")}]`;
95
+ if (value && typeof value === "object") {
96
+ const entries = Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => `${JSON.stringify(key)}:${stableStringify(item)}`);
97
+ return `{${entries.join(",")}}`;
98
+ }
99
+ return JSON.stringify(value);
100
+ }
93
101
 
94
102
  // src/wire/rubrics.ts
95
103
  var ANTI_SLOP = {
@@ -225,6 +233,47 @@ function judgeOutputSchema(rubric) {
225
233
  }
226
234
  };
227
235
  }
236
+ function validateJudgeOutput(value, rubric) {
237
+ if (!value || typeof value !== "object") {
238
+ throw new WireError("judge_error", "Judge returned malformed output.", 500, value);
239
+ }
240
+ const raw = value;
241
+ const rawDimensions = raw.dimensions;
242
+ if (!rawDimensions || typeof rawDimensions !== "object" || Array.isArray(rawDimensions)) {
243
+ throw new WireError("judge_error", "Judge returned malformed dimensions.", 500, value);
244
+ }
245
+ const dimensions = {};
246
+ const dimensionRecord = rawDimensions;
247
+ for (const dim of rubric.dimensions) {
248
+ const score = dimensionRecord[dim.id];
249
+ if (typeof score !== "number" || !Number.isFinite(score) || score < dim.min || score > dim.max) {
250
+ throw new WireError("judge_error", `Judge returned invalid score for dimension "${dim.id}".`, 500, value);
251
+ }
252
+ dimensions[dim.id] = score;
253
+ }
254
+ const allowedFailures = new Set(rubric.failureModes.map((mode) => mode.id));
255
+ const allowedWins = new Set(rubric.wins.map((win) => win.id));
256
+ const failureModes = validateIdArray(raw.failureModes, allowedFailures, "failureModes", value);
257
+ const wins = validateIdArray(raw.wins, allowedWins, "wins", value);
258
+ if (typeof raw.rationale !== "string" || raw.rationale.trim().length === 0) {
259
+ throw new WireError("judge_error", "Judge returned missing rationale.", 500, value);
260
+ }
261
+ return { dimensions, failureModes, wins, rationale: raw.rationale };
262
+ }
263
+ function validateIdArray(raw, allowed, field, original) {
264
+ if (raw === void 0) return [];
265
+ if (!Array.isArray(raw)) {
266
+ throw new WireError("judge_error", `Judge returned non-array ${field}.`, 500, original);
267
+ }
268
+ const out = [];
269
+ for (const item of raw) {
270
+ if (typeof item !== "string" || !allowed.has(item)) {
271
+ throw new WireError("judge_error", `Judge returned unknown ${field} id "${String(item)}".`, 500, original);
272
+ }
273
+ out.push(item);
274
+ }
275
+ return out;
276
+ }
228
277
  function compositeScore(dimensions, rubric) {
229
278
  let weighted = 0;
230
279
  let totalWeight = 0;
@@ -273,17 +322,15 @@ async function handleJudge(req) {
273
322
  temperature: 0,
274
323
  timeoutMs: 6e4
275
324
  });
276
- if (!value || typeof value !== "object" || !value.dimensions) {
277
- throw new WireError("judge_error", "Judge returned malformed output.", 500, value);
278
- }
279
- const composite = compositeScore(value.dimensions, rubric);
325
+ const output = validateJudgeOutput(value, rubric);
326
+ const composite = compositeScore(output.dimensions, rubric);
280
327
  const durationMs = Date.now() - startedAt;
281
328
  return {
282
329
  composite,
283
- dimensions: value.dimensions,
284
- failureModes: value.failureModes ?? [],
285
- wins: value.wins ?? [],
286
- rationale: value.rationale,
330
+ dimensions: output.dimensions,
331
+ failureModes: output.failureModes ?? [],
332
+ wins: output.wins ?? [],
333
+ rationale: output.rationale,
287
334
  rubricVersion: hashRubric(rubric),
288
335
  model: result.model,
289
336
  durationMs
@@ -400,7 +447,7 @@ function buildOpenApi(packageVersion) {
400
447
  }
401
448
  });
402
449
  const generator = new OpenApiGeneratorV31(registry.definitions);
403
- return generator.generateDocument({
450
+ const doc = generator.generateDocument({
404
451
  openapi: "3.1.0",
405
452
  info: {
406
453
  title: "@tangle-network/agent-eval \u2014 wire protocol",
@@ -413,6 +460,38 @@ Wire-protocol version: ${WIRE_VERSION}. Bumps on breaking changes to request/res
413
460
  },
414
461
  servers: [{ url: "http://localhost:5005", description: "Local agent-eval serve" }]
415
462
  });
463
+ const rubricRef = { $ref: "#/components/schemas/Rubric" };
464
+ const commonJudgeFields = {
465
+ content: { type: "string", minLength: 1 },
466
+ context: { type: "object", additionalProperties: true },
467
+ model: { type: "string" }
468
+ };
469
+ doc.components ??= {};
470
+ doc.components.schemas ??= {};
471
+ doc.components.schemas.JudgeRequest = {
472
+ oneOf: [
473
+ {
474
+ type: "object",
475
+ additionalProperties: false,
476
+ required: ["rubricName", "content"],
477
+ properties: {
478
+ rubricName: { type: "string", minLength: 1 },
479
+ ...commonJudgeFields
480
+ }
481
+ },
482
+ {
483
+ type: "object",
484
+ additionalProperties: false,
485
+ required: ["rubric", "content"],
486
+ properties: {
487
+ rubric: rubricRef,
488
+ ...commonJudgeFields
489
+ }
490
+ }
491
+ ],
492
+ description: "Judge request. Provide exactly one of rubricName or rubric."
493
+ };
494
+ return doc;
416
495
  }
417
496
 
418
497
  // src/wire/server.ts
@@ -591,4 +670,4 @@ export {
591
670
  runRpcOnce,
592
671
  runRpcBatch
593
672
  };
594
- //# sourceMappingURL=chunk-CJJSB6ZQ.js.map
673
+ //# sourceMappingURL=chunk-LSR4IAYN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/wire/schemas.ts","../src/wire/rubrics.ts","../src/wire/handlers.ts","../src/wire/openapi.ts","../src/wire/server.ts","../src/wire/rpc.ts"],"sourcesContent":["/**\n * Wire-protocol schemas.\n *\n * These Zod schemas are the contract between the agent-eval runtime and\n * any non-TypeScript client (Python, Rust, Go, …). They get rendered to\n * OpenAPI by `wire/openapi.ts` and code-generators consume that spec to\n * produce typed clients in other languages.\n *\n * Rule: if it's not in this file, it isn't on the wire. Keep names and\n * shapes self-explanatory — every field has a `.describe()` so the\n * generated docs are useful without reading the source.\n */\nimport { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi'\nimport { z } from 'zod'\n\nextendZodWithOpenApi(z)\n\n// ── Building blocks ─────────────────────────────────────────────────\n\nexport const RubricDimensionSchema = z\n .object({\n id: z\n .string()\n .min(1)\n .describe('Short stable id like \"buyer_quality\" — used as the key in scoring output.'),\n description: z\n .string()\n .min(1)\n .describe('One-line plain-English meaning. Read by humans reviewing low scores.'),\n weight: z\n .number()\n .min(0)\n .default(1)\n .describe('Relative weight in the composite score. Default 1; 0 disables.'),\n min: z.number().default(0).describe('Lower bound of valid score for this dimension.'),\n max: z.number().default(1).describe('Upper bound of valid score for this dimension.'),\n })\n .openapi('RubricDimension')\n\nexport const FailureModeSchema = z\n .object({\n id: z.string().min(1).describe('Short stable id like \"ai-cadence\" — used in detection lists.'),\n description: z.string().min(1).describe('Plain-English description of the failure pattern.'),\n })\n .openapi('FailureMode')\n\n// ── Rubric ──────────────────────────────────────────────────────────\n\nexport const RubricSchema = z\n .object({\n name: z\n .string()\n .min(1)\n .describe('Stable name like \"anti-slop\" — used by clients to invoke this rubric.'),\n description: z\n .string()\n .min(1)\n .describe('What this rubric measures. Shown in /v1/rubrics listing.'),\n systemPrompt: z\n .string()\n .min(1)\n .describe(\n 'Instructs the judging LLM. Should explain the persona (e.g. \"senior engineer reviewing voice\"), what to score on, and what to return.',\n ),\n dimensions: z\n .array(RubricDimensionSchema)\n .min(1)\n .describe('Scoring axes. The composite score is a weighted sum of these.'),\n failureModes: z\n .array(FailureModeSchema)\n .default([])\n .describe('Patterns to detect; each detected mode appears in the result.failureModes list.'),\n wins: z\n .array(FailureModeSchema)\n .default([])\n .describe('Positive patterns; each detected one appears in the result.wins list.'),\n })\n .openapi('Rubric')\n\n// ── Judge call ──────────────────────────────────────────────────────\n\nexport const JudgeRequestSchema = z\n .object({\n rubricName: z\n .string()\n .optional()\n .describe('Use a built-in rubric by name. Mutually exclusive with `rubric`.'),\n rubric: RubricSchema.optional().describe(\n 'Inline rubric definition. Mutually exclusive with `rubricName`.',\n ),\n content: z\n .string()\n .min(1)\n .describe('The text being judged — a tweet, a blog post, a code snippet, anything stringly.'),\n context: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\n 'Free-form metadata for the rubric to use — analytics, source URL, author, etc. Surfaced to the LLM.',\n ),\n model: z\n .string()\n .optional()\n .describe('Override the judge model (default routes via tcloud). e.g. \"claude-opus-4-7\".'),\n })\n .refine((v) => Boolean(v.rubricName) !== Boolean(v.rubric), {\n message: 'Provide exactly one of `rubricName` or `rubric`.',\n })\n .openapi('JudgeRequest')\n\nexport const JudgeResultSchema = z\n .object({\n composite: z\n .number()\n .min(0)\n .max(1)\n .describe('Weighted combination of dimension scores in 0..1. The single number to gate on.'),\n dimensions: z\n .record(z.string(), z.number())\n .describe('Per-dimension score, keyed by RubricDimension.id.'),\n failureModes: z\n .array(z.string())\n .default([])\n .describe('Failure-mode ids detected in the content (subset of rubric.failureModes ids).'),\n wins: z\n .array(z.string())\n .default([])\n .describe('Win ids detected in the content (subset of rubric.wins ids).'),\n rationale: z\n .string()\n .describe('Plain-English explanation of the score. Surfaced to the human reviewer.'),\n rubricVersion: z\n .string()\n .describe(\n 'Stable hash of the rubric used. Scores are only comparable across runs when this matches.',\n ),\n model: z.string().describe('Model that produced the judgement, for reproducibility.'),\n durationMs: z.number().int().nonnegative().describe('End-to-end wall time for this call.'),\n })\n .openapi('JudgeResult')\n\n// ── Rubric listing ──────────────────────────────────────────────────\n\nexport const RubricInfoSchema = z\n .object({\n name: z.string().describe('Pass this to /v1/judge as `rubricName`.'),\n description: z.string().describe('What this rubric measures.'),\n dimensions: z\n .array(z.object({ id: z.string(), description: z.string(), weight: z.number() }))\n .describe('The scoring axes this rubric uses, with weights.'),\n failureModes: z.array(z.string()).default([]).describe('Failure-mode ids this rubric detects.'),\n rubricVersion: z.string().describe('Stable hash — match this to compare scores across runs.'),\n })\n .openapi('RubricInfo')\n\nexport const ListRubricsResponseSchema = z\n .object({\n rubrics: z.array(RubricInfoSchema),\n })\n .openapi('ListRubricsResponse')\n\n// ── Version / health ────────────────────────────────────────────────\n\nexport const VersionResponseSchema = z\n .object({\n package: z.string().describe('Package name (always \"@tangle-network/agent-eval\").'),\n version: z.string().describe('Semver of the running server. Match your client to this.'),\n wireVersion: z\n .string()\n .describe(\n 'Wire-protocol semver. Bumps separately from package version when the schema changes.',\n ),\n apiSurface: z.array(z.string()).describe('List of supported method names.'),\n })\n .openapi('VersionResponse')\n\nexport const HealthResponseSchema = z\n .object({\n status: z.literal('ok'),\n uptimeSec: z.number(),\n })\n .openapi('HealthResponse')\n\n// ── Errors ──────────────────────────────────────────────────────────\n\nexport const ErrorResponseSchema = z\n .object({\n error: z\n .object({\n code: z\n .string()\n .describe('Machine-readable code: \"validation_error\", \"rubric_not_found\", \"judge_error\".'),\n message: z.string().describe('Human-readable message.'),\n details: z.unknown().optional().describe('Optional structured detail.'),\n })\n .describe('Errors are always wrapped in this shape across all endpoints.'),\n })\n .openapi('ErrorResponse')\n\n// ── Type exports for callers in the same package ────────────────────\n\nexport type RubricDimension = z.infer<typeof RubricDimensionSchema>\nexport type FailureMode = z.infer<typeof FailureModeSchema>\nexport type Rubric = z.infer<typeof RubricSchema>\nexport type JudgeRequest = z.infer<typeof JudgeRequestSchema>\nexport type JudgeResult = z.infer<typeof JudgeResultSchema>\nexport type RubricInfo = z.infer<typeof RubricInfoSchema>\nexport type ListRubricsResponse = z.infer<typeof ListRubricsResponseSchema>\nexport type VersionResponse = z.infer<typeof VersionResponseSchema>\nexport type ErrorResponse = z.infer<typeof ErrorResponseSchema>\n\n// ── Wire-protocol version ───────────────────────────────────────────\n\n/**\n * Bump on any breaking change to a request/response schema.\n * Non-breaking (additive) changes don't require a bump.\n */\nexport const WIRE_VERSION = '1.0.0'\n\n/**\n * Stable hash of a rubric. Used to make scores comparable across runs:\n * if the rubricVersion matches, the rubric was identical.\n */\nexport function hashRubric(rubric: Rubric): string {\n const stable = stableStringify(rubric)\n let h = 5381\n for (let i = 0; i < stable.length; i++) {\n h = (h * 33) ^ stable.charCodeAt(i)\n }\n // Unsigned 32-bit hex, prefixed with rubric name + version slot\n return `${rubric.name}@${(h >>> 0).toString(16).padStart(8, '0')}`\n}\n\nfunction stableStringify(value: unknown): string {\n if (Array.isArray(value)) return `[${value.map((item) => stableStringify(item)).join(',')}]`\n if (value && typeof value === 'object') {\n const entries = Object.entries(value as Record<string, unknown>)\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([key, item]) => `${JSON.stringify(key)}:${stableStringify(item)}`)\n return `{${entries.join(',')}}`\n }\n return JSON.stringify(value)\n}\n","/**\n * Built-in rubrics shipped with agent-eval.\n *\n * A rubric is a set of scoring axes plus a system prompt that tells the\n * judging LLM how to grade against those axes. Built-in rubrics are\n * curated for use cases that recur across Tangle projects — call them\n * by name from any client.\n *\n * Adding a rubric:\n * 1. Define the Rubric object below with a clear `description` and\n * named `dimensions`.\n * 2. Register it in `BUILTIN_RUBRICS` at the bottom.\n * 3. Add a test in `tests/wire/rubrics.test.ts`.\n *\n * Custom rubrics: callers pass `rubric` inline to /v1/judge instead of\n * `rubricName` — see schemas.ts.\n */\nimport type { Rubric } from './schemas'\nimport { hashRubric } from './schemas'\n\n// ── anti-slop ───────────────────────────────────────────────────────\n// Voice/style judge tuned for technical-buyer audiences. Used by the\n// Postiz autoresearch loop and any content-quality gate.\n\nconst ANTI_SLOP: Rubric = {\n name: 'anti-slop',\n description:\n 'Voice and signal quality for content aimed at senior engineers. Catches AI cadence, marketing tone, and engagement-bait shapes.',\n systemPrompt: `You are evaluating a piece of content written for senior engineers and technical founders.\n\nYou score three things:\n- buyer_quality (0..1): would a senior engineer in the target ICP find this worth their attention? High = specific, earned, technically interesting. Low = generic, hyped, off-target.\n- voice (0..1): does it read like a person who built the thing, or like AI/marketing copy?\n- signal (0..1): does it contain a non-obvious detail, constraint, or claim a reader couldn't get from the public docs?\n\nDetect failure modes (return ids matching):\n- ai-cadence: rule-of-three openings, em-dash flourish, \"Let me explain\", \"Here's the thing\", AI rhythm\n- marketing-tone: \"We're excited to announce\", \"thrilled\", \"delighted\", \"game-changer\", buzzword stack\n- vague-claim: technical claim without a specific component, file, or measurement\n- no-hook: opening doesn't earn attention from the target reader\n- engagement-bait: \"agree?\", \"thoughts?\", listicles, controversy-fishing, hook-detail-pitch\n- off-icp: content shape would attract motivational/grift/hype audiences instead of buyers\n- stale-claim: repeats a positioning line we've used many times this month\n\nDetect wins (return ids matching):\n- specific-component: names a real file, component, or measurement\n- earned-detail: shares a non-obvious detail not derivable from public docs\n- constraint-articulated: names a real tradeoff and the side chosen\n- honest-failure: describes a real failure mode and what was done about it\n\nReturn ONLY JSON matching the response schema. Be conservative — most content has 0-1 wins and 1-2 failure modes, not many of each.`,\n dimensions: [\n {\n id: 'buyer_quality',\n description: 'Would the target buyer find this worth attention?',\n weight: 0.5,\n min: 0,\n max: 1,\n },\n {\n id: 'voice',\n description: 'Does it sound like a builder, not AI or marketing?',\n weight: 0.3,\n min: 0,\n max: 1,\n },\n {\n id: 'signal',\n description: 'Non-obvious detail, constraint, or claim?',\n weight: 0.2,\n min: 0,\n max: 1,\n },\n ],\n failureModes: [\n { id: 'ai-cadence', description: 'AI-rhythm openings and transitions' },\n { id: 'marketing-tone', description: 'Buzzwords, hype, corporate-PR voice' },\n { id: 'vague-claim', description: 'Technical claim without specifics' },\n { id: 'no-hook', description: 'Opening fails to earn attention' },\n { id: 'engagement-bait', description: 'Listicle/controversy/agree-pattern' },\n { id: 'off-icp', description: 'Voice attracts the wrong audience' },\n { id: 'stale-claim', description: 'Reuses an over-used positioning line' },\n ],\n wins: [\n { id: 'specific-component', description: 'Names a real file/component/number' },\n { id: 'earned-detail', description: 'Detail not in public docs' },\n { id: 'constraint-articulated', description: 'Names a real tradeoff' },\n { id: 'honest-failure', description: 'Describes a real failure honestly' },\n ],\n}\n\n// ── Registry ────────────────────────────────────────────────────────\n\nexport const BUILTIN_RUBRICS: Record<string, Rubric> = {\n 'anti-slop': ANTI_SLOP,\n}\n\n/** Get a built-in rubric by name, or undefined. */\nexport function getBuiltinRubric(name: string): Rubric | undefined {\n return BUILTIN_RUBRICS[name]\n}\n\n/** List built-in rubrics with their stable versions. */\nexport function listBuiltinRubrics() {\n return Object.values(BUILTIN_RUBRICS).map((r) => ({\n name: r.name,\n description: r.description,\n dimensions: r.dimensions.map((d) => ({\n id: d.id,\n description: d.description,\n weight: d.weight,\n })),\n failureModes: r.failureModes.map((f) => f.id),\n rubricVersion: hashRubric(r),\n }))\n}\n","/**\n * Pure handler functions — the \"business logic\" behind every wire-protocol\n * method. The HTTP server (`server.ts`) and the stdio RPC (`rpc.ts`) both\n * call these. Tests call these directly without spinning a server.\n *\n * Each handler:\n * - Takes a parsed request (already Zod-validated by the transport).\n * - Returns a result that matches the response schema.\n * - Throws `WireError` for caller-fixable errors (404, 400, 422).\n * - Lets unexpected errors bubble — the transport maps them to 500.\n */\nimport { callLlmJson } from '../llm-client'\nimport { getBuiltinRubric, listBuiltinRubrics } from './rubrics'\nimport {\n hashRubric,\n WIRE_VERSION,\n type JudgeRequest,\n type JudgeResult,\n type ListRubricsResponse,\n type Rubric,\n type VersionResponse,\n} from './schemas'\n\n/** Caller-fixable error. The transport renders this to 4xx + ErrorResponse. */\nexport class WireError extends Error {\n constructor(\n public readonly code: string,\n message: string,\n public readonly status: number = 400,\n public readonly details?: unknown,\n ) {\n super(message)\n this.name = 'WireError'\n }\n}\n\n// ── judge ───────────────────────────────────────────────────────────\n\n/** The JSON schema we ask the judging LLM to fill in. */\nfunction judgeOutputSchema(rubric: Rubric) {\n return {\n name: 'JudgeOutput',\n schema: {\n type: 'object',\n additionalProperties: false,\n properties: {\n dimensions: {\n type: 'object',\n additionalProperties: false,\n properties: Object.fromEntries(\n rubric.dimensions.map((d) => [\n d.id,\n { type: 'number', minimum: d.min, maximum: d.max },\n ]),\n ),\n required: rubric.dimensions.map((d) => d.id),\n },\n failureModes: {\n type: 'array',\n items: { type: 'string', enum: rubric.failureModes.map((f) => f.id) },\n },\n wins: {\n type: 'array',\n items: { type: 'string', enum: rubric.wins.map((w) => w.id) },\n },\n rationale: { type: 'string' },\n },\n required: ['dimensions', 'rationale'],\n } as Record<string, unknown>,\n }\n}\n\ninterface JudgeOutput {\n dimensions: Record<string, number>\n failureModes?: string[]\n wins?: string[]\n rationale: string\n}\n\nfunction validateJudgeOutput(value: unknown, rubric: Rubric): JudgeOutput {\n if (!value || typeof value !== 'object') {\n throw new WireError('judge_error', 'Judge returned malformed output.', 500, value)\n }\n const raw = value as Record<string, unknown>\n const rawDimensions = raw.dimensions\n if (!rawDimensions || typeof rawDimensions !== 'object' || Array.isArray(rawDimensions)) {\n throw new WireError('judge_error', 'Judge returned malformed dimensions.', 500, value)\n }\n\n const dimensions: Record<string, number> = {}\n const dimensionRecord = rawDimensions as Record<string, unknown>\n for (const dim of rubric.dimensions) {\n const score = dimensionRecord[dim.id]\n if (typeof score !== 'number' || !Number.isFinite(score) || score < dim.min || score > dim.max) {\n throw new WireError('judge_error', `Judge returned invalid score for dimension \"${dim.id}\".`, 500, value)\n }\n dimensions[dim.id] = score\n }\n\n const allowedFailures = new Set(rubric.failureModes.map((mode) => mode.id))\n const allowedWins = new Set(rubric.wins.map((win) => win.id))\n const failureModes = validateIdArray(raw.failureModes, allowedFailures, 'failureModes', value)\n const wins = validateIdArray(raw.wins, allowedWins, 'wins', value)\n if (typeof raw.rationale !== 'string' || raw.rationale.trim().length === 0) {\n throw new WireError('judge_error', 'Judge returned missing rationale.', 500, value)\n }\n\n return { dimensions, failureModes, wins, rationale: raw.rationale }\n}\n\nfunction validateIdArray(\n raw: unknown,\n allowed: Set<string>,\n field: 'failureModes' | 'wins',\n original: unknown,\n): string[] {\n if (raw === undefined) return []\n if (!Array.isArray(raw)) {\n throw new WireError('judge_error', `Judge returned non-array ${field}.`, 500, original)\n }\n const out: string[] = []\n for (const item of raw) {\n if (typeof item !== 'string' || !allowed.has(item)) {\n throw new WireError('judge_error', `Judge returned unknown ${field} id \"${String(item)}\".`, 500, original)\n }\n out.push(item)\n }\n return out\n}\n\nfunction compositeScore(dimensions: Record<string, number>, rubric: Rubric): number {\n let weighted = 0\n let totalWeight = 0\n for (const dim of rubric.dimensions) {\n const raw = dimensions[dim.id] ?? 0\n const range = dim.max - dim.min || 1\n const normalized = Math.max(0, Math.min(1, (raw - dim.min) / range))\n weighted += normalized * dim.weight\n totalWeight += dim.weight\n }\n return totalWeight > 0 ? weighted / totalWeight : 0\n}\n\nfunction buildJudgePrompt(content: string, context: unknown): string {\n const ctx = context && Object.keys(context as object).length ? JSON.stringify(context) : ''\n return [\n `CONTENT TO JUDGE:`,\n content,\n '',\n ctx ? `CONTEXT (metadata, analytics, etc.):` : '',\n ctx ? ctx : '',\n ]\n .filter(Boolean)\n .join('\\n')\n}\n\nconst DEFAULT_JUDGE_MODEL = 'claude-sonnet-4-6'\n\nexport async function handleJudge(req: JudgeRequest): Promise<JudgeResult> {\n // Resolve rubric\n let rubric: Rubric\n if (req.rubricName) {\n const found = getBuiltinRubric(req.rubricName)\n if (!found) {\n throw new WireError('rubric_not_found', `No built-in rubric named \"${req.rubricName}\".`, 404)\n }\n rubric = found\n } else if (req.rubric) {\n rubric = req.rubric\n } else {\n // refine() in the schema should already have caught this — defense in depth\n throw new WireError('validation_error', 'Provide either `rubricName` or `rubric`.', 422)\n }\n\n const startedAt = Date.now()\n const model = req.model ?? DEFAULT_JUDGE_MODEL\n\n const { value, result } = await callLlmJson<JudgeOutput>({\n model,\n messages: [\n { role: 'system', content: rubric.systemPrompt },\n { role: 'user', content: buildJudgePrompt(req.content, req.context) },\n ],\n jsonSchema: judgeOutputSchema(rubric),\n temperature: 0.0,\n timeoutMs: 60_000,\n })\n\n const output = validateJudgeOutput(value, rubric)\n\n const composite = compositeScore(output.dimensions, rubric)\n const durationMs = Date.now() - startedAt\n\n return {\n composite,\n dimensions: output.dimensions,\n failureModes: output.failureModes ?? [],\n wins: output.wins ?? [],\n rationale: output.rationale,\n rubricVersion: hashRubric(rubric),\n model: result.model,\n durationMs,\n }\n}\n\n// ── listRubrics ─────────────────────────────────────────────────────\n\nexport function handleListRubrics(): ListRubricsResponse {\n return { rubrics: listBuiltinRubrics() }\n}\n\n// ── version ─────────────────────────────────────────────────────────\n\nimport { readFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nlet CACHED_VERSION: string | undefined\n\nfunction readPackageVersion(): string {\n if (CACHED_VERSION) return CACHED_VERSION\n // Walk up from this file looking for the nearest package.json.\n // In dist/ this is dist/.., in src/wire/ this is ../../package.json.\n const here = dirname(fileURLToPath(import.meta.url))\n const candidates = [\n resolve(here, '..', '..', 'package.json'), // src/wire → repo root\n resolve(here, '..', 'package.json'), // dist → repo root\n ]\n for (const path of candidates) {\n try {\n const pkg = JSON.parse(readFileSync(path, 'utf-8')) as { version?: string }\n if (pkg.version) {\n CACHED_VERSION = pkg.version\n return pkg.version\n }\n } catch {\n // try next\n }\n }\n return '0.0.0-unknown'\n}\n\nexport function handleVersion(): VersionResponse {\n return {\n package: '@tangle-network/agent-eval',\n version: readPackageVersion(),\n wireVersion: WIRE_VERSION,\n apiSurface: ['judge', 'listRubrics', 'version'],\n }\n}\n","/**\n * Build an OpenAPI spec from the wire schemas.\n *\n * The spec is the contract that other-language clients (Python, Rust,\n * Go, …) generate from. There is no hand-written client — clients are\n * derived artifacts of this file plus `schemas.ts`.\n *\n * Run `pnpm openapi` (defined in package.json) to write the spec to\n * `dist/openapi.json`. CI uses that file to regenerate the Python\n * client and gate the dual-publish workflow.\n */\nimport { OpenApiGeneratorV31, OpenAPIRegistry } from '@asteasolutions/zod-to-openapi'\nimport type { OpenAPIObject } from 'openapi3-ts/oas31'\n\nimport {\n ErrorResponseSchema,\n HealthResponseSchema,\n JudgeRequestSchema,\n JudgeResultSchema,\n ListRubricsResponseSchema,\n VersionResponseSchema,\n WIRE_VERSION,\n} from './schemas'\n\nexport function buildOpenApi(packageVersion: string): OpenAPIObject {\n const registry = new OpenAPIRegistry()\n\n // Components — each schema becomes a $ref-able component\n registry.register('JudgeRequest', JudgeRequestSchema)\n registry.register('JudgeResult', JudgeResultSchema)\n registry.register('ListRubricsResponse', ListRubricsResponseSchema)\n registry.register('VersionResponse', VersionResponseSchema)\n registry.register('HealthResponse', HealthResponseSchema)\n registry.register('ErrorResponse', ErrorResponseSchema)\n\n // Routes\n registry.registerPath({\n method: 'post',\n path: '/v1/judge',\n summary: 'Score a piece of content against a rubric',\n description:\n 'Runs the judging LLM with the named (or inline) rubric and returns dimension scores, detected failure modes, wins, and a composite score in 0..1.',\n request: {\n body: {\n content: {\n 'application/json': { schema: JudgeRequestSchema },\n },\n },\n },\n responses: {\n 200: {\n description: 'Successful judgement',\n content: { 'application/json': { schema: JudgeResultSchema } },\n },\n 400: {\n description: 'Validation error',\n content: { 'application/json': { schema: ErrorResponseSchema } },\n },\n 404: {\n description: 'Rubric not found',\n content: { 'application/json': { schema: ErrorResponseSchema } },\n },\n 500: {\n description: 'Judge error',\n content: { 'application/json': { schema: ErrorResponseSchema } },\n },\n },\n })\n\n registry.registerPath({\n method: 'get',\n path: '/v1/rubrics',\n summary: 'List built-in rubrics',\n description:\n 'Returns every rubric registered server-side, with their dimensions and stable rubricVersion hash.',\n responses: {\n 200: {\n description: 'Listing',\n content: { 'application/json': { schema: ListRubricsResponseSchema } },\n },\n },\n })\n\n registry.registerPath({\n method: 'get',\n path: '/v1/version',\n summary: 'Server and wire-protocol version',\n description: 'Match your client version to `version`; check `wireVersion` for compatibility.',\n responses: {\n 200: {\n description: 'Version info',\n content: { 'application/json': { schema: VersionResponseSchema } },\n },\n },\n })\n\n registry.registerPath({\n method: 'get',\n path: '/healthz',\n summary: 'Liveness check',\n responses: {\n 200: {\n description: 'OK',\n content: { 'application/json': { schema: HealthResponseSchema } },\n },\n },\n })\n\n const generator = new OpenApiGeneratorV31(registry.definitions)\n const doc = generator.generateDocument({\n openapi: '3.1.0',\n info: {\n title: '@tangle-network/agent-eval — wire protocol',\n version: packageVersion,\n description: `HTTP and stdio RPC interface to agent-eval. The TypeScript runtime is the source of truth; this spec is the contract that cross-language clients (Python, Rust, Go) generate from.\n\nWire-protocol version: ${WIRE_VERSION}. Bumps on breaking changes to request/response schemas.`,\n contact: { name: 'Tangle Network', url: 'https://github.com/tangle-network/agent-eval' },\n license: { name: 'MIT' },\n },\n servers: [{ url: 'http://localhost:5005', description: 'Local agent-eval serve' }],\n })\n const rubricRef = { $ref: '#/components/schemas/Rubric' } as const\n const commonJudgeFields = {\n content: { type: 'string', minLength: 1 },\n context: { type: 'object', additionalProperties: true },\n model: { type: 'string' },\n } as const\n doc.components ??= {}\n doc.components.schemas ??= {}\n doc.components.schemas.JudgeRequest = {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n required: ['rubricName', 'content'],\n properties: {\n rubricName: { type: 'string', minLength: 1 },\n ...commonJudgeFields,\n },\n },\n {\n type: 'object',\n additionalProperties: false,\n required: ['rubric', 'content'],\n properties: {\n rubric: rubricRef,\n ...commonJudgeFields,\n },\n },\n ],\n description: 'Judge request. Provide exactly one of rubricName or rubric.',\n }\n return doc\n}\n","/**\n * HTTP transport for the wire protocol.\n *\n * Hono + @hono/node-server. Every endpoint:\n * 1. Validates the request against its Zod schema.\n * 2. Calls the matching handler in `handlers.ts`.\n * 3. Renders 4xx for `WireError` with structured body, 500 for unexpected.\n *\n * The server has no internal state besides the handler imports — restart\n * costs nothing. Run via `agent-eval serve --port 5005`.\n */\nimport { serve, type ServerType } from '@hono/node-server'\nimport { Hono } from 'hono'\nimport { cors } from 'hono/cors'\n\nimport {\n handleJudge,\n handleListRubrics,\n handleVersion,\n WireError,\n} from './handlers'\nimport { buildOpenApi } from './openapi'\nimport { JudgeRequestSchema } from './schemas'\n\nconst STARTED_AT = Date.now()\n\nexport function createApp() {\n const app = new Hono()\n\n app.use('*', cors())\n\n app.onError((err, c) => {\n if (err instanceof WireError) {\n return c.json(\n { error: { code: err.code, message: err.message, details: err.details } },\n err.status as 400 | 404 | 422 | 500,\n )\n }\n // Unexpected — log and return generic 500 without leaking internals.\n console.error('[agent-eval] unhandled error:', err)\n return c.json(\n { error: { code: 'internal_error', message: 'Internal server error.' } },\n 500,\n )\n })\n\n // ── Health ──\n app.get('/healthz', (c) =>\n c.json({ status: 'ok' as const, uptimeSec: (Date.now() - STARTED_AT) / 1000 }),\n )\n\n // ── Version ──\n app.get('/v1/version', (c) => c.json(handleVersion()))\n\n // ── Rubrics ──\n app.get('/v1/rubrics', (c) => c.json(handleListRubrics()))\n\n // ── Judge ──\n app.post('/v1/judge', async (c) => {\n const raw = await c.req.json().catch(() => null)\n if (raw == null) {\n throw new WireError('validation_error', 'Request body must be JSON.', 400)\n }\n const parsed = JudgeRequestSchema.safeParse(raw)\n if (!parsed.success) {\n throw new WireError(\n 'validation_error',\n 'Request did not match JudgeRequest schema.',\n 400,\n parsed.error.issues,\n )\n }\n const result = await handleJudge(parsed.data)\n return c.json(result)\n })\n\n // ── OpenAPI spec ──\n app.get('/openapi.json', (c) => c.json(buildOpenApi(handleVersion().version)))\n\n return app\n}\n\nexport interface ServeOptions {\n /** Default 5005. */\n port?: number\n /** Default '127.0.0.1'. Set to '0.0.0.0' to listen on all interfaces. */\n host?: string\n}\n\nexport function startServer(opts: ServeOptions = {}): ServerType {\n const app = createApp()\n const port = opts.port ?? 5005\n const host = opts.host ?? '127.0.0.1'\n return serve({ fetch: app.fetch, port, hostname: host }, ({ address, port: actualPort }) => {\n // eslint-disable-next-line no-console\n console.log(`[agent-eval] serving on http://${address}:${actualPort}`)\n })\n}\n","/**\n * stdio RPC transport.\n *\n * For batch / cron use without a running server. The Python client falls\n * back to this when no server is reachable.\n *\n * Protocol (line-delimited JSON over stdin/stdout):\n * IN: one JSON object on stdin: {\"method\":\"judge\",\"params\":{...}}\n * OUT: one JSON object on stdout: {\"result\":{...}} or {\"error\":{...}}\n *\n * One request per process invocation. To pipeline many calls, the client\n * writes JSONL to stdin and reads JSONL from stdout — see batch mode below.\n */\nimport { handleJudge, handleListRubrics, handleVersion, WireError } from './handlers'\nimport { JudgeRequestSchema } from './schemas'\n\ninterface RpcRequest {\n method: 'judge' | 'listRubrics' | 'version'\n params?: unknown\n}\n\ninterface RpcSuccess {\n result: unknown\n}\n\ninterface RpcError {\n error: { code: string; message: string; details?: unknown }\n}\n\nexport async function dispatchRpc(req: RpcRequest): Promise<RpcSuccess | RpcError> {\n try {\n switch (req.method) {\n case 'judge': {\n const parsed = JudgeRequestSchema.safeParse(req.params)\n if (!parsed.success) {\n return {\n error: {\n code: 'validation_error',\n message: 'params did not match JudgeRequest schema.',\n details: parsed.error.issues,\n },\n }\n }\n return { result: await handleJudge(parsed.data) }\n }\n case 'listRubrics':\n return { result: handleListRubrics() }\n case 'version':\n return { result: handleVersion() }\n default:\n return {\n error: {\n code: 'unknown_method',\n message: `No such method: ${(req as { method: string }).method}`,\n },\n }\n }\n } catch (err) {\n if (err instanceof WireError) {\n return { error: { code: err.code, message: err.message, details: err.details } }\n }\n const message = err instanceof Error ? err.message : String(err)\n return { error: { code: 'internal_error', message } }\n }\n}\n\n// ── stdin/stdout driver ─────────────────────────────────────────────\n\nasync function readAll(stream: NodeJS.ReadableStream): Promise<string> {\n const chunks: Buffer[] = []\n for await (const chunk of stream) {\n chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk as string))\n }\n return Buffer.concat(chunks).toString('utf-8')\n}\n\n/** Read one JSON request from stdin, write one JSON response to stdout. */\nexport async function runRpcOnce(method?: string): Promise<number> {\n const raw = await readAll(process.stdin)\n let req: RpcRequest\n try {\n const body = JSON.parse(raw)\n req = method ? { method: method as RpcRequest['method'], params: body } : (body as RpcRequest)\n } catch (err) {\n process.stdout.write(\n JSON.stringify({\n error: {\n code: 'parse_error',\n message: `stdin was not valid JSON: ${err instanceof Error ? err.message : String(err)}`,\n },\n }) + '\\n',\n )\n return 1\n }\n const out = await dispatchRpc(req)\n process.stdout.write(JSON.stringify(out) + '\\n')\n return 'error' in out ? 1 : 0\n}\n\n/** Read JSONL requests from stdin, write JSONL responses to stdout. */\nexport async function runRpcBatch(method?: string): Promise<number> {\n const raw = await readAll(process.stdin)\n const lines = raw.split('\\n').filter((l) => l.trim().length > 0)\n let exitCode = 0\n for (const line of lines) {\n let req: RpcRequest\n try {\n const body = JSON.parse(line)\n req = method ? { method: method as RpcRequest['method'], params: body } : (body as RpcRequest)\n } catch (err) {\n process.stdout.write(\n JSON.stringify({\n error: {\n code: 'parse_error',\n message: `line was not valid JSON: ${err instanceof Error ? err.message : String(err)}`,\n },\n }) + '\\n',\n )\n exitCode = 1\n continue\n }\n const out = await dispatchRpc(req)\n process.stdout.write(JSON.stringify(out) + '\\n')\n if ('error' in out) exitCode = 1\n }\n return exitCode\n}\n"],"mappings":";;;;;AAYA,SAAS,4BAA4B;AACrC,SAAS,SAAS;AAElB,qBAAqB,CAAC;AAIf,IAAM,wBAAwB,EAClC,OAAO;AAAA,EACN,IAAI,EACD,OAAO,EACP,IAAI,CAAC,EACL,SAAS,gFAA2E;AAAA,EACvF,aAAa,EACV,OAAO,EACP,IAAI,CAAC,EACL,SAAS,sEAAsE;AAAA,EAClF,QAAQ,EACL,OAAO,EACP,IAAI,CAAC,EACL,QAAQ,CAAC,EACT,SAAS,gEAAgE;AAAA,EAC5E,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS,gDAAgD;AAAA,EACpF,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS,gDAAgD;AACtF,CAAC,EACA,QAAQ,iBAAiB;AAErB,IAAM,oBAAoB,EAC9B,OAAO;AAAA,EACN,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS,mEAA8D;AA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C;AACA,SAAO;AACT;","names":[]}
package/dist/cli.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  runRpcBatch,
6
6
  runRpcOnce,
7
7
  startServer
8
- } from "./chunk-CJJSB6ZQ.js";
8
+ } from "./chunk-LSR4IAYN.js";
9
9
  import "./chunk-JAOLXRIA.js";
10
10
  import "./chunk-PZ5AY32C.js";
11
11
 
@@ -0,0 +1,290 @@
1
+ /**
2
+ * Paper-grade RunRecord schema + runtime validator.
3
+ *
4
+ * Every run that participates in a promotion gate, paper table, or
5
+ * researcher loop SHOULD be recorded as a `RunRecord`. The mandatory
6
+ * fields are exactly those the paper "Two Loops, Three Roles" requires
7
+ * for reproducibility: who/what/when/cost/seed/hash, plus the search vs
8
+ * holdout split tag and either a `searchScore` or a `holdoutScore`.
9
+ *
10
+ * This is intentionally NOT a replacement for the rich `Run` /
11
+ * `ProposeReviewReport` / `ScenarioResult` types already in the
12
+ * package. Those are runtime structures with full provenance. A
13
+ * `RunRecord` is the analysis-time projection — the JSON-friendly
14
+ * row you'd put in a parquet file or paste into a notebook.
15
+ *
16
+ * Validate at the boundary:
17
+ *
18
+ * const rec = validateRunRecord(rawJson) // throws on missing
19
+ * const ok = isRunRecord(rawJson) // boolean check
20
+ * const rec = parseRunRecordSafe(rawJson) // { ok, value | error }
21
+ *
22
+ * The validator runs in pure TS — zod is intentionally NOT a
23
+ * dependency. Round-trip tested in `tests/run-record.test.ts`.
24
+ */
25
+ /** Search/dev/holdout split tag. 'search' is the paper-grade alias for the
26
+ * combined train+test pool that the optimizer is allowed to read. */
27
+ type RunSplitTag = 'search' | 'dev' | 'holdout';
28
+ interface RunTokenUsage {
29
+ input: number;
30
+ output: number;
31
+ cached?: number;
32
+ }
33
+ interface RunJudgeMetadata {
34
+ model: string;
35
+ promptVersion: string;
36
+ /** [0,1] confidence the judge declared. Constant judge confidence
37
+ * across many runs is a fallback signal (see `canary.ts`). */
38
+ confidence: number;
39
+ /** True if the judge degraded to a fallback path (rules-only,
40
+ * prior-call cache, etc.). The canary uses this to alert. */
41
+ fallback: boolean;
42
+ }
43
+ interface RunOutcome {
44
+ /** Score on the search/optimization split. Optional because a
45
+ * holdout-only evaluation only fills `holdoutScore`. */
46
+ searchScore?: number;
47
+ /** Score on the held-out split. Optional because a search-only run
48
+ * only fills `searchScore`. At least one must be present. */
49
+ holdoutScore?: number;
50
+ /** Bag of any other metric the run produced — judge dimensions,
51
+ * pass/fail counters, latency stats, etc. Numeric only — keeps
52
+ * reporters honest. */
53
+ raw: Record<string, number>;
54
+ }
55
+ /**
56
+ * Mandatory paper-grade fields for a single evaluation run. Optional
57
+ * fields are extension points; mandatory fields throw if missing.
58
+ *
59
+ * Hash discipline:
60
+ * - `promptHash` is the sha256 of the EFFECTIVE prompt sent to the
61
+ * model (after any steering bundle merge).
62
+ * - `configHash` is the sha256 of the effective run config (model,
63
+ * temperature, tools, judges, splits). The pair (promptHash,
64
+ * configHash) uniquely identifies an experimental cell.
65
+ *
66
+ * Model snapshot discipline:
67
+ * - `model` MUST encode a snapshot version. Bare aliases like
68
+ * `claude-sonnet-4` or `gpt-4o` are banned — they remap silently.
69
+ * Use `claude-sonnet-4-6@2025-04-15` or `gpt-4o-2024-11-20`.
70
+ */
71
+ interface RunRecord {
72
+ /** UUID for the run. */
73
+ runId: string;
74
+ /** Logical experiment grouping (a treatment vs a baseline within
75
+ * the same sweep should share `experimentId`). */
76
+ experimentId: string;
77
+ /** Stable identifier for the candidate (variant) being run. The
78
+ * promotion gate compares two `candidateId`s on matched items. */
79
+ candidateId: string;
80
+ /** RNG seed for the run. Always recorded — silent re-seeding is
81
+ * the most common cause of non-reproducible numbers. */
82
+ seed: number;
83
+ /** Model identifier WITH snapshot version. */
84
+ model: string;
85
+ /** sha256 of the effective prompt (post-steering). */
86
+ promptHash: string;
87
+ /** sha256 of the effective config. */
88
+ configHash: string;
89
+ /** Git SHA the harness was run from. */
90
+ commitSha: string;
91
+ /** End-to-end wall-clock duration in milliseconds. */
92
+ wallMs: number;
93
+ /** Time spent queued before execution started, if known. */
94
+ queueMs?: number;
95
+ /** Total USD cost. Mandatory — runs without a cost number are
96
+ * unbounded by definition and must not be admitted into the gate. */
97
+ costUsd: number;
98
+ /** Token usage breakdown. */
99
+ tokenUsage: RunTokenUsage;
100
+ /** Judge-side metadata, if a judge was used. */
101
+ judgeMetadata?: RunJudgeMetadata;
102
+ /** Per-split scores + raw bag. */
103
+ outcome: RunOutcome;
104
+ /** Categorical failure tag, when the run failed and the harness
105
+ * classified it. Free-form string; standard tags live in
106
+ * `failure-taxonomy.ts`. */
107
+ failureMode?: string;
108
+ /** Which split this run was drawn from. */
109
+ splitTag: RunSplitTag;
110
+ }
111
+ declare class RunRecordValidationError extends Error {
112
+ readonly path: string;
113
+ constructor(message: string, path?: string);
114
+ }
115
+ /**
116
+ * Strict validator. Throws `RunRecordValidationError` on the first
117
+ * missing or wrongly-typed field. Returns the input cast to
118
+ * `RunRecord` on success — the validator does not coerce.
119
+ */
120
+ declare function validateRunRecord(input: unknown): RunRecord;
121
+ /** Boolean validator — convenience for filtering arrays. */
122
+ declare function isRunRecord(input: unknown): input is RunRecord;
123
+ /** Non-throwing validator — returns a discriminated union. */
124
+ declare function parseRunRecordSafe(input: unknown): {
125
+ ok: true;
126
+ value: RunRecord;
127
+ } | {
128
+ ok: false;
129
+ error: RunRecordValidationError;
130
+ };
131
+ /** Round-trip helper — `JSON.parse(JSON.stringify(record))` then validate. */
132
+ declare function roundTripRunRecord(record: RunRecord): RunRecord;
133
+
134
+ /**
135
+ * Shared types for the reference benchmark wrappers under
136
+ * `src/benchmarks/`. Each wrapper exports the three functions in
137
+ * `BenchmarkAdapter` plus its own typed `DatasetItem` shape.
138
+ */
139
+
140
+ interface BenchmarkDatasetItem<TPayload = unknown> {
141
+ /** Stable dataset-local item id (used for split assignment + paper
142
+ * references). Unique within a benchmark. */
143
+ id: string;
144
+ /** Free-form payload. Each benchmark defines its own shape. */
145
+ payload: TPayload;
146
+ }
147
+ interface BenchmarkEvaluation {
148
+ /** [0, 1] score for the response on this item. Exact-match
149
+ * benchmarks use 0/1; partial-credit benchmarks may return
150
+ * fractional values. */
151
+ score: number;
152
+ /** Optional bag of raw scoring signals — e.g. parsed numeric
153
+ * answer, regex match, judge sub-scores. */
154
+ raw: Record<string, unknown>;
155
+ }
156
+ /** Common signature implemented by every adapter under `src/benchmarks/*`. */
157
+ interface BenchmarkAdapter<_TItem = unknown, TPayload = unknown> {
158
+ /** Load the dataset for the given split. May hit the network on
159
+ * first call but should be cache-friendly. Adapters that don't
160
+ * ship the dataset itself MUST throw a clearly-marked error
161
+ * pointing the caller at the loader script. */
162
+ loadDataset(split: RunSplitTag): Promise<BenchmarkDatasetItem<TPayload>[]>;
163
+ /** Score a single response. Pure with respect to the inputs. */
164
+ evaluate(item: BenchmarkDatasetItem<TPayload>, response: string): Promise<BenchmarkEvaluation>;
165
+ /** Deterministic split assignment via item id hashing. The
166
+ * fraction of items in each split is implementation-defined but
167
+ * MUST be stable across processes and platforms. */
168
+ assignSplit(itemId: string): RunSplitTag;
169
+ }
170
+ /** Split-assignment seed shared across all benchmarks. Bumping this
171
+ * value reshuffles every split — do NOT do that lightly. */
172
+ declare const BENCHMARK_SPLIT_SEED = "agent-eval-v1";
173
+ /**
174
+ * Assign an item id to one of `'search' | 'dev' | 'holdout'` using a
175
+ * stable 32-bit hash of `${seed}::${id}`. Default proportions:
176
+ *
177
+ * search: 60% (optimization-readable)
178
+ * dev: 20% (held-out for tuning, leak-on-purpose during dev)
179
+ * holdout:20% (paper-grade held-out, gated reads)
180
+ */
181
+ declare function deterministicSplit(itemId: string, seed?: string): RunSplitTag;
182
+
183
+ /**
184
+ * Synthetic routing dataset. 16 tasks across 4 categories. Used as a
185
+ * deterministic, dependency-free benchmark for any router that maps a
186
+ * natural-language request to one of a fixed set of route labels.
187
+ *
188
+ * Format (see `routing/README.md` for prose):
189
+ *
190
+ * {
191
+ * id: stable per-task ID (matches across processes).
192
+ * category: one of the four route labels.
193
+ * prompt: the user-facing request the router must classify.
194
+ * route: the ground-truth route the router should pick.
195
+ * synonyms: other strings that count as a correct answer.
196
+ * hardNegatives:close-but-wrong route labels — used to detect the
197
+ * "always picks the popular route" failure mode.
198
+ * }
199
+ *
200
+ * The four categories are intentionally cross-domain (file ops,
201
+ * math, search, conversation) so a router that collapses to one
202
+ * category is easy to spot.
203
+ */
204
+ interface RoutingItem {
205
+ id: string;
206
+ category: 'file' | 'math' | 'search' | 'chat';
207
+ prompt: string;
208
+ /** Canonical correct route label. */
209
+ route: string;
210
+ /** Alternate route labels that also count as correct. */
211
+ synonyms: string[];
212
+ /** Wrong-but-tempting route labels (for analysis, not grading). */
213
+ hardNegatives: string[];
214
+ }
215
+ declare const ROUTING_DATASET: RoutingItem[];
216
+
217
+ /**
218
+ * Routing benchmark — synthetic, dependency-free, ships in the
219
+ * package. 16 cross-category items in `dataset.ts`. See
220
+ * `routing/README.md` for the format.
221
+ *
222
+ * `evaluate` does case-insensitive exact match against the canonical
223
+ * route plus declared synonyms. The first valid route token in the
224
+ * response wins; everything else is ignored. Wrong answers also
225
+ * report whether they hit a hard negative — useful when triaging
226
+ * "always picks the popular route" failure modes.
227
+ */
228
+
229
+ type RoutingPayload = RoutingItem;
230
+ type RoutingDatasetItem = BenchmarkDatasetItem<RoutingPayload>;
231
+ declare class RoutingAdapter implements BenchmarkAdapter<RoutingDatasetItem, RoutingPayload> {
232
+ loadDataset(split: RunSplitTag): Promise<RoutingDatasetItem[]>;
233
+ evaluate(item: RoutingDatasetItem, response: string): Promise<BenchmarkEvaluation>;
234
+ assignSplit(itemId: string): RunSplitTag;
235
+ }
236
+ /**
237
+ * Pull route-shaped tokens out of a model response. Routes look like
238
+ * `category.action` (`fs.write`, `chat.reply`). Bare alphanumerics
239
+ * are not routes, but `category.action` patterns are robust to most
240
+ * model wrappers (JSON output, prose explanations, code fences).
241
+ */
242
+ declare function extractRouteTokens(response: string): string[];
243
+ declare const loadDataset: (split: RunSplitTag) => Promise<RoutingDatasetItem[]>;
244
+ declare const evaluate: (item: RoutingDatasetItem, response: string) => Promise<BenchmarkEvaluation>;
245
+ declare const assignSplit: (itemId: string) => RunSplitTag;
246
+
247
+ declare const index$1_ROUTING_DATASET: typeof ROUTING_DATASET;
248
+ type index$1_RoutingAdapter = RoutingAdapter;
249
+ declare const index$1_RoutingAdapter: typeof RoutingAdapter;
250
+ type index$1_RoutingDatasetItem = RoutingDatasetItem;
251
+ type index$1_RoutingItem = RoutingItem;
252
+ type index$1_RoutingPayload = RoutingPayload;
253
+ declare const index$1_assignSplit: typeof assignSplit;
254
+ declare const index$1_evaluate: typeof evaluate;
255
+ declare const index$1_extractRouteTokens: typeof extractRouteTokens;
256
+ declare const index$1_loadDataset: typeof loadDataset;
257
+ declare namespace index$1 {
258
+ export { index$1_ROUTING_DATASET as ROUTING_DATASET, index$1_RoutingAdapter as RoutingAdapter, type index$1_RoutingDatasetItem as RoutingDatasetItem, type index$1_RoutingItem as RoutingItem, type index$1_RoutingPayload as RoutingPayload, index$1_assignSplit as assignSplit, index$1_evaluate as evaluate, index$1_extractRouteTokens as extractRouteTokens, index$1_loadDataset as loadDataset };
259
+ }
260
+
261
+ /**
262
+ * Reference benchmark wrappers — entry point.
263
+ *
264
+ * Core surface (exported here):
265
+ * - The `BenchmarkAdapter` contract.
266
+ * - `deterministicSplit` + `BENCHMARK_SPLIT_SEED` for split assignment.
267
+ * - `routing` — synthetic 16-task router benchmark. The only novel
268
+ * benchmark we built; ships in the package.
269
+ *
270
+ * Example wrappers (under `examples/benchmarks/`, NOT in the bundle):
271
+ * - `gsm8k` — exact-match math reasoning (HF mirror, dataset
272
+ * not bundled).
273
+ * - `swebench-lite` — 30-instance SWE-Bench subset via an external
274
+ * grader command.
275
+ *
276
+ * The example wrappers are reference implementations of `BenchmarkAdapter`.
277
+ * Read them, copy them, adapt them. They're intentionally not in the main
278
+ * entry — every team will configure them differently.
279
+ */
280
+
281
+ declare const index_BENCHMARK_SPLIT_SEED: typeof BENCHMARK_SPLIT_SEED;
282
+ type index_BenchmarkAdapter<_TItem = unknown, TPayload = unknown> = BenchmarkAdapter<_TItem, TPayload>;
283
+ type index_BenchmarkDatasetItem<TPayload = unknown> = BenchmarkDatasetItem<TPayload>;
284
+ type index_BenchmarkEvaluation = BenchmarkEvaluation;
285
+ declare const index_deterministicSplit: typeof deterministicSplit;
286
+ declare namespace index {
287
+ export { index_BENCHMARK_SPLIT_SEED as BENCHMARK_SPLIT_SEED, type index_BenchmarkAdapter as BenchmarkAdapter, type index_BenchmarkDatasetItem as BenchmarkDatasetItem, type index_BenchmarkEvaluation as BenchmarkEvaluation, index_deterministicSplit as deterministicSplit, index$1 as routing };
288
+ }
289
+
290
+ export { BENCHMARK_SPLIT_SEED as B, type RunRecord as R, type RunSplitTag as a, type BenchmarkAdapter as b, type BenchmarkDatasetItem as c, type BenchmarkEvaluation as d, type RunJudgeMetadata as e, type RunOutcome as f, RunRecordValidationError as g, type RunTokenUsage as h, deterministicSplit as i, index as j, isRunRecord as k, index$1 as l, parseRunRecordSafe as p, roundTripRunRecord as r, validateRunRecord as v };