@skill-harness/core 0.6.0 → 0.7.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.
package/dist/journal.d.ts CHANGED
@@ -54,6 +54,23 @@ export type JournalEvent = {
54
54
  ok: boolean;
55
55
  detail: string;
56
56
  rep?: number;
57
+ }
58
+ /** Trace-gate outcome. Separate from `gate-result`, which is the seeded diff/vitest gates. */
59
+ | {
60
+ event: "objective-result";
61
+ ts: string;
62
+ id: string;
63
+ ok: boolean;
64
+ detail: string;
65
+ rep?: number;
66
+ }
67
+ /** One adjudication pass: which cells were re-judged, what it cost in CALLS, what stayed unresolved. */
68
+ | {
69
+ event: "adjudication";
70
+ ts: string;
71
+ triggered: string[];
72
+ judge_calls: number;
73
+ unresolved: string[];
57
74
  } | {
58
75
  event: "judge-verdict";
59
76
  ts: string;
package/dist/lint.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type LintCode = "spec" | "ship_bar" | "critical" | "fixture" | "fixture-marker" | "consistency" | "stale" | "stability" | "lint-error";
1
+ export type LintCode = "spec" | "ship_bar" | "critical" | "fixture" | "fixture-marker" | "consistency" | "stale" | "stability" | "covers" | "lint-error";
2
2
  /**
3
3
  * How much a finding means.
4
4
  *
package/dist/lint.js CHANGED
@@ -2,6 +2,7 @@ import { existsSync, statSync, readdirSync, readFileSync } from "node:fs";
2
2
  import { basename, dirname, isAbsolute, join, resolve } from "node:path";
3
3
  import yaml from "js-yaml";
4
4
  import { loadSpec, SpecError } from "./spec.js";
5
+ import { computeCoverage } from "./instruction-coverage.js";
5
6
  import { readResults, finalizeResults, findTranscriptFiles, resultsPath, scoreContextFor } from "./results.js";
6
7
  import { currentHashFor, describeSourceKey, remedyForKey, scenarioIdForKey, effectiveFixture, SCENARIO_PREFIX, STIMULUS_PREFIX, UNREADABLE } from "./sources.js";
7
8
  import { downgradeWarning } from "./downgrade.js";
@@ -140,6 +141,28 @@ export function lintSkill(skillDir) {
140
141
  // system_prompt_file must exist — an agent-file scenario silently falling back to
141
142
  // skill activation would measure the wrong artifact entirely.
142
143
  for (const s of spec.scenarios) {
144
+ // A `covers` reference that names a section which does not exist is a WRONG
145
+ // STATEMENT in the spec, not a coverage gap — so it fails the gate, while an
146
+ // uncovered section is only reported by `coverage --strict`. Renaming a heading
147
+ // is the usual cause, so the finding names the near-misses.
148
+ if (s.covers?.length) {
149
+ const report = computeCoverage({ specDir, scenarios: [s] });
150
+ for (const b of report.broken) {
151
+ const hint = b.didYouMean.length ? ` — did you mean ${b.didYouMean.map((x) => `#${x}`).join(", ")}?` : "";
152
+ findings.push({
153
+ skill, scenario: s.id, code: "covers",
154
+ message: `covers reference \`${b.raw}\` is broken (${b.reason})${hint}`,
155
+ });
156
+ }
157
+ }
158
+ // Extension paths, checked statically so a typo is a free CI failure rather
159
+ // than a wave that ran with no subagent tool and graded the absence.
160
+ for (const ext of s.extensions ?? []) {
161
+ const extAbs = isAbsolute(ext) ? ext : resolve(specDir, ext);
162
+ if (!existsSync(extAbs)) {
163
+ findings.push({ skill, scenario: s.id, code: "fixture", message: `env.extensions not found: ${ext}` });
164
+ }
165
+ }
143
166
  if (!s.systemPromptFile)
144
167
  continue;
145
168
  const abs = isAbsolute(s.systemPromptFile) ? s.systemPromptFile : resolve(specDir, s.systemPromptFile);
package/dist/regate.js CHANGED
@@ -2,8 +2,10 @@ import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { parseVerdict, detectMisfire } from "./grade.js";
4
4
  import { evaluateNeedleGates, hasNeedleGates } from "./seeded.js";
5
+ import { evaluateTraceGates } from "./trace-gates.js";
6
+ import { mergeTraces, deserializeTrace } from "./execution-trace.js";
5
7
  import { judgeOneRep } from "./regrade.js";
6
- import { readResults, writeResults, transcriptPath, judgeRawPath, repIndexOf, findDiffFiles, effectiveThreshold, scoreContextFor, } from "./results.js";
8
+ import { readResults, writeResults, transcriptPath, judgeRawPath, repIndexOf, findDiffFiles, findTraceFiles, tracePath, effectiveThreshold, scoreContextFor, rebuildScenarioResult, } from "./results.js";
7
9
  import { outcomesToResult } from "./reps.js";
8
10
  import { appendJournal } from "./journal.js";
9
11
  import { gatesDigest, GATES_PREFIX } from "./sources.js";
@@ -84,22 +86,32 @@ export async function regateRun(opts) {
84
86
  const targets = [];
85
87
  for (const rec of prev.scenarios) {
86
88
  const s = specById.get(rec.id);
87
- if (!s || !hasNeedleGates(s))
89
+ const needles = hasNeedleGates(s ?? {});
90
+ const traceGated = Boolean(s?.traceAssert);
91
+ if (!s || (!needles && !traceGated))
88
92
  continue; // nothing for regate to re-decide
89
93
  if (s.assert?.vitest || s.assert?.post_test) {
90
94
  blocked.push(`${s.id}: declares ${s.assert.vitest ? "assert.vitest" : "assert.post_test"}, which needs the workspace — ` +
91
95
  `no saved artifact can stand in for it, so this scenario needs a re-run`);
92
96
  continue;
93
97
  }
94
- if (findDiffFiles(opts.runDir, s.id, mode).length === 0) {
98
+ if (needles && findDiffFiles(opts.runDir, s.id, mode).length === 0) {
95
99
  blocked.push(`${s.id}: no staged-diff artifact on disk (\`.diff.txt\` is gitignored — regate needs the run dir that produced it)`);
96
100
  continue;
97
101
  }
102
+ // A trace gate is only re-decidable from a saved trace. A run recorded before
103
+ // traces existed has none, and saying so is the whole point — pretending
104
+ // regate can answer would report a verdict derived from no evidence.
105
+ if (traceGated && findTraceFiles(opts.runDir, s.id, mode).length === 0) {
106
+ blocked.push(`${s.id}: declares assert.trace but this run saved no \`.trace.jsonl\` artifact ` +
107
+ `(it predates trace capture, or the trace was not persisted) — it needs a re-run`);
108
+ continue;
109
+ }
98
110
  targets.push(s);
99
111
  }
100
112
  if (targets.length === 0) {
101
113
  throw new Error(`nothing to regate in ${opts.runDir}` +
102
- (blocked.length > 0 ? `:\n ${blocked.join("\n ")}` : " — no scenario declares diff_contains/diff_excludes"));
114
+ (blocked.length > 0 ? `:\n ${blocked.join("\n ")}` : " — no scenario declares diff_contains/diff_excludes or assert.trace"));
103
115
  }
104
116
  const changes = [];
105
117
  let judgeCalls = 0;
@@ -111,18 +123,66 @@ export async function regateRun(opts) {
111
123
  continue;
112
124
  }
113
125
  const diffFiles = findDiffFiles(opts.runDir, scenario.id, mode);
126
+ const traceFiles = findTraceFiles(opts.runDir, scenario.id, mode);
127
+ // Reps come from whichever artifact this scenario actually has. A trace-only
128
+ // scenario has no `.diff.txt` at all, so iterating diffs would silently
129
+ // regate nothing and report success.
130
+ const repKeys = diffFiles.length > 0
131
+ ? diffFiles.map((f) => ({ rep: repIndexOf(f) ?? undefined, diffFile: f }))
132
+ : traceFiles.map((f) => ({ rep: repIndexOf(f) ?? undefined, diffFile: undefined }));
114
133
  const outcomes = [];
115
134
  // Per scenario, not run-wide: with several regated scenarios, a global counter
116
135
  // would report every change as "re-judged" because some other scenario was.
117
136
  let judgedHere = 0;
118
137
  let gateFailedHere = false;
119
- for (const file of diffFiles) {
120
- const rep = repIndexOf(file) ?? undefined;
121
- const diff = readFileSync(join(opts.runDir, file), "utf8");
122
- const gate = evaluateNeedleGates(scenario, diff);
138
+ for (const { rep, diffFile } of repKeys) {
139
+ const diff = diffFile ? readFileSync(join(opts.runDir, diffFile), "utf8") : "";
140
+ const needleGate = diffFile ? evaluateNeedleGates(scenario, diff) : { lines: [], failure: null };
141
+ // Trace gate, re-decided from the saved trace. Free: no model, no judge.
142
+ let traceFailure = null;
143
+ let objective;
144
+ if (scenario.traceAssert) {
145
+ const tp = tracePath(opts.runDir, scenario.id, mode, rep);
146
+ // A PARTIAL read is refused, not graded. `deserializeTrace` returns null
147
+ // for a malformed line and for a version it declines, and dropping those
148
+ // silently graded whatever survived: a 3-turn trace with a torn middle
149
+ // line reported `forbid_calls: [bash] → PASS` when the lost turn was the
150
+ // one that called bash. The write side already refuses an incomplete
151
+ // stream (`pi.ts` throws on no terminal event) precisely so "called
152
+ // nothing" and "recorded nothing" cannot look the same; the read side
153
+ // has to hold the same line.
154
+ const lines = existsSync(tp)
155
+ ? readFileSync(tp, "utf8").split("\n").filter((l) => l.trim())
156
+ : [];
157
+ const parsed = lines.map((l) => deserializeTrace(l));
158
+ const usable = parsed.filter((t) => t !== null);
159
+ const merged = usable.length === lines.length ? mergeTraces(usable) : null;
160
+ if (merged === null) {
161
+ traceFailure =
162
+ usable.length === lines.length
163
+ ? "objective: saved trace is missing or unreadable — cannot re-evaluate assert.trace"
164
+ : `objective: saved trace is incomplete (${usable.length}/${lines.length} turns readable) — cannot re-evaluate assert.trace`;
165
+ objective = { status: "ERROR", assertions: [] };
166
+ }
167
+ else {
168
+ const g = evaluateTraceGates(scenario.traceAssert, merged);
169
+ objective = { status: g.status, trace_version: merged.trace_version, trace_sha256: merged.trace_sha256, assertions: g.assertions };
170
+ if (g.status === "FAIL" || g.status === "ERROR") {
171
+ const bad = g.assertions.filter((x) => x.status === g.status).map((x) => x.detail);
172
+ traceFailure = `objective: ${bad.join("; ")}`;
173
+ }
174
+ }
175
+ }
176
+ const gate = { lines: needleGate.lines, failure: needleGate.failure ?? traceFailure };
123
177
  const tPath = transcriptPath(opts.runDir, scenario.id, mode, rep);
124
178
  const before = existsSync(tPath) ? readFileSync(tPath, "utf8") : "";
125
- const oldGateFailed = GATE_FAILED_RE.test(before.slice(before.indexOf(TRAILER)));
179
+ // Two sources, because the two gate kinds record their prior state
180
+ // differently: a seeded needle gate leaves a trailer in the transcript, a
181
+ // trace gate leaves an `objective` block on the result. Reading only the
182
+ // trailer meant a trace gate flipping to PASS never triggered the re-judge
183
+ // it needs, leaving a stale FAIL verdict beside a PASS objective.
184
+ const oldObjectiveFailed = rec.objective?.status === "FAIL" || rec.objective?.status === "ERROR";
185
+ const oldGateFailed = GATE_FAILED_RE.test(before.slice(before.indexOf(TRAILER))) || oldObjectiveFailed;
126
186
  // The trailer is regenerated whatever the outcome: leaving a stale
127
187
  // `MISSING` note beside a corrected verdict would misinform the next reader
128
188
  // (and the next judge, which reads this transcript).
@@ -130,23 +190,23 @@ export async function regateRun(opts) {
130
190
  rewriteTranscript(tPath, gate.lines);
131
191
  if (gate.failure) {
132
192
  gateFailedHere = true;
133
- outcomes.push({ verdict: "FAIL", reason: gate.failure, suspect: false });
193
+ outcomes.push({ verdict: "FAIL", reason: gate.failure, suspect: false, objective });
134
194
  continue;
135
195
  }
136
196
  if (!oldGateFailed) {
137
197
  // The judge already saw this rep. Its verdict is on disk — re-read it rather
138
198
  // than paying to ask the same question again.
139
199
  const saved = verdictFromSavedJudgement(opts.runDir, scenario.id, mode, rep);
140
- outcomes.push(saved ?? { verdict: rec.judge_verdict, reason: rec.judge_reason, suspect: rec.suspect });
200
+ outcomes.push({ ...(saved ?? { verdict: rec.judge_verdict, reason: rec.judge_reason, suspect: rec.suspect }), objective });
141
201
  continue;
142
202
  }
143
203
  // The gate blocked this rep before, so no judgement of it exists anywhere.
144
204
  const transcript = readFileSync(tPath, "utf8");
145
- outcomes.push(await judgeOneRep({
146
- runDir: opts.runDir, spec: opts.spec, scenario, transcript,
147
- adapter: opts.adapter, judge: opts.judge, specDir: opts.specDir,
148
- mode, rep, now,
149
- }));
205
+ outcomes.push({ ...(await judgeOneRep({
206
+ runDir: opts.runDir, spec: opts.spec, scenario, transcript,
207
+ adapter: opts.adapter, judge: opts.judge, specDir: opts.specDir,
208
+ mode, rep, now,
209
+ })), objective });
150
210
  judgeCalls++;
151
211
  judgedHere++;
152
212
  }
@@ -154,7 +214,10 @@ export async function regateRun(opts) {
154
214
  const next = outcomesToResult(scenario.id, outcomes, outcomes.length, threshold);
155
215
  // Overrides and their notes survive: a regate re-decides the gate, and an author
156
216
  // override is a statement about the judge, not about the needle.
157
- scenarios.push({ ...next, override: rec.override, note: rec.note });
217
+ // `regate` re-evaluates gates from saved artifacts and asks no judge anything:
218
+ // `objective` is freshly recomputed above, and the recorded judge panel still
219
+ // describes the current judgments.
220
+ scenarios.push(rebuildScenarioResult(next, rec, { objective: "fresh", adjudication: "carry" }));
158
221
  const to = next.judge_verdict;
159
222
  if (to !== rec.judge_verdict) {
160
223
  changes.push({
package/dist/regrade.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { readFileSync, writeFileSync, existsSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { buildJudgePrompt, judgeInWorkspace } from "./grade.js";
4
- import { findTranscriptFiles, judgeRawPath, repIndexOf, readResults, writeResults, effectiveThreshold, scoreContextFor, } from "./results.js";
4
+ import { findTranscriptFiles, judgeRawPath, repIndexOf, readResults, writeResults, effectiveThreshold, scoreContextFor, rebuildScenarioResult, } from "./results.js";
5
5
  import { outcomesToResult } from "./reps.js";
6
6
  import { appendJournal } from "./journal.js";
7
7
  import { rubricDigest, personaDigest, RUBRIC_PREFIX, PERSONA_KEY } from "./sources.js";
@@ -85,7 +85,18 @@ export async function regradeRun(opts) {
85
85
  const { runDir, spec, adapter, judge, specDir } = opts;
86
86
  const now = opts.now ?? (() => new Date().toISOString());
87
87
  const prev = existsSync(join(runDir, "results.yaml")) ? readResults(runDir) : null;
88
- const overrides = new Map((prev?.scenarios ?? []).map((s) => [s.id, { override: s.override, note: s.note }]));
88
+ // Carried across a re-judge, per field, because the right answer differs:
89
+ // - `override`/`note` — the author's, never the judge's to discard.
90
+ // - `objective` — a re-judge does NOT re-evaluate trace gates (that is
91
+ // `regate`), so the recorded evidence still describes this run. Dropping it
92
+ // silently downgraded a gated scenario to "no assertions declared".
93
+ // `adjudication` is deliberately NOT carried: it describes the judgments this
94
+ // re-grade just replaced, and a stale panel beside a fresh verdict is worse
95
+ // than none. `grade --auto-rejudge` recomputes it.
96
+ // The whole prior result per id — `rebuildScenarioResult` decides, field by
97
+ // field, what survives. Passing a hand-picked subset here is how fields got
98
+ // dropped before.
99
+ const overrides = new Map((prev?.scenarios ?? []).map((s) => [s.id, s]));
89
100
  const mode = prev?.mode ?? "green";
90
101
  // Re-grading rewrites the WHOLE results.yaml, so re-judge exactly the
91
102
  // scenarios the run recorded (falling back to the spec for a run with no
@@ -131,7 +142,10 @@ export async function regradeRun(opts) {
131
142
  runDir, spec, scenario, adapter, judge, specDir, threshold, mode, now,
132
143
  });
133
144
  const carry = overrides.get(id);
134
- scenarioResults.push({ ...rr, override: carry?.override ?? null, note: carry?.note ?? "" });
145
+ // `grade` re-judges the saved transcript. It does not re-evaluate trace gates
146
+ // (that is `regate`), so `objective` still describes this run; and it replaced
147
+ // the judgments a prior adjudication described, so that panel must go.
148
+ scenarioResults.push(rebuildScenarioResult(rr, carry, { objective: "carry", adjudication: "drop" }));
135
149
  }
136
150
  const ctx = scoreContextFor({ mode, partial: prev?.partial }, spec);
137
151
  const results = writeResults(runDir, {
package/dist/report.d.ts CHANGED
@@ -14,6 +14,18 @@ export interface RunColumn {
14
14
  judge_verdict: string;
15
15
  judge_reason: string;
16
16
  suspect: boolean;
17
+ /** Objective trace-gate outcome, when the scenario declared `assert.trace`. */
18
+ objective?: {
19
+ status: string;
20
+ detail: string;
21
+ };
22
+ /** Adjudication outcome, when the cell was re-judged. */
23
+ adjudication?: {
24
+ state: string;
25
+ trigger: string;
26
+ count: number;
27
+ detail: string;
28
+ };
17
29
  reps?: number;
18
30
  passes?: number;
19
31
  clean?: number;
@@ -89,6 +101,18 @@ export declare function publicView(data: ReportData): {
89
101
  judge_verdict: string;
90
102
  judge_reason: string;
91
103
  suspect: boolean;
104
+ /** Objective trace-gate outcome, when the scenario declared `assert.trace`. */
105
+ objective?: {
106
+ status: string;
107
+ detail: string;
108
+ };
109
+ /** Adjudication outcome, when the cell was re-judged. */
110
+ adjudication?: {
111
+ state: string;
112
+ trigger: string;
113
+ count: number;
114
+ detail: string;
115
+ };
92
116
  reps?: number;
93
117
  passes?: number;
94
118
  clean?: number;
package/dist/report.js CHANGED
@@ -52,6 +52,30 @@ export function collectReport(skillDir) {
52
52
  },
53
53
  }
54
54
  : {}),
