@fullstackhouse/cerber 1.4.1 → 1.5.0-pr.87.1fdc3c7

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
@@ -437,14 +437,13 @@ The AI's summary and verdict still describe the commit that was reviewed. To
437
437
  get its opinion of the new code, hit **Re-review at the new head** in the
438
438
  cockpit (or `cerber review <pr> --force`).
439
439
 
440
- > ⚠️ **A re-review replaces the whole draft — including comments you wrote or
441
- > rewrote, and a send body you wrote yourself.** They are dropped when the run
442
- > starts and they do not come back, on success or on failure. This is a
443
- > decision, not a bug ([`docs/lifecycle.md`](docs/lifecycle.md)): the run owns
444
- > the draft. If you have written comments you want to keep, send the review or
445
- > copy them out first. Your *decisions* do survive — a `reviewed` or `skipped`
446
- > you set and the chat transcript are kept, and a send is kept as a record of
447
- > what went to GitHub (see the next section).
440
+ > **A re-review replaces the AI's draft and keeps your comments.** The ones you
441
+ > wrote, rewrote, or had the chat add or rewrite move onto the new head by
442
+ > their line's text; one whose code is gone posts in the body instead
443
+ > ([`docs/lifecycle.md`](docs/lifecycle.md)). A send body you wrote yourself
444
+ > does not survive — it described the old draft. Your *decisions* survive too:
445
+ > a `reviewed` or `skipped` you set and the chat transcript are kept, and a send
446
+ > is kept as a record of what went to GitHub (see the next section).
448
447
 
449
448
  ### Re-reviewing one you already sent
450
449
 
@@ -90,6 +90,11 @@ export const CommentSchema = z.object({
90
90
  drifted: z.boolean().default(false),
91
91
  /** Somebody else already raised this on the PR. AI comments only. */
92
92
  alreadyRaised: AlreadyRaisedSchema.nullable().default(null),
93
+ /**
94
+ * Added or rewritten through the chat. That was the user's call, not the
95
+ * run's, so a re-review carries it over like their own (`carryYours`).
96
+ */
97
+ fromChat: z.boolean().default(false),
93
98
  });
94
99
  /**
95
100
  * The last comparison of the draft against what others already said on the PR.
@@ -33,6 +33,26 @@ export function refreshArtifact(artifact, pr, diff) {
33
33
  results,
34
34
  };
35
35
  }
36
+ /**
37
+ * A comment that is the user's call rather than the run's: one they wrote, one
38
+ * they rewrote, or one they had the chat add or rewrite.
39
+ */
40
+ export function isYours(c) {
41
+ return c.origin === "user" || c.editedByUser || c.fromChat;
42
+ }
43
+ /**
44
+ * The user's comments, pulled from the diff they were written on onto the one a
45
+ * re-review is reading.
46
+ *
47
+ * A re-review replaces the AI's findings, not the user's. A push from the
48
+ * author is no reason to lose a comment they wrote or a finding they argued
49
+ * into shape in the chat — and the old conversation would go on naming it
50
+ * as though it were still there. Anchored by line text like a refresh; one
51
+ * whose code is gone is marked drifted and posts in the body.
52
+ */
53
+ export function carryYours(comments, fromDiff, toDiff) {
54
+ return reanchorComments(comments.filter(isYours), fromDiff, toDiff).comments;
55
+ }
36
56
  /**
37
57
  * Is this artifact's status the user's to keep, rather than the run's to set?
38
58
  *
@@ -66,10 +86,8 @@ export function supersede(a) {
66
86
  * `mergeConcurrentEdits` exists to stop a chat turn making.
67
87
  *
68
88
  * `fresh` is what the run produced; `current` is what is on disk now. The run
69
- * owns the draft — summary, chapters, verdict, comments — and that includes
70
- * replacing comments the user wrote: a re-review starts fresh by design, and
71
- * `docs/lifecycle.md` says so plainly rather than leaving anyone to count on
72
- * work surviving one. What it does *not* own are the decisions:
89
+ * owns the draft — summary, chapters, verdict, the AI's comments. What it does
90
+ * *not* own are the decisions:
73
91
  *
74
92
  * - **a send** stands, and takes the status with it. Without this a run
75
93
  * finishing after a send wrote `sent: null` back over the record, and the
@@ -79,10 +97,13 @@ export function supersede(a) {
79
97
  * The fresh draft still lands underneath, which is what the row shows if
80
98
  * the user changes their mind.
81
99
  * - **the conversation** is the user's writing, snapshot and all.
100
+ * - **the user's comments** (`carryYours`), read from disk so one written
101
+ * while the run worked is kept too, and put ahead of the run's own.
82
102
  */
