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

+90 -2
View File
@@ -471,8 +471,9 @@ test("the stop buttons: Stop after is a toggle, off on the last phase, and both
test("app.js sends the toggle's wish and shows a failed press with a Retry", () => {
const app = fs.readFileSync(path.join(HERE, "..", "plan2code-app", "ui", "app.js"), "utf8");
assert.match(app, /invoke\(command, args\)\.then\(hideLoopError/, "a good press clears the error");
assert.match(app, /pressLoop\('loop_stop_after_phase', \{ on: !loopStopAfterOn \}\)/);
assert.match(app, /pressLoop\('loop_stop_now'\)/);
// The press goes to the phase commands for an Implementation Loop and to the Review Loop's own for rounds.
assert.match(app, /'loop_stop_after_phase', \{ on: !loopStopAfterOn \}\)/);
assert.match(app, /: 'loop_stop_now'\)/);
assert.match(app, /loopRetryBtn\.hidden = false/, "a failed press offers Retry");
const html = fs.readFileSync(path.join(HERE, "..", "plan2code-app", "ui", "index.html"), "utf8");
assert.match(html, /id="loop-error"[^>]*hidden/);
@@ -570,6 +571,93 @@ test("the banner and stop buttons agree for a state carrying stopping, stopAfter
assert.equal(loopStopLabels(last).afterDisabled, true);
});
// The Review Loop's banner: the same states in round words, one pip per round, and the detail the app builds.
const ROUNDS = { running: true, kind: "rounds", round: 2, rounds: 3, phase: 2, phases: 3, phaseName: "Round 2 of 3: Reviewing", step: "Reviewing", stopAfterRound: false, stopAfterPhase: false, stopping: false, canStopAfter: true, phaseRetried: false, roundCounts: [{ critical: 2, warning: 1 }] };
test("a rounds state says Review Loop, with one pip per round and the app's detail line", () => {
const banner = loopBanner(ROUNDS);
assert.equal(banner.title, "Review Loop running");
assert.equal(banner.detail, "Round 2 of 3: Reviewing");
assert.equal(banner.tone, "running");
assert.deepEqual(banner.pips, ["done", "current", "todo"]);
assert.deepEqual(loopBanner({ ...ROUNDS, round: 1 }).pips, ["current", "todo", "todo"]);
assert.deepEqual(loopBanner({ ...ROUNDS, round: 3 }).pips, ["done", "done", "current"]);
assert.deepEqual(loopBanner({ ...ROUNDS, rounds: 6, round: 4 }).pips, ["done", "done", "done", "current", "todo", "todo"]);
});
test("a rounds state in each step: fixing with counts, starting, retrying, waiting, stopping, stop after this round", () => {
const fixing = loopBanner({ ...ROUNDS, step: "Fixing", phaseName: "Round 2 of 3: Fixing 3 findings (1 Critical, 2 Warning)" });
assert.equal(fixing.title, "Review Loop running");
assert.equal(fixing.detail, "Round 2 of 3: Fixing 3 findings (1 Critical, 2 Warning)");
// Without the app's detail line the banner builds the plain one from the round and step.
assert.equal(loopBanner({ ...ROUNDS, step: "Testing", phaseName: "" }).detail, "Round 2 of 3: Testing");
assert.equal(loopBanner({ ...ROUNDS, step: "Testing", phaseName: "Round 2 of 3: Testing", model: "sonnet", effort: "low", strength: "thrifty" }).detail, "Round 2 of 3: Testing \u00b7 Thrifty (sonnet, low)");
const first = loopBanner({ ...ROUNDS, round: 1, step: "Starting" });
assert.equal(first.title, "Starting the Review Loop");
assert.equal(first.detail, "Opening a fresh agent for Round 1 of 3.");
const next = loopBanner({ ...ROUNDS, step: "Starting" });
assert.equal(next.title, "Round 1 done");
assert.equal(next.detail, "Opening a fresh agent for Round 2 of 3.");
const retry = loopBanner({ ...ROUNDS, step: "Starting", phaseRetried: true });
assert.equal(retry.title, "Retrying round 2");
assert.match(retry.detail, /crashed or went quiet, so a fresh one is picking up Round 2 of 3/);
const waiting = loopBanner({ ...ROUNDS, step: "Waiting on you" });
assert.equal(waiting.title, "The Review Loop needs your answer");
assert.equal(waiting.tone, "waiting");
assert.equal(waiting.detail, "Round 2 of 3 is waiting on the question below.");
const stopping = loopBanner({ ...ROUNDS, stopping: true });
assert.equal(stopping.title, "Stopping");
assert.deepEqual(stopping.pips, ["done", "current", "todo"]);
const after = loopBanner({ ...ROUNDS, stopAfterRound: true, stopAfterPhase: true });
assert.equal(after.title, "Stopping after this round");
assert.match(after.detail, /Round 2 of 3 finishes, is judged and committed, then the Review Loop stops/);
});
test("a rounds state's stop buttons and window title use round words", () => {
assert.deepEqual(loopStopLabels(ROUNDS), { afterText: "Stop after this round", afterDisabled: false, nowDisabled: false });
assert.deepEqual(loopStopLabels({ ...ROUNDS, stopAfterRound: true }), { afterText: "Cancel stop after this round", afterDisabled: false, nowDisabled: false });
assert.equal(loopStopLabels({ ...ROUNDS, canStopAfter: false }).afterDisabled, true, "the cap round has nothing to stop after");
assert.deepEqual(loopStopLabels({ ...ROUNDS, stopping: true }), { afterText: "Stop after this round", afterDisabled: true, nowDisabled: true });
assert.equal(loopWindowTitle("C:/git/lunch", ROUNDS), "Review Loop: Round 2 of 3 - lunch");
assert.equal(loopWindowTitle("C:/git/lunch", { ...ROUNDS, step: "Waiting on you" }), "Review Loop needs you: Round 2 - lunch");
});
test("the Suggestions batch and final check are named for what they are, never as a round past the cap", () => {
const batch = { ...ROUNDS, round: 3, phase: 3, afterRounds: "Suggestions batch", phaseName: "Suggestions batch: Fixing", step: "Fixing" };
const shown = loopBanner(batch);
assert.equal(shown.detail, "Suggestions batch: Fixing");
assert.deepEqual(shown.pips, ["done", "done", "done"]);
assert.equal(loopBanner({ ...batch, step: "Starting" }).detail, "Opening a fresh agent for the suggestions batch.");
assert.equal(loopWindowTitle("C:/git/lunch", { ...batch, afterRounds: "Final check" }), "Review Loop: Final check - lunch");
assert.doesNotMatch(JSON.stringify(shown), /Round 4|of 3: Fixing/);
});
test("a phases state renders exactly as before, whatever kind it names", () => {
const phases = { running: true, phase: 2, phases: 4, phaseName: "API", step: "Build", stopAfterPhase: false, stopping: false, canStopAfter: true };
const plain = loopBanner(phases);
assert.equal(plain.title, "Implementation loop running");
assert.equal(plain.detail, "Phase 2 of 4: API \u00b7 Build");
assert.deepEqual(plain.pips, ["done", "current", "todo", "todo"]);
assert.deepEqual(loopBanner({ ...phases, kind: "phases", round: 0, rounds: 0, roundCounts: [], stopAfterRound: false }), plain);
assert.deepEqual(loopStopLabels({ ...phases, kind: "phases" }), loopStopLabels(phases));
assert.equal(loopWindowTitle("C:/git/lunch", { ...phases, kind: "phases" }), "Loop: Phase 2 of 4 - lunch");
});
test("app.js hangs round counts on the pips and sends the Review Loop's stop buttons to its own commands", () => {
assert.match(APP_JS, /function roundPipTitle\(state, i\)/);
assert.match(APP_JS, /pip\.title = roundPipTitle\(state, i\)/);
const title = APP_JS.slice(APP_JS.indexOf("function roundPipTitle"), APP_JS.indexOf("function applyLoopState"));
assert.match(title, /if \(state\.kind !== 'rounds'\) return `Phase \$\{i \+ 1\}`/, "a phases pip keeps its title");
assert.match(title, /Round \$\{i \+ 1\}: \$\{found\.length \? found\.join\(', '\) : 'nothing found'\}/);
assert.match(APP_JS, /pressLoop\(loopKind === 'rounds' \? 'review_loop_stop_after' : 'loop_stop_after_phase'/);
assert.match(APP_JS, /pressLoop\(rounds \? 'review_loop_stop_now' : 'loop_stop_now'\)/);
assert.match(APP_JS, /loopStopAfterOn = !!\(state\.kind === 'rounds' \? state\.stopAfterRound : state\.stopAfterPhase\)/);
});
test("app.js asks loop_state after attach and again once it listens, without calling a reload a loop's end", () => {
assert.match(APP_JS, /async function syncLoopState\(\)[\s\S]*?invoke\('loop_state'\)/);
assert.match(APP_JS, /\.listen\('loop-state'[\s\S]*?\.then\(syncLoopState/, "asked again once the listener is up");