@fullstackhouse/cerber 1.1.0 → 1.2.0-pr.81.aa49442
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 +14 -2
- package/dist/cli/index.js +15 -6
- package/dist/core/artifact.js +7 -0
- package/dist/core/autoreview.js +33 -0
- package/dist/core/autosend.js +13 -1
- package/dist/core/config.js +20 -0
- package/dist/core/gh.js +26 -4
- package/dist/core/own.js +20 -0
- package/dist/core/send.js +21 -0
- package/dist/server/daemon.js +142 -37
- package/dist/server/index.js +78 -2
- package/package.json +1 -1
- package/web/dist/assets/index-Dy9jXHNd.js +250 -0
- package/web/dist/assets/index-JYCx7Rxo.css +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-DHoDGlFy.css +0 -1
- package/web/dist/assets/index-Di8xS2Ft.js +0 -250
package/README.md
CHANGED
|
@@ -86,7 +86,9 @@ npx @fullstackhouse/cerber list
|
|
|
86
86
|
Sending stays a human click. Tame it with `--no-auto-review` (list awaiting
|
|
87
87
|
PRs, review on click) or `--no-poll` (no GitHub polling at all) — or flip those
|
|
88
88
|
switches in the cockpit's Settings, which persist in `~/.cerber/config.json`
|
|
89
|
-
and apply on the next poll.
|
|
89
|
+
and apply on the next poll. Settings also takes per-repo exceptions
|
|
90
|
+
(`daemon.autoReviewRepos`): keep a busy repo to the click while the rest are
|
|
91
|
+
drafted, or draft one repo with auto-review otherwise off.
|
|
90
92
|
|
|
91
93
|
## Contents
|
|
92
94
|
|
|
@@ -155,6 +157,16 @@ ones you marked reviewed or skipped, merged and closed PRs — each tab appearin
|
|
|
155
157
|
only while it holds something. PRs in archived repos are never picked up at
|
|
156
158
|
all, since the repo is read-only and a review could never be sent.
|
|
157
159
|
|
|
160
|
+
### Your own PRs
|
|
161
|
+
|
|
162
|
+
Your own open PRs are in the inbox too, under **your PRs** below the ones
|
|
163
|
+
awaiting you — GitHub never asks you to review them, so they would otherwise
|
|
164
|
+
need their URL pasted every time. Cerber never drafts one on its own and never
|
|
165
|
+
taps you about one: press `r` when you want a self-review. Send posts it as a
|
|
166
|
+
comment, since GitHub takes no approve or change request from a PR's author,
|
|
167
|
+
and auto-send leaves it alone. Skip one to hide it; it leaves for good once it
|
|
168
|
+
merges or closes.
|
|
169
|
+
|
|
158
170
|
### Settled means you settled it
|
|
159
171
|
|
|
160
172
|
Settling a review is your decision, not GitHub's: skip a PR, or mark one
|
|
@@ -200,7 +212,7 @@ into one popup when several land at once. Ready means *there is something to
|
|
|
200
212
|
read*: cerber drafts the review itself, so the tap waits for the draft and says
|
|
201
213
|
what it found — "widgets#7 draft ready · requests changes · 2 blockers" — rather
|
|
202
214
|
than walking you back to a row that says "no run yet". A PR nobody is going to
|
|
203
|
-
draft (auto-review off, or a run that failed) is announced as it arrives, since
|
|
215
|
+
draft (auto-review off for its repo, or a run that failed) is announced as it arrives, since
|
|
204
216
|
that is all the news there will be — and if a retry drafts it after all, that is
|
|
205
217
|
new news and you are told. Nothing else is: a PR whose draft you have been told
|
|
206
218
|
about stays quiet however its next re-review ends. The tap comes from the poll, so it reaches
|
package/dist/cli/index.js
CHANGED
|
@@ -5,12 +5,13 @@ import readline from "node:readline/promises";
|
|
|
5
5
|
import { artifactId, artifactKey } from "../core/artifact.js";
|
|
6
6
|
import { listCheckouts, removeCheckout } from "../core/checkout.js";
|
|
7
7
|
import { toMarkdown } from "../core/export.js";
|
|
8
|
+
import { anyAutoReview, capAutoReview } from "../core/autoreview.js";
|
|
8
9
|
import { configPath, loadConfig, saveConfig } from "../core/config.js";
|
|
9
10
|
import { formatBlockers, isBlocking, preflight } from "../core/preflight.js";
|
|
10
11
|
import { withWriter } from "../core/history.js";
|
|
11
12
|
import { TrustRuleError, describeRule, explainRule, parseTrustRule } from "../core/trust.js";
|
|
12
|
-
import { parsePrRef, postReplies, searchAwaitingMe, submitReview } from "../core/gh.js";
|
|
13
|
-
import { buildReviewPayload, computeCalibration, describeReplyFailures, eventForRecommendation, recordReplies, } from "../core/send.js";
|
|
13
|
+
import { currentLogin, parsePrRef, postReplies, searchAwaitingMe, submitReview } from "../core/gh.js";
|
|
14
|
+
import { buildReviewPayload, computeCalibration, defaultSendEvent, describeReplyFailures, eventForRecommendation, ownPrRefusal, recordReplies, } from "../core/send.js";
|
|
14
15
|
import { cerberHome, listArtifacts, loadArtifact, readAutoSendLog, reconcileRunning, updateArtifactByKey, } from "../core/state.js";
|
|
15
16
|
import { pool, reviewPr } from "../runner/review.js";
|
|
16
17
|
import { isReviewRunning } from "../runner/inflight.js";
|
|
@@ -210,12 +211,19 @@ program
|
|
|
210
211
|
`If nothing is running, restart \`cerber serve\`, which clears a check that died mid-flight.`);
|
|
211
212
|
process.exit(1);
|
|
212
213
|
}
|
|
213
|
-
|
|
214
|
-
|
|
214
|
+
// Your own PR defaults to a comment, the one event GitHub takes from its
|
|
215
|
+
// author — the same rule the cockpit's send button follows.
|
|
216
|
+
const me = await currentLogin().catch(() => null);
|
|
217
|
+
const event = (opts.event ?? defaultSendEvent(artifact, me)).toUpperCase();
|
|
215
218
|
if (!["APPROVE", "COMMENT", "REQUEST_CHANGES"].includes(event)) {
|
|
216
219
|
console.error(`Invalid event: ${event}`);
|
|
217
220
|
process.exit(1);
|
|
218
221
|
}
|
|
222
|
+
const refusal = ownPrRefusal(artifact.pr, event, me);
|
|
223
|
+
if (refusal) {
|
|
224
|
+
console.error(`Not sent: ${refusal}.`);
|
|
225
|
+
process.exit(1);
|
|
226
|
+
}
|
|
219
227
|
const payload = buildReviewPayload(artifact, event);
|
|
220
228
|
console.log(`About to send to ${artifact.pr.url}:`);
|
|
221
229
|
// Said before anything else about the payload: on a PR you have already
|
|
@@ -446,7 +454,7 @@ program
|
|
|
446
454
|
.option("-H, --host <host>", "host to bind (0.0.0.0 for VPS — requires --token)", "127.0.0.1")
|
|
447
455
|
.option("-t, --token <token>", "require this token on every request (env: CERBER_TOKEN)")
|
|
448
456
|
.option("--no-poll", "don't poll GitHub for PRs awaiting your review (also disables auto-review)")
|
|
449
|
-
.option("--no-auto-review", "list awaiting PRs but don't review them until you click review")
|
|
457
|
+
.option("--no-auto-review", "list awaiting PRs but don't review them until you click review (per-repo exceptions included)")
|
|
450
458
|
.option("--no-notify", "don't notify this machine when a review is ready for you")
|
|
451
459
|
.option("-d, --daemon", "(deprecated no-op — polling and auto-review are now the default)")
|
|
452
460
|
.option("-i, --interval <minutes>", "poll interval (default: config daemon.intervalMinutes, 5)")
|
|
@@ -484,7 +492,8 @@ program
|
|
|
484
492
|
const d = config.daemon;
|
|
485
493
|
// Trust means "run this PR's code". A human clicking review accepted that
|
|
486
494
|
// per PR; auto-review does it unattended, on whatever lands in the queue.
|
|
487
|
-
|
|
495
|
+
const drafting = anyAutoReview(capAutoReview(d, opts.autoReview));
|
|
496
|
+
if (opts.poll && d.poll && drafting && opts.trust && config.trust.length > 0) {
|
|
488
497
|
console.log(`⚠ ${config.trust.length} trust rule(s) in ${configPath()}: unattended reviews will run commands from ` +
|
|
489
498
|
`matching PRs, with nobody watching. Pass --no-trust to keep every review read-only, ` +
|
|
490
499
|
`or --no-auto-review to only review on click.`);
|
package/dist/core/artifact.js
CHANGED
|
@@ -148,6 +148,13 @@ export const PrInfoSchema = z.object({
|
|
|
148
148
|
additions: z.number().int().default(0),
|
|
149
149
|
deletions: z.number().int().default(0),
|
|
150
150
|
changedFiles: z.number().int().default(0),
|
|
151
|
+
/**
|
|
152
|
+
* When the PR itself last changed on GitHub — not when cerber last wrote this
|
|
153
|
+
* file. On a row nobody has drafted, `updatedAt` is only when the poll found
|
|
154
|
+
* it, so this is what the queue shows and sorts by there. Optional: artifacts
|
|
155
|
+
* written before it existed load without it, and the poll fills it in.
|
|
156
|
+
*/
|
|
157
|
+
updatedAt: z.string().optional(),
|
|
151
158
|
});
|
|
152
159
|
export const ArtifactStatusSchema = z.enum([
|
|
153
160
|
"awaiting", // discovered, not yet reviewed by AI
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function autoReviewFor(knobs, owner, repo) {
|
|
2
|
+
const want = `${owner}/${repo}`.toLowerCase();
|
|
3
|
+
for (const [key, on] of Object.entries(knobs.autoReviewRepos)) {
|
|
4
|
+
if (key.toLowerCase() === want)
|
|
5
|
+
return on;
|
|
6
|
+
}
|
|
7
|
+
return knobs.autoReview;
|
|
8
|
+
}
|
|
9
|
+
/** Whether any repo at all is drafted unattended — what the trust warning and
|
|
10
|
+
* the strip's `trustedRuns` are about. */
|
|
11
|
+
export function anyAutoReview(knobs) {
|
|
12
|
+
return knobs.autoReview || Object.values(knobs.autoReviewRepos).some(Boolean);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* What a process actually drafts: `--no-auto-review` caps the default and the
|
|
16
|
+
* exceptions alike, so the flag means "this process starts no AI runs" and the
|
|
17
|
+
* trust warning's advice to pass it holds. A `true` exception still outranks
|
|
18
|
+
* the config's own `autoReview: false` — never the flag.
|
|
19
|
+
*/
|
|
20
|
+
export function capAutoReview(knobs, flag) {
|
|
21
|
+
return flag ? knobs : { autoReview: false, autoReviewRepos: {} };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* One exception set (`true`/`false`) or removed (`null`), the rest left as they
|
|
25
|
+
* are. Any spelling of the same repo is replaced rather than kept beside it,
|
|
26
|
+
* since the match ignores case. One repo per write, so an edit made from a stale
|
|
27
|
+
* view can't take a concurrent one with it.
|
|
28
|
+
*/
|
|
29
|
+
export function setException(repos, repo, on) {
|
|
30
|
+
const want = repo.toLowerCase();
|
|
31
|
+
const rest = Object.fromEntries(Object.entries(repos).filter(([k]) => k.toLowerCase() !== want));
|
|
32
|
+
return on === null ? rest : { ...rest, [repo]: on };
|
|
33
|
+
}
|
package/dist/core/autosend.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isOwnPr } from "./own.js";
|
|
1
2
|
import { sendTreatment } from "./raised.js";
|
|
2
3
|
/**
|
|
3
4
|
* Auto-send policy — deliberately narrow:
|
|
@@ -9,10 +10,21 @@ import { sendTreatment } from "./raised.js";
|
|
|
9
10
|
* there to decide, and the default is the side that posts less. A reply into
|
|
10
11
|
* someone's thread is never auto-sent — that is a decision only a person makes,
|
|
11
12
|
* and auto-send posts one review and nothing else.
|
|
13
|
+
*
|
|
14
|
+
* Never on your own PR. GitHub refuses an approve from a PR's author, and the
|
|
15
|
+
* poll never drafts one of yours to begin with — this is the line that holds
|
|
16
|
+
* if anything ever does. `login` is who you are; null is "gh could not say",
|
|
17
|
+
* and a post nobody is watching does not go out on a guess.
|
|
12
18
|
*/
|
|
13
|
-
export function evaluateAutoSend(artifact, threshold) {
|
|
19
|
+
export function evaluateAutoSend(artifact, threshold, login) {
|
|
14
20
|
if (artifact.sent)
|
|
15
21
|
return { eligible: false, reason: "already sent" };
|
|
22
|
+
if (login === null) {
|
|
23
|
+
return { eligible: false, reason: "could not ask gh who you are, so whether this PR is your own is unknown" };
|
|
24
|
+
}
|
|
25
|
+
if (isOwnPr(artifact.pr, login)) {
|
|
26
|
+
return { eligible: false, reason: "this is your own PR — GitHub takes no approve from its author" };
|
|
27
|
+
}
|
|
16
28
|
// The same rule, for a send a re-review has since superseded. `sent` only
|
|
17
29
|
// ever describes the draft on the row, so once one moves to `priorSends`
|
|
18
30
|
// that guard stops seeing it — and "never a re-send" would quietly come to
|
package/dist/core/config.js
CHANGED
|
@@ -22,6 +22,26 @@ export const DaemonConfigSchema = z.object({
|
|
|
22
22
|
poll: z.boolean().default(true),
|
|
23
23
|
/** Draft an AI review for whatever lands in the queue. Never sends. */
|
|
24
24
|
autoReview: z.boolean().default(true),
|
|
25
|
+
/**
|
|
26
|
+
* Per-repo exceptions to `autoReview`, either way: `false` leaves that repo's
|
|
27
|
+
* PRs waiting for a click, `true` drafts them even with `autoReview` off.
|
|
28
|
+
* Resolved by `autoReviewFor` in core/autoreview.ts.
|
|
29
|
+
*/
|
|
30
|
+
autoReviewRepos: z
|
|
31
|
+
.record(z.string().regex(/^[\w.-]+\/[\w.-]+$/, "expected owner/repo"), z.boolean())
|
|
32
|
+
// The match ignores case, so two spellings of one repo would leave the
|
|
33
|
+
// answer to key order — refused, like any other key that can't mean one thing.
|
|
34
|
+
.superRefine((repos, ctx) => {
|
|
35
|
+
const seen = new Map();
|
|
36
|
+
for (const key of Object.keys(repos)) {
|
|
37
|
+
const first = seen.get(key.toLowerCase());
|
|
38
|
+
if (first !== undefined)
|
|
39
|
+
ctx.addIssue({ code: "custom", path: [key], message: `same repo as ${first}` });
|
|
40
|
+
else
|
|
41
|
+
seen.set(key.toLowerCase(), key);
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
.default({}),
|
|
25
45
|
/**
|
|
26
46
|
* Tap this machine's notification centre when a PR is worth coming back for
|
|
27
47
|
* — the draft landing, or the arrival itself when nothing is going to be
|
package/dist/core/gh.js
CHANGED
|
@@ -45,7 +45,7 @@ export async function fetchPrInfo(ref) {
|
|
|
45
45
|
"--repo",
|
|
46
46
|
`${ref.owner}/${ref.repo}`,
|
|
47
47
|
"--json",
|
|
48
|
-
"title,url,author,body,baseRefName,headRefName,headRefOid,additions,deletions,changedFiles,state,isDraft",
|
|
48
|
+
"title,url,author,body,baseRefName,headRefName,headRefOid,additions,deletions,changedFiles,state,isDraft,updatedAt",
|
|
49
49
|
]);
|
|
50
50
|
const raw = JSON.parse(out);
|
|
51
51
|
return PrInfoSchema.parse({
|
|
@@ -64,6 +64,7 @@ export async function fetchPrInfo(ref) {
|
|
|
64
64
|
additions: raw.additions ?? 0,
|
|
65
65
|
deletions: raw.deletions ?? 0,
|
|
66
66
|
changedFiles: raw.changedFiles ?? 0,
|
|
67
|
+
updatedAt: raw.updatedAt ?? undefined,
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
@@ -186,7 +187,9 @@ export function assembleDiff(files) {
|
|
|
186
187
|
* pressed the button, which makes it a review someone is waiting on rather than
|
|
187
188
|
* work-in-progress to leave alone. Filtering drafts here would be redundant with
|
|
188
189
|
* a stronger filter that already ran, and it would contradict the promise the
|
|
189
|
-
* daemon config makes: the inbox holds what awaits you, drafts and all.
|
|
190
|
+
* daemon config makes: the inbox holds what awaits you, drafts and all. The
|
|
191
|
+
* `author:@me` search keeps them for a plainer reason: your own draft is where
|
|
192
|
+
* a self-review is most worth having, and nothing is drafted there unasked.
|
|
190
193
|
*/
|
|
191
194
|
export function mapSearchResults(raw) {
|
|
192
195
|
return raw.flatMap((r) => {
|
|
@@ -523,14 +526,24 @@ export async function fetchPriorRemarks(ref, people) {
|
|
|
523
526
|
throw new Error(`GitHub returned no pull request for ${ref.owner}/${ref.repo}#${ref.number}`);
|
|
524
527
|
return priorRemarks({ threads: pr.reviewThreads?.nodes ?? [], reviews: pr.reviews?.nodes ?? [] }, people);
|
|
525
528
|
}
|
|
526
|
-
|
|
529
|
+
/**
|
|
530
|
+
* The two questions the inbox asks GitHub, as `gh search prs` qualifiers.
|
|
531
|
+
*
|
|
532
|
+
* `review-requested` is the inbox proper: PRs somebody is waiting on you for.
|
|
533
|
+
* `author` is your own open PRs, which that search returns only when a team
|
|
534
|
+
* you are on was requested — GitHub will not let anyone request a review from
|
|
535
|
+
* a PR's author — so self-reviewing one would otherwise mean pasting its URL
|
|
536
|
+
* every time. Both are the same search with one flag changed, so they cannot
|
|
537
|
+
* drift apart on what "open" means or which repos are read-only.
|
|
538
|
+
*/
|
|
539
|
+
export function searchPrsArgs(search, repoFilter, limit = 50) {
|
|
527
540
|
const args = [
|
|
528
541
|
"search",
|
|
529
542
|
"prs",
|
|
530
543
|
// An archived repo is read-only: its PRs can never merge, close, or take a
|
|
531
544
|
// review. Without this they'd sit in the inbox forever — nothing retires them.
|
|
532
545
|
"archived:false",
|
|
533
|
-
|
|
546
|
+
`--${search}=@me`,
|
|
534
547
|
"--state=open",
|
|
535
548
|
"--limit",
|
|
536
549
|
String(limit),
|
|
@@ -541,11 +554,20 @@ export function searchAwaitingArgs(repoFilter, limit = 50) {
|
|
|
541
554
|
args.push("--repo", repoFilter);
|
|
542
555
|
return args;
|
|
543
556
|
}
|
|
557
|
+
export const searchAwaitingArgs = (repoFilter, limit = 50) => searchPrsArgs("review-requested", repoFilter, limit);
|
|
544
558
|
/** Open PRs where the current gh user's review is requested, drafts included. */
|
|
545
559
|
export async function searchAwaitingMe(repoFilter, limit = 50) {
|
|
546
560
|
const out = await gh(searchAwaitingArgs(repoFilter, limit));
|
|
547
561
|
return mapSearchResults(JSON.parse(out));
|
|
548
562
|
}
|
|
563
|
+
/**
|
|
564
|
+
* Open PRs the current gh user opened, drafts included. They come to the inbox
|
|
565
|
+
* to be reviewed on demand and never automatically — see `isOwnPr` (`own.ts`).
|
|
566
|
+
*/
|
|
567
|
+
export async function searchAuthoredByMe(repoFilter, limit = 50) {
|
|
568
|
+
const out = await gh(searchPrsArgs("author", repoFilter, limit));
|
|
569
|
+
return mapSearchResults(JSON.parse(out));
|
|
570
|
+
}
|
|
549
571
|
/**
|
|
550
572
|
* Who this repo will let you put on a PR — the list behind the handoff's
|
|
551
573
|
* suggestions.
|
package/dist/core/own.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Your own PRs — the one test for "is this PR yours", kept free of imports so
|
|
2
|
+
// the cockpit's bundle can share it with the server without pulling in `gh`.
|
|
3
|
+
/**
|
|
4
|
+
* Whether this PR is one you opened yourself.
|
|
5
|
+
*
|
|
6
|
+
* The one test for it, used by everything that treats your own PRs
|
|
7
|
+
* differently: the poll never drafts or announces one, auto-send never fires on
|
|
8
|
+
* one, Send refuses an approve or a change request on one (GitHub refuses both
|
|
9
|
+
* from the author anyway), and the cockpit lists them apart from the PRs
|
|
10
|
+
* somebody is waiting on you for. Derived from the PR's author rather than
|
|
11
|
+
* stored, so there is no field to drift out of step with GitHub.
|
|
12
|
+
*
|
|
13
|
+
* A login nobody could fetch claims nothing (false), and so does an author the
|
|
14
|
+
* row never recorded. GitHub logins are case-insensitive.
|
|
15
|
+
*/
|
|
16
|
+
export function isOwnPr(pr, login) {
|
|
17
|
+
if (!login || !pr.author)
|
|
18
|
+
return false;
|
|
19
|
+
return pr.author.toLowerCase() === login.toLowerCase();
|
|
20
|
+
}
|
package/dist/core/send.js
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
|
+
import { isOwnPr } from "./own.js";
|
|
1
2
|
import { newSideLines } from "./diff.js";
|
|
2
3
|
import { sendTreatment } from "./raised.js";
|
|
3
4
|
import { withGrade } from "./severity.js";
|
|
4
5
|
export function eventForRecommendation(rec) {
|
|
5
6
|
return { approve: "APPROVE", comment: "COMMENT", request_changes: "REQUEST_CHANGES" }[rec];
|
|
6
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Why Send refuses this event on this PR, or null when it may go.
|
|
10
|
+
*
|
|
11
|
+
* Your own PR takes a comment and nothing else: GitHub refuses an approve or a
|
|
12
|
+
* change request from a PR's author, and GitHub's error after the click is a
|
|
13
|
+
* worse place to learn that than here.
|
|
14
|
+
* A login nobody could fetch refuses nothing; GitHub is still the last word.
|
|
15
|
+
*/
|
|
16
|
+
export function ownPrRefusal(pr, event, login) {
|
|
17
|
+
if (event === "COMMENT" || !isOwnPr(pr, login))
|
|
18
|
+
return null;
|
|
19
|
+
const what = event === "APPROVE" ? "an approve" : "a change request";
|
|
20
|
+
return `this is your own PR, and GitHub takes no ${what} from its author — send it as a comment`;
|
|
21
|
+
}
|
|
22
|
+
/** What Send posts by default: the verdict's event, except on your own PR. */
|
|
23
|
+
export function defaultSendEvent(artifact, login) {
|
|
24
|
+
if (isOwnPr(artifact.pr, login))
|
|
25
|
+
return "COMMENT";
|
|
26
|
+
return artifact.verdict ? eventForRecommendation(artifact.verdict.recommendation) : "COMMENT";
|
|
27
|
+
}
|
|
7
28
|
function graded(c) {
|
|
8
29
|
return withGrade(c.body, c.severity);
|
|
9
30
|
}
|