55
+ // Same optional-spread shape as `stability`: absent means "not declared"
56
+ // / "single judge", and the UI must not render either as a clean result.
57
+ ...(s.objective
58
+ ? {
59
+ objective: {
60
+ status: s.objective.status,
61
+ detail: s.objective.assertions.length
62
+ ? s.objective.assertions.map((a) => `${a.status} ${a.detail}`).join(" · ")
63
+ : "no assertion evidence recorded",
64
+ },
65
+ }
66
+ : {}),
67
+ ...(s.adjudication
68
+ ? {
69
+ adjudication: {
70
+ state: s.adjudication.state,
71
+ trigger: s.adjudication.trigger,
72
+ count: s.adjudication.judgments.length,
73
+ detail: s.adjudication.judgments
74
+ .map((j) => `#${j.ordinal} ${j.judge.provider}:${j.judge.model} ${j.verdict}${j.suspect ? " (misfired, not counted)" : ""}`)
75
+ .join(" · "),
76
+ },
77
+ }
78
+ : {}),
55
79
  judge_verdict: s.judge_verdict,
56
80
  judge_reason: s.judge_reason,
57
81
  suspect: s.suspect ?? false, // suspect defaults false for older results that predate the field
package/dist/reps.d.ts CHANGED
@@ -1,11 +1,24 @@
1
1
  import type { Verdict } from "./score.js";
