@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.
@@ -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),
@@ -243,6 +303,9 @@ export async function buildApp(opts) {
243
303
  // rows the daemon deliberately stays silent about, and the two bells
244
304
  // would stop telling one story.
245
305
  announceable: a.notified !== undefined,
306
+ // A PR you opened: listed apart from the ones awaiting you, and sent
307
+ // as a comment only (`ownPrRefusal`).
308
+ own: isOwnPr(a.pr, me),
246
309
  costUsd: a.run?.costUsd ?? null,
247
310
  withSource: a.run?.withSource ?? null,
248
311
  trusted: a.run?.trusted ?? null,
@@ -392,7 +455,9 @@ export async function buildApp(opts) {
392
455
  const artifact = await loadArtifactByKey(c.req.param("key"));
393
456
  if (!artifact)
394
457
  return c.json({ error: "not found" }, 404);
395
- return c.json(artifact);
458
+ // `own` rides along so the review page knows what Send may post without
459
+ // depending on the queue list having loaded (§9.10).
460
+ return c.json({ ...artifact, own: isOwnPr(artifact.pr, await loginWithin(LOGIN_WAIT_MS)) });
396
461
  });
397
462
  // ---- Mutations (all local — artifact edits only) ----
398
463
  app.patch("/api/reviews/:key", async (c) => {
@@ -868,6 +933,14 @@ export async function buildApp(opts) {
868
933
  if (artifact.sent) {
869
934
  return c.json({ error: `already sent at ${artifact.sent.at}` }, 409);
870
935
  }
936
+ // Only a comment on your own PR. The cockpit offers nothing else there, so
937
+ // this is for a stale tab or a direct call; the login is only asked for
938
+ // when the event could be refused.
939
+ if (event !== "COMMENT") {
940
+ const refusal = ownPrRefusal(artifact.pr, event, await currentLogin().catch(() => null));
941
+ if (refusal)
942
+ return c.json({ error: refusal }, 400);
943
+ }
871
944
  // Not while a run is rewriting this draft. Vouching for a review that is
872
945
  // being replaced under you is reason enough on its own; on top of that the
873
946
  // run used to save `sent: null` back over the record when it landed, so the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fullstackhouse/cerber",
3
- "version": "1.1.0",
3
+ "version": "1.2.0-pr.81.58d1702",
4
4
  "description": "AI code-review cockpit: Claude reviews your PRs into local artifacts; nothing reaches GitHub until you say so.",
5
5
  "license": "MIT",
6
6
  "keywords": [