@fullstackhouse/cerber 0.39.0 → 0.40.0-pr.75.302a297

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.
@@ -16,12 +16,12 @@ import { refreshArtifact, userOwnsStatus } from "../core/refresh.js";
16
16
  import { withWriter } from "../core/history.js";
17
17
  import { TrustRuleError, describeRule, explainRule, parseTrustRule } from "../core/trust.js";
18
18
  import { buildReviewPayload, computeCalibration, describeReplyFailures, recordReplies, } from "../core/send.js";
19
- import { raisedChanged, startRaisedCheck } from "../core/raised.js";
19
+ import { raisedChanged, rewriteFinding, startRaisedCheck } from "../core/raised.js";
20
20
  import { checkAlreadyRaised, claimRaisedCheck, finishRaisedCheck, isRaisedCheckRunning, prepareRaisedCheck, releaseRaisedCheck, } from "../runner/raised.js";
21
- import { listArtifacts, loadArtifact, loadArtifactByKey, saveArtifact, updateArtifactByKey, } from "../core/state.js";
21
+ import { listArtifacts, loadArtifact, loadArtifactByKey, noteHistory, saveArtifact, updateArtifactByKey, } from "../core/state.js";
22
22
  import { isReviewRunning } from "../runner/inflight.js";
23
23
  import { reviewPr } from "../runner/review.js";
24
- import { runChatTurn } from "../runner/chat.js";
24
+ import { runChatTurn, steerChatTurn } from "../runner/chat.js";
25
25
  import { mergeConcurrentEdits, restoreReview } from "../core/revise.js";
26
26
  import { progressWriter } from "./progress.js";
27
27
  import { ChatTurnSchema } from "../core/artifact.js";
@@ -342,6 +342,7 @@ export async function buildApp(opts) {
342
342
  },
343
343
  sent: null,
344
344
  refresh: null,
345
+ priorSends: [],
345
346
  filed: null,
346
347
  handoff: null,
347
348
  raisedCheck: null,
