replz
Every export of replz, with its signature and doc comment: KINDS, parseCase, selectCases, SETS, CONFIG, parseConfig and 18 more, plus 10 types.
import { KINDS, parseCase, selectCases, … } from 'replz';Constants
blamed
The pull requests a commit says were bugs: the one a revert undoes, or the one a fix names.
const blamed: (commit: Commit) => number[];CASES
const CASES = ".sdlc/replz/cases";CONFIG
const CONFIG = ".sdlc/replz/config.yaml";gradePrompt
The grader's whole prompt: the answer key, one finding, and the question.
const gradePrompt: (answer: string, finding: Finding) => string;HISTORY
const HISTORY = ".sdlc/replz/history.jsonl";isYes
A grader answer counts as a match only when its first word is yes.
const isYes: (stdout: string) => boolean;KINDS
const KINDS: readonly ["bug", "control"];parseCase
Read one case from its YAML; source names it in every error.
const parseCase: (source: string, yaml: string) => Case;parseConfig
const parseConfig: (source: string, yaml: string) => Config;parseFindings
The reviewer's stdout as findings; a stage the config does not name is refused, never dropped.
const parseFindings: (stdout: string, stages: readonly string[]) => Finding[];parseLog
Read what git <LOG_ARGS> prints: per commit, its fields, then the body's end mark, then its stat.
const parseLog: (log: string) => Commit[];prOf
const prOf: (subject: string) => number | undefined;program
const program: import("burgee").Manifest;propose
Bug drafts for every blamed pull request found on main, newest first, alternating test and tune so neither set is all old or all new; and per bug, the nearest-sized unblamed pull request as its control, never one used twice.
const propose: (commits: readonly Commit[], limit: number) => Proposal;readCases
Every *.yaml case under dir, sorted by file name, each named <id>.yaml.
const readCases: (repo: string, dir: string) => Case[];replayCase
const replayCase: (replayer: Replayer, found: Case) => Promise<CaseResult>;runCheck
The config and every case parse, each case file is named by its id, no answer is the draft's placeholder, ids are distinct, and each set holds a bug and a control: what a run needs. A set of one kind gives a score of one kind, recall with no false alarms or the reverse.
const runCheck: (options: CheckOptions) => Data;runPropose
const runPropose: (options: ProposeOptions) => Promise<Data>;runReplay
const runReplay: (options: RunOptions) => Promise<Data>;score
const score: (results: readonly CaseResult[], stages: readonly string[], checks: readonly string[], items: readonly string[]) => Report;selectCases
Cases must have distinct ids; a run on set takes only that set's cases.
const selectCases: (cases: readonly Case[], set: Case["set"] | undefined) => Case[];SETS
const SETS: readonly ["tune", "test"];SEVERITIES
const SEVERITIES: readonly ["must-fix", "should-fix", "nit", "pre-existing"];VERSION
const VERSION: string;Interfaces
Case
interface Case {
readonly id: string;
readonly kind: (typeof KINDS)[number];
/** The pull request the commits belong to. */
readonly pr: number;
/** The commit the pull request was reviewed against. */
readonly base: string;
/** The commit the reviewer saw: the pull request applied to `base`. */
readonly head: string;
/** What the bug is, in one sentence. Bugs only. */
readonly answer?: string | undefined;
readonly set: (typeof SETS)[number];
}CaseResult
interface CaseResult {
readonly case: Case;
readonly findings: readonly Graded[];
/** More findings than the cap: those past it were not graded. */
readonly capped: boolean;
/** Each check's id, and whether it failed on this case. */
readonly fired: Readonly<Record<string, boolean>>;
}Commit
One commit on main.
interface Commit {
readonly sha: string;
readonly parent: string;
readonly subject: string;
readonly body: string;
/** Lines added and removed. */
readonly size: number;
}Config
interface Config {
/** Run first in each case's worktree, which starts without node_modules. */
readonly setup?: string | undefined;
readonly reviewer: string;
/** `{model}` in it is replaced by the model a run grades with. */
readonly grader: string;
/** The default for `--model`. Left out, a run must name one. */
readonly model?: string | undefined;
readonly maxFindings: number;
/** The reviewer's stages, in order; the last is what ships. */
readonly stages: readonly string[];
readonly checks: readonly Check[];
/** The checklist whose items a finding may name, so an item that never fires is reported too. */
readonly checklist?: string | undefined;
}Finding
One thing the reviewer said, at one stage of its pipeline.
interface Finding {
readonly stage: string;
readonly severity: Severity;
readonly text: string;
/** The checklist item that prompted it, when the reviewer says. */
readonly item?: string | undefined;
}Replayer
What every case of one run shares.
interface Replayer {
readonly shell: Shell;
readonly worktrees: Worktrees;
readonly config: Config;
/** Put into the grader command's `{model}`. */
readonly model: string | undefined;
/**
* The repository replz was started in, as an absolute path: `REPLZ_REPO` for every command, so a
* reviewer script kept in it is found from a case's worktree, where it may not exist yet.
*/
readonly repo?: string | undefined;
}Report
interface Report {
readonly bugs: number;
readonly controls: number;
readonly recall: readonly {
readonly stage: string;
readonly found: number;
}[];
/** Findings at the last stage, by severity. */
readonly severity: Readonly<Record<Severity, number>>;
/** Controls with a must-fix or should-fix finding at the last stage. */
readonly falseAlarms: number;
readonly firing: readonly Firing[];
readonly neverFired: readonly string[];
readonly capped: readonly string[];
}Worktrees
interface Worktrees {
/** A detached worktree at `ref`, and the function that removes it. */
readonly add: (ref: string) => Promise<{
readonly dir: string;
readonly remove: () => Promise<void>;
}>;
}Types
Severity
type Severity = (typeof SEVERITIES)[number];Shell
Runs a shell command line; a test passes its own and runs nothing.
type Shell = (command: string, options: {
readonly cwd: string;
readonly env?: Readonly<Record<string, string>>;
readonly input?: string;
}) => Promise<Ran>;Pruning checks and comparing runs
Read replz's firing table to decide which checks and checklist items earn their cost, and compare two recorded runs on the same cases to see what a change to REVIEW.md did to recall and false alarms.
FAQ
Short answers about replz: what it costs, where the cases come from, why controls, why a grader model, what counts as a match, running in CI, other reviewers, and what check does not catch, each with where to read more.