83
103
  export function mergeRunResult(fresh, current) {
84
104
  return {
85
105
  ...fresh,
106
+ comments: [...carryYours(current.comments, current.diff, fresh.diff), ...fresh.comments],
86
107
  status: userOwnsStatus(current) ? current.status : fresh.status,
87
108
  // Travels with the status it dates. A settle that landed while the run
88
109
  // worked keeps both halves of itself, and a run that reopens the row takes
@@ -152,6 +152,8 @@ export function applyRevisions(artifact, revisions, opts = {}) {
152
152
  ...rewriteFinding(c, revision.body),
153
153
  // Omitted = the turn is not re-grading; null = "not a finding".
154
154
  severity: revision.severity === undefined ? c.severity : revision.severity,
155
+ // The user's call now, so a re-review keeps it.
156
+ fromChat: true,
155
157
  }
156
158
  : c),
157
159
  };
@@ -194,6 +196,7 @@ export function applyRevisions(artifact, revisions, opts = {}) {
194
196
  originalLine: null,
195
197
  drifted: false,
196
198
  alreadyRaised: null,
199
+ fromChat: true,
197
200
  },
198
201
  ],
199
202
  };
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
2
2
  import { AiReviewSchema, SCHEMA_VERSION, artifactId, artifactKey, } from "../core/artifact.js";
3
3
  import { createRunDir, evictOldCheckouts, prepareCheckout, removeRunDir } from "../core/checkout.js";
4
4
  import { fetchPrDiff, fetchPrInfo, isOrgMember, isTeamMember } from "../core/gh.js";
5
- import { mergeRunResult, supersede, userOwnsStatus } from "../core/refresh.js";
5
+ import { carryYours, isYours, mergeRunResult, supersede, userOwnsStatus } from "../core/refresh.js";
6
6
  import { loadArtifact, noteHistory, saveArtifact, updateArtifactByKey } from "../core/state.js";
7
7
  import { withWriter } from "../core/history.js";
8
8
  import { loadConfig } from "../core/config.js";
@@ -146,13 +146,14 @@ async function performReview(ref, pr, existing, opts, log) {
146
146
  `reviewing from the diff alone.`);
147
147
  }
148
148
  }
149
- // A re-review regenerates the draft, comments and all — deliberately, and
150
- // including any the user wrote. Carrying them across is a feature this tool
151
- // has decided not to have, so nothing here tries to half-keep them: they go
152
- // when the run starts, whichever way it ends. `docs/lifecycle.md` says so
153
- // where a reader would otherwise assume otherwise.
149
+ // A re-review regenerates the AI's draft, comments included. The user's own
150
+ // comments — written, rewritten, or added through the chat — are carried
151
+ // over at the claim below (`carryYours`), whichever way the run ends.
154
152
  if (existing && existing.comments.length > 0) {
155
- log(`Replacing the previous draft's ${existing.comments.length} comment(s) — a re-review starts fresh.`);
153
+ const yours = existing.comments.filter(isYours).length;
154
+ const theirs = existing.comments.length - yours;
155
+ log(`Replacing the previous draft's ${theirs} AI comment(s)` +
156
+ (yours > 0 ? `, keeping your ${yours}.` : "."));
156
157
  }
