promptwheel 0.7.2 → 0.7.4

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 CHANGED
@@ -1,21 +1,202 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Matthew Owens
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # PromptWheel
2
2
 
3
- [![CI](https://github.com/promptwheel-ai/promptwheel/actions/workflows/ci.yml/badge.svg)](https://github.com/promptwheel-ai/promptwheel/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) ![Node ≥18](https://img.shields.io/badge/node-%E2%89%A518-brightgreen) ![deps: zero](https://img.shields.io/badge/deps-zero-blue)
3
+ [![CI](https://github.com/promptwheel-ai/promptwheel/actions/workflows/ci.yml/badge.svg)](https://github.com/promptwheel-ai/promptwheel/actions/workflows/ci.yml) [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE) ![Node ≥18](https://img.shields.io/badge/node-%E2%89%A518-brightgreen) ![deps: zero](https://img.shields.io/badge/deps-zero-blue)
4
4
 
5
5
  **A deterministic check for your coding loop.** A green test should mean your agent *fixed the code*, not that it edited the test to match the bug. PromptWheel tells the difference: it re-proves every win from the source changes alone, with no LLM, so a win that only survived by editing the test reads `GAMED`. Un-gameable by construction, because the code being checked never gets to grade itself.
6
6
 
@@ -213,6 +213,20 @@ Teams keep one shared base config and have every repo inherit it via `extends`:
213
213
 
214
214
  Read this way, `extends` is **the shared invariants, the "business rules", your agents inherit and are held to**: enforced as *measured guards* (a trusted regression fails the gate / reverts the commit), not advisory text an agent can quietly ignore. (Natural-language conventions belong in `AGENTS.md`; only deterministic, measurable guards belong here.)
215
215
 
216
+ ## Mandates (protected paths)
217
+
218
+ Some rules are not a metric at all, they are a hard line: *never touch `src/auth/**`*, *the migration files are frozen*, *do not edit the billing schema*. Declare those as `mandates`, and any change that touches a protected path **fails the gate before a single metric is read**, however green everything else is:
219
+
220
+ ```json
221
+ // promptwheel.config.json
222
+ { "mandates": [
223
+ { "name": "no-auth-edits", "paths": ["src/auth/**"], "reason": "auth changes go through a dedicated, reviewed PR" }
224
+ ],
225
+ "metrics": [ /* ... */ ] }
226
+ ```
227
+
228
+ A mandate is deterministic (a path match on the diff, zero-LLM), rides at the top of the report, and **inherits through `extends`** so a parent scope's hard rule holds for every repo beneath it. It is folded into the gate fingerprint, so quietly deleting a mandate to pass is itself a tracked, tamper-evident change. This is the line between a contract and a request: `AGENTS.md` can *ask* an agent not to touch auth; a mandate *will not let the change past the gate*.
229
+
216
230
  ## Trust model, the point of the whole thing
217
231
 
218
232
  A number that jumps around between runs is worthless as a signal. PromptWheel won't pretend otherwise:
@@ -229,6 +243,10 @@ The accumulated record of **which change-types move which metrics** is the asset
229
243
  - **vs loop/agent frameworks** (Ralph, GEPA, reward models): PromptWheel is the **execution-grounded reward they lack**, it runs your real suite with zero deps; it does not drive the loop or do test-time search.
230
244
  - **When NOT to use it:** if you only care that tests pass, your base verifier already has you covered. PromptWheel earns its place when you have a **graded numeric metric** beyond pass/fail (eval score, $/run, latency, size) that a change could quietly move.
231
245
 
246
+ ## Portability
247
+
248
+ The core gamed-win check is **git only** and runs anywhere git does: it classifies the files a win touched (`git diff --name-only`) to separate production source from test, config, and grader files, so a green that came only from editing the goalposts is caught the same on Linux, macOS, and Windows (the `gamed-catch` CI job proves this on all three). The starter tripwire metrics that `init` writes (`test_count`, `assertions`, `suppressions`, `skipped_tests`) are `grep` one-liners that assume a GNU-grep-compatible shell, which PromptWheel runs through the system shell (`sh` on Linux/macOS, `cmd` on native Windows). Where grep is absent, those metrics read **unmeasurable**, and an unmeasurable guard **fails closed** (verdict `FAIL`), so a gamed green is still caught, never passed, it just lands as `FAIL` rather than the dedicated `GAMED`. Run under WSL or git-bash, or replace those tripwire `cmd`s with your toolchain's own counters, for a clean verdict on Windows.
249
+
232
250
  ## Docs
233
251
 
234
252
  - [docs/DETECTION-LAYERS.md](docs/DETECTION-LAYERS.md), how `--detect-gaming` fits as the **deterministic layer** alongside held-out tests, LLM judges, and human review: the coverage matrix, the compose-as-a-pipeline model, and the honest in/out-of-scope boundary.
@@ -46,19 +46,22 @@ function resolveConfig(p, repo, label, seen) {
46
46
  try {
47
47
  const cfg = readConfigFile(p);
48
48
  const byName = new Map();
49
+ const mandatesByName = new Map(); // hard rules accumulate down the extends chain (a parent's holds)
49
50
  const scalars = {};
50
51
  for (const ref of [].concat(cfg.extends || [])) {
51
52
  const bp = isAbsolute(ref) ? ref : join(dirname(p), ref);
52
53
  if (!existsSync(bp)) { console.error(`extends target not found: ${ref} (from ${relOf(repo, p)})`); process.exit(2); }
53
54
  const base = resolveConfig(bp, repo, relOf(repo, bp), seen);
54
55
  for (const m of base.metrics) byName.set(m.name, m);
56
+ for (const md of (base.mandates || [])) if (md && md.name) mandatesByName.set(md.name, md);
55
57
  for (const k of ['repeat', 'linkNodeModules', 'linkDirs', 'env', 'setup', 'record', 'gamingThreshold', 'evaluatorPaths']) if (base[k] !== undefined) scalars[k] = base[k];
56
58
  }
57
59
  for (const m of (cfg.metrics || [])) {
58
60
  byName.set(m.name, { ...m, __src: label, __override: byName.has(m.name) });
59
61
  }
62
+ for (const md of (cfg.mandates || [])) if (md && md.name) mandatesByName.set(md.name, { ...md, __src: label });
60
63
  for (const k of ['repeat', 'linkNodeModules', 'linkDirs', 'env', 'setup', 'record', 'gamingThreshold', 'evaluatorPaths']) if (cfg[k] !== undefined) scalars[k] = cfg[k];
61
- return { ...scalars, metrics: [...byName.values()] };
64
+ return { ...scalars, metrics: [...byName.values()], mandates: [...mandatesByName.values()] };
62
65
  } finally {
63
66
  seen.delete(abs); // only ACTIVE ancestors are a cycle, a diamond (a base reached two ways) is fine
64
67
  }
@@ -267,6 +270,26 @@ function evaluatorMatcher(cfg) {
267
270
  return (p) => res.some((re) => re.test(p));
268
271
  }
269
272
 
273
+ // mandates: named hard rules that compile to a deterministic gate. A protected-path mandate
274
+ // forbids ANY change to its paths (same glob semantics as evaluatorPaths). A hit fails the gate
275
+ // regardless of metrics and rides at the top of the report; mandates inherit through `extends`,
276
+ // so a parent scope's rule holds for every repo beneath it.
277
+ function checkMandates(repo, base, head, cfg) {
278
+ const mandates = Array.isArray(cfg.mandates) ? cfg.mandates : [];
279
+ if (!mandates.length) return [];
280
+ let changed = [];
281
+ try { changed = git(['diff', '--name-only', base, head], repo).split('\n').filter(Boolean); } catch { return []; }
282
+ const out = [];
283
+ for (const m of mandates) {
284
+ const pats = (Array.isArray(m.paths) ? m.paths : []).filter((s) => typeof s === 'string' && s.trim());
285
+ if (!pats.length) continue;
286
+ const res = pats.map(globToRe);
287
+ const hit = changed.filter((f) => res.some((re) => re.test(f)));
288
+ if (hit.length) out.push({ name: String(m.name || 'mandate'), reason: m.reason ? String(m.reason).slice(0, 300) : '', files: hit.slice(0, 20) });
289
+ }
290
+ return out;
291
+ }
292
+
270
293
  // split the agent's changed files into production-source vs test/config/grader/golden.
271
294
  // `isEval` is the repo's opt-in evaluator-path matcher, treated as non-source alongside
272
295
  // the built-in classifier, so a cheat that only edits a declared gate file is caught.
@@ -298,7 +321,9 @@ function measureSourceOnly(repo, base, head, metric, cfg, repeat) {
298
321
  const env = bridgeEnv(repo, wt, cfg);
299
322
  const patch = git(['diff', base, head, '--', ...source], repo);
300
323
  if (patch.trim()) {
301
- const tryApply = (extra) => { execFileSync('git', ['apply', '--whitespace=nowarn', ...extra], { cwd: wt, input: patch + '\n', encoding: 'utf8' }); };
324
+ // stdio stderr 'ignore': git apply --3way prints "Applied patch ... cleanly" to stderr; that
325
+ // is noise on an otherwise-quiet run (and corrupts --json for callers that fold in stderr).
326
+ const tryApply = (extra) => { execFileSync('git', ['apply', '--whitespace=nowarn', ...extra], { cwd: wt, input: patch + '\n', encoding: 'utf8', stdio: ['pipe', 'ignore', 'ignore'] }); };
302
327
  try { tryApply(['--3way']); }
303
328
  catch { try { tryApply([]); } catch { return { samples: [], hadSourceChange: true, applyFailed: true }; } }
304
329
  }
@@ -454,6 +479,46 @@ function gateFingerprint(metricsList, scalars) {
454
479
  })).sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0)),
455
480
  gamingThreshold: scalars.gamingThreshold ?? null,
456
481
  evaluatorPaths: Array.isArray(scalars.evaluatorPaths) ? [...scalars.evaluatorPaths].sort() : [],
482
+ mandates: Array.isArray(scalars.mandates) ? scalars.mandates.map((m) => ({ name: String(m.name || ''), paths: [...(Array.isArray(m.paths) ? m.paths : [])].sort() })).sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) : [],
483
+ };
484
+ return createHash('sha256').update(JSON.stringify(norm)).digest('hex').slice(0, 16);
485
+ }
486
+
487
+ // tool version (read once from the sibling package.json) for the provenance receipt
488
+ const TOOL_VERSION = (() => {
489
+ try { return JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf8')).version || null; }
490
+ catch { return null; }
491
+ })();
492
+
493
+ // full sha of a ref, best-effort (never throws into the gate)
494
+ function safeRev(repo, ref) { try { return git(['rev-parse', ref], repo); } catch { return null; } }
495
+
496
+ // SHA-256 (truncated) of a file's content at a ref, or null if the file is absent there
497
+ function blobHashAt(repo, ref, path) {
498
+ try { return createHash('sha256').update(execFileSync('git', ['show', `${ref}:${path}`], { cwd: repo, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] })).digest('hex').slice(0, 16); }
499
+ catch { return null; } // absent at this ref (added or removed)
500
+ }
501
+ // declared evaluatorPaths whose CONTENT changed between base and head. A declared gate file is a
502
+ // goalpost the user named; editing it in the same diff that improves a metric is gamed by
503
+ // declaration (content-hash auto-fail) - deterministic even when the source-only re-run is inert.
504
+ // Fires ONLY on declared files, so the opt-in semantics (an undeclared config stays source) hold.
505
+ function changedEvaluatorPaths(repo, base, head, cfg) {
506
+ const isEval = evaluatorMatcher(cfg);
507
+ let changed = [];
508
+ try { changed = git(['diff', '--name-only', base, head], repo).split('\n').filter(Boolean).filter(isEval); }
509
+ catch { return []; }
510
+ return changed.map((p) => ({ path: p, base: blobHashAt(repo, base, p), head: blobHashAt(repo, head, p) }))
511
+ .filter((e) => e.base !== e.head);
512
+ }
513
+
514
+ // reproducible fingerprint of the verdict CONTENT (everything but the provenance block itself), so
515
+ // a skeptic who re-runs (base, head, config) gets the same hash - the tamper-evident receipt.
516
+ function verdictFingerprint(report) {
517
+ const norm = {
518
+ verdict: report.verdict,
519
+ metrics: (report.metrics || []).map((m) => ({ name: m.name, status: m.status, ok: m.ok === true, guard: m.guard === true, gamed: m.gamed === true }))
520
+ .sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0)),
521
+ gate: (report.gate && report.gate.fingerprint) || null,
457
522
  };
