@fullstackhouse/cerber 1.1.0 → 1.2.0-pr.81.58d1702

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 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
- const event = (opts.event ??
214
- (artifact.verdict ? eventForRecommendation(artifact.verdict.recommendation) : "COMMENT")).toUpperCase();
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
- if (opts.poll && d.poll && opts.autoReview && d.autoReview && opts.trust && config.trust.length > 0) {
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.`);
@@ -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
+ }
@@ -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
@@ -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
@@ -186,7 +186,9 @@ export function assembleDiff(files) {
186
186
  * pressed the button, which makes it a review someone is waiting on rather than
187
187
  * work-in-progress to leave alone. Filtering drafts here would be redundant with
188
188
  * 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.
189
+ * daemon config makes: the inbox holds what awaits you, drafts and all. The
190
+ * `author:@me` search keeps them for a plainer reason: your own draft is where
191
+ * a self-review is most worth having, and nothing is drafted there unasked.
190
192
  */
191
193
  export function mapSearchResults(raw) {
192
194
  return raw.flatMap((r) => {
@@ -523,14 +525,24 @@ export async function fetchPriorRemarks(ref, people) {
523
525
  throw new Error(`GitHub returned no pull request for ${ref.owner}/${ref.repo}#${ref.number}`);
524
526
  return priorRemarks({ threads: pr.reviewThreads?.nodes ?? [], reviews: pr.reviews?.nodes ?? [] }, people);
525
527
  }
