@fullstackhouse/cerber 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/cli/index.js +11 -4
- package/dist/core/artifact.js +7 -0
- package/dist/core/autosend.js +13 -1
- package/dist/core/config.js +7 -0
- package/dist/core/gh.js +41 -4
- package/dist/core/own.js +20 -0
- package/dist/core/send.js +21 -0
- package/dist/server/daemon.js +132 -32
- package/dist/server/index.js +42 -2
- package/package.json +1 -1
- package/web/dist/assets/index-B3z-3n2K.js +250 -0
- package/web/dist/assets/index-CiBfeOoU.css +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-CHF4kBTR.js +0 -250
- package/web/dist/assets/index-DPt1TcJ6.css +0 -1
package/README.md
CHANGED
|
@@ -157,6 +157,17 @@ ones you marked reviewed or skipped, merged and closed PRs — each tab appearin
|
|
|
157
157
|
only while it holds something. PRs in archived repos are never picked up at
|
|
158
158
|
all, since the repo is read-only and a review could never be sent.
|
|
159
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. PRs of yours idle for more than 30 days stay out
|
|
169
|
+
(`daemon.ownPrMaxAgeDays`; 0 turns that off).
|
|
170
|
+
|
|
160
171
|
### Settled means you settled it
|
|
161
172
|
|
|
162
173
|
Settling a review is your decision, not GitHub's: skip a PR, or mark one
|
package/dist/cli/index.js
CHANGED
|
@@ -10,8 +10,8 @@ import { configPath, loadConfig, saveConfig } from "../core/config.js";
|
|
|
10
10
|
import { formatBlockers, isBlocking, preflight } from "../core/preflight.js";
|
|
11
11
|
import { withWriter } from "../core/history.js";
|
|
12
12
|
import { TrustRuleError, describeRule, explainRule, parseTrustRule } from "../core/trust.js";
|
|
13
|
-
import { parsePrRef, postReplies, searchAwaitingMe, submitReview } from "../core/gh.js";
|
|
14
|
-
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";
|
|
15
15
|
import { cerberHome, listArtifacts, loadArtifact, readAutoSendLog, reconcileRunning, updateArtifactByKey, } from "../core/state.js";
|
|
16
16
|
import { pool, reviewPr } from "../runner/review.js";
|
|
17
17
|
import { isReviewRunning } from "../runner/inflight.js";
|
|
@@ -211,12 +211,19 @@ program
|
|
|
211
211
|
`If nothing is running, restart \`cerber serve\`, which clears a check that died mid-flight.`);
|
|
212
212
|
process.exit(1);
|
|
213
213
|
}
|
|
214
|
-
|
|
215
|
-
|
|
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();
|
|
216
218
|
if (!["APPROVE", "COMMENT", "REQUEST_CHANGES"].includes(event)) {
|
|
217
219
|
console.error(`Invalid event: ${event}`);
|
|
218
220
|
process.exit(1);
|
|
219
221
|
}
|
|
222
|
+
const refusal = ownPrRefusal(artifact.pr, event, me);
|
|
223
|
+
if (refusal) {
|
|
224
|
+
console.error(`Not sent: ${refusal}.`);
|
|
225
|
+
process.exit(1);
|
|
226
|
+
}
|
|
220
227
|
const payload = buildReviewPayload(artifact, event);
|
|
221
228
|
console.log(`About to send to ${artifact.pr.url}:`);
|
|
222
229
|
// Said before anything else about the payload: on a PR you have already
|
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
|
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
|
@@ -53,6 +53,13 @@ export const DaemonConfigSchema = z.object({
|
|
|
53
53
|
parallel: z.number().int().positive().default(3),
|
|
54
54
|
/** Repos to watch (owner/repo). Empty = everything your gh account can see. */
|
|
55
55
|
repos: z.array(z.string()).default([]),
|
|
56
|
+
/**
|
|
57
|
+
* Your own PRs with no activity for longer than this many days are left out
|
|
58
|
+
* of the inbox — applied in the author search itself (`updated:>=`), so they
|
|
59
|
+
* never arrive and never take a slot of its 50. 0 or null turns the cut off.
|
|
60
|
+
* Your own PRs only: a review somebody asked you for is never aged out.
|
|
61
|
+
*/
|
|
62
|
+
ownPrMaxAgeDays: z.number().int().nonnegative().nullable().default(30),
|
|
56
63
|
});
|
|
57
64
|
export const ConfigSchema = z.object({
|
|
58
65
|
/** Whose PRs may be reviewed by running code. See core/trust.ts for syntax. */
|
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,26 @@ 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, updatedSince = null) {
|
|
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
|
+
// Only the author search is ever given one (`ownPrUpdatedSince`).
|
|
547
|
+
...(updatedSince ? [`updated:>=${updatedSince}`] : []),
|
|
548
|
+
`--${search}=@me`,
|
|
534
549
|
"--state=open",
|
|
535
550
|
"--limit",
|
|
536
551
|
String(limit),
|
|
@@ -541,11 +556,33 @@ export function searchAwaitingArgs(repoFilter, limit = 50) {
|
|
|
541
556
|
args.push("--repo", repoFilter);
|
|
542
557
|
return args;
|
|
543
558
|
}
|
|
559
|
+
export const searchAwaitingArgs = (repoFilter, limit = 50) => searchPrsArgs("review-requested", repoFilter, limit);
|
|
544
560
|
/** Open PRs where the current gh user's review is requested, drafts included. */
|
|
545
561
|
export async function searchAwaitingMe(repoFilter, limit = 50) {
|
|
546
562
|
const out = await gh(searchAwaitingArgs(repoFilter, limit));
|
|
547
563
|
return mapSearchResults(JSON.parse(out));
|
|
548
564
|
}
|
|
565
|
+
/**
|
|
566
|
+
* Open PRs the current gh user opened, drafts included. They come to the inbox
|
|
567
|
+
* to be reviewed on demand and never automatically — see `isOwnPr` (`own.ts`).
|
|
568
|
+
*/
|
|
569
|
+
export async function searchAuthoredByMe(repoFilter, updatedSince = null, limit = 50) {
|
|
570
|
+
const out = await gh(searchPrsArgs("author", repoFilter, limit, updatedSince));
|
|
571
|
+
return mapSearchResults(JSON.parse(out));
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* The day your own PRs must have been active on or after to come into the
|
|
575
|
+
* inbox (`daemon.ownPrMaxAgeDays`), as GitHub's `updated:>=` reads it — or null
|
|
576
|
+
* for no cut. A PR of yours nobody has touched in months is not one you are
|
|
577
|
+
* about to self-review, and fifty of them would fill the search's whole page.
|
|
578
|
+
* A calendar day in UTC: GitHub's qualifier takes a date, and a day either way
|
|
579
|
+
* at the edge changes nothing anyone would notice.
|
|
580
|
+
*/
|
|
581
|
+
export function ownPrUpdatedSince(days, now = new Date()) {
|
|
582
|
+
if (!days)
|
|
583
|
+
return null;
|
|
584
|
+
return new Date(now.getTime() - days * 86_400_000).toISOString().slice(0, 10);
|
|
585
|
+
}
|
|
549
586
|
/**
|
|
550
587
|
* Who this repo will let you put on a PR — the list behind the handoff's
|
|
551
588
|
* 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
|
}
|
package/dist/server/daemon.js
CHANGED
|
@@ -2,20 +2,47 @@ import { SCHEMA_VERSION, artifactId, artifactKey } from "../core/artifact.js";
|
|
|
2
2
|
import { evaluateAutoSend } from "../core/autosend.js";
|
|
3
3
|
import { anyAutoReview, autoReviewFor, capAutoReview } from "../core/autoreview.js";
|
|
4
4
|
import { loadConfig } from "../core/config.js";
|
|
5
|
-
import { classifyReply, currentLogin, fetchConversation, fetchLastReviewRequest, fetchOwnReview, fetchPrInfo, fetchReviewRequests, lastMentionOfYou, lastWordOfYours, searchAwaitingMe, stillRequested, submitReview, } from "../core/gh.js";
|
|
5
|
+
import { classifyReply, currentLogin, fetchConversation, fetchLastReviewRequest, fetchOwnReview, fetchPrInfo, fetchReviewRequests, lastMentionOfYou, lastWordOfYours, ownPrUpdatedSince, searchAuthoredByMe, searchAwaitingMe, stillRequested, submitReview, } from "../core/gh.js";
|
|
6
6
|
import { withWriter } from "../core/history.js";
|
|
7
|
+
import { isOwnPr } from "../core/own.js";
|
|
7
8
|
import { pendingNews, notice, notify } from "../core/notify.js";
|
|
8
9
|
import { buildReviewPayload, computeCalibration } from "../core/send.js";
|
|
9
10
|
import { appendAutoSendLog, deleteArtifact, listArtifacts, loadArtifact, noteHistory, saveArtifact, updateArtifactByKey, } from "../core/state.js";
|
|
10
11
|
import { ReviewInProgressError } from "../runner/inflight.js";
|
|
11
12
|
import { SETTLED_BY_YOU, pool, reviewPr } from "../runner/review.js";
|
|
13
|
+
/**
|
|
14
|
+
* Whether a row could be one of your own PRs: it is, or cerber cannot tell
|
|
15
|
+
* because gh would not say who you are.
|
|
16
|
+
*/
|
|
17
|
+
export const mightBeYours = (a, me) => me === null || isOwnPr(a.pr, me);
|
|
18
|
+
/**
|
|
19
|
+
* The poll's searches as one list: first occurrence wins, so the order the
|
|
20
|
+
* searches are passed in is the order of precedence.
|
|
21
|
+
*/
|
|
22
|
+
export function dedupeDiscovered(refs) {
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
return refs.filter((r) => {
|
|
25
|
+
const id = artifactId(r);
|
|
26
|
+
if (seen.has(id))
|
|
27
|
+
return false;
|
|
28
|
+
seen.add(id);
|
|
29
|
+
return true;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
12
32
|
/**
|
|
13
33
|
* A pure discovery stub: enough artifact for the queue to show an awaiting row.
|
|
14
34
|
* The AI run that follows (automatic or clicked) replaces it wholesale.
|
|
35
|
+
*
|
|
36
|
+
* `own` is a PR you opened yourself. It gets no `notified` ledger at all —
|
|
37
|
+
* absent, which is "nobody meant to announce this row" — because nobody is
|
|
38
|
+
* waiting on you for it: it is in the inbox so you can ask for a self-review
|
|
39
|
+
* when you want one, not to call you back to the cockpit. Both bells read the
|
|
40
|
+
* ledger, so this one omission keeps the machine's tap and the browser's quiet
|
|
41
|
+
* about it, now and after you ask for a draft (the run carries the ledger over).
|
|
15
42
|
*/
|
|
16
|
-
export function stubArtifact(ref) {
|
|
43
|
+
export function stubArtifact(ref, own = false) {
|
|
17
44
|
const now = new Date().toISOString();
|
|
18
|
-
|
|
45
|
+
const stub = {
|
|
19
46
|
schemaVersion: SCHEMA_VERSION,
|
|
20
47
|
id: artifactId(ref),
|
|
21
48
|
status: "awaiting",
|
|
@@ -34,6 +61,7 @@ export function stubArtifact(ref) {
|
|
|
34
61
|
headSha: "",
|
|
35
62
|
state: "OPEN",
|
|
36
63
|
isDraft: ref.isDraft,
|
|
64
|
+
updatedAt: ref.updatedAt,
|
|
37
65
|
additions: 0,
|
|
38
66
|
deletions: 0,
|
|
39
67
|
changedFiles: 0,
|
|
@@ -60,6 +88,9 @@ export function stubArtifact(ref) {
|
|
|
60
88
|
preChat: null,
|
|
61
89
|
pendingChat: null,
|
|
62
90
|
};
|
|
91
|
+
if (own)
|
|
92
|
+
delete stub.notified;
|
|
93
|
+
return stub;
|
|
63
94
|
}
|
|
64
95
|
/**
|
|
65
96
|
* An artifact nothing has touched yet — safe to delete when its PR leaves the
|
|
@@ -242,18 +273,40 @@ export function startDaemon(opts) {
|
|
|
242
273
|
/** When GitHub was last asked whether a settled row has been re-requested, by
|
|
243
274
|
* artifact id. In-memory for the same reason: a restart just asks sooner. */
|
|
244
275
|
const requestCheckedAt = new Map();
|
|
245
|
-
|
|
276
|
+
/**
|
|
277
|
+
* What GitHub has for you: the PRs awaiting your review, then your own open
|
|
278
|
+
* ones, as one deduplicated list — and whether the second search ran at all
|
|
279
|
+
* (`ownSearched`).
|
|
280
|
+
*
|
|
281
|
+
* Your own PRs are asked for only when cerber knows who you are (`me`). The
|
|
282
|
+
* whole of their special handling — never drafted, never announced, never
|
|
283
|
+
* approved — turns on recognising them, so a poll that could not tell would
|
|
284
|
+
* be better off not bringing them in at all than bringing them in as if
|
|
285
|
+
* somebody had asked. And that search is the optional half: when it fails,
|
|
286
|
+
* the PRs people are waiting on you for still come through, and the poll
|
|
287
|
+
* says what it could not see rather than failing whole. Which search found a
|
|
288
|
+
* PR decides nothing — a team you are on can be requested on your own PR,
|
|
289
|
+
* and `isOwnPr` reads the author either way.
|
|
290
|
+
*/
|
|
291
|
+
async function discover(me, ownPrMaxAgeDays) {
|
|
246
292
|
const filters = opts.repos.length > 0 ? opts.repos : [undefined];
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
293
|
+
// Your own PRs only: a review request is never aged out. One that went
|
|
294
|
+
// stale leaves the search, and the reaper below drops its stub like any
|
|
295
|
+
// other the search stopped returning — a draft of yours stays put.
|
|
296
|
+
const since = ownPrUpdatedSince(ownPrMaxAgeDays);
|
|
297
|
+
const [awaiting, authored] = await Promise.all([
|
|
298
|
+
Promise.all(filters.map((repo) => searchAwaitingMe(repo))),
|
|
299
|
+
me === null
|
|
300
|
+
? Promise.resolve(null)
|
|
301
|
+
: Promise.all(filters.map((repo) => searchAuthoredByMe(repo, since))).catch((err) => {
|
|
302
|
+
log(`could not search for your own PRs: ${err instanceof Error ? err.message : String(err)}`);
|
|
303
|
+
return null;
|
|
304
|
+
}),
|
|
305
|
+
]);
|
|
306
|
+
return {
|
|
307
|
+
refs: dedupeDiscovered([...awaiting.flat(), ...(authored ?? []).flat()]),
|
|
308
|
+
ownSearched: authored !== null,
|
|
309
|
+
};
|
|
257
310
|
}
|
|
258
311
|
/**
|
|
259
312
|
* Make the local queue mirror what's actually awaiting: stub artifacts for
|
|
@@ -261,7 +314,7 @@ export function startDaemon(opts) {
|
|
|
261
314
|
* request went away. Freshness decisions always come from local artifacts —
|
|
262
315
|
* search results lag GitHub by minutes and never override them.
|
|
263
316
|
*/
|
|
264
|
-
async function syncQueue(refs) {
|
|
317
|
+
async function syncQueue(refs, ownSearched) {
|
|
265
318
|
const discovered = [];
|
|
266
319
|
/** Reopen checks spent this poll — the same cap the state refresh below obeys. */
|
|
267
320
|
let reopenChecks = 0;
|
|
@@ -297,6 +350,11 @@ export function startDaemon(opts) {
|
|
|
297
350
|
async function reopenIfAskedAgain(artifact) {
|
|
298
351
|
if (settledAtOf(artifact) === null)
|
|
299
352
|
return;
|
|
353
|
+
// Nobody can ask you to review your own PR, and a comment naming its
|
|
354
|
+
// author is the conversation of the PR rather than a request for a
|
|
355
|
+
// review — so a skip there stands until you undo it yourself.
|
|
356
|
+
if (isOwnPr(artifact.pr, await who()))
|
|
357
|
+
return;
|
|
300
358
|
const last = requestCheckedAt.get(artifact.id) ?? 0;
|
|
301
359
|
if (reopenChecks >= STATE_REFRESH_CAP || Date.now() - last < STATE_REFRESH_MIN_MS)
|
|
302
360
|
return;
|
|
@@ -346,6 +404,8 @@ export function startDaemon(opts) {
|
|
|
346
404
|
const me = await who();
|
|
347
405
|
if (me === null)
|
|
348
406
|
return;
|
|
407
|
+
if (isOwnPr(artifact.pr, me))
|
|
408
|
+
return;
|
|
349
409
|
let ask;
|
|
350
410
|
try {
|
|
351
411
|
ask = await askedInWords(artifact, me);
|
|
@@ -397,15 +457,27 @@ export function startDaemon(opts) {
|
|
|
397
457
|
// predate a draft→ready flip. Refresh from it — it costs nothing, it's
|
|
398
458
|
// already in hand — or the queue keeps calling a ready PR a draft until
|
|
399
459
|
// something happens to re-review it.
|
|
400
|
-
|
|
460
|
+
//
|
|
461
|
+
// The PR's last activity is refreshed only on a row nobody has drafted,
|
|
462
|
+
// the one place the queue reads it (`activityAt`). Every write bumps the
|
|
463
|
+
// artifact's own `updatedAt`, and on a drafted row that is the review's
|
|
464
|
+
// date: refreshing there would re-date every draft by the poll each time
|
|
465
|
+
// its PR saw a comment, which is the meaningless date this field exists
|
|
466
|
+
// to replace — and would race an open review's refresh besides.
|
|
467
|
+
const activity = existing.status === "awaiting" && existing.pr.updatedAt !== ref.updatedAt;
|
|
468
|
+
if (existing.pr.isDraft !== ref.isDraft || activity) {
|
|
401
469
|
await updateArtifactByKey(artifactKey(existing.id), (a) => ({
|
|
402
470
|
...a,
|
|
403
|
-
pr: {
|
|
471
|
+
pr: {
|
|
472
|
+
...a.pr,
|
|
473
|
+
isDraft: ref.isDraft,
|
|
474
|
+
updatedAt: a.status === "awaiting" ? ref.updatedAt : a.pr.updatedAt,
|
|
475
|
+
},
|
|
404
476
|
}));
|
|
405
477
|
}
|
|
406
478
|
continue;
|
|
407
479
|
}
|
|
408
|
-
await saveArtifact(stubArtifact(ref));
|
|
480
|
+
await saveArtifact(stubArtifact(ref, isOwnPr(ref, await who())));
|
|
409
481
|
discovered.push(ref);
|
|
410
482
|
}
|
|
411
483
|
/**
|
|
@@ -438,6 +510,13 @@ export function startDaemon(opts) {
|
|
|
438
510
|
const me = await who();
|
|
439
511
|
if (me === null)
|
|
440
512
|
return;
|
|
513
|
+
// Your own PR is never filed. Every reason below reads *you* acting on
|
|
514
|
+
// the PR as an answer to somebody's request, and on your own PR you act
|
|
515
|
+
// all the time — replying to its review threads posts a review of yours —
|
|
516
|
+
// with no request there to answer. It leaves the inbox when it merges or
|
|
517
|
+
// closes, or when you skip it.
|
|
518
|
+
if (isOwnPr(artifact.pr, me))
|
|
519
|
+
return;
|
|
441
520
|
/** Re-reads from disk: a run or a send may have started in the seconds
|
|
442
521
|
* these reads took, and neither wants filing out from under it. */
|
|
443
522
|
async function file(filed, note, stillFilable) {
|
|
@@ -502,10 +581,16 @@ export function startDaemon(opts) {
|
|
|
502
581
|
await updateArtifactByKey(artifactKey(artifact.id), (a) => ({ ...a, pr }));
|
|
503
582
|
log(`[${artifact.id}] ${pr.state.toLowerCase()} — archived`);
|
|
504
583
|
}
|
|
505
|
-
else {
|
|
584
|
+
else if (ownSearched || !mightBeYours(artifact, await who())) {
|
|
506
585
|
await deleteArtifact(artifact.id);
|
|
507
586
|
log(`[${artifact.id}] no longer awaiting your review — removed from the queue`);
|
|
508
587
|
}
|
|
588
|
+
// Otherwise this poll could not look for your own PRs, so "not in
|
|
589
|
+
// the results" says nothing about a stub that may be yours: it
|
|
590
|
+
// stays, rather than being dropped and logged as gone only to
|
|
591
|
+
// return next poll. Everybody else's is reaped as before — unless
|
|
592
|
+
// gh cannot say who you are, when any stub may be yours and every
|
|
593
|
+
// one waits for a poll that can tell.
|
|
509
594
|
}
|
|
510
595
|
catch {
|
|
511
596
|
// GitHub unreachable — leave the stub; next poll retries.
|
|
@@ -726,10 +811,13 @@ export function startDaemon(opts) {
|
|
|
726
811
|
* The status fields that follow the config, set from it. The poll calls this
|
|
727
812
|
* with what it just read, and `reconfigure` with what the cockpit just saved.
|
|
728
813
|
*/
|
|
729
|
-
function applyKnobs(config) {
|
|
814
|
+
function applyKnobs(config, me = null) {
|
|
730
815
|
const knobs = config.daemon;
|
|
731
816
|
const autoReview = capAutoReview(knobs, opts.autoReview);
|
|
732
|
-
|
|
817
|
+
// Your own PRs are never drafted unasked, whatever auto-review says for
|
|
818
|
+
// their repo: they are in the inbox for a self-review on demand. The same
|
|
819
|
+
// predicate decides when a tap is due, which keeps them quiet there too.
|
|
820
|
+
const drafts = (pr) => !isOwnPr(pr, me) && autoReviewFor(autoReview, pr.owner, pr.repo);
|
|
733
821
|
status.pollEnabled = knobs.poll;
|
|
734
822
|
// What the cockpit's bell defers to: a loop that isn't polling announces
|
|
735
823
|
// nothing, whatever the notify toggle says.
|
|
@@ -760,7 +848,11 @@ export function startDaemon(opts) {
|
|
|
760
848
|
// or the knobs), so a broken file skips the tick loudly instead of
|
|
761
849
|
// proceeding on guessed defaults.
|
|
762
850
|
const config = await loadConfig();
|
|
763
|
-
|
|
851
|
+
// Who you are, asked once per poll (and cached for the process): it is
|
|
852
|
+
// what tells your own PRs apart from the ones awaiting you. Null is "gh
|
|
853
|
+
// could not say", and then no own PR is brought in at all — see `discover`.
|
|
854
|
+
const me = await currentLogin().catch(() => null);
|
|
855
|
+
const { knobs, drafts, drafting, notifyOn, announcing } = applyKnobs(config, me);
|
|
764
856
|
if (!knobs.poll) {
|
|
765
857
|
// Deliberately off is not an outage — don't leave a stale error up, or
|
|
766
858
|
// a list of PRs we are no longer checking are still awaiting you.
|
|
@@ -769,26 +861,34 @@ export function startDaemon(opts) {
|
|
|
769
861
|
status.lastSummary = "polling off (settings) — the queue only shows what you review by hand";
|
|
770
862
|
return;
|
|
771
863
|
}
|
|
772
|
-
const refs = await discover();
|
|
864
|
+
const { refs, ownSearched } = await discover(me, knobs.ownPrMaxAgeDays);
|
|
865
|
+
// Your own PRs are synced into the queue with the rest, but nobody is
|
|
866
|
+
// asking you for them: they are not "awaiting" in anything the strip
|
|
867
|
+
// counts, and the cockpit's open-requests tab — "GitHub still lists you
|
|
868
|
+
// as a requested reviewer" — must never name one.
|
|
869
|
+
const asked = refs.filter((r) => !isOwnPr(r, me));
|
|
870
|
+
const yours = refs.length - asked.length;
|
|
871
|
+
const ownPart = yours > 0 ? `, ${yours} of your own` : "";
|
|
773
872
|
status.lastPollError = null;
|
|
774
873
|
// The same refs behind lastSummary's count, so the number the strip shows
|
|
775
874
|
// and the rows the cockpit can name always come from one answer.
|
|
776
875
|
// A failed poll leaves the last good list up; lastPollError says so.
|
|
777
|
-
status.awaiting = await classifyAll(
|
|
778
|
-
const { discovered } = await syncQueue(refs);
|
|
876
|
+
status.awaiting = await classifyAll(asked);
|
|
877
|
+
const { discovered } = await syncQueue(refs, ownSearched);
|
|
779
878
|
if (drafting) {
|
|
780
879
|
// A repo excepted from auto-review is discovered like any other — it
|
|
781
|
-
// is in the queue above — and only its run waits for the click.
|
|
782
|
-
|
|
783
|
-
const
|
|
880
|
+
// is in the queue above — and only its run waits for the click. So is
|
|
881
|
+
// your own PR, in every repo.
|
|
882
|
+
const toDraft = asked.filter(drafts);
|
|
883
|
+
const onClick = asked.length - toDraft.length;
|
|
784
884
|
const { reviewed, skipped, failed } = await reviewAll(toDraft);
|
|
785
885
|
status.lastSummary =
|
|
786
|
-
`${
|
|
886
|
+
`${asked.length} awaiting; ${reviewed} reviewed, ${skipped} up to date` +
|
|
787
887
|
`${failed > 0 ? `, ${failed} failed` : ""}` +
|
|
788
|
-
`${onClick > 0 ? `, ${onClick} waiting for a click` : ""}`;
|
|
888
|
+
`${onClick > 0 ? `, ${onClick} waiting for a click` : ""}${ownPart}`;
|
|
789
889
|
}
|
|
790
890
|
else {
|
|
791
|
-
status.lastSummary = `${
|
|
891
|
+
status.lastSummary = `${asked.length} awaiting${discovered.length > 0 ? `, ${discovered.length} new` : ""}${ownPart} (auto-review off)`;
|
|
792
892
|
}
|
|
793
893
|
// After the drafting, not before it. The arrival is not the news when
|
|
794
894
|
// cerber is about to write the review itself: a tap that lands on "no run
|
|
@@ -821,7 +921,7 @@ export function startDaemon(opts) {
|
|
|
821
921
|
}
|
|
822
922
|
}
|
|
823
923
|
async function handleAutoSend(artifact) {
|
|
824
|
-
const decision = evaluateAutoSend(artifact, opts.autoSendThreshold);
|
|
924
|
+
const decision = evaluateAutoSend(artifact, opts.autoSendThreshold, await currentLogin().catch(() => null));
|
|
825
925
|
if (decision.eligible)
|
|
826
926
|
status.autoSendCandidates++;
|
|
827
927
|
const entryBase = {
|
package/dist/server/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import { randomUUID } from "node:crypto";
|
|
|
9
9
|
import { isPureStub } from "./daemon.js";
|
|
10
10
|
import { ArtifactStatusSchema, SCHEMA_VERSION, SeveritySchema, VerdictSchema, artifactId, artifactKey, } from "../core/artifact.js";
|
|
11
11
|
import { toMarkdown } from "../core/export.js";
|
|
12
|
+
import { isOwnPr } from "../core/own.js";
|
|
12
13
|
import { currentLogin, fetchAssignableUsers, fetchPrDiff, fetchPrInfo, handOffReview, parsePrRef, postIssueComment, postReplies, submitReview, } from "../core/gh.js";
|
|
13
14
|
import { z } from "zod";
|
|
14
15
|
import { setException } from "../core/autoreview.js";
|
|
@@ -17,7 +18,7 @@ import { version } from "../core/version.js";
|
|
|
17
18
|
import { refreshArtifact, userOwnsStatus } from "../core/refresh.js";
|
|
18
19
|
import { withWriter } from "../core/history.js";
|
|
19
20
|
import { TrustRuleError, describeRule, explainRule, parseTrustRule } from "../core/trust.js";
|
|
20
|
-
import { buildReviewPayload, computeCalibration, describeReplyFailures, recordReplies, } from "../core/send.js";
|
|
21
|
+
import { buildReviewPayload, computeCalibration, describeReplyFailures, ownPrRefusal, recordReplies, } from "../core/send.js";
|
|
21
22
|
import { raisedChanged, rewriteFinding, startRaisedCheck } from "../core/raised.js";
|
|
22
23
|
import { checkAlreadyRaised, claimRaisedCheck, finishRaisedCheck, isRaisedCheckRunning, prepareRaisedCheck, releaseRaisedCheck, } from "../runner/raised.js";
|
|
23
24
|
import { listArtifacts, loadArtifact, loadArtifactByKey, noteHistory, saveArtifact, updateArtifactByKey, } from "../core/state.js";
|
|
@@ -33,6 +34,25 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
33
34
|
* own decision about a PR. Everything else is a fact some other path owns.
|
|
34
35
|
*/
|
|
35
36
|
const SETTLEABLE = ["reviewed", "skipped"];
|
|
37
|
+
/** How long a read of local state waits on `gh` to say who you are (`loginWithin`). */
|
|
38
|
+
const LOGIN_WAIT_MS = 1500;
|
|
39
|
+
/**
|
|
40
|
+
* The login, if `gh` can say within `ms`, else null — for reads that must not
|
|
41
|
+
* wait on GitHub, like the cockpit's queue list. A slow answer is not lost: the
|
|
42
|
+
* call it raced keeps going, and once it lands the cache answers instantly.
|
|
43
|
+
*/
|
|
44
|
+
function loginWithin(ms) {
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
const timer = setTimeout(() => resolve(null), ms);
|
|
47
|
+
currentLogin().then((login) => {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
resolve(login);
|
|
50
|
+
}, () => {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
resolve(null);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
36
56
|
/** What the user may decide about a finding somebody else already raised. */
|
|
37
57
|
const RaisedDecisionSchema = z.enum(["send", "reply"]).nullable();
|
|
38
58
|
/**
|
|
@@ -242,6 +262,10 @@ export async function buildApp(opts) {
|
|
|
242
262
|
});
|
|
243
263
|
app.get("/api/reviews", async (c) => {
|
|
244
264
|
const artifacts = await listArtifacts();
|
|
265
|
+
// Cached for the process after the first answer. The list is local state
|
|
266
|
+
// and must not hang on GitHub: a gh that cannot say in time marks nothing
|
|
267
|
+
// as yours, and Send's own guard still refuses what GitHub would.
|
|
268
|
+
const me = await loginWithin(LOGIN_WAIT_MS);
|
|
245
269
|
return c.json(artifacts.map((a) => ({
|
|
246
270
|
id: a.id,
|
|
247
271
|
key: artifactKey(a.id),
|
|
@@ -256,6 +280,9 @@ export async function buildApp(opts) {
|
|
|
256
280
|
number: a.pr.number,
|
|
257
281
|
state: a.pr.state,
|
|
258
282
|
isDraft: a.pr.isDraft,
|
|
283
|
+
// When the PR itself last changed — what an undrafted row is dated
|
|
284
|
+
// and sorted by in the queue (`activityAt`).
|
|
285
|
+
updatedAt: a.pr.updatedAt,
|
|
259
286
|
additions: a.pr.additions,
|
|
260
287
|
deletions: a.pr.deletions,
|
|
261
288
|
changedFiles: a.pr.changedFiles,
|
|
@@ -279,6 +306,9 @@ export async function buildApp(opts) {
|
|
|
279
306
|
// rows the daemon deliberately stays silent about, and the two bells
|
|
280
307
|
// would stop telling one story.
|
|
281
308
|
announceable: a.notified !== undefined,
|
|
309
|
+
// A PR you opened: listed apart from the ones awaiting you, and sent
|
|
310
|
+
// as a comment only (`ownPrRefusal`).
|
|
311
|
+
own: isOwnPr(a.pr, me),
|
|
282
312
|
costUsd: a.run?.costUsd ?? null,
|
|
283
313
|
withSource: a.run?.withSource ?? null,
|
|
284
314
|
trusted: a.run?.trusted ?? null,
|
|
@@ -428,7 +458,9 @@ export async function buildApp(opts) {
|
|
|
428
458
|
const artifact = await loadArtifactByKey(c.req.param("key"));
|
|
429
459
|
if (!artifact)
|
|
430
460
|
return c.json({ error: "not found" }, 404);
|
|
431
|
-
|
|
461
|
+
// `own` rides along so the review page knows what Send may post without
|
|
462
|
+
// depending on the queue list having loaded (§9.10).
|
|
463
|
+
return c.json({ ...artifact, own: isOwnPr(artifact.pr, await loginWithin(LOGIN_WAIT_MS)) });
|
|
432
464
|
});
|
|
433
465
|
// ---- Mutations (all local — artifact edits only) ----
|
|
434
466
|
app.patch("/api/reviews/:key", async (c) => {
|
|
@@ -904,6 +936,14 @@ export async function buildApp(opts) {
|
|
|
904
936
|
if (artifact.sent) {
|
|
905
937
|
return c.json({ error: `already sent at ${artifact.sent.at}` }, 409);
|
|
906
938
|
}
|
|
939
|
+
// Only a comment on your own PR. The cockpit offers nothing else there, so
|
|
940
|
+
// this is for a stale tab or a direct call; the login is only asked for
|
|
941
|
+
// when the event could be refused.
|
|
942
|
+
if (event !== "COMMENT") {
|
|
943
|
+
const refusal = ownPrRefusal(artifact.pr, event, await currentLogin().catch(() => null));
|
|
944
|
+
if (refusal)
|
|
945
|
+
return c.json({ error: refusal }, 400);
|
|
946
|
+
}
|
|
907
947
|
// Not while a run is rewriting this draft. Vouching for a review that is
|
|
908
948
|
// being replaced under you is reason enough on its own; on top of that the
|
|
909
949
|
// run used to save `sent: null` back over the record when it landed, so the
|