replz 0.3.1 → 1.0.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/README.md +20 -13
- package/dist/cases.d.ts +2 -0
- package/dist/cases.js +4 -1
- package/dist/cli.d.ts +6 -2
- package/dist/cli.js +31 -13
- package/dist/config.js +10 -3
- package/dist/propose.js +2 -1
- package/dist/refusal.js +27 -0
- package/dist/run.d.ts +13 -2
- package/dist/run.js +13 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,14 +33,15 @@
|
|
|
33
33
|
**replz** grades a code reviewer, and a repository's own checks, against bugs that actually
|
|
34
34
|
shipped. Each case is a merged pull request a later revert or fix blamed, with a one-sentence
|
|
35
35
|
answer key; size-matched clean pull requests are its controls. `replz run` checks each case out
|
|
36
|
-
at its
|
|
37
|
-
|
|
36
|
+
at its head, the commit the reviewer saw (its base with the pull request applied), runs the
|
|
37
|
+
reviewer and the checks there, and grades every finding against the answer key, the last stage's
|
|
38
|
+
findings first: only a finding that describes that bug counts. The report gives recall
|
|
38
39
|
per stage, severity, false alarms on the controls, and how often every check fired and was right.
|
|
39
40
|
|
|
40
41
|
It covers the review half of **promptfoo**: where a promptfoo suite asserts on a model's answer
|
|
41
42
|
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`
|
|
43
|
-
command prints burgee's `--json` envelope, each error
|
|
43
|
+
what the reviewer said about them. `replz propose` prints draft cases from the history, and every
|
|
44
|
+
command prints burgee's `--json` envelope, each error with its `fix:`, for a pipe or an agent.
|
|
44
45
|
|
|
45
46
|
## Install
|
|
46
47
|
|
|
@@ -82,13 +83,14 @@ bug-12 at a1a1a1a1a1a1
|
|
|
82
83
|
control-13 (size-matched)
|
|
83
84
|
```
|
|
84
85
|
|
|
85
|
-
That is what `replz propose`
|
|
86
|
-
`answer:` line for a person to fill in.
|
|
86
|
+
That is what `replz propose` prints: each draft under the file name it belongs at in
|
|
87
|
+
`.sdlc/replz/cases/`, each bug with an `answer:` line for a person to fill in. It writes no file;
|
|
88
|
+
save the drafts you keep, and `replz check` refuses one whose answer is still the draft's `TODO`.
|
|
87
89
|
|
|
88
90
|
## What it checks
|
|
89
91
|
|
|
90
92
|
```sh
|
|
91
|
-
replz propose --limit 10 # ten bug drafts and ten size-matched controls
|
|
93
|
+
replz propose --limit 10 # prints ten bug drafts and ten size-matched controls
|
|
92
94
|
replz check # the config and every case, and each set's count
|
|
93
95
|
replz run --set test # the score on the held-out cases
|
|
94
96
|
replz run --set tune --max-findings 5 --record # a cheaper run, appended to the history
|
|
@@ -96,12 +98,17 @@ replz run --set tune --max-findings 5 --record # a cheaper run, appended to the
|
|
|
96
98
|
|
|
97
99
|
| Command | Exit 1 when |
|
|
98
100
|
| :-- | :-- |
|
|
99
|
-
| `check` | the config or a case file is invalid, each with the `fix:` that repairs it |
|
|
101
|
+
| `check` | the config or a case file is invalid, a case file is not named `<id>.yaml`, an answer is still the draft's `TODO`, or a set lacks a bug or a control, each with the `fix:` that repairs it |
|
|
100
102
|
| `run` | a case could not be replayed |
|
|
101
103
|
|
|
102
104
|
`run` calls a model once per case and once per graded finding, so it is never a per-pull-request
|
|
103
105
|
step: run it by hand or on a schedule. `check` and `propose` cost nothing.
|
|
104
106
|
|
|
107
|
+
Every command in the config runs in the case's worktree with `REPLZ_BASE`, `REPLZ_HEAD`,
|
|
108
|
+
`REPLZ_PR` and `REPLZ_REPO` set. `REPLZ_REPO` is the repository `replz run` started in, as an
|
|
109
|
+
absolute path: name a reviewer script kept there as `bash "$REPLZ_REPO/review.sh"`, because a
|
|
110
|
+
relative path is read in the worktree, at a head that may predate the script.
|
|
111
|
+
|
|
105
112
|
## Migrating
|
|
106
113
|
|
|
107
114
|
The switch is one command, `npx replz run`, where the review suite ran:
|
|
@@ -114,8 +121,8 @@ The switch is one command, `npx replz run`, where the review suite ran:
|
|
|
114
121
|
}
|
|
115
122
|
```
|
|
116
123
|
|
|
117
|
-
and the hand-written review prompts come out, replaced by
|
|
118
|
-
|
|
124
|
+
and the hand-written review prompts come out, replaced by case files saved from the drafts
|
|
125
|
+
`npx replz propose` prints from the history. Keep promptfoo for prompts that are not reviews of a pull request.
|
|
119
126
|
|
|
120
127
|
## Compatibility
|
|
121
128
|
|
|
@@ -131,11 +138,11 @@ No suite is graded against this package yet, so there is no compatibility number
|
|
|
131
138
|
## For agents
|
|
132
139
|
|
|
133
140
|
- **`replz check --json`**, **`run --json`** and **`propose --json`** print burgee's `--json`
|
|
134
|
-
envelope
|
|
141
|
+
envelope; a failure carries its remedy as `error.fix`, and prose prints it on a `fix:` line.
|
|
135
142
|
- **`--json`, `--schema` and an MCP server** come from one declaration on burgee:
|
|
136
143
|
`replz --mcp` serves its commands as tools.
|
|
137
|
-
- **Exit codes are the contract.** `0` passed; `1` a check failed, as the table above says
|
|
138
|
-
usage error, with the
|
|
144
|
+
- **Exit codes are the contract.** `0` passed; `1` a check failed, as the table above says, with
|
|
145
|
+
its `fix:`; `2` a usage error, with the command's usage.
|
|
139
146
|
- **The docs are machine-readable** at
|
|
140
147
|
[burgee.interlace.tools/llms.txt](https://burgee.interlace.tools/llms.txt).
|
|
141
148
|
|
package/dist/cases.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export interface Case {
|
|
|
13
13
|
readonly answer?: string | undefined;
|
|
14
14
|
readonly set: (typeof SETS)[number];
|
|
15
15
|
}
|
|
16
|
+
/** How a drafted answer starts until a person writes it; `replz propose` leaves it on every bug. */
|
|
17
|
+
export declare const PLACEHOLDER = "TODO";
|
|
16
18
|
/** Read one case from its YAML; `source` names it in every error. */
|
|
17
19
|
export declare const parseCase: (source: string, yaml: string) => Case;
|
|
18
20
|
/** Cases must have distinct ids; a run on `set` takes only that set's cases. */
|
package/dist/cases.js
CHANGED
|
@@ -3,6 +3,7 @@ import { enumOf, number, object, optional, parse, string } from 'truefit';
|
|
|
3
3
|
export const KINDS = ['bug', 'control'];
|
|
4
4
|
export const SETS = ['tune', 'test'];
|
|
5
5
|
const SHA = /^[0-9a-f]{7,40}$/;
|
|
6
|
+
export const PLACEHOLDER = 'TODO';
|
|
6
7
|
const SCHEMA = object({
|
|
7
8
|
id: string({ pattern: /^[a-z0-9][a-z0-9-]*$/ }),
|
|
8
9
|
kind: enumOf(KINDS),
|
|
@@ -23,11 +24,13 @@ export const parseCase = (source, yaml) => {
|
|
|
23
24
|
const parsed = parse(SCHEMA, document);
|
|
24
25
|
if (!parsed.ok) {
|
|
25
26
|
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
|
+
throw new Error(`${source} is not a valid case:\n${lines}\nfix: correct each field named above`);
|
|
27
28
|
}
|
|
28
29
|
const found = parsed.value;
|
|
29
30
|
if (found.kind === 'bug' && found.answer === undefined)
|
|
30
31
|
throw new Error(`${source}: a bug case needs its answer, one sentence saying what the bug is. fix: add answer`);
|
|
32
|
+
if (found.answer?.startsWith(PLACEHOLDER) === true)
|
|
33
|
+
throw new Error(`${source}: the answer is still the draft's ${PLACEHOLDER}, and a finding graded against it grades nothing. fix: write one sentence saying what the bug is, from the revert or the fix`);
|
|
31
34
|
if (found.kind === 'control' && found.answer !== undefined)
|
|
32
35
|
throw new Error(`${source}: a control has no bug, so no answer. fix: remove answer, or make it kind: bug`);
|
|
33
36
|
return found;
|
package/dist/cli.d.ts
CHANGED
|
@@ -6,14 +6,18 @@ export declare const DEFAULT_LIMIT = 10;
|
|
|
6
6
|
type Data = Record<string | symbol, unknown>;
|
|
7
7
|
export declare const CASES = ".sdlc/replz/cases";
|
|
8
8
|
export declare const HISTORY = ".sdlc/replz/history.jsonl";
|
|
9
|
-
/** Every `*.yaml` case under `dir`, sorted by file name
|
|
9
|
+
/** Every `*.yaml` case under `dir`, sorted by file name, each named `<id>.yaml`. */
|
|
10
10
|
export declare const readCases: (repo: string, dir: string) => Case[];
|
|
11
11
|
export interface CheckOptions {
|
|
12
12
|
readonly repo: string;
|
|
13
13
|
readonly config: string;
|
|
14
14
|
readonly cases: string;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The config and every case parse, each case file is named by its id, no answer is the draft's
|
|
18
|
+
* placeholder, ids are distinct, and each set holds a bug and a control: what a run needs. A set of
|
|
19
|
+
* one kind gives a score of one kind, recall with no false alarms or the reverse.
|
|
20
|
+
*/
|
|
17
21
|
export declare const runCheck: (options: CheckOptions) => Data;
|
|
18
22
|
export interface RunOptions extends CheckOptions {
|
|
19
23
|
readonly set?: Case['set'] | undefined;
|
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { appendFileSync, readdirSync, readFileSync } from 'node:fs';
|
|
1
|
+
import { appendFileSync, existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join, resolve } from 'node:path';
|
|
3
3
|
import { defineCommand, defineProgram } from 'burgee';
|
|
4
4
|
import { parse as parseYaml } from 'seniority/yaml';
|
|
5
|
-
import { parseCase, selectCases, SETS } from './cases.js';
|
|
5
|
+
import { KINDS, parseCase, selectCases, SETS } from './cases.js';
|
|
6
6
|
import { CONFIG, parseConfig } from './config.js';
|
|
7
7
|
import { LOG_ARGS, parseLog, propose, toYaml } from './propose.js';
|
|
8
|
+
import { refusing } from './refusal.js';
|
|
8
9
|
import { replayCase } from './run.js';
|
|
9
10
|
import { score, toText } from './score.js';
|
|
10
11
|
import { logOf, sh, worktreesIn } from './shell.js';
|
|
@@ -14,11 +15,25 @@ const TEXT = Symbol.for('burgee.text');
|
|
|
14
15
|
const HERE = '.';
|
|
15
16
|
export const CASES = '.sdlc/replz/cases';
|
|
16
17
|
export const HISTORY = '.sdlc/replz/history.jsonl';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const existing = (repo, path, option) => {
|
|
19
|
+
const at = resolve(repo, path);
|
|
20
|
+
if (!existsSync(at))
|
|
21
|
+
throw new Error(`${path} does not exist in ${resolve(repo)}. fix: run replz in the repository it replays, or pass --repo, or ${option}`);
|
|
22
|
+
return at;
|
|
23
|
+
};
|
|
24
|
+
export const readCases = (repo, dir) => {
|
|
25
|
+
const at = existing(repo, dir, '--cases');
|
|
26
|
+
return readdirSync(at)
|
|
27
|
+
.filter((name) => name.endsWith('.yaml'))
|
|
28
|
+
.sort()
|
|
29
|
+
.map((name) => {
|
|
30
|
+
const found = parseCase(`${dir}/${name}`, readFileSync(join(at, name), 'utf8'));
|
|
31
|
+
if (name !== `${found.id}.yaml`)
|
|
32
|
+
throw new Error(`${dir}/${name} holds the case \`${found.id}\`. fix: rename the file ${found.id}.yaml, or change its id`);
|
|
33
|
+
return found;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const readConfig = (repo, path) => parseConfig(path, readFileSync(existing(repo, path, '--config'), 'utf8'));
|
|
22
37
|
const itemsOf = (repo, config) => {
|
|
23
38
|
if (config.checklist === undefined)
|
|
24
39
|
return [];
|
|
@@ -29,6 +44,9 @@ export const runCheck = (options) => {
|
|
|
29
44
|
const config = readConfig(options.repo, options.config);
|
|
30
45
|
const cases = selectCases(readCases(options.repo, options.cases), undefined);
|
|
31
46
|
const count = (set, kind) => cases.filter((found) => found.set === set && found.kind === kind).length;
|
|
47
|
+
const short = SETS.flatMap((set) => KINDS.filter((kind) => count(set, kind) === 0).map((kind) => `the ${set} set has no ${kind} case`));
|
|
48
|
+
if (short.length > 0)
|
|
49
|
+
throw new Error(`${short.join('; ')}. fix: add the cases each set lacks (replz propose drafts them), so neither score is of one kind`);
|
|
32
50
|
const sets = Object.fromEntries(SETS.map((set) => [set, { bugs: count(set, 'bug'), controls: count(set, 'control') }]));
|
|
33
51
|
const data = { cases: cases.length, sets, checks: config.checks.length, stages: config.stages };
|
|
34
52
|
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(' > ')}`;
|
|
@@ -41,7 +59,7 @@ export const runReplay = async (options) => {
|
|
|
41
59
|
const cases = selectCases(readCases(options.repo, options.cases), options.set);
|
|
42
60
|
const results = [];
|
|
43
61
|
for (const found of cases) {
|
|
44
|
-
results.push(await replayCase({ shell: options.shell, worktrees: options.worktrees, config, model }, found));
|
|
62
|
+
results.push(await replayCase({ shell: options.shell, worktrees: options.worktrees, config, model, repo: resolve(options.repo) }, found));
|
|
45
63
|
}
|
|
46
64
|
const report = score(results, config.stages, config.checks.map((check) => check.id), itemsOf(options.repo, config));
|
|
47
65
|
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 };
|
|
@@ -62,7 +80,7 @@ export const runPropose = async (options) => {
|
|
|
62
80
|
: drafts.map((draft) => `--- ${draft.file}\n${draft.text}`).join('\n');
|
|
63
81
|
return data;
|
|
64
82
|
};
|
|
65
|
-
const repoOption = { type: 'string', default: HERE, description: 'the repository
|
|
83
|
+
const repoOption = { type: 'string', default: HERE, description: 'the repository', placeholder: 'dir' };
|
|
66
84
|
const configOption = { type: 'string', default: CONFIG, description: 'the replz config', placeholder: 'path' };
|
|
67
85
|
const casesOption = { type: 'string', default: CASES, description: 'the folder of case files', placeholder: 'dir' };
|
|
68
86
|
export const program = defineProgram({
|
|
@@ -76,7 +94,7 @@ export const program = defineProgram({
|
|
|
76
94
|
effects: 'read_only',
|
|
77
95
|
examples: [{ command: 'replz check', description: 'are the cases ready to run' }],
|
|
78
96
|
options: { repo: repoOption, config: configOption, cases: casesOption },
|
|
79
|
-
run: ({ options }) => runCheck({ repo: options.repo, config: options.config, cases: options.cases }),
|
|
97
|
+
run: refusing(({ options }) => runCheck({ repo: options.repo, config: options.config, cases: options.cases })),
|
|
80
98
|
}),
|
|
81
99
|
defineCommand({
|
|
82
100
|
name: 'run',
|
|
@@ -95,7 +113,7 @@ export const program = defineProgram({
|
|
|
95
113
|
maxFindings: { type: 'number', description: 'the most findings graded per case, which caps the cost (default: the config)', placeholder: 'n' },
|
|
96
114
|
record: { type: 'boolean', description: `append the report to ${HISTORY}` },
|
|
97
115
|
},
|
|
98
|
-
run: ({ options }) => runReplay({
|
|
116
|
+
run: refusing(({ options }) => runReplay({
|
|
99
117
|
repo: options.repo,
|
|
100
118
|
config: options.config,
|
|
101
119
|
cases: options.cases,
|
|
@@ -106,7 +124,7 @@ export const program = defineProgram({
|
|
|
106
124
|
shell: sh,
|
|
107
125
|
worktrees: worktreesIn(options.repo),
|
|
108
126
|
now: () => new Date(),
|
|
109
|
-
}),
|
|
127
|
+
})),
|
|
110
128
|
}),
|
|
111
129
|
defineCommand({
|
|
112
130
|
name: 'propose',
|
|
@@ -118,7 +136,7 @@ export const program = defineProgram({
|
|
|
118
136
|
ref: { type: 'string', default: 'origin/main', description: 'the history to read', placeholder: 'ref' },
|
|
119
137
|
limit: { type: 'number', default: DEFAULT_LIMIT, description: 'the most bug cases to draft', placeholder: 'n' },
|
|
120
138
|
},
|
|
121
|
-
run: ({ options }) => runPropose({ repo: options.repo, ref: options.ref, limit: options.limit, log: logOf }),
|
|
139
|
+
run: refusing(({ options }) => runPropose({ repo: options.repo, ref: options.ref, limit: options.limit, log: logOf })),
|
|
122
140
|
}),
|
|
123
141
|
],
|
|
124
142
|
});
|
package/dist/config.js
CHANGED
|
@@ -15,10 +15,17 @@ const SCHEMA = object({
|
|
|
15
15
|
checklist: optional(text),
|
|
16
16
|
}, { unknown: 'strict' });
|
|
17
17
|
export const parseConfig = (source, yaml) => {
|
|
18
|
-
|
|
18
|
+
let document;
|
|
19
|
+
try {
|
|
20
|
+
document = parseYaml(yaml);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw new Error(`${source} is not YAML: ${error.message}. fix: correct the YAML`, { cause: error });
|
|
24
|
+
}
|
|
25
|
+
const parsed = parse(SCHEMA, document);
|
|
19
26
|
if (!parsed.ok) {
|
|
20
27
|
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}`);
|
|
28
|
+
throw new Error(`${source} is not a valid replz config:\n${lines}\nfix: correct each field named above`);
|
|
22
29
|
}
|
|
23
30
|
return parsed.value;
|
|
24
31
|
};
|
|
@@ -33,7 +40,7 @@ export const parseFindings = (stdout, stages) => {
|
|
|
33
40
|
}
|
|
34
41
|
const parsed = parse(FINDINGS, document);
|
|
35
42
|
if (!parsed.ok)
|
|
36
|
-
throw new Error(`the reviewer's findings are not valid: ${parsed.issues.map((issue) => `${issue.path} ${issue.message}`).join('; ')}`);
|
|
43
|
+
throw new Error(`the reviewer's findings are not valid: ${parsed.issues.map((issue) => `${issue.path} ${issue.message}`).join('; ')}. fix: make the reviewer print a JSON array of { stage, severity, text, item? }`);
|
|
37
44
|
const findings = parsed.value;
|
|
38
45
|
const unknown = findings.find((finding) => !stages.includes(finding.stage));
|
|
39
46
|
if (unknown !== undefined)
|
package/dist/propose.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PLACEHOLDER } from './cases.js';
|
|
1
2
|
export const LOG_ARGS = ['log', '--first-parent', '--shortstat', '--format=%x00%H%x09%P%x09%s%x09%b%x01'];
|
|
2
3
|
const PR_IN_SUBJECT = /\(#(\d+)\)$/;
|
|
3
4
|
const REVERTED = /^Revert "(.*)"(?: \(#\d+\))?$/;
|
|
@@ -63,7 +64,7 @@ export const toYaml = (found, subject) => [
|
|
|
63
64
|
`pr: ${String(found.pr)}`,
|
|
64
65
|
`base: ${JSON.stringify(found.base)}`,
|
|
65
66
|
`head: ${JSON.stringify(found.head)}`,
|
|
66
|
-
...(found.kind === 'bug' ? [
|
|
67
|
+
...(found.kind === 'bug' ? [`answer: ${PLACEHOLDER} one sentence saying what the bug is, from the revert or the fix`] : []),
|
|
67
68
|
`set: ${found.set}`,
|
|
68
69
|
'',
|
|
69
70
|
].join('\n');
|
package/dist/refusal.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const FIX = 'fix: ';
|
|
2
|
+
export class Refusal extends Error {
|
|
3
|
+
fix;
|
|
4
|
+
constructor(message, fix, options) {
|
|
5
|
+
super(message, options);
|
|
6
|
+
this.name = 'Refusal';
|
|
7
|
+
this.fix = fix;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export const RUNTIME = 1;
|
|
11
|
+
Object.defineProperty(Refusal, Symbol.for('burgee.exitCode'), { value: RUNTIME });
|
|
12
|
+
export const refusalOf = (error) => {
|
|
13
|
+
const at = error.message.lastIndexOf(FIX);
|
|
14
|
+
if (at === -1)
|
|
15
|
+
return error;
|
|
16
|
+
const message = error.message.slice(0, at).replace(/[\s.;,]+$/, '');
|
|
17
|
+
return new Refusal(message, error.message.slice(at + FIX.length), { cause: error });
|
|
18
|
+
};
|
|
19
|
+
export const refusing = (run) => async (...args) => {
|
|
20
|
+
try {
|
|
21
|
+
return await run(...args);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
const refused = error instanceof Error ? refusalOf(error) : error;
|
|
25
|
+
throw refused;
|
|
26
|
+
}
|
|
27
|
+
};
|
package/dist/run.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* One replay (replz spec R2, R3): for each case, a git worktree at its head, the reviewer and every
|
|
3
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:
|
|
5
|
-
* they cost one reviewer call and nothing more.
|
|
4
|
+
* grader call, at most `maxFindings` per case, the last stage's first. Controls are never graded:
|
|
5
|
+
* they have no answer, so they cost one reviewer call and nothing more.
|
|
6
6
|
*/
|
|
7
7
|
import { type Case } from './cases.js';
|
|
8
8
|
import { type Config, type Finding } from './config.js';
|
|
@@ -36,5 +36,16 @@ export interface Replayer {
|
|
|
36
36
|
readonly config: Config;
|
|
37
37
|
/** Put into the grader command's `{model}`. */
|
|
38
38
|
readonly model: string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* The repository replz was started in, as an absolute path: `REPLZ_REPO` for every command, so a
|
|
41
|
+
* reviewer script kept in it is found from a case's worktree, where it may not exist yet.
|
|
42
|
+
*/
|
|
43
|
+
readonly repo?: string | undefined;
|
|
39
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* The findings the cap leaves graded, as their places: the last stage's first, then each earlier
|
|
47
|
+
* stage's, each stage in the order the reviewer printed. The last stage is what ships, so a low cap
|
|
48
|
+
* spends its grader calls there before it spends any on a finding the pipeline later dropped.
|
|
49
|
+
*/
|
|
50
|
+
export declare const gradedFirst: (findings: readonly Finding[], stages: readonly string[], cap: number) => number[];
|
|
40
51
|
export declare const replayCase: (replayer: Replayer, found: Case) => Promise<CaseResult>;
|
package/dist/run.js
CHANGED
|
@@ -6,20 +6,22 @@ export const gradePrompt = (answer, finding) => [
|
|
|
6
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
7
|
].join('\n');
|
|
8
8
|
export const isYes = (stdout) => /^\W*yes\b/i.test(stdout);
|
|
9
|
+
export const gradedFirst = (findings, stages, cap) => findings
|
|
10
|
+
.map((finding, index) => ({ index, rank: stages.indexOf(finding.stage) }))
|
|
11
|
+
.toSorted((a, b) => b.rank - a.rank)
|
|
12
|
+
.slice(0, cap)
|
|
13
|
+
.map(({ index }) => index);
|
|
9
14
|
const grade = async ({ shell, config, model }, cwd, answer, findings) => {
|
|
10
15
|
const command = config.grader.replaceAll('{model}', String(model));
|
|
11
|
-
const
|
|
12
|
-
for (const
|
|
13
|
-
|
|
14
|
-
graded.push({ finding, matches: false });
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
const answered = await shell(command, { cwd, input: gradePrompt(answer, finding) });
|
|
16
|
+
const matched = new Set();
|
|
17
|
+
for (const index of gradedFirst(findings, config.stages, config.maxFindings)) {
|
|
18
|
+
const answered = await shell(command, { cwd, input: gradePrompt(answer, findings[index]) });
|
|
18
19
|
if (answered.code !== 0)
|
|
19
20
|
throw new Error(`the grader failed (exit ${String(answered.code)}): ${answered.stderr.trim()}. fix: check the grader command in the replz config`);
|
|
20
|
-
|
|
21
|
+
if (isYes(answered.stdout))
|
|
22
|
+
matched.add(index);
|
|
21
23
|
}
|
|
22
|
-
return { graded, capped: findings.length > config.maxFindings };
|
|
24
|
+
return { graded: findings.map((finding, index) => ({ finding, matches: matched.has(index) })), capped: findings.length > config.maxFindings };
|
|
23
25
|
};
|
|
24
26
|
export const replayCase = async (replayer, found) => {
|
|
25
27
|
const { shell, config } = replayer;
|
|
@@ -29,6 +31,8 @@ export const replayCase = async (replayer, found) => {
|
|
|
29
31
|
const { dir, remove } = await replayer.worktrees.add(found.head);
|
|
30
32
|
try {
|
|
31
33
|
const env = { REPLZ_BASE: found.base, REPLZ_HEAD: found.head, REPLZ_PR: String(found.pr) };
|
|
34
|
+
if (replayer.repo !== undefined)
|
|
35
|
+
env.REPLZ_REPO = replayer.repo;
|
|
32
36
|
if (config.setup !== undefined) {
|
|
33
37
|
const ready = await shell(config.setup, { cwd: dir, env });
|
|
34
38
|
if (ready.code !== 0)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "replz",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"private": false,
|
|
5
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
6
|
"keywords": [
|