2
- import type { ScenarioResult } from "./results.js";
2
+ import type { ScenarioResult, ObjectiveResult } from "./results.js";
3
3
  /** One rep's outcome (subject run + judge). */
4
4
  export interface RepOutcome {
5
5
  verdict: Verdict;
6
6
  reason: string;
7
7
  suspect: boolean;
8
+ /** Present only when the scenario declared `assert.trace`. */
9
+ objective?: ObjectiveResult;
8
10
  }
11
+ /**
12
+ * Collapse per-rep objective results.
13
+ *
14
+ * Strict on purpose, and deliberately NOT the same policy as the judge's
15
+ * pass-threshold aggregation: an objective assertion is a statement about what
16
+ * the model DID, so one rep that called a forbidden tool is a real finding, not
17
+ * a minority draw to be voted away. ERROR dominates (missing evidence is never a
18
+ * pass), then FAIL, then PASS. The retained assertion detail comes from the
19
+ * first non-passing rep, since that is the one worth reading.
20
+ */
21
+ export declare function aggregateObjective(outcomes: RepOutcome[]): ObjectiveResult | undefined;
9
22
  /** A scenario's aggregated result over N reps. */
10
23
  export interface RepAggregate {
11
24
  verdict: Verdict;
package/dist/reps.js CHANGED
@@ -1,3 +1,25 @@
1
+ /**
2
+ * Collapse per-rep objective results.
3
+ *
4
+ * Strict on purpose, and deliberately NOT the same policy as the judge's
5
+ * pass-threshold aggregation: an objective assertion is a statement about what
6
+ * the model DID, so one rep that called a forbidden tool is a real finding, not
7
+ * a minority draw to be voted away. ERROR dominates (missing evidence is never a
8
+ * pass), then FAIL, then PASS. The retained assertion detail comes from the
9
+ * first non-passing rep, since that is the one worth reading.
10
+ */
11
+ export function aggregateObjective(outcomes) {
12
+ const present = outcomes.map((o) => o.objective).filter((o) => o !== undefined);
13
+ if (present.length === 0)
14
+ return undefined;
15
+ const errored = present.find((o) => o.status === "ERROR");
16
+ if (errored)
17
+ return errored;
18
+ const failed = present.find((o) => o.status === "FAIL");
19
+ if (failed)
20
+ return failed;
21
+ return present[0];
22
+ }
1
23
  /**
2
24
  * Collapse N rep outcomes into one scenario verdict. A rep is "clean" when its
3
25
  * judge did not misfire. If fewer than half the reps are clean the scenario is
@@ -31,15 +53,19 @@ export function aggregateReps(outcomes, threshold) {
31
53
  * caller to merge.
32
54
  */
33
55
  export function outcomesToResult(id, outcomes, repCount, threshold) {
56
+ // Spread rather than always-set: a scenario with no trace assertions must
57
+ // produce a result byte-identical to one from before this field existed.
58
+ const objective = aggregateObjective(outcomes);
59
+ const objectiveField = objective ? { objective } : {};
34
60
  if (repCount === 1) {
35
61
  const o = outcomes[0];
36
- return { id, judge_verdict: o.verdict, judge_reason: o.reason, suspect: o.suspect, override: null, note: "" };
62
+ return { id, judge_verdict: o.verdict, judge_reason: o.reason, suspect: o.suspect, override: null, note: "", ...objectiveField };
37
63
  }
38
64
  const agg = aggregateReps(outcomes, threshold);
39
65
  return {
40
66
  id, judge_verdict: agg.verdict, judge_reason: agg.reason, suspect: agg.suspect,
41
67
  reps: agg.reps, passes: agg.passes, clean: agg.clean, flakiness: agg.flakiness,
42
- pass_threshold: threshold, override: null, note: "",
68
+ pass_threshold: threshold, override: null, note: "", ...objectiveField,
43
69
  };
44
70
  }
45
71
  //# sourceMappingURL=reps.js.map
package/dist/rescore.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { readResults, writeResults, scoreContextFor } from "./results.js";
3
+ import { readResults, writeResults, scoreContextFor, rebuildScenarioResult } from "./results.js";
4
4
  import { appendJournal } from "./journal.js";
5
5
  import { policyDigest, POLICY_PREFIX } from "./sources.js";
6
6
  /**
@@ -65,7 +65,16 @@ export function rescoreRun(opts) {
65
65
  if (verdict !== s.judge_verdict) {
66
66
  changes.push({ id: s.id, from: s.judge_verdict, to: verdict, passes: s.passes, clean: s.clean, fromThreshold, toThreshold });
67
67
  }
68
- return { ...s, judge_verdict: verdict, pass_threshold: toThreshold };
68
+ // Through the choke point, not a spread. This was the FIFTH rewriter of a
69
+ // `ScenarioResult` and the only one still using `{ ...s }` — so it inherited
70
+ // none of the invariants the others get, and adding `objective` and
71
+ // `adjudication` to the type did not fail the build here. Concretely: a cell
72
+ // that adjudication settled FAIL reverted to PASS when a threshold change
73
+ // recomputed it from rep counters that adjudication never updated.
74
+ //
75
+ // Both blocks are CARRIED: a rescore re-applies a threshold to reps that were
76
+ // already measured. It re-measures nothing, so it may discard nothing.
77
+ return rebuildScenarioResult({ ...s, judge_verdict: verdict, pass_threshold: toThreshold }, s, { objective: "carry", adjudication: "carry" });
69
78
  });
70
79
  const ctx = scoreContextFor(prev, opts.spec);
71
80
  const results = writeResults(opts.runDir, {
package/dist/results.d.ts CHANGED
@@ -14,6 +14,56 @@ export interface ScenarioResult {
14
14
  clean?: number;
15
15
  flakiness?: number;
16
16
  pass_threshold?: number;
17
+ /**
18
+ * Objective trace-gate evidence. ADDITIVE and optional.
19
+ *
20
+ * Absent means "the scenario declared no trace assertions" — NOT an objective
21
+ * pass. Anything reading this must treat the two as different; collapsing them
22
+ * would silently upgrade every legacy result to "objectively verified".
23
+ */
24
+ objective?: ObjectiveResult;
25
+ /**
26
+ * Confidence-aware adjudication. ADDITIVE and optional.
27
+ *
28
+ * Absent means historical single-judge behavior — NOT that judges agreed. An
29
+ * unresolved adjudication additionally sets `suspect: true`, which is what
30
+ * actually blocks SHIP; this field is the audit trail behind that flag.
31
+ */
32
+ adjudication?: AdjudicationResult;
33
+ }
34
+ /** One judge's answer for a cell, kept verbatim however the collapse turned out. */
35
+ export interface Judgment {
36
+ /** 1-based: judgment 1 is the first-wave judge, 2 the secondary, 3 the tie-break. */
37
+ ordinal: number;
38
+ judge: {
39
+ provider: string;
40
+ model: string;
41
+ };
42
+ verdict: Verdict;
43
+ reason: string;
44
+ /** The judge misfired — recorded, never counted as a clean vote. */
45
+ suspect: boolean;
46
+ }
47
+ export interface AdjudicationResult {
48
+ state: "confirmed" | "tie_broken" | "unresolved";
49
+ /** Why the cell was re-judged. */
50
+ trigger: "ambiguous" | "contradictory" | "non_unanimous" | "ship_deciding";
51
+ /** Every judgment, in order. Never pruned — an author resolving this needs all of them. */
52
+ judgments: Judgment[];
53
+ /** The collapsed answer. Absent when unresolved. */
54
+ verdict?: "PASS" | "FAIL";
55
+ }
56
+ /** Objective gate outcome for one scenario cell. */
57
+ export interface ObjectiveResult {
58
+ /** ERROR means the evidence was missing or malformed — never a pass. */
59
+ status: "PASS" | "FAIL" | "ERROR";
60
+ trace_version?: number;
61
+ trace_sha256?: string;
62
+ assertions: {
63
+ kind: string;
64
+ status: "PASS" | "FAIL" | "ERROR";
65
+ detail: string;
66
+ }[];
17
67
  }