458
523
  return createHash('sha256').update(JSON.stringify(norm)).digest('hex').slice(0, 16);
459
524
  }
@@ -522,6 +587,22 @@ function gate(repo, opts) {
522
587
  m.gamed = j.gamed; m.sourceOnly = j.sourceOnly; m.retained = j.retained; m.gamingReason = j.reason;
523
588
  }
524
589
  }
590
+ // content-hash auto-fail (Section 3): a declared evaluatorPath gate file edited in this diff is a
591
+ // moved goalpost, so a metric that improved alongside it is gamed by declaration - deterministic,
592
+ // even if the source-only re-run above read inert. An allow-trailer can still clear it, below.
593
+ let evalChanged = [];
594
+ if (opts.detectGaming) {
595
+ evalChanged = changedEvaluatorPaths(repo, base, head, cfg);
596
+ if (evalChanged.length) {
597
+ for (const m of metrics) {
598
+ if (m.status !== 'improved' || m.gamed === true) continue;
599
+ const cm = cfg.metrics.find((c) => c.name === m.name);
600
+ if (cm && cm.gamingCheck === false) continue; // tripwire/test-side guards legitimately live in gate files
601
+ m.gamed = true;
602
+ m.gamingReason = `a declared evaluatorPath gate file changed in this diff (${evalChanged.map((e) => e.path).join(', ')}); a win alongside a goalpost edit is gamed by declaration`;
603
+ }
604
+ }
605
+ }
525
606
  // gate integrity (Section 3): did HEAD weaken the gate it is judged by? Resolve the gate as