157
158
  let artifact = {
158
159
  schemaVersion: SCHEMA_VERSION,
@@ -242,6 +243,8 @@ async function performReview(ref, pr, existing, opts, log) {
242
243
  ...artifact,
243
244
  notified: current.notified,
244
245
  viewed: current.viewed,
246
+ // Yours stay through the run, its failure included; the AI's go.
247
+ comments: carryYours(current.comments, current.diff, artifact.diff),
245
248
  priorSends: supersede(current),
246
249
  calibration: current.calibration,
247
250
  });
@@ -287,6 +290,7 @@ async function performReview(ref, pr, existing, opts, log) {
287
290
  originalLine: null,
288
291
  drifted: false,
289
292
  alreadyRaised: null,
293
+ fromChat: false,
290
294
  })),
291
295
  verdict: review.ai.verdict,
292
296
  run: {
@@ -275,6 +275,10 @@ export function startDaemon(opts) {
275
275
  /** When GitHub was last asked whether a settled row has been re-requested, by
276
276
  * artifact id. In-memory for the same reason: a restart just asks sooner. */
277
277
  const requestCheckedAt = new Map();
278
+ /** What the last poll's searches returned. A row that has just dropped out
279
+ * of them most likely merged or closed, so its state check skips the queue.
280
+ * In-memory: a restart just waits for the rotation, as before. */
281
+ let lastSearched = new Set();
278
282
  /**
279
283
  * What GitHub has for you: the PRs awaiting your review, then your own open
280
284
  * ones, as one deduplicated list — and whether the second search ran at all
@@ -565,6 +569,14 @@ export function startDaemon(opts) {
565
569
  await file({ at: new Date().toISOString(), reason: "request-withdrawn", review: null, reply: null }, "nobody is asking for this review any more", filedByWithdrawnRequest);
566
570
  }
567
571
  const awaitingIds = new Set(refs.map((r) => artifactId(r)));
572
+ // A row that left the searches since last poll is checked now, outside the
573
+ // cap and the leash: it is the one most likely to have merged, and behind
574
+ // the rotation of every open draft it could sit in the inbox for several
575
+ // polls. Without the own-PR search, every PR of yours would look like it left.
576
+ const me = ownSearched ? null : await who();
577
+ const searchedBefore = lastSearched;
578
+ lastSearched = awaitingIds;
579
+ const leftSearch = (a) => searchedBefore.has(a.id) && (ownSearched || (me !== null && !isOwnPr(a.pr, me)));
568
580
  let refreshed = 0;
569
581
  for (const artifact of await listArtifacts()) {
570
582
  if (artifact.status === "running")
@@ -602,12 +614,14 @@ export function startDaemon(opts) {
602
614
  // Anything with real work in it: periodically confirm the PR is still
603
615
  // open, so merged/closed ones stop cluttering the queue. Capped and
604
616
  // spaced out — this is book-keeping, not a data feed.
605
- if (refreshed >= STATE_REFRESH_CAP)
606
- continue;
607
- const last = stateCheckedAt.get(artifact.id) ?? 0;
608
- if (Date.now() - last < STATE_REFRESH_MIN_MS)
609
- continue;
610
- refreshed++;
617
+ if (!leftSearch(artifact)) {
618
+ if (refreshed >= STATE_REFRESH_CAP)
619
+ continue;
620
+ const last = stateCheckedAt.get(artifact.id) ?? 0;
621
+ if (Date.now() - last < STATE_REFRESH_MIN_MS)
622
+ continue;
623
+ refreshed++;
624
+ }
611
625
  stateCheckedAt.set(artifact.id, Date.now());
612
626
  try {
613
627
  const pr = await fetchPrInfo(artifact.pr);
@@ -587,6 +587,7 @@ export async function buildApp(opts) {
587
587
  originalLine: null,
588
588
  drifted: false,
589
589
  alreadyRaised: null,
590
+ fromChat: false,
590
591
  },
591
592
  ],
592
593
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fullstackhouse/cerber",
3
- "version": "1.4.1",
3
+ "version": "1.5.0-pr.87.1fdc3c7",
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": [