mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-17 04:45:33 -08:00
Add the desktop app loop driver with commit, notify, report and tools modules, and update the quit prompt, task dialog and meter
AI Assisted
This commit is contained in:
1 parent
8db8df5791
commit
1f80fa6a7c
24 files changed
+9850
-64
No files matched your search
@@ -2,7 +2,9 @@
|
||||
//! agent is not mid-step at all but waiting on the person's answer in the web
|
||||
//! console, so the check reads the page's last taskbar signal (attention.rs)
|
||||
//! and says which case it is. Anything it cannot be sure of is the working
|
||||
//! case, the safer warning. Knows nothing about Tauri; main.rs shows it.
|
||||
//! case, the safer warning. While the Implementation Loop builds a phase the
|
||||
//! words are the loop's own (`loop_quit_prompt`). Knows nothing about Tauri;
|
||||
//! main.rs shows it.
|
||||
|
||||
use crate::attention::Signal;
|
||||
|
||||
@@ -16,38 +18,73 @@ pub enum QuitCase {
|
||||
}
|
||||
|
||||
/// Everything the box says.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct QuitPrompt {
|
||||
pub case: QuitCase,
|
||||
pub title: &'static str,
|
||||
pub heading: &'static str,
|
||||
pub message: &'static str,
|
||||
pub quit: &'static str,
|
||||
pub stay: &'static str,
|
||||
pub title: String,
|
||||
pub heading: String,
|
||||
pub message: String,
|
||||
pub quit: String,
|
||||
pub stay: String,
|
||||
}
|
||||
|
||||
fn words(case: QuitCase, heading: &str, message: &str, quit: &str) -> QuitPrompt {
|
||||
QuitPrompt {
|
||||
case,
|
||||
title: "Plan2Code".to_string(),
|
||||
heading: heading.to_string(),
|
||||
message: message.to_string(),
|
||||
quit: quit.to_string(),
|
||||
stay: "Stay".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The prompt for the page's last signal (`None` before the page has sent one).
|
||||
pub fn quit_prompt(last: Option<Signal>) -> QuitPrompt {
|
||||
match last {
|
||||
Some(Signal::Ready | Signal::Plain) => QuitPrompt {
|
||||
case: QuitCase::Waiting,
|
||||
title: "Plan2Code",
|
||||
heading: "Done for now?",
|
||||
message: "Your agent is just waiting on your next answer. Quit and this session ends.",
|
||||
quit: "Quit",
|
||||
stay: "Stay",
|
||||
},
|
||||
Some(Signal::Busy | Signal::Attention) | None => QuitPrompt {
|
||||
case: QuitCase::Working,
|
||||
title: "Plan2Code",
|
||||
heading: "Leave while your agent is busy?",
|
||||
message: "If you quit now, the agent stops mid-step. Everything it has saved so far stays put.",
|
||||
quit: "Quit and stop it",
|
||||
stay: "Stay",
|
||||
},
|
||||
Some(Signal::Ready | Signal::Plain) => words(
|
||||
QuitCase::Waiting,
|
||||
"Done for now?",
|
||||
"Your agent is just waiting on your next answer. Quit and this session ends.",
|
||||
"Quit",
|
||||
),
|
||||
Some(Signal::Busy | Signal::Attention) | None => words(
|
||||
QuitCase::Working,
|
||||
"Leave while your agent is busy?",
|
||||
"If you quit now, the agent stops mid-step. Everything it has saved so far stays put.",
|
||||
"Quit and stop it",
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// "Phase 1", "Phases 1 and 2", "Phases 1, 2 and 3".
|
||||
fn phase_list(committed: &[u32]) -> String {
|
||||
let numbers: Vec<String> = committed.iter().map(u32::to_string).collect();
|
||||
match numbers.as_slice() {
|
||||
[] => String::new(),
|
||||
[one] => format!("Phase {one}"),
|
||||
[init @ .., last] => format!("Phases {} and {last}", init.join(", ")),
|
||||
}
|
||||
}
|
||||
|
||||
/// The words for quitting while the Implementation Loop builds a phase.
|
||||
/// `committed` lists the phase numbers already committed.
|
||||
pub fn loop_quit_prompt(phase: u32, phases: u32, committed: &[u32]) -> QuitPrompt {
|
||||
let done = match committed.len() {
|
||||
0 => "No phase is committed yet".to_string(),
|
||||
1 => format!("{} is committed", phase_list(committed)),
|
||||
_ => format!("{} are committed", phase_list(committed)),
|
||||
};
|
||||
words(
|
||||
QuitCase::Working,
|
||||
"Stop the loop and quit?",
|
||||
&format!(
|
||||
"Phase {phase} of {phases} is mid-build. {done}; this phase's changes stay uncommitted."
|
||||
),
|
||||
"Quit and stop the loop",
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -92,11 +129,38 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn no_text_carries_an_em_dash() {
|
||||
for last in [None, Some(Signal::Busy), Some(Signal::Ready)] {
|
||||
let p = quit_prompt(last);
|
||||
for text in [p.title, p.heading, p.message, p.quit, p.stay] {
|
||||
let mut all = vec![loop_quit_prompt(2, 4, &[1]), loop_quit_prompt(1, 4, &[])];
|
||||
all.extend([None, Some(Signal::Busy), Some(Signal::Ready)].map(quit_prompt));
|
||||
for p in all {
|
||||
for text in [&p.title, &p.heading, &p.message, &p.quit, &p.stay] {
|
||||
assert!(!text.contains('\u{2014}'), "{text}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_loop_wording_names_what_is_committed() {
|
||||
let none = loop_quit_prompt(1, 4, &[]);
|
||||
assert_eq!(none.heading, "Stop the loop and quit?");
|
||||
assert_eq!(none.title, "Plan2Code");
|
||||
assert_eq!(none.quit, "Quit and stop the loop");
|
||||
assert_eq!(none.stay, "Stay");
|
||||
assert_eq!(none.case, QuitCase::Working);
|
||||
assert_eq!(
|
||||
none.message,
|
||||
"Phase 1 of 4 is mid-build. No phase is committed yet; this phase's changes stay uncommitted."
|
||||
);
|
||||
assert_eq!(
|
||||
loop_quit_prompt(2, 4, &[1]).message,
|
||||
"Phase 2 of 4 is mid-build. Phase 1 is committed; this phase's changes stay uncommitted."
|
||||
);
|
||||
assert_eq!(
|
||||
loop_quit_prompt(3, 4, &[1, 2]).message,
|
||||
"Phase 3 of 4 is mid-build. Phases 1 and 2 are committed; this phase's changes stay uncommitted."
|
||||
);
|
||||
assert_eq!(
|
||||
loop_quit_prompt(4, 4, &[1, 2, 3]).message,
|
||||
"Phase 4 of 4 is mid-build. Phases 1, 2 and 3 are committed; this phase's changes stay uncommitted."
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user