Files
PaperClipAI/packages/paperclip-runner/src/eval/workflow-scoring.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

169 lines
7.0 KiB
TypeScript

import { scoreEval } from "./eval-scoring.js";
import {
RUNNER_WORKFLOW_DIMENSION_KEYS,
RUNNER_WORKFLOW_SCORECARD_SCHEMA,
assertRunnerWorkflowObservation,
type RunnerWorkflowCheck,
type RunnerWorkflowDimensionKey,
type RunnerWorkflowDimensionScore,
type RunnerWorkflowEvalScorecard,
type RunnerWorkflowObservation,
} from "./workflow-contracts.js";
import { runnerWorkflowCase } from "./workflow-catalog.js";
export interface RunnerWorkflowScoringOptions {
bundleId: string;
weights?: Partial<Record<RunnerWorkflowDimensionKey, number>>;
thresholds?: Partial<Record<RunnerWorkflowDimensionKey, number>>;
}
const DEFAULT_WEIGHTS: Record<RunnerWorkflowDimensionKey, number> = {
hard_invariants: 0,
lifecycle_integrity: 0,
semantic_outcome: 0.20,
trajectory_restraint: 0.15,
trace_completeness: 0.10,
quality_efficiency: 0.10,
continuation_integrity: 0.20,
presentation_fidelity: 0.25,
};
function checksScore(checks: readonly RunnerWorkflowCheck[]): { score: number; reasons: string[] } {
const failed = checks.filter((check) => !check.passed);
return {
score: checks.filter((check) => check.passed).length / checks.length,
reasons: failed.map((check) => check.reason ?? `check failed: ${check.id}`),
};
}
function unscoredDimensions(): Record<RunnerWorkflowDimensionKey, RunnerWorkflowDimensionScore> {
return Object.fromEntries(RUNNER_WORKFLOW_DIMENSION_KEYS.map((dimension) => [dimension, {
dimension,
score: null,
passed: null,
gate: dimension === "hard_invariants" || dimension === "lifecycle_integrity",
weight: DEFAULT_WEIGHTS[dimension],
reasons: ["execution was not scoreable"],
}])) as Record<RunnerWorkflowDimensionKey, RunnerWorkflowDimensionScore>;
}
function traceLineageScore(observation: RunnerWorkflowObservation): { score: number; reasons: string[] } {
const expected = runnerWorkflowCase(observation.caseId).assertions.trace;
const checks: RunnerWorkflowCheck[] = [];
const captureExpectation = expected?.capture ?? "either";
if (captureExpectation === "off") {
checks.push({
id: "capture-off-isolation",
passed: observation.traceLineage.capture === "off"
&& observation.traceLineage.frameCount === 0
&& observation.traceLineage.byteCount === 0
&& observation.traceLineage.traceRef === undefined,
reason: "capture-off execution retained provider trace data",
});
} else if (captureExpectation === "on" || observation.traceLineage.capture === "on") {
checks.push(
{ id: "capture-present", passed: observation.traceLineage.capture === "on" && observation.traceLineage.frameCount > 0 && observation.traceLineage.byteCount > 0, reason: "provider trace capture is empty" },
{ id: "frame-digests", passed: observation.traceLineage.digestVerified, reason: "provider trace frame digest or byte length did not verify" },
{ id: "frame-order", passed: observation.traceLineage.ordered, reason: "provider trace frame or debug sequence is not strictly ordered" },
);
} else {
checks.push({ id: "capture-optional", passed: true });
}
for (const disposition of expected?.dispositions ?? []) {
checks.push({
id: `disposition-${disposition}`,
passed: observation.traceLineage.dispositions.includes(disposition),
reason: `provider trace did not exercise ${disposition} mapping`,
});
}
for (const lineage of expected?.lineage ?? []) {
checks.push({
id: `lineage-${lineage}`,
passed: observation.traceLineage.lineage.includes(lineage),
reason: `provider trace did not exercise ${lineage} lineage`,
});
}
return checksScore(checks);
}
/** Scores the complete Runner workflow while preserving the v1 capability dimensions. */
export function scoreRunnerWorkflow(
observation: RunnerWorkflowObservation,
options: RunnerWorkflowScoringOptions,
): RunnerWorkflowEvalScorecard {
assertRunnerWorkflowObservation(observation);
if (observation.classification === "infrastructure_failure" || observation.classification === "skipped") {
return {
schema: RUNNER_WORKFLOW_SCORECARD_SCHEMA,
bundleId: options.bundleId,
caseId: observation.caseId,
candidateId: observation.candidateId,
classification: observation.classification,
dimensions: unscoredDimensions(),
overall: { score: null, gatePassed: null, passed: null },
};
}
const v1 = scoreEval(observation.base, { bundleId: options.bundleId });
const lineageTrace = traceLineageScore(observation);
const workflowScores = {
lifecycle_integrity: checksScore(observation.lifecycle.checks),
continuation_integrity: checksScore(observation.continuation.checks),
presentation_fidelity: checksScore(observation.presentation.checks),
};
const weights = { ...DEFAULT_WEIGHTS, ...options.weights };
const dimensions = {} as Record<RunnerWorkflowDimensionKey, RunnerWorkflowDimensionScore>;
for (const dimension of RUNNER_WORKFLOW_DIMENSION_KEYS) {
const legacy = dimension in v1.dimensions
? v1.dimensions[dimension as keyof typeof v1.dimensions]
: undefined;
const workflow = dimension in workflowScores
? workflowScores[dimension as keyof typeof workflowScores]
: undefined;
const observedScore = dimension === "trace_completeness" && legacy !== undefined
? Math.min(legacy.score, lineageTrace.score)
: legacy?.score ?? workflow?.score ?? 0;
const candidateFailed = observation.classification === "candidate_failure"
&& dimension === "lifecycle_integrity";
const score = candidateFailed ? 0 : observedScore;
const gate = dimension === "hard_invariants" || dimension === "lifecycle_integrity";
const threshold = options.thresholds?.[dimension] ?? 1;
const reasons = dimension === "trace_completeness" && legacy !== undefined
? [...legacy.reasons, ...lineageTrace.reasons]
: legacy?.reasons ?? workflow?.reasons ?? [];
dimensions[dimension] = {
dimension,
score,
passed: score >= threshold,
gate,
weight: gate ? 0 : weights[dimension],
reasons: candidateFailed
? [...reasons, "candidate execution failed"]
: reasons,
};
}
const gatePassed = dimensions.hard_invariants.passed === true
&& dimensions.lifecycle_integrity.passed === true;
const weighted = RUNNER_WORKFLOW_DIMENSION_KEYS.filter((dimension) => !dimensions[dimension].gate);
const totalWeight = weighted.reduce((sum, dimension) => sum + dimensions[dimension].weight, 0);
const weightedScore = totalWeight === 0 ? 0 : weighted.reduce(
(sum, dimension) => sum + (dimensions[dimension].score ?? 0) * dimensions[dimension].weight,
0,
) / totalWeight;
const passed = gatePassed && RUNNER_WORKFLOW_DIMENSION_KEYS.every(
(dimension) => dimensions[dimension].passed === true,
);
return {
schema: RUNNER_WORKFLOW_SCORECARD_SCHEMA,
bundleId: options.bundleId,
caseId: observation.caseId,
candidateId: observation.candidateId,
classification: observation.classification,
dimensions,
overall: { score: gatePassed ? weightedScore : 0, gatePassed, passed },
};
}