@tangle-network/agent-eval 0.179.0 → 0.180.0

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 (29) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +13 -0
  3. package/dist/analyst/index.d.ts +2 -2
  4. package/dist/analyst/index.js +2 -2
  5. package/dist/{benchmark-command-CY6Dg5t5.js → benchmark-command-D4vpnAdO.js} +2 -2
  6. package/dist/{benchmark-command-CY6Dg5t5.js.map → benchmark-command-D4vpnAdO.js.map} +1 -1
  7. package/dist/cli.js +2 -2
  8. package/dist/contract/index.js +1 -1
  9. package/dist/{default-registry-BryMEmr8.js → default-registry-aL7xUrUz.js} +2 -2
  10. package/dist/{default-registry-BryMEmr8.js.map → default-registry-aL7xUrUz.js.map} +1 -1
  11. package/dist/{index-CbLmrWCa.d.ts → index-CiUjjEIa.d.ts} +2 -2
  12. package/dist/{index-CbLmrWCa.d.ts.map → index-CiUjjEIa.d.ts.map} +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.js +1 -1
  15. package/dist/{integrity-DsHWCebQ.js → integrity-DH5ng72x.js} +2 -2
  16. package/dist/{integrity-DsHWCebQ.js.map → integrity-DH5ng72x.js.map} +1 -1
  17. package/dist/openapi.json +1 -1
  18. package/dist/{report-command-DKlXfU5r.js → report-command-V1ecVgAv.js} +27 -3
  19. package/dist/report-command-V1ecVgAv.js.map +1 -0
  20. package/dist/supervisor-run/index.d.ts +4 -2
  21. package/dist/supervisor-run/index.d.ts.map +1 -1
  22. package/dist/supervisor-run/index.js +3 -3
  23. package/dist/{terminal-record-Ce9_UjRz.js → terminal-record-BtPwKTSr.js} +58 -26
  24. package/dist/terminal-record-BtPwKTSr.js.map +1 -0
  25. package/dist/{types-vUdAx2Cj.d.ts → types-lPkDQNqJ.d.ts} +20 -2
  26. package/dist/{types-vUdAx2Cj.d.ts.map → types-lPkDQNqJ.d.ts.map} +1 -1
  27. package/package.json +1 -1
  28. package/dist/report-command-DKlXfU5r.js.map +0 -1
  29. package/dist/terminal-record-Ce9_UjRz.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"benchmark-command-CY6Dg5t5.js","names":["nonEmpty","isRecord","isRecord","nonEmpty","isRecord","summarizeRunner","escapeCell","rate","number","mean","requiredString","mean","safeInteger","positiveInteger","rate","isRecord","TextDecoder","isNodeError","slashRelative","isRecord","escapeCell","rate","trajectoryIdFromCaseId","pricingForModel","isPaidCallControlError","trajectoryIdFromCaseId","pricingForModel","httpsRequest","httpRequest"],"sources":["../src/analyst/benchmark-dataset-utils.ts","../src/analyst/benchmark-dataset-agentrx.ts","../src/analyst/benchmark-dataset-codetrace.ts","../src/analyst/benchmark-agentrx-calibration.ts","../src/analyst/benchmark-comparison.ts","../src/analyst/benchmark-command-validation.ts","../src/analyst/benchmark-command-artifact.ts","../src/analyst/benchmark-implementation.ts","../src/analyst/benchmark-evidence-validation.ts","../src/analyst/benchmark-verification-outcome.ts","../src/analyst/benchmark-verification-artifacts.ts","../src/analyst/benchmark-public-prompt.ts","../src/analyst/benchmark-instructions-override.ts","../src/analyst/benchmark-command-persistence.ts","../src/analyst/benchmark-public-calibration.ts","../src/analyst/benchmark-command-result.ts","../src/analyst/benchmark-public-adapters.ts","../src/analyst/benchmark-public-errors.ts","../src/analyst/benchmark-public-types.ts","../src/analyst/benchmark-response-cache.ts","../src/analyst/definition.ts","../src/analyst/benchmark-public-model.ts","../src/analyst/benchmark-public-consensus.ts","../src/analyst/benchmark-public-rlm.ts","../src/analyst/benchmark-public-data.ts","../src/analyst/prime-bridge-transport.ts","../src/analyst/benchmark-runner-prime.ts","../src/analyst/benchmark-report.ts","../src/analyst/benchmark-command.ts"],"sourcesContent":["import type { ExternalId } from './benchmark-dataset-types'\n\nexport function normalizeBenchmarkLabel(value: string): string {\n const normalized = nonEmpty(value, 'benchmark label')\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-|-$/g, '')\n if (!normalized) throw new TypeError('benchmark label must contain letters or digits')\n return normalized\n}\n\nexport function predictionConfidence(value: number | undefined): number {\n const confidence = value ?? 0.5\n if (!Number.isFinite(confidence) || confidence < 0 || confidence > 1) {\n throw new RangeError('upstream prediction confidence must be between 0 and 1')\n }\n return confidence\n}\n\nexport function assertStepWithinRange(\n step: number,\n stepCount: number | undefined,\n field: string,\n): void {\n if (stepCount === undefined) return\n const count = positiveStep(stepCount, `${field} stepCount`)\n if (step > count) throw new RangeError(`${field} step ${step} exceeds stepCount ${count}`)\n}\n\nexport function defaultStepUri(trajectoryId: string, step: number): string {\n return `trace://${encodeURIComponent(trajectoryId)}/span/step-${step}`\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nexport function positiveStep(value: number, field: string): number {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new RangeError(`${field} must be a positive safe integer`)\n }\n return value\n}\n\nexport function externalId(value: ExternalId | undefined, field: string): string {\n if (typeof value !== 'string' && typeof value !== 'number') {\n throw new TypeError(`${field} must be a string or number`)\n }\n if (typeof value === 'number' && !Number.isSafeInteger(value)) {\n throw new TypeError(`${field} must be a safe integer when numeric`)\n }\n return nonEmpty(String(value), field)\n}\n\nexport function nonEmpty(value: string, field: string): string {\n if (!value.trim()) throw new TypeError(`${field} must not be empty`)\n return value\n}\n","import type { AnalystBenchmarkCase } from './benchmark'\nimport type {\n AgentRxBenchmarkCaseOptions,\n AgentRxPrediction,\n AgentRxPredictionReport,\n AgentRxRow,\n ExternalId,\n UpstreamPredictionAdapterOptions,\n} from './benchmark-dataset-types'\nimport {\n assertStepWithinRange,\n defaultStepUri,\n externalId,\n isRecord,\n normalizeBenchmarkLabel,\n positiveStep,\n predictionConfidence,\n} from './benchmark-dataset-utils'\nimport { type AnalystFinding, makeFinding } from './types'\n\nexport function agentRxBenchmarkCase<TInput>(\n row: AgentRxRow,\n input: TInput,\n options: AgentRxBenchmarkCaseOptions = {},\n): AnalystBenchmarkCase<TInput> {\n const trajectoryId = externalId(row.trajectory_id, 'AgentRx trajectory_id')\n if (!Array.isArray(row.failures) || row.failures.length === 0) {\n throw new TypeError(`AgentRx trajectory '${trajectoryId}' must contain failures`)\n }\n if (row.num_failures !== undefined && row.num_failures !== row.failures.length) {\n throw new TypeError(\n `AgentRx trajectory '${trajectoryId}' declares ${row.num_failures} failures but contains ${row.failures.length}`,\n )\n }\n const rootCauseId = externalId(\n row.root_cause_failure_id ?? row.root_cause?.failure_id,\n `AgentRx trajectory '${trajectoryId}' root cause failure id`,\n )\n const failureIds = new Set<string>()\n const failureMetadata: Array<{ id: string; step: number; category: string }> = []\n const evidenceKind = options.evidenceKind ?? 'span'\n const uri = options.stepUri ?? defaultStepUri\n const allIssues = row.failures.map((failure) => {\n const failureId = externalId(\n failure.failure_id,\n `AgentRx trajectory '${trajectoryId}' failure id`,\n )\n if (failureIds.has(failureId)) {\n throw new TypeError(`AgentRx trajectory '${trajectoryId}' repeats failure id '${failureId}'`)\n }\n failureIds.add(failureId)\n const step = positiveStep(failure.step_number, `AgentRx trajectory '${trajectoryId}'`)\n const evidence = [{ kind: evidenceKind, uri: uri(trajectoryId, step) }]\n if (typeof failure.failure_category !== 'string') {\n throw new TypeError(\n `AgentRx trajectory '${trajectoryId}' failure '${failureId}' category must be a string`,\n )\n }\n const category = normalizeAgentRxCategory(failure.failure_category)\n if (!AGENT_RX_TAXONOMY_BY_LABEL.has(category)) {\n throw new RangeError(\n `AgentRx trajectory '${trajectoryId}' failure '${failureId}' category '${failure.failure_category}' is outside the AgentRx taxonomy`,\n )\n }\n failureMetadata.push({ id: failureId, step, category })\n return {\n id: failureId,\n areas: [category],\n ...(failureId === rootCauseId && (options.target ?? 'root-cause') === 'root-cause'\n ? {}\n : { evidence }),\n criticalEvidence: failureId === rootCauseId ? evidence : undefined,\n }\n })\n if (!failureIds.has(rootCauseId)) {\n throw new TypeError(\n `AgentRx trajectory '${trajectoryId}' root cause '${rootCauseId}' is not in failures`,\n )\n }\n if (\n options.stepCount !== undefined &&\n row.failures.some((failure) => failure.step_number > options.stepCount!)\n ) {\n throw new RangeError(\n `AgentRx trajectory '${trajectoryId}' contains a failure beyond stepCount ${options.stepCount}`,\n )\n }\n const expectedIssues =\n (options.target ?? 'root-cause') === 'root-cause'\n ? allIssues.filter((issue) => issue.id === rootCauseId)\n : allIssues\n const rootCause = failureMetadata.find((failure) => failure.id === rootCauseId)!\n const orderedFailures = [...failureMetadata].sort(\n (left, right) => left.step - right.step || left.id.localeCompare(right.id),\n )\n\n const rootCauseReason = row.root_cause_reason ?? row.root_cause?.reason_for_root_cause\n\n return {\n id: `agentrx:${trajectoryId}`,\n clusterId: `agentrx:${trajectoryId}`,\n labelState: 'positive',\n input,\n expectedIssues,\n labeledEvidence: expectedIssues.flatMap(\n (issue) => issue.evidence ?? issue.criticalEvidence ?? [],\n ),\n tags: ['agentrx'],\n metadata: {\n benchmark: 'AgentRx',\n trajectoryId,\n ...(row.failure_summary === undefined ? {} : { failureSummary: row.failure_summary }),\n ...(rootCauseReason === undefined ? {} : { rootCauseReason }),\n annotatedFailures: row.failures.length,\n target: options.target ?? 'root-cause',\n rootCauseStep: rootCause.step,\n rootCauseCategory: rootCause.category,\n allFailureCategories: [...new Set(failureMetadata.map((failure) => failure.category))].sort(),\n earliestFailureCategory: orderedFailures[0]!.category,\n terminalFailureCategory: orderedFailures.at(-1)!.category,\n ...(options.stepCount === undefined ? {} : { trajectoryLength: options.stepCount }),\n },\n }\n}\n\n/** Translate AgentRx `Report.to_dict()` output or its `failures` array into findings. */\nexport function agentRxPredictionsToFindings(\n trajectoryIdValue: ExternalId,\n output: unknown,\n options: UpstreamPredictionAdapterOptions = {},\n): AnalystFinding[] {\n const trajectoryId = externalId(trajectoryIdValue, 'AgentRx prediction trajectory id')\n const parsed = parseAgentRxPredictions(output, trajectoryId)\n for (const prediction of parsed.predictions) {\n assertStepWithinRange(\n prediction.step_number,\n parsed.report?.trajectory_length,\n `AgentRx prediction '${trajectoryId}' report`,\n )\n assertStepWithinRange(\n prediction.step_number,\n options.stepCount,\n `AgentRx prediction '${trajectoryId}'`,\n )\n }\n const consensus = agentRxConsensus(parsed, trajectoryId)\n if (consensus.failureCase === 0) return []\n const confidence = predictionConfidence(options.confidence)\n const uri = options.stepUri ?? defaultStepUri\n assertStepWithinRange(consensus.step, options.stepCount, `AgentRx prediction '${trajectoryId}'`)\n const area = AGENT_RX_TAXONOMY.get(consensus.failureCase)!\n return [\n makeFinding({\n analyst_id: options.analystId ?? 'agentrx',\n produced_at: options.producedAt,\n area,\n subject: 'root-cause',\n claim: `AgentRx classified step ${consensus.step} as ${area}.`,\n id_basis: `${area}:${consensus.step}`,\n rationale: consensus.representative.description,\n severity: 'high',\n confidence,\n evidence_refs: [\n {\n kind: options.evidenceKind ?? 'span',\n uri: uri(trajectoryId, consensus.step),\n },\n ],\n metadata: {\n upstream: 'AgentRx',\n failure_case: consensus.failureCase,\n step: consensus.step,\n step_mean: consensus.stepMean,\n judge_votes: parsed.predictions.length,\n consensus_votes: consensus.votes,\n category_agreement: consensus.votes / parsed.predictions.length,\n ...(consensus.representative.checklist_reasoning === undefined ||\n consensus.representative.checklist_reasoning === null\n ? {}\n : { checklist_reasoning: consensus.representative.checklist_reasoning }),\n },\n }),\n ]\n}\n\nconst AGENT_RX_TAXONOMY = new Map<number, string>([\n [1, 'instruction-plan-adherence-failure'],\n [2, 'invention-of-new-information'],\n [3, 'invalid-invocation'],\n [4, 'misinterpretation-of-tool-output-handoff-failure'],\n [5, 'intent-plan-misalignment'],\n [6, 'underspecified-user-intent'],\n [7, 'intent-not-supported'],\n [8, 'guardrails-triggered'],\n [9, 'system-failure'],\n [10, 'inconclusive'],\n])\n\nconst AGENT_RX_CATEGORY_ALIASES = new Map<string, string>([\n ['instruction-adherence-failure', 'instruction-plan-adherence-failure'],\n ['misinterpretation-of-tool-output', 'misinterpretation-of-tool-output-handoff-failure'],\n])\n\nconst AGENT_RX_TAXONOMY_BY_LABEL = new Map(\n [...AGENT_RX_TAXONOMY].map(([failureCase, label]) => [label, failureCase]),\n)\n\nexport function normalizeAgentRxCategory(value: string): string {\n const normalized = normalizeBenchmarkLabel(value)\n return AGENT_RX_CATEGORY_ALIASES.get(normalized) ?? normalized\n}\n\nfunction parseAgentRxFailureCase(value: unknown, field: string): number {\n if (typeof value !== 'number' && typeof value !== 'string') {\n throw new TypeError(`${field} must be a taxonomy number or label`)\n }\n if (typeof value === 'string' && !/^\\d+$/.test(value.trim())) {\n const normalized = normalizeAgentRxCategory(value)\n const failureCase = AGENT_RX_TAXONOMY_BY_LABEL.get(normalized)\n if (failureCase === undefined) {\n throw new RangeError(`${field} '${value}' is not an AgentRx taxonomy label`)\n }\n return failureCase\n }\n const numeric = typeof value === 'number' ? value : Number(value)\n if (!Number.isSafeInteger(numeric)) {\n throw new TypeError(`${field} must be a taxonomy number or label`)\n }\n if (numeric < 0 || numeric > 10) {\n throw new RangeError(`${field} ${numeric} is outside 0-10`)\n }\n return numeric\n}\n\ninterface ParsedAgentRxPredictions {\n predictions: Array<\n Omit<AgentRxPrediction, 'failure_case'> & {\n failure_case: number\n }\n >\n report?: AgentRxPredictionReport\n}\n\nfunction parseAgentRxPredictions(output: unknown, trajectoryId: string): ParsedAgentRxPredictions {\n let failures: unknown\n let report: AgentRxPredictionReport | undefined\n if (Array.isArray(output)) {\n failures = output\n } else if (isRecord(output)) {\n assertMatchingAgentRxTaskId(output.task_id, trajectoryId, 'report.task_id')\n if (!Object.hasOwn(output, 'failures')) {\n throw new TypeError(`AgentRx prediction '${trajectoryId}' report must contain failures`)\n }\n failures = output.failures\n if (output.num_judges !== undefined) {\n if (!Number.isSafeInteger(output.num_judges) || (output.num_judges as number) < 0) {\n throw new RangeError(\n `AgentRx prediction '${trajectoryId}' report.num_judges must be a non-negative safe integer`,\n )\n }\n }\n if (output.trajectory_length !== undefined) {\n positiveStep(\n output.trajectory_length as number,\n `AgentRx prediction '${trajectoryId}' report.trajectory_length`,\n )\n }\n if (output.step_mean !== undefined) {\n if (typeof output.step_mean !== 'number' || !Number.isFinite(output.step_mean)) {\n throw new TypeError(`AgentRx prediction '${trajectoryId}' report.step_mean must be finite`)\n }\n }\n if (output.modes !== undefined && !Array.isArray(output.modes)) {\n throw new TypeError(`AgentRx prediction '${trajectoryId}' report.modes must be an array`)\n }\n report = output as unknown as AgentRxPredictionReport\n } else {\n throw new TypeError(`AgentRx prediction '${trajectoryId}' must be a report or failures array`)\n }\n if (!Array.isArray(failures)) {\n throw new TypeError(`AgentRx prediction '${trajectoryId}' failures must be an array`)\n }\n if (failures.length === 0) {\n throw new TypeError(\n `AgentRx prediction '${trajectoryId}' failures must contain a judge prediction`,\n )\n }\n if (\n isRecord(output) &&\n output.num_judges !== undefined &&\n output.num_judges !== failures.length\n ) {\n throw new TypeError(\n `AgentRx prediction '${trajectoryId}' declares ${output.num_judges} judges but contains ${failures.length} failures`,\n )\n }\n const predictions = failures.map((value, index) => {\n const field = `AgentRx prediction '${trajectoryId}' failures[${index}]`\n if (!isRecord(value)) throw new TypeError(`${field} must be an object`)\n assertMatchingAgentRxTaskId(value.task_id, trajectoryId, `${field}.task_id`)\n const failureCase = parseAgentRxFailureCase(value.failure_case, `${field}.failure_case`)\n if (!Number.isSafeInteger(value.step_number)) {\n throw new TypeError(`${field}.step_number must be a safe integer`)\n }\n const stepNumber = value.step_number as number\n if (failureCase === 0 ? stepNumber !== 0 : stepNumber < 1) {\n throw new RangeError(\n failureCase === 0\n ? `${field}.step_number must be 0 when failure_case is 0`\n : `${field}.step_number must be positive when failure_case is 1-10`,\n )\n }\n if (value.description !== undefined && typeof value.description !== 'string') {\n throw new TypeError(`${field}.description must be a string`)\n }\n if (\n value.checklist_reasoning !== undefined &&\n value.checklist_reasoning !== null &&\n typeof value.checklist_reasoning !== 'string'\n ) {\n throw new TypeError(`${field}.checklist_reasoning must be a string or null`)\n }\n return {\n ...(value.task_id === undefined ? {} : { task_id: value.task_id as ExternalId }),\n failure_case: failureCase,\n step_number: stepNumber,\n ...(value.description === undefined ? {} : { description: value.description as string }),\n ...(value.checklist_reasoning === undefined\n ? {}\n : { checklist_reasoning: value.checklist_reasoning as string | null }),\n }\n })\n return { predictions, report }\n}\n\nfunction agentRxConsensus(\n parsed: ParsedAgentRxPredictions,\n trajectoryId: string,\n): {\n failureCase: number\n step: number\n stepMean: number\n votes: number\n representative: ParsedAgentRxPredictions['predictions'][number]\n} {\n const counts = new Map<number, number>()\n for (const prediction of parsed.predictions) {\n counts.set(prediction.failure_case, (counts.get(prediction.failure_case) ?? 0) + 1)\n }\n const maxVotes = Math.max(...counts.values())\n let failureCase = [...counts].find(([, count]) => count === maxVotes)![0]\n if (parsed.report?.most_common_failure !== undefined) {\n const declared = parseAgentRxFailureCase(\n parsed.report.most_common_failure,\n `AgentRx prediction '${trajectoryId}' report.most_common_failure`,\n )\n if ((counts.get(declared) ?? 0) !== maxVotes) {\n throw new TypeError(\n `AgentRx prediction '${trajectoryId}' report.most_common_failure disagrees with failures`,\n )\n }\n failureCase = declared\n }\n if (parsed.report?.modes !== undefined) {\n const declaredModes = parsed.report.modes.map((value, index) =>\n parseAgentRxFailureCase(value, `AgentRx prediction '${trajectoryId}' report.modes[${index}]`),\n )\n if (new Set(declaredModes).size !== declaredModes.length) {\n throw new TypeError(`AgentRx prediction '${trajectoryId}' report.modes contains duplicates`)\n }\n const expectedModes = [...counts]\n .filter(([, count]) => count === maxVotes)\n .map(([value]) => value)\n .sort((left, right) => left - right)\n if (\n [...new Set(declaredModes)].sort((left, right) => left - right).join(',') !==\n expectedModes.join(',')\n ) {\n throw new TypeError(\n `AgentRx prediction '${trajectoryId}' report.modes disagrees with failures`,\n )\n }\n }\n\n const computedStepMean =\n parsed.predictions.reduce((sum, prediction) => sum + prediction.step_number, 0) /\n parsed.predictions.length\n if (\n parsed.report?.step_mean !== undefined &&\n Math.abs(parsed.report.step_mean - computedStepMean) > 1e-12\n ) {\n throw new TypeError(\n `AgentRx prediction '${trajectoryId}' report.step_mean disagrees with failures`,\n )\n }\n const stepMean = parsed.report?.step_mean ?? computedStepMean\n const step =\n failureCase === 0\n ? 0\n : positiveStep(\n roundAgentRxStep(stepMean),\n `AgentRx prediction '${trajectoryId}' consensus step`,\n )\n const representative =\n parsed.predictions\n .filter((prediction) => prediction.failure_case === failureCase)\n .sort(\n (left, right) => Math.abs(left.step_number - step) - Math.abs(right.step_number - step),\n )[0] ?? parsed.predictions[0]!\n return {\n failureCase,\n step,\n stepMean,\n votes: counts.get(failureCase)!,\n representative,\n }\n}\n\n/** Match Python's round() behavior used by AgentRx for consensus steps. */\nexport function roundAgentRxStep(value: number): number {\n if (!Number.isFinite(value)) {\n throw new TypeError('AgentRx step mean must be finite')\n }\n const lower = Math.floor(value)\n const fraction = value - lower\n if (Math.abs(fraction - 0.5) <= Number.EPSILON * Math.max(1, Math.abs(value))) {\n return lower % 2 === 0 ? lower : lower + 1\n }\n return Math.round(value)\n}\n\nfunction assertMatchingAgentRxTaskId(value: unknown, trajectoryId: string, field: string): void {\n if (value === undefined) return\n const taskId = externalId(value as ExternalId, `AgentRx prediction '${trajectoryId}' ${field}`)\n if (taskId !== trajectoryId) {\n throw new TypeError(\n `AgentRx prediction '${trajectoryId}' ${field} '${taskId}' does not match trajectory id`,\n )\n }\n}\n","import type { AnalystBenchmarkCase } from './benchmark'\nimport type {\n CodeTraceBenchCaseOptions,\n CodeTraceBenchLabelSet,\n CodeTraceBenchRow,\n CodeTracerPredictionAdapterOptions,\n CodeTracerPredictions,\n CodeTracerStepLabel,\n CodeTraceStageAnnotation,\n} from './benchmark-dataset-types'\nimport {\n assertStepWithinRange,\n defaultStepUri,\n isRecord,\n nonEmpty,\n positiveStep,\n predictionConfidence,\n} from './benchmark-dataset-utils'\nimport { type AnalystFinding, makeFinding } from './types'\n\nexport function codeTraceBenchCase<TInput>(\n row: CodeTraceBenchRow,\n input: TInput,\n options: CodeTraceBenchCaseOptions = {},\n): AnalystBenchmarkCase<TInput> {\n const trajectoryId = requiredCodeTraceString(row.traj_id, 'CodeTraceBench traj_id')\n const taskName = requiredCodeTraceString(\n row.task_name,\n `CodeTraceBench '${trajectoryId}' task_name`,\n )\n const agent = requiredCodeTraceString(row.agent, `CodeTraceBench '${trajectoryId}' agent`)\n const model = requiredCodeTraceString(row.model, `CodeTraceBench '${trajectoryId}' model`)\n const difficulty = optionalCodeTraceString(\n row.difficulty,\n `CodeTraceBench '${trajectoryId}' difficulty`,\n )\n const category = optionalCodeTraceString(\n row.category,\n `CodeTraceBench '${trajectoryId}' category`,\n )\n const sourceRelpath = optionalSourceRelativePath(row.source_relpath, trajectoryId)\n const solved = codeTraceSolved(row.solved, trajectoryId)\n const tags = parseTags(row.tags, trajectoryId)\n const stepCount = positiveStep(row.step_count, `CodeTraceBench '${trajectoryId}' step_count`)\n const stages = parseCodeTraceStages(row.incorrect_stages, trajectoryId)\n const evidenceKind = options.evidenceKind ?? 'span'\n const uri = options.stepUri ?? defaultStepUri\n const labelSet = codeTraceLabelSet(options.labelSet)\n const labels = new Set<string>()\n const expectedIssues = stages.flatMap((stage) => {\n const incorrect = stepIssues('incorrect', stage.incorrect_step_ids ?? [])\n const unuseful = stepIssues('unuseful', stage.unuseful_step_ids ?? [])\n return labelSet === 'incorrect-only' ? incorrect : [...incorrect, ...unuseful]\n })\n const labelState =\n expectedIssues.length > 0 ? 'positive' : solved === true ? 'trusted-negative' : 'unlabeled'\n\n return {\n id: `codetrace:${trajectoryId}`,\n clusterId: `codetrace-task:${taskName}`,\n labelState,\n input,\n expectedIssues,\n ...(labelState === 'unlabeled'\n ? {}\n : { labeledEvidence: expectedIssues.flatMap((issue) => issue.evidence ?? []) }),\n tags: [\n 'codetracebench',\n agent,\n model,\n ...(difficulty === undefined ? [] : [difficulty]),\n ...(category === undefined ? [] : [category]),\n ...tags,\n ],\n metadata: {\n benchmark: 'CodeTraceBench',\n trajectoryId,\n taskName,\n agent,\n model,\n solved,\n stepCount,\n labelSet,\n ...(sourceRelpath === undefined ? {} : { sourceRelpath }),\n ...(difficulty === undefined ? {} : { difficulty }),\n ...(category === undefined ? {} : { category }),\n },\n }\n\n function stepIssues(label: 'incorrect' | 'unuseful', steps: readonly number[]) {\n return steps.map((rawStep) => {\n const step = positiveStep(rawStep, `CodeTraceBench '${trajectoryId}' ${label} step`)\n if (step > stepCount) {\n throw new RangeError(\n `CodeTraceBench '${trajectoryId}' ${label} step ${step} exceeds step_count ${stepCount}`,\n )\n }\n const id = `${label}:${step}`\n if (labels.has(id)) {\n throw new TypeError(`CodeTraceBench '${trajectoryId}' repeats label '${id}'`)\n }\n labels.add(id)\n return {\n id,\n areas: [label],\n evidence: [{ kind: evidenceKind, uri: uri(trajectoryId, step) }],\n }\n })\n }\n}\n\n/** Translate CodeTracer's `codetracer_labels.json` into shared findings. */\nexport function codeTracerPredictionsToFindings(\n trajectoryIdValue: string,\n predictions: CodeTracerPredictions,\n options: CodeTracerPredictionAdapterOptions = {},\n): AnalystFinding[] {\n const trajectoryId = nonEmpty(trajectoryIdValue, 'CodeTracer prediction trajectory id')\n const labels = parseCodeTracerPredictionLabels(predictions, trajectoryId)\n const confidence = predictionConfidence(options.confidence)\n const uri = options.stepUri ?? defaultStepUri\n const labelSet = codeTraceLabelSet(options.labelSet)\n const seen = new Set<string>()\n const findings: AnalystFinding[] = []\n for (const label of labels) {\n const step = positiveStep(\n label.step,\n `CodeTracer prediction '${trajectoryId}' ${label.area} step`,\n )\n assertStepWithinRange(step, options.stepCount, `CodeTracer prediction '${trajectoryId}'`)\n const key = `${label.area}:${step}`\n if (seen.has(key)) {\n throw new TypeError(`CodeTracer prediction '${trajectoryId}' repeats label '${key}'`)\n }\n seen.add(key)\n if (label.area === 'unuseful' && labelSet === 'incorrect-only') continue\n findings.push(\n makeFinding({\n analyst_id: options.analystId ?? 'codetracer',\n produced_at: options.producedAt,\n area: label.area,\n subject: `step-${step}`,\n claim: `CodeTracer labeled step ${step} as ${label.area}.`,\n id_basis: key,\n rationale: label.reasoning,\n severity: 'medium',\n confidence,\n evidence_refs: [\n {\n kind: options.evidenceKind ?? 'span',\n uri: uri(trajectoryId, step),\n },\n ],\n metadata: {\n upstream: 'CodeTracer',\n stage_id: label.stageId,\n step,\n },\n }),\n )\n }\n return findings\n}\n\nfunction parseCodeTraceStages(\n value: CodeTraceBenchRow['incorrect_stages'],\n trajectoryId: string,\n): readonly CodeTraceStageAnnotation[] {\n let parsed: unknown = value\n if (typeof value === 'string') {\n try {\n parsed = JSON.parse(value) as unknown\n } catch (error) {\n throw new TypeError(\n `CodeTraceBench '${trajectoryId}' incorrect_stages is invalid JSON: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n if (!Array.isArray(parsed)) {\n throw new TypeError(`CodeTraceBench '${trajectoryId}' incorrect_stages must be an array`)\n }\n const stageIds = new Set<number>()\n for (const stage of parsed) {\n if (\n !stage ||\n typeof stage !== 'object' ||\n !Number.isSafeInteger((stage as CodeTraceStageAnnotation).stage_id) ||\n (stage as CodeTraceStageAnnotation).stage_id < 1 ||\n !optionalStepArray((stage as CodeTraceStageAnnotation).incorrect_step_ids) ||\n !optionalStepArray((stage as CodeTraceStageAnnotation).unuseful_step_ids) ||\n ((stage as CodeTraceStageAnnotation).reasoning !== undefined &&\n typeof (stage as CodeTraceStageAnnotation).reasoning !== 'string')\n ) {\n throw new TypeError(`CodeTraceBench '${trajectoryId}' contains an invalid stage annotation`)\n }\n const stageId = (stage as CodeTraceStageAnnotation).stage_id\n if (stageIds.has(stageId)) {\n throw new TypeError(`CodeTraceBench '${trajectoryId}' repeats stage_id ${stageId}`)\n }\n stageIds.add(stageId)\n }\n return parsed as unknown as readonly CodeTraceStageAnnotation[]\n}\n\nfunction parseCodeTracerPredictionLabels(\n value: CodeTracerPredictions,\n trajectoryId: string,\n): Array<{\n stageId: string | number\n area: CodeTracerStepLabel['label']\n step: number\n reasoning?: string\n}> {\n let parsed: unknown = value\n if (typeof value === 'string') {\n try {\n parsed = JSON.parse(value) as unknown\n } catch (error) {\n throw new TypeError(\n `CodeTracer prediction '${trajectoryId}' is invalid JSON: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n if (!Array.isArray(parsed)) {\n throw new TypeError(`CodeTracer prediction '${trajectoryId}' must be an array`)\n }\n if (parsed.length === 0) return []\n\n if (parsed.every(isCodeTraceStageAnnotation)) {\n return (parsed as readonly CodeTraceStageAnnotation[]).flatMap((stage) => [\n ...(stage.incorrect_step_ids ?? []).map((step) => ({\n stageId: stage.stage_id,\n area: 'incorrect' as const,\n step,\n ...(stage.reasoning === undefined ? {} : { reasoning: stage.reasoning }),\n })),\n ...(stage.unuseful_step_ids ?? []).map((step) => ({\n stageId: stage.stage_id,\n area: 'unuseful' as const,\n step,\n ...(stage.reasoning === undefined ? {} : { reasoning: stage.reasoning }),\n })),\n ])\n }\n\n const flat: Array<{\n stageId: string | number\n area: CodeTracerStepLabel['label']\n step: number\n reasoning?: string\n }> = []\n for (const [index, item] of parsed.entries()) {\n if (isCodeTracerStepLabel(item)) {\n flat.push(\n toCodeTracerPredictionLabel(\n item,\n codeTracerStageId(item, index + 1, trajectoryId),\n trajectoryId,\n ),\n )\n continue\n }\n if (!isRecord(item) || !Array.isArray(item.labels)) {\n throw new TypeError(\n `CodeTracer prediction '${trajectoryId}' contains an unsupported label row`,\n )\n }\n const stageId = codeTracerStageId(item, index + 1, trajectoryId)\n for (const label of item.labels) {\n if (!isCodeTracerStepLabel(label)) {\n throw new TypeError(\n `CodeTracer prediction '${trajectoryId}' contains an invalid step label`,\n )\n }\n flat.push(toCodeTracerPredictionLabel(label, stageId, trajectoryId))\n }\n }\n return flat\n}\n\nfunction isCodeTraceStageAnnotation(value: unknown): value is CodeTraceStageAnnotation {\n return (\n isRecord(value) &&\n Number.isSafeInteger(value.stage_id) &&\n (value.stage_id as number) > 0 &&\n optionalStepArray(value.incorrect_step_ids as readonly number[] | undefined) &&\n optionalStepArray(value.unuseful_step_ids as readonly number[] | undefined) &&\n (value.reasoning === undefined || typeof value.reasoning === 'string')\n )\n}\n\nfunction isCodeTracerStepLabel(value: unknown): value is CodeTracerStepLabel {\n return (\n isRecord(value) &&\n Number.isSafeInteger(value.step_id) &&\n (value.step_id as number) > 0 &&\n (value.stage === undefined ||\n typeof value.stage === 'string' ||\n typeof value.stage === 'number') &&\n (value.stage_name === undefined ||\n typeof value.stage_name === 'string' ||\n typeof value.stage_name === 'number') &&\n (value.stage_id === undefined ||\n typeof value.stage_id === 'string' ||\n typeof value.stage_id === 'number') &&\n (value.label === 'incorrect' || value.label === 'unuseful') &&\n (value.rationale === undefined || typeof value.rationale === 'string') &&\n (value.reason === undefined || typeof value.reason === 'string') &&\n (value.note === undefined || typeof value.note === 'string') &&\n (value.comment === undefined || typeof value.comment === 'string')\n )\n}\n\nfunction toCodeTracerPredictionLabel(\n label: CodeTracerStepLabel,\n stageId: string | number,\n trajectoryId: string,\n): {\n stageId: string | number\n area: CodeTracerStepLabel['label']\n step: number\n reasoning?: string\n} {\n if (!isCodeTracerStepLabel(label)) {\n throw new TypeError(`CodeTracer prediction '${trajectoryId}' contains an invalid step label`)\n }\n return {\n stageId,\n area: label.label,\n step: label.step_id,\n ...codeTracerReason(label, trajectoryId),\n }\n}\n\nfunction codeTracerStageId(\n value: { stage?: unknown; stage_name?: unknown; stage_id?: unknown },\n fallback: number,\n trajectoryId: string,\n): string | number {\n const candidates = [value.stage, value.stage_name, value.stage_id].filter(\n (candidate): candidate is string | number =>\n typeof candidate === 'string' || typeof candidate === 'number',\n )\n if (new Set(candidates).size > 1) {\n throw new TypeError(`CodeTracer prediction '${trajectoryId}' has conflicting stage fields`)\n }\n return candidates[0] ?? fallback\n}\n\nfunction codeTracerReason(\n label: CodeTracerStepLabel,\n trajectoryId: string,\n): { reasoning?: string } {\n const candidates = [label.rationale, label.reason, label.note, label.comment].filter(\n (candidate): candidate is string => candidate !== undefined,\n )\n if (new Set(candidates).size > 1) {\n throw new TypeError(\n `CodeTracer prediction '${trajectoryId}' step ${label.step_id} has conflicting reason fields`,\n )\n }\n return candidates[0] === undefined ? {} : { reasoning: candidates[0] }\n}\n\nfunction parseTags(value: CodeTraceBenchRow['tags'], trajectoryId: string): string[] {\n if (value === undefined) return []\n let parsed: unknown = value\n if (typeof value === 'string') {\n try {\n parsed = JSON.parse(value) as unknown\n } catch (error) {\n throw new TypeError(\n `CodeTraceBench '${trajectoryId}' tags is invalid JSON: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n if (!Array.isArray(parsed)) {\n throw new TypeError(`CodeTraceBench '${trajectoryId}' tags must be an array of strings`)\n }\n const tags = parsed.map((tag, index) =>\n requiredCodeTraceString(tag, `CodeTraceBench '${trajectoryId}' tags[${index}]`),\n )\n if (new Set(tags).size !== tags.length) {\n throw new TypeError(`CodeTraceBench '${trajectoryId}' tags must not repeat values`)\n }\n return tags\n}\n\nfunction codeTraceLabelSet(value: CodeTraceBenchLabelSet | undefined): CodeTraceBenchLabelSet {\n if (value === undefined || value === 'incorrect-only') return 'incorrect-only'\n if (value === 'incorrect-and-unuseful') return value\n throw new TypeError(\n \"CodeTraceBench labelSet must be 'incorrect-only' or 'incorrect-and-unuseful'\",\n )\n}\n\nfunction optionalStepArray(value: readonly number[] | undefined): boolean {\n return value === undefined || (Array.isArray(value) && value.every(Number.isSafeInteger))\n}\n\nfunction requiredCodeTraceString(value: unknown, field: string): string {\n if (typeof value !== 'string') throw new TypeError(`${field} must be a string`)\n return nonEmpty(value, field)\n}\n\nfunction optionalCodeTraceString(value: unknown, field: string): string | undefined {\n if (value === undefined) return undefined\n return requiredCodeTraceString(value, field)\n}\n\nfunction optionalSourceRelativePath(value: unknown, trajectoryId: string): string | undefined {\n const path = optionalCodeTraceString(value, `CodeTraceBench '${trajectoryId}' source_relpath`)\n if (path === undefined) return undefined\n const segments = path.replaceAll('\\\\', '/').split('/')\n if (\n path.startsWith('/') ||\n /^[a-zA-Z]:[\\\\/]/.test(path) ||\n segments.some((segment) => segment === '..')\n ) {\n throw new TypeError(\n `CodeTraceBench '${trajectoryId}' source_relpath must stay within the artifact root`,\n )\n }\n return path\n}\n\nfunction codeTraceSolved(value: unknown, trajectoryId: string): boolean | null | undefined {\n if (value === undefined || value === null || typeof value === 'boolean') return value\n throw new TypeError(`CodeTraceBench '${trajectoryId}' solved must be a boolean or null`)\n}\n","import type { AnalystBenchmarkObservation, AnalystBenchmarkResult } from './benchmark'\nimport { roundAgentRxStep } from './benchmark-datasets'\n\nexport const AGENT_RX_UPSTREAM_REVISION = 'f228165bfec60a801fd5fedd9d8ffe0f9de0c69d'\n\nexport interface AgentRxCalibrationRunnerSummary {\n runnerId: string\n selectedRuns: number\n completedRuns: number\n failedRuns: number\n predictedRuns: number\n missingPredictionRuns: number\n exactStepAccuracy: number | null\n stepAccuracyWithin1: number | null\n stepAccuracyWithin2: number | null\n stepAccuracyWithin3: number | null\n stepAccuracyWithin4: number | null\n stepAccuracyWithin5: number | null\n meanStepDistance: number | null\n normalizedMeanStepDistance: number | null\n normalizedDistanceRuns: number\n normalizedDistanceUnknownRuns: number\n rootCauseCategoryAccuracy: number | null\n anyFailureCategoryAccuracy: number | null\n earliestFailureCategoryAccuracy: number | null\n terminalFailureCategoryAccuracy: number | null\n}\n\nexport interface AgentRxCalibrationSummary {\n protocol: 'official-agentrx-root-cause'\n upstreamRevision: string\n rationale: string\n runners: AgentRxCalibrationRunnerSummary[]\n}\n\nexport function summarizeAgentRxCalibration(\n result: AnalystBenchmarkResult,\n upstreamRevision: string,\n): AgentRxCalibrationSummary {\n if (!upstreamRevision.trim()) {\n throw new TypeError('AgentRx calibration requires an upstream revision')\n }\n return {\n protocol: 'official-agentrx-root-cause',\n upstreamRevision,\n rationale:\n 'Matches AgentRx root-category accuracy, Python-rounded exact and tolerance step accuracy, unrounded mean step distance, normalized distance, and any, earliest, and terminal category accuracy. Failed runs and empty predictions score as no prediction.',\n runners: result.provenance.runnerIds.map((runnerId) =>\n summarizeRunner(\n runnerId,\n result.observations.filter((observation) => observation.runnerId === runnerId),\n ),\n ),\n }\n}\n\nexport function renderAgentRxCalibrationMarkdown(summary: AgentRxCalibrationSummary): string {\n return [\n '## AgentRx Published Metrics',\n '',\n summary.rationale,\n '',\n `Upstream revision: \\`${summary.upstreamRevision}\\`.`,\n '',\n '| Runner | Completed/selected | Failed | Predictions | Missing predictions | Exact step | Within 1 | Within 2 | Within 3 | Within 4 | Within 5 | Mean step distance | Normalized distance | Normalized known/unknown | Root category | Any category | Earliest category | Terminal category |',\n '| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |',\n ...summary.runners.map(\n (runner) =>\n `| ${escapeCell(runner.runnerId)} | ${runner.completedRuns}/${runner.selectedRuns} | ${runner.failedRuns} | ${runner.predictedRuns} | ${runner.missingPredictionRuns} | ${rate(runner.exactStepAccuracy)} | ${rate(runner.stepAccuracyWithin1)} | ${rate(runner.stepAccuracyWithin2)} | ${rate(runner.stepAccuracyWithin3)} | ${rate(runner.stepAccuracyWithin4)} | ${rate(runner.stepAccuracyWithin5)} | ${number(runner.meanStepDistance)} | ${number(runner.normalizedMeanStepDistance)} | ${runner.normalizedDistanceRuns}/${runner.normalizedDistanceUnknownRuns} | ${rate(runner.rootCauseCategoryAccuracy)} | ${rate(runner.anyFailureCategoryAccuracy)} | ${rate(runner.earliestFailureCategoryAccuracy)} | ${rate(runner.terminalFailureCategoryAccuracy)} |`,\n ),\n ].join('\\n')\n}\n\nfunction summarizeRunner(\n runnerId: string,\n observations: readonly AnalystBenchmarkObservation[],\n): AgentRxCalibrationRunnerSummary {\n const scored = observations.map(scoredObservation)\n const normalized = scored.filter(\n (row): row is ReturnType<typeof scoredObservation> & { normalizedDistance: number } =>\n row.normalizedDistance !== null,\n )\n const predicted = scored.filter(\n (row): row is ReturnType<typeof scoredObservation> & { distance: number } =>\n row.distance !== null,\n )\n return {\n runnerId,\n selectedRuns: observations.length,\n completedRuns: observations.filter((observation) => !observation.error).length,\n failedRuns: observations.filter((observation) => Boolean(observation.error)).length,\n predictedRuns: predicted.length,\n missingPredictionRuns: scored.length - predicted.length,\n exactStepAccuracy: mean(scored.map((row) => Number(row.roundedDistance === 0))),\n stepAccuracyWithin1: mean(\n scored.map((row) => Number(row.roundedDistance !== null && row.roundedDistance <= 1)),\n ),\n stepAccuracyWithin2: mean(\n scored.map((row) => Number(row.roundedDistance !== null && row.roundedDistance <= 2)),\n ),\n stepAccuracyWithin3: mean(\n scored.map((row) => Number(row.roundedDistance !== null && row.roundedDistance <= 3)),\n ),\n stepAccuracyWithin4: mean(\n scored.map((row) => Number(row.roundedDistance !== null && row.roundedDistance <= 4)),\n ),\n stepAccuracyWithin5: mean(\n scored.map((row) => Number(row.roundedDistance !== null && row.roundedDistance <= 5)),\n ),\n meanStepDistance: mean(predicted.map((row) => row.distance)),\n normalizedMeanStepDistance: mean(normalized.map((row) => row.normalizedDistance)),\n normalizedDistanceRuns: normalized.length,\n normalizedDistanceUnknownRuns: scored.length - normalized.length,\n rootCauseCategoryAccuracy: mean(scored.map((row) => Number(row.rootCategoryMatch))),\n anyFailureCategoryAccuracy: mean(scored.map((row) => Number(row.anyCategoryMatch))),\n earliestFailureCategoryAccuracy: mean(scored.map((row) => Number(row.earliestCategoryMatch))),\n terminalFailureCategoryAccuracy: mean(scored.map((row) => Number(row.terminalCategoryMatch))),\n }\n}\n\nfunction scoredObservation(observation: AnalystBenchmarkObservation) {\n const metadata = record(observation.caseMetadata)\n const rootStep = requiredPositiveNumber(\n metadata.rootCauseStep,\n observation.caseId,\n 'rootCauseStep',\n )\n const rootCategory = requiredString(\n metadata.rootCauseCategory,\n observation.caseId,\n 'rootCauseCategory',\n )\n const allCategories = requiredStringArray(\n metadata.allFailureCategories,\n observation.caseId,\n 'allFailureCategories',\n )\n const earliestCategory = requiredString(\n metadata.earliestFailureCategory,\n observation.caseId,\n 'earliestFailureCategory',\n )\n const terminalCategory = requiredString(\n metadata.terminalFailureCategory,\n observation.caseId,\n 'terminalFailureCategory',\n )\n const finding = observation.error ? undefined : observation.findings[0]\n const findingMetadata = record(finding?.metadata)\n const stepMean = finding\n ? finiteNonNegative(\n findingMetadata.step_mean ?? findingMetadata.step,\n observation.caseId,\n 'predicted step',\n )\n : null\n const roundedDistance = stepMean === null ? null : Math.abs(roundAgentRxStep(stepMean) - rootStep)\n const distance = stepMean === null ? null : Math.abs(stepMean - rootStep)\n const trajectoryLength =\n metadata.trajectoryLength === undefined\n ? null\n : requiredPositiveNumber(metadata.trajectoryLength, observation.caseId, 'trajectoryLength')\n const predictedCategory = finding?.area\n return {\n roundedDistance,\n distance,\n normalizedDistance:\n trajectoryLength === null || distance === null ? null : distance / trajectoryLength,\n rootCategoryMatch: predictedCategory === rootCategory,\n anyCategoryMatch: predictedCategory !== undefined && allCategories.includes(predictedCategory),\n earliestCategoryMatch: predictedCategory === earliestCategory,\n terminalCategoryMatch: predictedCategory === terminalCategory,\n }\n}\n\nfunction record(value: unknown): Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : {}\n}\n\nfunction requiredPositiveNumber(value: unknown, caseId: string, field: string): number {\n const numberValue = finiteNonNegative(value, caseId, field)\n if (numberValue <= 0) throw new TypeError(`${caseId}: ${field} must be positive`)\n return numberValue\n}\n\nfunction finiteNonNegative(value: unknown, caseId: string, field: string): number {\n if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {\n throw new TypeError(`${caseId}: ${field} must be a finite non-negative number`)\n }\n return value\n}\n\nfunction requiredString(value: unknown, caseId: string, field: string): string {\n if (typeof value !== 'string' || !value.trim()) {\n throw new TypeError(`${caseId}: ${field} must be a non-empty string`)\n }\n return value\n}\n\nfunction requiredStringArray(value: unknown, caseId: string, field: string): string[] {\n if (\n !Array.isArray(value) ||\n value.length === 0 ||\n value.some((entry) => typeof entry !== 'string' || !entry.trim())\n ) {\n throw new TypeError(`${caseId}: ${field} must be a non-empty string array`)\n }\n return value as string[]\n}\n\nfunction mean(values: readonly number[]): number | null {\n return values.length === 0\n ? null\n : values.reduce((total, value) => total + value, 0) / values.length\n}\n\nfunction rate(value: number | null): string {\n return value === null ? 'n/a' : value.toFixed(3)\n}\n\nfunction number(value: number | null): string {\n return value === null ? 'n/a' : value.toFixed(3)\n}\n\nfunction escapeCell(value: string): string {\n return value.replaceAll('|', '\\\\|').replaceAll('\\n', ' ')\n}\n","import { pairedBootstrap } from '../statistics'\nimport type { AnalystBenchmarkObservation, AnalystBenchmarkResult } from './benchmark'\n\n/**\n * Every metric a benchmark comparison reports, mapped to the direction that\n * is an improvement. This table is the only declaration of the vocabulary:\n * the type, the reporting order, the artifact schema's accepted values, and\n * each metric's direction all derive from it, so a metric cannot exist in one\n * of those four places and be missing from another.\n */\nconst ANALYST_COMPARISON_METRIC_DIRECTION = {\n completion: 'higher',\n issueRecall: 'higher',\n findingPrecision: 'higher',\n f1: 'higher',\n criticalStepAccuracy: 'higher',\n citationCoverage: 'higher',\n citationExcerptCoverage: 'higher',\n citationLabelAgreement: 'higher',\n citationResolution: 'higher',\n trustedNegativeAccuracy: 'higher',\n latencyMs: 'lower',\n calls: 'lower',\n inputTokens: 'lower',\n outputTokens: 'lower',\n reasoningTokens: 'lower',\n cachedTokens: 'lower',\n cacheWriteTokens: 'lower',\n costUsd: 'lower',\n} as const satisfies Record<string, 'higher' | 'lower'>\n\nexport type AnalystComparisonMetric = keyof typeof ANALYST_COMPARISON_METRIC_DIRECTION\n\n/** The vocabulary as a non-empty tuple, which is what `z.enum` accepts. Key\n * order is the declaration order above, and it is the reporting order. */\nexport const ANALYST_COMPARISON_METRICS = Object.keys(ANALYST_COMPARISON_METRIC_DIRECTION) as [\n AnalystComparisonMetric,\n ...AnalystComparisonMetric[],\n]\n\n/** `'lower'` when a smaller value is the improvement. */\nexport function analystComparisonMetricDirection(\n metric: AnalystComparisonMetric,\n): 'higher' | 'lower' {\n return ANALYST_COMPARISON_METRIC_DIRECTION[metric]\n}\n\nexport interface AnalystMetricComparison {\n metric: AnalystComparisonMetric\n direction: 'higher' | 'lower'\n /** Trajectories with at least one complete pair for this metric. */\n pairedCases: number\n /** Independent task or incident groups resampled by the interval. */\n pairedClusters: number\n /** Same-run pairs where this metric applies before missing values are removed. */\n eligibleObservations: number\n pairedObservations: number\n baselineMissingObservations: number\n candidateMissingObservations: number\n asymmetricMissingObservations: number\n survivorOnly: boolean\n baselineMean: number | null\n candidateMean: number | null\n meanDelta: number | null\n intervalLow: number | null\n intervalHigh: number | null\n confidence: number\n resamples: number\n minimumSampleMet: boolean\n populationInferenceEligible: boolean\n inferenceLimitations: string[]\n}\n\nexport interface AnalystRunnerComparison {\n baselineRunnerId: string\n candidateRunnerId: string\n metrics: AnalystMetricComparison[]\n}\n\ninterface PairedCaseMetric {\n clusterId: string\n baseline: number\n candidate: number\n}\n\nexport function compareAnalystRunners(\n result: AnalystBenchmarkResult,\n options: {\n baselineRunnerId: string\n candidateRunnerId: string\n confidence?: number\n resamples?: number\n seed?: number\n },\n): AnalystRunnerComparison {\n const confidence = options.confidence ?? 0.95\n const resamples = options.resamples ?? 2000\n assertComparisonControls(confidence, resamples)\n\n const runnerIds = new Set(result.summaries.map((summary) => summary.runnerId))\n if (!runnerIds.has(options.baselineRunnerId)) {\n throw new TypeError(`unknown baseline analyst runner '${options.baselineRunnerId}'`)\n }\n if (!runnerIds.has(options.candidateRunnerId)) {\n throw new TypeError(`unknown candidate analyst runner '${options.candidateRunnerId}'`)\n }\n if (options.baselineRunnerId === options.candidateRunnerId) {\n throw new TypeError('baseline and candidate analyst runners must be different')\n }\n\n const baseline = observationsByCase(result.observations, options.baselineRunnerId)\n const candidate = observationsByCase(result.observations, options.candidateRunnerId)\n const populationRepresentativenessProven =\n result.provenance.metadata?.populationRepresentativenessProven === true\n const metrics = ANALYST_COMPARISON_METRICS.map((metric) =>\n compareMetric({\n metric,\n baseline,\n candidate,\n confidence,\n resamples,\n seed: options.seed,\n populationRepresentativenessProven,\n }),\n )\n\n return {\n baselineRunnerId: options.baselineRunnerId,\n candidateRunnerId: options.candidateRunnerId,\n metrics,\n }\n}\n\nfunction compareMetric(options: {\n metric: AnalystComparisonMetric\n baseline: Map<string, AnalystBenchmarkObservation[]>\n candidate: Map<string, AnalystBenchmarkObservation[]>\n confidence: number\n resamples: number\n seed?: number\n populationRepresentativenessProven: boolean\n}): AnalystMetricComparison {\n const pairedCases: PairedCaseMetric[] = []\n let eligibleObservations = 0\n let pairedObservations = 0\n let baselineMissingObservations = 0\n let candidateMissingObservations = 0\n let asymmetricMissingObservations = 0\n\n const caseIds = new Set([...options.baseline.keys(), ...options.candidate.keys()])\n for (const caseId of caseIds) {\n const baselineByRepetition = new Map(\n (options.baseline.get(caseId) ?? []).map((observation) => [\n observation.repetition,\n observation,\n ]),\n )\n const candidateByRepetition = new Map(\n (options.candidate.get(caseId) ?? []).map((observation) => [\n observation.repetition,\n observation,\n ]),\n )\n const caseBefore: number[] = []\n const caseAfter: number[] = []\n let clusterId: string | undefined\n const repetitions = new Set([...baselineByRepetition.keys(), ...candidateByRepetition.keys()])\n for (const repetition of repetitions) {\n const baselineObservation = baselineByRepetition.get(repetition)\n const candidateObservation = candidateByRepetition.get(repetition)\n const identity = baselineObservation ?? candidateObservation\n if (!identity || !metricApplies(identity, options.metric)) continue\n if (baselineObservation && candidateObservation) {\n assertSameCaseIdentity(baselineObservation, candidateObservation)\n }\n eligibleObservations += 1\n clusterId = identity.clusterId\n const baselineValue = baselineObservation\n ? metricValue(baselineObservation, options.metric)\n : null\n const candidateValue = candidateObservation\n ? metricValue(candidateObservation, options.metric)\n : null\n const baselineMissing = baselineValue === null\n const candidateMissing = candidateValue === null\n if (baselineMissing) baselineMissingObservations += 1\n if (candidateMissing) candidateMissingObservations += 1\n if (baselineMissing !== candidateMissing) asymmetricMissingObservations += 1\n if (baselineMissing || candidateMissing) continue\n caseBefore.push(baselineValue)\n caseAfter.push(candidateValue)\n pairedObservations += 1\n }\n if (caseBefore.length === 0 || !clusterId) continue\n pairedCases.push({\n clusterId,\n baseline: mean(caseBefore),\n candidate: mean(caseAfter),\n })\n }\n\n const byCluster = new Map<string, PairedCaseMetric[]>()\n for (const pairedCase of pairedCases) {\n const rows = byCluster.get(pairedCase.clusterId) ?? []\n rows.push(pairedCase)\n byCluster.set(pairedCase.clusterId, rows)\n }\n const before = [...byCluster.values()].map((rows) => mean(rows.map((row) => row.baseline)))\n const after = [...byCluster.values()].map((rows) => mean(rows.map((row) => row.candidate)))\n const interval =\n before.length === 0\n ? null\n : pairedBootstrap(before, after, {\n confidence: options.confidence,\n resamples: options.resamples,\n statistic: 'mean',\n seed: options.seed,\n })\n const survivorOnly = pairedObservations < eligibleObservations\n const limitations: string[] = []\n if (!interval?.gateEligible) limitations.push('fewer-than-20-independent-clusters')\n if (!options.populationRepresentativenessProven) {\n limitations.push('population-representativeness-not-proven')\n }\n if (survivorOnly) limitations.push('missing-observations')\n\n const comparison: AnalystMetricComparison = {\n metric: options.metric,\n direction: analystComparisonMetricDirection(options.metric),\n pairedCases: pairedCases.length,\n pairedClusters: before.length,\n eligibleObservations,\n pairedObservations,\n baselineMissingObservations,\n candidateMissingObservations,\n asymmetricMissingObservations,\n survivorOnly,\n baselineMean: before.length === 0 ? null : mean(before),\n candidateMean: after.length === 0 ? null : mean(after),\n meanDelta: interval?.mean ?? null,\n intervalLow: interval?.low ?? null,\n intervalHigh: interval?.high ?? null,\n confidence: options.confidence,\n resamples: options.resamples,\n minimumSampleMet: interval?.gateEligible ?? false,\n populationInferenceEligible: limitations.length === 0,\n inferenceLimitations: limitations,\n }\n assertValidComparison(comparison)\n return comparison\n}\n\nfunction observationsByCase(\n observations: readonly AnalystBenchmarkObservation[],\n runnerId: string,\n): Map<string, AnalystBenchmarkObservation[]> {\n const byCase = new Map<string, AnalystBenchmarkObservation[]>()\n for (const observation of observations) {\n if (observation.runnerId !== runnerId) continue\n const rows = byCase.get(observation.caseId) ?? []\n rows.push(observation)\n byCase.set(observation.caseId, rows)\n }\n return byCase\n}\n\nfunction assertSameCaseIdentity(\n baseline: AnalystBenchmarkObservation,\n candidate: AnalystBenchmarkObservation,\n): void {\n if (baseline.clusterId !== candidate.clusterId || baseline.labelState !== candidate.labelState) {\n throw new Error(\n `analyst comparison case identity differs for '${baseline.caseId}' repetition ${baseline.repetition}`,\n )\n }\n}\n\nfunction metricApplies(\n observation: AnalystBenchmarkObservation,\n metric: AnalystComparisonMetric,\n): boolean {\n if (metric === 'trustedNegativeAccuracy') {\n return observation.labelState === 'trusted-negative'\n }\n if (metric === 'issueRecall' || metric === 'findingPrecision' || metric === 'f1') {\n return observation.labelState === 'positive'\n }\n if (metric === 'criticalStepAccuracy') {\n return observation.labelState === 'positive' && observation.score.criticalStepAccuracy !== null\n }\n return true\n}\n\nfunction metricValue(\n observation: AnalystBenchmarkObservation,\n metric: AnalystComparisonMetric,\n): number | null {\n if (metric === 'completion') return observation.error ? 0 : 1\n if (metric === 'latencyMs') return observation.latencyMs\n if (metric === 'trustedNegativeAccuracy') {\n if (observation.error) return 0\n return observation.score.predictionOnLabelEmptyCase ? 0 : 1\n }\n if (\n observation.error &&\n (metric === 'issueRecall' ||\n metric === 'findingPrecision' ||\n metric === 'f1' ||\n metric === 'criticalStepAccuracy')\n ) {\n return 0\n }\n if (\n observation.error &&\n (metric === 'citationCoverage' ||\n metric === 'citationExcerptCoverage' ||\n metric === 'citationLabelAgreement' ||\n metric === 'citationResolution')\n ) {\n return null\n }\n if (metric === 'issueRecall') return observation.score.issueRecall\n if (metric === 'findingPrecision') return observation.score.findingPrecision\n if (metric === 'f1') return observation.score.f1\n if (metric === 'criticalStepAccuracy') return observation.score.criticalStepAccuracy\n if (metric === 'citationCoverage') return observation.score.citationCoverage\n if (metric === 'citationExcerptCoverage') return observation.score.citationExcerptCoverage\n if (metric === 'citationLabelAgreement') return observation.score.citationLabelAgreement\n if (metric === 'citationResolution') return observation.evidenceResolution?.validity ?? null\n if (metric === 'calls') return observation.usage?.calls ?? null\n if (metric === 'inputTokens') return observation.usage?.tokens?.input ?? null\n if (metric === 'outputTokens') return observation.usage?.tokens?.output ?? null\n if (metric === 'reasoningTokens') return observation.usage?.tokens?.reasoning ?? null\n if (metric === 'cachedTokens') return observation.usage?.tokens?.cached ?? null\n if (metric === 'cacheWriteTokens') return observation.usage?.tokens?.cacheWrite ?? null\n if (observation.usage?.cost.kind === 'uncaptured') return null\n return observation.usage?.cost.usd ?? null\n}\n\nfunction mean(values: readonly number[]): number {\n return values.reduce((sum, value) => sum + value, 0) / values.length\n}\n\nfunction assertComparisonControls(confidence: number, resamples: number): void {\n if (!Number.isSafeInteger(resamples) || resamples <= 0 || resamples > 1_000_000) {\n throw new Error(\n `compareAnalystRunners: resamples must be a positive safe integer no greater than 1000000, got ${String(resamples)}`,\n )\n }\n if (!Number.isFinite(confidence) || confidence <= 0 || confidence >= 1) {\n throw new Error(\n `compareAnalystRunners: confidence must be a finite number in (0,1), got ${String(confidence)}`,\n )\n }\n}\n\nfunction assertValidComparison(comparison: AnalystMetricComparison): void {\n const numericFields = [\n 'pairedCases',\n 'pairedClusters',\n 'eligibleObservations',\n 'pairedObservations',\n 'baselineMissingObservations',\n 'candidateMissingObservations',\n 'asymmetricMissingObservations',\n 'confidence',\n 'resamples',\n ] as const\n const nullableFields = [\n 'baselineMean',\n 'candidateMean',\n 'meanDelta',\n 'intervalLow',\n 'intervalHigh',\n ] as const\n if (\n numericFields.some((field) => !Number.isFinite(comparison[field])) ||\n nullableFields.some(\n (field) => comparison[field] !== null && !Number.isFinite(comparison[field]),\n )\n ) {\n throw new Error(\n `compareAnalystRunners: ${comparison.metric} produced non-finite comparison output`,\n )\n }\n if (\n comparison.intervalLow !== null &&\n comparison.intervalHigh !== null &&\n comparison.intervalLow > comparison.intervalHigh\n ) {\n throw new Error(\n `compareAnalystRunners: ${comparison.metric} produced an invalid confidence interval`,\n )\n }\n}\n","import { z } from 'zod'\nimport type { AnalystBenchmarkObservation } from './benchmark'\nimport type { AnalystBenchmarkArtifact } from './benchmark-command-artifact'\nimport { ANALYST_COMPARISON_METRICS } from './benchmark-comparison'\n\nconst nonEmptyString = z.string().refine((value) => value.trim().length > 0, {\n message: 'must be a non-empty string',\n})\nconst safeInteger = z.number().refine(Number.isSafeInteger, {\n message: 'must be a safe integer',\n})\nconst nonNegativeInteger = safeInteger.refine((value) => value >= 0, {\n message: 'must be a non-negative safe integer',\n})\nconst positiveInteger = safeInteger.refine((value) => value > 0, {\n message: 'must be a positive safe integer',\n})\nconst nonNegativeNumber = z.number().nonnegative()\nconst rate = z.number().min(0).max(1)\nconst nullableRate = rate.nullable()\nconst finiteNumber = z.number()\nconst nullableFiniteNumber = finiteNumber.nullable()\nconst sha256 = z.string().regex(/^[a-f0-9]{64}$/, 'must be a lowercase SHA-256 digest')\nconst revision = z\n .string()\n .regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/, 'must be a lowercase 40 or 64 character revision')\nconst timestamp = z.string().refine((value) => Number.isFinite(Date.parse(value)), {\n message: 'must be a valid timestamp',\n})\nconst stringArray = z.array(z.string())\nconst nonEmptyStringArray = z.array(nonEmptyString)\nconst metadata = z.record(z.string(), z.unknown())\n\nconst errorSchema = z.strictObject({\n class: nonEmptyString,\n message: nonEmptyString,\n code: nonEmptyString.optional(),\n status: z.number().int().min(100).max(599).optional(),\n})\n\nconst evidenceSchema = z.strictObject({\n kind: z.enum(['span', 'event', 'artifact', 'finding', 'metric']),\n uri: nonEmptyString,\n excerpt: z.string().optional(),\n})\n\nconst findingSchema = z.strictObject({\n schema_version: z.literal('1.0.0'),\n finding_id: nonEmptyString,\n analyst_id: nonEmptyString,\n produced_at: timestamp,\n severity: z.enum(['critical', 'high', 'medium', 'low', 'info']),\n area: nonEmptyString,\n claim: nonEmptyString,\n rationale: z.string().optional(),\n evidence_refs: z.array(evidenceSchema),\n recommended_action: z.string().optional(),\n validation_plan: z.string().optional(),\n confidence: rate,\n subject: z.string().optional(),\n derived_from_judge: z.boolean().optional(),\n metadata: metadata.optional(),\n})\n\nconst tokenUsageSchema = z\n .strictObject({\n input: nonNegativeInteger,\n output: nonNegativeInteger,\n reasoning: nonNegativeInteger.optional(),\n cached: nonNegativeInteger.optional(),\n cacheWrite: nonNegativeInteger.optional(),\n })\n .superRefine((usage, context) => {\n if (usage.reasoning !== undefined && usage.reasoning > usage.output) {\n context.addIssue({\n code: 'custom',\n path: ['reasoning'],\n message: 'must not exceed output tokens',\n })\n }\n })\n\nconst costSchema = z.discriminatedUnion('kind', [\n z.strictObject({\n kind: z.literal('observed'),\n usd: nonNegativeNumber,\n }),\n z.strictObject({\n kind: z.literal('estimated'),\n usd: nonNegativeNumber,\n }),\n z.strictObject({\n kind: z.literal('uncaptured'),\n usd: z.null(),\n }),\n])\n\nconst usageSchema = z.strictObject({\n calls: nonNegativeInteger.nullable(),\n tokens: tokenUsageSchema.nullable(),\n cost: costSchema,\n knownCostUsd: nonNegativeNumber.optional(),\n // A provider that reports one side only: the count is kept here rather than\n // zero-filled into `tokens`, so this gate must accept it or a paid run is\n // rejected at journal-write time, after the model call is spent.\n partialTokens: z\n .strictObject({\n input: nonNegativeInteger.nullable(),\n output: nonNegativeInteger.nullable(),\n })\n .optional(),\n tokensEstimated: z.boolean().optional(),\n})\n\nconst findingScoreSchema = z.strictObject({\n expectedIssueCount: nonNegativeInteger,\n matchedIssueIds: nonEmptyStringArray,\n missedIssueIds: nonEmptyStringArray,\n supportedFindingIndexes: z.array(nonNegativeInteger),\n unsupportedFindingIndexes: z.array(nonNegativeInteger),\n unlabeledEvidence: z.array(evidenceSchema),\n issueRecall: rate,\n findingPrecision: rate,\n f1: rate,\n criticalStepAccuracy: nullableRate,\n citationCoverage: nullableRate,\n citationExcerptCoverage: nullableRate,\n citationLabelAgreement: nullableRate,\n predictionOnLabelEmptyCase: z.boolean(),\n})\n\nconst evidenceResolutionSchema = z.strictObject({\n checked: nonNegativeInteger,\n resolved: nonNegativeInteger,\n unresolvedEvidence: z.array(evidenceSchema),\n errors: z.array(\n z.strictObject({\n evidence: evidenceSchema,\n class: nonEmptyString,\n message: nonEmptyString,\n }),\n ),\n validity: nullableRate,\n})\n\nconst observationSchema: z.ZodType<AnalystBenchmarkObservation> = z\n .strictObject({\n runnerId: nonEmptyString,\n caseId: nonEmptyString,\n clusterId: nonEmptyString,\n labelState: z.enum(['positive', 'trusted-negative', 'unlabeled']),\n repetition: nonNegativeInteger,\n executionIndex: nonNegativeInteger,\n latencyMs: nonNegativeNumber.nullable(),\n latencySource: z.enum(['benchmark-clock', 'runner-reported', 'uncaptured']),\n findings: z.array(findingSchema),\n score: findingScoreSchema,\n evidenceResolution: evidenceResolutionSchema.optional(),\n caseTags: stringArray,\n caseMetadata: metadata.optional(),\n usage: usageSchema.optional(),\n runnerMetadata: metadata.optional(),\n error: errorSchema.optional(),\n })\n .superRefine((observation, context) => {\n const latencyIsMissing = observation.latencyMs === null\n if (\n (observation.latencySource === 'uncaptured' && !latencyIsMissing) ||\n (observation.latencySource !== 'uncaptured' && latencyIsMissing)\n ) {\n context.addIssue({\n code: 'custom',\n path: ['latencyMs'],\n message: `must ${observation.latencySource === 'uncaptured' ? '' : 'not '}be null for '${observation.latencySource}' latency`,\n })\n }\n })\n\nconst latencyDistributionSchema = z.strictObject({\n min: nonNegativeNumber,\n mean: nonNegativeNumber,\n p50: nonNegativeNumber,\n p95: nonNegativeNumber,\n max: nonNegativeNumber,\n})\n\nconst summarySchema = z.strictObject({\n runnerId: nonEmptyString,\n plannedRuns: nonNegativeInteger,\n completedRuns: nonNegativeInteger,\n failedRuns: nonNegativeInteger,\n issueBearingRuns: nonNegativeInteger,\n trustedNegativeRuns: nonNegativeInteger,\n unlabeledRuns: nonNegativeInteger,\n issueRecall: nullableRate,\n findingPrecision: nullableRate,\n f1: nullableRate,\n macroIssueRecall: nullableRate,\n macroFindingPrecision: nullableRate,\n macroF1: nullableRate,\n criticalStepAccuracy: nullableRate,\n citationCoverage: nullableRate,\n citationExcerptCoverage: nullableRate,\n citationLabelAgreement: nullableRate,\n citationResolution: nullableRate,\n citationResolutionUnknownRuns: nonNegativeInteger,\n unresolvedCitations: nonNegativeInteger,\n citationResolutionErrors: nonNegativeInteger,\n trustedNegativeFalsePositiveRate: nullableRate,\n trustedNegativeFailureRate: nullableRate,\n unlabeledPredictionRate: nullableRate,\n unlabeledFailureRate: nullableRate,\n predictionAgreement: nullableRate,\n predictionAgreementCases: nonNegativeInteger,\n matchedLabelAgreement: nullableRate,\n matchedLabelAgreementCases: nonNegativeInteger,\n latencyMs: latencyDistributionSchema.nullable(),\n benchmarkClockLatencyRuns: nonNegativeInteger,\n runnerReportedLatencyRuns: nonNegativeInteger,\n latencyUnknownRuns: nonNegativeInteger,\n calls: nonNegativeInteger,\n callsUnknownRuns: nonNegativeInteger,\n inputTokens: nonNegativeInteger,\n outputTokens: nonNegativeInteger,\n reasoningTokens: nonNegativeInteger,\n cachedTokens: nonNegativeInteger,\n cacheWriteTokens: nonNegativeInteger,\n tokenUsageUnknownRuns: nonNegativeInteger,\n reasoningTokenUsageUnknownRuns: nonNegativeInteger,\n cachedTokenUsageUnknownRuns: nonNegativeInteger,\n cacheWriteTokenUsageUnknownRuns: nonNegativeInteger,\n knownCostUsd: nonNegativeNumber,\n costUnknownRuns: nonNegativeInteger,\n})\n\nconst provenanceSchema = z\n .strictObject({\n id: nonEmptyString.optional(),\n dataset: z\n .strictObject({\n id: nonEmptyString,\n revision: nonEmptyString,\n split: nonEmptyString.optional(),\n })\n .optional(),\n command: nonEmptyString.optional(),\n environment: z.record(z.string(), z.string()).optional(),\n metadata: metadata.optional(),\n startedAt: timestamp,\n endedAt: timestamp,\n caseCount: positiveInteger,\n runnerIds: nonEmptyStringArray.min(1),\n repetitions: positiveInteger,\n maxConcurrency: positiveInteger,\n runnerOrderSeed: safeInteger,\n })\n .superRefine((provenance, context) => {\n if (Date.parse(provenance.endedAt) < Date.parse(provenance.startedAt)) {\n context.addIssue({\n code: 'custom',\n path: ['endedAt'],\n message: 'must not precede startedAt',\n })\n }\n })\n\nconst resultSchema = z.strictObject({\n provenance: provenanceSchema,\n observations: z.array(observationSchema),\n summaries: z.array(summarySchema),\n})\n\nconst comparisonMetricSchema = z.strictObject({\n metric: z.enum(ANALYST_COMPARISON_METRICS),\n direction: z.enum(['higher', 'lower']),\n pairedCases: nonNegativeInteger,\n pairedClusters: nonNegativeInteger,\n eligibleObservations: nonNegativeInteger,\n pairedObservations: nonNegativeInteger,\n baselineMissingObservations: nonNegativeInteger,\n candidateMissingObservations: nonNegativeInteger,\n asymmetricMissingObservations: nonNegativeInteger,\n survivorOnly: z.boolean(),\n baselineMean: nullableFiniteNumber,\n candidateMean: nullableFiniteNumber,\n meanDelta: nullableFiniteNumber,\n intervalLow: nullableFiniteNumber,\n intervalHigh: nullableFiniteNumber,\n confidence: z.number().gt(0).lt(1),\n resamples: positiveInteger,\n minimumSampleMet: z.boolean(),\n populationInferenceEligible: z.boolean(),\n inferenceLimitations: stringArray,\n})\n\nconst comparisonSchema = z.strictObject({\n baselineRunnerId: nonEmptyString,\n candidateRunnerId: nonEmptyString,\n metrics: z.array(comparisonMetricSchema),\n})\n\nconst valueDistributionSchema = z.strictObject({\n total: nonNegativeInteger,\n missing: nonNegativeInteger,\n counts: z.record(z.string(), nonNegativeInteger),\n})\n\nconst distributionsSchema = z.strictObject({\n class: valueDistributionSchema,\n agent: valueDistributionSchema,\n model: valueDistributionSchema,\n difficulty: valueDistributionSchema,\n solved: valueDistributionSchema,\n})\n\nconst selectionReportSchema = z.strictObject({\n method: z.enum(['census', 'deterministic-hash']),\n seed: safeInteger,\n sourceCount: positiveInteger,\n selectedCount: positiveInteger,\n stratified: z.literal(false),\n representativeOfInput: z.boolean(),\n source: distributionsSchema,\n selected: distributionsSchema,\n})\n\nconst verificationOutcomeSchema = z.strictObject({\n status: z.enum(['passed', 'failed', 'unavailable']),\n reason: z\n .enum([\n 'missing-result',\n 'result-output-unavailable',\n 'result-parse-error',\n 'result-label-disagreement',\n ])\n .optional(),\n parseError: errorSchema.optional(),\n sources: z.array(\n z.strictObject({\n path: nonEmptyString,\n format: z.enum(['terminal-bench', 'swe-bench', 'swe-multi']),\n status: z.enum(['passed', 'failed', 'unavailable']),\n }),\n ),\n passedCheckCount: nonNegativeInteger,\n failedCheckCount: nonNegativeInteger,\n passedChecks: stringArray,\n failedChecks: stringArray,\n})\n\nconst verificationArtifactRole = z.enum(['final-test-output', 'final-result', 'final-metrics'])\n\nconst verificationArtifactSchema = z.strictObject({\n traceId: nonEmptyString,\n status: z.enum(['present', 'missing']),\n outcome: verificationOutcomeSchema,\n outcomeSpanId: nonEmptyString,\n caseDirectory: nonEmptyString,\n caseDirectoriesSearched: nonEmptyStringArray,\n totalBytes: nonNegativeInteger,\n maxBytes: positiveInteger,\n files: z.array(\n z.strictObject({\n role: verificationArtifactRole,\n path: nonEmptyString,\n relativePath: nonEmptyString,\n sha256,\n bytes: nonNegativeInteger,\n spanId: nonEmptyString,\n }),\n ),\n missingRoles: z.array(verificationArtifactRole),\n searched: z.strictObject({\n 'final-test-output': stringArray,\n 'final-result': stringArray,\n 'final-metrics': stringArray,\n }),\n})\n\nconst verificationAvailabilitySchema = z.strictObject({\n cases: nonNegativeInteger,\n resultFilesPresent: nonNegativeInteger,\n resultFilesMissing: nonNegativeInteger,\n outcomes: z.strictObject({\n passed: nonNegativeInteger,\n failed: nonNegativeInteger,\n unavailable: nonNegativeInteger,\n }),\n})\n\nconst codeTraceCalibrationSchema = z.strictObject({\n protocol: z.literal('labeled-positive-and-solved-negative'),\n rationale: nonEmptyString,\n runners: z.array(\n z.strictObject({\n runnerId: nonEmptyString,\n selectedRuns: nonNegativeInteger,\n positiveRuns: nonNegativeInteger,\n trustedNegativeRuns: nonNegativeInteger,\n unlabeledRuns: nonNegativeInteger,\n failedLabelEmptyRuns: nonNegativeInteger,\n unknownLabelEmptyRuns: nonNegativeInteger,\n completedRuns: nonNegativeInteger,\n failedRuns: nonNegativeInteger,\n expectedIncorrectSteps: nonNegativeInteger,\n predictedIncorrectSteps: nonNegativeInteger,\n matchedIncorrectSteps: nonNegativeInteger,\n officialAllRowF1: nullableRate,\n officialAllRowRuns: nonNegativeInteger,\n precision: nullableRate,\n recall: nullableRate,\n f1: nullableRate,\n trustedNegativeFalsePositiveRate: nullableRate,\n trustedNegativeFailureRate: nullableRate,\n unlabeledPredictionRate: nullableRate,\n unlabeledFailureRate: nullableRate,\n }),\n ),\n})\n\nconst agentRxCalibrationSchema = z.strictObject({\n protocol: z.literal('official-agentrx-root-cause'),\n upstreamRevision: revision,\n rationale: nonEmptyString,\n runners: z.array(\n z.strictObject({\n runnerId: nonEmptyString,\n selectedRuns: nonNegativeInteger,\n completedRuns: nonNegativeInteger,\n failedRuns: nonNegativeInteger,\n predictedRuns: nonNegativeInteger,\n missingPredictionRuns: nonNegativeInteger,\n exactStepAccuracy: nullableRate,\n stepAccuracyWithin1: nullableRate,\n stepAccuracyWithin2: nullableRate,\n stepAccuracyWithin3: nullableRate,\n stepAccuracyWithin4: nullableRate,\n stepAccuracyWithin5: nullableRate,\n meanStepDistance: nonNegativeNumber.nullable(),\n normalizedMeanStepDistance: nullableRate,\n normalizedDistanceRuns: nonNegativeInteger,\n normalizedDistanceUnknownRuns: nonNegativeInteger,\n rootCauseCategoryAccuracy: nullableRate,\n anyFailureCategoryAccuracy: nullableRate,\n earliestFailureCategoryAccuracy: nullableRate,\n terminalFailureCategoryAccuracy: nullableRate,\n }),\n ),\n})\n\nconst artifactSchema: z.ZodType<AnalystBenchmarkArtifact> = z\n .strictObject({\n kind: z.literal('agent-eval/analyst-benchmark-result'),\n runIdentitySha256: sha256,\n inputs: z.strictObject({\n dataset: z.enum(['agentrx', 'codetracebench']),\n datasetRevision: revision,\n datasetSplit: nonEmptyString,\n labelsSha256: sha256,\n sourceRowCount: positiveInteger,\n traceFiles: z.array(\n z.strictObject({\n traceId: nonEmptyString,\n relativePath: nonEmptyString,\n sha256,\n }),\n ),\n verificationArtifacts: z.array(verificationArtifactSchema),\n verificationAvailability: verificationAvailabilitySchema,\n selection: z.strictObject({\n limit: positiveInteger,\n seed: safeInteger,\n selectedCaseIds: nonEmptyStringArray.min(1),\n report: selectionReportSchema,\n }),\n execution: z.strictObject({\n repetitions: positiveInteger,\n concurrency: positiveInteger,\n rlmSamples: positiveInteger.optional(),\n model: nonEmptyString,\n modelOwnerCallRef: nonEmptyString.optional(),\n maxOutputTokens: positiveInteger,\n maxReasoningTokens: nonNegativeInteger.optional(),\n maxModelRequestBytes: positiveInteger.optional(),\n maxModelResponseBytes: positiveInteger.optional(),\n modelRequestTimeoutMs: positiveInteger.optional(),\n timeoutMs: positiveInteger,\n pricing: z\n .strictObject({\n inputUsdPerMillion: nonNegativeNumber,\n cachedInputUsdPerMillion: nonNegativeNumber.optional(),\n cacheWriteUsdPerMillion: nonNegativeNumber.optional(),\n outputUsdPerMillion: nonNegativeNumber,\n })\n .optional(),\n recursiveLimits: z\n .strictObject({\n maxIterations: positiveInteger,\n maxLlmCalls: positiveInteger,\n maxToolCalls: positiveInteger,\n maxOutputChars: positiveInteger,\n maxModelRequests: positiveInteger.nullable(),\n traceToolRequestBytes: positiveInteger,\n traceToolResponseBytes: positiveInteger,\n traceToolTimeoutMs: positiveInteger,\n })\n .optional(),\n processLimits: z\n .strictObject({\n maxInputBytes: positiveInteger,\n maxResultBytes: positiveInteger,\n maxOutputChars: positiveInteger,\n })\n .optional(),\n maxCostUsd: nonNegativeNumber,\n maxArtifactBytes: positiveInteger,\n analystProtocolSha256: sha256,\n implementationSha256: sha256,\n dependencyLockSha256: sha256,\n }),\n }),\n result: resultSchema,\n comparisons: z.array(comparisonSchema),\n codeTraceCalibration: codeTraceCalibrationSchema.optional(),\n agentRxCalibration: agentRxCalibrationSchema.optional(),\n })\n .superRefine((artifact, context) => {\n const isCodeTrace = artifact.inputs.dataset === 'codetracebench'\n if (isCodeTrace && !artifact.codeTraceCalibration) {\n context.addIssue({\n code: 'custom',\n path: ['codeTraceCalibration'],\n message: 'is required for CodeTraceBench artifacts',\n })\n }\n if (isCodeTrace && artifact.agentRxCalibration) {\n context.addIssue({\n code: 'custom',\n path: ['agentRxCalibration'],\n message: 'is not allowed for CodeTraceBench artifacts',\n })\n }\n if (!isCodeTrace && !artifact.agentRxCalibration) {\n context.addIssue({\n code: 'custom',\n path: ['agentRxCalibration'],\n message: 'is required for AgentRx artifacts',\n })\n }\n if (!isCodeTrace && artifact.codeTraceCalibration) {\n context.addIssue({\n code: 'custom',\n path: ['codeTraceCalibration'],\n message: 'is not allowed for AgentRx artifacts',\n })\n }\n })\n\nexport function assertAnalystBenchmarkObservation(\n value: unknown,\n context: string,\n): asserts value is AnalystBenchmarkObservation {\n assertSchema(observationSchema, value, context)\n}\n\nexport function assertAnalystBenchmarkArtifact(\n value: unknown,\n context: string,\n): asserts value is AnalystBenchmarkArtifact {\n assertSchema(artifactSchema, value, context)\n}\n\nfunction assertSchema(schema: z.ZodType, value: unknown, context: string): void {\n const result = schema.safeParse(value)\n if (result.success) return\n throw new TypeError(formatIssue(result.error.issues[0]!, context))\n}\n\nfunction formatIssue(issue: z.core.$ZodIssue, context: string): string {\n const path = issue.path.length === 0 ? context : `${context}.${issue.path.join('.')}`\n if (issue.code === 'unrecognized_keys') {\n return `${path} contains unknown field '${issue.keys[0]}'`\n }\n return `${path} ${issue.message}`\n}\n","import type { CustomTokenPricing } from '../cost-ledger'\nimport { canonicalString, hashCanonical, jsonDocument } from '../ledger-core/canonical'\nimport type { AnalystBenchmarkObservation, AnalystBenchmarkResult } from './benchmark'\nimport type { AgentRxCalibrationSummary } from './benchmark-agentrx-calibration'\nimport type { AnalystRunnerComparison } from './benchmark-comparison'\nimport type { CodeTraceCalibrationSummary } from './benchmark-public-calibration'\nimport type {\n PublicAnalystBenchmarkDataset,\n PublicBenchmarkSelectionReport,\n} from './benchmark-real-model'\nimport type { VerificationArtifactManifest } from './benchmark-verification-artifacts'\n\nexport { assertAnalystBenchmarkObservation } from './benchmark-command-validation'\n\nexport interface AnalystBenchmarkArtifact {\n kind: 'agent-eval/analyst-benchmark-result'\n runIdentitySha256: string\n inputs: {\n dataset: PublicAnalystBenchmarkDataset\n datasetRevision: string\n datasetSplit: string\n labelsSha256: string\n sourceRowCount: number\n traceFiles: Array<{ traceId: string; relativePath: string; sha256: string }>\n verificationArtifacts: VerificationArtifactManifest[]\n verificationAvailability: VerificationAvailabilitySummary\n selection: {\n limit: number\n seed: number\n selectedCaseIds: string[]\n report: PublicBenchmarkSelectionReport\n }\n execution: {\n repetitions: number\n concurrency: number\n /** Absent on artifacts produced before consensus sampling existed. */\n rlmSamples?: number\n model: string\n /** These fields are absent only on immutable evidence produced before model owners existed. */\n modelOwnerCallRef?: string\n maxOutputTokens: number\n maxReasoningTokens?: number\n maxModelRequestBytes?: number\n maxModelResponseBytes?: number\n modelRequestTimeoutMs?: number\n timeoutMs: number\n pricing?: CustomTokenPricing\n recursiveLimits?: {\n maxIterations: number\n maxLlmCalls: number\n maxToolCalls: number\n maxOutputChars: number\n maxModelRequests: number | null\n traceToolRequestBytes: number\n traceToolResponseBytes: number\n traceToolTimeoutMs: number\n }\n processLimits?: {\n maxInputBytes: number\n maxResultBytes: number\n maxOutputChars: number\n }\n maxCostUsd: number\n maxArtifactBytes: number\n analystProtocolSha256: string\n /** Present only when the run replaced the recursive analyst instructions. */\n instructionsOverrideSha256?: string\n implementationSha256: string\n dependencyLockSha256: string\n }\n }\n result: AnalystBenchmarkResult\n comparisons: AnalystRunnerComparison[]\n codeTraceCalibration?: CodeTraceCalibrationSummary\n agentRxCalibration?: AgentRxCalibrationSummary\n}\n\nexport interface VerificationAvailabilitySummary {\n cases: number\n resultFilesPresent: number\n resultFilesMissing: number\n outcomes: {\n passed: number\n failed: number\n unavailable: number\n }\n}\n\nexport interface AnalystBenchmarkRunIdentity {\n config: {\n dataset: PublicAnalystBenchmarkDataset\n datasetRevision: string\n datasetSplit: string\n model: {\n id: string\n ownerCallRef: string\n maxOutputTokens: number\n maxReasoningTokens: number\n maxRequestBytes: number\n maxResponseBytes: number\n requestTimeoutMs: number\n timeoutMs: number\n pricing: CustomTokenPricing\n recursiveLimits: {\n maxIterations: number\n maxLlmCalls: number\n maxToolCalls: number\n maxOutputChars: number\n maxModelRequests: number | null\n traceToolRequestBytes: number\n traceToolResponseBytes: number\n traceToolTimeoutMs: number\n }\n processLimits: {\n maxInputBytes: number\n maxResultBytes: number\n maxOutputChars: number\n }\n }\n limit: number\n seed: number\n concurrency: number\n repetitions: number\n /** Absent on manifests written before consensus sampling existed. */\n rlmSamples?: number\n maxCostUsd: number\n maxArtifactBytes: number\n analystProtocolSha256: string\n /** Present only when the run replaced the recursive analyst instructions. */\n instructionsOverrideSha256?: string\n implementationSha256: string\n dependencyLockSha256: string\n runnerIds: readonly ['empty', string]\n }\n inputs: {\n labelsSha256: string\n sourceRowCount: number\n selectedCaseIds: string[]\n traceFiles: Array<{ traceId: string; relativePath: string; sha256: string }>\n verificationArtifactsSha256: string\n caseDefinitionsSha256: string\n }\n}\n\nexport interface AnalystBenchmarkRunManifest {\n kind: 'agent-eval/analyst-benchmark-run'\n createdAt: string\n identitySha256: string\n localIdentitySha256: string\n identity: AnalystBenchmarkRunIdentity\n}\n\nexport interface AnalystBenchmarkLocalRunReceipt {\n kind: 'agent-eval/analyst-benchmark-local-run'\n runIdentitySha256: string\n localIdentitySha256: string\n local: {\n labelsPath: string\n traceDir: string\n artifactDir?: string\n outputDir: string\n /** Absent when the analyst owns its own transport (`prime`). */\n modelOwnerModule?: string\n }\n command: string\n environment: {\n node: string\n platform: string\n arch: string\n }\n files: {\n manifest: string\n observations: string\n costLedger: string\n modelResponses: string\n result: string\n report: string\n }\n}\n\nexport interface AnalystBenchmarkProgressRow {\n sequence: number\n runIdentitySha256: string\n previousRowSha256: string | null\n observation: AnalystBenchmarkObservation\n rowSha256: string\n}\n\nexport const ANALYST_BENCHMARK_MANIFEST_FILE = 'manifest.json'\nexport const ANALYST_BENCHMARK_OBSERVATIONS_FILE = 'observations.jsonl'\nexport const ANALYST_BENCHMARK_LOCAL_RECEIPT_FILE = 'run.local.json'\nexport const ANALYST_BENCHMARK_COST_LEDGER_FILE = 'cost-ledger.jsonl'\n\nexport function observationKey(observation: {\n runnerId: string\n caseId: string\n repetition: number\n}): string {\n return `${observation.runnerId}\\u0000${observation.caseId}\\u0000${observation.repetition}`\n}\n\nexport function parseJson(text: string, source: string): unknown {\n try {\n return JSON.parse(text)\n } catch {\n throw new Error(`invalid JSON in ${source}`)\n }\n}\n\nexport function assertExactKeys(\n value: Record<string, unknown>,\n allowed: readonly string[],\n context: string,\n optional: readonly string[] = [],\n): void {\n const allowedSet = new Set(allowed)\n const optionalSet = new Set(optional)\n for (const key of Object.keys(value)) {\n if (!allowedSet.has(key)) throw new TypeError(`${context} contains unknown field '${key}'`)\n }\n for (const key of allowed) {\n if (!optionalSet.has(key) && !(key in value)) {\n throw new TypeError(`${context} is missing field '${key}'`)\n }\n }\n}\n\n/**\n * Digest a benchmark receipt as the artifact file will carry it. Receipts are\n * digested before they are written and re-digested when they are read back, so\n * the digest covers the JSON document form (see {@link jsonDocument}); every\n * other ambiguous value is still refused.\n */\nexport function digestCanonical(value: unknown): string {\n return hashCanonical(jsonDocument(value)).slice('sha256:'.length)\n}\n\n/** RFC 8785 canonical JSON of the value's JSON document form — the byte form\n * the receipt digests and compares against. */\nexport function canonicalJson(value: unknown): string {\n return canonicalString(jsonDocument(value))\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nexport function isSha256(value: unknown): value is string {\n return typeof value === 'string' && /^[a-f0-9]{64}$/.test(value)\n}\n\nexport function isNonNegativeSafeInteger(value: unknown): value is number {\n return Number.isSafeInteger(value) && Number(value) >= 0\n}\n\nexport function isNonNegativeFinite(value: unknown): value is number {\n return typeof value === 'number' && Number.isFinite(value) && value >= 0\n}\n","export const ANALYST_BENCHMARK_IMPLEMENTATION_DIGEST_ALGORITHM = 'sha256-canonical-source-manifest'\n\nexport const ANALYST_BENCHMARK_DEPENDENCY_LOCK_DIGEST_ALGORITHM = 'sha256-canonical-file-manifest'\n\nexport const ANALYST_BENCHMARK_DEPENDENCY_LOCK_FILES = Object.freeze([\n 'clients/python/pyproject.toml',\n 'clients/python/uv.lock',\n 'package.json',\n 'pnpm-lock.yaml',\n])\n\nexport const ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256 =\n '7b4c3f9a7c13539960a62697b783dec3dd6738d2d9044a62ecb77bd6bf53e920'\n\n/** The published benchmark evidence was produced at this package version, by\n * the retired one-shot direct runner, before trace analysts moved to the\n * recursive DSPy RLM engine. Both evidence digests below are historical facts\n * about that artifact: the current implementation and dependency manifest have\n * since changed, so they cannot describe the current engine. A fresh certified\n * run must replace the published evidence before any accuracy number is\n * attributed to the engine that ships today. */\nexport const ANALYST_BENCHMARK_EVIDENCE_PACKAGE_VERSION = '0.137.0'\n\nexport const ANALYST_BENCHMARK_EVIDENCE_DEPENDENCY_LOCK_SHA256 =\n '1e03f2daed356d60316aabefb407ec1e437ac94d408d61eea4ae096e9c6fbb5b'\n\nexport const ANALYST_BENCHMARK_EVIDENCE_IMPLEMENTATION_SHA256 =\n '4dba263b6256a30d56c7fdb2d992d3a953c0035d731f359b704db806f68f75ac'\n\nexport const ANALYST_BENCHMARK_IMPLEMENTATION_FILES = Object.freeze([\n 'clients/python/src/agent_eval_rpc/dspy_rlm_bridge.py',\n 'clients/python/src/agent_eval_rpc/optimizer_bridge_common.py',\n 'src/analyst/benchmark-agentrx-calibration.ts',\n 'src/analyst/benchmark-command-artifact.ts',\n 'src/analyst/benchmark-command-persistence.ts',\n 'src/analyst/benchmark-command-result.ts',\n 'src/analyst/benchmark-command-validation.ts',\n 'src/analyst/benchmark-command.ts',\n 'src/analyst/benchmark-comparison.ts',\n 'src/analyst/benchmark-dataset-agentrx.ts',\n 'src/analyst/benchmark-dataset-codetrace.ts',\n 'src/analyst/benchmark-dataset-utils.ts',\n 'src/analyst/benchmark-datasets.ts',\n 'src/analyst/benchmark-evidence-validation.ts',\n 'src/analyst/benchmark-instructions-override.ts',\n 'src/analyst/benchmark-public-adapters.ts',\n 'src/analyst/benchmark-public-calibration.ts',\n 'src/analyst/benchmark-public-consensus.ts',\n 'src/analyst/benchmark-public-data.ts',\n 'src/analyst/benchmark-public-errors.ts',\n 'src/analyst/benchmark-public-model.ts',\n 'src/analyst/benchmark-public-prompt.ts',\n 'src/analyst/benchmark-public-rlm.ts',\n 'src/analyst/benchmark-public-types.ts',\n 'src/analyst/benchmark-real-model.ts',\n 'src/analyst/benchmark-report.ts',\n 'src/analyst/benchmark-response-cache.ts',\n 'src/analyst/benchmark-runner-prime.ts',\n 'src/analyst/benchmark-scoring.ts',\n 'src/analyst/benchmark-summary.ts',\n 'src/analyst/benchmark-verification-artifacts.ts',\n 'src/analyst/benchmark-verification-outcome.ts',\n 'src/analyst/benchmark.ts',\n 'src/analyst/definition.ts',\n 'src/analyst/dspy-rlm-engine.ts',\n 'src/analyst/engine.ts',\n 'src/analyst/equal-terms.ts',\n 'src/analyst/exact-types.ts',\n 'src/analyst/finding-codec.ts',\n 'src/analyst/finding-signature.ts',\n 'src/analyst/finding-subject.ts',\n 'src/analyst/kind-factory.ts',\n 'src/analyst/parse-tolerant.ts',\n 'src/analyst/prime-bridge-transport.ts',\n 'src/analyst/prime-protocol.ts',\n 'src/analyst/reply-contract.ts',\n 'src/analyst/tool-groups.ts',\n 'src/analyst/trace-tool-callback.ts',\n 'src/analyst/types.ts',\n 'src/analyst/usage-receipt.ts',\n 'src/campaign/external-optimizer-anthropic.ts',\n 'src/campaign/external-optimizer-callback.ts',\n 'src/campaign/external-optimizer-contracts.ts',\n 'src/campaign/external-optimizer-http.ts',\n 'src/campaign/external-optimizer-model-proxy.ts',\n 'src/campaign/external-optimizer-process.ts',\n 'src/campaign/external-optimizer-resources.ts',\n 'src/campaign/external-optimizer-subprocess.ts',\n 'src/campaign/search-ledger-errors.ts',\n 'src/campaign/search-ledger-file.ts',\n 'src/campaign/single-run-lock.ts',\n 'src/campaign/storage.ts',\n 'src/concurrency.ts',\n 'src/cost-ledger.ts',\n 'src/errors.ts',\n 'src/integrity/served-model.ts',\n 'src/judge-calibration.ts',\n 'src/judge-families.ts',\n 'src/ledger-core/atomic-file-lock.ts',\n 'src/ledger-core/canonical.ts',\n 'src/ledger-core/deep-freeze.ts',\n 'src/ledger-core/index.ts',\n 'src/ledger-core/journal-file.ts',\n 'src/ledger-core/journal.ts',\n 'src/ledger-core/trusted-head.ts',\n 'src/llm-client.ts',\n 'src/math/normal.ts',\n 'src/math/special-functions.ts',\n 'src/math/student-t.ts',\n 'src/metrics.ts',\n 'src/record-id.ts',\n 'src/statistics/agreement-irr.ts',\n 'src/statistics/descriptive.ts',\n 'src/statistics/effect-sizes.ts',\n 'src/statistics/index.ts',\n 'src/statistics/internal.ts',\n 'src/statistics/multiplicity.ts',\n 'src/statistics/paired-binary.ts',\n 'src/statistics/paired-tests.ts',\n 'src/statistics/power-and-mde.ts',\n 'src/statistics/random.ts',\n 'src/statistics/rank-tests.ts',\n 'src/statistics/sequential-eprocess.ts',\n 'src/trace-analyst/errors.ts',\n 'src/trace-analyst/otlp-span.ts',\n 'src/trace-analyst/shared-abortable-task.ts',\n 'src/trace-analyst/store-boundary.ts',\n 'src/trace-analyst/store-bounds.ts',\n 'src/trace-analyst/store-contract.ts',\n 'src/trace-analyst/store-otlp.ts',\n 'src/trace-analyst/store-schemas.ts',\n 'src/trace-analyst/store.ts',\n 'src/trace-analyst/tools.ts',\n 'src/trace-analyst/types.ts',\n 'src/trace/attribute-vocabulary.ts',\n 'src/trace/otlp-attributes.ts',\n 'src/trace/raw-provider-sink.ts',\n 'src/verdict-cache.ts',\n])\n\nexport const ANALYST_BENCHMARK_IMPLEMENTATION_SHA256 =\n 'e499ff9c5a3b24104d1a9dbc0c3742ffd08b67ff1b852922b423d38231954254'\n\nexport function analystBenchmarkImplementationDigest() {\n return ANALYST_BENCHMARK_IMPLEMENTATION_SHA256\n}\n\nexport function analystBenchmarkDependencyLockDigest() {\n return ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256\n}\n","import { TRACE_ANALYSIS_LIMITS, type TraceAnalysisStore } from '../trace-analyst/store'\nimport type { AnalystFinding, EvidenceRef } from './types'\n\nconst MIN_ACTION_EXCERPT_CHARACTERS = 12\nexport const MAX_ASSISTANT_STEP_EVIDENCE_EXCERPT_CHARACTERS = 512\nconst MAX_LABEL_SCAN_DEPTH = 64\nconst MAX_SERIALIZED_JSON_SCAN_BYTES = 64 * 1024\nconst MAX_SERIALIZED_JSON_SCAN_DEPTH = 8\n\nconst BENCHMARK_LABEL_KEYS = new Set([\n 'category_reason',\n 'failure_category',\n 'failure_summary',\n 'incorrect_stages',\n 'incorrect_step_ids',\n 'root_cause',\n 'root_cause_failure_id',\n 'root_cause_reason',\n 'step_reason',\n 'unuseful_step_ids',\n])\nconst BENCHMARK_LABEL_KEY_TOKENS = [...BENCHMARK_LABEL_KEYS].sort(\n (left, right) => right.length - left.length,\n)\n\nconst BENCHMARK_LABEL_PATH_MARKERS = [\n 'bench_manifest.verified',\n 'codetracer_labels.json',\n '/ground_truth/',\n '\\\\ground_truth\\\\',\n] as const\n\nexport interface BenchmarkLabelLeakScan {\n passed: true\n scannedBytes: number\n scannedValues: number\n}\n\nexport function assertNoBenchmarkLabelsInTrace(options: {\n traceId: string\n otlpText: string\n}): BenchmarkLabelLeakScan {\n let scannedValues = 0\n for (const [index, line] of options.otlpText.split(/\\r?\\n/).entries()) {\n if (!line.trim()) continue\n let value: unknown\n try {\n value = JSON.parse(line)\n } catch (error) {\n throw new TypeError(\n `trace '${options.traceId}' line ${index + 1} is invalid JSON: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n scannedValues += scanValue(value, options.traceId, `$line[${index + 1}]`, 0, 0)\n }\n if (scannedValues === 0) {\n throw new Error(`trace '${options.traceId}' contains no JSON values`)\n }\n return {\n passed: true,\n scannedBytes: Buffer.byteLength(options.otlpText),\n scannedValues,\n }\n}\n\nexport function assertNoBenchmarkLabelsInArtifact(options: {\n traceId: string\n relativePath: string\n content: string\n}): void {\n const normalizedPath = options.relativePath.toLowerCase()\n for (const marker of BENCHMARK_LABEL_PATH_MARKERS) {\n if (normalizedPath.includes(marker.toLowerCase())) {\n throw new Error(\n `trace '${options.traceId}' verification artifact path contains benchmark label marker '${marker}'`,\n )\n }\n }\n const normalizedContent = options.content.toLowerCase()\n for (const key of BENCHMARK_LABEL_KEYS) {\n if (normalizedContent.includes(key)) {\n throw new Error(\n `trace '${options.traceId}' verification artifact contains benchmark label key '${key}'`,\n )\n }\n }\n for (const marker of BENCHMARK_LABEL_PATH_MARKERS) {\n if (normalizedContent.includes(marker.toLowerCase())) {\n throw new Error(\n `trace '${options.traceId}' verification artifact contains benchmark label path marker '${marker}'`,\n )\n }\n }\n}\n\nexport async function validateCodeTraceFindingEvidence(options: {\n trajectoryId: string\n findings: readonly AnalystFinding[]\n store: TraceAnalysisStore\n signal?: AbortSignal\n}): Promise<void> {\n const citations = options.findings.flatMap((finding) =>\n finding.evidence_refs.map((evidence) => ({\n evidence,\n findingId: finding.finding_id,\n location: codeTraceStepFromEvidence(evidence.uri),\n })),\n )\n if (citations.length === 0) return\n\n for (const citation of citations) {\n if (!citation.location || citation.location.traceId !== options.trajectoryId) {\n throw new Error(\n `model finding '${citation.findingId}' cites non-case evidence '${citation.evidence.uri}'`,\n )\n }\n }\n\n const spanIds = [...new Set(citations.map((citation) => `step-${citation.location!.step}`))]\n const { spans, missing } = await fetchTraceSpans(options.store, {\n trajectoryId: options.trajectoryId,\n spanIds,\n ...(options.signal ? { signal: options.signal } : {}),\n })\n if (missing.length > 0) {\n throw new Error(\n `model finding evidence is unavailable in the case trace: ${missing.join(', ')}`,\n )\n }\n\n for (const citation of citations) {\n const spanId = `step-${citation.location!.step}`\n const span = spans.get(spanId)\n if (!span) {\n throw new Error(`model finding '${citation.findingId}' cites missing span '${spanId}'`)\n }\n if (span.kind !== 'LLM') {\n throw new Error(\n `model finding '${citation.findingId}' cites '${spanId}', which is ${span.kind}, not an assistant LLM span`,\n )\n }\n assertExactActionExcerpt(citation.findingId, citation.evidence, spanId, span.attributes.content)\n }\n}\n\n/**\n * Resolve assistant-step evidence for a trajectory.\n *\n * `steps` are claims the model made explicitly: an unresolvable one is a model\n * error and throws. `optionalSteps` are derived by the runner (a block's\n * interior, a block's consequence step), so an unresolvable one is simply\n * absent from the returned map and the caller decides what that means.\n */\nexport async function resolveAssistantStepEvidence(options: {\n trajectoryId: string\n steps: readonly number[]\n optionalSteps?: readonly number[]\n store: TraceAnalysisStore\n signal?: AbortSignal\n}): Promise<Map<number, EvidenceRef>> {\n const required = [...new Set(options.steps)]\n const optional = [...new Set(options.optionalSteps ?? [])].filter(\n (step) => !required.includes(step),\n )\n for (const step of [...required, ...optional]) {\n if (!Number.isSafeInteger(step) || step < 1) {\n throw new TypeError(`assistant evidence step must be a positive safe integer: ${step}`)\n }\n }\n const steps = [...required, ...optional]\n if (steps.length === 0) return new Map()\n\n const { spans, missing } = await fetchTraceSpans(options.store, {\n trajectoryId: options.trajectoryId,\n spanIds: steps.map((step) => `step-${step}`),\n ...(options.signal ? { signal: options.signal } : {}),\n })\n const missingRequired = missing.filter((spanId) =>\n required.some((step) => `step-${step}` === spanId),\n )\n if (missingRequired.length > 0) {\n throw new Error(`model selected unavailable assistant steps: ${missingRequired.join(', ')}`)\n }\n\n const evidence = new Map<number, EvidenceRef>()\n for (const step of steps) {\n const spanId = `step-${step}`\n const optionalStep = optional.includes(step)\n const span = spans.get(spanId)\n if (!span) {\n if (optionalStep) continue\n throw new Error(`model selected missing assistant step '${spanId}'`)\n }\n if (span.kind !== 'LLM') {\n if (optionalStep) continue\n throw new Error(\n `model selected '${spanId}', which is ${span.kind}, not an assistant LLM span`,\n )\n }\n const content = span.attributes.content\n if (typeof content !== 'string' || content.trim().length === 0) {\n if (optionalStep) continue\n throw new Error(`model selected '${spanId}' without action content`)\n }\n evidence.set(step, {\n kind: 'span',\n uri: codeTraceStepEvidenceUri(options.trajectoryId, step),\n excerpt: content.trim().slice(0, MAX_ASSISTANT_STEP_EVIDENCE_EXCERPT_CHARACTERS),\n })\n }\n return evidence\n}\n\n/**\n * Read spans by id, paging over the store's byte-budget omissions.\n *\n * `omitted_span_ids` names spans that exist but did not fit the response\n * ceiling; the store guarantees at least one span lands per call, so\n * re-requesting exactly the omitted ids terminates. Only `missing_span_ids`\n * describes a span the trace does not contain.\n */\nasync function fetchTraceSpans(\n store: TraceAnalysisStore,\n options: { trajectoryId: string; spanIds: readonly string[]; signal?: AbortSignal },\n): Promise<{\n spans: Map<string, Awaited<ReturnType<TraceAnalysisStore['viewSpans']>>['spans'][number]>\n missing: string[]\n}> {\n const spans = new Map<\n string,\n Awaited<ReturnType<TraceAnalysisStore['viewSpans']>>['spans'][number]\n >()\n const missing: string[] = []\n const unique = [...new Set(options.spanIds)]\n const context = options.signal ? { signal: options.signal } : undefined\n for (let offset = 0; offset < unique.length; offset += TRACE_ANALYSIS_LIMITS.viewSpans) {\n let pending = unique.slice(offset, offset + TRACE_ANALYSIS_LIMITS.viewSpans)\n while (pending.length > 0) {\n const result = await store.viewSpans(\n { trace_id: options.trajectoryId, span_ids: pending },\n context,\n )\n for (const span of result.spans) spans.set(span.span_id, span)\n missing.push(...result.missing_span_ids)\n const omitted = result.omitted_span_ids.filter((spanId) => !spans.has(spanId))\n if (omitted.length >= pending.length) {\n throw new Error(\n `trace '${options.trajectoryId}' cannot project spans within the store response budget: ${omitted.join(', ')}`,\n )\n }\n pending = omitted\n }\n }\n return { spans, missing }\n}\n\nfunction scanValue(\n value: unknown,\n traceId: string,\n path: string,\n depth: number,\n serializedDepth: number,\n): number {\n if (depth > MAX_LABEL_SCAN_DEPTH) {\n throw new Error(`trace '${traceId}' exceeds benchmark label scan depth at ${path}`)\n }\n if (Array.isArray(value)) {\n return (\n 1 +\n value.reduce(\n (count, entry, index) =>\n count + scanValue(entry, traceId, `${path}[${index}]`, depth + 1, serializedDepth),\n 0,\n )\n )\n }\n if (typeof value === 'object' && value !== null) {\n let count = 1\n for (const [key, entry] of Object.entries(value)) {\n if (BENCHMARK_LABEL_KEYS.has(key.toLowerCase())) {\n throw new Error(`trace '${traceId}' exposes benchmark label key '${key}' at ${path}`)\n }\n count += scanValue(entry, traceId, `${path}.${key}`, depth + 1, serializedDepth)\n }\n return count\n }\n if (typeof value === 'string') {\n const normalized = value.toLowerCase()\n const labelKey = BENCHMARK_LABEL_KEY_TOKENS.find((candidate) => normalized.includes(candidate))\n if (labelKey) {\n throw new Error(\n `trace '${traceId}' exposes benchmark label key '${labelKey}' inside a string at ${path}`,\n )\n }\n const marker = BENCHMARK_LABEL_PATH_MARKERS.find((candidate) => normalized.includes(candidate))\n if (marker) {\n throw new Error(\n `trace '${traceId}' exposes benchmark label path marker '${marker}' at ${path}`,\n )\n }\n const trimmed = value.trim()\n if (\n serializedDepth < MAX_SERIALIZED_JSON_SCAN_DEPTH &&\n Buffer.byteLength(trimmed) <= MAX_SERIALIZED_JSON_SCAN_BYTES &&\n looksLikeSerializedJson(trimmed)\n ) {\n let parsed: unknown\n try {\n parsed = JSON.parse(trimmed)\n } catch {\n return 1\n }\n return (\n 1 + scanValue(parsed, traceId, `${path}<serialized-json>`, depth + 1, serializedDepth + 1)\n )\n }\n }\n return 1\n}\n\nfunction looksLikeSerializedJson(value: string): boolean {\n return (\n (value.startsWith('{') && value.endsWith('}')) ||\n (value.startsWith('[') && value.endsWith(']')) ||\n (value.startsWith('\"') && value.endsWith('\"'))\n )\n}\n\nexport function codeTraceStepFromEvidence(uri: string): { traceId: string; step: number } | null {\n const match = /^trace:\\/\\/([^/]+)\\/span\\/step-(\\d+)$/.exec(uri)\n if (!match) return null\n try {\n const traceId = decodeURIComponent(match[1]!)\n const step = Number(match[2])\n return traceId && Number.isSafeInteger(step) && step > 0 ? { traceId, step } : null\n } catch {\n return null\n }\n}\n\nexport function codeTraceStepEvidenceUri(traceId: string, step: number): string {\n return `trace://${encodeURIComponent(traceId)}/span/step-${step}`\n}\n\nfunction assertExactActionExcerpt(\n findingId: string,\n evidence: EvidenceRef,\n spanId: string,\n content: unknown,\n): void {\n if (typeof content !== 'string' || content.length === 0) {\n throw new Error(`model finding '${findingId}' cites '${spanId}' without action content`)\n }\n const excerpt = evidence.excerpt?.trim()\n if (!excerpt) {\n throw new Error(`model finding '${findingId}' must quote action content from '${spanId}'`)\n }\n const requiredLength = Math.min(MIN_ACTION_EXCERPT_CHARACTERS, content.trim().length)\n if (excerpt.length < requiredLength) {\n throw new Error(\n `model finding '${findingId}' excerpt for '${spanId}' is too short; expected at least ${requiredLength} characters`,\n )\n }\n if (!content.includes(excerpt)) {\n throw new Error(\n `model finding '${findingId}' excerpt is not present in '${spanId}' action content`,\n )\n }\n}\n","import { z } from 'zod'\n\nexport type VerificationOutcomeStatus = 'passed' | 'failed' | 'unavailable'\n\nexport interface VerificationOutcomeSource {\n path: string\n format: 'terminal-bench' | 'swe-bench' | 'swe-multi'\n status: VerificationOutcomeStatus\n}\n\nexport interface VerificationOutcome {\n status: VerificationOutcomeStatus\n reason?:\n | 'missing-result'\n | 'result-output-unavailable'\n | 'result-parse-error'\n | 'result-label-disagreement'\n parseError?: { class: string; message: string }\n sources: VerificationOutcomeSource[]\n passedCheckCount: number\n failedCheckCount: number\n passedChecks: string[]\n failedChecks: string[]\n}\n\nexport interface VerificationResultFile {\n relativePath: string\n content: string\n}\n\nconst MAX_REPORTED_CHECKS = 20\nconst SWE_MULTI_NO_TEST_RESULTS =\n 'After applying the fix patch, no test results were captured when executing the test command.'\n\nconst checkNameSchema = z.string().min(1)\nconst checkListSchema = z.array(checkNameSchema).superRefine((checks, context) => {\n const seen = new Set<string>()\n for (const [index, check] of checks.entries()) {\n if (seen.has(check)) {\n context.addIssue({\n code: 'custom',\n path: [index],\n message: `duplicate check '${check}'`,\n })\n }\n seen.add(check)\n }\n})\nconst nonNegativeCountSchema = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER)\n\nconst terminalBenchSchema = z\n .object({\n is_resolved: z.boolean().nullable(),\n failure_mode: z.string().min(1),\n parser_results: z.record(z.string().min(1), z.enum(['passed', 'failed'])).nullable(),\n })\n .passthrough()\n\nconst directSweBenchSchema = z\n .object({\n resolved: z.boolean(),\n passed_tests: checkListSchema,\n failed_tests: checkListSchema,\n })\n .passthrough()\n\nconst nestedSweBenchCategorySchema = z\n .object({\n success: checkListSchema,\n failure: checkListSchema,\n })\n .passthrough()\n\nconst nestedSweBenchInstanceSchema = z\n .object({\n resolved: z.boolean(),\n tests_status: z\n .record(z.string().min(1), nestedSweBenchCategorySchema)\n .refine((value) => Object.keys(value).length > 0, 'must contain at least one test category'),\n })\n .passthrough()\n\nconst nestedSweBenchSchema = z\n .record(z.string().min(1), nestedSweBenchInstanceSchema)\n .refine((value) => Object.keys(value).length > 0, 'must contain at least one instance')\n\nconst sweMultiCheckResultSchema = z\n .object({\n passed_count: nonNegativeCountSchema,\n failed_count: nonNegativeCountSchema,\n skipped_count: nonNegativeCountSchema,\n passed_tests: checkListSchema,\n failed_tests: checkListSchema,\n skipped_tests: checkListSchema,\n })\n .passthrough()\n\nconst sweMultiSchema = z\n .object({\n valid: z.boolean(),\n error_msg: z.string(),\n fix_patch_result: sweMultiCheckResultSchema,\n })\n .passthrough()\n\nexport function parseVerificationOutcome(\n files: readonly VerificationResultFile[],\n): VerificationOutcome {\n if (files.length === 0) {\n throw new Error('final verification outcome requires at least one result file')\n }\n\n const sources: VerificationOutcomeSource[] = []\n const passedChecks = new Set<string>()\n const failedChecks = new Set<string>()\n const unavailableReasons = new Set<NonNullable<VerificationOutcome['reason']>>()\n\n for (const file of files) {\n let value: unknown\n try {\n value = JSON.parse(file.content)\n } catch (error) {\n throw new TypeError(\n `final verification result is not valid JSON: ${file.relativePath}: ${errorMessage(error)}`,\n )\n }\n const parsed = parseResult(value, file.relativePath)\n sources.push({\n path: file.relativePath,\n format: parsed.format,\n status: parsed.status,\n })\n if (parsed.reason) unavailableReasons.add(parsed.reason)\n for (const check of parsed.passedChecks) passedChecks.add(check)\n for (const check of parsed.failedChecks) failedChecks.add(check)\n }\n\n const statuses = new Set(sources.map((source) => source.status))\n if (statuses.size !== 1) {\n throw new Error(\n `final verification result files disagree: ${sources\n .map((source) => `${source.path}=${source.status}`)\n .join(', ')}`,\n )\n }\n if (unavailableReasons.size > 1) {\n throw new Error(\n `final verification result files disagree on why the outcome is unavailable: ${[\n ...unavailableReasons,\n ].join(', ')}`,\n )\n }\n const [unavailableReason] = unavailableReasons\n\n const passed = [...passedChecks].sort()\n const failed = [...failedChecks].sort()\n assertDisjointChecks(passed, failed, 'final verification result')\n return {\n status: sources[0]!.status,\n ...(unavailableReason ? { reason: unavailableReason } : {}),\n sources,\n passedCheckCount: passed.length,\n failedCheckCount: failed.length,\n passedChecks: passed.slice(0, MAX_REPORTED_CHECKS),\n failedChecks: failed.slice(0, MAX_REPORTED_CHECKS),\n }\n}\n\ninterface ParsedResult {\n format: VerificationOutcomeSource['format']\n status: VerificationOutcomeStatus\n reason?: NonNullable<VerificationOutcome['reason']>\n passedChecks: string[]\n failedChecks: string[]\n}\n\nfunction parseResult(value: unknown, path: string): ParsedResult {\n const record = asRecord(value)\n if (!record) {\n throw unsupported(path)\n }\n\n const discriminators = ['is_resolved', 'resolved', 'valid'].filter((field) =>\n Object.hasOwn(record, field),\n )\n if (discriminators.length > 1) {\n throw new TypeError(\n `final verification result is ambiguous: ${path}: found ${discriminators.join(', ')}`,\n )\n }\n if (discriminators[0] === 'is_resolved') return parseTerminalBench(record, path)\n if (discriminators[0] === 'resolved') return parseDirectSweBench(record, path)\n if (discriminators[0] === 'valid') return parseSweMulti(record, path)\n\n const entries = Object.entries(record)\n const looksNested = entries.some(([, candidate]) => {\n const nested = asRecord(candidate)\n return nested !== null && Object.hasOwn(nested, 'resolved')\n })\n if (looksNested) return parseNestedSweBench(record, path)\n\n throw unsupported(path)\n}\n\nfunction parseTerminalBench(value: unknown, path: string): ParsedResult {\n const record = parseSchema(terminalBenchSchema, value, path, 'Terminal-Bench')\n if (record.is_resolved === null) {\n if (record.parser_results !== null) {\n throw malformed(\n path,\n 'Terminal-Bench',\n 'parser_results must be null when is_resolved is null',\n )\n }\n if (record.failure_mode === 'unset') {\n throw malformed(path, 'Terminal-Bench', \"failure_mode cannot be 'unset' when unresolved\")\n }\n return {\n format: 'terminal-bench',\n status: 'unavailable',\n reason:\n record.failure_mode === 'parse_error' ? 'result-parse-error' : 'result-output-unavailable',\n passedChecks: [],\n failedChecks: [],\n }\n }\n if (record.parser_results === null) {\n throw malformed(\n path,\n 'Terminal-Bench',\n 'parser_results must be an object when is_resolved is boolean',\n )\n }\n const checks = stringStatusChecks(record.parser_results)\n if (checks.passedChecks.length + checks.failedChecks.length === 0) {\n throw malformed(path, 'Terminal-Bench', 'parser_results must contain at least one check')\n }\n assertOutcomeConsistency(record.is_resolved, checks, path, 'Terminal-Bench is_resolved', true)\n return {\n format: 'terminal-bench',\n status: status(record.is_resolved),\n ...checks,\n }\n}\n\nfunction parseDirectSweBench(value: unknown, path: string): ParsedResult {\n const record = parseSchema(directSweBenchSchema, value, path, 'SWE-bench')\n const checks = {\n passedChecks: record.passed_tests,\n failedChecks: record.failed_tests,\n }\n assertOutcomeConsistency(record.resolved, checks, path, 'SWE-bench resolved')\n return {\n format: 'swe-bench',\n status: status(record.resolved),\n ...checks,\n }\n}\n\nfunction parseNestedSweBench(value: unknown, path: string): ParsedResult {\n const record = parseSchema(nestedSweBenchSchema, value, path, 'SWE-bench instance report')\n const instances = Object.entries(record)\n const statuses = new Set(instances.map(([, instance]) => status(instance.resolved)))\n if (statuses.size !== 1) {\n throw new Error(\n `final verification report contains conflicting instance outcomes: ${path}: ${instances\n .map(([id, instance]) => `${id}=${status(instance.resolved)}`)\n .join(', ')}`,\n )\n }\n\n const passedChecks: string[] = []\n const failedChecks: string[] = []\n for (const [instanceId, instance] of instances) {\n const checks = nestedSweBenchChecks(instanceId, instance.tests_status)\n assertOutcomeConsistency(\n instance.resolved,\n checks,\n path,\n `SWE-bench instance '${instanceId}' resolved`,\n )\n passedChecks.push(...checks.passedChecks)\n failedChecks.push(...checks.failedChecks)\n }\n return {\n format: 'swe-bench',\n status: [...statuses][0]!,\n passedChecks,\n failedChecks,\n }\n}\n\nfunction parseSweMulti(value: unknown, path: string): ParsedResult {\n const record = parseSchema(sweMultiSchema, value, path, 'SWE-Multi')\n const fix = record.fix_patch_result\n assertCount(fix.passed_count, fix.passed_tests, 'passed', path)\n assertCount(fix.failed_count, fix.failed_tests, 'failed', path)\n assertCount(fix.skipped_count, fix.skipped_tests, 'skipped', path)\n assertDisjointChecks(fix.passed_tests, fix.failed_tests, `SWE-Multi result ${path}`)\n assertDisjointChecks(fix.passed_tests, fix.skipped_tests, `SWE-Multi result ${path}`)\n assertDisjointChecks(fix.failed_tests, fix.skipped_tests, `SWE-Multi result ${path}`)\n\n const checks = {\n passedChecks: fix.passed_tests,\n failedChecks: fix.failed_tests,\n }\n if (record.valid === false && isSweMultiOutputUnavailable(record)) {\n return {\n format: 'swe-multi',\n status: 'unavailable',\n reason: 'result-output-unavailable',\n ...checks,\n }\n }\n assertOutcomeConsistency(record.valid, checks, path, 'SWE-Multi valid')\n return {\n format: 'swe-multi',\n status: status(record.valid),\n ...checks,\n }\n}\n\nfunction isSweMultiOutputUnavailable(record: z.infer<typeof sweMultiSchema>): boolean {\n const fix = record.fix_patch_result\n return (\n (record.error_msg === SWE_MULTI_NO_TEST_RESULTS ||\n record.error_msg.startsWith(`${SWE_MULTI_NO_TEST_RESULTS} `)) &&\n fix.passed_count === 0 &&\n fix.failed_count === 0 &&\n fix.skipped_count === 0\n )\n}\n\nfunction stringStatusChecks(record: Record<string, 'passed' | 'failed'>): {\n passedChecks: string[]\n failedChecks: string[]\n} {\n const passedChecks: string[] = []\n const failedChecks: string[] = []\n for (const [name, result] of Object.entries(record)) {\n if (result === 'passed') passedChecks.push(name)\n else failedChecks.push(name)\n }\n return { passedChecks, failedChecks }\n}\n\nfunction nestedSweBenchChecks(\n instanceId: string,\n testsStatus: z.infer<typeof nestedSweBenchInstanceSchema>['tests_status'],\n): { passedChecks: string[]; failedChecks: string[] } {\n const passedChecks: string[] = []\n const failedChecks: string[] = []\n for (const [category, result] of Object.entries(testsStatus)) {\n passedChecks.push(...result.success.map((name) => `${instanceId}:${category}:${name}`))\n failedChecks.push(...result.failure.map((name) => `${instanceId}:${category}:${name}`))\n }\n return { passedChecks, failedChecks }\n}\n\nfunction assertOutcomeConsistency(\n passed: boolean,\n checks: { passedChecks: readonly string[]; failedChecks: readonly string[] },\n path: string,\n field: string,\n requireFailedCheck = false,\n): void {\n assertDisjointChecks(checks.passedChecks, checks.failedChecks, `${field} in ${path}`)\n if (passed && checks.failedChecks.length > 0) {\n throw malformed(\n path,\n field,\n `cannot be true while failed checks are reported: ${checks.failedChecks.join(', ')}`,\n )\n }\n if (passed && checks.passedChecks.length === 0) {\n throw malformed(path, field, 'cannot be true without at least one passed check')\n }\n if (!passed && requireFailedCheck && checks.failedChecks.length === 0) {\n throw malformed(path, field, 'cannot be false without at least one failed check')\n }\n}\n\nfunction assertCount(count: number, checks: readonly string[], kind: string, path: string): void {\n if (count !== checks.length) {\n throw malformed(\n path,\n 'SWE-Multi',\n `${kind}_count=${count} does not match ${kind}_tests length ${checks.length}`,\n )\n }\n}\n\nfunction assertDisjointChecks(\n left: readonly string[],\n right: readonly string[],\n source: string,\n): void {\n const rightSet = new Set(right)\n const contradictions = [...new Set(left.filter((check) => rightSet.has(check)))].sort()\n if (contradictions.length > 0) {\n throw new Error(\n `${source} marks checks as both passed and failed: ${contradictions.join(', ')}`,\n )\n }\n}\n\nfunction parseSchema<T>(schema: z.ZodType<T>, value: unknown, path: string, format: string): T {\n const parsed = schema.safeParse(value)\n if (parsed.success) return parsed.data\n const details = parsed.error.issues\n .map((issue) => `${issue.path.join('.') || '<root>'}: ${issue.message}`)\n .join('; ')\n throw malformed(path, format, details)\n}\n\nfunction malformed(path: string, format: string, details: string): TypeError {\n return new TypeError(`malformed ${format} verification result: ${path}: ${details}`)\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | null {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : null\n}\n\nfunction status(value: boolean): VerificationOutcomeStatus {\n return value ? 'passed' : 'failed'\n}\n\nfunction unsupported(path: string): TypeError {\n return new TypeError(\n `final verification result has no supported outcome field: ${path}; expected is_resolved, resolved, valid, or a SWE-bench instance report`,\n )\n}\n\nfunction errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n","import { createHash } from 'node:crypto'\nimport { constants, type Stats } from 'node:fs'\nimport { type FileHandle, open, readdir, realpath, stat } from 'node:fs/promises'\nimport { isAbsolute, relative, resolve, sep } from 'node:path'\nimport { TextDecoder } from 'node:util'\nimport { compareCodeUnits } from '../ledger-core/canonical'\nimport type { CodeTraceBenchRow } from './benchmark-datasets'\nimport {\n parseVerificationOutcome,\n type VerificationOutcome,\n} from './benchmark-verification-outcome'\n\nexport const DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES = 8 * 1024 * 1024\n\nexport type VerificationArtifactRole = 'final-test-output' | 'final-result' | 'final-metrics'\n\nexport interface VerificationArtifactFile {\n role: VerificationArtifactRole\n path: string\n relativePath: string\n sha256: string\n bytes: number\n spanId: string\n}\n\nexport interface VerificationArtifactManifest {\n traceId: string\n status: 'present' | 'missing'\n outcome: VerificationOutcome\n outcomeSpanId: string\n caseDirectory: string\n caseDirectoriesSearched: string[]\n totalBytes: number\n maxBytes: number\n files: VerificationArtifactFile[]\n missingRoles: VerificationArtifactRole[]\n searched: Record<VerificationArtifactRole, string[]>\n}\n\nexport interface LoadedVerificationArtifacts {\n manifest: VerificationArtifactManifest\n outcome: VerificationOutcome\n files: Array<VerificationArtifactFile & { content: string }>\n}\n\nconst SEARCHED_ARTIFACTS: Record<VerificationArtifactRole, string[]> = {\n 'final-test-output': ['panes/post-test.txt', 'sessions/tests.log', 'test_output.txt'],\n 'final-result': ['results.json', 'result.json', 'report.json', '*_result.json'],\n 'final-metrics': ['*_metrics.json'],\n}\n\nconst REQUIRED_ROLES = new Set<VerificationArtifactRole>(['final-result'])\n\nconst UTF8 = new TextDecoder('utf-8', { fatal: true })\n\nexport async function loadCodeTraceVerificationArtifacts(options: {\n artifactDir: string\n row: CodeTraceBenchRow\n maxBytes?: number\n}): Promise<LoadedVerificationArtifacts> {\n const maxBytes = positiveInteger(\n options.maxBytes ?? DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES,\n 'max verification artifact bytes',\n )\n const sourceRelativePath = nonEmpty(\n options.row.source_relpath,\n `CodeTraceBench '${options.row.traj_id}' source_relpath`,\n )\n const artifactRoot = await realpath(resolve(options.artifactDir))\n const caseDirectoriesSearched = [\n resolve(artifactRoot, options.row.traj_id, sourceRelativePath),\n resolve(artifactRoot, sourceRelativePath),\n ].filter((path, index, paths) => paths.indexOf(path) === index)\n for (const path of caseDirectoriesSearched) {\n assertContained(artifactRoot, path, sourceRelativePath)\n }\n const existingCaseDirectories = new Set<string>()\n for (const path of caseDirectoriesSearched) {\n try {\n const canonicalPath = await realpath(path)\n assertContained(artifactRoot, canonicalPath, sourceRelativePath)\n const metadata = await stat(canonicalPath)\n if (!metadata.isDirectory()) {\n throw new TypeError(\n `CodeTraceBench '${options.row.traj_id}' artifact case path is not a directory: ${canonicalPath}`,\n )\n }\n existingCaseDirectories.add(canonicalPath)\n } catch (error) {\n if (!isMissing(error)) throw error\n }\n }\n if (existingCaseDirectories.size === 0) {\n return missingArtifacts(\n options.row.traj_id,\n caseDirectoriesSearched[0]!,\n caseDirectoriesSearched,\n maxBytes,\n )\n }\n if (existingCaseDirectories.size > 1) {\n throw new Error(\n `CodeTraceBench '${options.row.traj_id}' artifact directory is ambiguous: ${[...existingCaseDirectories].join(', ')}`,\n )\n }\n const [caseDirectory] = existingCaseDirectories\n\n const candidates = await artifactCandidates(caseDirectory!)\n const files: LoadedVerificationArtifacts['files'] = []\n let totalBytes = 0\n for (const candidate of candidates) {\n const snapshot = await readArtifactSnapshot({\n artifactRoot,\n candidatePath: candidate.path,\n relativePath: candidate.relativePath,\n traceId: options.row.traj_id,\n totalBytes,\n maxBytes,\n })\n const { bytes, canonicalPath } = snapshot\n totalBytes += bytes.byteLength\n let content: string\n try {\n content = UTF8.decode(bytes)\n } catch {\n throw new TypeError(\n `CodeTraceBench '${options.row.traj_id}' verification artifact is not UTF-8 text: ${canonicalPath}`,\n )\n }\n if (!content.trim()) {\n throw new Error(\n `CodeTraceBench '${options.row.traj_id}' verification artifact is empty: ${canonicalPath}`,\n )\n }\n const relativePath = candidate.relativePath\n files.push({\n role: candidate.role,\n path: canonicalPath,\n relativePath,\n sha256: sha256Digest(bytes),\n bytes: bytes.byteLength,\n spanId: verificationSpanId(candidate.role, relativePath),\n content,\n })\n }\n\n const roles = new Set(files.map((file) => file.role))\n const missingRoles = (Object.keys(SEARCHED_ARTIFACTS) as VerificationArtifactRole[]).filter(\n (role) => !roles.has(role),\n )\n const hasFinalVerification = [...REQUIRED_ROLES].every((role) => roles.has(role))\n const outcome = hasFinalVerification\n ? loadVerificationOutcome(\n files\n .filter((file) => file.role === 'final-result')\n .map((file) => ({ relativePath: file.relativePath, content: file.content })),\n options.row,\n )\n : unavailableOutcome('missing-result')\n const outcomeSpanId = verificationOutcomeSpanId(options.row.traj_id, outcome)\n return {\n manifest: {\n traceId: options.row.traj_id,\n status: hasFinalVerification ? 'present' : 'missing',\n outcome,\n outcomeSpanId,\n caseDirectory: caseDirectory!,\n caseDirectoriesSearched,\n totalBytes,\n maxBytes,\n files: files.map(({ content: _content, ...file }) => file),\n missingRoles,\n searched: searchedArtifacts(),\n },\n outcome,\n files,\n }\n}\n\nexport function appendVerificationArtifactsToOtlp(\n otlpText: string,\n traceId: string,\n artifacts: LoadedVerificationArtifacts,\n afterTimestamp: string,\n): string {\n if (!otlpText.trim()) throw new Error(`trace '${traceId}' OTLP input is empty`)\n if (artifacts.manifest.traceId !== traceId) {\n throw new Error(\n `verification artifacts for trace '${artifacts.manifest.traceId}' cannot be attached to '${traceId}'`,\n )\n }\n if (!artifacts.outcome || !artifacts.manifest.outcomeSpanId) {\n throw new Error(`trace '${traceId}' has no final verification artifacts to attach`)\n }\n const afterMs = Date.parse(afterTimestamp)\n if (!Number.isFinite(afterMs)) {\n throw new TypeError(`trace '${traceId}' latest timestamp is invalid: ${afterTimestamp}`)\n }\n const outcome = artifacts.outcome\n const outcomeLine = JSON.stringify({\n trace_id: traceId,\n span_id: artifacts.manifest.outcomeSpanId,\n parent_span_id: null,\n name: `final verification outcome: ${outcome.status}`,\n start_time: timestampAfter(afterMs, 1, traceId),\n end_time: timestampAfter(afterMs, 2, traceId),\n status: {\n code:\n outcome.status === 'passed'\n ? 'STATUS_CODE_OK'\n : outcome.status === 'failed'\n ? 'STATUS_CODE_ERROR'\n : 'STATUS_CODE_UNSET',\n },\n resource: {\n attributes: {\n 'service.name': 'agent-eval-public-benchmark',\n },\n },\n attributes: {\n 'openinference.span.kind': 'EVALUATOR',\n 'benchmark.evidence.role': 'final-verification',\n 'benchmark.verification.outcome': outcome.status,\n 'benchmark.verification.passed_check_count': outcome.passedCheckCount,\n 'benchmark.verification.failed_check_count': outcome.failedCheckCount,\n 'benchmark.verification.passed_checks': JSON.stringify(outcome.passedChecks),\n 'benchmark.verification.failed_checks': JSON.stringify(outcome.failedChecks),\n 'benchmark.verification.sources': JSON.stringify(outcome.sources),\n ...(outcome.reason ? { 'benchmark.verification.reason': outcome.reason } : {}),\n ...(outcome.parseError\n ? { 'benchmark.verification.parse_error': JSON.stringify(outcome.parseError) }\n : {}),\n },\n })\n const artifactLines = artifacts.files\n .filter((artifact) => artifact.role === 'final-test-output')\n .map((artifact, index) =>\n JSON.stringify({\n trace_id: traceId,\n span_id: artifact.spanId,\n parent_span_id: null,\n name: `final verification artifact: ${artifact.relativePath}`,\n start_time: timestampAfter(afterMs, index * 2 + 3, traceId),\n end_time: timestampAfter(afterMs, index * 2 + 4, traceId),\n status: { code: 'STATUS_CODE_UNSET' },\n resource: {\n attributes: {\n 'service.name': 'agent-eval-public-benchmark',\n },\n },\n attributes: {\n 'openinference.span.kind': 'EVALUATOR',\n 'benchmark.evidence.role': 'final-verification-artifact',\n 'benchmark.verification.outcome': outcome.status,\n 'artifact.role': artifact.role,\n 'artifact.path': artifact.relativePath,\n 'artifact.sha256': artifact.sha256,\n 'artifact.bytes': artifact.bytes,\n 'artifact.content': artifact.content,\n },\n }),\n )\n return `${otlpText.trimEnd()}\\n${[outcomeLine, ...artifactLines].join('\\n')}\\n`\n}\n\nfunction timestampAfter(afterMs: number, offsetMs: number, traceId: string): string {\n const date = new Date(afterMs + offsetMs)\n if (!Number.isFinite(date.getTime())) {\n throw new RangeError(`trace '${traceId}' cannot place final verification after its latest span`)\n }\n return date.toISOString()\n}\n\nexport function sha256Digest(value: string | NodeJS.ArrayBufferView): string {\n return createHash('sha256').update(value).digest('hex')\n}\n\nasync function readArtifactSnapshot(options: {\n artifactRoot: string\n candidatePath: string\n relativePath: string\n traceId: string\n totalBytes: number\n maxBytes: number\n}): Promise<{ canonicalPath: string; bytes: Buffer }> {\n const safeOpenFlags =\n constants.O_RDONLY |\n (process.platform === 'win32' ? 0 : constants.O_NOFOLLOW | constants.O_NONBLOCK)\n let handle: FileHandle\n try {\n handle = await open(options.candidatePath, safeOpenFlags)\n } catch (error) {\n if (isNodeError(error, 'ELOOP')) {\n throw new Error(\n `CodeTraceBench '${options.traceId}' verification artifact must not be a symbolic link: ${options.relativePath}`,\n )\n }\n throw error\n }\n\n try {\n const before = await handle.stat()\n if (!before.isFile()) {\n throw new TypeError(\n `CodeTraceBench '${options.traceId}' verification artifact is not a regular file: ${options.relativePath}`,\n )\n }\n const bytes = checkedFileSize(before.size, options)\n const descriptorPath = await openedDescriptorPath(handle.fd)\n if (descriptorPath !== null) {\n assertContained(options.artifactRoot, descriptorPath, options.relativePath)\n }\n\n const canonicalPath = await realpath(options.candidatePath)\n assertContained(options.artifactRoot, canonicalPath, options.relativePath)\n const current = await stat(canonicalPath)\n if (!sameFile(before, current)) {\n throw changedArtifact(options.traceId, options.relativePath)\n }\n\n const content = Buffer.allocUnsafe(bytes)\n let offset = 0\n while (offset < content.byteLength) {\n const { bytesRead } = await handle.read(content, offset, content.byteLength - offset, offset)\n if (bytesRead === 0) break\n offset += bytesRead\n }\n const eofProbe = Buffer.allocUnsafe(1)\n const { bytesRead: trailingBytes } = await handle.read(\n eofProbe,\n 0,\n eofProbe.byteLength,\n content.byteLength,\n )\n const after = await handle.stat()\n if (offset !== content.byteLength || trailingBytes !== 0 || !sameSnapshot(before, after)) {\n throw changedArtifact(options.traceId, options.relativePath)\n }\n return { canonicalPath, bytes: content }\n } finally {\n await handle.close()\n }\n}\n\nfunction checkedFileSize(\n bytes: number,\n options: {\n traceId: string\n relativePath: string\n totalBytes: number\n maxBytes: number\n },\n): number {\n if (!Number.isSafeInteger(bytes) || bytes < 0) {\n throw new RangeError(\n `CodeTraceBench '${options.traceId}' verification artifact has an invalid byte size: ${options.relativePath}`,\n )\n }\n if (bytes > options.maxBytes) {\n throw new RangeError(\n `CodeTraceBench '${options.traceId}' verification artifact '${options.relativePath}' requires ${bytes} bytes, over the ${options.maxBytes}-byte per-file limit`,\n )\n }\n if (options.totalBytes > options.maxBytes - bytes) {\n throw new RangeError(\n `CodeTraceBench '${options.traceId}' verification artifacts require ${options.totalBytes + bytes} bytes, over the ${options.maxBytes}-byte cumulative limit`,\n )\n }\n return bytes\n}\n\nasync function openedDescriptorPath(fileDescriptor: number): Promise<string | null> {\n if (process.platform !== 'linux') return null\n try {\n return await realpath(`/proc/self/fd/${fileDescriptor}`)\n } catch (error) {\n if (\n isNodeError(error, 'ENOENT') ||\n isNodeError(error, 'ENOTDIR') ||\n isNodeError(error, 'EACCES')\n ) {\n return null\n }\n throw error\n }\n}\n\nfunction sameFile(left: Stats, right: Stats): boolean {\n return (\n left.isFile() &&\n right.isFile() &&\n left.dev === right.dev &&\n left.ino === right.ino &&\n left.size === right.size\n )\n}\n\nfunction sameSnapshot(left: Stats, right: Stats): boolean {\n return (\n sameFile(left, right) &&\n left.mode === right.mode &&\n left.mtimeMs === right.mtimeMs &&\n left.ctimeMs === right.ctimeMs\n )\n}\n\nfunction changedArtifact(traceId: string, relativePath: string): Error {\n return new Error(\n `CodeTraceBench '${traceId}' verification artifact changed while being read: ${relativePath}`,\n )\n}\n\nasync function artifactCandidates(\n caseDirectory: string,\n): Promise<Array<{ role: VerificationArtifactRole; path: string; relativePath: string }>> {\n const entries = await readdir(caseDirectory, { withFileTypes: true })\n const rootFiles = entries\n .filter((entry) => entry.isFile() || entry.isSymbolicLink())\n .map((entry) => entry.name)\n const testOutput = await firstExisting(caseDirectory, SEARCHED_ARTIFACTS['final-test-output'])\n const finalResults = [\n ...SEARCHED_ARTIFACTS['final-result']\n .filter((name) => !name.includes('*'))\n .map((name) => resolve(caseDirectory, name)),\n ...rootFiles\n .filter((name) => name.endsWith('_result.json'))\n .map((name) => resolve(caseDirectory, name)),\n ]\n const finalMetrics = rootFiles\n .filter((name) => name.endsWith('_metrics.json'))\n .map((name) => resolve(caseDirectory, name))\n\n const candidates = [\n ...testOutput.map((path) => candidate('final-test-output', caseDirectory, path)),\n ...(await existing(finalResults)).map((path) => candidate('final-result', caseDirectory, path)),\n ...(await existing(finalMetrics)).map((path) =>\n candidate('final-metrics', caseDirectory, path),\n ),\n ]\n const seen = new Set<string>()\n return candidates\n .filter((entry) => {\n if (seen.has(entry.path)) return false\n seen.add(entry.path)\n return true\n })\n .sort(\n (left, right) =>\n artifactRoleOrder(left.role) - artifactRoleOrder(right.role) ||\n compareCodeUnits(left.relativePath, right.relativePath),\n )\n}\n\nasync function firstExisting(\n caseDirectory: string,\n candidates: readonly string[],\n): Promise<string[]> {\n for (const relativePath of candidates) {\n const path = resolve(caseDirectory, relativePath)\n if (await isFile(path)) return [path]\n }\n return []\n}\n\nasync function existing(paths: readonly string[]): Promise<string[]> {\n const out: string[] = []\n for (const path of paths) {\n if (await isFile(path)) out.push(path)\n }\n return out\n}\n\nasync function isFile(path: string): Promise<boolean> {\n try {\n return (await stat(path)).isFile()\n } catch (error) {\n if (isMissing(error)) return false\n throw error\n }\n}\n\nfunction candidate(\n role: VerificationArtifactRole,\n caseDirectory: string,\n path: string,\n): { role: VerificationArtifactRole; path: string; relativePath: string } {\n return { role, path, relativePath: slashRelative(caseDirectory, path) }\n}\n\nfunction missingArtifacts(\n traceId: string,\n caseDirectory: string,\n caseDirectoriesSearched: string[],\n maxBytes: number,\n): LoadedVerificationArtifacts {\n const outcome = unavailableOutcome('missing-result')\n return {\n manifest: {\n traceId,\n status: 'missing',\n outcome,\n outcomeSpanId: verificationOutcomeSpanId(traceId, outcome),\n caseDirectory,\n caseDirectoriesSearched,\n totalBytes: 0,\n maxBytes,\n files: [],\n missingRoles: Object.keys(SEARCHED_ARTIFACTS) as VerificationArtifactRole[],\n searched: searchedArtifacts(),\n },\n outcome,\n files: [],\n }\n}\n\nfunction verificationOutcomeSpanId(traceId: string, outcome: VerificationOutcome): string {\n return `benchmark-verification-outcome-${sha256Digest(\n `${traceId}\\u0000${JSON.stringify(outcome.sources)}\\u0000${outcome.status}`,\n ).slice(0, 16)}`\n}\n\nfunction unavailableOutcome(\n reason: NonNullable<VerificationOutcome['reason']>,\n): VerificationOutcome {\n return {\n status: 'unavailable',\n reason,\n sources: [],\n passedCheckCount: 0,\n failedCheckCount: 0,\n passedChecks: [],\n failedChecks: [],\n }\n}\n\nfunction loadVerificationOutcome(\n files: Parameters<typeof parseVerificationOutcome>[0],\n row: CodeTraceBenchRow,\n): VerificationOutcome {\n try {\n const outcome = parseVerificationOutcome(files)\n if (outcome.status === 'unavailable' || typeof row.solved !== 'boolean') {\n return outcome\n }\n const labelStatus = row.solved ? 'passed' : 'failed'\n if (outcome.status === labelStatus) {\n return outcome\n }\n return {\n ...outcome,\n status: 'unavailable',\n reason: 'result-label-disagreement',\n parseError: {\n class: 'ResultLabelDisagreementError',\n message: `CodeTraceBench '${row.traj_id}' solved=${row.solved} disagrees with parsed final verification status '${outcome.status}' from ${outcome.sources\n .map((source) => `${source.path}=${source.status}`)\n .join(', ')}`,\n },\n }\n } catch (error) {\n return {\n ...unavailableOutcome('result-parse-error'),\n parseError: {\n class: error instanceof Error ? error.constructor.name : 'Error',\n message: error instanceof Error ? error.message : String(error),\n },\n }\n }\n}\n\nfunction verificationSpanId(role: VerificationArtifactRole, relativePath: string): string {\n return `benchmark-verification-${sha256Digest(`${role}\\u0000${relativePath}`).slice(0, 16)}`\n}\n\nfunction artifactRoleOrder(role: VerificationArtifactRole): number {\n return role === 'final-test-output' ? 0 : role === 'final-result' ? 1 : 2\n}\n\nfunction assertContained(root: string, candidate: string, source: string): void {\n const rel = relative(root, candidate)\n if (isAbsolute(rel) || rel === '..' || rel.startsWith(`..${sep}`)) {\n throw new Error(`verification artifact path escapes --artifact-dir: ${source}`)\n }\n}\n\nfunction searchedArtifacts(): Record<VerificationArtifactRole, string[]> {\n return {\n 'final-test-output': [...SEARCHED_ARTIFACTS['final-test-output']],\n 'final-result': [...SEARCHED_ARTIFACTS['final-result']],\n 'final-metrics': [...SEARCHED_ARTIFACTS['final-metrics']],\n }\n}\n\nfunction slashRelative(root: string, path: string): string {\n return relative(root, path).split(sep).join('/')\n}\n\nfunction nonEmpty(value: unknown, field: string): string {\n if (typeof value !== 'string' || !value.trim()) {\n throw new TypeError(`${field} must be a non-empty string`)\n }\n return value.trim()\n}\n\nfunction positiveInteger(value: number, field: string): number {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new RangeError(`${field} must be a positive safe integer`)\n }\n return value\n}\n\nfunction isMissing(error: unknown): boolean {\n return isNodeError(error, 'ENOENT')\n}\n\nfunction isNodeError(error: unknown, code: string): error is NodeJS.ErrnoException {\n return error instanceof Error && 'code' in error && error.code === code\n}\n","import { MAX_ASSISTANT_STEP_EVIDENCE_EXCERPT_CHARACTERS } from './benchmark-evidence-validation'\nimport type { PublicAnalystBenchmarkDataset } from './benchmark-public-types'\nimport { sha256Digest } from './benchmark-verification-artifacts'\n\n/** Widest contiguous failure block a model may report. The published corpus's\n * widest labeled block is 8 steps and its widest stage span is 9, so this bound\n * never binds honest enumeration; it caps how far one over-wide block can push\n * unlabeled steps into the precision denominator. */\nexport const MAX_INCORRECT_BLOCK_STEPS = 12\n\n/** Most blocks a model may report for one trajectory. The published corpus's\n * densest case carries 4 disjoint labeled blocks. Together with the per-block\n * cap this bounds one case at 192 predicted steps without a second ceiling. */\nexport const MAX_INCORRECT_BLOCKS = 16\n\nexport const TRACE_PROJECTION_ATTRIBUTE_BYTE_CAPS = [\n 4_096, 2_048, 1_024, 512, 256, 128, 64,\n] as const\n\nexport const CODE_TRACE_BENCH_ANALYST_PROMPT = `Analyze exactly one coding-agent trajectory and its attached final verification.\nYour task is the CodeTraceBench incorrect-step task: identify every incorrect step, defined as a wrong state-changing intervention given the evidence — a mislocalized edit, a wrong hypothesis that drives an action, a regression, an irrelevant change, or an incorrect dependency or configuration choice.\nIf the final verification failed, the trajectory MUST contain at least one incorrect step. Never return an empty findings array on a failing trajectory; trace backward until you find the root cause.\nWork backward, the way this benchmark was annotated, never by scanning forward for suspicious steps: start from the final verification outcome or the latest observed failure evidence, identify the immediately preceding step whose action or output produced that observed error, then recursively ask which earlier decision led to each intermediate failure, until the preceding steps contain no error or the cause is unrelated to the trajectory's own decisions.\nEach backward chain terminates at an error-critical step — the earliest decision that triggered the downstream cascade — and that step is the block's first_step: the step that committed the mistake, not the step that planned it and not a later step that repeats it.\nA block is a maximal contiguous sequence of strictly incorrect steps. A step belongs in the block ONLY if it introduces, propagates, or compounds the error. \nDo NOT include steps that merely \"act on\", diagnose, or react to the error. A diagnostic command, a test run exposing the bug, or a correct exploratory read is a CORRECT step. \nIf an incorrect step is followed by a correct diagnostic step and then another incorrect step, you MUST emit two separate blocks. NEVER bridge correct steps by grouping them into a single block with incorrect steps. Over-blocking drastically hurts your precision.\nAfter identifying first_step, extend last_step forward ONLY through consecutive steps that independently introduce, propagate, or compound the mistake. A cascade of repeated failed attempts at the same wrong approach is one maximal block, provided EVERY step is independently incorrect.\nDo not end a block merely because the agent tried a variation of the same wrong approach; a variation that still carries the error stays inside the block.\nA partially correct or ambiguous fix still counts as incorrect; the block ends only at the first step free of the error — a clean diagnostic read, the corrective action that closes the issue and needs no further rework, or a genuine abandonment of the wrong approach.\nBlock extent follows the traced chain and this forward extension, nothing else.\nReport each failure block as exactly one finding whose first_step is the block's first incorrect step and whose last_step is its last, covering every consecutive step between them.\nEvery step inside a block is scored on its own: naming a correct step costs exactly as much as missing an incorrect one, and naming only the first step of a longer block forfeits every unnamed step. Because of this, carefully verify every step between first_step and last_step. Only include steps that introduce, propagate, or compound the error.\nReport blocks separated by at least one correct step as separate findings, and never let two blocks overlap. If there are multiple separate failure cascades, emit a separate finding for each one.\nPrefer anchored blocks: a block whose chain traces back from observed failure evidence — a failing command or verification, an error observation, a regression, or, on a solved trajectory, a later step that reverts or supersedes it — outranks one without.\nWhen an action is clearly wrong on its own evidence but you cannot trace such an anchor, report the block anyway with proportionally lower confidence.\nA solved trajectory still carries every mistake made along the way: inspect its final patching and verification stages for a state-changing action that a later step reverted, superseded, or corrected — a wrong edit just before the final fix is incorrect even when every test ends green.\nBefore emitting a candidate block, check its boundaries.\nNeighbor check: ask whether the accusation fits one step earlier (the decision rather than its consequence) or one step later (the next step still acts on or reworks the same error) better than where you placed it, and move the boundary when it does; a boundary off by one step scores zero at that step.\nCompleteness check: a block must cover the maximal contiguous sequence of incorrect steps. If an agent fails at step 10, tries to fix it at 11, fails, and tries again at 12 and 13, all four steps are incorrect and must be included in the block. Never truncate a cascade. If you miss the later steps of a cascade, your recall drops to zero for them.\nCounterfactual check: ask which step's correct execution would have made the downstream failure or rework disappear, and move first_step onto that step; use this check only to move a boundary, never to delete a block.\nWidth check: inspect the step immediately before first_step and the step immediately after last_step; when either neighbor commits to, compounds, or propagates the same mistake, it belongs inside the block — move that boundary outward and repeat until both neighbors are free of the error.\nFor each block you keep, name as consequence_step the step number whose action or observation shows the damage — a failing command, a wrong file state, a repeated failure, or rework the agent had to do because of this block; that step is the block's own last step when its observation already shows the damage, and a later step otherwise.\nWhen you cannot name that step number from the trace you were given, drop the block; a plausible story about why a step looks wrong is not evidence that it was.\nA passing final verification is not evidence that a block caused nothing, and a failing final verification is not evidence that any particular block caused it.\nFor every block, decide whether the agent escaped the failure.\nMark escape_status \"escaped\" only when you can name the single later step that fully reversed the block, the agent needed no other step to recover, and nothing after that step revisits the same file, command, or hypothesis; write that step number in the rationale. If the agent required multiple steps to fix the issue, or if you are unsure, it is not escaped.\nMark escape_status \"unescaped\" in every other case, including whenever you are unsure.\nA passing final verification never makes a block escaped.\nDo not label a diagnostic probe or test run merely because its output exposes an earlier defect.\nDo not label a redundant but correct read or search; CodeTraceBench scores unuseful steps separately, and this run scores incorrect steps only. Never include a correct step in a block just to bridge two incorrect steps; instead, emit two separate blocks.\nDo not label a step solely because final verification failed.\nWhen final verification is unavailable, trace backward from the latest failure evidence inside the trajectory itself.\nEvery step in a reported block MUST be the positive integer n from an existing assistant LLM span named step-<n>.\nNever select an EVALUATOR, TOOL, CHAIN, final-verification, benchmark-verification, or message-<n> span.\nBefore emitting a finding, inspect every covered span's attributes.content and describe only the actions shown there.\nReport at most 16 blocks and at most 12 steps in one block; when more candidates than that exist, report the ones whose chains carry the clearest downstream evidence.\nWhen the trajectory has no incorrect steps — its final verification passed and the final-stage sweep found no reverted, superseded, or corrected action — return an empty findings array.`\n\nconst AGENT_RX_PROMPT = `Analyze exactly one failed agent trajectory.\nFind the first unrecoverable critical failure, not every later symptom.\nInspect the complete supplied trace data.\nEmit zero findings only when the trace does not contain enough evidence.\nOtherwise emit exactly one finding.\nIts category MUST be exactly one of:\ninstruction-plan-adherence-failure\ninvention-of-new-information\ninvalid-invocation\nmisinterpretation-of-tool-output-handoff-failure\nintent-plan-misalignment\nunderspecified-user-intent\nintent-not-supported\nguardrails-triggered\nsystem-failure\ninconclusive\nIts step is the positive integer n from the first unrecoverable assistant span named step-<n>.`\n\nconst AGENT_RX_JSON_CONTRACT = `Each finding must contain only:\n- \"step\": a positive integer matching an existing assistant LLM span named step-<n>\n- \"severity\": \"critical\", \"high\", \"medium\", \"low\", or \"info\"\n- \"claim\": one sentence\n- \"confidence\": a number from 0 through 1\n- optional \"rationale\" and \"recommended_action\" strings\n- \"category\": one allowed failure category listed above`\n\nconst CODE_TRACE_JSON_CONTRACT = `Each finding is one contiguous failure block and must contain only:\n- \"first_step\": a positive integer, the block's first incorrect step, matching an existing assistant LLM span named step-<n>\n- \"last_step\": a positive integer >= first_step, the block's last incorrect step; every step from first_step through last_step must be an existing assistant LLM span, and a block spans at most ${MAX_INCORRECT_BLOCK_STEPS} steps\n- \"consequence_step\": a positive integer >= first_step, the step whose action or following observation shows the damage this block caused; it may sit inside the block when the damage is already visible there\n- \"escape_status\": \"escaped\" only when one single later step fully reversed the block and nothing afterwards revisits it, \"unescaped\" otherwise and whenever you are unsure\n- \"severity\": \"critical\", \"high\", \"medium\", \"low\", or \"info\"\n- \"claim\": one sentence describing the block's failure\n- \"confidence\": a number from 0 through 1\n- optional \"rationale\" and \"recommended_action\" strings`\n\nconst AGENT_RX_RLM_CONTRACT = `Use the trace tools to inspect the action and its following observation.\nEmit exactly one finding whose subject is exactly one of the allowed failure categories.\nCite exactly one assistant span named step-<n> as trace://<URL-encoded-trace-id>/span/step-<n>.\nThe excerpt must quote the assistant action exactly.`\n\nconst CODE_TRACE_RLM_CONTRACT = `Use the trace tools rather than asking for the whole trajectory in the prompt.\nKeep retrieved trace objects in Python variables.\nNever print an entire trace, full source file, or more than 12000 characters in one iteration.\nRead the final verification and the latest failure evidence first, then build a compact table of assistant step ids, actions, and following observations.\nTrace backward from that evidence with viewSpans or searchSpan, confirming each candidate step's own action content, instead of repeatedly printing the table.\nThis runner emits no JSON fields, so the block is encoded in the finding's subject.\nOnly findings_json is scored; your prose answer is ignored, so every incorrect block you identify must appear as a finding, never only in the answer.\nEmit exactly one finding per contiguous failure block.\nSet the finding's subject to incorrect-steps-<first_step>-<last_step>-<escape_status>-consequence-<consequence_step>, using the same four values the task defines; for a block covering only step 7 that the agent never escaped and whose damage shows at step 9, the subject is incorrect-steps-7-7-unescaped-consequence-9.\nThe runner expands the block to one scored step per member and builds every scored citation itself.\nCite the block's first step and its last step as trace://<URL-encoded-trace-id>/span/step-<n>, each excerpt an exact quote from that step's own action content.\nGive the rationale as the concrete downstream evidence visible at the consequence step.\nSubmit as soon as every candidate failure block has a supported verdict.\nReturn no finding for a clean trajectory.`\n\n/** Reply-envelope contract shared by both one-shot datasets. */\nexport const PUBLIC_BENCHMARK_ENVELOPE_CONTRACT = `Return exactly one JSON object with:\n- \"report\": a concise evidence-based explanation, at most 4000 characters\n- \"findings\": the strict finding array\nUse an empty findings array when the trace does not support a finding.\nDo not return a bare array, markdown, trace URIs, copied excerpts, or fields not listed above.\nThe runner constructs exact trace URIs and action previews from each selected step.`\n\n/** Per-dataset field grammar for the one-shot JSON reply. */\nexport function publicBenchmarkFieldContract(dataset: PublicAnalystBenchmarkDataset): string {\n return dataset === 'agentrx' ? AGENT_RX_JSON_CONTRACT : CODE_TRACE_JSON_CONTRACT\n}\n\n/** One-shot JSON transport prompt for the direct runner. */\nexport function publicBenchmarkSystemPrompt(dataset: PublicAnalystBenchmarkDataset): string {\n return [\n publicBenchmarkTaskPrompt(dataset),\n publicBenchmarkFieldContract(dataset),\n PUBLIC_BENCHMARK_ENVELOPE_CONTRACT,\n ].join('\\n\\n')\n}\n\n/** Tool-loop prompt for the recursive runner. Same task, subject-encoded block. */\nexport function publicBenchmarkRlmInstructions(dataset: PublicAnalystBenchmarkDataset): string {\n const outputContract = dataset === 'agentrx' ? AGENT_RX_RLM_CONTRACT : CODE_TRACE_RLM_CONTRACT\n return `${publicBenchmarkTaskPrompt(dataset)}\n${outputContract}`\n}\n\n/** Task text shared by every runner shape on one dataset. */\nexport function publicBenchmarkTaskPrompt(dataset: PublicAnalystBenchmarkDataset): string {\n return dataset === 'agentrx' ? AGENT_RX_PROMPT : CODE_TRACE_BENCH_ANALYST_PROMPT\n}\n\n/** Digest of every prompt a runner can send plus the shared transport limits.\n * Both runner contracts are hashed so an edit to either one changes the digest\n * a run records, whichever runner executed. */\nexport function publicBenchmarkProtocolSha256(dataset: PublicAnalystBenchmarkDataset): string {\n return sha256Digest(\n JSON.stringify({\n dataset,\n systemPrompt: publicBenchmarkSystemPrompt(dataset),\n rlmInstructions: publicBenchmarkRlmInstructions(dataset),\n transport: {\n attempts: 1,\n jsonMode: true,\n thinking: 'disabled',\n },\n blockLimits:\n dataset === 'agentrx'\n ? null\n : {\n maxBlocks: MAX_INCORRECT_BLOCKS,\n maxBlockSteps: MAX_INCORRECT_BLOCK_STEPS,\n },\n traceProjectionAttributeByteCaps: TRACE_PROJECTION_ATTRIBUTE_BYTE_CAPS,\n evidence: {\n location: 'model-selected-positive-integer-assistant-step',\n uri: 'deterministic-trace-uri',\n excerpt: `exact-action-prefix-${MAX_ASSISTANT_STEP_EVIDENCE_EXCERPT_CHARACTERS}`,\n },\n }),\n )\n}\n","import { readFileSync } from 'node:fs'\nimport { publicBenchmarkProtocolSha256 } from './benchmark-public-prompt'\nimport type {\n AnalystInstructionsOverride,\n PublicAnalystBenchmarkDataset,\n} from './benchmark-public-types'\nimport { sha256Digest } from './benchmark-verification-artifacts'\n\n/** Build an override from instruction text. Blank text is a caller error. */\nexport function analystInstructionsOverrideFromText(text: string): AnalystInstructionsOverride {\n if (typeof text !== 'string' || !text.trim()) {\n throw new Error('analyst instructions override must contain non-empty instruction text')\n }\n return { text, sha256: sha256Digest(text) }\n}\n\n/** Read override instructions from a file. Any read failure is fatal. */\nexport function readAnalystInstructionsOverride(path: string): AnalystInstructionsOverride {\n let text: string\n try {\n text = readFileSync(path, 'utf8')\n } catch (error) {\n throw new Error(\n `cannot read --instructions-file '${path}': ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n if (!text.trim()) {\n throw new Error(`--instructions-file '${path}' is empty; refusing to run without instructions`)\n }\n return analystInstructionsOverrideFromText(text)\n}\n\n/**\n * Protocol digest of the run as executed.\n *\n * Without an override this is exactly `publicBenchmarkProtocolSha256(dataset)`,\n * so stock runs stay byte-identical to runs recorded before the override\n * existed. With an override the digest binds the stock protocol digest (which\n * covers both shipped prompts, including the abstention fallback's direct\n * prompt) to the exact override text, so the recorded digest always hashes the\n * instructions that actually ran.\n */\nexport function effectiveAnalystProtocolSha256(\n dataset: PublicAnalystBenchmarkDataset,\n override?: Pick<AnalystInstructionsOverride, 'sha256'>,\n): string {\n const stock = publicBenchmarkProtocolSha256(dataset)\n if (!override) return stock\n return sha256Digest(\n JSON.stringify({\n kind: 'analyst-instructions-override-protocol',\n dataset,\n stockProtocolSha256: stock,\n rlmInstructionsSha256: override.sha256,\n }),\n )\n}\n","import { randomUUID } from 'node:crypto'\nimport { constants } from 'node:fs'\nimport { link, lstat, mkdir, open, readFile, unlink } from 'node:fs/promises'\nimport { arch, platform } from 'node:os'\nimport { dirname, resolve } from 'node:path'\nimport { resolveExternalOptimizerProcessLimits } from '../campaign/external-optimizer-contracts'\nimport { resolveModelPricing } from '../metrics'\nimport type { AnalystBenchmarkObservation } from './benchmark'\nimport {\n ANALYST_BENCHMARK_COST_LEDGER_FILE,\n ANALYST_BENCHMARK_LOCAL_RECEIPT_FILE,\n ANALYST_BENCHMARK_MANIFEST_FILE,\n ANALYST_BENCHMARK_OBSERVATIONS_FILE,\n type AnalystBenchmarkLocalRunReceipt,\n type AnalystBenchmarkProgressRow,\n type AnalystBenchmarkRunIdentity,\n type AnalystBenchmarkRunManifest,\n assertAnalystBenchmarkObservation,\n assertExactKeys,\n canonicalJson,\n digestCanonical,\n isRecord,\n isSha256,\n observationKey,\n parseJson,\n} from './benchmark-command-artifact'\nimport {\n ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256,\n ANALYST_BENCHMARK_IMPLEMENTATION_SHA256,\n} from './benchmark-implementation'\nimport { effectiveAnalystProtocolSha256 } from './benchmark-instructions-override'\nimport type {\n PreparedPublicAnalystBenchmark,\n PublicAnalystBenchmarkDataset,\n PublicAnalystBenchmarkModelSettings,\n} from './benchmark-real-model'\n\nexport interface AnalystBenchmarkOutputPaths {\n directory: string\n initializationComplete: string\n manifest: string\n observations: string\n costLedger: string\n modelResponses: string\n localReceipt: string\n result: string\n report: string\n}\n\nexport const ANALYST_BENCHMARK_INITIALIZATION_COMPLETE_FILE = 'initialization-complete.json'\n\nexport interface AnalystBenchmarkProgress {\n observations: AnalystBenchmarkObservation[]\n nextSequence: number\n previousRowSha256: string | null\n}\n\ninterface AnalystBenchmarkPersistenceConfig {\n dataset: PublicAnalystBenchmarkDataset\n analyst: string\n labelsPath: string\n traceDir: string\n artifactDir?: string\n revision: string\n split: string\n model: PublicAnalystBenchmarkModelSettings\n limit: number\n seed: number\n concurrency: number\n repetitions: number\n rlmSamples: number\n maxCostUsd: number\n maxArtifactBytes: number\n /** Absent when the analyst owns its own transport (`prime`). */\n modelOwnerModule?: string\n command: string\n}\n\nexport async function openOutputDirectory(\n outDir: string,\n resume: boolean,\n): Promise<AnalystBenchmarkOutputPaths> {\n const directory = resolve(outDir)\n if (resume) {\n let outputStat: Awaited<ReturnType<typeof lstat>>\n try {\n outputStat = await lstat(directory)\n } catch (error) {\n if (isNodeError(error, 'ENOENT')) {\n throw new Error(`cannot resume missing benchmark output directory: ${directory}`)\n }\n throw error\n }\n if (!outputStat.isDirectory() || outputStat.isSymbolicLink()) {\n throw new Error(`benchmark output must be a real directory: ${directory}`)\n }\n } else {\n await mkdir(dirname(directory), { recursive: true })\n try {\n await mkdir(directory)\n } catch (error) {\n if (isNodeError(error, 'EEXIST')) {\n throw new Error(`refusing to use existing benchmark output directory: ${directory}`)\n }\n throw error\n }\n await syncDirectory(dirname(directory))\n }\n return {\n directory,\n initializationComplete: resolve(directory, ANALYST_BENCHMARK_INITIALIZATION_COMPLETE_FILE),\n manifest: resolve(directory, ANALYST_BENCHMARK_MANIFEST_FILE),\n observations: resolve(directory, ANALYST_BENCHMARK_OBSERVATIONS_FILE),\n costLedger: resolve(directory, ANALYST_BENCHMARK_COST_LEDGER_FILE),\n modelResponses: resolve(directory, 'model-responses'),\n localReceipt: resolve(directory, ANALYST_BENCHMARK_LOCAL_RECEIPT_FILE),\n result: resolve(directory, 'result.json'),\n report: resolve(directory, 'report.md'),\n }\n}\n\nexport async function prepareOutputLockPath(outDir: string): Promise<string> {\n const directory = resolve(outDir)\n await mkdir(dirname(directory), { recursive: true })\n return `${directory}.lock`\n}\n\nexport function createRunIdentity(\n config: AnalystBenchmarkPersistenceConfig,\n prepared: PreparedPublicAnalystBenchmark,\n): AnalystBenchmarkRunIdentity {\n const model = commandModelIdentity(config.model)\n const caseDefinitions = prepared.cases.map((testCase) => ({\n id: testCase.id,\n clusterId: testCase.clusterId,\n labelState: testCase.labelState,\n expectedIssues: testCase.expectedIssues,\n labeledEvidence: testCase.labeledEvidence ?? [],\n tags: testCase.tags ?? [],\n metadata: testCase.metadata ?? {},\n }))\n return {\n config: {\n dataset: config.dataset,\n datasetRevision: config.revision,\n datasetSplit: config.split,\n model: {\n id: config.model.model,\n ...model,\n },\n limit: config.limit,\n seed: config.seed,\n concurrency: config.concurrency,\n repetitions: config.repetitions,\n rlmSamples: config.rlmSamples,\n maxCostUsd: config.maxCostUsd,\n maxArtifactBytes: config.maxArtifactBytes,\n analystProtocolSha256: effectiveAnalystProtocolSha256(\n config.dataset,\n config.model.instructionsOverride,\n ),\n ...(config.model.instructionsOverride\n ? { instructionsOverrideSha256: config.model.instructionsOverride.sha256 }\n : {}),\n implementationSha256: ANALYST_BENCHMARK_IMPLEMENTATION_SHA256,\n dependencyLockSha256: ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256,\n runnerIds: ['empty', config.analyst] as const,\n },\n inputs: {\n labelsSha256: prepared.labelsSha256,\n sourceRowCount: prepared.sourceRowCount,\n selectedCaseIds: [...prepared.selectedCaseIds],\n traceFiles: prepared.traceFiles.map((traceFile) => ({ ...traceFile })),\n verificationArtifactsSha256: digestCanonical(prepared.verificationArtifacts),\n caseDefinitionsSha256: digestCanonical(caseDefinitions),\n },\n }\n}\n\nfunction commandModelIdentity(config: PublicAnalystBenchmarkModelSettings) {\n const catalogPricing = resolveModelPricing(config.model)\n const pricing =\n config.pricing ??\n (catalogPricing\n ? {\n inputUsdPerMillion: catalogPricing.input * 1_000,\n outputUsdPerMillion: catalogPricing.output * 1_000,\n }\n : undefined)\n if (!pricing) {\n throw new Error(`benchmark model '${config.model}' has no recorded pricing`)\n }\n const recursive = config.dspyRlm\n return {\n ownerCallRef: config.callRef,\n maxOutputTokens: config.maxOutputTokens,\n maxReasoningTokens: config.maxReasoningTokens ?? config.maxOutputTokens * 4,\n maxRequestBytes: config.maxModelRequestBytes ?? 16 * 1024 * 1024,\n maxResponseBytes: config.maxModelResponseBytes ?? 4 * 1024 * 1024,\n requestTimeoutMs: config.modelRequestTimeoutMs ?? config.timeoutMs,\n timeoutMs: config.timeoutMs,\n pricing: { ...pricing },\n recursiveLimits: {\n maxIterations: recursive?.maxIterations ?? 14,\n maxLlmCalls: recursive?.maxLlmCalls ?? 8,\n maxToolCalls: recursive?.maxToolCalls ?? 80,\n maxOutputChars: recursive?.maxOutputChars ?? 8_000,\n maxModelRequests: recursive?.maxModelRequests ?? null,\n traceToolRequestBytes: recursive?.traceToolRequestBytes ?? 1_000_000,\n traceToolResponseBytes: recursive?.traceToolResponseBytes ?? 4_000_000,\n traceToolTimeoutMs: recursive?.traceToolTimeoutMs ?? 60_000,\n },\n processLimits: resolveExternalOptimizerProcessLimits(recursive?.runner?.limits),\n }\n}\n\nexport function createLocalRunReceipt(\n config: AnalystBenchmarkPersistenceConfig,\n paths: AnalystBenchmarkOutputPaths,\n): Omit<AnalystBenchmarkLocalRunReceipt, 'runIdentitySha256' | 'localIdentitySha256'> {\n return {\n kind: 'agent-eval/analyst-benchmark-local-run',\n local: {\n labelsPath: resolve(config.labelsPath),\n traceDir: resolve(config.traceDir),\n ...(config.artifactDir ? { artifactDir: resolve(config.artifactDir) } : {}),\n outputDir: paths.directory,\n ...(config.modelOwnerModule === undefined\n ? {}\n : { modelOwnerModule: config.modelOwnerModule }),\n },\n command: config.command,\n environment: {\n node: process.version,\n platform: platform(),\n arch: arch(),\n },\n files: {\n manifest: paths.manifest,\n observations: paths.observations,\n costLedger: paths.costLedger,\n modelResponses: paths.modelResponses,\n result: paths.result,\n report: paths.report,\n },\n }\n}\n\nexport async function initializeRunFiles(\n paths: AnalystBenchmarkOutputPaths,\n identity: AnalystBenchmarkRunIdentity,\n identitySha256: string,\n localIdentitySha256: string,\n localReceiptInput: Omit<\n AnalystBenchmarkLocalRunReceipt,\n 'runIdentitySha256' | 'localIdentitySha256'\n >,\n): Promise<AnalystBenchmarkRunManifest> {\n const existingManifest = await readOptionalRegularFile(paths.manifest, 'benchmark run manifest')\n const manifest = existingManifest\n ? await readAndValidateManifestContent(\n paths.manifest,\n existingManifest,\n identity,\n identitySha256,\n localIdentitySha256,\n )\n : {\n kind: 'agent-eval/analyst-benchmark-run' as const,\n createdAt: new Date().toISOString(),\n identitySha256,\n localIdentitySha256,\n identity,\n }\n const localReceipt: AnalystBenchmarkLocalRunReceipt = {\n ...localReceiptInput,\n runIdentitySha256: identitySha256,\n localIdentitySha256,\n }\n const manifestContent = `${JSON.stringify(manifest, null, 2)}\\n`\n const localReceiptContent = `${JSON.stringify(localReceipt, null, 2)}\\n`\n const initializationCompleteContent = renderInitializationComplete(manifest)\n\n await assertAbsentOrExact(paths.observations, '', 'benchmark observation log')\n await assertAbsentOrExact(paths.localReceipt, localReceiptContent, 'benchmark local run receipt')\n await assertAbsentOrExact(paths.manifest, manifestContent, 'benchmark run manifest')\n for (const path of [paths.costLedger, paths.modelResponses, paths.result, paths.report]) {\n if (await regularFileExists(path)) {\n throw new Error(\n `benchmark initialization marker is missing but later run artifact exists: ${path}`,\n )\n }\n }\n if (await regularFileExists(paths.initializationComplete)) {\n throw new Error(\n `benchmark initialization marker already exists during partial initialization: ${paths.initializationComplete}`,\n )\n }\n\n await writeExclusiveOrVerify(paths.observations, '')\n await writeExclusiveOrVerify(paths.localReceipt, localReceiptContent)\n await writeExclusiveOrVerify(paths.manifest, manifestContent)\n await writeExclusiveOrVerify(paths.initializationComplete, initializationCompleteContent)\n return manifest\n}\n\nexport async function readAndValidateResumeFiles(\n paths: AnalystBenchmarkOutputPaths,\n currentIdentity: AnalystBenchmarkRunIdentity,\n currentIdentitySha256: string,\n currentLocalIdentitySha256: string,\n localReceiptInput: Omit<\n AnalystBenchmarkLocalRunReceipt,\n 'runIdentitySha256' | 'localIdentitySha256'\n >,\n): Promise<AnalystBenchmarkRunManifest> {\n if (!(await regularFileExists(paths.initializationComplete))) {\n return initializeRunFiles(\n paths,\n currentIdentity,\n currentIdentitySha256,\n currentLocalIdentitySha256,\n localReceiptInput,\n )\n }\n const manifest = await readAndValidateManifest(\n paths.manifest,\n currentIdentity,\n currentIdentitySha256,\n currentLocalIdentitySha256,\n )\n const localReceiptContent = await readRegularFile(\n paths.localReceipt,\n 'benchmark local run receipt',\n )\n const value = parseJson(localReceiptContent, paths.localReceipt)\n if (!isRecord(value)) {\n throw new TypeError(`benchmark local run receipt must be an object: ${paths.localReceipt}`)\n }\n assertExactKeys(\n value,\n [\n 'kind',\n 'runIdentitySha256',\n 'localIdentitySha256',\n 'local',\n 'command',\n 'environment',\n 'files',\n ],\n 'benchmark local run receipt',\n )\n if (\n value.kind !== 'agent-eval/analyst-benchmark-local-run' ||\n value.runIdentitySha256 !== currentIdentitySha256 ||\n value.localIdentitySha256 !== currentLocalIdentitySha256 ||\n !isRecord(value.local)\n ) {\n throw new Error('benchmark local run receipt does not match the requested resume')\n }\n const expectedLocalReceipt: AnalystBenchmarkLocalRunReceipt = {\n ...localReceiptInput,\n runIdentitySha256: currentIdentitySha256,\n localIdentitySha256: currentLocalIdentitySha256,\n }\n const storedLocalIdentitySha256 = digestCanonical(value.local)\n if (\n storedLocalIdentitySha256 !== currentLocalIdentitySha256 ||\n canonicalJson(value.local) !== canonicalJson(localReceiptInput.local)\n ) {\n throw new Error('benchmark local paths or model-owner module do not match the requested resume')\n }\n if (localReceiptContent !== `${JSON.stringify(expectedLocalReceipt, null, 2)}\\n`) {\n throw new Error(`benchmark local run receipt does not exactly match: ${paths.localReceipt}`)\n }\n const initializationCompleteContent = await readRegularFile(\n paths.initializationComplete,\n 'benchmark initialization marker',\n )\n if (initializationCompleteContent !== renderInitializationComplete(manifest)) {\n throw new Error(\n `benchmark initialization marker does not match the run manifest: ${paths.initializationComplete}`,\n )\n }\n return manifest\n}\n\nasync function readAndValidateManifest(\n path: string,\n currentIdentity: AnalystBenchmarkRunIdentity,\n currentIdentitySha256: string,\n currentLocalIdentitySha256: string,\n): Promise<AnalystBenchmarkRunManifest> {\n const content = await readRegularFile(path, 'benchmark run manifest')\n const manifest = await readAndValidateManifestContent(\n path,\n content,\n currentIdentity,\n currentIdentitySha256,\n currentLocalIdentitySha256,\n )\n if (content !== `${JSON.stringify(manifest, null, 2)}\\n`) {\n throw new Error(`benchmark run manifest does not exactly match: ${path}`)\n }\n return manifest\n}\n\nasync function readAndValidateManifestContent(\n path: string,\n content: string,\n currentIdentity: AnalystBenchmarkRunIdentity,\n currentIdentitySha256: string,\n currentLocalIdentitySha256: string,\n): Promise<AnalystBenchmarkRunManifest> {\n const value = parseJson(content, path)\n if (!isRecord(value)) throw new TypeError(`benchmark run manifest must be an object: ${path}`)\n assertExactKeys(\n value,\n ['kind', 'createdAt', 'identitySha256', 'localIdentitySha256', 'identity'],\n 'benchmark run manifest',\n )\n if (value.kind !== 'agent-eval/analyst-benchmark-run') {\n throw new TypeError(`unsupported benchmark run manifest: ${path}`)\n }\n if (typeof value.createdAt !== 'string' || !Number.isFinite(Date.parse(value.createdAt))) {\n throw new TypeError(`benchmark run manifest has an invalid createdAt: ${path}`)\n }\n if (\n !isSha256(value.identitySha256) ||\n !isSha256(value.localIdentitySha256) ||\n !isRecord(value.identity)\n ) {\n throw new TypeError(`benchmark run manifest has an invalid identity: ${path}`)\n }\n const storedIdentitySha256 = digestCanonical(value.identity)\n if (storedIdentitySha256 !== value.identitySha256) {\n throw new Error(`benchmark run manifest identity digest does not match its contents: ${path}`)\n }\n if (\n currentIdentitySha256 !== value.identitySha256 ||\n currentLocalIdentitySha256 !== value.localIdentitySha256 ||\n canonicalJson(currentIdentity) !== canonicalJson(value.identity)\n ) {\n throw new Error(\n `benchmark resume configuration or inputs do not match ${ANALYST_BENCHMARK_MANIFEST_FILE}`,\n )\n }\n return {\n kind: 'agent-eval/analyst-benchmark-run',\n createdAt: value.createdAt,\n identitySha256: currentIdentitySha256,\n localIdentitySha256: currentLocalIdentitySha256,\n identity: currentIdentity,\n }\n}\n\nfunction renderInitializationComplete(manifest: AnalystBenchmarkRunManifest): string {\n return `${JSON.stringify(\n {\n kind: 'agent-eval/analyst-benchmark-initialization-complete',\n runIdentitySha256: manifest.identitySha256,\n localIdentitySha256: manifest.localIdentitySha256,\n createdAt: manifest.createdAt,\n },\n null,\n 2,\n )}\\n`\n}\n\nasync function assertAbsentOrExact(path: string, expected: string, label: string): Promise<void> {\n const existing = await readOptionalRegularFile(path, label)\n if (existing !== undefined && existing !== expected) {\n throw new Error(`${label} does not exactly match interrupted initialization: ${path}`)\n }\n}\n\nasync function readOptionalRegularFile(path: string, label: string): Promise<string | undefined> {\n if (!(await regularFileExists(path))) return undefined\n return readRegularFile(path, label)\n}\n\nexport function createObservationAppender(\n path: string,\n runIdentitySha256: string,\n progress: AnalystBenchmarkProgress,\n): (observation: AnalystBenchmarkObservation) => Promise<void> {\n let writes = Promise.resolve()\n const seen = new Set(progress.observations.map(observationKey))\n return (observation) => {\n const write = writes.then(async () => {\n assertAnalystBenchmarkObservation(observation, 'benchmark observation')\n const key = observationKey(observation)\n if (seen.has(key)) {\n throw new Error(\n `refusing duplicate benchmark observation '${observation.runnerId}/${observation.caseId}/${observation.repetition}'`,\n )\n }\n const rowWithoutDigest = {\n sequence: progress.nextSequence,\n runIdentitySha256,\n previousRowSha256: progress.previousRowSha256,\n observation,\n }\n const row: AnalystBenchmarkProgressRow = {\n ...rowWithoutDigest,\n rowSha256: digestCanonical(rowWithoutDigest),\n }\n await appendDurable(path, `${JSON.stringify(row)}\\n`)\n progress.nextSequence += 1\n progress.previousRowSha256 = row.rowSha256\n progress.observations.push(observation)\n seen.add(key)\n })\n writes = write\n return write\n }\n}\n\nexport async function readProgress(\n path: string,\n runIdentitySha256: string,\n caseIds: readonly string[],\n repetitions: number,\n analystRunnerId: string,\n): Promise<AnalystBenchmarkProgress> {\n const text = await readRegularFile(path, 'benchmark observation log')\n const rawLines = text.split('\\n')\n if (rawLines.at(-1) === '') rawLines.pop()\n const observations: AnalystBenchmarkObservation[] = []\n const seen = new Set<string>()\n const executionIndexes = new Set<number>()\n let previousRowSha256: string | null = null\n const allowedCases = new Set(caseIds)\n const plannedObservationCount = caseIds.length * 2 * repetitions\n\n for (const [index, line] of rawLines.entries()) {\n if (!line.trim()) {\n throw new Error(`benchmark observation log contains an empty row at line ${index + 1}`)\n }\n const parsed = parseJson(line, `${path}:${index + 1}`)\n if (!isRecord(parsed)) {\n throw new TypeError(`benchmark observation row ${index + 1} must be an object`)\n }\n assertExactKeys(\n parsed,\n ['sequence', 'runIdentitySha256', 'previousRowSha256', 'observation', 'rowSha256'],\n `benchmark observation row ${index + 1}`,\n )\n assertAnalystBenchmarkObservation(\n parsed.observation,\n `benchmark observation row ${index + 1}.observation`,\n )\n const observation = parsed.observation\n const key = observationKey(observation)\n if (seen.has(key)) {\n throw new Error(\n `duplicate benchmark observation '${observation.runnerId}/${observation.caseId}/${observation.repetition}' at line ${index + 1}`,\n )\n }\n if (parsed.sequence !== index) {\n throw new Error(\n `benchmark observation row ${index + 1} has sequence ${String(parsed.sequence)}; expected ${index}`,\n )\n }\n if (parsed.runIdentitySha256 !== runIdentitySha256) {\n throw new Error(`benchmark observation row ${index + 1} belongs to another run`)\n }\n if (parsed.previousRowSha256 !== previousRowSha256) {\n throw new Error(`benchmark observation row ${index + 1} breaks the digest chain`)\n }\n if (!isSha256(parsed.rowSha256)) {\n throw new TypeError(`benchmark observation row ${index + 1} has an invalid digest`)\n }\n const expectedDigest = digestCanonical({\n sequence: parsed.sequence,\n runIdentitySha256: parsed.runIdentitySha256,\n previousRowSha256: parsed.previousRowSha256,\n observation,\n })\n if (expectedDigest !== parsed.rowSha256) {\n throw new Error(`benchmark observation row ${index + 1} digest does not match its contents`)\n }\n if (\n !allowedCases.has(observation.caseId) ||\n (observation.runnerId !== 'empty' && observation.runnerId !== analystRunnerId) ||\n observation.repetition >= repetitions ||\n observation.executionIndex >= plannedObservationCount\n ) {\n throw new Error(\n `benchmark observation row ${index + 1} does not match a planned case, runner, and repetition`,\n )\n }\n if (executionIndexes.has(observation.executionIndex)) {\n throw new Error(\n `duplicate benchmark executionIndex ${observation.executionIndex} at line ${index + 1}`,\n )\n }\n observations.push(observation)\n seen.add(key)\n executionIndexes.add(observation.executionIndex)\n previousRowSha256 = parsed.rowSha256\n }\n\n return {\n observations,\n nextSequence: observations.length,\n previousRowSha256,\n }\n}\n\nexport async function writeExclusiveOrVerify(path: string, content: string): Promise<void> {\n try {\n await writeExclusive(path, content)\n } catch (error) {\n if (!isNodeError(error, 'EEXIST')) throw error\n const existing = await readRegularFile(path, 'existing benchmark artifact')\n if (existing !== content) {\n throw new Error(`refusing to replace existing benchmark artifact: ${path}`)\n }\n }\n}\n\nexport async function regularFileExists(path: string): Promise<boolean> {\n try {\n const fileStat = await lstat(path)\n if (!fileStat.isFile() || fileStat.isSymbolicLink()) {\n throw new Error(`benchmark artifact path must be a real file: ${path}`)\n }\n return true\n } catch (error) {\n if (isNodeError(error, 'ENOENT')) return false\n throw error\n }\n}\n\nasync function appendDurable(path: string, content: string): Promise<void> {\n const handle = await open(path, constants.O_APPEND | constants.O_WRONLY | constants.O_NOFOLLOW)\n try {\n await handle.writeFile(content, 'utf8')\n await handle.sync()\n } finally {\n await handle.close()\n }\n}\n\nasync function writeExclusive(path: string, content: string): Promise<void> {\n const temporary = `${path}.tmp-${process.pid}-${randomUUID()}`\n let handle: Awaited<ReturnType<typeof open>> | undefined\n try {\n handle = await open(temporary, 'wx')\n await handle.writeFile(content, 'utf8')\n await handle.sync()\n await handle.close()\n handle = undefined\n await link(temporary, path)\n await syncDirectory(dirname(path))\n } finally {\n await handle?.close().catch(() => undefined)\n await unlink(temporary).catch(() => undefined)\n }\n}\n\nexport async function readRegularFile(path: string, label: string): Promise<string> {\n let fileStat: Awaited<ReturnType<typeof lstat>>\n try {\n fileStat = await lstat(path)\n } catch (error) {\n if (isNodeError(error, 'ENOENT')) throw new Error(`${label} is missing: ${path}`)\n throw error\n }\n if (!fileStat.isFile() || fileStat.isSymbolicLink()) {\n throw new Error(`${label} must be a real file: ${path}`)\n }\n return readFile(path, 'utf8')\n}\n\nasync function syncDirectory(path: string): Promise<void> {\n const directory = await open(path, 'r')\n try {\n await directory.sync()\n } finally {\n await directory.close()\n }\n}\n\nfunction isNodeError(error: unknown, code: string): error is NodeJS.ErrnoException {\n return error instanceof Error && 'code' in error && error.code === code\n}\n","import type { AnalystBenchmarkObservation, AnalystBenchmarkResult } from './benchmark'\nimport { codeTraceStepFromEvidence } from './benchmark-evidence-validation'\n\nexport interface CodeTraceCalibrationRunnerSummary {\n runnerId: string\n selectedRuns: number\n positiveRuns: number\n trustedNegativeRuns: number\n unlabeledRuns: number\n failedLabelEmptyRuns: number\n unknownLabelEmptyRuns: number\n completedRuns: number\n failedRuns: number\n expectedIncorrectSteps: number\n predictedIncorrectSteps: number\n matchedIncorrectSteps: number\n /** CodeTraceBench's published mean per-row incorrect-step F1 over every row. */\n officialAllRowF1: number | null\n officialAllRowRuns: number\n precision: number | null\n recall: number | null\n f1: number | null\n trustedNegativeFalsePositiveRate: number | null\n trustedNegativeFailureRate: number | null\n unlabeledPredictionRate: number | null\n unlabeledFailureRate: number | null\n}\n\nexport interface CodeTraceCalibrationSummary {\n protocol: 'labeled-positive-and-solved-negative'\n rationale: string\n runners: CodeTraceCalibrationRunnerSummary[]\n}\n\nexport function summarizeCodeTraceCalibration(\n result: AnalystBenchmarkResult,\n): CodeTraceCalibrationSummary {\n return {\n protocol: 'labeled-positive-and-solved-negative',\n rationale:\n 'Uses rows with incorrect-step labels as positives and solved label-empty rows as trusted negatives. Failed label-empty rows remain in the published result but are not treated as clean controls.',\n runners: result.provenance.runnerIds.map((runnerId) =>\n summarizeRunner(\n runnerId,\n result.observations.filter((observation) => observation.runnerId === runnerId),\n ),\n ),\n }\n}\n\nexport function renderCodeTraceCalibrationMarkdown(summary: CodeTraceCalibrationSummary): string {\n return [\n '## CodeTraceBench Calibrated View',\n '',\n summary.rationale,\n '',\n '| Runner | Completed/selected | Failed | Positive runs | Trusted negative runs | Unlabeled runs | Failed label-empty | Unknown label-empty | Matched/expected steps | Predicted steps | Precision | Recall | F1 | Official all-row F1 | Official rows | Trusted-negative false positives | Trusted-negative failures | Unlabeled predictions | Unlabeled failures |',\n '| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |',\n ...summary.runners.map(\n (runner) =>\n `| ${escapeCell(runner.runnerId)} | ${runner.completedRuns}/${runner.selectedRuns} | ${runner.failedRuns} | ${runner.positiveRuns} | ${runner.trustedNegativeRuns} | ${runner.unlabeledRuns} | ${runner.failedLabelEmptyRuns} | ${runner.unknownLabelEmptyRuns} | ${runner.matchedIncorrectSteps}/${runner.expectedIncorrectSteps} | ${runner.predictedIncorrectSteps} | ${rate(runner.precision)} | ${rate(runner.recall)} | ${rate(runner.f1)} | ${rate(runner.officialAllRowF1)} | ${runner.officialAllRowRuns} | ${rate(runner.trustedNegativeFalsePositiveRate)} | ${rate(runner.trustedNegativeFailureRate)} | ${rate(runner.unlabeledPredictionRate)} | ${rate(runner.unlabeledFailureRate)} |`,\n ),\n ].join('\\n')\n}\n\nfunction summarizeRunner(\n runnerId: string,\n observations: readonly AnalystBenchmarkObservation[],\n): CodeTraceCalibrationRunnerSummary {\n const positive = observations.filter((observation) => observation.labelState === 'positive')\n const trustedNegative = observations.filter(\n (observation) => observation.labelState === 'trusted-negative',\n )\n const excluded = observations.filter((observation) => observation.labelState === 'unlabeled')\n const selected = [...positive, ...trustedNegative]\n const expected = sum(positive.map((observation) => observation.score.expectedIssueCount))\n const predicted = sum(\n selected.map((observation) => (observation.error ? 0 : observation.findings.length)),\n )\n const matched = sum(positive.map((observation) => observation.score.matchedIssueIds.length))\n const precision = predicted === 0 ? (expected > 0 ? 0 : null) : matched / predicted\n const recall = ratio(matched, expected)\n const completedTrustedNegative = trustedNegative.filter((observation) => !observation.error)\n const completedExcluded = excluded.filter((observation) => !observation.error)\n const officialRows = observations.map(officialCodeTraceF1)\n\n return {\n runnerId,\n selectedRuns: selected.length,\n positiveRuns: positive.length,\n trustedNegativeRuns: trustedNegative.length,\n unlabeledRuns: excluded.length,\n failedLabelEmptyRuns: excluded.filter(\n (observation) => observation.caseMetadata?.solved === false,\n ).length,\n unknownLabelEmptyRuns: excluded.filter(\n (observation) => observation.caseMetadata?.solved !== false,\n ).length,\n completedRuns: selected.filter((observation) => !observation.error).length,\n failedRuns: selected.filter((observation) => observation.error).length,\n expectedIncorrectSteps: expected,\n predictedIncorrectSteps: predicted,\n matchedIncorrectSteps: matched,\n officialAllRowF1: mean(officialRows),\n officialAllRowRuns: officialRows.length,\n precision,\n recall,\n f1: harmonicMean(precision, recall),\n trustedNegativeFalsePositiveRate: ratio(\n completedTrustedNegative.filter((observation) => observation.score.predictionOnLabelEmptyCase)\n .length,\n completedTrustedNegative.length,\n ),\n trustedNegativeFailureRate: ratio(\n trustedNegative.filter((observation) => observation.error).length,\n trustedNegative.length,\n ),\n unlabeledPredictionRate: ratio(\n completedExcluded.filter((observation) => observation.findings.length > 0).length,\n completedExcluded.length,\n ),\n unlabeledFailureRate: ratio(\n excluded.filter((observation) => Boolean(observation.error)).length,\n excluded.length,\n ),\n }\n}\n\nfunction officialCodeTraceF1(observation: AnalystBenchmarkObservation): number {\n const trajectoryId = observation.caseMetadata?.trajectoryId\n if (typeof trajectoryId !== 'string' || !trajectoryId.trim()) {\n throw new TypeError(`${observation.caseId}: CodeTraceBench trajectoryId metadata is missing`)\n }\n const expected = new Set(\n [...observation.score.matchedIssueIds, ...observation.score.missedIssueIds].map((issueId) => {\n const match = /^incorrect:(\\d+)$/.exec(issueId)\n if (!match) {\n throw new TypeError(`${observation.caseId}: invalid incorrect-step label '${issueId}'`)\n }\n return Number(match[1])\n }),\n )\n const predicted = new Set<number>()\n if (!observation.error) {\n for (const finding of observation.findings) {\n if (finding.area !== 'incorrect') continue\n for (const evidence of finding.evidence_refs) {\n const location = codeTraceStepFromEvidence(evidence.uri)\n if (!location || location.traceId !== trajectoryId) {\n throw new TypeError(\n `${observation.caseId}: invalid CodeTraceBench prediction evidence '${evidence.uri}'`,\n )\n }\n predicted.add(location.step)\n }\n }\n }\n let matched = 0\n for (const step of predicted) if (expected.has(step)) matched += 1\n const precision = predicted.size === 0 ? 0 : matched / predicted.size\n const recall = expected.size === 0 ? 0 : matched / expected.size\n return harmonicMean(precision, recall) ?? 0\n}\n\nfunction sum(values: readonly number[]): number {\n return values.reduce((total, value) => total + value, 0)\n}\n\nfunction ratio(numerator: number, denominator: number): number | null {\n return denominator === 0 ? null : numerator / denominator\n}\n\nfunction mean(values: readonly number[]): number | null {\n return values.length === 0 ? null : sum(values) / values.length\n}\n\nfunction harmonicMean(left: number | null, right: number | null): number | null {\n if (left === null || right === null) return null\n return left + right === 0 ? 0 : (2 * left * right) / (left + right)\n}\n\nfunction rate(value: number | null): string {\n return value === null ? 'n/a' : value.toFixed(3)\n}\n\nfunction escapeCell(value: string): string {\n return value.replaceAll('|', '\\\\|').replaceAll('\\n', ' ')\n}\n","import type { AnalystBenchmarkObservation } from './benchmark'\nimport {\n AGENT_RX_UPSTREAM_REVISION,\n summarizeAgentRxCalibration,\n} from './benchmark-agentrx-calibration'\nimport {\n type AnalystBenchmarkArtifact,\n type AnalystBenchmarkRunManifest,\n canonicalJson,\n observationKey,\n parseJson,\n} from './benchmark-command-artifact'\nimport { readRegularFile } from './benchmark-command-persistence'\nimport { assertAnalystBenchmarkArtifact } from './benchmark-command-validation'\nimport { compareAnalystRunners } from './benchmark-comparison'\nimport { summarizeCodeTraceCalibration } from './benchmark-public-calibration'\nimport type { PreparedPublicAnalystBenchmark } from './benchmark-real-model'\nimport { summarizeAnalystBenchmarkRunner } from './benchmark-summary'\n\nexport async function readAnalystBenchmarkArtifact(\n path: string,\n): Promise<AnalystBenchmarkArtifact> {\n const value = parseJson(await readRegularFile(path, 'analyst benchmark result'), path)\n assertAnalystBenchmarkArtifact(value, 'analyst benchmark result')\n return value\n}\n\nexport function assertCompletedArtifactMatchesRun(\n artifact: AnalystBenchmarkArtifact,\n manifest: AnalystBenchmarkRunManifest,\n observations: readonly AnalystBenchmarkObservation[],\n prepared: PreparedPublicAnalystBenchmark,\n): void {\n if (artifact.runIdentitySha256 !== manifest.identitySha256) {\n throw new Error('completed benchmark result belongs to another run')\n }\n assertSameObservations(artifact.result.observations, observations)\n const expectedCount =\n manifest.identity.inputs.selectedCaseIds.length *\n manifest.identity.config.runnerIds.length *\n manifest.identity.config.repetitions\n if (observations.length !== expectedCount) {\n throw new Error(\n `completed benchmark result has ${observations.length} observations; expected ${expectedCount}`,\n )\n }\n\n const { config, inputs } = manifest.identity\n const verificationAvailability = {\n cases: prepared.verificationArtifacts.length,\n resultFilesPresent: prepared.verificationArtifacts.filter(\n (artifact) => artifact.status === 'present',\n ).length,\n resultFilesMissing: prepared.verificationArtifacts.filter(\n (artifact) => artifact.status === 'missing',\n ).length,\n outcomes: {\n passed: prepared.verificationArtifacts.filter(\n (artifact) => artifact.outcome.status === 'passed',\n ).length,\n failed: prepared.verificationArtifacts.filter(\n (artifact) => artifact.outcome.status === 'failed',\n ).length,\n unavailable: prepared.verificationArtifacts.filter(\n (artifact) => artifact.outcome.status === 'unavailable',\n ).length,\n },\n }\n const expectedInputs: AnalystBenchmarkArtifact['inputs'] = {\n dataset: config.dataset,\n datasetRevision: config.datasetRevision,\n datasetSplit: config.datasetSplit,\n labelsSha256: inputs.labelsSha256,\n sourceRowCount: inputs.sourceRowCount,\n traceFiles: inputs.traceFiles.map((traceFile) => ({ ...traceFile })),\n verificationArtifacts: prepared.verificationArtifacts,\n verificationAvailability,\n selection: {\n limit: config.limit,\n seed: config.seed,\n selectedCaseIds: [...inputs.selectedCaseIds],\n report: prepared.selection,\n },\n execution: {\n repetitions: config.repetitions,\n concurrency: config.concurrency,\n ...(config.rlmSamples === undefined ? {} : { rlmSamples: config.rlmSamples }),\n model: config.model.id,\n modelOwnerCallRef: config.model.ownerCallRef,\n maxOutputTokens: config.model.maxOutputTokens,\n maxReasoningTokens: config.model.maxReasoningTokens,\n maxModelRequestBytes: config.model.maxRequestBytes,\n maxModelResponseBytes: config.model.maxResponseBytes,\n modelRequestTimeoutMs: config.model.requestTimeoutMs,\n timeoutMs: config.model.timeoutMs,\n pricing: config.model.pricing,\n recursiveLimits: config.model.recursiveLimits,\n processLimits: config.model.processLimits,\n maxCostUsd: config.maxCostUsd,\n maxArtifactBytes: config.maxArtifactBytes,\n analystProtocolSha256: config.analystProtocolSha256,\n ...(config.instructionsOverrideSha256 === undefined\n ? {}\n : { instructionsOverrideSha256: config.instructionsOverrideSha256 }),\n implementationSha256: config.implementationSha256,\n dependencyLockSha256: config.dependencyLockSha256,\n },\n }\n if (canonicalJson(artifact.inputs) !== canonicalJson(expectedInputs)) {\n throw new Error('completed benchmark result inputs do not match the run manifest')\n }\n\n const provenance = artifact.result.provenance\n const expectedDatasetId =\n config.dataset === 'agentrx' ? 'microsoft/AgentRx' : 'NJU-LINK/CodeTraceBench'\n const expectedOutputAdapter =\n config.dataset === 'agentrx'\n ? 'agentrx-taxonomy-and-root-step'\n : 'codetracebench-incorrect-block'\n if (\n provenance.id !== `${config.dataset}-real-model-analyst` ||\n provenance.startedAt !== manifest.createdAt ||\n !Number.isFinite(Date.parse(provenance.endedAt)) ||\n Date.parse(provenance.endedAt) < Date.parse(provenance.startedAt) ||\n canonicalJson(provenance.dataset) !==\n canonicalJson({\n id: expectedDatasetId,\n revision: config.datasetRevision,\n split: config.datasetSplit,\n }) ||\n provenance.caseCount !== inputs.selectedCaseIds.length ||\n canonicalJson(provenance.runnerIds) !== canonicalJson(config.runnerIds) ||\n provenance.repetitions !== config.repetitions ||\n provenance.maxConcurrency !== Math.min(config.concurrency, expectedCount) ||\n provenance.runnerOrderSeed !== config.seed ||\n provenance.metadata?.model !== config.model.id ||\n provenance.metadata?.modelOwnerCallRef !== config.model.ownerCallRef ||\n provenance.metadata?.rlmSamples !== config.rlmSamples ||\n provenance.metadata?.outputAdapter !== expectedOutputAdapter ||\n provenance.metadata?.caseSelection !== prepared.selection.method ||\n provenance.metadata?.caseSelectionSeed !== config.seed ||\n provenance.metadata?.selectionStratified !== prepared.selection.stratified ||\n provenance.metadata?.protocolSha256 !== config.analystProtocolSha256 ||\n provenance.metadata?.implementationSha256 !== config.implementationSha256 ||\n provenance.metadata?.dependencyLockSha256 !== config.dependencyLockSha256 ||\n provenance.metadata?.populationRepresentativenessProven !== false\n ) {\n throw new Error('completed benchmark result provenance does not match the run manifest')\n }\n\n const expectedSummaries = config.runnerIds.map((runnerId) =>\n summarizeAnalystBenchmarkRunner(\n runnerId,\n observations.filter((observation) => observation.runnerId === runnerId),\n ),\n )\n if (canonicalJson(artifact.result.summaries) !== canonicalJson(expectedSummaries)) {\n throw new Error('completed benchmark summaries do not match durable observations')\n }\n\n const expectedComparisons = [\n compareAnalystRunners(artifact.result, {\n baselineRunnerId: 'empty',\n candidateRunnerId: config.runnerIds[1],\n seed: config.seed,\n }),\n ]\n if (canonicalJson(artifact.comparisons) !== canonicalJson(expectedComparisons)) {\n throw new Error('completed benchmark comparisons do not match durable observations')\n }\n\n if (config.dataset === 'codetracebench') {\n if (\n canonicalJson(artifact.codeTraceCalibration) !==\n canonicalJson(summarizeCodeTraceCalibration(artifact.result)) ||\n artifact.agentRxCalibration !== undefined\n ) {\n throw new Error('completed CodeTraceBench calibration does not match durable observations')\n }\n } else if (\n canonicalJson(artifact.agentRxCalibration) !==\n canonicalJson(summarizeAgentRxCalibration(artifact.result, AGENT_RX_UPSTREAM_REVISION)) ||\n artifact.codeTraceCalibration !== undefined\n ) {\n throw new Error('completed AgentRx calibration does not match durable observations')\n }\n}\n\nexport function assertSameObservations(\n expected: readonly AnalystBenchmarkObservation[],\n actual: readonly AnalystBenchmarkObservation[],\n): void {\n if (expected.length !== actual.length) {\n throw new Error(\n `benchmark result has ${expected.length} observations but the durable log has ${actual.length}`,\n )\n }\n const expectedByKey = new Map(\n expected.map((observation) => [observationKey(observation), canonicalJson(observation)]),\n )\n for (const observation of actual) {\n const key = observationKey(observation)\n if (expectedByKey.get(key) !== canonicalJson(observation)) {\n throw new Error(\n `benchmark result does not match durable observation '${observation.runnerId}/${observation.caseId}/${observation.repetition}'`,\n )\n }\n expectedByKey.delete(key)\n }\n if (expectedByKey.size > 0) {\n throw new Error('benchmark result is missing durable observations')\n }\n}\n","import type { TraceAnalysisStore } from '../trace-analyst/store'\nimport type { AnalystBenchmarkRunner } from './benchmark'\nimport { agentRxPredictionsToFindings } from './benchmark-datasets'\nimport {\n codeTraceStepFromEvidence,\n resolveAssistantStepEvidence,\n validateCodeTraceFindingEvidence,\n} from './benchmark-evidence-validation'\nimport { MAX_INCORRECT_BLOCK_STEPS, MAX_INCORRECT_BLOCKS } from './benchmark-public-prompt'\nimport type { PublicAnalystBenchmarkDataset } from './benchmark-public-types'\nimport type { AnalystFinding, AnalystRunInputs, AnalystSeverity } from './types'\nimport { makeFinding } from './types'\n\n/**\n * One contiguous run of incorrect assistant steps, in the shape both public\n * benchmark runners produce. The direct runner parses it from JSON fields; the\n * recursive runner parses it from the finding subject. Expansion, evidence\n * resolution and scoring are identical from here on.\n */\nexport interface CodeTraceFailureBlock {\n firstStep: number\n lastStep: number\n /** Later step whose action or observation shows the damage this block caused. */\n consequenceStep: number\n escapeStatus: 'escaped' | 'unescaped'\n severity: AnalystSeverity\n claim: string\n confidence: number\n rationale?: string\n recommendedAction?: string\n metadata?: Record<string, unknown>\n}\n\n/**\n * What the expansion did with the model's blocks.\n *\n * Escaped blocks are scored exactly like unescaped ones — the escape decision\n * is recorded, never applied — so `escapedBlocks` measures the model's own\n * judgement without moving precision, recall, or the trusted-negative rate.\n */\nexport interface CodeTraceBlockDiagnostics {\n reportedBlocks: number\n escapedBlocks: number\n /** Blocks dropped because their consequence step is not a real assistant step. */\n blocksWithoutConsequenceEvidence: CodeTraceFailureBlock[]\n /** Interior steps a block claimed that the trace does not carry as assistant steps. */\n unresolvedBlockInteriorSteps: number[]\n /** Steps claimed by more than one block; the first block keeps the step. */\n overlappingBlockSteps: number[]\n /** Blocks dropped for violating the protocol's width, order, or count limits. */\n droppedBlocks: string[]\n /** Findings dropped before expansion because their shape or evidence is invalid. */\n rejectedFindings?: string[]\n /** Out-of-block citations removed from findings that kept at least one in-block citation. */\n trimmedCitations?: string[]\n}\n\n/**\n * One expanded step with the accepted block that owns it. The expansion's\n * per-step ownership record: exactly the steps that survived shape, count,\n * and evidence checks, so consensus voting sees the same step set the\n * benchmark scores.\n */\nexport interface CodeTraceStepAssignment {\n step: number\n block: CodeTraceFailureBlock\n}\n\nexport function emptyPublicBenchmarkRunner(): AnalystBenchmarkRunner<AnalystRunInputs> {\n return {\n id: 'empty',\n analyze() {\n return {\n findings: [],\n usage: {\n calls: 0,\n tokens: { input: 0, output: 0 },\n cost: { kind: 'observed', usd: 0 },\n },\n metadata: { baseline: 'emit-no-findings' },\n }\n },\n }\n}\n\nexport async function adaptPublicBenchmarkFindings(options: {\n dataset: PublicAnalystBenchmarkDataset\n trajectoryId: string\n findings: readonly AnalystFinding[]\n analystId: string\n store: TraceAnalysisStore\n signal?: AbortSignal\n}): Promise<{\n findings: AnalystFinding[]\n diagnostics: CodeTraceBlockDiagnostics | undefined\n /** Present for CodeTraceBench only; AgentRx has no step-level expansion. */\n stepBlocks?: CodeTraceStepAssignment[]\n}> {\n if (options.dataset === 'agentrx') {\n return {\n findings: adaptAgentRxFindings(options.trajectoryId, options.findings, options.analystId),\n diagnostics: undefined,\n }\n }\n return adaptCodeTraceFindings(\n options.trajectoryId,\n options.findings,\n options.analystId,\n options.store,\n options.signal,\n )\n}\n\nfunction adaptAgentRxFindings(\n trajectoryId: string,\n findings: readonly AnalystFinding[],\n analystId: string,\n): AnalystFinding[] {\n if (findings.length === 0) return []\n if (findings.length !== 1) {\n throw new Error(\n `AgentRx model analyst must emit zero or one root cause, received ${findings.length}`,\n )\n }\n const source = findings[0]!\n if (!source.subject) {\n throw new Error('AgentRx model analyst finding is missing its failure-category subject')\n }\n const steps = exactFindingSteps(trajectoryId, source)\n if (steps.length !== 1) {\n throw new Error(\n `AgentRx model analyst must cite exactly one root-cause step, received ${steps.length}`,\n )\n }\n const [adapted] = agentRxPredictionsToFindings(\n trajectoryId,\n [\n {\n failure_case: source.subject,\n step_number: steps[0]!,\n description: source.rationale ?? source.claim,\n },\n ],\n {\n analystId,\n producedAt: source.produced_at,\n confidence: source.confidence,\n },\n )\n if (!adapted) throw new Error('AgentRx output adapter produced no root-cause finding')\n return [\n {\n ...adapted,\n metadata: {\n ...adapted.metadata,\n sourceFindingId: source.finding_id,\n },\n },\n ]\n}\n\nconst CODE_TRACE_BLOCK_SUBJECT =\n /^incorrect-steps-(\\d+)-(\\d+)-(escaped|unescaped)-consequence-(\\d+)$/\n\nasync function adaptCodeTraceFindings(\n trajectoryId: string,\n findings: readonly AnalystFinding[],\n analystId: string,\n store: TraceAnalysisStore,\n signal?: AbortSignal,\n): Promise<{\n findings: AnalystFinding[]\n diagnostics: CodeTraceBlockDiagnostics\n stepBlocks: CodeTraceStepAssignment[]\n}> {\n const clean = findings.filter((finding) => finding.subject === 'clean')\n if (clean.length > 0) {\n if (findings.length !== 1) {\n throw new Error('CodeTraceBench model analyst mixed a clean verdict with incorrect steps')\n }\n exactFindingSteps(trajectoryId, clean[0]!)\n return {\n findings: [],\n diagnostics: emptyCodeTraceBlockDiagnostics(),\n stepBlocks: [],\n }\n }\n // Each finding is model output. One whose subject is unparseable, whose\n // citations all fall outside its own block, or whose evidence does not\n // resolve is dropped with a recorded reason — the rest of a completed, paid\n // investigation must survive it. Citations and excerpts are checked here\n // because expansion replaces them with runner-built evidence.\n const blocks: CodeTraceFailureBlock[] = []\n const rejectedFindings: string[] = []\n const trimmedCitations: string[] = []\n for (const source of findings) {\n try {\n await validateCodeTraceFindingEvidence({\n trajectoryId,\n findings: [source],\n store,\n ...(signal ? { signal } : {}),\n })\n const converted = codeTraceBlockFromFinding(trajectoryId, source)\n trimmedCitations.push(...converted.trimmedCitations)\n blocks.push(converted.block)\n } catch (error) {\n rejectedFindings.push(\n `${source.finding_id}: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n const expanded = await expandCodeTraceFailureBlocks({\n trajectoryId,\n blocks,\n store,\n analystId,\n ...(findings[0] ? { producedAt: findings[0].produced_at } : {}),\n ...(signal ? { signal } : {}),\n })\n return {\n findings: expanded.findings,\n diagnostics: { ...expanded.diagnostics, rejectedFindings, trimmedCitations },\n stepBlocks: expanded.stepBlocks,\n }\n}\n\n/**\n * Block coordinates recoverable from a subject in the block grammar, in the\n * metadata field names the expanded findings carry. Returns undefined when the\n * subject does not parse — nothing is invented for a malformed subject.\n */\nexport function codeTraceBlockMetadataFromSubject(\n subject: string | undefined,\n): Record<string, unknown> | undefined {\n const parsed = CODE_TRACE_BLOCK_SUBJECT.exec(subject ?? '')\n if (!parsed) return undefined\n return {\n block_first_step: Number(parsed[1]),\n block_last_step: Number(parsed[2]),\n block_consequence_step: Number(parsed[4]),\n escape_status: parsed[3],\n }\n}\n\nfunction codeTraceBlockFromFinding(\n trajectoryId: string,\n source: AnalystFinding,\n): { block: CodeTraceFailureBlock; trimmedCitations: string[] } {\n const parsed = CODE_TRACE_BLOCK_SUBJECT.exec(source.subject ?? '')\n if (!parsed) {\n throw new Error(\n `CodeTraceBench model finding '${source.finding_id}' must set subject to incorrect-steps-<first>-<last>-<escaped|unescaped>-consequence-<step>, received '${source.subject ?? ''}'`,\n )\n }\n const firstStep = Number(parsed[1])\n const lastStep = Number(parsed[2])\n const consequenceStep = Number(parsed[4])\n const cited = exactFindingSteps(trajectoryId, source)\n // A citation outside [firstStep, lastStep] (typically the consequence step)\n // is trimmed, not fatal: expansion rebuilds per-step evidence, so the block\n // only needs one citation grounding it inside its own range. A finding whose\n // citations ALL fall outside its block has no in-block grounding and is\n // rejected.\n const outOfRange = cited.filter((step) => step < firstStep || step > lastStep)\n if (outOfRange.length === cited.length) {\n throw new Error(\n `CodeTraceBench model finding '${source.finding_id}' cites step ${outOfRange.join(', ')} outside its block ${firstStep}-${lastStep} and no citation falls inside the block`,\n )\n }\n const trimmedCitations = outOfRange.map(\n (step) =>\n `${source.finding_id}: trimmed citation step ${step} outside block ${firstStep}-${lastStep}`,\n )\n return {\n block: {\n firstStep,\n lastStep,\n consequenceStep,\n escapeStatus: parsed[3] as 'escaped' | 'unescaped',\n severity: source.severity,\n claim: source.claim,\n confidence: source.confidence,\n ...(source.rationale === undefined ? {} : { rationale: source.rationale }),\n ...(source.recommended_action === undefined\n ? {}\n : { recommendedAction: source.recommended_action }),\n metadata: { sourceFindingId: source.finding_id },\n },\n trimmedCitations,\n }\n}\n\n/**\n * Expand contiguous failure blocks into one scored finding per member step.\n *\n * The official scorer matches on area plus the exact step evidence URI, so\n * blocks never reach it: every runner reports blocks, and this function turns\n * them into the per-step findings the benchmark defines.\n */\nexport async function expandCodeTraceFailureBlocks(options: {\n trajectoryId: string\n blocks: readonly CodeTraceFailureBlock[]\n store: TraceAnalysisStore\n analystId: string\n producedAt?: string\n signal?: AbortSignal\n}): Promise<{\n findings: AnalystFinding[]\n diagnostics: CodeTraceBlockDiagnostics\n stepBlocks: CodeTraceStepAssignment[]\n}> {\n const diagnostics = emptyCodeTraceBlockDiagnostics()\n diagnostics.reportedBlocks = options.blocks.length\n if (options.blocks.length === 0) return { findings: [], diagnostics, stepBlocks: [] }\n const blocks = acceptCodeTraceBlockShape(options.blocks, diagnostics)\n if (blocks.length === 0) return { findings: [], diagnostics, stepBlocks: [] }\n\n const boundarySteps = blocks.flatMap((block) => [block.firstStep, block.lastStep])\n const derivedSteps = blocks.flatMap((block) => [block.consequenceStep, ...interiorSteps(block)])\n const evidenceByStep = await resolveAssistantStepEvidence({\n trajectoryId: options.trajectoryId,\n steps: boundarySteps,\n optionalSteps: derivedSteps,\n store: options.store,\n ...(options.signal ? { signal: options.signal } : {}),\n })\n\n const byStep = new Map<number, CodeTraceFailureBlock>()\n for (const block of blocks) {\n if (!evidenceByStep.has(block.consequenceStep)) {\n diagnostics.blocksWithoutConsequenceEvidence.push(block)\n continue\n }\n if (block.escapeStatus === 'escaped') diagnostics.escapedBlocks += 1\n for (let step = block.firstStep; step <= block.lastStep; step += 1) {\n if (!evidenceByStep.has(step)) {\n diagnostics.unresolvedBlockInteriorSteps.push(step)\n continue\n }\n if (byStep.has(step)) {\n diagnostics.overlappingBlockSteps.push(step)\n continue\n }\n byStep.set(step, block)\n }\n }\n\n const stepBlocks = [...byStep]\n .sort(([left], [right]) => left - right)\n .map(([step, block]) => ({ step, block }))\n const findings = stepBlocks.map(({ step, block }) =>\n makeFinding({\n analyst_id: options.analystId,\n area: 'incorrect',\n subject: `incorrect-step-${step}`,\n claim: `Step ${step} is incorrect. ${block.claim}`,\n rationale: block.rationale,\n severity: block.severity,\n confidence: block.confidence,\n evidence_refs: [evidenceByStep.get(step)!],\n recommended_action: block.recommendedAction,\n metadata: {\n ...block.metadata,\n block_first_step: block.firstStep,\n block_last_step: block.lastStep,\n block_consequence_step: block.consequenceStep,\n escape_status: block.escapeStatus,\n },\n ...(options.producedAt === undefined ? {} : { produced_at: options.producedAt }),\n id_basis: `incorrect-step-${step}`,\n }),\n )\n return { findings, diagnostics, stepBlocks }\n}\n\n/**\n * Enforce the protocol's per-block and per-case limits without voiding the\n * case: an offending block is dropped and named in `diagnostics.droppedBlocks`\n * while every valid sibling survives. A case whose blocks are ALL invalid ends\n * empty and carries the diagnostic for each drop. Shape is checked before the\n * count, so a malformed block never consumes one of the accepted slots.\n */\nfunction acceptCodeTraceBlockShape(\n blocks: readonly CodeTraceFailureBlock[],\n diagnostics: CodeTraceBlockDiagnostics,\n): CodeTraceFailureBlock[] {\n const accepted: CodeTraceFailureBlock[] = []\n for (const block of blocks) {\n const reason =\n codeTraceBlockShapeViolation(block) ??\n (accepted.length >= MAX_INCORRECT_BLOCKS\n ? `model reported ${blocks.length} failure blocks; the maximum is ${MAX_INCORRECT_BLOCKS}`\n : undefined)\n if (reason) {\n diagnostics.droppedBlocks.push(\n `block ${block.firstStep}-${block.lastStep} (consequence ${block.consequenceStep}): ${reason}`,\n )\n continue\n }\n accepted.push(block)\n }\n return accepted\n}\n\nfunction codeTraceBlockShapeViolation(block: CodeTraceFailureBlock): string | undefined {\n if (block.lastStep < block.firstStep) {\n return `failure block last_step ${block.lastStep} precedes first_step ${block.firstStep}`\n }\n const length = block.lastStep - block.firstStep + 1\n if (length > MAX_INCORRECT_BLOCK_STEPS) {\n return `failure block spans ${length} steps; the maximum is ${MAX_INCORRECT_BLOCK_STEPS}`\n }\n if (block.consequenceStep < block.firstStep) {\n return `failure block consequence_step ${block.consequenceStep} precedes first_step ${block.firstStep}`\n }\n return undefined\n}\n\nfunction interiorSteps(block: CodeTraceFailureBlock): number[] {\n const steps: number[] = []\n for (let step = block.firstStep + 1; step < block.lastStep; step += 1) steps.push(step)\n return steps\n}\n\nfunction emptyCodeTraceBlockDiagnostics(): CodeTraceBlockDiagnostics {\n return {\n reportedBlocks: 0,\n escapedBlocks: 0,\n blocksWithoutConsequenceEvidence: [],\n unresolvedBlockInteriorSteps: [],\n overlappingBlockSteps: [],\n droppedBlocks: [],\n }\n}\n\nfunction exactFindingSteps(trajectoryId: string, finding: AnalystFinding): number[] {\n if (finding.evidence_refs.length === 0) {\n throw new Error(`model finding '${finding.finding_id}' has no step evidence`)\n }\n const steps = finding.evidence_refs.map((evidence) => {\n const parsed = codeTraceStepFromEvidence(evidence.uri)\n if (!parsed || parsed.traceId !== trajectoryId) {\n throw new Error(\n `model finding '${finding.finding_id}' cites non-case evidence '${evidence.uri}'`,\n )\n }\n return parsed.step\n })\n return [...new Set(steps)]\n}\n","import { z } from 'zod'\nimport {\n CostAccountingIncompleteError,\n CostCeilingReachedError,\n CostReservationExceededError,\n} from '../cost-ledger'\nimport { AgentEvalError } from '../errors'\nimport { LlmCallError, LlmResponseError } from '../llm-client'\nimport type { AnalystBenchmarkError } from './benchmark'\n\nexport function publicBenchmarkError(\n error: unknown,\n secrets: readonly string[] = [],\n): AnalystBenchmarkError {\n if (error instanceof LlmCallError) {\n return {\n class: 'LlmCallError',\n code: error.code,\n status: error.status,\n message: `Provider request failed with HTTP ${error.status}.`,\n }\n }\n if (error instanceof LlmResponseError) {\n return {\n class: 'LlmResponseError',\n code: error.code,\n message: 'Provider response did not satisfy the structured output contract.',\n }\n }\n if (error instanceof z.ZodError) {\n return {\n class: 'ModelOutputValidationError',\n message: 'Provider response did not match the benchmark output schema.',\n }\n }\n if (error instanceof SyntaxError) {\n return {\n class: 'ModelOutputParseError',\n message: 'Provider response was not valid JSON.',\n }\n }\n if (\n error instanceof CostCeilingReachedError ||\n error instanceof CostAccountingIncompleteError ||\n error instanceof CostReservationExceededError\n ) {\n return {\n class: error.constructor.name,\n code: error.code,\n message: redactSensitiveText(error.message, secrets),\n }\n }\n if (error instanceof Error && error.name === 'AbortError') {\n return {\n class: 'ProviderTimeoutError',\n message: 'Provider request timed out.',\n }\n }\n if (\n error instanceof Error &&\n /(?:assistant steps?|finding evidence|selected missing|selected unavailable|no readable spans|requires a trace store)/i.test(\n error.message,\n )\n ) {\n return {\n class: 'BenchmarkEvidenceError',\n message: redactSensitiveText(error.message, secrets),\n }\n }\n if (error instanceof AgentEvalError) {\n return {\n class: error.constructor.name,\n code: error.code,\n message: redactSensitiveText(error.message, secrets),\n }\n }\n if (error instanceof Error) {\n return {\n class: error.constructor.name || 'Error',\n message: redactSensitiveText(error.message, secrets),\n }\n }\n return {\n class: 'Error',\n message: 'Benchmark analyst execution failed.',\n }\n}\n\nfunction redactSensitiveText(value: string, secrets: readonly string[]): string {\n let redacted = value\n for (const secret of secrets) {\n if (secret) redacted = redacted.replaceAll(secret, '[REDACTED]')\n }\n redacted = redacted\n .replace(/\\bBearer\\s+[^\\s\"',;]+/gi, 'Bearer [REDACTED]')\n .replace(\n /\\b(api[_-]?key|access[_-]?token|refresh[_-]?token|password|secret)\\b\\s*[:=]\\s*[^\\s\"',;]+/gi,\n '$1=[REDACTED]',\n )\n if (redacted.length <= 500) return redacted\n const head = redacted.slice(0, 180)\n const omitted = redacted.length - 460\n const marker = `...[${omitted} chars omitted]...`\n return `${head}${marker}${redacted.slice(-(500 - head.length - marker.length))}`\n}\n","import type {\n ExternalOptimizerModelCall,\n ExternalOptimizerModelExecutionObservation,\n ExternalOptimizerRunnerCommand,\n} from '../campaign/external-optimizer-contracts'\nimport type { CostLedgerHandle, CustomTokenPricing } from '../cost-ledger'\nimport type { AnalystBenchmarkCase } from './benchmark'\nimport type { VerificationArtifactManifest } from './benchmark-verification-artifacts'\nimport type { AnalystRunInputs } from './types'\n\nexport type PublicAnalystBenchmarkDataset = 'agentrx' | 'codetracebench'\n\n/**\n * Caller-supplied replacement for the recursive runner's analyst instructions.\n * Only the `dspy-rlm` runner accepts one; the direct runner rejects it, and the\n * recursive runner's abstention fallback keeps the stock direct prompt. Every\n * recorded protocol digest for an override run binds the stock protocol digest\n * to `sha256`, so an override run is never confusable with a stock run.\n */\nexport interface AnalystInstructionsOverride {\n /** Complete instruction text used instead of the shipped RLM instructions. */\n readonly text: string\n /** SHA-256 hex digest of `text`. */\n readonly sha256: string\n}\n\n/** Model execution supplied by the package that owns credentials and provider policy. */\nexport interface PublicAnalystBenchmarkModelOwner {\n call: ExternalOptimizerModelCall\n callRef: string\n recordExecution: (observation: ExternalOptimizerModelExecutionObservation) => void\n /** Exact rates when the selected model is absent from Agent Eval's catalog. */\n pricing?: CustomTokenPricing\n}\n\nexport interface PublicAnalystBenchmarkModelConfig {\n /** Caller-owned execution path. Agent Eval never receives provider credentials. */\n call: ExternalOptimizerModelCall\n /** Stable public identity for the caller-owned execution path. */\n callRef: string\n /** Persist every finite execution record returned by the caller-owned path. */\n recordExecution: (observation: ExternalOptimizerModelExecutionObservation) => void\n model: string\n maxOutputTokens: number\n timeoutMs: number\n /** Model request bytes per call. Default: 16 MiB. */\n maxModelRequestBytes?: number\n /** Model response bytes per call. Default: 4 MiB. */\n maxModelResponseBytes?: number\n /** Reasoning tokens billed beyond completion tokens. Default: four times output. */\n maxReasoningTokens?: number\n /** Deadline for one caller-owned model invocation. Default: timeoutMs. */\n modelRequestTimeoutMs?: number\n /** Required when the model is absent from agent-eval's pricing table. */\n pricing?: CustomTokenPricing\n /** Independent per-case recursive-engine spend limit. Default: 1 USD. */\n maxCostUsdPerAnalysis?: number\n /** Replaces the shipped RLM instructions. `dspy-rlm` runner only. */\n instructionsOverride?: AnalystInstructionsOverride\n dspyRlm?: {\n runner?: ExternalOptimizerRunnerCommand\n maxIterations?: number\n maxLlmCalls?: number\n maxToolCalls?: number\n maxOutputChars?: number\n maxModelRequests?: number\n traceToolRequestBytes?: number\n traceToolResponseBytes?: number\n traceToolTimeoutMs?: number\n /**\n * Independent engine runs per case. Above 1 (CodeTraceBench only), the\n * runner scores the step-level majority consensus across all runs instead\n * of a single draw. Default: 1.\n */\n samples?: number\n }\n costLedger?: CostLedgerHandle\n durability?: {\n runIdentitySha256: string\n responseCacheDir: string\n }\n}\n\n/**\n * Model settings the benchmark command records in the run identity. The\n * owner-call pair is present exactly when a model-owner module executes the\n * provider calls (`dspy-rlm` and `direct`); the `prime` analyst owns its own\n * cli-bridge transport and never receives an owner call path.\n */\nexport type PublicAnalystBenchmarkModelSettings = Omit<\n PublicAnalystBenchmarkModelConfig,\n 'call' | 'recordExecution'\n> &\n Partial<Pick<PublicAnalystBenchmarkModelConfig, 'call' | 'recordExecution'>>\n\nexport interface PreparedPublicAnalystBenchmark {\n cases: AnalystBenchmarkCase<AnalystRunInputs>[]\n sourceRowCount: number\n selectedCaseIds: string[]\n labelsSha256: string\n traceFiles: Array<{\n traceId: string\n relativePath: string\n sha256: string\n }>\n verificationArtifacts: VerificationArtifactManifest[]\n selection: PublicBenchmarkSelectionReport\n}\n\nexport interface PublicBenchmarkValueDistribution {\n total: number\n missing: number\n counts: Record<string, number>\n}\n\nexport interface PublicBenchmarkDistributions {\n class: PublicBenchmarkValueDistribution\n agent: PublicBenchmarkValueDistribution\n model: PublicBenchmarkValueDistribution\n difficulty: PublicBenchmarkValueDistribution\n solved: PublicBenchmarkValueDistribution\n}\n\nexport interface PublicBenchmarkSelectionReport {\n method: 'census' | 'deterministic-hash'\n seed: number\n sourceCount: number\n selectedCount: number\n stratified: false\n representativeOfInput: boolean\n source: PublicBenchmarkDistributions\n selected: PublicBenchmarkDistributions\n}\n\nexport function requiredString(value: string, field: string): string {\n const trimmed = value.trim()\n if (!trimmed) throw new TypeError(`${field} must be a non-empty string`)\n return trimmed\n}\n\nexport function positiveSafeInteger(value: number, field: string): number {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new RangeError(`${field} must be a positive safe integer`)\n }\n return value\n}\n\nexport function safeInteger(value: number, field: string): number {\n if (!Number.isSafeInteger(value)) throw new RangeError(`${field} must be a safe integer`)\n return value\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n","import { existsSync, lstatSync, readFileSync } from 'node:fs'\nimport * as nodePath from 'node:path'\nimport { z } from 'zod'\nimport type { CostReceiptInput } from '../cost-ledger'\nimport { ValidationError } from '../errors'\nimport {\n canonicalString,\n hashCanonical,\n withLedgerFileLock,\n writeLedgerFileAtomically,\n} from '../ledger-core'\nimport type { AnalystBenchmarkError } from './benchmark'\n\nconst SHA256 = /^[a-f0-9]{64}$/\n\nconst CostReceiptInputSchema = z\n .object({\n model: z.string().min(1),\n inputTokens: z.number().int().nonnegative(),\n outputTokens: z.number().int().nonnegative(),\n reasoningTokens: z.number().int().nonnegative().optional(),\n cachedTokens: z.number().int().nonnegative().optional(),\n cacheWriteTokens: z.number().int().nonnegative().optional(),\n customTokenPricing: z\n .object({\n inputUsdPerMillion: z.number().nonnegative(),\n cachedInputUsdPerMillion: z.number().nonnegative().optional(),\n cacheWriteUsdPerMillion: z.number().nonnegative().optional(),\n outputUsdPerMillion: z.number().nonnegative(),\n })\n .strict()\n .optional(),\n actualCostUsd: z.number().nonnegative().optional(),\n estimatedCostUsd: z.number().nonnegative().optional(),\n costUnknown: z.boolean().optional(),\n usageUnknown: z.boolean().optional(),\n })\n .strict()\n\nconst BenchmarkErrorSchema = z\n .object({\n class: z.string().min(1),\n message: z.string(),\n code: z.string().min(1).optional(),\n status: z.number().int().min(100).max(599).optional(),\n })\n .strict()\n\nconst ResponseMetadataSchema = z\n .object({\n providerModel: z.string().min(1),\n providerDurationMs: z.number().nonnegative(),\n finishReason: z.string().nullable(),\n producedAt: z.string().datetime(),\n })\n .strict()\n\nconst CacheIdentityShape = {\n kind: z.literal('agent-eval/public-benchmark-model-response'),\n callId: z.string().min(1),\n runIdentitySha256: z.string().regex(SHA256),\n caseId: z.string().min(1),\n repetition: z.number().int().nonnegative(),\n}\n\nconst SuccessCacheEntryWithoutDigestSchema = z\n .object({\n ...CacheIdentityShape,\n status: z.literal('succeeded'),\n response: z.json(),\n metadata: ResponseMetadataSchema,\n receipt: CostReceiptInputSchema,\n })\n .strict()\n\nconst FailureCacheEntryWithoutDigestSchema = z\n .object({\n ...CacheIdentityShape,\n status: z.literal('failed'),\n error: BenchmarkErrorSchema,\n receipt: CostReceiptInputSchema,\n })\n .strict()\n\nconst CacheEntryWithoutDigestSchema = z.discriminatedUnion('status', [\n SuccessCacheEntryWithoutDigestSchema,\n FailureCacheEntryWithoutDigestSchema,\n])\n\nconst CacheEntrySchema = z.discriminatedUnion('status', [\n SuccessCacheEntryWithoutDigestSchema.extend({\n entrySha256: z.string().regex(SHA256),\n }),\n FailureCacheEntryWithoutDigestSchema.extend({\n entrySha256: z.string().regex(SHA256),\n }),\n])\n\ninterface CacheIdentity {\n runIdentitySha256: string\n caseId: string\n repetition: number\n}\n\nexport interface PublicBenchmarkResponseMetadata {\n providerModel: string\n providerDurationMs: number\n finishReason: string | null\n producedAt: string\n}\n\nexport type PublicBenchmarkResponseCacheEntry =\n | (CacheIdentity & {\n kind: 'agent-eval/public-benchmark-model-response'\n callId: string\n status: 'succeeded'\n response: unknown\n metadata: PublicBenchmarkResponseMetadata\n receipt: CostReceiptInput\n entrySha256: string\n })\n | (CacheIdentity & {\n kind: 'agent-eval/public-benchmark-model-response'\n callId: string\n status: 'failed'\n error: AnalystBenchmarkError\n receipt: CostReceiptInput\n entrySha256: string\n })\n\nexport type PublicBenchmarkResponseCacheInput =\n | Omit<Extract<PublicBenchmarkResponseCacheEntry, { status: 'succeeded' }>, 'entrySha256'>\n | Omit<Extract<PublicBenchmarkResponseCacheEntry, { status: 'failed' }>, 'entrySha256'>\n\nexport function publicBenchmarkCallId(identity: CacheIdentity): string {\n assertCacheIdentity(identity)\n const boundIdentity: CacheIdentity = {\n runIdentitySha256: identity.runIdentitySha256,\n caseId: identity.caseId,\n repetition: identity.repetition,\n }\n return `analyst-benchmark-${hashCanonical(boundIdentity).slice('sha256:'.length)}`\n}\n\nexport function readPublicBenchmarkResponseCache(\n cacheDirectory: string,\n identity: CacheIdentity,\n): PublicBenchmarkResponseCacheEntry | undefined {\n const callId = publicBenchmarkCallId(identity)\n const path = responseCachePath(cacheDirectory, callId)\n if (!existsSync(path)) return undefined\n const metadata = lstatSync(path)\n if (!metadata.isFile() || metadata.isSymbolicLink()) {\n throw new ValidationError(`benchmark response cache must be a real file: ${path}`)\n }\n let parsed: unknown\n try {\n parsed = JSON.parse(readFileSync(path, 'utf8'))\n } catch (error) {\n throw new ValidationError(`benchmark response cache contains invalid JSON: ${path}`, {\n cause: error,\n })\n }\n const entry = parseCacheEntry(parsed, path)\n if (\n entry.callId !== callId ||\n entry.runIdentitySha256 !== identity.runIdentitySha256 ||\n entry.caseId !== identity.caseId ||\n entry.repetition !== identity.repetition\n ) {\n throw new ValidationError(`benchmark response cache identity does not match: ${path}`)\n }\n return entry\n}\n\nexport function writePublicBenchmarkResponseCache(\n cacheDirectory: string,\n entry: PublicBenchmarkResponseCacheInput,\n): PublicBenchmarkResponseCacheEntry {\n const expectedCallId = publicBenchmarkCallId(entry)\n if (entry.callId !== expectedCallId) {\n throw new ValidationError('benchmark response cache callId does not match its identity')\n }\n const validated = JSON.parse(\n JSON.stringify(CacheEntryWithoutDigestSchema.parse(entry)),\n ) as z.infer<typeof CacheEntryWithoutDigestSchema>\n const complete = {\n ...validated,\n entrySha256: hashCanonical(validated).slice('sha256:'.length),\n } as PublicBenchmarkResponseCacheEntry\n const path = responseCachePath(cacheDirectory, complete.callId)\n const content = `${canonicalString(complete)}\\n`\n withLedgerFileLock(path, fileContext(), () => {\n if (existsSync(path)) {\n const existing = readPublicBenchmarkResponseCache(cacheDirectory, complete)\n if (!existing || canonicalString(existing) !== canonicalString(complete)) {\n throw new ValidationError(`benchmark response cache conflicts with existing file: ${path}`)\n }\n return\n }\n writeLedgerFileAtomically(path, content, fileContext())\n })\n return complete\n}\n\nfunction parseCacheEntry(value: unknown, path: string): PublicBenchmarkResponseCacheEntry {\n let parsed: z.infer<typeof CacheEntrySchema>\n try {\n parsed = CacheEntrySchema.parse(value)\n } catch (error) {\n throw new ValidationError(`benchmark response cache has an invalid shape: ${path}`, {\n cause: error,\n })\n }\n const { entrySha256, ...withoutDigest } = parsed\n const expected = hashCanonical(withoutDigest).slice('sha256:'.length)\n if (entrySha256 !== expected) {\n throw new ValidationError(`benchmark response cache digest does not match: ${path}`)\n }\n return parsed as PublicBenchmarkResponseCacheEntry\n}\n\nfunction responseCachePath(cacheDirectory: string, callId: string): string {\n const directory = nodePath.resolve(cacheDirectory)\n const path = nodePath.resolve(directory, `${hashCanonical(callId).slice('sha256:'.length)}.json`)\n if (!isPathInsideDirectory(directory, path, nodePath)) {\n throw new ValidationError('benchmark response cache path escapes its directory')\n }\n return path\n}\n\ninterface PathOperations {\n relative(from: string, to: string): string\n isAbsolute(path: string): boolean\n sep: string\n}\n\nexport function isPathInsideDirectory(\n directory: string,\n candidate: string,\n pathOperations: PathOperations = nodePath,\n): boolean {\n const relative = pathOperations.relative(directory, candidate)\n return (\n relative !== '' &&\n relative !== '..' &&\n !relative.startsWith(`..${pathOperations.sep}`) &&\n !pathOperations.isAbsolute(relative)\n )\n}\n\nfunction assertCacheIdentity(identity: CacheIdentity): void {\n if (!SHA256.test(identity.runIdentitySha256)) {\n throw new ValidationError('benchmark response cache requires a SHA-256 run identity')\n }\n if (!identity.caseId.trim()) {\n throw new ValidationError('benchmark response cache requires a case id')\n }\n if (!Number.isSafeInteger(identity.repetition) || identity.repetition < 0) {\n throw new ValidationError('benchmark response cache repetition must be non-negative')\n }\n}\n\nfunction fileContext() {\n return {\n subject: 'benchmark response cache',\n integrityError: (message: string, options?: { cause?: unknown }) =>\n new ValidationError(message, options),\n }\n}\n","/**\n * AnalystDefinition — the declarative unit behind an analyst arm.\n *\n * An arm is one way of EXECUTING an analysis question: a one-shot JSON call, a\n * bridge-reached RLM, a recursive engine with trace tools. What the arm SAYS —\n * the question, the task text, the reply grammar, how evidence reaches the\n * model, the repair-turn and budget terms — is protocol, not execution, so it\n * lives here as one inspectable value. `bindAnalyst` (./bind) compiles a\n * definition plus a transport binding into a runnable arm, and the parity\n * suite holds the compiled arm to the byte against the arm's entry point, so a\n * definition cannot drift from what its arm actually sends.\n *\n * Three rules carried over from the repair-arm comparison contract\n * (trace-repair's `repairArmAsymmetries`), made structural here:\n *\n * one contract the reply grammar is a `ReplyContract` value on the\n * definition, never prose inside a runner body.\n * one repair turn `analystDefinitionAsymmetries` refuses a set whose\n * definitions declare unequal repair turns, because a second\n * attempt is a second sample the other arms never got.\n * declared difference what arms MAY differ in — the evidence projection, the\n * reasoning effort, the budget — is declared per definition\n * and rendered beside the comparison instead of being\n * inferred from two runners' source.\n */\n\nimport { createHash } from 'node:crypto'\nimport type { AgentProfile } from '../agent-profile'\nimport type { TraceAnalysisStore } from '../trace-analyst/store'\nimport type { TraceAnalystSpan } from '../trace-analyst/types'\nimport type { AnalystBenchmarkRunner } from './benchmark'\nimport type { PublicAnalystBenchmarkModelConfig } from './benchmark-public-types'\nimport type { TraceAnalystLimits } from './engine'\nimport { assertEqualDeclarativeTerms } from './equal-terms'\nimport { primeProtocolSha256 } from './prime-protocol'\nimport type { ReplyContract } from './reply-contract'\nimport type { TraceToolGroupName } from './tool-groups'\nimport type { AnalystFinding, AnalystRunInputs } from './types'\n\n// ── Profile fragment ────────────────────────────────────────────────\n\n/**\n * The slice of the canonical `AgentProfile` an analyst definition carries:\n * model hints (pinned model, reasoning effort) and prompt shaping. Transport\n * bindings that own model selection leave `model.default` unset.\n */\nexport type AnalystProfileFragment = Pick<AgentProfile, 'model' | 'prompt'>\n\n// ── Evidence projection ─────────────────────────────────────────────\n\n/**\n * How evidence reaches the model. This is the declared affordance axis of an\n * arm: two arms answering the same question through different projections are\n * comparable only with the difference rendered, never silently.\n */\nexport type EvidenceProjection =\n | {\n readonly mode: 'inline'\n /** Ceiling on serialized evidence characters embedded in one prompt. */\n readonly maxInlineChars: number\n /**\n * Per-attribute byte cap for the reduced refetch when the full\n * projection is oversized. Still oversized after the refetch = refusal,\n * never a silent truncation.\n */\n readonly cappedAttributeBytes: number\n }\n | {\n readonly mode: 'chunked'\n /** Descending per-attribute byte caps tried until the store yields a projection. */\n readonly attributeByteCaps: readonly number[]\n }\n | {\n /** Evidence bound as an engine REPL variable, read through bounded trace tools. */\n readonly mode: 'repl-variable'\n readonly toolGroup: TraceToolGroupName\n }\n | {\n /** Evidence read through agent tool calls only; no REPL. */\n readonly mode: 'agent-tools'\n readonly toolGroup: TraceToolGroupName\n }\n\n// ── Budget and repair declarations ──────────────────────────────────\n\nexport interface AnalystBudgetDeclaration {\n /** Deadline for one model exchange. */\n readonly timeoutMs: number\n /** Provider spend ceiling for one analysis, when the transport meters cost. */\n readonly maxCostUsd?: number\n /** Completion-token cap per model call, when the transport enforces one. */\n readonly maxOutputTokens?: number\n /** Recursive-engine iteration limits (repl-variable / agent-tools projections). */\n readonly engineLimits?: TraceAnalystLimits\n}\n\nexport interface AnalystRepairDeclaration {\n /**\n * Bounded retries a structurally malformed reply earns. Compared definitions\n * must declare the same number: a retry is a second sample.\n */\n readonly turns: number\n}\n\n// ── Evidence bindings (typed ports per projection) ──────────────────\n\nexport interface AnalystRowExpansion {\n findings: AnalystFinding[]\n /** Arm-specific expansion diagnostics recorded in observation metadata. */\n diagnostics?: unknown\n}\n\nexport interface ExpandRowsArgs<TRow> {\n /** Evidence subject the case names (e.g. a trajectory id). */\n subject: string\n rows: readonly TRow[]\n store: TraceAnalysisStore\n analystId: string\n producedAt?: string\n /** Model the provider reported serving, when the transport captures it. */\n providerModel?: string\n signal?: AbortSignal\n}\n\n/** Ports an inline-projection arm binds: prompt framing plus row expansion. */\nexport interface InlineEvidenceBinding<TRow> {\n readonly kind: 'inline'\n subjectFromCaseId(caseId: string): string\n /** Base observation metadata (analysis mode, engine label). */\n readonly baseMetadata: Readonly<Record<string, unknown>>\n /**\n * Line introducing the inlined evidence. Throws when the projected spans\n * cannot ground the question (e.g. no assistant step spans).\n */\n header(subject: string, spans: readonly TraceAnalystSpan[]): string\n /** Material appended after the evidence. */\n trailer(subject: string, spans: readonly TraceAnalystSpan[]): string\n expandRows(args: ExpandRowsArgs<TRow>): Promise<AnalystRowExpansion>\n}\n\n/** Ports a chunked-projection one-shot arm binds. */\nexport interface ChunkedEvidenceBinding<TRow> {\n readonly kind: 'chunked'\n subjectFromCaseId(caseId: string): string\n readonly baseMetadata: Readonly<Record<string, unknown>>\n /** Actor name paid calls are attributed to in the cost ledger. */\n readonly costActor: string\n /** Cost-ledger phase paid calls settle under. */\n readonly costPhase: string\n /** Compose the user message around the rendered evidence. */\n userMessage(rendered: string): string\n expandRows(args: ExpandRowsArgs<TRow>): Promise<AnalystRowExpansion>\n /** Ground accepted findings against the store; throws on unresolvable evidence. */\n verifyFindings?(args: {\n subject: string\n findings: readonly AnalystFinding[]\n store: TraceAnalysisStore\n signal?: AbortSignal\n }): Promise<void>\n}\n\n/** Majority-vote ports for a multi-sample repl-variable arm. */\nexport interface ReplVariableConsensusPort<TAssignment, TBlock> {\n /** Vote across per-sample assignments; returns voted blocks plus the decision record. */\n vote(samples: ReadonlyArray<readonly TAssignment[]>): {\n blocks: readonly TBlock[]\n decision: unknown\n }\n /** Expand voted blocks into findings grounded in the store. */\n expand(args: {\n subject: string\n blocks: readonly TBlock[]\n store: TraceAnalysisStore\n analystId: string\n producedAt: string\n signal?: AbortSignal\n }): Promise<AnalystRowExpansion>\n /** Per-sample observation record (accepted blocks, member steps). */\n sampleRecord(assignments: readonly TAssignment[]): Record<string, unknown>\n}\n\n/** Ports a repl-variable (recursive engine) arm binds. */\nexport interface ReplVariableEvidenceBinding<TAssignment = unknown, TBlock = unknown> {\n readonly kind: 'repl-variable'\n /** Identity of the trace-analyst definition the engine runs. */\n readonly traceAnalystId: string\n subjectFromCaseId(caseId: string): string\n readonly baseMetadata: Readonly<Record<string, unknown>>\n /** Metadata stamped on every finding the arm emits. */\n readonly findingBaseMetadata: Readonly<Record<string, unknown>>\n /** Cost-ledger phase paid calls settle under. */\n readonly costPhase: string\n /** Row metadata derived from the finding's subject grammar. */\n metadataFromSubject?(subject: string | undefined): Record<string, unknown> | undefined\n /** Map raw engine rows into scored findings grounded in the store. */\n adapt(args: {\n subject: string\n findings: readonly AnalystFinding[]\n analystId: string\n store: TraceAnalysisStore\n signal?: AbortSignal\n }): Promise<{ findings: AnalystFinding[]; stepBlocks?: TAssignment[]; diagnostics?: unknown }>\n /** Multi-sample majority consensus; required when the arm runs samples > 1. */\n consensus?: ReplVariableConsensusPort<TAssignment, TBlock>\n /** Second-opinion arm invoked when the engine submits no finding at all. */\n abstentionFallback(\n config: PublicAnalystBenchmarkModelConfig,\n ): AnalystBenchmarkRunner<AnalystRunInputs>\n}\n\nexport type AnalystEvidenceBinding<TRow, TAssignment = unknown, TBlock = unknown> =\n | InlineEvidenceBinding<TRow>\n | ChunkedEvidenceBinding<TRow>\n | ReplVariableEvidenceBinding<TAssignment, TBlock>\n\n// ── The definition ──────────────────────────────────────────────────\n\nexport interface AnalystDefinition<TRow = unknown, TAssignment = unknown, TBlock = unknown> {\n /** Arm identity — appears as the runner id and in every finding. */\n readonly id: string\n readonly description: string\n readonly version: string\n /** Finding area the arm's expansion stamps, when uniform per arm. */\n readonly area?: string\n readonly profile: AnalystProfileFragment\n /** User-facing question. Empty when the task text is the whole ask. */\n readonly question: string\n /** Task definition / instruction text sent beside the question. */\n readonly taskDefinition?: string\n readonly projection: EvidenceProjection\n readonly replyContract: ReplyContract<TRow>\n /**\n * Numeric limits the contract states (row caps, width caps). They enter the\n * protocol digest; insertion order is digest-bearing because the digest\n * serializes with `JSON.stringify`.\n */\n readonly contractLimits: Readonly<Record<string, number>>\n readonly budget: AnalystBudgetDeclaration\n readonly repair: AnalystRepairDeclaration\n /**\n * Digest the bound arm stamps on observations. For an inline definition this\n * equals `analystDefinitionProtocolSha256`; benchmark arms that record a\n * shared dataset-level digest carry that digest here instead.\n */\n readonly protocolSha256: string\n readonly binding: AnalystEvidenceBinding<TRow, TAssignment, TBlock>\n}\n\n/**\n * Thrown at bind time when a definition asks for something no strategy can\n * compile — an unknown projection × transport pair, a repair-turn count the\n * exchange machinery cannot grant, a reasoning effort the arm cannot map. The\n * message names the construct so an expressiveness gap is a loud, attributable\n * failure instead of a silently narrowed protocol.\n */\nexport class AnalystExpressivenessError extends Error {}\n\n// ── Protocol identity ───────────────────────────────────────────────\n\n/**\n * Digest of everything a definition can send to its model. An inline\n * definition hashes under the historical prime-protocol domain, so its digest\n * equals the digest its bespoke arm always recorded; other projections hash\n * under the definition domain.\n */\nexport function analystDefinitionProtocolSha256<TRow, TAssignment, TBlock>(\n definition: AnalystDefinition<TRow, TAssignment, TBlock>,\n): string {\n const { projection, replyContract } = definition\n if (projection.mode === 'inline') {\n return primeProtocolSha256({\n question: definition.question,\n ...(definition.taskDefinition === undefined\n ? {}\n : { taskDefinition: definition.taskDefinition }),\n contractLines: replyContract.contractLines,\n repairContractLines: replyContract.repairContractLines,\n limits: {\n ...definition.contractLimits,\n maxInlineTrajectoryChars: projection.maxInlineChars,\n chunkedProjectionAttributeByteCap: projection.cappedAttributeBytes,\n },\n })\n }\n return createHash('sha256')\n .update(\n JSON.stringify({\n kind: 'analyst-definition-protocol',\n mode: projection.mode,\n question: definition.question,\n taskDefinition: definition.taskDefinition ?? null,\n contractLines: replyContract.contractLines,\n repairContractLines: replyContract.repairContractLines,\n limits: definition.contractLimits,\n projection:\n projection.mode === 'chunked'\n ? { attributeByteCaps: projection.attributeByteCaps }\n : { toolGroup: projection.toolGroup },\n }),\n )\n .digest('hex')\n}\n\n// ── Equal-terms comparison ──────────────────────────────────────────\n\n/** One definition's declared difference from the compared set. */\nexport interface AnalystDefinitionAsymmetry {\n readonly id: string\n readonly projectionMode: EvidenceProjection['mode']\n readonly reasoningEffort: NonNullable<AgentProfile['model']>['reasoningEffort'] | null\n readonly timeoutMs: number\n readonly maxCostUsd: number | null\n readonly maxOutputTokens: number | null\n /** The digest the arm records on observations. */\n readonly protocolSha256: string\n /** The definition's own protocol identity. */\n readonly definitionSha256: string\n}\n\nexport interface AnalystDefinitionAsymmetryReport {\n readonly ids: readonly string[]\n /** Repair turns every compared definition declares. */\n readonly repairTurns: number\n /** The one projection mode all definitions share, or null when they differ. */\n readonly sharedProjectionMode: EvidenceProjection['mode'] | null\n readonly asymmetries: readonly AnalystDefinitionAsymmetry[]\n}\n\n/**\n * Refuse a set of definitions that cannot be compared on equal terms, and\n * render what still differs between the ones that can. The hard rule is the\n * repair turn: a malformed reply must earn the same number of retries in every\n * arm, because a retry is a second sample. Projection, reasoning effort, and\n * budget differences are declared and reported, never hidden.\n */\nexport function analystDefinitionAsymmetries(\n definitions: ReadonlyArray<AnalystDefinition<unknown, unknown, unknown>>,\n): AnalystDefinitionAsymmetryReport {\n const { ids, repairTurns } = assertEqualDeclarativeTerms(\n 'analyst definition',\n definitions.map((definition) => ({ id: definition.id, repairTurns: definition.repair.turns })),\n )\n const firstMode = definitions[0]!.projection.mode\n const sharedProjectionMode = definitions.every(\n (definition) => definition.projection.mode === firstMode,\n )\n ? firstMode\n : null\n return {\n ids,\n repairTurns,\n sharedProjectionMode,\n asymmetries: definitions.map((definition) => ({\n id: definition.id,\n projectionMode: definition.projection.mode,\n reasoningEffort: definition.profile.model?.reasoningEffort ?? null,\n timeoutMs: definition.budget.timeoutMs,\n maxCostUsd: definition.budget.maxCostUsd ?? null,\n maxOutputTokens: definition.budget.maxOutputTokens ?? null,\n protocolSha256: definition.protocolSha256,\n definitionSha256: analystDefinitionProtocolSha256(definition),\n })),\n }\n}\n","import { randomUUID } from 'node:crypto'\nimport { z } from 'zod'\nimport {\n type ExternalOptimizerModelProxy,\n runWithCleanup,\n startExternalOptimizerModelProxy,\n} from '../campaign/external-optimizer-process'\nimport {\n CostAccountingIncompleteError,\n CostCallConflictError,\n CostCeilingReachedError,\n CostLedger,\n type CostLedgerHandle,\n CostLedgerPersistenceError,\n type CostReceipt,\n CostReceiptCaptureError,\n type CostReceiptInput,\n CostReservationExceededError,\n} from '../cost-ledger'\nimport { callLlmJson, type LlmCallRequest, type LlmClientOptions } from '../llm-client'\nimport { resolveModelPricing } from '../metrics'\nimport type { TraceAnalysisStore } from '../trace-analyst/store'\nimport type { AnalystBenchmarkRunner } from './benchmark'\nimport { agentRxPredictionsToFindings } from './benchmark-datasets'\nimport {\n resolveAssistantStepEvidence,\n validateCodeTraceFindingEvidence,\n} from './benchmark-evidence-validation'\nimport {\n type CodeTraceBlockDiagnostics,\n type CodeTraceFailureBlock,\n expandCodeTraceFailureBlocks,\n} from './benchmark-public-adapters'\nimport { publicBenchmarkError } from './benchmark-public-errors'\nimport {\n MAX_INCORRECT_BLOCK_STEPS,\n MAX_INCORRECT_BLOCKS,\n PUBLIC_BENCHMARK_ENVELOPE_CONTRACT,\n publicBenchmarkFieldContract,\n publicBenchmarkProtocolSha256,\n publicBenchmarkTaskPrompt,\n TRACE_PROJECTION_ATTRIBUTE_BYTE_CAPS,\n} from './benchmark-public-prompt'\nimport {\n type PublicAnalystBenchmarkDataset,\n type PublicAnalystBenchmarkModelConfig,\n positiveSafeInteger,\n requiredString,\n} from './benchmark-public-types'\nimport {\n type PublicBenchmarkResponseCacheEntry,\n publicBenchmarkCallId,\n readPublicBenchmarkResponseCache,\n writePublicBenchmarkResponseCache,\n} from './benchmark-response-cache'\nimport { type AnalystDefinition, AnalystExpressivenessError } from './definition'\nimport { decodeReplyRows, type ReplyContract } from './reply-contract'\nimport type { AnalystFinding, AnalystRunInputs } from './types'\nimport { usageReceiptFromCostLedger } from './usage-receipt'\n\nexport {\n CODE_TRACE_BENCH_ANALYST_PROMPT,\n publicBenchmarkProtocolSha256,\n} from './benchmark-public-prompt'\n\n/**\n * One-shot JSON baseline arm. Not a recursive trace analyst.\n *\n * The arm is expressed as an `AnalystDefinition`\n * (`publicDirectAnalystDefinition`): the task text, field and envelope\n * contracts, the descending projection ladder, and the zero-repair declaration\n * are definition content, and `createPublicBenchmarkDirectRunner` is a thin\n * shell that builds the definition and runs it through the chunked strategy\n * below — the same strategy `bindAnalyst` (./bind) dispatches to.\n */\n\nexport interface PublicDirectDefinitionArgs {\n /** Whole-analysis deadline (`config.timeoutMs`). */\n timeoutMs: number\n /** Completion-token cap per call (`config.maxOutputTokens`). */\n maxOutputTokens: number\n /** Per-case provider spend ceiling (`config.maxCostUsdPerAnalysis`). */\n maxCostUsd: number\n}\n\n/** The direct arm as a declarative unit for one public dataset. */\nexport function publicDirectAnalystDefinition(\n dataset: PublicAnalystBenchmarkDataset,\n args: PublicDirectDefinitionArgs,\n): AnalystDefinition<PublicBenchmarkModelPrediction> {\n const actor =\n dataset === 'agentrx' ? 'agentrx-root-cause-localizer' : 'codetracebench-step-localizer'\n const outputAdapter =\n dataset === 'agentrx' ? 'agentrx-taxonomy-and-root-step' : 'codetracebench-incorrect-block'\n return {\n id: 'direct',\n description: 'One-shot JSON baseline over the caller-owned model path.',\n version: '1.0.0',\n area: dataset === 'agentrx' ? 'root-cause' : 'incorrect',\n // One-shot JSON transport runs with thinking disabled.\n profile: { model: { reasoningEffort: 'none' } },\n // The task text is the whole ask: the one-shot prompt carries no question line.\n question: '',\n taskDefinition: publicBenchmarkTaskPrompt(dataset),\n projection: { mode: 'chunked', attributeByteCaps: TRACE_PROJECTION_ATTRIBUTE_BYTE_CAPS },\n replyContract: directReplyContract(dataset),\n contractLimits:\n dataset === 'agentrx'\n ? { maxFindings: 1 }\n : { maxBlocks: MAX_INCORRECT_BLOCKS, maxBlockSteps: MAX_INCORRECT_BLOCK_STEPS },\n budget: {\n timeoutMs: args.timeoutMs,\n maxCostUsd: args.maxCostUsd,\n maxOutputTokens: args.maxOutputTokens,\n },\n repair: { turns: 0 },\n protocolSha256: publicBenchmarkProtocolSha256(dataset),\n binding: {\n kind: 'chunked',\n subjectFromCaseId: (caseId) => trajectoryIdFromCaseId(dataset, caseId),\n baseMetadata: { analysisMode: 'direct-baseline', outputAdapter },\n costActor: actor,\n costPhase: 'analyst.public-benchmark',\n userMessage: (rendered) => `TRACE DATA:\\n${rendered}\\n\\nReturn the analysis JSON object.`,\n async expandRows({ subject, rows, store, analystId, producedAt, providerModel, signal }) {\n const converted = await publicBenchmarkPredictionsToFindings({\n dataset,\n trajectoryId: subject,\n predictions: rows,\n store,\n analystId,\n providerModel: requiredString(providerModel ?? '', 'finding providerModel'),\n producedAt: requiredString(producedAt ?? '', 'finding producedAt'),\n ...(signal ? { signal } : {}),\n })\n return { findings: converted.findings, diagnostics: converted.diagnostics }\n },\n ...(dataset === 'codetracebench'\n ? {\n verifyFindings: async (args: {\n subject: string\n findings: readonly AnalystFinding[]\n store: TraceAnalysisStore\n signal?: AbortSignal\n }) => {\n await validateCodeTraceFindingEvidence({\n trajectoryId: args.subject,\n findings: [...args.findings],\n store: args.store,\n ...(args.signal ? { signal: args.signal } : {}),\n })\n },\n }\n : {}),\n },\n }\n}\n\n/** Thin shell: validate config, declare the definition, run the chunked strategy. */\nexport function createPublicBenchmarkDirectRunner(\n dataset: PublicAnalystBenchmarkDataset,\n config: PublicAnalystBenchmarkModelConfig,\n): AnalystBenchmarkRunner<AnalystRunInputs> {\n if (config.instructionsOverride) {\n throw new Error(\n 'the direct runner executes only the stock protocol; an instructions override requires the dspy-rlm runner',\n )\n }\n const maxOutputTokens = positiveSafeInteger(config.maxOutputTokens, 'maxOutputTokens')\n const timeoutMs = positiveSafeInteger(config.timeoutMs, 'timeoutMs')\n return runChunkedAnalystDefinition(\n publicDirectAnalystDefinition(dataset, {\n timeoutMs,\n maxOutputTokens,\n maxCostUsd: config.maxCostUsdPerAnalysis ?? 1,\n }),\n config,\n )\n}\n\n// ── Chunked one-shot execution strategy ─────────────────────────────\n\n/**\n * Compile a chunked-projection definition into a runnable one-shot JSON arm\n * over the caller-owned model path. Prompt content, the projection ladder,\n * the reply grammar, and the budget declaration come from the definition;\n * caching, cost settlement, and the model proxy are transport machinery.\n */\nexport function runChunkedAnalystDefinition<TRow>(\n definition: AnalystDefinition<TRow>,\n config: PublicAnalystBenchmarkModelConfig,\n): AnalystBenchmarkRunner<AnalystRunInputs> {\n const { projection, binding, replyContract } = definition\n if (projection.mode !== 'chunked' || binding.kind !== 'chunked') {\n throw new AnalystExpressivenessError(\n `the chunked one-shot strategy compiles only chunked projections; definition ` +\n `'${definition.id}' declares projection '${projection.mode}' with a '${binding.kind}' binding`,\n )\n }\n if (config.instructionsOverride) {\n throw new Error(\n 'the direct runner executes only the stock protocol; an instructions override requires the dspy-rlm runner',\n )\n }\n if (definition.repair.turns !== 0) {\n throw new AnalystExpressivenessError(\n `the one-shot JSON exchange grants no repair turn; definition '${definition.id}' ` +\n `declares ${definition.repair.turns}`,\n )\n }\n const reasoningEffort = definition.profile.model?.reasoningEffort\n if (reasoningEffort !== 'none') {\n throw new AnalystExpressivenessError(\n `the one-shot JSON strategy runs with thinking disabled and can express only reasoning ` +\n `effort 'none'; definition '${definition.id}' declares '${reasoningEffort}'`,\n )\n }\n if (!replyContract.parseEnvelope) {\n throw new AnalystExpressivenessError(\n `the one-shot JSON strategy needs a strict reply envelope; definition ` +\n `'${definition.id}' declares no parseEnvelope`,\n )\n }\n if (definition.taskDefinition === undefined) {\n throw new AnalystExpressivenessError(\n `the one-shot JSON strategy composes its system prompt from the task definition; ` +\n `definition '${definition.id}' declares none`,\n )\n }\n const model = requiredString(config.model, 'model')\n const callRef = requiredString(config.callRef, 'callRef')\n if (typeof config.call !== 'function') throw new TypeError('call must be a function')\n if (typeof config.recordExecution !== 'function') {\n throw new TypeError('recordExecution must be a function')\n }\n const maxOutputTokens = positiveSafeInteger(config.maxOutputTokens, 'maxOutputTokens')\n const timeoutMs = positiveSafeInteger(config.timeoutMs, 'timeoutMs')\n const maxCostUsd = config.maxCostUsdPerAnalysis ?? 1\n assertDeclaredBudget(definition, { timeoutMs, maxOutputTokens, maxCostUsd })\n const maxReasoningTokens = config.maxReasoningTokens ?? maxOutputTokens * 4\n const maxModelRequestBytes = config.maxModelRequestBytes ?? 16 * 1024 * 1024\n const maxModelResponseBytes = config.maxModelResponseBytes ?? 4 * 1024 * 1024\n const modelRequestTimeoutMs = config.modelRequestTimeoutMs ?? timeoutMs\n const pricing = config.pricing ?? pricingForModel(model)\n const costLedger = config.costLedger ?? new CostLedger()\n const durability = config.durability\n ? {\n runIdentitySha256: requiredString(\n config.durability.runIdentitySha256,\n 'durability.runIdentitySha256',\n ),\n responseCacheDir: requiredString(\n config.durability.responseCacheDir,\n 'durability.responseCacheDir',\n ),\n }\n : undefined\n // The composed system prompt is definition content, sealed at bind time.\n const systemPrompt = [definition.taskDefinition, ...replyContract.contractLines].join('\\n\\n')\n return {\n id: definition.id,\n async analyze(input, context) {\n const trajectoryId = binding.subjectFromCaseId(context.caseId)\n const costTags = {\n analystId: binding.costActor,\n benchmarkCaseId: context.caseId,\n benchmarkRepetition: String(context.repetition),\n }\n let rawPredictions: TRow[] = []\n let rejectedRows: string[] = []\n let modelFindings: AnalystFinding[] = []\n let providerModel = model\n let producedAt: string | undefined\n let modelMetadata: Record<string, unknown> = {\n ...binding.baseMetadata,\n protocolSha256: definition.protocolSha256,\n callRef,\n }\n try {\n if (!input.traceStore) {\n throw new Error(`chunked analyst '${definition.id}' requires a trace store`)\n }\n const preparedContext = await prepareSingleTraceContext(\n input.traceStore,\n context,\n projection.attributeByteCaps,\n )\n if (preparedContext === undefined) {\n throw new Error(`trace '${trajectoryId}' has no readable spans`)\n }\n const request: LlmCallRequest = {\n model,\n messages: [\n {\n role: 'system',\n content: systemPrompt,\n },\n {\n role: 'user',\n content: binding.userMessage(preparedContext),\n },\n ],\n jsonMode: true,\n thinking: 'disabled',\n maxTokens: maxOutputTokens,\n timeoutMs: modelRequestTimeoutMs,\n }\n const cacheIdentity = durability\n ? {\n runIdentitySha256: durability.runIdentitySha256,\n caseId: context.caseId,\n repetition: context.repetition,\n }\n : undefined\n const callId = cacheIdentity ? publicBenchmarkCallId(cacheIdentity) : undefined\n const cached = cacheIdentity\n ? readPublicBenchmarkResponseCache(durability!.responseCacheDir, cacheIdentity)\n : undefined\n if (cached) {\n const receipt = settleCachedResponse(costLedger, cached)\n modelMetadata = {\n ...modelMetadata,\n responseSource: 'durable-cache',\n cost: costReceiptMetadata(receipt),\n }\n if (cached.status === 'failed') {\n return {\n findings: [],\n usage: usageReceiptFromCostLedger(costLedger, {\n channel: 'analyst',\n tags: costTags,\n }),\n error: cached.error,\n metadata: modelMetadata,\n }\n }\n const response = decodeReplyRows(replyContract, cached.response)\n rawPredictions = response.rows\n rejectedRows = response.rejected.map((entry) => entry.reason)\n providerModel = cached.metadata.providerModel\n producedAt = cached.metadata.producedAt\n modelMetadata = {\n ...modelMetadata,\n ...response.extras,\n providerModel: cached.metadata.providerModel,\n providerDurationMs: cached.metadata.providerDurationMs,\n finishReason: cached.metadata.finishReason,\n }\n } else {\n assertNoSettledResponseWithoutCache(costLedger, callId)\n const providerCallId = callId ?? `analyst-benchmark-${randomUUID()}`\n let modelProxy: ExternalOptimizerModelProxy | undefined\n const completed = await runWithCleanup({\n label: 'public benchmark direct model resources',\n run: async () => {\n modelProxy = await startExternalOptimizerModelProxy({\n call: config.call,\n callRef,\n recordExecution: config.recordExecution,\n model,\n budget: {\n maxCostUsd,\n maxRequests: 1,\n maxRequestBytes: maxModelRequestBytes,\n maxResponseBytes: maxModelResponseBytes,\n maxOutputTokensPerRequest: maxOutputTokens,\n maxReasoningTokensPerRequest: maxReasoningTokens,\n pricing,\n requestTimeoutMs: modelRequestTimeoutMs,\n },\n costLedger,\n channel: 'analyst',\n phase: binding.costPhase,\n actor: binding.costActor,\n tags: costTags,\n callId: providerCallId,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n // The only endpoint this client ever targets is the loopback\n // model proxy started above: `modelProxy.baseUrl` is\n // `http://127.0.0.1:<port>/v1` with an ephemeral token, and the\n // caller-owned execution owner behind it makes the paid call.\n // agent-eval issues no provider request here.\n const llmOptions: LlmClientOptions = {\n baseUrl: modelProxy.baseUrl,\n apiKey: modelProxy.apiKey,\n maximumAttempts: 1,\n jsonSchemaTransport: 'json-object',\n jsonPayloadMode: 'exact',\n thinking: 'disabled',\n }\n try {\n const completed = await callLlmJson<unknown>(request, {\n ...llmOptions,\n ...(context.signal ? { signal: context.signal } : {}),\n idempotencyKey: providerCallId,\n })\n const response = decodeReplyRows(replyContract, completed.value)\n const responseProducedAt = new Date().toISOString()\n const receipt = requiredSettledReceipt(costLedger, providerCallId)\n if (cacheIdentity) {\n writePublicBenchmarkResponseCache(durability!.responseCacheDir, {\n kind: 'agent-eval/public-benchmark-model-response',\n ...cacheIdentity,\n callId: providerCallId,\n status: 'succeeded',\n // Cache the provider's own payload, not the parse result: a\n // resume re-parses this value, so it must stay exactly what\n // the contract accepts.\n response: completed.value,\n metadata: {\n providerModel: completed.result.model,\n providerDurationMs: completed.result.durationMs,\n finishReason: completed.result.finishReason ?? null,\n producedAt: responseProducedAt,\n },\n receipt: cacheReceiptInput(receipt),\n })\n }\n modelProxy.assertExecutionComplete()\n return { ...completed, response, producedAt: responseProducedAt, receipt }\n } catch (error) {\n const controlFailure = modelProxy.failures().find(isPaidCallControlError)\n if (controlFailure) throw controlFailure\n const receipt = settledReceipt(costLedger, providerCallId)\n if (cacheIdentity) {\n if (receipt) {\n writePublicBenchmarkResponseCache(durability!.responseCacheDir, {\n kind: 'agent-eval/public-benchmark-model-response',\n ...cacheIdentity,\n callId: providerCallId,\n status: 'failed',\n error: publicBenchmarkError(error, []),\n receipt: cacheReceiptInput(receipt),\n })\n }\n }\n throw error\n }\n },\n cleanup: async () => {\n await modelProxy?.close()\n },\n })\n const response = completed.response\n rawPredictions = response.rows\n rejectedRows = response.rejected.map((entry) => entry.reason)\n providerModel = completed.result.model\n producedAt = completed.producedAt\n modelMetadata = {\n ...modelMetadata,\n responseSource: 'provider',\n ...response.extras,\n providerModel: completed.result.model,\n providerDurationMs: completed.result.durationMs,\n finishReason: completed.result.finishReason ?? null,\n cost: costReceiptMetadata(completed.receipt),\n }\n }\n\n const converted = await binding.expandRows({\n subject: trajectoryId,\n rows: rawPredictions,\n store: input.traceStore,\n analystId: definition.id,\n providerModel,\n producedAt: requiredString(producedAt ?? '', 'finding producedAt'),\n ...(context.signal ? { signal: context.signal } : {}),\n })\n modelFindings = converted.findings\n if (converted.diagnostics) {\n modelMetadata = {\n ...modelMetadata,\n blockDiagnostics: {\n ...(converted.diagnostics as Record<string, unknown>),\n rejectedBlocks: rejectedRows,\n },\n }\n }\n if (binding.verifyFindings) {\n await binding.verifyFindings({\n subject: trajectoryId,\n findings: modelFindings,\n store: input.traceStore,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n }\n return {\n findings: modelFindings,\n usage: usageReceiptFromCostLedger(costLedger, {\n channel: 'analyst',\n tags: costTags,\n }),\n metadata: modelMetadata,\n }\n } catch (error) {\n if (context.signal?.aborted) throw error\n if (isPaidCallControlError(error)) throw error\n return {\n findings: [],\n usage: usageReceiptFromCostLedger(costLedger, {\n channel: 'analyst',\n tags: costTags,\n }),\n error: publicBenchmarkError(error, []),\n metadata: {\n ...modelMetadata,\n rawPredictions,\n acceptedFindings: modelFindings,\n },\n }\n }\n },\n }\n}\n\n/** A definition that declares one budget while the transport runs another is refused. */\nfunction assertDeclaredBudget<TRow>(\n definition: AnalystDefinition<TRow>,\n effective: { timeoutMs: number; maxOutputTokens: number; maxCostUsd: number },\n): void {\n const declared = definition.budget\n if (\n declared.timeoutMs !== effective.timeoutMs ||\n declared.maxOutputTokens !== effective.maxOutputTokens ||\n declared.maxCostUsd !== effective.maxCostUsd\n ) {\n throw new AnalystExpressivenessError(\n `definition '${definition.id}' declares budget ${JSON.stringify(declared)} but the bound ` +\n `transport runs ${JSON.stringify(effective)}; the declaration must state what executes`,\n )\n }\n}\n\nfunction settleCachedResponse(\n costLedger: CostLedgerHandle,\n cached: PublicBenchmarkResponseCacheEntry,\n): CostReceipt {\n const settled = costLedger.list().find((receipt) => receipt.callId === cached.callId)\n const pending = costLedger.listPending?.().find((record) => record.callId === cached.callId)\n if (settled && pending) {\n throw new CostCallConflictError(\n `benchmark response '${cached.callId}' is both pending and settled`,\n { callId: cached.callId },\n )\n }\n const receipt = pending\n ? costLedger.reconcile(cached.callId, cached.receipt, {\n ...(cached.status === 'failed' ? { failed: true } : {}),\n })\n : settled\n if (!receipt) {\n throw new CostCallConflictError(\n `benchmark response cache '${cached.callId}' has no matching cost record`,\n { callId: cached.callId },\n )\n }\n assertCacheReceiptMatches(cached, receipt)\n return receipt\n}\n\nfunction assertNoSettledResponseWithoutCache(\n costLedger: CostLedgerHandle,\n callId: string | undefined,\n): void {\n if (!callId) return\n if (costLedger.list().some((receipt) => receipt.callId === callId)) {\n throw new CostCallConflictError(\n `settled benchmark call '${callId}' has no durable response cache`,\n { callId },\n )\n }\n}\n\nfunction assertCacheReceiptMatches(\n cached: PublicBenchmarkResponseCacheEntry,\n receipt: CostReceipt,\n): void {\n const expected = cached.receipt\n const mismatch =\n receipt.callId !== cached.callId ||\n receipt.model !== expected.model ||\n receipt.inputTokens !== expected.inputTokens ||\n receipt.outputTokens !== expected.outputTokens ||\n (receipt.reasoningTokens ?? 0) !== (expected.reasoningTokens ?? 0) ||\n (receipt.cachedTokens ?? 0) !== (expected.cachedTokens ?? 0) ||\n (receipt.cacheWriteTokens ?? 0) !== (expected.cacheWriteTokens ?? 0) ||\n (expected.actualCostUsd !== undefined && receipt.actualCostUsd !== expected.actualCostUsd) ||\n (expected.estimatedCostUsd !== undefined &&\n receipt.estimatedCostUsd !== expected.estimatedCostUsd) ||\n (expected.costUnknown === true && !receipt.costUnknown) ||\n (expected.usageUnknown === true && !receipt.usageUnknown) ||\n (cached.status === 'succeeded' && receipt.error !== undefined) ||\n (cached.status === 'failed' && receipt.error === undefined)\n if (mismatch) {\n throw new CostCallConflictError(\n `benchmark response cache receipt does not match cost record '${cached.callId}'`,\n { callId: cached.callId, receipt },\n )\n }\n}\n\nfunction isPaidCallControlError(error: unknown): boolean {\n return (\n error instanceof CostAccountingIncompleteError ||\n error instanceof CostCallConflictError ||\n error instanceof CostCeilingReachedError ||\n error instanceof CostLedgerPersistenceError ||\n error instanceof CostReceiptCaptureError ||\n error instanceof CostReservationExceededError\n )\n}\n\nfunction settledReceipt(costLedger: CostLedgerHandle, callId: string): CostReceipt | undefined {\n return costLedger.list().find((receipt) => receipt.callId === callId)\n}\n\nfunction requiredSettledReceipt(costLedger: CostLedgerHandle, callId: string): CostReceipt {\n const receipt = settledReceipt(costLedger, callId)\n if (!receipt) {\n throw new CostAccountingIncompleteError(\n `caller-owned model call '${callId}' produced no cost receipt`,\n )\n }\n return receipt\n}\n\nfunction cacheReceiptInput(receipt: CostReceipt): CostReceiptInput {\n const usage = {\n model: receipt.model,\n inputTokens: receipt.inputTokens,\n outputTokens: receipt.outputTokens,\n ...(receipt.reasoningTokens === undefined ? {} : { reasoningTokens: receipt.reasoningTokens }),\n ...(receipt.cachedTokens === undefined ? {} : { cachedTokens: receipt.cachedTokens }),\n ...(receipt.cacheWriteTokens === undefined\n ? {}\n : { cacheWriteTokens: receipt.cacheWriteTokens }),\n ...(receipt.usageUnknown === undefined ? {} : { usageUnknown: receipt.usageUnknown }),\n }\n if (receipt.costUnknown) return { ...usage, costUnknown: true }\n if (receipt.actualCostUsd !== undefined) {\n return { ...usage, actualCostUsd: receipt.actualCostUsd }\n }\n if (receipt.estimatedCostUsd !== undefined) {\n return { ...usage, estimatedCostUsd: receipt.estimatedCostUsd }\n }\n if (receipt.pricing) {\n return {\n ...usage,\n customTokenPricing: {\n inputUsdPerMillion: receipt.pricing.inputUsdPerThousand * 1_000,\n ...(receipt.pricing.cachedInputUsdPerThousand === undefined\n ? {}\n : { cachedInputUsdPerMillion: receipt.pricing.cachedInputUsdPerThousand * 1_000 }),\n ...(receipt.pricing.cacheWriteUsdPerThousand === undefined\n ? {}\n : { cacheWriteUsdPerMillion: receipt.pricing.cacheWriteUsdPerThousand * 1_000 }),\n outputUsdPerMillion: receipt.pricing.outputUsdPerThousand * 1_000,\n },\n }\n }\n return { ...usage, estimatedCostUsd: receipt.costUsd }\n}\n\nfunction costReceiptMetadata(receipt: CostReceipt): Record<string, unknown> {\n if (receipt.actualCostUsd !== undefined) {\n return { source: 'provider', actualCostUsd: receipt.actualCostUsd }\n }\n if (receipt.estimatedCostUsd !== undefined) {\n return { source: 'external-estimate', estimatedCostUsd: receipt.estimatedCostUsd }\n }\n if (receipt.pricing) {\n return {\n source: 'agent-eval-model-pricing',\n estimatedCostUsd: receipt.costUsd,\n ratesPerThousandTokens: receipt.pricing,\n }\n }\n return {\n source: 'unknown',\n estimatedCostUsd: null,\n }\n}\n\nfunction pricingForModel(model: string): NonNullable<PublicAnalystBenchmarkModelConfig['pricing']> {\n const pricing = resolveModelPricing(model)\n if (!pricing) {\n throw new Error(\n `no pricing is configured for '${model}'; provide PublicAnalystBenchmarkModelConfig.pricing`,\n )\n }\n return {\n inputUsdPerMillion: pricing.input * 1_000,\n outputUsdPerMillion: pricing.output * 1_000,\n }\n}\n\nconst ModelSeveritySchema = z.enum(['critical', 'high', 'medium', 'low', 'info'])\nconst AgentRxPredictionSchema = z\n .object({\n step: z.number().int().positive(),\n severity: ModelSeveritySchema,\n claim: z.string().min(1),\n confidence: z.number().min(0).max(1),\n rationale: z.string().min(1).optional(),\n recommended_action: z.string().min(1).optional(),\n })\n .strict()\nconst CodeTraceBlockPredictionSchema = z\n .object({\n first_step: z.number().int().positive(),\n last_step: z.number().int().positive(),\n consequence_step: z.number().int().positive(),\n escape_status: z.enum(['escaped', 'unescaped']),\n severity: ModelSeveritySchema,\n claim: z.string().min(1),\n confidence: z.number().min(0).max(1),\n rationale: z.string().min(1).optional(),\n recommended_action: z.string().min(1).optional(),\n })\n .strict()\n .superRefine((block, ctx) => {\n if (block.last_step < block.first_step) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `failure block last_step ${block.last_step} precedes first_step ${block.first_step}`,\n })\n return\n }\n const length = block.last_step - block.first_step + 1\n if (length > MAX_INCORRECT_BLOCK_STEPS) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `failure block spans ${length} steps; the maximum is ${MAX_INCORRECT_BLOCK_STEPS}`,\n })\n }\n // The damage a block caused can surface anywhere from the block's own first\n // step onward: a step carries both the assistant action and the observation\n // it produced, and a long block often shows its damage mid-block rather than\n // at the end. Only a consequence before the block began is incoherent.\n if (block.consequence_step < block.first_step) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `failure block consequence_step ${block.consequence_step} precedes first_step ${block.first_step}`,\n })\n }\n })\nconst AgentRxCategorySchema = z.enum([\n 'instruction-plan-adherence-failure',\n 'invention-of-new-information',\n 'invalid-invocation',\n 'misinterpretation-of-tool-output-handoff-failure',\n 'intent-plan-misalignment',\n 'underspecified-user-intent',\n 'intent-not-supported',\n 'guardrails-triggered',\n 'system-failure',\n 'inconclusive',\n])\nconst CodeTraceModelResponseEnvelopeSchema = z\n .object({\n report: z.string().min(1).max(4_000),\n findings: z.array(z.unknown()).max(MAX_INCORRECT_BLOCKS),\n })\n .strict()\nconst AgentRxModelResponseSchema = z\n .object({\n report: z.string().min(1).max(4_000),\n findings: z\n .array(AgentRxPredictionSchema.extend({ category: AgentRxCategorySchema }).strict())\n .max(1),\n })\n .strict()\n\ntype AgentRxModelPrediction = z.infer<typeof AgentRxPredictionSchema> & {\n category?: z.infer<typeof AgentRxCategorySchema>\n}\ntype CodeTraceModelPrediction = z.infer<typeof CodeTraceBlockPredictionSchema>\nexport type PublicBenchmarkModelPrediction = AgentRxModelPrediction | CodeTraceModelPrediction\n\n/**\n * The one-shot reply grammar per dataset. The envelope is the contract and\n * stays strict. Individual CodeTraceBench blocks are model output: one\n * malformed block must not void a case whose remaining blocks are usable and\n * whose provider call is already paid for, so rows decode individually and\n * every rejection is reported.\n */\nfunction directReplyContract(\n dataset: PublicAnalystBenchmarkDataset,\n): ReplyContract<PublicBenchmarkModelPrediction> {\n if (dataset === 'agentrx') {\n return {\n rowsField: 'findings',\n contractLines: [publicBenchmarkFieldContract('agentrx'), PUBLIC_BENCHMARK_ENVELOPE_CONTRACT],\n repairContractLines: [],\n parseEnvelope(value) {\n const parsed = AgentRxModelResponseSchema.parse(value)\n return { rows: parsed.findings, extras: { report: parsed.report } }\n },\n decodeRow(row) {\n // The strict envelope already validated every row.\n return { ok: true, row: row as AgentRxModelPrediction }\n },\n }\n }\n return {\n rowsField: 'findings',\n contractLines: [\n publicBenchmarkFieldContract('codetracebench'),\n PUBLIC_BENCHMARK_ENVELOPE_CONTRACT,\n ],\n repairContractLines: [],\n parseEnvelope(value) {\n const envelope = CodeTraceModelResponseEnvelopeSchema.parse(value)\n return { rows: envelope.findings, extras: { report: envelope.report } }\n },\n decodeRow(row, index) {\n const parsed = CodeTraceBlockPredictionSchema.safeParse(row)\n if (parsed.success) return { ok: true, row: parsed.data }\n return {\n ok: false,\n reason: `block ${index}: ${parsed.error.issues\n .map((issue) => `${issue.path.join('.') || '<root>'} ${issue.message}`)\n .join('; ')}`,\n }\n },\n whenAllRowsRejected: 'fail',\n allRejectedMessage: 'every reported failure block was malformed',\n }\n}\n\nasync function publicBenchmarkPredictionsToFindings(options: {\n dataset: PublicAnalystBenchmarkDataset\n trajectoryId: string\n predictions: readonly PublicBenchmarkModelPrediction[]\n store: TraceAnalysisStore\n analystId: string\n providerModel: string\n producedAt: string\n signal?: AbortSignal\n}): Promise<{ findings: AnalystFinding[]; diagnostics: CodeTraceBlockDiagnostics | undefined }> {\n if (options.predictions.length === 0 && options.dataset === 'agentrx') {\n return { findings: [], diagnostics: undefined }\n }\n if (options.dataset === 'agentrx') {\n const prediction = options.predictions[0]!\n if (!('step' in prediction)) {\n throw new Error('AgentRx model output must name a single root-cause step')\n }\n if (!prediction.category) {\n throw new Error('AgentRx model output is missing its failure category')\n }\n const evidenceByStep = await resolveAssistantStepEvidence({\n trajectoryId: options.trajectoryId,\n steps: [prediction.step],\n store: options.store,\n ...(options.signal ? { signal: options.signal } : {}),\n })\n const [finding] = agentRxPredictionsToFindings(\n options.trajectoryId,\n [\n {\n failure_case: prediction.category,\n step_number: prediction.step,\n description: prediction.rationale ?? prediction.claim,\n },\n ],\n {\n analystId: options.analystId,\n producedAt: options.producedAt,\n confidence: prediction.confidence,\n },\n )\n if (!finding) throw new Error('AgentRx output adapter produced no root-cause finding')\n return {\n findings: [\n {\n ...finding,\n evidence_refs: [evidenceByStep.get(prediction.step)!],\n metadata: {\n ...finding.metadata,\n model: options.providerModel,\n },\n },\n ],\n diagnostics: undefined,\n }\n }\n\n const blocks = options.predictions.map((prediction): CodeTraceFailureBlock => {\n if (!('first_step' in prediction)) {\n throw new Error('CodeTraceBench model output must report first_step/last_step failure blocks')\n }\n return {\n firstStep: prediction.first_step,\n lastStep: prediction.last_step,\n consequenceStep: prediction.consequence_step,\n escapeStatus: prediction.escape_status,\n severity: prediction.severity,\n claim: prediction.claim,\n confidence: prediction.confidence,\n ...(prediction.rationale === undefined ? {} : { rationale: prediction.rationale }),\n ...(prediction.recommended_action === undefined\n ? {}\n : { recommendedAction: prediction.recommended_action }),\n metadata: { analysis_mode: 'direct-baseline', model: options.providerModel },\n }\n })\n return expandCodeTraceFailureBlocks({\n trajectoryId: options.trajectoryId,\n blocks,\n store: options.store,\n analystId: options.analystId,\n producedAt: options.producedAt,\n ...(options.signal ? { signal: options.signal } : {}),\n })\n}\n\nasync function prepareSingleTraceContext(\n store: TraceAnalysisStore,\n context: { signal?: AbortSignal },\n attributeByteCaps: readonly number[],\n): Promise<string | undefined> {\n const storeContext = context.signal ? { signal: context.signal } : undefined\n const overview = await store.getOverview(undefined, storeContext)\n if (overview.total_traces !== 1 || overview.sample_trace_ids.length !== 1) {\n throw new Error(\n `public model benchmark requires exactly one trace, received ${overview.total_traces}`,\n )\n }\n const traceId = overview.sample_trace_ids[0]!\n for (const perAttributeByteCap of attributeByteCaps) {\n const viewed = await store.viewTrace(\n {\n trace_id: traceId,\n per_attribute_byte_cap: perAttributeByteCap,\n },\n storeContext,\n )\n if (!viewed.spans) continue\n return JSON.stringify({\n trace_id: traceId,\n per_attribute_byte_cap: perAttributeByteCap,\n spans: viewed.spans,\n })\n }\n return undefined\n}\n\nfunction trajectoryIdFromCaseId(dataset: PublicAnalystBenchmarkDataset, caseId: string): string {\n const prefix = dataset === 'agentrx' ? 'agentrx:' : 'codetrace:'\n if (!caseId.startsWith(prefix) || caseId.length === prefix.length) {\n throw new Error(`unexpected ${dataset} benchmark case id '${caseId}'`)\n }\n return caseId.slice(prefix.length)\n}\n","import type { CodeTraceFailureBlock, CodeTraceStepAssignment } from './benchmark-public-adapters'\n\n/**\n * One sample block's contribution to a consensus block, in the shape the\n * decision record persists: block coordinates plus how many consensus steps\n * the block's accepted steps cover.\n */\nexport interface CodeTraceConsensusContributor {\n sample: number\n firstStep: number\n lastStep: number\n consequenceStep: number\n confidence: number\n overlapSteps: number\n}\n\nexport interface CodeTraceConsensusBlockDecision {\n firstStep: number\n lastStep: number\n consequenceStep: number\n escapeStatus: 'escaped' | 'unescaped'\n /** Mean confidence across every contributor. */\n confidence: number\n donor: CodeTraceConsensusContributor\n contributors: CodeTraceConsensusContributor[]\n}\n\n/** The full voting record: every step any sample accepted, and what won. */\nexport interface CodeTraceConsensusDecision {\n samples: number\n threshold: number\n stepVotes: Array<{ step: number; votes: number; kept: boolean }>\n blocks: CodeTraceConsensusBlockDecision[]\n}\n\n/**\n * Step-level majority vote across independent analyst samples.\n *\n * Each sample's accepted, evidence-resolved steps count as one vote per step.\n * Steps present in at least ceil(k/2) samples survive; surviving steps are\n * reassembled into contiguous consensus blocks. Each consensus block borrows\n * its metadata (consequence step, escape status, claim, severity, rationale)\n * from the contributing sample block with the largest step overlap — ties go\n * to the higher-confidence block, then to the earlier sample — while its\n * confidence is the mean across every contributor. The returned blocks still\n * pass through the shared expansion, so width, count, and evidence rules are\n * enforced there, never assumed here.\n */\nexport function consensusCodeTraceBlocks(\n sampleAssignments: ReadonlyArray<readonly CodeTraceStepAssignment[]>,\n): { blocks: CodeTraceFailureBlock[]; decision: CodeTraceConsensusDecision } {\n const samples = sampleAssignments.length\n if (samples < 2) {\n throw new RangeError('step-level consensus requires at least two samples')\n }\n const threshold = Math.ceil(samples / 2)\n const votesByStep = new Map<number, number>()\n sampleAssignments.forEach((assignments, sample) => {\n const seen = new Set<number>()\n for (const { step } of assignments) {\n if (!Number.isSafeInteger(step) || step < 0) {\n throw new RangeError(`sample ${sample} assigned a non-step value: ${step}`)\n }\n if (seen.has(step)) {\n throw new Error(`sample ${sample} assigned step ${step} to more than one block`)\n }\n seen.add(step)\n votesByStep.set(step, (votesByStep.get(step) ?? 0) + 1)\n }\n })\n const stepVotes = [...votesByStep]\n .sort(([left], [right]) => left - right)\n .map(([step, votes]) => ({ step, votes, kept: votes >= threshold }))\n const keptSteps = stepVotes.filter((entry) => entry.kept).map((entry) => entry.step)\n\n const blocks: CodeTraceFailureBlock[] = []\n const blockDecisions: CodeTraceConsensusBlockDecision[] = []\n for (const segment of contiguousSegments(keptSteps)) {\n const contributors = segmentContributors(sampleAssignments, segment)\n // Every kept step carries >= threshold sample votes, so a segment always\n // has at least one contributor.\n const donor = contributors.reduce(betterDonor)\n const confidence =\n contributors.reduce((sum, contributor) => sum + contributor.block.confidence, 0) /\n contributors.length\n blocks.push({\n firstStep: segment.firstStep,\n lastStep: segment.lastStep,\n consequenceStep: donor.block.consequenceStep,\n escapeStatus: donor.block.escapeStatus,\n severity: donor.block.severity,\n claim: donor.block.claim,\n confidence,\n ...(donor.block.rationale === undefined ? {} : { rationale: donor.block.rationale }),\n ...(donor.block.recommendedAction === undefined\n ? {}\n : { recommendedAction: donor.block.recommendedAction }),\n metadata: {\n ...donor.block.metadata,\n consensus_samples: samples,\n consensus_threshold: threshold,\n consensus_contributors: contributors.length,\n consensus_donor_sample: donor.sample,\n },\n })\n blockDecisions.push({\n firstStep: segment.firstStep,\n lastStep: segment.lastStep,\n consequenceStep: donor.block.consequenceStep,\n escapeStatus: donor.block.escapeStatus,\n confidence,\n donor: publicContributor(donor),\n contributors: contributors.map(publicContributor),\n })\n }\n return { blocks, decision: { samples, threshold, stepVotes, blocks: blockDecisions } }\n}\n\ninterface SegmentContributor {\n sample: number\n block: CodeTraceFailureBlock\n overlapSteps: number\n}\n\n/**\n * All (sample, block) pairs whose accepted steps intersect the segment,\n * ordered by sample then by first overlapping step — the deterministic\n * tie-break order for donor selection.\n */\nfunction segmentContributors(\n sampleAssignments: ReadonlyArray<readonly CodeTraceStepAssignment[]>,\n segment: { firstStep: number; lastStep: number },\n): SegmentContributor[] {\n const contributors: SegmentContributor[] = []\n sampleAssignments.forEach((assignments, sample) => {\n const overlapByBlock = new Map<CodeTraceFailureBlock, number>()\n for (const { step, block } of assignments) {\n if (step < segment.firstStep || step > segment.lastStep) continue\n overlapByBlock.set(block, (overlapByBlock.get(block) ?? 0) + 1)\n }\n for (const [block, overlapSteps] of overlapByBlock) {\n contributors.push({ sample, block, overlapSteps })\n }\n })\n return contributors\n}\n\nfunction betterDonor(left: SegmentContributor, right: SegmentContributor): SegmentContributor {\n if (right.overlapSteps !== left.overlapSteps) {\n return right.overlapSteps > left.overlapSteps ? right : left\n }\n if (right.block.confidence !== left.block.confidence) {\n return right.block.confidence > left.block.confidence ? right : left\n }\n // Remaining ties keep the earlier contributor: lower sample index, then the\n // block whose first overlapping step comes first (construction order).\n return left\n}\n\nfunction publicContributor(contributor: SegmentContributor): CodeTraceConsensusContributor {\n return {\n sample: contributor.sample,\n firstStep: contributor.block.firstStep,\n lastStep: contributor.block.lastStep,\n consequenceStep: contributor.block.consequenceStep,\n confidence: contributor.block.confidence,\n overlapSteps: contributor.overlapSteps,\n }\n}\n\nfunction contiguousSegments(\n sortedSteps: readonly number[],\n): Array<{ firstStep: number; lastStep: number }> {\n const segments: Array<{ firstStep: number; lastStep: number }> = []\n for (const step of sortedSteps) {\n const current = segments[segments.length - 1]\n if (current && step === current.lastStep + 1) {\n current.lastStep = step\n continue\n }\n segments.push({ firstStep: step, lastStep: step })\n }\n return segments\n}\n","import {\n CostAccountingIncompleteError,\n CostCallConflictError,\n CostCeilingReachedError,\n CostLedger,\n CostLedgerPersistenceError,\n CostReceiptCaptureError,\n CostReservationExceededError,\n type CustomTokenPricing,\n} from '../cost-ledger'\nimport { resolveModelPricing } from '../metrics'\nimport type { AnalystBenchmarkOutput, AnalystBenchmarkRunner } from './benchmark'\nimport { effectiveAnalystProtocolSha256 } from './benchmark-instructions-override'\nimport {\n adaptPublicBenchmarkFindings,\n type CodeTraceFailureBlock,\n type CodeTraceStepAssignment,\n codeTraceBlockMetadataFromSubject,\n expandCodeTraceFailureBlocks,\n} from './benchmark-public-adapters'\nimport { consensusCodeTraceBlocks } from './benchmark-public-consensus'\nimport { publicBenchmarkError } from './benchmark-public-errors'\nimport { createPublicBenchmarkDirectRunner } from './benchmark-public-model'\nimport { publicBenchmarkRlmInstructions } from './benchmark-public-prompt'\nimport type {\n PublicAnalystBenchmarkDataset,\n PublicAnalystBenchmarkModelConfig,\n} from './benchmark-public-types'\nimport {\n type AnalystDefinition,\n AnalystExpressivenessError,\n type ReplVariableConsensusPort,\n} from './definition'\nimport { createDspyRlmTraceEngine, type DspyRlmTraceEngineOptions } from './dspy-rlm-engine'\nimport type { TraceAnalystLimits } from './engine'\nimport {\n evidenceRefsFromRawFinding,\n RAW_FINDING_SCHEMA_PROMPT,\n type RawAnalystFinding,\n RawAnalystFindingSchema,\n} from './finding-signature'\nimport { runTraceAnalyst, type TraceAnalystDefinition } from './kind-factory'\nimport type { AnalystFinding, AnalystRunInputs, AnalystUsageReceipt } from './types'\nimport { makeFinding } from './types'\nimport { usageReceiptFromCostLedger } from './usage-receipt'\n\n/**\n * Public benchmark candidate that runs the actual recursive trace analyst.\n *\n * The arm is expressed as an `AnalystDefinition` (`publicRlmAnalystDefinition`):\n * the question, the recursive instructions (stock or override), the tool group,\n * the engine iteration limits, and the budget are definition content, and\n * `createPublicBenchmarkRlmRunner` is a thin shell that builds the definition\n * and runs it through the repl-variable strategy below — the same strategy\n * `bindAnalyst` (./bind) dispatches to.\n */\n\nexport interface PublicRlmDefinitionArgs {\n /** Effective recursive instructions: the override text or the stock prompt. */\n instructions: string\n /** Digest the arm records: the stock digest, bound to any override. */\n protocolSha256: string\n /** Whole-analysis deadline (`config.timeoutMs`). */\n timeoutMs: number\n /** Controller completion-token cap (`config.maxOutputTokens`). */\n maxOutputTokens: number\n /** Per-case engine spend ceiling (`config.maxCostUsdPerAnalysis`). */\n maxCostUsd: number\n /** Resolved recursive-engine iteration limits. */\n engineLimits: TraceAnalystLimits\n}\n\n/** The dspy-rlm arm as a declarative unit for one public dataset. */\nexport function publicRlmAnalystDefinition(\n dataset: PublicAnalystBenchmarkDataset,\n args: PublicRlmDefinitionArgs,\n): AnalystDefinition<RawAnalystFinding, CodeTraceStepAssignment> {\n return {\n id: 'dspy-rlm',\n description:\n dataset === 'agentrx'\n ? 'Localizes the first unrecoverable root-cause step.'\n : 'Localizes every incorrect state-changing assistant step.',\n version: '1.0.0',\n area: dataset === 'agentrx' ? 'root-cause' : 'incorrect',\n // The caller-owned model path selects the model; the engine owns reasoning.\n profile: {},\n question:\n dataset === 'agentrx'\n ? 'What is the first unrecoverable root cause in this failed trajectory?'\n : 'Which assistant steps are incorrect under the CodeTraceBench definition?',\n taskDefinition: args.instructions,\n projection: { mode: 'repl-variable', toolGroup: 'singleTrace' },\n // Declarative restatement of the engine's row grammar: the engine enforces\n // the same `RawAnalystFindingSchema` on every submitted row, and the\n // schema prompt below is what `runTraceAnalyst` splices into the\n // instructions. The bounded typed repair lives inside the engine's control\n // adapter, so no repair grammar restatement exists.\n replyContract: {\n rowsField: 'findings',\n contractLines: [RAW_FINDING_SCHEMA_PROMPT],\n repairContractLines: [],\n decodeRow(row) {\n const parsed = RawAnalystFindingSchema.safeParse(row)\n if (parsed.success) return { ok: true, row: parsed.data }\n return {\n ok: false,\n reason: parsed.error.issues\n .map((issue) => `${issue.path.join('.')}: ${issue.message}`)\n .join('; '),\n }\n },\n },\n contractLimits: {\n maxIterations: args.engineLimits.maxIterations,\n maxLlmCalls: args.engineLimits.maxLlmCalls,\n maxToolCalls: args.engineLimits.maxToolCalls,\n maxOutputChars: args.engineLimits.maxOutputChars,\n },\n budget: {\n timeoutMs: args.timeoutMs,\n maxCostUsd: args.maxCostUsd,\n maxOutputTokens: args.maxOutputTokens,\n engineLimits: args.engineLimits,\n },\n // One bounded typed-extraction repair inside the engine's control adapter,\n // mirroring the prime arm's single repair turn.\n repair: { turns: 1 },\n protocolSha256: args.protocolSha256,\n binding: {\n kind: 'repl-variable',\n traceAnalystId: dataset === 'agentrx' ? 'agentrx-dspy-rlm' : 'codetracebench-dspy-rlm',\n subjectFromCaseId: (caseId) => trajectoryIdFromCaseId(dataset, caseId),\n baseMetadata: { analysisMode: 'recursive', engine: 'dspy-rlm' },\n findingBaseMetadata: { analysis_mode: 'recursive', engine: 'dspy-rlm' },\n costPhase: 'analyst.public-benchmark.dspy-rlm',\n ...(dataset === 'codetracebench'\n ? { metadataFromSubject: codeTraceBlockMetadataFromSubject }\n : {}),\n async adapt({ subject, findings, analystId, store, signal }) {\n return adaptPublicBenchmarkFindings({\n dataset,\n trajectoryId: subject,\n findings: [...findings],\n analystId,\n store,\n ...(signal ? { signal } : {}),\n })\n },\n ...(dataset === 'codetracebench' ? { consensus: codeTraceConsensusPort() } : {}),\n abstentionFallback: (fallbackConfig) =>\n createPublicBenchmarkDirectRunner(dataset, fallbackConfig),\n },\n }\n}\n\n/** Step-level majority consensus on the CodeTraceBench block grammar. */\nfunction codeTraceConsensusPort(): ReplVariableConsensusPort<\n CodeTraceStepAssignment,\n CodeTraceFailureBlock\n> {\n return {\n vote(samples) {\n const consensus = consensusCodeTraceBlocks(samples.map((sample) => [...sample]))\n return { blocks: consensus.blocks, decision: consensus.decision }\n },\n async expand({ subject, blocks, store, analystId, producedAt, signal }) {\n const expanded = await expandCodeTraceFailureBlocks({\n trajectoryId: subject,\n blocks,\n store,\n analystId,\n producedAt,\n ...(signal ? { signal } : {}),\n })\n return { findings: expanded.findings, diagnostics: expanded.diagnostics }\n },\n sampleRecord(assignments) {\n return {\n blocks: sampleBlockRecords(assignments),\n steps: assignments.map((assignment) => assignment.step),\n }\n },\n }\n}\n\n/** Thin shell: validate config, declare the definition, run the repl-variable strategy. */\nexport function createPublicBenchmarkRlmRunner(\n dataset: PublicAnalystBenchmarkDataset,\n config: PublicAnalystBenchmarkModelConfig,\n): AnalystBenchmarkRunner<AnalystRunInputs> {\n const samples = config.dspyRlm?.samples ?? 1\n if (!Number.isSafeInteger(samples) || samples < 1) {\n throw new RangeError('dspyRlm.samples must be a positive safe integer')\n }\n if (samples > 1 && dataset !== 'codetracebench') {\n throw new Error(\n 'dspyRlm.samples > 1 requires the codetracebench dataset; step-level consensus is defined on its block grammar',\n )\n }\n return runReplVariableAnalystDefinition(\n publicRlmAnalystDefinition(dataset, {\n instructions: config.instructionsOverride?.text ?? publicBenchmarkRlmInstructions(dataset),\n protocolSha256: effectiveAnalystProtocolSha256(dataset, config.instructionsOverride),\n timeoutMs: config.timeoutMs,\n maxOutputTokens: config.maxOutputTokens,\n maxCostUsd: config.maxCostUsdPerAnalysis ?? 1,\n engineLimits: rlmEngineLimits(config),\n }),\n config,\n )\n}\n\n/** Engine iteration limits with this arm's defaults applied. */\nexport function rlmEngineLimits(config: PublicAnalystBenchmarkModelConfig): TraceAnalystLimits {\n return {\n maxIterations: config.dspyRlm?.maxIterations ?? 14,\n maxLlmCalls: config.dspyRlm?.maxLlmCalls ?? 8,\n maxToolCalls: config.dspyRlm?.maxToolCalls ?? 80,\n maxOutputChars: config.dspyRlm?.maxOutputChars ?? 8_000,\n }\n}\n\n// ── Repl-variable execution strategy ────────────────────────────────\n\n/**\n * Compile a repl-variable definition into a runnable recursive-engine arm over\n * the caller-owned model path. The question, instructions, tool group, and\n * iteration limits come from the definition; the engine, model proxy, sampling\n * loop, and abstention floor are transport machinery.\n */\nexport function runReplVariableAnalystDefinition(\n definition: AnalystDefinition<RawAnalystFinding, CodeTraceStepAssignment>,\n config: PublicAnalystBenchmarkModelConfig,\n): AnalystBenchmarkRunner<AnalystRunInputs> {\n const { projection, binding } = definition\n if (projection.mode !== 'repl-variable' || binding.kind !== 'repl-variable') {\n throw new AnalystExpressivenessError(\n `the repl-variable strategy compiles only repl-variable projections; definition ` +\n `'${definition.id}' declares projection '${projection.mode}' with a '${binding.kind}' binding`,\n )\n }\n const instructions = definition.taskDefinition\n if (instructions === undefined) {\n throw new AnalystExpressivenessError(\n `the repl-variable strategy runs the definition's task text as engine instructions; ` +\n `definition '${definition.id}' declares none`,\n )\n }\n if (\n config.instructionsOverride !== undefined &&\n config.instructionsOverride.text !== instructions\n ) {\n throw new AnalystExpressivenessError(\n `definition '${definition.id}' declares instructions that differ from the transport's ` +\n 'instructionsOverride; one text must execute',\n )\n }\n const area = definition.area\n if (area === undefined) {\n throw new AnalystExpressivenessError(\n `the repl-variable strategy stamps the definition's area on every finding; definition ` +\n `'${definition.id}' declares none`,\n )\n }\n const limits = definition.budget.engineLimits\n if (limits === undefined) {\n throw new AnalystExpressivenessError(\n `the repl-variable strategy needs declared engine limits; definition ` +\n `'${definition.id}' declares none`,\n )\n }\n const effectiveLimits = rlmEngineLimits(config)\n if (\n limits.maxIterations !== effectiveLimits.maxIterations ||\n limits.maxLlmCalls !== effectiveLimits.maxLlmCalls ||\n limits.maxToolCalls !== effectiveLimits.maxToolCalls ||\n limits.maxOutputChars !== effectiveLimits.maxOutputChars\n ) {\n throw new AnalystExpressivenessError(\n `definition '${definition.id}' declares engine limits ${JSON.stringify(limits)} but the ` +\n `bound transport runs ${JSON.stringify(effectiveLimits)}; the declaration must state what executes`,\n )\n }\n const costLedger = config.costLedger ?? new CostLedger()\n const samples = config.dspyRlm?.samples ?? 1\n if (!Number.isSafeInteger(samples) || samples < 1) {\n throw new RangeError('dspyRlm.samples must be a positive safe integer')\n }\n if (samples > 1 && binding.consensus === undefined) {\n throw new AnalystExpressivenessError(\n `samples > 1 needs a consensus port; definition '${definition.id}' declares none`,\n )\n }\n const pricing = config.pricing ?? pricingForModel(config.model)\n const engine = createDspyRlmTraceEngine({\n call: config.call,\n callRef: config.callRef,\n recordExecution: config.recordExecution,\n model: config.model,\n maxOutputTokens: config.maxOutputTokens,\n timeoutMs: config.timeoutMs,\n maxCostUsd: config.maxCostUsdPerAnalysis ?? 1,\n pricing,\n ...(config.maxReasoningTokens === undefined\n ? {}\n : { maxReasoningTokens: config.maxReasoningTokens }),\n ...(config.maxModelRequestBytes === undefined\n ? {}\n : { maxModelRequestBytes: config.maxModelRequestBytes }),\n ...(config.maxModelResponseBytes === undefined\n ? {}\n : { maxModelResponseBytes: config.maxModelResponseBytes }),\n ...(config.modelRequestTimeoutMs === undefined\n ? {}\n : { modelRequestTimeoutMs: config.modelRequestTimeoutMs }),\n ...(config.dspyRlm?.maxModelRequests === undefined\n ? {}\n : { maxModelRequests: config.dspyRlm.maxModelRequests }),\n ...(config.dspyRlm?.traceToolRequestBytes === undefined &&\n config.dspyRlm?.traceToolResponseBytes === undefined\n ? {}\n : {\n traceToolLimits: {\n ...(config.dspyRlm?.traceToolRequestBytes === undefined\n ? {}\n : { maxRequestBytes: config.dspyRlm.traceToolRequestBytes }),\n ...(config.dspyRlm?.traceToolResponseBytes === undefined\n ? {}\n : { maxResponseBytes: config.dspyRlm.traceToolResponseBytes }),\n },\n }),\n ...(config.dspyRlm?.traceToolTimeoutMs === undefined\n ? {}\n : { traceToolTimeoutMs: config.dspyRlm.traceToolTimeoutMs }),\n ...(config.dspyRlm?.runner ? { runner: config.dspyRlm.runner } : {}),\n } satisfies DspyRlmTraceEngineOptions)\n const protocolSha256 = definition.protocolSha256\n const traceDefinition: TraceAnalystDefinition = {\n id: binding.traceAnalystId,\n description: definition.description,\n area,\n version: definition.version,\n question: definition.question,\n instructions,\n toolGroup: projection.toolGroup,\n limits,\n }\n // Abstention floor: shares this arm's cost ledger so a fallback call's spend\n // lands under the same case and repetition tags as the engine's calls. The\n // fallback always runs the stock direct prompt — an instructions override\n // replaces only the recursive instructions, and the effective protocol digest\n // binds the stock digest (covering this fallback prompt) to the override.\n const { instructionsOverride: _rlmOnlyOverride, ...directConfig } = config\n void _rlmOnlyOverride\n const abstentionFallbackRunner = binding.abstentionFallback({ ...directConfig, costLedger })\n\n return {\n id: definition.id,\n async analyze(input, context) {\n const trajectoryId = binding.subjectFromCaseId(context.caseId)\n const tags = {\n benchmarkCaseId: context.caseId,\n benchmarkRepetition: String(context.repetition),\n }\n let usage: AnalystUsageReceipt | undefined\n let rawFindings: AnalystFinding[] = []\n try {\n if (!input.traceStore) {\n throw new Error(`repl-variable analyst '${definition.id}' requires a trace store`)\n }\n if (samples > 1) {\n const store = input.traceStore\n const caseUsageFilter = { channel: 'analyst' as const, tags }\n const sampleRuns: Array<Record<string, unknown>> = []\n const sampleAssignments: CodeTraceStepAssignment[][] = []\n let totalModelCalls = 0\n let totalToolCalls = 0\n for (let sample = 0; sample < samples; sample += 1) {\n let sampleUsage: AnalystUsageReceipt | undefined\n const completed = await runTraceAnalyst({\n definition: traceDefinition,\n engine,\n store,\n context: {\n runId: context.caseId,\n // A distinct correlation id per sample tags each sample's\n // provider calls individually in the shared ledger, while the\n // case and repetition tags keep all k samples' spend — and a\n // fallback's — on this one case.\n correlationId: `${context.caseId}:${context.repetition}:sample-${sample}`,\n costLedger,\n costPhase: binding.costPhase,\n tags,\n recordUsage: (receipt) => {\n sampleUsage = receipt\n usage = usageReceiptFromCostLedger(costLedger, caseUsageFilter)\n },\n signal: context.signal,\n },\n })\n const producedAt = new Date().toISOString()\n const sampleFindings = completed.findings.map((finding) =>\n makeFinding({\n analyst_id: definition.id,\n area,\n subject: finding.subject,\n claim: finding.claim,\n rationale: finding.rationale,\n severity: finding.severity,\n confidence: finding.confidence,\n evidence_refs: evidenceRefsFromRawFinding(finding),\n recommended_action: finding.recommended_action,\n metadata: {\n ...binding.findingBaseMetadata,\n model: config.model,\n sample,\n ...(binding.metadataFromSubject?.(finding.subject) ?? {}),\n },\n produced_at: producedAt,\n }),\n )\n rawFindings = [...rawFindings, ...sampleFindings]\n const adapted = await binding.adapt({\n subject: trajectoryId,\n findings: sampleFindings,\n analystId: definition.id,\n store,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n const assignments = adapted.stepBlocks ?? []\n sampleAssignments.push(assignments)\n totalModelCalls += completed.modelCalls\n totalToolCalls += completed.toolCalls\n sampleRuns.push({\n sample,\n answer: completed.answer,\n trajectory: completed.trajectory,\n modelCalls: completed.modelCalls,\n toolCalls: completed.toolCalls,\n runtime: completed.runtime,\n ...binding.consensus!.sampleRecord(assignments),\n ...(adapted.diagnostics ? { blockDiagnostics: adapted.diagnostics } : {}),\n ...(sampleUsage ? { usage: sampleUsage } : {}),\n })\n }\n const consensus = binding.consensus!.vote(sampleAssignments)\n const expanded = await binding.consensus!.expand({\n subject: trajectoryId,\n blocks: consensus.blocks,\n store,\n analystId: definition.id,\n producedAt: new Date().toISOString(),\n ...(context.signal ? { signal: context.signal } : {}),\n })\n // Abstention floor, applied AFTER the vote and never per sample:\n // one direct structured call fires only when no step reached the\n // majority threshold, so the whole panel — not one noisy sample —\n // failed to localize anything.\n let fallback: AnalystBenchmarkOutput | undefined\n if (consensus.blocks.length === 0) {\n fallback = await abstentionFallbackRunner.analyze(input, context)\n }\n usage = usageReceiptFromCostLedger(costLedger, caseUsageFilter)\n return {\n findings: fallback && !fallback.error ? fallback.findings : expanded.findings,\n usage,\n metadata: {\n ...binding.baseMetadata,\n protocolSha256,\n samples,\n sampleRuns,\n consensus: consensus.decision,\n blockDiagnostics: expanded.diagnostics,\n modelCalls: totalModelCalls,\n toolCalls: totalToolCalls,\n ...(fallback\n ? {\n abstentionFallback: 'direct',\n ...(fallback.metadata ? { abstentionFallbackMetadata: fallback.metadata } : {}),\n ...(fallback.error ? { abstentionFallbackError: fallback.error } : {}),\n }\n : {}),\n },\n }\n }\n const completed = await runTraceAnalyst({\n definition: traceDefinition,\n engine,\n store: input.traceStore,\n context: {\n runId: context.caseId,\n correlationId: `${context.caseId}:${context.repetition}`,\n costLedger,\n costPhase: binding.costPhase,\n tags,\n recordUsage: (receipt) => {\n usage = receipt\n },\n signal: context.signal,\n },\n })\n const producedAt = new Date().toISOString()\n rawFindings = completed.findings.map((finding) =>\n makeFinding({\n analyst_id: definition.id,\n area,\n subject: finding.subject,\n claim: finding.claim,\n rationale: finding.rationale,\n severity: finding.severity,\n confidence: finding.confidence,\n evidence_refs: evidenceRefsFromRawFinding(finding),\n recommended_action: finding.recommended_action,\n metadata: {\n ...binding.findingBaseMetadata,\n model: config.model,\n // Block coordinates from the subject grammar, so a row retained\n // by a failed or empty case still carries its block metadata.\n ...(binding.metadataFromSubject?.(finding.subject) ?? {}),\n },\n produced_at: producedAt,\n }),\n )\n const adapted = await binding.adapt({\n subject: trajectoryId,\n findings: rawFindings,\n analystId: definition.id,\n store: input.traceStore,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n // Abstention floor: the engine finished but submitted no finding at\n // all — indistinguishable from a missed investigation, so one direct\n // structured call gets a second opinion. An explicit clean verdict\n // arrives as a finding and never reaches this branch; an engine error\n // is thrown above and never reaches it either.\n let fallback: AnalystBenchmarkOutput | undefined\n if (completed.findings.length === 0) {\n fallback = await abstentionFallbackRunner.analyze(input, context)\n usage = usageReceiptFromCostLedger(costLedger, {\n channel: 'analyst',\n tags: {\n benchmarkCaseId: context.caseId,\n benchmarkRepetition: String(context.repetition),\n },\n })\n }\n return {\n findings: fallback && !fallback.error ? fallback.findings : adapted.findings,\n usage,\n metadata: {\n ...binding.baseMetadata,\n protocolSha256,\n ...(adapted.diagnostics ? { blockDiagnostics: adapted.diagnostics } : {}),\n answer: completed.answer,\n trajectory: completed.trajectory,\n modelCalls: completed.modelCalls,\n toolCalls: completed.toolCalls,\n runtime: completed.runtime,\n ...(fallback\n ? {\n abstentionFallback: 'direct',\n ...(fallback.metadata ? { abstentionFallbackMetadata: fallback.metadata } : {}),\n ...(fallback.error ? { abstentionFallbackError: fallback.error } : {}),\n }\n : {}),\n },\n }\n } catch (error) {\n if (context.signal?.aborted) throw error\n if (isPaidCallControlError(error)) throw error\n return {\n findings: [],\n usage,\n error: publicBenchmarkError(error, []),\n metadata: {\n ...binding.baseMetadata,\n ...(samples > 1 ? { samples } : {}),\n rawFindings,\n },\n }\n }\n },\n }\n}\n\n/** Per-sample accepted blocks with the exact steps the expansion kept for each. */\nfunction sampleBlockRecords(\n assignments: readonly CodeTraceStepAssignment[],\n): Array<Record<string, unknown>> {\n const stepsByBlock = new Map<CodeTraceStepAssignment['block'], number[]>()\n for (const { step, block } of assignments) {\n const steps = stepsByBlock.get(block)\n if (steps) steps.push(step)\n else stepsByBlock.set(block, [step])\n }\n return [...stepsByBlock].map(([block, acceptedSteps]) => ({\n firstStep: block.firstStep,\n lastStep: block.lastStep,\n consequenceStep: block.consequenceStep,\n escapeStatus: block.escapeStatus,\n severity: block.severity,\n confidence: block.confidence,\n claim: block.claim,\n acceptedSteps,\n }))\n}\n\nfunction pricingForModel(model: string): CustomTokenPricing {\n const pricing = resolveModelPricing(model)\n if (!pricing) {\n throw new Error(\n `no pricing is configured for '${model}'; provide PublicAnalystBenchmarkModelConfig.pricing`,\n )\n }\n return {\n inputUsdPerMillion: pricing.input * 1_000,\n outputUsdPerMillion: pricing.output * 1_000,\n }\n}\n\nfunction trajectoryIdFromCaseId(dataset: PublicAnalystBenchmarkDataset, caseId: string): string {\n const prefix = dataset === 'agentrx' ? 'agentrx:' : 'codetrace:'\n if (!caseId.startsWith(prefix) || caseId.length === prefix.length) {\n throw new Error(`unexpected ${dataset} benchmark case id '${caseId}'`)\n }\n return caseId.slice(prefix.length)\n}\n\nfunction isPaidCallControlError(error: unknown): boolean {\n return (\n error instanceof CostAccountingIncompleteError ||\n error instanceof CostCallConflictError ||\n error instanceof CostCeilingReachedError ||\n error instanceof CostLedgerPersistenceError ||\n error instanceof CostReceiptCaptureError ||\n error instanceof CostReservationExceededError\n )\n}\n","import { constants } from 'node:fs'\nimport { type FileHandle, open, readdir, realpath } from 'node:fs/promises'\nimport { relative, resolve, sep } from 'node:path'\nimport { compareCodeUnits } from '../ledger-core/canonical'\nimport type { TraceAnalysisStore } from '../trace-analyst/store'\nimport {\n createOtlpBufferTraceStore,\n DEFAULT_MAX_TRACE_FILE_BYTES,\n otlpTextToTraceAnalysisStore,\n} from '../trace-analyst/store-otlp'\nimport { type AnalystBenchmarkCase, traceStoreEvidenceResolver } from './benchmark'\nimport {\n type AgentRxRow,\n agentRxBenchmarkCase,\n type CodeTraceBenchRow,\n codeTraceBenchCase,\n} from './benchmark-datasets'\nimport {\n assertNoBenchmarkLabelsInArtifact,\n assertNoBenchmarkLabelsInTrace,\n} from './benchmark-evidence-validation'\nimport {\n isRecord,\n type PreparedPublicAnalystBenchmark,\n type PublicAnalystBenchmarkDataset,\n type PublicBenchmarkDistributions,\n type PublicBenchmarkSelectionReport,\n type PublicBenchmarkValueDistribution,\n positiveSafeInteger,\n safeInteger,\n} from './benchmark-public-types'\nimport {\n appendVerificationArtifactsToOtlp,\n DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES,\n loadCodeTraceVerificationArtifacts,\n sha256Digest,\n type VerificationArtifactManifest,\n} from './benchmark-verification-artifacts'\nimport type { AnalystRunInputs } from './types'\n\nconst DEFAULT_MAX_PUBLIC_BENCHMARK_LABEL_BYTES = 256 * 1024 * 1024\nconst INPUT_OPEN_FLAGS = constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0)\n\ninterface ImmutableInputSnapshot {\n bytes: Buffer\n sha256: string\n text: string\n}\n\nexport async function loadPublicBenchmarkRows(\n path: string,\n): Promise<Array<Record<string, unknown>>> {\n const snapshot = await readImmutableInputSnapshot(\n resolve(path),\n DEFAULT_MAX_PUBLIC_BENCHMARK_LABEL_BYTES,\n )\n return parsePublicBenchmarkRows(snapshot.text, path)\n}\n\nfunction parsePublicBenchmarkRows(text: string, path: string): Array<Record<string, unknown>> {\n const trimmed = text.trim()\n if (!trimmed) throw new Error(`public analyst benchmark dataset is empty: ${path}`)\n\n let parsed: unknown\n try {\n parsed = JSON.parse(trimmed)\n } catch {\n return parseJsonl(trimmed, path)\n }\n if (Array.isArray(parsed)) return records(parsed, path)\n if (isRecord(parsed) && Array.isArray(parsed.data)) return records(parsed.data, `${path}.data`)\n if (isRecord(parsed) && Array.isArray(parsed.cases)) {\n return records(parsed.cases, `${path}.cases`)\n }\n if (isRecord(parsed)) return [parsed]\n throw new TypeError(`public analyst benchmark dataset must contain JSON objects: ${path}`)\n}\n\nexport function selectPublicBenchmarkRows(\n dataset: PublicAnalystBenchmarkDataset,\n rows: readonly Record<string, unknown>[],\n options: { limit: number; seed: number },\n): Array<Record<string, unknown>> {\n positiveSafeInteger(options.limit, 'limit')\n safeInteger(options.seed, 'seed')\n if (rows.length === 0) throw new Error('public analyst benchmark dataset has no rows')\n\n const byId = new Map<string, Record<string, unknown>>()\n for (const row of rows) {\n const id = publicBenchmarkRowId(dataset, row)\n if (byId.has(id)) {\n throw new Error(`public analyst benchmark dataset repeats trajectory id '${id}'`)\n }\n byId.set(id, row)\n }\n\n return [...byId]\n .sort(\n ([left], [right]) =>\n compareCodeUnits(selectionKey(options.seed, left), selectionKey(options.seed, right)) ||\n compareCodeUnits(left, right),\n )\n .slice(0, Math.min(options.limit, byId.size))\n .map(([, row]) => row)\n}\n\nexport function publicBenchmarkDistributions(\n dataset: PublicAnalystBenchmarkDataset,\n rows: readonly Record<string, unknown>[],\n): PublicBenchmarkDistributions {\n const values: Record<keyof PublicBenchmarkDistributions, Array<string | undefined>> = {\n class: [],\n agent: [],\n model: [],\n difficulty: [],\n solved: [],\n }\n for (const row of rows) {\n const benchmarkCase =\n dataset === 'agentrx'\n ? agentRxBenchmarkCase(row as unknown as AgentRxRow, undefined)\n : codeTraceBenchCase(row as unknown as CodeTraceBenchRow, undefined)\n values.class.push(\n dataset === 'codetracebench'\n ? benchmarkCase.expectedIssues.length > 0\n ? 'positive'\n : row.solved === true\n ? 'trusted-negative'\n : row.solved === false\n ? 'unlabeled-failure'\n : 'unlabeled-unknown'\n : benchmarkCase.expectedIssues[0]?.areas?.[0],\n )\n values.agent.push(\n scalarDistributionValue(row.agent) ??\n (dataset === 'agentrx' ? rootAgent(row as unknown as AgentRxRow) : undefined),\n )\n values.model.push(scalarDistributionValue(row.model))\n values.difficulty.push(scalarDistributionValue(row.difficulty))\n values.solved.push(scalarDistributionValue(row.solved))\n }\n return {\n class: valueDistribution(values.class),\n agent: valueDistribution(values.agent),\n model: valueDistribution(values.model),\n difficulty: valueDistribution(values.difficulty),\n solved: valueDistribution(values.solved),\n }\n}\n\nexport function publicBenchmarkSelectionReport(\n dataset: PublicAnalystBenchmarkDataset,\n source: readonly Record<string, unknown>[],\n selected: readonly Record<string, unknown>[],\n seed: number,\n): PublicBenchmarkSelectionReport {\n const census = source.length === selected.length\n return {\n method: census ? 'census' : 'deterministic-hash',\n seed,\n sourceCount: source.length,\n selectedCount: selected.length,\n stratified: false,\n representativeOfInput: census,\n source: publicBenchmarkDistributions(dataset, source),\n selected: publicBenchmarkDistributions(dataset, selected),\n }\n}\n\nexport async function preparePublicAnalystBenchmark(options: {\n dataset: PublicAnalystBenchmarkDataset\n labelsPath: string\n traceDir: string\n artifactDir?: string\n maxArtifactBytes?: number\n limit: number\n seed: number\n}): Promise<PreparedPublicAnalystBenchmark> {\n const labelsPath = resolve(options.labelsPath)\n const traceRoot = resolve(options.traceDir)\n const labelSnapshot = await readImmutableInputSnapshot(\n labelsPath,\n DEFAULT_MAX_PUBLIC_BENCHMARK_LABEL_BYTES,\n )\n const rows = parsePublicBenchmarkRows(labelSnapshot.text, labelsPath)\n const selected = selectPublicBenchmarkRows(options.dataset, rows, {\n limit: options.limit,\n seed: options.seed,\n })\n const selectedTrajectoryIds = new Set(\n selected.map((row) => publicBenchmarkRowId(options.dataset, row)),\n )\n const stores = await indexSelectedSingleTraceFiles(traceRoot, selectedTrajectoryIds)\n const resolver = traceStoreEvidenceResolver<AnalystRunInputs>((input) => {\n if (!input.traceStore) throw new Error('prepared benchmark case has no trace store')\n return input.traceStore\n })\n const traceFiles: PreparedPublicAnalystBenchmark['traceFiles'] = []\n const verificationArtifacts: VerificationArtifactManifest[] = []\n const cases: AnalystBenchmarkCase<AnalystRunInputs>[] = []\n\n for (const row of selected) {\n const trajectoryId = publicBenchmarkRowId(options.dataset, row)\n const indexed = stores.get(trajectoryId)\n if (!indexed) {\n throw new Error(\n `public analyst benchmark trace directory has no single-trace OTLP JSONL for '${trajectoryId}'`,\n )\n }\n let modelVisibleOtlp = indexed.text\n let traceStore = indexed.store\n let artifactDir: string | undefined\n let verificationManifest: VerificationArtifactManifest | undefined\n if (options.dataset === 'codetracebench') {\n if (!options.artifactDir?.trim()) {\n throw new Error(\n '--artifact-dir is required for CodeTraceBench so final verification evidence is not omitted',\n )\n }\n const artifactRoot = await realpath(options.artifactDir)\n const artifacts = await loadCodeTraceVerificationArtifacts({\n artifactDir: artifactRoot,\n row: row as unknown as CodeTraceBenchRow,\n maxBytes: options.maxArtifactBytes ?? DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES,\n })\n for (const artifact of artifacts.files) {\n assertNoBenchmarkLabelsInArtifact({\n traceId: trajectoryId,\n relativePath: artifact.relativePath,\n content: artifact.content,\n })\n }\n verificationManifest = shareableVerificationManifest(artifacts.manifest, artifactRoot)\n const collisions = await indexed.store.hasSpans({\n trace_id: trajectoryId,\n span_ids: [\n ...artifacts.manifest.files.map((file) => file.spanId),\n artifacts.manifest.outcomeSpanId,\n ],\n })\n if (collisions.length > 0) {\n throw new Error(\n `CodeTraceBench '${trajectoryId}' trace already contains benchmark verification span '${collisions[0]}'`,\n )\n }\n modelVisibleOtlp = appendVerificationArtifactsToOtlp(\n indexed.text,\n trajectoryId,\n artifacts,\n indexed.latestTimestamp,\n )\n traceStore = otlpTextToTraceAnalysisStore(modelVisibleOtlp)\n artifactDir =\n artifacts.manifest.status === 'present' ? artifacts.manifest.caseDirectory : undefined\n verificationArtifacts.push(verificationManifest)\n }\n const labelLeakScan = assertNoBenchmarkLabelsInTrace({\n traceId: trajectoryId,\n otlpText: modelVisibleOtlp,\n })\n\n const input: AnalystRunInputs = { traceStore, artifactDir }\n const benchmarkCase =\n options.dataset === 'agentrx'\n ? agentRxBenchmarkCase(row as unknown as AgentRxRow, input, {\n stepCount: indexed.stepCount,\n })\n : codeTraceBenchCase(row as unknown as CodeTraceBenchRow, input)\n\n for (const evidence of benchmarkCase.labeledEvidence ?? []) {\n const resolved = await resolver({\n caseId: benchmarkCase.id,\n caseInput: input,\n evidence: { kind: evidence.kind ?? 'span', uri: evidence.uri },\n })\n if (!resolved) {\n throw new Error(\n `${benchmarkCase.id}: missing labeled span ${spanIdFromEvidence(evidence.uri) ?? evidence.uri} in ${indexed.path}`,\n )\n }\n }\n\n cases.push({\n ...benchmarkCase,\n metadata: {\n ...benchmarkCase.metadata,\n traceFileRelativePath: slashRelative(traceRoot, indexed.path),\n traceFileSha256: indexed.sha256,\n labelLeakScan,\n ...(verificationManifest ? { verificationArtifacts: verificationManifest } : {}),\n },\n })\n traceFiles.push({\n traceId: trajectoryId,\n relativePath: slashRelative(traceRoot, indexed.path),\n sha256: indexed.sha256,\n })\n }\n\n return {\n cases,\n sourceRowCount: rows.length,\n selectedCaseIds: cases.map((testCase) => testCase.id),\n labelsSha256: labelSnapshot.sha256,\n traceFiles,\n verificationArtifacts,\n selection: publicBenchmarkSelectionReport(options.dataset, rows, selected, options.seed),\n }\n}\n\nasync function indexSelectedSingleTraceFiles(\n traceDir: string,\n selectedTraceIds: ReadonlySet<string>,\n): Promise<\n Map<\n string,\n {\n path: string\n sha256: string\n store: TraceAnalysisStore\n latestTimestamp: string\n text: string\n stepCount: number\n }\n >\n> {\n if (selectedTraceIds.size === 0) {\n throw new Error('public analyst benchmark selected no trace ids')\n }\n const entries = await readdir(traceDir, { withFileTypes: true })\n const files = entries\n .filter((entry) => entry.isFile() && entry.name.endsWith('.jsonl'))\n .map((entry) => resolve(traceDir, entry.name))\n .sort()\n if (files.length === 0) {\n throw new Error(`public analyst benchmark trace directory has no JSONL files: ${traceDir}`)\n }\n\n const indexed = new Map<\n string,\n {\n path: string\n sha256: string\n store: TraceAnalysisStore\n latestTimestamp: string\n text: string\n stepCount: number\n }\n >()\n for (const path of files) {\n const snapshot = await readImmutableInputSnapshot(path, DEFAULT_MAX_TRACE_FILE_BYTES)\n const store = createOtlpBufferTraceStore(snapshot.bytes)\n const overview = await store.getOverview()\n if (overview.total_traces !== 1 || overview.sample_trace_ids.length !== 1) {\n throw new Error(\n `public analyst benchmark trace file must contain exactly one trace: ${path} contains ${overview.total_traces}`,\n )\n }\n if (!overview.time_range) {\n throw new Error(`public analyst benchmark trace file has no valid timestamps: ${path}`)\n }\n const traceId = overview.sample_trace_ids[0]!\n if (!selectedTraceIds.has(traceId)) continue\n if (indexed.has(traceId)) {\n throw new Error(`public analyst benchmark trace id '${traceId}' appears in multiple files`)\n }\n indexed.set(traceId, {\n path,\n sha256: snapshot.sha256,\n store,\n latestTimestamp: overview.time_range.latest,\n text: snapshot.text,\n stepCount: traceStepCount(snapshot.text, path),\n })\n }\n return indexed\n}\n\nasync function readImmutableInputSnapshot(\n path: string,\n maxBytes: number,\n): Promise<ImmutableInputSnapshot> {\n if (!Number.isSafeInteger(maxBytes) || maxBytes < 1) {\n throw new RangeError('benchmark input maxBytes must be a positive safe integer')\n }\n const handle = await open(path, INPUT_OPEN_FLAGS)\n try {\n return await readImmutableInputHandle(handle, path, maxBytes)\n } finally {\n await handle.close()\n }\n}\n\nasync function readImmutableInputHandle(\n handle: FileHandle,\n path: string,\n maxBytes: number,\n): Promise<ImmutableInputSnapshot> {\n const before = await handle.stat({ bigint: true })\n if (!before.isFile()) {\n throw new TypeError(`public analyst benchmark input must be a regular file: ${path}`)\n }\n if (before.size > BigInt(maxBytes)) {\n throw new RangeError(\n `public analyst benchmark input exceeds ${maxBytes} bytes: ${path} has ${before.size}`,\n )\n }\n\n const size = Number(before.size)\n const bytes = Buffer.allocUnsafe(size)\n let offset = 0\n while (offset < size) {\n const result = await handle.read(bytes, offset, size - offset, offset)\n if (result.bytesRead === 0) {\n throw new Error(`public analyst benchmark input changed while being read: ${path}`)\n }\n offset += result.bytesRead\n }\n const overflow = Buffer.allocUnsafe(1)\n const extra = await handle.read(overflow, 0, 1, size)\n const after = await handle.stat({ bigint: true })\n if (\n extra.bytesRead !== 0 ||\n before.dev !== after.dev ||\n before.ino !== after.ino ||\n before.size !== after.size ||\n before.mtimeNs !== after.mtimeNs ||\n before.ctimeNs !== after.ctimeNs\n ) {\n throw new Error(`public analyst benchmark input changed while being read: ${path}`)\n }\n\n let text: string\n try {\n text = new TextDecoder('utf-8', { fatal: true }).decode(bytes)\n } catch (error) {\n throw new TypeError(\n `public analyst benchmark input is not valid UTF-8: ${path}: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n return Object.freeze({\n bytes,\n sha256: sha256Digest(bytes),\n text,\n })\n}\n\nfunction traceStepCount(text: string, path: string): number {\n const steps = parseJsonl(text, path)\n .map((row) => row.span_id)\n .filter((spanId): spanId is string => typeof spanId === 'string')\n .map((spanId) => /^step-(\\d+)$/.exec(spanId)?.[1])\n .filter((step): step is string => step !== undefined)\n .map(Number)\n .filter((step) => Number.isSafeInteger(step) && step > 0)\n if (steps.length === 0) {\n throw new Error(`public analyst benchmark trace has no step-<n> spans: ${path}`)\n }\n return Math.max(...steps)\n}\n\nfunction shareableVerificationManifest(\n manifest: VerificationArtifactManifest,\n artifactRoot: string,\n): VerificationArtifactManifest {\n return {\n ...manifest,\n caseDirectory: slashRelative(artifactRoot, manifest.caseDirectory),\n caseDirectoriesSearched: manifest.caseDirectoriesSearched.map((path) =>\n slashRelative(artifactRoot, path),\n ),\n files: manifest.files.map((file) => ({\n ...file,\n path: slashRelative(artifactRoot, file.path),\n })),\n }\n}\n\nfunction slashRelative(root: string, path: string): string {\n const value = relative(root, path)\n if (!value || value === '..' || value.startsWith(`..${sep}`)) {\n if (!value) return '.'\n throw new Error(`benchmark artifact path escapes its declared root: ${path}`)\n }\n return value.replaceAll('\\\\', '/')\n}\n\nfunction parseJsonl(text: string, path: string): Array<Record<string, unknown>> {\n const rows: Array<Record<string, unknown>> = []\n for (const [index, line] of text.split(/\\r?\\n/).entries()) {\n const trimmed = line.trim()\n if (!trimmed) continue\n let parsed: unknown\n try {\n parsed = JSON.parse(trimmed)\n } catch (error) {\n throw new Error(\n `${path}:${index + 1}: invalid JSON: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n if (!isRecord(parsed)) {\n throw new TypeError(`${path}:${index + 1}: dataset row must be a JSON object`)\n }\n rows.push(parsed)\n }\n if (rows.length === 0) throw new Error(`public analyst benchmark dataset is empty: ${path}`)\n return rows\n}\n\nfunction records(values: readonly unknown[], path: string): Array<Record<string, unknown>> {\n return values.map((value, index) => {\n if (!isRecord(value)) throw new TypeError(`${path}[${index}] must be a JSON object`)\n return value\n })\n}\n\nfunction publicBenchmarkRowId(\n dataset: PublicAnalystBenchmarkDataset,\n row: Record<string, unknown>,\n): string {\n const value = dataset === 'agentrx' ? row.trajectory_id : row.traj_id\n if ((typeof value !== 'string' && typeof value !== 'number') || !String(value).trim()) {\n throw new TypeError(\n `${dataset} dataset row requires a non-empty ${dataset === 'agentrx' ? 'trajectory_id' : 'traj_id'}`,\n )\n }\n return String(value)\n}\n\nfunction spanIdFromEvidence(uri: string): string | null {\n const match = /\\/span\\/([^/]+)$/.exec(uri)\n return match?.[1] ? decodeURIComponent(match[1]) : null\n}\n\nfunction selectionKey(seed: number, id: string): string {\n return sha256Digest(`${seed}\\u0000${id}`)\n}\n\nfunction valueDistribution(\n values: readonly (string | undefined)[],\n): PublicBenchmarkValueDistribution {\n const counts = new Map<string, number>()\n let missing = 0\n for (const value of values) {\n if (value === undefined) {\n missing += 1\n continue\n }\n counts.set(value, (counts.get(value) ?? 0) + 1)\n }\n return {\n total: values.length,\n missing,\n counts: Object.fromEntries([...counts].sort(([left], [right]) => left.localeCompare(right))),\n }\n}\n\nfunction scalarDistributionValue(value: unknown): string | undefined {\n if (typeof value === 'string') return value.trim() || undefined\n if (typeof value === 'number' || typeof value === 'boolean') return String(value)\n return undefined\n}\n\nfunction rootAgent(row: AgentRxRow): string | undefined {\n const rootCauseId = row.root_cause_failure_id ?? row.root_cause?.failure_id\n const root = row.failures.find((failure) => String(failure.failure_id) === String(rootCauseId))\n return scalarDistributionValue(root?.failed_agent)\n}\n","import { request as httpRequest } from 'node:http'\nimport { request as httpsRequest } from 'node:https'\n\n/**\n * The bridge seam for the prime analyst protocol: one POST to an\n * OpenAI-compatible `/v1/chat/completions` endpoint, returning the raw status\n * and body text.\n *\n * Deliberately NOT `callLlm` from `../llm-client`, which serves a different\n * contract:\n * - it retries transient failures, and a prime turn holds a single model seat\n * for minutes — a silent second attempt doubles the seat time and the spend;\n * - it normalizes usage, while the protocol's receipt depends on the bridge's\n * non-standard `model_requests` and `estimated` fields;\n * - it composes sampling and response-format options the bridge's CLI backends\n * reject;\n * - it collapses HTTP status, unparseable body, and empty content into two\n * error classes, while the protocol classifies them as three distinct\n * terminal reasons.\n */\nexport interface PrimeBridgeTransportRequest {\n url: string\n body: {\n model: string\n messages: Array<{ role: 'user'; content: string }>\n }\n /**\n * The call's only deadline. The protocol aborts it on the per-call timeout\n * and on the caller's cancellation, so a transport that imposes a second\n * deadline of its own competes with this one.\n */\n signal: AbortSignal\n}\n\nexport interface PrimeBridgeTransportResult {\n status: number\n text: string\n}\n\n/** One POST to the bridge. Injectable so tests run against a fake bridge. */\nexport type PrimeBridgeTransport = (\n request: PrimeBridgeTransportRequest,\n) => Promise<PrimeBridgeTransportResult>\n\n/**\n * Default transport on node:http/node:https rather than fetch: undici's fixed\n * response-header timeout kills prime calls that legitimately run past five\n * minutes, so the request's AbortSignal is the only deadline.\n */\nexport function nodeHttpPrimeBridgeTransport(): PrimeBridgeTransport {\n return ({ url, body, signal }) => {\n const target = new URL(url)\n if (target.protocol !== 'http:' && target.protocol !== 'https:') {\n throw new TypeError(`bridge URL must be http: or https:, got ${target.protocol}`)\n }\n const send = target.protocol === 'https:' ? httpsRequest : httpRequest\n const encoded = JSON.stringify(body)\n return new Promise((resolvePromise, rejectPromise) => {\n const req = send(\n {\n hostname: target.hostname,\n port: target.port,\n // The query string is part of the caller's URL; dropping it would\n // send the request somewhere other than where the caller pointed.\n path: `${target.pathname}${target.search}`,\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n 'content-length': Buffer.byteLength(encoded),\n },\n signal,\n },\n (res) => {\n const chunks: Buffer[] = []\n res.on('data', (chunk: Buffer) => chunks.push(chunk))\n res.on('end', () =>\n resolvePromise({\n status: res.statusCode ?? 0,\n text: Buffer.concat(chunks).toString('utf8'),\n }),\n )\n res.on('error', rejectPromise)\n },\n )\n req.on('error', rejectPromise)\n req.end(encoded)\n })\n }\n}\n","import type { CustomTokenPricing } from '../cost-ledger'\nimport { resolveModelPricing } from '../metrics'\nimport type { TraceAnalysisStore, TraceAnalysisStoreContext } from '../trace-analyst/store'\nimport type { TraceAnalystSpan } from '../trace-analyst/types'\nimport type { AnalystBenchmarkRunner } from './benchmark'\nimport {\n type CodeTraceFailureBlock,\n expandCodeTraceFailureBlocks,\n} from './benchmark-public-adapters'\nimport { publicBenchmarkError } from './benchmark-public-errors'\nimport {\n CODE_TRACE_BENCH_ANALYST_PROMPT,\n MAX_INCORRECT_BLOCK_STEPS,\n MAX_INCORRECT_BLOCKS,\n} from './benchmark-public-prompt'\nimport { positiveSafeInteger, requiredString } from './benchmark-public-types'\nimport { type AnalystDefinition, AnalystExpressivenessError } from './definition'\nimport { nodeHttpPrimeBridgeTransport, type PrimeBridgeTransport } from './prime-bridge-transport'\nimport {\n analystUsageReceiptFromPrimeUsage,\n buildPrimePrompt,\n type PrimeFailure,\n type PrimeProjectionSource,\n type PrimeProtocolIdentity,\n type PrimeReplyContract,\n type PrimeTurnRecord,\n primeProtocolSha256,\n projectPrimeTrajectory,\n runPrimeExchange,\n} from './prime-protocol'\nimport type { AnalystRunInputs, AnalystSeverity, AnalystUsageReceipt } from './types'\n\n/**\n * Prime analyst arm: the RLM coding agent reached through an OpenAI-compatible\n * cli-bridge solves the CodeTraceBench incorrect-step task as a one-shot trace\n * analyst.\n *\n * The arm is expressed as an `AnalystDefinition`\n * (`primeCodeTraceAnalystDefinition`): the question, task text, output\n * contract, inline projection budget, and repair-turn declaration are all\n * definition content, and `createPrimeBenchmarkRunner` is a thin shell that\n * builds the definition and runs it through the inline strategy below. The\n * same strategy is what `bindAnalyst` (./bind) dispatches to, so a compiled\n * definition and this entry point send byte-identical requests — the parity\n * suite asserts exactly that.\n *\n * The protocol machinery — prompt composition, the bounded repair turn, reply\n * extraction, the projection ladder, usage normalization — lives in\n * `./prime-protocol`, which knows nothing about CodeTraceBench. This file adds\n * the benchmark's binding to it (block row grammar, store-backed projection,\n * observation shape) plus the projection-generic inline execution strategy.\n *\n * Trajectory delivery is inline JSON in the prompt. The dspy typed path binds\n * the viewTrace span projection as a REPL variable; prime has no REPL, so the\n * same projection is serialized into the prompt. When the full projection is\n * oversized the strategy falls back to chunked viewSpans over the same\n * projection surface with a per-attribute byte cap, and fails loud if the\n * result still exceeds the inline budget.\n *\n * A structurally malformed reply gets ONE bounded repair turn (disable with\n * `repair: false`): a second stateless call carrying the malformed reply plus\n * the output contract — never the trajectory — mirroring the dspy arm's typed\n * repair so both arms face the same structured-output affordance. Still\n * malformed after repair = failed observation with a typed error, exactly how\n * a dspy-rlm failure is recorded. Zero valid blocks from a well-formed reply\n * is an honest null, not a failure.\n */\n\nconst PRIME_ANALYST_ID = 'prime'\nconst PRIME_QUESTION = 'Which assistant steps are incorrect under the CodeTraceBench definition?'\n/** Ceiling on the serialized trajectory JSON embedded in the prompt. */\nconst MAX_INLINE_TRAJECTORY_CHARS = 360_000\n/** Per-attribute projection cap used by the chunked viewSpans fallback. */\nconst CHUNKED_PROJECTION_ATTRIBUTE_BYTE_CAP = 1_200\n/** Minimal per-attribute cap used only to enumerate span ids in store order. */\nconst SPAN_ID_ENUMERATION_ATTRIBUTE_BYTE_CAP = 64\n/** viewSpans accepts at most 100 ids per call; 40 keeps each response bounded. */\nconst VIEW_SPANS_CHUNK_SIZE = 40\nconst PRIME_SEVERITIES: ReadonlySet<string> = new Set(['critical', 'high', 'medium', 'low', 'info'])\n\nexport interface PrimeBenchmarkRunnerOptions {\n /** OpenAI-compatible cli-bridge base URL, e.g. `http://localhost:4181`. */\n baseUrl: string\n /** Bridge model id in `<backend>/<provider>/<model>` form, e.g. `prime/zai/glm-5.2`. */\n model: string\n /** Deadline for one bridge call. Prime analyses routinely exceed 5 minutes. */\n timeoutMs: number\n /** Whether a structurally malformed reply gets one bounded repair turn. */\n repair: boolean\n /** Exact token rates. Default: the agent-eval catalog rates for `model`. */\n pricing?: CustomTokenPricing\n /** Bridge transport. Default: node:http POST (see nodeHttpPrimeBridgeTransport). */\n transport?: PrimeBridgeTransport\n}\n\nexport class PrimeBridgeTransportError extends Error {}\nexport class PrimeBridgeHttpError extends Error {\n readonly status: number\n constructor(status: number, bodySnippet: string) {\n super(`bridge HTTP ${status}: ${bodySnippet}`)\n this.status = status\n }\n}\nexport class PrimeMalformedReplyError extends Error {}\nexport class PrimeTraceProjectionError extends Error {}\n\n/**\n * Short-strings rule: long reply strings get corrupted when the bridge splices\n * its backend's stream, so the contract forbids a rationale field and caps\n * every string the model must emit.\n */\nconst PRIME_OUTPUT_CONTRACT_LINES: readonly string[] = [\n 'OUTPUT CONTRACT (supersedes any transport wording above — you have no trace tools and no REPL):',\n 'You are a one-shot analyst. Every fact you need is in the TRAJECTORY JSON below.',\n 'Do not run shell commands, do not read or write files, do not use any tools.',\n 'Reply with EXACTLY one fenced ```json code block and no other fenced block. The JSON object has exactly two fields:',\n ' \"answer\": string — ONE short sentence (max 300 chars) naming the latest failure evidence you traced from.',\n ' \"blocks\": array (possibly empty) of failure blocks, each exactly:',\n ' {\"first_step\": int, \"last_step\": int, \"consequence_step\": int,',\n ' \"escape_status\": \"escaped\"|\"unescaped\",',\n ' \"severity\": \"critical\"|\"high\"|\"medium\"|\"low\"|\"info\",',\n ' \"claim\": string (ONE short sentence, max 200 chars),',\n ' \"confidence\": number 0..1}',\n 'Do NOT include a rationale field. Keep every string SHORT — long strings get corrupted in transport and void your work.',\n `Report at most ${MAX_INCORRECT_BLOCKS} blocks; a block spans at most ${MAX_INCORRECT_BLOCK_STEPS} steps.`,\n 'Every step number must be the n of an existing assistant span with span_id \"step-<n>\" and kind \"LLM\" in the trajectory below; never cite TOOL, CHAIN, or AGENT spans.',\n '\"blocks\" is [] only for a clean trajectory.',\n]\n\nconst PRIME_REPAIR_CONTRACT_LINES: readonly string[] = [\n ' \"answer\": string (ONE short sentence, max 300 chars)',\n ' \"blocks\": array (possibly empty) of {\"first_step\": int, \"last_step\": int, \"consequence_step\": int,',\n ' \"escape_status\": \"escaped\"|\"unescaped\", \"severity\": \"critical\"|\"high\"|\"medium\"|\"low\"|\"info\",',\n ' \"claim\": string (max 200 chars), \"confidence\": number 0..1}',\n 'No rationale field. Keep every string SHORT. Preserve the step numbers and verdicts of your previous reply exactly; shorten prose freely.',\n]\n\nconst PRIME_PROTOCOL_IDENTITY: PrimeProtocolIdentity = {\n question: PRIME_QUESTION,\n taskDefinition: CODE_TRACE_BENCH_ANALYST_PROMPT,\n contractLines: PRIME_OUTPUT_CONTRACT_LINES,\n repairContractLines: PRIME_REPAIR_CONTRACT_LINES,\n limits: {\n maxBlocks: MAX_INCORRECT_BLOCKS,\n maxBlockSteps: MAX_INCORRECT_BLOCK_STEPS,\n maxInlineTrajectoryChars: MAX_INLINE_TRAJECTORY_CHARS,\n chunkedProjectionAttributeByteCap: CHUNKED_PROJECTION_ATTRIBUTE_BYTE_CAP,\n },\n}\n\n/**\n * The block row grammar. No `maxRows`: the count cap belongs to\n * `expandCodeTraceFailureBlocks`, which drops the offending block and names it\n * in `diagnostics.droppedBlocks`, so capping here would erase that record.\n */\nconst PRIME_BLOCK_CONTRACT: PrimeReplyContract<CodeTraceFailureBlock> = {\n rowsField: 'blocks',\n contractLines: PRIME_OUTPUT_CONTRACT_LINES,\n repairContractLines: PRIME_REPAIR_CONTRACT_LINES,\n decodeRow(row) {\n const reason = blockRowDefect(row)\n if (reason !== null) return { ok: false, reason }\n return { ok: true, row: blockFromRow(row as PrimeBlockRow) }\n },\n}\n\n/**\n * Digest of everything this arm can send to the bridge, recorded per\n * observation so a prime result names the exact contract that produced it.\n */\nexport function primeAnalystProtocolSha256(): string {\n return primeProtocolSha256(PRIME_PROTOCOL_IDENTITY)\n}\n\nexport interface PrimeCodeTraceDefinitionArgs {\n /** Deadline for one bridge call. */\n timeoutMs: number\n /** 1 grants the bounded repair turn; 0 disables it. */\n repairTurns: number\n}\n\n/**\n * The prime arm as a declarative unit. CodeTraceBench-only: the question,\n * task text, and block grammar speak its incorrect-step definition.\n */\nexport function primeCodeTraceAnalystDefinition(\n args: PrimeCodeTraceDefinitionArgs,\n): AnalystDefinition<CodeTraceFailureBlock> {\n return {\n id: PRIME_ANALYST_ID,\n description:\n 'One-shot RLM over an OpenAI-compatible bridge answering the CodeTraceBench incorrect-step task.',\n version: '1.0.0',\n area: 'incorrect',\n // The bridge owns model selection and reasoning control; the fragment pins nothing.\n profile: {},\n question: PRIME_QUESTION,\n taskDefinition: CODE_TRACE_BENCH_ANALYST_PROMPT,\n projection: {\n mode: 'inline',\n maxInlineChars: MAX_INLINE_TRAJECTORY_CHARS,\n cappedAttributeBytes: CHUNKED_PROJECTION_ATTRIBUTE_BYTE_CAP,\n },\n replyContract: PRIME_BLOCK_CONTRACT,\n // Insertion order is digest-bearing: it mirrors PRIME_PROTOCOL_IDENTITY.limits.\n contractLimits: {\n maxBlocks: MAX_INCORRECT_BLOCKS,\n maxBlockSteps: MAX_INCORRECT_BLOCK_STEPS,\n },\n budget: { timeoutMs: args.timeoutMs },\n repair: { turns: args.repairTurns },\n protocolSha256: primeAnalystProtocolSha256(),\n binding: {\n kind: 'inline',\n subjectFromCaseId: trajectoryIdFromCaseId,\n baseMetadata: { analysisMode: 'prime-rlm', engine: 'prime' },\n header(subject, spans) {\n const stepSpans = spans.filter((span) => /^step-\\d+$/.test(String(span.span_id)))\n if (stepSpans.length === 0) {\n throw new PrimeTraceProjectionError(`no step-<n> spans in trace '${subject}'`)\n }\n return `TRAJECTORY (trace_id ${subject}; ${stepSpans.length} assistant step spans; full span projection as JSON):`\n },\n trailer(_subject, spans) {\n const finalVerification = spans.filter(isFinalVerificationSpan)\n return finalVerification.length > 0\n ? `FINAL VERIFICATION SPANS:\\n${JSON.stringify(finalVerification)}`\n : 'FINAL VERIFICATION: unavailable for this trajectory — trace backward from the latest failure evidence inside the trajectory itself.'\n },\n async expandRows({ subject, rows, store, analystId, signal }) {\n const expanded = await expandCodeTraceFailureBlocks({\n trajectoryId: subject,\n blocks: rows,\n store,\n analystId,\n ...(signal ? { signal } : {}),\n })\n return { findings: expanded.findings, diagnostics: expanded.diagnostics }\n },\n },\n }\n}\n\n/** Thin shell: validate options, declare the definition, run the inline strategy. */\nexport function createPrimeBenchmarkRunner(\n options: PrimeBenchmarkRunnerOptions,\n): AnalystBenchmarkRunner<AnalystRunInputs> {\n const timeoutMs = positiveSafeInteger(options.timeoutMs, 'timeoutMs')\n const repair = options.repair\n if (typeof repair !== 'boolean') throw new TypeError('repair must be a boolean')\n return runInlineAnalystDefinition(\n primeCodeTraceAnalystDefinition({ timeoutMs, repairTurns: repair ? 1 : 0 }),\n {\n baseUrl: options.baseUrl,\n model: options.model,\n ...(options.transport ? { transport: options.transport } : {}),\n ...(options.pricing ? { pricing: options.pricing } : {}),\n },\n )\n}\n\n// ── Inline execution strategy ───────────────────────────────────────\n\n/** The transport half of an inline-projection binding: the bridge endpoint. */\nexport interface InlineBridgeTransports {\n /** OpenAI-compatible bridge base URL. */\n baseUrl: string\n /** Bridge model id. */\n model: string\n /** Bridge transport. Default: node:http POST. */\n transport?: PrimeBridgeTransport\n /** Exact token rates. Default: the agent-eval catalog rates for `model`. */\n pricing?: CustomTokenPricing\n}\n\n/**\n * Compile an inline-projection definition into a runnable arm. Projection,\n * prompt composition, the bounded repair turn, and usage accounting are all\n * driven by the definition; nothing in this strategy names a benchmark.\n */\nexport function runInlineAnalystDefinition<TRow>(\n definition: AnalystDefinition<TRow>,\n transports: InlineBridgeTransports,\n): AnalystBenchmarkRunner<AnalystRunInputs> {\n const { projection, binding } = definition\n if (projection.mode !== 'inline' || binding.kind !== 'inline') {\n throw new AnalystExpressivenessError(\n `the inline strategy compiles only inline projections; definition '${definition.id}' ` +\n `declares projection '${projection.mode}' with a '${binding.kind}' binding`,\n )\n }\n if (definition.repair.turns > 1) {\n throw new AnalystExpressivenessError(\n `the inline exchange grants at most one bounded repair turn; definition ` +\n `'${definition.id}' declares ${definition.repair.turns}`,\n )\n }\n const baseUrl = requiredString(transports.baseUrl, 'baseUrl').replace(/\\/+$/, '')\n const model = requiredString(transports.model, 'model')\n const timeoutMs = positiveSafeInteger(definition.budget.timeoutMs, 'timeoutMs')\n const repair = definition.repair.turns === 1\n const pricing = transports.pricing ?? pricingForModel(model)\n const transport = transports.transport ?? nodeHttpPrimeBridgeTransport()\n const url = `${baseUrl}/v1/chat/completions`\n\n return {\n id: definition.id,\n async analyze(input, context) {\n const subject = binding.subjectFromCaseId(context.caseId)\n let usage: AnalystUsageReceipt | undefined\n let metadata: Record<string, unknown> = {\n ...binding.baseMetadata,\n bridgeUrl: baseUrl,\n model,\n protocolSha256: definition.protocolSha256,\n }\n try {\n const store = input.traceStore\n if (!store) throw new Error(`inline analyst '${definition.id}' requires a trace store`)\n const storeContext: TraceAnalysisStoreContext | undefined = context.signal\n ? { signal: context.signal }\n : undefined\n const projected = await projectPrimeTrajectory(\n inlineProjectionSource(store, subject, projection.cappedAttributeBytes, storeContext),\n { maxInlineChars: projection.maxInlineChars },\n )\n if (!projected.ok) throw new PrimeTraceProjectionError(projected.reason)\n const delivery: InlineTrajectoryDelivery = {\n mode: projected.delivery.mode,\n fetch: projected.delivery.fetch === 'full' ? 'view-trace' : 'view-spans-chunked',\n perAttributeByteCap:\n projected.delivery.fetch === 'full' ? null : projection.cappedAttributeBytes,\n renderedChars: projected.delivery.renderedChars,\n }\n metadata = { ...metadata, delivery }\n const prompt = buildPrimePrompt({\n question: definition.question,\n ...(definition.taskDefinition === undefined\n ? {}\n : { taskDefinition: definition.taskDefinition }),\n contractLines: definition.replyContract.contractLines,\n trajectoryHeader: binding.header(subject, projected.items),\n renderedTrajectory: projected.rendered,\n trailer: binding.trailer(subject, projected.items),\n })\n metadata = { ...metadata, promptChars: prompt.length }\n\n const outcome = await runPrimeExchange({\n contract: definition.replyContract,\n prompt,\n transport,\n url,\n model,\n timeoutMs,\n repair,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n if (!outcome.ok && outcome.failure.kind === 'aborted') throw abortCause(outcome.failure)\n if (outcome.turns.length > 0) {\n usage = analystUsageReceiptFromPrimeUsage(outcome.usage, pricing)\n metadata = { ...metadata, bridgeUsage: bridgeUsageFromTurns(outcome.turns) }\n }\n metadata = { ...metadata, repair: outcome.repair }\n if (!outcome.ok) {\n // The raw reply is the diagnostic artifact for a malformed case.\n if (outcome.reply !== undefined) {\n metadata = { ...metadata, reply: outcome.reply.slice(0, 4_000) }\n }\n throw primeFailureError(outcome.failure)\n }\n\n const expanded = await binding.expandRows({\n subject,\n rows: outcome.rows,\n store,\n analystId: definition.id,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n return {\n findings: expanded.findings,\n usage,\n metadata: {\n ...metadata,\n answer: outcome.answer,\n reportedRows: outcome.reportedRows,\n rejectedRows: outcome.rejected,\n blockDiagnostics: expanded.diagnostics,\n },\n }\n } catch (error) {\n if (context.signal?.aborted) throw error\n return {\n findings: [],\n ...(usage ? { usage } : {}),\n error: publicBenchmarkError(error, []),\n metadata,\n }\n }\n },\n }\n}\n\ninterface InlineTrajectoryDelivery {\n mode: 'inline-json'\n fetch: 'view-trace' | 'view-spans-chunked'\n perAttributeByteCap: number | null\n renderedChars: number\n}\n\n/**\n * The trace store, seen through the protocol's two-move projection contract:\n * the full viewTrace projection, or the chunked viewSpans projection at a\n * per-attribute byte cap.\n */\nfunction inlineProjectionSource(\n store: TraceAnalysisStore,\n trajectoryId: string,\n cappedAttributeBytes: number,\n context: TraceAnalysisStoreContext | undefined,\n): PrimeProjectionSource<TraceAnalystSpan> {\n return {\n async full() {\n const view = await store.viewTrace({ trace_id: trajectoryId }, context)\n return view.spans ?? null\n },\n capped: () => projectSpansChunked(store, trajectoryId, cappedAttributeBytes, context),\n cappedDescription: `per-attribute cap ${cappedAttributeBytes}`,\n }\n}\n\n/**\n * Chunked viewSpans projection for traces whose full viewTrace response is\n * oversized. Span ids come from a minimal-cap viewTrace in store order; every\n * id must project or the case fails loud — a silently dropped span would\n * understate the trajectory.\n */\nasync function projectSpansChunked(\n store: TraceAnalysisStore,\n trajectoryId: string,\n cappedAttributeBytes: number,\n context: TraceAnalysisStoreContext | undefined,\n): Promise<TraceAnalystSpan[]> {\n const enumeration = await store.viewTrace(\n { trace_id: trajectoryId, per_attribute_byte_cap: SPAN_ID_ENUMERATION_ATTRIBUTE_BYTE_CAP },\n context,\n )\n if (!enumeration.spans) {\n throw new PrimeTraceProjectionError(\n `trace '${trajectoryId}' is oversized even at per-attribute cap ${SPAN_ID_ENUMERATION_ATTRIBUTE_BYTE_CAP}; cannot enumerate span ids`,\n )\n }\n const ids: string[] = []\n const seen = new Set<string>()\n for (const span of enumeration.spans) {\n if (typeof span.span_id === 'string' && span.span_id.length > 0 && !seen.has(span.span_id)) {\n seen.add(span.span_id)\n ids.push(span.span_id)\n }\n }\n if (ids.length === 0) {\n throw new PrimeTraceProjectionError(`no span ids parsed from trace '${trajectoryId}'`)\n }\n const projected: TraceAnalystSpan[] = []\n for (let index = 0; index < ids.length; index += VIEW_SPANS_CHUNK_SIZE) {\n const chunk = ids.slice(index, index + VIEW_SPANS_CHUNK_SIZE)\n const result = await store.viewSpans(\n {\n trace_id: trajectoryId,\n span_ids: chunk,\n per_attribute_byte_cap: cappedAttributeBytes,\n },\n context,\n )\n if (\n result.missing_span_ids.length > 0 ||\n result.omitted_span_ids.length > 0 ||\n result.spans.length !== chunk.length\n ) {\n throw new PrimeTraceProjectionError(\n `viewSpans projected ${result.spans.length}/${chunk.length} spans for chunk at ${index} of '${trajectoryId}'`,\n )\n }\n projected.push(...result.spans)\n }\n return projected\n}\n\n/** Map the protocol's terminal reason onto this benchmark's typed error classes. */\nfunction primeFailureError(failure: PrimeFailure): Error {\n switch (failure.kind) {\n case 'http-status':\n return new PrimeBridgeHttpError(failure.status, failure.bodySnippet)\n case 'malformed-reply':\n return new PrimeMalformedReplyError(failure.message)\n default:\n return new PrimeBridgeTransportError(failure.message)\n }\n}\n\n/** A cancelled run is not a result: the caller's error propagates unchanged. */\nfunction abortCause(failure: Extract<PrimeFailure, { kind: 'aborted' }>): unknown {\n return failure.cause instanceof Error ? failure.cause : new Error(failure.message)\n}\n\nfunction bridgeUsageFromTurns(turns: readonly PrimeTurnRecord[]): Record<string, unknown> {\n return {\n first: turns.find((turn) => turn.turn === 'first')?.rawUsage ?? null,\n repair: turns.find((turn) => turn.turn === 'repair')?.rawUsage ?? null,\n }\n}\n\nfunction isFinalVerificationSpan(span: TraceAnalystSpan): boolean {\n if (span.span_id.startsWith('benchmark-verification')) return true\n const role = span.attributes['benchmark.evidence.role']\n return typeof role === 'string' && role.startsWith('final-verification')\n}\n\nfunction trajectoryIdFromCaseId(caseId: string): string {\n const prefix = 'codetrace:'\n if (!caseId.startsWith(prefix) || caseId.length === prefix.length) {\n throw new Error(`unexpected codetracebench benchmark case id '${caseId}'`)\n }\n return caseId.slice(prefix.length)\n}\n\ninterface PrimeBlockRow {\n first_step: number\n last_step: number\n consequence_step: number\n escape_status: 'escaped' | 'unescaped'\n severity: AnalystSeverity\n claim: string\n confidence: number\n rationale?: unknown\n}\n\nfunction blockRowDefect(row: unknown): string | null {\n if (typeof row !== 'object' || row === null || Array.isArray(row)) return 'row is not an object'\n const record = row as Record<string, unknown>\n for (const field of ['first_step', 'last_step', 'consequence_step'] as const) {\n const value = record[field]\n if (!Number.isInteger(value) || (value as number) < 1) {\n return `${field} must be a positive integer`\n }\n }\n const firstStep = record.first_step as number\n const lastStep = record.last_step as number\n const consequenceStep = record.consequence_step as number\n if (lastStep < firstStep) return 'last_step < first_step'\n if (consequenceStep < firstStep) return 'consequence_step < first_step'\n if (lastStep - firstStep + 1 > MAX_INCORRECT_BLOCK_STEPS) {\n return `block spans ${lastStep - firstStep + 1} steps (cap ${MAX_INCORRECT_BLOCK_STEPS})`\n }\n if (record.escape_status !== 'escaped' && record.escape_status !== 'unescaped') {\n return 'escape_status must be escaped|unescaped'\n }\n if (typeof record.severity !== 'string' || !PRIME_SEVERITIES.has(record.severity)) {\n return 'severity outside the analyst severity enum'\n }\n if (\n typeof record.claim !== 'string' ||\n record.claim.trim().length === 0 ||\n record.claim.length > 2000\n ) {\n return 'claim must be a 1-2000 char string'\n }\n if (\n typeof record.confidence !== 'number' ||\n !Number.isFinite(record.confidence) ||\n record.confidence < 0 ||\n record.confidence > 1\n ) {\n return 'confidence must be 0..1'\n }\n return null\n}\n\nfunction blockFromRow(row: PrimeBlockRow): CodeTraceFailureBlock {\n // The contract asks the model not to send a rationale, but a volunteered one\n // is model-produced evidence: discarding it is unrecoverable, while carrying\n // a bounded string costs nothing and the destination field exists.\n const rationale =\n typeof row.rationale === 'string' && row.rationale.trim().length > 0\n ? row.rationale.trim().slice(0, 4_000)\n : undefined\n return {\n firstStep: row.first_step,\n lastStep: row.last_step,\n consequenceStep: row.consequence_step,\n escapeStatus: row.escape_status,\n severity: row.severity,\n claim: row.claim.trim(),\n confidence: row.confidence,\n ...(rationale === undefined ? {} : { rationale }),\n }\n}\n\nfunction pricingForModel(model: string): CustomTokenPricing {\n const pricing = resolveModelPricing(model)\n if (!pricing) {\n throw new Error(\n `no pricing is configured for '${model}'; provide PrimeBenchmarkRunnerOptions.pricing`,\n )\n }\n return {\n inputUsdPerMillion: pricing.input * 1_000,\n outputUsdPerMillion: pricing.output * 1_000,\n }\n}\n","import type { AnalystBenchmarkResult } from './benchmark'\nimport type { AnalystRunnerComparison } from './benchmark-comparison'\n\nexport function renderAnalystBenchmarkMarkdown(\n result: AnalystBenchmarkResult,\n comparisons: readonly AnalystRunnerComparison[] = [],\n): string {\n const { provenance } = result\n const lines = [\n '# Trace analyst benchmark',\n '',\n '## Run',\n '',\n '| Field | Value |',\n '| --- | --- |',\n `| Benchmark | ${escapeCell(provenance.id ?? 'unspecified')} |`,\n `| Dataset | ${escapeCell(provenance.dataset?.id ?? 'unspecified')} |`,\n `| Dataset revision | ${escapeCell(provenance.dataset?.revision ?? 'unspecified')} |`,\n `| Dataset split | ${escapeCell(provenance.dataset?.split ?? 'unspecified')} |`,\n `| Started | ${escapeCell(provenance.startedAt)} |`,\n `| Ended | ${escapeCell(provenance.endedAt)} |`,\n `| Cases | ${provenance.caseCount} |`,\n `| Runners | ${escapeCell(provenance.runnerIds.join(', '))} |`,\n `| Repetitions | ${provenance.repetitions} |`,\n `| Maximum concurrency | ${provenance.maxConcurrency} |`,\n `| Runner-order seed | ${provenance.runnerOrderSeed} |`,\n `| Command | ${escapeCell(provenance.command ?? 'uncaptured')} |`,\n `| Environment | ${escapeCell(json(provenance.environment))} |`,\n `| Metadata | ${escapeCell(json(provenance.metadata))} |`,\n '',\n '## Summary',\n '',\n ]\n lines.push(\n '| Runner | Runs | Failed | Issue-bearing | Trusted negatives | Unlabeled | Micro recall | Micro precision | Micro F1 | Macro recall | Macro precision | Macro F1 | Critical step | Citation coverage | Quote coverage | Label-location agreement | Citation resolution | Resolution unknown runs | Unresolved citations | Resolution errors | Trusted-negative false positives | Trusted-negative failures | Unlabeled prediction rate | Unlabeled failures | Prediction repeat | Prediction repeated cases | Matched-label repeat | Matched-label repeated cases | Latency min/mean/p50/p95/max ms | Locally timed runs | Runner-reported latency runs | Unknown latency | Calls | Input tokens | Output tokens | Reasoning tokens | Cached tokens | Cache-write tokens | Known cost USD | Unknown calls | Unknown input/output | Unknown reasoning | Unknown cached | Unknown cache-write | Unknown cost |',\n '| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |',\n )\n for (const summary of result.summaries) {\n lines.push(\n `| ${escapeCell(summary.runnerId)} | ${summary.completedRuns}/${summary.plannedRuns} | ${summary.failedRuns} | ${summary.issueBearingRuns} | ${summary.trustedNegativeRuns} | ${summary.unlabeledRuns} | ${optionalRate(summary.issueRecall)} | ${optionalRate(summary.findingPrecision)} | ${optionalRate(summary.f1)} | ${optionalRate(summary.macroIssueRecall)} | ${optionalRate(summary.macroFindingPrecision)} | ${optionalRate(summary.macroF1)} | ${optionalRate(summary.criticalStepAccuracy)} | ${optionalRate(summary.citationCoverage)} | ${optionalRate(summary.citationExcerptCoverage)} | ${optionalRate(summary.citationLabelAgreement)} | ${optionalRate(summary.citationResolution)} | ${summary.citationResolutionUnknownRuns} | ${summary.unresolvedCitations} | ${summary.citationResolutionErrors} | ${optionalRate(summary.trustedNegativeFalsePositiveRate)} | ${optionalRate(summary.trustedNegativeFailureRate)} | ${optionalRate(summary.unlabeledPredictionRate)} | ${optionalRate(summary.unlabeledFailureRate)} | ${optionalRate(summary.predictionAgreement)} | ${summary.predictionAgreementCases} | ${optionalRate(summary.matchedLabelAgreement)} | ${summary.matchedLabelAgreementCases} | ${latency(summary.latencyMs)} | ${summary.benchmarkClockLatencyRuns} | ${summary.runnerReportedLatencyRuns} | ${summary.latencyUnknownRuns} | ${summary.calls} | ${summary.inputTokens} | ${summary.outputTokens} | ${summary.reasoningTokens} | ${summary.cachedTokens} | ${summary.cacheWriteTokens} | ${summary.knownCostUsd.toFixed(6)} | ${summary.callsUnknownRuns} | ${summary.tokenUsageUnknownRuns} | ${summary.reasoningTokenUsageUnknownRuns} | ${summary.cachedTokenUsageUnknownRuns} | ${summary.cacheWriteTokenUsageUnknownRuns} | ${summary.costUnknownRuns} |`,\n )\n }\n\n for (const comparison of comparisons) {\n lines.push(\n '',\n `## ${escapeCell(comparison.candidateRunnerId)} compared with ${escapeCell(comparison.baselineRunnerId)}`,\n '',\n '| Metric | Better direction | Paired cases | Independent clusters | Eligible observations | Paired observations | Missing baseline | Missing candidate | Missing asymmetry | Survivor-only | Baseline mean | Candidate mean | Delta | Interval | Minimum sample | Population inference | Limits |',\n '| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | --- | ---: | ---: | ---: | --- | --- | --- | --- |',\n )\n for (const metric of comparison.metrics) {\n lines.push(\n `| ${metric.metric} | ${metric.direction} | ${metric.pairedCases} | ${metric.pairedClusters} | ${metric.eligibleObservations} | ${metric.pairedObservations} | ${metric.baselineMissingObservations} | ${metric.candidateMissingObservations} | ${metric.asymmetricMissingObservations} | ${metric.survivorOnly ? 'yes' : 'no'} | ${optionalMetricNumber(metric.baselineMean)} | ${optionalMetricNumber(metric.candidateMean)} | ${optionalSigned(metric.meanDelta)} | ${interval(metric.intervalLow, metric.intervalHigh)} | ${metric.minimumSampleMet ? 'yes' : 'no'} | ${metric.populationInferenceEligible ? 'yes' : 'no'} | ${escapeCell(metric.inferenceLimitations.join(', ') || 'none')} |`,\n )\n }\n }\n\n lines.push(\n '',\n '## Runs',\n '',\n '| Runner | Case | Cluster | Label state | Tags | Case metadata | Runner metadata | Rep | Execution index | Completed | Recall | Precision | F1 | Critical step | Citation coverage | Quote coverage | Label-location agreement | Citation resolution | Prediction on label-empty case | Scored findings | Diagnostic findings | Unlabeled citations | Unresolved citations | Resolution errors | Latency ms | Latency source | Calls | Input tokens | Output tokens | Reasoning tokens | Cached tokens | Cache-write tokens | Cost USD | Known cost USD | Cost source | Error class | Error |',\n '| --- | --- | --- | --- | --- | --- | --- | ---: | ---: | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | --- | ---: | ---: | ---: | ---: | ---: | ---: | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | --- | --- | --- |',\n )\n for (const observation of result.observations) {\n const usage = observation.usage\n const cost = usage?.cost.kind === 'uncaptured' ? null : usage?.cost.usd\n const positive = observation.labelState === 'positive'\n lines.push(\n `| ${escapeCell(observation.runnerId)} | ${escapeCell(observation.caseId)} | ${escapeCell(observation.clusterId)} | ${observation.labelState} | ${escapeCell(observation.caseTags.join(', '))} | ${escapeCell(json(observation.caseMetadata))} | ${escapeCell(json(observation.runnerMetadata))} | ${observation.repetition} | ${observation.executionIndex} | ${observation.error ? 'no' : 'yes'} | ${positive ? rate(observation.score.issueRecall) : 'n/a'} | ${positive ? rate(observation.score.findingPrecision) : 'n/a'} | ${positive ? rate(observation.score.f1) : 'n/a'} | ${optionalRate(observation.score.criticalStepAccuracy)} | ${optionalRate(observation.score.citationCoverage)} | ${optionalRate(observation.score.citationExcerptCoverage)} | ${optionalRate(observation.score.citationLabelAgreement)} | ${optionalRate(observation.evidenceResolution?.validity ?? null)} | ${positive ? 'n/a' : observation.score.predictionOnLabelEmptyCase ? 'yes' : 'no'} | ${observation.score.supportedFindingIndexes.length}/${observation.error ? 0 : observation.findings.length} | ${observation.error ? observation.findings.length : 0} | ${observation.score.unlabeledEvidence.length} | ${observation.evidenceResolution?.unresolvedEvidence.length ?? 'unknown'} | ${observation.evidenceResolution?.errors.length ?? 'unknown'} | ${optionalNumber(observation.latencyMs)} | ${observation.latencySource} | ${usage?.calls ?? 'unknown'} | ${usage?.tokens?.input ?? 'unknown'} | ${usage?.tokens?.output ?? 'unknown'} | ${usage?.tokens?.reasoning ?? 'unknown'} | ${usage?.tokens?.cached ?? 'unknown'} | ${usage?.tokens?.cacheWrite ?? 'unknown'} | ${cost === null || cost === undefined ? 'unknown' : cost.toFixed(6)} | ${usage?.knownCostUsd?.toFixed(6) ?? (cost === null || cost === undefined ? 'unknown' : cost.toFixed(6))} | ${usage?.cost.kind ?? 'unknown'} | ${escapeCell(observation.error?.class ?? '')} | ${escapeCell(observation.error?.message ?? '')} |`,\n )\n }\n return `${lines.join('\\n')}\\n`\n}\n\nfunction rate(value: number): string {\n return `${(value * 100).toFixed(1)}%`\n}\n\nfunction optionalRate(value: number | null): string {\n return value === null ? 'n/a' : rate(value)\n}\n\nfunction number(value: number): string {\n return Number.isInteger(value) ? String(value) : value.toFixed(3)\n}\n\nfunction optionalNumber(value: number | null): string {\n return value === null ? 'unknown' : number(value)\n}\n\nfunction optionalMetricNumber(value: number | null): string {\n return value === null ? 'n/a' : number(value)\n}\n\nfunction signed(value: number): string {\n return `${value >= 0 ? '+' : ''}${number(value)}`\n}\n\nfunction optionalSigned(value: number | null): string {\n return value === null ? 'n/a' : signed(value)\n}\n\nfunction interval(low: number | null, high: number | null): string {\n return low === null || high === null ? 'n/a' : `[${number(low)}, ${number(high)}]`\n}\n\nfunction latency(value: AnalystBenchmarkResult['summaries'][number]['latencyMs']): string {\n if (value === null) return 'unknown'\n return [value.min, value.mean, value.p50, value.p95, value.max].map(number).join('/')\n}\n\nfunction json(value: unknown): string {\n return value === undefined ? 'uncaptured' : JSON.stringify(value)\n}\n\nfunction escapeCell(value: string): string {\n return value.replaceAll('|', '\\\\|').replaceAll('\\n', ' ')\n}\n","import { arch, platform } from 'node:os'\nimport { resolve } from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { acquireSingleRunLock } from '../campaign/single-run-lock'\nimport { createRunCostLedger, fsCampaignStorage } from '../campaign/storage'\nimport {\n CostAccountingIncompleteError,\n type CostLedger,\n type CostLedgerSummary,\n} from '../cost-ledger'\nimport { resolveModelPricing } from '../metrics'\nimport {\n type AnalystBenchmarkObservation,\n type AnalystBenchmarkResult,\n type AnalystBenchmarkRunner,\n runAnalystBenchmark,\n traceStoreEvidenceResolver,\n} from './benchmark'\nimport {\n AGENT_RX_UPSTREAM_REVISION,\n renderAgentRxCalibrationMarkdown,\n summarizeAgentRxCalibration,\n} from './benchmark-agentrx-calibration'\nimport type {\n AnalystBenchmarkArtifact,\n VerificationAvailabilitySummary,\n} from './benchmark-command-artifact'\nimport { digestCanonical } from './benchmark-command-artifact'\nimport {\n type AnalystBenchmarkOutputPaths,\n createLocalRunReceipt,\n createObservationAppender,\n createRunIdentity,\n initializeRunFiles,\n openOutputDirectory,\n prepareOutputLockPath,\n readAndValidateResumeFiles,\n readProgress,\n regularFileExists,\n writeExclusiveOrVerify,\n} from './benchmark-command-persistence'\nimport {\n assertCompletedArtifactMatchesRun,\n assertSameObservations,\n readAnalystBenchmarkArtifact,\n} from './benchmark-command-result'\nimport { compareAnalystRunners } from './benchmark-comparison'\nimport {\n ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256,\n ANALYST_BENCHMARK_IMPLEMENTATION_SHA256,\n} from './benchmark-implementation'\nimport {\n effectiveAnalystProtocolSha256,\n readAnalystInstructionsOverride,\n} from './benchmark-instructions-override'\nimport {\n renderCodeTraceCalibrationMarkdown,\n summarizeCodeTraceCalibration,\n} from './benchmark-public-calibration'\nimport { createPublicBenchmarkDirectRunner } from './benchmark-public-model'\nimport { createPublicBenchmarkRlmRunner } from './benchmark-public-rlm'\nimport {\n createPrimeBenchmarkRunner,\n emptyPublicBenchmarkRunner,\n type PublicAnalystBenchmarkDataset,\n type PublicAnalystBenchmarkModelConfig,\n type PublicAnalystBenchmarkModelOwner,\n type PublicAnalystBenchmarkModelSettings,\n type PublicBenchmarkSelectionReport,\n preparePublicAnalystBenchmark,\n} from './benchmark-real-model'\nimport { renderAnalystBenchmarkMarkdown } from './benchmark-report'\nimport {\n DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES,\n type VerificationArtifactManifest,\n} from './benchmark-verification-artifacts'\nimport type { AnalystRunInputs } from './types'\n\nexport {\n ANALYST_BENCHMARK_COST_LEDGER_FILE,\n ANALYST_BENCHMARK_LOCAL_RECEIPT_FILE,\n ANALYST_BENCHMARK_MANIFEST_FILE,\n ANALYST_BENCHMARK_OBSERVATIONS_FILE,\n type AnalystBenchmarkArtifact,\n type AnalystBenchmarkLocalRunReceipt,\n type AnalystBenchmarkProgressRow,\n type AnalystBenchmarkRunIdentity,\n type AnalystBenchmarkRunManifest,\n type VerificationAvailabilitySummary,\n} from './benchmark-command-artifact'\nexport { readAnalystBenchmarkArtifact } from './benchmark-command-result'\n\nexport interface AnalystBenchmarkCommandDependencies {\n createAnalystRunner?: (\n dataset: PublicAnalystBenchmarkDataset,\n config: PublicAnalystBenchmarkModelSettings,\n ) => AnalystBenchmarkRunner<AnalystRunInputs>\n loadModelExecutionOwner?: (\n moduleRef: string,\n context: {\n model: string\n environment: Readonly<NodeJS.ProcessEnv>\n },\n ) => Promise<PublicAnalystBenchmarkModelOwner>\n}\n\n/**\n * Which analyst produces the scored arm.\n *\n * `dspy-rlm` is the recursive engine. `direct` is the one-shot comparison arm.\n * `prime` is the RLM coding agent reached through an OpenAI-compatible\n * cli-bridge (CodeTraceBench only; see docs/prime-analyst.md).\n */\nexport type AnalystBenchmarkRunnerKind = 'dspy-rlm' | 'direct' | 'prime'\n\n/** Bridge execution settings, present exactly when the analyst is `prime`. */\nexport interface PrimeAnalystBridgeConfig {\n bridgeUrl: string\n repair: boolean\n}\n\nexport interface AnalystBenchmarkCommandConfig {\n dataset: PublicAnalystBenchmarkDataset\n analyst: AnalystBenchmarkRunnerKind\n labelsPath: string\n traceDir: string\n artifactDir?: string\n outDir: string\n revision: string\n split: string\n model: PublicAnalystBenchmarkModelSettings\n limit: number\n seed: number\n concurrency: number\n repetitions: number\n /** Recursive-engine runs per case; above 1 the consensus is scored. */\n rlmSamples: number\n maxCostUsd: number\n maxArtifactBytes: number\n /** Absent exactly when the analyst is `prime`: the cli-bridge owns execution. */\n modelOwnerModule?: string\n /** Present exactly when the analyst is `prime`. */\n prime?: PrimeAnalystBridgeConfig\n command: string\n resume: boolean\n}\n\nexport { AGENT_RX_UPSTREAM_REVISION } from './benchmark-agentrx-calibration'\n\nexport async function runAnalystBenchmarkCommand(\n argv: readonly string[],\n env: NodeJS.ProcessEnv = process.env,\n dependencies: AnalystBenchmarkCommandDependencies = {},\n): Promise<number> {\n if (argv.includes('--help') || argv.includes('-h')) {\n process.stdout.write(`${ANALYST_BENCHMARK_HELP}\\n`)\n return 0\n }\n const config = await parseCommandConfig(argv, env, dependencies)\n const outputLock = acquireSingleRunLock({\n lockPath: await prepareOutputLockPath(config.outDir),\n })\n try {\n return await executeAnalystBenchmarkCommand(config, dependencies)\n } finally {\n outputLock.release()\n }\n}\n\nasync function executeAnalystBenchmarkCommand(\n config: AnalystBenchmarkCommandConfig,\n dependencies: AnalystBenchmarkCommandDependencies,\n): Promise<number> {\n const paths = await openOutputDirectory(config.outDir, config.resume)\n\n const prepared = await preparePublicAnalystBenchmark({\n dataset: config.dataset,\n labelsPath: config.labelsPath,\n traceDir: config.traceDir,\n artifactDir: config.artifactDir,\n maxArtifactBytes: config.maxArtifactBytes,\n limit: config.limit,\n seed: config.seed,\n })\n const identity = createRunIdentity(config, prepared)\n const localReceipt = createLocalRunReceipt(config, paths)\n const localIdentitySha256 = digestCanonical(localReceipt.local)\n const identitySha256 = digestCanonical(identity)\n const manifest = config.resume\n ? await readAndValidateResumeFiles(\n paths,\n identity,\n identitySha256,\n localIdentitySha256,\n localReceipt,\n )\n : await initializeRunFiles(paths, identity, identitySha256, localIdentitySha256, localReceipt)\n const progress = await readProgress(\n paths.observations,\n manifest.identitySha256,\n prepared.selectedCaseIds,\n config.repetitions,\n config.analyst,\n )\n const costLedger = createRunCostLedger({\n storage: fsCampaignStorage(),\n runDir: paths.directory,\n costCeilingUsd: config.maxCostUsd,\n })\n\n if (await regularFileExists(paths.result)) {\n assertCostLedgerFinalizable(costLedger)\n const artifact = await readAnalystBenchmarkArtifact(paths.result)\n assertCompletedArtifactMatchesRun(artifact, manifest, progress.observations, prepared)\n const markdown = renderArtifactMarkdown(artifact)\n await writeExclusiveOrVerify(paths.report, markdown)\n printSuccessSummary(artifact, paths)\n return benchmarkExitCode(artifact.result, config.analyst)\n }\n if (await regularFileExists(paths.report)) {\n throw new Error(\n `benchmark report exists without a completed result; refusing ambiguous resume: ${paths.report}`,\n )\n }\n\n const createAnalystRunner =\n dependencies.createAnalystRunner ??\n ((dataset: PublicAnalystBenchmarkDataset, model: PublicAnalystBenchmarkModelSettings) => {\n if (config.analyst === 'prime') {\n if (!config.prime) throw new Error(\"analyst 'prime' is missing its bridge configuration\")\n return createPrimeBenchmarkRunner({\n baseUrl: config.prime.bridgeUrl,\n model: model.model,\n timeoutMs: model.timeoutMs,\n repair: config.prime.repair,\n ...(model.pricing ? { pricing: model.pricing } : {}),\n })\n }\n const ownerModel = requireModelOwnerSettings(model)\n return config.analyst === 'direct'\n ? createPublicBenchmarkDirectRunner(dataset, ownerModel)\n : createPublicBenchmarkRlmRunner(dataset, ownerModel)\n })\n const runners = [\n emptyPublicBenchmarkRunner(),\n createAnalystRunner(config.dataset, {\n ...config.model,\n costLedger,\n durability: {\n runIdentitySha256: manifest.identitySha256,\n responseCacheDir: paths.modelResponses,\n },\n }),\n ]\n const appendObservation = createObservationAppender(\n paths.observations,\n manifest.identitySha256,\n progress,\n )\n const runAbort = new AbortController()\n let result: AnalystBenchmarkResult\n try {\n result = await runAnalystBenchmark({\n cases: prepared.cases,\n runners,\n repetitions: config.repetitions,\n maxConcurrency: config.concurrency,\n runnerOrderSeed: config.seed,\n initialObservations: progress.observations,\n signal: runAbort.signal,\n onObservation: async (observation) => {\n assertObservationAccountingComplete(observation, costLedger, config.analyst)\n await appendObservation(observation)\n },\n resolveEvidence: traceStoreEvidenceResolver((input) => {\n if (!input.traceStore) throw new Error('benchmark case has no trace store')\n return input.traceStore\n }),\n benchmark: {\n id: `${config.dataset}-real-model-analyst`,\n dataset: {\n id: config.dataset === 'agentrx' ? 'microsoft/AgentRx' : 'NJU-LINK/CodeTraceBench',\n revision: config.revision,\n split: config.split,\n },\n environment: {\n node: process.version,\n platform: platform(),\n arch: arch(),\n },\n metadata: {\n model: config.model.model,\n modelOwnerCallRef: config.model.callRef,\n rlmSamples: config.rlmSamples,\n outputAdapter:\n config.dataset === 'agentrx'\n ? 'agentrx-taxonomy-and-root-step'\n : 'codetracebench-incorrect-block',\n caseSelection: prepared.selection.method,\n caseSelectionSeed: config.seed,\n selectionStratified: prepared.selection.stratified,\n protocolSha256: effectiveAnalystProtocolSha256(\n config.dataset,\n config.model.instructionsOverride,\n ),\n implementationSha256: ANALYST_BENCHMARK_IMPLEMENTATION_SHA256,\n dependencyLockSha256: ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256,\n populationRepresentativenessProven: false,\n },\n },\n })\n } catch (error) {\n runAbort.abort(error)\n const idle = await costLedger.waitForIdle({\n timeoutMs: Math.min(config.model.timeoutMs, 10_000),\n })\n if (!idle) {\n throw accountingError(costLedger, 'provider calls remain unresolved after cancellation')\n }\n throw error\n }\n assertCostLedgerFinalizable(costLedger)\n result.provenance.startedAt = manifest.createdAt\n const persisted = await readProgress(\n paths.observations,\n manifest.identitySha256,\n prepared.selectedCaseIds,\n config.repetitions,\n config.analyst,\n )\n assertSameObservations(result.observations, persisted.observations)\n const comparisons = [\n compareAnalystRunners(result, {\n baselineRunnerId: 'empty',\n candidateRunnerId: config.analyst,\n seed: config.seed,\n }),\n ]\n const codeTraceCalibration =\n config.dataset === 'codetracebench' ? summarizeCodeTraceCalibration(result) : undefined\n const agentRxCalibration =\n config.dataset === 'agentrx'\n ? summarizeAgentRxCalibration(result, AGENT_RX_UPSTREAM_REVISION)\n : undefined\n const artifact: AnalystBenchmarkArtifact = {\n kind: 'agent-eval/analyst-benchmark-result',\n runIdentitySha256: manifest.identitySha256,\n inputs: {\n dataset: config.dataset,\n datasetRevision: config.revision,\n datasetSplit: config.split,\n labelsSha256: prepared.labelsSha256,\n sourceRowCount: prepared.sourceRowCount,\n traceFiles: prepared.traceFiles,\n verificationArtifacts: prepared.verificationArtifacts,\n verificationAvailability: summarizeVerificationAvailability(prepared.verificationArtifacts),\n selection: {\n limit: config.limit,\n seed: config.seed,\n selectedCaseIds: prepared.selectedCaseIds,\n report: prepared.selection,\n },\n execution: {\n repetitions: config.repetitions,\n concurrency: config.concurrency,\n rlmSamples: config.rlmSamples,\n model: config.model.model,\n modelOwnerCallRef: manifest.identity.config.model.ownerCallRef,\n maxOutputTokens: manifest.identity.config.model.maxOutputTokens,\n maxReasoningTokens: manifest.identity.config.model.maxReasoningTokens,\n maxModelRequestBytes: manifest.identity.config.model.maxRequestBytes,\n maxModelResponseBytes: manifest.identity.config.model.maxResponseBytes,\n modelRequestTimeoutMs: manifest.identity.config.model.requestTimeoutMs,\n timeoutMs: manifest.identity.config.model.timeoutMs,\n pricing: manifest.identity.config.model.pricing,\n recursiveLimits: manifest.identity.config.model.recursiveLimits,\n processLimits: manifest.identity.config.model.processLimits,\n maxCostUsd: config.maxCostUsd,\n maxArtifactBytes: config.maxArtifactBytes,\n analystProtocolSha256: effectiveAnalystProtocolSha256(\n config.dataset,\n config.model.instructionsOverride,\n ),\n ...(config.model.instructionsOverride\n ? { instructionsOverrideSha256: config.model.instructionsOverride.sha256 }\n : {}),\n implementationSha256: ANALYST_BENCHMARK_IMPLEMENTATION_SHA256,\n dependencyLockSha256: ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256,\n },\n },\n result,\n comparisons,\n ...(codeTraceCalibration ? { codeTraceCalibration } : {}),\n ...(agentRxCalibration ? { agentRxCalibration } : {}),\n }\n\n const markdown = renderArtifactMarkdown(artifact)\n await writeExclusiveOrVerify(paths.result, `${JSON.stringify(artifact, null, 2)}\\n`)\n await writeExclusiveOrVerify(paths.report, markdown)\n printSuccessSummary(artifact, paths)\n return benchmarkExitCode(result, config.analyst)\n}\n\nconst NON_SCORABLE_COST_ERRORS = new Set([\n 'CostAccountingIncompleteError',\n 'CostCallConflictError',\n 'CostCeilingReachedError',\n 'CostLedgerPersistenceError',\n 'CostReceiptCaptureError',\n 'CostReservationExceededError',\n])\n\nfunction assertObservationAccountingComplete(\n observation: AnalystBenchmarkObservation,\n costLedger: CostLedger,\n analystRunnerId: string,\n): void {\n if (observation.error && NON_SCORABLE_COST_ERRORS.has(observation.error.class)) {\n throw new CostAccountingIncompleteError(\n `Analyst benchmark stopped before scoring: ${observation.error.message}`,\n )\n }\n if (observation.runnerId !== analystRunnerId) return\n const filter = {\n channel: 'analyst' as const,\n tags: {\n benchmarkCaseId: observation.caseId,\n benchmarkRepetition: String(observation.repetition),\n },\n }\n const summary = costLedger.summary(filter)\n // Every settled call is honestly accounted: a known cost is summed, and a\n // provider response that omitted usage is flagged and excluded from the\n // reported total. Neither invalidates a run, whether the case succeeded or\n // failed. Only a call left pending, one lost, or one charged beyond its\n // maximum leaves the cost genuinely unknowable, and those still halt.\n if (!costAccountingIsTrustworthy(summary)) {\n throw accountingError(\n costLedger,\n 'the recursive analyst has incomplete cost accounting',\n filter,\n )\n }\n}\n\nconst BUDGET_BREACH_REASON = /exceeding its enforced maximum/\n\n/**\n * Cost accounting is trustworthy when every call resolved and none breached its\n * budget. A recursive analyst on a real provider will occasionally receive a\n * settled response whose usage the provider omitted; that call is honestly\n * recorded as unknown and excluded from the reported cost, so it does not\n * invalidate a completed run. A call left pending, one lost, or one charged\n * beyond its maximum is a genuine integrity failure and still halts.\n */\nfunction costAccountingIsTrustworthy(summary: CostLedgerSummary): boolean {\n if (summary.pendingCalls > 0 || summary.unresolvedCalls > 0) return false\n return !summary.incompleteReasons.some((reason) => BUDGET_BREACH_REASON.test(reason))\n}\n\nfunction assertCostLedgerFinalizable(costLedger: CostLedger): void {\n const summary = costLedger.summary()\n if (!costAccountingIsTrustworthy(summary)) {\n throw accountingError(costLedger, 'the run has pending or budget-breaching cost entries')\n }\n}\n\nfunction accountingError(\n costLedger: CostLedger,\n reason: string,\n filter?: Parameters<CostLedger['summary']>[0],\n): CostAccountingIncompleteError {\n const summary = costLedger.summary(filter)\n const details = summary.incompleteReasons.slice(0, 3).join('; ')\n return new CostAccountingIncompleteError(\n `Analyst benchmark cannot continue because ${reason}${details ? `: ${details}` : ''}`,\n )\n}\n\nconst ANALYST_BENCHMARK_HELP = `agent-eval analyst-benchmark\n\nRun the recursive DSPy trace analyst against public AgentRx or CodeTraceBench labels.\n\nRequired:\n --dataset agentrx|codetracebench\n --analyst dspy-rlm|direct|prime Scored analyst. Default: dspy-rlm.\n 'direct' is the one-shot comparison arm.\n 'prime' is the RLM coding agent behind an\n OpenAI-compatible cli-bridge (codetracebench\n only; see docs/prime-analyst.md)\n --labels <dataset.json|dataset.jsonl>\n --trace-dir <one-trace-per-file OTLP JSONL directory>\n --artifact-dir <extracted artifact root> Required for CodeTraceBench\n --out <new output directory>\n --revision <full 40- or 64-character hex digest>\n --split <dataset split>\n --model-owner-module <module> dspy-rlm|direct only. Module exporting\n createModelExecutionOwner; the owner keeps\n provider credentials and policy\n --model <provider model id> For prime, the bridge model id in\n <backend>/<provider>/<model> form, e.g.\n prime/zai/glm-5.2\n --limit <positive case count>\n\nControls:\n --resume Continue an interrupted run in --out\n --bridge-url <url> prime only. OpenAI-compatible cli-bridge\n base URL. Default: http://localhost:4181\n --no-repair prime only. Disable the bounded repair turn\n for a structurally malformed reply\n --seed <integer> Case-selection and comparison seed. Default: 0\n --concurrency <positive integer> Parallel benchmark jobs. Default: 1\n --repetitions <positive integer> Runs per case and runner. Default: 1\n --rlm-samples <positive integer> Recursive-engine runs per case; above 1 the\n step-level majority consensus is scored\n (CodeTraceBench + dspy-rlm only). Default: 1\n --instructions-file <path> Replace the recursive analyst instructions\n with this file's text (dspy-rlm only). The\n recorded protocol digest binds the stock\n protocol to the override text, and\n result.json records instructionsOverrideSha256.\n --max-output-tokens <positive> Model output limit per call. Default: 16384\n --max-reasoning-tokens <integer> Reasoning-token limit per call. Default: 65536\n --max-model-requests <positive> Caller-owned model calls per analysis.\n Default: max iterations + model calls + 1\n --max-model-request-bytes <positive> Default: 16777216\n --max-model-response-bytes <positive> Default: 4194304\n --model-request-timeout-ms <positive> Default: --timeout-ms\n --max-iterations <positive> Recursive iterations per analysis. Default: 14\n --max-llm-calls <positive> DSPy model calls per analysis. Default: 8\n --max-tool-calls <positive> Trace-tool calls per analysis. Default: 80\n --max-analysis-output-chars <positive> Default: 8000\n --trace-tool-request-bytes <positive> Default: 1000000\n --trace-tool-response-bytes <positive> Default: 4000000\n --trace-tool-timeout-ms <positive> Default: 60000\n --max-process-input-bytes <positive> Default: 67108864\n --max-process-result-bytes <positive> Default: 4194304\n --max-process-output-chars <positive> Default: 64000\n --python <executable> Python with agent-eval-rpc[dspy]. Default: python\n --timeout-ms <positive> Model analyst deadline per case. Default: 300000\n --max-cost-usd <positive> Run-wide spend limit. Default: 5\n --max-artifact-bytes <positive> Final evidence bytes per case. Default: ${DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES}\n\nWrites result.json with every observation, metric, usage field, error, comparison,\ninput digest, artifact digest, case distribution, selected case id, and explicit\nunknown cost. Limited deterministic-hash subsets are marked non-representative.\nCompleted observations are fsynced to observations.jsonl. Shareable output is in\nresult.json and report.md. Machine-local paths, execution-owner module, and command\nare isolated in run.local.json. Provider credentials never enter this command.`\n\nasync function parseCommandConfig(\n argv: readonly string[],\n env: NodeJS.ProcessEnv,\n dependencies: AnalystBenchmarkCommandDependencies,\n): Promise<AnalystBenchmarkCommandConfig> {\n const flags = parseFlags(argv)\n assertKnownFlags(flags)\n const dataset = requiredFlag(flags, 'dataset')\n if (dataset !== 'agentrx' && dataset !== 'codetracebench') {\n throw new Error(\"--dataset must be 'agentrx' or 'codetracebench'\")\n }\n const artifactDir = flags.get('artifact-dir')?.trim()\n if (dataset === 'codetracebench' && !artifactDir) {\n throw new Error('--artifact-dir is required for CodeTraceBench')\n }\n const maxCostUsd = positiveFiniteFlag(flags, 'max-cost-usd', 5)\n const python = flags.get('python')?.trim()\n const analyst = flags.get('analyst')?.trim() ?? 'dspy-rlm'\n if (analyst !== 'dspy-rlm' && analyst !== 'direct' && analyst !== 'prime') {\n throw new Error(\"--analyst must be 'dspy-rlm', 'direct', or 'prime'\")\n }\n const bridgeUrl = flags.get('bridge-url')?.trim()\n if (bridgeUrl !== undefined && analyst !== 'prime') {\n throw new Error('--bridge-url requires --analyst prime')\n }\n if (bridgeUrl === '') throw new Error('--bridge-url must not be blank')\n if (flags.has('no-repair') && analyst !== 'prime') {\n throw new Error('--no-repair requires --analyst prime')\n }\n if (analyst === 'prime' && dataset !== 'codetracebench') {\n throw new Error(\n '--analyst prime requires --dataset codetracebench; the prime runner speaks the CodeTraceBench failure-block contract',\n )\n }\n if (analyst === 'prime' && flags.has('model-owner-module')) {\n throw new Error(\n '--model-owner-module is not used by --analyst prime; the cli-bridge owns model execution',\n )\n }\n const prime =\n analyst === 'prime'\n ? { bridgeUrl: bridgeUrl ?? 'http://localhost:4181', repair: !flags.has('no-repair') }\n : undefined\n const rlmSamples = positiveFlag(flags, 'rlm-samples', 1)\n if (rlmSamples > 1 && analyst !== 'dspy-rlm') {\n throw new Error('--rlm-samples above 1 requires --analyst dspy-rlm')\n }\n const instructionsFile = flags.get('instructions-file')?.trim()\n if (instructionsFile && analyst !== 'dspy-rlm') {\n throw new Error('--instructions-file requires --analyst dspy-rlm')\n }\n const instructionsOverride = instructionsFile\n ? readAnalystInstructionsOverride(instructionsFile)\n : undefined\n if (rlmSamples > 1 && dataset !== 'codetracebench') {\n throw new Error(\n '--rlm-samples above 1 requires --dataset codetracebench; step-level consensus is defined on its block grammar',\n )\n }\n const model = requiredFlag(flags, 'model')\n const modelOwnerModule =\n analyst === 'prime' ? undefined : requiredFlag(flags, 'model-owner-module')\n const owner = modelOwnerModule\n ? await (dependencies.loadModelExecutionOwner ?? loadModelExecutionOwner)(modelOwnerModule, {\n model,\n environment: Object.freeze({ ...env }),\n })\n : undefined\n if (owner) assertModelExecutionOwner(owner)\n const pricing = owner?.pricing ?? benchmarkModelPricing(model)\n const maxOutputTokens = positiveFlag(flags, 'max-output-tokens', 16_384)\n const timeoutMs = positiveFlag(flags, 'timeout-ms', 300_000)\n return {\n dataset,\n analyst,\n labelsPath: requiredFlag(flags, 'labels'),\n traceDir: requiredFlag(flags, 'trace-dir'),\n ...(artifactDir ? { artifactDir } : {}),\n outDir: requiredFlag(flags, 'out'),\n revision: immutableRevision(requiredFlag(flags, 'revision')),\n split: requiredFlag(flags, 'split'),\n model: {\n ...(owner\n ? { call: owner.call, callRef: owner.callRef, recordExecution: owner.recordExecution }\n : { callRef: `cli-bridge:${prime!.bridgeUrl}` }),\n model,\n maxOutputTokens,\n timeoutMs,\n maxReasoningTokens: nonNegativeFlag(flags, 'max-reasoning-tokens', maxOutputTokens * 4),\n maxModelRequestBytes: positiveFlag(flags, 'max-model-request-bytes', 16 * 1024 * 1024),\n maxModelResponseBytes: positiveFlag(flags, 'max-model-response-bytes', 4 * 1024 * 1024),\n modelRequestTimeoutMs: positiveFlag(flags, 'model-request-timeout-ms', timeoutMs),\n pricing,\n maxCostUsdPerAnalysis: maxCostUsd,\n ...(instructionsOverride ? { instructionsOverride } : {}),\n dspyRlm: {\n runner: {\n ...(python ? { command: python } : {}),\n limits: {\n maxInputBytes: positiveFlag(flags, 'max-process-input-bytes', 64 * 1024 * 1024),\n maxResultBytes: positiveFlag(flags, 'max-process-result-bytes', 4 * 1024 * 1024),\n maxOutputChars: positiveFlag(flags, 'max-process-output-chars', 64_000),\n },\n },\n maxIterations: positiveFlag(flags, 'max-iterations', 14),\n maxLlmCalls: positiveFlag(flags, 'max-llm-calls', 8),\n maxToolCalls: positiveFlag(flags, 'max-tool-calls', 80),\n maxOutputChars: positiveFlag(flags, 'max-analysis-output-chars', 8_000),\n ...(flags.has('max-model-requests')\n ? { maxModelRequests: positiveFlag(flags, 'max-model-requests') }\n : {}),\n traceToolRequestBytes: positiveFlag(flags, 'trace-tool-request-bytes', 1_000_000),\n traceToolResponseBytes: positiveFlag(flags, 'trace-tool-response-bytes', 4_000_000),\n traceToolTimeoutMs: positiveFlag(flags, 'trace-tool-timeout-ms', 60_000),\n samples: rlmSamples,\n },\n },\n limit: positiveFlag(flags, 'limit'),\n seed: integerFlag(flags, 'seed', 0),\n concurrency: positiveFlag(flags, 'concurrency', 1),\n repetitions: positiveFlag(flags, 'repetitions', 1),\n rlmSamples,\n maxCostUsd,\n maxArtifactBytes: positiveFlag(\n flags,\n 'max-artifact-bytes',\n DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES,\n ),\n ...(modelOwnerModule === undefined ? {} : { modelOwnerModule }),\n ...(prime === undefined ? {} : { prime }),\n command: `agent-eval analyst-benchmark ${argv\n .filter((argument) => argument !== '--resume')\n .map(shellQuote)\n .join(' ')}`,\n resume: flags.has('resume'),\n }\n}\n\n/** Fail-loud narrowing: the dspy-rlm and direct analysts require an owner call path. */\nfunction requireModelOwnerSettings(\n model: PublicAnalystBenchmarkModelSettings,\n): PublicAnalystBenchmarkModelConfig {\n const { call, recordExecution } = model\n if (typeof call !== 'function' || typeof recordExecution !== 'function') {\n throw new Error('model-owner execution is required for the dspy-rlm and direct analysts')\n }\n return { ...model, call, recordExecution }\n}\n\nfunction parseFlags(argv: readonly string[]): Map<string, string> {\n const flags = new Map<string, string>()\n for (let index = 0; index < argv.length; index += 1) {\n const token = argv[index]!\n if (!token.startsWith('--')) throw new Error(`unexpected positional argument: ${token}`)\n const raw = token.slice(2)\n const equalsAt = raw.indexOf('=')\n const name = equalsAt < 0 ? raw : raw.slice(0, equalsAt)\n const inlineValue = equalsAt < 0 ? undefined : raw.slice(equalsAt + 1)\n if (!name || flags.has(name)) throw new Error(`duplicate or empty flag: --${name}`)\n if (BOOLEAN_FLAGS.has(name)) {\n if (inlineValue !== undefined) throw new Error(`--${name} does not accept a value`)\n flags.set(name, 'true')\n continue\n }\n const value = inlineValue ?? argv[++index]\n if (!value || value.startsWith('--')) throw new Error(`--${name} requires a value`)\n flags.set(name, value)\n }\n return flags\n}\n\nconst KNOWN_FLAGS = new Set([\n 'resume',\n 'dataset',\n 'analyst',\n 'bridge-url',\n 'no-repair',\n 'labels',\n 'trace-dir',\n 'artifact-dir',\n 'out',\n 'revision',\n 'split',\n 'model-owner-module',\n 'model',\n 'limit',\n 'seed',\n 'concurrency',\n 'repetitions',\n 'rlm-samples',\n 'instructions-file',\n 'max-output-tokens',\n 'max-reasoning-tokens',\n 'max-model-requests',\n 'max-model-request-bytes',\n 'max-model-response-bytes',\n 'model-request-timeout-ms',\n 'max-iterations',\n 'max-llm-calls',\n 'max-tool-calls',\n 'max-analysis-output-chars',\n 'trace-tool-request-bytes',\n 'trace-tool-response-bytes',\n 'trace-tool-timeout-ms',\n 'max-process-input-bytes',\n 'max-process-result-bytes',\n 'max-process-output-chars',\n 'python',\n 'timeout-ms',\n 'max-cost-usd',\n 'max-artifact-bytes',\n])\n\nconst BOOLEAN_FLAGS = new Set(['resume', 'no-repair'])\n\nfunction assertKnownFlags(flags: ReadonlyMap<string, string>): void {\n for (const flag of flags.keys()) {\n if (!KNOWN_FLAGS.has(flag)) throw new Error(`unknown analyst-benchmark flag: --${flag}`)\n }\n}\n\nfunction requiredFlag(flags: ReadonlyMap<string, string>, name: string): string {\n const value = flags.get(name)?.trim()\n if (!value) throw new Error(`--${name} is required`)\n return value\n}\n\nfunction positiveFlag(\n flags: ReadonlyMap<string, string>,\n name: string,\n defaultValue?: number,\n): number {\n const raw = flags.get(name)\n if (raw === undefined && defaultValue !== undefined) return defaultValue\n if (raw === undefined) throw new Error(`--${name} is required`)\n const value = Number(raw)\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new Error(`--${name} must be a positive safe integer`)\n }\n return value\n}\n\nfunction integerFlag(\n flags: ReadonlyMap<string, string>,\n name: string,\n defaultValue: number,\n): number {\n const raw = flags.get(name)\n if (raw === undefined) return defaultValue\n const value = Number(raw)\n if (!Number.isSafeInteger(value)) throw new Error(`--${name} must be a safe integer`)\n return value\n}\n\nfunction nonNegativeFlag(\n flags: ReadonlyMap<string, string>,\n name: string,\n defaultValue: number,\n): number {\n const raw = flags.get(name)\n if (raw === undefined) return defaultValue\n const value = Number(raw)\n if (!Number.isSafeInteger(value) || value < 0) {\n throw new Error(`--${name} must be a non-negative safe integer`)\n }\n return value\n}\n\nfunction positiveFiniteFlag(\n flags: ReadonlyMap<string, string>,\n name: string,\n defaultValue: number,\n): number {\n const raw = flags.get(name)\n if (raw === undefined) return defaultValue\n const value = Number(raw)\n if (!Number.isFinite(value) || value <= 0) {\n throw new Error(`--${name} must be a positive finite number`)\n }\n return value\n}\n\nasync function loadModelExecutionOwner(\n moduleRef: string,\n context: { model: string; environment: Readonly<NodeJS.ProcessEnv> },\n): Promise<PublicAnalystBenchmarkModelOwner> {\n const specifier =\n moduleRef.startsWith('.') || moduleRef.startsWith('/')\n ? pathToFileURL(resolve(moduleRef)).href\n : moduleRef\n const imported = (await import(specifier)) as {\n createModelExecutionOwner?: (value: {\n model: string\n environment: Readonly<NodeJS.ProcessEnv>\n }) => PublicAnalystBenchmarkModelOwner | Promise<PublicAnalystBenchmarkModelOwner>\n }\n if (typeof imported.createModelExecutionOwner !== 'function') {\n throw new Error(`${moduleRef} must export createModelExecutionOwner({ model, environment })`)\n }\n return imported.createModelExecutionOwner(context)\n}\n\nfunction assertModelExecutionOwner(value: PublicAnalystBenchmarkModelOwner): void {\n if (!value || typeof value !== 'object') {\n throw new Error('createModelExecutionOwner must return an object')\n }\n if (typeof value.call !== 'function') {\n throw new Error('model execution owner call must be a function')\n }\n if (\n typeof value.callRef !== 'string' ||\n !value.callRef.trim() ||\n value.callRef !== value.callRef.trim()\n ) {\n throw new Error('model execution owner callRef must be trimmed and non-empty')\n }\n if (typeof value.recordExecution !== 'function') {\n throw new Error('model execution owner recordExecution must be a function')\n }\n}\n\nfunction benchmarkModelPricing(\n model: string,\n): NonNullable<PublicAnalystBenchmarkModelConfig['pricing']> {\n const pricing = resolveModelPricing(model)\n if (!pricing) {\n throw new Error(`model execution owner must supply pricing for uncatalogued model '${model}'`)\n }\n return {\n inputUsdPerMillion: pricing.input * 1_000,\n outputUsdPerMillion: pricing.output * 1_000,\n }\n}\n\nfunction immutableRevision(value: string): string {\n if (!/^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/.test(value)) {\n throw new Error('--revision must be a full 40- or 64-character hexadecimal digest')\n }\n return value.toLowerCase()\n}\n\nfunction renderSelectionMarkdown(report: PublicBenchmarkSelectionReport): string {\n const rows = (['class', 'agent', 'model', 'difficulty', 'solved'] as const).map((dimension) => {\n const source = report.source[dimension]\n const selected = report.selected[dimension]\n return `| ${dimension} | ${distributionText(source.counts, source.missing, source.total)} | ${distributionText(selected.counts, selected.missing, selected.total)} |`\n })\n return [\n '## Case Selection',\n '',\n `Method: \\`${report.method}\\`; seed: \\`${report.seed}\\`; selected: ${report.selectedCount}/${report.sourceCount}.`,\n report.representativeOfInput\n ? 'This is a census of the supplied input.'\n : 'This deterministic hash subset is not stratified and must not be presented as representative.',\n '',\n '| Dimension | Supplied input | Selected cases |',\n '| --- | --- | --- |',\n ...rows,\n ].join('\\n')\n}\n\nfunction distributionText(\n counts: Readonly<Record<string, number>>,\n missing: number,\n total: number,\n): string {\n const values = Object.entries(counts).map(([value, count]) => `${value}=${count}`)\n if (missing > 0) values.push(`missing=${missing}`)\n return `${values.join(', ') || 'none'} (n=${total})`\n}\n\nfunction summarizeVerificationAvailability(\n manifests: readonly VerificationArtifactManifest[],\n): VerificationAvailabilitySummary {\n return {\n cases: manifests.length,\n resultFilesPresent: manifests.filter((manifest) => manifest.status === 'present').length,\n resultFilesMissing: manifests.filter((manifest) => manifest.status === 'missing').length,\n outcomes: {\n passed: manifests.filter((manifest) => manifest.outcome.status === 'passed').length,\n failed: manifests.filter((manifest) => manifest.outcome.status === 'failed').length,\n unavailable: manifests.filter((manifest) => manifest.outcome.status === 'unavailable').length,\n },\n }\n}\n\nfunction renderVerificationAvailability(summary: VerificationAvailabilitySummary): string {\n return [\n '## Final Verification Availability',\n '',\n '| Cases | Result files present | Result files missing | Passed | Failed | Unavailable |',\n '| ---: | ---: | ---: | ---: | ---: | ---: |',\n `| ${summary.cases} | ${summary.resultFilesPresent} | ${summary.resultFilesMissing} | ${summary.outcomes.passed} | ${summary.outcomes.failed} | ${summary.outcomes.unavailable} |`,\n ].join('\\n')\n}\n\nfunction renderArtifactMarkdown(artifact: AnalystBenchmarkArtifact): string {\n const calibrationMarkdown = artifact.codeTraceCalibration\n ? `\\n\\n${renderCodeTraceCalibrationMarkdown(artifact.codeTraceCalibration)}`\n : artifact.agentRxCalibration\n ? `\\n\\n${renderAgentRxCalibrationMarkdown(artifact.agentRxCalibration)}`\n : ''\n const verificationMarkdown =\n artifact.inputs.dataset === 'codetracebench'\n ? `\\n\\n${renderVerificationAvailability(artifact.inputs.verificationAvailability)}`\n : ''\n return `${renderAnalystBenchmarkMarkdown(artifact.result, artifact.comparisons).trimEnd()}${calibrationMarkdown}${verificationMarkdown}\\n\\n${renderSelectionMarkdown(artifact.inputs.selection.report)}\\n`\n}\n\nfunction benchmarkExitCode(result: AnalystBenchmarkResult, analystRunnerId: string): number {\n return result.summaries.find((summary) => summary.runnerId === analystRunnerId)?.failedRuns\n ? 2\n : 0\n}\n\nfunction printSuccessSummary(\n artifact: AnalystBenchmarkArtifact,\n paths: AnalystBenchmarkOutputPaths,\n): void {\n const failures = artifact.result.summaries.reduce(\n (total, summary) => total + summary.failedRuns,\n 0,\n )\n const knownCostUsd = artifact.result.summaries.reduce(\n (total, summary) => total + summary.knownCostUsd,\n 0,\n )\n const unknownCostRuns = artifact.result.summaries.reduce(\n (total, summary) => total + summary.costUnknownRuns,\n 0,\n )\n process.stdout.write(\n `Analyst benchmark complete: cases=${artifact.result.provenance.caseCount} failures=${failures} known_cost_usd=${knownCostUsd.toFixed(6)} unknown_cost_runs=${unknownCostRuns}\\nresult=${paths.result}\\nreport=${paths.report}\\n`,\n )\n}\n\nfunction shellQuote(value: string): string {\n return /^[a-zA-Z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replaceAll(\"'\", \"'\\\\''\")}'`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAgB,wBAAwB,OAAuB;CAC7D,MAAM,aAAaA,WAAS,OAAO,iBAAiB,CAAC,CAClD,YAAY,CAAC,CACb,QAAQ,eAAe,GAAG,CAAC,CAC3B,QAAQ,UAAU,EAAE;CACvB,IAAI,CAAC,YAAY,MAAM,IAAI,UAAU,gDAAgD;CACrF,OAAO;AACT;AAEA,SAAgB,qBAAqB,OAAmC;CACtE,MAAM,aAAa,SAAS;CAC5B,IAAI,CAAC,OAAO,SAAS,UAAU,KAAK,aAAa,KAAK,aAAa,GACjE,MAAM,IAAI,WAAW,wDAAwD;CAE/E,OAAO;AACT;AAEA,SAAgB,sBACd,MACA,WACA,OACM;CACN,IAAI,cAAc,KAAA,GAAW;CAC7B,MAAM,QAAQ,aAAa,WAAW,GAAG,MAAM,WAAW;CAC1D,IAAI,OAAO,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kD;CACzE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAgB,SAAS,OAAiC;CACxD,OAAO,OAAO,UAAU,YAAY,iBAAiB,KAAK,KAAK;AACjE;;;ACzPA,MAAa,oDAAoD;AAEjE,MAAa,qDAAqD;AAElE,MAAa,0CAA0C,OAAO,OAAO;CACnE;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,2CACX;AAWF,MAAa,oDACX;AAEF,MAAa,mDACX;AAEF,MAAa,yCAAyC,OAAO,OAAO;CAClE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,0CACX;AAEF,SAAgB,uCAAuC;CACrD,OAAO;AACT;AAEA,SAAgB,uCAAuC;CACrD,OAAO;AACT;;;AClJA,MAAM,gCAAgC;AAEtC,MAAM,uBAAuB;AAC7B,MAAM,iCAAiC,KAAK;AAC5C,MAAM,iCAAiC;AAEvC,MAAM,uCAAuB,IAAI,IAAI;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,6BAA6B,CAAC,GAAG,oBAAoB,CAAC,CAAC,MAC1D,MA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AC/C,OAAO,YAAY,QAAQ,QAAQ,iBACpC,CACF;CACA,QAAQ,OAAO,MACb,qCAAqC,SAAS,OAAO,WAAW,UAAU,YAAY,SAAS,kBAAkB,aAAa,QAAQ,CAAC,EAAE,qBAAqB,gBAAgB,WAAW,MAAM,OAAO,WAAW,MAAM,OAAO,GAChO;AACF;AAEA,SAAS,WAAW,OAAuB;CACzC,OAAO,2BAA2B,KAAK,KAAK,IAAI,QAAQ,IAAI,MAAM,WAAW,KAAK,OAAO,EAAE;AAC7F"}
1
+ {"version":3,"file":"benchmark-command-D4vpnAdO.js","names":["nonEmpty","isRecord","isRecord","nonEmpty","isRecord","summarizeRunner","escapeCell","rate","number","mean","requiredString","mean","safeInteger","positiveInteger","rate","isRecord","TextDecoder","isNodeError","slashRelative","isRecord","escapeCell","rate","trajectoryIdFromCaseId","pricingForModel","isPaidCallControlError","trajectoryIdFromCaseId","pricingForModel","httpsRequest","httpRequest"],"sources":["../src/analyst/benchmark-dataset-utils.ts","../src/analyst/benchmark-dataset-agentrx.ts","../src/analyst/benchmark-dataset-codetrace.ts","../src/analyst/benchmark-agentrx-calibration.ts","../src/analyst/benchmark-comparison.ts","../src/analyst/benchmark-command-validation.ts","../src/analyst/benchmark-command-artifact.ts","../src/analyst/benchmark-implementation.ts","../src/analyst/benchmark-evidence-validation.ts","../src/analyst/benchmark-verification-outcome.ts","../src/analyst/benchmark-verification-artifacts.ts","../src/analyst/benchmark-public-prompt.ts","../src/analyst/benchmark-instructions-override.ts","../src/analyst/benchmark-command-persistence.ts","../src/analyst/benchmark-public-calibration.ts","../src/analyst/benchmark-command-result.ts","../src/analyst/benchmark-public-adapters.ts","../src/analyst/benchmark-public-errors.ts","../src/analyst/benchmark-public-types.ts","../src/analyst/benchmark-response-cache.ts","../src/analyst/definition.ts","../src/analyst/benchmark-public-model.ts","../src/analyst/benchmark-public-consensus.ts","../src/analyst/benchmark-public-rlm.ts","../src/analyst/benchmark-public-data.ts","../src/analyst/prime-bridge-transport.ts","../src/analyst/benchmark-runner-prime.ts","../src/analyst/benchmark-report.ts","../src/analyst/benchmark-command.ts"],"sourcesContent":["import type { ExternalId } from './benchmark-dataset-types'\n\nexport function normalizeBenchmarkLabel(value: string): string {\n const normalized = nonEmpty(value, 'benchmark label')\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-|-$/g, '')\n if (!normalized) throw new TypeError('benchmark label must contain letters or digits')\n return normalized\n}\n\nexport function predictionConfidence(value: number | undefined): number {\n const confidence = value ?? 0.5\n if (!Number.isFinite(confidence) || confidence < 0 || confidence > 1) {\n throw new RangeError('upstream prediction confidence must be between 0 and 1')\n }\n return confidence\n}\n\nexport function assertStepWithinRange(\n step: number,\n stepCount: number | undefined,\n field: string,\n): void {\n if (stepCount === undefined) return\n const count = positiveStep(stepCount, `${field} stepCount`)\n if (step > count) throw new RangeError(`${field} step ${step} exceeds stepCount ${count}`)\n}\n\nexport function defaultStepUri(trajectoryId: string, step: number): string {\n return `trace://${encodeURIComponent(trajectoryId)}/span/step-${step}`\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nexport function positiveStep(value: number, field: string): number {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new RangeError(`${field} must be a positive safe integer`)\n }\n return value\n}\n\nexport function externalId(value: ExternalId | undefined, field: string): string {\n if (typeof value !== 'string' && typeof value !== 'number') {\n throw new TypeError(`${field} must be a string or number`)\n }\n if (typeof value === 'number' && !Number.isSafeInteger(value)) {\n throw new TypeError(`${field} must be a safe integer when numeric`)\n }\n return nonEmpty(String(value), field)\n}\n\nexport function nonEmpty(value: string, field: string): string {\n if (!value.trim()) throw new TypeError(`${field} must not be empty`)\n return value\n}\n","import type { AnalystBenchmarkCase } from './benchmark'\nimport type {\n AgentRxBenchmarkCaseOptions,\n AgentRxPrediction,\n AgentRxPredictionReport,\n AgentRxRow,\n ExternalId,\n UpstreamPredictionAdapterOptions,\n} from './benchmark-dataset-types'\nimport {\n assertStepWithinRange,\n defaultStepUri,\n externalId,\n isRecord,\n normalizeBenchmarkLabel,\n positiveStep,\n predictionConfidence,\n} from './benchmark-dataset-utils'\nimport { type AnalystFinding, makeFinding } from './types'\n\nexport function agentRxBenchmarkCase<TInput>(\n row: AgentRxRow,\n input: TInput,\n options: AgentRxBenchmarkCaseOptions = {},\n): AnalystBenchmarkCase<TInput> {\n const trajectoryId = externalId(row.trajectory_id, 'AgentRx trajectory_id')\n if (!Array.isArray(row.failures) || row.failures.length === 0) {\n throw new TypeError(`AgentRx trajectory '${trajectoryId}' must contain failures`)\n }\n if (row.num_failures !== undefined && row.num_failures !== row.failures.length) {\n throw new TypeError(\n `AgentRx trajectory '${trajectoryId}' declares ${row.num_failures} failures but contains ${row.failures.length}`,\n )\n }\n const rootCauseId = externalId(\n row.root_cause_failure_id ?? row.root_cause?.failure_id,\n `AgentRx trajectory '${trajectoryId}' root cause failure id`,\n )\n const failureIds = new Set<string>()\n const failureMetadata: Array<{ id: string; step: number; category: string }> = []\n const evidenceKind = options.evidenceKind ?? 'span'\n const uri = options.stepUri ?? defaultStepUri\n const allIssues = row.failures.map((failure) => {\n const failureId = externalId(\n failure.failure_id,\n `AgentRx trajectory '${trajectoryId}' failure id`,\n )\n if (failureIds.has(failureId)) {\n throw new TypeError(`AgentRx trajectory '${trajectoryId}' repeats failure id '${failureId}'`)\n }\n failureIds.add(failureId)\n const step = positiveStep(failure.step_number, `AgentRx trajectory '${trajectoryId}'`)\n const evidence = [{ kind: evidenceKind, uri: uri(trajectoryId, step) }]\n if (typeof failure.failure_category !== 'string') {\n throw new TypeError(\n `AgentRx trajectory '${trajectoryId}' failure '${failureId}' category must be a string`,\n )\n }\n const category = normalizeAgentRxCategory(failure.failure_category)\n if (!AGENT_RX_TAXONOMY_BY_LABEL.has(category)) {\n throw new RangeError(\n `AgentRx trajectory '${trajectoryId}' failure '${failureId}' category '${failure.failure_category}' is outside the AgentRx taxonomy`,\n )\n }\n failureMetadata.push({ id: failureId, step, category })\n return {\n id: failureId,\n areas: [category],\n ...(failureId === rootCauseId && (options.target ?? 'root-cause') === 'root-cause'\n ? {}\n : { evidence }),\n criticalEvidence: failureId === rootCauseId ? evidence : undefined,\n }\n })\n if (!failureIds.has(rootCauseId)) {\n throw new TypeError(\n `AgentRx trajectory '${trajectoryId}' root cause '${rootCauseId}' is not in failures`,\n )\n }\n if (\n options.stepCount !== undefined &&\n row.failures.some((failure) => failure.step_number > options.stepCount!)\n ) {\n throw new RangeError(\n `AgentRx trajectory '${trajectoryId}' contains a failure beyond stepCount ${options.stepCount}`,\n )\n }\n const expectedIssues =\n (options.target ?? 'root-cause') === 'root-cause'\n ? allIssues.filter((issue) => issue.id === rootCauseId)\n : allIssues\n const rootCause = failureMetadata.find((failure) => failure.id === rootCauseId)!\n const orderedFailures = [...failureMetadata].sort(\n (left, right) => left.step - right.step || left.id.localeCompare(right.id),\n )\n\n const rootCauseReason = row.root_cause_reason ?? row.root_cause?.reason_for_root_cause\n\n return {\n id: `agentrx:${trajectoryId}`,\n clusterId: `agentrx:${trajectoryId}`,\n labelState: 'positive',\n input,\n expectedIssues,\n labeledEvidence: expectedIssues.flatMap(\n (issue) => issue.evidence ?? issue.criticalEvidence ?? [],\n ),\n tags: ['agentrx'],\n metadata: {\n benchmark: 'AgentRx',\n trajectoryId,\n ...(row.failure_summary === undefined ? {} : { failureSummary: row.failure_summary }),\n ...(rootCauseReason === undefined ? {} : { rootCauseReason }),\n annotatedFailures: row.failures.length,\n target: options.target ?? 'root-cause',\n rootCauseStep: rootCause.step,\n rootCauseCategory: rootCause.category,\n allFailureCategories: [...new Set(failureMetadata.map((failure) => failure.category))].sort(),\n earliestFailureCategory: orderedFailures[0]!.category,\n terminalFailureCategory: orderedFailures.at(-1)!.category,\n ...(options.stepCount === undefined ? {} : { trajectoryLength: options.stepCount }),\n },\n }\n}\n\n/** Translate AgentRx `Report.to_dict()` output or its `failures` array into findings. */\nexport function agentRxPredictionsToFindings(\n trajectoryIdValue: ExternalId,\n output: unknown,\n options: UpstreamPredictionAdapterOptions = {},\n): AnalystFinding[] {\n const trajectoryId = externalId(trajectoryIdValue, 'AgentRx prediction trajectory id')\n const parsed = parseAgentRxPredictions(output, trajectoryId)\n for (const prediction of parsed.predictions) {\n assertStepWithinRange(\n prediction.step_number,\n parsed.report?.trajectory_length,\n `AgentRx prediction '${trajectoryId}' report`,\n )\n assertStepWithinRange(\n prediction.step_number,\n options.stepCount,\n `AgentRx prediction '${trajectoryId}'`,\n )\n }\n const consensus = agentRxConsensus(parsed, trajectoryId)\n if (consensus.failureCase === 0) return []\n const confidence = predictionConfidence(options.confidence)\n const uri = options.stepUri ?? defaultStepUri\n assertStepWithinRange(consensus.step, options.stepCount, `AgentRx prediction '${trajectoryId}'`)\n const area = AGENT_RX_TAXONOMY.get(consensus.failureCase)!\n return [\n makeFinding({\n analyst_id: options.analystId ?? 'agentrx',\n produced_at: options.producedAt,\n area,\n subject: 'root-cause',\n claim: `AgentRx classified step ${consensus.step} as ${area}.`,\n id_basis: `${area}:${consensus.step}`,\n rationale: consensus.representative.description,\n severity: 'high',\n confidence,\n evidence_refs: [\n {\n kind: options.evidenceKind ?? 'span',\n uri: uri(trajectoryId, consensus.step),\n },\n ],\n metadata: {\n upstream: 'AgentRx',\n failure_case: consensus.failureCase,\n step: consensus.step,\n step_mean: consensus.stepMean,\n judge_votes: parsed.predictions.length,\n consensus_votes: consensus.votes,\n category_agreement: consensus.votes / parsed.predictions.length,\n ...(consensus.representative.checklist_reasoning === undefined ||\n consensus.representative.checklist_reasoning === null\n ? {}\n : { checklist_reasoning: consensus.representative.checklist_reasoning }),\n },\n }),\n ]\n}\n\nconst AGENT_RX_TAXONOMY = new Map<number, string>([\n [1, 'instruction-plan-adherence-failure'],\n [2, 'invention-of-new-information'],\n [3, 'invalid-invocation'],\n [4, 'misinterpretation-of-tool-output-handoff-failure'],\n [5, 'intent-plan-misalignment'],\n [6, 'underspecified-user-intent'],\n [7, 'intent-not-supported'],\n [8, 'guardrails-triggered'],\n [9, 'system-failure'],\n [10, 'inconclusive'],\n])\n\nconst AGENT_RX_CATEGORY_ALIASES = new Map<string, string>([\n ['instruction-adherence-failure', 'instruction-plan-adherence-failure'],\n ['misinterpretation-of-tool-output', 'misinterpretation-of-tool-output-handoff-failure'],\n])\n\nconst AGENT_RX_TAXONOMY_BY_LABEL = new Map(\n [...AGENT_RX_TAXONOMY].map(([failureCase, label]) => [label, failureCase]),\n)\n\nexport function normalizeAgentRxCategory(value: string): string {\n const normalized = normalizeBenchmarkLabel(value)\n return AGENT_RX_CATEGORY_ALIASES.get(normalized) ?? normalized\n}\n\nfunction parseAgentRxFailureCase(value: unknown, field: string): number {\n if (typeof value !== 'number' && typeof value !== 'string') {\n throw new TypeError(`${field} must be a taxonomy number or label`)\n }\n if (typeof value === 'string' && !/^\\d+$/.test(value.trim())) {\n const normalized = normalizeAgentRxCategory(value)\n const failureCase = AGENT_RX_TAXONOMY_BY_LABEL.get(normalized)\n if (failureCase === undefined) {\n throw new RangeError(`${field} '${value}' is not an AgentRx taxonomy label`)\n }\n return failureCase\n }\n const numeric = typeof value === 'number' ? value : Number(value)\n if (!Number.isSafeInteger(numeric)) {\n throw new TypeError(`${field} must be a taxonomy number or label`)\n }\n if (numeric < 0 || numeric > 10) {\n throw new RangeError(`${field} ${numeric} is outside 0-10`)\n }\n return numeric\n}\n\ninterface ParsedAgentRxPredictions {\n predictions: Array<\n Omit<AgentRxPrediction, 'failure_case'> & {\n failure_case: number\n }\n >\n report?: AgentRxPredictionReport\n}\n\nfunction parseAgentRxPredictions(output: unknown, trajectoryId: string): ParsedAgentRxPredictions {\n let failures: unknown\n let report: AgentRxPredictionReport | undefined\n if (Array.isArray(output)) {\n failures = output\n } else if (isRecord(output)) {\n assertMatchingAgentRxTaskId(output.task_id, trajectoryId, 'report.task_id')\n if (!Object.hasOwn(output, 'failures')) {\n throw new TypeError(`AgentRx prediction '${trajectoryId}' report must contain failures`)\n }\n failures = output.failures\n if (output.num_judges !== undefined) {\n if (!Number.isSafeInteger(output.num_judges) || (output.num_judges as number) < 0) {\n throw new RangeError(\n `AgentRx prediction '${trajectoryId}' report.num_judges must be a non-negative safe integer`,\n )\n }\n }\n if (output.trajectory_length !== undefined) {\n positiveStep(\n output.trajectory_length as number,\n `AgentRx prediction '${trajectoryId}' report.trajectory_length`,\n )\n }\n if (output.step_mean !== undefined) {\n if (typeof output.step_mean !== 'number' || !Number.isFinite(output.step_mean)) {\n throw new TypeError(`AgentRx prediction '${trajectoryId}' report.step_mean must be finite`)\n }\n }\n if (output.modes !== undefined && !Array.isArray(output.modes)) {\n throw new TypeError(`AgentRx prediction '${trajectoryId}' report.modes must be an array`)\n }\n report = output as unknown as AgentRxPredictionReport\n } else {\n throw new TypeError(`AgentRx prediction '${trajectoryId}' must be a report or failures array`)\n }\n if (!Array.isArray(failures)) {\n throw new TypeError(`AgentRx prediction '${trajectoryId}' failures must be an array`)\n }\n if (failures.length === 0) {\n throw new TypeError(\n `AgentRx prediction '${trajectoryId}' failures must contain a judge prediction`,\n )\n }\n if (\n isRecord(output) &&\n output.num_judges !== undefined &&\n output.num_judges !== failures.length\n ) {\n throw new TypeError(\n `AgentRx prediction '${trajectoryId}' declares ${output.num_judges} judges but contains ${failures.length} failures`,\n )\n }\n const predictions = failures.map((value, index) => {\n const field = `AgentRx prediction '${trajectoryId}' failures[${index}]`\n if (!isRecord(value)) throw new TypeError(`${field} must be an object`)\n assertMatchingAgentRxTaskId(value.task_id, trajectoryId, `${field}.task_id`)\n const failureCase = parseAgentRxFailureCase(value.failure_case, `${field}.failure_case`)\n if (!Number.isSafeInteger(value.step_number)) {\n throw new TypeError(`${field}.step_number must be a safe integer`)\n }\n const stepNumber = value.step_number as number\n if (failureCase === 0 ? stepNumber !== 0 : stepNumber < 1) {\n throw new RangeError(\n failureCase === 0\n ? `${field}.step_number must be 0 when failure_case is 0`\n : `${field}.step_number must be positive when failure_case is 1-10`,\n )\n }\n if (value.description !== undefined && typeof value.description !== 'string') {\n throw new TypeError(`${field}.description must be a string`)\n }\n if (\n value.checklist_reasoning !== undefined &&\n value.checklist_reasoning !== null &&\n typeof value.checklist_reasoning !== 'string'\n ) {\n throw new TypeError(`${field}.checklist_reasoning must be a string or null`)\n }\n return {\n ...(value.task_id === undefined ? {} : { task_id: value.task_id as ExternalId }),\n failure_case: failureCase,\n step_number: stepNumber,\n ...(value.description === undefined ? {} : { description: value.description as string }),\n ...(value.checklist_reasoning === undefined\n ? {}\n : { checklist_reasoning: value.checklist_reasoning as string | null }),\n }\n })\n return { predictions, report }\n}\n\nfunction agentRxConsensus(\n parsed: ParsedAgentRxPredictions,\n trajectoryId: string,\n): {\n failureCase: number\n step: number\n stepMean: number\n votes: number\n representative: ParsedAgentRxPredictions['predictions'][number]\n} {\n const counts = new Map<number, number>()\n for (const prediction of parsed.predictions) {\n counts.set(prediction.failure_case, (counts.get(prediction.failure_case) ?? 0) + 1)\n }\n const maxVotes = Math.max(...counts.values())\n let failureCase = [...counts].find(([, count]) => count === maxVotes)![0]\n if (parsed.report?.most_common_failure !== undefined) {\n const declared = parseAgentRxFailureCase(\n parsed.report.most_common_failure,\n `AgentRx prediction '${trajectoryId}' report.most_common_failure`,\n )\n if ((counts.get(declared) ?? 0) !== maxVotes) {\n throw new TypeError(\n `AgentRx prediction '${trajectoryId}' report.most_common_failure disagrees with failures`,\n )\n }\n failureCase = declared\n }\n if (parsed.report?.modes !== undefined) {\n const declaredModes = parsed.report.modes.map((value, index) =>\n parseAgentRxFailureCase(value, `AgentRx prediction '${trajectoryId}' report.modes[${index}]`),\n )\n if (new Set(declaredModes).size !== declaredModes.length) {\n throw new TypeError(`AgentRx prediction '${trajectoryId}' report.modes contains duplicates`)\n }\n const expectedModes = [...counts]\n .filter(([, count]) => count === maxVotes)\n .map(([value]) => value)\n .sort((left, right) => left - right)\n if (\n [...new Set(declaredModes)].sort((left, right) => left - right).join(',') !==\n expectedModes.join(',')\n ) {\n throw new TypeError(\n `AgentRx prediction '${trajectoryId}' report.modes disagrees with failures`,\n )\n }\n }\n\n const computedStepMean =\n parsed.predictions.reduce((sum, prediction) => sum + prediction.step_number, 0) /\n parsed.predictions.length\n if (\n parsed.report?.step_mean !== undefined &&\n Math.abs(parsed.report.step_mean - computedStepMean) > 1e-12\n ) {\n throw new TypeError(\n `AgentRx prediction '${trajectoryId}' report.step_mean disagrees with failures`,\n )\n }\n const stepMean = parsed.report?.step_mean ?? computedStepMean\n const step =\n failureCase === 0\n ? 0\n : positiveStep(\n roundAgentRxStep(stepMean),\n `AgentRx prediction '${trajectoryId}' consensus step`,\n )\n const representative =\n parsed.predictions\n .filter((prediction) => prediction.failure_case === failureCase)\n .sort(\n (left, right) => Math.abs(left.step_number - step) - Math.abs(right.step_number - step),\n )[0] ?? parsed.predictions[0]!\n return {\n failureCase,\n step,\n stepMean,\n votes: counts.get(failureCase)!,\n representative,\n }\n}\n\n/** Match Python's round() behavior used by AgentRx for consensus steps. */\nexport function roundAgentRxStep(value: number): number {\n if (!Number.isFinite(value)) {\n throw new TypeError('AgentRx step mean must be finite')\n }\n const lower = Math.floor(value)\n const fraction = value - lower\n if (Math.abs(fraction - 0.5) <= Number.EPSILON * Math.max(1, Math.abs(value))) {\n return lower % 2 === 0 ? lower : lower + 1\n }\n return Math.round(value)\n}\n\nfunction assertMatchingAgentRxTaskId(value: unknown, trajectoryId: string, field: string): void {\n if (value === undefined) return\n const taskId = externalId(value as ExternalId, `AgentRx prediction '${trajectoryId}' ${field}`)\n if (taskId !== trajectoryId) {\n throw new TypeError(\n `AgentRx prediction '${trajectoryId}' ${field} '${taskId}' does not match trajectory id`,\n )\n }\n}\n","import type { AnalystBenchmarkCase } from './benchmark'\nimport type {\n CodeTraceBenchCaseOptions,\n CodeTraceBenchLabelSet,\n CodeTraceBenchRow,\n CodeTracerPredictionAdapterOptions,\n CodeTracerPredictions,\n CodeTracerStepLabel,\n CodeTraceStageAnnotation,\n} from './benchmark-dataset-types'\nimport {\n assertStepWithinRange,\n defaultStepUri,\n isRecord,\n nonEmpty,\n positiveStep,\n predictionConfidence,\n} from './benchmark-dataset-utils'\nimport { type AnalystFinding, makeFinding } from './types'\n\nexport function codeTraceBenchCase<TInput>(\n row: CodeTraceBenchRow,\n input: TInput,\n options: CodeTraceBenchCaseOptions = {},\n): AnalystBenchmarkCase<TInput> {\n const trajectoryId = requiredCodeTraceString(row.traj_id, 'CodeTraceBench traj_id')\n const taskName = requiredCodeTraceString(\n row.task_name,\n `CodeTraceBench '${trajectoryId}' task_name`,\n )\n const agent = requiredCodeTraceString(row.agent, `CodeTraceBench '${trajectoryId}' agent`)\n const model = requiredCodeTraceString(row.model, `CodeTraceBench '${trajectoryId}' model`)\n const difficulty = optionalCodeTraceString(\n row.difficulty,\n `CodeTraceBench '${trajectoryId}' difficulty`,\n )\n const category = optionalCodeTraceString(\n row.category,\n `CodeTraceBench '${trajectoryId}' category`,\n )\n const sourceRelpath = optionalSourceRelativePath(row.source_relpath, trajectoryId)\n const solved = codeTraceSolved(row.solved, trajectoryId)\n const tags = parseTags(row.tags, trajectoryId)\n const stepCount = positiveStep(row.step_count, `CodeTraceBench '${trajectoryId}' step_count`)\n const stages = parseCodeTraceStages(row.incorrect_stages, trajectoryId)\n const evidenceKind = options.evidenceKind ?? 'span'\n const uri = options.stepUri ?? defaultStepUri\n const labelSet = codeTraceLabelSet(options.labelSet)\n const labels = new Set<string>()\n const expectedIssues = stages.flatMap((stage) => {\n const incorrect = stepIssues('incorrect', stage.incorrect_step_ids ?? [])\n const unuseful = stepIssues('unuseful', stage.unuseful_step_ids ?? [])\n return labelSet === 'incorrect-only' ? incorrect : [...incorrect, ...unuseful]\n })\n const labelState =\n expectedIssues.length > 0 ? 'positive' : solved === true ? 'trusted-negative' : 'unlabeled'\n\n return {\n id: `codetrace:${trajectoryId}`,\n clusterId: `codetrace-task:${taskName}`,\n labelState,\n input,\n expectedIssues,\n ...(labelState === 'unlabeled'\n ? {}\n : { labeledEvidence: expectedIssues.flatMap((issue) => issue.evidence ?? []) }),\n tags: [\n 'codetracebench',\n agent,\n model,\n ...(difficulty === undefined ? [] : [difficulty]),\n ...(category === undefined ? [] : [category]),\n ...tags,\n ],\n metadata: {\n benchmark: 'CodeTraceBench',\n trajectoryId,\n taskName,\n agent,\n model,\n solved,\n stepCount,\n labelSet,\n ...(sourceRelpath === undefined ? {} : { sourceRelpath }),\n ...(difficulty === undefined ? {} : { difficulty }),\n ...(category === undefined ? {} : { category }),\n },\n }\n\n function stepIssues(label: 'incorrect' | 'unuseful', steps: readonly number[]) {\n return steps.map((rawStep) => {\n const step = positiveStep(rawStep, `CodeTraceBench '${trajectoryId}' ${label} step`)\n if (step > stepCount) {\n throw new RangeError(\n `CodeTraceBench '${trajectoryId}' ${label} step ${step} exceeds step_count ${stepCount}`,\n )\n }\n const id = `${label}:${step}`\n if (labels.has(id)) {\n throw new TypeError(`CodeTraceBench '${trajectoryId}' repeats label '${id}'`)\n }\n labels.add(id)\n return {\n id,\n areas: [label],\n evidence: [{ kind: evidenceKind, uri: uri(trajectoryId, step) }],\n }\n })\n }\n}\n\n/** Translate CodeTracer's `codetracer_labels.json` into shared findings. */\nexport function codeTracerPredictionsToFindings(\n trajectoryIdValue: string,\n predictions: CodeTracerPredictions,\n options: CodeTracerPredictionAdapterOptions = {},\n): AnalystFinding[] {\n const trajectoryId = nonEmpty(trajectoryIdValue, 'CodeTracer prediction trajectory id')\n const labels = parseCodeTracerPredictionLabels(predictions, trajectoryId)\n const confidence = predictionConfidence(options.confidence)\n const uri = options.stepUri ?? defaultStepUri\n const labelSet = codeTraceLabelSet(options.labelSet)\n const seen = new Set<string>()\n const findings: AnalystFinding[] = []\n for (const label of labels) {\n const step = positiveStep(\n label.step,\n `CodeTracer prediction '${trajectoryId}' ${label.area} step`,\n )\n assertStepWithinRange(step, options.stepCount, `CodeTracer prediction '${trajectoryId}'`)\n const key = `${label.area}:${step}`\n if (seen.has(key)) {\n throw new TypeError(`CodeTracer prediction '${trajectoryId}' repeats label '${key}'`)\n }\n seen.add(key)\n if (label.area === 'unuseful' && labelSet === 'incorrect-only') continue\n findings.push(\n makeFinding({\n analyst_id: options.analystId ?? 'codetracer',\n produced_at: options.producedAt,\n area: label.area,\n subject: `step-${step}`,\n claim: `CodeTracer labeled step ${step} as ${label.area}.`,\n id_basis: key,\n rationale: label.reasoning,\n severity: 'medium',\n confidence,\n evidence_refs: [\n {\n kind: options.evidenceKind ?? 'span',\n uri: uri(trajectoryId, step),\n },\n ],\n metadata: {\n upstream: 'CodeTracer',\n stage_id: label.stageId,\n step,\n },\n }),\n )\n }\n return findings\n}\n\nfunction parseCodeTraceStages(\n value: CodeTraceBenchRow['incorrect_stages'],\n trajectoryId: string,\n): readonly CodeTraceStageAnnotation[] {\n let parsed: unknown = value\n if (typeof value === 'string') {\n try {\n parsed = JSON.parse(value) as unknown\n } catch (error) {\n throw new TypeError(\n `CodeTraceBench '${trajectoryId}' incorrect_stages is invalid JSON: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n if (!Array.isArray(parsed)) {\n throw new TypeError(`CodeTraceBench '${trajectoryId}' incorrect_stages must be an array`)\n }\n const stageIds = new Set<number>()\n for (const stage of parsed) {\n if (\n !stage ||\n typeof stage !== 'object' ||\n !Number.isSafeInteger((stage as CodeTraceStageAnnotation).stage_id) ||\n (stage as CodeTraceStageAnnotation).stage_id < 1 ||\n !optionalStepArray((stage as CodeTraceStageAnnotation).incorrect_step_ids) ||\n !optionalStepArray((stage as CodeTraceStageAnnotation).unuseful_step_ids) ||\n ((stage as CodeTraceStageAnnotation).reasoning !== undefined &&\n typeof (stage as CodeTraceStageAnnotation).reasoning !== 'string')\n ) {\n throw new TypeError(`CodeTraceBench '${trajectoryId}' contains an invalid stage annotation`)\n }\n const stageId = (stage as CodeTraceStageAnnotation).stage_id\n if (stageIds.has(stageId)) {\n throw new TypeError(`CodeTraceBench '${trajectoryId}' repeats stage_id ${stageId}`)\n }\n stageIds.add(stageId)\n }\n return parsed as unknown as readonly CodeTraceStageAnnotation[]\n}\n\nfunction parseCodeTracerPredictionLabels(\n value: CodeTracerPredictions,\n trajectoryId: string,\n): Array<{\n stageId: string | number\n area: CodeTracerStepLabel['label']\n step: number\n reasoning?: string\n}> {\n let parsed: unknown = value\n if (typeof value === 'string') {\n try {\n parsed = JSON.parse(value) as unknown\n } catch (error) {\n throw new TypeError(\n `CodeTracer prediction '${trajectoryId}' is invalid JSON: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n if (!Array.isArray(parsed)) {\n throw new TypeError(`CodeTracer prediction '${trajectoryId}' must be an array`)\n }\n if (parsed.length === 0) return []\n\n if (parsed.every(isCodeTraceStageAnnotation)) {\n return (parsed as readonly CodeTraceStageAnnotation[]).flatMap((stage) => [\n ...(stage.incorrect_step_ids ?? []).map((step) => ({\n stageId: stage.stage_id,\n area: 'incorrect' as const,\n step,\n ...(stage.reasoning === undefined ? {} : { reasoning: stage.reasoning }),\n })),\n ...(stage.unuseful_step_ids ?? []).map((step) => ({\n stageId: stage.stage_id,\n area: 'unuseful' as const,\n step,\n ...(stage.reasoning === undefined ? {} : { reasoning: stage.reasoning }),\n })),\n ])\n }\n\n const flat: Array<{\n stageId: string | number\n area: CodeTracerStepLabel['label']\n step: number\n reasoning?: string\n }> = []\n for (const [index, item] of parsed.entries()) {\n if (isCodeTracerStepLabel(item)) {\n flat.push(\n toCodeTracerPredictionLabel(\n item,\n codeTracerStageId(item, index + 1, trajectoryId),\n trajectoryId,\n ),\n )\n continue\n }\n if (!isRecord(item) || !Array.isArray(item.labels)) {\n throw new TypeError(\n `CodeTracer prediction '${trajectoryId}' contains an unsupported label row`,\n )\n }\n const stageId = codeTracerStageId(item, index + 1, trajectoryId)\n for (const label of item.labels) {\n if (!isCodeTracerStepLabel(label)) {\n throw new TypeError(\n `CodeTracer prediction '${trajectoryId}' contains an invalid step label`,\n )\n }\n flat.push(toCodeTracerPredictionLabel(label, stageId, trajectoryId))\n }\n }\n return flat\n}\n\nfunction isCodeTraceStageAnnotation(value: unknown): value is CodeTraceStageAnnotation {\n return (\n isRecord(value) &&\n Number.isSafeInteger(value.stage_id) &&\n (value.stage_id as number) > 0 &&\n optionalStepArray(value.incorrect_step_ids as readonly number[] | undefined) &&\n optionalStepArray(value.unuseful_step_ids as readonly number[] | undefined) &&\n (value.reasoning === undefined || typeof value.reasoning === 'string')\n )\n}\n\nfunction isCodeTracerStepLabel(value: unknown): value is CodeTracerStepLabel {\n return (\n isRecord(value) &&\n Number.isSafeInteger(value.step_id) &&\n (value.step_id as number) > 0 &&\n (value.stage === undefined ||\n typeof value.stage === 'string' ||\n typeof value.stage === 'number') &&\n (value.stage_name === undefined ||\n typeof value.stage_name === 'string' ||\n typeof value.stage_name === 'number') &&\n (value.stage_id === undefined ||\n typeof value.stage_id === 'string' ||\n typeof value.stage_id === 'number') &&\n (value.label === 'incorrect' || value.label === 'unuseful') &&\n (value.rationale === undefined || typeof value.rationale === 'string') &&\n (value.reason === undefined || typeof value.reason === 'string') &&\n (value.note === undefined || typeof value.note === 'string') &&\n (value.comment === undefined || typeof value.comment === 'string')\n )\n}\n\nfunction toCodeTracerPredictionLabel(\n label: CodeTracerStepLabel,\n stageId: string | number,\n trajectoryId: string,\n): {\n stageId: string | number\n area: CodeTracerStepLabel['label']\n step: number\n reasoning?: string\n} {\n if (!isCodeTracerStepLabel(label)) {\n throw new TypeError(`CodeTracer prediction '${trajectoryId}' contains an invalid step label`)\n }\n return {\n stageId,\n area: label.label,\n step: label.step_id,\n ...codeTracerReason(label, trajectoryId),\n }\n}\n\nfunction codeTracerStageId(\n value: { stage?: unknown; stage_name?: unknown; stage_id?: unknown },\n fallback: number,\n trajectoryId: string,\n): string | number {\n const candidates = [value.stage, value.stage_name, value.stage_id].filter(\n (candidate): candidate is string | number =>\n typeof candidate === 'string' || typeof candidate === 'number',\n )\n if (new Set(candidates).size > 1) {\n throw new TypeError(`CodeTracer prediction '${trajectoryId}' has conflicting stage fields`)\n }\n return candidates[0] ?? fallback\n}\n\nfunction codeTracerReason(\n label: CodeTracerStepLabel,\n trajectoryId: string,\n): { reasoning?: string } {\n const candidates = [label.rationale, label.reason, label.note, label.comment].filter(\n (candidate): candidate is string => candidate !== undefined,\n )\n if (new Set(candidates).size > 1) {\n throw new TypeError(\n `CodeTracer prediction '${trajectoryId}' step ${label.step_id} has conflicting reason fields`,\n )\n }\n return candidates[0] === undefined ? {} : { reasoning: candidates[0] }\n}\n\nfunction parseTags(value: CodeTraceBenchRow['tags'], trajectoryId: string): string[] {\n if (value === undefined) return []\n let parsed: unknown = value\n if (typeof value === 'string') {\n try {\n parsed = JSON.parse(value) as unknown\n } catch (error) {\n throw new TypeError(\n `CodeTraceBench '${trajectoryId}' tags is invalid JSON: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n if (!Array.isArray(parsed)) {\n throw new TypeError(`CodeTraceBench '${trajectoryId}' tags must be an array of strings`)\n }\n const tags = parsed.map((tag, index) =>\n requiredCodeTraceString(tag, `CodeTraceBench '${trajectoryId}' tags[${index}]`),\n )\n if (new Set(tags).size !== tags.length) {\n throw new TypeError(`CodeTraceBench '${trajectoryId}' tags must not repeat values`)\n }\n return tags\n}\n\nfunction codeTraceLabelSet(value: CodeTraceBenchLabelSet | undefined): CodeTraceBenchLabelSet {\n if (value === undefined || value === 'incorrect-only') return 'incorrect-only'\n if (value === 'incorrect-and-unuseful') return value\n throw new TypeError(\n \"CodeTraceBench labelSet must be 'incorrect-only' or 'incorrect-and-unuseful'\",\n )\n}\n\nfunction optionalStepArray(value: readonly number[] | undefined): boolean {\n return value === undefined || (Array.isArray(value) && value.every(Number.isSafeInteger))\n}\n\nfunction requiredCodeTraceString(value: unknown, field: string): string {\n if (typeof value !== 'string') throw new TypeError(`${field} must be a string`)\n return nonEmpty(value, field)\n}\n\nfunction optionalCodeTraceString(value: unknown, field: string): string | undefined {\n if (value === undefined) return undefined\n return requiredCodeTraceString(value, field)\n}\n\nfunction optionalSourceRelativePath(value: unknown, trajectoryId: string): string | undefined {\n const path = optionalCodeTraceString(value, `CodeTraceBench '${trajectoryId}' source_relpath`)\n if (path === undefined) return undefined\n const segments = path.replaceAll('\\\\', '/').split('/')\n if (\n path.startsWith('/') ||\n /^[a-zA-Z]:[\\\\/]/.test(path) ||\n segments.some((segment) => segment === '..')\n ) {\n throw new TypeError(\n `CodeTraceBench '${trajectoryId}' source_relpath must stay within the artifact root`,\n )\n }\n return path\n}\n\nfunction codeTraceSolved(value: unknown, trajectoryId: string): boolean | null | undefined {\n if (value === undefined || value === null || typeof value === 'boolean') return value\n throw new TypeError(`CodeTraceBench '${trajectoryId}' solved must be a boolean or null`)\n}\n","import type { AnalystBenchmarkObservation, AnalystBenchmarkResult } from './benchmark'\nimport { roundAgentRxStep } from './benchmark-datasets'\n\nexport const AGENT_RX_UPSTREAM_REVISION = 'f228165bfec60a801fd5fedd9d8ffe0f9de0c69d'\n\nexport interface AgentRxCalibrationRunnerSummary {\n runnerId: string\n selectedRuns: number\n completedRuns: number\n failedRuns: number\n predictedRuns: number\n missingPredictionRuns: number\n exactStepAccuracy: number | null\n stepAccuracyWithin1: number | null\n stepAccuracyWithin2: number | null\n stepAccuracyWithin3: number | null\n stepAccuracyWithin4: number | null\n stepAccuracyWithin5: number | null\n meanStepDistance: number | null\n normalizedMeanStepDistance: number | null\n normalizedDistanceRuns: number\n normalizedDistanceUnknownRuns: number\n rootCauseCategoryAccuracy: number | null\n anyFailureCategoryAccuracy: number | null\n earliestFailureCategoryAccuracy: number | null\n terminalFailureCategoryAccuracy: number | null\n}\n\nexport interface AgentRxCalibrationSummary {\n protocol: 'official-agentrx-root-cause'\n upstreamRevision: string\n rationale: string\n runners: AgentRxCalibrationRunnerSummary[]\n}\n\nexport function summarizeAgentRxCalibration(\n result: AnalystBenchmarkResult,\n upstreamRevision: string,\n): AgentRxCalibrationSummary {\n if (!upstreamRevision.trim()) {\n throw new TypeError('AgentRx calibration requires an upstream revision')\n }\n return {\n protocol: 'official-agentrx-root-cause',\n upstreamRevision,\n rationale:\n 'Matches AgentRx root-category accuracy, Python-rounded exact and tolerance step accuracy, unrounded mean step distance, normalized distance, and any, earliest, and terminal category accuracy. Failed runs and empty predictions score as no prediction.',\n runners: result.provenance.runnerIds.map((runnerId) =>\n summarizeRunner(\n runnerId,\n result.observations.filter((observation) => observation.runnerId === runnerId),\n ),\n ),\n }\n}\n\nexport function renderAgentRxCalibrationMarkdown(summary: AgentRxCalibrationSummary): string {\n return [\n '## AgentRx Published Metrics',\n '',\n summary.rationale,\n '',\n `Upstream revision: \\`${summary.upstreamRevision}\\`.`,\n '',\n '| Runner | Completed/selected | Failed | Predictions | Missing predictions | Exact step | Within 1 | Within 2 | Within 3 | Within 4 | Within 5 | Mean step distance | Normalized distance | Normalized known/unknown | Root category | Any category | Earliest category | Terminal category |',\n '| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |',\n ...summary.runners.map(\n (runner) =>\n `| ${escapeCell(runner.runnerId)} | ${runner.completedRuns}/${runner.selectedRuns} | ${runner.failedRuns} | ${runner.predictedRuns} | ${runner.missingPredictionRuns} | ${rate(runner.exactStepAccuracy)} | ${rate(runner.stepAccuracyWithin1)} | ${rate(runner.stepAccuracyWithin2)} | ${rate(runner.stepAccuracyWithin3)} | ${rate(runner.stepAccuracyWithin4)} | ${rate(runner.stepAccuracyWithin5)} | ${number(runner.meanStepDistance)} | ${number(runner.normalizedMeanStepDistance)} | ${runner.normalizedDistanceRuns}/${runner.normalizedDistanceUnknownRuns} | ${rate(runner.rootCauseCategoryAccuracy)} | ${rate(runner.anyFailureCategoryAccuracy)} | ${rate(runner.earliestFailureCategoryAccuracy)} | ${rate(runner.terminalFailureCategoryAccuracy)} |`,\n ),\n ].join('\\n')\n}\n\nfunction summarizeRunner(\n runnerId: string,\n observations: readonly AnalystBenchmarkObservation[],\n): AgentRxCalibrationRunnerSummary {\n const scored = observations.map(scoredObservation)\n const normalized = scored.filter(\n (row): row is ReturnType<typeof scoredObservation> & { normalizedDistance: number } =>\n row.normalizedDistance !== null,\n )\n const predicted = scored.filter(\n (row): row is ReturnType<typeof scoredObservation> & { distance: number } =>\n row.distance !== null,\n )\n return {\n runnerId,\n selectedRuns: observations.length,\n completedRuns: observations.filter((observation) => !observation.error).length,\n failedRuns: observations.filter((observation) => Boolean(observation.error)).length,\n predictedRuns: predicted.length,\n missingPredictionRuns: scored.length - predicted.length,\n exactStepAccuracy: mean(scored.map((row) => Number(row.roundedDistance === 0))),\n stepAccuracyWithin1: mean(\n scored.map((row) => Number(row.roundedDistance !== null && row.roundedDistance <= 1)),\n ),\n stepAccuracyWithin2: mean(\n scored.map((row) => Number(row.roundedDistance !== null && row.roundedDistance <= 2)),\n ),\n stepAccuracyWithin3: mean(\n scored.map((row) => Number(row.roundedDistance !== null && row.roundedDistance <= 3)),\n ),\n stepAccuracyWithin4: mean(\n scored.map((row) => Number(row.roundedDistance !== null && row.roundedDistance <= 4)),\n ),\n stepAccuracyWithin5: mean(\n scored.map((row) => Number(row.roundedDistance !== null && row.roundedDistance <= 5)),\n ),\n meanStepDistance: mean(predicted.map((row) => row.distance)),\n normalizedMeanStepDistance: mean(normalized.map((row) => row.normalizedDistance)),\n normalizedDistanceRuns: normalized.length,\n normalizedDistanceUnknownRuns: scored.length - normalized.length,\n rootCauseCategoryAccuracy: mean(scored.map((row) => Number(row.rootCategoryMatch))),\n anyFailureCategoryAccuracy: mean(scored.map((row) => Number(row.anyCategoryMatch))),\n earliestFailureCategoryAccuracy: mean(scored.map((row) => Number(row.earliestCategoryMatch))),\n terminalFailureCategoryAccuracy: mean(scored.map((row) => Number(row.terminalCategoryMatch))),\n }\n}\n\nfunction scoredObservation(observation: AnalystBenchmarkObservation) {\n const metadata = record(observation.caseMetadata)\n const rootStep = requiredPositiveNumber(\n metadata.rootCauseStep,\n observation.caseId,\n 'rootCauseStep',\n )\n const rootCategory = requiredString(\n metadata.rootCauseCategory,\n observation.caseId,\n 'rootCauseCategory',\n )\n const allCategories = requiredStringArray(\n metadata.allFailureCategories,\n observation.caseId,\n 'allFailureCategories',\n )\n const earliestCategory = requiredString(\n metadata.earliestFailureCategory,\n observation.caseId,\n 'earliestFailureCategory',\n )\n const terminalCategory = requiredString(\n metadata.terminalFailureCategory,\n observation.caseId,\n 'terminalFailureCategory',\n )\n const finding = observation.error ? undefined : observation.findings[0]\n const findingMetadata = record(finding?.metadata)\n const stepMean = finding\n ? finiteNonNegative(\n findingMetadata.step_mean ?? findingMetadata.step,\n observation.caseId,\n 'predicted step',\n )\n : null\n const roundedDistance = stepMean === null ? null : Math.abs(roundAgentRxStep(stepMean) - rootStep)\n const distance = stepMean === null ? null : Math.abs(stepMean - rootStep)\n const trajectoryLength =\n metadata.trajectoryLength === undefined\n ? null\n : requiredPositiveNumber(metadata.trajectoryLength, observation.caseId, 'trajectoryLength')\n const predictedCategory = finding?.area\n return {\n roundedDistance,\n distance,\n normalizedDistance:\n trajectoryLength === null || distance === null ? null : distance / trajectoryLength,\n rootCategoryMatch: predictedCategory === rootCategory,\n anyCategoryMatch: predictedCategory !== undefined && allCategories.includes(predictedCategory),\n earliestCategoryMatch: predictedCategory === earliestCategory,\n terminalCategoryMatch: predictedCategory === terminalCategory,\n }\n}\n\nfunction record(value: unknown): Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : {}\n}\n\nfunction requiredPositiveNumber(value: unknown, caseId: string, field: string): number {\n const numberValue = finiteNonNegative(value, caseId, field)\n if (numberValue <= 0) throw new TypeError(`${caseId}: ${field} must be positive`)\n return numberValue\n}\n\nfunction finiteNonNegative(value: unknown, caseId: string, field: string): number {\n if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {\n throw new TypeError(`${caseId}: ${field} must be a finite non-negative number`)\n }\n return value\n}\n\nfunction requiredString(value: unknown, caseId: string, field: string): string {\n if (typeof value !== 'string' || !value.trim()) {\n throw new TypeError(`${caseId}: ${field} must be a non-empty string`)\n }\n return value\n}\n\nfunction requiredStringArray(value: unknown, caseId: string, field: string): string[] {\n if (\n !Array.isArray(value) ||\n value.length === 0 ||\n value.some((entry) => typeof entry !== 'string' || !entry.trim())\n ) {\n throw new TypeError(`${caseId}: ${field} must be a non-empty string array`)\n }\n return value as string[]\n}\n\nfunction mean(values: readonly number[]): number | null {\n return values.length === 0\n ? null\n : values.reduce((total, value) => total + value, 0) / values.length\n}\n\nfunction rate(value: number | null): string {\n return value === null ? 'n/a' : value.toFixed(3)\n}\n\nfunction number(value: number | null): string {\n return value === null ? 'n/a' : value.toFixed(3)\n}\n\nfunction escapeCell(value: string): string {\n return value.replaceAll('|', '\\\\|').replaceAll('\\n', ' ')\n}\n","import { pairedBootstrap } from '../statistics'\nimport type { AnalystBenchmarkObservation, AnalystBenchmarkResult } from './benchmark'\n\n/**\n * Every metric a benchmark comparison reports, mapped to the direction that\n * is an improvement. This table is the only declaration of the vocabulary:\n * the type, the reporting order, the artifact schema's accepted values, and\n * each metric's direction all derive from it, so a metric cannot exist in one\n * of those four places and be missing from another.\n */\nconst ANALYST_COMPARISON_METRIC_DIRECTION = {\n completion: 'higher',\n issueRecall: 'higher',\n findingPrecision: 'higher',\n f1: 'higher',\n criticalStepAccuracy: 'higher',\n citationCoverage: 'higher',\n citationExcerptCoverage: 'higher',\n citationLabelAgreement: 'higher',\n citationResolution: 'higher',\n trustedNegativeAccuracy: 'higher',\n latencyMs: 'lower',\n calls: 'lower',\n inputTokens: 'lower',\n outputTokens: 'lower',\n reasoningTokens: 'lower',\n cachedTokens: 'lower',\n cacheWriteTokens: 'lower',\n costUsd: 'lower',\n} as const satisfies Record<string, 'higher' | 'lower'>\n\nexport type AnalystComparisonMetric = keyof typeof ANALYST_COMPARISON_METRIC_DIRECTION\n\n/** The vocabulary as a non-empty tuple, which is what `z.enum` accepts. Key\n * order is the declaration order above, and it is the reporting order. */\nexport const ANALYST_COMPARISON_METRICS = Object.keys(ANALYST_COMPARISON_METRIC_DIRECTION) as [\n AnalystComparisonMetric,\n ...AnalystComparisonMetric[],\n]\n\n/** `'lower'` when a smaller value is the improvement. */\nexport function analystComparisonMetricDirection(\n metric: AnalystComparisonMetric,\n): 'higher' | 'lower' {\n return ANALYST_COMPARISON_METRIC_DIRECTION[metric]\n}\n\nexport interface AnalystMetricComparison {\n metric: AnalystComparisonMetric\n direction: 'higher' | 'lower'\n /** Trajectories with at least one complete pair for this metric. */\n pairedCases: number\n /** Independent task or incident groups resampled by the interval. */\n pairedClusters: number\n /** Same-run pairs where this metric applies before missing values are removed. */\n eligibleObservations: number\n pairedObservations: number\n baselineMissingObservations: number\n candidateMissingObservations: number\n asymmetricMissingObservations: number\n survivorOnly: boolean\n baselineMean: number | null\n candidateMean: number | null\n meanDelta: number | null\n intervalLow: number | null\n intervalHigh: number | null\n confidence: number\n resamples: number\n minimumSampleMet: boolean\n populationInferenceEligible: boolean\n inferenceLimitations: string[]\n}\n\nexport interface AnalystRunnerComparison {\n baselineRunnerId: string\n candidateRunnerId: string\n metrics: AnalystMetricComparison[]\n}\n\ninterface PairedCaseMetric {\n clusterId: string\n baseline: number\n candidate: number\n}\n\nexport function compareAnalystRunners(\n result: AnalystBenchmarkResult,\n options: {\n baselineRunnerId: string\n candidateRunnerId: string\n confidence?: number\n resamples?: number\n seed?: number\n },\n): AnalystRunnerComparison {\n const confidence = options.confidence ?? 0.95\n const resamples = options.resamples ?? 2000\n assertComparisonControls(confidence, resamples)\n\n const runnerIds = new Set(result.summaries.map((summary) => summary.runnerId))\n if (!runnerIds.has(options.baselineRunnerId)) {\n throw new TypeError(`unknown baseline analyst runner '${options.baselineRunnerId}'`)\n }\n if (!runnerIds.has(options.candidateRunnerId)) {\n throw new TypeError(`unknown candidate analyst runner '${options.candidateRunnerId}'`)\n }\n if (options.baselineRunnerId === options.candidateRunnerId) {\n throw new TypeError('baseline and candidate analyst runners must be different')\n }\n\n const baseline = observationsByCase(result.observations, options.baselineRunnerId)\n const candidate = observationsByCase(result.observations, options.candidateRunnerId)\n const populationRepresentativenessProven =\n result.provenance.metadata?.populationRepresentativenessProven === true\n const metrics = ANALYST_COMPARISON_METRICS.map((metric) =>\n compareMetric({\n metric,\n baseline,\n candidate,\n confidence,\n resamples,\n seed: options.seed,\n populationRepresentativenessProven,\n }),\n )\n\n return {\n baselineRunnerId: options.baselineRunnerId,\n candidateRunnerId: options.candidateRunnerId,\n metrics,\n }\n}\n\nfunction compareMetric(options: {\n metric: AnalystComparisonMetric\n baseline: Map<string, AnalystBenchmarkObservation[]>\n candidate: Map<string, AnalystBenchmarkObservation[]>\n confidence: number\n resamples: number\n seed?: number\n populationRepresentativenessProven: boolean\n}): AnalystMetricComparison {\n const pairedCases: PairedCaseMetric[] = []\n let eligibleObservations = 0\n let pairedObservations = 0\n let baselineMissingObservations = 0\n let candidateMissingObservations = 0\n let asymmetricMissingObservations = 0\n\n const caseIds = new Set([...options.baseline.keys(), ...options.candidate.keys()])\n for (const caseId of caseIds) {\n const baselineByRepetition = new Map(\n (options.baseline.get(caseId) ?? []).map((observation) => [\n observation.repetition,\n observation,\n ]),\n )\n const candidateByRepetition = new Map(\n (options.candidate.get(caseId) ?? []).map((observation) => [\n observation.repetition,\n observation,\n ]),\n )\n const caseBefore: number[] = []\n const caseAfter: number[] = []\n let clusterId: string | undefined\n const repetitions = new Set([...baselineByRepetition.keys(), ...candidateByRepetition.keys()])\n for (const repetition of repetitions) {\n const baselineObservation = baselineByRepetition.get(repetition)\n const candidateObservation = candidateByRepetition.get(repetition)\n const identity = baselineObservation ?? candidateObservation\n if (!identity || !metricApplies(identity, options.metric)) continue\n if (baselineObservation && candidateObservation) {\n assertSameCaseIdentity(baselineObservation, candidateObservation)\n }\n eligibleObservations += 1\n clusterId = identity.clusterId\n const baselineValue = baselineObservation\n ? metricValue(baselineObservation, options.metric)\n : null\n const candidateValue = candidateObservation\n ? metricValue(candidateObservation, options.metric)\n : null\n const baselineMissing = baselineValue === null\n const candidateMissing = candidateValue === null\n if (baselineMissing) baselineMissingObservations += 1\n if (candidateMissing) candidateMissingObservations += 1\n if (baselineMissing !== candidateMissing) asymmetricMissingObservations += 1\n if (baselineMissing || candidateMissing) continue\n caseBefore.push(baselineValue)\n caseAfter.push(candidateValue)\n pairedObservations += 1\n }\n if (caseBefore.length === 0 || !clusterId) continue\n pairedCases.push({\n clusterId,\n baseline: mean(caseBefore),\n candidate: mean(caseAfter),\n })\n }\n\n const byCluster = new Map<string, PairedCaseMetric[]>()\n for (const pairedCase of pairedCases) {\n const rows = byCluster.get(pairedCase.clusterId) ?? []\n rows.push(pairedCase)\n byCluster.set(pairedCase.clusterId, rows)\n }\n const before = [...byCluster.values()].map((rows) => mean(rows.map((row) => row.baseline)))\n const after = [...byCluster.values()].map((rows) => mean(rows.map((row) => row.candidate)))\n const interval =\n before.length === 0\n ? null\n : pairedBootstrap(before, after, {\n confidence: options.confidence,\n resamples: options.resamples,\n statistic: 'mean',\n seed: options.seed,\n })\n const survivorOnly = pairedObservations < eligibleObservations\n const limitations: string[] = []\n if (!interval?.gateEligible) limitations.push('fewer-than-20-independent-clusters')\n if (!options.populationRepresentativenessProven) {\n limitations.push('population-representativeness-not-proven')\n }\n if (survivorOnly) limitations.push('missing-observations')\n\n const comparison: AnalystMetricComparison = {\n metric: options.metric,\n direction: analystComparisonMetricDirection(options.metric),\n pairedCases: pairedCases.length,\n pairedClusters: before.length,\n eligibleObservations,\n pairedObservations,\n baselineMissingObservations,\n candidateMissingObservations,\n asymmetricMissingObservations,\n survivorOnly,\n baselineMean: before.length === 0 ? null : mean(before),\n candidateMean: after.length === 0 ? null : mean(after),\n meanDelta: interval?.mean ?? null,\n intervalLow: interval?.low ?? null,\n intervalHigh: interval?.high ?? null,\n confidence: options.confidence,\n resamples: options.resamples,\n minimumSampleMet: interval?.gateEligible ?? false,\n populationInferenceEligible: limitations.length === 0,\n inferenceLimitations: limitations,\n }\n assertValidComparison(comparison)\n return comparison\n}\n\nfunction observationsByCase(\n observations: readonly AnalystBenchmarkObservation[],\n runnerId: string,\n): Map<string, AnalystBenchmarkObservation[]> {\n const byCase = new Map<string, AnalystBenchmarkObservation[]>()\n for (const observation of observations) {\n if (observation.runnerId !== runnerId) continue\n const rows = byCase.get(observation.caseId) ?? []\n rows.push(observation)\n byCase.set(observation.caseId, rows)\n }\n return byCase\n}\n\nfunction assertSameCaseIdentity(\n baseline: AnalystBenchmarkObservation,\n candidate: AnalystBenchmarkObservation,\n): void {\n if (baseline.clusterId !== candidate.clusterId || baseline.labelState !== candidate.labelState) {\n throw new Error(\n `analyst comparison case identity differs for '${baseline.caseId}' repetition ${baseline.repetition}`,\n )\n }\n}\n\nfunction metricApplies(\n observation: AnalystBenchmarkObservation,\n metric: AnalystComparisonMetric,\n): boolean {\n if (metric === 'trustedNegativeAccuracy') {\n return observation.labelState === 'trusted-negative'\n }\n if (metric === 'issueRecall' || metric === 'findingPrecision' || metric === 'f1') {\n return observation.labelState === 'positive'\n }\n if (metric === 'criticalStepAccuracy') {\n return observation.labelState === 'positive' && observation.score.criticalStepAccuracy !== null\n }\n return true\n}\n\nfunction metricValue(\n observation: AnalystBenchmarkObservation,\n metric: AnalystComparisonMetric,\n): number | null {\n if (metric === 'completion') return observation.error ? 0 : 1\n if (metric === 'latencyMs') return observation.latencyMs\n if (metric === 'trustedNegativeAccuracy') {\n if (observation.error) return 0\n return observation.score.predictionOnLabelEmptyCase ? 0 : 1\n }\n if (\n observation.error &&\n (metric === 'issueRecall' ||\n metric === 'findingPrecision' ||\n metric === 'f1' ||\n metric === 'criticalStepAccuracy')\n ) {\n return 0\n }\n if (\n observation.error &&\n (metric === 'citationCoverage' ||\n metric === 'citationExcerptCoverage' ||\n metric === 'citationLabelAgreement' ||\n metric === 'citationResolution')\n ) {\n return null\n }\n if (metric === 'issueRecall') return observation.score.issueRecall\n if (metric === 'findingPrecision') return observation.score.findingPrecision\n if (metric === 'f1') return observation.score.f1\n if (metric === 'criticalStepAccuracy') return observation.score.criticalStepAccuracy\n if (metric === 'citationCoverage') return observation.score.citationCoverage\n if (metric === 'citationExcerptCoverage') return observation.score.citationExcerptCoverage\n if (metric === 'citationLabelAgreement') return observation.score.citationLabelAgreement\n if (metric === 'citationResolution') return observation.evidenceResolution?.validity ?? null\n if (metric === 'calls') return observation.usage?.calls ?? null\n if (metric === 'inputTokens') return observation.usage?.tokens?.input ?? null\n if (metric === 'outputTokens') return observation.usage?.tokens?.output ?? null\n if (metric === 'reasoningTokens') return observation.usage?.tokens?.reasoning ?? null\n if (metric === 'cachedTokens') return observation.usage?.tokens?.cached ?? null\n if (metric === 'cacheWriteTokens') return observation.usage?.tokens?.cacheWrite ?? null\n if (observation.usage?.cost.kind === 'uncaptured') return null\n return observation.usage?.cost.usd ?? null\n}\n\nfunction mean(values: readonly number[]): number {\n return values.reduce((sum, value) => sum + value, 0) / values.length\n}\n\nfunction assertComparisonControls(confidence: number, resamples: number): void {\n if (!Number.isSafeInteger(resamples) || resamples <= 0 || resamples > 1_000_000) {\n throw new Error(\n `compareAnalystRunners: resamples must be a positive safe integer no greater than 1000000, got ${String(resamples)}`,\n )\n }\n if (!Number.isFinite(confidence) || confidence <= 0 || confidence >= 1) {\n throw new Error(\n `compareAnalystRunners: confidence must be a finite number in (0,1), got ${String(confidence)}`,\n )\n }\n}\n\nfunction assertValidComparison(comparison: AnalystMetricComparison): void {\n const numericFields = [\n 'pairedCases',\n 'pairedClusters',\n 'eligibleObservations',\n 'pairedObservations',\n 'baselineMissingObservations',\n 'candidateMissingObservations',\n 'asymmetricMissingObservations',\n 'confidence',\n 'resamples',\n ] as const\n const nullableFields = [\n 'baselineMean',\n 'candidateMean',\n 'meanDelta',\n 'intervalLow',\n 'intervalHigh',\n ] as const\n if (\n numericFields.some((field) => !Number.isFinite(comparison[field])) ||\n nullableFields.some(\n (field) => comparison[field] !== null && !Number.isFinite(comparison[field]),\n )\n ) {\n throw new Error(\n `compareAnalystRunners: ${comparison.metric} produced non-finite comparison output`,\n )\n }\n if (\n comparison.intervalLow !== null &&\n comparison.intervalHigh !== null &&\n comparison.intervalLow > comparison.intervalHigh\n ) {\n throw new Error(\n `compareAnalystRunners: ${comparison.metric} produced an invalid confidence interval`,\n )\n }\n}\n","import { z } from 'zod'\nimport type { AnalystBenchmarkObservation } from './benchmark'\nimport type { AnalystBenchmarkArtifact } from './benchmark-command-artifact'\nimport { ANALYST_COMPARISON_METRICS } from './benchmark-comparison'\n\nconst nonEmptyString = z.string().refine((value) => value.trim().length > 0, {\n message: 'must be a non-empty string',\n})\nconst safeInteger = z.number().refine(Number.isSafeInteger, {\n message: 'must be a safe integer',\n})\nconst nonNegativeInteger = safeInteger.refine((value) => value >= 0, {\n message: 'must be a non-negative safe integer',\n})\nconst positiveInteger = safeInteger.refine((value) => value > 0, {\n message: 'must be a positive safe integer',\n})\nconst nonNegativeNumber = z.number().nonnegative()\nconst rate = z.number().min(0).max(1)\nconst nullableRate = rate.nullable()\nconst finiteNumber = z.number()\nconst nullableFiniteNumber = finiteNumber.nullable()\nconst sha256 = z.string().regex(/^[a-f0-9]{64}$/, 'must be a lowercase SHA-256 digest')\nconst revision = z\n .string()\n .regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/, 'must be a lowercase 40 or 64 character revision')\nconst timestamp = z.string().refine((value) => Number.isFinite(Date.parse(value)), {\n message: 'must be a valid timestamp',\n})\nconst stringArray = z.array(z.string())\nconst nonEmptyStringArray = z.array(nonEmptyString)\nconst metadata = z.record(z.string(), z.unknown())\n\nconst errorSchema = z.strictObject({\n class: nonEmptyString,\n message: nonEmptyString,\n code: nonEmptyString.optional(),\n status: z.number().int().min(100).max(599).optional(),\n})\n\nconst evidenceSchema = z.strictObject({\n kind: z.enum(['span', 'event', 'artifact', 'finding', 'metric']),\n uri: nonEmptyString,\n excerpt: z.string().optional(),\n})\n\nconst findingSchema = z.strictObject({\n schema_version: z.literal('1.0.0'),\n finding_id: nonEmptyString,\n analyst_id: nonEmptyString,\n produced_at: timestamp,\n severity: z.enum(['critical', 'high', 'medium', 'low', 'info']),\n area: nonEmptyString,\n claim: nonEmptyString,\n rationale: z.string().optional(),\n evidence_refs: z.array(evidenceSchema),\n recommended_action: z.string().optional(),\n validation_plan: z.string().optional(),\n confidence: rate,\n subject: z.string().optional(),\n derived_from_judge: z.boolean().optional(),\n metadata: metadata.optional(),\n})\n\nconst tokenUsageSchema = z\n .strictObject({\n input: nonNegativeInteger,\n output: nonNegativeInteger,\n reasoning: nonNegativeInteger.optional(),\n cached: nonNegativeInteger.optional(),\n cacheWrite: nonNegativeInteger.optional(),\n })\n .superRefine((usage, context) => {\n if (usage.reasoning !== undefined && usage.reasoning > usage.output) {\n context.addIssue({\n code: 'custom',\n path: ['reasoning'],\n message: 'must not exceed output tokens',\n })\n }\n })\n\nconst costSchema = z.discriminatedUnion('kind', [\n z.strictObject({\n kind: z.literal('observed'),\n usd: nonNegativeNumber,\n }),\n z.strictObject({\n kind: z.literal('estimated'),\n usd: nonNegativeNumber,\n }),\n z.strictObject({\n kind: z.literal('uncaptured'),\n usd: z.null(),\n }),\n])\n\nconst usageSchema = z.strictObject({\n calls: nonNegativeInteger.nullable(),\n tokens: tokenUsageSchema.nullable(),\n cost: costSchema,\n knownCostUsd: nonNegativeNumber.optional(),\n // A provider that reports one side only: the count is kept here rather than\n // zero-filled into `tokens`, so this gate must accept it or a paid run is\n // rejected at journal-write time, after the model call is spent.\n partialTokens: z\n .strictObject({\n input: nonNegativeInteger.nullable(),\n output: nonNegativeInteger.nullable(),\n })\n .optional(),\n tokensEstimated: z.boolean().optional(),\n})\n\nconst findingScoreSchema = z.strictObject({\n expectedIssueCount: nonNegativeInteger,\n matchedIssueIds: nonEmptyStringArray,\n missedIssueIds: nonEmptyStringArray,\n supportedFindingIndexes: z.array(nonNegativeInteger),\n unsupportedFindingIndexes: z.array(nonNegativeInteger),\n unlabeledEvidence: z.array(evidenceSchema),\n issueRecall: rate,\n findingPrecision: rate,\n f1: rate,\n criticalStepAccuracy: nullableRate,\n citationCoverage: nullableRate,\n citationExcerptCoverage: nullableRate,\n citationLabelAgreement: nullableRate,\n predictionOnLabelEmptyCase: z.boolean(),\n})\n\nconst evidenceResolutionSchema = z.strictObject({\n checked: nonNegativeInteger,\n resolved: nonNegativeInteger,\n unresolvedEvidence: z.array(evidenceSchema),\n errors: z.array(\n z.strictObject({\n evidence: evidenceSchema,\n class: nonEmptyString,\n message: nonEmptyString,\n }),\n ),\n validity: nullableRate,\n})\n\nconst observationSchema: z.ZodType<AnalystBenchmarkObservation> = z\n .strictObject({\n runnerId: nonEmptyString,\n caseId: nonEmptyString,\n clusterId: nonEmptyString,\n labelState: z.enum(['positive', 'trusted-negative', 'unlabeled']),\n repetition: nonNegativeInteger,\n executionIndex: nonNegativeInteger,\n latencyMs: nonNegativeNumber.nullable(),\n latencySource: z.enum(['benchmark-clock', 'runner-reported', 'uncaptured']),\n findings: z.array(findingSchema),\n score: findingScoreSchema,\n evidenceResolution: evidenceResolutionSchema.optional(),\n caseTags: stringArray,\n caseMetadata: metadata.optional(),\n usage: usageSchema.optional(),\n runnerMetadata: metadata.optional(),\n error: errorSchema.optional(),\n })\n .superRefine((observation, context) => {\n const latencyIsMissing = observation.latencyMs === null\n if (\n (observation.latencySource === 'uncaptured' && !latencyIsMissing) ||\n (observation.latencySource !== 'uncaptured' && latencyIsMissing)\n ) {\n context.addIssue({\n code: 'custom',\n path: ['latencyMs'],\n message: `must ${observation.latencySource === 'uncaptured' ? '' : 'not '}be null for '${observation.latencySource}' latency`,\n })\n }\n })\n\nconst latencyDistributionSchema = z.strictObject({\n min: nonNegativeNumber,\n mean: nonNegativeNumber,\n p50: nonNegativeNumber,\n p95: nonNegativeNumber,\n max: nonNegativeNumber,\n})\n\nconst summarySchema = z.strictObject({\n runnerId: nonEmptyString,\n plannedRuns: nonNegativeInteger,\n completedRuns: nonNegativeInteger,\n failedRuns: nonNegativeInteger,\n issueBearingRuns: nonNegativeInteger,\n trustedNegativeRuns: nonNegativeInteger,\n unlabeledRuns: nonNegativeInteger,\n issueRecall: nullableRate,\n findingPrecision: nullableRate,\n f1: nullableRate,\n macroIssueRecall: nullableRate,\n macroFindingPrecision: nullableRate,\n macroF1: nullableRate,\n criticalStepAccuracy: nullableRate,\n citationCoverage: nullableRate,\n citationExcerptCoverage: nullableRate,\n citationLabelAgreement: nullableRate,\n citationResolution: nullableRate,\n citationResolutionUnknownRuns: nonNegativeInteger,\n unresolvedCitations: nonNegativeInteger,\n citationResolutionErrors: nonNegativeInteger,\n trustedNegativeFalsePositiveRate: nullableRate,\n trustedNegativeFailureRate: nullableRate,\n unlabeledPredictionRate: nullableRate,\n unlabeledFailureRate: nullableRate,\n predictionAgreement: nullableRate,\n predictionAgreementCases: nonNegativeInteger,\n matchedLabelAgreement: nullableRate,\n matchedLabelAgreementCases: nonNegativeInteger,\n latencyMs: latencyDistributionSchema.nullable(),\n benchmarkClockLatencyRuns: nonNegativeInteger,\n runnerReportedLatencyRuns: nonNegativeInteger,\n latencyUnknownRuns: nonNegativeInteger,\n calls: nonNegativeInteger,\n callsUnknownRuns: nonNegativeInteger,\n inputTokens: nonNegativeInteger,\n outputTokens: nonNegativeInteger,\n reasoningTokens: nonNegativeInteger,\n cachedTokens: nonNegativeInteger,\n cacheWriteTokens: nonNegativeInteger,\n tokenUsageUnknownRuns: nonNegativeInteger,\n reasoningTokenUsageUnknownRuns: nonNegativeInteger,\n cachedTokenUsageUnknownRuns: nonNegativeInteger,\n cacheWriteTokenUsageUnknownRuns: nonNegativeInteger,\n knownCostUsd: nonNegativeNumber,\n costUnknownRuns: nonNegativeInteger,\n})\n\nconst provenanceSchema = z\n .strictObject({\n id: nonEmptyString.optional(),\n dataset: z\n .strictObject({\n id: nonEmptyString,\n revision: nonEmptyString,\n split: nonEmptyString.optional(),\n })\n .optional(),\n command: nonEmptyString.optional(),\n environment: z.record(z.string(), z.string()).optional(),\n metadata: metadata.optional(),\n startedAt: timestamp,\n endedAt: timestamp,\n caseCount: positiveInteger,\n runnerIds: nonEmptyStringArray.min(1),\n repetitions: positiveInteger,\n maxConcurrency: positiveInteger,\n runnerOrderSeed: safeInteger,\n })\n .superRefine((provenance, context) => {\n if (Date.parse(provenance.endedAt) < Date.parse(provenance.startedAt)) {\n context.addIssue({\n code: 'custom',\n path: ['endedAt'],\n message: 'must not precede startedAt',\n })\n }\n })\n\nconst resultSchema = z.strictObject({\n provenance: provenanceSchema,\n observations: z.array(observationSchema),\n summaries: z.array(summarySchema),\n})\n\nconst comparisonMetricSchema = z.strictObject({\n metric: z.enum(ANALYST_COMPARISON_METRICS),\n direction: z.enum(['higher', 'lower']),\n pairedCases: nonNegativeInteger,\n pairedClusters: nonNegativeInteger,\n eligibleObservations: nonNegativeInteger,\n pairedObservations: nonNegativeInteger,\n baselineMissingObservations: nonNegativeInteger,\n candidateMissingObservations: nonNegativeInteger,\n asymmetricMissingObservations: nonNegativeInteger,\n survivorOnly: z.boolean(),\n baselineMean: nullableFiniteNumber,\n candidateMean: nullableFiniteNumber,\n meanDelta: nullableFiniteNumber,\n intervalLow: nullableFiniteNumber,\n intervalHigh: nullableFiniteNumber,\n confidence: z.number().gt(0).lt(1),\n resamples: positiveInteger,\n minimumSampleMet: z.boolean(),\n populationInferenceEligible: z.boolean(),\n inferenceLimitations: stringArray,\n})\n\nconst comparisonSchema = z.strictObject({\n baselineRunnerId: nonEmptyString,\n candidateRunnerId: nonEmptyString,\n metrics: z.array(comparisonMetricSchema),\n})\n\nconst valueDistributionSchema = z.strictObject({\n total: nonNegativeInteger,\n missing: nonNegativeInteger,\n counts: z.record(z.string(), nonNegativeInteger),\n})\n\nconst distributionsSchema = z.strictObject({\n class: valueDistributionSchema,\n agent: valueDistributionSchema,\n model: valueDistributionSchema,\n difficulty: valueDistributionSchema,\n solved: valueDistributionSchema,\n})\n\nconst selectionReportSchema = z.strictObject({\n method: z.enum(['census', 'deterministic-hash']),\n seed: safeInteger,\n sourceCount: positiveInteger,\n selectedCount: positiveInteger,\n stratified: z.literal(false),\n representativeOfInput: z.boolean(),\n source: distributionsSchema,\n selected: distributionsSchema,\n})\n\nconst verificationOutcomeSchema = z.strictObject({\n status: z.enum(['passed', 'failed', 'unavailable']),\n reason: z\n .enum([\n 'missing-result',\n 'result-output-unavailable',\n 'result-parse-error',\n 'result-label-disagreement',\n ])\n .optional(),\n parseError: errorSchema.optional(),\n sources: z.array(\n z.strictObject({\n path: nonEmptyString,\n format: z.enum(['terminal-bench', 'swe-bench', 'swe-multi']),\n status: z.enum(['passed', 'failed', 'unavailable']),\n }),\n ),\n passedCheckCount: nonNegativeInteger,\n failedCheckCount: nonNegativeInteger,\n passedChecks: stringArray,\n failedChecks: stringArray,\n})\n\nconst verificationArtifactRole = z.enum(['final-test-output', 'final-result', 'final-metrics'])\n\nconst verificationArtifactSchema = z.strictObject({\n traceId: nonEmptyString,\n status: z.enum(['present', 'missing']),\n outcome: verificationOutcomeSchema,\n outcomeSpanId: nonEmptyString,\n caseDirectory: nonEmptyString,\n caseDirectoriesSearched: nonEmptyStringArray,\n totalBytes: nonNegativeInteger,\n maxBytes: positiveInteger,\n files: z.array(\n z.strictObject({\n role: verificationArtifactRole,\n path: nonEmptyString,\n relativePath: nonEmptyString,\n sha256,\n bytes: nonNegativeInteger,\n spanId: nonEmptyString,\n }),\n ),\n missingRoles: z.array(verificationArtifactRole),\n searched: z.strictObject({\n 'final-test-output': stringArray,\n 'final-result': stringArray,\n 'final-metrics': stringArray,\n }),\n})\n\nconst verificationAvailabilitySchema = z.strictObject({\n cases: nonNegativeInteger,\n resultFilesPresent: nonNegativeInteger,\n resultFilesMissing: nonNegativeInteger,\n outcomes: z.strictObject({\n passed: nonNegativeInteger,\n failed: nonNegativeInteger,\n unavailable: nonNegativeInteger,\n }),\n})\n\nconst codeTraceCalibrationSchema = z.strictObject({\n protocol: z.literal('labeled-positive-and-solved-negative'),\n rationale: nonEmptyString,\n runners: z.array(\n z.strictObject({\n runnerId: nonEmptyString,\n selectedRuns: nonNegativeInteger,\n positiveRuns: nonNegativeInteger,\n trustedNegativeRuns: nonNegativeInteger,\n unlabeledRuns: nonNegativeInteger,\n failedLabelEmptyRuns: nonNegativeInteger,\n unknownLabelEmptyRuns: nonNegativeInteger,\n completedRuns: nonNegativeInteger,\n failedRuns: nonNegativeInteger,\n expectedIncorrectSteps: nonNegativeInteger,\n predictedIncorrectSteps: nonNegativeInteger,\n matchedIncorrectSteps: nonNegativeInteger,\n officialAllRowF1: nullableRate,\n officialAllRowRuns: nonNegativeInteger,\n precision: nullableRate,\n recall: nullableRate,\n f1: nullableRate,\n trustedNegativeFalsePositiveRate: nullableRate,\n trustedNegativeFailureRate: nullableRate,\n unlabeledPredictionRate: nullableRate,\n unlabeledFailureRate: nullableRate,\n }),\n ),\n})\n\nconst agentRxCalibrationSchema = z.strictObject({\n protocol: z.literal('official-agentrx-root-cause'),\n upstreamRevision: revision,\n rationale: nonEmptyString,\n runners: z.array(\n z.strictObject({\n runnerId: nonEmptyString,\n selectedRuns: nonNegativeInteger,\n completedRuns: nonNegativeInteger,\n failedRuns: nonNegativeInteger,\n predictedRuns: nonNegativeInteger,\n missingPredictionRuns: nonNegativeInteger,\n exactStepAccuracy: nullableRate,\n stepAccuracyWithin1: nullableRate,\n stepAccuracyWithin2: nullableRate,\n stepAccuracyWithin3: nullableRate,\n stepAccuracyWithin4: nullableRate,\n stepAccuracyWithin5: nullableRate,\n meanStepDistance: nonNegativeNumber.nullable(),\n normalizedMeanStepDistance: nullableRate,\n normalizedDistanceRuns: nonNegativeInteger,\n normalizedDistanceUnknownRuns: nonNegativeInteger,\n rootCauseCategoryAccuracy: nullableRate,\n anyFailureCategoryAccuracy: nullableRate,\n earliestFailureCategoryAccuracy: nullableRate,\n terminalFailureCategoryAccuracy: nullableRate,\n }),\n ),\n})\n\nconst artifactSchema: z.ZodType<AnalystBenchmarkArtifact> = z\n .strictObject({\n kind: z.literal('agent-eval/analyst-benchmark-result'),\n runIdentitySha256: sha256,\n inputs: z.strictObject({\n dataset: z.enum(['agentrx', 'codetracebench']),\n datasetRevision: revision,\n datasetSplit: nonEmptyString,\n labelsSha256: sha256,\n sourceRowCount: positiveInteger,\n traceFiles: z.array(\n z.strictObject({\n traceId: nonEmptyString,\n relativePath: nonEmptyString,\n sha256,\n }),\n ),\n verificationArtifacts: z.array(verificationArtifactSchema),\n verificationAvailability: verificationAvailabilitySchema,\n selection: z.strictObject({\n limit: positiveInteger,\n seed: safeInteger,\n selectedCaseIds: nonEmptyStringArray.min(1),\n report: selectionReportSchema,\n }),\n execution: z.strictObject({\n repetitions: positiveInteger,\n concurrency: positiveInteger,\n rlmSamples: positiveInteger.optional(),\n model: nonEmptyString,\n modelOwnerCallRef: nonEmptyString.optional(),\n maxOutputTokens: positiveInteger,\n maxReasoningTokens: nonNegativeInteger.optional(),\n maxModelRequestBytes: positiveInteger.optional(),\n maxModelResponseBytes: positiveInteger.optional(),\n modelRequestTimeoutMs: positiveInteger.optional(),\n timeoutMs: positiveInteger,\n pricing: z\n .strictObject({\n inputUsdPerMillion: nonNegativeNumber,\n cachedInputUsdPerMillion: nonNegativeNumber.optional(),\n cacheWriteUsdPerMillion: nonNegativeNumber.optional(),\n outputUsdPerMillion: nonNegativeNumber,\n })\n .optional(),\n recursiveLimits: z\n .strictObject({\n maxIterations: positiveInteger,\n maxLlmCalls: positiveInteger,\n maxToolCalls: positiveInteger,\n maxOutputChars: positiveInteger,\n maxModelRequests: positiveInteger.nullable(),\n traceToolRequestBytes: positiveInteger,\n traceToolResponseBytes: positiveInteger,\n traceToolTimeoutMs: positiveInteger,\n })\n .optional(),\n processLimits: z\n .strictObject({\n maxInputBytes: positiveInteger,\n maxResultBytes: positiveInteger,\n maxOutputChars: positiveInteger,\n })\n .optional(),\n maxCostUsd: nonNegativeNumber,\n maxArtifactBytes: positiveInteger,\n analystProtocolSha256: sha256,\n implementationSha256: sha256,\n dependencyLockSha256: sha256,\n }),\n }),\n result: resultSchema,\n comparisons: z.array(comparisonSchema),\n codeTraceCalibration: codeTraceCalibrationSchema.optional(),\n agentRxCalibration: agentRxCalibrationSchema.optional(),\n })\n .superRefine((artifact, context) => {\n const isCodeTrace = artifact.inputs.dataset === 'codetracebench'\n if (isCodeTrace && !artifact.codeTraceCalibration) {\n context.addIssue({\n code: 'custom',\n path: ['codeTraceCalibration'],\n message: 'is required for CodeTraceBench artifacts',\n })\n }\n if (isCodeTrace && artifact.agentRxCalibration) {\n context.addIssue({\n code: 'custom',\n path: ['agentRxCalibration'],\n message: 'is not allowed for CodeTraceBench artifacts',\n })\n }\n if (!isCodeTrace && !artifact.agentRxCalibration) {\n context.addIssue({\n code: 'custom',\n path: ['agentRxCalibration'],\n message: 'is required for AgentRx artifacts',\n })\n }\n if (!isCodeTrace && artifact.codeTraceCalibration) {\n context.addIssue({\n code: 'custom',\n path: ['codeTraceCalibration'],\n message: 'is not allowed for AgentRx artifacts',\n })\n }\n })\n\nexport function assertAnalystBenchmarkObservation(\n value: unknown,\n context: string,\n): asserts value is AnalystBenchmarkObservation {\n assertSchema(observationSchema, value, context)\n}\n\nexport function assertAnalystBenchmarkArtifact(\n value: unknown,\n context: string,\n): asserts value is AnalystBenchmarkArtifact {\n assertSchema(artifactSchema, value, context)\n}\n\nfunction assertSchema(schema: z.ZodType, value: unknown, context: string): void {\n const result = schema.safeParse(value)\n if (result.success) return\n throw new TypeError(formatIssue(result.error.issues[0]!, context))\n}\n\nfunction formatIssue(issue: z.core.$ZodIssue, context: string): string {\n const path = issue.path.length === 0 ? context : `${context}.${issue.path.join('.')}`\n if (issue.code === 'unrecognized_keys') {\n return `${path} contains unknown field '${issue.keys[0]}'`\n }\n return `${path} ${issue.message}`\n}\n","import type { CustomTokenPricing } from '../cost-ledger'\nimport { canonicalString, hashCanonical, jsonDocument } from '../ledger-core/canonical'\nimport type { AnalystBenchmarkObservation, AnalystBenchmarkResult } from './benchmark'\nimport type { AgentRxCalibrationSummary } from './benchmark-agentrx-calibration'\nimport type { AnalystRunnerComparison } from './benchmark-comparison'\nimport type { CodeTraceCalibrationSummary } from './benchmark-public-calibration'\nimport type {\n PublicAnalystBenchmarkDataset,\n PublicBenchmarkSelectionReport,\n} from './benchmark-real-model'\nimport type { VerificationArtifactManifest } from './benchmark-verification-artifacts'\n\nexport { assertAnalystBenchmarkObservation } from './benchmark-command-validation'\n\nexport interface AnalystBenchmarkArtifact {\n kind: 'agent-eval/analyst-benchmark-result'\n runIdentitySha256: string\n inputs: {\n dataset: PublicAnalystBenchmarkDataset\n datasetRevision: string\n datasetSplit: string\n labelsSha256: string\n sourceRowCount: number\n traceFiles: Array<{ traceId: string; relativePath: string; sha256: string }>\n verificationArtifacts: VerificationArtifactManifest[]\n verificationAvailability: VerificationAvailabilitySummary\n selection: {\n limit: number\n seed: number\n selectedCaseIds: string[]\n report: PublicBenchmarkSelectionReport\n }\n execution: {\n repetitions: number\n concurrency: number\n /** Absent on artifacts produced before consensus sampling existed. */\n rlmSamples?: number\n model: string\n /** These fields are absent only on immutable evidence produced before model owners existed. */\n modelOwnerCallRef?: string\n maxOutputTokens: number\n maxReasoningTokens?: number\n maxModelRequestBytes?: number\n maxModelResponseBytes?: number\n modelRequestTimeoutMs?: number\n timeoutMs: number\n pricing?: CustomTokenPricing\n recursiveLimits?: {\n maxIterations: number\n maxLlmCalls: number\n maxToolCalls: number\n maxOutputChars: number\n maxModelRequests: number | null\n traceToolRequestBytes: number\n traceToolResponseBytes: number\n traceToolTimeoutMs: number\n }\n processLimits?: {\n maxInputBytes: number\n maxResultBytes: number\n maxOutputChars: number\n }\n maxCostUsd: number\n maxArtifactBytes: number\n analystProtocolSha256: string\n /** Present only when the run replaced the recursive analyst instructions. */\n instructionsOverrideSha256?: string\n implementationSha256: string\n dependencyLockSha256: string\n }\n }\n result: AnalystBenchmarkResult\n comparisons: AnalystRunnerComparison[]\n codeTraceCalibration?: CodeTraceCalibrationSummary\n agentRxCalibration?: AgentRxCalibrationSummary\n}\n\nexport interface VerificationAvailabilitySummary {\n cases: number\n resultFilesPresent: number\n resultFilesMissing: number\n outcomes: {\n passed: number\n failed: number\n unavailable: number\n }\n}\n\nexport interface AnalystBenchmarkRunIdentity {\n config: {\n dataset: PublicAnalystBenchmarkDataset\n datasetRevision: string\n datasetSplit: string\n model: {\n id: string\n ownerCallRef: string\n maxOutputTokens: number\n maxReasoningTokens: number\n maxRequestBytes: number\n maxResponseBytes: number\n requestTimeoutMs: number\n timeoutMs: number\n pricing: CustomTokenPricing\n recursiveLimits: {\n maxIterations: number\n maxLlmCalls: number\n maxToolCalls: number\n maxOutputChars: number\n maxModelRequests: number | null\n traceToolRequestBytes: number\n traceToolResponseBytes: number\n traceToolTimeoutMs: number\n }\n processLimits: {\n maxInputBytes: number\n maxResultBytes: number\n maxOutputChars: number\n }\n }\n limit: number\n seed: number\n concurrency: number\n repetitions: number\n /** Absent on manifests written before consensus sampling existed. */\n rlmSamples?: number\n maxCostUsd: number\n maxArtifactBytes: number\n analystProtocolSha256: string\n /** Present only when the run replaced the recursive analyst instructions. */\n instructionsOverrideSha256?: string\n implementationSha256: string\n dependencyLockSha256: string\n runnerIds: readonly ['empty', string]\n }\n inputs: {\n labelsSha256: string\n sourceRowCount: number\n selectedCaseIds: string[]\n traceFiles: Array<{ traceId: string; relativePath: string; sha256: string }>\n verificationArtifactsSha256: string\n caseDefinitionsSha256: string\n }\n}\n\nexport interface AnalystBenchmarkRunManifest {\n kind: 'agent-eval/analyst-benchmark-run'\n createdAt: string\n identitySha256: string\n localIdentitySha256: string\n identity: AnalystBenchmarkRunIdentity\n}\n\nexport interface AnalystBenchmarkLocalRunReceipt {\n kind: 'agent-eval/analyst-benchmark-local-run'\n runIdentitySha256: string\n localIdentitySha256: string\n local: {\n labelsPath: string\n traceDir: string\n artifactDir?: string\n outputDir: string\n /** Absent when the analyst owns its own transport (`prime`). */\n modelOwnerModule?: string\n }\n command: string\n environment: {\n node: string\n platform: string\n arch: string\n }\n files: {\n manifest: string\n observations: string\n costLedger: string\n modelResponses: string\n result: string\n report: string\n }\n}\n\nexport interface AnalystBenchmarkProgressRow {\n sequence: number\n runIdentitySha256: string\n previousRowSha256: string | null\n observation: AnalystBenchmarkObservation\n rowSha256: string\n}\n\nexport const ANALYST_BENCHMARK_MANIFEST_FILE = 'manifest.json'\nexport const ANALYST_BENCHMARK_OBSERVATIONS_FILE = 'observations.jsonl'\nexport const ANALYST_BENCHMARK_LOCAL_RECEIPT_FILE = 'run.local.json'\nexport const ANALYST_BENCHMARK_COST_LEDGER_FILE = 'cost-ledger.jsonl'\n\nexport function observationKey(observation: {\n runnerId: string\n caseId: string\n repetition: number\n}): string {\n return `${observation.runnerId}\\u0000${observation.caseId}\\u0000${observation.repetition}`\n}\n\nexport function parseJson(text: string, source: string): unknown {\n try {\n return JSON.parse(text)\n } catch {\n throw new Error(`invalid JSON in ${source}`)\n }\n}\n\nexport function assertExactKeys(\n value: Record<string, unknown>,\n allowed: readonly string[],\n context: string,\n optional: readonly string[] = [],\n): void {\n const allowedSet = new Set(allowed)\n const optionalSet = new Set(optional)\n for (const key of Object.keys(value)) {\n if (!allowedSet.has(key)) throw new TypeError(`${context} contains unknown field '${key}'`)\n }\n for (const key of allowed) {\n if (!optionalSet.has(key) && !(key in value)) {\n throw new TypeError(`${context} is missing field '${key}'`)\n }\n }\n}\n\n/**\n * Digest a benchmark receipt as the artifact file will carry it. Receipts are\n * digested before they are written and re-digested when they are read back, so\n * the digest covers the JSON document form (see {@link jsonDocument}); every\n * other ambiguous value is still refused.\n */\nexport function digestCanonical(value: unknown): string {\n return hashCanonical(jsonDocument(value)).slice('sha256:'.length)\n}\n\n/** RFC 8785 canonical JSON of the value's JSON document form — the byte form\n * the receipt digests and compares against. */\nexport function canonicalJson(value: unknown): string {\n return canonicalString(jsonDocument(value))\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nexport function isSha256(value: unknown): value is string {\n return typeof value === 'string' && /^[a-f0-9]{64}$/.test(value)\n}\n\nexport function isNonNegativeSafeInteger(value: unknown): value is number {\n return Number.isSafeInteger(value) && Number(value) >= 0\n}\n\nexport function isNonNegativeFinite(value: unknown): value is number {\n return typeof value === 'number' && Number.isFinite(value) && value >= 0\n}\n","export const ANALYST_BENCHMARK_IMPLEMENTATION_DIGEST_ALGORITHM = 'sha256-canonical-source-manifest'\n\nexport const ANALYST_BENCHMARK_DEPENDENCY_LOCK_DIGEST_ALGORITHM = 'sha256-canonical-file-manifest'\n\nexport const ANALYST_BENCHMARK_DEPENDENCY_LOCK_FILES = Object.freeze([\n 'clients/python/pyproject.toml',\n 'clients/python/uv.lock',\n 'package.json',\n 'pnpm-lock.yaml',\n])\n\nexport const ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256 =\n '4698aea8dc7ba8f57106cd145fdbb6f74bcbc6f9acf6f9d0c40bf013e1f0f2cc'\n\n/** The published benchmark evidence was produced at this package version, by\n * the retired one-shot direct runner, before trace analysts moved to the\n * recursive DSPy RLM engine. Both evidence digests below are historical facts\n * about that artifact: the current implementation and dependency manifest have\n * since changed, so they cannot describe the current engine. A fresh certified\n * run must replace the published evidence before any accuracy number is\n * attributed to the engine that ships today. */\nexport const ANALYST_BENCHMARK_EVIDENCE_PACKAGE_VERSION = '0.137.0'\n\nexport const ANALYST_BENCHMARK_EVIDENCE_DEPENDENCY_LOCK_SHA256 =\n '1e03f2daed356d60316aabefb407ec1e437ac94d408d61eea4ae096e9c6fbb5b'\n\nexport const ANALYST_BENCHMARK_EVIDENCE_IMPLEMENTATION_SHA256 =\n '4dba263b6256a30d56c7fdb2d992d3a953c0035d731f359b704db806f68f75ac'\n\nexport const ANALYST_BENCHMARK_IMPLEMENTATION_FILES = Object.freeze([\n 'clients/python/src/agent_eval_rpc/dspy_rlm_bridge.py',\n 'clients/python/src/agent_eval_rpc/optimizer_bridge_common.py',\n 'src/analyst/benchmark-agentrx-calibration.ts',\n 'src/analyst/benchmark-command-artifact.ts',\n 'src/analyst/benchmark-command-persistence.ts',\n 'src/analyst/benchmark-command-result.ts',\n 'src/analyst/benchmark-command-validation.ts',\n 'src/analyst/benchmark-command.ts',\n 'src/analyst/benchmark-comparison.ts',\n 'src/analyst/benchmark-dataset-agentrx.ts',\n 'src/analyst/benchmark-dataset-codetrace.ts',\n 'src/analyst/benchmark-dataset-utils.ts',\n 'src/analyst/benchmark-datasets.ts',\n 'src/analyst/benchmark-evidence-validation.ts',\n 'src/analyst/benchmark-instructions-override.ts',\n 'src/analyst/benchmark-public-adapters.ts',\n 'src/analyst/benchmark-public-calibration.ts',\n 'src/analyst/benchmark-public-consensus.ts',\n 'src/analyst/benchmark-public-data.ts',\n 'src/analyst/benchmark-public-errors.ts',\n 'src/analyst/benchmark-public-model.ts',\n 'src/analyst/benchmark-public-prompt.ts',\n 'src/analyst/benchmark-public-rlm.ts',\n 'src/analyst/benchmark-public-types.ts',\n 'src/analyst/benchmark-real-model.ts',\n 'src/analyst/benchmark-report.ts',\n 'src/analyst/benchmark-response-cache.ts',\n 'src/analyst/benchmark-runner-prime.ts',\n 'src/analyst/benchmark-scoring.ts',\n 'src/analyst/benchmark-summary.ts',\n 'src/analyst/benchmark-verification-artifacts.ts',\n 'src/analyst/benchmark-verification-outcome.ts',\n 'src/analyst/benchmark.ts',\n 'src/analyst/definition.ts',\n 'src/analyst/dspy-rlm-engine.ts',\n 'src/analyst/engine.ts',\n 'src/analyst/equal-terms.ts',\n 'src/analyst/exact-types.ts',\n 'src/analyst/finding-codec.ts',\n 'src/analyst/finding-signature.ts',\n 'src/analyst/finding-subject.ts',\n 'src/analyst/kind-factory.ts',\n 'src/analyst/parse-tolerant.ts',\n 'src/analyst/prime-bridge-transport.ts',\n 'src/analyst/prime-protocol.ts',\n 'src/analyst/reply-contract.ts',\n 'src/analyst/tool-groups.ts',\n 'src/analyst/trace-tool-callback.ts',\n 'src/analyst/types.ts',\n 'src/analyst/usage-receipt.ts',\n 'src/campaign/external-optimizer-anthropic.ts',\n 'src/campaign/external-optimizer-callback.ts',\n 'src/campaign/external-optimizer-contracts.ts',\n 'src/campaign/external-optimizer-http.ts',\n 'src/campaign/external-optimizer-model-proxy.ts',\n 'src/campaign/external-optimizer-process.ts',\n 'src/campaign/external-optimizer-resources.ts',\n 'src/campaign/external-optimizer-subprocess.ts',\n 'src/campaign/search-ledger-errors.ts',\n 'src/campaign/search-ledger-file.ts',\n 'src/campaign/single-run-lock.ts',\n 'src/campaign/storage.ts',\n 'src/concurrency.ts',\n 'src/cost-ledger.ts',\n 'src/errors.ts',\n 'src/integrity/served-model.ts',\n 'src/judge-calibration.ts',\n 'src/judge-families.ts',\n 'src/ledger-core/atomic-file-lock.ts',\n 'src/ledger-core/canonical.ts',\n 'src/ledger-core/deep-freeze.ts',\n 'src/ledger-core/index.ts',\n 'src/ledger-core/journal-file.ts',\n 'src/ledger-core/journal.ts',\n 'src/ledger-core/trusted-head.ts',\n 'src/llm-client.ts',\n 'src/math/normal.ts',\n 'src/math/special-functions.ts',\n 'src/math/student-t.ts',\n 'src/metrics.ts',\n 'src/record-id.ts',\n 'src/statistics/agreement-irr.ts',\n 'src/statistics/descriptive.ts',\n 'src/statistics/effect-sizes.ts',\n 'src/statistics/index.ts',\n 'src/statistics/internal.ts',\n 'src/statistics/multiplicity.ts',\n 'src/statistics/paired-binary.ts',\n 'src/statistics/paired-tests.ts',\n 'src/statistics/power-and-mde.ts',\n 'src/statistics/random.ts',\n 'src/statistics/rank-tests.ts',\n 'src/statistics/sequential-eprocess.ts',\n 'src/trace-analyst/errors.ts',\n 'src/trace-analyst/otlp-span.ts',\n 'src/trace-analyst/shared-abortable-task.ts',\n 'src/trace-analyst/store-boundary.ts',\n 'src/trace-analyst/store-bounds.ts',\n 'src/trace-analyst/store-contract.ts',\n 'src/trace-analyst/store-otlp.ts',\n 'src/trace-analyst/store-schemas.ts',\n 'src/trace-analyst/store.ts',\n 'src/trace-analyst/tools.ts',\n 'src/trace-analyst/types.ts',\n 'src/trace/attribute-vocabulary.ts',\n 'src/trace/otlp-attributes.ts',\n 'src/trace/raw-provider-sink.ts',\n 'src/verdict-cache.ts',\n])\n\nexport const ANALYST_BENCHMARK_IMPLEMENTATION_SHA256 =\n 'e499ff9c5a3b24104d1a9dbc0c3742ffd08b67ff1b852922b423d38231954254'\n\nexport function analystBenchmarkImplementationDigest() {\n return ANALYST_BENCHMARK_IMPLEMENTATION_SHA256\n}\n\nexport function analystBenchmarkDependencyLockDigest() {\n return ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256\n}\n","import { TRACE_ANALYSIS_LIMITS, type TraceAnalysisStore } from '../trace-analyst/store'\nimport type { AnalystFinding, EvidenceRef } from './types'\n\nconst MIN_ACTION_EXCERPT_CHARACTERS = 12\nexport const MAX_ASSISTANT_STEP_EVIDENCE_EXCERPT_CHARACTERS = 512\nconst MAX_LABEL_SCAN_DEPTH = 64\nconst MAX_SERIALIZED_JSON_SCAN_BYTES = 64 * 1024\nconst MAX_SERIALIZED_JSON_SCAN_DEPTH = 8\n\nconst BENCHMARK_LABEL_KEYS = new Set([\n 'category_reason',\n 'failure_category',\n 'failure_summary',\n 'incorrect_stages',\n 'incorrect_step_ids',\n 'root_cause',\n 'root_cause_failure_id',\n 'root_cause_reason',\n 'step_reason',\n 'unuseful_step_ids',\n])\nconst BENCHMARK_LABEL_KEY_TOKENS = [...BENCHMARK_LABEL_KEYS].sort(\n (left, right) => right.length - left.length,\n)\n\nconst BENCHMARK_LABEL_PATH_MARKERS = [\n 'bench_manifest.verified',\n 'codetracer_labels.json',\n '/ground_truth/',\n '\\\\ground_truth\\\\',\n] as const\n\nexport interface BenchmarkLabelLeakScan {\n passed: true\n scannedBytes: number\n scannedValues: number\n}\n\nexport function assertNoBenchmarkLabelsInTrace(options: {\n traceId: string\n otlpText: string\n}): BenchmarkLabelLeakScan {\n let scannedValues = 0\n for (const [index, line] of options.otlpText.split(/\\r?\\n/).entries()) {\n if (!line.trim()) continue\n let value: unknown\n try {\n value = JSON.parse(line)\n } catch (error) {\n throw new TypeError(\n `trace '${options.traceId}' line ${index + 1} is invalid JSON: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n scannedValues += scanValue(value, options.traceId, `$line[${index + 1}]`, 0, 0)\n }\n if (scannedValues === 0) {\n throw new Error(`trace '${options.traceId}' contains no JSON values`)\n }\n return {\n passed: true,\n scannedBytes: Buffer.byteLength(options.otlpText),\n scannedValues,\n }\n}\n\nexport function assertNoBenchmarkLabelsInArtifact(options: {\n traceId: string\n relativePath: string\n content: string\n}): void {\n const normalizedPath = options.relativePath.toLowerCase()\n for (const marker of BENCHMARK_LABEL_PATH_MARKERS) {\n if (normalizedPath.includes(marker.toLowerCase())) {\n throw new Error(\n `trace '${options.traceId}' verification artifact path contains benchmark label marker '${marker}'`,\n )\n }\n }\n const normalizedContent = options.content.toLowerCase()\n for (const key of BENCHMARK_LABEL_KEYS) {\n if (normalizedContent.includes(key)) {\n throw new Error(\n `trace '${options.traceId}' verification artifact contains benchmark label key '${key}'`,\n )\n }\n }\n for (const marker of BENCHMARK_LABEL_PATH_MARKERS) {\n if (normalizedContent.includes(marker.toLowerCase())) {\n throw new Error(\n `trace '${options.traceId}' verification artifact contains benchmark label path marker '${marker}'`,\n )\n }\n }\n}\n\nexport async function validateCodeTraceFindingEvidence(options: {\n trajectoryId: string\n findings: readonly AnalystFinding[]\n store: TraceAnalysisStore\n signal?: AbortSignal\n}): Promise<void> {\n const citations = options.findings.flatMap((finding) =>\n finding.evidence_refs.map((evidence) => ({\n evidence,\n findingId: finding.finding_id,\n location: codeTraceStepFromEvidence(evidence.uri),\n })),\n )\n if (citations.length === 0) return\n\n for (const citation of citations) {\n if (!citation.location || citation.location.traceId !== options.trajectoryId) {\n throw new Error(\n `model finding '${citation.findingId}' cites non-case evidence '${citation.evidence.uri}'`,\n )\n }\n }\n\n const spanIds = [...new Set(citations.map((citation) => `step-${citation.location!.step}`))]\n const { spans, missing } = await fetchTraceSpans(options.store, {\n trajectoryId: options.trajectoryId,\n spanIds,\n ...(options.signal ? { signal: options.signal } : {}),\n })\n if (missing.length > 0) {\n throw new Error(\n `model finding evidence is unavailable in the case trace: ${missing.join(', ')}`,\n )\n }\n\n for (const citation of citations) {\n const spanId = `step-${citation.location!.step}`\n const span = spans.get(spanId)\n if (!span) {\n throw new Error(`model finding '${citation.findingId}' cites missing span '${spanId}'`)\n }\n if (span.kind !== 'LLM') {\n throw new Error(\n `model finding '${citation.findingId}' cites '${spanId}', which is ${span.kind}, not an assistant LLM span`,\n )\n }\n assertExactActionExcerpt(citation.findingId, citation.evidence, spanId, span.attributes.content)\n }\n}\n\n/**\n * Resolve assistant-step evidence for a trajectory.\n *\n * `steps` are claims the model made explicitly: an unresolvable one is a model\n * error and throws. `optionalSteps` are derived by the runner (a block's\n * interior, a block's consequence step), so an unresolvable one is simply\n * absent from the returned map and the caller decides what that means.\n */\nexport async function resolveAssistantStepEvidence(options: {\n trajectoryId: string\n steps: readonly number[]\n optionalSteps?: readonly number[]\n store: TraceAnalysisStore\n signal?: AbortSignal\n}): Promise<Map<number, EvidenceRef>> {\n const required = [...new Set(options.steps)]\n const optional = [...new Set(options.optionalSteps ?? [])].filter(\n (step) => !required.includes(step),\n )\n for (const step of [...required, ...optional]) {\n if (!Number.isSafeInteger(step) || step < 1) {\n throw new TypeError(`assistant evidence step must be a positive safe integer: ${step}`)\n }\n }\n const steps = [...required, ...optional]\n if (steps.length === 0) return new Map()\n\n const { spans, missing } = await fetchTraceSpans(options.store, {\n trajectoryId: options.trajectoryId,\n spanIds: steps.map((step) => `step-${step}`),\n ...(options.signal ? { signal: options.signal } : {}),\n })\n const missingRequired = missing.filter((spanId) =>\n required.some((step) => `step-${step}` === spanId),\n )\n if (missingRequired.length > 0) {\n throw new Error(`model selected unavailable assistant steps: ${missingRequired.join(', ')}`)\n }\n\n const evidence = new Map<number, EvidenceRef>()\n for (const step of steps) {\n const spanId = `step-${step}`\n const optionalStep = optional.includes(step)\n const span = spans.get(spanId)\n if (!span) {\n if (optionalStep) continue\n throw new Error(`model selected missing assistant step '${spanId}'`)\n }\n if (span.kind !== 'LLM') {\n if (optionalStep) continue\n throw new Error(\n `model selected '${spanId}', which is ${span.kind}, not an assistant LLM span`,\n )\n }\n const content = span.attributes.content\n if (typeof content !== 'string' || content.trim().length === 0) {\n if (optionalStep) continue\n throw new Error(`model selected '${spanId}' without action content`)\n }\n evidence.set(step, {\n kind: 'span',\n uri: codeTraceStepEvidenceUri(options.trajectoryId, step),\n excerpt: content.trim().slice(0, MAX_ASSISTANT_STEP_EVIDENCE_EXCERPT_CHARACTERS),\n })\n }\n return evidence\n}\n\n/**\n * Read spans by id, paging over the store's byte-budget omissions.\n *\n * `omitted_span_ids` names spans that exist but did not fit the response\n * ceiling; the store guarantees at least one span lands per call, so\n * re-requesting exactly the omitted ids terminates. Only `missing_span_ids`\n * describes a span the trace does not contain.\n */\nasync function fetchTraceSpans(\n store: TraceAnalysisStore,\n options: { trajectoryId: string; spanIds: readonly string[]; signal?: AbortSignal },\n): Promise<{\n spans: Map<string, Awaited<ReturnType<TraceAnalysisStore['viewSpans']>>['spans'][number]>\n missing: string[]\n}> {\n const spans = new Map<\n string,\n Awaited<ReturnType<TraceAnalysisStore['viewSpans']>>['spans'][number]\n >()\n const missing: string[] = []\n const unique = [...new Set(options.spanIds)]\n const context = options.signal ? { signal: options.signal } : undefined\n for (let offset = 0; offset < unique.length; offset += TRACE_ANALYSIS_LIMITS.viewSpans) {\n let pending = unique.slice(offset, offset + TRACE_ANALYSIS_LIMITS.viewSpans)\n while (pending.length > 0) {\n const result = await store.viewSpans(\n { trace_id: options.trajectoryId, span_ids: pending },\n context,\n )\n for (const span of result.spans) spans.set(span.span_id, span)\n missing.push(...result.missing_span_ids)\n const omitted = result.omitted_span_ids.filter((spanId) => !spans.has(spanId))\n if (omitted.length >= pending.length) {\n throw new Error(\n `trace '${options.trajectoryId}' cannot project spans within the store response budget: ${omitted.join(', ')}`,\n )\n }\n pending = omitted\n }\n }\n return { spans, missing }\n}\n\nfunction scanValue(\n value: unknown,\n traceId: string,\n path: string,\n depth: number,\n serializedDepth: number,\n): number {\n if (depth > MAX_LABEL_SCAN_DEPTH) {\n throw new Error(`trace '${traceId}' exceeds benchmark label scan depth at ${path}`)\n }\n if (Array.isArray(value)) {\n return (\n 1 +\n value.reduce(\n (count, entry, index) =>\n count + scanValue(entry, traceId, `${path}[${index}]`, depth + 1, serializedDepth),\n 0,\n )\n )\n }\n if (typeof value === 'object' && value !== null) {\n let count = 1\n for (const [key, entry] of Object.entries(value)) {\n if (BENCHMARK_LABEL_KEYS.has(key.toLowerCase())) {\n throw new Error(`trace '${traceId}' exposes benchmark label key '${key}' at ${path}`)\n }\n count += scanValue(entry, traceId, `${path}.${key}`, depth + 1, serializedDepth)\n }\n return count\n }\n if (typeof value === 'string') {\n const normalized = value.toLowerCase()\n const labelKey = BENCHMARK_LABEL_KEY_TOKENS.find((candidate) => normalized.includes(candidate))\n if (labelKey) {\n throw new Error(\n `trace '${traceId}' exposes benchmark label key '${labelKey}' inside a string at ${path}`,\n )\n }\n const marker = BENCHMARK_LABEL_PATH_MARKERS.find((candidate) => normalized.includes(candidate))\n if (marker) {\n throw new Error(\n `trace '${traceId}' exposes benchmark label path marker '${marker}' at ${path}`,\n )\n }\n const trimmed = value.trim()\n if (\n serializedDepth < MAX_SERIALIZED_JSON_SCAN_DEPTH &&\n Buffer.byteLength(trimmed) <= MAX_SERIALIZED_JSON_SCAN_BYTES &&\n looksLikeSerializedJson(trimmed)\n ) {\n let parsed: unknown\n try {\n parsed = JSON.parse(trimmed)\n } catch {\n return 1\n }\n return (\n 1 + scanValue(parsed, traceId, `${path}<serialized-json>`, depth + 1, serializedDepth + 1)\n )\n }\n }\n return 1\n}\n\nfunction looksLikeSerializedJson(value: string): boolean {\n return (\n (value.startsWith('{') && value.endsWith('}')) ||\n (value.startsWith('[') && value.endsWith(']')) ||\n (value.startsWith('\"') && value.endsWith('\"'))\n )\n}\n\nexport function codeTraceStepFromEvidence(uri: string): { traceId: string; step: number } | null {\n const match = /^trace:\\/\\/([^/]+)\\/span\\/step-(\\d+)$/.exec(uri)\n if (!match) return null\n try {\n const traceId = decodeURIComponent(match[1]!)\n const step = Number(match[2])\n return traceId && Number.isSafeInteger(step) && step > 0 ? { traceId, step } : null\n } catch {\n return null\n }\n}\n\nexport function codeTraceStepEvidenceUri(traceId: string, step: number): string {\n return `trace://${encodeURIComponent(traceId)}/span/step-${step}`\n}\n\nfunction assertExactActionExcerpt(\n findingId: string,\n evidence: EvidenceRef,\n spanId: string,\n content: unknown,\n): void {\n if (typeof content !== 'string' || content.length === 0) {\n throw new Error(`model finding '${findingId}' cites '${spanId}' without action content`)\n }\n const excerpt = evidence.excerpt?.trim()\n if (!excerpt) {\n throw new Error(`model finding '${findingId}' must quote action content from '${spanId}'`)\n }\n const requiredLength = Math.min(MIN_ACTION_EXCERPT_CHARACTERS, content.trim().length)\n if (excerpt.length < requiredLength) {\n throw new Error(\n `model finding '${findingId}' excerpt for '${spanId}' is too short; expected at least ${requiredLength} characters`,\n )\n }\n if (!content.includes(excerpt)) {\n throw new Error(\n `model finding '${findingId}' excerpt is not present in '${spanId}' action content`,\n )\n }\n}\n","import { z } from 'zod'\n\nexport type VerificationOutcomeStatus = 'passed' | 'failed' | 'unavailable'\n\nexport interface VerificationOutcomeSource {\n path: string\n format: 'terminal-bench' | 'swe-bench' | 'swe-multi'\n status: VerificationOutcomeStatus\n}\n\nexport interface VerificationOutcome {\n status: VerificationOutcomeStatus\n reason?:\n | 'missing-result'\n | 'result-output-unavailable'\n | 'result-parse-error'\n | 'result-label-disagreement'\n parseError?: { class: string; message: string }\n sources: VerificationOutcomeSource[]\n passedCheckCount: number\n failedCheckCount: number\n passedChecks: string[]\n failedChecks: string[]\n}\n\nexport interface VerificationResultFile {\n relativePath: string\n content: string\n}\n\nconst MAX_REPORTED_CHECKS = 20\nconst SWE_MULTI_NO_TEST_RESULTS =\n 'After applying the fix patch, no test results were captured when executing the test command.'\n\nconst checkNameSchema = z.string().min(1)\nconst checkListSchema = z.array(checkNameSchema).superRefine((checks, context) => {\n const seen = new Set<string>()\n for (const [index, check] of checks.entries()) {\n if (seen.has(check)) {\n context.addIssue({\n code: 'custom',\n path: [index],\n message: `duplicate check '${check}'`,\n })\n }\n seen.add(check)\n }\n})\nconst nonNegativeCountSchema = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER)\n\nconst terminalBenchSchema = z\n .object({\n is_resolved: z.boolean().nullable(),\n failure_mode: z.string().min(1),\n parser_results: z.record(z.string().min(1), z.enum(['passed', 'failed'])).nullable(),\n })\n .passthrough()\n\nconst directSweBenchSchema = z\n .object({\n resolved: z.boolean(),\n passed_tests: checkListSchema,\n failed_tests: checkListSchema,\n })\n .passthrough()\n\nconst nestedSweBenchCategorySchema = z\n .object({\n success: checkListSchema,\n failure: checkListSchema,\n })\n .passthrough()\n\nconst nestedSweBenchInstanceSchema = z\n .object({\n resolved: z.boolean(),\n tests_status: z\n .record(z.string().min(1), nestedSweBenchCategorySchema)\n .refine((value) => Object.keys(value).length > 0, 'must contain at least one test category'),\n })\n .passthrough()\n\nconst nestedSweBenchSchema = z\n .record(z.string().min(1), nestedSweBenchInstanceSchema)\n .refine((value) => Object.keys(value).length > 0, 'must contain at least one instance')\n\nconst sweMultiCheckResultSchema = z\n .object({\n passed_count: nonNegativeCountSchema,\n failed_count: nonNegativeCountSchema,\n skipped_count: nonNegativeCountSchema,\n passed_tests: checkListSchema,\n failed_tests: checkListSchema,\n skipped_tests: checkListSchema,\n })\n .passthrough()\n\nconst sweMultiSchema = z\n .object({\n valid: z.boolean(),\n error_msg: z.string(),\n fix_patch_result: sweMultiCheckResultSchema,\n })\n .passthrough()\n\nexport function parseVerificationOutcome(\n files: readonly VerificationResultFile[],\n): VerificationOutcome {\n if (files.length === 0) {\n throw new Error('final verification outcome requires at least one result file')\n }\n\n const sources: VerificationOutcomeSource[] = []\n const passedChecks = new Set<string>()\n const failedChecks = new Set<string>()\n const unavailableReasons = new Set<NonNullable<VerificationOutcome['reason']>>()\n\n for (const file of files) {\n let value: unknown\n try {\n value = JSON.parse(file.content)\n } catch (error) {\n throw new TypeError(\n `final verification result is not valid JSON: ${file.relativePath}: ${errorMessage(error)}`,\n )\n }\n const parsed = parseResult(value, file.relativePath)\n sources.push({\n path: file.relativePath,\n format: parsed.format,\n status: parsed.status,\n })\n if (parsed.reason) unavailableReasons.add(parsed.reason)\n for (const check of parsed.passedChecks) passedChecks.add(check)\n for (const check of parsed.failedChecks) failedChecks.add(check)\n }\n\n const statuses = new Set(sources.map((source) => source.status))\n if (statuses.size !== 1) {\n throw new Error(\n `final verification result files disagree: ${sources\n .map((source) => `${source.path}=${source.status}`)\n .join(', ')}`,\n )\n }\n if (unavailableReasons.size > 1) {\n throw new Error(\n `final verification result files disagree on why the outcome is unavailable: ${[\n ...unavailableReasons,\n ].join(', ')}`,\n )\n }\n const [unavailableReason] = unavailableReasons\n\n const passed = [...passedChecks].sort()\n const failed = [...failedChecks].sort()\n assertDisjointChecks(passed, failed, 'final verification result')\n return {\n status: sources[0]!.status,\n ...(unavailableReason ? { reason: unavailableReason } : {}),\n sources,\n passedCheckCount: passed.length,\n failedCheckCount: failed.length,\n passedChecks: passed.slice(0, MAX_REPORTED_CHECKS),\n failedChecks: failed.slice(0, MAX_REPORTED_CHECKS),\n }\n}\n\ninterface ParsedResult {\n format: VerificationOutcomeSource['format']\n status: VerificationOutcomeStatus\n reason?: NonNullable<VerificationOutcome['reason']>\n passedChecks: string[]\n failedChecks: string[]\n}\n\nfunction parseResult(value: unknown, path: string): ParsedResult {\n const record = asRecord(value)\n if (!record) {\n throw unsupported(path)\n }\n\n const discriminators = ['is_resolved', 'resolved', 'valid'].filter((field) =>\n Object.hasOwn(record, field),\n )\n if (discriminators.length > 1) {\n throw new TypeError(\n `final verification result is ambiguous: ${path}: found ${discriminators.join(', ')}`,\n )\n }\n if (discriminators[0] === 'is_resolved') return parseTerminalBench(record, path)\n if (discriminators[0] === 'resolved') return parseDirectSweBench(record, path)\n if (discriminators[0] === 'valid') return parseSweMulti(record, path)\n\n const entries = Object.entries(record)\n const looksNested = entries.some(([, candidate]) => {\n const nested = asRecord(candidate)\n return nested !== null && Object.hasOwn(nested, 'resolved')\n })\n if (looksNested) return parseNestedSweBench(record, path)\n\n throw unsupported(path)\n}\n\nfunction parseTerminalBench(value: unknown, path: string): ParsedResult {\n const record = parseSchema(terminalBenchSchema, value, path, 'Terminal-Bench')\n if (record.is_resolved === null) {\n if (record.parser_results !== null) {\n throw malformed(\n path,\n 'Terminal-Bench',\n 'parser_results must be null when is_resolved is null',\n )\n }\n if (record.failure_mode === 'unset') {\n throw malformed(path, 'Terminal-Bench', \"failure_mode cannot be 'unset' when unresolved\")\n }\n return {\n format: 'terminal-bench',\n status: 'unavailable',\n reason:\n record.failure_mode === 'parse_error' ? 'result-parse-error' : 'result-output-unavailable',\n passedChecks: [],\n failedChecks: [],\n }\n }\n if (record.parser_results === null) {\n throw malformed(\n path,\n 'Terminal-Bench',\n 'parser_results must be an object when is_resolved is boolean',\n )\n }\n const checks = stringStatusChecks(record.parser_results)\n if (checks.passedChecks.length + checks.failedChecks.length === 0) {\n throw malformed(path, 'Terminal-Bench', 'parser_results must contain at least one check')\n }\n assertOutcomeConsistency(record.is_resolved, checks, path, 'Terminal-Bench is_resolved', true)\n return {\n format: 'terminal-bench',\n status: status(record.is_resolved),\n ...checks,\n }\n}\n\nfunction parseDirectSweBench(value: unknown, path: string): ParsedResult {\n const record = parseSchema(directSweBenchSchema, value, path, 'SWE-bench')\n const checks = {\n passedChecks: record.passed_tests,\n failedChecks: record.failed_tests,\n }\n assertOutcomeConsistency(record.resolved, checks, path, 'SWE-bench resolved')\n return {\n format: 'swe-bench',\n status: status(record.resolved),\n ...checks,\n }\n}\n\nfunction parseNestedSweBench(value: unknown, path: string): ParsedResult {\n const record = parseSchema(nestedSweBenchSchema, value, path, 'SWE-bench instance report')\n const instances = Object.entries(record)\n const statuses = new Set(instances.map(([, instance]) => status(instance.resolved)))\n if (statuses.size !== 1) {\n throw new Error(\n `final verification report contains conflicting instance outcomes: ${path}: ${instances\n .map(([id, instance]) => `${id}=${status(instance.resolved)}`)\n .join(', ')}`,\n )\n }\n\n const passedChecks: string[] = []\n const failedChecks: string[] = []\n for (const [instanceId, instance] of instances) {\n const checks = nestedSweBenchChecks(instanceId, instance.tests_status)\n assertOutcomeConsistency(\n instance.resolved,\n checks,\n path,\n `SWE-bench instance '${instanceId}' resolved`,\n )\n passedChecks.push(...checks.passedChecks)\n failedChecks.push(...checks.failedChecks)\n }\n return {\n format: 'swe-bench',\n status: [...statuses][0]!,\n passedChecks,\n failedChecks,\n }\n}\n\nfunction parseSweMulti(value: unknown, path: string): ParsedResult {\n const record = parseSchema(sweMultiSchema, value, path, 'SWE-Multi')\n const fix = record.fix_patch_result\n assertCount(fix.passed_count, fix.passed_tests, 'passed', path)\n assertCount(fix.failed_count, fix.failed_tests, 'failed', path)\n assertCount(fix.skipped_count, fix.skipped_tests, 'skipped', path)\n assertDisjointChecks(fix.passed_tests, fix.failed_tests, `SWE-Multi result ${path}`)\n assertDisjointChecks(fix.passed_tests, fix.skipped_tests, `SWE-Multi result ${path}`)\n assertDisjointChecks(fix.failed_tests, fix.skipped_tests, `SWE-Multi result ${path}`)\n\n const checks = {\n passedChecks: fix.passed_tests,\n failedChecks: fix.failed_tests,\n }\n if (record.valid === false && isSweMultiOutputUnavailable(record)) {\n return {\n format: 'swe-multi',\n status: 'unavailable',\n reason: 'result-output-unavailable',\n ...checks,\n }\n }\n assertOutcomeConsistency(record.valid, checks, path, 'SWE-Multi valid')\n return {\n format: 'swe-multi',\n status: status(record.valid),\n ...checks,\n }\n}\n\nfunction isSweMultiOutputUnavailable(record: z.infer<typeof sweMultiSchema>): boolean {\n const fix = record.fix_patch_result\n return (\n (record.error_msg === SWE_MULTI_NO_TEST_RESULTS ||\n record.error_msg.startsWith(`${SWE_MULTI_NO_TEST_RESULTS} `)) &&\n fix.passed_count === 0 &&\n fix.failed_count === 0 &&\n fix.skipped_count === 0\n )\n}\n\nfunction stringStatusChecks(record: Record<string, 'passed' | 'failed'>): {\n passedChecks: string[]\n failedChecks: string[]\n} {\n const passedChecks: string[] = []\n const failedChecks: string[] = []\n for (const [name, result] of Object.entries(record)) {\n if (result === 'passed') passedChecks.push(name)\n else failedChecks.push(name)\n }\n return { passedChecks, failedChecks }\n}\n\nfunction nestedSweBenchChecks(\n instanceId: string,\n testsStatus: z.infer<typeof nestedSweBenchInstanceSchema>['tests_status'],\n): { passedChecks: string[]; failedChecks: string[] } {\n const passedChecks: string[] = []\n const failedChecks: string[] = []\n for (const [category, result] of Object.entries(testsStatus)) {\n passedChecks.push(...result.success.map((name) => `${instanceId}:${category}:${name}`))\n failedChecks.push(...result.failure.map((name) => `${instanceId}:${category}:${name}`))\n }\n return { passedChecks, failedChecks }\n}\n\nfunction assertOutcomeConsistency(\n passed: boolean,\n checks: { passedChecks: readonly string[]; failedChecks: readonly string[] },\n path: string,\n field: string,\n requireFailedCheck = false,\n): void {\n assertDisjointChecks(checks.passedChecks, checks.failedChecks, `${field} in ${path}`)\n if (passed && checks.failedChecks.length > 0) {\n throw malformed(\n path,\n field,\n `cannot be true while failed checks are reported: ${checks.failedChecks.join(', ')}`,\n )\n }\n if (passed && checks.passedChecks.length === 0) {\n throw malformed(path, field, 'cannot be true without at least one passed check')\n }\n if (!passed && requireFailedCheck && checks.failedChecks.length === 0) {\n throw malformed(path, field, 'cannot be false without at least one failed check')\n }\n}\n\nfunction assertCount(count: number, checks: readonly string[], kind: string, path: string): void {\n if (count !== checks.length) {\n throw malformed(\n path,\n 'SWE-Multi',\n `${kind}_count=${count} does not match ${kind}_tests length ${checks.length}`,\n )\n }\n}\n\nfunction assertDisjointChecks(\n left: readonly string[],\n right: readonly string[],\n source: string,\n): void {\n const rightSet = new Set(right)\n const contradictions = [...new Set(left.filter((check) => rightSet.has(check)))].sort()\n if (contradictions.length > 0) {\n throw new Error(\n `${source} marks checks as both passed and failed: ${contradictions.join(', ')}`,\n )\n }\n}\n\nfunction parseSchema<T>(schema: z.ZodType<T>, value: unknown, path: string, format: string): T {\n const parsed = schema.safeParse(value)\n if (parsed.success) return parsed.data\n const details = parsed.error.issues\n .map((issue) => `${issue.path.join('.') || '<root>'}: ${issue.message}`)\n .join('; ')\n throw malformed(path, format, details)\n}\n\nfunction malformed(path: string, format: string, details: string): TypeError {\n return new TypeError(`malformed ${format} verification result: ${path}: ${details}`)\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | null {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : null\n}\n\nfunction status(value: boolean): VerificationOutcomeStatus {\n return value ? 'passed' : 'failed'\n}\n\nfunction unsupported(path: string): TypeError {\n return new TypeError(\n `final verification result has no supported outcome field: ${path}; expected is_resolved, resolved, valid, or a SWE-bench instance report`,\n )\n}\n\nfunction errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n","import { createHash } from 'node:crypto'\nimport { constants, type Stats } from 'node:fs'\nimport { type FileHandle, open, readdir, realpath, stat } from 'node:fs/promises'\nimport { isAbsolute, relative, resolve, sep } from 'node:path'\nimport { TextDecoder } from 'node:util'\nimport { compareCodeUnits } from '../ledger-core/canonical'\nimport type { CodeTraceBenchRow } from './benchmark-datasets'\nimport {\n parseVerificationOutcome,\n type VerificationOutcome,\n} from './benchmark-verification-outcome'\n\nexport const DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES = 8 * 1024 * 1024\n\nexport type VerificationArtifactRole = 'final-test-output' | 'final-result' | 'final-metrics'\n\nexport interface VerificationArtifactFile {\n role: VerificationArtifactRole\n path: string\n relativePath: string\n sha256: string\n bytes: number\n spanId: string\n}\n\nexport interface VerificationArtifactManifest {\n traceId: string\n status: 'present' | 'missing'\n outcome: VerificationOutcome\n outcomeSpanId: string\n caseDirectory: string\n caseDirectoriesSearched: string[]\n totalBytes: number\n maxBytes: number\n files: VerificationArtifactFile[]\n missingRoles: VerificationArtifactRole[]\n searched: Record<VerificationArtifactRole, string[]>\n}\n\nexport interface LoadedVerificationArtifacts {\n manifest: VerificationArtifactManifest\n outcome: VerificationOutcome\n files: Array<VerificationArtifactFile & { content: string }>\n}\n\nconst SEARCHED_ARTIFACTS: Record<VerificationArtifactRole, string[]> = {\n 'final-test-output': ['panes/post-test.txt', 'sessions/tests.log', 'test_output.txt'],\n 'final-result': ['results.json', 'result.json', 'report.json', '*_result.json'],\n 'final-metrics': ['*_metrics.json'],\n}\n\nconst REQUIRED_ROLES = new Set<VerificationArtifactRole>(['final-result'])\n\nconst UTF8 = new TextDecoder('utf-8', { fatal: true })\n\nexport async function loadCodeTraceVerificationArtifacts(options: {\n artifactDir: string\n row: CodeTraceBenchRow\n maxBytes?: number\n}): Promise<LoadedVerificationArtifacts> {\n const maxBytes = positiveInteger(\n options.maxBytes ?? DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES,\n 'max verification artifact bytes',\n )\n const sourceRelativePath = nonEmpty(\n options.row.source_relpath,\n `CodeTraceBench '${options.row.traj_id}' source_relpath`,\n )\n const artifactRoot = await realpath(resolve(options.artifactDir))\n const caseDirectoriesSearched = [\n resolve(artifactRoot, options.row.traj_id, sourceRelativePath),\n resolve(artifactRoot, sourceRelativePath),\n ].filter((path, index, paths) => paths.indexOf(path) === index)\n for (const path of caseDirectoriesSearched) {\n assertContained(artifactRoot, path, sourceRelativePath)\n }\n const existingCaseDirectories = new Set<string>()\n for (const path of caseDirectoriesSearched) {\n try {\n const canonicalPath = await realpath(path)\n assertContained(artifactRoot, canonicalPath, sourceRelativePath)\n const metadata = await stat(canonicalPath)\n if (!metadata.isDirectory()) {\n throw new TypeError(\n `CodeTraceBench '${options.row.traj_id}' artifact case path is not a directory: ${canonicalPath}`,\n )\n }\n existingCaseDirectories.add(canonicalPath)\n } catch (error) {\n if (!isMissing(error)) throw error\n }\n }\n if (existingCaseDirectories.size === 0) {\n return missingArtifacts(\n options.row.traj_id,\n caseDirectoriesSearched[0]!,\n caseDirectoriesSearched,\n maxBytes,\n )\n }\n if (existingCaseDirectories.size > 1) {\n throw new Error(\n `CodeTraceBench '${options.row.traj_id}' artifact directory is ambiguous: ${[...existingCaseDirectories].join(', ')}`,\n )\n }\n const [caseDirectory] = existingCaseDirectories\n\n const candidates = await artifactCandidates(caseDirectory!)\n const files: LoadedVerificationArtifacts['files'] = []\n let totalBytes = 0\n for (const candidate of candidates) {\n const snapshot = await readArtifactSnapshot({\n artifactRoot,\n candidatePath: candidate.path,\n relativePath: candidate.relativePath,\n traceId: options.row.traj_id,\n totalBytes,\n maxBytes,\n })\n const { bytes, canonicalPath } = snapshot\n totalBytes += bytes.byteLength\n let content: string\n try {\n content = UTF8.decode(bytes)\n } catch {\n throw new TypeError(\n `CodeTraceBench '${options.row.traj_id}' verification artifact is not UTF-8 text: ${canonicalPath}`,\n )\n }\n if (!content.trim()) {\n throw new Error(\n `CodeTraceBench '${options.row.traj_id}' verification artifact is empty: ${canonicalPath}`,\n )\n }\n const relativePath = candidate.relativePath\n files.push({\n role: candidate.role,\n path: canonicalPath,\n relativePath,\n sha256: sha256Digest(bytes),\n bytes: bytes.byteLength,\n spanId: verificationSpanId(candidate.role, relativePath),\n content,\n })\n }\n\n const roles = new Set(files.map((file) => file.role))\n const missingRoles = (Object.keys(SEARCHED_ARTIFACTS) as VerificationArtifactRole[]).filter(\n (role) => !roles.has(role),\n )\n const hasFinalVerification = [...REQUIRED_ROLES].every((role) => roles.has(role))\n const outcome = hasFinalVerification\n ? loadVerificationOutcome(\n files\n .filter((file) => file.role === 'final-result')\n .map((file) => ({ relativePath: file.relativePath, content: file.content })),\n options.row,\n )\n : unavailableOutcome('missing-result')\n const outcomeSpanId = verificationOutcomeSpanId(options.row.traj_id, outcome)\n return {\n manifest: {\n traceId: options.row.traj_id,\n status: hasFinalVerification ? 'present' : 'missing',\n outcome,\n outcomeSpanId,\n caseDirectory: caseDirectory!,\n caseDirectoriesSearched,\n totalBytes,\n maxBytes,\n files: files.map(({ content: _content, ...file }) => file),\n missingRoles,\n searched: searchedArtifacts(),\n },\n outcome,\n files,\n }\n}\n\nexport function appendVerificationArtifactsToOtlp(\n otlpText: string,\n traceId: string,\n artifacts: LoadedVerificationArtifacts,\n afterTimestamp: string,\n): string {\n if (!otlpText.trim()) throw new Error(`trace '${traceId}' OTLP input is empty`)\n if (artifacts.manifest.traceId !== traceId) {\n throw new Error(\n `verification artifacts for trace '${artifacts.manifest.traceId}' cannot be attached to '${traceId}'`,\n )\n }\n if (!artifacts.outcome || !artifacts.manifest.outcomeSpanId) {\n throw new Error(`trace '${traceId}' has no final verification artifacts to attach`)\n }\n const afterMs = Date.parse(afterTimestamp)\n if (!Number.isFinite(afterMs)) {\n throw new TypeError(`trace '${traceId}' latest timestamp is invalid: ${afterTimestamp}`)\n }\n const outcome = artifacts.outcome\n const outcomeLine = JSON.stringify({\n trace_id: traceId,\n span_id: artifacts.manifest.outcomeSpanId,\n parent_span_id: null,\n name: `final verification outcome: ${outcome.status}`,\n start_time: timestampAfter(afterMs, 1, traceId),\n end_time: timestampAfter(afterMs, 2, traceId),\n status: {\n code:\n outcome.status === 'passed'\n ? 'STATUS_CODE_OK'\n : outcome.status === 'failed'\n ? 'STATUS_CODE_ERROR'\n : 'STATUS_CODE_UNSET',\n },\n resource: {\n attributes: {\n 'service.name': 'agent-eval-public-benchmark',\n },\n },\n attributes: {\n 'openinference.span.kind': 'EVALUATOR',\n 'benchmark.evidence.role': 'final-verification',\n 'benchmark.verification.outcome': outcome.status,\n 'benchmark.verification.passed_check_count': outcome.passedCheckCount,\n 'benchmark.verification.failed_check_count': outcome.failedCheckCount,\n 'benchmark.verification.passed_checks': JSON.stringify(outcome.passedChecks),\n 'benchmark.verification.failed_checks': JSON.stringify(outcome.failedChecks),\n 'benchmark.verification.sources': JSON.stringify(outcome.sources),\n ...(outcome.reason ? { 'benchmark.verification.reason': outcome.reason } : {}),\n ...(outcome.parseError\n ? { 'benchmark.verification.parse_error': JSON.stringify(outcome.parseError) }\n : {}),\n },\n })\n const artifactLines = artifacts.files\n .filter((artifact) => artifact.role === 'final-test-output')\n .map((artifact, index) =>\n JSON.stringify({\n trace_id: traceId,\n span_id: artifact.spanId,\n parent_span_id: null,\n name: `final verification artifact: ${artifact.relativePath}`,\n start_time: timestampAfter(afterMs, index * 2 + 3, traceId),\n end_time: timestampAfter(afterMs, index * 2 + 4, traceId),\n status: { code: 'STATUS_CODE_UNSET' },\n resource: {\n attributes: {\n 'service.name': 'agent-eval-public-benchmark',\n },\n },\n attributes: {\n 'openinference.span.kind': 'EVALUATOR',\n 'benchmark.evidence.role': 'final-verification-artifact',\n 'benchmark.verification.outcome': outcome.status,\n 'artifact.role': artifact.role,\n 'artifact.path': artifact.relativePath,\n 'artifact.sha256': artifact.sha256,\n 'artifact.bytes': artifact.bytes,\n 'artifact.content': artifact.content,\n },\n }),\n )\n return `${otlpText.trimEnd()}\\n${[outcomeLine, ...artifactLines].join('\\n')}\\n`\n}\n\nfunction timestampAfter(afterMs: number, offsetMs: number, traceId: string): string {\n const date = new Date(afterMs + offsetMs)\n if (!Number.isFinite(date.getTime())) {\n throw new RangeError(`trace '${traceId}' cannot place final verification after its latest span`)\n }\n return date.toISOString()\n}\n\nexport function sha256Digest(value: string | NodeJS.ArrayBufferView): string {\n return createHash('sha256').update(value).digest('hex')\n}\n\nasync function readArtifactSnapshot(options: {\n artifactRoot: string\n candidatePath: string\n relativePath: string\n traceId: string\n totalBytes: number\n maxBytes: number\n}): Promise<{ canonicalPath: string; bytes: Buffer }> {\n const safeOpenFlags =\n constants.O_RDONLY |\n (process.platform === 'win32' ? 0 : constants.O_NOFOLLOW | constants.O_NONBLOCK)\n let handle: FileHandle\n try {\n handle = await open(options.candidatePath, safeOpenFlags)\n } catch (error) {\n if (isNodeError(error, 'ELOOP')) {\n throw new Error(\n `CodeTraceBench '${options.traceId}' verification artifact must not be a symbolic link: ${options.relativePath}`,\n )\n }\n throw error\n }\n\n try {\n const before = await handle.stat()\n if (!before.isFile()) {\n throw new TypeError(\n `CodeTraceBench '${options.traceId}' verification artifact is not a regular file: ${options.relativePath}`,\n )\n }\n const bytes = checkedFileSize(before.size, options)\n const descriptorPath = await openedDescriptorPath(handle.fd)\n if (descriptorPath !== null) {\n assertContained(options.artifactRoot, descriptorPath, options.relativePath)\n }\n\n const canonicalPath = await realpath(options.candidatePath)\n assertContained(options.artifactRoot, canonicalPath, options.relativePath)\n const current = await stat(canonicalPath)\n if (!sameFile(before, current)) {\n throw changedArtifact(options.traceId, options.relativePath)\n }\n\n const content = Buffer.allocUnsafe(bytes)\n let offset = 0\n while (offset < content.byteLength) {\n const { bytesRead } = await handle.read(content, offset, content.byteLength - offset, offset)\n if (bytesRead === 0) break\n offset += bytesRead\n }\n const eofProbe = Buffer.allocUnsafe(1)\n const { bytesRead: trailingBytes } = await handle.read(\n eofProbe,\n 0,\n eofProbe.byteLength,\n content.byteLength,\n )\n const after = await handle.stat()\n if (offset !== content.byteLength || trailingBytes !== 0 || !sameSnapshot(before, after)) {\n throw changedArtifact(options.traceId, options.relativePath)\n }\n return { canonicalPath, bytes: content }\n } finally {\n await handle.close()\n }\n}\n\nfunction checkedFileSize(\n bytes: number,\n options: {\n traceId: string\n relativePath: string\n totalBytes: number\n maxBytes: number\n },\n): number {\n if (!Number.isSafeInteger(bytes) || bytes < 0) {\n throw new RangeError(\n `CodeTraceBench '${options.traceId}' verification artifact has an invalid byte size: ${options.relativePath}`,\n )\n }\n if (bytes > options.maxBytes) {\n throw new RangeError(\n `CodeTraceBench '${options.traceId}' verification artifact '${options.relativePath}' requires ${bytes} bytes, over the ${options.maxBytes}-byte per-file limit`,\n )\n }\n if (options.totalBytes > options.maxBytes - bytes) {\n throw new RangeError(\n `CodeTraceBench '${options.traceId}' verification artifacts require ${options.totalBytes + bytes} bytes, over the ${options.maxBytes}-byte cumulative limit`,\n )\n }\n return bytes\n}\n\nasync function openedDescriptorPath(fileDescriptor: number): Promise<string | null> {\n if (process.platform !== 'linux') return null\n try {\n return await realpath(`/proc/self/fd/${fileDescriptor}`)\n } catch (error) {\n if (\n isNodeError(error, 'ENOENT') ||\n isNodeError(error, 'ENOTDIR') ||\n isNodeError(error, 'EACCES')\n ) {\n return null\n }\n throw error\n }\n}\n\nfunction sameFile(left: Stats, right: Stats): boolean {\n return (\n left.isFile() &&\n right.isFile() &&\n left.dev === right.dev &&\n left.ino === right.ino &&\n left.size === right.size\n )\n}\n\nfunction sameSnapshot(left: Stats, right: Stats): boolean {\n return (\n sameFile(left, right) &&\n left.mode === right.mode &&\n left.mtimeMs === right.mtimeMs &&\n left.ctimeMs === right.ctimeMs\n )\n}\n\nfunction changedArtifact(traceId: string, relativePath: string): Error {\n return new Error(\n `CodeTraceBench '${traceId}' verification artifact changed while being read: ${relativePath}`,\n )\n}\n\nasync function artifactCandidates(\n caseDirectory: string,\n): Promise<Array<{ role: VerificationArtifactRole; path: string; relativePath: string }>> {\n const entries = await readdir(caseDirectory, { withFileTypes: true })\n const rootFiles = entries\n .filter((entry) => entry.isFile() || entry.isSymbolicLink())\n .map((entry) => entry.name)\n const testOutput = await firstExisting(caseDirectory, SEARCHED_ARTIFACTS['final-test-output'])\n const finalResults = [\n ...SEARCHED_ARTIFACTS['final-result']\n .filter((name) => !name.includes('*'))\n .map((name) => resolve(caseDirectory, name)),\n ...rootFiles\n .filter((name) => name.endsWith('_result.json'))\n .map((name) => resolve(caseDirectory, name)),\n ]\n const finalMetrics = rootFiles\n .filter((name) => name.endsWith('_metrics.json'))\n .map((name) => resolve(caseDirectory, name))\n\n const candidates = [\n ...testOutput.map((path) => candidate('final-test-output', caseDirectory, path)),\n ...(await existing(finalResults)).map((path) => candidate('final-result', caseDirectory, path)),\n ...(await existing(finalMetrics)).map((path) =>\n candidate('final-metrics', caseDirectory, path),\n ),\n ]\n const seen = new Set<string>()\n return candidates\n .filter((entry) => {\n if (seen.has(entry.path)) return false\n seen.add(entry.path)\n return true\n })\n .sort(\n (left, right) =>\n artifactRoleOrder(left.role) - artifactRoleOrder(right.role) ||\n compareCodeUnits(left.relativePath, right.relativePath),\n )\n}\n\nasync function firstExisting(\n caseDirectory: string,\n candidates: readonly string[],\n): Promise<string[]> {\n for (const relativePath of candidates) {\n const path = resolve(caseDirectory, relativePath)\n if (await isFile(path)) return [path]\n }\n return []\n}\n\nasync function existing(paths: readonly string[]): Promise<string[]> {\n const out: string[] = []\n for (const path of paths) {\n if (await isFile(path)) out.push(path)\n }\n return out\n}\n\nasync function isFile(path: string): Promise<boolean> {\n try {\n return (await stat(path)).isFile()\n } catch (error) {\n if (isMissing(error)) return false\n throw error\n }\n}\n\nfunction candidate(\n role: VerificationArtifactRole,\n caseDirectory: string,\n path: string,\n): { role: VerificationArtifactRole; path: string; relativePath: string } {\n return { role, path, relativePath: slashRelative(caseDirectory, path) }\n}\n\nfunction missingArtifacts(\n traceId: string,\n caseDirectory: string,\n caseDirectoriesSearched: string[],\n maxBytes: number,\n): LoadedVerificationArtifacts {\n const outcome = unavailableOutcome('missing-result')\n return {\n manifest: {\n traceId,\n status: 'missing',\n outcome,\n outcomeSpanId: verificationOutcomeSpanId(traceId, outcome),\n caseDirectory,\n caseDirectoriesSearched,\n totalBytes: 0,\n maxBytes,\n files: [],\n missingRoles: Object.keys(SEARCHED_ARTIFACTS) as VerificationArtifactRole[],\n searched: searchedArtifacts(),\n },\n outcome,\n files: [],\n }\n}\n\nfunction verificationOutcomeSpanId(traceId: string, outcome: VerificationOutcome): string {\n return `benchmark-verification-outcome-${sha256Digest(\n `${traceId}\\u0000${JSON.stringify(outcome.sources)}\\u0000${outcome.status}`,\n ).slice(0, 16)}`\n}\n\nfunction unavailableOutcome(\n reason: NonNullable<VerificationOutcome['reason']>,\n): VerificationOutcome {\n return {\n status: 'unavailable',\n reason,\n sources: [],\n passedCheckCount: 0,\n failedCheckCount: 0,\n passedChecks: [],\n failedChecks: [],\n }\n}\n\nfunction loadVerificationOutcome(\n files: Parameters<typeof parseVerificationOutcome>[0],\n row: CodeTraceBenchRow,\n): VerificationOutcome {\n try {\n const outcome = parseVerificationOutcome(files)\n if (outcome.status === 'unavailable' || typeof row.solved !== 'boolean') {\n return outcome\n }\n const labelStatus = row.solved ? 'passed' : 'failed'\n if (outcome.status === labelStatus) {\n return outcome\n }\n return {\n ...outcome,\n status: 'unavailable',\n reason: 'result-label-disagreement',\n parseError: {\n class: 'ResultLabelDisagreementError',\n message: `CodeTraceBench '${row.traj_id}' solved=${row.solved} disagrees with parsed final verification status '${outcome.status}' from ${outcome.sources\n .map((source) => `${source.path}=${source.status}`)\n .join(', ')}`,\n },\n }\n } catch (error) {\n return {\n ...unavailableOutcome('result-parse-error'),\n parseError: {\n class: error instanceof Error ? error.constructor.name : 'Error',\n message: error instanceof Error ? error.message : String(error),\n },\n }\n }\n}\n\nfunction verificationSpanId(role: VerificationArtifactRole, relativePath: string): string {\n return `benchmark-verification-${sha256Digest(`${role}\\u0000${relativePath}`).slice(0, 16)}`\n}\n\nfunction artifactRoleOrder(role: VerificationArtifactRole): number {\n return role === 'final-test-output' ? 0 : role === 'final-result' ? 1 : 2\n}\n\nfunction assertContained(root: string, candidate: string, source: string): void {\n const rel = relative(root, candidate)\n if (isAbsolute(rel) || rel === '..' || rel.startsWith(`..${sep}`)) {\n throw new Error(`verification artifact path escapes --artifact-dir: ${source}`)\n }\n}\n\nfunction searchedArtifacts(): Record<VerificationArtifactRole, string[]> {\n return {\n 'final-test-output': [...SEARCHED_ARTIFACTS['final-test-output']],\n 'final-result': [...SEARCHED_ARTIFACTS['final-result']],\n 'final-metrics': [...SEARCHED_ARTIFACTS['final-metrics']],\n }\n}\n\nfunction slashRelative(root: string, path: string): string {\n return relative(root, path).split(sep).join('/')\n}\n\nfunction nonEmpty(value: unknown, field: string): string {\n if (typeof value !== 'string' || !value.trim()) {\n throw new TypeError(`${field} must be a non-empty string`)\n }\n return value.trim()\n}\n\nfunction positiveInteger(value: number, field: string): number {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new RangeError(`${field} must be a positive safe integer`)\n }\n return value\n}\n\nfunction isMissing(error: unknown): boolean {\n return isNodeError(error, 'ENOENT')\n}\n\nfunction isNodeError(error: unknown, code: string): error is NodeJS.ErrnoException {\n return error instanceof Error && 'code' in error && error.code === code\n}\n","import { MAX_ASSISTANT_STEP_EVIDENCE_EXCERPT_CHARACTERS } from './benchmark-evidence-validation'\nimport type { PublicAnalystBenchmarkDataset } from './benchmark-public-types'\nimport { sha256Digest } from './benchmark-verification-artifacts'\n\n/** Widest contiguous failure block a model may report. The published corpus's\n * widest labeled block is 8 steps and its widest stage span is 9, so this bound\n * never binds honest enumeration; it caps how far one over-wide block can push\n * unlabeled steps into the precision denominator. */\nexport const MAX_INCORRECT_BLOCK_STEPS = 12\n\n/** Most blocks a model may report for one trajectory. The published corpus's\n * densest case carries 4 disjoint labeled blocks. Together with the per-block\n * cap this bounds one case at 192 predicted steps without a second ceiling. */\nexport const MAX_INCORRECT_BLOCKS = 16\n\nexport const TRACE_PROJECTION_ATTRIBUTE_BYTE_CAPS = [\n 4_096, 2_048, 1_024, 512, 256, 128, 64,\n] as const\n\nexport const CODE_TRACE_BENCH_ANALYST_PROMPT = `Analyze exactly one coding-agent trajectory and its attached final verification.\nYour task is the CodeTraceBench incorrect-step task: identify every incorrect step, defined as a wrong state-changing intervention given the evidence — a mislocalized edit, a wrong hypothesis that drives an action, a regression, an irrelevant change, or an incorrect dependency or configuration choice.\nIf the final verification failed, the trajectory MUST contain at least one incorrect step. Never return an empty findings array on a failing trajectory; trace backward until you find the root cause.\nWork backward, the way this benchmark was annotated, never by scanning forward for suspicious steps: start from the final verification outcome or the latest observed failure evidence, identify the immediately preceding step whose action or output produced that observed error, then recursively ask which earlier decision led to each intermediate failure, until the preceding steps contain no error or the cause is unrelated to the trajectory's own decisions.\nEach backward chain terminates at an error-critical step — the earliest decision that triggered the downstream cascade — and that step is the block's first_step: the step that committed the mistake, not the step that planned it and not a later step that repeats it.\nA block is a maximal contiguous sequence of strictly incorrect steps. A step belongs in the block ONLY if it introduces, propagates, or compounds the error. \nDo NOT include steps that merely \"act on\", diagnose, or react to the error. A diagnostic command, a test run exposing the bug, or a correct exploratory read is a CORRECT step. \nIf an incorrect step is followed by a correct diagnostic step and then another incorrect step, you MUST emit two separate blocks. NEVER bridge correct steps by grouping them into a single block with incorrect steps. Over-blocking drastically hurts your precision.\nAfter identifying first_step, extend last_step forward ONLY through consecutive steps that independently introduce, propagate, or compound the mistake. A cascade of repeated failed attempts at the same wrong approach is one maximal block, provided EVERY step is independently incorrect.\nDo not end a block merely because the agent tried a variation of the same wrong approach; a variation that still carries the error stays inside the block.\nA partially correct or ambiguous fix still counts as incorrect; the block ends only at the first step free of the error — a clean diagnostic read, the corrective action that closes the issue and needs no further rework, or a genuine abandonment of the wrong approach.\nBlock extent follows the traced chain and this forward extension, nothing else.\nReport each failure block as exactly one finding whose first_step is the block's first incorrect step and whose last_step is its last, covering every consecutive step between them.\nEvery step inside a block is scored on its own: naming a correct step costs exactly as much as missing an incorrect one, and naming only the first step of a longer block forfeits every unnamed step. Because of this, carefully verify every step between first_step and last_step. Only include steps that introduce, propagate, or compound the error.\nReport blocks separated by at least one correct step as separate findings, and never let two blocks overlap. If there are multiple separate failure cascades, emit a separate finding for each one.\nPrefer anchored blocks: a block whose chain traces back from observed failure evidence — a failing command or verification, an error observation, a regression, or, on a solved trajectory, a later step that reverts or supersedes it — outranks one without.\nWhen an action is clearly wrong on its own evidence but you cannot trace such an anchor, report the block anyway with proportionally lower confidence.\nA solved trajectory still carries every mistake made along the way: inspect its final patching and verification stages for a state-changing action that a later step reverted, superseded, or corrected — a wrong edit just before the final fix is incorrect even when every test ends green.\nBefore emitting a candidate block, check its boundaries.\nNeighbor check: ask whether the accusation fits one step earlier (the decision rather than its consequence) or one step later (the next step still acts on or reworks the same error) better than where you placed it, and move the boundary when it does; a boundary off by one step scores zero at that step.\nCompleteness check: a block must cover the maximal contiguous sequence of incorrect steps. If an agent fails at step 10, tries to fix it at 11, fails, and tries again at 12 and 13, all four steps are incorrect and must be included in the block. Never truncate a cascade. If you miss the later steps of a cascade, your recall drops to zero for them.\nCounterfactual check: ask which step's correct execution would have made the downstream failure or rework disappear, and move first_step onto that step; use this check only to move a boundary, never to delete a block.\nWidth check: inspect the step immediately before first_step and the step immediately after last_step; when either neighbor commits to, compounds, or propagates the same mistake, it belongs inside the block — move that boundary outward and repeat until both neighbors are free of the error.\nFor each block you keep, name as consequence_step the step number whose action or observation shows the damage — a failing command, a wrong file state, a repeated failure, or rework the agent had to do because of this block; that step is the block's own last step when its observation already shows the damage, and a later step otherwise.\nWhen you cannot name that step number from the trace you were given, drop the block; a plausible story about why a step looks wrong is not evidence that it was.\nA passing final verification is not evidence that a block caused nothing, and a failing final verification is not evidence that any particular block caused it.\nFor every block, decide whether the agent escaped the failure.\nMark escape_status \"escaped\" only when you can name the single later step that fully reversed the block, the agent needed no other step to recover, and nothing after that step revisits the same file, command, or hypothesis; write that step number in the rationale. If the agent required multiple steps to fix the issue, or if you are unsure, it is not escaped.\nMark escape_status \"unescaped\" in every other case, including whenever you are unsure.\nA passing final verification never makes a block escaped.\nDo not label a diagnostic probe or test run merely because its output exposes an earlier defect.\nDo not label a redundant but correct read or search; CodeTraceBench scores unuseful steps separately, and this run scores incorrect steps only. Never include a correct step in a block just to bridge two incorrect steps; instead, emit two separate blocks.\nDo not label a step solely because final verification failed.\nWhen final verification is unavailable, trace backward from the latest failure evidence inside the trajectory itself.\nEvery step in a reported block MUST be the positive integer n from an existing assistant LLM span named step-<n>.\nNever select an EVALUATOR, TOOL, CHAIN, final-verification, benchmark-verification, or message-<n> span.\nBefore emitting a finding, inspect every covered span's attributes.content and describe only the actions shown there.\nReport at most 16 blocks and at most 12 steps in one block; when more candidates than that exist, report the ones whose chains carry the clearest downstream evidence.\nWhen the trajectory has no incorrect steps — its final verification passed and the final-stage sweep found no reverted, superseded, or corrected action — return an empty findings array.`\n\nconst AGENT_RX_PROMPT = `Analyze exactly one failed agent trajectory.\nFind the first unrecoverable critical failure, not every later symptom.\nInspect the complete supplied trace data.\nEmit zero findings only when the trace does not contain enough evidence.\nOtherwise emit exactly one finding.\nIts category MUST be exactly one of:\ninstruction-plan-adherence-failure\ninvention-of-new-information\ninvalid-invocation\nmisinterpretation-of-tool-output-handoff-failure\nintent-plan-misalignment\nunderspecified-user-intent\nintent-not-supported\nguardrails-triggered\nsystem-failure\ninconclusive\nIts step is the positive integer n from the first unrecoverable assistant span named step-<n>.`\n\nconst AGENT_RX_JSON_CONTRACT = `Each finding must contain only:\n- \"step\": a positive integer matching an existing assistant LLM span named step-<n>\n- \"severity\": \"critical\", \"high\", \"medium\", \"low\", or \"info\"\n- \"claim\": one sentence\n- \"confidence\": a number from 0 through 1\n- optional \"rationale\" and \"recommended_action\" strings\n- \"category\": one allowed failure category listed above`\n\nconst CODE_TRACE_JSON_CONTRACT = `Each finding is one contiguous failure block and must contain only:\n- \"first_step\": a positive integer, the block's first incorrect step, matching an existing assistant LLM span named step-<n>\n- \"last_step\": a positive integer >= first_step, the block's last incorrect step; every step from first_step through last_step must be an existing assistant LLM span, and a block spans at most ${MAX_INCORRECT_BLOCK_STEPS} steps\n- \"consequence_step\": a positive integer >= first_step, the step whose action or following observation shows the damage this block caused; it may sit inside the block when the damage is already visible there\n- \"escape_status\": \"escaped\" only when one single later step fully reversed the block and nothing afterwards revisits it, \"unescaped\" otherwise and whenever you are unsure\n- \"severity\": \"critical\", \"high\", \"medium\", \"low\", or \"info\"\n- \"claim\": one sentence describing the block's failure\n- \"confidence\": a number from 0 through 1\n- optional \"rationale\" and \"recommended_action\" strings`\n\nconst AGENT_RX_RLM_CONTRACT = `Use the trace tools to inspect the action and its following observation.\nEmit exactly one finding whose subject is exactly one of the allowed failure categories.\nCite exactly one assistant span named step-<n> as trace://<URL-encoded-trace-id>/span/step-<n>.\nThe excerpt must quote the assistant action exactly.`\n\nconst CODE_TRACE_RLM_CONTRACT = `Use the trace tools rather than asking for the whole trajectory in the prompt.\nKeep retrieved trace objects in Python variables.\nNever print an entire trace, full source file, or more than 12000 characters in one iteration.\nRead the final verification and the latest failure evidence first, then build a compact table of assistant step ids, actions, and following observations.\nTrace backward from that evidence with viewSpans or searchSpan, confirming each candidate step's own action content, instead of repeatedly printing the table.\nThis runner emits no JSON fields, so the block is encoded in the finding's subject.\nOnly findings_json is scored; your prose answer is ignored, so every incorrect block you identify must appear as a finding, never only in the answer.\nEmit exactly one finding per contiguous failure block.\nSet the finding's subject to incorrect-steps-<first_step>-<last_step>-<escape_status>-consequence-<consequence_step>, using the same four values the task defines; for a block covering only step 7 that the agent never escaped and whose damage shows at step 9, the subject is incorrect-steps-7-7-unescaped-consequence-9.\nThe runner expands the block to one scored step per member and builds every scored citation itself.\nCite the block's first step and its last step as trace://<URL-encoded-trace-id>/span/step-<n>, each excerpt an exact quote from that step's own action content.\nGive the rationale as the concrete downstream evidence visible at the consequence step.\nSubmit as soon as every candidate failure block has a supported verdict.\nReturn no finding for a clean trajectory.`\n\n/** Reply-envelope contract shared by both one-shot datasets. */\nexport const PUBLIC_BENCHMARK_ENVELOPE_CONTRACT = `Return exactly one JSON object with:\n- \"report\": a concise evidence-based explanation, at most 4000 characters\n- \"findings\": the strict finding array\nUse an empty findings array when the trace does not support a finding.\nDo not return a bare array, markdown, trace URIs, copied excerpts, or fields not listed above.\nThe runner constructs exact trace URIs and action previews from each selected step.`\n\n/** Per-dataset field grammar for the one-shot JSON reply. */\nexport function publicBenchmarkFieldContract(dataset: PublicAnalystBenchmarkDataset): string {\n return dataset === 'agentrx' ? AGENT_RX_JSON_CONTRACT : CODE_TRACE_JSON_CONTRACT\n}\n\n/** One-shot JSON transport prompt for the direct runner. */\nexport function publicBenchmarkSystemPrompt(dataset: PublicAnalystBenchmarkDataset): string {\n return [\n publicBenchmarkTaskPrompt(dataset),\n publicBenchmarkFieldContract(dataset),\n PUBLIC_BENCHMARK_ENVELOPE_CONTRACT,\n ].join('\\n\\n')\n}\n\n/** Tool-loop prompt for the recursive runner. Same task, subject-encoded block. */\nexport function publicBenchmarkRlmInstructions(dataset: PublicAnalystBenchmarkDataset): string {\n const outputContract = dataset === 'agentrx' ? AGENT_RX_RLM_CONTRACT : CODE_TRACE_RLM_CONTRACT\n return `${publicBenchmarkTaskPrompt(dataset)}\n${outputContract}`\n}\n\n/** Task text shared by every runner shape on one dataset. */\nexport function publicBenchmarkTaskPrompt(dataset: PublicAnalystBenchmarkDataset): string {\n return dataset === 'agentrx' ? AGENT_RX_PROMPT : CODE_TRACE_BENCH_ANALYST_PROMPT\n}\n\n/** Digest of every prompt a runner can send plus the shared transport limits.\n * Both runner contracts are hashed so an edit to either one changes the digest\n * a run records, whichever runner executed. */\nexport function publicBenchmarkProtocolSha256(dataset: PublicAnalystBenchmarkDataset): string {\n return sha256Digest(\n JSON.stringify({\n dataset,\n systemPrompt: publicBenchmarkSystemPrompt(dataset),\n rlmInstructions: publicBenchmarkRlmInstructions(dataset),\n transport: {\n attempts: 1,\n jsonMode: true,\n thinking: 'disabled',\n },\n blockLimits:\n dataset === 'agentrx'\n ? null\n : {\n maxBlocks: MAX_INCORRECT_BLOCKS,\n maxBlockSteps: MAX_INCORRECT_BLOCK_STEPS,\n },\n traceProjectionAttributeByteCaps: TRACE_PROJECTION_ATTRIBUTE_BYTE_CAPS,\n evidence: {\n location: 'model-selected-positive-integer-assistant-step',\n uri: 'deterministic-trace-uri',\n excerpt: `exact-action-prefix-${MAX_ASSISTANT_STEP_EVIDENCE_EXCERPT_CHARACTERS}`,\n },\n }),\n )\n}\n","import { readFileSync } from 'node:fs'\nimport { publicBenchmarkProtocolSha256 } from './benchmark-public-prompt'\nimport type {\n AnalystInstructionsOverride,\n PublicAnalystBenchmarkDataset,\n} from './benchmark-public-types'\nimport { sha256Digest } from './benchmark-verification-artifacts'\n\n/** Build an override from instruction text. Blank text is a caller error. */\nexport function analystInstructionsOverrideFromText(text: string): AnalystInstructionsOverride {\n if (typeof text !== 'string' || !text.trim()) {\n throw new Error('analyst instructions override must contain non-empty instruction text')\n }\n return { text, sha256: sha256Digest(text) }\n}\n\n/** Read override instructions from a file. Any read failure is fatal. */\nexport function readAnalystInstructionsOverride(path: string): AnalystInstructionsOverride {\n let text: string\n try {\n text = readFileSync(path, 'utf8')\n } catch (error) {\n throw new Error(\n `cannot read --instructions-file '${path}': ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n if (!text.trim()) {\n throw new Error(`--instructions-file '${path}' is empty; refusing to run without instructions`)\n }\n return analystInstructionsOverrideFromText(text)\n}\n\n/**\n * Protocol digest of the run as executed.\n *\n * Without an override this is exactly `publicBenchmarkProtocolSha256(dataset)`,\n * so stock runs stay byte-identical to runs recorded before the override\n * existed. With an override the digest binds the stock protocol digest (which\n * covers both shipped prompts, including the abstention fallback's direct\n * prompt) to the exact override text, so the recorded digest always hashes the\n * instructions that actually ran.\n */\nexport function effectiveAnalystProtocolSha256(\n dataset: PublicAnalystBenchmarkDataset,\n override?: Pick<AnalystInstructionsOverride, 'sha256'>,\n): string {\n const stock = publicBenchmarkProtocolSha256(dataset)\n if (!override) return stock\n return sha256Digest(\n JSON.stringify({\n kind: 'analyst-instructions-override-protocol',\n dataset,\n stockProtocolSha256: stock,\n rlmInstructionsSha256: override.sha256,\n }),\n )\n}\n","import { randomUUID } from 'node:crypto'\nimport { constants } from 'node:fs'\nimport { link, lstat, mkdir, open, readFile, unlink } from 'node:fs/promises'\nimport { arch, platform } from 'node:os'\nimport { dirname, resolve } from 'node:path'\nimport { resolveExternalOptimizerProcessLimits } from '../campaign/external-optimizer-contracts'\nimport { resolveModelPricing } from '../metrics'\nimport type { AnalystBenchmarkObservation } from './benchmark'\nimport {\n ANALYST_BENCHMARK_COST_LEDGER_FILE,\n ANALYST_BENCHMARK_LOCAL_RECEIPT_FILE,\n ANALYST_BENCHMARK_MANIFEST_FILE,\n ANALYST_BENCHMARK_OBSERVATIONS_FILE,\n type AnalystBenchmarkLocalRunReceipt,\n type AnalystBenchmarkProgressRow,\n type AnalystBenchmarkRunIdentity,\n type AnalystBenchmarkRunManifest,\n assertAnalystBenchmarkObservation,\n assertExactKeys,\n canonicalJson,\n digestCanonical,\n isRecord,\n isSha256,\n observationKey,\n parseJson,\n} from './benchmark-command-artifact'\nimport {\n ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256,\n ANALYST_BENCHMARK_IMPLEMENTATION_SHA256,\n} from './benchmark-implementation'\nimport { effectiveAnalystProtocolSha256 } from './benchmark-instructions-override'\nimport type {\n PreparedPublicAnalystBenchmark,\n PublicAnalystBenchmarkDataset,\n PublicAnalystBenchmarkModelSettings,\n} from './benchmark-real-model'\n\nexport interface AnalystBenchmarkOutputPaths {\n directory: string\n initializationComplete: string\n manifest: string\n observations: string\n costLedger: string\n modelResponses: string\n localReceipt: string\n result: string\n report: string\n}\n\nexport const ANALYST_BENCHMARK_INITIALIZATION_COMPLETE_FILE = 'initialization-complete.json'\n\nexport interface AnalystBenchmarkProgress {\n observations: AnalystBenchmarkObservation[]\n nextSequence: number\n previousRowSha256: string | null\n}\n\ninterface AnalystBenchmarkPersistenceConfig {\n dataset: PublicAnalystBenchmarkDataset\n analyst: string\n labelsPath: string\n traceDir: string\n artifactDir?: string\n revision: string\n split: string\n model: PublicAnalystBenchmarkModelSettings\n limit: number\n seed: number\n concurrency: number\n repetitions: number\n rlmSamples: number\n maxCostUsd: number\n maxArtifactBytes: number\n /** Absent when the analyst owns its own transport (`prime`). */\n modelOwnerModule?: string\n command: string\n}\n\nexport async function openOutputDirectory(\n outDir: string,\n resume: boolean,\n): Promise<AnalystBenchmarkOutputPaths> {\n const directory = resolve(outDir)\n if (resume) {\n let outputStat: Awaited<ReturnType<typeof lstat>>\n try {\n outputStat = await lstat(directory)\n } catch (error) {\n if (isNodeError(error, 'ENOENT')) {\n throw new Error(`cannot resume missing benchmark output directory: ${directory}`)\n }\n throw error\n }\n if (!outputStat.isDirectory() || outputStat.isSymbolicLink()) {\n throw new Error(`benchmark output must be a real directory: ${directory}`)\n }\n } else {\n await mkdir(dirname(directory), { recursive: true })\n try {\n await mkdir(directory)\n } catch (error) {\n if (isNodeError(error, 'EEXIST')) {\n throw new Error(`refusing to use existing benchmark output directory: ${directory}`)\n }\n throw error\n }\n await syncDirectory(dirname(directory))\n }\n return {\n directory,\n initializationComplete: resolve(directory, ANALYST_BENCHMARK_INITIALIZATION_COMPLETE_FILE),\n manifest: resolve(directory, ANALYST_BENCHMARK_MANIFEST_FILE),\n observations: resolve(directory, ANALYST_BENCHMARK_OBSERVATIONS_FILE),\n costLedger: resolve(directory, ANALYST_BENCHMARK_COST_LEDGER_FILE),\n modelResponses: resolve(directory, 'model-responses'),\n localReceipt: resolve(directory, ANALYST_BENCHMARK_LOCAL_RECEIPT_FILE),\n result: resolve(directory, 'result.json'),\n report: resolve(directory, 'report.md'),\n }\n}\n\nexport async function prepareOutputLockPath(outDir: string): Promise<string> {\n const directory = resolve(outDir)\n await mkdir(dirname(directory), { recursive: true })\n return `${directory}.lock`\n}\n\nexport function createRunIdentity(\n config: AnalystBenchmarkPersistenceConfig,\n prepared: PreparedPublicAnalystBenchmark,\n): AnalystBenchmarkRunIdentity {\n const model = commandModelIdentity(config.model)\n const caseDefinitions = prepared.cases.map((testCase) => ({\n id: testCase.id,\n clusterId: testCase.clusterId,\n labelState: testCase.labelState,\n expectedIssues: testCase.expectedIssues,\n labeledEvidence: testCase.labeledEvidence ?? [],\n tags: testCase.tags ?? [],\n metadata: testCase.metadata ?? {},\n }))\n return {\n config: {\n dataset: config.dataset,\n datasetRevision: config.revision,\n datasetSplit: config.split,\n model: {\n id: config.model.model,\n ...model,\n },\n limit: config.limit,\n seed: config.seed,\n concurrency: config.concurrency,\n repetitions: config.repetitions,\n rlmSamples: config.rlmSamples,\n maxCostUsd: config.maxCostUsd,\n maxArtifactBytes: config.maxArtifactBytes,\n analystProtocolSha256: effectiveAnalystProtocolSha256(\n config.dataset,\n config.model.instructionsOverride,\n ),\n ...(config.model.instructionsOverride\n ? { instructionsOverrideSha256: config.model.instructionsOverride.sha256 }\n : {}),\n implementationSha256: ANALYST_BENCHMARK_IMPLEMENTATION_SHA256,\n dependencyLockSha256: ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256,\n runnerIds: ['empty', config.analyst] as const,\n },\n inputs: {\n labelsSha256: prepared.labelsSha256,\n sourceRowCount: prepared.sourceRowCount,\n selectedCaseIds: [...prepared.selectedCaseIds],\n traceFiles: prepared.traceFiles.map((traceFile) => ({ ...traceFile })),\n verificationArtifactsSha256: digestCanonical(prepared.verificationArtifacts),\n caseDefinitionsSha256: digestCanonical(caseDefinitions),\n },\n }\n}\n\nfunction commandModelIdentity(config: PublicAnalystBenchmarkModelSettings) {\n const catalogPricing = resolveModelPricing(config.model)\n const pricing =\n config.pricing ??\n (catalogPricing\n ? {\n inputUsdPerMillion: catalogPricing.input * 1_000,\n outputUsdPerMillion: catalogPricing.output * 1_000,\n }\n : undefined)\n if (!pricing) {\n throw new Error(`benchmark model '${config.model}' has no recorded pricing`)\n }\n const recursive = config.dspyRlm\n return {\n ownerCallRef: config.callRef,\n maxOutputTokens: config.maxOutputTokens,\n maxReasoningTokens: config.maxReasoningTokens ?? config.maxOutputTokens * 4,\n maxRequestBytes: config.maxModelRequestBytes ?? 16 * 1024 * 1024,\n maxResponseBytes: config.maxModelResponseBytes ?? 4 * 1024 * 1024,\n requestTimeoutMs: config.modelRequestTimeoutMs ?? config.timeoutMs,\n timeoutMs: config.timeoutMs,\n pricing: { ...pricing },\n recursiveLimits: {\n maxIterations: recursive?.maxIterations ?? 14,\n maxLlmCalls: recursive?.maxLlmCalls ?? 8,\n maxToolCalls: recursive?.maxToolCalls ?? 80,\n maxOutputChars: recursive?.maxOutputChars ?? 8_000,\n maxModelRequests: recursive?.maxModelRequests ?? null,\n traceToolRequestBytes: recursive?.traceToolRequestBytes ?? 1_000_000,\n traceToolResponseBytes: recursive?.traceToolResponseBytes ?? 4_000_000,\n traceToolTimeoutMs: recursive?.traceToolTimeoutMs ?? 60_000,\n },\n processLimits: resolveExternalOptimizerProcessLimits(recursive?.runner?.limits),\n }\n}\n\nexport function createLocalRunReceipt(\n config: AnalystBenchmarkPersistenceConfig,\n paths: AnalystBenchmarkOutputPaths,\n): Omit<AnalystBenchmarkLocalRunReceipt, 'runIdentitySha256' | 'localIdentitySha256'> {\n return {\n kind: 'agent-eval/analyst-benchmark-local-run',\n local: {\n labelsPath: resolve(config.labelsPath),\n traceDir: resolve(config.traceDir),\n ...(config.artifactDir ? { artifactDir: resolve(config.artifactDir) } : {}),\n outputDir: paths.directory,\n ...(config.modelOwnerModule === undefined\n ? {}\n : { modelOwnerModule: config.modelOwnerModule }),\n },\n command: config.command,\n environment: {\n node: process.version,\n platform: platform(),\n arch: arch(),\n },\n files: {\n manifest: paths.manifest,\n observations: paths.observations,\n costLedger: paths.costLedger,\n modelResponses: paths.modelResponses,\n result: paths.result,\n report: paths.report,\n },\n }\n}\n\nexport async function initializeRunFiles(\n paths: AnalystBenchmarkOutputPaths,\n identity: AnalystBenchmarkRunIdentity,\n identitySha256: string,\n localIdentitySha256: string,\n localReceiptInput: Omit<\n AnalystBenchmarkLocalRunReceipt,\n 'runIdentitySha256' | 'localIdentitySha256'\n >,\n): Promise<AnalystBenchmarkRunManifest> {\n const existingManifest = await readOptionalRegularFile(paths.manifest, 'benchmark run manifest')\n const manifest = existingManifest\n ? await readAndValidateManifestContent(\n paths.manifest,\n existingManifest,\n identity,\n identitySha256,\n localIdentitySha256,\n )\n : {\n kind: 'agent-eval/analyst-benchmark-run' as const,\n createdAt: new Date().toISOString(),\n identitySha256,\n localIdentitySha256,\n identity,\n }\n const localReceipt: AnalystBenchmarkLocalRunReceipt = {\n ...localReceiptInput,\n runIdentitySha256: identitySha256,\n localIdentitySha256,\n }\n const manifestContent = `${JSON.stringify(manifest, null, 2)}\\n`\n const localReceiptContent = `${JSON.stringify(localReceipt, null, 2)}\\n`\n const initializationCompleteContent = renderInitializationComplete(manifest)\n\n await assertAbsentOrExact(paths.observations, '', 'benchmark observation log')\n await assertAbsentOrExact(paths.localReceipt, localReceiptContent, 'benchmark local run receipt')\n await assertAbsentOrExact(paths.manifest, manifestContent, 'benchmark run manifest')\n for (const path of [paths.costLedger, paths.modelResponses, paths.result, paths.report]) {\n if (await regularFileExists(path)) {\n throw new Error(\n `benchmark initialization marker is missing but later run artifact exists: ${path}`,\n )\n }\n }\n if (await regularFileExists(paths.initializationComplete)) {\n throw new Error(\n `benchmark initialization marker already exists during partial initialization: ${paths.initializationComplete}`,\n )\n }\n\n await writeExclusiveOrVerify(paths.observations, '')\n await writeExclusiveOrVerify(paths.localReceipt, localReceiptContent)\n await writeExclusiveOrVerify(paths.manifest, manifestContent)\n await writeExclusiveOrVerify(paths.initializationComplete, initializationCompleteContent)\n return manifest\n}\n\nexport async function readAndValidateResumeFiles(\n paths: AnalystBenchmarkOutputPaths,\n currentIdentity: AnalystBenchmarkRunIdentity,\n currentIdentitySha256: string,\n currentLocalIdentitySha256: string,\n localReceiptInput: Omit<\n AnalystBenchmarkLocalRunReceipt,\n 'runIdentitySha256' | 'localIdentitySha256'\n >,\n): Promise<AnalystBenchmarkRunManifest> {\n if (!(await regularFileExists(paths.initializationComplete))) {\n return initializeRunFiles(\n paths,\n currentIdentity,\n currentIdentitySha256,\n currentLocalIdentitySha256,\n localReceiptInput,\n )\n }\n const manifest = await readAndValidateManifest(\n paths.manifest,\n currentIdentity,\n currentIdentitySha256,\n currentLocalIdentitySha256,\n )\n const localReceiptContent = await readRegularFile(\n paths.localReceipt,\n 'benchmark local run receipt',\n )\n const value = parseJson(localReceiptContent, paths.localReceipt)\n if (!isRecord(value)) {\n throw new TypeError(`benchmark local run receipt must be an object: ${paths.localReceipt}`)\n }\n assertExactKeys(\n value,\n [\n 'kind',\n 'runIdentitySha256',\n 'localIdentitySha256',\n 'local',\n 'command',\n 'environment',\n 'files',\n ],\n 'benchmark local run receipt',\n )\n if (\n value.kind !== 'agent-eval/analyst-benchmark-local-run' ||\n value.runIdentitySha256 !== currentIdentitySha256 ||\n value.localIdentitySha256 !== currentLocalIdentitySha256 ||\n !isRecord(value.local)\n ) {\n throw new Error('benchmark local run receipt does not match the requested resume')\n }\n const expectedLocalReceipt: AnalystBenchmarkLocalRunReceipt = {\n ...localReceiptInput,\n runIdentitySha256: currentIdentitySha256,\n localIdentitySha256: currentLocalIdentitySha256,\n }\n const storedLocalIdentitySha256 = digestCanonical(value.local)\n if (\n storedLocalIdentitySha256 !== currentLocalIdentitySha256 ||\n canonicalJson(value.local) !== canonicalJson(localReceiptInput.local)\n ) {\n throw new Error('benchmark local paths or model-owner module do not match the requested resume')\n }\n if (localReceiptContent !== `${JSON.stringify(expectedLocalReceipt, null, 2)}\\n`) {\n throw new Error(`benchmark local run receipt does not exactly match: ${paths.localReceipt}`)\n }\n const initializationCompleteContent = await readRegularFile(\n paths.initializationComplete,\n 'benchmark initialization marker',\n )\n if (initializationCompleteContent !== renderInitializationComplete(manifest)) {\n throw new Error(\n `benchmark initialization marker does not match the run manifest: ${paths.initializationComplete}`,\n )\n }\n return manifest\n}\n\nasync function readAndValidateManifest(\n path: string,\n currentIdentity: AnalystBenchmarkRunIdentity,\n currentIdentitySha256: string,\n currentLocalIdentitySha256: string,\n): Promise<AnalystBenchmarkRunManifest> {\n const content = await readRegularFile(path, 'benchmark run manifest')\n const manifest = await readAndValidateManifestContent(\n path,\n content,\n currentIdentity,\n currentIdentitySha256,\n currentLocalIdentitySha256,\n )\n if (content !== `${JSON.stringify(manifest, null, 2)}\\n`) {\n throw new Error(`benchmark run manifest does not exactly match: ${path}`)\n }\n return manifest\n}\n\nasync function readAndValidateManifestContent(\n path: string,\n content: string,\n currentIdentity: AnalystBenchmarkRunIdentity,\n currentIdentitySha256: string,\n currentLocalIdentitySha256: string,\n): Promise<AnalystBenchmarkRunManifest> {\n const value = parseJson(content, path)\n if (!isRecord(value)) throw new TypeError(`benchmark run manifest must be an object: ${path}`)\n assertExactKeys(\n value,\n ['kind', 'createdAt', 'identitySha256', 'localIdentitySha256', 'identity'],\n 'benchmark run manifest',\n )\n if (value.kind !== 'agent-eval/analyst-benchmark-run') {\n throw new TypeError(`unsupported benchmark run manifest: ${path}`)\n }\n if (typeof value.createdAt !== 'string' || !Number.isFinite(Date.parse(value.createdAt))) {\n throw new TypeError(`benchmark run manifest has an invalid createdAt: ${path}`)\n }\n if (\n !isSha256(value.identitySha256) ||\n !isSha256(value.localIdentitySha256) ||\n !isRecord(value.identity)\n ) {\n throw new TypeError(`benchmark run manifest has an invalid identity: ${path}`)\n }\n const storedIdentitySha256 = digestCanonical(value.identity)\n if (storedIdentitySha256 !== value.identitySha256) {\n throw new Error(`benchmark run manifest identity digest does not match its contents: ${path}`)\n }\n if (\n currentIdentitySha256 !== value.identitySha256 ||\n currentLocalIdentitySha256 !== value.localIdentitySha256 ||\n canonicalJson(currentIdentity) !== canonicalJson(value.identity)\n ) {\n throw new Error(\n `benchmark resume configuration or inputs do not match ${ANALYST_BENCHMARK_MANIFEST_FILE}`,\n )\n }\n return {\n kind: 'agent-eval/analyst-benchmark-run',\n createdAt: value.createdAt,\n identitySha256: currentIdentitySha256,\n localIdentitySha256: currentLocalIdentitySha256,\n identity: currentIdentity,\n }\n}\n\nfunction renderInitializationComplete(manifest: AnalystBenchmarkRunManifest): string {\n return `${JSON.stringify(\n {\n kind: 'agent-eval/analyst-benchmark-initialization-complete',\n runIdentitySha256: manifest.identitySha256,\n localIdentitySha256: manifest.localIdentitySha256,\n createdAt: manifest.createdAt,\n },\n null,\n 2,\n )}\\n`\n}\n\nasync function assertAbsentOrExact(path: string, expected: string, label: string): Promise<void> {\n const existing = await readOptionalRegularFile(path, label)\n if (existing !== undefined && existing !== expected) {\n throw new Error(`${label} does not exactly match interrupted initialization: ${path}`)\n }\n}\n\nasync function readOptionalRegularFile(path: string, label: string): Promise<string | undefined> {\n if (!(await regularFileExists(path))) return undefined\n return readRegularFile(path, label)\n}\n\nexport function createObservationAppender(\n path: string,\n runIdentitySha256: string,\n progress: AnalystBenchmarkProgress,\n): (observation: AnalystBenchmarkObservation) => Promise<void> {\n let writes = Promise.resolve()\n const seen = new Set(progress.observations.map(observationKey))\n return (observation) => {\n const write = writes.then(async () => {\n assertAnalystBenchmarkObservation(observation, 'benchmark observation')\n const key = observationKey(observation)\n if (seen.has(key)) {\n throw new Error(\n `refusing duplicate benchmark observation '${observation.runnerId}/${observation.caseId}/${observation.repetition}'`,\n )\n }\n const rowWithoutDigest = {\n sequence: progress.nextSequence,\n runIdentitySha256,\n previousRowSha256: progress.previousRowSha256,\n observation,\n }\n const row: AnalystBenchmarkProgressRow = {\n ...rowWithoutDigest,\n rowSha256: digestCanonical(rowWithoutDigest),\n }\n await appendDurable(path, `${JSON.stringify(row)}\\n`)\n progress.nextSequence += 1\n progress.previousRowSha256 = row.rowSha256\n progress.observations.push(observation)\n seen.add(key)\n })\n writes = write\n return write\n }\n}\n\nexport async function readProgress(\n path: string,\n runIdentitySha256: string,\n caseIds: readonly string[],\n repetitions: number,\n analystRunnerId: string,\n): Promise<AnalystBenchmarkProgress> {\n const text = await readRegularFile(path, 'benchmark observation log')\n const rawLines = text.split('\\n')\n if (rawLines.at(-1) === '') rawLines.pop()\n const observations: AnalystBenchmarkObservation[] = []\n const seen = new Set<string>()\n const executionIndexes = new Set<number>()\n let previousRowSha256: string | null = null\n const allowedCases = new Set(caseIds)\n const plannedObservationCount = caseIds.length * 2 * repetitions\n\n for (const [index, line] of rawLines.entries()) {\n if (!line.trim()) {\n throw new Error(`benchmark observation log contains an empty row at line ${index + 1}`)\n }\n const parsed = parseJson(line, `${path}:${index + 1}`)\n if (!isRecord(parsed)) {\n throw new TypeError(`benchmark observation row ${index + 1} must be an object`)\n }\n assertExactKeys(\n parsed,\n ['sequence', 'runIdentitySha256', 'previousRowSha256', 'observation', 'rowSha256'],\n `benchmark observation row ${index + 1}`,\n )\n assertAnalystBenchmarkObservation(\n parsed.observation,\n `benchmark observation row ${index + 1}.observation`,\n )\n const observation = parsed.observation\n const key = observationKey(observation)\n if (seen.has(key)) {\n throw new Error(\n `duplicate benchmark observation '${observation.runnerId}/${observation.caseId}/${observation.repetition}' at line ${index + 1}`,\n )\n }\n if (parsed.sequence !== index) {\n throw new Error(\n `benchmark observation row ${index + 1} has sequence ${String(parsed.sequence)}; expected ${index}`,\n )\n }\n if (parsed.runIdentitySha256 !== runIdentitySha256) {\n throw new Error(`benchmark observation row ${index + 1} belongs to another run`)\n }\n if (parsed.previousRowSha256 !== previousRowSha256) {\n throw new Error(`benchmark observation row ${index + 1} breaks the digest chain`)\n }\n if (!isSha256(parsed.rowSha256)) {\n throw new TypeError(`benchmark observation row ${index + 1} has an invalid digest`)\n }\n const expectedDigest = digestCanonical({\n sequence: parsed.sequence,\n runIdentitySha256: parsed.runIdentitySha256,\n previousRowSha256: parsed.previousRowSha256,\n observation,\n })\n if (expectedDigest !== parsed.rowSha256) {\n throw new Error(`benchmark observation row ${index + 1} digest does not match its contents`)\n }\n if (\n !allowedCases.has(observation.caseId) ||\n (observation.runnerId !== 'empty' && observation.runnerId !== analystRunnerId) ||\n observation.repetition >= repetitions ||\n observation.executionIndex >= plannedObservationCount\n ) {\n throw new Error(\n `benchmark observation row ${index + 1} does not match a planned case, runner, and repetition`,\n )\n }\n if (executionIndexes.has(observation.executionIndex)) {\n throw new Error(\n `duplicate benchmark executionIndex ${observation.executionIndex} at line ${index + 1}`,\n )\n }\n observations.push(observation)\n seen.add(key)\n executionIndexes.add(observation.executionIndex)\n previousRowSha256 = parsed.rowSha256\n }\n\n return {\n observations,\n nextSequence: observations.length,\n previousRowSha256,\n }\n}\n\nexport async function writeExclusiveOrVerify(path: string, content: string): Promise<void> {\n try {\n await writeExclusive(path, content)\n } catch (error) {\n if (!isNodeError(error, 'EEXIST')) throw error\n const existing = await readRegularFile(path, 'existing benchmark artifact')\n if (existing !== content) {\n throw new Error(`refusing to replace existing benchmark artifact: ${path}`)\n }\n }\n}\n\nexport async function regularFileExists(path: string): Promise<boolean> {\n try {\n const fileStat = await lstat(path)\n if (!fileStat.isFile() || fileStat.isSymbolicLink()) {\n throw new Error(`benchmark artifact path must be a real file: ${path}`)\n }\n return true\n } catch (error) {\n if (isNodeError(error, 'ENOENT')) return false\n throw error\n }\n}\n\nasync function appendDurable(path: string, content: string): Promise<void> {\n const handle = await open(path, constants.O_APPEND | constants.O_WRONLY | constants.O_NOFOLLOW)\n try {\n await handle.writeFile(content, 'utf8')\n await handle.sync()\n } finally {\n await handle.close()\n }\n}\n\nasync function writeExclusive(path: string, content: string): Promise<void> {\n const temporary = `${path}.tmp-${process.pid}-${randomUUID()}`\n let handle: Awaited<ReturnType<typeof open>> | undefined\n try {\n handle = await open(temporary, 'wx')\n await handle.writeFile(content, 'utf8')\n await handle.sync()\n await handle.close()\n handle = undefined\n await link(temporary, path)\n await syncDirectory(dirname(path))\n } finally {\n await handle?.close().catch(() => undefined)\n await unlink(temporary).catch(() => undefined)\n }\n}\n\nexport async function readRegularFile(path: string, label: string): Promise<string> {\n let fileStat: Awaited<ReturnType<typeof lstat>>\n try {\n fileStat = await lstat(path)\n } catch (error) {\n if (isNodeError(error, 'ENOENT')) throw new Error(`${label} is missing: ${path}`)\n throw error\n }\n if (!fileStat.isFile() || fileStat.isSymbolicLink()) {\n throw new Error(`${label} must be a real file: ${path}`)\n }\n return readFile(path, 'utf8')\n}\n\nasync function syncDirectory(path: string): Promise<void> {\n const directory = await open(path, 'r')\n try {\n await directory.sync()\n } finally {\n await directory.close()\n }\n}\n\nfunction isNodeError(error: unknown, code: string): error is NodeJS.ErrnoException {\n return error instanceof Error && 'code' in error && error.code === code\n}\n","import type { AnalystBenchmarkObservation, AnalystBenchmarkResult } from './benchmark'\nimport { codeTraceStepFromEvidence } from './benchmark-evidence-validation'\n\nexport interface CodeTraceCalibrationRunnerSummary {\n runnerId: string\n selectedRuns: number\n positiveRuns: number\n trustedNegativeRuns: number\n unlabeledRuns: number\n failedLabelEmptyRuns: number\n unknownLabelEmptyRuns: number\n completedRuns: number\n failedRuns: number\n expectedIncorrectSteps: number\n predictedIncorrectSteps: number\n matchedIncorrectSteps: number\n /** CodeTraceBench's published mean per-row incorrect-step F1 over every row. */\n officialAllRowF1: number | null\n officialAllRowRuns: number\n precision: number | null\n recall: number | null\n f1: number | null\n trustedNegativeFalsePositiveRate: number | null\n trustedNegativeFailureRate: number | null\n unlabeledPredictionRate: number | null\n unlabeledFailureRate: number | null\n}\n\nexport interface CodeTraceCalibrationSummary {\n protocol: 'labeled-positive-and-solved-negative'\n rationale: string\n runners: CodeTraceCalibrationRunnerSummary[]\n}\n\nexport function summarizeCodeTraceCalibration(\n result: AnalystBenchmarkResult,\n): CodeTraceCalibrationSummary {\n return {\n protocol: 'labeled-positive-and-solved-negative',\n rationale:\n 'Uses rows with incorrect-step labels as positives and solved label-empty rows as trusted negatives. Failed label-empty rows remain in the published result but are not treated as clean controls.',\n runners: result.provenance.runnerIds.map((runnerId) =>\n summarizeRunner(\n runnerId,\n result.observations.filter((observation) => observation.runnerId === runnerId),\n ),\n ),\n }\n}\n\nexport function renderCodeTraceCalibrationMarkdown(summary: CodeTraceCalibrationSummary): string {\n return [\n '## CodeTraceBench Calibrated View',\n '',\n summary.rationale,\n '',\n '| Runner | Completed/selected | Failed | Positive runs | Trusted negative runs | Unlabeled runs | Failed label-empty | Unknown label-empty | Matched/expected steps | Predicted steps | Precision | Recall | F1 | Official all-row F1 | Official rows | Trusted-negative false positives | Trusted-negative failures | Unlabeled predictions | Unlabeled failures |',\n '| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |',\n ...summary.runners.map(\n (runner) =>\n `| ${escapeCell(runner.runnerId)} | ${runner.completedRuns}/${runner.selectedRuns} | ${runner.failedRuns} | ${runner.positiveRuns} | ${runner.trustedNegativeRuns} | ${runner.unlabeledRuns} | ${runner.failedLabelEmptyRuns} | ${runner.unknownLabelEmptyRuns} | ${runner.matchedIncorrectSteps}/${runner.expectedIncorrectSteps} | ${runner.predictedIncorrectSteps} | ${rate(runner.precision)} | ${rate(runner.recall)} | ${rate(runner.f1)} | ${rate(runner.officialAllRowF1)} | ${runner.officialAllRowRuns} | ${rate(runner.trustedNegativeFalsePositiveRate)} | ${rate(runner.trustedNegativeFailureRate)} | ${rate(runner.unlabeledPredictionRate)} | ${rate(runner.unlabeledFailureRate)} |`,\n ),\n ].join('\\n')\n}\n\nfunction summarizeRunner(\n runnerId: string,\n observations: readonly AnalystBenchmarkObservation[],\n): CodeTraceCalibrationRunnerSummary {\n const positive = observations.filter((observation) => observation.labelState === 'positive')\n const trustedNegative = observations.filter(\n (observation) => observation.labelState === 'trusted-negative',\n )\n const excluded = observations.filter((observation) => observation.labelState === 'unlabeled')\n const selected = [...positive, ...trustedNegative]\n const expected = sum(positive.map((observation) => observation.score.expectedIssueCount))\n const predicted = sum(\n selected.map((observation) => (observation.error ? 0 : observation.findings.length)),\n )\n const matched = sum(positive.map((observation) => observation.score.matchedIssueIds.length))\n const precision = predicted === 0 ? (expected > 0 ? 0 : null) : matched / predicted\n const recall = ratio(matched, expected)\n const completedTrustedNegative = trustedNegative.filter((observation) => !observation.error)\n const completedExcluded = excluded.filter((observation) => !observation.error)\n const officialRows = observations.map(officialCodeTraceF1)\n\n return {\n runnerId,\n selectedRuns: selected.length,\n positiveRuns: positive.length,\n trustedNegativeRuns: trustedNegative.length,\n unlabeledRuns: excluded.length,\n failedLabelEmptyRuns: excluded.filter(\n (observation) => observation.caseMetadata?.solved === false,\n ).length,\n unknownLabelEmptyRuns: excluded.filter(\n (observation) => observation.caseMetadata?.solved !== false,\n ).length,\n completedRuns: selected.filter((observation) => !observation.error).length,\n failedRuns: selected.filter((observation) => observation.error).length,\n expectedIncorrectSteps: expected,\n predictedIncorrectSteps: predicted,\n matchedIncorrectSteps: matched,\n officialAllRowF1: mean(officialRows),\n officialAllRowRuns: officialRows.length,\n precision,\n recall,\n f1: harmonicMean(precision, recall),\n trustedNegativeFalsePositiveRate: ratio(\n completedTrustedNegative.filter((observation) => observation.score.predictionOnLabelEmptyCase)\n .length,\n completedTrustedNegative.length,\n ),\n trustedNegativeFailureRate: ratio(\n trustedNegative.filter((observation) => observation.error).length,\n trustedNegative.length,\n ),\n unlabeledPredictionRate: ratio(\n completedExcluded.filter((observation) => observation.findings.length > 0).length,\n completedExcluded.length,\n ),\n unlabeledFailureRate: ratio(\n excluded.filter((observation) => Boolean(observation.error)).length,\n excluded.length,\n ),\n }\n}\n\nfunction officialCodeTraceF1(observation: AnalystBenchmarkObservation): number {\n const trajectoryId = observation.caseMetadata?.trajectoryId\n if (typeof trajectoryId !== 'string' || !trajectoryId.trim()) {\n throw new TypeError(`${observation.caseId}: CodeTraceBench trajectoryId metadata is missing`)\n }\n const expected = new Set(\n [...observation.score.matchedIssueIds, ...observation.score.missedIssueIds].map((issueId) => {\n const match = /^incorrect:(\\d+)$/.exec(issueId)\n if (!match) {\n throw new TypeError(`${observation.caseId}: invalid incorrect-step label '${issueId}'`)\n }\n return Number(match[1])\n }),\n )\n const predicted = new Set<number>()\n if (!observation.error) {\n for (const finding of observation.findings) {\n if (finding.area !== 'incorrect') continue\n for (const evidence of finding.evidence_refs) {\n const location = codeTraceStepFromEvidence(evidence.uri)\n if (!location || location.traceId !== trajectoryId) {\n throw new TypeError(\n `${observation.caseId}: invalid CodeTraceBench prediction evidence '${evidence.uri}'`,\n )\n }\n predicted.add(location.step)\n }\n }\n }\n let matched = 0\n for (const step of predicted) if (expected.has(step)) matched += 1\n const precision = predicted.size === 0 ? 0 : matched / predicted.size\n const recall = expected.size === 0 ? 0 : matched / expected.size\n return harmonicMean(precision, recall) ?? 0\n}\n\nfunction sum(values: readonly number[]): number {\n return values.reduce((total, value) => total + value, 0)\n}\n\nfunction ratio(numerator: number, denominator: number): number | null {\n return denominator === 0 ? null : numerator / denominator\n}\n\nfunction mean(values: readonly number[]): number | null {\n return values.length === 0 ? null : sum(values) / values.length\n}\n\nfunction harmonicMean(left: number | null, right: number | null): number | null {\n if (left === null || right === null) return null\n return left + right === 0 ? 0 : (2 * left * right) / (left + right)\n}\n\nfunction rate(value: number | null): string {\n return value === null ? 'n/a' : value.toFixed(3)\n}\n\nfunction escapeCell(value: string): string {\n return value.replaceAll('|', '\\\\|').replaceAll('\\n', ' ')\n}\n","import type { AnalystBenchmarkObservation } from './benchmark'\nimport {\n AGENT_RX_UPSTREAM_REVISION,\n summarizeAgentRxCalibration,\n} from './benchmark-agentrx-calibration'\nimport {\n type AnalystBenchmarkArtifact,\n type AnalystBenchmarkRunManifest,\n canonicalJson,\n observationKey,\n parseJson,\n} from './benchmark-command-artifact'\nimport { readRegularFile } from './benchmark-command-persistence'\nimport { assertAnalystBenchmarkArtifact } from './benchmark-command-validation'\nimport { compareAnalystRunners } from './benchmark-comparison'\nimport { summarizeCodeTraceCalibration } from './benchmark-public-calibration'\nimport type { PreparedPublicAnalystBenchmark } from './benchmark-real-model'\nimport { summarizeAnalystBenchmarkRunner } from './benchmark-summary'\n\nexport async function readAnalystBenchmarkArtifact(\n path: string,\n): Promise<AnalystBenchmarkArtifact> {\n const value = parseJson(await readRegularFile(path, 'analyst benchmark result'), path)\n assertAnalystBenchmarkArtifact(value, 'analyst benchmark result')\n return value\n}\n\nexport function assertCompletedArtifactMatchesRun(\n artifact: AnalystBenchmarkArtifact,\n manifest: AnalystBenchmarkRunManifest,\n observations: readonly AnalystBenchmarkObservation[],\n prepared: PreparedPublicAnalystBenchmark,\n): void {\n if (artifact.runIdentitySha256 !== manifest.identitySha256) {\n throw new Error('completed benchmark result belongs to another run')\n }\n assertSameObservations(artifact.result.observations, observations)\n const expectedCount =\n manifest.identity.inputs.selectedCaseIds.length *\n manifest.identity.config.runnerIds.length *\n manifest.identity.config.repetitions\n if (observations.length !== expectedCount) {\n throw new Error(\n `completed benchmark result has ${observations.length} observations; expected ${expectedCount}`,\n )\n }\n\n const { config, inputs } = manifest.identity\n const verificationAvailability = {\n cases: prepared.verificationArtifacts.length,\n resultFilesPresent: prepared.verificationArtifacts.filter(\n (artifact) => artifact.status === 'present',\n ).length,\n resultFilesMissing: prepared.verificationArtifacts.filter(\n (artifact) => artifact.status === 'missing',\n ).length,\n outcomes: {\n passed: prepared.verificationArtifacts.filter(\n (artifact) => artifact.outcome.status === 'passed',\n ).length,\n failed: prepared.verificationArtifacts.filter(\n (artifact) => artifact.outcome.status === 'failed',\n ).length,\n unavailable: prepared.verificationArtifacts.filter(\n (artifact) => artifact.outcome.status === 'unavailable',\n ).length,\n },\n }\n const expectedInputs: AnalystBenchmarkArtifact['inputs'] = {\n dataset: config.dataset,\n datasetRevision: config.datasetRevision,\n datasetSplit: config.datasetSplit,\n labelsSha256: inputs.labelsSha256,\n sourceRowCount: inputs.sourceRowCount,\n traceFiles: inputs.traceFiles.map((traceFile) => ({ ...traceFile })),\n verificationArtifacts: prepared.verificationArtifacts,\n verificationAvailability,\n selection: {\n limit: config.limit,\n seed: config.seed,\n selectedCaseIds: [...inputs.selectedCaseIds],\n report: prepared.selection,\n },\n execution: {\n repetitions: config.repetitions,\n concurrency: config.concurrency,\n ...(config.rlmSamples === undefined ? {} : { rlmSamples: config.rlmSamples }),\n model: config.model.id,\n modelOwnerCallRef: config.model.ownerCallRef,\n maxOutputTokens: config.model.maxOutputTokens,\n maxReasoningTokens: config.model.maxReasoningTokens,\n maxModelRequestBytes: config.model.maxRequestBytes,\n maxModelResponseBytes: config.model.maxResponseBytes,\n modelRequestTimeoutMs: config.model.requestTimeoutMs,\n timeoutMs: config.model.timeoutMs,\n pricing: config.model.pricing,\n recursiveLimits: config.model.recursiveLimits,\n processLimits: config.model.processLimits,\n maxCostUsd: config.maxCostUsd,\n maxArtifactBytes: config.maxArtifactBytes,\n analystProtocolSha256: config.analystProtocolSha256,\n ...(config.instructionsOverrideSha256 === undefined\n ? {}\n : { instructionsOverrideSha256: config.instructionsOverrideSha256 }),\n implementationSha256: config.implementationSha256,\n dependencyLockSha256: config.dependencyLockSha256,\n },\n }\n if (canonicalJson(artifact.inputs) !== canonicalJson(expectedInputs)) {\n throw new Error('completed benchmark result inputs do not match the run manifest')\n }\n\n const provenance = artifact.result.provenance\n const expectedDatasetId =\n config.dataset === 'agentrx' ? 'microsoft/AgentRx' : 'NJU-LINK/CodeTraceBench'\n const expectedOutputAdapter =\n config.dataset === 'agentrx'\n ? 'agentrx-taxonomy-and-root-step'\n : 'codetracebench-incorrect-block'\n if (\n provenance.id !== `${config.dataset}-real-model-analyst` ||\n provenance.startedAt !== manifest.createdAt ||\n !Number.isFinite(Date.parse(provenance.endedAt)) ||\n Date.parse(provenance.endedAt) < Date.parse(provenance.startedAt) ||\n canonicalJson(provenance.dataset) !==\n canonicalJson({\n id: expectedDatasetId,\n revision: config.datasetRevision,\n split: config.datasetSplit,\n }) ||\n provenance.caseCount !== inputs.selectedCaseIds.length ||\n canonicalJson(provenance.runnerIds) !== canonicalJson(config.runnerIds) ||\n provenance.repetitions !== config.repetitions ||\n provenance.maxConcurrency !== Math.min(config.concurrency, expectedCount) ||\n provenance.runnerOrderSeed !== config.seed ||\n provenance.metadata?.model !== config.model.id ||\n provenance.metadata?.modelOwnerCallRef !== config.model.ownerCallRef ||\n provenance.metadata?.rlmSamples !== config.rlmSamples ||\n provenance.metadata?.outputAdapter !== expectedOutputAdapter ||\n provenance.metadata?.caseSelection !== prepared.selection.method ||\n provenance.metadata?.caseSelectionSeed !== config.seed ||\n provenance.metadata?.selectionStratified !== prepared.selection.stratified ||\n provenance.metadata?.protocolSha256 !== config.analystProtocolSha256 ||\n provenance.metadata?.implementationSha256 !== config.implementationSha256 ||\n provenance.metadata?.dependencyLockSha256 !== config.dependencyLockSha256 ||\n provenance.metadata?.populationRepresentativenessProven !== false\n ) {\n throw new Error('completed benchmark result provenance does not match the run manifest')\n }\n\n const expectedSummaries = config.runnerIds.map((runnerId) =>\n summarizeAnalystBenchmarkRunner(\n runnerId,\n observations.filter((observation) => observation.runnerId === runnerId),\n ),\n )\n if (canonicalJson(artifact.result.summaries) !== canonicalJson(expectedSummaries)) {\n throw new Error('completed benchmark summaries do not match durable observations')\n }\n\n const expectedComparisons = [\n compareAnalystRunners(artifact.result, {\n baselineRunnerId: 'empty',\n candidateRunnerId: config.runnerIds[1],\n seed: config.seed,\n }),\n ]\n if (canonicalJson(artifact.comparisons) !== canonicalJson(expectedComparisons)) {\n throw new Error('completed benchmark comparisons do not match durable observations')\n }\n\n if (config.dataset === 'codetracebench') {\n if (\n canonicalJson(artifact.codeTraceCalibration) !==\n canonicalJson(summarizeCodeTraceCalibration(artifact.result)) ||\n artifact.agentRxCalibration !== undefined\n ) {\n throw new Error('completed CodeTraceBench calibration does not match durable observations')\n }\n } else if (\n canonicalJson(artifact.agentRxCalibration) !==\n canonicalJson(summarizeAgentRxCalibration(artifact.result, AGENT_RX_UPSTREAM_REVISION)) ||\n artifact.codeTraceCalibration !== undefined\n ) {\n throw new Error('completed AgentRx calibration does not match durable observations')\n }\n}\n\nexport function assertSameObservations(\n expected: readonly AnalystBenchmarkObservation[],\n actual: readonly AnalystBenchmarkObservation[],\n): void {\n if (expected.length !== actual.length) {\n throw new Error(\n `benchmark result has ${expected.length} observations but the durable log has ${actual.length}`,\n )\n }\n const expectedByKey = new Map(\n expected.map((observation) => [observationKey(observation), canonicalJson(observation)]),\n )\n for (const observation of actual) {\n const key = observationKey(observation)\n if (expectedByKey.get(key) !== canonicalJson(observation)) {\n throw new Error(\n `benchmark result does not match durable observation '${observation.runnerId}/${observation.caseId}/${observation.repetition}'`,\n )\n }\n expectedByKey.delete(key)\n }\n if (expectedByKey.size > 0) {\n throw new Error('benchmark result is missing durable observations')\n }\n}\n","import type { TraceAnalysisStore } from '../trace-analyst/store'\nimport type { AnalystBenchmarkRunner } from './benchmark'\nimport { agentRxPredictionsToFindings } from './benchmark-datasets'\nimport {\n codeTraceStepFromEvidence,\n resolveAssistantStepEvidence,\n validateCodeTraceFindingEvidence,\n} from './benchmark-evidence-validation'\nimport { MAX_INCORRECT_BLOCK_STEPS, MAX_INCORRECT_BLOCKS } from './benchmark-public-prompt'\nimport type { PublicAnalystBenchmarkDataset } from './benchmark-public-types'\nimport type { AnalystFinding, AnalystRunInputs, AnalystSeverity } from './types'\nimport { makeFinding } from './types'\n\n/**\n * One contiguous run of incorrect assistant steps, in the shape both public\n * benchmark runners produce. The direct runner parses it from JSON fields; the\n * recursive runner parses it from the finding subject. Expansion, evidence\n * resolution and scoring are identical from here on.\n */\nexport interface CodeTraceFailureBlock {\n firstStep: number\n lastStep: number\n /** Later step whose action or observation shows the damage this block caused. */\n consequenceStep: number\n escapeStatus: 'escaped' | 'unescaped'\n severity: AnalystSeverity\n claim: string\n confidence: number\n rationale?: string\n recommendedAction?: string\n metadata?: Record<string, unknown>\n}\n\n/**\n * What the expansion did with the model's blocks.\n *\n * Escaped blocks are scored exactly like unescaped ones — the escape decision\n * is recorded, never applied — so `escapedBlocks` measures the model's own\n * judgement without moving precision, recall, or the trusted-negative rate.\n */\nexport interface CodeTraceBlockDiagnostics {\n reportedBlocks: number\n escapedBlocks: number\n /** Blocks dropped because their consequence step is not a real assistant step. */\n blocksWithoutConsequenceEvidence: CodeTraceFailureBlock[]\n /** Interior steps a block claimed that the trace does not carry as assistant steps. */\n unresolvedBlockInteriorSteps: number[]\n /** Steps claimed by more than one block; the first block keeps the step. */\n overlappingBlockSteps: number[]\n /** Blocks dropped for violating the protocol's width, order, or count limits. */\n droppedBlocks: string[]\n /** Findings dropped before expansion because their shape or evidence is invalid. */\n rejectedFindings?: string[]\n /** Out-of-block citations removed from findings that kept at least one in-block citation. */\n trimmedCitations?: string[]\n}\n\n/**\n * One expanded step with the accepted block that owns it. The expansion's\n * per-step ownership record: exactly the steps that survived shape, count,\n * and evidence checks, so consensus voting sees the same step set the\n * benchmark scores.\n */\nexport interface CodeTraceStepAssignment {\n step: number\n block: CodeTraceFailureBlock\n}\n\nexport function emptyPublicBenchmarkRunner(): AnalystBenchmarkRunner<AnalystRunInputs> {\n return {\n id: 'empty',\n analyze() {\n return {\n findings: [],\n usage: {\n calls: 0,\n tokens: { input: 0, output: 0 },\n cost: { kind: 'observed', usd: 0 },\n },\n metadata: { baseline: 'emit-no-findings' },\n }\n },\n }\n}\n\nexport async function adaptPublicBenchmarkFindings(options: {\n dataset: PublicAnalystBenchmarkDataset\n trajectoryId: string\n findings: readonly AnalystFinding[]\n analystId: string\n store: TraceAnalysisStore\n signal?: AbortSignal\n}): Promise<{\n findings: AnalystFinding[]\n diagnostics: CodeTraceBlockDiagnostics | undefined\n /** Present for CodeTraceBench only; AgentRx has no step-level expansion. */\n stepBlocks?: CodeTraceStepAssignment[]\n}> {\n if (options.dataset === 'agentrx') {\n return {\n findings: adaptAgentRxFindings(options.trajectoryId, options.findings, options.analystId),\n diagnostics: undefined,\n }\n }\n return adaptCodeTraceFindings(\n options.trajectoryId,\n options.findings,\n options.analystId,\n options.store,\n options.signal,\n )\n}\n\nfunction adaptAgentRxFindings(\n trajectoryId: string,\n findings: readonly AnalystFinding[],\n analystId: string,\n): AnalystFinding[] {\n if (findings.length === 0) return []\n if (findings.length !== 1) {\n throw new Error(\n `AgentRx model analyst must emit zero or one root cause, received ${findings.length}`,\n )\n }\n const source = findings[0]!\n if (!source.subject) {\n throw new Error('AgentRx model analyst finding is missing its failure-category subject')\n }\n const steps = exactFindingSteps(trajectoryId, source)\n if (steps.length !== 1) {\n throw new Error(\n `AgentRx model analyst must cite exactly one root-cause step, received ${steps.length}`,\n )\n }\n const [adapted] = agentRxPredictionsToFindings(\n trajectoryId,\n [\n {\n failure_case: source.subject,\n step_number: steps[0]!,\n description: source.rationale ?? source.claim,\n },\n ],\n {\n analystId,\n producedAt: source.produced_at,\n confidence: source.confidence,\n },\n )\n if (!adapted) throw new Error('AgentRx output adapter produced no root-cause finding')\n return [\n {\n ...adapted,\n metadata: {\n ...adapted.metadata,\n sourceFindingId: source.finding_id,\n },\n },\n ]\n}\n\nconst CODE_TRACE_BLOCK_SUBJECT =\n /^incorrect-steps-(\\d+)-(\\d+)-(escaped|unescaped)-consequence-(\\d+)$/\n\nasync function adaptCodeTraceFindings(\n trajectoryId: string,\n findings: readonly AnalystFinding[],\n analystId: string,\n store: TraceAnalysisStore,\n signal?: AbortSignal,\n): Promise<{\n findings: AnalystFinding[]\n diagnostics: CodeTraceBlockDiagnostics\n stepBlocks: CodeTraceStepAssignment[]\n}> {\n const clean = findings.filter((finding) => finding.subject === 'clean')\n if (clean.length > 0) {\n if (findings.length !== 1) {\n throw new Error('CodeTraceBench model analyst mixed a clean verdict with incorrect steps')\n }\n exactFindingSteps(trajectoryId, clean[0]!)\n return {\n findings: [],\n diagnostics: emptyCodeTraceBlockDiagnostics(),\n stepBlocks: [],\n }\n }\n // Each finding is model output. One whose subject is unparseable, whose\n // citations all fall outside its own block, or whose evidence does not\n // resolve is dropped with a recorded reason — the rest of a completed, paid\n // investigation must survive it. Citations and excerpts are checked here\n // because expansion replaces them with runner-built evidence.\n const blocks: CodeTraceFailureBlock[] = []\n const rejectedFindings: string[] = []\n const trimmedCitations: string[] = []\n for (const source of findings) {\n try {\n await validateCodeTraceFindingEvidence({\n trajectoryId,\n findings: [source],\n store,\n ...(signal ? { signal } : {}),\n })\n const converted = codeTraceBlockFromFinding(trajectoryId, source)\n trimmedCitations.push(...converted.trimmedCitations)\n blocks.push(converted.block)\n } catch (error) {\n rejectedFindings.push(\n `${source.finding_id}: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n const expanded = await expandCodeTraceFailureBlocks({\n trajectoryId,\n blocks,\n store,\n analystId,\n ...(findings[0] ? { producedAt: findings[0].produced_at } : {}),\n ...(signal ? { signal } : {}),\n })\n return {\n findings: expanded.findings,\n diagnostics: { ...expanded.diagnostics, rejectedFindings, trimmedCitations },\n stepBlocks: expanded.stepBlocks,\n }\n}\n\n/**\n * Block coordinates recoverable from a subject in the block grammar, in the\n * metadata field names the expanded findings carry. Returns undefined when the\n * subject does not parse — nothing is invented for a malformed subject.\n */\nexport function codeTraceBlockMetadataFromSubject(\n subject: string | undefined,\n): Record<string, unknown> | undefined {\n const parsed = CODE_TRACE_BLOCK_SUBJECT.exec(subject ?? '')\n if (!parsed) return undefined\n return {\n block_first_step: Number(parsed[1]),\n block_last_step: Number(parsed[2]),\n block_consequence_step: Number(parsed[4]),\n escape_status: parsed[3],\n }\n}\n\nfunction codeTraceBlockFromFinding(\n trajectoryId: string,\n source: AnalystFinding,\n): { block: CodeTraceFailureBlock; trimmedCitations: string[] } {\n const parsed = CODE_TRACE_BLOCK_SUBJECT.exec(source.subject ?? '')\n if (!parsed) {\n throw new Error(\n `CodeTraceBench model finding '${source.finding_id}' must set subject to incorrect-steps-<first>-<last>-<escaped|unescaped>-consequence-<step>, received '${source.subject ?? ''}'`,\n )\n }\n const firstStep = Number(parsed[1])\n const lastStep = Number(parsed[2])\n const consequenceStep = Number(parsed[4])\n const cited = exactFindingSteps(trajectoryId, source)\n // A citation outside [firstStep, lastStep] (typically the consequence step)\n // is trimmed, not fatal: expansion rebuilds per-step evidence, so the block\n // only needs one citation grounding it inside its own range. A finding whose\n // citations ALL fall outside its block has no in-block grounding and is\n // rejected.\n const outOfRange = cited.filter((step) => step < firstStep || step > lastStep)\n if (outOfRange.length === cited.length) {\n throw new Error(\n `CodeTraceBench model finding '${source.finding_id}' cites step ${outOfRange.join(', ')} outside its block ${firstStep}-${lastStep} and no citation falls inside the block`,\n )\n }\n const trimmedCitations = outOfRange.map(\n (step) =>\n `${source.finding_id}: trimmed citation step ${step} outside block ${firstStep}-${lastStep}`,\n )\n return {\n block: {\n firstStep,\n lastStep,\n consequenceStep,\n escapeStatus: parsed[3] as 'escaped' | 'unescaped',\n severity: source.severity,\n claim: source.claim,\n confidence: source.confidence,\n ...(source.rationale === undefined ? {} : { rationale: source.rationale }),\n ...(source.recommended_action === undefined\n ? {}\n : { recommendedAction: source.recommended_action }),\n metadata: { sourceFindingId: source.finding_id },\n },\n trimmedCitations,\n }\n}\n\n/**\n * Expand contiguous failure blocks into one scored finding per member step.\n *\n * The official scorer matches on area plus the exact step evidence URI, so\n * blocks never reach it: every runner reports blocks, and this function turns\n * them into the per-step findings the benchmark defines.\n */\nexport async function expandCodeTraceFailureBlocks(options: {\n trajectoryId: string\n blocks: readonly CodeTraceFailureBlock[]\n store: TraceAnalysisStore\n analystId: string\n producedAt?: string\n signal?: AbortSignal\n}): Promise<{\n findings: AnalystFinding[]\n diagnostics: CodeTraceBlockDiagnostics\n stepBlocks: CodeTraceStepAssignment[]\n}> {\n const diagnostics = emptyCodeTraceBlockDiagnostics()\n diagnostics.reportedBlocks = options.blocks.length\n if (options.blocks.length === 0) return { findings: [], diagnostics, stepBlocks: [] }\n const blocks = acceptCodeTraceBlockShape(options.blocks, diagnostics)\n if (blocks.length === 0) return { findings: [], diagnostics, stepBlocks: [] }\n\n const boundarySteps = blocks.flatMap((block) => [block.firstStep, block.lastStep])\n const derivedSteps = blocks.flatMap((block) => [block.consequenceStep, ...interiorSteps(block)])\n const evidenceByStep = await resolveAssistantStepEvidence({\n trajectoryId: options.trajectoryId,\n steps: boundarySteps,\n optionalSteps: derivedSteps,\n store: options.store,\n ...(options.signal ? { signal: options.signal } : {}),\n })\n\n const byStep = new Map<number, CodeTraceFailureBlock>()\n for (const block of blocks) {\n if (!evidenceByStep.has(block.consequenceStep)) {\n diagnostics.blocksWithoutConsequenceEvidence.push(block)\n continue\n }\n if (block.escapeStatus === 'escaped') diagnostics.escapedBlocks += 1\n for (let step = block.firstStep; step <= block.lastStep; step += 1) {\n if (!evidenceByStep.has(step)) {\n diagnostics.unresolvedBlockInteriorSteps.push(step)\n continue\n }\n if (byStep.has(step)) {\n diagnostics.overlappingBlockSteps.push(step)\n continue\n }\n byStep.set(step, block)\n }\n }\n\n const stepBlocks = [...byStep]\n .sort(([left], [right]) => left - right)\n .map(([step, block]) => ({ step, block }))\n const findings = stepBlocks.map(({ step, block }) =>\n makeFinding({\n analyst_id: options.analystId,\n area: 'incorrect',\n subject: `incorrect-step-${step}`,\n claim: `Step ${step} is incorrect. ${block.claim}`,\n rationale: block.rationale,\n severity: block.severity,\n confidence: block.confidence,\n evidence_refs: [evidenceByStep.get(step)!],\n recommended_action: block.recommendedAction,\n metadata: {\n ...block.metadata,\n block_first_step: block.firstStep,\n block_last_step: block.lastStep,\n block_consequence_step: block.consequenceStep,\n escape_status: block.escapeStatus,\n },\n ...(options.producedAt === undefined ? {} : { produced_at: options.producedAt }),\n id_basis: `incorrect-step-${step}`,\n }),\n )\n return { findings, diagnostics, stepBlocks }\n}\n\n/**\n * Enforce the protocol's per-block and per-case limits without voiding the\n * case: an offending block is dropped and named in `diagnostics.droppedBlocks`\n * while every valid sibling survives. A case whose blocks are ALL invalid ends\n * empty and carries the diagnostic for each drop. Shape is checked before the\n * count, so a malformed block never consumes one of the accepted slots.\n */\nfunction acceptCodeTraceBlockShape(\n blocks: readonly CodeTraceFailureBlock[],\n diagnostics: CodeTraceBlockDiagnostics,\n): CodeTraceFailureBlock[] {\n const accepted: CodeTraceFailureBlock[] = []\n for (const block of blocks) {\n const reason =\n codeTraceBlockShapeViolation(block) ??\n (accepted.length >= MAX_INCORRECT_BLOCKS\n ? `model reported ${blocks.length} failure blocks; the maximum is ${MAX_INCORRECT_BLOCKS}`\n : undefined)\n if (reason) {\n diagnostics.droppedBlocks.push(\n `block ${block.firstStep}-${block.lastStep} (consequence ${block.consequenceStep}): ${reason}`,\n )\n continue\n }\n accepted.push(block)\n }\n return accepted\n}\n\nfunction codeTraceBlockShapeViolation(block: CodeTraceFailureBlock): string | undefined {\n if (block.lastStep < block.firstStep) {\n return `failure block last_step ${block.lastStep} precedes first_step ${block.firstStep}`\n }\n const length = block.lastStep - block.firstStep + 1\n if (length > MAX_INCORRECT_BLOCK_STEPS) {\n return `failure block spans ${length} steps; the maximum is ${MAX_INCORRECT_BLOCK_STEPS}`\n }\n if (block.consequenceStep < block.firstStep) {\n return `failure block consequence_step ${block.consequenceStep} precedes first_step ${block.firstStep}`\n }\n return undefined\n}\n\nfunction interiorSteps(block: CodeTraceFailureBlock): number[] {\n const steps: number[] = []\n for (let step = block.firstStep + 1; step < block.lastStep; step += 1) steps.push(step)\n return steps\n}\n\nfunction emptyCodeTraceBlockDiagnostics(): CodeTraceBlockDiagnostics {\n return {\n reportedBlocks: 0,\n escapedBlocks: 0,\n blocksWithoutConsequenceEvidence: [],\n unresolvedBlockInteriorSteps: [],\n overlappingBlockSteps: [],\n droppedBlocks: [],\n }\n}\n\nfunction exactFindingSteps(trajectoryId: string, finding: AnalystFinding): number[] {\n if (finding.evidence_refs.length === 0) {\n throw new Error(`model finding '${finding.finding_id}' has no step evidence`)\n }\n const steps = finding.evidence_refs.map((evidence) => {\n const parsed = codeTraceStepFromEvidence(evidence.uri)\n if (!parsed || parsed.traceId !== trajectoryId) {\n throw new Error(\n `model finding '${finding.finding_id}' cites non-case evidence '${evidence.uri}'`,\n )\n }\n return parsed.step\n })\n return [...new Set(steps)]\n}\n","import { z } from 'zod'\nimport {\n CostAccountingIncompleteError,\n CostCeilingReachedError,\n CostReservationExceededError,\n} from '../cost-ledger'\nimport { AgentEvalError } from '../errors'\nimport { LlmCallError, LlmResponseError } from '../llm-client'\nimport type { AnalystBenchmarkError } from './benchmark'\n\nexport function publicBenchmarkError(\n error: unknown,\n secrets: readonly string[] = [],\n): AnalystBenchmarkError {\n if (error instanceof LlmCallError) {\n return {\n class: 'LlmCallError',\n code: error.code,\n status: error.status,\n message: `Provider request failed with HTTP ${error.status}.`,\n }\n }\n if (error instanceof LlmResponseError) {\n return {\n class: 'LlmResponseError',\n code: error.code,\n message: 'Provider response did not satisfy the structured output contract.',\n }\n }\n if (error instanceof z.ZodError) {\n return {\n class: 'ModelOutputValidationError',\n message: 'Provider response did not match the benchmark output schema.',\n }\n }\n if (error instanceof SyntaxError) {\n return {\n class: 'ModelOutputParseError',\n message: 'Provider response was not valid JSON.',\n }\n }\n if (\n error instanceof CostCeilingReachedError ||\n error instanceof CostAccountingIncompleteError ||\n error instanceof CostReservationExceededError\n ) {\n return {\n class: error.constructor.name,\n code: error.code,\n message: redactSensitiveText(error.message, secrets),\n }\n }\n if (error instanceof Error && error.name === 'AbortError') {\n return {\n class: 'ProviderTimeoutError',\n message: 'Provider request timed out.',\n }\n }\n if (\n error instanceof Error &&\n /(?:assistant steps?|finding evidence|selected missing|selected unavailable|no readable spans|requires a trace store)/i.test(\n error.message,\n )\n ) {\n return {\n class: 'BenchmarkEvidenceError',\n message: redactSensitiveText(error.message, secrets),\n }\n }\n if (error instanceof AgentEvalError) {\n return {\n class: error.constructor.name,\n code: error.code,\n message: redactSensitiveText(error.message, secrets),\n }\n }\n if (error instanceof Error) {\n return {\n class: error.constructor.name || 'Error',\n message: redactSensitiveText(error.message, secrets),\n }\n }\n return {\n class: 'Error',\n message: 'Benchmark analyst execution failed.',\n }\n}\n\nfunction redactSensitiveText(value: string, secrets: readonly string[]): string {\n let redacted = value\n for (const secret of secrets) {\n if (secret) redacted = redacted.replaceAll(secret, '[REDACTED]')\n }\n redacted = redacted\n .replace(/\\bBearer\\s+[^\\s\"',;]+/gi, 'Bearer [REDACTED]')\n .replace(\n /\\b(api[_-]?key|access[_-]?token|refresh[_-]?token|password|secret)\\b\\s*[:=]\\s*[^\\s\"',;]+/gi,\n '$1=[REDACTED]',\n )\n if (redacted.length <= 500) return redacted\n const head = redacted.slice(0, 180)\n const omitted = redacted.length - 460\n const marker = `...[${omitted} chars omitted]...`\n return `${head}${marker}${redacted.slice(-(500 - head.length - marker.length))}`\n}\n","import type {\n ExternalOptimizerModelCall,\n ExternalOptimizerModelExecutionObservation,\n ExternalOptimizerRunnerCommand,\n} from '../campaign/external-optimizer-contracts'\nimport type { CostLedgerHandle, CustomTokenPricing } from '../cost-ledger'\nimport type { AnalystBenchmarkCase } from './benchmark'\nimport type { VerificationArtifactManifest } from './benchmark-verification-artifacts'\nimport type { AnalystRunInputs } from './types'\n\nexport type PublicAnalystBenchmarkDataset = 'agentrx' | 'codetracebench'\n\n/**\n * Caller-supplied replacement for the recursive runner's analyst instructions.\n * Only the `dspy-rlm` runner accepts one; the direct runner rejects it, and the\n * recursive runner's abstention fallback keeps the stock direct prompt. Every\n * recorded protocol digest for an override run binds the stock protocol digest\n * to `sha256`, so an override run is never confusable with a stock run.\n */\nexport interface AnalystInstructionsOverride {\n /** Complete instruction text used instead of the shipped RLM instructions. */\n readonly text: string\n /** SHA-256 hex digest of `text`. */\n readonly sha256: string\n}\n\n/** Model execution supplied by the package that owns credentials and provider policy. */\nexport interface PublicAnalystBenchmarkModelOwner {\n call: ExternalOptimizerModelCall\n callRef: string\n recordExecution: (observation: ExternalOptimizerModelExecutionObservation) => void\n /** Exact rates when the selected model is absent from Agent Eval's catalog. */\n pricing?: CustomTokenPricing\n}\n\nexport interface PublicAnalystBenchmarkModelConfig {\n /** Caller-owned execution path. Agent Eval never receives provider credentials. */\n call: ExternalOptimizerModelCall\n /** Stable public identity for the caller-owned execution path. */\n callRef: string\n /** Persist every finite execution record returned by the caller-owned path. */\n recordExecution: (observation: ExternalOptimizerModelExecutionObservation) => void\n model: string\n maxOutputTokens: number\n timeoutMs: number\n /** Model request bytes per call. Default: 16 MiB. */\n maxModelRequestBytes?: number\n /** Model response bytes per call. Default: 4 MiB. */\n maxModelResponseBytes?: number\n /** Reasoning tokens billed beyond completion tokens. Default: four times output. */\n maxReasoningTokens?: number\n /** Deadline for one caller-owned model invocation. Default: timeoutMs. */\n modelRequestTimeoutMs?: number\n /** Required when the model is absent from agent-eval's pricing table. */\n pricing?: CustomTokenPricing\n /** Independent per-case recursive-engine spend limit. Default: 1 USD. */\n maxCostUsdPerAnalysis?: number\n /** Replaces the shipped RLM instructions. `dspy-rlm` runner only. */\n instructionsOverride?: AnalystInstructionsOverride\n dspyRlm?: {\n runner?: ExternalOptimizerRunnerCommand\n maxIterations?: number\n maxLlmCalls?: number\n maxToolCalls?: number\n maxOutputChars?: number\n maxModelRequests?: number\n traceToolRequestBytes?: number\n traceToolResponseBytes?: number\n traceToolTimeoutMs?: number\n /**\n * Independent engine runs per case. Above 1 (CodeTraceBench only), the\n * runner scores the step-level majority consensus across all runs instead\n * of a single draw. Default: 1.\n */\n samples?: number\n }\n costLedger?: CostLedgerHandle\n durability?: {\n runIdentitySha256: string\n responseCacheDir: string\n }\n}\n\n/**\n * Model settings the benchmark command records in the run identity. The\n * owner-call pair is present exactly when a model-owner module executes the\n * provider calls (`dspy-rlm` and `direct`); the `prime` analyst owns its own\n * cli-bridge transport and never receives an owner call path.\n */\nexport type PublicAnalystBenchmarkModelSettings = Omit<\n PublicAnalystBenchmarkModelConfig,\n 'call' | 'recordExecution'\n> &\n Partial<Pick<PublicAnalystBenchmarkModelConfig, 'call' | 'recordExecution'>>\n\nexport interface PreparedPublicAnalystBenchmark {\n cases: AnalystBenchmarkCase<AnalystRunInputs>[]\n sourceRowCount: number\n selectedCaseIds: string[]\n labelsSha256: string\n traceFiles: Array<{\n traceId: string\n relativePath: string\n sha256: string\n }>\n verificationArtifacts: VerificationArtifactManifest[]\n selection: PublicBenchmarkSelectionReport\n}\n\nexport interface PublicBenchmarkValueDistribution {\n total: number\n missing: number\n counts: Record<string, number>\n}\n\nexport interface PublicBenchmarkDistributions {\n class: PublicBenchmarkValueDistribution\n agent: PublicBenchmarkValueDistribution\n model: PublicBenchmarkValueDistribution\n difficulty: PublicBenchmarkValueDistribution\n solved: PublicBenchmarkValueDistribution\n}\n\nexport interface PublicBenchmarkSelectionReport {\n method: 'census' | 'deterministic-hash'\n seed: number\n sourceCount: number\n selectedCount: number\n stratified: false\n representativeOfInput: boolean\n source: PublicBenchmarkDistributions\n selected: PublicBenchmarkDistributions\n}\n\nexport function requiredString(value: string, field: string): string {\n const trimmed = value.trim()\n if (!trimmed) throw new TypeError(`${field} must be a non-empty string`)\n return trimmed\n}\n\nexport function positiveSafeInteger(value: number, field: string): number {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new RangeError(`${field} must be a positive safe integer`)\n }\n return value\n}\n\nexport function safeInteger(value: number, field: string): number {\n if (!Number.isSafeInteger(value)) throw new RangeError(`${field} must be a safe integer`)\n return value\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n","import { existsSync, lstatSync, readFileSync } from 'node:fs'\nimport * as nodePath from 'node:path'\nimport { z } from 'zod'\nimport type { CostReceiptInput } from '../cost-ledger'\nimport { ValidationError } from '../errors'\nimport {\n canonicalString,\n hashCanonical,\n withLedgerFileLock,\n writeLedgerFileAtomically,\n} from '../ledger-core'\nimport type { AnalystBenchmarkError } from './benchmark'\n\nconst SHA256 = /^[a-f0-9]{64}$/\n\nconst CostReceiptInputSchema = z\n .object({\n model: z.string().min(1),\n inputTokens: z.number().int().nonnegative(),\n outputTokens: z.number().int().nonnegative(),\n reasoningTokens: z.number().int().nonnegative().optional(),\n cachedTokens: z.number().int().nonnegative().optional(),\n cacheWriteTokens: z.number().int().nonnegative().optional(),\n customTokenPricing: z\n .object({\n inputUsdPerMillion: z.number().nonnegative(),\n cachedInputUsdPerMillion: z.number().nonnegative().optional(),\n cacheWriteUsdPerMillion: z.number().nonnegative().optional(),\n outputUsdPerMillion: z.number().nonnegative(),\n })\n .strict()\n .optional(),\n actualCostUsd: z.number().nonnegative().optional(),\n estimatedCostUsd: z.number().nonnegative().optional(),\n costUnknown: z.boolean().optional(),\n usageUnknown: z.boolean().optional(),\n })\n .strict()\n\nconst BenchmarkErrorSchema = z\n .object({\n class: z.string().min(1),\n message: z.string(),\n code: z.string().min(1).optional(),\n status: z.number().int().min(100).max(599).optional(),\n })\n .strict()\n\nconst ResponseMetadataSchema = z\n .object({\n providerModel: z.string().min(1),\n providerDurationMs: z.number().nonnegative(),\n finishReason: z.string().nullable(),\n producedAt: z.string().datetime(),\n })\n .strict()\n\nconst CacheIdentityShape = {\n kind: z.literal('agent-eval/public-benchmark-model-response'),\n callId: z.string().min(1),\n runIdentitySha256: z.string().regex(SHA256),\n caseId: z.string().min(1),\n repetition: z.number().int().nonnegative(),\n}\n\nconst SuccessCacheEntryWithoutDigestSchema = z\n .object({\n ...CacheIdentityShape,\n status: z.literal('succeeded'),\n response: z.json(),\n metadata: ResponseMetadataSchema,\n receipt: CostReceiptInputSchema,\n })\n .strict()\n\nconst FailureCacheEntryWithoutDigestSchema = z\n .object({\n ...CacheIdentityShape,\n status: z.literal('failed'),\n error: BenchmarkErrorSchema,\n receipt: CostReceiptInputSchema,\n })\n .strict()\n\nconst CacheEntryWithoutDigestSchema = z.discriminatedUnion('status', [\n SuccessCacheEntryWithoutDigestSchema,\n FailureCacheEntryWithoutDigestSchema,\n])\n\nconst CacheEntrySchema = z.discriminatedUnion('status', [\n SuccessCacheEntryWithoutDigestSchema.extend({\n entrySha256: z.string().regex(SHA256),\n }),\n FailureCacheEntryWithoutDigestSchema.extend({\n entrySha256: z.string().regex(SHA256),\n }),\n])\n\ninterface CacheIdentity {\n runIdentitySha256: string\n caseId: string\n repetition: number\n}\n\nexport interface PublicBenchmarkResponseMetadata {\n providerModel: string\n providerDurationMs: number\n finishReason: string | null\n producedAt: string\n}\n\nexport type PublicBenchmarkResponseCacheEntry =\n | (CacheIdentity & {\n kind: 'agent-eval/public-benchmark-model-response'\n callId: string\n status: 'succeeded'\n response: unknown\n metadata: PublicBenchmarkResponseMetadata\n receipt: CostReceiptInput\n entrySha256: string\n })\n | (CacheIdentity & {\n kind: 'agent-eval/public-benchmark-model-response'\n callId: string\n status: 'failed'\n error: AnalystBenchmarkError\n receipt: CostReceiptInput\n entrySha256: string\n })\n\nexport type PublicBenchmarkResponseCacheInput =\n | Omit<Extract<PublicBenchmarkResponseCacheEntry, { status: 'succeeded' }>, 'entrySha256'>\n | Omit<Extract<PublicBenchmarkResponseCacheEntry, { status: 'failed' }>, 'entrySha256'>\n\nexport function publicBenchmarkCallId(identity: CacheIdentity): string {\n assertCacheIdentity(identity)\n const boundIdentity: CacheIdentity = {\n runIdentitySha256: identity.runIdentitySha256,\n caseId: identity.caseId,\n repetition: identity.repetition,\n }\n return `analyst-benchmark-${hashCanonical(boundIdentity).slice('sha256:'.length)}`\n}\n\nexport function readPublicBenchmarkResponseCache(\n cacheDirectory: string,\n identity: CacheIdentity,\n): PublicBenchmarkResponseCacheEntry | undefined {\n const callId = publicBenchmarkCallId(identity)\n const path = responseCachePath(cacheDirectory, callId)\n if (!existsSync(path)) return undefined\n const metadata = lstatSync(path)\n if (!metadata.isFile() || metadata.isSymbolicLink()) {\n throw new ValidationError(`benchmark response cache must be a real file: ${path}`)\n }\n let parsed: unknown\n try {\n parsed = JSON.parse(readFileSync(path, 'utf8'))\n } catch (error) {\n throw new ValidationError(`benchmark response cache contains invalid JSON: ${path}`, {\n cause: error,\n })\n }\n const entry = parseCacheEntry(parsed, path)\n if (\n entry.callId !== callId ||\n entry.runIdentitySha256 !== identity.runIdentitySha256 ||\n entry.caseId !== identity.caseId ||\n entry.repetition !== identity.repetition\n ) {\n throw new ValidationError(`benchmark response cache identity does not match: ${path}`)\n }\n return entry\n}\n\nexport function writePublicBenchmarkResponseCache(\n cacheDirectory: string,\n entry: PublicBenchmarkResponseCacheInput,\n): PublicBenchmarkResponseCacheEntry {\n const expectedCallId = publicBenchmarkCallId(entry)\n if (entry.callId !== expectedCallId) {\n throw new ValidationError('benchmark response cache callId does not match its identity')\n }\n const validated = JSON.parse(\n JSON.stringify(CacheEntryWithoutDigestSchema.parse(entry)),\n ) as z.infer<typeof CacheEntryWithoutDigestSchema>\n const complete = {\n ...validated,\n entrySha256: hashCanonical(validated).slice('sha256:'.length),\n } as PublicBenchmarkResponseCacheEntry\n const path = responseCachePath(cacheDirectory, complete.callId)\n const content = `${canonicalString(complete)}\\n`\n withLedgerFileLock(path, fileContext(), () => {\n if (existsSync(path)) {\n const existing = readPublicBenchmarkResponseCache(cacheDirectory, complete)\n if (!existing || canonicalString(existing) !== canonicalString(complete)) {\n throw new ValidationError(`benchmark response cache conflicts with existing file: ${path}`)\n }\n return\n }\n writeLedgerFileAtomically(path, content, fileContext())\n })\n return complete\n}\n\nfunction parseCacheEntry(value: unknown, path: string): PublicBenchmarkResponseCacheEntry {\n let parsed: z.infer<typeof CacheEntrySchema>\n try {\n parsed = CacheEntrySchema.parse(value)\n } catch (error) {\n throw new ValidationError(`benchmark response cache has an invalid shape: ${path}`, {\n cause: error,\n })\n }\n const { entrySha256, ...withoutDigest } = parsed\n const expected = hashCanonical(withoutDigest).slice('sha256:'.length)\n if (entrySha256 !== expected) {\n throw new ValidationError(`benchmark response cache digest does not match: ${path}`)\n }\n return parsed as PublicBenchmarkResponseCacheEntry\n}\n\nfunction responseCachePath(cacheDirectory: string, callId: string): string {\n const directory = nodePath.resolve(cacheDirectory)\n const path = nodePath.resolve(directory, `${hashCanonical(callId).slice('sha256:'.length)}.json`)\n if (!isPathInsideDirectory(directory, path, nodePath)) {\n throw new ValidationError('benchmark response cache path escapes its directory')\n }\n return path\n}\n\ninterface PathOperations {\n relative(from: string, to: string): string\n isAbsolute(path: string): boolean\n sep: string\n}\n\nexport function isPathInsideDirectory(\n directory: string,\n candidate: string,\n pathOperations: PathOperations = nodePath,\n): boolean {\n const relative = pathOperations.relative(directory, candidate)\n return (\n relative !== '' &&\n relative !== '..' &&\n !relative.startsWith(`..${pathOperations.sep}`) &&\n !pathOperations.isAbsolute(relative)\n )\n}\n\nfunction assertCacheIdentity(identity: CacheIdentity): void {\n if (!SHA256.test(identity.runIdentitySha256)) {\n throw new ValidationError('benchmark response cache requires a SHA-256 run identity')\n }\n if (!identity.caseId.trim()) {\n throw new ValidationError('benchmark response cache requires a case id')\n }\n if (!Number.isSafeInteger(identity.repetition) || identity.repetition < 0) {\n throw new ValidationError('benchmark response cache repetition must be non-negative')\n }\n}\n\nfunction fileContext() {\n return {\n subject: 'benchmark response cache',\n integrityError: (message: string, options?: { cause?: unknown }) =>\n new ValidationError(message, options),\n }\n}\n","/**\n * AnalystDefinition — the declarative unit behind an analyst arm.\n *\n * An arm is one way of EXECUTING an analysis question: a one-shot JSON call, a\n * bridge-reached RLM, a recursive engine with trace tools. What the arm SAYS —\n * the question, the task text, the reply grammar, how evidence reaches the\n * model, the repair-turn and budget terms — is protocol, not execution, so it\n * lives here as one inspectable value. `bindAnalyst` (./bind) compiles a\n * definition plus a transport binding into a runnable arm, and the parity\n * suite holds the compiled arm to the byte against the arm's entry point, so a\n * definition cannot drift from what its arm actually sends.\n *\n * Three rules carried over from the repair-arm comparison contract\n * (trace-repair's `repairArmAsymmetries`), made structural here:\n *\n * one contract the reply grammar is a `ReplyContract` value on the\n * definition, never prose inside a runner body.\n * one repair turn `analystDefinitionAsymmetries` refuses a set whose\n * definitions declare unequal repair turns, because a second\n * attempt is a second sample the other arms never got.\n * declared difference what arms MAY differ in — the evidence projection, the\n * reasoning effort, the budget — is declared per definition\n * and rendered beside the comparison instead of being\n * inferred from two runners' source.\n */\n\nimport { createHash } from 'node:crypto'\nimport type { AgentProfile } from '../agent-profile'\nimport type { TraceAnalysisStore } from '../trace-analyst/store'\nimport type { TraceAnalystSpan } from '../trace-analyst/types'\nimport type { AnalystBenchmarkRunner } from './benchmark'\nimport type { PublicAnalystBenchmarkModelConfig } from './benchmark-public-types'\nimport type { TraceAnalystLimits } from './engine'\nimport { assertEqualDeclarativeTerms } from './equal-terms'\nimport { primeProtocolSha256 } from './prime-protocol'\nimport type { ReplyContract } from './reply-contract'\nimport type { TraceToolGroupName } from './tool-groups'\nimport type { AnalystFinding, AnalystRunInputs } from './types'\n\n// ── Profile fragment ────────────────────────────────────────────────\n\n/**\n * The slice of the canonical `AgentProfile` an analyst definition carries:\n * model hints (pinned model, reasoning effort) and prompt shaping. Transport\n * bindings that own model selection leave `model.default` unset.\n */\nexport type AnalystProfileFragment = Pick<AgentProfile, 'model' | 'prompt'>\n\n// ── Evidence projection ─────────────────────────────────────────────\n\n/**\n * How evidence reaches the model. This is the declared affordance axis of an\n * arm: two arms answering the same question through different projections are\n * comparable only with the difference rendered, never silently.\n */\nexport type EvidenceProjection =\n | {\n readonly mode: 'inline'\n /** Ceiling on serialized evidence characters embedded in one prompt. */\n readonly maxInlineChars: number\n /**\n * Per-attribute byte cap for the reduced refetch when the full\n * projection is oversized. Still oversized after the refetch = refusal,\n * never a silent truncation.\n */\n readonly cappedAttributeBytes: number\n }\n | {\n readonly mode: 'chunked'\n /** Descending per-attribute byte caps tried until the store yields a projection. */\n readonly attributeByteCaps: readonly number[]\n }\n | {\n /** Evidence bound as an engine REPL variable, read through bounded trace tools. */\n readonly mode: 'repl-variable'\n readonly toolGroup: TraceToolGroupName\n }\n | {\n /** Evidence read through agent tool calls only; no REPL. */\n readonly mode: 'agent-tools'\n readonly toolGroup: TraceToolGroupName\n }\n\n// ── Budget and repair declarations ──────────────────────────────────\n\nexport interface AnalystBudgetDeclaration {\n /** Deadline for one model exchange. */\n readonly timeoutMs: number\n /** Provider spend ceiling for one analysis, when the transport meters cost. */\n readonly maxCostUsd?: number\n /** Completion-token cap per model call, when the transport enforces one. */\n readonly maxOutputTokens?: number\n /** Recursive-engine iteration limits (repl-variable / agent-tools projections). */\n readonly engineLimits?: TraceAnalystLimits\n}\n\nexport interface AnalystRepairDeclaration {\n /**\n * Bounded retries a structurally malformed reply earns. Compared definitions\n * must declare the same number: a retry is a second sample.\n */\n readonly turns: number\n}\n\n// ── Evidence bindings (typed ports per projection) ──────────────────\n\nexport interface AnalystRowExpansion {\n findings: AnalystFinding[]\n /** Arm-specific expansion diagnostics recorded in observation metadata. */\n diagnostics?: unknown\n}\n\nexport interface ExpandRowsArgs<TRow> {\n /** Evidence subject the case names (e.g. a trajectory id). */\n subject: string\n rows: readonly TRow[]\n store: TraceAnalysisStore\n analystId: string\n producedAt?: string\n /** Model the provider reported serving, when the transport captures it. */\n providerModel?: string\n signal?: AbortSignal\n}\n\n/** Ports an inline-projection arm binds: prompt framing plus row expansion. */\nexport interface InlineEvidenceBinding<TRow> {\n readonly kind: 'inline'\n subjectFromCaseId(caseId: string): string\n /** Base observation metadata (analysis mode, engine label). */\n readonly baseMetadata: Readonly<Record<string, unknown>>\n /**\n * Line introducing the inlined evidence. Throws when the projected spans\n * cannot ground the question (e.g. no assistant step spans).\n */\n header(subject: string, spans: readonly TraceAnalystSpan[]): string\n /** Material appended after the evidence. */\n trailer(subject: string, spans: readonly TraceAnalystSpan[]): string\n expandRows(args: ExpandRowsArgs<TRow>): Promise<AnalystRowExpansion>\n}\n\n/** Ports a chunked-projection one-shot arm binds. */\nexport interface ChunkedEvidenceBinding<TRow> {\n readonly kind: 'chunked'\n subjectFromCaseId(caseId: string): string\n readonly baseMetadata: Readonly<Record<string, unknown>>\n /** Actor name paid calls are attributed to in the cost ledger. */\n readonly costActor: string\n /** Cost-ledger phase paid calls settle under. */\n readonly costPhase: string\n /** Compose the user message around the rendered evidence. */\n userMessage(rendered: string): string\n expandRows(args: ExpandRowsArgs<TRow>): Promise<AnalystRowExpansion>\n /** Ground accepted findings against the store; throws on unresolvable evidence. */\n verifyFindings?(args: {\n subject: string\n findings: readonly AnalystFinding[]\n store: TraceAnalysisStore\n signal?: AbortSignal\n }): Promise<void>\n}\n\n/** Majority-vote ports for a multi-sample repl-variable arm. */\nexport interface ReplVariableConsensusPort<TAssignment, TBlock> {\n /** Vote across per-sample assignments; returns voted blocks plus the decision record. */\n vote(samples: ReadonlyArray<readonly TAssignment[]>): {\n blocks: readonly TBlock[]\n decision: unknown\n }\n /** Expand voted blocks into findings grounded in the store. */\n expand(args: {\n subject: string\n blocks: readonly TBlock[]\n store: TraceAnalysisStore\n analystId: string\n producedAt: string\n signal?: AbortSignal\n }): Promise<AnalystRowExpansion>\n /** Per-sample observation record (accepted blocks, member steps). */\n sampleRecord(assignments: readonly TAssignment[]): Record<string, unknown>\n}\n\n/** Ports a repl-variable (recursive engine) arm binds. */\nexport interface ReplVariableEvidenceBinding<TAssignment = unknown, TBlock = unknown> {\n readonly kind: 'repl-variable'\n /** Identity of the trace-analyst definition the engine runs. */\n readonly traceAnalystId: string\n subjectFromCaseId(caseId: string): string\n readonly baseMetadata: Readonly<Record<string, unknown>>\n /** Metadata stamped on every finding the arm emits. */\n readonly findingBaseMetadata: Readonly<Record<string, unknown>>\n /** Cost-ledger phase paid calls settle under. */\n readonly costPhase: string\n /** Row metadata derived from the finding's subject grammar. */\n metadataFromSubject?(subject: string | undefined): Record<string, unknown> | undefined\n /** Map raw engine rows into scored findings grounded in the store. */\n adapt(args: {\n subject: string\n findings: readonly AnalystFinding[]\n analystId: string\n store: TraceAnalysisStore\n signal?: AbortSignal\n }): Promise<{ findings: AnalystFinding[]; stepBlocks?: TAssignment[]; diagnostics?: unknown }>\n /** Multi-sample majority consensus; required when the arm runs samples > 1. */\n consensus?: ReplVariableConsensusPort<TAssignment, TBlock>\n /** Second-opinion arm invoked when the engine submits no finding at all. */\n abstentionFallback(\n config: PublicAnalystBenchmarkModelConfig,\n ): AnalystBenchmarkRunner<AnalystRunInputs>\n}\n\nexport type AnalystEvidenceBinding<TRow, TAssignment = unknown, TBlock = unknown> =\n | InlineEvidenceBinding<TRow>\n | ChunkedEvidenceBinding<TRow>\n | ReplVariableEvidenceBinding<TAssignment, TBlock>\n\n// ── The definition ──────────────────────────────────────────────────\n\nexport interface AnalystDefinition<TRow = unknown, TAssignment = unknown, TBlock = unknown> {\n /** Arm identity — appears as the runner id and in every finding. */\n readonly id: string\n readonly description: string\n readonly version: string\n /** Finding area the arm's expansion stamps, when uniform per arm. */\n readonly area?: string\n readonly profile: AnalystProfileFragment\n /** User-facing question. Empty when the task text is the whole ask. */\n readonly question: string\n /** Task definition / instruction text sent beside the question. */\n readonly taskDefinition?: string\n readonly projection: EvidenceProjection\n readonly replyContract: ReplyContract<TRow>\n /**\n * Numeric limits the contract states (row caps, width caps). They enter the\n * protocol digest; insertion order is digest-bearing because the digest\n * serializes with `JSON.stringify`.\n */\n readonly contractLimits: Readonly<Record<string, number>>\n readonly budget: AnalystBudgetDeclaration\n readonly repair: AnalystRepairDeclaration\n /**\n * Digest the bound arm stamps on observations. For an inline definition this\n * equals `analystDefinitionProtocolSha256`; benchmark arms that record a\n * shared dataset-level digest carry that digest here instead.\n */\n readonly protocolSha256: string\n readonly binding: AnalystEvidenceBinding<TRow, TAssignment, TBlock>\n}\n\n/**\n * Thrown at bind time when a definition asks for something no strategy can\n * compile — an unknown projection × transport pair, a repair-turn count the\n * exchange machinery cannot grant, a reasoning effort the arm cannot map. The\n * message names the construct so an expressiveness gap is a loud, attributable\n * failure instead of a silently narrowed protocol.\n */\nexport class AnalystExpressivenessError extends Error {}\n\n// ── Protocol identity ───────────────────────────────────────────────\n\n/**\n * Digest of everything a definition can send to its model. An inline\n * definition hashes under the historical prime-protocol domain, so its digest\n * equals the digest its bespoke arm always recorded; other projections hash\n * under the definition domain.\n */\nexport function analystDefinitionProtocolSha256<TRow, TAssignment, TBlock>(\n definition: AnalystDefinition<TRow, TAssignment, TBlock>,\n): string {\n const { projection, replyContract } = definition\n if (projection.mode === 'inline') {\n return primeProtocolSha256({\n question: definition.question,\n ...(definition.taskDefinition === undefined\n ? {}\n : { taskDefinition: definition.taskDefinition }),\n contractLines: replyContract.contractLines,\n repairContractLines: replyContract.repairContractLines,\n limits: {\n ...definition.contractLimits,\n maxInlineTrajectoryChars: projection.maxInlineChars,\n chunkedProjectionAttributeByteCap: projection.cappedAttributeBytes,\n },\n })\n }\n return createHash('sha256')\n .update(\n JSON.stringify({\n kind: 'analyst-definition-protocol',\n mode: projection.mode,\n question: definition.question,\n taskDefinition: definition.taskDefinition ?? null,\n contractLines: replyContract.contractLines,\n repairContractLines: replyContract.repairContractLines,\n limits: definition.contractLimits,\n projection:\n projection.mode === 'chunked'\n ? { attributeByteCaps: projection.attributeByteCaps }\n : { toolGroup: projection.toolGroup },\n }),\n )\n .digest('hex')\n}\n\n// ── Equal-terms comparison ──────────────────────────────────────────\n\n/** One definition's declared difference from the compared set. */\nexport interface AnalystDefinitionAsymmetry {\n readonly id: string\n readonly projectionMode: EvidenceProjection['mode']\n readonly reasoningEffort: NonNullable<AgentProfile['model']>['reasoningEffort'] | null\n readonly timeoutMs: number\n readonly maxCostUsd: number | null\n readonly maxOutputTokens: number | null\n /** The digest the arm records on observations. */\n readonly protocolSha256: string\n /** The definition's own protocol identity. */\n readonly definitionSha256: string\n}\n\nexport interface AnalystDefinitionAsymmetryReport {\n readonly ids: readonly string[]\n /** Repair turns every compared definition declares. */\n readonly repairTurns: number\n /** The one projection mode all definitions share, or null when they differ. */\n readonly sharedProjectionMode: EvidenceProjection['mode'] | null\n readonly asymmetries: readonly AnalystDefinitionAsymmetry[]\n}\n\n/**\n * Refuse a set of definitions that cannot be compared on equal terms, and\n * render what still differs between the ones that can. The hard rule is the\n * repair turn: a malformed reply must earn the same number of retries in every\n * arm, because a retry is a second sample. Projection, reasoning effort, and\n * budget differences are declared and reported, never hidden.\n */\nexport function analystDefinitionAsymmetries(\n definitions: ReadonlyArray<AnalystDefinition<unknown, unknown, unknown>>,\n): AnalystDefinitionAsymmetryReport {\n const { ids, repairTurns } = assertEqualDeclarativeTerms(\n 'analyst definition',\n definitions.map((definition) => ({ id: definition.id, repairTurns: definition.repair.turns })),\n )\n const firstMode = definitions[0]!.projection.mode\n const sharedProjectionMode = definitions.every(\n (definition) => definition.projection.mode === firstMode,\n )\n ? firstMode\n : null\n return {\n ids,\n repairTurns,\n sharedProjectionMode,\n asymmetries: definitions.map((definition) => ({\n id: definition.id,\n projectionMode: definition.projection.mode,\n reasoningEffort: definition.profile.model?.reasoningEffort ?? null,\n timeoutMs: definition.budget.timeoutMs,\n maxCostUsd: definition.budget.maxCostUsd ?? null,\n maxOutputTokens: definition.budget.maxOutputTokens ?? null,\n protocolSha256: definition.protocolSha256,\n definitionSha256: analystDefinitionProtocolSha256(definition),\n })),\n }\n}\n","import { randomUUID } from 'node:crypto'\nimport { z } from 'zod'\nimport {\n type ExternalOptimizerModelProxy,\n runWithCleanup,\n startExternalOptimizerModelProxy,\n} from '../campaign/external-optimizer-process'\nimport {\n CostAccountingIncompleteError,\n CostCallConflictError,\n CostCeilingReachedError,\n CostLedger,\n type CostLedgerHandle,\n CostLedgerPersistenceError,\n type CostReceipt,\n CostReceiptCaptureError,\n type CostReceiptInput,\n CostReservationExceededError,\n} from '../cost-ledger'\nimport { callLlmJson, type LlmCallRequest, type LlmClientOptions } from '../llm-client'\nimport { resolveModelPricing } from '../metrics'\nimport type { TraceAnalysisStore } from '../trace-analyst/store'\nimport type { AnalystBenchmarkRunner } from './benchmark'\nimport { agentRxPredictionsToFindings } from './benchmark-datasets'\nimport {\n resolveAssistantStepEvidence,\n validateCodeTraceFindingEvidence,\n} from './benchmark-evidence-validation'\nimport {\n type CodeTraceBlockDiagnostics,\n type CodeTraceFailureBlock,\n expandCodeTraceFailureBlocks,\n} from './benchmark-public-adapters'\nimport { publicBenchmarkError } from './benchmark-public-errors'\nimport {\n MAX_INCORRECT_BLOCK_STEPS,\n MAX_INCORRECT_BLOCKS,\n PUBLIC_BENCHMARK_ENVELOPE_CONTRACT,\n publicBenchmarkFieldContract,\n publicBenchmarkProtocolSha256,\n publicBenchmarkTaskPrompt,\n TRACE_PROJECTION_ATTRIBUTE_BYTE_CAPS,\n} from './benchmark-public-prompt'\nimport {\n type PublicAnalystBenchmarkDataset,\n type PublicAnalystBenchmarkModelConfig,\n positiveSafeInteger,\n requiredString,\n} from './benchmark-public-types'\nimport {\n type PublicBenchmarkResponseCacheEntry,\n publicBenchmarkCallId,\n readPublicBenchmarkResponseCache,\n writePublicBenchmarkResponseCache,\n} from './benchmark-response-cache'\nimport { type AnalystDefinition, AnalystExpressivenessError } from './definition'\nimport { decodeReplyRows, type ReplyContract } from './reply-contract'\nimport type { AnalystFinding, AnalystRunInputs } from './types'\nimport { usageReceiptFromCostLedger } from './usage-receipt'\n\nexport {\n CODE_TRACE_BENCH_ANALYST_PROMPT,\n publicBenchmarkProtocolSha256,\n} from './benchmark-public-prompt'\n\n/**\n * One-shot JSON baseline arm. Not a recursive trace analyst.\n *\n * The arm is expressed as an `AnalystDefinition`\n * (`publicDirectAnalystDefinition`): the task text, field and envelope\n * contracts, the descending projection ladder, and the zero-repair declaration\n * are definition content, and `createPublicBenchmarkDirectRunner` is a thin\n * shell that builds the definition and runs it through the chunked strategy\n * below — the same strategy `bindAnalyst` (./bind) dispatches to.\n */\n\nexport interface PublicDirectDefinitionArgs {\n /** Whole-analysis deadline (`config.timeoutMs`). */\n timeoutMs: number\n /** Completion-token cap per call (`config.maxOutputTokens`). */\n maxOutputTokens: number\n /** Per-case provider spend ceiling (`config.maxCostUsdPerAnalysis`). */\n maxCostUsd: number\n}\n\n/** The direct arm as a declarative unit for one public dataset. */\nexport function publicDirectAnalystDefinition(\n dataset: PublicAnalystBenchmarkDataset,\n args: PublicDirectDefinitionArgs,\n): AnalystDefinition<PublicBenchmarkModelPrediction> {\n const actor =\n dataset === 'agentrx' ? 'agentrx-root-cause-localizer' : 'codetracebench-step-localizer'\n const outputAdapter =\n dataset === 'agentrx' ? 'agentrx-taxonomy-and-root-step' : 'codetracebench-incorrect-block'\n return {\n id: 'direct',\n description: 'One-shot JSON baseline over the caller-owned model path.',\n version: '1.0.0',\n area: dataset === 'agentrx' ? 'root-cause' : 'incorrect',\n // One-shot JSON transport runs with thinking disabled.\n profile: { model: { reasoningEffort: 'none' } },\n // The task text is the whole ask: the one-shot prompt carries no question line.\n question: '',\n taskDefinition: publicBenchmarkTaskPrompt(dataset),\n projection: { mode: 'chunked', attributeByteCaps: TRACE_PROJECTION_ATTRIBUTE_BYTE_CAPS },\n replyContract: directReplyContract(dataset),\n contractLimits:\n dataset === 'agentrx'\n ? { maxFindings: 1 }\n : { maxBlocks: MAX_INCORRECT_BLOCKS, maxBlockSteps: MAX_INCORRECT_BLOCK_STEPS },\n budget: {\n timeoutMs: args.timeoutMs,\n maxCostUsd: args.maxCostUsd,\n maxOutputTokens: args.maxOutputTokens,\n },\n repair: { turns: 0 },\n protocolSha256: publicBenchmarkProtocolSha256(dataset),\n binding: {\n kind: 'chunked',\n subjectFromCaseId: (caseId) => trajectoryIdFromCaseId(dataset, caseId),\n baseMetadata: { analysisMode: 'direct-baseline', outputAdapter },\n costActor: actor,\n costPhase: 'analyst.public-benchmark',\n userMessage: (rendered) => `TRACE DATA:\\n${rendered}\\n\\nReturn the analysis JSON object.`,\n async expandRows({ subject, rows, store, analystId, producedAt, providerModel, signal }) {\n const converted = await publicBenchmarkPredictionsToFindings({\n dataset,\n trajectoryId: subject,\n predictions: rows,\n store,\n analystId,\n providerModel: requiredString(providerModel ?? '', 'finding providerModel'),\n producedAt: requiredString(producedAt ?? '', 'finding producedAt'),\n ...(signal ? { signal } : {}),\n })\n return { findings: converted.findings, diagnostics: converted.diagnostics }\n },\n ...(dataset === 'codetracebench'\n ? {\n verifyFindings: async (args: {\n subject: string\n findings: readonly AnalystFinding[]\n store: TraceAnalysisStore\n signal?: AbortSignal\n }) => {\n await validateCodeTraceFindingEvidence({\n trajectoryId: args.subject,\n findings: [...args.findings],\n store: args.store,\n ...(args.signal ? { signal: args.signal } : {}),\n })\n },\n }\n : {}),\n },\n }\n}\n\n/** Thin shell: validate config, declare the definition, run the chunked strategy. */\nexport function createPublicBenchmarkDirectRunner(\n dataset: PublicAnalystBenchmarkDataset,\n config: PublicAnalystBenchmarkModelConfig,\n): AnalystBenchmarkRunner<AnalystRunInputs> {\n if (config.instructionsOverride) {\n throw new Error(\n 'the direct runner executes only the stock protocol; an instructions override requires the dspy-rlm runner',\n )\n }\n const maxOutputTokens = positiveSafeInteger(config.maxOutputTokens, 'maxOutputTokens')\n const timeoutMs = positiveSafeInteger(config.timeoutMs, 'timeoutMs')\n return runChunkedAnalystDefinition(\n publicDirectAnalystDefinition(dataset, {\n timeoutMs,\n maxOutputTokens,\n maxCostUsd: config.maxCostUsdPerAnalysis ?? 1,\n }),\n config,\n )\n}\n\n// ── Chunked one-shot execution strategy ─────────────────────────────\n\n/**\n * Compile a chunked-projection definition into a runnable one-shot JSON arm\n * over the caller-owned model path. Prompt content, the projection ladder,\n * the reply grammar, and the budget declaration come from the definition;\n * caching, cost settlement, and the model proxy are transport machinery.\n */\nexport function runChunkedAnalystDefinition<TRow>(\n definition: AnalystDefinition<TRow>,\n config: PublicAnalystBenchmarkModelConfig,\n): AnalystBenchmarkRunner<AnalystRunInputs> {\n const { projection, binding, replyContract } = definition\n if (projection.mode !== 'chunked' || binding.kind !== 'chunked') {\n throw new AnalystExpressivenessError(\n `the chunked one-shot strategy compiles only chunked projections; definition ` +\n `'${definition.id}' declares projection '${projection.mode}' with a '${binding.kind}' binding`,\n )\n }\n if (config.instructionsOverride) {\n throw new Error(\n 'the direct runner executes only the stock protocol; an instructions override requires the dspy-rlm runner',\n )\n }\n if (definition.repair.turns !== 0) {\n throw new AnalystExpressivenessError(\n `the one-shot JSON exchange grants no repair turn; definition '${definition.id}' ` +\n `declares ${definition.repair.turns}`,\n )\n }\n const reasoningEffort = definition.profile.model?.reasoningEffort\n if (reasoningEffort !== 'none') {\n throw new AnalystExpressivenessError(\n `the one-shot JSON strategy runs with thinking disabled and can express only reasoning ` +\n `effort 'none'; definition '${definition.id}' declares '${reasoningEffort}'`,\n )\n }\n if (!replyContract.parseEnvelope) {\n throw new AnalystExpressivenessError(\n `the one-shot JSON strategy needs a strict reply envelope; definition ` +\n `'${definition.id}' declares no parseEnvelope`,\n )\n }\n if (definition.taskDefinition === undefined) {\n throw new AnalystExpressivenessError(\n `the one-shot JSON strategy composes its system prompt from the task definition; ` +\n `definition '${definition.id}' declares none`,\n )\n }\n const model = requiredString(config.model, 'model')\n const callRef = requiredString(config.callRef, 'callRef')\n if (typeof config.call !== 'function') throw new TypeError('call must be a function')\n if (typeof config.recordExecution !== 'function') {\n throw new TypeError('recordExecution must be a function')\n }\n const maxOutputTokens = positiveSafeInteger(config.maxOutputTokens, 'maxOutputTokens')\n const timeoutMs = positiveSafeInteger(config.timeoutMs, 'timeoutMs')\n const maxCostUsd = config.maxCostUsdPerAnalysis ?? 1\n assertDeclaredBudget(definition, { timeoutMs, maxOutputTokens, maxCostUsd })\n const maxReasoningTokens = config.maxReasoningTokens ?? maxOutputTokens * 4\n const maxModelRequestBytes = config.maxModelRequestBytes ?? 16 * 1024 * 1024\n const maxModelResponseBytes = config.maxModelResponseBytes ?? 4 * 1024 * 1024\n const modelRequestTimeoutMs = config.modelRequestTimeoutMs ?? timeoutMs\n const pricing = config.pricing ?? pricingForModel(model)\n const costLedger = config.costLedger ?? new CostLedger()\n const durability = config.durability\n ? {\n runIdentitySha256: requiredString(\n config.durability.runIdentitySha256,\n 'durability.runIdentitySha256',\n ),\n responseCacheDir: requiredString(\n config.durability.responseCacheDir,\n 'durability.responseCacheDir',\n ),\n }\n : undefined\n // The composed system prompt is definition content, sealed at bind time.\n const systemPrompt = [definition.taskDefinition, ...replyContract.contractLines].join('\\n\\n')\n return {\n id: definition.id,\n async analyze(input, context) {\n const trajectoryId = binding.subjectFromCaseId(context.caseId)\n const costTags = {\n analystId: binding.costActor,\n benchmarkCaseId: context.caseId,\n benchmarkRepetition: String(context.repetition),\n }\n let rawPredictions: TRow[] = []\n let rejectedRows: string[] = []\n let modelFindings: AnalystFinding[] = []\n let providerModel = model\n let producedAt: string | undefined\n let modelMetadata: Record<string, unknown> = {\n ...binding.baseMetadata,\n protocolSha256: definition.protocolSha256,\n callRef,\n }\n try {\n if (!input.traceStore) {\n throw new Error(`chunked analyst '${definition.id}' requires a trace store`)\n }\n const preparedContext = await prepareSingleTraceContext(\n input.traceStore,\n context,\n projection.attributeByteCaps,\n )\n if (preparedContext === undefined) {\n throw new Error(`trace '${trajectoryId}' has no readable spans`)\n }\n const request: LlmCallRequest = {\n model,\n messages: [\n {\n role: 'system',\n content: systemPrompt,\n },\n {\n role: 'user',\n content: binding.userMessage(preparedContext),\n },\n ],\n jsonMode: true,\n thinking: 'disabled',\n maxTokens: maxOutputTokens,\n timeoutMs: modelRequestTimeoutMs,\n }\n const cacheIdentity = durability\n ? {\n runIdentitySha256: durability.runIdentitySha256,\n caseId: context.caseId,\n repetition: context.repetition,\n }\n : undefined\n const callId = cacheIdentity ? publicBenchmarkCallId(cacheIdentity) : undefined\n const cached = cacheIdentity\n ? readPublicBenchmarkResponseCache(durability!.responseCacheDir, cacheIdentity)\n : undefined\n if (cached) {\n const receipt = settleCachedResponse(costLedger, cached)\n modelMetadata = {\n ...modelMetadata,\n responseSource: 'durable-cache',\n cost: costReceiptMetadata(receipt),\n }\n if (cached.status === 'failed') {\n return {\n findings: [],\n usage: usageReceiptFromCostLedger(costLedger, {\n channel: 'analyst',\n tags: costTags,\n }),\n error: cached.error,\n metadata: modelMetadata,\n }\n }\n const response = decodeReplyRows(replyContract, cached.response)\n rawPredictions = response.rows\n rejectedRows = response.rejected.map((entry) => entry.reason)\n providerModel = cached.metadata.providerModel\n producedAt = cached.metadata.producedAt\n modelMetadata = {\n ...modelMetadata,\n ...response.extras,\n providerModel: cached.metadata.providerModel,\n providerDurationMs: cached.metadata.providerDurationMs,\n finishReason: cached.metadata.finishReason,\n }\n } else {\n assertNoSettledResponseWithoutCache(costLedger, callId)\n const providerCallId = callId ?? `analyst-benchmark-${randomUUID()}`\n let modelProxy: ExternalOptimizerModelProxy | undefined\n const completed = await runWithCleanup({\n label: 'public benchmark direct model resources',\n run: async () => {\n modelProxy = await startExternalOptimizerModelProxy({\n call: config.call,\n callRef,\n recordExecution: config.recordExecution,\n model,\n budget: {\n maxCostUsd,\n maxRequests: 1,\n maxRequestBytes: maxModelRequestBytes,\n maxResponseBytes: maxModelResponseBytes,\n maxOutputTokensPerRequest: maxOutputTokens,\n maxReasoningTokensPerRequest: maxReasoningTokens,\n pricing,\n requestTimeoutMs: modelRequestTimeoutMs,\n },\n costLedger,\n channel: 'analyst',\n phase: binding.costPhase,\n actor: binding.costActor,\n tags: costTags,\n callId: providerCallId,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n // The only endpoint this client ever targets is the loopback\n // model proxy started above: `modelProxy.baseUrl` is\n // `http://127.0.0.1:<port>/v1` with an ephemeral token, and the\n // caller-owned execution owner behind it makes the paid call.\n // agent-eval issues no provider request here.\n const llmOptions: LlmClientOptions = {\n baseUrl: modelProxy.baseUrl,\n apiKey: modelProxy.apiKey,\n maximumAttempts: 1,\n jsonSchemaTransport: 'json-object',\n jsonPayloadMode: 'exact',\n thinking: 'disabled',\n }\n try {\n const completed = await callLlmJson<unknown>(request, {\n ...llmOptions,\n ...(context.signal ? { signal: context.signal } : {}),\n idempotencyKey: providerCallId,\n })\n const response = decodeReplyRows(replyContract, completed.value)\n const responseProducedAt = new Date().toISOString()\n const receipt = requiredSettledReceipt(costLedger, providerCallId)\n if (cacheIdentity) {\n writePublicBenchmarkResponseCache(durability!.responseCacheDir, {\n kind: 'agent-eval/public-benchmark-model-response',\n ...cacheIdentity,\n callId: providerCallId,\n status: 'succeeded',\n // Cache the provider's own payload, not the parse result: a\n // resume re-parses this value, so it must stay exactly what\n // the contract accepts.\n response: completed.value,\n metadata: {\n providerModel: completed.result.model,\n providerDurationMs: completed.result.durationMs,\n finishReason: completed.result.finishReason ?? null,\n producedAt: responseProducedAt,\n },\n receipt: cacheReceiptInput(receipt),\n })\n }\n modelProxy.assertExecutionComplete()\n return { ...completed, response, producedAt: responseProducedAt, receipt }\n } catch (error) {\n const controlFailure = modelProxy.failures().find(isPaidCallControlError)\n if (controlFailure) throw controlFailure\n const receipt = settledReceipt(costLedger, providerCallId)\n if (cacheIdentity) {\n if (receipt) {\n writePublicBenchmarkResponseCache(durability!.responseCacheDir, {\n kind: 'agent-eval/public-benchmark-model-response',\n ...cacheIdentity,\n callId: providerCallId,\n status: 'failed',\n error: publicBenchmarkError(error, []),\n receipt: cacheReceiptInput(receipt),\n })\n }\n }\n throw error\n }\n },\n cleanup: async () => {\n await modelProxy?.close()\n },\n })\n const response = completed.response\n rawPredictions = response.rows\n rejectedRows = response.rejected.map((entry) => entry.reason)\n providerModel = completed.result.model\n producedAt = completed.producedAt\n modelMetadata = {\n ...modelMetadata,\n responseSource: 'provider',\n ...response.extras,\n providerModel: completed.result.model,\n providerDurationMs: completed.result.durationMs,\n finishReason: completed.result.finishReason ?? null,\n cost: costReceiptMetadata(completed.receipt),\n }\n }\n\n const converted = await binding.expandRows({\n subject: trajectoryId,\n rows: rawPredictions,\n store: input.traceStore,\n analystId: definition.id,\n providerModel,\n producedAt: requiredString(producedAt ?? '', 'finding producedAt'),\n ...(context.signal ? { signal: context.signal } : {}),\n })\n modelFindings = converted.findings\n if (converted.diagnostics) {\n modelMetadata = {\n ...modelMetadata,\n blockDiagnostics: {\n ...(converted.diagnostics as Record<string, unknown>),\n rejectedBlocks: rejectedRows,\n },\n }\n }\n if (binding.verifyFindings) {\n await binding.verifyFindings({\n subject: trajectoryId,\n findings: modelFindings,\n store: input.traceStore,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n }\n return {\n findings: modelFindings,\n usage: usageReceiptFromCostLedger(costLedger, {\n channel: 'analyst',\n tags: costTags,\n }),\n metadata: modelMetadata,\n }\n } catch (error) {\n if (context.signal?.aborted) throw error\n if (isPaidCallControlError(error)) throw error\n return {\n findings: [],\n usage: usageReceiptFromCostLedger(costLedger, {\n channel: 'analyst',\n tags: costTags,\n }),\n error: publicBenchmarkError(error, []),\n metadata: {\n ...modelMetadata,\n rawPredictions,\n acceptedFindings: modelFindings,\n },\n }\n }\n },\n }\n}\n\n/** A definition that declares one budget while the transport runs another is refused. */\nfunction assertDeclaredBudget<TRow>(\n definition: AnalystDefinition<TRow>,\n effective: { timeoutMs: number; maxOutputTokens: number; maxCostUsd: number },\n): void {\n const declared = definition.budget\n if (\n declared.timeoutMs !== effective.timeoutMs ||\n declared.maxOutputTokens !== effective.maxOutputTokens ||\n declared.maxCostUsd !== effective.maxCostUsd\n ) {\n throw new AnalystExpressivenessError(\n `definition '${definition.id}' declares budget ${JSON.stringify(declared)} but the bound ` +\n `transport runs ${JSON.stringify(effective)}; the declaration must state what executes`,\n )\n }\n}\n\nfunction settleCachedResponse(\n costLedger: CostLedgerHandle,\n cached: PublicBenchmarkResponseCacheEntry,\n): CostReceipt {\n const settled = costLedger.list().find((receipt) => receipt.callId === cached.callId)\n const pending = costLedger.listPending?.().find((record) => record.callId === cached.callId)\n if (settled && pending) {\n throw new CostCallConflictError(\n `benchmark response '${cached.callId}' is both pending and settled`,\n { callId: cached.callId },\n )\n }\n const receipt = pending\n ? costLedger.reconcile(cached.callId, cached.receipt, {\n ...(cached.status === 'failed' ? { failed: true } : {}),\n })\n : settled\n if (!receipt) {\n throw new CostCallConflictError(\n `benchmark response cache '${cached.callId}' has no matching cost record`,\n { callId: cached.callId },\n )\n }\n assertCacheReceiptMatches(cached, receipt)\n return receipt\n}\n\nfunction assertNoSettledResponseWithoutCache(\n costLedger: CostLedgerHandle,\n callId: string | undefined,\n): void {\n if (!callId) return\n if (costLedger.list().some((receipt) => receipt.callId === callId)) {\n throw new CostCallConflictError(\n `settled benchmark call '${callId}' has no durable response cache`,\n { callId },\n )\n }\n}\n\nfunction assertCacheReceiptMatches(\n cached: PublicBenchmarkResponseCacheEntry,\n receipt: CostReceipt,\n): void {\n const expected = cached.receipt\n const mismatch =\n receipt.callId !== cached.callId ||\n receipt.model !== expected.model ||\n receipt.inputTokens !== expected.inputTokens ||\n receipt.outputTokens !== expected.outputTokens ||\n (receipt.reasoningTokens ?? 0) !== (expected.reasoningTokens ?? 0) ||\n (receipt.cachedTokens ?? 0) !== (expected.cachedTokens ?? 0) ||\n (receipt.cacheWriteTokens ?? 0) !== (expected.cacheWriteTokens ?? 0) ||\n (expected.actualCostUsd !== undefined && receipt.actualCostUsd !== expected.actualCostUsd) ||\n (expected.estimatedCostUsd !== undefined &&\n receipt.estimatedCostUsd !== expected.estimatedCostUsd) ||\n (expected.costUnknown === true && !receipt.costUnknown) ||\n (expected.usageUnknown === true && !receipt.usageUnknown) ||\n (cached.status === 'succeeded' && receipt.error !== undefined) ||\n (cached.status === 'failed' && receipt.error === undefined)\n if (mismatch) {\n throw new CostCallConflictError(\n `benchmark response cache receipt does not match cost record '${cached.callId}'`,\n { callId: cached.callId, receipt },\n )\n }\n}\n\nfunction isPaidCallControlError(error: unknown): boolean {\n return (\n error instanceof CostAccountingIncompleteError ||\n error instanceof CostCallConflictError ||\n error instanceof CostCeilingReachedError ||\n error instanceof CostLedgerPersistenceError ||\n error instanceof CostReceiptCaptureError ||\n error instanceof CostReservationExceededError\n )\n}\n\nfunction settledReceipt(costLedger: CostLedgerHandle, callId: string): CostReceipt | undefined {\n return costLedger.list().find((receipt) => receipt.callId === callId)\n}\n\nfunction requiredSettledReceipt(costLedger: CostLedgerHandle, callId: string): CostReceipt {\n const receipt = settledReceipt(costLedger, callId)\n if (!receipt) {\n throw new CostAccountingIncompleteError(\n `caller-owned model call '${callId}' produced no cost receipt`,\n )\n }\n return receipt\n}\n\nfunction cacheReceiptInput(receipt: CostReceipt): CostReceiptInput {\n const usage = {\n model: receipt.model,\n inputTokens: receipt.inputTokens,\n outputTokens: receipt.outputTokens,\n ...(receipt.reasoningTokens === undefined ? {} : { reasoningTokens: receipt.reasoningTokens }),\n ...(receipt.cachedTokens === undefined ? {} : { cachedTokens: receipt.cachedTokens }),\n ...(receipt.cacheWriteTokens === undefined\n ? {}\n : { cacheWriteTokens: receipt.cacheWriteTokens }),\n ...(receipt.usageUnknown === undefined ? {} : { usageUnknown: receipt.usageUnknown }),\n }\n if (receipt.costUnknown) return { ...usage, costUnknown: true }\n if (receipt.actualCostUsd !== undefined) {\n return { ...usage, actualCostUsd: receipt.actualCostUsd }\n }\n if (receipt.estimatedCostUsd !== undefined) {\n return { ...usage, estimatedCostUsd: receipt.estimatedCostUsd }\n }\n if (receipt.pricing) {\n return {\n ...usage,\n customTokenPricing: {\n inputUsdPerMillion: receipt.pricing.inputUsdPerThousand * 1_000,\n ...(receipt.pricing.cachedInputUsdPerThousand === undefined\n ? {}\n : { cachedInputUsdPerMillion: receipt.pricing.cachedInputUsdPerThousand * 1_000 }),\n ...(receipt.pricing.cacheWriteUsdPerThousand === undefined\n ? {}\n : { cacheWriteUsdPerMillion: receipt.pricing.cacheWriteUsdPerThousand * 1_000 }),\n outputUsdPerMillion: receipt.pricing.outputUsdPerThousand * 1_000,\n },\n }\n }\n return { ...usage, estimatedCostUsd: receipt.costUsd }\n}\n\nfunction costReceiptMetadata(receipt: CostReceipt): Record<string, unknown> {\n if (receipt.actualCostUsd !== undefined) {\n return { source: 'provider', actualCostUsd: receipt.actualCostUsd }\n }\n if (receipt.estimatedCostUsd !== undefined) {\n return { source: 'external-estimate', estimatedCostUsd: receipt.estimatedCostUsd }\n }\n if (receipt.pricing) {\n return {\n source: 'agent-eval-model-pricing',\n estimatedCostUsd: receipt.costUsd,\n ratesPerThousandTokens: receipt.pricing,\n }\n }\n return {\n source: 'unknown',\n estimatedCostUsd: null,\n }\n}\n\nfunction pricingForModel(model: string): NonNullable<PublicAnalystBenchmarkModelConfig['pricing']> {\n const pricing = resolveModelPricing(model)\n if (!pricing) {\n throw new Error(\n `no pricing is configured for '${model}'; provide PublicAnalystBenchmarkModelConfig.pricing`,\n )\n }\n return {\n inputUsdPerMillion: pricing.input * 1_000,\n outputUsdPerMillion: pricing.output * 1_000,\n }\n}\n\nconst ModelSeveritySchema = z.enum(['critical', 'high', 'medium', 'low', 'info'])\nconst AgentRxPredictionSchema = z\n .object({\n step: z.number().int().positive(),\n severity: ModelSeveritySchema,\n claim: z.string().min(1),\n confidence: z.number().min(0).max(1),\n rationale: z.string().min(1).optional(),\n recommended_action: z.string().min(1).optional(),\n })\n .strict()\nconst CodeTraceBlockPredictionSchema = z\n .object({\n first_step: z.number().int().positive(),\n last_step: z.number().int().positive(),\n consequence_step: z.number().int().positive(),\n escape_status: z.enum(['escaped', 'unescaped']),\n severity: ModelSeveritySchema,\n claim: z.string().min(1),\n confidence: z.number().min(0).max(1),\n rationale: z.string().min(1).optional(),\n recommended_action: z.string().min(1).optional(),\n })\n .strict()\n .superRefine((block, ctx) => {\n if (block.last_step < block.first_step) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `failure block last_step ${block.last_step} precedes first_step ${block.first_step}`,\n })\n return\n }\n const length = block.last_step - block.first_step + 1\n if (length > MAX_INCORRECT_BLOCK_STEPS) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `failure block spans ${length} steps; the maximum is ${MAX_INCORRECT_BLOCK_STEPS}`,\n })\n }\n // The damage a block caused can surface anywhere from the block's own first\n // step onward: a step carries both the assistant action and the observation\n // it produced, and a long block often shows its damage mid-block rather than\n // at the end. Only a consequence before the block began is incoherent.\n if (block.consequence_step < block.first_step) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `failure block consequence_step ${block.consequence_step} precedes first_step ${block.first_step}`,\n })\n }\n })\nconst AgentRxCategorySchema = z.enum([\n 'instruction-plan-adherence-failure',\n 'invention-of-new-information',\n 'invalid-invocation',\n 'misinterpretation-of-tool-output-handoff-failure',\n 'intent-plan-misalignment',\n 'underspecified-user-intent',\n 'intent-not-supported',\n 'guardrails-triggered',\n 'system-failure',\n 'inconclusive',\n])\nconst CodeTraceModelResponseEnvelopeSchema = z\n .object({\n report: z.string().min(1).max(4_000),\n findings: z.array(z.unknown()).max(MAX_INCORRECT_BLOCKS),\n })\n .strict()\nconst AgentRxModelResponseSchema = z\n .object({\n report: z.string().min(1).max(4_000),\n findings: z\n .array(AgentRxPredictionSchema.extend({ category: AgentRxCategorySchema }).strict())\n .max(1),\n })\n .strict()\n\ntype AgentRxModelPrediction = z.infer<typeof AgentRxPredictionSchema> & {\n category?: z.infer<typeof AgentRxCategorySchema>\n}\ntype CodeTraceModelPrediction = z.infer<typeof CodeTraceBlockPredictionSchema>\nexport type PublicBenchmarkModelPrediction = AgentRxModelPrediction | CodeTraceModelPrediction\n\n/**\n * The one-shot reply grammar per dataset. The envelope is the contract and\n * stays strict. Individual CodeTraceBench blocks are model output: one\n * malformed block must not void a case whose remaining blocks are usable and\n * whose provider call is already paid for, so rows decode individually and\n * every rejection is reported.\n */\nfunction directReplyContract(\n dataset: PublicAnalystBenchmarkDataset,\n): ReplyContract<PublicBenchmarkModelPrediction> {\n if (dataset === 'agentrx') {\n return {\n rowsField: 'findings',\n contractLines: [publicBenchmarkFieldContract('agentrx'), PUBLIC_BENCHMARK_ENVELOPE_CONTRACT],\n repairContractLines: [],\n parseEnvelope(value) {\n const parsed = AgentRxModelResponseSchema.parse(value)\n return { rows: parsed.findings, extras: { report: parsed.report } }\n },\n decodeRow(row) {\n // The strict envelope already validated every row.\n return { ok: true, row: row as AgentRxModelPrediction }\n },\n }\n }\n return {\n rowsField: 'findings',\n contractLines: [\n publicBenchmarkFieldContract('codetracebench'),\n PUBLIC_BENCHMARK_ENVELOPE_CONTRACT,\n ],\n repairContractLines: [],\n parseEnvelope(value) {\n const envelope = CodeTraceModelResponseEnvelopeSchema.parse(value)\n return { rows: envelope.findings, extras: { report: envelope.report } }\n },\n decodeRow(row, index) {\n const parsed = CodeTraceBlockPredictionSchema.safeParse(row)\n if (parsed.success) return { ok: true, row: parsed.data }\n return {\n ok: false,\n reason: `block ${index}: ${parsed.error.issues\n .map((issue) => `${issue.path.join('.') || '<root>'} ${issue.message}`)\n .join('; ')}`,\n }\n },\n whenAllRowsRejected: 'fail',\n allRejectedMessage: 'every reported failure block was malformed',\n }\n}\n\nasync function publicBenchmarkPredictionsToFindings(options: {\n dataset: PublicAnalystBenchmarkDataset\n trajectoryId: string\n predictions: readonly PublicBenchmarkModelPrediction[]\n store: TraceAnalysisStore\n analystId: string\n providerModel: string\n producedAt: string\n signal?: AbortSignal\n}): Promise<{ findings: AnalystFinding[]; diagnostics: CodeTraceBlockDiagnostics | undefined }> {\n if (options.predictions.length === 0 && options.dataset === 'agentrx') {\n return { findings: [], diagnostics: undefined }\n }\n if (options.dataset === 'agentrx') {\n const prediction = options.predictions[0]!\n if (!('step' in prediction)) {\n throw new Error('AgentRx model output must name a single root-cause step')\n }\n if (!prediction.category) {\n throw new Error('AgentRx model output is missing its failure category')\n }\n const evidenceByStep = await resolveAssistantStepEvidence({\n trajectoryId: options.trajectoryId,\n steps: [prediction.step],\n store: options.store,\n ...(options.signal ? { signal: options.signal } : {}),\n })\n const [finding] = agentRxPredictionsToFindings(\n options.trajectoryId,\n [\n {\n failure_case: prediction.category,\n step_number: prediction.step,\n description: prediction.rationale ?? prediction.claim,\n },\n ],\n {\n analystId: options.analystId,\n producedAt: options.producedAt,\n confidence: prediction.confidence,\n },\n )\n if (!finding) throw new Error('AgentRx output adapter produced no root-cause finding')\n return {\n findings: [\n {\n ...finding,\n evidence_refs: [evidenceByStep.get(prediction.step)!],\n metadata: {\n ...finding.metadata,\n model: options.providerModel,\n },\n },\n ],\n diagnostics: undefined,\n }\n }\n\n const blocks = options.predictions.map((prediction): CodeTraceFailureBlock => {\n if (!('first_step' in prediction)) {\n throw new Error('CodeTraceBench model output must report first_step/last_step failure blocks')\n }\n return {\n firstStep: prediction.first_step,\n lastStep: prediction.last_step,\n consequenceStep: prediction.consequence_step,\n escapeStatus: prediction.escape_status,\n severity: prediction.severity,\n claim: prediction.claim,\n confidence: prediction.confidence,\n ...(prediction.rationale === undefined ? {} : { rationale: prediction.rationale }),\n ...(prediction.recommended_action === undefined\n ? {}\n : { recommendedAction: prediction.recommended_action }),\n metadata: { analysis_mode: 'direct-baseline', model: options.providerModel },\n }\n })\n return expandCodeTraceFailureBlocks({\n trajectoryId: options.trajectoryId,\n blocks,\n store: options.store,\n analystId: options.analystId,\n producedAt: options.producedAt,\n ...(options.signal ? { signal: options.signal } : {}),\n })\n}\n\nasync function prepareSingleTraceContext(\n store: TraceAnalysisStore,\n context: { signal?: AbortSignal },\n attributeByteCaps: readonly number[],\n): Promise<string | undefined> {\n const storeContext = context.signal ? { signal: context.signal } : undefined\n const overview = await store.getOverview(undefined, storeContext)\n if (overview.total_traces !== 1 || overview.sample_trace_ids.length !== 1) {\n throw new Error(\n `public model benchmark requires exactly one trace, received ${overview.total_traces}`,\n )\n }\n const traceId = overview.sample_trace_ids[0]!\n for (const perAttributeByteCap of attributeByteCaps) {\n const viewed = await store.viewTrace(\n {\n trace_id: traceId,\n per_attribute_byte_cap: perAttributeByteCap,\n },\n storeContext,\n )\n if (!viewed.spans) continue\n return JSON.stringify({\n trace_id: traceId,\n per_attribute_byte_cap: perAttributeByteCap,\n spans: viewed.spans,\n })\n }\n return undefined\n}\n\nfunction trajectoryIdFromCaseId(dataset: PublicAnalystBenchmarkDataset, caseId: string): string {\n const prefix = dataset === 'agentrx' ? 'agentrx:' : 'codetrace:'\n if (!caseId.startsWith(prefix) || caseId.length === prefix.length) {\n throw new Error(`unexpected ${dataset} benchmark case id '${caseId}'`)\n }\n return caseId.slice(prefix.length)\n}\n","import type { CodeTraceFailureBlock, CodeTraceStepAssignment } from './benchmark-public-adapters'\n\n/**\n * One sample block's contribution to a consensus block, in the shape the\n * decision record persists: block coordinates plus how many consensus steps\n * the block's accepted steps cover.\n */\nexport interface CodeTraceConsensusContributor {\n sample: number\n firstStep: number\n lastStep: number\n consequenceStep: number\n confidence: number\n overlapSteps: number\n}\n\nexport interface CodeTraceConsensusBlockDecision {\n firstStep: number\n lastStep: number\n consequenceStep: number\n escapeStatus: 'escaped' | 'unescaped'\n /** Mean confidence across every contributor. */\n confidence: number\n donor: CodeTraceConsensusContributor\n contributors: CodeTraceConsensusContributor[]\n}\n\n/** The full voting record: every step any sample accepted, and what won. */\nexport interface CodeTraceConsensusDecision {\n samples: number\n threshold: number\n stepVotes: Array<{ step: number; votes: number; kept: boolean }>\n blocks: CodeTraceConsensusBlockDecision[]\n}\n\n/**\n * Step-level majority vote across independent analyst samples.\n *\n * Each sample's accepted, evidence-resolved steps count as one vote per step.\n * Steps present in at least ceil(k/2) samples survive; surviving steps are\n * reassembled into contiguous consensus blocks. Each consensus block borrows\n * its metadata (consequence step, escape status, claim, severity, rationale)\n * from the contributing sample block with the largest step overlap — ties go\n * to the higher-confidence block, then to the earlier sample — while its\n * confidence is the mean across every contributor. The returned blocks still\n * pass through the shared expansion, so width, count, and evidence rules are\n * enforced there, never assumed here.\n */\nexport function consensusCodeTraceBlocks(\n sampleAssignments: ReadonlyArray<readonly CodeTraceStepAssignment[]>,\n): { blocks: CodeTraceFailureBlock[]; decision: CodeTraceConsensusDecision } {\n const samples = sampleAssignments.length\n if (samples < 2) {\n throw new RangeError('step-level consensus requires at least two samples')\n }\n const threshold = Math.ceil(samples / 2)\n const votesByStep = new Map<number, number>()\n sampleAssignments.forEach((assignments, sample) => {\n const seen = new Set<number>()\n for (const { step } of assignments) {\n if (!Number.isSafeInteger(step) || step < 0) {\n throw new RangeError(`sample ${sample} assigned a non-step value: ${step}`)\n }\n if (seen.has(step)) {\n throw new Error(`sample ${sample} assigned step ${step} to more than one block`)\n }\n seen.add(step)\n votesByStep.set(step, (votesByStep.get(step) ?? 0) + 1)\n }\n })\n const stepVotes = [...votesByStep]\n .sort(([left], [right]) => left - right)\n .map(([step, votes]) => ({ step, votes, kept: votes >= threshold }))\n const keptSteps = stepVotes.filter((entry) => entry.kept).map((entry) => entry.step)\n\n const blocks: CodeTraceFailureBlock[] = []\n const blockDecisions: CodeTraceConsensusBlockDecision[] = []\n for (const segment of contiguousSegments(keptSteps)) {\n const contributors = segmentContributors(sampleAssignments, segment)\n // Every kept step carries >= threshold sample votes, so a segment always\n // has at least one contributor.\n const donor = contributors.reduce(betterDonor)\n const confidence =\n contributors.reduce((sum, contributor) => sum + contributor.block.confidence, 0) /\n contributors.length\n blocks.push({\n firstStep: segment.firstStep,\n lastStep: segment.lastStep,\n consequenceStep: donor.block.consequenceStep,\n escapeStatus: donor.block.escapeStatus,\n severity: donor.block.severity,\n claim: donor.block.claim,\n confidence,\n ...(donor.block.rationale === undefined ? {} : { rationale: donor.block.rationale }),\n ...(donor.block.recommendedAction === undefined\n ? {}\n : { recommendedAction: donor.block.recommendedAction }),\n metadata: {\n ...donor.block.metadata,\n consensus_samples: samples,\n consensus_threshold: threshold,\n consensus_contributors: contributors.length,\n consensus_donor_sample: donor.sample,\n },\n })\n blockDecisions.push({\n firstStep: segment.firstStep,\n lastStep: segment.lastStep,\n consequenceStep: donor.block.consequenceStep,\n escapeStatus: donor.block.escapeStatus,\n confidence,\n donor: publicContributor(donor),\n contributors: contributors.map(publicContributor),\n })\n }\n return { blocks, decision: { samples, threshold, stepVotes, blocks: blockDecisions } }\n}\n\ninterface SegmentContributor {\n sample: number\n block: CodeTraceFailureBlock\n overlapSteps: number\n}\n\n/**\n * All (sample, block) pairs whose accepted steps intersect the segment,\n * ordered by sample then by first overlapping step — the deterministic\n * tie-break order for donor selection.\n */\nfunction segmentContributors(\n sampleAssignments: ReadonlyArray<readonly CodeTraceStepAssignment[]>,\n segment: { firstStep: number; lastStep: number },\n): SegmentContributor[] {\n const contributors: SegmentContributor[] = []\n sampleAssignments.forEach((assignments, sample) => {\n const overlapByBlock = new Map<CodeTraceFailureBlock, number>()\n for (const { step, block } of assignments) {\n if (step < segment.firstStep || step > segment.lastStep) continue\n overlapByBlock.set(block, (overlapByBlock.get(block) ?? 0) + 1)\n }\n for (const [block, overlapSteps] of overlapByBlock) {\n contributors.push({ sample, block, overlapSteps })\n }\n })\n return contributors\n}\n\nfunction betterDonor(left: SegmentContributor, right: SegmentContributor): SegmentContributor {\n if (right.overlapSteps !== left.overlapSteps) {\n return right.overlapSteps > left.overlapSteps ? right : left\n }\n if (right.block.confidence !== left.block.confidence) {\n return right.block.confidence > left.block.confidence ? right : left\n }\n // Remaining ties keep the earlier contributor: lower sample index, then the\n // block whose first overlapping step comes first (construction order).\n return left\n}\n\nfunction publicContributor(contributor: SegmentContributor): CodeTraceConsensusContributor {\n return {\n sample: contributor.sample,\n firstStep: contributor.block.firstStep,\n lastStep: contributor.block.lastStep,\n consequenceStep: contributor.block.consequenceStep,\n confidence: contributor.block.confidence,\n overlapSteps: contributor.overlapSteps,\n }\n}\n\nfunction contiguousSegments(\n sortedSteps: readonly number[],\n): Array<{ firstStep: number; lastStep: number }> {\n const segments: Array<{ firstStep: number; lastStep: number }> = []\n for (const step of sortedSteps) {\n const current = segments[segments.length - 1]\n if (current && step === current.lastStep + 1) {\n current.lastStep = step\n continue\n }\n segments.push({ firstStep: step, lastStep: step })\n }\n return segments\n}\n","import {\n CostAccountingIncompleteError,\n CostCallConflictError,\n CostCeilingReachedError,\n CostLedger,\n CostLedgerPersistenceError,\n CostReceiptCaptureError,\n CostReservationExceededError,\n type CustomTokenPricing,\n} from '../cost-ledger'\nimport { resolveModelPricing } from '../metrics'\nimport type { AnalystBenchmarkOutput, AnalystBenchmarkRunner } from './benchmark'\nimport { effectiveAnalystProtocolSha256 } from './benchmark-instructions-override'\nimport {\n adaptPublicBenchmarkFindings,\n type CodeTraceFailureBlock,\n type CodeTraceStepAssignment,\n codeTraceBlockMetadataFromSubject,\n expandCodeTraceFailureBlocks,\n} from './benchmark-public-adapters'\nimport { consensusCodeTraceBlocks } from './benchmark-public-consensus'\nimport { publicBenchmarkError } from './benchmark-public-errors'\nimport { createPublicBenchmarkDirectRunner } from './benchmark-public-model'\nimport { publicBenchmarkRlmInstructions } from './benchmark-public-prompt'\nimport type {\n PublicAnalystBenchmarkDataset,\n PublicAnalystBenchmarkModelConfig,\n} from './benchmark-public-types'\nimport {\n type AnalystDefinition,\n AnalystExpressivenessError,\n type ReplVariableConsensusPort,\n} from './definition'\nimport { createDspyRlmTraceEngine, type DspyRlmTraceEngineOptions } from './dspy-rlm-engine'\nimport type { TraceAnalystLimits } from './engine'\nimport {\n evidenceRefsFromRawFinding,\n RAW_FINDING_SCHEMA_PROMPT,\n type RawAnalystFinding,\n RawAnalystFindingSchema,\n} from './finding-signature'\nimport { runTraceAnalyst, type TraceAnalystDefinition } from './kind-factory'\nimport type { AnalystFinding, AnalystRunInputs, AnalystUsageReceipt } from './types'\nimport { makeFinding } from './types'\nimport { usageReceiptFromCostLedger } from './usage-receipt'\n\n/**\n * Public benchmark candidate that runs the actual recursive trace analyst.\n *\n * The arm is expressed as an `AnalystDefinition` (`publicRlmAnalystDefinition`):\n * the question, the recursive instructions (stock or override), the tool group,\n * the engine iteration limits, and the budget are definition content, and\n * `createPublicBenchmarkRlmRunner` is a thin shell that builds the definition\n * and runs it through the repl-variable strategy below — the same strategy\n * `bindAnalyst` (./bind) dispatches to.\n */\n\nexport interface PublicRlmDefinitionArgs {\n /** Effective recursive instructions: the override text or the stock prompt. */\n instructions: string\n /** Digest the arm records: the stock digest, bound to any override. */\n protocolSha256: string\n /** Whole-analysis deadline (`config.timeoutMs`). */\n timeoutMs: number\n /** Controller completion-token cap (`config.maxOutputTokens`). */\n maxOutputTokens: number\n /** Per-case engine spend ceiling (`config.maxCostUsdPerAnalysis`). */\n maxCostUsd: number\n /** Resolved recursive-engine iteration limits. */\n engineLimits: TraceAnalystLimits\n}\n\n/** The dspy-rlm arm as a declarative unit for one public dataset. */\nexport function publicRlmAnalystDefinition(\n dataset: PublicAnalystBenchmarkDataset,\n args: PublicRlmDefinitionArgs,\n): AnalystDefinition<RawAnalystFinding, CodeTraceStepAssignment> {\n return {\n id: 'dspy-rlm',\n description:\n dataset === 'agentrx'\n ? 'Localizes the first unrecoverable root-cause step.'\n : 'Localizes every incorrect state-changing assistant step.',\n version: '1.0.0',\n area: dataset === 'agentrx' ? 'root-cause' : 'incorrect',\n // The caller-owned model path selects the model; the engine owns reasoning.\n profile: {},\n question:\n dataset === 'agentrx'\n ? 'What is the first unrecoverable root cause in this failed trajectory?'\n : 'Which assistant steps are incorrect under the CodeTraceBench definition?',\n taskDefinition: args.instructions,\n projection: { mode: 'repl-variable', toolGroup: 'singleTrace' },\n // Declarative restatement of the engine's row grammar: the engine enforces\n // the same `RawAnalystFindingSchema` on every submitted row, and the\n // schema prompt below is what `runTraceAnalyst` splices into the\n // instructions. The bounded typed repair lives inside the engine's control\n // adapter, so no repair grammar restatement exists.\n replyContract: {\n rowsField: 'findings',\n contractLines: [RAW_FINDING_SCHEMA_PROMPT],\n repairContractLines: [],\n decodeRow(row) {\n const parsed = RawAnalystFindingSchema.safeParse(row)\n if (parsed.success) return { ok: true, row: parsed.data }\n return {\n ok: false,\n reason: parsed.error.issues\n .map((issue) => `${issue.path.join('.')}: ${issue.message}`)\n .join('; '),\n }\n },\n },\n contractLimits: {\n maxIterations: args.engineLimits.maxIterations,\n maxLlmCalls: args.engineLimits.maxLlmCalls,\n maxToolCalls: args.engineLimits.maxToolCalls,\n maxOutputChars: args.engineLimits.maxOutputChars,\n },\n budget: {\n timeoutMs: args.timeoutMs,\n maxCostUsd: args.maxCostUsd,\n maxOutputTokens: args.maxOutputTokens,\n engineLimits: args.engineLimits,\n },\n // One bounded typed-extraction repair inside the engine's control adapter,\n // mirroring the prime arm's single repair turn.\n repair: { turns: 1 },\n protocolSha256: args.protocolSha256,\n binding: {\n kind: 'repl-variable',\n traceAnalystId: dataset === 'agentrx' ? 'agentrx-dspy-rlm' : 'codetracebench-dspy-rlm',\n subjectFromCaseId: (caseId) => trajectoryIdFromCaseId(dataset, caseId),\n baseMetadata: { analysisMode: 'recursive', engine: 'dspy-rlm' },\n findingBaseMetadata: { analysis_mode: 'recursive', engine: 'dspy-rlm' },\n costPhase: 'analyst.public-benchmark.dspy-rlm',\n ...(dataset === 'codetracebench'\n ? { metadataFromSubject: codeTraceBlockMetadataFromSubject }\n : {}),\n async adapt({ subject, findings, analystId, store, signal }) {\n return adaptPublicBenchmarkFindings({\n dataset,\n trajectoryId: subject,\n findings: [...findings],\n analystId,\n store,\n ...(signal ? { signal } : {}),\n })\n },\n ...(dataset === 'codetracebench' ? { consensus: codeTraceConsensusPort() } : {}),\n abstentionFallback: (fallbackConfig) =>\n createPublicBenchmarkDirectRunner(dataset, fallbackConfig),\n },\n }\n}\n\n/** Step-level majority consensus on the CodeTraceBench block grammar. */\nfunction codeTraceConsensusPort(): ReplVariableConsensusPort<\n CodeTraceStepAssignment,\n CodeTraceFailureBlock\n> {\n return {\n vote(samples) {\n const consensus = consensusCodeTraceBlocks(samples.map((sample) => [...sample]))\n return { blocks: consensus.blocks, decision: consensus.decision }\n },\n async expand({ subject, blocks, store, analystId, producedAt, signal }) {\n const expanded = await expandCodeTraceFailureBlocks({\n trajectoryId: subject,\n blocks,\n store,\n analystId,\n producedAt,\n ...(signal ? { signal } : {}),\n })\n return { findings: expanded.findings, diagnostics: expanded.diagnostics }\n },\n sampleRecord(assignments) {\n return {\n blocks: sampleBlockRecords(assignments),\n steps: assignments.map((assignment) => assignment.step),\n }\n },\n }\n}\n\n/** Thin shell: validate config, declare the definition, run the repl-variable strategy. */\nexport function createPublicBenchmarkRlmRunner(\n dataset: PublicAnalystBenchmarkDataset,\n config: PublicAnalystBenchmarkModelConfig,\n): AnalystBenchmarkRunner<AnalystRunInputs> {\n const samples = config.dspyRlm?.samples ?? 1\n if (!Number.isSafeInteger(samples) || samples < 1) {\n throw new RangeError('dspyRlm.samples must be a positive safe integer')\n }\n if (samples > 1 && dataset !== 'codetracebench') {\n throw new Error(\n 'dspyRlm.samples > 1 requires the codetracebench dataset; step-level consensus is defined on its block grammar',\n )\n }\n return runReplVariableAnalystDefinition(\n publicRlmAnalystDefinition(dataset, {\n instructions: config.instructionsOverride?.text ?? publicBenchmarkRlmInstructions(dataset),\n protocolSha256: effectiveAnalystProtocolSha256(dataset, config.instructionsOverride),\n timeoutMs: config.timeoutMs,\n maxOutputTokens: config.maxOutputTokens,\n maxCostUsd: config.maxCostUsdPerAnalysis ?? 1,\n engineLimits: rlmEngineLimits(config),\n }),\n config,\n )\n}\n\n/** Engine iteration limits with this arm's defaults applied. */\nexport function rlmEngineLimits(config: PublicAnalystBenchmarkModelConfig): TraceAnalystLimits {\n return {\n maxIterations: config.dspyRlm?.maxIterations ?? 14,\n maxLlmCalls: config.dspyRlm?.maxLlmCalls ?? 8,\n maxToolCalls: config.dspyRlm?.maxToolCalls ?? 80,\n maxOutputChars: config.dspyRlm?.maxOutputChars ?? 8_000,\n }\n}\n\n// ── Repl-variable execution strategy ────────────────────────────────\n\n/**\n * Compile a repl-variable definition into a runnable recursive-engine arm over\n * the caller-owned model path. The question, instructions, tool group, and\n * iteration limits come from the definition; the engine, model proxy, sampling\n * loop, and abstention floor are transport machinery.\n */\nexport function runReplVariableAnalystDefinition(\n definition: AnalystDefinition<RawAnalystFinding, CodeTraceStepAssignment>,\n config: PublicAnalystBenchmarkModelConfig,\n): AnalystBenchmarkRunner<AnalystRunInputs> {\n const { projection, binding } = definition\n if (projection.mode !== 'repl-variable' || binding.kind !== 'repl-variable') {\n throw new AnalystExpressivenessError(\n `the repl-variable strategy compiles only repl-variable projections; definition ` +\n `'${definition.id}' declares projection '${projection.mode}' with a '${binding.kind}' binding`,\n )\n }\n const instructions = definition.taskDefinition\n if (instructions === undefined) {\n throw new AnalystExpressivenessError(\n `the repl-variable strategy runs the definition's task text as engine instructions; ` +\n `definition '${definition.id}' declares none`,\n )\n }\n if (\n config.instructionsOverride !== undefined &&\n config.instructionsOverride.text !== instructions\n ) {\n throw new AnalystExpressivenessError(\n `definition '${definition.id}' declares instructions that differ from the transport's ` +\n 'instructionsOverride; one text must execute',\n )\n }\n const area = definition.area\n if (area === undefined) {\n throw new AnalystExpressivenessError(\n `the repl-variable strategy stamps the definition's area on every finding; definition ` +\n `'${definition.id}' declares none`,\n )\n }\n const limits = definition.budget.engineLimits\n if (limits === undefined) {\n throw new AnalystExpressivenessError(\n `the repl-variable strategy needs declared engine limits; definition ` +\n `'${definition.id}' declares none`,\n )\n }\n const effectiveLimits = rlmEngineLimits(config)\n if (\n limits.maxIterations !== effectiveLimits.maxIterations ||\n limits.maxLlmCalls !== effectiveLimits.maxLlmCalls ||\n limits.maxToolCalls !== effectiveLimits.maxToolCalls ||\n limits.maxOutputChars !== effectiveLimits.maxOutputChars\n ) {\n throw new AnalystExpressivenessError(\n `definition '${definition.id}' declares engine limits ${JSON.stringify(limits)} but the ` +\n `bound transport runs ${JSON.stringify(effectiveLimits)}; the declaration must state what executes`,\n )\n }\n const costLedger = config.costLedger ?? new CostLedger()\n const samples = config.dspyRlm?.samples ?? 1\n if (!Number.isSafeInteger(samples) || samples < 1) {\n throw new RangeError('dspyRlm.samples must be a positive safe integer')\n }\n if (samples > 1 && binding.consensus === undefined) {\n throw new AnalystExpressivenessError(\n `samples > 1 needs a consensus port; definition '${definition.id}' declares none`,\n )\n }\n const pricing = config.pricing ?? pricingForModel(config.model)\n const engine = createDspyRlmTraceEngine({\n call: config.call,\n callRef: config.callRef,\n recordExecution: config.recordExecution,\n model: config.model,\n maxOutputTokens: config.maxOutputTokens,\n timeoutMs: config.timeoutMs,\n maxCostUsd: config.maxCostUsdPerAnalysis ?? 1,\n pricing,\n ...(config.maxReasoningTokens === undefined\n ? {}\n : { maxReasoningTokens: config.maxReasoningTokens }),\n ...(config.maxModelRequestBytes === undefined\n ? {}\n : { maxModelRequestBytes: config.maxModelRequestBytes }),\n ...(config.maxModelResponseBytes === undefined\n ? {}\n : { maxModelResponseBytes: config.maxModelResponseBytes }),\n ...(config.modelRequestTimeoutMs === undefined\n ? {}\n : { modelRequestTimeoutMs: config.modelRequestTimeoutMs }),\n ...(config.dspyRlm?.maxModelRequests === undefined\n ? {}\n : { maxModelRequests: config.dspyRlm.maxModelRequests }),\n ...(config.dspyRlm?.traceToolRequestBytes === undefined &&\n config.dspyRlm?.traceToolResponseBytes === undefined\n ? {}\n : {\n traceToolLimits: {\n ...(config.dspyRlm?.traceToolRequestBytes === undefined\n ? {}\n : { maxRequestBytes: config.dspyRlm.traceToolRequestBytes }),\n ...(config.dspyRlm?.traceToolResponseBytes === undefined\n ? {}\n : { maxResponseBytes: config.dspyRlm.traceToolResponseBytes }),\n },\n }),\n ...(config.dspyRlm?.traceToolTimeoutMs === undefined\n ? {}\n : { traceToolTimeoutMs: config.dspyRlm.traceToolTimeoutMs }),\n ...(config.dspyRlm?.runner ? { runner: config.dspyRlm.runner } : {}),\n } satisfies DspyRlmTraceEngineOptions)\n const protocolSha256 = definition.protocolSha256\n const traceDefinition: TraceAnalystDefinition = {\n id: binding.traceAnalystId,\n description: definition.description,\n area,\n version: definition.version,\n question: definition.question,\n instructions,\n toolGroup: projection.toolGroup,\n limits,\n }\n // Abstention floor: shares this arm's cost ledger so a fallback call's spend\n // lands under the same case and repetition tags as the engine's calls. The\n // fallback always runs the stock direct prompt — an instructions override\n // replaces only the recursive instructions, and the effective protocol digest\n // binds the stock digest (covering this fallback prompt) to the override.\n const { instructionsOverride: _rlmOnlyOverride, ...directConfig } = config\n void _rlmOnlyOverride\n const abstentionFallbackRunner = binding.abstentionFallback({ ...directConfig, costLedger })\n\n return {\n id: definition.id,\n async analyze(input, context) {\n const trajectoryId = binding.subjectFromCaseId(context.caseId)\n const tags = {\n benchmarkCaseId: context.caseId,\n benchmarkRepetition: String(context.repetition),\n }\n let usage: AnalystUsageReceipt | undefined\n let rawFindings: AnalystFinding[] = []\n try {\n if (!input.traceStore) {\n throw new Error(`repl-variable analyst '${definition.id}' requires a trace store`)\n }\n if (samples > 1) {\n const store = input.traceStore\n const caseUsageFilter = { channel: 'analyst' as const, tags }\n const sampleRuns: Array<Record<string, unknown>> = []\n const sampleAssignments: CodeTraceStepAssignment[][] = []\n let totalModelCalls = 0\n let totalToolCalls = 0\n for (let sample = 0; sample < samples; sample += 1) {\n let sampleUsage: AnalystUsageReceipt | undefined\n const completed = await runTraceAnalyst({\n definition: traceDefinition,\n engine,\n store,\n context: {\n runId: context.caseId,\n // A distinct correlation id per sample tags each sample's\n // provider calls individually in the shared ledger, while the\n // case and repetition tags keep all k samples' spend — and a\n // fallback's — on this one case.\n correlationId: `${context.caseId}:${context.repetition}:sample-${sample}`,\n costLedger,\n costPhase: binding.costPhase,\n tags,\n recordUsage: (receipt) => {\n sampleUsage = receipt\n usage = usageReceiptFromCostLedger(costLedger, caseUsageFilter)\n },\n signal: context.signal,\n },\n })\n const producedAt = new Date().toISOString()\n const sampleFindings = completed.findings.map((finding) =>\n makeFinding({\n analyst_id: definition.id,\n area,\n subject: finding.subject,\n claim: finding.claim,\n rationale: finding.rationale,\n severity: finding.severity,\n confidence: finding.confidence,\n evidence_refs: evidenceRefsFromRawFinding(finding),\n recommended_action: finding.recommended_action,\n metadata: {\n ...binding.findingBaseMetadata,\n model: config.model,\n sample,\n ...(binding.metadataFromSubject?.(finding.subject) ?? {}),\n },\n produced_at: producedAt,\n }),\n )\n rawFindings = [...rawFindings, ...sampleFindings]\n const adapted = await binding.adapt({\n subject: trajectoryId,\n findings: sampleFindings,\n analystId: definition.id,\n store,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n const assignments = adapted.stepBlocks ?? []\n sampleAssignments.push(assignments)\n totalModelCalls += completed.modelCalls\n totalToolCalls += completed.toolCalls\n sampleRuns.push({\n sample,\n answer: completed.answer,\n trajectory: completed.trajectory,\n modelCalls: completed.modelCalls,\n toolCalls: completed.toolCalls,\n runtime: completed.runtime,\n ...binding.consensus!.sampleRecord(assignments),\n ...(adapted.diagnostics ? { blockDiagnostics: adapted.diagnostics } : {}),\n ...(sampleUsage ? { usage: sampleUsage } : {}),\n })\n }\n const consensus = binding.consensus!.vote(sampleAssignments)\n const expanded = await binding.consensus!.expand({\n subject: trajectoryId,\n blocks: consensus.blocks,\n store,\n analystId: definition.id,\n producedAt: new Date().toISOString(),\n ...(context.signal ? { signal: context.signal } : {}),\n })\n // Abstention floor, applied AFTER the vote and never per sample:\n // one direct structured call fires only when no step reached the\n // majority threshold, so the whole panel — not one noisy sample —\n // failed to localize anything.\n let fallback: AnalystBenchmarkOutput | undefined\n if (consensus.blocks.length === 0) {\n fallback = await abstentionFallbackRunner.analyze(input, context)\n }\n usage = usageReceiptFromCostLedger(costLedger, caseUsageFilter)\n return {\n findings: fallback && !fallback.error ? fallback.findings : expanded.findings,\n usage,\n metadata: {\n ...binding.baseMetadata,\n protocolSha256,\n samples,\n sampleRuns,\n consensus: consensus.decision,\n blockDiagnostics: expanded.diagnostics,\n modelCalls: totalModelCalls,\n toolCalls: totalToolCalls,\n ...(fallback\n ? {\n abstentionFallback: 'direct',\n ...(fallback.metadata ? { abstentionFallbackMetadata: fallback.metadata } : {}),\n ...(fallback.error ? { abstentionFallbackError: fallback.error } : {}),\n }\n : {}),\n },\n }\n }\n const completed = await runTraceAnalyst({\n definition: traceDefinition,\n engine,\n store: input.traceStore,\n context: {\n runId: context.caseId,\n correlationId: `${context.caseId}:${context.repetition}`,\n costLedger,\n costPhase: binding.costPhase,\n tags,\n recordUsage: (receipt) => {\n usage = receipt\n },\n signal: context.signal,\n },\n })\n const producedAt = new Date().toISOString()\n rawFindings = completed.findings.map((finding) =>\n makeFinding({\n analyst_id: definition.id,\n area,\n subject: finding.subject,\n claim: finding.claim,\n rationale: finding.rationale,\n severity: finding.severity,\n confidence: finding.confidence,\n evidence_refs: evidenceRefsFromRawFinding(finding),\n recommended_action: finding.recommended_action,\n metadata: {\n ...binding.findingBaseMetadata,\n model: config.model,\n // Block coordinates from the subject grammar, so a row retained\n // by a failed or empty case still carries its block metadata.\n ...(binding.metadataFromSubject?.(finding.subject) ?? {}),\n },\n produced_at: producedAt,\n }),\n )\n const adapted = await binding.adapt({\n subject: trajectoryId,\n findings: rawFindings,\n analystId: definition.id,\n store: input.traceStore,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n // Abstention floor: the engine finished but submitted no finding at\n // all — indistinguishable from a missed investigation, so one direct\n // structured call gets a second opinion. An explicit clean verdict\n // arrives as a finding and never reaches this branch; an engine error\n // is thrown above and never reaches it either.\n let fallback: AnalystBenchmarkOutput | undefined\n if (completed.findings.length === 0) {\n fallback = await abstentionFallbackRunner.analyze(input, context)\n usage = usageReceiptFromCostLedger(costLedger, {\n channel: 'analyst',\n tags: {\n benchmarkCaseId: context.caseId,\n benchmarkRepetition: String(context.repetition),\n },\n })\n }\n return {\n findings: fallback && !fallback.error ? fallback.findings : adapted.findings,\n usage,\n metadata: {\n ...binding.baseMetadata,\n protocolSha256,\n ...(adapted.diagnostics ? { blockDiagnostics: adapted.diagnostics } : {}),\n answer: completed.answer,\n trajectory: completed.trajectory,\n modelCalls: completed.modelCalls,\n toolCalls: completed.toolCalls,\n runtime: completed.runtime,\n ...(fallback\n ? {\n abstentionFallback: 'direct',\n ...(fallback.metadata ? { abstentionFallbackMetadata: fallback.metadata } : {}),\n ...(fallback.error ? { abstentionFallbackError: fallback.error } : {}),\n }\n : {}),\n },\n }\n } catch (error) {\n if (context.signal?.aborted) throw error\n if (isPaidCallControlError(error)) throw error\n return {\n findings: [],\n usage,\n error: publicBenchmarkError(error, []),\n metadata: {\n ...binding.baseMetadata,\n ...(samples > 1 ? { samples } : {}),\n rawFindings,\n },\n }\n }\n },\n }\n}\n\n/** Per-sample accepted blocks with the exact steps the expansion kept for each. */\nfunction sampleBlockRecords(\n assignments: readonly CodeTraceStepAssignment[],\n): Array<Record<string, unknown>> {\n const stepsByBlock = new Map<CodeTraceStepAssignment['block'], number[]>()\n for (const { step, block } of assignments) {\n const steps = stepsByBlock.get(block)\n if (steps) steps.push(step)\n else stepsByBlock.set(block, [step])\n }\n return [...stepsByBlock].map(([block, acceptedSteps]) => ({\n firstStep: block.firstStep,\n lastStep: block.lastStep,\n consequenceStep: block.consequenceStep,\n escapeStatus: block.escapeStatus,\n severity: block.severity,\n confidence: block.confidence,\n claim: block.claim,\n acceptedSteps,\n }))\n}\n\nfunction pricingForModel(model: string): CustomTokenPricing {\n const pricing = resolveModelPricing(model)\n if (!pricing) {\n throw new Error(\n `no pricing is configured for '${model}'; provide PublicAnalystBenchmarkModelConfig.pricing`,\n )\n }\n return {\n inputUsdPerMillion: pricing.input * 1_000,\n outputUsdPerMillion: pricing.output * 1_000,\n }\n}\n\nfunction trajectoryIdFromCaseId(dataset: PublicAnalystBenchmarkDataset, caseId: string): string {\n const prefix = dataset === 'agentrx' ? 'agentrx:' : 'codetrace:'\n if (!caseId.startsWith(prefix) || caseId.length === prefix.length) {\n throw new Error(`unexpected ${dataset} benchmark case id '${caseId}'`)\n }\n return caseId.slice(prefix.length)\n}\n\nfunction isPaidCallControlError(error: unknown): boolean {\n return (\n error instanceof CostAccountingIncompleteError ||\n error instanceof CostCallConflictError ||\n error instanceof CostCeilingReachedError ||\n error instanceof CostLedgerPersistenceError ||\n error instanceof CostReceiptCaptureError ||\n error instanceof CostReservationExceededError\n )\n}\n","import { constants } from 'node:fs'\nimport { type FileHandle, open, readdir, realpath } from 'node:fs/promises'\nimport { relative, resolve, sep } from 'node:path'\nimport { compareCodeUnits } from '../ledger-core/canonical'\nimport type { TraceAnalysisStore } from '../trace-analyst/store'\nimport {\n createOtlpBufferTraceStore,\n DEFAULT_MAX_TRACE_FILE_BYTES,\n otlpTextToTraceAnalysisStore,\n} from '../trace-analyst/store-otlp'\nimport { type AnalystBenchmarkCase, traceStoreEvidenceResolver } from './benchmark'\nimport {\n type AgentRxRow,\n agentRxBenchmarkCase,\n type CodeTraceBenchRow,\n codeTraceBenchCase,\n} from './benchmark-datasets'\nimport {\n assertNoBenchmarkLabelsInArtifact,\n assertNoBenchmarkLabelsInTrace,\n} from './benchmark-evidence-validation'\nimport {\n isRecord,\n type PreparedPublicAnalystBenchmark,\n type PublicAnalystBenchmarkDataset,\n type PublicBenchmarkDistributions,\n type PublicBenchmarkSelectionReport,\n type PublicBenchmarkValueDistribution,\n positiveSafeInteger,\n safeInteger,\n} from './benchmark-public-types'\nimport {\n appendVerificationArtifactsToOtlp,\n DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES,\n loadCodeTraceVerificationArtifacts,\n sha256Digest,\n type VerificationArtifactManifest,\n} from './benchmark-verification-artifacts'\nimport type { AnalystRunInputs } from './types'\n\nconst DEFAULT_MAX_PUBLIC_BENCHMARK_LABEL_BYTES = 256 * 1024 * 1024\nconst INPUT_OPEN_FLAGS = constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0)\n\ninterface ImmutableInputSnapshot {\n bytes: Buffer\n sha256: string\n text: string\n}\n\nexport async function loadPublicBenchmarkRows(\n path: string,\n): Promise<Array<Record<string, unknown>>> {\n const snapshot = await readImmutableInputSnapshot(\n resolve(path),\n DEFAULT_MAX_PUBLIC_BENCHMARK_LABEL_BYTES,\n )\n return parsePublicBenchmarkRows(snapshot.text, path)\n}\n\nfunction parsePublicBenchmarkRows(text: string, path: string): Array<Record<string, unknown>> {\n const trimmed = text.trim()\n if (!trimmed) throw new Error(`public analyst benchmark dataset is empty: ${path}`)\n\n let parsed: unknown\n try {\n parsed = JSON.parse(trimmed)\n } catch {\n return parseJsonl(trimmed, path)\n }\n if (Array.isArray(parsed)) return records(parsed, path)\n if (isRecord(parsed) && Array.isArray(parsed.data)) return records(parsed.data, `${path}.data`)\n if (isRecord(parsed) && Array.isArray(parsed.cases)) {\n return records(parsed.cases, `${path}.cases`)\n }\n if (isRecord(parsed)) return [parsed]\n throw new TypeError(`public analyst benchmark dataset must contain JSON objects: ${path}`)\n}\n\nexport function selectPublicBenchmarkRows(\n dataset: PublicAnalystBenchmarkDataset,\n rows: readonly Record<string, unknown>[],\n options: { limit: number; seed: number },\n): Array<Record<string, unknown>> {\n positiveSafeInteger(options.limit, 'limit')\n safeInteger(options.seed, 'seed')\n if (rows.length === 0) throw new Error('public analyst benchmark dataset has no rows')\n\n const byId = new Map<string, Record<string, unknown>>()\n for (const row of rows) {\n const id = publicBenchmarkRowId(dataset, row)\n if (byId.has(id)) {\n throw new Error(`public analyst benchmark dataset repeats trajectory id '${id}'`)\n }\n byId.set(id, row)\n }\n\n return [...byId]\n .sort(\n ([left], [right]) =>\n compareCodeUnits(selectionKey(options.seed, left), selectionKey(options.seed, right)) ||\n compareCodeUnits(left, right),\n )\n .slice(0, Math.min(options.limit, byId.size))\n .map(([, row]) => row)\n}\n\nexport function publicBenchmarkDistributions(\n dataset: PublicAnalystBenchmarkDataset,\n rows: readonly Record<string, unknown>[],\n): PublicBenchmarkDistributions {\n const values: Record<keyof PublicBenchmarkDistributions, Array<string | undefined>> = {\n class: [],\n agent: [],\n model: [],\n difficulty: [],\n solved: [],\n }\n for (const row of rows) {\n const benchmarkCase =\n dataset === 'agentrx'\n ? agentRxBenchmarkCase(row as unknown as AgentRxRow, undefined)\n : codeTraceBenchCase(row as unknown as CodeTraceBenchRow, undefined)\n values.class.push(\n dataset === 'codetracebench'\n ? benchmarkCase.expectedIssues.length > 0\n ? 'positive'\n : row.solved === true\n ? 'trusted-negative'\n : row.solved === false\n ? 'unlabeled-failure'\n : 'unlabeled-unknown'\n : benchmarkCase.expectedIssues[0]?.areas?.[0],\n )\n values.agent.push(\n scalarDistributionValue(row.agent) ??\n (dataset === 'agentrx' ? rootAgent(row as unknown as AgentRxRow) : undefined),\n )\n values.model.push(scalarDistributionValue(row.model))\n values.difficulty.push(scalarDistributionValue(row.difficulty))\n values.solved.push(scalarDistributionValue(row.solved))\n }\n return {\n class: valueDistribution(values.class),\n agent: valueDistribution(values.agent),\n model: valueDistribution(values.model),\n difficulty: valueDistribution(values.difficulty),\n solved: valueDistribution(values.solved),\n }\n}\n\nexport function publicBenchmarkSelectionReport(\n dataset: PublicAnalystBenchmarkDataset,\n source: readonly Record<string, unknown>[],\n selected: readonly Record<string, unknown>[],\n seed: number,\n): PublicBenchmarkSelectionReport {\n const census = source.length === selected.length\n return {\n method: census ? 'census' : 'deterministic-hash',\n seed,\n sourceCount: source.length,\n selectedCount: selected.length,\n stratified: false,\n representativeOfInput: census,\n source: publicBenchmarkDistributions(dataset, source),\n selected: publicBenchmarkDistributions(dataset, selected),\n }\n}\n\nexport async function preparePublicAnalystBenchmark(options: {\n dataset: PublicAnalystBenchmarkDataset\n labelsPath: string\n traceDir: string\n artifactDir?: string\n maxArtifactBytes?: number\n limit: number\n seed: number\n}): Promise<PreparedPublicAnalystBenchmark> {\n const labelsPath = resolve(options.labelsPath)\n const traceRoot = resolve(options.traceDir)\n const labelSnapshot = await readImmutableInputSnapshot(\n labelsPath,\n DEFAULT_MAX_PUBLIC_BENCHMARK_LABEL_BYTES,\n )\n const rows = parsePublicBenchmarkRows(labelSnapshot.text, labelsPath)\n const selected = selectPublicBenchmarkRows(options.dataset, rows, {\n limit: options.limit,\n seed: options.seed,\n })\n const selectedTrajectoryIds = new Set(\n selected.map((row) => publicBenchmarkRowId(options.dataset, row)),\n )\n const stores = await indexSelectedSingleTraceFiles(traceRoot, selectedTrajectoryIds)\n const resolver = traceStoreEvidenceResolver<AnalystRunInputs>((input) => {\n if (!input.traceStore) throw new Error('prepared benchmark case has no trace store')\n return input.traceStore\n })\n const traceFiles: PreparedPublicAnalystBenchmark['traceFiles'] = []\n const verificationArtifacts: VerificationArtifactManifest[] = []\n const cases: AnalystBenchmarkCase<AnalystRunInputs>[] = []\n\n for (const row of selected) {\n const trajectoryId = publicBenchmarkRowId(options.dataset, row)\n const indexed = stores.get(trajectoryId)\n if (!indexed) {\n throw new Error(\n `public analyst benchmark trace directory has no single-trace OTLP JSONL for '${trajectoryId}'`,\n )\n }\n let modelVisibleOtlp = indexed.text\n let traceStore = indexed.store\n let artifactDir: string | undefined\n let verificationManifest: VerificationArtifactManifest | undefined\n if (options.dataset === 'codetracebench') {\n if (!options.artifactDir?.trim()) {\n throw new Error(\n '--artifact-dir is required for CodeTraceBench so final verification evidence is not omitted',\n )\n }\n const artifactRoot = await realpath(options.artifactDir)\n const artifacts = await loadCodeTraceVerificationArtifacts({\n artifactDir: artifactRoot,\n row: row as unknown as CodeTraceBenchRow,\n maxBytes: options.maxArtifactBytes ?? DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES,\n })\n for (const artifact of artifacts.files) {\n assertNoBenchmarkLabelsInArtifact({\n traceId: trajectoryId,\n relativePath: artifact.relativePath,\n content: artifact.content,\n })\n }\n verificationManifest = shareableVerificationManifest(artifacts.manifest, artifactRoot)\n const collisions = await indexed.store.hasSpans({\n trace_id: trajectoryId,\n span_ids: [\n ...artifacts.manifest.files.map((file) => file.spanId),\n artifacts.manifest.outcomeSpanId,\n ],\n })\n if (collisions.length > 0) {\n throw new Error(\n `CodeTraceBench '${trajectoryId}' trace already contains benchmark verification span '${collisions[0]}'`,\n )\n }\n modelVisibleOtlp = appendVerificationArtifactsToOtlp(\n indexed.text,\n trajectoryId,\n artifacts,\n indexed.latestTimestamp,\n )\n traceStore = otlpTextToTraceAnalysisStore(modelVisibleOtlp)\n artifactDir =\n artifacts.manifest.status === 'present' ? artifacts.manifest.caseDirectory : undefined\n verificationArtifacts.push(verificationManifest)\n }\n const labelLeakScan = assertNoBenchmarkLabelsInTrace({\n traceId: trajectoryId,\n otlpText: modelVisibleOtlp,\n })\n\n const input: AnalystRunInputs = { traceStore, artifactDir }\n const benchmarkCase =\n options.dataset === 'agentrx'\n ? agentRxBenchmarkCase(row as unknown as AgentRxRow, input, {\n stepCount: indexed.stepCount,\n })\n : codeTraceBenchCase(row as unknown as CodeTraceBenchRow, input)\n\n for (const evidence of benchmarkCase.labeledEvidence ?? []) {\n const resolved = await resolver({\n caseId: benchmarkCase.id,\n caseInput: input,\n evidence: { kind: evidence.kind ?? 'span', uri: evidence.uri },\n })\n if (!resolved) {\n throw new Error(\n `${benchmarkCase.id}: missing labeled span ${spanIdFromEvidence(evidence.uri) ?? evidence.uri} in ${indexed.path}`,\n )\n }\n }\n\n cases.push({\n ...benchmarkCase,\n metadata: {\n ...benchmarkCase.metadata,\n traceFileRelativePath: slashRelative(traceRoot, indexed.path),\n traceFileSha256: indexed.sha256,\n labelLeakScan,\n ...(verificationManifest ? { verificationArtifacts: verificationManifest } : {}),\n },\n })\n traceFiles.push({\n traceId: trajectoryId,\n relativePath: slashRelative(traceRoot, indexed.path),\n sha256: indexed.sha256,\n })\n }\n\n return {\n cases,\n sourceRowCount: rows.length,\n selectedCaseIds: cases.map((testCase) => testCase.id),\n labelsSha256: labelSnapshot.sha256,\n traceFiles,\n verificationArtifacts,\n selection: publicBenchmarkSelectionReport(options.dataset, rows, selected, options.seed),\n }\n}\n\nasync function indexSelectedSingleTraceFiles(\n traceDir: string,\n selectedTraceIds: ReadonlySet<string>,\n): Promise<\n Map<\n string,\n {\n path: string\n sha256: string\n store: TraceAnalysisStore\n latestTimestamp: string\n text: string\n stepCount: number\n }\n >\n> {\n if (selectedTraceIds.size === 0) {\n throw new Error('public analyst benchmark selected no trace ids')\n }\n const entries = await readdir(traceDir, { withFileTypes: true })\n const files = entries\n .filter((entry) => entry.isFile() && entry.name.endsWith('.jsonl'))\n .map((entry) => resolve(traceDir, entry.name))\n .sort()\n if (files.length === 0) {\n throw new Error(`public analyst benchmark trace directory has no JSONL files: ${traceDir}`)\n }\n\n const indexed = new Map<\n string,\n {\n path: string\n sha256: string\n store: TraceAnalysisStore\n latestTimestamp: string\n text: string\n stepCount: number\n }\n >()\n for (const path of files) {\n const snapshot = await readImmutableInputSnapshot(path, DEFAULT_MAX_TRACE_FILE_BYTES)\n const store = createOtlpBufferTraceStore(snapshot.bytes)\n const overview = await store.getOverview()\n if (overview.total_traces !== 1 || overview.sample_trace_ids.length !== 1) {\n throw new Error(\n `public analyst benchmark trace file must contain exactly one trace: ${path} contains ${overview.total_traces}`,\n )\n }\n if (!overview.time_range) {\n throw new Error(`public analyst benchmark trace file has no valid timestamps: ${path}`)\n }\n const traceId = overview.sample_trace_ids[0]!\n if (!selectedTraceIds.has(traceId)) continue\n if (indexed.has(traceId)) {\n throw new Error(`public analyst benchmark trace id '${traceId}' appears in multiple files`)\n }\n indexed.set(traceId, {\n path,\n sha256: snapshot.sha256,\n store,\n latestTimestamp: overview.time_range.latest,\n text: snapshot.text,\n stepCount: traceStepCount(snapshot.text, path),\n })\n }\n return indexed\n}\n\nasync function readImmutableInputSnapshot(\n path: string,\n maxBytes: number,\n): Promise<ImmutableInputSnapshot> {\n if (!Number.isSafeInteger(maxBytes) || maxBytes < 1) {\n throw new RangeError('benchmark input maxBytes must be a positive safe integer')\n }\n const handle = await open(path, INPUT_OPEN_FLAGS)\n try {\n return await readImmutableInputHandle(handle, path, maxBytes)\n } finally {\n await handle.close()\n }\n}\n\nasync function readImmutableInputHandle(\n handle: FileHandle,\n path: string,\n maxBytes: number,\n): Promise<ImmutableInputSnapshot> {\n const before = await handle.stat({ bigint: true })\n if (!before.isFile()) {\n throw new TypeError(`public analyst benchmark input must be a regular file: ${path}`)\n }\n if (before.size > BigInt(maxBytes)) {\n throw new RangeError(\n `public analyst benchmark input exceeds ${maxBytes} bytes: ${path} has ${before.size}`,\n )\n }\n\n const size = Number(before.size)\n const bytes = Buffer.allocUnsafe(size)\n let offset = 0\n while (offset < size) {\n const result = await handle.read(bytes, offset, size - offset, offset)\n if (result.bytesRead === 0) {\n throw new Error(`public analyst benchmark input changed while being read: ${path}`)\n }\n offset += result.bytesRead\n }\n const overflow = Buffer.allocUnsafe(1)\n const extra = await handle.read(overflow, 0, 1, size)\n const after = await handle.stat({ bigint: true })\n if (\n extra.bytesRead !== 0 ||\n before.dev !== after.dev ||\n before.ino !== after.ino ||\n before.size !== after.size ||\n before.mtimeNs !== after.mtimeNs ||\n before.ctimeNs !== after.ctimeNs\n ) {\n throw new Error(`public analyst benchmark input changed while being read: ${path}`)\n }\n\n let text: string\n try {\n text = new TextDecoder('utf-8', { fatal: true }).decode(bytes)\n } catch (error) {\n throw new TypeError(\n `public analyst benchmark input is not valid UTF-8: ${path}: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n return Object.freeze({\n bytes,\n sha256: sha256Digest(bytes),\n text,\n })\n}\n\nfunction traceStepCount(text: string, path: string): number {\n const steps = parseJsonl(text, path)\n .map((row) => row.span_id)\n .filter((spanId): spanId is string => typeof spanId === 'string')\n .map((spanId) => /^step-(\\d+)$/.exec(spanId)?.[1])\n .filter((step): step is string => step !== undefined)\n .map(Number)\n .filter((step) => Number.isSafeInteger(step) && step > 0)\n if (steps.length === 0) {\n throw new Error(`public analyst benchmark trace has no step-<n> spans: ${path}`)\n }\n return Math.max(...steps)\n}\n\nfunction shareableVerificationManifest(\n manifest: VerificationArtifactManifest,\n artifactRoot: string,\n): VerificationArtifactManifest {\n return {\n ...manifest,\n caseDirectory: slashRelative(artifactRoot, manifest.caseDirectory),\n caseDirectoriesSearched: manifest.caseDirectoriesSearched.map((path) =>\n slashRelative(artifactRoot, path),\n ),\n files: manifest.files.map((file) => ({\n ...file,\n path: slashRelative(artifactRoot, file.path),\n })),\n }\n}\n\nfunction slashRelative(root: string, path: string): string {\n const value = relative(root, path)\n if (!value || value === '..' || value.startsWith(`..${sep}`)) {\n if (!value) return '.'\n throw new Error(`benchmark artifact path escapes its declared root: ${path}`)\n }\n return value.replaceAll('\\\\', '/')\n}\n\nfunction parseJsonl(text: string, path: string): Array<Record<string, unknown>> {\n const rows: Array<Record<string, unknown>> = []\n for (const [index, line] of text.split(/\\r?\\n/).entries()) {\n const trimmed = line.trim()\n if (!trimmed) continue\n let parsed: unknown\n try {\n parsed = JSON.parse(trimmed)\n } catch (error) {\n throw new Error(\n `${path}:${index + 1}: invalid JSON: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n if (!isRecord(parsed)) {\n throw new TypeError(`${path}:${index + 1}: dataset row must be a JSON object`)\n }\n rows.push(parsed)\n }\n if (rows.length === 0) throw new Error(`public analyst benchmark dataset is empty: ${path}`)\n return rows\n}\n\nfunction records(values: readonly unknown[], path: string): Array<Record<string, unknown>> {\n return values.map((value, index) => {\n if (!isRecord(value)) throw new TypeError(`${path}[${index}] must be a JSON object`)\n return value\n })\n}\n\nfunction publicBenchmarkRowId(\n dataset: PublicAnalystBenchmarkDataset,\n row: Record<string, unknown>,\n): string {\n const value = dataset === 'agentrx' ? row.trajectory_id : row.traj_id\n if ((typeof value !== 'string' && typeof value !== 'number') || !String(value).trim()) {\n throw new TypeError(\n `${dataset} dataset row requires a non-empty ${dataset === 'agentrx' ? 'trajectory_id' : 'traj_id'}`,\n )\n }\n return String(value)\n}\n\nfunction spanIdFromEvidence(uri: string): string | null {\n const match = /\\/span\\/([^/]+)$/.exec(uri)\n return match?.[1] ? decodeURIComponent(match[1]) : null\n}\n\nfunction selectionKey(seed: number, id: string): string {\n return sha256Digest(`${seed}\\u0000${id}`)\n}\n\nfunction valueDistribution(\n values: readonly (string | undefined)[],\n): PublicBenchmarkValueDistribution {\n const counts = new Map<string, number>()\n let missing = 0\n for (const value of values) {\n if (value === undefined) {\n missing += 1\n continue\n }\n counts.set(value, (counts.get(value) ?? 0) + 1)\n }\n return {\n total: values.length,\n missing,\n counts: Object.fromEntries([...counts].sort(([left], [right]) => left.localeCompare(right))),\n }\n}\n\nfunction scalarDistributionValue(value: unknown): string | undefined {\n if (typeof value === 'string') return value.trim() || undefined\n if (typeof value === 'number' || typeof value === 'boolean') return String(value)\n return undefined\n}\n\nfunction rootAgent(row: AgentRxRow): string | undefined {\n const rootCauseId = row.root_cause_failure_id ?? row.root_cause?.failure_id\n const root = row.failures.find((failure) => String(failure.failure_id) === String(rootCauseId))\n return scalarDistributionValue(root?.failed_agent)\n}\n","import { request as httpRequest } from 'node:http'\nimport { request as httpsRequest } from 'node:https'\n\n/**\n * The bridge seam for the prime analyst protocol: one POST to an\n * OpenAI-compatible `/v1/chat/completions` endpoint, returning the raw status\n * and body text.\n *\n * Deliberately NOT `callLlm` from `../llm-client`, which serves a different\n * contract:\n * - it retries transient failures, and a prime turn holds a single model seat\n * for minutes — a silent second attempt doubles the seat time and the spend;\n * - it normalizes usage, while the protocol's receipt depends on the bridge's\n * non-standard `model_requests` and `estimated` fields;\n * - it composes sampling and response-format options the bridge's CLI backends\n * reject;\n * - it collapses HTTP status, unparseable body, and empty content into two\n * error classes, while the protocol classifies them as three distinct\n * terminal reasons.\n */\nexport interface PrimeBridgeTransportRequest {\n url: string\n body: {\n model: string\n messages: Array<{ role: 'user'; content: string }>\n }\n /**\n * The call's only deadline. The protocol aborts it on the per-call timeout\n * and on the caller's cancellation, so a transport that imposes a second\n * deadline of its own competes with this one.\n */\n signal: AbortSignal\n}\n\nexport interface PrimeBridgeTransportResult {\n status: number\n text: string\n}\n\n/** One POST to the bridge. Injectable so tests run against a fake bridge. */\nexport type PrimeBridgeTransport = (\n request: PrimeBridgeTransportRequest,\n) => Promise<PrimeBridgeTransportResult>\n\n/**\n * Default transport on node:http/node:https rather than fetch: undici's fixed\n * response-header timeout kills prime calls that legitimately run past five\n * minutes, so the request's AbortSignal is the only deadline.\n */\nexport function nodeHttpPrimeBridgeTransport(): PrimeBridgeTransport {\n return ({ url, body, signal }) => {\n const target = new URL(url)\n if (target.protocol !== 'http:' && target.protocol !== 'https:') {\n throw new TypeError(`bridge URL must be http: or https:, got ${target.protocol}`)\n }\n const send = target.protocol === 'https:' ? httpsRequest : httpRequest\n const encoded = JSON.stringify(body)\n return new Promise((resolvePromise, rejectPromise) => {\n const req = send(\n {\n hostname: target.hostname,\n port: target.port,\n // The query string is part of the caller's URL; dropping it would\n // send the request somewhere other than where the caller pointed.\n path: `${target.pathname}${target.search}`,\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n 'content-length': Buffer.byteLength(encoded),\n },\n signal,\n },\n (res) => {\n const chunks: Buffer[] = []\n res.on('data', (chunk: Buffer) => chunks.push(chunk))\n res.on('end', () =>\n resolvePromise({\n status: res.statusCode ?? 0,\n text: Buffer.concat(chunks).toString('utf8'),\n }),\n )\n res.on('error', rejectPromise)\n },\n )\n req.on('error', rejectPromise)\n req.end(encoded)\n })\n }\n}\n","import type { CustomTokenPricing } from '../cost-ledger'\nimport { resolveModelPricing } from '../metrics'\nimport type { TraceAnalysisStore, TraceAnalysisStoreContext } from '../trace-analyst/store'\nimport type { TraceAnalystSpan } from '../trace-analyst/types'\nimport type { AnalystBenchmarkRunner } from './benchmark'\nimport {\n type CodeTraceFailureBlock,\n expandCodeTraceFailureBlocks,\n} from './benchmark-public-adapters'\nimport { publicBenchmarkError } from './benchmark-public-errors'\nimport {\n CODE_TRACE_BENCH_ANALYST_PROMPT,\n MAX_INCORRECT_BLOCK_STEPS,\n MAX_INCORRECT_BLOCKS,\n} from './benchmark-public-prompt'\nimport { positiveSafeInteger, requiredString } from './benchmark-public-types'\nimport { type AnalystDefinition, AnalystExpressivenessError } from './definition'\nimport { nodeHttpPrimeBridgeTransport, type PrimeBridgeTransport } from './prime-bridge-transport'\nimport {\n analystUsageReceiptFromPrimeUsage,\n buildPrimePrompt,\n type PrimeFailure,\n type PrimeProjectionSource,\n type PrimeProtocolIdentity,\n type PrimeReplyContract,\n type PrimeTurnRecord,\n primeProtocolSha256,\n projectPrimeTrajectory,\n runPrimeExchange,\n} from './prime-protocol'\nimport type { AnalystRunInputs, AnalystSeverity, AnalystUsageReceipt } from './types'\n\n/**\n * Prime analyst arm: the RLM coding agent reached through an OpenAI-compatible\n * cli-bridge solves the CodeTraceBench incorrect-step task as a one-shot trace\n * analyst.\n *\n * The arm is expressed as an `AnalystDefinition`\n * (`primeCodeTraceAnalystDefinition`): the question, task text, output\n * contract, inline projection budget, and repair-turn declaration are all\n * definition content, and `createPrimeBenchmarkRunner` is a thin shell that\n * builds the definition and runs it through the inline strategy below. The\n * same strategy is what `bindAnalyst` (./bind) dispatches to, so a compiled\n * definition and this entry point send byte-identical requests — the parity\n * suite asserts exactly that.\n *\n * The protocol machinery — prompt composition, the bounded repair turn, reply\n * extraction, the projection ladder, usage normalization — lives in\n * `./prime-protocol`, which knows nothing about CodeTraceBench. This file adds\n * the benchmark's binding to it (block row grammar, store-backed projection,\n * observation shape) plus the projection-generic inline execution strategy.\n *\n * Trajectory delivery is inline JSON in the prompt. The dspy typed path binds\n * the viewTrace span projection as a REPL variable; prime has no REPL, so the\n * same projection is serialized into the prompt. When the full projection is\n * oversized the strategy falls back to chunked viewSpans over the same\n * projection surface with a per-attribute byte cap, and fails loud if the\n * result still exceeds the inline budget.\n *\n * A structurally malformed reply gets ONE bounded repair turn (disable with\n * `repair: false`): a second stateless call carrying the malformed reply plus\n * the output contract — never the trajectory — mirroring the dspy arm's typed\n * repair so both arms face the same structured-output affordance. Still\n * malformed after repair = failed observation with a typed error, exactly how\n * a dspy-rlm failure is recorded. Zero valid blocks from a well-formed reply\n * is an honest null, not a failure.\n */\n\nconst PRIME_ANALYST_ID = 'prime'\nconst PRIME_QUESTION = 'Which assistant steps are incorrect under the CodeTraceBench definition?'\n/** Ceiling on the serialized trajectory JSON embedded in the prompt. */\nconst MAX_INLINE_TRAJECTORY_CHARS = 360_000\n/** Per-attribute projection cap used by the chunked viewSpans fallback. */\nconst CHUNKED_PROJECTION_ATTRIBUTE_BYTE_CAP = 1_200\n/** Minimal per-attribute cap used only to enumerate span ids in store order. */\nconst SPAN_ID_ENUMERATION_ATTRIBUTE_BYTE_CAP = 64\n/** viewSpans accepts at most 100 ids per call; 40 keeps each response bounded. */\nconst VIEW_SPANS_CHUNK_SIZE = 40\nconst PRIME_SEVERITIES: ReadonlySet<string> = new Set(['critical', 'high', 'medium', 'low', 'info'])\n\nexport interface PrimeBenchmarkRunnerOptions {\n /** OpenAI-compatible cli-bridge base URL, e.g. `http://localhost:4181`. */\n baseUrl: string\n /** Bridge model id in `<backend>/<provider>/<model>` form, e.g. `prime/zai/glm-5.2`. */\n model: string\n /** Deadline for one bridge call. Prime analyses routinely exceed 5 minutes. */\n timeoutMs: number\n /** Whether a structurally malformed reply gets one bounded repair turn. */\n repair: boolean\n /** Exact token rates. Default: the agent-eval catalog rates for `model`. */\n pricing?: CustomTokenPricing\n /** Bridge transport. Default: node:http POST (see nodeHttpPrimeBridgeTransport). */\n transport?: PrimeBridgeTransport\n}\n\nexport class PrimeBridgeTransportError extends Error {}\nexport class PrimeBridgeHttpError extends Error {\n readonly status: number\n constructor(status: number, bodySnippet: string) {\n super(`bridge HTTP ${status}: ${bodySnippet}`)\n this.status = status\n }\n}\nexport class PrimeMalformedReplyError extends Error {}\nexport class PrimeTraceProjectionError extends Error {}\n\n/**\n * Short-strings rule: long reply strings get corrupted when the bridge splices\n * its backend's stream, so the contract forbids a rationale field and caps\n * every string the model must emit.\n */\nconst PRIME_OUTPUT_CONTRACT_LINES: readonly string[] = [\n 'OUTPUT CONTRACT (supersedes any transport wording above — you have no trace tools and no REPL):',\n 'You are a one-shot analyst. Every fact you need is in the TRAJECTORY JSON below.',\n 'Do not run shell commands, do not read or write files, do not use any tools.',\n 'Reply with EXACTLY one fenced ```json code block and no other fenced block. The JSON object has exactly two fields:',\n ' \"answer\": string — ONE short sentence (max 300 chars) naming the latest failure evidence you traced from.',\n ' \"blocks\": array (possibly empty) of failure blocks, each exactly:',\n ' {\"first_step\": int, \"last_step\": int, \"consequence_step\": int,',\n ' \"escape_status\": \"escaped\"|\"unescaped\",',\n ' \"severity\": \"critical\"|\"high\"|\"medium\"|\"low\"|\"info\",',\n ' \"claim\": string (ONE short sentence, max 200 chars),',\n ' \"confidence\": number 0..1}',\n 'Do NOT include a rationale field. Keep every string SHORT — long strings get corrupted in transport and void your work.',\n `Report at most ${MAX_INCORRECT_BLOCKS} blocks; a block spans at most ${MAX_INCORRECT_BLOCK_STEPS} steps.`,\n 'Every step number must be the n of an existing assistant span with span_id \"step-<n>\" and kind \"LLM\" in the trajectory below; never cite TOOL, CHAIN, or AGENT spans.',\n '\"blocks\" is [] only for a clean trajectory.',\n]\n\nconst PRIME_REPAIR_CONTRACT_LINES: readonly string[] = [\n ' \"answer\": string (ONE short sentence, max 300 chars)',\n ' \"blocks\": array (possibly empty) of {\"first_step\": int, \"last_step\": int, \"consequence_step\": int,',\n ' \"escape_status\": \"escaped\"|\"unescaped\", \"severity\": \"critical\"|\"high\"|\"medium\"|\"low\"|\"info\",',\n ' \"claim\": string (max 200 chars), \"confidence\": number 0..1}',\n 'No rationale field. Keep every string SHORT. Preserve the step numbers and verdicts of your previous reply exactly; shorten prose freely.',\n]\n\nconst PRIME_PROTOCOL_IDENTITY: PrimeProtocolIdentity = {\n question: PRIME_QUESTION,\n taskDefinition: CODE_TRACE_BENCH_ANALYST_PROMPT,\n contractLines: PRIME_OUTPUT_CONTRACT_LINES,\n repairContractLines: PRIME_REPAIR_CONTRACT_LINES,\n limits: {\n maxBlocks: MAX_INCORRECT_BLOCKS,\n maxBlockSteps: MAX_INCORRECT_BLOCK_STEPS,\n maxInlineTrajectoryChars: MAX_INLINE_TRAJECTORY_CHARS,\n chunkedProjectionAttributeByteCap: CHUNKED_PROJECTION_ATTRIBUTE_BYTE_CAP,\n },\n}\n\n/**\n * The block row grammar. No `maxRows`: the count cap belongs to\n * `expandCodeTraceFailureBlocks`, which drops the offending block and names it\n * in `diagnostics.droppedBlocks`, so capping here would erase that record.\n */\nconst PRIME_BLOCK_CONTRACT: PrimeReplyContract<CodeTraceFailureBlock> = {\n rowsField: 'blocks',\n contractLines: PRIME_OUTPUT_CONTRACT_LINES,\n repairContractLines: PRIME_REPAIR_CONTRACT_LINES,\n decodeRow(row) {\n const reason = blockRowDefect(row)\n if (reason !== null) return { ok: false, reason }\n return { ok: true, row: blockFromRow(row as PrimeBlockRow) }\n },\n}\n\n/**\n * Digest of everything this arm can send to the bridge, recorded per\n * observation so a prime result names the exact contract that produced it.\n */\nexport function primeAnalystProtocolSha256(): string {\n return primeProtocolSha256(PRIME_PROTOCOL_IDENTITY)\n}\n\nexport interface PrimeCodeTraceDefinitionArgs {\n /** Deadline for one bridge call. */\n timeoutMs: number\n /** 1 grants the bounded repair turn; 0 disables it. */\n repairTurns: number\n}\n\n/**\n * The prime arm as a declarative unit. CodeTraceBench-only: the question,\n * task text, and block grammar speak its incorrect-step definition.\n */\nexport function primeCodeTraceAnalystDefinition(\n args: PrimeCodeTraceDefinitionArgs,\n): AnalystDefinition<CodeTraceFailureBlock> {\n return {\n id: PRIME_ANALYST_ID,\n description:\n 'One-shot RLM over an OpenAI-compatible bridge answering the CodeTraceBench incorrect-step task.',\n version: '1.0.0',\n area: 'incorrect',\n // The bridge owns model selection and reasoning control; the fragment pins nothing.\n profile: {},\n question: PRIME_QUESTION,\n taskDefinition: CODE_TRACE_BENCH_ANALYST_PROMPT,\n projection: {\n mode: 'inline',\n maxInlineChars: MAX_INLINE_TRAJECTORY_CHARS,\n cappedAttributeBytes: CHUNKED_PROJECTION_ATTRIBUTE_BYTE_CAP,\n },\n replyContract: PRIME_BLOCK_CONTRACT,\n // Insertion order is digest-bearing: it mirrors PRIME_PROTOCOL_IDENTITY.limits.\n contractLimits: {\n maxBlocks: MAX_INCORRECT_BLOCKS,\n maxBlockSteps: MAX_INCORRECT_BLOCK_STEPS,\n },\n budget: { timeoutMs: args.timeoutMs },\n repair: { turns: args.repairTurns },\n protocolSha256: primeAnalystProtocolSha256(),\n binding: {\n kind: 'inline',\n subjectFromCaseId: trajectoryIdFromCaseId,\n baseMetadata: { analysisMode: 'prime-rlm', engine: 'prime' },\n header(subject, spans) {\n const stepSpans = spans.filter((span) => /^step-\\d+$/.test(String(span.span_id)))\n if (stepSpans.length === 0) {\n throw new PrimeTraceProjectionError(`no step-<n> spans in trace '${subject}'`)\n }\n return `TRAJECTORY (trace_id ${subject}; ${stepSpans.length} assistant step spans; full span projection as JSON):`\n },\n trailer(_subject, spans) {\n const finalVerification = spans.filter(isFinalVerificationSpan)\n return finalVerification.length > 0\n ? `FINAL VERIFICATION SPANS:\\n${JSON.stringify(finalVerification)}`\n : 'FINAL VERIFICATION: unavailable for this trajectory — trace backward from the latest failure evidence inside the trajectory itself.'\n },\n async expandRows({ subject, rows, store, analystId, signal }) {\n const expanded = await expandCodeTraceFailureBlocks({\n trajectoryId: subject,\n blocks: rows,\n store,\n analystId,\n ...(signal ? { signal } : {}),\n })\n return { findings: expanded.findings, diagnostics: expanded.diagnostics }\n },\n },\n }\n}\n\n/** Thin shell: validate options, declare the definition, run the inline strategy. */\nexport function createPrimeBenchmarkRunner(\n options: PrimeBenchmarkRunnerOptions,\n): AnalystBenchmarkRunner<AnalystRunInputs> {\n const timeoutMs = positiveSafeInteger(options.timeoutMs, 'timeoutMs')\n const repair = options.repair\n if (typeof repair !== 'boolean') throw new TypeError('repair must be a boolean')\n return runInlineAnalystDefinition(\n primeCodeTraceAnalystDefinition({ timeoutMs, repairTurns: repair ? 1 : 0 }),\n {\n baseUrl: options.baseUrl,\n model: options.model,\n ...(options.transport ? { transport: options.transport } : {}),\n ...(options.pricing ? { pricing: options.pricing } : {}),\n },\n )\n}\n\n// ── Inline execution strategy ───────────────────────────────────────\n\n/** The transport half of an inline-projection binding: the bridge endpoint. */\nexport interface InlineBridgeTransports {\n /** OpenAI-compatible bridge base URL. */\n baseUrl: string\n /** Bridge model id. */\n model: string\n /** Bridge transport. Default: node:http POST. */\n transport?: PrimeBridgeTransport\n /** Exact token rates. Default: the agent-eval catalog rates for `model`. */\n pricing?: CustomTokenPricing\n}\n\n/**\n * Compile an inline-projection definition into a runnable arm. Projection,\n * prompt composition, the bounded repair turn, and usage accounting are all\n * driven by the definition; nothing in this strategy names a benchmark.\n */\nexport function runInlineAnalystDefinition<TRow>(\n definition: AnalystDefinition<TRow>,\n transports: InlineBridgeTransports,\n): AnalystBenchmarkRunner<AnalystRunInputs> {\n const { projection, binding } = definition\n if (projection.mode !== 'inline' || binding.kind !== 'inline') {\n throw new AnalystExpressivenessError(\n `the inline strategy compiles only inline projections; definition '${definition.id}' ` +\n `declares projection '${projection.mode}' with a '${binding.kind}' binding`,\n )\n }\n if (definition.repair.turns > 1) {\n throw new AnalystExpressivenessError(\n `the inline exchange grants at most one bounded repair turn; definition ` +\n `'${definition.id}' declares ${definition.repair.turns}`,\n )\n }\n const baseUrl = requiredString(transports.baseUrl, 'baseUrl').replace(/\\/+$/, '')\n const model = requiredString(transports.model, 'model')\n const timeoutMs = positiveSafeInteger(definition.budget.timeoutMs, 'timeoutMs')\n const repair = definition.repair.turns === 1\n const pricing = transports.pricing ?? pricingForModel(model)\n const transport = transports.transport ?? nodeHttpPrimeBridgeTransport()\n const url = `${baseUrl}/v1/chat/completions`\n\n return {\n id: definition.id,\n async analyze(input, context) {\n const subject = binding.subjectFromCaseId(context.caseId)\n let usage: AnalystUsageReceipt | undefined\n let metadata: Record<string, unknown> = {\n ...binding.baseMetadata,\n bridgeUrl: baseUrl,\n model,\n protocolSha256: definition.protocolSha256,\n }\n try {\n const store = input.traceStore\n if (!store) throw new Error(`inline analyst '${definition.id}' requires a trace store`)\n const storeContext: TraceAnalysisStoreContext | undefined = context.signal\n ? { signal: context.signal }\n : undefined\n const projected = await projectPrimeTrajectory(\n inlineProjectionSource(store, subject, projection.cappedAttributeBytes, storeContext),\n { maxInlineChars: projection.maxInlineChars },\n )\n if (!projected.ok) throw new PrimeTraceProjectionError(projected.reason)\n const delivery: InlineTrajectoryDelivery = {\n mode: projected.delivery.mode,\n fetch: projected.delivery.fetch === 'full' ? 'view-trace' : 'view-spans-chunked',\n perAttributeByteCap:\n projected.delivery.fetch === 'full' ? null : projection.cappedAttributeBytes,\n renderedChars: projected.delivery.renderedChars,\n }\n metadata = { ...metadata, delivery }\n const prompt = buildPrimePrompt({\n question: definition.question,\n ...(definition.taskDefinition === undefined\n ? {}\n : { taskDefinition: definition.taskDefinition }),\n contractLines: definition.replyContract.contractLines,\n trajectoryHeader: binding.header(subject, projected.items),\n renderedTrajectory: projected.rendered,\n trailer: binding.trailer(subject, projected.items),\n })\n metadata = { ...metadata, promptChars: prompt.length }\n\n const outcome = await runPrimeExchange({\n contract: definition.replyContract,\n prompt,\n transport,\n url,\n model,\n timeoutMs,\n repair,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n if (!outcome.ok && outcome.failure.kind === 'aborted') throw abortCause(outcome.failure)\n if (outcome.turns.length > 0) {\n usage = analystUsageReceiptFromPrimeUsage(outcome.usage, pricing)\n metadata = { ...metadata, bridgeUsage: bridgeUsageFromTurns(outcome.turns) }\n }\n metadata = { ...metadata, repair: outcome.repair }\n if (!outcome.ok) {\n // The raw reply is the diagnostic artifact for a malformed case.\n if (outcome.reply !== undefined) {\n metadata = { ...metadata, reply: outcome.reply.slice(0, 4_000) }\n }\n throw primeFailureError(outcome.failure)\n }\n\n const expanded = await binding.expandRows({\n subject,\n rows: outcome.rows,\n store,\n analystId: definition.id,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n return {\n findings: expanded.findings,\n usage,\n metadata: {\n ...metadata,\n answer: outcome.answer,\n reportedRows: outcome.reportedRows,\n rejectedRows: outcome.rejected,\n blockDiagnostics: expanded.diagnostics,\n },\n }\n } catch (error) {\n if (context.signal?.aborted) throw error\n return {\n findings: [],\n ...(usage ? { usage } : {}),\n error: publicBenchmarkError(error, []),\n metadata,\n }\n }\n },\n }\n}\n\ninterface InlineTrajectoryDelivery {\n mode: 'inline-json'\n fetch: 'view-trace' | 'view-spans-chunked'\n perAttributeByteCap: number | null\n renderedChars: number\n}\n\n/**\n * The trace store, seen through the protocol's two-move projection contract:\n * the full viewTrace projection, or the chunked viewSpans projection at a\n * per-attribute byte cap.\n */\nfunction inlineProjectionSource(\n store: TraceAnalysisStore,\n trajectoryId: string,\n cappedAttributeBytes: number,\n context: TraceAnalysisStoreContext | undefined,\n): PrimeProjectionSource<TraceAnalystSpan> {\n return {\n async full() {\n const view = await store.viewTrace({ trace_id: trajectoryId }, context)\n return view.spans ?? null\n },\n capped: () => projectSpansChunked(store, trajectoryId, cappedAttributeBytes, context),\n cappedDescription: `per-attribute cap ${cappedAttributeBytes}`,\n }\n}\n\n/**\n * Chunked viewSpans projection for traces whose full viewTrace response is\n * oversized. Span ids come from a minimal-cap viewTrace in store order; every\n * id must project or the case fails loud — a silently dropped span would\n * understate the trajectory.\n */\nasync function projectSpansChunked(\n store: TraceAnalysisStore,\n trajectoryId: string,\n cappedAttributeBytes: number,\n context: TraceAnalysisStoreContext | undefined,\n): Promise<TraceAnalystSpan[]> {\n const enumeration = await store.viewTrace(\n { trace_id: trajectoryId, per_attribute_byte_cap: SPAN_ID_ENUMERATION_ATTRIBUTE_BYTE_CAP },\n context,\n )\n if (!enumeration.spans) {\n throw new PrimeTraceProjectionError(\n `trace '${trajectoryId}' is oversized even at per-attribute cap ${SPAN_ID_ENUMERATION_ATTRIBUTE_BYTE_CAP}; cannot enumerate span ids`,\n )\n }\n const ids: string[] = []\n const seen = new Set<string>()\n for (const span of enumeration.spans) {\n if (typeof span.span_id === 'string' && span.span_id.length > 0 && !seen.has(span.span_id)) {\n seen.add(span.span_id)\n ids.push(span.span_id)\n }\n }\n if (ids.length === 0) {\n throw new PrimeTraceProjectionError(`no span ids parsed from trace '${trajectoryId}'`)\n }\n const projected: TraceAnalystSpan[] = []\n for (let index = 0; index < ids.length; index += VIEW_SPANS_CHUNK_SIZE) {\n const chunk = ids.slice(index, index + VIEW_SPANS_CHUNK_SIZE)\n const result = await store.viewSpans(\n {\n trace_id: trajectoryId,\n span_ids: chunk,\n per_attribute_byte_cap: cappedAttributeBytes,\n },\n context,\n )\n if (\n result.missing_span_ids.length > 0 ||\n result.omitted_span_ids.length > 0 ||\n result.spans.length !== chunk.length\n ) {\n throw new PrimeTraceProjectionError(\n `viewSpans projected ${result.spans.length}/${chunk.length} spans for chunk at ${index} of '${trajectoryId}'`,\n )\n }\n projected.push(...result.spans)\n }\n return projected\n}\n\n/** Map the protocol's terminal reason onto this benchmark's typed error classes. */\nfunction primeFailureError(failure: PrimeFailure): Error {\n switch (failure.kind) {\n case 'http-status':\n return new PrimeBridgeHttpError(failure.status, failure.bodySnippet)\n case 'malformed-reply':\n return new PrimeMalformedReplyError(failure.message)\n default:\n return new PrimeBridgeTransportError(failure.message)\n }\n}\n\n/** A cancelled run is not a result: the caller's error propagates unchanged. */\nfunction abortCause(failure: Extract<PrimeFailure, { kind: 'aborted' }>): unknown {\n return failure.cause instanceof Error ? failure.cause : new Error(failure.message)\n}\n\nfunction bridgeUsageFromTurns(turns: readonly PrimeTurnRecord[]): Record<string, unknown> {\n return {\n first: turns.find((turn) => turn.turn === 'first')?.rawUsage ?? null,\n repair: turns.find((turn) => turn.turn === 'repair')?.rawUsage ?? null,\n }\n}\n\nfunction isFinalVerificationSpan(span: TraceAnalystSpan): boolean {\n if (span.span_id.startsWith('benchmark-verification')) return true\n const role = span.attributes['benchmark.evidence.role']\n return typeof role === 'string' && role.startsWith('final-verification')\n}\n\nfunction trajectoryIdFromCaseId(caseId: string): string {\n const prefix = 'codetrace:'\n if (!caseId.startsWith(prefix) || caseId.length === prefix.length) {\n throw new Error(`unexpected codetracebench benchmark case id '${caseId}'`)\n }\n return caseId.slice(prefix.length)\n}\n\ninterface PrimeBlockRow {\n first_step: number\n last_step: number\n consequence_step: number\n escape_status: 'escaped' | 'unescaped'\n severity: AnalystSeverity\n claim: string\n confidence: number\n rationale?: unknown\n}\n\nfunction blockRowDefect(row: unknown): string | null {\n if (typeof row !== 'object' || row === null || Array.isArray(row)) return 'row is not an object'\n const record = row as Record<string, unknown>\n for (const field of ['first_step', 'last_step', 'consequence_step'] as const) {\n const value = record[field]\n if (!Number.isInteger(value) || (value as number) < 1) {\n return `${field} must be a positive integer`\n }\n }\n const firstStep = record.first_step as number\n const lastStep = record.last_step as number\n const consequenceStep = record.consequence_step as number\n if (lastStep < firstStep) return 'last_step < first_step'\n if (consequenceStep < firstStep) return 'consequence_step < first_step'\n if (lastStep - firstStep + 1 > MAX_INCORRECT_BLOCK_STEPS) {\n return `block spans ${lastStep - firstStep + 1} steps (cap ${MAX_INCORRECT_BLOCK_STEPS})`\n }\n if (record.escape_status !== 'escaped' && record.escape_status !== 'unescaped') {\n return 'escape_status must be escaped|unescaped'\n }\n if (typeof record.severity !== 'string' || !PRIME_SEVERITIES.has(record.severity)) {\n return 'severity outside the analyst severity enum'\n }\n if (\n typeof record.claim !== 'string' ||\n record.claim.trim().length === 0 ||\n record.claim.length > 2000\n ) {\n return 'claim must be a 1-2000 char string'\n }\n if (\n typeof record.confidence !== 'number' ||\n !Number.isFinite(record.confidence) ||\n record.confidence < 0 ||\n record.confidence > 1\n ) {\n return 'confidence must be 0..1'\n }\n return null\n}\n\nfunction blockFromRow(row: PrimeBlockRow): CodeTraceFailureBlock {\n // The contract asks the model not to send a rationale, but a volunteered one\n // is model-produced evidence: discarding it is unrecoverable, while carrying\n // a bounded string costs nothing and the destination field exists.\n const rationale =\n typeof row.rationale === 'string' && row.rationale.trim().length > 0\n ? row.rationale.trim().slice(0, 4_000)\n : undefined\n return {\n firstStep: row.first_step,\n lastStep: row.last_step,\n consequenceStep: row.consequence_step,\n escapeStatus: row.escape_status,\n severity: row.severity,\n claim: row.claim.trim(),\n confidence: row.confidence,\n ...(rationale === undefined ? {} : { rationale }),\n }\n}\n\nfunction pricingForModel(model: string): CustomTokenPricing {\n const pricing = resolveModelPricing(model)\n if (!pricing) {\n throw new Error(\n `no pricing is configured for '${model}'; provide PrimeBenchmarkRunnerOptions.pricing`,\n )\n }\n return {\n inputUsdPerMillion: pricing.input * 1_000,\n outputUsdPerMillion: pricing.output * 1_000,\n }\n}\n","import type { AnalystBenchmarkResult } from './benchmark'\nimport type { AnalystRunnerComparison } from './benchmark-comparison'\n\nexport function renderAnalystBenchmarkMarkdown(\n result: AnalystBenchmarkResult,\n comparisons: readonly AnalystRunnerComparison[] = [],\n): string {\n const { provenance } = result\n const lines = [\n '# Trace analyst benchmark',\n '',\n '## Run',\n '',\n '| Field | Value |',\n '| --- | --- |',\n `| Benchmark | ${escapeCell(provenance.id ?? 'unspecified')} |`,\n `| Dataset | ${escapeCell(provenance.dataset?.id ?? 'unspecified')} |`,\n `| Dataset revision | ${escapeCell(provenance.dataset?.revision ?? 'unspecified')} |`,\n `| Dataset split | ${escapeCell(provenance.dataset?.split ?? 'unspecified')} |`,\n `| Started | ${escapeCell(provenance.startedAt)} |`,\n `| Ended | ${escapeCell(provenance.endedAt)} |`,\n `| Cases | ${provenance.caseCount} |`,\n `| Runners | ${escapeCell(provenance.runnerIds.join(', '))} |`,\n `| Repetitions | ${provenance.repetitions} |`,\n `| Maximum concurrency | ${provenance.maxConcurrency} |`,\n `| Runner-order seed | ${provenance.runnerOrderSeed} |`,\n `| Command | ${escapeCell(provenance.command ?? 'uncaptured')} |`,\n `| Environment | ${escapeCell(json(provenance.environment))} |`,\n `| Metadata | ${escapeCell(json(provenance.metadata))} |`,\n '',\n '## Summary',\n '',\n ]\n lines.push(\n '| Runner | Runs | Failed | Issue-bearing | Trusted negatives | Unlabeled | Micro recall | Micro precision | Micro F1 | Macro recall | Macro precision | Macro F1 | Critical step | Citation coverage | Quote coverage | Label-location agreement | Citation resolution | Resolution unknown runs | Unresolved citations | Resolution errors | Trusted-negative false positives | Trusted-negative failures | Unlabeled prediction rate | Unlabeled failures | Prediction repeat | Prediction repeated cases | Matched-label repeat | Matched-label repeated cases | Latency min/mean/p50/p95/max ms | Locally timed runs | Runner-reported latency runs | Unknown latency | Calls | Input tokens | Output tokens | Reasoning tokens | Cached tokens | Cache-write tokens | Known cost USD | Unknown calls | Unknown input/output | Unknown reasoning | Unknown cached | Unknown cache-write | Unknown cost |',\n '| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |',\n )\n for (const summary of result.summaries) {\n lines.push(\n `| ${escapeCell(summary.runnerId)} | ${summary.completedRuns}/${summary.plannedRuns} | ${summary.failedRuns} | ${summary.issueBearingRuns} | ${summary.trustedNegativeRuns} | ${summary.unlabeledRuns} | ${optionalRate(summary.issueRecall)} | ${optionalRate(summary.findingPrecision)} | ${optionalRate(summary.f1)} | ${optionalRate(summary.macroIssueRecall)} | ${optionalRate(summary.macroFindingPrecision)} | ${optionalRate(summary.macroF1)} | ${optionalRate(summary.criticalStepAccuracy)} | ${optionalRate(summary.citationCoverage)} | ${optionalRate(summary.citationExcerptCoverage)} | ${optionalRate(summary.citationLabelAgreement)} | ${optionalRate(summary.citationResolution)} | ${summary.citationResolutionUnknownRuns} | ${summary.unresolvedCitations} | ${summary.citationResolutionErrors} | ${optionalRate(summary.trustedNegativeFalsePositiveRate)} | ${optionalRate(summary.trustedNegativeFailureRate)} | ${optionalRate(summary.unlabeledPredictionRate)} | ${optionalRate(summary.unlabeledFailureRate)} | ${optionalRate(summary.predictionAgreement)} | ${summary.predictionAgreementCases} | ${optionalRate(summary.matchedLabelAgreement)} | ${summary.matchedLabelAgreementCases} | ${latency(summary.latencyMs)} | ${summary.benchmarkClockLatencyRuns} | ${summary.runnerReportedLatencyRuns} | ${summary.latencyUnknownRuns} | ${summary.calls} | ${summary.inputTokens} | ${summary.outputTokens} | ${summary.reasoningTokens} | ${summary.cachedTokens} | ${summary.cacheWriteTokens} | ${summary.knownCostUsd.toFixed(6)} | ${summary.callsUnknownRuns} | ${summary.tokenUsageUnknownRuns} | ${summary.reasoningTokenUsageUnknownRuns} | ${summary.cachedTokenUsageUnknownRuns} | ${summary.cacheWriteTokenUsageUnknownRuns} | ${summary.costUnknownRuns} |`,\n )\n }\n\n for (const comparison of comparisons) {\n lines.push(\n '',\n `## ${escapeCell(comparison.candidateRunnerId)} compared with ${escapeCell(comparison.baselineRunnerId)}`,\n '',\n '| Metric | Better direction | Paired cases | Independent clusters | Eligible observations | Paired observations | Missing baseline | Missing candidate | Missing asymmetry | Survivor-only | Baseline mean | Candidate mean | Delta | Interval | Minimum sample | Population inference | Limits |',\n '| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | --- | ---: | ---: | ---: | --- | --- | --- | --- |',\n )\n for (const metric of comparison.metrics) {\n lines.push(\n `| ${metric.metric} | ${metric.direction} | ${metric.pairedCases} | ${metric.pairedClusters} | ${metric.eligibleObservations} | ${metric.pairedObservations} | ${metric.baselineMissingObservations} | ${metric.candidateMissingObservations} | ${metric.asymmetricMissingObservations} | ${metric.survivorOnly ? 'yes' : 'no'} | ${optionalMetricNumber(metric.baselineMean)} | ${optionalMetricNumber(metric.candidateMean)} | ${optionalSigned(metric.meanDelta)} | ${interval(metric.intervalLow, metric.intervalHigh)} | ${metric.minimumSampleMet ? 'yes' : 'no'} | ${metric.populationInferenceEligible ? 'yes' : 'no'} | ${escapeCell(metric.inferenceLimitations.join(', ') || 'none')} |`,\n )\n }\n }\n\n lines.push(\n '',\n '## Runs',\n '',\n '| Runner | Case | Cluster | Label state | Tags | Case metadata | Runner metadata | Rep | Execution index | Completed | Recall | Precision | F1 | Critical step | Citation coverage | Quote coverage | Label-location agreement | Citation resolution | Prediction on label-empty case | Scored findings | Diagnostic findings | Unlabeled citations | Unresolved citations | Resolution errors | Latency ms | Latency source | Calls | Input tokens | Output tokens | Reasoning tokens | Cached tokens | Cache-write tokens | Cost USD | Known cost USD | Cost source | Error class | Error |',\n '| --- | --- | --- | --- | --- | --- | --- | ---: | ---: | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | --- | ---: | ---: | ---: | ---: | ---: | ---: | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | --- | --- | --- |',\n )\n for (const observation of result.observations) {\n const usage = observation.usage\n const cost = usage?.cost.kind === 'uncaptured' ? null : usage?.cost.usd\n const positive = observation.labelState === 'positive'\n lines.push(\n `| ${escapeCell(observation.runnerId)} | ${escapeCell(observation.caseId)} | ${escapeCell(observation.clusterId)} | ${observation.labelState} | ${escapeCell(observation.caseTags.join(', '))} | ${escapeCell(json(observation.caseMetadata))} | ${escapeCell(json(observation.runnerMetadata))} | ${observation.repetition} | ${observation.executionIndex} | ${observation.error ? 'no' : 'yes'} | ${positive ? rate(observation.score.issueRecall) : 'n/a'} | ${positive ? rate(observation.score.findingPrecision) : 'n/a'} | ${positive ? rate(observation.score.f1) : 'n/a'} | ${optionalRate(observation.score.criticalStepAccuracy)} | ${optionalRate(observation.score.citationCoverage)} | ${optionalRate(observation.score.citationExcerptCoverage)} | ${optionalRate(observation.score.citationLabelAgreement)} | ${optionalRate(observation.evidenceResolution?.validity ?? null)} | ${positive ? 'n/a' : observation.score.predictionOnLabelEmptyCase ? 'yes' : 'no'} | ${observation.score.supportedFindingIndexes.length}/${observation.error ? 0 : observation.findings.length} | ${observation.error ? observation.findings.length : 0} | ${observation.score.unlabeledEvidence.length} | ${observation.evidenceResolution?.unresolvedEvidence.length ?? 'unknown'} | ${observation.evidenceResolution?.errors.length ?? 'unknown'} | ${optionalNumber(observation.latencyMs)} | ${observation.latencySource} | ${usage?.calls ?? 'unknown'} | ${usage?.tokens?.input ?? 'unknown'} | ${usage?.tokens?.output ?? 'unknown'} | ${usage?.tokens?.reasoning ?? 'unknown'} | ${usage?.tokens?.cached ?? 'unknown'} | ${usage?.tokens?.cacheWrite ?? 'unknown'} | ${cost === null || cost === undefined ? 'unknown' : cost.toFixed(6)} | ${usage?.knownCostUsd?.toFixed(6) ?? (cost === null || cost === undefined ? 'unknown' : cost.toFixed(6))} | ${usage?.cost.kind ?? 'unknown'} | ${escapeCell(observation.error?.class ?? '')} | ${escapeCell(observation.error?.message ?? '')} |`,\n )\n }\n return `${lines.join('\\n')}\\n`\n}\n\nfunction rate(value: number): string {\n return `${(value * 100).toFixed(1)}%`\n}\n\nfunction optionalRate(value: number | null): string {\n return value === null ? 'n/a' : rate(value)\n}\n\nfunction number(value: number): string {\n return Number.isInteger(value) ? String(value) : value.toFixed(3)\n}\n\nfunction optionalNumber(value: number | null): string {\n return value === null ? 'unknown' : number(value)\n}\n\nfunction optionalMetricNumber(value: number | null): string {\n return value === null ? 'n/a' : number(value)\n}\n\nfunction signed(value: number): string {\n return `${value >= 0 ? '+' : ''}${number(value)}`\n}\n\nfunction optionalSigned(value: number | null): string {\n return value === null ? 'n/a' : signed(value)\n}\n\nfunction interval(low: number | null, high: number | null): string {\n return low === null || high === null ? 'n/a' : `[${number(low)}, ${number(high)}]`\n}\n\nfunction latency(value: AnalystBenchmarkResult['summaries'][number]['latencyMs']): string {\n if (value === null) return 'unknown'\n return [value.min, value.mean, value.p50, value.p95, value.max].map(number).join('/')\n}\n\nfunction json(value: unknown): string {\n return value === undefined ? 'uncaptured' : JSON.stringify(value)\n}\n\nfunction escapeCell(value: string): string {\n return value.replaceAll('|', '\\\\|').replaceAll('\\n', ' ')\n}\n","import { arch, platform } from 'node:os'\nimport { resolve } from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { acquireSingleRunLock } from '../campaign/single-run-lock'\nimport { createRunCostLedger, fsCampaignStorage } from '../campaign/storage'\nimport {\n CostAccountingIncompleteError,\n type CostLedger,\n type CostLedgerSummary,\n} from '../cost-ledger'\nimport { resolveModelPricing } from '../metrics'\nimport {\n type AnalystBenchmarkObservation,\n type AnalystBenchmarkResult,\n type AnalystBenchmarkRunner,\n runAnalystBenchmark,\n traceStoreEvidenceResolver,\n} from './benchmark'\nimport {\n AGENT_RX_UPSTREAM_REVISION,\n renderAgentRxCalibrationMarkdown,\n summarizeAgentRxCalibration,\n} from './benchmark-agentrx-calibration'\nimport type {\n AnalystBenchmarkArtifact,\n VerificationAvailabilitySummary,\n} from './benchmark-command-artifact'\nimport { digestCanonical } from './benchmark-command-artifact'\nimport {\n type AnalystBenchmarkOutputPaths,\n createLocalRunReceipt,\n createObservationAppender,\n createRunIdentity,\n initializeRunFiles,\n openOutputDirectory,\n prepareOutputLockPath,\n readAndValidateResumeFiles,\n readProgress,\n regularFileExists,\n writeExclusiveOrVerify,\n} from './benchmark-command-persistence'\nimport {\n assertCompletedArtifactMatchesRun,\n assertSameObservations,\n readAnalystBenchmarkArtifact,\n} from './benchmark-command-result'\nimport { compareAnalystRunners } from './benchmark-comparison'\nimport {\n ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256,\n ANALYST_BENCHMARK_IMPLEMENTATION_SHA256,\n} from './benchmark-implementation'\nimport {\n effectiveAnalystProtocolSha256,\n readAnalystInstructionsOverride,\n} from './benchmark-instructions-override'\nimport {\n renderCodeTraceCalibrationMarkdown,\n summarizeCodeTraceCalibration,\n} from './benchmark-public-calibration'\nimport { createPublicBenchmarkDirectRunner } from './benchmark-public-model'\nimport { createPublicBenchmarkRlmRunner } from './benchmark-public-rlm'\nimport {\n createPrimeBenchmarkRunner,\n emptyPublicBenchmarkRunner,\n type PublicAnalystBenchmarkDataset,\n type PublicAnalystBenchmarkModelConfig,\n type PublicAnalystBenchmarkModelOwner,\n type PublicAnalystBenchmarkModelSettings,\n type PublicBenchmarkSelectionReport,\n preparePublicAnalystBenchmark,\n} from './benchmark-real-model'\nimport { renderAnalystBenchmarkMarkdown } from './benchmark-report'\nimport {\n DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES,\n type VerificationArtifactManifest,\n} from './benchmark-verification-artifacts'\nimport type { AnalystRunInputs } from './types'\n\nexport {\n ANALYST_BENCHMARK_COST_LEDGER_FILE,\n ANALYST_BENCHMARK_LOCAL_RECEIPT_FILE,\n ANALYST_BENCHMARK_MANIFEST_FILE,\n ANALYST_BENCHMARK_OBSERVATIONS_FILE,\n type AnalystBenchmarkArtifact,\n type AnalystBenchmarkLocalRunReceipt,\n type AnalystBenchmarkProgressRow,\n type AnalystBenchmarkRunIdentity,\n type AnalystBenchmarkRunManifest,\n type VerificationAvailabilitySummary,\n} from './benchmark-command-artifact'\nexport { readAnalystBenchmarkArtifact } from './benchmark-command-result'\n\nexport interface AnalystBenchmarkCommandDependencies {\n createAnalystRunner?: (\n dataset: PublicAnalystBenchmarkDataset,\n config: PublicAnalystBenchmarkModelSettings,\n ) => AnalystBenchmarkRunner<AnalystRunInputs>\n loadModelExecutionOwner?: (\n moduleRef: string,\n context: {\n model: string\n environment: Readonly<NodeJS.ProcessEnv>\n },\n ) => Promise<PublicAnalystBenchmarkModelOwner>\n}\n\n/**\n * Which analyst produces the scored arm.\n *\n * `dspy-rlm` is the recursive engine. `direct` is the one-shot comparison arm.\n * `prime` is the RLM coding agent reached through an OpenAI-compatible\n * cli-bridge (CodeTraceBench only; see docs/prime-analyst.md).\n */\nexport type AnalystBenchmarkRunnerKind = 'dspy-rlm' | 'direct' | 'prime'\n\n/** Bridge execution settings, present exactly when the analyst is `prime`. */\nexport interface PrimeAnalystBridgeConfig {\n bridgeUrl: string\n repair: boolean\n}\n\nexport interface AnalystBenchmarkCommandConfig {\n dataset: PublicAnalystBenchmarkDataset\n analyst: AnalystBenchmarkRunnerKind\n labelsPath: string\n traceDir: string\n artifactDir?: string\n outDir: string\n revision: string\n split: string\n model: PublicAnalystBenchmarkModelSettings\n limit: number\n seed: number\n concurrency: number\n repetitions: number\n /** Recursive-engine runs per case; above 1 the consensus is scored. */\n rlmSamples: number\n maxCostUsd: number\n maxArtifactBytes: number\n /** Absent exactly when the analyst is `prime`: the cli-bridge owns execution. */\n modelOwnerModule?: string\n /** Present exactly when the analyst is `prime`. */\n prime?: PrimeAnalystBridgeConfig\n command: string\n resume: boolean\n}\n\nexport { AGENT_RX_UPSTREAM_REVISION } from './benchmark-agentrx-calibration'\n\nexport async function runAnalystBenchmarkCommand(\n argv: readonly string[],\n env: NodeJS.ProcessEnv = process.env,\n dependencies: AnalystBenchmarkCommandDependencies = {},\n): Promise<number> {\n if (argv.includes('--help') || argv.includes('-h')) {\n process.stdout.write(`${ANALYST_BENCHMARK_HELP}\\n`)\n return 0\n }\n const config = await parseCommandConfig(argv, env, dependencies)\n const outputLock = acquireSingleRunLock({\n lockPath: await prepareOutputLockPath(config.outDir),\n })\n try {\n return await executeAnalystBenchmarkCommand(config, dependencies)\n } finally {\n outputLock.release()\n }\n}\n\nasync function executeAnalystBenchmarkCommand(\n config: AnalystBenchmarkCommandConfig,\n dependencies: AnalystBenchmarkCommandDependencies,\n): Promise<number> {\n const paths = await openOutputDirectory(config.outDir, config.resume)\n\n const prepared = await preparePublicAnalystBenchmark({\n dataset: config.dataset,\n labelsPath: config.labelsPath,\n traceDir: config.traceDir,\n artifactDir: config.artifactDir,\n maxArtifactBytes: config.maxArtifactBytes,\n limit: config.limit,\n seed: config.seed,\n })\n const identity = createRunIdentity(config, prepared)\n const localReceipt = createLocalRunReceipt(config, paths)\n const localIdentitySha256 = digestCanonical(localReceipt.local)\n const identitySha256 = digestCanonical(identity)\n const manifest = config.resume\n ? await readAndValidateResumeFiles(\n paths,\n identity,\n identitySha256,\n localIdentitySha256,\n localReceipt,\n )\n : await initializeRunFiles(paths, identity, identitySha256, localIdentitySha256, localReceipt)\n const progress = await readProgress(\n paths.observations,\n manifest.identitySha256,\n prepared.selectedCaseIds,\n config.repetitions,\n config.analyst,\n )\n const costLedger = createRunCostLedger({\n storage: fsCampaignStorage(),\n runDir: paths.directory,\n costCeilingUsd: config.maxCostUsd,\n })\n\n if (await regularFileExists(paths.result)) {\n assertCostLedgerFinalizable(costLedger)\n const artifact = await readAnalystBenchmarkArtifact(paths.result)\n assertCompletedArtifactMatchesRun(artifact, manifest, progress.observations, prepared)\n const markdown = renderArtifactMarkdown(artifact)\n await writeExclusiveOrVerify(paths.report, markdown)\n printSuccessSummary(artifact, paths)\n return benchmarkExitCode(artifact.result, config.analyst)\n }\n if (await regularFileExists(paths.report)) {\n throw new Error(\n `benchmark report exists without a completed result; refusing ambiguous resume: ${paths.report}`,\n )\n }\n\n const createAnalystRunner =\n dependencies.createAnalystRunner ??\n ((dataset: PublicAnalystBenchmarkDataset, model: PublicAnalystBenchmarkModelSettings) => {\n if (config.analyst === 'prime') {\n if (!config.prime) throw new Error(\"analyst 'prime' is missing its bridge configuration\")\n return createPrimeBenchmarkRunner({\n baseUrl: config.prime.bridgeUrl,\n model: model.model,\n timeoutMs: model.timeoutMs,\n repair: config.prime.repair,\n ...(model.pricing ? { pricing: model.pricing } : {}),\n })\n }\n const ownerModel = requireModelOwnerSettings(model)\n return config.analyst === 'direct'\n ? createPublicBenchmarkDirectRunner(dataset, ownerModel)\n : createPublicBenchmarkRlmRunner(dataset, ownerModel)\n })\n const runners = [\n emptyPublicBenchmarkRunner(),\n createAnalystRunner(config.dataset, {\n ...config.model,\n costLedger,\n durability: {\n runIdentitySha256: manifest.identitySha256,\n responseCacheDir: paths.modelResponses,\n },\n }),\n ]\n const appendObservation = createObservationAppender(\n paths.observations,\n manifest.identitySha256,\n progress,\n )\n const runAbort = new AbortController()\n let result: AnalystBenchmarkResult\n try {\n result = await runAnalystBenchmark({\n cases: prepared.cases,\n runners,\n repetitions: config.repetitions,\n maxConcurrency: config.concurrency,\n runnerOrderSeed: config.seed,\n initialObservations: progress.observations,\n signal: runAbort.signal,\n onObservation: async (observation) => {\n assertObservationAccountingComplete(observation, costLedger, config.analyst)\n await appendObservation(observation)\n },\n resolveEvidence: traceStoreEvidenceResolver((input) => {\n if (!input.traceStore) throw new Error('benchmark case has no trace store')\n return input.traceStore\n }),\n benchmark: {\n id: `${config.dataset}-real-model-analyst`,\n dataset: {\n id: config.dataset === 'agentrx' ? 'microsoft/AgentRx' : 'NJU-LINK/CodeTraceBench',\n revision: config.revision,\n split: config.split,\n },\n environment: {\n node: process.version,\n platform: platform(),\n arch: arch(),\n },\n metadata: {\n model: config.model.model,\n modelOwnerCallRef: config.model.callRef,\n rlmSamples: config.rlmSamples,\n outputAdapter:\n config.dataset === 'agentrx'\n ? 'agentrx-taxonomy-and-root-step'\n : 'codetracebench-incorrect-block',\n caseSelection: prepared.selection.method,\n caseSelectionSeed: config.seed,\n selectionStratified: prepared.selection.stratified,\n protocolSha256: effectiveAnalystProtocolSha256(\n config.dataset,\n config.model.instructionsOverride,\n ),\n implementationSha256: ANALYST_BENCHMARK_IMPLEMENTATION_SHA256,\n dependencyLockSha256: ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256,\n populationRepresentativenessProven: false,\n },\n },\n })\n } catch (error) {\n runAbort.abort(error)\n const idle = await costLedger.waitForIdle({\n timeoutMs: Math.min(config.model.timeoutMs, 10_000),\n })\n if (!idle) {\n throw accountingError(costLedger, 'provider calls remain unresolved after cancellation')\n }\n throw error\n }\n assertCostLedgerFinalizable(costLedger)\n result.provenance.startedAt = manifest.createdAt\n const persisted = await readProgress(\n paths.observations,\n manifest.identitySha256,\n prepared.selectedCaseIds,\n config.repetitions,\n config.analyst,\n )\n assertSameObservations(result.observations, persisted.observations)\n const comparisons = [\n compareAnalystRunners(result, {\n baselineRunnerId: 'empty',\n candidateRunnerId: config.analyst,\n seed: config.seed,\n }),\n ]\n const codeTraceCalibration =\n config.dataset === 'codetracebench' ? summarizeCodeTraceCalibration(result) : undefined\n const agentRxCalibration =\n config.dataset === 'agentrx'\n ? summarizeAgentRxCalibration(result, AGENT_RX_UPSTREAM_REVISION)\n : undefined\n const artifact: AnalystBenchmarkArtifact = {\n kind: 'agent-eval/analyst-benchmark-result',\n runIdentitySha256: manifest.identitySha256,\n inputs: {\n dataset: config.dataset,\n datasetRevision: config.revision,\n datasetSplit: config.split,\n labelsSha256: prepared.labelsSha256,\n sourceRowCount: prepared.sourceRowCount,\n traceFiles: prepared.traceFiles,\n verificationArtifacts: prepared.verificationArtifacts,\n verificationAvailability: summarizeVerificationAvailability(prepared.verificationArtifacts),\n selection: {\n limit: config.limit,\n seed: config.seed,\n selectedCaseIds: prepared.selectedCaseIds,\n report: prepared.selection,\n },\n execution: {\n repetitions: config.repetitions,\n concurrency: config.concurrency,\n rlmSamples: config.rlmSamples,\n model: config.model.model,\n modelOwnerCallRef: manifest.identity.config.model.ownerCallRef,\n maxOutputTokens: manifest.identity.config.model.maxOutputTokens,\n maxReasoningTokens: manifest.identity.config.model.maxReasoningTokens,\n maxModelRequestBytes: manifest.identity.config.model.maxRequestBytes,\n maxModelResponseBytes: manifest.identity.config.model.maxResponseBytes,\n modelRequestTimeoutMs: manifest.identity.config.model.requestTimeoutMs,\n timeoutMs: manifest.identity.config.model.timeoutMs,\n pricing: manifest.identity.config.model.pricing,\n recursiveLimits: manifest.identity.config.model.recursiveLimits,\n processLimits: manifest.identity.config.model.processLimits,\n maxCostUsd: config.maxCostUsd,\n maxArtifactBytes: config.maxArtifactBytes,\n analystProtocolSha256: effectiveAnalystProtocolSha256(\n config.dataset,\n config.model.instructionsOverride,\n ),\n ...(config.model.instructionsOverride\n ? { instructionsOverrideSha256: config.model.instructionsOverride.sha256 }\n : {}),\n implementationSha256: ANALYST_BENCHMARK_IMPLEMENTATION_SHA256,\n dependencyLockSha256: ANALYST_BENCHMARK_DEPENDENCY_LOCK_SHA256,\n },\n },\n result,\n comparisons,\n ...(codeTraceCalibration ? { codeTraceCalibration } : {}),\n ...(agentRxCalibration ? { agentRxCalibration } : {}),\n }\n\n const markdown = renderArtifactMarkdown(artifact)\n await writeExclusiveOrVerify(paths.result, `${JSON.stringify(artifact, null, 2)}\\n`)\n await writeExclusiveOrVerify(paths.report, markdown)\n printSuccessSummary(artifact, paths)\n return benchmarkExitCode(result, config.analyst)\n}\n\nconst NON_SCORABLE_COST_ERRORS = new Set([\n 'CostAccountingIncompleteError',\n 'CostCallConflictError',\n 'CostCeilingReachedError',\n 'CostLedgerPersistenceError',\n 'CostReceiptCaptureError',\n 'CostReservationExceededError',\n])\n\nfunction assertObservationAccountingComplete(\n observation: AnalystBenchmarkObservation,\n costLedger: CostLedger,\n analystRunnerId: string,\n): void {\n if (observation.error && NON_SCORABLE_COST_ERRORS.has(observation.error.class)) {\n throw new CostAccountingIncompleteError(\n `Analyst benchmark stopped before scoring: ${observation.error.message}`,\n )\n }\n if (observation.runnerId !== analystRunnerId) return\n const filter = {\n channel: 'analyst' as const,\n tags: {\n benchmarkCaseId: observation.caseId,\n benchmarkRepetition: String(observation.repetition),\n },\n }\n const summary = costLedger.summary(filter)\n // Every settled call is honestly accounted: a known cost is summed, and a\n // provider response that omitted usage is flagged and excluded from the\n // reported total. Neither invalidates a run, whether the case succeeded or\n // failed. Only a call left pending, one lost, or one charged beyond its\n // maximum leaves the cost genuinely unknowable, and those still halt.\n if (!costAccountingIsTrustworthy(summary)) {\n throw accountingError(\n costLedger,\n 'the recursive analyst has incomplete cost accounting',\n filter,\n )\n }\n}\n\nconst BUDGET_BREACH_REASON = /exceeding its enforced maximum/\n\n/**\n * Cost accounting is trustworthy when every call resolved and none breached its\n * budget. A recursive analyst on a real provider will occasionally receive a\n * settled response whose usage the provider omitted; that call is honestly\n * recorded as unknown and excluded from the reported cost, so it does not\n * invalidate a completed run. A call left pending, one lost, or one charged\n * beyond its maximum is a genuine integrity failure and still halts.\n */\nfunction costAccountingIsTrustworthy(summary: CostLedgerSummary): boolean {\n if (summary.pendingCalls > 0 || summary.unresolvedCalls > 0) return false\n return !summary.incompleteReasons.some((reason) => BUDGET_BREACH_REASON.test(reason))\n}\n\nfunction assertCostLedgerFinalizable(costLedger: CostLedger): void {\n const summary = costLedger.summary()\n if (!costAccountingIsTrustworthy(summary)) {\n throw accountingError(costLedger, 'the run has pending or budget-breaching cost entries')\n }\n}\n\nfunction accountingError(\n costLedger: CostLedger,\n reason: string,\n filter?: Parameters<CostLedger['summary']>[0],\n): CostAccountingIncompleteError {\n const summary = costLedger.summary(filter)\n const details = summary.incompleteReasons.slice(0, 3).join('; ')\n return new CostAccountingIncompleteError(\n `Analyst benchmark cannot continue because ${reason}${details ? `: ${details}` : ''}`,\n )\n}\n\nconst ANALYST_BENCHMARK_HELP = `agent-eval analyst-benchmark\n\nRun the recursive DSPy trace analyst against public AgentRx or CodeTraceBench labels.\n\nRequired:\n --dataset agentrx|codetracebench\n --analyst dspy-rlm|direct|prime Scored analyst. Default: dspy-rlm.\n 'direct' is the one-shot comparison arm.\n 'prime' is the RLM coding agent behind an\n OpenAI-compatible cli-bridge (codetracebench\n only; see docs/prime-analyst.md)\n --labels <dataset.json|dataset.jsonl>\n --trace-dir <one-trace-per-file OTLP JSONL directory>\n --artifact-dir <extracted artifact root> Required for CodeTraceBench\n --out <new output directory>\n --revision <full 40- or 64-character hex digest>\n --split <dataset split>\n --model-owner-module <module> dspy-rlm|direct only. Module exporting\n createModelExecutionOwner; the owner keeps\n provider credentials and policy\n --model <provider model id> For prime, the bridge model id in\n <backend>/<provider>/<model> form, e.g.\n prime/zai/glm-5.2\n --limit <positive case count>\n\nControls:\n --resume Continue an interrupted run in --out\n --bridge-url <url> prime only. OpenAI-compatible cli-bridge\n base URL. Default: http://localhost:4181\n --no-repair prime only. Disable the bounded repair turn\n for a structurally malformed reply\n --seed <integer> Case-selection and comparison seed. Default: 0\n --concurrency <positive integer> Parallel benchmark jobs. Default: 1\n --repetitions <positive integer> Runs per case and runner. Default: 1\n --rlm-samples <positive integer> Recursive-engine runs per case; above 1 the\n step-level majority consensus is scored\n (CodeTraceBench + dspy-rlm only). Default: 1\n --instructions-file <path> Replace the recursive analyst instructions\n with this file's text (dspy-rlm only). The\n recorded protocol digest binds the stock\n protocol to the override text, and\n result.json records instructionsOverrideSha256.\n --max-output-tokens <positive> Model output limit per call. Default: 16384\n --max-reasoning-tokens <integer> Reasoning-token limit per call. Default: 65536\n --max-model-requests <positive> Caller-owned model calls per analysis.\n Default: max iterations + model calls + 1\n --max-model-request-bytes <positive> Default: 16777216\n --max-model-response-bytes <positive> Default: 4194304\n --model-request-timeout-ms <positive> Default: --timeout-ms\n --max-iterations <positive> Recursive iterations per analysis. Default: 14\n --max-llm-calls <positive> DSPy model calls per analysis. Default: 8\n --max-tool-calls <positive> Trace-tool calls per analysis. Default: 80\n --max-analysis-output-chars <positive> Default: 8000\n --trace-tool-request-bytes <positive> Default: 1000000\n --trace-tool-response-bytes <positive> Default: 4000000\n --trace-tool-timeout-ms <positive> Default: 60000\n --max-process-input-bytes <positive> Default: 67108864\n --max-process-result-bytes <positive> Default: 4194304\n --max-process-output-chars <positive> Default: 64000\n --python <executable> Python with agent-eval-rpc[dspy]. Default: python\n --timeout-ms <positive> Model analyst deadline per case. Default: 300000\n --max-cost-usd <positive> Run-wide spend limit. Default: 5\n --max-artifact-bytes <positive> Final evidence bytes per case. Default: ${DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES}\n\nWrites result.json with every observation, metric, usage field, error, comparison,\ninput digest, artifact digest, case distribution, selected case id, and explicit\nunknown cost. Limited deterministic-hash subsets are marked non-representative.\nCompleted observations are fsynced to observations.jsonl. Shareable output is in\nresult.json and report.md. Machine-local paths, execution-owner module, and command\nare isolated in run.local.json. Provider credentials never enter this command.`\n\nasync function parseCommandConfig(\n argv: readonly string[],\n env: NodeJS.ProcessEnv,\n dependencies: AnalystBenchmarkCommandDependencies,\n): Promise<AnalystBenchmarkCommandConfig> {\n const flags = parseFlags(argv)\n assertKnownFlags(flags)\n const dataset = requiredFlag(flags, 'dataset')\n if (dataset !== 'agentrx' && dataset !== 'codetracebench') {\n throw new Error(\"--dataset must be 'agentrx' or 'codetracebench'\")\n }\n const artifactDir = flags.get('artifact-dir')?.trim()\n if (dataset === 'codetracebench' && !artifactDir) {\n throw new Error('--artifact-dir is required for CodeTraceBench')\n }\n const maxCostUsd = positiveFiniteFlag(flags, 'max-cost-usd', 5)\n const python = flags.get('python')?.trim()\n const analyst = flags.get('analyst')?.trim() ?? 'dspy-rlm'\n if (analyst !== 'dspy-rlm' && analyst !== 'direct' && analyst !== 'prime') {\n throw new Error(\"--analyst must be 'dspy-rlm', 'direct', or 'prime'\")\n }\n const bridgeUrl = flags.get('bridge-url')?.trim()\n if (bridgeUrl !== undefined && analyst !== 'prime') {\n throw new Error('--bridge-url requires --analyst prime')\n }\n if (bridgeUrl === '') throw new Error('--bridge-url must not be blank')\n if (flags.has('no-repair') && analyst !== 'prime') {\n throw new Error('--no-repair requires --analyst prime')\n }\n if (analyst === 'prime' && dataset !== 'codetracebench') {\n throw new Error(\n '--analyst prime requires --dataset codetracebench; the prime runner speaks the CodeTraceBench failure-block contract',\n )\n }\n if (analyst === 'prime' && flags.has('model-owner-module')) {\n throw new Error(\n '--model-owner-module is not used by --analyst prime; the cli-bridge owns model execution',\n )\n }\n const prime =\n analyst === 'prime'\n ? { bridgeUrl: bridgeUrl ?? 'http://localhost:4181', repair: !flags.has('no-repair') }\n : undefined\n const rlmSamples = positiveFlag(flags, 'rlm-samples', 1)\n if (rlmSamples > 1 && analyst !== 'dspy-rlm') {\n throw new Error('--rlm-samples above 1 requires --analyst dspy-rlm')\n }\n const instructionsFile = flags.get('instructions-file')?.trim()\n if (instructionsFile && analyst !== 'dspy-rlm') {\n throw new Error('--instructions-file requires --analyst dspy-rlm')\n }\n const instructionsOverride = instructionsFile\n ? readAnalystInstructionsOverride(instructionsFile)\n : undefined\n if (rlmSamples > 1 && dataset !== 'codetracebench') {\n throw new Error(\n '--rlm-samples above 1 requires --dataset codetracebench; step-level consensus is defined on its block grammar',\n )\n }\n const model = requiredFlag(flags, 'model')\n const modelOwnerModule =\n analyst === 'prime' ? undefined : requiredFlag(flags, 'model-owner-module')\n const owner = modelOwnerModule\n ? await (dependencies.loadModelExecutionOwner ?? loadModelExecutionOwner)(modelOwnerModule, {\n model,\n environment: Object.freeze({ ...env }),\n })\n : undefined\n if (owner) assertModelExecutionOwner(owner)\n const pricing = owner?.pricing ?? benchmarkModelPricing(model)\n const maxOutputTokens = positiveFlag(flags, 'max-output-tokens', 16_384)\n const timeoutMs = positiveFlag(flags, 'timeout-ms', 300_000)\n return {\n dataset,\n analyst,\n labelsPath: requiredFlag(flags, 'labels'),\n traceDir: requiredFlag(flags, 'trace-dir'),\n ...(artifactDir ? { artifactDir } : {}),\n outDir: requiredFlag(flags, 'out'),\n revision: immutableRevision(requiredFlag(flags, 'revision')),\n split: requiredFlag(flags, 'split'),\n model: {\n ...(owner\n ? { call: owner.call, callRef: owner.callRef, recordExecution: owner.recordExecution }\n : { callRef: `cli-bridge:${prime!.bridgeUrl}` }),\n model,\n maxOutputTokens,\n timeoutMs,\n maxReasoningTokens: nonNegativeFlag(flags, 'max-reasoning-tokens', maxOutputTokens * 4),\n maxModelRequestBytes: positiveFlag(flags, 'max-model-request-bytes', 16 * 1024 * 1024),\n maxModelResponseBytes: positiveFlag(flags, 'max-model-response-bytes', 4 * 1024 * 1024),\n modelRequestTimeoutMs: positiveFlag(flags, 'model-request-timeout-ms', timeoutMs),\n pricing,\n maxCostUsdPerAnalysis: maxCostUsd,\n ...(instructionsOverride ? { instructionsOverride } : {}),\n dspyRlm: {\n runner: {\n ...(python ? { command: python } : {}),\n limits: {\n maxInputBytes: positiveFlag(flags, 'max-process-input-bytes', 64 * 1024 * 1024),\n maxResultBytes: positiveFlag(flags, 'max-process-result-bytes', 4 * 1024 * 1024),\n maxOutputChars: positiveFlag(flags, 'max-process-output-chars', 64_000),\n },\n },\n maxIterations: positiveFlag(flags, 'max-iterations', 14),\n maxLlmCalls: positiveFlag(flags, 'max-llm-calls', 8),\n maxToolCalls: positiveFlag(flags, 'max-tool-calls', 80),\n maxOutputChars: positiveFlag(flags, 'max-analysis-output-chars', 8_000),\n ...(flags.has('max-model-requests')\n ? { maxModelRequests: positiveFlag(flags, 'max-model-requests') }\n : {}),\n traceToolRequestBytes: positiveFlag(flags, 'trace-tool-request-bytes', 1_000_000),\n traceToolResponseBytes: positiveFlag(flags, 'trace-tool-response-bytes', 4_000_000),\n traceToolTimeoutMs: positiveFlag(flags, 'trace-tool-timeout-ms', 60_000),\n samples: rlmSamples,\n },\n },\n limit: positiveFlag(flags, 'limit'),\n seed: integerFlag(flags, 'seed', 0),\n concurrency: positiveFlag(flags, 'concurrency', 1),\n repetitions: positiveFlag(flags, 'repetitions', 1),\n rlmSamples,\n maxCostUsd,\n maxArtifactBytes: positiveFlag(\n flags,\n 'max-artifact-bytes',\n DEFAULT_MAX_VERIFICATION_ARTIFACT_BYTES,\n ),\n ...(modelOwnerModule === undefined ? {} : { modelOwnerModule }),\n ...(prime === undefined ? {} : { prime }),\n command: `agent-eval analyst-benchmark ${argv\n .filter((argument) => argument !== '--resume')\n .map(shellQuote)\n .join(' ')}`,\n resume: flags.has('resume'),\n }\n}\n\n/** Fail-loud narrowing: the dspy-rlm and direct analysts require an owner call path. */\nfunction requireModelOwnerSettings(\n model: PublicAnalystBenchmarkModelSettings,\n): PublicAnalystBenchmarkModelConfig {\n const { call, recordExecution } = model\n if (typeof call !== 'function' || typeof recordExecution !== 'function') {\n throw new Error('model-owner execution is required for the dspy-rlm and direct analysts')\n }\n return { ...model, call, recordExecution }\n}\n\nfunction parseFlags(argv: readonly string[]): Map<string, string> {\n const flags = new Map<string, string>()\n for (let index = 0; index < argv.length; index += 1) {\n const token = argv[index]!\n if (!token.startsWith('--')) throw new Error(`unexpected positional argument: ${token}`)\n const raw = token.slice(2)\n const equalsAt = raw.indexOf('=')\n const name = equalsAt < 0 ? raw : raw.slice(0, equalsAt)\n const inlineValue = equalsAt < 0 ? undefined : raw.slice(equalsAt + 1)\n if (!name || flags.has(name)) throw new Error(`duplicate or empty flag: --${name}`)\n if (BOOLEAN_FLAGS.has(name)) {\n if (inlineValue !== undefined) throw new Error(`--${name} does not accept a value`)\n flags.set(name, 'true')\n continue\n }\n const value = inlineValue ?? argv[++index]\n if (!value || value.startsWith('--')) throw new Error(`--${name} requires a value`)\n flags.set(name, value)\n }\n return flags\n}\n\nconst KNOWN_FLAGS = new Set([\n 'resume',\n 'dataset',\n 'analyst',\n 'bridge-url',\n 'no-repair',\n 'labels',\n 'trace-dir',\n 'artifact-dir',\n 'out',\n 'revision',\n 'split',\n 'model-owner-module',\n 'model',\n 'limit',\n 'seed',\n 'concurrency',\n 'repetitions',\n 'rlm-samples',\n 'instructions-file',\n 'max-output-tokens',\n 'max-reasoning-tokens',\n 'max-model-requests',\n 'max-model-request-bytes',\n 'max-model-response-bytes',\n 'model-request-timeout-ms',\n 'max-iterations',\n 'max-llm-calls',\n 'max-tool-calls',\n 'max-analysis-output-chars',\n 'trace-tool-request-bytes',\n 'trace-tool-response-bytes',\n 'trace-tool-timeout-ms',\n 'max-process-input-bytes',\n 'max-process-result-bytes',\n 'max-process-output-chars',\n 'python',\n 'timeout-ms',\n 'max-cost-usd',\n 'max-artifact-bytes',\n])\n\nconst BOOLEAN_FLAGS = new Set(['resume', 'no-repair'])\n\nfunction assertKnownFlags(flags: ReadonlyMap<string, string>): void {\n for (const flag of flags.keys()) {\n if (!KNOWN_FLAGS.has(flag)) throw new Error(`unknown analyst-benchmark flag: --${flag}`)\n }\n}\n\nfunction requiredFlag(flags: ReadonlyMap<string, string>, name: string): string {\n const value = flags.get(name)?.trim()\n if (!value) throw new Error(`--${name} is required`)\n return value\n}\n\nfunction positiveFlag(\n flags: ReadonlyMap<string, string>,\n name: string,\n defaultValue?: number,\n): number {\n const raw = flags.get(name)\n if (raw === undefined && defaultValue !== undefined) return defaultValue\n if (raw === undefined) throw new Error(`--${name} is required`)\n const value = Number(raw)\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new Error(`--${name} must be a positive safe integer`)\n }\n return value\n}\n\nfunction integerFlag(\n flags: ReadonlyMap<string, string>,\n name: string,\n defaultValue: number,\n): number {\n const raw = flags.get(name)\n if (raw === undefined) return defaultValue\n const value = Number(raw)\n if (!Number.isSafeInteger(value)) throw new Error(`--${name} must be a safe integer`)\n return value\n}\n\nfunction nonNegativeFlag(\n flags: ReadonlyMap<string, string>,\n name: string,\n defaultValue: number,\n): number {\n const raw = flags.get(name)\n if (raw === undefined) return defaultValue\n const value = Number(raw)\n if (!Number.isSafeInteger(value) || value < 0) {\n throw new Error(`--${name} must be a non-negative safe integer`)\n }\n return value\n}\n\nfunction positiveFiniteFlag(\n flags: ReadonlyMap<string, string>,\n name: string,\n defaultValue: number,\n): number {\n const raw = flags.get(name)\n if (raw === undefined) return defaultValue\n const value = Number(raw)\n if (!Number.isFinite(value) || value <= 0) {\n throw new Error(`--${name} must be a positive finite number`)\n }\n return value\n}\n\nasync function loadModelExecutionOwner(\n moduleRef: string,\n context: { model: string; environment: Readonly<NodeJS.ProcessEnv> },\n): Promise<PublicAnalystBenchmarkModelOwner> {\n const specifier =\n moduleRef.startsWith('.') || moduleRef.startsWith('/')\n ? pathToFileURL(resolve(moduleRef)).href\n : moduleRef\n const imported = (await import(specifier)) as {\n createModelExecutionOwner?: (value: {\n model: string\n environment: Readonly<NodeJS.ProcessEnv>\n }) => PublicAnalystBenchmarkModelOwner | Promise<PublicAnalystBenchmarkModelOwner>\n }\n if (typeof imported.createModelExecutionOwner !== 'function') {\n throw new Error(`${moduleRef} must export createModelExecutionOwner({ model, environment })`)\n }\n return imported.createModelExecutionOwner(context)\n}\n\nfunction assertModelExecutionOwner(value: PublicAnalystBenchmarkModelOwner): void {\n if (!value || typeof value !== 'object') {\n throw new Error('createModelExecutionOwner must return an object')\n }\n if (typeof value.call !== 'function') {\n throw new Error('model execution owner call must be a function')\n }\n if (\n typeof value.callRef !== 'string' ||\n !value.callRef.trim() ||\n value.callRef !== value.callRef.trim()\n ) {\n throw new Error('model execution owner callRef must be trimmed and non-empty')\n }\n if (typeof value.recordExecution !== 'function') {\n throw new Error('model execution owner recordExecution must be a function')\n }\n}\n\nfunction benchmarkModelPricing(\n model: string,\n): NonNullable<PublicAnalystBenchmarkModelConfig['pricing']> {\n const pricing = resolveModelPricing(model)\n if (!pricing) {\n throw new Error(`model execution owner must supply pricing for uncatalogued model '${model}'`)\n }\n return {\n inputUsdPerMillion: pricing.input * 1_000,\n outputUsdPerMillion: pricing.output * 1_000,\n }\n}\n\nfunction immutableRevision(value: string): string {\n if (!/^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/.test(value)) {\n throw new Error('--revision must be a full 40- or 64-character hexadecimal digest')\n }\n return value.toLowerCase()\n}\n\nfunction renderSelectionMarkdown(report: PublicBenchmarkSelectionReport): string {\n const rows = (['class', 'agent', 'model', 'difficulty', 'solved'] as const).map((dimension) => {\n const source = report.source[dimension]\n const selected = report.selected[dimension]\n return `| ${dimension} | ${distributionText(source.counts, source.missing, source.total)} | ${distributionText(selected.counts, selected.missing, selected.total)} |`\n })\n return [\n '## Case Selection',\n '',\n `Method: \\`${report.method}\\`; seed: \\`${report.seed}\\`; selected: ${report.selectedCount}/${report.sourceCount}.`,\n report.representativeOfInput\n ? 'This is a census of the supplied input.'\n : 'This deterministic hash subset is not stratified and must not be presented as representative.',\n '',\n '| Dimension | Supplied input | Selected cases |',\n '| --- | --- | --- |',\n ...rows,\n ].join('\\n')\n}\n\nfunction distributionText(\n counts: Readonly<Record<string, number>>,\n missing: number,\n total: number,\n): string {\n const values = Object.entries(counts).map(([value, count]) => `${value}=${count}`)\n if (missing > 0) values.push(`missing=${missing}`)\n return `${values.join(', ') || 'none'} (n=${total})`\n}\n\nfunction summarizeVerificationAvailability(\n manifests: readonly VerificationArtifactManifest[],\n): VerificationAvailabilitySummary {\n return {\n cases: manifests.length,\n resultFilesPresent: manifests.filter((manifest) => manifest.status === 'present').length,\n resultFilesMissing: manifests.filter((manifest) => manifest.status === 'missing').length,\n outcomes: {\n passed: manifests.filter((manifest) => manifest.outcome.status === 'passed').length,\n failed: manifests.filter((manifest) => manifest.outcome.status === 'failed').length,\n unavailable: manifests.filter((manifest) => manifest.outcome.status === 'unavailable').length,\n },\n }\n}\n\nfunction renderVerificationAvailability(summary: VerificationAvailabilitySummary): string {\n return [\n '## Final Verification Availability',\n '',\n '| Cases | Result files present | Result files missing | Passed | Failed | Unavailable |',\n '| ---: | ---: | ---: | ---: | ---: | ---: |',\n `| ${summary.cases} | ${summary.resultFilesPresent} | ${summary.resultFilesMissing} | ${summary.outcomes.passed} | ${summary.outcomes.failed} | ${summary.outcomes.unavailable} |`,\n ].join('\\n')\n}\n\nfunction renderArtifactMarkdown(artifact: AnalystBenchmarkArtifact): string {\n const calibrationMarkdown = artifact.codeTraceCalibration\n ? `\\n\\n${renderCodeTraceCalibrationMarkdown(artifact.codeTraceCalibration)}`\n : artifact.agentRxCalibration\n ? `\\n\\n${renderAgentRxCalibrationMarkdown(artifact.agentRxCalibration)}`\n : ''\n const verificationMarkdown =\n artifact.inputs.dataset === 'codetracebench'\n ? `\\n\\n${renderVerificationAvailability(artifact.inputs.verificationAvailability)}`\n : ''\n return `${renderAnalystBenchmarkMarkdown(artifact.result, artifact.comparisons).trimEnd()}${calibrationMarkdown}${verificationMarkdown}\\n\\n${renderSelectionMarkdown(artifact.inputs.selection.report)}\\n`\n}\n\nfunction benchmarkExitCode(result: AnalystBenchmarkResult, analystRunnerId: string): number {\n return result.summaries.find((summary) => summary.runnerId === analystRunnerId)?.failedRuns\n ? 2\n : 0\n}\n\nfunction printSuccessSummary(\n artifact: AnalystBenchmarkArtifact,\n paths: AnalystBenchmarkOutputPaths,\n): void {\n const failures = artifact.result.summaries.reduce(\n (total, summary) => total + summary.failedRuns,\n 0,\n )\n const knownCostUsd = artifact.result.summaries.reduce(\n (total, summary) => total + summary.knownCostUsd,\n 0,\n )\n const unknownCostRuns = artifact.result.summaries.reduce(\n (total, summary) => total + summary.costUnknownRuns,\n 0,\n )\n process.stdout.write(\n `Analyst benchmark complete: cases=${artifact.result.provenance.caseCount} failures=${failures} known_cost_usd=${knownCostUsd.toFixed(6)} unknown_cost_runs=${unknownCostRuns}\\nresult=${paths.result}\\nreport=${paths.report}\\n`,\n )\n}\n\nfunction shellQuote(value: string): string {\n return /^[a-zA-Z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replaceAll(\"'\", \"'\\\\''\")}'`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAgB,wBAAwB,OAAuB;CAC7D,MAAM,aAAaA,WAAS,OAAO,iBAAiB,CAAC,CAClD,YAAY,CAAC,CACb,QAAQ,eAAe,GAAG,CAAC,CAC3B,QAAQ,UAAU,EAAE;CACvB,IAAI,CAAC,YAAY,MAAM,IAAI,UAAU,gDAAgD;CACrF,OAAO;AACT;AAEA,SAAgB,qBAAqB,OAAmC;CACtE,MAAM,aAAa,SAAS;CAC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AG,QAAQ,qBAAqB,IAAI,EAAE;AAGhE;;;;;;;AAQA,SAAgB,gBAAgB,OAAwB;CACtD,OAAO,cAAc,aAAa,KAAK,CAAC,CAAC,CAAC,MAAM,CAAgB;AAClE;;;AAIA,SAAgB,cAAc,OAAwB;CACpD,OAAO,gBAAgB,aAAa,KAAK,CAAC;AAC5C;AAEA,SAAgBE,WAAS,OAAkD;CACzE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAgB,SAAS,OAAiC;CACxD,OAAO,OAAO,UAAU,YAAY,iBAAiB,KAAK,KAAK;AACjE;;;ACzPA,MAAa,oDAAoD;AAEjE,MAAa,qDAAqD;AAElE,MAAa,0CAA0C,OAAO,OAAO;CACnE;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,2CACX;AAWF,MAAa,oDACX;AAEF,MAAa,mDACX;AAEF,MAAa,yCAAyC,OAAO,OAAO;CAClE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,0CACX;AAEF,SAAgB,uCAAuC;CACrD,OAAO;AACT;AAEA,SAAgB,uCAAuC;CACrD,OAAO;AACT;;;AClJA,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