@crewhaus/grader-provability 0.0.0-stage → 0.8.1

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,9 @@
1
+ CrewHaus Factory
2
+ Copyright 2026 Max Meier
3
+
4
+ This product includes software developed by Max Meier
5
+ (operating as StudioMax — https://studiomax.io) and contributors.
6
+
7
+ The CrewHaus name and logo are trademarks of Max Meier. See
8
+ https://github.com/crewhaus/factory/blob/main/TRADEMARK.md for the
9
+ use-of-marks policy.
package/README.md CHANGED
@@ -1,3 +1,99 @@
1
- # Temporary Holding Version
1
+ # @crewhaus/grader-provability
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Deterministic eval graders over the proof bundle the provability gate produced for each eval
4
+ sample (`RunResult.artifacts.proof`, the gate's standing verdict). They make no model call and
5
+ never re-run the verifier: the bundle is the gate's own record of the answer, so a graded sample
6
+ and the footer the answer carried can never disagree.
7
+
8
+ | Grader | Measures | Passes |
9
+ |---|---|---|
10
+ | `provability.claimCoverage` | claims that meet the floor ÷ claims that count (assumptions excluded) | ≥ 0.95, and every `expected_sources` origin grounds the answer |
11
+ | `provability.rungAchieved` | the highest floor the answer passed, as rank ÷ 4 | at or above the floor |
12
+ | `provability.citationValidity` | defined markers ÷ markers | ≥ 0.99 |
13
+ | `provability.assumptionRate` | declared assumptions (refused ones and proof hypotheses included) ÷ claims; lower is better | ≤ 0.1 |
14
+ | `provability.replayIntegrity` | replayed tool results that matched ÷ replayed | = 1.0 (none replayed passes) |
15
+ | `provability.costPerProvenClaim` | gate-caused spend per met claim | reported, never gates |
16
+
17
+ The floor is the sample's `metadata.provability.level` when set, else the run's (the spec's
18
+ `provability.level`, or `crewhaus eval --provability <level>`). `crewhaus eval` runs each such
19
+ sample's gate at its own level, so its grade is exact. A sample can also name the sources that
20
+ must ground its answer, as URLs, `doi:` references or workspace paths:
21
+
22
+ ```jsonl
23
+ {"id": "refund", "input": "What is the refund window?", "metadata": {"provability": {"level": "grounded", "expected_sources": ["https://acme.example/policy"]}}}
24
+ ```
25
+
26
+ `metadata.provability: grounded` is the shorthand for `{ level: grounded }`. A malformed value
27
+ fails the sample with a rationale naming the field, never silently grades it at the wrong bar.
28
+
29
+ ## Unmeasured is never a pass
30
+
31
+ A run with no proof bundle fails every grader with "no proof bundle (is provability:
32
+ declared?)", and a bundle the gate could not verify fails them with "the gate could not verify
33
+ this answer". Proof was expected, so a missing verdict is never a pass. A bundle made below the
34
+ sample's level cannot grade it either: rungs above a gate's floor are recorded without the checks
35
+ only those floors run, so the floor-dependent graders fail it as unmeasured (`citationValidity`
36
+ and `assumptionRate` do not depend on the floor and still measure). `isUnmeasured(result)` tells
37
+ these failures apart from measured ones by their pinned prefixes (`UNMEASURED_PREFIXES`), and the
38
+ roll-up keeps them out of a lower-is-better mean.
39
+
40
+ `costPerProvenClaim` prices the gate's retries from the run's cost events, or through a
41
+ `pricing` function when nothing metered the run, and adds the waiver judge's reported spend;
42
+ checker time (`proof_checked` durations) is reported beside it, never added. Tokens it cannot
43
+ price are reported as unpriced (the score is then a lower bound), never as free, and spend with
44
+ no met claim is reported as an infinite ratio.
45
+
46
+ ## API
47
+
48
+ ```ts
49
+ import { GraderRegistry } from "@crewhaus/grader-registry";
50
+ import { registerProvabilityGraders, summarizeProvabilityMetrics } from "@crewhaus/grader-provability";
51
+
52
+ const registry = new GraderRegistry();
53
+ registerProvabilityGraders(registry); // the graders above, under their canonical names
54
+ ```
55
+
56
+ - `registerProvabilityGraders(registry)` registers every grader, skipping a name already
57
+ present (a plugin registered first keeps it), and returns the canonical names.
58
+ - `PROVABILITY_GRADERS` (name, grader pairs in table order), `PROVABILITY_GRADER_NAMES`, and
59
+ `createProvabilityGraders({ pricing? })`, the same set with `costPerProvenClaim` pricing
60
+ through `pricing`. The graders are exported one by one too (`claimCoverage`, …).
61
+ - `provabilityGraderRole(name)`: `"requirement"` for the graders with a bar, `"report"` for
62
+ `costPerProvenClaim` (`PROVABILITY_REPORTED_GRADERS`), `undefined` for any other name.
63
+ - `summarizeProvabilityMetrics(byMetric): ProvabilitySummary` folds per-sample results into the
64
+ roll-up (mean, pass fraction, p50/p95, breaches, unmeasured counts);
65
+ `renderProvabilitySummaryLines(summary)` prints it; `summarizeCostPerProvenClaim` is the cost
66
+ metric's own fold.
67
+ - `PROVABILITY_METRIC_THRESHOLDS`, `PROVABILITY_METRIC_SPECS`, `sampleProvabilityOf(sample)`,
68
+ `expectedSourceKey(source, workspaceRoot?)`, `gateSpendOf(events, bundle?, { pricing? })`, and
69
+ the pinned prefixes.
70
+
71
+ ## How it is wired
72
+
73
+ `crewhaus eval` registers the graders in its default registry, so a graders file can name them
74
+ with `type: registry`, and `crewhaus eval --provability <level>` adds all of them to the run.
75
+ Either way they sit beside your graders' `combine:` policy rather than inside it: a sample passes
76
+ only when your graders pass and every provability bar holds, and the cost is reported only. A
77
+ `weight` on one of them is not used, and under `combine: any` or `weighted` the run says so at
78
+ start.
79
+
80
+ ## Limits
81
+
82
+ - A bundle made outside `crewhaus eval` (a hand-wired invoker) graded at a floor below its own is
83
+ re-read from the rungs the gate recorded: `grounded.independent` and the guarded HEAD apply only
84
+ at the run's own floor, so that grade is close, not exact.
85
+ - An `expected_sources` origin counts only when it grounded the answer in text the run did not
86
+ write there itself (`writtenBy`); a source the run wrote is named in the rationale instead.
87
+ - `citationValidity` counts the markers the answer wrote: a claim read from a definition line's
88
+ text is skipped, since its binding is defined by construction.
89
+
90
+ ## Tests
91
+
92
+ ```sh
93
+ bun test src
94
+ ```
95
+
96
+ Fixture bundles (`src/__test__/fixtures.ts`) pin each grader's score and rationale, the
97
+ unmeasured cases, the spend windows and pricing, the sample metadata reader and the roll-up.
98
+
99
+ Design: [design/0.8.0-provability-release.md](../../design/0.8.0-provability-release.md) §9.1.
package/dist/cost.d.ts ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * What the provability gate cost a sample (design/0.8.0-provability-release.md
3
+ * §9.1 `provability.costPerProvenClaim`, the `continuity.costPerProvenOutcome`
4
+ * precedent): the spend the gate CAUSED, read from the run's own trace events,
5
+ * never estimated.
6
+ *
7
+ * - re-runs — every model call inside a turn AFTER a failing
8
+ * `provability_graded` pass and BEFORE that turn's next pass: the retry
9
+ * (or escalation) the failing verdict triggered. Calls with
10
+ * `role: "judge"` are left out of the window: the waiver judge is counted
11
+ * from the gate's own report below (counting both would double it), and
12
+ * an `evaluation:` judge re-grading the re-run is that gate's spend;
13
+ * - the waiver judge — `judgeCostUsdMicros` on every `provability_graded`
14
+ * pass (the bundle's `spentUsdMicros` when the run carried no pass
15
+ * events, e.g. a hand-wired invoker that supplied only the bundle);
16
+ * - checker time — `durationMs` of every `proof_checked` event. Time, not
17
+ * money: reported beside the spend, never added to it.
18
+ *
19
+ * How a re-run call is priced depends on whether the run was METERED:
20
+ *
21
+ * - a run whose cost-tracker was attached (`CREWHAUS_COST_TRACKING=1`, or a
22
+ * session-scoped budget) publishes one `cost_accrual` per call, so the
23
+ * window's accruals ARE the price; an accrual the tracker could not price
24
+ * (`unpriced: true`) adds its tokens to the unpriced count;
25
+ * - an unmetered run (a plain `crewhaus eval` attaches no tracker) prices
26
+ * the window's `model_response` usage through the caller's `pricing`
27
+ * seam (the eval runner's `RunEvalOptions.pricing` — the same lookup the
28
+ * run's budget cap uses); a call it cannot price, or every call when no
29
+ * seam was given, is unpriced.
30
+ *
31
+ * Unpriced tokens are reported as UNPRICED, never as free: the grader marks
32
+ * the ratio a lower bound and the roll-up counts it apart.
33
+ */
34
+ import type { ProofBundle } from "@crewhaus/provability";
35
+ import type { TraceEvent } from "@crewhaus/trace-event-bus";
36
+ /**
37
+ * Prices one model call in USD micro-dollars, or `undefined` when the model
38
+ * has no pricing row. Structurally the eval runner's `EvalPricingFn`.
39
+ */
40
+ export type GatePricing = (model: string, tokens: {
41
+ readonly input: number;
42
+ readonly output: number;
43
+ }) => number | undefined;
44
+ export type GateSpend = {
45
+ /** Gate-triggered re-runs: agent/escalation calls inside a retry window, as priced. */
46
+ readonly rerunUsdMicros: number;
47
+ /** The opt-in paraphrase-waiver judge, as the gate reported it. */
48
+ readonly judgeUsdMicros: number;
49
+ /** `rerunUsdMicros + judgeUsdMicros` — a LOWER BOUND when {@link unpriced}. */
50
+ readonly totalUsdMicros: number;
51
+ /** Verification passes after the first, across every turn. */
52
+ readonly reruns: number;
53
+ /** Input + output tokens of the re-run calls (priced or not). */
54
+ readonly rerunTokens: number;
55
+ /** Re-run tokens nothing priced (an unpriced accrual, or a call the seam could not price). */
56
+ readonly unpricedTokens: number;
57
+ /** `unpricedTokens > 0`: the spend above is a lower bound. */
58
+ readonly unpriced: boolean;
59
+ /** `ProofCheck` checker runs and their summed wall-clock time. */
60
+ readonly checks: number;
61
+ readonly checkerMs: number;
62
+ };
63
+ /** The spend the gate caused across `events` (see the module doc). */
64
+ export declare function gateSpendOf(events: ReadonlyArray<TraceEvent>, bundle?: Pick<ProofBundle, "spentUsdMicros">, opts?: {
65
+ readonly pricing?: GatePricing;
66
+ }): GateSpend;
package/dist/cost.js ADDED
@@ -0,0 +1,91 @@
1
+ const finite = (v) => (typeof v === "number" && Number.isFinite(v) ? v : 0);
2
+ /** A per-call accrual (not the role-less optimizer roll-up, which re-sums per-call ones). */
3
+ const isCallAccrual = (event) => event.kind === "cost_accrual" && event.summary !== true;
4
+ /** The spend the gate caused across `events` (see the module doc). */
5
+ export function gateSpendOf(events, bundle, opts = {}) {
6
+ // Passes per turn, in publish order: a window opens after a FAILING pass
7
+ // and closes at the turn's next pass.
8
+ const passesByTurn = new Map();
9
+ let judgeUsdMicros = 0;
10
+ let sawPass = false;
11
+ let checks = 0;
12
+ let checkerMs = 0;
13
+ events.forEach((event, index) => {
14
+ if (event.kind === "provability_graded") {
15
+ sawPass = true;
16
+ judgeUsdMicros += finite(event.judgeCostUsdMicros);
17
+ const passes = passesByTurn.get(event.turnNumber) ?? [];
18
+ passes.push({ index, failing: event.verdict === "fail" });
19
+ passesByTurn.set(event.turnNumber, passes);
20
+ }
21
+ else if (event.kind === "proof_checked") {
22
+ checks += 1;
23
+ checkerMs += finite(event.durationMs);
24
+ }
25
+ });
26
+ if (!sawPass)
27
+ judgeUsdMicros = finite(bundle?.spentUsdMicros);
28
+ /** Whether event `index` of turn `turn` sits inside a retry window. */
29
+ const inWindow = (turn, index) => {
30
+ const passes = passesByTurn.get(turn);
31
+ if (passes === undefined)
32
+ return false;
33
+ for (let i = 0; i + 1 < passes.length; i++) {
34
+ const open = passes[i];
35
+ const close = passes[i + 1];
36
+ if (open.failing && index > open.index && index < close.index)
37
+ return true;
38
+ }
39
+ return false;
40
+ };
41
+ // A tracker publishes an accrual for EVERY call, so one per-call accrual
42
+ // anywhere means the accruals are the price; without one, the seam prices.
43
+ const metered = events.some(isCallAccrual);
44
+ let rerunUsdMicros = 0;
45
+ let rerunTokens = 0;
46
+ let unpricedTokens = 0;
47
+ events.forEach((event, index) => {
48
+ if (event.kind === "cost_accrual") {
49
+ if (event.role === "judge" || !inWindow(event.turnNumber, index))
50
+ return;
51
+ // The role-less optimizer total re-sums per-call accruals; a ROLED
52
+ // summary is a nested run (a Task child) whose calls this bus never saw.
53
+ if (event.summary === true && event.role === undefined)
54
+ return;
55
+ if (event.unpriced === true) {
56
+ unpricedTokens += finite(event.inputTokens) + finite(event.outputTokens);
57
+ }
58
+ else {
59
+ rerunUsdMicros += finite(event.costUsdMicros);
60
+ }
61
+ }
62
+ else if (event.kind === "model_response") {
63
+ if (event.role === "judge" || !inWindow(event.turnNumber, index))
64
+ return;
65
+ const input = finite(event.usage.input);
66
+ const output = finite(event.usage.output);
67
+ rerunTokens += input + output;
68
+ if (metered)
69
+ return;
70
+ const priced = opts.pricing?.(event.specModel ?? event.model, { input, output });
71
+ if (typeof priced === "number" && Number.isFinite(priced))
72
+ rerunUsdMicros += priced;
73
+ else
74
+ unpricedTokens += input + output;
75
+ }
76
+ });
77
+ let reruns = 0;
78
+ for (const passes of passesByTurn.values())
79
+ reruns += Math.max(0, passes.length - 1);
80
+ return {
81
+ rerunUsdMicros,
82
+ judgeUsdMicros,
83
+ totalUsdMicros: rerunUsdMicros + judgeUsdMicros,
84
+ reruns,
85
+ rerunTokens,
86
+ unpricedTokens,
87
+ unpriced: unpricedTokens > 0,
88
+ checks,
89
+ checkerMs,
90
+ };
91
+ }
@@ -0,0 +1,149 @@
1
+ /**
2
+ * The six provability graders (design/0.8.0-provability-release.md §9.1) —
3
+ * deterministic reads of the proof bundle the eval runner captured for a
4
+ * sample (`RunResult.artifacts.proof`, the gate's STANDING verdict). No
5
+ * grader re-verifies anything: the bundle is the gate's own record, and these
6
+ * only measure it, so a sample graded here and the footer its answer carried
7
+ * can never disagree.
8
+ *
9
+ * The floor a sample is graded at is `metadata.provability.level` when the
10
+ * sample sets one, else the bundle's own (the spec's `provability.level`, or
11
+ * the `crewhaus eval --provability` override). The eval runner wires each
12
+ * gated sample's gate AT that floor, so in a runner-made bundle the two
13
+ * agree and every grade is the gate's own. A bundle made elsewhere (a
14
+ * hand-wired invoker) can disagree:
15
+ * - a floor BELOW the bundle's re-reads the rungs the gate RECORDED: a
16
+ * claim meets it when it has no dangling marker and some non-assumption
17
+ * binding reached that rung. `grounded.independent` and the guarded HEAD
18
+ * are applied only at the run's own floor, so that grade is close, not
19
+ * exact;
20
+ * - a floor ABOVE the bundle's is not graded at all by the floor-dependent
21
+ * graders (claimCoverage, rungAchieved, replayIntegrity,
22
+ * costPerProvenClaim): the verifier computes rungs above its floor
23
+ * WITHOUT the checks only those floors run (replay at checked), so a
24
+ * recorded `checked` there is a claim nobody checked. Those graders fail
25
+ * the sample as unmeasured ({@link FLOOR_ABOVE_BUNDLE}); citationValidity
26
+ * and assumptionRate do not depend on the floor and still measure.
27
+ *
28
+ * Every failure that replaces a measurement starts with a pinned prefix
29
+ * ({@link UNMEASURED_PREFIXES}, read by {@link isUnmeasured} and the roll-up),
30
+ * never a guess:
31
+ * - NO BUNDLE — the run was not gated (no `provability:` block and no
32
+ * `--provability`), or the sample ended (an invoker error, a timeout)
33
+ * before the gate graded an answer. A provability grader is configured
34
+ * because proof is expected; a missing verdict must not read as a pass
35
+ * (the research report's NO_CITATIONS_NOTICE posture: an ungated answer
36
+ * never passes for a gated one).
37
+ * - UNVERIFIED — the gate's verifier threw and the answer stood unchecked
38
+ * (design §5.1 fail-open). Nothing was measured, so nothing passes.
39
+ * - INVALID METADATA — a malformed `metadata.provability`, naming the field.
40
+ * - FLOOR ABOVE THE BUNDLE — see above.
41
+ */
42
+ import type { GradeResult, Grader } from "@crewhaus/eval-grader";
43
+ import { type GatePricing } from "./cost";
44
+ /** The release thresholds (design §9.1's table). */
45
+ export declare const PROVABILITY_METRIC_THRESHOLDS: Readonly<{
46
+ /** met / (claims − assumptions) at the floor. */
47
+ claimCoverage: 0.95;
48
+ /** defined markers / markers. */
49
+ citationValidity: 0.99;
50
+ /** declared assumptions / claims — an UPPER bound. */
51
+ assumptionRate: 0.1;
52
+ /** matched replays / replays — every replay must match. */
53
+ replayIntegrity: 1;
54
+ }>;
55
+ /** The reason a provability grader returns when the run carried no bundle. */
56
+ export declare const NO_PROOF_BUNDLE = "no proof bundle (is provability: declared?)";
57
+ /** The pinned prefix of the result for a bundle whose verifier threw (§5.1 fail-open). */
58
+ export declare const UNVERIFIED_BUNDLE = "the gate could not verify this answer";
59
+ /** The pinned prefix of the result for a malformed `metadata.provability`. */
60
+ export declare const INVALID_SAMPLE_METADATA = "invalid metadata.provability";
61
+ /** The pinned prefix of a floor-dependent result whose floor is above the bundle's. */
62
+ export declare const FLOOR_ABOVE_BUNDLE = "not gradable at this floor";
63
+ /**
64
+ * Every prefix a result carries when it REPLACES a measurement (no score was
65
+ * measured; `score` is a placeholder 0). A roll-up keeps these out of a
66
+ * lower-is-better mean, where a placeholder 0 would read as the best value.
67
+ */
68
+ export declare const UNMEASURED_PREFIXES: ReadonlyArray<string>;
69
+ /** Whether a provability grade replaced its measurement with a failure (see {@link UNMEASURED_PREFIXES}). */
70
+ export declare function isUnmeasured(result: Pick<GradeResult, "rationale">): boolean;
71
+ /** The pinned prefix of an infinite `costPerProvenClaim` rationale (see the grader). */
72
+ export declare const INFINITE_COST_PREFIX = "\u221E per proven claim";
73
+ /** The pinned prefix of a `costPerProvenClaim` whose spend is a lower bound (see the grader). */
74
+ export declare const UNPRICED_COST_PREFIX = "\u2265 (partly unpriced) per proven claim";
75
+ /**
76
+ * met / (claims − assumptions) at the floor, the gate's own score when the
77
+ * floor is the run's. Passes at ≥ 0.95 AND when every
78
+ * `metadata.provability.expected_sources` origin grounded the answer — an ok
79
+ * source binding, or at `checked` / `proven` (where a source is never `ok`)
80
+ * one that reached `grounded` (see `sourceGrounds`). A missing one fails the
81
+ * sample; the score stays the coverage, the rationale names the source.
82
+ */
83
+ export declare const claimCoverage: Grader;
84
+ /**
85
+ * The highest floor the answer would have passed (`bundle.achieved`, the
86
+ * gate ran every rung for it), normalized 0..1 as rank/4 — a per-sample
87
+ * ladder score that shows HOW FAR an answer falls short. Passes when the
88
+ * achieved rung is at or above the floor.
89
+ */
90
+ export declare const rungAchieved: Grader;
91
+ /**
92
+ * defined markers / markers — the `cited` sub-check alone: every `[n]` in a
93
+ * claim needs its `[n]: …` definition. One binding is one marker occurrence;
94
+ * a marker with no definition is a binding whose reason is `no_definition`.
95
+ * No markers at all is a vacuous pass (claimCoverage is what fails an
96
+ * uncited answer). Passes at ≥ 0.99.
97
+ *
98
+ * Design §9.1 counts the markers the ANSWER wrote. A claim carrying
99
+ * `definition` is text a definition line shows after what it names, read
100
+ * as citing that definition: its one binding is the verifier's synthetic
101
+ * self-binding, defined by construction and never typed as a marker. So it
102
+ * is skipped — counted, a gloss sentence (or a long bibliography) would add
103
+ * a defined marker to both sides and lift a dangling-marker answer over the
104
+ * bar.
105
+ */
106
+ export declare const citationValidity: Grader;
107
+ /**
108
+ * declared assumptions / claims — the assumption dodge made visible. LOWER is
109
+ * better (the continuity.reAskRate precedent): passes at ≤ 0.1. Declared
110
+ * counts the accepted assumptions, the ones the config refused
111
+ * (`assumptions: forbid`, past `max_assumptions`) — a refused assumption is
112
+ * still the answer leaning on one — and the hypotheses accepted proofs rest
113
+ * on (`hypotheses`, design §6.4): a proof that assumes its own conclusion is
114
+ * not "0 assumptions". Zero claims is a vacuous 0.
115
+ */
116
+ export declare const assumptionRate: Grader;
117
+ /**
118
+ * replayed executions whose output digest matched / replayed executions.
119
+ * An execution is one `tool:<toolUseId>` (bindings citing the same call share
120
+ * its one replay). Must be exactly 1: a mismatch means a cited result is not
121
+ * what the tool returns for that input. None replayed is a vacuous pass —
122
+ * replay runs only at a `checked` floor, for pure tools, with
123
+ * `execution.replay` on.
124
+ */
125
+ export declare const replayIntegrity: Grader;
126
+ /**
127
+ * Gate-caused spend per met claim (see `./cost` for exactly what counts and
128
+ * how it is priced) — the `continuity.costPerProvenOutcome` precedent, but
129
+ * REPORTED, with no threshold: it never fails a measured sample (only a
130
+ * missing or unverified bundle does, like every grader here). Score is USD
131
+ * per claim met at the floor. Three outcomes are told apart by a pinned
132
+ * rationale prefix, which the roll-up reads:
133
+ * - {@link INFINITE_COST_PREFIX} — spend (priced, or tokens nothing could
134
+ * price) with zero met claims: the infinite ratio, kept JSON-safe as
135
+ * score 0;
136
+ * - {@link UNPRICED_COST_PREFIX} — some re-run tokens had no price, so the
137
+ * score is the PRICED part per met claim, a lower bound, never a $0 that
138
+ * reads as free;
139
+ * - otherwise the exact ratio.
140
+ *
141
+ * `pricing` prices re-run calls on a run no cost-tracker metered (the eval
142
+ * runner passes its own `RunEvalOptions.pricing`); without it those calls
143
+ * are unpriced.
144
+ */
145
+ export declare function createCostPerProvenClaim(opts?: {
146
+ readonly pricing?: GatePricing;
147
+ }): Grader;
148
+ /** {@link createCostPerProvenClaim} with no pricing seam (the registry's instance). */
149
+ export declare const costPerProvenClaim: Grader;