# replz

> Every export of replz, with its signature and doc comment: KINDS, parseCase, selectCases, SETS, CONFIG, parseConfig and 18 more, plus 10 types.

Source: https://replz.interlace.tools/docs/api

<!-- Generated by scripts/api-reference.ts from the built dist/*.d.ts. Do not edit; run `npx tsx scripts/api-reference.ts`. -->

```ts
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.

```ts
const blamed: (commit: Commit) => number[];
```

### CASES

```ts
const CASES = ".sdlc/replz/cases";
```

### CONFIG

```ts
const CONFIG = ".sdlc/replz/config.yaml";
```

### gradePrompt

The grader's whole prompt: the answer key, one finding, and the question.

```ts
const gradePrompt: (answer: string, finding: Finding) => string;
```

### HISTORY

```ts
const HISTORY = ".sdlc/replz/history.jsonl";
```

### isYes

A grader answer counts as a match only when its first word is yes.

```ts
const isYes: (stdout: string) => boolean;
```

### KINDS

```ts
const KINDS: readonly ["bug", "control"];
```

### parseCase

Read one case from its YAML; `source` names it in every error.

```ts
const parseCase: (source: string, yaml: string) => Case;
```

### parseConfig

```ts
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.

```ts
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.

```ts
const parseLog: (log: string) => Commit[];
```

### prOf

```ts
const prOf: (subject: string) => number | undefined;
```

### program

```ts
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.

```ts
const propose: (commits: readonly Commit[], limit: number) => Proposal;
```

### readCases

Every `*.yaml` case under `dir`, sorted by file name, each named `<id>.yaml`.

```ts
const readCases: (repo: string, dir: string) => Case[];
```

### replayCase

```ts
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.

```ts
const runCheck: (options: CheckOptions) => Data;
```

### runPropose

```ts
const runPropose: (options: ProposeOptions) => Promise<Data>;
```

### runReplay

```ts
const runReplay: (options: RunOptions) => Promise<Data>;
```

### score

```ts
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.

```ts
const selectCases: (cases: readonly Case[], set: Case["set"] | undefined) => Case[];
```

### SETS

```ts
const SETS: readonly ["tune", "test"];
```

### SEVERITIES

```ts
const SEVERITIES: readonly ["must-fix", "should-fix", "nit", "pre-existing"];
```

### VERSION

```ts
const VERSION: string;
```

## Interfaces

### Case

```ts
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

```ts
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.

```ts
interface Commit {
    readonly sha: string;
    readonly parent: string;
    readonly subject: string;
    readonly body: string;
    /** Lines added and removed. */
    readonly size: number;
}
```

### Config

```ts
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.

```ts
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.

```ts
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

```ts
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

```ts
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

```ts
type Severity = (typeof SEVERITIES)[number];
```

### Shell

Runs a shell command line; a test passes its own and runs nothing.

```ts
type Shell = (command: string, options: {
    readonly cwd: string;
    readonly env?: Readonly<Record<string, string>>;
    readonly input?: string;
}) => Promise<Ran>;
```
