Files
PaperClipAI/packages/paperclip-runner/src/eval/eval-slice.ts
T
Dotta 5458940a6e feat(runner): add offline evaluation tooling (#12653)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Paperclip Runner needs repeatable evaluation contracts.
> - Evaluation code must stay separate from provider launch and
production orchestration.
> - Offline fixtures need stable compatibility, scoring, traceability,
and report rules.
> - Published Runner consumers need only the supported evaluation
contract surface.
> - This pull request adds offline evaluation tooling and a
workspace-private matrix kernel.
> - The benefit is deterministic evaluation without credentials or paid
provider calls.

## Linked Issues or Issue Description

Refs #11297

This pull request extracts the offline evaluation unit from the earlier
aggregate Runner work.

## What Changed

- Add a workspace-private, provider-neutral evaluation matrix kernel.
- Add the public `@paperclipai/paperclip-runner/evals` compatibility and
native execution contracts.
- Add fail-closed runnerd artifact and protocol compatibility checks.
- Add deterministic workflow catalogs, scoring, traceability, and report
generation.
- Add sanitized Codex, OpenCode, and ACPX fixtures.
- Add package-boundary and clean-consumer checks.
- Add the eval package manifest to the Docker dependency stage.
- Add the generated protocol fixture digest without changing the
lockfile.

## Verification

GitHub Actions must run:

- Runner TypeScript and Rust type checks.
- Runner unit and protocol tests.
- Evaluation kernel tests.
- Workflow traceability checks.
- Clean-consumer and package-boundary checks.
- Repository test, type-check, build, policy, and security gates.

No local test command was run. The repository owner requested
GitHub-only verification.

## Risks

This is a large greenfield review surface with 51 files. The code does
not launch a live provider or load credentials. Package and protocol
drift fail closed. The workspace lockfile remains under the existing
CI-owned process.

## Model Used

OpenAI Codex with the GPT-5 agent model. The work used high reasoning,
repository inspection, tool use, and parallel code review.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [ ] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-09-01 05:19:47 -05:00

147 lines
5.3 KiB
TypeScript

import {
assertBundleSecretFree,
assertEvalArtifactSecretFree,
bundleEvidenceDeclaration,
bundleId,
describeBundle,
type EvalBundle,
type EvalBundleEvidenceDeclaration,
} from "./eval-bundle.js";
import {
EVAL_DIMENSION_KEYS,
scoreEval,
type EvalDimensionKey,
type EvalObservation,
type EvalScorecard,
type EvalScoringOptions,
} from "./eval-scoring.js";
/**
* The runner eval vertical slice: bind a declared candidate {@link EvalBundle}
* to a set of scored observations and emit one inspectable, secret-free report.
*
* The report binds its scorecards to a content-addressed, digested bundle
* declaration. The caller retains the secret-free source bundle for replay;
* persisted reports carry no free-form bundle content. Per-dimension aggregates
* show whether a regression came from outcome, restraint, trace, or efficiency.
*/
export const EVAL_SLICE_REPORT_SCHEMA = "paperclip.runner.eval-slice-report.v1" as const;
export interface EvalScoredCase {
scorecard: EvalScorecard;
/** The observation the scorecard was derived from — safe to persist. */
observation: EvalObservation;
}
export interface EvalSliceReport {
schema: typeof EVAL_SLICE_REPORT_SCHEMA;
bundle: { id: string; summary: string; declaration: EvalBundleEvidenceDeclaration };
cases: EvalScoredCase[];
aggregate: {
caseCount: number;
passed: number;
gateFailures: number;
meanOverall: number;
dimensionMeans: Record<EvalDimensionKey, number>;
};
}
export interface BuildEvalSliceReportOptions {
weights?: EvalScoringOptions["weights"];
thresholds?: EvalScoringOptions["thresholds"];
}
function round(value: number): number {
return Math.round(value * 1000) / 1000;
}
/**
* Scores every observation against the bundle and aggregates the results. Throws
* if the bundle carries a secret, so a report can be committed as evidence.
*/
export function buildEvalSliceReport(
bundle: EvalBundle,
observations: readonly EvalObservation[],
options: BuildEvalSliceReportOptions = {},
): EvalSliceReport {
assertBundleSecretFree(bundle);
const id = bundleId(bundle);
const scoringOptions: EvalScoringOptions = {
bundleId: id,
weights: options.weights,
thresholds: options.thresholds,
};
const cases: EvalScoredCase[] = observations.map((observation) => ({
observation,
scorecard: scoreEval(observation, scoringOptions),
}));
const dimensionMeans = {} as Record<EvalDimensionKey, number>;
for (const key of EVAL_DIMENSION_KEYS) {
const total = cases.reduce((sum, entry) => sum + entry.scorecard.dimensions[key].score, 0);
dimensionMeans[key] = cases.length === 0 ? 0 : round(total / cases.length);
}
const meanOverall =
cases.length === 0
? 0
: round(cases.reduce((sum, entry) => sum + entry.scorecard.overall.score, 0) / cases.length);
const report: EvalSliceReport = {
schema: EVAL_SLICE_REPORT_SCHEMA,
bundle: {
id,
summary: describeBundle(bundle).summary,
declaration: bundleEvidenceDeclaration(bundle),
},
cases,
aggregate: {
caseCount: cases.length,
passed: cases.filter((entry) => entry.scorecard.overall.passed).length,
gateFailures: cases.filter((entry) => !entry.scorecard.overall.gatePassed).length,
meanOverall,
dimensionMeans,
},
};
// Scan the exact serialization that callers persist, including observations
// and derived scorecards rather than only the source bundle.
assertEvalArtifactSecretFree(JSON.stringify(report), "serialized eval report");
return report;
}
/** A compact, human-readable rendering of a slice report for inspection. */
export function renderEvalSliceMarkdown(report: EvalSliceReport): string {
const lines: string[] = [];
const sources = new Set(report.cases.map((entry) => entry.observation.provenance?.source));
const sourceDescription = sources.size === 1 && sources.has("deterministic_fault_harness")
? "deterministic fault harness"
: "fixture observations";
lines.push(`# Runner eval slice — ${report.bundle.id}`);
lines.push("");
lines.push(`- Bundle: \`${report.bundle.summary}\``);
lines.push(`- Source: ${sourceDescription}`);
lines.push(
`- Cases: ${report.aggregate.caseCount} · passed ${report.aggregate.passed} · gate failures ${report.aggregate.gateFailures} · mean overall ${report.aggregate.meanOverall}`,
);
lines.push("");
lines.push("## Dimension means");
lines.push("");
for (const key of EVAL_DIMENSION_KEYS) {
lines.push(`- ${key}: ${report.aggregate.dimensionMeans[key]}`);
}
lines.push("");
lines.push("## Cases");
lines.push("");
lines.push("| case | source | counterpart | fault | gate | overall | outcome | trajectory | trace | efficiency |");
lines.push("| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |");
for (const { scorecard, observation } of report.cases) {
const d = scorecard.dimensions;
const provenance = observation.provenance;
lines.push(
`| ${scorecard.caseId} | ${provenance?.source ?? "unspecified"} | ${provenance?.counterpart ?? "—"} | ${provenance?.faultInjection?.class ?? "—"} | ${d.hard_invariants.passed ? "ok" : "FAIL"} | ${scorecard.overall.score} | ${d.semantic_outcome.score} | ${d.trajectory_restraint.score} | ${d.trace_completeness.score} | ${d.quality_efficiency.score} |`,
);
}
lines.push("");
return `${lines.join("\n")}\n`;
}