@@ -465,11 +466,19 @@ export async function buildApp(opts) {
465
466
  ...a,
466
467
  comments: a.comments.map((cm) => cm.id === id
467
468
  ? {
468
- ...cm,
469
+ // Rewriting a finding somebody else raised decides it: the words
470
+ // that post are the user's, not the ones the check compared. An
471
+ // explicit decision in the same request still wins, below. On a
472
+ // sent review nothing is re-decided — it is a record of what was
473
+ // posted, and `foldRaised` holds the same line.
474
+ ...(body.body === undefined
475
+ ? cm
476
+ : a.sent
477
+ ? { ...cm, body: String(body.body) }
478
+ : rewriteFinding(cm, String(body.body))),
469
479
  ...(decision.success && body.raisedDecision !== undefined && cm.alreadyRaised
470
480
  ? { alreadyRaised: { ...cm.alreadyRaised, decision: decision.data } }
471
481
  : {}),
472
- ...(body.body !== undefined ? { body: String(body.body) } : {}),
473
482
  ...(body.severity !== undefined
474
483
  ? { severity: SeveritySchema.nullable().parse(body.severity) }
475
484
  : {}),
@@ -560,8 +569,14 @@ export async function buildApp(opts) {
560
569
  const stale = artifact.pr.headSha !== "" && artifact.pr.headSha !== pr.headSha;
561
570
  // A sent review is a record of what was posted — never rewrite it. A running
562
571
  // one is mid-run and would be overwritten from under the runner.
572
+ //
573
+ // `headSha` rides on the answer either way, and it is the only thing a
574
+ // declined refresh can tell the cockpit: on a sent row nothing is written,
575
+ // so the artifact handed back still names the commit that was reviewed,
576
+ // and the page would have nothing to say about a PR that has moved past a
577
+ // review the user cannot edit but can replace.
563
578
  if (!stale || artifact.sent || artifact.status === "running") {
564
- return c.json({ stale, changed: false, prState: pr.state, artifact });
579
+ return c.json({ stale, changed: false, prState: pr.state, headSha: pr.headSha, artifact });
565
580
  }
566
581
  try {
567
582
  const diff = await fetchPrDiff(ref);
@@ -590,6 +605,7 @@ export async function buildApp(opts) {
590
605
  stale: true,
591
606
  changed: applied && result.changed,
592
607
  prState: pr.state,
608
+ headSha: pr.headSha,
593
609
  moved: applied ? result.moved : 0,
594
610
  drifted: applied ? result.drifted : 0,
595
611
  artifact: saved,
@@ -605,8 +621,13 @@ export async function buildApp(opts) {
605
621
  const artifact = await loadArtifactByKey(key);
606
622
  if (!artifact)
607
623
  return c.json({ error: "not found" }, 404);
608
- if (artifact.sent)
609
- return c.json({ error: `already sent at ${artifact.sent.at}` }, 409);
624
+ // A sent row may be re-reviewed, and this is the only way back into one.
625
+ // The author pushed again, somebody asked for another look, the review
626
+ // went out at a commit that no longer exists — none of that is answered by
627
+ // the review already on the PR, and refusing here left the cockpit with no
628
+ // move at all while `cerber review --force` did it from a terminal. What
629
+ // was sent is kept (`supersede`), the new draft is sendable in its own
630
+ // right, and the send panel says it would be a second review.
610
631
  if (isReviewRunning(artifact.id)) {
611
632
  return c.json({ error: busy(artifact, "a review of this PR is already running") }, 409);
612
633
  }
@@ -617,21 +638,29 @@ export async function buildApp(opts) {
617
638
  const withSource = sourceParam == null ? opts.withSource : sourceParam !== "0";
618
639
  // Mark it running before responding, so the cockpit's next poll can't catch
619
640
  // the old "ready" status and conclude the run already finished.
641
+ //
642
+ // The run block is left alone while the row still carries its send: that
643
+ // block describes the review on GitHub — its model, its cost, the commit
644
+ // it read — and a stub written here would erase all of it minutes before
645
+ // the runner's claim writes a real one, with nothing able to bring it back
646
+ // if the run never gets that far. The claim replaces it either way.
620
647
  const running = await updateArtifactByKey(key, (a) => ({
621
648
  ...a,
622
649
  status: "running",
623
- run: {
624
- model: null,
625
- startedAt: new Date().toISOString(),
626
- finishedAt: null,
627
- costUsd: null,
628
- error: null,
629
- withSource: withSource !== false,
630
- trusted: false,
631
- sessionId: null,
632
- trigger: "user",
633
- reviewedSha: null,
634
- },
650
+ run: a.sent
651
+ ? a.run
652
+ : {
653
+ model: null,
654
+ startedAt: new Date().toISOString(),
655
+ finishedAt: null,
656
+ costUsd: null,
657
+ error: null,
658
+ withSource: withSource !== false,
659
+ trusted: false,
660
+ sessionId: null,
661
+ trigger: "user",
662
+ reviewedSha: null,
663
+ },
635
664
  }));
636
665
  // Minutes-long: run it detached and let the cockpit poll the artifact.
637
666
  void reviewPr(ref, {
@@ -646,9 +675,20 @@ export async function buildApp(opts) {
646
675
  // The runner marks the artifact failed once it owns it; a failure before
647
676
  // that (fetching the PR, or a run already in flight) would otherwise
648
677
  // leave it stuck at "running" with nothing to clear it.
649
- await updateArtifactByKey(key, (a) => a.status === "running"
650
- ? { ...a, status: "failed", run: a.run ? { ...a.run, error: message } : null }
651
- : a).catch(() => { });
678
+ //
679
+ // A row that still carries its send never got as far as the claim, so
680
+ // the draft on it is the one that went to GitHub and nothing about it
681
+ // has changed: it goes back to `sent`, untouched. The failure is the
682
+ // re-review's, not that review's, so it goes in the history rather
683
+ // than onto a run block that describes something else entirely.
684
+ const back = await updateArtifactByKey(key, (a) => a.status === "running"
685
+ ? a.sent
686
+ ? { ...a, status: "sent" }
687
+ : { ...a, status: "failed", run: a.run ? { ...a.run, error: message } : null }
688
+ : a).catch(() => null);
689
+ if (back?.sent) {
690
+ await noteHistory(back.id, `re-review did not start: ${message}`).catch(() => { });
691
+ }
652
692
  });
653
693
  return c.json(running, 202);
654
694
  });
@@ -691,6 +731,7 @@ export async function buildApp(opts) {
691
731
  refs: request.refs ?? [],
692
732
  startedAt: new Date().toISOString(),
693
733
  progress: [],
734
+ steers: [],
694
735
  error: null,
695
736
  },
696
737
  }));
@@ -741,6 +782,29 @@ export async function buildApp(opts) {
741
782
  });
742
783
  return c.json(pending, 202);
743
784
  });
785
+ // Add to the turn being answered rather than waiting minutes to say "not that,
786
+ // this". The message goes into the live run; when the turn has already
787
+ // answered (or is only retrying its JSON) there is nothing to add it to, and
788
+ // the cockpit is told so instead of being shown a message that went nowhere.
789
+ const SteerRequestSchema = z.object({ message: z.string().min(1) });
790
+ app.post("/api/reviews/:key/chat/steer", async (c) => {
791
+ const key = c.req.param("key");
792
+ const artifact = await loadArtifactByKey(key);
793
+ if (!artifact)
794
+ return c.json({ error: "not found" }, 404);
795
+ let request;
796
+ try {
797
+ request = SteerRequestSchema.parse(await c.req.json());
798
+ }
799
+ catch (err) {
800
+ return c.json({ error: err instanceof Error ? err.message : String(err) }, 400);
801
+ }
802
+ if (!turnInFlight(artifact) || !steerChatTurn(artifact.id, request.message)) {
803
+ return c.json({ error: "that turn is no longer taking messages — send this as the next one" }, 409);
804
+ }
805
+ const updated = await updateArtifactByKey(key, (a) => a.pendingChat ? { ...a, pendingChat: { ...a.pendingChat, steers: [...a.pendingChat.steers, request.message] } } : a);
806
+ return c.json(updated);
807
+ });
744
808
  // Clear a turn that failed. Only that: a turn still being answered would come
745
809
  // back on the next write and the cockpit would have lied about dropping it.
746
810
  app.delete("/api/reviews/:key/chat/pending", async (c) => {
@@ -1009,12 +1073,36 @@ export async function buildApp(opts) {
1009
1073
  let sendError = null;
1010
1074
  let sent = null;
1011
1075
  let payload = null;
1012
- const alreadySent = postReview ? ((await loadArtifactByKey(key))?.sent ?? artifact.sent) : null;
1076
+ //
1077
+ // A send a re-review has since superseded counts here too. It is not on
1078
+ // this draft, but it is on the PR under the user's name, and this guard
1079
+ // exists to stop a handoff being the second review — which it would be.
1080
+ const onDisk = postReview ? await loadArtifactByKey(key) : null;
1081
+ const alreadySent = postReview
1082
+ ? (onDisk?.sent ??
1083
+ artifact.sent ??
1084
+ (onDisk ?? artifact).priorSends.at(-1) ??
1085
+ null)
1086
+ : null;
1013
1087
  // And there has to be a review to post. The dialog only offers the box on a
1014
1088
  // row that has one, but the dialog is not the guard: a stale tab or a direct
1015
1089
  // call would otherwise submit a body that is nothing but cerber's footer,
1016
1090
  // under the user's name, on a PR nobody has drafted a word about.
1017
1091
  const somethingToSay = artifact.summary !== "" || artifact.comments.some((cm) => cm.status !== "dropped");
1092
+ // A decline here has to say so. The dialog's own line promises "this row
1093
+ // goes under sent, with the review on the PR"; letting the guard refuse in
1094
+ // silence walks the user to the next review believing it posted.
1095
+ if (postReview && alreadySent) {
1096
+ // Phrased to read after the cockpit's own "the review did not post:",
1097
+ // which is what wraps every `sendError` on the way to the user.
1098
+ sendError =
1099
+ `a review was already sent on this PR on ${alreadySent.at.slice(0, 10)}` +
1100
+ `${alreadySent.url ? ` (${alreadySent.url})` : ""}, and a second one is yours to send.` +
1101
+ ` The draft is untouched.`;
1102
+ }
1103
+ else if (postReview && !somethingToSay) {
1104
+ sendError = "there is no draft on this row — only cerber's footer would have gone up.";
1105
+ }
1018
1106
  if (postReview && !alreadySent && somethingToSay) {
1019
1107
  payload = buildReviewPayload(artifact, "COMMENT");
1020
1108
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fullstackhouse/cerber",
3
- "version": "0.39.0",
3
+ "version": "0.40.0-pr.75.302a297",
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": [
@@ -55,6 +55,7 @@
55
55
  "@types/react": "^19.0.4",
56
56
  "@types/react-dom": "^19.0.2",
57
57
  "@vitejs/plugin-react": "^4.3.4",
58
+ "conventional-changelog-conventionalcommits": "^9.3.1",
58
59
  "dompurify": "^3.4.13",
59
60
  "highlight.js": "^11.12.0",
60
61
  "marked": "^18.0.10",