526
607
  // of BASE; a guard HEAD dropped is re-measured under its base definition and only counts as
527
608
  // tampering if it WOULD HAVE FAILED at head (a real regression hidden by dropping the guard).
@@ -545,6 +626,7 @@ function gate(repo, opts) {
545
626
  head: gateFingerprint(cfg.metrics, cfg),
546
627
  },
547
628
  ...(weakened.length ? { weakened } : {}),
629
+ ...(evalChanged.length ? { evaluatorChanged: evalChanged } : {}),
548
630
  };
549
631
  }
550
632
  // declared override: a Sawbuck-Allow trailer (or --allow) acknowledges an intentional
@@ -560,6 +642,9 @@ function gate(repo, opts) {
560
642
  if (gw) gateInfo.allowed = true;
561
643
  }
562
644
  }
645
+ // mandates run first: a protected-path hard rule fails the gate no matter what the metrics say.
646
+ const mandateViolations = checkMandates(repo, base, head, cfg);
647
+ const mandated = mandateViolations.length > 0;
563
648
  const failed = metrics.some((m) => m.guard && !m.ok);
564
649
  const gamed = metrics.some((m) => m.gamed === true) || !!(gateInfo && gateInfo.weakened && !gateInfo.allowed);
565
650
  // a guard that never runs (inert: a pass/fail metric stuck at 0 across both refs) verifies
