mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-29 13:21:18 -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
@@ -18,6 +18,7 @@ use plan2code_app_lib::node_check;
|
||||
use plan2code_app_lib::project::{self, ProjectDir};
|
||||
use plan2code_app_lib::quit_prompt::{loop_quit_prompt, quit_prompt, QuitCase};
|
||||
use plan2code_app_lib::restart_brief;
|
||||
use plan2code_app_lib::review_loop::{self, ReviewSlot};
|
||||
use plan2code_app_lib::session_reader;
|
||||
use plan2code_app_lib::settings;
|
||||
#[cfg(windows)]
|
||||
@@ -54,6 +55,9 @@ struct AppState {
|
||||
// The Implementation Loop running now, if any: in memory only, so an app
|
||||
// restart ends it (NFR-5).
|
||||
loop_run: LoopSlot,
|
||||
// The Review Loop running now, or the one that stopped and waits for
|
||||
// Continue or its report: in memory only, so an app restart ends it.
|
||||
review_run: ReviewSlot,
|
||||
// The last loop's project, spec, launch choice and confirmed quick check,
|
||||
// kept after the running record is gone so Resume, Fix together with an agent and
|
||||
// Finalize still work. Memory only.
|
||||
@@ -450,7 +454,7 @@ fn sync_agent_env(app: &tauri::AppHandle) {
|
||||
// commands, and `agent_input` stays open so a trust or login prompt can be
|
||||
// answered.
|
||||
fn refuse_while_looping(state: &AppState, what: &str) -> Result<(), String> {
|
||||
if loop_driver::is_running(&state.loop_run) {
|
||||
if loop_driver::is_running(&state.loop_run) || review_loop::is_running(&state.review_run) {
|
||||
return Err(format!(
|
||||
"A loop is running. Stop it before you change the {what}."
|
||||
));
|
||||
@@ -729,6 +733,7 @@ fn confirm_quit(app: &tauri::AppHandle) {
|
||||
fn agent_is_active(app: &tauri::AppHandle) -> bool {
|
||||
let state = app.state::<AppState>();
|
||||
loop_driver::is_running(&state.loop_run)
|
||||
|| review_loop::is_running(&state.review_run)
|
||||
|| current_agent(&state).is_some_and(|agent| agent.is_active())
|
||||
}
|
||||
|
||||
@@ -739,6 +744,7 @@ fn quit_app(app: &tauri::AppHandle) {
|
||||
let restart = RESTART_ON_QUIT.lock().ok().and_then(|mut plan| plan.take());
|
||||
let state = app.state::<AppState>();
|
||||
loop_driver::abandon(&state.loop_run);
|
||||
review_loop::abandon(&state.review_run);
|
||||
if let Some(agent) = current_agent(&state) {
|
||||
agent.stop();
|
||||
}
|
||||
@@ -1410,8 +1416,8 @@ async fn start_loop(
|
||||
spec: String,
|
||||
skip_confirm_if_same: bool,
|
||||
) -> Result<bool, String> {
|
||||
if loop_driver::is_running(&state.loop_run) {
|
||||
return Err("A loop is already running".to_string());
|
||||
if loop_driver::is_running(&state.loop_run) || review_loop::is_running(&state.review_run) {
|
||||
return Err("A loop is already running in this window.".to_string());
|
||||
}
|
||||
let project = state
|
||||
.project
|
||||
@@ -1601,11 +1607,203 @@ fn loop_stop_now(app: tauri::AppHandle, state: State<'_, AppState>) -> Result<()
|
||||
#[tauri::command]
|
||||
fn loop_state(state: State<'_, AppState>) -> Option<loop_driver::LoopStateEvent> {
|
||||
loop_driver::current_event(&state.loop_run)
|
||||
.or_else(|| review_loop::current_event(&state.review_run))
|
||||
}
|
||||
|
||||
// The project folder and the agent a Review Loop would use, or why there is none.
|
||||
fn review_target(
|
||||
state: &AppState,
|
||||
) -> Result<(std::path::PathBuf, Arc<AgentManager>, loop_driver::Launch), String> {
|
||||
let project = state
|
||||
.project
|
||||
.lock()
|
||||
.map_err(|e| e.to_string())?
|
||||
.as_ref()
|
||||
.map(|p| p.dir.clone())
|
||||
.ok_or("no project folder chosen")?;
|
||||
let agent = current_agent(state)
|
||||
.filter(|a| a.folder() == &project)
|
||||
.ok_or("Start an agent first, with permission checks off.")?;
|
||||
// A stopped agent has forgotten its launch choice; the run kept its own.
|
||||
let launch = agent
|
||||
.launch_choice()
|
||||
.or_else(|| {
|
||||
state
|
||||
.review_run
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|run| run.as_ref().map(|r| r.launch.clone()))
|
||||
})
|
||||
.ok_or("Start an agent first, with permission checks off.")?;
|
||||
Ok((project, agent, launch))
|
||||
}
|
||||
|
||||
// What the Review Loop's setup screen shows about the agent a run would use,
|
||||
// and the notification settings the Implementation Loop's setup holds.
|
||||
#[tauri::command]
|
||||
fn review_loop_facts(state: State<'_, AppState>) -> review_loop::ReviewFacts {
|
||||
let running =
|
||||
loop_driver::is_running(&state.loop_run) || review_loop::is_running(&state.review_run);
|
||||
let project = state
|
||||
.project
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|guard| guard.as_ref().map(|p| p.dir.clone()));
|
||||
let setup = project
|
||||
.as_deref()
|
||||
.and_then(|dir| loop_driver::read_setup(dir).ok())
|
||||
.unwrap_or_default();
|
||||
let agent = current_agent(&state)
|
||||
.and_then(|a| a.launch_choice())
|
||||
.map(|choice| choice.0)
|
||||
.or_else(|| state.launch.agent.as_deref().and_then(agents::find_agent));
|
||||
review_loop::facts(agent.as_ref(), running, &setup)
|
||||
}
|
||||
|
||||
// Starts a Review Loop. Async and off the main thread: the pre-run commit and
|
||||
// the start boundary run git. The notification comes from the Implementation
|
||||
// Loop's setup file, never from the page's message.
|
||||
#[tauri::command]
|
||||
async fn review_loop_start(
|
||||
app: tauri::AppHandle,
|
||||
state: State<'_, AppState>,
|
||||
setup: review_loop::ReviewRequest,
|
||||
) -> Result<bool, String> {
|
||||
let (project, agent, launch) = review_target(&state)?;
|
||||
let loop_setup = loop_driver::read_setup(&project).unwrap_or_default();
|
||||
let setup = setup.into_setup(&loop_setup);
|
||||
let (slot, phases) = (state.review_run.clone(), state.loop_run.clone());
|
||||
let hooks = loop_hooks(&app);
|
||||
tauri::async_runtime::spawn_blocking(move || {
|
||||
review_loop::start_review_loop(&slot, &phases, agent, launch, project, setup, hooks)
|
||||
})
|
||||
.await
|
||||
.map_err(|e| e.to_string())??;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
// Stop after this round: it finishes, is judged and committed, then the run stops.
|
||||
#[tauri::command]
|
||||
fn review_loop_stop_after(
|
||||
app: tauri::AppHandle,
|
||||
state: State<'_, AppState>,
|
||||
on: bool,
|
||||
) -> Result<(), String> {
|
||||
let event = review_loop::request_stop_after(&state.review_run, on)?;
|
||||
let _ = app.emit("loop-state", &event);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Stop now: the flag first, then the agent ends at once. Nothing more is
|
||||
// committed; the stop screen offers Keep or Discard for the partial changes.
|
||||
#[tauri::command]
|
||||
fn review_loop_stop_now(app: tauri::AppHandle, state: State<'_, AppState>) -> Result<(), String> {
|
||||
let agent = current_agent(&state);
|
||||
review_loop::request_stop_now(&state.review_run, agent.as_deref(), |event| {
|
||||
let _ = app.emit("loop-state", event);
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Keep the partial changes of a Stop now, or put the tree back to the last
|
||||
// finished round.
|
||||
#[tauri::command]
|
||||
async fn review_loop_partial(state: State<'_, AppState>, keep: bool) -> Result<(), String> {
|
||||
let home = session_reader::console_home().ok_or("no home folder found")?;
|
||||
let slot = state.review_run.clone();
|
||||
// The end screen is posted through node, so this is not main-thread work.
|
||||
tauri::async_runtime::spawn_blocking(move || review_loop::settle_partial(&slot, keep, &home))
|
||||
.await
|
||||
.map_err(|e| e.to_string())?
|
||||
}
|
||||
|
||||
// Sign off a finished Review Loop: fix the Suggestions the person ticked (one
|
||||
// fixer session and its fresh check), squash the round commits when asked, and
|
||||
// show the finished screen. Async and off the main thread: it runs git.
|
||||
#[tauri::command]
|
||||
async fn review_loop_sign_off(
|
||||
app: tauri::AppHandle,
|
||||
state: State<'_, AppState>,
|
||||
picks: Vec<String>,
|
||||
squash: bool,
|
||||
) -> Result<(), String> {
|
||||
let (project, agent, _) = review_target(&state)?;
|
||||
let same_project = state
|
||||
.review_run
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|run| run.as_ref().map(|r| r.project == project));
|
||||
if same_project != Some(true) {
|
||||
return Err("The project changed since that Review Loop.".to_string());
|
||||
}
|
||||
let home = session_reader::console_home().ok_or("no home folder found")?;
|
||||
let (slot, phases) = (state.review_run.clone(), state.loop_run.clone());
|
||||
let hooks = loop_hooks(&app);
|
||||
tauri::async_runtime::spawn_blocking(move || {
|
||||
review_loop::sign_off(
|
||||
&slot,
|
||||
&phases,
|
||||
agent,
|
||||
hooks,
|
||||
loop_driver::Limits::default(),
|
||||
home,
|
||||
&picks,
|
||||
squash,
|
||||
true,
|
||||
)
|
||||
})
|
||||
.await
|
||||
.map_err(|e| e.to_string())?
|
||||
}
|
||||
|
||||
// The finished screen's PR Prep and Fix what's left by hand: an ordinary
|
||||
// session on the skill, with no `--loop`, so the person talks to the agent.
|
||||
#[tauri::command]
|
||||
fn review_loop_next(state: State<'_, AppState>, next: String) -> Result<(), String> {
|
||||
let prompt = review_loop::next_prompt(&state.review_run, &next)?;
|
||||
let (_, agent, launch) = review_target(&state)?;
|
||||
loop_driver::start_with(&agent, &launch, prompt)
|
||||
}
|
||||
|
||||
// Continue a stopped Review Loop: the next round from the last boundary; past
|
||||
// the cap one round at a time, never above six in all.
|
||||
#[tauri::command]
|
||||
async fn review_loop_continue(
|
||||
app: tauri::AppHandle,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<(), String> {
|
||||
let (project, agent, _) = review_target(&state)?;
|
||||
// A stopped run stays after a change of project: its git work would run
|
||||
// in the old folder while the agent works in the new one.
|
||||
let same_project = state
|
||||
.review_run
|
||||
.lock()
|
||||
.ok()
|
||||
.and_then(|run| run.as_ref().map(|r| r.project == project));
|
||||
if same_project != Some(true) {
|
||||
return Err("The project changed since that Review Loop.".to_string());
|
||||
}
|
||||
let home = session_reader::console_home().ok_or("no home folder found")?;
|
||||
let (slot, phases) = (state.review_run.clone(), state.loop_run.clone());
|
||||
let hooks = loop_hooks(&app);
|
||||
tauri::async_runtime::spawn_blocking(move || {
|
||||
review_loop::continue_run(
|
||||
&slot,
|
||||
&phases,
|
||||
agent,
|
||||
hooks,
|
||||
loop_driver::Limits::default(),
|
||||
home,
|
||||
true,
|
||||
)
|
||||
})
|
||||
.await
|
||||
.map_err(|e| e.to_string())?
|
||||
}
|
||||
|
||||
// The last loop, for the stop and finish screens' buttons.
|
||||
fn last_loop(state: &AppState) -> Result<LastLoop, String> {
|
||||
if loop_driver::is_running(&state.loop_run) {
|
||||
if loop_driver::is_running(&state.loop_run) || review_loop::is_running(&state.review_run) {
|
||||
return Err("A loop is running".to_string());
|
||||
}
|
||||
let last = state
|
||||
@@ -1808,6 +2006,14 @@ fn main() {
|
||||
loop_stop_after_phase,
|
||||
loop_stop_now,
|
||||
loop_state,
|
||||
review_loop_facts,
|
||||
review_loop_start,
|
||||
review_loop_stop_after,
|
||||
review_loop_stop_now,
|
||||
review_loop_partial,
|
||||
review_loop_sign_off,
|
||||
review_loop_next,
|
||||
review_loop_continue,
|
||||
loop_resume,
|
||||
loop_fix,
|
||||
loop_ask,
|
||||
@@ -1848,6 +2054,7 @@ fn main() {
|
||||
.map(|session| session.state)
|
||||
.unwrap_or(serde_json::Value::Null);
|
||||
loop_driver::note_page(&state.loop_run, ¬ice.workflow, ¬ice.sid, &page);
|
||||
review_loop::note_page(&state.review_run, ¬ice.workflow, ¬ice.sid, &page);
|
||||
let _ = handle.emit("console-page", ¬ice);
|
||||
} else {
|
||||
eprintln!(
|
||||
|
||||
Reference in new issue
Block a user