triggerlist 0.0.1 → 0.2.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 +208 -0
- package/dist/bin.js +4 -0
- package/dist/brief.d.ts +30 -0
- package/dist/brief.js +31 -0
- package/dist/checklist.d.ts +23 -0
- package/dist/checklist.js +41 -0
- package/dist/cli.d.ts +50 -0
- package/dist/cli.js +215 -0
- package/dist/compile.d.ts +17 -0
- package/dist/compile.js +28 -0
- package/dist/diff.d.ts +16 -0
- package/dist/diff.js +35 -0
- package/dist/git.d.ts +7 -0
- package/dist/git.js +11 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/match.d.ts +20 -0
- package/dist/match.js +42 -0
- package/dist/protect.d.ts +8 -0
- package/dist/protect.js +15 -0
- package/dist/seed.d.ts +21 -0
- package/dist/seed.js +69 -0
- package/package.json +74 -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,208 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/ofri-peretz/burgee/tree/main/packages/triggerlist" target="blank">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ofri-peretz/burgee/main/brand-assets/triggerlist-lockup.svg" />
|
|
5
|
+
<img src="https://raw.githubusercontent.com/ofri-peretz/burgee/main/brand-assets/triggerlist-lockup-light.svg" alt="triggerlist" width="360" />
|
|
6
|
+
</picture>
|
|
7
|
+
</a>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
Only what the diff fires: the review checklist a change selects, read from the base branch so the change cannot edit its own checks.
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://www.npmjs.com/package/triggerlist"><img src="https://img.shields.io/npm/v/triggerlist?style=flat-square&color=0a6b47" alt="triggerlist on npm: the latest version" /></a>
|
|
16
|
+
<a href="https://www.npmjs.com/package/triggerlist"><img src="https://img.shields.io/npm/dm/triggerlist?style=flat-square" alt="triggerlist 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=triggerlist&style=flat-square" alt="triggerlist 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/triggerlist?activeTab=code"><img src="https://img.shields.io/npm/unpacked-size/triggerlist?style=flat-square" alt="Unpacked size of the latest triggerlist release on npm" /></a>
|
|
21
|
+
<a href="https://github.com/ofri-peretz/burgee/blob/main/packages/triggerlist/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/triggerlist/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/triggerlist/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/triggerlist/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/triggerlist#provenance"><img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fregistry.npmjs.org%2Ftriggerlist%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/triggerlist">https://burgee.interlace.tools/docs/packages/triggerlist</a><br />
|
|
30
|
+
Migrating from: <a href="https://github.com/ofri-peretz/burgee/tree/main/packages/triggerlist#migrating">danger</a>
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
**triggerlist** gives a code reviewer, a person or a model, only the checklist items a change
|
|
34
|
+
fires. Each item names the paths and the line pattern that trigger it, the question to ask and
|
|
35
|
+
the check that answers it. `triggerlist match` lists what fires on a diff, `brief` writes the
|
|
36
|
+
reviewer's prompt for one round, `compile` writes REVIEW.md under a byte budget, and `protect`
|
|
37
|
+
flags a change that edits a gate and the code it judges together. The checklist and the rules
|
|
38
|
+
are read from the base branch, so a pull request is reviewed by rules it did not write.
|
|
39
|
+
|
|
40
|
+
It covers the rules half of **danger**: where a Dangerfile runs code against a pull request,
|
|
41
|
+
triggerlist keeps the rules as data a reviewer reads. Every command prints burgee's `--json`
|
|
42
|
+
envelope, each item with where it fired, for a pipe or an agent.
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install triggerlist
|
|
48
|
+
pnpm add triggerlist
|
|
49
|
+
yarn add triggerlist
|
|
50
|
+
bun add triggerlist
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Install it as a dev dependency (`-D`) of the repository it reviews. It needs git.
|
|
54
|
+
|
|
55
|
+
## Quick start
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install triggerlist
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
import { match, parseChecklist, parseDiff } from "triggerlist";
|
|
63
|
+
|
|
64
|
+
const checklist = parseChecklist(".sdlc/checklist.yaml", `
|
|
65
|
+
gates: ["scripts/*-lock.test.ts"]
|
|
66
|
+
items:
|
|
67
|
+
- id: spawn
|
|
68
|
+
trigger: { paths: ["src/**/*.ts"], pattern: "child_process" }
|
|
69
|
+
question: Does it spawn through bellpull?
|
|
70
|
+
check: a direct child_process import is a finding
|
|
71
|
+
sources: ["#212"]
|
|
72
|
+
`);
|
|
73
|
+
// What `git diff --no-renames -U0` prints for one added import.
|
|
74
|
+
const diff = `diff --git a/src/run.ts b/src/run.ts
|
|
75
|
+
--- a/src/run.ts
|
|
76
|
+
+++ b/src/run.ts
|
|
77
|
+
@@ -1,0 +2,1 @@
|
|
78
|
+
+import { spawn } from "node:child_process";
|
|
79
|
+
`;
|
|
80
|
+
for (const { item, at } of match(checklist, parseDiff(diff))) console.log(`${item.id}: ${item.question} (${at[0].file}:${at[0].line})`);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
spawn: Does it spawn through bellpull? (src/run.ts:2)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## What it checks
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
triggerlist match origin/main # the items that fire on origin/main...HEAD
|
|
91
|
+
triggerlist brief origin/main --head "$SHA" # the reviewer's prompt for one round
|
|
92
|
+
triggerlist compile --check # fail when REVIEW.md is stale
|
|
93
|
+
triggerlist protect origin/main # a gate and the code it judges, changed together
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
| Command | Exit 1 when |
|
|
97
|
+
| :-- | :-- |
|
|
98
|
+
| `compile --check` | REVIEW.md is not what the checklist compiles to |
|
|
99
|
+
| `protect` | one change edits a gate file and the code that gate judges |
|
|
100
|
+
|
|
101
|
+
## Migrating
|
|
102
|
+
|
|
103
|
+
The switch is one command, `npx triggerlist brief`, where the Dangerfile ran:
|
|
104
|
+
|
|
105
|
+
```diff
|
|
106
|
+
# .github/workflows/review.yml
|
|
107
|
+
- - run: npx danger ci
|
|
108
|
+
+ - run: npx triggerlist brief origin/${{ github.base_ref }} --head ${{ github.sha }} > brief.md
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
and each Dangerfile rule becomes a checklist item with the paths that trigger it. Keep danger for
|
|
112
|
+
rules that must post on the pull request themselves.
|
|
113
|
+
|
|
114
|
+
## Compatibility
|
|
115
|
+
|
|
116
|
+
Not graded: triggerlist reads a repository's diff and checklist, and no suite is graded against
|
|
117
|
+
it. It runs anywhere git does.
|
|
118
|
+
|
|
119
|
+
## Benchmarks
|
|
120
|
+
|
|
121
|
+
Every number here is produced by `npm run bench` and published at [burgee.interlace.tools/docs/benchmarks](https://burgee.interlace.tools/docs/benchmarks).
|
|
122
|
+
|
|
123
|
+
No suite is graded against this package yet, so there is no compatibility number to quote.
|
|
124
|
+
|
|
125
|
+
## For agents
|
|
126
|
+
|
|
127
|
+
- **`triggerlist match --json`**, **`brief --json`** and **`protect --json`** print burgee's
|
|
128
|
+
`--json` envelope; a failure ends in `fix:`.
|
|
129
|
+
- **`--json`, `--schema` and an MCP server** come from one declaration on burgee:
|
|
130
|
+
`triggerlist --mcp` serves its commands as tools.
|
|
131
|
+
- **Exit codes are the contract.** `0` passed; `1` a check failed, as the table above says; `2` a
|
|
132
|
+
usage error, with the `fix:` to run.
|
|
133
|
+
- **The docs are machine-readable** at
|
|
134
|
+
[burgee.interlace.tools/llms.txt](https://burgee.interlace.tools/llms.txt).
|
|
135
|
+
|
|
136
|
+
## API
|
|
137
|
+
|
|
138
|
+
| Import | What it gives you |
|
|
139
|
+
| :-- | :-- |
|
|
140
|
+
| `triggerlist` | `parseChecklist()`, `parseDiff()`, `match()`, `compile()`, `protect()`, `briefText()` and `program` |
|
|
141
|
+
|
|
142
|
+
The `triggerlist` bin is that API, declared once on burgee.
|
|
143
|
+
|
|
144
|
+
## Requirements
|
|
145
|
+
|
|
146
|
+
Node 22.13 or later, and git.
|
|
147
|
+
|
|
148
|
+
## Where it sits
|
|
149
|
+
|
|
150
|
+
It hosts no plugin key of its own.
|
|
151
|
+
|
|
152
|
+
Nothing in this family builds on it yet, and it builds on `bellpull`, `burgee`, `seniority`, `truefit`.
|
|
153
|
+
|
|
154
|
+
## The family
|
|
155
|
+
|
|
156
|
+
18 packages, one repository, one release pipeline. Each installs and works on its own, and each owns
|
|
157
|
+
one job. Seven of them — `bellpull`, `closeout`, `linegauge`, `paratext`, `roundel`, `seniority`,
|
|
158
|
+
`truefit` — depend on nothing; the others depend only on packages in this table, and every
|
|
159
|
+
dependency points one way, down the [layers](https://burgee.interlace.tools/docs/concepts/family).
|
|
160
|
+
|
|
161
|
+
No package declares a dependency from outside the family; `react` and `react-reconciler` are
|
|
162
|
+
optional peers of `controlroom`, which npm does not install; `vitest` is an optional peer of
|
|
163
|
+
`oxmutate`, which npm does not install; `eslint` is an optional peer of `truepass`, which npm does
|
|
164
|
+
not install.
|
|
165
|
+
[`package-shape-lock`](https://github.com/ofri-peretz/burgee/blob/main/scripts/package-shape-lock.test.ts)
|
|
166
|
+
holds that for every manifest, and
|
|
167
|
+
[`independence-install-lock`](https://github.com/ofri-peretz/burgee/blob/main/scripts/independence-install-lock.test.ts)
|
|
168
|
+
installs each package alone and finds nothing but the family packages it declares.
|
|
169
|
+
|
|
170
|
+
Releases are published by one workflow through npm trusted publishing: no npm token is used, and
|
|
171
|
+
each release carries SLSA provenance, which `npm view <package> dist.attestations` shows.
|
|
172
|
+
[`trusted-publishing-lock`](https://github.com/ofri-peretz/burgee/blob/main/scripts/trusted-publishing-lock.test.ts)
|
|
173
|
+
keeps both true.
|
|
174
|
+
|
|
175
|
+
| Package | What it is | Migrates from |
|
|
176
|
+
| :-- | :-- | :-- |
|
|
177
|
+
| [burgee](https://burgee.interlace.tools/docs/packages/burgee) | The CLI framework: one declaration, every surface | commander, yargs and meow |
|
|
178
|
+
| [roundel](https://roundel.interlace.tools/docs) | Colour: one output policy, semantic tokens, a theme | chalk, colorette, kleur, picocolors, supports-color and yoctocolors |
|
|
179
|
+
| [flagstaff](https://flagstaff.interlace.tools/docs) | The frame loop: spinners, progress, boxes and tables | ora, log-update, boxen and cli-table3 |
|
|
180
|
+
| [caique](https://caique.interlace.tools/docs) | Prompts that are flags first, and never hang | @inquirer/core |
|
|
181
|
+
| [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 |
|
|
182
|
+
| [paratext](https://paratext.interlace.tools/docs) | Hyperlinks, images, title, clipboard and notifications | ansi-escapes, terminal-link and term-img |
|
|
183
|
+
| [seniority](https://seniority.interlace.tools/docs) | Configuration precedence and discovery, with provenance | cosmiconfig, lilconfig, dotenv and rc |
|
|
184
|
+
| [closeout](https://closeout.interlace.tools/docs) | Exit handlers, terminal restore and a bounded shutdown | signal-exit, exit-hook, restore-cursor, cli-cursor and onetime |
|
|
185
|
+
| [bellpull](https://bellpull.interlace.tools/docs) | Subprocesses, and which executable actually ran | cross-spawn and which |
|
|
186
|
+
| [controlroom](https://controlroom.interlace.tools/docs) | Keyboard-driven terminal screens, inline or full-screen | ink |
|
|
187
|
+
| [oxmutate](https://oxmutate.interlace.tools/docs) | Mutation testing on the oxc engine, inside your own Vitest | Stryker |
|
|
188
|
+
| [truepass](https://burgee.interlace.tools/docs/packages/truepass) | Lint rules and a pre-push check that keep a test suite honest | @vitest/eslint-plugin |
|
|
189
|
+
| [contractdiff](https://burgee.interlace.tools/docs/packages/contractdiff) | API contracts: breaking-change diff, lint, and code from the spec | openapi-typescript |
|
|
190
|
+
| [truefit](https://burgee.interlace.tools/docs/packages/truefit) | Validation whose schemas are data, with no eval | zod |
|
|
191
|
+
| [provedone](https://burgee.interlace.tools/docs/packages/provedone) | A receipt for how every change was verified, and a gate that reads it | @commitlint/cli |
|
|
192
|
+
| [replz](https://burgee.interlace.tools/docs/packages/replz) | Recall of a reviewer and its checks, replayed on bugs that shipped | promptfoo |
|
|
193
|
+
| [hookset](https://burgee.interlace.tools/docs/packages/hookset) | The same git and Claude Code hooks in every repository, pinned by tag | husky |
|
|
194
|
+
| **triggerlist** (this package) | The review checklist a diff selects, read from the base branch | danger |
|
|
195
|
+
|
|
196
|
+
Every migration guide, and the family-wide [compatibility](https://burgee.interlace.tools/docs/compatibility)
|
|
197
|
+
and [benchmarks](https://burgee.interlace.tools/docs/benchmarks) pages, are on
|
|
198
|
+
[burgee.interlace.tools](https://burgee.interlace.tools/docs/packages).
|
|
199
|
+
|
|
200
|
+
## Contributing
|
|
201
|
+
|
|
202
|
+
Issues and pull requests are welcome at [ofri-peretz/burgee](https://github.com/ofri-peretz/burgee/issues); read
|
|
203
|
+
[CONTRIBUTING.md](https://github.com/ofri-peretz/burgee/blob/main/CONTRIBUTING.md) first. Report a vulnerability privately, as
|
|
204
|
+
[SECURITY.md](https://github.com/ofri-peretz/burgee/blob/main/SECURITY.md) describes — never in a public issue.
|
|
205
|
+
|
|
206
|
+
## Licence
|
|
207
|
+
|
|
208
|
+
MIT © Ofri Peretz — see [LICENSE](https://github.com/ofri-peretz/burgee/blob/main/packages/triggerlist/LICENSE).
|
package/dist/bin.js
ADDED
package/dist/brief.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the reviewer is handed for one round (spec R5): the rules as the base branch has them, the
|
|
3
|
+
* items this diff fires, its own findings from the round before, and the commit it reviews. The
|
|
4
|
+
* base copy of REVIEW.md is the point: a pull request that edits the rules is still reviewed by
|
|
5
|
+
* the rules it did not write.
|
|
6
|
+
*/
|
|
7
|
+
import { type Fired } from './match.js';
|
|
8
|
+
/** The line a review summary ends with, so the next round finds it among the PR's comments. */
|
|
9
|
+
export declare const MARKER = "<!-- triggerlist-review";
|
|
10
|
+
/** The marker line for a review of `head`. */
|
|
11
|
+
export declare const markerFor: (head: string) => string;
|
|
12
|
+
/** A PR comment as `gh api repos/<owner>/<repo>/issues/<n>/comments` lists it. */
|
|
13
|
+
export interface Comment {
|
|
14
|
+
readonly body?: string | null;
|
|
15
|
+
}
|
|
16
|
+
/** The body of the last comment that carries the marker: the previous round's findings, if any. */
|
|
17
|
+
export declare const previousFindings: (comments: readonly Comment[]) => string | undefined;
|
|
18
|
+
/** The head a previous review recorded in its marker, if it has one. */
|
|
19
|
+
export declare const reviewedHead: (findings: string | undefined) => string | undefined;
|
|
20
|
+
export interface Brief {
|
|
21
|
+
/** Where the rules were read from: `<base>:REVIEW.md`. */
|
|
22
|
+
readonly rules: string;
|
|
23
|
+
readonly rulesText: string;
|
|
24
|
+
readonly range: string;
|
|
25
|
+
readonly fired: readonly Fired[];
|
|
26
|
+
readonly previous: string | undefined;
|
|
27
|
+
readonly head: string;
|
|
28
|
+
}
|
|
29
|
+
/** The brief as the reviewer reads it: four sections, then the marker its summary must end with. */
|
|
30
|
+
export declare const briefText: (brief: Brief) => string;
|
package/dist/brief.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { toText } from './match.js';
|
|
2
|
+
const OPEN = '\u003C!--';
|
|
3
|
+
const CLOSE = '--\u003E';
|
|
4
|
+
export const MARKER = `${OPEN} triggerlist-review`;
|
|
5
|
+
export const markerFor = (head) => `${MARKER} head=${head} ${CLOSE}`;
|
|
6
|
+
export const previousFindings = (comments) => comments.findLast((comment) => comment.body?.includes(MARKER) === true)?.body ?? undefined;
|
|
7
|
+
export const reviewedHead = (findings) => findings?.match(/\u003C!-- triggerlist-review head=([0-9a-f]+) --\u003E/u)?.[1];
|
|
8
|
+
export const briefText = (brief) => {
|
|
9
|
+
const before = reviewedHead(brief.previous);
|
|
10
|
+
return [
|
|
11
|
+
`## The rules (${brief.rules}, as the base branch has them)`,
|
|
12
|
+
'',
|
|
13
|
+
brief.rulesText.trim(),
|
|
14
|
+
'',
|
|
15
|
+
`## The rules this diff fires (${brief.range})`,
|
|
16
|
+
'',
|
|
17
|
+
toText(brief.fired, brief.range),
|
|
18
|
+
'',
|
|
19
|
+
'## Your findings from the previous round',
|
|
20
|
+
'',
|
|
21
|
+
brief.previous === undefined
|
|
22
|
+
? 'None: this is the first review of this pull request.'
|
|
23
|
+
: [`Reviewed at ${before ?? 'an unrecorded head'}. Say which of these the new commits fixed, and do not repeat a finding that still stands unless it changed.`, '', brief.previous.trim()].join('\n'),
|
|
24
|
+
'',
|
|
25
|
+
'## The commit under review',
|
|
26
|
+
'',
|
|
27
|
+
`${brief.head}. End your one summary comment with this line, exactly:`,
|
|
28
|
+
'',
|
|
29
|
+
markerFor(brief.head),
|
|
30
|
+
].join('\n');
|
|
31
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** One item: an id, a trigger readable from a diff, and what the reviewer does when it fires. */
|
|
2
|
+
export interface Item {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly trigger: {
|
|
5
|
+
/** Globs, matched with `path.matchesGlob` against the repo-relative path of a changed file. */
|
|
6
|
+
readonly paths: readonly string[];
|
|
7
|
+
/** A regex tested against each added or removed line of a matching file. Absent: any change fires. */
|
|
8
|
+
readonly pattern?: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
readonly question: string;
|
|
11
|
+
readonly check: string;
|
|
12
|
+
/** The PRs, incidents, decisions or lock tests behind the item: why it exists. */
|
|
13
|
+
readonly sources: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
export interface Checklist {
|
|
16
|
+
/** Globs naming the files that judge code: lock tests, hooks, bands, REVIEW.md, this file. */
|
|
17
|
+
readonly gates: readonly string[];
|
|
18
|
+
readonly items: readonly Item[];
|
|
19
|
+
}
|
|
20
|
+
/** Where the checklist lives when nobody says otherwise. */
|
|
21
|
+
export declare const CHECKLIST = ".sdlc/checklist.yaml";
|
|
22
|
+
/** Read a checklist from its YAML text; `source` names it in every error. */
|
|
23
|
+
export declare const parseChecklist: (source: string, yaml: string) => Checklist;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { parse as parseYaml } from 'seniority/yaml';
|
|
2
|
+
import { array, object, optional, parse, string } from 'truefit';
|
|
3
|
+
export const CHECKLIST = '.sdlc/checklist.yaml';
|
|
4
|
+
const text = string({ min: 1 });
|
|
5
|
+
const ITEM = object({
|
|
6
|
+
id: string({ pattern: /^[a-z0-9][a-z0-9-]*$/ }),
|
|
7
|
+
trigger: object({ paths: array(text, { min: 1 }), pattern: optional(text) }, { unknown: 'strict' }),
|
|
8
|
+
question: text,
|
|
9
|
+
check: text,
|
|
10
|
+
sources: array(text, { min: 1 }),
|
|
11
|
+
}, { unknown: 'strict' });
|
|
12
|
+
const SCHEMA = object({ gates: array(text), items: array(ITEM) }, { unknown: 'strict' });
|
|
13
|
+
export const parseChecklist = (source, yaml) => {
|
|
14
|
+
let document;
|
|
15
|
+
try {
|
|
16
|
+
document = parseYaml(yaml);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
throw new Error(`${source} is not YAML: ${error.message}. fix: correct the YAML`, { cause: error });
|
|
20
|
+
}
|
|
21
|
+
const parsed = parse(SCHEMA, document);
|
|
22
|
+
if (!parsed.ok) {
|
|
23
|
+
const lines = parsed.issues.map((issue) => ` ${issue.path === '' ? '/' : issue.path}: ${issue.message}`).join('\n');
|
|
24
|
+
throw new Error(`${source} is not a valid checklist:\n${lines}`);
|
|
25
|
+
}
|
|
26
|
+
const checklist = parsed.value;
|
|
27
|
+
const seen = new Set();
|
|
28
|
+
for (const item of checklist.items) {
|
|
29
|
+
if (seen.has(item.id))
|
|
30
|
+
throw new Error(`${source} names the item \`${item.id}\` twice. fix: give each item its own id`);
|
|
31
|
+
seen.add(item.id);
|
|
32
|
+
const pattern = item.trigger.pattern ?? '';
|
|
33
|
+
try {
|
|
34
|
+
new RegExp(pattern, 'u');
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw new Error(`${source}: \`${item.id}\` has a pattern that is not a regex: ${error.message}. fix: correct trigger.pattern`, { cause: error });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return checklist;
|
|
41
|
+
};
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type Checklist } from './checklist.js';
|
|
2
|
+
import { type Git } from './git.js';
|
|
3
|
+
export declare const VERSION: string;
|
|
4
|
+
type Data = Record<string | symbol, unknown>;
|
|
5
|
+
/** The checklist from the base branch, or from the working tree when asked: the source and the parsed list. */
|
|
6
|
+
export declare const loadChecklist: (repo: string, git: Git, path: string, base: string | undefined) => Promise<{
|
|
7
|
+
source: string;
|
|
8
|
+
checklist: Checklist;
|
|
9
|
+
}>;
|
|
10
|
+
export interface RangeOptions {
|
|
11
|
+
readonly repo: string;
|
|
12
|
+
readonly git: Git;
|
|
13
|
+
readonly base: string;
|
|
14
|
+
readonly checklist: string;
|
|
15
|
+
/** Read the checklist from the working tree instead of the base branch: for writing it, never for CI. */
|
|
16
|
+
readonly worktree: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare const runMatch: (options: RangeOptions) => Promise<Data>;
|
|
19
|
+
export declare const runProtect: (options: RangeOptions & {
|
|
20
|
+
readonly enforce: boolean;
|
|
21
|
+
}) => Promise<Data>;
|
|
22
|
+
export interface BriefOptions extends RangeOptions {
|
|
23
|
+
/** The rules file, read from the base branch. */
|
|
24
|
+
readonly review: string;
|
|
25
|
+
/** The commit under review, recorded in the marker so the next round knows what it saw. */
|
|
26
|
+
readonly head: string;
|
|
27
|
+
/** A JSON file of the PR's comments, as `gh api .../issues/<n>/comments` prints them. */
|
|
28
|
+
readonly comments?: string | undefined;
|
|
29
|
+
}
|
|
30
|
+
export declare const runBrief: (options: BriefOptions) => Promise<Data>;
|
|
31
|
+
export interface CompileOptions {
|
|
32
|
+
readonly repo: string;
|
|
33
|
+
readonly checklist: string;
|
|
34
|
+
readonly out: string;
|
|
35
|
+
readonly budget: number;
|
|
36
|
+
/** A JSON file of `{ "<id>": <firings> }`, as `replz` reports them. */
|
|
37
|
+
readonly firings?: string | undefined;
|
|
38
|
+
/** Write nothing; fail when the file on disk is not what compile would write. */
|
|
39
|
+
readonly check: boolean;
|
|
40
|
+
}
|
|
41
|
+
export declare const runCompile: (options: CompileOptions) => Data;
|
|
42
|
+
export interface SeedOptions {
|
|
43
|
+
readonly repo: string;
|
|
44
|
+
readonly checklist: string;
|
|
45
|
+
readonly locks: string;
|
|
46
|
+
readonly decisions: string;
|
|
47
|
+
}
|
|
48
|
+
export declare const runSeed: (options: SeedOptions) => Data;
|
|
49
|
+
export declare const program: import("burgee").Manifest;
|
|
50
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { defineCommand, defineProgram, ExitCode } from 'burgee';
|
|
4
|
+
import { briefText, markerFor, previousFindings } from './brief.js';
|
|
5
|
+
import { CHECKLIST, parseChecklist } from './checklist.js';
|
|
6
|
+
import { compile, DEFAULT_BUDGET } from './compile.js';
|
|
7
|
+
import { parseDiff } from './diff.js';
|
|
8
|
+
import { gitIn } from './git.js';
|
|
9
|
+
import { match, toText as matchText, where } from './match.js';
|
|
10
|
+
import { protect, toText as protectText } from './protect.js';
|
|
11
|
+
import { fromDecision, fromLockTest, toYaml } from './seed.js';
|
|
12
|
+
export const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
13
|
+
const TEXT = Symbol.for('burgee.text');
|
|
14
|
+
const HERE = '.';
|
|
15
|
+
export const loadChecklist = async (repo, git, path, base) => {
|
|
16
|
+
if (base === undefined)
|
|
17
|
+
return { source: path, checklist: parseChecklist(path, readFileSync(resolve(repo, path), 'utf8')) };
|
|
18
|
+
const source = `${base}:${path}`;
|
|
19
|
+
return { source, checklist: parseChecklist(source, await git.show(base, path)) };
|
|
20
|
+
};
|
|
21
|
+
const range = (base) => `${base}...HEAD`;
|
|
22
|
+
export const runMatch = async (options) => {
|
|
23
|
+
const { source, checklist } = await loadChecklist(options.repo, options.git, options.checklist, options.worktree ? undefined : options.base);
|
|
24
|
+
const fired = match(checklist, parseDiff(await options.git.diff(range(options.base))));
|
|
25
|
+
const data = {
|
|
26
|
+
range: range(options.base),
|
|
27
|
+
checklist: source,
|
|
28
|
+
fired: fired.map(({ item, at }) => ({ id: item.id, question: item.question, check: item.check, sources: item.sources, at: at.map(where) })),
|
|
29
|
+
};
|
|
30
|
+
data[TEXT] = () => matchText(fired, range(options.base));
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
export const runProtect = async (options) => {
|
|
34
|
+
const { source, checklist } = await loadChecklist(options.repo, options.git, options.checklist, options.worktree ? undefined : options.base);
|
|
35
|
+
const paths = parseDiff(await options.git.diff(range(options.base))).map((file) => file.path);
|
|
36
|
+
const result = protect(paths, checklist.gates);
|
|
37
|
+
const failed = result.flagged && options.enforce;
|
|
38
|
+
const data = {
|
|
39
|
+
range: range(options.base),
|
|
40
|
+
checklist: source,
|
|
41
|
+
mode: options.enforce ? 'enforce' : 'observe',
|
|
42
|
+
...result,
|
|
43
|
+
...(failed ? { exitCode: ExitCode.RUNTIME, fix: 'land the gate change in its own pull request first' } : {}),
|
|
44
|
+
};
|
|
45
|
+
data[TEXT] = () => protectText(result, range(options.base), options.enforce);
|
|
46
|
+
return data;
|
|
47
|
+
};
|
|
48
|
+
export const runBrief = async (options) => {
|
|
49
|
+
const rulesText = await options.git.show(options.base, options.review);
|
|
50
|
+
const { source, checklist } = await loadChecklist(options.repo, options.git, options.checklist, options.worktree ? undefined : options.base);
|
|
51
|
+
const fired = match(checklist, parseDiff(await options.git.diff(range(options.base))));
|
|
52
|
+
const comments = options.comments === undefined ? [] : JSON.parse(readFileSync(resolve(options.repo, options.comments), 'utf8'));
|
|
53
|
+
const previous = previousFindings(comments);
|
|
54
|
+
const rules = `${options.base}:${options.review}`;
|
|
55
|
+
const data = {
|
|
56
|
+
rules,
|
|
57
|
+
range: range(options.base),
|
|
58
|
+
checklist: source,
|
|
59
|
+
fired: fired.map(({ item, at }) => ({ id: item.id, at: at.map(where) })),
|
|
60
|
+
previous: previous !== undefined,
|
|
61
|
+
head: options.head,
|
|
62
|
+
marker: markerFor(options.head),
|
|
63
|
+
};
|
|
64
|
+
data[TEXT] = () => briefText({ rules, rulesText, range: range(options.base), fired, previous, head: options.head });
|
|
65
|
+
return data;
|
|
66
|
+
};
|
|
67
|
+
const readIfThere = (path) => {
|
|
68
|
+
try {
|
|
69
|
+
return readFileSync(path, 'utf8');
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
export const runCompile = (options) => {
|
|
76
|
+
const checklist = parseChecklist(options.checklist, readFileSync(resolve(options.repo, options.checklist), 'utf8'));
|
|
77
|
+
const firings = options.firings === undefined ? {} : JSON.parse(readFileSync(resolve(options.repo, options.firings), 'utf8'));
|
|
78
|
+
const compiled = compile(checklist, options.checklist, options.budget, firings);
|
|
79
|
+
const target = resolve(options.repo, options.out);
|
|
80
|
+
const before = readIfThere(target);
|
|
81
|
+
const stale = before !== compiled.text;
|
|
82
|
+
const base = { out: options.out, rules: checklist.items.length, bytes: compiled.bytes, budget: compiled.budget };
|
|
83
|
+
let data;
|
|
84
|
+
if (compiled.drop.length > 0) {
|
|
85
|
+
data = { ...base, changed: false, drop: compiled.drop, exitCode: ExitCode.RUNTIME, fix: `drop the least-fired rules: ${compiled.drop.join(', ')}` };
|
|
86
|
+
data[TEXT] = () => `${options.out} would be ${String(compiled.bytes)} bytes, over the ${String(compiled.budget)}-byte budget. fix: drop the least-fired rules: ${compiled.drop.join(', ')}`;
|
|
87
|
+
}
|
|
88
|
+
else if (options.check) {
|
|
89
|
+
data = { ...base, changed: false, stale, ...(stale ? { exitCode: ExitCode.RUNTIME, fix: 'run `triggerlist compile` and commit the result' } : {}) };
|
|
90
|
+
data[TEXT] = () => (stale ? `${options.out} is not what the checklist compiles to. fix: run \`triggerlist compile\` and commit the result` : `${options.out} is up to date`);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
if (stale)
|
|
94
|
+
writeFileSync(target, compiled.text);
|
|
95
|
+
data = { ...base, changed: stale };
|
|
96
|
+
data[TEXT] = () => `${stale ? 'wrote' : 'unchanged:'} ${options.out}, ${String(checklist.items.length)} rule(s), ${String(compiled.bytes)} of ${String(compiled.budget)} bytes`;
|
|
97
|
+
}
|
|
98
|
+
return data;
|
|
99
|
+
};
|
|
100
|
+
const sources = (repo, dir, keep) => {
|
|
101
|
+
const full = resolve(repo, dir);
|
|
102
|
+
if (!existsSync(full))
|
|
103
|
+
return [];
|
|
104
|
+
return readdirSync(full)
|
|
105
|
+
.filter(keep)
|
|
106
|
+
.sort()
|
|
107
|
+
.map((name) => ({ path: `${dir}/${name}`, text: readFileSync(join(full, name), 'utf8') }));
|
|
108
|
+
};
|
|
109
|
+
export const runSeed = (options) => {
|
|
110
|
+
const existing = existsSync(resolve(options.repo, options.checklist))
|
|
111
|
+
? new Set(parseChecklist(options.checklist, readFileSync(resolve(options.repo, options.checklist), 'utf8')).items.map((item) => item.id))
|
|
112
|
+
: new Set();
|
|
113
|
+
const items = [
|
|
114
|
+
...sources(options.repo, options.locks, (name) => name.endsWith('-lock.test.ts')).map(fromLockTest),
|
|
115
|
+
...sources(options.repo, options.decisions, (name) => name.endsWith('.md')).map(fromDecision),
|
|
116
|
+
].filter((item) => item !== undefined);
|
|
117
|
+
const fresh = items.filter((item) => !existing.has(item.id));
|
|
118
|
+
const data = { drafted: fresh.length, skipped: items.length - fresh.length, items: fresh };
|
|
119
|
+
data[TEXT] = () => toYaml(fresh, existing);
|
|
120
|
+
return data;
|
|
121
|
+
};
|
|
122
|
+
const repoOption = { type: 'string', default: HERE, description: 'the repository to read (default: the current directory)', placeholder: 'dir' };
|
|
123
|
+
const checklistOption = { type: 'string', default: CHECKLIST, description: 'the checklist file', placeholder: 'path' };
|
|
124
|
+
const worktreeOption = { type: 'boolean', description: 'read the checklist from the working tree, not the base branch (for editing it; never in CI)' };
|
|
125
|
+
const rangeOptions = (args, options) => ({
|
|
126
|
+
repo: options.repo,
|
|
127
|
+
git: gitIn(options.repo),
|
|
128
|
+
base: args.base,
|
|
129
|
+
checklist: options.checklist,
|
|
130
|
+
worktree: options.worktree === true,
|
|
131
|
+
});
|
|
132
|
+
export const program = defineProgram({
|
|
133
|
+
name: 'triggerlist',
|
|
134
|
+
version: VERSION,
|
|
135
|
+
description: 'The review checklist a diff selects, read from the base branch so a change cannot edit its own checks',
|
|
136
|
+
commands: [
|
|
137
|
+
defineCommand({
|
|
138
|
+
name: 'match',
|
|
139
|
+
description: 'The checklist items whose triggers fire on <base>...HEAD, each with where it fired',
|
|
140
|
+
effects: 'read_only',
|
|
141
|
+
examples: [{ command: 'triggerlist match origin/main', description: 'the items a reviewer of this branch answers' }],
|
|
142
|
+
arguments: [{ name: 'base', description: 'the base ref; the checklist is read from it too' }],
|
|
143
|
+
options: { repo: repoOption, checklist: checklistOption, worktree: worktreeOption },
|
|
144
|
+
run: ({ args, options }) => runMatch(rangeOptions(args, options)),
|
|
145
|
+
}),
|
|
146
|
+
defineCommand({
|
|
147
|
+
name: 'brief',
|
|
148
|
+
description: "The reviewer's brief for one round: the base branch's REVIEW.md, the items that fire, the previous round's findings and the commit under review",
|
|
149
|
+
effects: 'read_only',
|
|
150
|
+
examples: [{ command: 'triggerlist brief origin/main --head "$HEAD_SHA" --comments comments.json', description: 'the prompt a CI review step hands its reviewer' }],
|
|
151
|
+
arguments: [{ name: 'base', description: 'the base ref; REVIEW.md and the checklist are read from it' }],
|
|
152
|
+
options: {
|
|
153
|
+
repo: repoOption,
|
|
154
|
+
checklist: checklistOption,
|
|
155
|
+
worktree: worktreeOption,
|
|
156
|
+
review: { type: 'string', default: 'REVIEW.md', description: 'the rules file, read from the base ref', placeholder: 'path' },
|
|
157
|
+
head: { type: 'string', required: true, description: 'the commit under review', placeholder: 'sha' },
|
|
158
|
+
comments: { type: 'string', description: "a JSON file of the pull request's comments, for the previous round's findings", placeholder: 'path' },
|
|
159
|
+
},
|
|
160
|
+
run: ({ args, options }) => runBrief({ ...rangeOptions(args, options), review: options.review, head: options.head, comments: options.comments }),
|
|
161
|
+
}),
|
|
162
|
+
defineCommand({
|
|
163
|
+
name: 'protect',
|
|
164
|
+
description: 'Flag a change that edits a gate file and the code the gates judge together',
|
|
165
|
+
effects: 'read_only',
|
|
166
|
+
examples: [{ command: 'triggerlist protect origin/main --enforce', description: 'fail when a gate and code change together' }],
|
|
167
|
+
arguments: [{ name: 'base', description: 'the base ref; the gate list is read from it too' }],
|
|
168
|
+
options: {
|
|
169
|
+
repo: repoOption,
|
|
170
|
+
checklist: checklistOption,
|
|
171
|
+
worktree: worktreeOption,
|
|
172
|
+
enforce: { type: 'boolean', description: 'exit 1 when flagged (default: observe, report only)' },
|
|
173
|
+
},
|
|
174
|
+
run: ({ args, options }) => runProtect({ ...rangeOptions(args, options), enforce: options.enforce === true }),
|
|
175
|
+
}),
|
|
176
|
+
defineCommand({
|
|
177
|
+
name: 'compile',
|
|
178
|
+
description: 'Write REVIEW.md from the checklist, one line per rule, under a byte budget',
|
|
179
|
+
effects: 'idempotent',
|
|
180
|
+
examples: [
|
|
181
|
+
{ command: 'triggerlist compile', description: 'write REVIEW.md' },
|
|
182
|
+
{ command: 'triggerlist compile --check', description: 'fail when REVIEW.md is stale' },
|
|
183
|
+
],
|
|
184
|
+
options: {
|
|
185
|
+
repo: repoOption,
|
|
186
|
+
checklist: checklistOption,
|
|
187
|
+
out: { type: 'string', default: 'REVIEW.md', description: 'the file to write', placeholder: 'path' },
|
|
188
|
+
budget: { type: 'number', default: DEFAULT_BUDGET, description: 'the most bytes it may be', placeholder: 'bytes' },
|
|
189
|
+
firings: { type: 'string', description: 'a JSON file of firing counts per item id, to choose which rules to drop', placeholder: 'path' },
|
|
190
|
+
check: { type: 'boolean', description: 'write nothing; exit 1 when the file is stale' },
|
|
191
|
+
},
|
|
192
|
+
run: ({ options }) => runCompile({
|
|
193
|
+
repo: options.repo,
|
|
194
|
+
checklist: options.checklist,
|
|
195
|
+
out: options.out,
|
|
196
|
+
budget: options.budget,
|
|
197
|
+
firings: options.firings,
|
|
198
|
+
check: options.check === true,
|
|
199
|
+
}),
|
|
200
|
+
}),
|
|
201
|
+
defineCommand({
|
|
202
|
+
name: 'seed',
|
|
203
|
+
description: 'Draft checklist items from lock-test headers and decision files, printed for a person to edit',
|
|
204
|
+
effects: 'read_only',
|
|
205
|
+
examples: [{ command: 'triggerlist seed > draft.yaml', description: 'draft items to narrow and move into the checklist' }],
|
|
206
|
+
options: {
|
|
207
|
+
repo: repoOption,
|
|
208
|
+
checklist: checklistOption,
|
|
209
|
+
locks: { type: 'string', default: 'scripts', description: 'the folder of *-lock.test.ts files', placeholder: 'dir' },
|
|
210
|
+
decisions: { type: 'string', default: '.sdlc/decisions', description: 'the folder of decision files', placeholder: 'dir' },
|
|
211
|
+
},
|
|
212
|
+
run: ({ options }) => runSeed({ repo: options.repo, checklist: options.checklist, locks: options.locks, decisions: options.decisions }),
|
|
213
|
+
}),
|
|
214
|
+
],
|
|
215
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `REVIEW.md` from the checklist (triggerlist spec R3): one line per rule with a link to why it
|
|
3
|
+
* exists, under a byte budget. Rules past a reviewer's limit drop silently, so over budget is an
|
|
4
|
+
* error that names the rules to drop: the ones that fire least, by the counts `replz` reports.
|
|
5
|
+
*/
|
|
6
|
+
import { type Checklist, type Item } from './checklist.js';
|
|
7
|
+
/** The playbook's measured limit of the review tool this feeds: 150 KB. */
|
|
8
|
+
export declare const DEFAULT_BUDGET = 150000;
|
|
9
|
+
export interface Compiled {
|
|
10
|
+
readonly text: string;
|
|
11
|
+
readonly bytes: number;
|
|
12
|
+
readonly budget: number;
|
|
13
|
+
/** Ids to drop to fit, lowest firing first; empty when it fits. */
|
|
14
|
+
readonly drop: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
export declare const ruleLine: (item: Item) => string;
|
|
17
|
+
export declare const compile: (checklist: Checklist, source: string, budget: number, firings?: Readonly<Record<string, number>>) => Compiled;
|
package/dist/compile.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const DEFAULT_BUDGET = 150_000;
|
|
2
|
+
const bytesOf = (text) => Buffer.byteLength(text);
|
|
3
|
+
export const ruleLine = (item) => `- \`${item.id}\` ${item.question} ([why](${item.sources[0]}))`;
|
|
4
|
+
export const compile = (checklist, source, budget, firings = {}) => {
|
|
5
|
+
const lines = [
|
|
6
|
+
'# REVIEW.md',
|
|
7
|
+
'',
|
|
8
|
+
`Generated by \`triggerlist compile\` from \`${source}\`. Do not edit it by hand: edit the checklist and compile again.`,
|
|
9
|
+
'CI reads this file and the checklist from the base branch, so a pull request is always reviewed by the rules it did not write.',
|
|
10
|
+
'',
|
|
11
|
+
'The reviewer is shown only the rules whose triggers fire on the diff (`triggerlist match <base>`), each with the check that answers it. Every rule:',
|
|
12
|
+
'',
|
|
13
|
+
...checklist.items.map(ruleLine),
|
|
14
|
+
'',
|
|
15
|
+
];
|
|
16
|
+
const text = lines.join('\n');
|
|
17
|
+
const bytes = bytesOf(text);
|
|
18
|
+
const drop = [];
|
|
19
|
+
let excess = bytes - budget;
|
|
20
|
+
const order = checklist.items.map((item, index) => ({ item, index, fired: firings[item.id] ?? 0 })).sort((a, b) => a.fired - b.fired || b.index - a.index);
|
|
21
|
+
for (const { item } of order) {
|
|
22
|
+
if (excess <= 0)
|
|
23
|
+
break;
|
|
24
|
+
drop.push(item.id);
|
|
25
|
+
excess -= bytesOf(`${ruleLine(item)}\n`);
|
|
26
|
+
}
|
|
27
|
+
return { text, bytes, budget, drop };
|
|
28
|
+
};
|
package/dist/diff.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a diff changed, read from `git diff --no-renames -U0` text: each file with the lines it
|
|
3
|
+
* added (numbered in the new file) and removed (numbered in the old one). A deleted file keeps its
|
|
4
|
+
* old path, so a trigger on that path still fires when the file goes away, and a binary or
|
|
5
|
+
* mode-only change is still a changed file, with no lines.
|
|
6
|
+
*/
|
|
7
|
+
export interface Line {
|
|
8
|
+
readonly line: number;
|
|
9
|
+
readonly text: string;
|
|
10
|
+
}
|
|
11
|
+
export interface Changed {
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly added: readonly Line[];
|
|
14
|
+
readonly removed: readonly Line[];
|
|
15
|
+
}
|
|
16
|
+
export declare const parseDiff: (diff: string) => Changed[];
|
package/dist/diff.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const HUNK = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
|
|
2
|
+
const GIT = 'diff --git ';
|
|
3
|
+
const headerPath = (line) => {
|
|
4
|
+
const rest = line.slice(GIT.length);
|
|
5
|
+
const half = (rest.length - ' b/'.length - 'a/'.length) / 2;
|
|
6
|
+
return rest.slice('a/'.length, 'a/'.length + half);
|
|
7
|
+
};
|
|
8
|
+
export const parseDiff = (diff) => {
|
|
9
|
+
const files = [];
|
|
10
|
+
let current;
|
|
11
|
+
let oldLine = 0;
|
|
12
|
+
let newLine = 0;
|
|
13
|
+
for (const raw of diff.split('\n')) {
|
|
14
|
+
if (raw.startsWith(GIT)) {
|
|
15
|
+
current = { path: headerPath(raw), added: [], removed: [], header: true };
|
|
16
|
+
files.push(current);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (current === undefined)
|
|
20
|
+
continue;
|
|
21
|
+
const hunk = HUNK.exec(raw);
|
|
22
|
+
if (hunk !== null) {
|
|
23
|
+
current.header = false;
|
|
24
|
+
oldLine = Number(hunk[1]);
|
|
25
|
+
newLine = Number(hunk[2]);
|
|
26
|
+
}
|
|
27
|
+
else if (!current.header && raw.startsWith('+')) {
|
|
28
|
+
current.added.push({ line: newLine++, text: raw.slice(1) });
|
|
29
|
+
}
|
|
30
|
+
else if (!current.header && raw.startsWith('-')) {
|
|
31
|
+
current.removed.push({ line: oldLine++, text: raw.slice(1) });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return files.map(({ path, added, removed }) => ({ path, added, removed }));
|
|
35
|
+
};
|
package/dist/git.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface Git {
|
|
2
|
+
/** `git diff --no-renames -U0 <range>`. */
|
|
3
|
+
readonly diff: (range: string) => Promise<string>;
|
|
4
|
+
/** The file at `ref`, as `git show <ref>:<path>` prints it. */
|
|
5
|
+
readonly show: (ref: string, path: string) => Promise<string>;
|
|
6
|
+
}
|
|
7
|
+
export declare const gitIn: (cwd: string) => Git;
|
package/dist/git.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ambientRuntime, run } from 'bellpull';
|
|
2
|
+
const git = async (cwd, args) => {
|
|
3
|
+
const result = await run('git', ['-c', 'core.quotePath=false', ...args], { cwd, runtime: ambientRuntime() });
|
|
4
|
+
if (!result.ok)
|
|
5
|
+
throw new Error(`git ${args.join(' ')} failed: ${result.stderr.trim()}. fix: pass a ref this checkout has (fetch it first in CI)`);
|
|
6
|
+
return result.stdout;
|
|
7
|
+
};
|
|
8
|
+
export const gitIn = (cwd) => ({
|
|
9
|
+
diff: (range) => git(cwd, ['diff', '--no-color', '--no-ext-diff', '--no-renames', '-U0', range, '--']),
|
|
10
|
+
show: (ref, path) => git(cwd, ['show', `${ref}:${path}`]),
|
|
11
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { briefText, type Comment, MARKER, markerFor, previousFindings, reviewedHead } from './brief.js';
|
|
2
|
+
export { CHECKLIST, type Checklist, type Item, parseChecklist } from './checklist.js';
|
|
3
|
+
export { compile, type Compiled, DEFAULT_BUDGET } from './compile.js';
|
|
4
|
+
export { type Changed, type Line, parseDiff } from './diff.js';
|
|
5
|
+
export { type Git, gitIn } from './git.js';
|
|
6
|
+
export { type Fired, type Hit, match } from './match.js';
|
|
7
|
+
export { protect, type Protection } from './protect.js';
|
|
8
|
+
export { fromDecision, fromLockTest, toYaml } from './seed.js';
|
|
9
|
+
export { loadChecklist, program, runBrief, runCompile, runMatch, runProtect, runSeed, VERSION } from './cli.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { briefText, MARKER, markerFor, previousFindings, reviewedHead } from './brief.js';
|
|
2
|
+
export { CHECKLIST, parseChecklist } from './checklist.js';
|
|
3
|
+
export { compile, DEFAULT_BUDGET } from './compile.js';
|
|
4
|
+
export { parseDiff } from './diff.js';
|
|
5
|
+
export { gitIn } from './git.js';
|
|
6
|
+
export { match } from './match.js';
|
|
7
|
+
export { protect } from './protect.js';
|
|
8
|
+
export { fromDecision, fromLockTest, toYaml } from './seed.js';
|
|
9
|
+
export { loadChecklist, program, runBrief, runCompile, runMatch, runProtect, runSeed, VERSION } from './cli.js';
|
package/dist/match.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Checklist, type Item } from './checklist.js';
|
|
2
|
+
import { type Changed } from './diff.js';
|
|
3
|
+
export interface Hit {
|
|
4
|
+
readonly file: string;
|
|
5
|
+
/** The line in the new file for an added line, in the old file for a removed one; absent for a file-level hit. */
|
|
6
|
+
readonly line?: number;
|
|
7
|
+
readonly side?: 'added' | 'removed';
|
|
8
|
+
}
|
|
9
|
+
export interface Fired {
|
|
10
|
+
readonly item: Item;
|
|
11
|
+
readonly at: readonly Hit[];
|
|
12
|
+
}
|
|
13
|
+
export declare const matchesAny: (path: string, globs: readonly string[]) => boolean;
|
|
14
|
+
/** The items that fire, in checklist order, each with every place it fired. */
|
|
15
|
+
export declare const match: (checklist: Checklist, files: readonly Changed[]) => Fired[];
|
|
16
|
+
/** How many places a reviewer is shown per item before the rest are counted. */
|
|
17
|
+
export declare const SHOWN = 3;
|
|
18
|
+
export declare const where: (hit: Hit) => string;
|
|
19
|
+
/** The text a reviewer prompt takes: per fired item, its question, its check and where it fired. */
|
|
20
|
+
export declare const toText: (fired: readonly Fired[], range: string) => string;
|
package/dist/match.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { matchesGlob } from 'node:path';
|
|
2
|
+
export const matchesAny = (path, globs) => globs.some((glob) => matchesGlob(path, glob));
|
|
3
|
+
const firstHit = (file) => {
|
|
4
|
+
const added = file.added[0];
|
|
5
|
+
if (added !== undefined)
|
|
6
|
+
return { file: file.path, line: added.line, side: 'added' };
|
|
7
|
+
const removed = file.removed[0];
|
|
8
|
+
if (removed !== undefined)
|
|
9
|
+
return { file: file.path, line: removed.line, side: 'removed' };
|
|
10
|
+
return { file: file.path };
|
|
11
|
+
};
|
|
12
|
+
const hitsIn = (item, file) => {
|
|
13
|
+
const { pattern } = item.trigger;
|
|
14
|
+
if (pattern === undefined)
|
|
15
|
+
return [firstHit(file)];
|
|
16
|
+
const regex = new RegExp(pattern, 'u');
|
|
17
|
+
return [
|
|
18
|
+
...file.added.filter((line) => regex.test(line.text)).map((line) => ({ file: file.path, line: line.line, side: 'added' })),
|
|
19
|
+
...file.removed.filter((line) => regex.test(line.text)).map((line) => ({ file: file.path, line: line.line, side: 'removed' })),
|
|
20
|
+
];
|
|
21
|
+
};
|
|
22
|
+
export const match = (checklist, files) => checklist.items.flatMap((item) => {
|
|
23
|
+
const at = files.filter((file) => matchesAny(file.path, item.trigger.paths)).flatMap((file) => hitsIn(item, file));
|
|
24
|
+
return at.length === 0 ? [] : [{ item, at }];
|
|
25
|
+
});
|
|
26
|
+
export const SHOWN = 3;
|
|
27
|
+
export const where = (hit) => {
|
|
28
|
+
if (hit.line === undefined)
|
|
29
|
+
return hit.file;
|
|
30
|
+
const removed = hit.side === 'removed' ? ' (removed)' : '';
|
|
31
|
+
return `${hit.file}:${String(hit.line)}${removed}`;
|
|
32
|
+
};
|
|
33
|
+
export const toText = (fired, range) => {
|
|
34
|
+
if (fired.length === 0)
|
|
35
|
+
return `no checklist item fires for ${range}`;
|
|
36
|
+
const lines = [`${String(fired.length)} checklist item(s) fire for ${range}:`];
|
|
37
|
+
for (const { item, at } of fired) {
|
|
38
|
+
const more = at.length - SHOWN;
|
|
39
|
+
lines.push('', `${item.id}: ${item.question}`, ` check: ${item.check}`, ` at: ${at.slice(0, SHOWN).map(where).join(', ')}${more > 0 ? ` and ${String(more)} more` : ''}`);
|
|
40
|
+
}
|
|
41
|
+
return lines.join('\n');
|
|
42
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface Protection {
|
|
2
|
+
readonly gates: readonly string[];
|
|
3
|
+
readonly code: readonly string[];
|
|
4
|
+
/** Both kinds changed together. */
|
|
5
|
+
readonly flagged: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const protect: (paths: readonly string[], gates: readonly string[]) => Protection;
|
|
8
|
+
export declare const toText: (protection: Protection, range: string, enforce: boolean) => string;
|
package/dist/protect.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { matchesAny } from './match.js';
|
|
2
|
+
export const protect = (paths, gates) => {
|
|
3
|
+
const gateFiles = paths.filter((path) => matchesAny(path, gates));
|
|
4
|
+
const code = paths.filter((path) => !gateFiles.includes(path));
|
|
5
|
+
return { gates: gateFiles, code, flagged: gateFiles.length > 0 && code.length > 0 };
|
|
6
|
+
};
|
|
7
|
+
export const toText = (protection, range, enforce) => {
|
|
8
|
+
if (!protection.flagged)
|
|
9
|
+
return `${range} does not change a gate together with the code it judges`;
|
|
10
|
+
return [
|
|
11
|
+
`${range} changes ${String(protection.gates.length)} gate file(s) together with ${String(protection.code.length)} other file(s)${enforce ? '' : ' (observe mode: not failing)'}:`,
|
|
12
|
+
...protection.gates.map((path) => ` gate: ${path}`),
|
|
13
|
+
`fix: land the gate change in its own pull request first, so the code is judged by a gate it did not change`,
|
|
14
|
+
].join('\n');
|
|
15
|
+
};
|
package/dist/seed.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Draft checklist items from what the repository already records (triggerlist spec R4): each lock
|
|
3
|
+
* test's header says what broke and what it holds, and each decision file says what was chosen. The
|
|
4
|
+
* draft is printed for a person to edit, never written into the checklist: the trigger globs are
|
|
5
|
+
* `**` until someone narrows them, and a too-wide trigger is the one that fires on every PR.
|
|
6
|
+
*/
|
|
7
|
+
import { type Item } from './checklist.js';
|
|
8
|
+
export interface Source {
|
|
9
|
+
readonly path: string;
|
|
10
|
+
readonly text: string;
|
|
11
|
+
}
|
|
12
|
+
/** A file name as an item id: lowercase, words joined by `-`. */
|
|
13
|
+
export declare const idOf: (name: string) => string;
|
|
14
|
+
/** Each closed `/** … *\/` comment's body, in order. A scan, not a regex: a lazy regex over `/**` is quadratic on a file of unclosed openers. */
|
|
15
|
+
export declare const docComments: (text: string) => string[];
|
|
16
|
+
/** A lock test's header (the first doc comment that is not the licence) as a draft item. */
|
|
17
|
+
export declare const fromLockTest: ({ path, text }: Source) => Item | undefined;
|
|
18
|
+
/** A decision file's `id` and `subject` as a draft item. */
|
|
19
|
+
export declare const fromDecision: ({ path, text }: Source) => Item | undefined;
|
|
20
|
+
/** The draft as YAML the checklist's `items:` takes, skipping ids the checklist already has. */
|
|
21
|
+
export declare const toYaml: (items: readonly Item[], existing: ReadonlySet<string>) => string;
|
package/dist/seed.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const LOCK_PREFIX = /^Lock\s*[—–-]\s*/;
|
|
2
|
+
const FRONTMATTER = /^---\n[\s\S]*?\n---/;
|
|
3
|
+
export const idOf = (name) => name
|
|
4
|
+
.toLowerCase()
|
|
5
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
6
|
+
.replace(/^-|-$/g, '');
|
|
7
|
+
const firstSentence = (comment) => {
|
|
8
|
+
const flat = comment
|
|
9
|
+
.split('\n')
|
|
10
|
+
.map((line) => line.replace(/^\s*\*\s?/, ''))
|
|
11
|
+
.join(' ')
|
|
12
|
+
.replace(/\s+/g, ' ')
|
|
13
|
+
.trim();
|
|
14
|
+
const end = flat.search(/[.!?]\s/);
|
|
15
|
+
return end === -1 ? flat : flat.slice(0, end + 1);
|
|
16
|
+
};
|
|
17
|
+
const OPEN = '/**';
|
|
18
|
+
const CLOSE = '*/';
|
|
19
|
+
export const docComments = (text) => {
|
|
20
|
+
const bodies = [];
|
|
21
|
+
let open = text.indexOf(OPEN);
|
|
22
|
+
while (open !== -1) {
|
|
23
|
+
const close = text.indexOf(CLOSE, open + OPEN.length);
|
|
24
|
+
if (close === -1)
|
|
25
|
+
break;
|
|
26
|
+
bodies.push(text.slice(open + OPEN.length, close));
|
|
27
|
+
open = text.indexOf(OPEN, close + CLOSE.length);
|
|
28
|
+
}
|
|
29
|
+
return bodies;
|
|
30
|
+
};
|
|
31
|
+
export const fromLockTest = ({ path, text }) => {
|
|
32
|
+
const header = docComments(text).find((body) => !body.includes('Copyright'));
|
|
33
|
+
if (header === undefined)
|
|
34
|
+
return undefined;
|
|
35
|
+
const name = path.split('/').pop().slice(0, -'.test.ts'.length);
|
|
36
|
+
return {
|
|
37
|
+
id: idOf(name),
|
|
38
|
+
trigger: { paths: ['**'] },
|
|
39
|
+
question: firstSentence(header).replace(LOCK_PREFIX, ''),
|
|
40
|
+
check: `npx vitest run --config vitest.root.config.ts ${path}`,
|
|
41
|
+
sources: [path],
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const field = (front, key) => {
|
|
45
|
+
const line = front.split('\n').find((candidate) => candidate.startsWith(`${key}:`));
|
|
46
|
+
if (line === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
const value = line.slice(key.length + 1).trim();
|
|
49
|
+
return value.startsWith("'") && value.endsWith("'") ? value.slice(1, -1) : value;
|
|
50
|
+
};
|
|
51
|
+
export const fromDecision = ({ path, text }) => {
|
|
52
|
+
const front = FRONTMATTER.exec(text)?.[0];
|
|
53
|
+
if (front === undefined)
|
|
54
|
+
return undefined;
|
|
55
|
+
const id = field(front, 'id');
|
|
56
|
+
const subject = field(front, 'subject');
|
|
57
|
+
if (id === undefined || subject === undefined)
|
|
58
|
+
return undefined;
|
|
59
|
+
return { id: idOf(id), trigger: { paths: ['**'] }, question: `Does the change respect this decision: ${subject}`, check: `read ${path}`, sources: [path] };
|
|
60
|
+
};
|
|
61
|
+
const quote = (value) => JSON.stringify(value);
|
|
62
|
+
export const toYaml = (items, existing) => {
|
|
63
|
+
const fresh = items.filter((item) => !existing.has(item.id));
|
|
64
|
+
const lines = [`# ${String(fresh.length)} draft item(s) from triggerlist seed. Narrow each trigger before it goes into the checklist.`];
|
|
65
|
+
for (const item of fresh) {
|
|
66
|
+
lines.push(`- id: ${item.id}`, ' trigger:', ` paths: [${item.trigger.paths.map(quote).join(', ')}]`, ` question: ${quote(item.question)}`, ` check: ${quote(item.check)}`, ` sources: [${item.sources.map(quote).join(', ')}]`);
|
|
67
|
+
}
|
|
68
|
+
return lines.join('\n');
|
|
69
|
+
};
|
package/package.json
CHANGED
|
@@ -1 +1,74 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "triggerlist",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Code review checklist that the diff selects: only items whose triggers fire reach the reviewer, REVIEW.md compiles under a byte budget, and rules are read from the base branch. No dependency outside the burgee family. A danger migration path.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"code-review",
|
|
8
|
+
"checklist",
|
|
9
|
+
"ai-review",
|
|
10
|
+
"pull-request",
|
|
11
|
+
"review-rules",
|
|
12
|
+
"diff",
|
|
13
|
+
"ci",
|
|
14
|
+
"cli"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"homepage": "https://burgee.interlace.tools",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/ofri-peretz/burgee.git",
|
|
21
|
+
"directory": "packages/triggerlist"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/ofri-peretz/burgee/issues"
|
|
25
|
+
},
|
|
26
|
+
"author": "Ofri Peretz <ofriperetzdev@gmail.com>",
|
|
27
|
+
"type": "module",
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22.13.0"
|
|
30
|
+
},
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js",
|
|
36
|
+
"default": "./dist/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"bin": {
|
|
41
|
+
"triggerlist": "dist/bin.js"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist",
|
|
45
|
+
"!dist/**/*.map",
|
|
46
|
+
"!dist/**/*.test.*"
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc -p tsconfig.build.json && node ../../scripts/strip-comments.mjs dist && node ../../scripts/declaration-reach.mts --prune",
|
|
50
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"coverage": "vitest run --coverage.enabled",
|
|
53
|
+
"lint": "eslint src"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"bellpull": "^2.0.0",
|
|
57
|
+
"burgee": "^2.0.0",
|
|
58
|
+
"seniority": "^2.0.0",
|
|
59
|
+
"truefit": "^0.2.1"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"vitest": "^5.0.1"
|
|
63
|
+
},
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"access": "public",
|
|
66
|
+
"provenance": true
|
|
67
|
+
},
|
|
68
|
+
"sideEffects": [
|
|
69
|
+
"./dist/bin.js"
|
|
70
|
+
],
|
|
71
|
+
"typesVersions": {
|
|
72
|
+
"*": {}
|
|
73
|
+
}
|
|
74
|
+
}
|