@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/dist/server/daemon.js
CHANGED
|
@@ -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
|
-
|
|
45
|
+
const stub = {
|
|
18
46
|
schemaVersion: SCHEMA_VERSION,
|
|
19
47
|
id: artifactId(ref),
|
|
20
48
|
status: "awaiting",
|
|
@@ -33,6 +61,7 @@ export function stubArtifact(ref) {
|
|
|
33
61
|
headSha: "",
|
|
34
62
|
state: "OPEN",
|
|
35
63
|
isDraft: ref.isDraft,
|
|
64
|
+
updatedAt: ref.updatedAt,
|
|
36
65
|
additions: 0,
|
|
37
66
|
deletions: 0,
|
|
38
67
|
changedFiles: 0,
|
|
@@ -59,6 +88,9 @@ export function stubArtifact(ref) {
|
|
|
59
88
|
preChat: null,
|
|
60
89
|
pendingChat: null,
|
|
61
90
|
};
|
|
91
|
+
if (own)
|
|
92
|
+
delete stub.notified;
|
|
93
|
+
return stub;
|
|
62
94
|
}
|
|
63
95
|
/**
|
|
64
96
|
* An artifact nothing has touched yet — safe to delete when its PR leaves the
|
|
@@ -220,6 +252,7 @@ export function startDaemon(opts) {
|
|
|
220
252
|
// keeps its own counsel for the few seconds that takes.
|
|
221
253
|
notify: false,
|
|
222
254
|
autoReview: opts.autoReview,
|
|
255
|
+
autoReviewRepos: {},
|
|
223
256
|
trustedRuns: false,
|
|
224
257
|
polls: 0,
|
|
225
258
|
errors: 0,
|
|
@@ -240,18 +273,36 @@ export function startDaemon(opts) {
|
|
|
240
273
|
/** When GitHub was last asked whether a settled row has been re-requested, by
|
|
241
274
|
* artifact id. In-memory for the same reason: a restart just asks sooner. */
|
|
242
275
|
const requestCheckedAt = new Map();
|
|
243
|
-
|
|
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) {
|
|
244
292
|
const filters = opts.repos.length > 0 ? opts.repos : [undefined];
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
293
|
+
const [awaiting, authored] = await Promise.all([
|
|
294
|
+
Promise.all(filters.map((repo) => searchAwaitingMe(repo))),
|
|
295
|
+
me === null
|
|
296
|
+
? Promise.resolve(null)
|
|
297
|
+
: Promise.all(filters.map((repo) => searchAuthoredByMe(repo))).catch((err) => {
|
|
298
|
+
log(`could not search for your own PRs: ${err instanceof Error ? err.message : String(err)}`);
|
|
299
|
+
return null;
|
|
300
|
+
}),
|
|
301
|
+
]);
|
|
302
|
+
return {
|
|
303
|
+
refs: dedupeDiscovered([...awaiting.flat(), ...(authored ?? []).flat()]),
|
|
304
|
+
ownSearched: authored !== null,
|
|
305
|
+
};
|
|
255
306
|
}
|
|
256
307
|
/**
|
|
257
308
|
* Make the local queue mirror what's actually awaiting: stub artifacts for
|
|
@@ -259,7 +310,7 @@ export function startDaemon(opts) {
|
|
|
259
310
|
* request went away. Freshness decisions always come from local artifacts —
|
|
260
311
|
* search results lag GitHub by minutes and never override them.
|
|
261
312
|
*/
|
|
262
|
-
async function syncQueue(refs) {
|
|
313
|
+
async function syncQueue(refs, ownSearched) {
|
|
263
314
|
const discovered = [];
|
|
264
315
|
/** Reopen checks spent this poll — the same cap the state refresh below obeys. */
|
|
265
316
|
let reopenChecks = 0;
|
|
@@ -295,6 +346,11 @@ export function startDaemon(opts) {
|
|
|
295
346
|
async function reopenIfAskedAgain(artifact) {
|
|
296
347
|
if (settledAtOf(artifact) === null)
|
|
297
348
|
return;
|
|
349
|
+
// Nobody can ask you to review your own PR, and a comment naming its
|
|
350
|
+
// author is the conversation of the PR rather than a request for a
|
|
351
|
+
// review — so a skip there stands until you undo it yourself.
|
|
352
|
+
if (isOwnPr(artifact.pr, await who()))
|
|
353
|
+
return;
|
|
298
354
|
const last = requestCheckedAt.get(artifact.id) ?? 0;
|
|
299
355
|
if (reopenChecks >= STATE_REFRESH_CAP || Date.now() - last < STATE_REFRESH_MIN_MS)
|
|
300
356
|
return;
|
|
@@ -344,6 +400,8 @@ export function startDaemon(opts) {
|
|
|
344
400
|
const me = await who();
|
|
345
401
|
if (me === null)
|
|
346
402
|
return;
|
|
403
|
+
if (isOwnPr(artifact.pr, me))
|
|
404
|
+
return;
|
|
347
405
|
let ask;
|
|
348
406
|
try {
|
|
349
407
|
ask = await askedInWords(artifact, me);
|
|
@@ -395,15 +453,27 @@ export function startDaemon(opts) {
|
|
|
395
453
|
// predate a draft→ready flip. Refresh from it — it costs nothing, it's
|
|
396
454
|
// already in hand — or the queue keeps calling a ready PR a draft until
|
|
397
455
|
// something happens to re-review it.
|
|
398
|
-
|
|
456
|
+
//
|
|
457
|
+
// The PR's last activity is refreshed only on a row nobody has drafted,
|
|
458
|
+
// the one place the queue reads it (`activityAt`). Every write bumps the
|
|
459
|
+
// artifact's own `updatedAt`, and on a drafted row that is the review's
|
|
460
|
+
// date: refreshing there would re-date every draft by the poll each time
|
|
461
|
+
// its PR saw a comment, which is the meaningless date this field exists
|
|
462
|
+
// to replace — and would race an open review's refresh besides.
|
|
463
|
+
const activity = existing.status === "awaiting" && existing.pr.updatedAt !== ref.updatedAt;
|
|
464
|
+
if (existing.pr.isDraft !== ref.isDraft || activity) {
|
|
399
465
|
await updateArtifactByKey(artifactKey(existing.id), (a) => ({
|
|
400
466
|
...a,
|
|
401
|
-
pr: {
|
|
467
|
+
pr: {
|
|
468
|
+
...a.pr,
|
|
469
|
+
isDraft: ref.isDraft,
|
|
470
|
+
updatedAt: a.status === "awaiting" ? ref.updatedAt : a.pr.updatedAt,
|
|
471
|
+
},
|
|
402
472
|
}));
|
|
403
473
|
}
|
|
404
474
|
continue;
|
|
405
475
|
}
|
|
406
|
-
await saveArtifact(stubArtifact(ref));
|
|
476
|
+
await saveArtifact(stubArtifact(ref, isOwnPr(ref, await who())));
|
|
407
477
|
discovered.push(ref);
|
|
408
478
|
}
|
|
409
479
|
/**
|
|
@@ -436,6 +506,13 @@ export function startDaemon(opts) {
|
|
|
436
506
|
const me = await who();
|
|
437
507
|
if (me === null)
|
|
438
508
|
return;
|
|
509
|
+
// Your own PR is never filed. Every reason below reads *you* acting on
|
|
510
|
+
// the PR as an answer to somebody's request, and on your own PR you act
|
|
511
|
+
// all the time — replying to its review threads posts a review of yours —
|
|
512
|
+
// with no request there to answer. It leaves the inbox when it merges or
|
|
513
|
+
// closes, or when you skip it.
|
|
514
|
+
if (isOwnPr(artifact.pr, me))
|
|
515
|
+
return;
|
|
439
516
|
/** Re-reads from disk: a run or a send may have started in the seconds
|
|
440
517
|
* these reads took, and neither wants filing out from under it. */
|
|
441
518
|
async function file(filed, note, stillFilable) {
|
|
@@ -500,10 +577,16 @@ export function startDaemon(opts) {
|
|
|
500
577
|
await updateArtifactByKey(artifactKey(artifact.id), (a) => ({ ...a, pr }));
|
|
501
578
|
log(`[${artifact.id}] ${pr.state.toLowerCase()} — archived`);
|
|
502
579
|
}
|
|
503
|
-
else {
|
|
580
|
+
else if (ownSearched || !mightBeYours(artifact, await who())) {
|
|
504
581
|
await deleteArtifact(artifact.id);
|
|
505
582
|
log(`[${artifact.id}] no longer awaiting your review — removed from the queue`);
|
|
506
583
|
}
|
|
584
|
+
// Otherwise this poll could not look for your own PRs, so "not in
|
|
585
|
+
// the results" says nothing about a stub that may be yours: it
|
|
586
|
+
// stays, rather than being dropped and logged as gone only to
|
|
587
|
+
// return next poll. Everybody else's is reaped as before — unless
|
|
588
|
+
// gh cannot say who you are, when any stub may be yours and every
|
|
589
|
+
// one waits for a poll that can tell.
|
|
507
590
|
}
|
|
508
591
|
catch {
|
|
509
592
|
// GitHub unreachable — leave the stub; next poll retries.
|
|
@@ -582,9 +665,9 @@ export function startDaemon(opts) {
|
|
|
582
665
|
* quiet week would announce that whole week at once — the same reason the
|
|
583
666
|
* browser bell records what it stays quiet about.
|
|
584
667
|
*/
|
|
585
|
-
async function announce(
|
|
668
|
+
async function announce(drafts, tell) {
|
|
586
669
|
const owed = (await listArtifacts()).flatMap((a) => {
|
|
587
|
-
const news = pendingNews(a,
|
|
670
|
+
const news = pendingNews(a, drafts(a.pr));
|
|
588
671
|
return news ? [{ id: a.id, news }] : [];
|
|
589
672
|
});
|
|
590
673
|
// `cockpitUrl` is where a click lands, and it is read here rather than
|
|
@@ -724,9 +807,13 @@ export function startDaemon(opts) {
|
|
|
724
807
|
* The status fields that follow the config, set from it. The poll calls this
|
|
725
808
|
* with what it just read, and `reconfigure` with what the cockpit just saved.
|
|
726
809
|
*/
|
|
727
|
-
function applyKnobs(config) {
|
|
810
|
+
function applyKnobs(config, me = null) {
|
|
728
811
|
const knobs = config.daemon;
|
|
729
|
-
const autoReview = opts.autoReview
|
|
812
|
+
const autoReview = capAutoReview(knobs, opts.autoReview);
|
|
813
|
+
// Your own PRs are never drafted unasked, whatever auto-review says for
|
|
814
|
+
// their repo: they are in the inbox for a self-review on demand. The same
|
|
815
|
+
// predicate decides when a tap is due, which keeps them quiet there too.
|
|
816
|
+
const drafts = (pr) => !isOwnPr(pr, me) && autoReviewFor(autoReview, pr.owner, pr.repo);
|
|
730
817
|
status.pollEnabled = knobs.poll;
|
|
731
818
|
// What the cockpit's bell defers to: a loop that isn't polling announces
|
|
732
819
|
// nothing, whatever the notify toggle says.
|
|
@@ -736,10 +823,11 @@ export function startDaemon(opts) {
|
|
|
736
823
|
// should be standing down for.
|
|
737
824
|
const announcing = () => knobs.poll && notifyOn && notifierWorks !== false;
|
|
738
825
|
status.notify = announcing();
|
|
739
|
-
status.autoReview = autoReview;
|
|
826
|
+
status.autoReview = autoReview.autoReview;
|
|
827
|
+
status.autoReviewRepos = autoReview.autoReviewRepos;
|
|
740
828
|
// 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 };
|
|
829
|
+
status.trustedRuns = anyAutoReview(autoReview) && opts.trust !== false && config.trust.length > 0;
|
|
830
|
+
return { knobs, drafts, drafting: anyAutoReview(autoReview), notifyOn, announcing };
|
|
743
831
|
}
|
|
744
832
|
/** Everything a poll writes is the poll's — including the reviews it starts,
|
|
745
833
|
* which stamp themselves as runs from inside this. */
|
|
@@ -756,7 +844,11 @@ export function startDaemon(opts) {
|
|
|
756
844
|
// or the knobs), so a broken file skips the tick loudly instead of
|
|
757
845
|
// proceeding on guessed defaults.
|
|
758
846
|
const config = await loadConfig();
|
|
759
|
-
|
|
847
|
+
// Who you are, asked once per poll (and cached for the process): it is
|
|
848
|
+
// what tells your own PRs apart from the ones awaiting you. Null is "gh
|
|
849
|
+
// could not say", and then no own PR is brought in at all — see `discover`.
|
|
850
|
+
const me = await currentLogin().catch(() => null);
|
|
851
|
+
const { knobs, drafts, drafting, notifyOn, announcing } = applyKnobs(config, me);
|
|
760
852
|
if (!knobs.poll) {
|
|
761
853
|
// Deliberately off is not an outage — don't leave a stale error up, or
|
|
762
854
|
// a list of PRs we are no longer checking are still awaiting you.
|
|
@@ -765,21 +857,34 @@ export function startDaemon(opts) {
|
|
|
765
857
|
status.lastSummary = "polling off (settings) — the queue only shows what you review by hand";
|
|
766
858
|
return;
|
|
767
859
|
}
|
|
768
|
-
const refs = await discover();
|
|
860
|
+
const { refs, ownSearched } = await discover(me);
|
|
861
|
+
// Your own PRs are synced into the queue with the rest, but nobody is
|
|
862
|
+
// asking you for them: they are not "awaiting" in anything the strip
|
|
863
|
+
// counts, and the cockpit's open-requests tab — "GitHub still lists you
|
|
864
|
+
// as a requested reviewer" — must never name one.
|
|
865
|
+
const asked = refs.filter((r) => !isOwnPr(r, me));
|
|
866
|
+
const yours = refs.length - asked.length;
|
|
867
|
+
const ownPart = yours > 0 ? `, ${yours} of your own` : "";
|
|
769
868
|
status.lastPollError = null;
|
|
770
869
|
// The same refs behind lastSummary's count, so the number the strip shows
|
|
771
870
|
// and the rows the cockpit can name always come from one answer.
|
|
772
871
|
// A failed poll leaves the last good list up; lastPollError says so.
|
|
773
|
-
status.awaiting = await classifyAll(
|
|
774
|
-
const { discovered } = await syncQueue(refs);
|
|
775
|
-
if (
|
|
776
|
-
|
|
872
|
+
status.awaiting = await classifyAll(asked);
|
|
873
|
+
const { discovered } = await syncQueue(refs, ownSearched);
|
|
874
|
+
if (drafting) {
|
|
875
|
+
// A repo excepted from auto-review is discovered like any other — it
|
|
876
|
+
// is in the queue above — and only its run waits for the click. So is
|
|
877
|
+
// your own PR, in every repo.
|
|
878
|
+
const toDraft = asked.filter(drafts);
|
|
879
|
+
const onClick = asked.length - toDraft.length;
|
|
880
|
+
const { reviewed, skipped, failed } = await reviewAll(toDraft);
|
|
777
881
|
status.lastSummary =
|
|
778
|
-
`${
|
|
779
|
-
`${failed > 0 ? `, ${failed} failed` : ""}
|
|
882
|
+
`${asked.length} awaiting; ${reviewed} reviewed, ${skipped} up to date` +
|
|
883
|
+
`${failed > 0 ? `, ${failed} failed` : ""}` +
|
|
884
|
+
`${onClick > 0 ? `, ${onClick} waiting for a click` : ""}${ownPart}`;
|
|
780
885
|
}
|
|
781
886
|
else {
|
|
782
|
-
status.lastSummary = `${
|
|
887
|
+
status.lastSummary = `${asked.length} awaiting${discovered.length > 0 ? `, ${discovered.length} new` : ""}${ownPart} (auto-review off)`;
|
|
783
888
|
}
|
|
784
889
|
// After the drafting, not before it. The arrival is not the news when
|
|
785
890
|
// cerber is about to write the review itself: a tap that lands on "no run
|
|
@@ -788,7 +893,7 @@ export function startDaemon(opts) {
|
|
|
788
893
|
// for the draft — and for a PR nobody is drafting (auto-review off, or a
|
|
789
894
|
// run that failed) it goes out here all the same. `isNews` is the rule,
|
|
790
895
|
// and the cockpit's bell reads the same one.
|
|
791
|
-
await announce(
|
|
896
|
+
await announce(drafts, notifyOn);
|
|
792
897
|
// Recomputed on the spot rather than left to the next poll: that is
|
|
793
898
|
// minutes away, and the cockpit would spend them deferring to a tap that
|
|
794
899
|
// never came. Recomputed rather than only cleared, so a machine whose
|
|
@@ -812,7 +917,7 @@ export function startDaemon(opts) {
|
|
|
812
917
|
}
|
|
813
918
|
}
|
|
814
919
|
async function handleAutoSend(artifact) {
|
|
815
|
-
const decision = evaluateAutoSend(artifact, opts.autoSendThreshold);
|
|
920
|
+
const decision = evaluateAutoSend(artifact, opts.autoSendThreshold, await currentLogin().catch(() => null));
|
|
816
921
|
if (decision.eligible)
|
|
817
922
|
status.autoSendCandidates++;
|
|
818
923
|
const entryBase = {
|
package/dist/server/index.js
CHANGED
|
@@ -9,14 +9,16 @@ 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";
|
|
15
|
+
import { setException } from "../core/autoreview.js";
|
|
14
16
|
import { DaemonConfigSchema, configPath, loadConfig, saveConfig } from "../core/config.js";
|
|
15
17
|
import { version } from "../core/version.js";
|
|
16
18
|
import { refreshArtifact, userOwnsStatus } from "../core/refresh.js";
|
|
17
19
|
import { withWriter } from "../core/history.js";
|
|
18
20
|
import { TrustRuleError, describeRule, explainRule, parseTrustRule } from "../core/trust.js";
|
|
19
|
-
import { buildReviewPayload, computeCalibration, describeReplyFailures, recordReplies, } from "../core/send.js";
|
|
21
|
+
import { buildReviewPayload, computeCalibration, describeReplyFailures, ownPrRefusal, recordReplies, } from "../core/send.js";
|
|
20
22
|
import { raisedChanged, rewriteFinding, startRaisedCheck } from "../core/raised.js";
|
|
21
23
|
import { checkAlreadyRaised, claimRaisedCheck, finishRaisedCheck, isRaisedCheckRunning, prepareRaisedCheck, releaseRaisedCheck, } from "../runner/raised.js";
|
|
22
24
|
import { listArtifacts, loadArtifact, loadArtifactByKey, noteHistory, saveArtifact, updateArtifactByKey, } from "../core/state.js";
|
|
@@ -32,6 +34,25 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
32
34
|
* own decision about a PR. Everything else is a fact some other path owns.
|
|
33
35
|
*/
|
|
34
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
|
+
}
|
|
35
56
|
/** What the user may decide about a finding somebody else already raised. */
|
|
36
57
|
const RaisedDecisionSchema = z.enum(["send", "reply"]).nullable();
|
|
37
58
|
/**
|
|
@@ -164,6 +185,41 @@ export async function buildApp(opts) {
|
|
|
164
185
|
return c.json({ error: err instanceof Error ? err.message : String(err) }, 500);
|
|
165
186
|
}
|
|
166
187
|
});
|
|
188
|
+
// One per-repo auto-review exception at a time: `on` true or false sets it,
|
|
189
|
+
// null removes it. Merged into the file as it is now, not the map the cockpit
|
|
190
|
+
// loaded, so a second tab or a hand edit since then is not overwritten.
|
|
191
|
+
app.post("/api/config/auto-review-repo", async (c) => {
|
|
192
|
+
let body;
|
|
193
|
+
try {
|
|
194
|
+
body = await c.req.json();
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return c.json({ error: "body must be JSON" }, 400);
|
|
198
|
+
}
|
|
199
|
+
const { repo, on } = body;
|
|
200
|
+
if (typeof repo !== "string" || !repo.trim()) {
|
|
201
|
+
return c.json({ error: "repo is required" }, 400);
|
|
202
|
+
}
|
|
203
|
+
if (on !== null && typeof on !== "boolean") {
|
|
204
|
+
return c.json({ error: "on must be true, false or null" }, 400);
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
const config = await loadConfig();
|
|
208
|
+
const daemon = DaemonConfigSchema.parse({
|
|
209
|
+
...config.daemon,
|
|
210
|
+
autoReviewRepos: setException(config.daemon.autoReviewRepos, repo.trim(), on),
|
|
211
|
+
});
|
|
212
|
+
await saveConfig({ ...config, daemon });
|
|
213
|
+
opts.daemon?.reconfigure({ ...config, daemon });
|
|
214
|
+
return c.json(configView(config.trust, daemon));
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
if (err instanceof z.ZodError) {
|
|
218
|
+
return c.json({ error: err.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ") }, 400);
|
|
219
|
+
}
|
|
220
|
+
return c.json({ error: err instanceof Error ? err.message : String(err) }, 500);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
167
223
|
app.post("/api/config/trust", async (c) => {
|
|
168
224
|
let body;
|
|
169
225
|
try {
|
|
@@ -206,6 +262,10 @@ export async function buildApp(opts) {
|
|
|
206
262
|
});
|
|
207
263
|
app.get("/api/reviews", async (c) => {
|
|
208
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);
|
|
209
269
|
return c.json(artifacts.map((a) => ({
|
|
210
270
|
id: a.id,
|
|
211
271
|
key: artifactKey(a.id),
|
|
@@ -220,6 +280,9 @@ export async function buildApp(opts) {
|
|
|
220
280
|
number: a.pr.number,
|
|
221
281
|
state: a.pr.state,
|
|
222
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,
|
|
223
286
|
additions: a.pr.additions,
|
|
224
287
|
deletions: a.pr.deletions,
|
|
225
288
|
changedFiles: a.pr.changedFiles,
|
|
@@ -243,6 +306,9 @@ export async function buildApp(opts) {
|
|
|
243
306
|
// rows the daemon deliberately stays silent about, and the two bells
|
|
244
307
|
// would stop telling one story.
|
|
245
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),
|
|
246
312
|
costUsd: a.run?.costUsd ?? null,
|
|
247
313
|
withSource: a.run?.withSource ?? null,
|
|
248
314
|
trusted: a.run?.trusted ?? null,
|
|
@@ -392,7 +458,9 @@ export async function buildApp(opts) {
|
|
|
392
458
|
const artifact = await loadArtifactByKey(c.req.param("key"));
|
|
393
459
|
if (!artifact)
|
|
394
460
|
return c.json({ error: "not found" }, 404);
|
|
395
|
-
|
|
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)) });
|
|
396
464
|
});
|
|
397
465
|
// ---- Mutations (all local — artifact edits only) ----
|
|
398
466
|
app.patch("/api/reviews/:key", async (c) => {
|
|
@@ -868,6 +936,14 @@ export async function buildApp(opts) {
|
|
|
868
936
|
if (artifact.sent) {
|
|
869
937
|
return c.json({ error: `already sent at ${artifact.sent.at}` }, 409);
|
|
870
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
|
+
}
|
|
871
947
|
// Not while a run is rewriting this draft. Vouching for a review that is
|
|
872
948
|
// being replaced under you is reason enough on its own; on top of that the
|
|
873
949
|
// run used to save `sent: null` back over the record when it landed, so the
|
package/package.json
CHANGED