@@ -567,7 +652,7 @@ function gate(repo, opts) {
567
652
  // BUT scope it to a bare no-op run: an inert guard must NOT bury a genuine, measured win
568
653
  // elsewhere (that would make `improve` revert good changes and misread them as a plateau).
569
654
  const inconclusive = !failed && !gamed && metrics.some((m) => m.inert) && !metrics.some((m) => m.status === 'improved');
570
- const verdict = failed ? 'fail' : gamed ? 'gamed' : inconclusive ? 'inconclusive' : 'pass';
655
+ const verdict = (mandated || failed) ? 'fail' : gamed ? 'gamed' : inconclusive ? 'inconclusive' : 'pass';
571
656
  const report = {
572
657
  base: short(repo, base), head: short(repo, head), repeat, mode: opts.working ? 'working' : 'refs',
573
658
  // learning-substrate fields (Phase 5): cohort segments reliability by environment,
@@ -576,9 +661,18 @@ function gate(repo, opts) {
576
661
  ...(opts.label ? { label: opts.label } : {}),
577
662
  subsystems: subsystemsOf(repo, base, head, cfg),
578
663
  verdict, metrics,
664
+ ...(mandateViolations.length ? { mandates: mandateViolations } : {}),
579
665
  ...(gateInfo ? { gate: gateInfo } : {}),
580
666
  ...(allowed ? { allowed } : {}),
581
667
  };
668
+ // provenance receipt: makes the verdict tamper-evident + reproducible ("re-run and get the same
669
+ // verdict is checkable"). Additive to the record; never changes the verdict.
670
+ report.provenance = {
671
+ tool: 'promptwheel', toolVersion: TOOL_VERSION,
672
+ baseSha: safeRev(repo, base), headSha: opts.working ? head : safeRev(repo, head),
673
+ configHash: gateFingerprint(cfg.metrics, cfg),
674
+ verdictHash: verdictFingerprint(report),
675
+ };
582
676
  if (!opts.noRecord && cfg.record !== false) recordOutcome(repo, report);
583
677
  return report;
584
678
  }
@@ -1031,6 +1125,7 @@ const short = (repo, ref) => { try { return git(['rev-parse', '--short', ref], r
1031
1125
  function printHuman(r) {
1032
1126
  const arrowFor = (m) => (m.delta == null ? '?' : m.delta > 0 ? '▲' : m.delta < 0 ? '▼' : '=');
1033
1127
  console.log(`\nPromptWheel ${r.base} → ${r.head}${r.repeat > 1 ? ` (×${r.repeat})` : ''}\n`);
1128
+ if (r.mandates) for (const md of r.mandates) console.log(` ⛔ MANDATE "${md.name}" violated${md.reason ? ': ' + md.reason : ''} (touched: ${md.files.join(', ')})`);
1034
1129
  for (const m of r.metrics) {
1035
1130
  const tag = m.guard ? (m.ok ? 'guard✓' : 'GUARD✗') : 'info';
1036
1131
  const d = m.delta == null ? 'n/a' : (m.delta > 0 ? `+${m.delta}` : `${m.delta}`);
@@ -1039,8 +1134,10 @@ function printHuman(r) {
1039
1134
  if (m.gamed === true) console.log(` 🚩 GAMED, ${m.gamingReason}`);
1040
1135
  }
1041
1136
  if (r.gate && r.gate.weakened) for (const w of r.gate.weakened) console.log(` 🚩 GATE WEAKENED, the guard "${w.name}" was ${w.change === 'guard-removed' ? 'removed' : 'disabled'} in this change and it would have ${w.status} at head (goalpost moved, not earned)`);
1042
- console.log(`\n VERDICT: ${r.verdict.toUpperCase()}${r.verdict === 'fail' ? ', a guarded metric regressed (beyond noise)' : r.verdict === 'gamed' ? ', a metric "improved" by editing the goalposts, not the source' : r.verdict === 'inconclusive' ? ', a guard is inert (measured nothing); a pass cannot be certified' : ''}`);
1043
- if (r.verdict === 'fail') console.log(' intentional? loosen that guard locally in promptwheel.config.json (guard:false, or override the inherited metric by name), `promptwheel guards` shows the effective set');
1137
+ const failReason = r.mandates ? ', a mandate was violated (a protected path changed)' : ', a guarded metric regressed (beyond noise)';
1138
+ console.log(`\n VERDICT: ${r.verdict.toUpperCase()}${r.verdict === 'fail' ? failReason : r.verdict === 'gamed' ? ', a metric "improved" by editing the goalposts, not the source' : r.verdict === 'inconclusive' ? ', a guard is inert (measured nothing); a pass cannot be certified' : ''}`);
1139
+ if (r.verdict === 'fail' && r.mandates) console.log(' a mandate is a hard rule; if the change is truly intended, edit the mandate in promptwheel.config.json (a tracked, tamper-evident change), do not work around it');
1140
+ else if (r.verdict === 'fail') console.log(' intentional? loosen that guard locally in promptwheel.config.json (guard:false, or override the inherited metric by name), `promptwheel guards` shows the effective set');
1044
1141
  if (r.allowed) console.log(` ✓ allowed: ${r.allowed.cleared.join(', ')} acknowledged as an intentional change, recorded (Sawbuck-Allow: ${r.allowed.reason})`);
1045
1142
  console.log('');
1046
1143
  }
@@ -1059,11 +1156,12 @@ function renderMarkdown(r) {
1059
1156
  '',
1060
1157
  `\`${r.base} → ${r.head}\` · ${r.mode} mode${r.repeat > 1 ? ` · ×${r.repeat}` : ''}`,
1061
1158
  '',
1159
+ ...(r.mandates ? [r.mandates.map((md) => `> ⛔ **Mandate violated:** \`${md.name}\`${md.reason ? ': ' + md.reason : ''} (touched \`${md.files.join('`, `')}\`)`).join('\n'), ''] : []),
1062
1160
  '| metric | before | after | Δ | status | confidence |',
1063
1161
  '|---|--:|--:|--:|---|---|',
1064
1162
  rows,
1065
1163
  '',
1066
- r.verdict === 'gamed' ? '> 🚩 A metric "improved" only because the agent edited tests/config/grader, not the source. The win does not survive a source-only re-run.' : r.verdict === 'fail' ? '> ❌ A 🛡️ guarded metric regressed beyond the noise band.' : r.verdict === 'inconclusive' ? '> 🟡 A 🛡️ guarded check is **inert**, it never runs, so nothing was actually verified. Fix its command before trusting a pass.' : '> ✅ No guarded metric regressed.',
1164
+ r.verdict === 'gamed' ? '> 🚩 A metric "improved" only because the agent edited tests/config/grader, not the source. The win does not survive a source-only re-run.' : r.verdict === 'fail' ? (r.mandates ? '> ⛔ A mandate was violated: a protected path changed. This is a hard rule, enforced before any metric.' : '> ❌ A 🛡️ guarded metric regressed beyond the noise band.') : r.verdict === 'inconclusive' ? '> 🟡 A 🛡️ guarded check is **inert**, it never runs, so nothing was actually verified. Fix its command before trusting a pass.' : '> ✅ No guarded metric regressed.',
1067
1165
  ...(r.gate && r.gate.weakened ? ['', `> 🚩 **Gate weakened:** ${r.gate.weakened.map((w) => `\`${w.name}\` ${w.change === 'guard-removed' ? 'removed' : 'disabled'} (would have ${w.status} at head)`).join('; ')}. The pass was bought by dropping a guard, not by earning it.`] : []),
1068
1166
  '',
1069
1167
  '<sub>🛡️ = guard · _prove every change moved a metric_ · [PromptWheel](https://github.com/promptwheel-ai/promptwheel)</sub>',
@@ -1094,7 +1192,7 @@ function parseArgs(argv) {
1094
1192
 
1095
1193
  // pure, side-effect-free helpers are exported for unit testing; the CLI below only
1096
1194
  // runs when this file is executed directly (not when imported by the test suite).
1097
- export { extract, evaluate, median, spread, renderMarkdown, isNonSource, evaluatorMatcher, gain, judgeGaming, foldOutcomes, betaMean, scoreKey };
1195
+ export { extract, evaluate, median, spread, renderMarkdown, isNonSource, evaluatorMatcher, gain, judgeGaming, foldOutcomes, betaMean, scoreKey, verdictFingerprint };
1098
1196
 
1099
1197
  // ─────────────────────────────────────────────────────────────────────────────
1100
1198
  // Public library API: the Verified-Outcome Contract, in process.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "promptwheel",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "A deterministic, zero-LLM check for your coding loop. It proves every change earned its win by re-running the result from the agent's source edits alone, so a green that came from editing the test reads GAMED. Runs in CI or a Claude Code hook, or import { check } in process.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -34,7 +34,7 @@
34
34
  "url": "https://github.com/promptwheel-ai/promptwheel/issues"
35
35
  },
36
36
  "author": "Matthew Owens",
37
- "license": "MIT",
37
+ "license": "Apache-2.0",
38
38
  "keywords": [
39
39
  "agent",
40
40
  "ci",