@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.
- package/README.md +27 -3
- package/dist/cli/index.js +12 -0
- package/dist/core/artifact.js +20 -0
- package/dist/core/autosend.js +8 -0
- package/dist/core/history.js +5 -0
- package/dist/core/raised.js +39 -1
- package/dist/core/refresh.js +16 -0
- package/dist/core/revise.js +13 -3
- package/dist/core/state.js +12 -2
- package/dist/runner/chat.js +47 -2
- package/dist/runner/claude.js +56 -2
- package/dist/runner/review.js +21 -2
- package/dist/server/daemon.js +1 -0
- package/dist/server/index.js +112 -24
- package/package.json +2 -1
- package/web/dist/assets/index-BFMebSDr.js +250 -0
- package/web/dist/assets/{index-C1O70i8E.css → index-BjMp9wRh.css} +1 -1
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-C09rdnDK.js +0 -248
package/README.md
CHANGED
|
@@ -429,8 +429,31 @@ cockpit (or `cerber review <pr> --force`).
|
|
|
429
429
|
> starts and they do not come back, on success or on failure. This is a
|
|
430
430
|
> decision, not a bug ([`docs/lifecycle.md`](docs/lifecycle.md)): the run owns
|
|
431
431
|
> the draft. If you have written comments you want to keep, send the review or
|
|
432
|
-
> copy them out first. Your *decisions* do survive — a
|
|
433
|
-
>
|
|
432
|
+
> copy them out first. Your *decisions* do survive — a `reviewed` or `skipped`
|
|
433
|
+
> you set and the chat transcript are kept, and a send is kept as a record of
|
|
434
|
+
> what went to GitHub (see the next section).
|
|
435
|
+
|
|
436
|
+
### Re-reviewing one you already sent
|
|
437
|
+
|
|
438
|
+
Sending freezes the draft — it is the record of what GitHub has, so nothing
|
|
439
|
+
can edit it afterwards. What you can do is replace it. The same **Re-review at
|
|
440
|
+
head** button works on a sent review, and on a PR whose author has pushed
|
|
441
|
+
since it is the only thing that does: the review you sent answers a commit
|
|
442
|
+
that is gone, and cerber will not rewrite a review that is already public.
|
|
443
|
+
|
|
444
|
+
The run drafts against the current head and hands you an ordinary unsent
|
|
445
|
+
review again — editable, arguable, sendable. What you sent is kept beside it:
|
|
446
|
+
a note above the draft says what you posted and when, with a link, and the
|
|
447
|
+
line over the Send button says the next click would be review 2. **Nothing on
|
|
448
|
+
GitHub changes** — a second review sits beside the first; cerber never edits
|
|
449
|
+
or withdraws what it posted.
|
|
450
|
+
|
|
451
|
+
The poll does this on its own, too, for a sent review whose PR moved on and
|
|
452
|
+
whose author has asked you for another look. The two things that can reach
|
|
453
|
+
GitHub without you both stand down on a row like that: auto-send will not
|
|
454
|
+
approve a PR you have already reviewed yourself, and a handoff stops offering
|
|
455
|
+
to carry the draft — it is a new draft, but sending it would still be your
|
|
456
|
+
second review on that PR.
|
|
434
457
|
|
|
435
458
|
## Arguing with the review before you send it
|
|
436
459
|
|
|
@@ -488,7 +511,8 @@ the exchange went anywhere near GitHub.
|
|
|
488
511
|
Nothing in the conversation reaches GitHub. Send still builds its payload from
|
|
489
512
|
the summary, comments and verdict alone, and is still one deliberate click. A
|
|
490
513
|
review that has already been sent can't be argued with: that artifact is the
|
|
491
|
-
record of what GitHub has
|
|
514
|
+
record of what GitHub has — re-review it first, and the new draft is open to
|
|
515
|
+
the conversation like any other.
|
|
492
516
|
|
|
493
517
|
## Every row remembers what happened to it
|
|
494
518
|
|
package/dist/cli/index.js
CHANGED
|
@@ -231,6 +231,18 @@ program
|
|
|
231
231
|
}
|
|
232
232
|
const payload = buildReviewPayload(artifact, event);
|
|
233
233
|
console.log(`About to send to ${artifact.pr.url}:`);
|
|
234
|
+
// Said before anything else about the payload: on a PR you have already
|
|
235
|
+
// reviewed, "what is in this review" is the second question. The cockpit's
|
|
236
|
+
// send panel says the same thing in the same place (SPEC §8.3).
|
|
237
|
+
const posted = artifact.priorSends;
|
|
238
|
+
if (posted.length > 0) {
|
|
239
|
+
const last = posted[posted.length - 1];
|
|
240
|
+
const when = new Date(last.at).toLocaleDateString();
|
|
241
|
+
console.log(` ⚠ you already sent ${posted.length === 1 ? "a review" : `${posted.length} reviews`}` +
|
|
242
|
+
` on this PR${posted.length === 1 ? "" : ", the last"} on ${when}` +
|
|
243
|
+
` as ${last.event.toLowerCase().replace("_", " ")}${last.url ? ` (${last.url})` : ""}.` +
|
|
244
|
+
` This would be review ${posted.length + 1}; it sits beside them, replacing nothing.`);
|
|
245
|
+
}
|
|
234
246
|
console.log(` event: ${event}`);
|
|
235
247
|
console.log(` inline comments: ${payload.comments.length}`);
|
|
236
248
|
if (payload.folded.length > 0) {
|
package/dist/core/artifact.js
CHANGED
|
@@ -340,6 +340,8 @@ export const ChatTurnSchema = z.object({
|
|
|
340
340
|
/** Edits this turn asked for but the artifact would not accept. */
|
|
341
341
|
refused: z.array(RefusalSchema).default([]),
|
|
342
342
|
costUsd: z.number().nullable().default(null),
|
|
343
|
+
/** A user turn sent while the previous one was still being answered. */
|
|
344
|
+
steer: z.boolean().optional(),
|
|
343
345
|
});
|
|
344
346
|
/**
|
|
345
347
|
* The chat turn being answered right now — or the one that failed.
|
|
@@ -361,6 +363,8 @@ export const PendingChatSchema = z.object({
|
|
|
361
363
|
* only honest account of them; it is thrown away when the answer lands.
|
|
362
364
|
*/
|
|
363
365
|
progress: z.array(z.string()).default([]),
|
|
366
|
+
/** What the user added while it worked — each one went into the live run. */
|
|
367
|
+
steers: z.array(z.string()).default([]),
|
|
364
368
|
/** Why the turn failed. Null while it is still running. */
|
|
365
369
|
error: z.string().nullable().default(null),
|
|
366
370
|
});
|
|
@@ -403,6 +407,22 @@ export const ArtifactSchema = z.object({
|
|
|
403
407
|
run: RunInfoSchema.nullable().default(null),
|
|
404
408
|
/** Set once the review was sent to GitHub (explicitly, or via opt-in auto-send). */
|
|
405
409
|
sent: SentInfoSchema.nullable().default(null),
|
|
410
|
+
/**
|
|
411
|
+
* Reviews posted from this row that a later re-review has since replaced,
|
|
412
|
+
* oldest first.
|
|
413
|
+
*
|
|
414
|
+
* `sent` means "the draft on this page is the one that went to GitHub", and
|
|
415
|
+
* every guard in cerber reads it that way — the send path's "already sent"
|
|
416
|
+
* refusal most of all. So when a re-review replaces that draft the send
|
|
417
|
+
* cannot stay in the field (the new draft was never sent) and must not simply
|
|
418
|
+
* go (it is on the PR, under the user's name, for good). It moves here.
|
|
419
|
+
*
|
|
420
|
+
* What it buys is a cockpit that can say "you reviewed this on the 14th" over
|
|
421
|
+
* a draft of the 16th, and a send panel that says the next click posts a
|
|
422
|
+
* second review rather than a first. The GitHub URL rides along, because the
|
|
423
|
+
* record is only useful if the thing it names can be opened.
|
|
424
|
+
*/
|
|
425
|
+
priorSends: z.array(SentInfoSchema).default([]),
|
|
406
426
|
/** Set when cerber filed this draft away itself, and why. Never on a sent one. */
|
|
407
427
|
filed: FiledInfoSchema.nullable().default(null),
|
|
408
428
|
/** Set when you gave this review to somebody else. Mutually exclusive with `filed`. */
|
package/dist/core/autosend.js
CHANGED
|
@@ -13,6 +13,14 @@ import { sendTreatment } from "./raised.js";
|
|
|
13
13
|
export function evaluateAutoSend(artifact, threshold) {
|
|
14
14
|
if (artifact.sent)
|
|
15
15
|
return { eligible: false, reason: "already sent" };
|
|
16
|
+
// The same rule, for a send a re-review has since superseded. `sent` only
|
|
17
|
+
// ever describes the draft on the row, so once one moves to `priorSends`
|
|
18
|
+
// that guard stops seeing it — and "never a re-send" would quietly come to
|
|
19
|
+
// mean "never twice in a row". A PR this user has already reviewed is the
|
|
20
|
+
// last place to post unattended: the second review is theirs to send.
|
|
21
|
+
if (artifact.priorSends.length > 0) {
|
|
22
|
+
return { eligible: false, reason: "a review was already sent on this PR — the next one is yours to send" };
|
|
23
|
+
}
|
|
16
24
|
if (artifact.status !== "ready")
|
|
17
25
|
return { eligible: false, reason: `status is ${artifact.status}` };
|
|
18
26
|
if (!artifact.verdict)
|
package/dist/core/history.js
CHANGED
|
@@ -174,6 +174,11 @@ export function describeChange(before, after) {
|
|
|
174
174
|
lines.push(`sent to GitHub as ${after.sent.event.toLowerCase().replace("_", " ")}` +
|
|
175
175
|
`${after.sent.auto ? ", by auto-send" : ""}`);
|
|
176
176
|
}
|
|
177
|
+
// The one state change nothing else on this list would record: the row went
|
|
178
|
+
// from "this draft is on GitHub" back to "this draft has never been sent".
|
|
179
|
+
if (after.priorSends.length > (before?.priorSends.length ?? 0)) {
|
|
180
|
+
lines.push("a new draft took over from the review that was sent — what was sent stays on GitHub");
|
|
181
|
+
}
|
|
177
182
|
if (after.filed && after.filed.at !== before?.filed?.at) {
|
|
178
183
|
lines.push(`filed under settled — ${FILED_PHRASE[after.filed.reason] ?? after.filed.reason}`);
|
|
179
184
|
}
|
package/dist/core/raised.js
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* Undecided is not "post": a duplicate the user never looked at is exactly what
|
|
6
6
|
* this exists to keep off the PR. The one place undecided still posts is a
|
|
7
7
|
* resolved thread — somebody marked that problem settled, and a review that
|
|
8
|
-
* found it again in the current code is saying it isn't.
|
|
8
|
+
* found it again in the current code is saying it isn't. A finding the user
|
|
9
|
+
* has rewritten is not undecided at all: `rewriteFinding` decides it.
|
|
9
10
|
*/
|
|
10
11
|
export function sendTreatment(comment) {
|
|
11
12
|
const raised = comment.alreadyRaised;
|
|
@@ -19,6 +20,43 @@ export function sendTreatment(comment) {
|
|
|
19
20
|
return raised.where.kind === "thread" ? "reply" : "hold";
|
|
20
21
|
return raised.where.kind === "thread" && raised.where.state === "resolved" ? "post" : "hold";
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Rewrite a finding's body — and, where somebody else had raised it, let the
|
|
25
|
+
* rewrite be the decision.
|
|
26
|
+
*
|
|
27
|
+
* An undecided match is Send leaving the duplicate out, and that default is
|
|
28
|
+
* about one thing: nobody has looked at it yet. Rewriting the finding is
|
|
29
|
+
* looking at it. The words that would post are no longer the ones the check
|
|
30
|
+
* compared — they are what the user asked for, by hand or through the chat —
|
|
31
|
+
* and cerber does not hold back what the user wrote. A finding is compared
|
|
32
|
+
* once for the same reason (`whatToCompare`): the user who rewrote it is the
|
|
33
|
+
* one deciding about it.
|
|
34
|
+
*
|
|
35
|
+
* The match itself stays, with who raised it, where, and why the two are the
|
|
36
|
+
* same defect: the cockpit still shows all of it, and "send anyway" toggles
|
|
37
|
+
* straight back off. A decision already made is left alone — including
|
|
38
|
+
* `reply`, which keeps answering in their thread, in the new words.
|
|
39
|
+
*
|
|
40
|
+
* Only a match that would otherwise be held is decided. On a resolved thread
|
|
41
|
+
* the default already posts, and writing the decision down there would trade a
|
|
42
|
+
* state that follows the thread for one that doesn't: the cockpit would stop
|
|
43
|
+
* saying *why* it posts, and the finding would keep posting if somebody
|
|
44
|
+
* reopened that thread. Nothing is held, so there is nothing to decide — which
|
|
45
|
+
* goes for a dropped comment too, where drop decides it and the cockpit shows
|
|
46
|
+
* no toggle to take it back with.
|
|
47
|
+
*/
|
|
48
|
+
export function rewriteFinding(comment, body) {
|
|
49
|
+
if (body === comment.body)
|
|
50
|
+
return comment;
|
|
51
|
+
const raised = comment.alreadyRaised;
|
|
52
|
+
const held = comment.status !== "dropped" &&
|
|
53
|
+
raised != null &&
|
|
54
|
+
raised.decision === null &&
|
|
55
|
+
sendTreatment({ alreadyRaised: raised }) === "hold";
|
|
56
|
+
if (!held)
|
|
57
|
+
return { ...comment, body };
|
|
58
|
+
return { ...comment, body, alreadyRaised: { ...raised, decision: "send" } };
|
|
59
|
+
}
|
|
22
60
|
/**
|
|
23
61
|
* Which match a comment keeps when several remarks raised the same thing:
|
|
24
62
|
* the liveliest place first, because that is what decides whether posting it
|
package/dist/core/refresh.js
CHANGED
|
@@ -44,6 +44,19 @@ export function refreshArtifact(artifact, pr, diff) {
|
|
|
44
44
|
export function userOwnsStatus(a) {
|
|
45
45
|
return a.sent !== null || a.status === "reviewed" || a.status === "skipped";
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* This row's sends, with the one a starting run is about to supersede folded in.
|
|
49
|
+
*
|
|
50
|
+
* The only way back into a review that was sent is a new draft, and `sent`
|
|
51
|
+
* describes a draft that is about to stop existing — so it cannot stay where
|
|
52
|
+
* it is. It also cannot simply go: that review is on the PR under the user's
|
|
53
|
+
* name, and a cockpit that forgets it would offer a second one as if it were
|
|
54
|
+
* the first. Called by the claim at the top of a run, which is the one moment
|
|
55
|
+
* a send stops covering what is on the page.
|
|
56
|
+
*/
|
|
57
|
+
export function supersede(a) {
|
|
58
|
+
return a.sent ? [...a.priorSends, a.sent] : a.priorSends;
|
|
59
|
+
}
|
|
47
60
|
/**
|
|
48
61
|
* Fold a finished review run onto whatever the artifact says now.
|
|
49
62
|
*
|
|
@@ -76,6 +89,9 @@ export function mergeRunResult(fresh, current) {
|
|
|
76
89
|
// the stamp away with the status.
|
|
77
90
|
settledAt: userOwnsStatus(current) ? current.settledAt : fresh.settledAt,
|
|
78
91
|
sent: current.sent,
|
|
92
|
+
// Written by this run's own claim (`supersede`), or by an earlier one —
|
|
93
|
+
// either way the disk is the only copy; `fresh` was built before the claim.
|
|
94
|
+
priorSends: current.priorSends,
|
|
79
95
|
// Disk wins: the ledger is the poll's, and the run knows nothing about it.
|
|
80
96
|
notified: current.notified,
|
|
81
97
|
calibration: current.calibration,
|
package/dist/core/revise.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { rewriteFinding } from "./raised.js";
|
|
2
3
|
/** The review as it stands, for restoring later. */
|
|
3
4
|
export function snapshotReview(artifact, at) {
|
|
4
5
|
return {
|
|
@@ -43,10 +44,17 @@ export function mergeConcurrentEdits(before, after, current) {
|
|
|
43
44
|
};
|
|
44
45
|
const merged = current.comments.map((now) => {
|
|
45
46
|
const chosen = userTouched(now.id, now) ? now : fromTurn.get(now.id) ?? now;
|
|
47
|
+
if (chosen === now)
|
|
48
|
+
return now;
|
|
46
49
|
// Who else raised a comment is the check's to say, not the turn's: a check
|
|
47
50
|
// that landed while the turn ran — and a decision made about it — is only
|
|
48
51
|
// on disk, and the turn's copy predates both.
|
|
49
|
-
|
|
52
|
+
const onDisk = { ...chosen, body: now.body, alreadyRaised: now.alreadyRaised };
|
|
53
|
+
// The rewrite the turn made still decides an undecided match, as any
|
|
54
|
+
// rewrite does — measured against the body on disk, so a turn that changed
|
|
55
|
+
// nothing decides nothing. Never on a sent review: that is a record of what
|
|
56
|
+
// was posted, and nothing on it is re-decided, here or anywhere else.
|
|
57
|
+
return current.sent ? { ...onDisk, body: chosen.body } : rewriteFinding(onDisk, chosen.body);
|
|
50
58
|
});
|
|
51
59
|
// Comments the turn itself added are not in `current` yet. Only those: a
|
|
52
60
|
// comment present in both `before` and `after` but missing from `current` is
|
|
@@ -138,8 +146,10 @@ export function applyRevisions(artifact, revisions, opts = {}) {
|
|
|
138
146
|
...next,
|
|
139
147
|
comments: next.comments.map((c) => c.id === revision.commentId
|
|
140
148
|
? {
|
|
141
|
-
|
|
142
|
-
|
|
149
|
+
// A rewrite the user asked for decides a duplicate nobody
|
|
150
|
+
// had decided about: what posts is their words now, not the
|
|
151
|
+
// ones the check compared (`rewriteFinding`).
|
|
152
|
+
...rewriteFinding(c, revision.body),
|
|
143
153
|
// Omitted = the turn is not re-grading; null = "not a finding".
|
|
144
154
|
severity: revision.severity === undefined ? c.severity : revision.severity,
|
|
145
155
|
}
|
package/dist/core/state.js
CHANGED
|
@@ -197,11 +197,18 @@ export async function reconcileRunning(opts = {}) {
|
|
|
197
197
|
const stuckCheck = artifact.raisedCheck?.checkingSince != null;
|
|
198
198
|
if (!stuckRun && !stuckChat && !stuckCheck)
|
|
199
199
|
continue;
|
|
200
|
+
// A row still carrying its send was interrupted before the run claimed it,
|
|
201
|
+
// so the draft on it is untouched — and it is the one that went to GitHub.
|
|
202
|
+
// "failed" would hide a sent review behind a broken re-review, and the
|
|
203
|
+
// interruption belongs to the re-review rather than to the run block,
|
|
204
|
+
// which still describes the review that was posted. It goes to the history
|
|
205
|
+
// instead, which is where a thing that happened *to* a row belongs.
|
|
206
|
+
const interruptedSend = stuckRun && artifact.sent != null;
|
|
200
207
|
await saveArtifact({
|
|
201
208
|
...artifact,
|
|
202
|
-
status: stuckRun ? "failed" : artifact.status,
|
|
209
|
+
status: stuckRun ? (artifact.sent ? "sent" : "failed") : artifact.status,
|
|
203
210
|
updatedAt: new Date().toISOString(),
|
|
204
|
-
run: stuckRun && artifact.run
|
|
211
|
+
run: stuckRun && artifact.run && !interruptedSend
|
|
205
212
|
? { ...artifact.run, error: "interrupted — cerber restarted while this review was running" }
|
|
206
213
|
: artifact.run,
|
|
207
214
|
pendingChat: stuckChat
|
|
@@ -211,6 +218,9 @@ export async function reconcileRunning(opts = {}) {
|
|
|
211
218
|
// report, and the next open starts another.
|
|
212
219
|
raisedCheck: artifact.raisedCheck && { ...artifact.raisedCheck, checkingSince: null },
|
|
213
220
|
});
|
|
221
|
+
if (interruptedSend) {
|
|
222
|
+
await noteHistory(artifact.id, "re-review interrupted — cerber restarted; the sent review is untouched");
|
|
223
|
+
}
|
|
214
224
|
cleared++;
|
|
215
225
|
}
|
|
216
226
|
return cleared;
|
package/dist/runner/chat.js
CHANGED
|
@@ -75,6 +75,25 @@ async function isCheckedOut(dir) {
|
|
|
75
75
|
.then((s) => s.isDirectory())
|
|
76
76
|
.catch(() => false);
|
|
77
77
|
}
|
|
78
|
+
/** The live turns that can still take a message, by artifact id. */
|
|
79
|
+
const steerable = new Map();
|
|
80
|
+
/**
|
|
81
|
+
* Add a message to the turn being answered for this review, mid-run.
|
|
82
|
+
*
|
|
83
|
+
* False when there is no turn to add it to — none running, it is retrying its
|
|
84
|
+
* JSON, or it has already answered — so the caller can say "send it as the next
|
|
85
|
+
* message" rather than claim it landed.
|
|
86
|
+
*/
|
|
87
|
+
export function steerChatTurn(artifactId, message) {
|
|
88
|
+
return steerable.get(artifactId)?.(message) ?? false;
|
|
89
|
+
}
|
|
90
|
+
function steerPrompt(message) {
|
|
91
|
+
return `The user adds, while you work on this turn:
|
|
92
|
+
|
|
93
|
+
${message}
|
|
94
|
+
|
|
95
|
+
Take it into account. Your answer is still the one JSON object described earlier, with "reply" and "revisions" — and the reply should say what you did about this.`;
|
|
96
|
+
}
|
|
78
97
|
/**
|
|
79
98
|
* Append the user's message and the reviewer's answer, applying whatever the
|
|
80
99
|
* answer revised. Claims the artifact's inflight slot for the duration: the
|
|
@@ -142,11 +161,36 @@ async function turn(artifact, message, opts) {
|
|
|
142
161
|
isolateWorkspace: !(source && trusted),
|
|
143
162
|
resumeSessionId,
|
|
144
163
|
};
|
|
164
|
+
// Steers in the order they went in, stamped as they did: each is its own user
|
|
165
|
+
// turn in the transcript, between the question and the answer.
|
|
166
|
+
const steers = [];
|
|
167
|
+
const onSteer = (send) => {
|
|
168
|
+
if (!send) {
|
|
169
|
+
steerable.delete(artifact.id);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
steerable.set(artifact.id, (text) => {
|
|
173
|
+
if (!send(steerPrompt(text)))
|
|
174
|
+
return false;
|
|
175
|
+
steers.push({
|
|
176
|
+
id: newId(),
|
|
177
|
+
role: "user",
|
|
178
|
+
at: now(),
|
|
179
|
+
body: text,
|
|
180
|
+
refs: [],
|
|
181
|
+
revisions: [],
|
|
182
|
+
refused: [],
|
|
183
|
+
costUsd: null,
|
|
184
|
+
steer: true,
|
|
185
|
+
});
|
|
186
|
+
return true;
|
|
187
|
+
});
|
|
188
|
+
};
|
|
145
189
|
let reply;
|
|
146
190
|
let costUsd;
|
|
147
191
|
let sessionId;
|
|
148
192
|
try {
|
|
149
|
-
const first = await run(prompt, claudeOpts);
|
|
193
|
+
const first = await run(prompt, { ...claudeOpts, onSteer });
|
|
150
194
|
try {
|
|
151
195
|
reply = AiChatTurnSchema.parse(extractJson(first.text));
|
|
152
196
|
costUsd = first.costUsd;
|
|
@@ -168,6 +212,7 @@ async function turn(artifact, message, opts) {
|
|
|
168
212
|
}
|
|
169
213
|
}
|
|
170
214
|
finally {
|
|
215
|
+
steerable.delete(artifact.id);
|
|
171
216
|
await removeRunDir(empty);
|
|
172
217
|
}
|
|
173
218
|
// The first turn snapshots the review, so "reset" always has somewhere to go
|
|
@@ -204,7 +249,7 @@ async function turn(artifact, message, opts) {
|
|
|
204
249
|
...revised.artifact,
|
|
205
250
|
updatedAt: assistantTurn.at,
|
|
206
251
|
preChat,
|
|
207
|
-
chat: [...artifact.chat, userTurn, assistantTurn],
|
|
252
|
+
chat: [...artifact.chat, userTurn, ...steers, assistantTurn],
|
|
208
253
|
run: artifact.run ? { ...artifact.run, sessionId: sessionId ?? artifact.run.sessionId } : null,
|
|
209
254
|
},
|
|
210
255
|
applied: revised.applied,
|
package/dist/runner/claude.js
CHANGED
|
@@ -46,6 +46,10 @@ export function buildClaudeArgs(opts) {
|
|
|
46
46
|
// and everything before it is the run saying what it is doing. `--verbose` is
|
|
47
47
|
// not optional — the CLI refuses the combination without it.
|
|
48
48
|
const args = ["-p", "--output-format", "stream-json", "--verbose"];
|
|
49
|
+
// Echoing our own messages back is how a run says it took a steer — the only
|
|
50
|
+
// way to tell one that went in from one still sitting in the pipe.
|
|
51
|
+
if (opts.onSteer)
|
|
52
|
+
args.push("--input-format", "stream-json", "--replay-user-messages");
|
|
49
53
|
if (opts.resumeSessionId)
|
|
50
54
|
args.push("--resume", opts.resumeSessionId);
|
|
51
55
|
if (opts.model)
|
|
@@ -126,14 +130,40 @@ export function runClaude(prompt, opts = {}) {
|
|
|
126
130
|
child.stdout.destroy();
|
|
127
131
|
child.stderr.destroy();
|
|
128
132
|
child.stdin.destroy();
|
|
133
|
+
stopSteering();
|
|
129
134
|
settle(() => reject(new Error(`claude did not finish within ${Math.round(timeoutMs / 60_000)} minutes — run killed.`)));
|
|
130
135
|
}, timeoutMs);
|
|
136
|
+
// Messages written vs echoed back. stdin closes on a result only once every
|
|
137
|
+
// steer has been taken: one that lands as the answer is being written starts
|
|
138
|
+
// a second pass, and closing on the first result would end the run with the
|
|
139
|
+
// steer unread. The last result is the answer either way.
|
|
140
|
+
let written = 0;
|
|
141
|
+
let echoed = 0;
|
|
142
|
+
const steering = Boolean(opts.onSteer);
|
|
143
|
+
const userMessage = (text) => JSON.stringify({ type: "user", message: { role: "user", content: text } }) + "\n";
|
|
144
|
+
let open = steering;
|
|
145
|
+
const stopSteering = () => {
|
|
146
|
+
if (!open)
|
|
147
|
+
return;
|
|
148
|
+
open = false;
|
|
149
|
+
opts.onSteer?.(null);
|
|
150
|
+
};
|
|
151
|
+
const closeInput = () => {
|
|
152
|
+
if (!open)
|
|
153
|
+
return;
|
|
154
|
+
stopSteering();
|
|
155
|
+
child.stdin.end();
|
|
156
|
+
};
|
|
131
157
|
const ingest = (chunk) => {
|
|
132
158
|
const read = readEvents(unread + chunk);
|
|
133
159
|
unread = read.rest;
|
|
134
160
|
for (const event of read.events) {
|
|
135
161
|
if (event.type === "result")
|
|
136
162
|
result = event;
|
|
163
|
+
if (steering && event.type === "user" && isEchoedMessage(event))
|
|
164
|
+
echoed++;
|
|
165
|
+
if (steering && event.type === "result" && echoed >= written)
|
|
166
|
+
closeInput();
|
|
137
167
|
// A throwing listener must not take the run down with it: the answer is
|
|
138
168
|
// the point, the narration is not.
|
|
139
169
|
try {
|
|
@@ -150,9 +180,11 @@ export function runClaude(prompt, opts = {}) {
|
|
|
150
180
|
});
|
|
151
181
|
child.stderr.on("data", (d) => (stderr += d));
|
|
152
182
|
child.on("error", (err) => {
|
|
183
|
+
stopSteering();
|
|
153
184
|
settle(() => reject(new Error(`Failed to start claude CLI: ${err.message}. Is Claude Code installed and on PATH?`)));
|
|
154
185
|
});
|
|
155
186
|
child.on("close", (code) => {
|
|
187
|
+
stopSteering();
|
|
156
188
|
if (settled)
|
|
157
189
|
return;
|
|
158
190
|
clearTimeout(timer);
|
|
@@ -177,10 +209,32 @@ export function runClaude(prompt, opts = {}) {
|
|
|
177
209
|
sessionId: typeof wrapper.session_id === "string" ? wrapper.session_id : null,
|
|
178
210
|
});
|
|
179
211
|
});
|
|
180
|
-
|
|
181
|
-
|
|
212
|
+
// A run that dies early closes the pipe under a write; the close handler
|
|
213
|
+
// says why, so the EPIPE itself has nothing to add.
|
|
214
|
+
child.stdin.on("error", () => { });
|
|
215
|
+
if (!steering) {
|
|
216
|
+
child.stdin.write(prompt);
|
|
217
|
+
child.stdin.end();
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
written++;
|
|
221
|
+
child.stdin.write(userMessage(prompt));
|
|
222
|
+
opts.onSteer((text) => {
|
|
223
|
+
if (!open)
|
|
224
|
+
return false;
|
|
225
|
+
written++;
|
|
226
|
+
child.stdin.write(userMessage(text));
|
|
227
|
+
return true;
|
|
228
|
+
});
|
|
182
229
|
});
|
|
183
230
|
}
|
|
231
|
+
/** A user event carrying our own words back, as opposed to a tool's result. */
|
|
232
|
+
function isEchoedMessage(event) {
|
|
233
|
+
const content = event.message?.content;
|
|
234
|
+
if (typeof content === "string")
|
|
235
|
+
return true;
|
|
236
|
+
return Array.isArray(content) && content.length > 0 && content.every((b) => b?.type === "text");
|
|
237
|
+
}
|
|
184
238
|
/** Extract a JSON object from model output that may be wrapped in fences or prose. */
|
|
185
239
|
export function extractJson(text) {
|
|
186
240
|
const trimmed = text.trim();
|
package/dist/runner/review.js
CHANGED
|
@@ -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, userOwnsStatus } from "../core/refresh.js";
|
|
5
|
+
import { 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";
|
|
@@ -191,13 +191,19 @@ async function performReview(ref, pr, existing, opts, log) {
|
|
|
191
191
|
trigger: opts.trigger ?? "user",
|
|
192
192
|
reviewedSha: null,
|
|
193
193
|
},
|
|
194
|
+
// Both filled in at the claim below, from the row as it stands then: a
|
|
195
|
+
// send this run supersedes moves to `priorSends` rather than vanishing.
|
|
194
196
|
sent: null,
|
|
197
|
+
priorSends: [],
|
|
195
198
|
refresh: null,
|
|
196
199
|
// A new draft has new findings, compared afresh once the run has written them.
|
|
197
200
|
raisedCheck: null,
|
|
198
201
|
filed: null,
|
|
199
202
|
handoff: null,
|
|
200
203
|
settledAt: null,
|
|
204
|
+
// Carried at the claim, not reset: it describes a review that really was
|
|
205
|
+
// sent, and `cerber stats` is the only reader. Dropping it here
|
|
206
|
+
// would quietly delete one data point every time a sent PR is re-reviewed.
|
|
201
207
|
calibration: null,
|
|
202
208
|
// The conversation is the user's writing, so a re-review keeps it — the
|
|
203
209
|
// chat prompt replays the transcript, which is what makes it survive the
|
|
@@ -222,10 +228,23 @@ async function performReview(ref, pr, existing, opts, log) {
|
|
|
222
228
|
// (the guard above only lets a forced re-review that far), and claiming it is
|
|
223
229
|
// how the reopen happens at all. A settle that appeared since is the one this
|
|
224
230
|
// must not touch.
|
|
231
|
+
//
|
|
232
|
+
// A send is the one decision the claim takes *over* rather than leaves
|
|
233
|
+
// alone, because the only way to reopen a sent row is to replace the draft
|
|
234
|
+
// that was sent. It is not discarded: `supersede` files it under
|
|
235
|
+
// `priorSends`, so the cockpit can still say what went to GitHub and when,
|
|
236
|
+
// and the send panel knows the next click would post a second review.
|
|
237
|
+
// Read from `current` rather than `existing`, which is minutes old.
|
|
225
238
|
const decided = existing ? userOwnsStatus(existing) : false;
|
|
226
239
|
const claimed = await updateArtifactByKey(artifactKey(artifact.id), (current) => !decided && userOwnsStatus(current)
|
|
227
240
|
? current
|
|
228
|
-
: {
|
|
241
|
+
: {
|
|
242
|
+
...artifact,
|
|
243
|
+
notified: current.notified,
|
|
244
|
+
viewed: current.viewed,
|
|
245
|
+
priorSends: supersede(current),
|
|
246
|
+
calibration: current.calibration,
|
|
247
|
+
});
|
|
229
248
|
const held = claimed !== null && !decided && userOwnsStatus(claimed);
|
|
230
249
|
if (!held) {
|
|
231
250
|
if (claimed)
|