526
- export function searchAwaitingArgs(repoFilter, limit = 50) {
528
+ /**
529
+ * The two questions the inbox asks GitHub, as `gh search prs` qualifiers.
530
+ *
531
+ * `review-requested` is the inbox proper: PRs somebody is waiting on you for.
532
+ * `author` is your own open PRs, which that search returns only when a team
533
+ * you are on was requested — GitHub will not let anyone request a review from
534
+ * a PR's author — so self-reviewing one would otherwise mean pasting its URL
535
+ * every time. Both are the same search with one flag changed, so they cannot
536
+ * drift apart on what "open" means or which repos are read-only.
537
+ */
538
+ export function searchPrsArgs(search, repoFilter, limit = 50) {
527
539
  const args = [
528
540
  "search",
529
541
  "prs",
530
542
  // An archived repo is read-only: its PRs can never merge, close, or take a
531
543
  // review. Without this they'd sit in the inbox forever — nothing retires them.
532
544
  "archived:false",
533
- "--review-requested=@me",
545
+ `--${search}=@me`,
534
546
  "--state=open",
535
547
  "--limit",
536
548
  String(limit),
@@ -541,11 +553,20 @@ export function searchAwaitingArgs(repoFilter, limit = 50) {
541
553
  args.push("--repo", repoFilter);
542
554
  return args;
543
555
  }
556
+ export const searchAwaitingArgs = (repoFilter, limit = 50) => searchPrsArgs("review-requested", repoFilter, limit);
544
557
  /** Open PRs where the current gh user's review is requested, drafts included. */
545
558
  export async function searchAwaitingMe(repoFilter, limit = 50) {
546
559
  const out = await gh(searchAwaitingArgs(repoFilter, limit));
547
560
  return mapSearchResults(JSON.parse(out));
548
561
  }
562
+ /**
563
+ * Open PRs the current gh user opened, drafts included. They come to the inbox
564
+ * to be reviewed on demand and never automatically — see `isOwnPr` (`own.ts`).
565
+ */
566
+ export async function searchAuthoredByMe(repoFilter, limit = 50) {
567
+ const out = await gh(searchPrsArgs("author", repoFilter, limit));
568
+ return mapSearchResults(JSON.parse(out));
569
+ }
549
570
  /**
550
571
  * Who this repo will let you put on a PR — the list behind the handoff's
551
572
  * suggestions.
@@ -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
  }
@@ -1,20 +1,48 @@
1
1
  import { SCHEMA_VERSION, artifactId, artifactKey } from "../core/artifact.js";
2
2
  import { evaluateAutoSend } from "../core/autosend.js";
3
+ import { anyAutoReview, autoReviewFor, capAutoReview } from "../core/autoreview.js";
3
4
  import { loadConfig } from "../core/config.js";
4
- 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, searchAuthoredByMe, searchAwaitingMe, stillRequested, submitReview, } from "../core/gh.js";
5
6
  import { withWriter } from "../core/history.js";
7
+ import { isOwnPr } from "../core/own.js";
6
8
  import { pendingNews, notice, notify } from "../core/notify.js";
7
9
  import { buildReviewPayload, computeCalibration } from "../core/send.js";
8
10
  import { appendAutoSendLog, deleteArtifact, listArtifacts, loadArtifact, noteHistory, saveArtifact, updateArtifactByKey, } from "../core/state.js";
9
11
  import { ReviewInProgressError } from "../runner/inflight.js";
10
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
+ }
11
32
  /**
12
33
  * A pure discovery stub: enough artifact for the queue to show an awaiting row.
13
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).
14
42
  */
15
- export function stubArtifact(ref) {
43
+ export function stubArtifact(ref, own = false) {
16
44
  const now = new Date().toISOString();
17
- return {
45
+ const stub = {
18
46
  schemaVersion: SCHEMA_VERSION,
19
47
  id: artifactId(ref),
20
48
  status: "awaiting",
@@ -59,6 +87,9 @@ export function stubArtifact(ref) {
59
87
  preChat: null,
60
88
  pendingChat: null,
61
89
  };
90
+ if (own)
91
+ delete stub.notified;
92
+ return stub;
62
93
  }
63
94
  /**
64
95
  * An artifact nothing has touched yet — safe to delete when its PR leaves the
@@ -220,6 +251,7 @@ export function startDaemon(opts) {
220
251
  // keeps its own counsel for the few seconds that takes.
221
252
  notify: false,
222
253
  autoReview: opts.autoReview,
254
+ autoReviewRepos: {},
223
255
  trustedRuns: false,
224
256
  polls: 0,
225
257
  errors: 0,
@@ -240,18 +272,36 @@ export function startDaemon(opts) {
240
272
  /** When GitHub was last asked whether a settled row has been re-requested, by
241
273
  * artifact id. In-memory for the same reason: a restart just asks sooner. */
242
274
  const requestCheckedAt = new Map();
243
- async function discover() {
275
+ /**
276
+ * What GitHub has for you: the PRs awaiting your review, then your own open
277
+ * ones, as one deduplicated list — and whether the second search ran at all
278
+ * (`ownSearched`).
279
+ *
280
+ * Your own PRs are asked for only when cerber knows who you are (`me`). The
281
+ * whole of their special handling — never drafted, never announced, never
282
+ * approved — turns on recognising them, so a poll that could not tell would
283
+ * be better off not bringing them in at all than bringing them in as if
284
+ * somebody had asked. And that search is the optional half: when it fails,
285
+ * the PRs people are waiting on you for still come through, and the poll
286
+ * says what it could not see rather than failing whole. Which search found a
287
+ * PR decides nothing — a team you are on can be requested on your own PR,
288
+ * and `isOwnPr` reads the author either way.
289
+ */
290
+ async function discover(me) {
244
291
  const filters = opts.repos.length > 0 ? opts.repos : [undefined];
245
- const seen = new Set();
246
- return (await Promise.all(filters.map((repo) => searchAwaitingMe(repo))))
247
- .flat()
248
- .filter((r) => {
249
- const id = artifactId(r);
250
- if (seen.has(id))
251
- return false;
252
- seen.add(id);
253
- return true;
254
- });
292
+ const [awaiting, authored] = await Promise.all([
293
+ Promise.all(filters.map((repo) => searchAwaitingMe(repo))),
294
+ me === null
295
+ ? Promise.resolve(null)
296
+ : Promise.all(filters.map((repo) => searchAuthoredByMe(repo))).catch((err) => {
297
+ log(`could not search for your own PRs: ${err instanceof Error ? err.message : String(err)}`);
298
+ return null;
299
+ }),
300
+ ]);
301
+ return {
302
+ refs: dedupeDiscovered([...awaiting.flat(), ...(authored ?? []).flat()]),
303
+ ownSearched: authored !== null,
304
+ };
255
305
  }
256
306
  /**
257
307
  * Make the local queue mirror what's actually awaiting: stub artifacts for
@@ -259,7 +309,7 @@ export function startDaemon(opts) {
259
309
  * request went away. Freshness decisions always come from local artifacts —
260
310
  * search results lag GitHub by minutes and never override them.
261
311
  */
262
- async function syncQueue(refs) {
312
+ async function syncQueue(refs, ownSearched) {
263
313
  const discovered = [];
264
314
  /** Reopen checks spent this poll — the same cap the state refresh below obeys. */
265
315
  let reopenChecks = 0;
@@ -295,6 +345,11 @@ export function startDaemon(opts) {
295
345
  async function reopenIfAskedAgain(artifact) {
296
346
  if (settledAtOf(artifact) === null)
297
347
  return;
348
+ // Nobody can ask you to review your own PR, and a comment naming its
349
+ // author is the conversation of the PR rather than a request for a
350
+ // review — so a skip there stands until you undo it yourself.
351
+ if (isOwnPr(artifact.pr, await who()))
352
+ return;
298
353
  const last = requestCheckedAt.get(artifact.id) ?? 0;
299
354
  if (reopenChecks >= STATE_REFRESH_CAP || Date.now() - last < STATE_REFRESH_MIN_MS)
300
355
  return;
@@ -344,6 +399,8 @@ export function startDaemon(opts) {
344
399
  const me = await who();
345
400
  if (me === null)
346
401
  return;
402
+ if (isOwnPr(artifact.pr, me))
403
+ return;
347
404
  let ask;
348
405
  try {
349
406
  ask = await askedInWords(artifact, me);
@@ -403,7 +460,7 @@ export function startDaemon(opts) {
403
460
  }
404
461
  continue;
405
462
  }
406
- await saveArtifact(stubArtifact(ref));
463
+ await saveArtifact(stubArtifact(ref, isOwnPr(ref, await who())));
407
464
  discovered.push(ref);
408
465
  }
409
466
  /**
@@ -436,6 +493,13 @@ export function startDaemon(opts) {
436
493
  const me = await who();
437
494
  if (me === null)
438
495
  return;
496
+ // Your own PR is never filed. Every reason below reads *you* acting on
497
+ // the PR as an answer to somebody's request, and on your own PR you act
498
+ // all the time — replying to its review threads posts a review of yours —
499
+ // with no request there to answer. It leaves the inbox when it merges or
500
+ // closes, or when you skip it.
501
+ if (isOwnPr(artifact.pr, me))
502
+ return;
439
503
  /** Re-reads from disk: a run or a send may have started in the seconds
440
504
  * these reads took, and neither wants filing out from under it. */
441
505
  async function file(filed, note, stillFilable) {
@@ -500,10 +564,16 @@ export function startDaemon(opts) {
500
564
  await updateArtifactByKey(artifactKey(artifact.id), (a) => ({ ...a, pr }));
501
565
  log(`[${artifact.id}] ${pr.state.toLowerCase()} — archived`);
502
566
  }
503
- else {
567
+ else if (ownSearched || !mightBeYours(artifact, await who())) {
504
568
  await deleteArtifact(artifact.id);
505
569
  log(`[${artifact.id}] no longer awaiting your review — removed from the queue`);
506
570
  }
571
+ // Otherwise this poll could not look for your own PRs, so "not in
572
+ // the results" says nothing about a stub that may be yours: it
573
+ // stays, rather than being dropped and logged as gone only to
574
+ // return next poll. Everybody else's is reaped as before — unless
575
+ // gh cannot say who you are, when any stub may be yours and every
576
+ // one waits for a poll that can tell.
507
577
  }
508
578
  catch {
509
579
  // GitHub unreachable — leave the stub; next poll retries.
@@ -582,9 +652,9 @@ export function startDaemon(opts) {
582
652
  * quiet week would announce that whole week at once — the same reason the
583
653
  * browser bell records what it stays quiet about.
584
654
  */
585
- async function announce(autoReview, tell) {
655
+ async function announce(drafts, tell) {
586
656
  const owed = (await listArtifacts()).flatMap((a) => {
587
- const news = pendingNews(a, autoReview);
657
+ const news = pendingNews(a, drafts(a.pr));
588
658
  return news ? [{ id: a.id, news }] : [];
589
659
  });
590
660
  // `cockpitUrl` is where a click lands, and it is read here rather than
@@ -724,9 +794,13 @@ export function startDaemon(opts) {
724
794
  * The status fields that follow the config, set from it. The poll calls this
725
795
  * with what it just read, and `reconfigure` with what the cockpit just saved.
726
796
  */
727
- function applyKnobs(config) {
797
+ function applyKnobs(config, me = null) {
728
798
  const knobs = config.daemon;
729
- const autoReview = opts.autoReview && knobs.autoReview;
799
+ const autoReview = capAutoReview(knobs, opts.autoReview);
800
+ // Your own PRs are never drafted unasked, whatever auto-review says for
801
+ // their repo: they are in the inbox for a self-review on demand. The same
802
+ // predicate decides when a tap is due, which keeps them quiet there too.
803
+ const drafts = (pr) => !isOwnPr(pr, me) && autoReviewFor(autoReview, pr.owner, pr.repo);
730
804
  status.pollEnabled = knobs.poll;
731
805
  // What the cockpit's bell defers to: a loop that isn't polling announces
732
806
  // nothing, whatever the notify toggle says.
@@ -736,10 +810,11 @@ export function startDaemon(opts) {
736
810
  // should be standing down for.
737
811
  const announcing = () => knobs.poll && notifyOn && notifierWorks !== false;
738
812
  status.notify = announcing();
739
- status.autoReview = autoReview;
813
+ status.autoReview = autoReview.autoReview;
814
+ status.autoReviewRepos = autoReview.autoReviewRepos;
740
815
  // Recomputed too, so a trust rule added mid-run shows up in the strip.
741
- status.trustedRuns = autoReview && opts.trust !== false && config.trust.length > 0;
742
- return { knobs, autoReview, notifyOn, announcing };
816
+ status.trustedRuns = anyAutoReview(autoReview) && opts.trust !== false && config.trust.length > 0;
817
+ return { knobs, drafts, drafting: anyAutoReview(autoReview), notifyOn, announcing };
743
818
  }
744
819
  /** Everything a poll writes is the poll's — including the reviews it starts,
745
820
  * which stamp themselves as runs from inside this. */
@@ -756,7 +831,11 @@ export function startDaemon(opts) {
756
831
  // or the knobs), so a broken file skips the tick loudly instead of
757
832
  // proceeding on guessed defaults.
758
833
  const config = await loadConfig();
759
- const { knobs, autoReview, notifyOn, announcing } = applyKnobs(config);
834
+ // Who you are, asked once per poll (and cached for the process): it is
835
+ // what tells your own PRs apart from the ones awaiting you. Null is "gh
836
+ // could not say", and then no own PR is brought in at all — see `discover`.
837
+ const me = await currentLogin().catch(() => null);
838
+ const { knobs, drafts, drafting, notifyOn, announcing } = applyKnobs(config, me);
760
839
  if (!knobs.poll) {
761
840
  // Deliberately off is not an outage — don't leave a stale error up, or
762
841
  // a list of PRs we are no longer checking are still awaiting you.
@@ -765,21 +844,34 @@ export function startDaemon(opts) {
765
844
  status.lastSummary = "polling off (settings) — the queue only shows what you review by hand";
766
845
  return;
767
846
  }
768
- const refs = await discover();
847
+ const { refs, ownSearched } = await discover(me);
848
+ // Your own PRs are synced into the queue with the rest, but nobody is
849
+ // asking you for them: they are not "awaiting" in anything the strip
850
+ // counts, and the cockpit's open-requests tab — "GitHub still lists you
851
+ // as a requested reviewer" — must never name one.
852
+ const asked = refs.filter((r) => !isOwnPr(r, me));
853
+ const yours = refs.length - asked.length;
854
+ const ownPart = yours > 0 ? `, ${yours} of your own` : "";
769
855
  status.lastPollError = null;
770
856
  // The same refs behind lastSummary's count, so the number the strip shows
771
857
  // and the rows the cockpit can name always come from one answer.
772
858
  // A failed poll leaves the last good list up; lastPollError says so.
773
- status.awaiting = await classifyAll(refs);
774
- const { discovered } = await syncQueue(refs);
775
- if (autoReview) {
776
- const { reviewed, skipped, failed } = await reviewAll(refs);
859
+ status.awaiting = await classifyAll(asked);
860
+ const { discovered } = await syncQueue(refs, ownSearched);
861
+ if (drafting) {
862
+ // A repo excepted from auto-review is discovered like any other — it
863
+ // is in the queue above — and only its run waits for the click. So is
864
+ // your own PR, in every repo.
865
+ const toDraft = asked.filter(drafts);
866
+ const onClick = asked.length - toDraft.length;
867
+ const { reviewed, skipped, failed } = await reviewAll(toDraft);
777
868
  status.lastSummary =
778
- `${refs.length} awaiting; ${reviewed} reviewed, ${skipped} up to date` +
779
- `${failed > 0 ? `, ${failed} failed` : ""}`;
869
+ `${asked.length} awaiting; ${reviewed} reviewed, ${skipped} up to date` +
870
+ `${failed > 0 ? `, ${failed} failed` : ""}` +
871
+ `${onClick > 0 ? `, ${onClick} waiting for a click` : ""}${ownPart}`;
780
872
  }
781
873
  else {
782
- status.lastSummary = `${refs.length} awaiting${discovered.length > 0 ? `, ${discovered.length} new` : ""} (auto-review off)`;
874
+ status.lastSummary = `${asked.length} awaiting${discovered.length > 0 ? `, ${discovered.length} new` : ""}${ownPart} (auto-review off)`;
783
875
  }
784
876
  // After the drafting, not before it. The arrival is not the news when
785
877
  // cerber is about to write the review itself: a tap that lands on "no run
@@ -788,7 +880,7 @@ export function startDaemon(opts) {
788
880
  // for the draft — and for a PR nobody is drafting (auto-review off, or a
789
881
  // run that failed) it goes out here all the same. `isNews` is the rule,
790
882
  // and the cockpit's bell reads the same one.
791
- await announce(autoReview, notifyOn);
883
+ await announce(drafts, notifyOn);
792
884
  // Recomputed on the spot rather than left to the next poll: that is
793
885
  // minutes away, and the cockpit would spend them deferring to a tap that
794
886
  // never came. Recomputed rather than only cleared, so a machine whose
@@ -812,7 +904,7 @@ export function startDaemon(opts) {
812
904
  }
813
905
  }
814
906
  async function handleAutoSend(artifact) {
815
- const decision = evaluateAutoSend(artifact, opts.autoSendThreshold);
907
+ const decision = evaluateAutoSend(artifact, opts.autoSendThreshold, await currentLogin().catch(() => null));
816
908
  if (decision.eligible)
817
909
  status.autoSendCandidates++;
818
910
  const entryBase = {