replz 0.0.1 → 0.3.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/LICENSE +21 -0
- package/README.md +214 -0
- package/dist/bin.js +4 -0
- package/dist/cases.d.ts +19 -0
- package/dist/cases.js +43 -0
- package/dist/cli.d.ts +37 -0
- package/dist/cli.js +124 -0
- package/dist/config.d.ts +33 -0
- package/dist/config.js +42 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/propose.d.ts +36 -0
- package/dist/propose.js +69 -0
- package/dist/run.d.ts +40 -0
- package/dist/run.js +54 -0
- package/dist/score.d.ts +45 -0
- package/dist/score.js +48 -0
- package/dist/shell.js +39 -0
- package/package.json +75 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ofri Peretz
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/ofri-peretz/burgee/tree/main/packages/replz" target="blank">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ofri-peretz/burgee/main/brand-assets/replz-lockup.svg" />
|
|
5
|
+
<img src="https://raw.githubusercontent.com/ofri-peretz/burgee/main/brand-assets/replz-lockup-light.svg" alt="replz" width="360" />
|
|
6
|
+
</picture>
|
|
7
|
+
</a>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
Play the bug back: replay the bugs that shipped, and grade the reviewer and the checks on them.
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://www.npmjs.com/package/replz"><img src="https://img.shields.io/npm/v/replz?style=flat-square&color=0a6b47" alt="replz on npm: the latest version" /></a>
|
|
16
|
+
<a href="https://www.npmjs.com/package/replz"><img src="https://img.shields.io/npm/dm/replz?style=flat-square" alt="replz downloads per month on npm" /></a>
|
|
17
|
+
<a href="https://github.com/ofri-peretz/burgee/actions/workflows/quality.yml?query=branch%3Amain"><img src="https://img.shields.io/github/actions/workflow/status/ofri-peretz/burgee/quality.yml?branch=main&style=flat-square&label=Quality%20Gate" alt="Quality Gate: the CI status of main" /></a>
|
|
18
|
+
<a href="https://app.codecov.io/gh/ofri-peretz/burgee/components"><img src="https://img.shields.io/codecov/c/github/ofri-peretz/burgee/main?component=replz&style=flat-square" alt="replz line coverage: its Codecov component" /></a>
|
|
19
|
+
<a href="https://scorecard.dev/viewer/?uri=github.com/ofri-peretz/burgee"><img src="https://img.shields.io/ossf-scorecard/github.com/ofri-peretz/burgee?style=flat-square&label=OpenSSF%20Scorecard" alt="OpenSSF Scorecard for the repository" /></a>
|
|
20
|
+
<a href="https://www.npmjs.com/package/replz?activeTab=code"><img src="https://img.shields.io/npm/unpacked-size/replz?style=flat-square" alt="Unpacked size of the latest replz release on npm" /></a>
|
|
21
|
+
<a href="https://github.com/ofri-peretz/burgee/blob/main/packages/replz/package.json"><img src="https://img.shields.io/badge/dependencies-4%20in%20family%2C%200%20outside-0a6b47?style=flat-square" alt="Four dependencies, all in the burgee family (bellpull, burgee, seniority, truefit), none outside it" /></a>
|
|
22
|
+
<a href="https://github.com/ofri-peretz/burgee/blob/main/packages/replz/package.json"><img src="https://img.shields.io/badge/types-included-blue?style=flat-square" alt="TypeScript types included for every entry point" /></a>
|
|
23
|
+
<a href="https://github.com/ofri-peretz/burgee/blob/main/packages/replz/package.json"><img src="https://img.shields.io/badge/Node.js-22.13%2B-green?style=flat-square" alt="Node.js 22.13+" /></a>
|
|
24
|
+
<a href="https://github.com/ofri-peretz/burgee/blob/main/packages/replz/LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue?style=flat-square" alt="License: MIT" /></a>
|
|
25
|
+
<a href="https://www.npmjs.com/package/replz#provenance"><img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fregistry.npmjs.org%2Freplz%2Flatest&query=%24.dist.attestations.provenance~&label=npm&style=flat-square&color=0a6b47" alt="npm provenance of the latest release, read live from its registry attestation" /></a>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
<p align="center">
|
|
29
|
+
Docs: <a href="https://burgee.interlace.tools/docs/packages/replz">https://burgee.interlace.tools/docs/packages/replz</a><br />
|
|
30
|
+
Migrating from: <a href="https://github.com/ofri-peretz/burgee/tree/main/packages/replz#migrating">promptfoo</a>
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
**replz** grades a code reviewer, and a repository's own checks, against bugs that actually
|
|
34
|
+
shipped. Each case is a merged pull request a later revert or fix blamed, with a one-sentence
|
|
35
|
+
answer key; size-matched clean pull requests are its controls. `replz run` checks each case out
|
|
36
|
+
at its base, applies the pull request, runs the reviewer and the checks, and grades every finding
|
|
37
|
+
against the answer key: only a finding that describes that bug counts. The report gives recall
|
|
38
|
+
per stage, severity, false alarms on the controls, and how often every check fired and was right.
|
|
39
|
+
|
|
40
|
+
It covers the review half of **promptfoo**: where a promptfoo suite asserts on a model's answer
|
|
41
|
+
to prompts someone wrote, replz replays pull requests that really shipped a bug and asserts on
|
|
42
|
+
what the reviewer said about them. `replz propose` drafts the cases from the history, and every
|
|
43
|
+
command prints burgee's `--json` envelope, each error ending in `fix:`, for a pipe or an agent.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install replz
|
|
49
|
+
pnpm add replz
|
|
50
|
+
yarn add replz
|
|
51
|
+
bun add replz
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Install it as a dev dependency (`-D`) of the repository whose history it replays. It needs git,
|
|
55
|
+
and `run` needs the reviewer and grader commands its config names.
|
|
56
|
+
|
|
57
|
+
## Quick start
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm install replz
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
import { parseLog, propose } from "replz";
|
|
65
|
+
|
|
66
|
+
// What `git log --first-parent --shortstat` prints for three merged pull requests and a revert.
|
|
67
|
+
const record = (sha, parent, subject, lines) => `\0${sha}\t${parent}\t${subject}\t\u0001\n 1 file changed, ${lines} insertions(+)\n`;
|
|
68
|
+
const log = [
|
|
69
|
+
record("d4".repeat(20), "c3".repeat(20), 'Revert "feat: cache the config (#12)"', 40),
|
|
70
|
+
record("c3".repeat(20), "b2".repeat(20), "docs: a usage page (#13)", 35),
|
|
71
|
+
record("b2".repeat(20), "a1".repeat(20), "feat: cache the config (#12)", 40),
|
|
72
|
+
record("a1".repeat(20), "90".repeat(20), "feat: a --quiet flag (#11)", 300),
|
|
73
|
+
].join("");
|
|
74
|
+
|
|
75
|
+
const { bugs, controls } = propose(parseLog(log), 10);
|
|
76
|
+
console.log(bugs.map((c) => `${c.id} at ${c.base}`).join("\n"));
|
|
77
|
+
console.log(controls.map((c) => `${c.id} (size-matched)`).join("\n"));
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```text
|
|
81
|
+
bug-12 at a1a1a1a1a1a1
|
|
82
|
+
control-13 (size-matched)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
That is what `replz propose` writes as case files under `.sdlc/replz/cases/`, each bug with an
|
|
86
|
+
`answer:` line for a person to fill in.
|
|
87
|
+
|
|
88
|
+
## What it checks
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
replz propose --limit 10 # ten bug drafts and ten size-matched controls
|
|
92
|
+
replz check # the config and every case, and each set's count
|
|
93
|
+
replz run --set test # the score on the held-out cases
|
|
94
|
+
replz run --set tune --max-findings 5 --record # a cheaper run, appended to the history
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
| Command | Exit 1 when |
|
|
98
|
+
| :-- | :-- |
|
|
99
|
+
| `check` | the config or a case file is invalid, each with the `fix:` that repairs it |
|
|
100
|
+
| `run` | a case could not be replayed |
|
|
101
|
+
|
|
102
|
+
`run` calls a model once per case and once per graded finding, so it is never a per-pull-request
|
|
103
|
+
step: run it by hand or on a schedule. `check` and `propose` cost nothing.
|
|
104
|
+
|
|
105
|
+
## Migrating
|
|
106
|
+
|
|
107
|
+
The switch is one command, `npx replz run`, where the review suite ran:
|
|
108
|
+
|
|
109
|
+
```diff
|
|
110
|
+
// package.json
|
|
111
|
+
"scripts": {
|
|
112
|
+
- "eval:review": "promptfoo eval -c review.promptfooconfig.yaml",
|
|
113
|
+
+ "eval:review": "npx replz run --set test",
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
and the hand-written review prompts come out, replaced by the case files `npx replz propose`
|
|
118
|
+
drafts from the history. Keep promptfoo for prompts that are not reviews of a pull request.
|
|
119
|
+
|
|
120
|
+
## Compatibility
|
|
121
|
+
|
|
122
|
+
Not graded: replz replays a repository's own history, and no suite is graded against it. It runs
|
|
123
|
+
anywhere git does.
|
|
124
|
+
|
|
125
|
+
## Benchmarks
|
|
126
|
+
|
|
127
|
+
Every number here is produced by `npm run bench` and published at [burgee.interlace.tools/docs/benchmarks](https://burgee.interlace.tools/docs/benchmarks).
|
|
128
|
+
|
|
129
|
+
No suite is graded against this package yet, so there is no compatibility number to quote.
|
|
130
|
+
|
|
131
|
+
## For agents
|
|
132
|
+
|
|
133
|
+
- **`replz check --json`**, **`run --json`** and **`propose --json`** print burgee's `--json`
|
|
134
|
+
envelope, every finding with a message that ends in `fix:`.
|
|
135
|
+
- **`--json`, `--schema` and an MCP server** come from one declaration on burgee:
|
|
136
|
+
`replz --mcp` serves its commands as tools.
|
|
137
|
+
- **Exit codes are the contract.** `0` passed; `1` a check failed, as the table above says; `2` a
|
|
138
|
+
usage error, with the `fix:` to run.
|
|
139
|
+
- **The docs are machine-readable** at
|
|
140
|
+
[burgee.interlace.tools/llms.txt](https://burgee.interlace.tools/llms.txt).
|
|
141
|
+
|
|
142
|
+
## API
|
|
143
|
+
|
|
144
|
+
| Import | What it gives you |
|
|
145
|
+
| :-- | :-- |
|
|
146
|
+
| `replz` | `parseLog()`, `propose()`, `parseCase()`, `selectCases()`, `parseConfig()`, `replayCase()`, `score()` and `program` |
|
|
147
|
+
|
|
148
|
+
The `replz` bin is that API, declared once on burgee.
|
|
149
|
+
|
|
150
|
+
## Requirements
|
|
151
|
+
|
|
152
|
+
Node 22.13 or later, and git.
|
|
153
|
+
|
|
154
|
+
## Where it sits
|
|
155
|
+
|
|
156
|
+
It hosts no plugin key of its own.
|
|
157
|
+
|
|
158
|
+
Nothing in this family builds on it yet, and it builds on `bellpull`, `burgee`, `seniority`, `truefit`.
|
|
159
|
+
|
|
160
|
+
## The family
|
|
161
|
+
|
|
162
|
+
18 packages, one repository, one release pipeline. Each installs and works on its own, and each owns
|
|
163
|
+
one job. Seven of them — `bellpull`, `closeout`, `linegauge`, `paratext`, `roundel`, `seniority`,
|
|
164
|
+
`truefit` — depend on nothing; the others depend only on packages in this table, and every
|
|
165
|
+
dependency points one way, down the [layers](https://burgee.interlace.tools/docs/concepts/family).
|
|
166
|
+
|
|
167
|
+
No package declares a dependency from outside the family; `react` and `react-reconciler` are
|
|
168
|
+
optional peers of `controlroom`, which npm does not install; `vitest` is an optional peer of
|
|
169
|
+
`oxmutate`, which npm does not install; `eslint` is an optional peer of `truepass`, which npm does
|
|
170
|
+
not install.
|
|
171
|
+
[`package-shape-lock`](https://github.com/ofri-peretz/burgee/blob/main/scripts/package-shape-lock.test.ts)
|
|
172
|
+
holds that for every manifest, and
|
|
173
|
+
[`independence-install-lock`](https://github.com/ofri-peretz/burgee/blob/main/scripts/independence-install-lock.test.ts)
|
|
174
|
+
installs each package alone and finds nothing but the family packages it declares.
|
|
175
|
+
|
|
176
|
+
Releases are published by one workflow through npm trusted publishing: no npm token is used, and
|
|
177
|
+
each release carries SLSA provenance, which `npm view <package> dist.attestations` shows.
|
|
178
|
+
[`trusted-publishing-lock`](https://github.com/ofri-peretz/burgee/blob/main/scripts/trusted-publishing-lock.test.ts)
|
|
179
|
+
keeps both true.
|
|
180
|
+
|
|
181
|
+
| Package | What it is | Migrates from |
|
|
182
|
+
| :-- | :-- | :-- |
|
|
183
|
+
| [burgee](https://burgee.interlace.tools/docs/packages/burgee) | The CLI framework: one declaration, every surface | commander, yargs and meow |
|
|
184
|
+
| [roundel](https://roundel.interlace.tools/docs) | Colour: one output policy, semantic tokens, a theme | chalk, colorette, kleur, picocolors, supports-color and yoctocolors |
|
|
185
|
+
| [flagstaff](https://flagstaff.interlace.tools/docs) | The frame loop: spinners, progress, boxes and tables | ora, log-update, boxen and cli-table3 |
|
|
186
|
+
| [caique](https://caique.interlace.tools/docs) | Prompts that are flags first, and never hang | @inquirer/core |
|
|
187
|
+
| [linegauge](https://linegauge.interlace.tools/docs) | Measuring, wrapping, truncating and slicing styled text | string-width, wrap-ansi, strip-ansi, slice-ansi, cli-truncate and widest-line |
|
|
188
|
+
| [paratext](https://paratext.interlace.tools/docs) | Hyperlinks, images, title, clipboard and notifications | ansi-escapes, terminal-link and term-img |
|
|
189
|
+
| [seniority](https://seniority.interlace.tools/docs) | Configuration precedence and discovery, with provenance | cosmiconfig, lilconfig, dotenv and rc |
|
|
190
|
+
| [closeout](https://closeout.interlace.tools/docs) | Exit handlers, terminal restore and a bounded shutdown | signal-exit, exit-hook, restore-cursor, cli-cursor and onetime |
|
|
191
|
+
| [bellpull](https://bellpull.interlace.tools/docs) | Subprocesses, and which executable actually ran | cross-spawn and which |
|
|
192
|
+
| [controlroom](https://controlroom.interlace.tools/docs) | Keyboard-driven terminal screens, inline or full-screen | ink |
|
|
193
|
+
| [oxmutate](https://oxmutate.interlace.tools/docs) | Mutation testing on the oxc engine, inside your own Vitest | Stryker |
|
|
194
|
+
| [truepass](https://burgee.interlace.tools/docs/packages/truepass) | Lint rules and a pre-push check that keep a test suite honest | @vitest/eslint-plugin |
|
|
195
|
+
| [contractdiff](https://burgee.interlace.tools/docs/packages/contractdiff) | API contracts: breaking-change diff, lint, and code from the spec | openapi-typescript |
|
|
196
|
+
| [truefit](https://burgee.interlace.tools/docs/packages/truefit) | Validation whose schemas are data, with no eval | zod |
|
|
197
|
+
| [provedone](https://burgee.interlace.tools/docs/packages/provedone) | A receipt for how every change was verified, and a gate that reads it | @commitlint/cli |
|
|
198
|
+
| **replz** (this package) | Recall of a reviewer and its checks, replayed on bugs that shipped | promptfoo |
|
|
199
|
+
| [hookset](https://burgee.interlace.tools/docs/packages/hookset) | The same git and Claude Code hooks in every repository, pinned by tag | husky |
|
|
200
|
+
| [triggerlist](https://burgee.interlace.tools/docs/packages/triggerlist) | The review checklist a diff selects, read from the base branch | danger |
|
|
201
|
+
|
|
202
|
+
Every migration guide, and the family-wide [compatibility](https://burgee.interlace.tools/docs/compatibility)
|
|
203
|
+
and [benchmarks](https://burgee.interlace.tools/docs/benchmarks) pages, are on
|
|
204
|
+
[burgee.interlace.tools](https://burgee.interlace.tools/docs/packages).
|
|
205
|
+
|
|
206
|
+
## Contributing
|
|
207
|
+
|
|
208
|
+
Issues and pull requests are welcome at [ofri-peretz/burgee](https://github.com/ofri-peretz/burgee/issues); read
|
|
209
|
+
[CONTRIBUTING.md](https://github.com/ofri-peretz/burgee/blob/main/CONTRIBUTING.md) first. Report a vulnerability privately, as
|
|
210
|
+
[SECURITY.md](https://github.com/ofri-peretz/burgee/blob/main/SECURITY.md) describes — never in a public issue.
|
|
211
|
+
|
|
212
|
+
## Licence
|
|
213
|
+
|
|
214
|
+
MIT © Ofri Peretz — see [LICENSE](https://github.com/ofri-peretz/burgee/blob/main/packages/replz/LICENSE).
|
package/dist/bin.js
ADDED
package/dist/cases.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const KINDS: readonly ["bug", "control"];
|
|
2
|
+
export declare const SETS: readonly ["tune", "test"];
|
|
3
|
+
export interface Case {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly kind: (typeof KINDS)[number];
|
|
6
|
+
/** The pull request the commits belong to. */
|
|
7
|
+
readonly pr: number;
|
|
8
|
+
/** The commit the pull request was reviewed against. */
|
|
9
|
+
readonly base: string;
|
|
10
|
+
/** The commit the reviewer saw: the pull request applied to `base`. */
|
|
11
|
+
readonly head: string;
|
|
12
|
+
/** What the bug is, in one sentence. Bugs only. */
|
|
13
|
+
readonly answer?: string | undefined;
|
|
14
|
+
readonly set: (typeof SETS)[number];
|
|
15
|
+
}
|
|
16
|
+
/** Read one case from its YAML; `source` names it in every error. */
|
|
17
|
+
export declare const parseCase: (source: string, yaml: string) => Case;
|
|
18
|
+
/** Cases must have distinct ids; a run on `set` takes only that set's cases. */
|
|
19
|
+
export declare const selectCases: (cases: readonly Case[], set: Case["set"] | undefined) => Case[];
|
package/dist/cases.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { parse as parseYaml } from 'seniority/yaml';
|
|
2
|
+
import { enumOf, number, object, optional, parse, string } from 'truefit';
|
|
3
|
+
export const KINDS = ['bug', 'control'];
|
|
4
|
+
export const SETS = ['tune', 'test'];
|
|
5
|
+
const SHA = /^[0-9a-f]{7,40}$/;
|
|
6
|
+
const SCHEMA = object({
|
|
7
|
+
id: string({ pattern: /^[a-z0-9][a-z0-9-]*$/ }),
|
|
8
|
+
kind: enumOf(KINDS),
|
|
9
|
+
pr: number({ int: true, min: 1 }),
|
|
10
|
+
base: string({ pattern: SHA }),
|
|
11
|
+
head: string({ pattern: SHA }),
|
|
12
|
+
answer: optional(string({ min: 1 })),
|
|
13
|
+
set: enumOf(SETS),
|
|
14
|
+
}, { unknown: 'strict' });
|
|
15
|
+
export const parseCase = (source, yaml) => {
|
|
16
|
+
let document;
|
|
17
|
+
try {
|
|
18
|
+
document = parseYaml(yaml);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
throw new Error(`${source} is not YAML: ${error.message}. fix: correct the YAML`, { cause: error });
|
|
22
|
+
}
|
|
23
|
+
const parsed = parse(SCHEMA, document);
|
|
24
|
+
if (!parsed.ok) {
|
|
25
|
+
const lines = parsed.issues.map((issue) => ` ${issue.path === '' ? '/' : issue.path}: ${issue.message}`).join('\n');
|
|
26
|
+
throw new Error(`${source} is not a valid case:\n${lines}`);
|
|
27
|
+
}
|
|
28
|
+
const found = parsed.value;
|
|
29
|
+
if (found.kind === 'bug' && found.answer === undefined)
|
|
30
|
+
throw new Error(`${source}: a bug case needs its answer, one sentence saying what the bug is. fix: add answer`);
|
|
31
|
+
if (found.kind === 'control' && found.answer !== undefined)
|
|
32
|
+
throw new Error(`${source}: a control has no bug, so no answer. fix: remove answer, or make it kind: bug`);
|
|
33
|
+
return found;
|
|
34
|
+
};
|
|
35
|
+
export const selectCases = (cases, set) => {
|
|
36
|
+
const seen = new Set();
|
|
37
|
+
for (const found of cases) {
|
|
38
|
+
if (seen.has(found.id))
|
|
39
|
+
throw new Error(`two cases are named \`${found.id}\`. fix: give each case its own id`);
|
|
40
|
+
seen.add(found.id);
|
|
41
|
+
}
|
|
42
|
+
return cases.filter((found) => set === undefined || found.set === set);
|
|
43
|
+
};
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Case } from './cases.js';
|
|
2
|
+
import { type Shell, type Worktrees } from './run.js';
|
|
3
|
+
export declare const VERSION: string;
|
|
4
|
+
/** Ten bug cases and ten controls: the intent's first success criterion. */
|
|
5
|
+
export declare const DEFAULT_LIMIT = 10;
|
|
6
|
+
type Data = Record<string | symbol, unknown>;
|
|
7
|
+
export declare const CASES = ".sdlc/replz/cases";
|
|
8
|
+
export declare const HISTORY = ".sdlc/replz/history.jsonl";
|
|
9
|
+
/** Every `*.yaml` case under `dir`, sorted by file name. */
|
|
10
|
+
export declare const readCases: (repo: string, dir: string) => Case[];
|
|
11
|
+
export interface CheckOptions {
|
|
12
|
+
readonly repo: string;
|
|
13
|
+
readonly config: string;
|
|
14
|
+
readonly cases: string;
|
|
15
|
+
}
|
|
16
|
+
/** The config and every case parse, the sets hold both kinds, and ids are distinct: what a run needs. */
|
|
17
|
+
export declare const runCheck: (options: CheckOptions) => Data;
|
|
18
|
+
export interface RunOptions extends CheckOptions {
|
|
19
|
+
readonly set?: Case['set'] | undefined;
|
|
20
|
+
readonly model?: string | undefined;
|
|
21
|
+
readonly maxFindings?: number | undefined;
|
|
22
|
+
/** Append the report to the history file. */
|
|
23
|
+
readonly record: boolean;
|
|
24
|
+
readonly shell: Shell;
|
|
25
|
+
readonly worktrees: Worktrees;
|
|
26
|
+
readonly now: () => Date;
|
|
27
|
+
}
|
|
28
|
+
export declare const runReplay: (options: RunOptions) => Promise<Data>;
|
|
29
|
+
export interface ProposeOptions {
|
|
30
|
+
readonly repo: string;
|
|
31
|
+
readonly ref: string;
|
|
32
|
+
readonly limit: number;
|
|
33
|
+
readonly log: (repo: string, args: readonly string[]) => Promise<string>;
|
|
34
|
+
}
|
|
35
|
+
export declare const runPropose: (options: ProposeOptions) => Promise<Data>;
|
|
36
|
+
export declare const program: import("burgee").Manifest;
|
|
37
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { appendFileSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { defineCommand, defineProgram } from 'burgee';
|
|
4
|
+
import { parse as parseYaml } from 'seniority/yaml';
|
|
5
|
+
import { parseCase, selectCases, SETS } from './cases.js';
|
|
6
|
+
import { CONFIG, parseConfig } from './config.js';
|
|
7
|
+
import { LOG_ARGS, parseLog, propose, toYaml } from './propose.js';
|
|
8
|
+
import { replayCase } from './run.js';
|
|
9
|
+
import { score, toText } from './score.js';
|
|
10
|
+
import { logOf, sh, worktreesIn } from './shell.js';
|
|
11
|
+
export const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
12
|
+
export const DEFAULT_LIMIT = 10;
|
|
13
|
+
const TEXT = Symbol.for('burgee.text');
|
|
14
|
+
const HERE = '.';
|
|
15
|
+
export const CASES = '.sdlc/replz/cases';
|
|
16
|
+
export const HISTORY = '.sdlc/replz/history.jsonl';
|
|
17
|
+
export const readCases = (repo, dir) => readdirSync(resolve(repo, dir))
|
|
18
|
+
.filter((name) => name.endsWith('.yaml'))
|
|
19
|
+
.sort()
|
|
20
|
+
.map((name) => parseCase(`${dir}/${name}`, readFileSync(join(resolve(repo, dir), name), 'utf8')));
|
|
21
|
+
const readConfig = (repo, path) => parseConfig(path, readFileSync(resolve(repo, path), 'utf8'));
|
|
22
|
+
const itemsOf = (repo, config) => {
|
|
23
|
+
if (config.checklist === undefined)
|
|
24
|
+
return [];
|
|
25
|
+
const document = parseYaml(readFileSync(resolve(repo, config.checklist), 'utf8'));
|
|
26
|
+
return (document.items ?? []).map((item) => item.id);
|
|
27
|
+
};
|
|
28
|
+
export const runCheck = (options) => {
|
|
29
|
+
const config = readConfig(options.repo, options.config);
|
|
30
|
+
const cases = selectCases(readCases(options.repo, options.cases), undefined);
|
|
31
|
+
const count = (set, kind) => cases.filter((found) => found.set === set && found.kind === kind).length;
|
|
32
|
+
const sets = Object.fromEntries(SETS.map((set) => [set, { bugs: count(set, 'bug'), controls: count(set, 'control') }]));
|
|
33
|
+
const data = { cases: cases.length, sets, checks: config.checks.length, stages: config.stages };
|
|
34
|
+
data[TEXT] = () => `${String(cases.length)} case(s): ${SETS.map((set) => `${set} ${String(count(set, 'bug'))} bug(s) + ${String(count(set, 'control'))} control(s)`).join(', ')}; ${String(config.checks.length)} check(s); stages ${config.stages.join(' > ')}`;
|
|
35
|
+
return data;
|
|
36
|
+
};
|
|
37
|
+
export const runReplay = async (options) => {
|
|
38
|
+
const base = readConfig(options.repo, options.config);
|
|
39
|
+
const config = { ...base, maxFindings: options.maxFindings ?? base.maxFindings };
|
|
40
|
+
const model = options.model ?? config.model;
|
|
41
|
+
const cases = selectCases(readCases(options.repo, options.cases), options.set);
|
|
42
|
+
const results = [];
|
|
43
|
+
for (const found of cases) {
|
|
44
|
+
results.push(await replayCase({ shell: options.shell, worktrees: options.worktrees, config, model }, found));
|
|
45
|
+
}
|
|
46
|
+
const report = score(results, config.stages, config.checks.map((check) => check.id), itemsOf(options.repo, config));
|
|
47
|
+
const entry = { date: options.now().toISOString().slice(0, 'yyyy-mm-dd'.length), set: options.set ?? 'all', model, maxFindings: config.maxFindings, cases: cases.map((found) => found.id), report };
|
|
48
|
+
if (options.record)
|
|
49
|
+
appendFileSync(resolve(options.repo, HISTORY), `${JSON.stringify(entry)}\n`);
|
|
50
|
+
const data = { ...entry, recorded: options.record };
|
|
51
|
+
data[TEXT] = () => `${toText(report)}${options.record ? `\n\nrecorded in ${HISTORY}` : ''}`;
|
|
52
|
+
return data;
|
|
53
|
+
};
|
|
54
|
+
export const runPropose = async (options) => {
|
|
55
|
+
const commits = parseLog(await options.log(options.repo, [...LOG_ARGS, options.ref]));
|
|
56
|
+
const { bugs, controls } = propose(commits, options.limit);
|
|
57
|
+
const subjectOf = (found) => commits.find((commit) => commit.sha.startsWith(found.head)).subject;
|
|
58
|
+
const drafts = [...bugs, ...controls].map((found) => ({ file: `${CASES}/${found.id}.yaml`, text: toYaml(found, subjectOf(found)) }));
|
|
59
|
+
const data = { bugs: bugs.length, controls: controls.length, drafts };
|
|
60
|
+
data[TEXT] = () => drafts.length === 0
|
|
61
|
+
? `no revert or fix on ${options.ref} names a pull request. fix: write cases by hand from the incident ledger`
|
|
62
|
+
: drafts.map((draft) => `--- ${draft.file}\n${draft.text}`).join('\n');
|
|
63
|
+
return data;
|
|
64
|
+
};
|
|
65
|
+
const repoOption = { type: 'string', default: HERE, description: 'the repository (default: the current directory)', placeholder: 'dir' };
|
|
66
|
+
const configOption = { type: 'string', default: CONFIG, description: 'the replz config', placeholder: 'path' };
|
|
67
|
+
const casesOption = { type: 'string', default: CASES, description: 'the folder of case files', placeholder: 'dir' };
|
|
68
|
+
export const program = defineProgram({
|
|
69
|
+
name: 'replz',
|
|
70
|
+
version: VERSION,
|
|
71
|
+
description: 'Grade the reviewer and the checks against bugs that actually happened',
|
|
72
|
+
commands: [
|
|
73
|
+
defineCommand({
|
|
74
|
+
name: 'check',
|
|
75
|
+
description: 'Validate the replz config and every case, and count each set',
|
|
76
|
+
effects: 'read_only',
|
|
77
|
+
examples: [{ command: 'replz check', description: 'are the cases ready to run' }],
|
|
78
|
+
options: { repo: repoOption, config: configOption, cases: casesOption },
|
|
79
|
+
run: ({ options }) => runCheck({ repo: options.repo, config: options.config, cases: options.cases }),
|
|
80
|
+
}),
|
|
81
|
+
defineCommand({
|
|
82
|
+
name: 'run',
|
|
83
|
+
description: 'Replay every case through the reviewer and the checks, grade the findings, and report recall per stage',
|
|
84
|
+
effects: 'non_idempotent',
|
|
85
|
+
examples: [
|
|
86
|
+
{ command: 'replz run --set test', description: 'the score on the held-out cases' },
|
|
87
|
+
{ command: 'replz run --set tune --max-findings 5 --record', description: 'a cheaper run, appended to the history' },
|
|
88
|
+
],
|
|
89
|
+
options: {
|
|
90
|
+
repo: repoOption,
|
|
91
|
+
config: configOption,
|
|
92
|
+
cases: casesOption,
|
|
93
|
+
set: { type: 'string', choices: SETS, description: 'only the cases of this set (default: both)' },
|
|
94
|
+
model: { type: 'string', description: 'the grader model, put into the grader command (default: the config)', placeholder: 'id' },
|
|
95
|
+
maxFindings: { type: 'number', description: 'the most findings graded per case, which caps the cost (default: the config)', placeholder: 'n' },
|
|
96
|
+
record: { type: 'boolean', description: `append the report to ${HISTORY}` },
|
|
97
|
+
},
|
|
98
|
+
run: ({ options }) => runReplay({
|
|
99
|
+
repo: options.repo,
|
|
100
|
+
config: options.config,
|
|
101
|
+
cases: options.cases,
|
|
102
|
+
set: options.set,
|
|
103
|
+
model: options.model,
|
|
104
|
+
maxFindings: options.maxFindings,
|
|
105
|
+
record: options.record === true,
|
|
106
|
+
shell: sh,
|
|
107
|
+
worktrees: worktreesIn(options.repo),
|
|
108
|
+
now: () => new Date(),
|
|
109
|
+
}),
|
|
110
|
+
}),
|
|
111
|
+
defineCommand({
|
|
112
|
+
name: 'propose',
|
|
113
|
+
description: 'Draft bug cases from reverts and fixes on main, each with a size-matched control, for a person to finish',
|
|
114
|
+
effects: 'read_only',
|
|
115
|
+
examples: [{ command: 'replz propose --limit 10', description: 'ten bug drafts and ten controls' }],
|
|
116
|
+
options: {
|
|
117
|
+
repo: repoOption,
|
|
118
|
+
ref: { type: 'string', default: 'origin/main', description: 'the history to read', placeholder: 'ref' },
|
|
119
|
+
limit: { type: 'number', default: DEFAULT_LIMIT, description: 'the most bug cases to draft', placeholder: 'n' },
|
|
120
|
+
},
|
|
121
|
+
run: ({ options }) => runPropose({ repo: options.repo, ref: options.ref, limit: options.limit, log: logOf }),
|
|
122
|
+
}),
|
|
123
|
+
],
|
|
124
|
+
});
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const SEVERITIES: readonly ["must-fix", "should-fix", "nit", "pre-existing"];
|
|
2
|
+
export type Severity = (typeof SEVERITIES)[number];
|
|
3
|
+
export interface Check {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly command: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Config {
|
|
8
|
+
/** Run first in each case's worktree, which starts with no dependencies installed. */
|
|
9
|
+
readonly setup?: string | undefined;
|
|
10
|
+
readonly reviewer: string;
|
|
11
|
+
/** `{model}` in it is replaced by the model a run grades with. */
|
|
12
|
+
readonly grader: string;
|
|
13
|
+
/** The default for `--model`. Left out, a run must name one. */
|
|
14
|
+
readonly model?: string | undefined;
|
|
15
|
+
readonly maxFindings: number;
|
|
16
|
+
/** The reviewer's stages, in order; the last is what ships. */
|
|
17
|
+
readonly stages: readonly string[];
|
|
18
|
+
readonly checks: readonly Check[];
|
|
19
|
+
/** The checklist whose items a finding may name, so an item that never fires is reported too. */
|
|
20
|
+
readonly checklist?: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
export declare const CONFIG = ".sdlc/replz/config.yaml";
|
|
23
|
+
export declare const parseConfig: (source: string, yaml: string) => Config;
|
|
24
|
+
/** One thing the reviewer said, at one stage of its pipeline. */
|
|
25
|
+
export interface Finding {
|
|
26
|
+
readonly stage: string;
|
|
27
|
+
readonly severity: Severity;
|
|
28
|
+
readonly text: string;
|
|
29
|
+
/** The checklist item that prompted it, when the reviewer says. */
|
|
30
|
+
readonly item?: string | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** The reviewer's stdout as findings; a stage the config does not name is refused, never dropped. */
|
|
33
|
+
export declare const parseFindings: (stdout: string, stages: readonly string[]) => Finding[];
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { parse as parseYaml } from 'seniority/yaml';
|
|
2
|
+
import { array, enumOf, number, object, optional, parse, string } from 'truefit';
|
|
3
|
+
export const SEVERITIES = ['must-fix', 'should-fix', 'nit', 'pre-existing'];
|
|
4
|
+
export const CONFIG = '.sdlc/replz/config.yaml';
|
|
5
|
+
const id = string({ pattern: /^[a-z0-9][a-z0-9-]*$/ });
|
|
6
|
+
const text = string({ min: 1 });
|
|
7
|
+
const SCHEMA = object({
|
|
8
|
+
setup: optional(text),
|
|
9
|
+
reviewer: text,
|
|
10
|
+
grader: text,
|
|
11
|
+
model: optional(text),
|
|
12
|
+
maxFindings: number({ int: true, min: 1 }),
|
|
13
|
+
stages: array(id, { min: 1 }),
|
|
14
|
+
checks: array(object({ id, command: text }, { unknown: 'strict' })),
|
|
15
|
+
checklist: optional(text),
|
|
16
|
+
}, { unknown: 'strict' });
|
|
17
|
+
export const parseConfig = (source, yaml) => {
|
|
18
|
+
const parsed = parse(SCHEMA, parseYaml(yaml));
|
|
19
|
+
if (!parsed.ok) {
|
|
20
|
+
const lines = parsed.issues.map((issue) => ` ${issue.path === '' ? '/' : issue.path}: ${issue.message}`).join('\n');
|
|
21
|
+
throw new Error(`${source} is not a valid replz config:\n${lines}`);
|
|
22
|
+
}
|
|
23
|
+
return parsed.value;
|
|
24
|
+
};
|
|
25
|
+
const FINDINGS = array(object({ stage: id, severity: enumOf(SEVERITIES), text, item: optional(id) }));
|
|
26
|
+
export const parseFindings = (stdout, stages) => {
|
|
27
|
+
let document;
|
|
28
|
+
try {
|
|
29
|
+
document = JSON.parse(stdout);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new Error(`the reviewer did not print JSON: ${error.message}. fix: make the reviewer print a JSON array of { stage, severity, text, item? }`, { cause: error });
|
|
33
|
+
}
|
|
34
|
+
const parsed = parse(FINDINGS, document);
|
|
35
|
+
if (!parsed.ok)
|
|
36
|
+
throw new Error(`the reviewer's findings are not valid: ${parsed.issues.map((issue) => `${issue.path} ${issue.message}`).join('; ')}`);
|
|
37
|
+
const findings = parsed.value;
|
|
38
|
+
const unknown = findings.find((finding) => !stages.includes(finding.stage));
|
|
39
|
+
if (unknown !== undefined)
|
|
40
|
+
throw new Error(`the reviewer reported the stage \`${unknown.stage}\`, which the config does not list. fix: add it to stages, in order`);
|
|
41
|
+
return findings;
|
|
42
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { type Case, KINDS, parseCase, selectCases, SETS } from './cases.js';
|
|
2
|
+
export { CONFIG, type Config, type Finding, parseConfig, parseFindings, SEVERITIES, type Severity } from './config.js';
|
|
3
|
+
export { blamed, type Commit, parseLog, prOf, propose } from './propose.js';
|
|
4
|
+
export { gradePrompt, isYes, replayCase, type Replayer, type Shell, type Worktrees } from './run.js';
|
|
5
|
+
export { type CaseResult, type Report, score } from './score.js';
|
|
6
|
+
export { CASES, HISTORY, program, readCases, runCheck, runPropose, runReplay, VERSION } from './cli.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { KINDS, parseCase, selectCases, SETS } from './cases.js';
|
|
2
|
+
export { CONFIG, parseConfig, parseFindings, SEVERITIES } from './config.js';
|
|
3
|
+
export { blamed, parseLog, prOf, propose } from './propose.js';
|
|
4
|
+
export { gradePrompt, isYes, replayCase } from './run.js';
|
|
5
|
+
export { score } from './score.js';
|
|
6
|
+
export { CASES, HISTORY, program, readCases, runCheck, runPropose, runReplay, VERSION } from './cli.js';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Draft cases from history (replz intent, "Defaults taken"): a revert on main names the pull request
|
|
3
|
+
* that broke something, and a fix that says which pull request it fixes names another. Each draft
|
|
4
|
+
* is that pull request's squash commit as `head` and its parent as `base`; the answer key is left for
|
|
5
|
+
* a person, because a finding is graded against it and a guessed key grades nothing. Controls are
|
|
6
|
+
* merged pull requests of a similar size that no revert or fix names.
|
|
7
|
+
*/
|
|
8
|
+
import { type Case } from './cases.js';
|
|
9
|
+
/** One commit on main. */
|
|
10
|
+
export interface Commit {
|
|
11
|
+
readonly sha: string;
|
|
12
|
+
readonly parent: string;
|
|
13
|
+
readonly subject: string;
|
|
14
|
+
readonly body: string;
|
|
15
|
+
/** Lines added and removed. */
|
|
16
|
+
readonly size: number;
|
|
17
|
+
}
|
|
18
|
+
/** The `git log` arguments whose output `parseLog` reads. */
|
|
19
|
+
export declare const LOG_ARGS: readonly ["log", "--first-parent", "--shortstat", "--format=%x00%H%x09%P%x09%s%x09%b%x01"];
|
|
20
|
+
export declare const prOf: (subject: string) => number | undefined;
|
|
21
|
+
/** The pull requests a commit says were bugs: the one a revert undoes, or the one a fix names. */
|
|
22
|
+
export declare const blamed: (commit: Commit) => number[];
|
|
23
|
+
/** Read what `git <LOG_ARGS>` prints: per commit, its fields, then the body's end mark, then its stat. */
|
|
24
|
+
export declare const parseLog: (log: string) => Commit[];
|
|
25
|
+
export interface Proposal {
|
|
26
|
+
readonly bugs: readonly Case[];
|
|
27
|
+
readonly controls: readonly Case[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Bug drafts for every blamed pull request found on main, newest first, alternating test and tune
|
|
31
|
+
* so neither set is all old or all new; and per bug, the nearest-sized unblamed pull request as its
|
|
32
|
+
* control, never one used twice.
|
|
33
|
+
*/
|
|
34
|
+
export declare const propose: (commits: readonly Commit[], limit: number) => Proposal;
|
|
35
|
+
/** A draft case file; a bug's answer is left for a person to write. */
|
|
36
|
+
export declare const toYaml: (found: Case, subject: string) => string;
|
package/dist/propose.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export const LOG_ARGS = ['log', '--first-parent', '--shortstat', '--format=%x00%H%x09%P%x09%s%x09%b%x01'];
|
|
2
|
+
const PR_IN_SUBJECT = /\(#(\d+)\)$/;
|
|
3
|
+
const REVERTED = /^Revert "(.*)"(?: \(#\d+\))?$/;
|
|
4
|
+
const FIXES = /\b(?:fixes|regressed in|introduced in|broken by|shipped in|since)\s+#(\d+)/i;
|
|
5
|
+
const linesIn = (stat) => stat
|
|
6
|
+
.split(',')
|
|
7
|
+
.map((part) => part.trim().split(' '))
|
|
8
|
+
.filter(([, word]) => word !== undefined && (word.startsWith('insertion') || word.startsWith('deletion')))
|
|
9
|
+
.reduce((sum, [count]) => sum + Number(count), 0);
|
|
10
|
+
export const prOf = (subject) => {
|
|
11
|
+
const found = PR_IN_SUBJECT.exec(subject.trim())?.[1];
|
|
12
|
+
return found === undefined ? undefined : Number(found);
|
|
13
|
+
};
|
|
14
|
+
const isFix = (subject) => subject.startsWith('fix');
|
|
15
|
+
export const blamed = (commit) => {
|
|
16
|
+
const reverted = REVERTED.exec(commit.subject)?.[1];
|
|
17
|
+
const fromRevert = reverted === undefined ? undefined : prOf(reverted);
|
|
18
|
+
const named = isFix(commit.subject) ? FIXES.exec(`${commit.subject}\n${commit.body}`)?.[1] : undefined;
|
|
19
|
+
const fromFix = named === undefined ? undefined : Number(named);
|
|
20
|
+
return [fromRevert, fromFix].filter((pr) => pr !== undefined);
|
|
21
|
+
};
|
|
22
|
+
export const parseLog = (log) => log
|
|
23
|
+
.split('\0')
|
|
24
|
+
.filter((record) => record.includes('\u0001'))
|
|
25
|
+
.map((record) => {
|
|
26
|
+
const [fields = '', stat = ''] = record.split('\u0001');
|
|
27
|
+
const [sha, parents = '', subject = '', ...body] = fields.split('\t');
|
|
28
|
+
return { sha, parent: parents.split(' ')[0], subject, body: body.join('\t').trim(), size: linesIn(stat) };
|
|
29
|
+
});
|
|
30
|
+
const SHORT = 12;
|
|
31
|
+
const caseOf = (commit, pr, kind, set) => ({
|
|
32
|
+
id: `${kind}-${String(pr)}`,
|
|
33
|
+
kind,
|
|
34
|
+
pr,
|
|
35
|
+
base: commit.parent.slice(0, SHORT),
|
|
36
|
+
head: commit.sha.slice(0, SHORT),
|
|
37
|
+
set,
|
|
38
|
+
});
|
|
39
|
+
export const propose = (commits, limit) => {
|
|
40
|
+
const byPr = new Map(commits.flatMap((commit) => {
|
|
41
|
+
const pr = prOf(commit.subject);
|
|
42
|
+
return pr === undefined ? [] : [[pr, commit]];
|
|
43
|
+
}));
|
|
44
|
+
const blamedPrs = [...new Set(commits.flatMap(blamed))].filter((pr) => byPr.has(pr)).slice(0, limit);
|
|
45
|
+
const bugs = blamedPrs.map((pr, index) => caseOf(byPr.get(pr), pr, 'bug', index % 2 === 0 ? 'test' : 'tune'));
|
|
46
|
+
const blamedSet = new Set(commits.flatMap(blamed));
|
|
47
|
+
const pool = [...byPr.entries()].filter(([pr, commit]) => !blamedSet.has(pr) && !REVERTED.test(commit.subject) && !/^fix\b/.test(commit.subject));
|
|
48
|
+
const controls = [];
|
|
49
|
+
for (const bug of bugs) {
|
|
50
|
+
const size = byPr.get(bug.pr).size;
|
|
51
|
+
const nearest = pool.toSorted(([, a], [, b]) => Math.abs(a.size - size) - Math.abs(b.size - size))[0];
|
|
52
|
+
if (nearest === undefined)
|
|
53
|
+
break;
|
|
54
|
+
pool.splice(pool.indexOf(nearest), 1);
|
|
55
|
+
controls.push(caseOf(nearest[1], nearest[0], 'control', bug.set));
|
|
56
|
+
}
|
|
57
|
+
return { bugs, controls };
|
|
58
|
+
};
|
|
59
|
+
export const toYaml = (found, subject) => [
|
|
60
|
+
`# ${subject}`,
|
|
61
|
+
`id: ${found.id}`,
|
|
62
|
+
`kind: ${found.kind}`,
|
|
63
|
+
`pr: ${String(found.pr)}`,
|
|
64
|
+
`base: ${JSON.stringify(found.base)}`,
|
|
65
|
+
`head: ${JSON.stringify(found.head)}`,
|
|
66
|
+
...(found.kind === 'bug' ? ['answer: TODO one sentence saying what the bug is, from the revert or the fix'] : []),
|
|
67
|
+
`set: ${found.set}`,
|
|
68
|
+
'',
|
|
69
|
+
].join('\n');
|
package/dist/run.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One replay (replz spec R2, R3): for each case, a git worktree at its head, the reviewer and every
|
|
3
|
+
* check run inside it, and each finding of a bug case graded against the answer key, one finding per
|
|
4
|
+
* grader call, at most `maxFindings` per case. Controls are never graded: they have no answer, so
|
|
5
|
+
* they cost one reviewer call and nothing more.
|
|
6
|
+
*/
|
|
7
|
+
import { type Case } from './cases.js';
|
|
8
|
+
import { type Config, type Finding } from './config.js';
|
|
9
|
+
import { type CaseResult } from './score.js';
|
|
10
|
+
export interface Ran {
|
|
11
|
+
readonly code: number | null;
|
|
12
|
+
readonly stdout: string;
|
|
13
|
+
readonly stderr: string;
|
|
14
|
+
}
|
|
15
|
+
/** Runs a shell command line; a test passes its own and runs nothing. */
|
|
16
|
+
export type Shell = (command: string, options: {
|
|
17
|
+
readonly cwd: string;
|
|
18
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
19
|
+
readonly input?: string;
|
|
20
|
+
}) => Promise<Ran>;
|
|
21
|
+
export interface Worktrees {
|
|
22
|
+
/** A detached worktree at `ref`, and the function that removes it. */
|
|
23
|
+
readonly add: (ref: string) => Promise<{
|
|
24
|
+
readonly dir: string;
|
|
25
|
+
readonly remove: () => Promise<void>;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/** The grader's whole prompt: the answer key, one finding, and the question. */
|
|
29
|
+
export declare const gradePrompt: (answer: string, finding: Finding) => string;
|
|
30
|
+
/** A grader answer counts as a match only when its first word is yes. */
|
|
31
|
+
export declare const isYes: (stdout: string) => boolean;
|
|
32
|
+
/** What every case of one run shares. */
|
|
33
|
+
export interface Replayer {
|
|
34
|
+
readonly shell: Shell;
|
|
35
|
+
readonly worktrees: Worktrees;
|
|
36
|
+
readonly config: Config;
|
|
37
|
+
/** Put into the grader command's `{model}`. */
|
|
38
|
+
readonly model: string | undefined;
|
|
39
|
+
}
|
|
40
|
+
export declare const replayCase: (replayer: Replayer, found: Case) => Promise<CaseResult>;
|
package/dist/run.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { parseFindings } from './config.js';
|
|
2
|
+
export const gradePrompt = (answer, finding) => [
|
|
3
|
+
'You grade a code reviewer against a known bug.',
|
|
4
|
+
`The bug (answer key): ${answer}`,
|
|
5
|
+
`The reviewer's finding: ${finding.text}`,
|
|
6
|
+
'Does the finding describe this bug: the same defect, not merely the same file or area? Answer yes or no, and nothing else.',
|
|
7
|
+
].join('\n');
|
|
8
|
+
export const isYes = (stdout) => /^\W*yes\b/i.test(stdout);
|
|
9
|
+
const grade = async ({ shell, config, model }, cwd, answer, findings) => {
|
|
10
|
+
const command = config.grader.replaceAll('{model}', String(model));
|
|
11
|
+
const graded = [];
|
|
12
|
+
for (const [index, finding] of findings.entries()) {
|
|
13
|
+
if (index >= config.maxFindings) {
|
|
14
|
+
graded.push({ finding, matches: false });
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const answered = await shell(command, { cwd, input: gradePrompt(answer, finding) });
|
|
18
|
+
if (answered.code !== 0)
|
|
19
|
+
throw new Error(`the grader failed (exit ${String(answered.code)}): ${answered.stderr.trim()}. fix: check the grader command in the replz config`);
|
|
20
|
+
graded.push({ finding, matches: isYes(answered.stdout) });
|
|
21
|
+
}
|
|
22
|
+
return { graded, capped: findings.length > config.maxFindings };
|
|
23
|
+
};
|
|
24
|
+
export const replayCase = async (replayer, found) => {
|
|
25
|
+
const { shell, config } = replayer;
|
|
26
|
+
if (found.answer !== undefined && replayer.model === undefined && config.grader.includes('{model}')) {
|
|
27
|
+
throw new Error('the grader command takes {model} and none was given. fix: pass --model with the cheapest current model, or set model in the replz config');
|
|
28
|
+
}
|
|
29
|
+
const { dir, remove } = await replayer.worktrees.add(found.head);
|
|
30
|
+
try {
|
|
31
|
+
const env = { REPLZ_BASE: found.base, REPLZ_HEAD: found.head, REPLZ_PR: String(found.pr) };
|
|
32
|
+
if (config.setup !== undefined) {
|
|
33
|
+
const ready = await shell(config.setup, { cwd: dir, env });
|
|
34
|
+
if (ready.code !== 0)
|
|
35
|
+
throw new Error(`setup failed on ${found.id} (exit ${String(ready.code)}): ${ready.stderr.trim()}. fix: run it by hand in a worktree at ${found.head}`);
|
|
36
|
+
}
|
|
37
|
+
const reviewed = await shell(config.reviewer, { cwd: dir, env });
|
|
38
|
+
if (reviewed.code !== 0)
|
|
39
|
+
throw new Error(`the reviewer failed on ${found.id} (exit ${String(reviewed.code)}): ${reviewed.stderr.trim()}. fix: run it by hand in a worktree at ${found.head}`);
|
|
40
|
+
const findings = parseFindings(reviewed.stdout, config.stages);
|
|
41
|
+
const outcomes = [];
|
|
42
|
+
for (const check of config.checks) {
|
|
43
|
+
outcomes.push([check.id, (await shell(check.command, { cwd: dir, env })).code !== 0]);
|
|
44
|
+
}
|
|
45
|
+
const fired = Object.fromEntries(outcomes);
|
|
46
|
+
if (found.answer === undefined)
|
|
47
|
+
return { case: found, findings: findings.map((finding) => ({ finding, matches: false })), capped: false, fired };
|
|
48
|
+
const { graded, capped } = await grade(replayer, dir, found.answer, findings);
|
|
49
|
+
return { case: found, findings: graded, capped, fired };
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
await remove();
|
|
53
|
+
}
|
|
54
|
+
};
|
package/dist/score.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The report (replz spec R4): recall per stage, so a pipeline that finds a bug and then drops it in
|
|
3
|
+
* verification shows where; false alarms on the controls; and for every check and checklist item, how
|
|
4
|
+
* often it fired and how often that firing was right. A check or item that never fired is named: it
|
|
5
|
+
* costs a reviewer's attention or a CI minute and has not earned it on these cases.
|
|
6
|
+
*/
|
|
7
|
+
import { type Case } from './cases.js';
|
|
8
|
+
import { type Finding, type Severity } from './config.js';
|
|
9
|
+
export interface Graded {
|
|
10
|
+
readonly finding: Finding;
|
|
11
|
+
/** The grader said it describes the answer key. Always false on a control, which has none. */
|
|
12
|
+
readonly matches: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface CaseResult {
|
|
15
|
+
readonly case: Case;
|
|
16
|
+
readonly findings: readonly Graded[];
|
|
17
|
+
/** More findings than the cap: those past it were not graded. */
|
|
18
|
+
readonly capped: boolean;
|
|
19
|
+
/** Each check's id, and whether it failed on this case. */
|
|
20
|
+
readonly fired: Readonly<Record<string, boolean>>;
|
|
21
|
+
}
|
|
22
|
+
export interface Firing {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly kind: 'check' | 'item';
|
|
25
|
+
readonly fired: number;
|
|
26
|
+
/** A check firing on a bug case, or an item's finding that matched the answer. */
|
|
27
|
+
readonly right: number;
|
|
28
|
+
}
|
|
29
|
+
export interface Report {
|
|
30
|
+
readonly bugs: number;
|
|
31
|
+
readonly controls: number;
|
|
32
|
+
readonly recall: readonly {
|
|
33
|
+
readonly stage: string;
|
|
34
|
+
readonly found: number;
|
|
35
|
+
}[];
|
|
36
|
+
/** Findings at the last stage, by severity. */
|
|
37
|
+
readonly severity: Readonly<Record<Severity, number>>;
|
|
38
|
+
/** Controls with a must-fix or should-fix finding at the last stage. */
|
|
39
|
+
readonly falseAlarms: number;
|
|
40
|
+
readonly firing: readonly Firing[];
|
|
41
|
+
readonly neverFired: readonly string[];
|
|
42
|
+
readonly capped: readonly string[];
|
|
43
|
+
}
|
|
44
|
+
export declare const score: (results: readonly CaseResult[], stages: readonly string[], checks: readonly string[], items: readonly string[]) => Report;
|
|
45
|
+
export declare const toText: (report: Report) => string;
|
package/dist/score.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { SEVERITIES } from './config.js';
|
|
2
|
+
const BLOCKING = new Set(['must-fix', 'should-fix']);
|
|
3
|
+
export const score = (results, stages, checks, items) => {
|
|
4
|
+
const bugs = results.filter((result) => result.case.kind === 'bug');
|
|
5
|
+
const controls = results.filter((result) => result.case.kind === 'control');
|
|
6
|
+
const final = stages.at(-1);
|
|
7
|
+
const atFinal = results.flatMap((result) => result.findings.filter((graded) => graded.finding.stage === final));
|
|
8
|
+
const severity = Object.fromEntries(SEVERITIES.map((level) => [level, atFinal.filter((graded) => graded.finding.severity === level).length]));
|
|
9
|
+
const firing = [
|
|
10
|
+
...checks.map((check) => {
|
|
11
|
+
const firedOn = results.filter((result) => result.fired[check] === true);
|
|
12
|
+
return { id: check, kind: 'check', fired: firedOn.length, right: firedOn.filter((result) => result.case.kind === 'bug').length };
|
|
13
|
+
}),
|
|
14
|
+
...items.map((item) => {
|
|
15
|
+
const named = results.flatMap((result) => result.findings).filter((graded) => graded.finding.item === item);
|
|
16
|
+
return { id: item, kind: 'item', fired: named.length, right: named.filter((graded) => graded.matches).length };
|
|
17
|
+
}),
|
|
18
|
+
];
|
|
19
|
+
return {
|
|
20
|
+
bugs: bugs.length,
|
|
21
|
+
controls: controls.length,
|
|
22
|
+
recall: stages.map((stage) => ({ stage, found: bugs.filter((result) => result.findings.some((graded) => graded.matches && graded.finding.stage === stage)).length })),
|
|
23
|
+
severity,
|
|
24
|
+
falseAlarms: controls.filter((result) => result.findings.some((graded) => graded.finding.stage === final && BLOCKING.has(graded.finding.severity))).length,
|
|
25
|
+
firing,
|
|
26
|
+
neverFired: firing.filter((row) => row.fired === 0).map((row) => row.id),
|
|
27
|
+
capped: results.filter((result) => result.capped).map((result) => result.case.id),
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const HUNDRED = 100;
|
|
31
|
+
const percent = (part, whole) => (whole === 0 ? 'n/a' : `${String(Math.round((part / whole) * HUNDRED))}%`);
|
|
32
|
+
export const toText = (report) => {
|
|
33
|
+
const lines = [`${String(report.bugs)} bug case(s), ${String(report.controls)} control(s)`, '', 'recall per stage:'];
|
|
34
|
+
for (const { stage, found } of report.recall)
|
|
35
|
+
lines.push(` ${stage}: ${String(found)} of ${String(report.bugs)} (${percent(found, report.bugs)})`);
|
|
36
|
+
lines.push(`false alarms on controls: ${String(report.falseAlarms)} of ${String(report.controls)} (${percent(report.falseAlarms, report.controls)})`);
|
|
37
|
+
lines.push(`last-stage findings: ${SEVERITIES.map((level) => `${level} ${String(report.severity[level])}`).join(', ')}`);
|
|
38
|
+
if (report.firing.length > 0) {
|
|
39
|
+
lines.push('', 'firing (fired / right):');
|
|
40
|
+
for (const row of report.firing)
|
|
41
|
+
lines.push(` ${row.kind} ${row.id}: ${String(row.fired)} / ${String(row.right)}`);
|
|
42
|
+
}
|
|
43
|
+
if (report.neverFired.length > 0)
|
|
44
|
+
lines.push('', `never fired: ${report.neverFired.join(', ')}. fix: keep or drop each, in a decision`);
|
|
45
|
+
if (report.capped.length > 0)
|
|
46
|
+
lines.push('', `capped (findings past --max-findings not graded): ${report.capped.join(', ')}`);
|
|
47
|
+
return lines.join('\n');
|
|
48
|
+
};
|
package/dist/shell.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { ambientRuntime, run } from 'bellpull';
|
|
5
|
+
export const sh = async (command, options) => {
|
|
6
|
+
const runtime = ambientRuntime();
|
|
7
|
+
const scratch = options.input === undefined ? undefined : mkdtempSync(join(tmpdir(), 'replz-input-'));
|
|
8
|
+
try {
|
|
9
|
+
const env = { ...runtime.env, ...options.env, REPLZ_INPUT: '/dev/null' };
|
|
10
|
+
if (scratch !== undefined) {
|
|
11
|
+
env.REPLZ_INPUT = join(scratch, 'input.txt');
|
|
12
|
+
writeFileSync(env.REPLZ_INPUT, options.input);
|
|
13
|
+
}
|
|
14
|
+
const result = await run('sh', ['-c', `{ ${command}\n} < "$REPLZ_INPUT"`], { cwd: options.cwd, runtime, env, timeout: 0 });
|
|
15
|
+
return { code: result.code, stdout: result.stdout, stderr: result.stderr };
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
if (scratch !== undefined)
|
|
19
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const git = async (repo, args) => {
|
|
23
|
+
const result = await run('git', args, { cwd: repo, runtime: ambientRuntime() });
|
|
24
|
+
if (!result.ok)
|
|
25
|
+
throw new Error(`git ${args.join(' ')} failed: ${result.stderr.trim()}. fix: fetch the commit the case names`);
|
|
26
|
+
};
|
|
27
|
+
export const worktreesIn = (repo) => ({
|
|
28
|
+
add: async (ref) => {
|
|
29
|
+
const dir = join(mkdtempSync(join(tmpdir(), 'replz-case-')), 'tree');
|
|
30
|
+
await git(repo, ['worktree', 'add', '--detach', dir, ref]);
|
|
31
|
+
return { dir, remove: () => git(repo, ['worktree', 'remove', '--force', dir]) };
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
export const logOf = async (repo, args) => {
|
|
35
|
+
const result = await run('git', args, { cwd: repo, runtime: ambientRuntime() });
|
|
36
|
+
if (!result.ok)
|
|
37
|
+
throw new Error(`git ${args.join(' ')} failed: ${result.stderr.trim()}. fix: run it inside a clone with history (not a shallow one)`);
|
|
38
|
+
return result.stdout;
|
|
39
|
+
};
|
package/package.json
CHANGED
|
@@ -1 +1,75 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "replz",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Code review benchmark for AI reviewers and a repo's checks: replays each pull request a revert or fix blamed beside clean controls, and grades findings against a one-line answer key. No dependency outside the burgee family. A promptfoo migration path.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"code-review",
|
|
8
|
+
"ai-review",
|
|
9
|
+
"benchmark",
|
|
10
|
+
"regression",
|
|
11
|
+
"bug-replay",
|
|
12
|
+
"precision",
|
|
13
|
+
"recall",
|
|
14
|
+
"ci",
|
|
15
|
+
"cli"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"homepage": "https://burgee.interlace.tools",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/ofri-peretz/burgee.git",
|
|
22
|
+
"directory": "packages/replz"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/ofri-peretz/burgee/issues"
|
|
26
|
+
},
|
|
27
|
+
"author": "Ofri Peretz <ofriperetzdev@gmail.com>",
|
|
28
|
+
"type": "module",
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22.13.0"
|
|
31
|
+
},
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.js",
|
|
37
|
+
"default": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"bin": {
|
|
42
|
+
"replz": "dist/bin.js"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"!dist/**/*.map",
|
|
47
|
+
"!dist/**/*.test.*"
|
|
48
|
+
],
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc -p tsconfig.build.json && node ../../scripts/strip-comments.mjs dist && node ../../scripts/declaration-reach.mts --prune",
|
|
51
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"coverage": "vitest run --coverage.enabled",
|
|
54
|
+
"lint": "eslint src"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"bellpull": "^2.0.0",
|
|
58
|
+
"burgee": "^2.1.5",
|
|
59
|
+
"seniority": "^2.0.0",
|
|
60
|
+
"truefit": "^0.2.1"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"vitest": "^5.0.1"
|
|
64
|
+
},
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public",
|
|
67
|
+
"provenance": true
|
|
68
|
+
},
|
|
69
|
+
"sideEffects": [
|
|
70
|
+
"./dist/bin.js"
|
|
71
|
+
],
|
|
72
|
+
"typesVersions": {
|
|
73
|
+
"*": {}
|
|
74
|
+
}
|
|
75
|
+
}
|