mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-29 05:11:19 -08:00
Add the Review Loop: unattended review-and-fix rounds in the desktop app and in loop phases
AI Assisted
This commit is contained in:
1 parent
d6a28b5dc8
commit
57567d7a0b
71 files changed
+11331
-443
No files matched your search
+99
-5
@@ -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
|
||||
|
||||
Reference in new issue
Block a user