Add the Review Loop: unattended review-and-fix rounds in the desktop app and in loop phases

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-28 21:09:02 -08:00
1 parent d6a28b5dc8
commit 57567d7a0b
71 files changed
+11331 -443

No files matched your search

+99 -5
View File
@@ -1038,6 +1038,85 @@ window.addEventListener('message', (event) => {
invoke('loop_facts')
.then((facts) => source.postMessage({ plan2code: 'loop-facts', facts }, '*'))
.catch(() => {});
} else if (kind === 'review-loop-facts') {
// The Review Loop's setup screen asks what agent a run would use and
// whether it has helpers. Facts only; the page sends no setup value.
const source = event.source;
invoke('review_loop_facts')
.then((facts) => source.postMessage({ plan2code: 'review-loop-facts', facts }, '*'))
.catch(() => {});
} else if (kind === 'review-loop-start') {
// Start: the setup screen's picks, only the known fields and kinds. The
// notification address is never taken from the page; the app reads it.
const source = event.source;
const picked = event.data.setup && typeof event.data.setup === 'object' ? event.data.setup : {};
const text = (value) => (typeof value === 'string' ? value : '');
const flag = (value) => value === true;
const setup = {
scope: text(picked.scope),
spec: text(picked.spec),
cap: Number.isInteger(picked.cap) ? picked.cap : 3,
commit: picked.commit !== false,
preRunCommitAgreed: flag(picked.preRunCommitAgreed),
suggestions: flag(picked.suggestions),
strength: text(picked.strength),
silenceMinutes: Number.isInteger(picked.silenceMinutes) ? picked.silenceMinutes : 20,
notifyRounds: flag(picked.notifyRounds),
};
invoke('review_loop_start', { setup })
.then((started) => source.postMessage({ plan2code: 'review-loop-start-result', ok: true, started, error: null }, '*'))
.catch((error) =>
source.postMessage({ plan2code: 'review-loop-start-result', ok: false, started: false, error: String(error) }, '*')
);
} else if (kind === 'review-loop-continue') {
const source = event.source;
invoke('review_loop_continue')
.then(() => source.postMessage({ plan2code: 'review-loop-continue-result', ok: true, error: null }, '*'))
.catch((error) =>
source.postMessage({ plan2code: 'review-loop-continue-result', ok: false, error: String(error) }, '*')
);
} else if (kind === 'review-loop-partial') {
// Keep or Discard what Stop now left: one boolean, nothing else.
const source = event.source;
if (typeof event.data.keep !== 'boolean') {
// Discard cannot be undone: only an explicit true or false is a choice.
source.postMessage({ plan2code: 'review-loop-partial-result', ok: false, error: 'keep must be true or false' }, '*');
return;
}
invoke('review_loop_partial', { keep: event.data.keep })
.then(() => source.postMessage({ plan2code: 'review-loop-partial-result', ok: true, error: null }, '*'))
.catch((error) =>
source.postMessage({ plan2code: 'review-loop-partial-result', ok: false, error: String(error) }, '*')
);
} else if (kind === 'review-loop-sign-off') {
// Sign off: the ticked Suggestions by id and the squash switch, nothing else.
const source = event.source;
const { picks, squash } = event.data;
const refuse = (error) => source.postMessage({ plan2code: 'review-loop-sign-off-result', ok: false, error }, '*');
if (!Array.isArray(picks) || picks.length > 50 || !picks.every((id) => typeof id === 'string' && /^s[0-9]{1,3}$/.test(id))) {
refuse('picks must be a list of up to 50 suggestion ids');
return;
}
if (typeof squash !== 'boolean') {
refuse('squash must be true or false');
return;
}
invoke('review_loop_sign_off', { picks, squash })
.then(() => source.postMessage({ plan2code: 'review-loop-sign-off-result', ok: true, error: null }, '*'))
.catch((error) => refuse(String(error)));
} else if (kind === 'review-loop-next') {
// The finished screen's launch: one of two words, the app builds the brief.
const source = event.source;
const next = event.data.next;
if (next !== 'pr-prep' && next !== 'quick-task') {
source.postMessage({ plan2code: 'review-loop-next-result', ok: false, error: 'next must be pr-prep or quick-task' }, '*');
return;
}
invoke('review_loop_next', { next })
.then(() => source.postMessage({ plan2code: 'review-loop-next-result', ok: true, error: null }, '*'))
.catch((error) =>
source.postMessage({ plan2code: 'review-loop-next-result', ok: false, error: String(error) }, '*')
);
} else if (kind === 'loop-resume' || kind === 'loop-ask' || kind === 'loop-fix' || kind === 'loop-finalize') {
// Fixed requests, no free text: the page answers with ok or the error.
const source = event.source;
@@ -1628,6 +1707,19 @@ async function syncLoopState() {
}
}
// Which loop the strip is showing, so the stop buttons press the right commands.
let loopKind = 'phases';
// A pip's hover text: "Phase 2", or for a Review Loop round the counts it found
// ("Round 1: 2 Critical, 1 Warning"), "Round 3" for one not finished yet.
function roundPipTitle(state, i) {
if (state.kind !== 'rounds') return `Phase ${i + 1}`;
const counts = Array.isArray(state.roundCounts) ? state.roundCounts[i] : null;
if (!counts) return `Round ${i + 1}`;
const found = [counts.critical > 0 ? `${counts.critical} Critical` : '', counts.warning > 0 ? `${counts.warning} Warning` : ''].filter(Boolean);
return `Round ${i + 1}: ${found.length ? found.join(', ') : 'nothing found'}`;
}
function applyLoopState(state) {
if (!state || !state.running) {
const wasRunning = loopRunning;
@@ -1664,13 +1756,14 @@ function applyLoopState(state) {
...banner.pips.map((kind, i) => {
const pip = document.createElement('span');
pip.className = `loop-pip ${kind}`;
pip.title = `Phase ${i + 1}`;
pip.title = roundPipTitle(state, i);
return pip;
})
);
setLoopTitle(loopWindowTitle(projectPathEl.textContent, state));
const stopLabels = loopStopLabels(state);
loopStopAfterOn = !!state.stopAfterPhase;
loopStopAfterOn = !!(state.kind === 'rounds' ? state.stopAfterRound : state.stopAfterPhase);
loopKind = state.kind === 'rounds' ? 'rounds' : 'phases';
loopStopAfterBtn.disabled = stopLabels.afterDisabled;
loopStopAfterBtn.textContent = stopLabels.afterText;
loopStopNowBtn.disabled = stopLabels.nowDisabled;
@@ -1730,15 +1823,16 @@ function pressLoop(command, args) {
loopRetryBtn.onclick = () => {
if (loopRetryAction) loopRetryAction();
};
loopStopAfterBtn.onclick = () => pressLoop('loop_stop_after_phase', { on: !loopStopAfterOn });
loopStopAfterBtn.onclick = () => pressLoop(loopKind === 'rounds' ? 'review_loop_stop_after' : 'loop_stop_after_phase', { on: !loopStopAfterOn });
loopStopNowBtn.onclick = async () => {
const rounds = loopKind === 'rounds';
const yes = await confirmModal({
title: 'End the agent now?',
lines: [{ kind: 'text', text: "This phase's changes stay uncommitted." }],
lines: [{ kind: 'text', text: rounds ? "This round's changes stay uncommitted until you choose to keep or discard them." : "This phase's changes stay uncommitted." }],
primary: 'Stop now',
danger: true,
});
if (yes) pressLoop('loop_stop_now');
if (yes) pressLoop(rounds ? 'review_loop_stop_now' : 'loop_stop_now');
};
// The right end of the bar: whether the console stopped answering and where
+44 -2
View File
@@ -210,6 +210,11 @@ export function windowTitleFor(dir) {
*/
export function loopWindowTitle(dir, state) {
const name = lastSegment(dir);
if (state.kind === "rounds") {
const where = state.afterRounds || `Round ${state.round}`;
const round = state.step === "Waiting on you" ? `Review Loop needs you: ${where}` : state.afterRounds ? `Review Loop: ${state.afterRounds}` : `Review Loop: Round ${state.round} of ${state.rounds}`;
return name ? `${round} - ${name}` : round;
}
const what = state.step === "Waiting on you" ? `Loop needs you: Phase ${state.phase}` : `Loop: Phase ${state.phase} of ${state.phases}`;
return name ? `${what} - ${name}` : what;
}
@@ -221,6 +226,7 @@ export function loopWindowTitle(dir, state) {
* of the spec up to the last this run builds.
*/
export function loopBanner(state) {
if (state.kind === "rounds") return roundsBanner(state);
const { phase, phases, phaseName, step } = state;
const named = phaseName ? `Phase ${phase} of ${phases}: ${phaseName}` : `Phase ${phase} of ${phases}`;
const pips = Array.from({ length: Math.max(phases, 0) }, (_, i) => (i + 1 < phase ? "done" : i + 1 === phase ? "current" : "todo"));
@@ -247,6 +253,40 @@ export function loopBanner(state) {
return { ...base, title: "Implementation loop running", detail: ran ? `${where} \u00b7 ${ran}` : where };
}
/**
* The Review Loop's banner (`kind: "rounds"`): the same words as the phase banner
* with "round" for "phase", one pip per round up to the cap, and the detail line
* the app builds from the round, step and counts ("Round 2 of 3: Fixing 3 findings
* (1 Critical, 2 Warning)", carried in `phaseName`). After the rounds,
* `afterRounds` names the Suggestions batch or the final check, and every pip
* shows done.
*/
function roundsBanner(state) {
const { round, rounds, step } = state;
const after = state.afterRounds || "";
const named = after || `Round ${round} of ${rounds}`;
const detailLine = state.phaseName || (step ? `${named}: ${step}` : named);
const pips = Array.from({ length: Math.max(rounds, 0) }, (_, i) => (after || i + 1 < round ? "done" : i + 1 === round ? "current" : "todo"));
const base = { tone: "running", pips, hint: "Working on its own. You can walk away." };
if (state.stopping) {
return { ...base, title: "Stopping", detail: "The agent is ending. You will be asked what to do with the round's changes.", hint: "The stop screen follows in a moment." };
}
if (step === "Waiting on you") {
return { ...base, tone: "waiting", title: "The Review Loop needs your answer", detail: `${named} is waiting on the question below.`, hint: "Nothing is lost while it waits." };
}
if (state.stopAfterRound) {
return { ...base, title: "Stopping after this round", detail: `${named} finishes, is judged and committed, then the Review Loop stops.`, hint: "Stop now ends the agent at once." };
}
if (step === "Starting") {
if (state.phaseRetried) return { ...base, title: after ? `Retrying the ${after.toLowerCase()}` : `Retrying round ${round}`, detail: `The agent crashed or went quiet, so a fresh one is picking up ${after ? `the ${after.toLowerCase()}` : named}.` };
if (after) return { ...base, title: "Rounds done", detail: `Opening a fresh agent for the ${after.toLowerCase()}.` };
if (round > 1) return { ...base, title: `Round ${round - 1} done`, detail: `Opening a fresh agent for ${named}.` };
return { ...base, title: "Starting the Review Loop", detail: `Opening a fresh agent for ${named}.` };
}
const ran = loopRunText(state);
return { ...base, title: "Review Loop running", detail: ran ? `${detailLine} · ${ran}` : detailLine };
}
/**
* What the running phase runs on, from the app's `loop-state`: "Thrifty (sonnet,
* low)" for a phase on a strength, "(opus, high)" for a Match my session phase
@@ -267,9 +307,11 @@ export function loopRunText(state) {
*/
export function loopStopLabels(state) {
const stopping = Boolean(state.stopping);
const on = Boolean(state.stopAfterPhase);
const rounds = state.kind === "rounds";
const on = Boolean(rounds ? state.stopAfterRound : state.stopAfterPhase);
const unit = rounds ? "round" : "phase";
return {
afterText: on ? "Cancel stop after this phase" : "Stop after this phase",
afterText: on ? `Cancel stop after this ${unit}` : `Stop after this ${unit}`,
afterDisabled: stopping || (!on && state.canStopAfter === false),
nowDisabled: stopping,
};