18
68
  export interface GradeSummary {
19
69
  passed: number;
@@ -56,16 +106,23 @@ export interface ResultsFile {
56
106
  harness_cli_version?: string;
57
107
  /**
58
108
  * `pass` when this run proved, before spending the wave, that the skill body was
59
- * reachable in the model's context (see canary.ts). Absent means the probe was
60
- * not asked for never that it failed, because a failed canary aborts the run
61
- * and no results.yaml is written.
109
+ * reachable in the model's context (see canary.ts). `skipped` when the probe was
110
+ * asked for but could not be performed SKILL.md has no `## ` heading to quote
111
+ * back, so no reply could prove anything. Absent means the probe was not asked
112
+ * for — never that it failed, because a failed canary aborts the run and no
113
+ * results.yaml is written.
114
+ *
115
+ * `skipped` exists because absent and skipped were the same value: a user who
116
+ * passed `--canary` precisely because pi ≥ 0.83.0 delivery is unreliable got a
117
+ * silently degraded probe, a fully billed wave, and a committed results.yaml
118
+ * byte-identical to a run where delivery was never checked at all.
62
119
  *
63
120
  * Only green runs can carry it: red delivers nothing by design and force delivers
64
121
  * through the system prompt. It is provenance for the *validity* of a green run,
65
122
  * which is why it lives here rather than only in the journal — `journal.jsonl` is
66
123
  * gitignored, and this claim has to survive a commit.
67
124
  */
68
- delivery_canary?: "pass";
125
+ delivery_canary?: "pass" | "skipped";
69
126
  skill: string;
70
127
  harness: string;
71
128
  model: string;
@@ -152,12 +209,35 @@ export declare function runDirFor(skillDir: string, harness: string, model: Mode
152
209
  export declare function transcriptPath(runDir: string, scenarioId: string, mode: string, rep?: number): string;
153
210
  export declare function reportPath(runDir: string): string;
154
211
  export declare function resultsPath(runDir: string): string;
155
- /** The verdict that counts: author override when present, else the judge's. */
212
+ /**
213
+ * The verdict that counts: author override when present, else the objective
214
+ * gate, else the judge's.
215
+ *
216
+ * **The objective gate outranks the judge.** `assert.trace` is a mechanical
217
+ * statement about what the model DID — it called `write`, it touched `.env`.
218
+ * The judge is an LLM reading prose. When they disagree, the measurement wins.
219
+ *
220
+ * This is the only place that ordering is enforced, and it has to be here.
221
+ * `objective` used to reach the ship decision solely through `gatePrefix` in
222
+ * `run.ts`, which forces a single rep's verdict — so every path that recomputed
223
+ * a verdict afterwards silently dropped the gate while keeping the `objective`
224
+ * block that claimed it was enforced. Three of them did: `--reps N` out-voted an
225
+ * objective FAIL 2-to-1 (100%, grade A, SHIP, on a CRITICAL scenario that called
226
+ * a forbidden tool), `regrade` re-judged from a transcript the tool calls are
227
+ * absent from, and `regate` recomputed it. `reps.ts` already states the policy —
228
+ * "one rep that called a forbidden tool is a real finding, not a minority draw
229
+ * to be voted away" — and nothing enforced it.
230
+ *
231
+ * An author override still wins, exactly as it does over `suspect`. Overriding a
232
+ * deterministic assertion is a deliberate, recorded human act — and the failure
233
+ * this guards against was never a human deciding, it was nobody deciding.
234
+ */
156
235
  export declare function effectiveVerdicts(scenarios: ScenarioResult[]): ScenarioVerdict[];
157
236
  /**
158
237
  * The ONLY place effective_grade is computed. Every writer goes through here,
159
238
  * so a persisted grade can never disagree with verdicts + overrides.
160
- * ctx is null for unscored (red/force) runs.
239
+ * ctx is null for unscored runs — `red` only, since 0.5.0: `force` is a real
240
+ * deployment and is scored (see SCORED_MODES directly above).
161
241
  */
162
242
  export declare function finalizeResults(draft: ResultsDraft, ctx: ScoreContext | null): ResultsFile;
163
243
  /** Finalize + persist results.yaml (creating the run dir). Returns what was written. */
@@ -207,8 +287,50 @@ export declare function findJudgeRawFiles(runDir: string, scenarioId: string, mo
207
287
  * generated evidence, ignored like transcripts, not committed like results.yaml.
208
288
  */
209
289
  export declare function diffPath(runDir: string, scenarioId: string, mode: string, rep?: number): string;
290
+ /**
291
+ * What happens to one piece of recorded evidence when a command rebuilds a result.
292
+ *
293
+ * - `carry` — the command did not re-measure this, so the prior value still
294
+ * describes the run and must survive.
295
+ * - `fresh` — the command re-measured it; take the new value.
296
+ * - `drop` — the command invalidated it; a stale value would misinform.
297
+ */
298
+ export type EvidencePolicy = "carry" | "fresh" | "drop";
299
+ export interface RebuildPolicy {
300
+ objective: EvidencePolicy;
301
+ adjudication: EvidencePolicy;
302
+ }
303
+ /**
304
+ * Rebuild a `ScenarioResult` after a command re-measured part of it.
305
+ *
306
+ * **The single choke point for every rewriter**, and exhaustive by construction:
307
+ * every field is destructured below, so adding one to `ScenarioResult` fails the
308
+ * build HERE until someone decides whether it is carried, taken fresh, or
309
+ * dropped. That guard is the whole point of the function.
310
+ *
311
+ * It exists because the ad-hoc version — `{ ...fresh, override: prior.override,
312
+ * note: prior.note }`, written independently in three places — silently dropped
313
+ * `objective` from `grade` and `adjudication` from `regate`. Both failures ran in
314
+ * the dangerous direction: a trace-gated scenario re-read as "no assertions
315
+ * declared", and an unresolved judge disagreement as a settled verdict. 1,036
316
+ * tests passed through it; a real smoke run caught it.
317
+ *
318
+ * The author's `override` and `note` are always carried and are not policy —
319
+ * no command re-measures a human's judgement.
320
+ */
321
+ export declare function rebuildScenarioResult(fresh: ScenarioResult, prior: ScenarioResult | undefined, policy: RebuildPolicy): ScenarioResult;
322
+ /**
323
+ * Where a rep's execution trace is saved: `<id>.<mode>[.rep<k>].trace.jsonl`.
324
+ *
325
+ * `.jsonl` rather than `.txt` so it is distinguishable at a glance from a
326
+ * transcript, and one JSON object per line so a multi-turn scenario's per-turn
327
+ * traces append without a wrapper.
328
+ */
329
+ export declare function tracePath(runDir: string, scenarioId: string, mode: string, rep?: number): string;
210
330
  /** A scenario's staged-diff files, sorted (plain first, then numeric rep). Mode-scoped when given. */
211
331
  export declare function findDiffFiles(runDir: string, scenarioId: string, mode?: string): string[];
332
+ /** A scenario's execution-trace files, sorted (plain first, then numeric rep). Mode-scoped when given. */
333
+ export declare function findTraceFiles(runDir: string, scenarioId: string, mode?: string): string[];
212
334
  /** A single representative transcript file for a scenario in a run dir. Null if none. */
213
335
  export declare function findTranscriptFile(runDir: string, scenarioId: string): string | null;
214
336
  /**