mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Make the Loop stopped screen say why and recommend one button
AI Assisted
This commit is contained in:
1 parent
b585eccd5a
commit
785a4dc8b9
11 files changed
+500
-54
No files matched your search
@@ -1605,8 +1605,13 @@ as your move rather than leaving a stale "starting" line behind.
|
||||
A stopped loop also offers **Ask a question**, first in the row. The app ended
|
||||
its agent when the loop stopped, so the Ask tab says no agent is available;
|
||||
the button wakes an ordinary agent on the same page, without starting the loop
|
||||
or changing anything, and **Resume the loop** is still there afterwards. **Back
|
||||
to the dashboard** ends that agent too.
|
||||
or changing anything, and **Continue building** is still there afterwards; once
|
||||
the agent is up, the button opens the Ask tab instead. **Back to the dashboard**
|
||||
ends that agent too. The stop screen leads with a short reason, puts one line
|
||||
under each button saying what it does, and highlights the one that fits the
|
||||
stop: **Continue building** after a crash, a silence or your own stop, **Fix
|
||||
together with an agent** after a failed check, a blocked task, a refused commit
|
||||
or a question. The phases and uncommitted files sit under **Details**.
|
||||
|
||||
You don't have to finish first. On every skill but the dashboard itself, a
|
||||
small **triangle** pointing left, in your highlight color, sits beside *Stop
|
||||
|
||||
+5
-5
@@ -163,7 +163,7 @@ not), so your own edits never end up inside a phase's commit.
|
||||
The last setup is remembered per project in `~/.plan2code/console/loop-setup.json`, so the next loop
|
||||
starts from it. The quick check is typed text the page never runs: the app reads it from that file
|
||||
itself and names it in its own window before the loop begins. The notification gets the same treatment,
|
||||
and Resume asks again if either one changed.
|
||||
and Continue building asks again if either one changed.
|
||||
|
||||
**The notification.** The loop says a question is waiting, that it is complete, or why it stopped, and,
|
||||
when you turn on **Also tell me when each phase is complete**, that a phase passed. Nothing is sent when you
|
||||
@@ -233,17 +233,17 @@ evidence, when:
|
||||
- the Smart pick skipped a Critical finding.
|
||||
|
||||
A crashed or silent agent gets exactly one retry per phase when the retry tick is on, and none when it is off.
|
||||
It never retries a real failure. On a stop screen, **Ask a question** (first in the row, offered whenever Resume is) wakes an ordinary agent on the stopped phase on the same page, so the Ask tab answers; it starts no loop and changes nothing, and **Resume the loop** is still there afterwards. **Resume the loop** carries on from the stopped
|
||||
phase and **Fix it by hand** opens an ordinary Implement session on it.
|
||||
It never retries a real failure. On a stop screen, **Ask a question** (first in the row, offered whenever Continue building is) wakes an ordinary agent on the stopped phase on the same page, so the Ask tab answers; it starts no loop and changes nothing, and **Continue building** is still there afterwards (pressing Ask again only opens the Ask tab). **Continue building** carries on unattended from the stopped
|
||||
phase and **Fix together with an agent** opens an ordinary Implement session on it. The stop screen leads with a short reason, puts one line under each button saying what it does, and highlights one: Continue building after a crash, a silence or your own stop, Fix together after a failed check, a blocked task, a refused commit or a question. The phase list and uncommitted files sit under **Details**.
|
||||
|
||||
**The report.** One report follows the whole build, across stops and Resume. For every phase it says what
|
||||
**The report.** One report follows the whole build, across stops and Continue building. For every phase it says what
|
||||
was built and committed, the tests, the findings fixed, the findings it chose not to fix and why, the
|
||||
findings left open, each assumption with its note, and any other decisions the agent reported, plus every
|
||||
retry and stop, in order. The agent writes most of this, so it holds what the agent noticed; the task marks,
|
||||
the quick check and the commits are the app's own. The finish screen counts each kind per phase, and **Read
|
||||
the full report** opens it, saved as `specs/<feature>/LOOP-SUMMARY-<date>.md` (`-2` and so on for another
|
||||
the same day). After a stop, **Read why, and the report so far** shows it on the stop screen. While a build
|
||||
is unfinished it lives in `~/.plan2code/console/loop-reports.json`, not the project, because Resume needs a
|
||||
is unfinished it lives in `~/.plan2code/console/loop-reports.json`, not the project, because Continue building needs a
|
||||
clean tree. The in-app **Help** has a matching topic, **Implementation Loop**, which the loop card links to as "How the loop works".
|
||||
|
||||
## Keep it up to date
|
||||
|
||||
@@ -631,7 +631,7 @@ pub fn current_event(slot: &LoopSlot) -> Option<LoopStateEvent> {
|
||||
lock(slot).as_ref().map(state_event)
|
||||
}
|
||||
|
||||
/// What Resume, Fix it by hand and Finalize need after the running record is
|
||||
/// What Resume, Fix together with an agent and Finalize need after the running record is
|
||||
/// gone. Memory only (NFR-5).
|
||||
#[derive(Clone)]
|
||||
pub struct LastLoop {
|
||||
@@ -993,7 +993,7 @@ pub fn stop_line(cause: &StopCause, phase: u32, detail: &str, retried: bool) ->
|
||||
why
|
||||
};
|
||||
format!(
|
||||
"Phase {phase} was not committed: {why}. The work is uncommitted; Resume tries the commit again"
|
||||
"Phase {phase} was not committed: {why}. The work is uncommitted; Continue building tries the commit again"
|
||||
)
|
||||
}
|
||||
StopCause::MarkedNotCommitted(file) => {
|
||||
@@ -1023,7 +1023,7 @@ pub fn stop_line(cause: &StopCause, phase: u32, detail: &str, retried: bool) ->
|
||||
StopCause::WatcherFailed(text) => {
|
||||
let text: String = one_line(text).chars().take(100).collect();
|
||||
format!(
|
||||
"The loop's watcher failed: {text}. Nothing more was committed; Resume starts again"
|
||||
"The loop's watcher failed: {text}. Nothing more was committed; Continue building starts again"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1803,7 +1803,7 @@ pub fn start_phase_with(
|
||||
}
|
||||
}
|
||||
|
||||
/// The prompt behind Fix it by hand: an ordinary Implement session.
|
||||
/// The prompt behind Fix together with an agent: an ordinary Implement session.
|
||||
pub fn fix_prompt(spec: &str) -> String {
|
||||
format!("/plan2code-3-implement {spec}/overview.md --web")
|
||||
}
|
||||
@@ -1825,7 +1825,15 @@ pub fn ask_prompt(spec: &str) -> String {
|
||||
/// Start the Ask agent: `start_with` without the forget step, so the agent's
|
||||
/// `open` joins the session on screen and the stopped screen stays up. The
|
||||
/// prompt is transient, as `start_with`'s is.
|
||||
///
|
||||
/// An agent already running here is the Ask agent from an earlier press (the
|
||||
/// loop's own agent ended with the stop, and Continue building, Fix together
|
||||
/// and Finalize replace the screen), so a second press is answered with it,
|
||||
/// never with the "already running" refusal.
|
||||
pub fn start_asking(agent: &AgentManager, launch: &Launch, prompt: String) -> Result<(), String> {
|
||||
if agent.snapshot().state == crate::agent_manager::AgentState::Running {
|
||||
return Ok(());
|
||||
}
|
||||
let (kind, model, effort, mode) = launch.clone();
|
||||
agent.start_transient(kind, model, effort, mode, prompt)
|
||||
}
|
||||
@@ -3004,7 +3012,7 @@ pub fn evidence_markdown(cause: &StopCause, line: &str, rec: &RunningRecord) ->
|
||||
rec.failure_output.as_deref().unwrap_or("(no output)"),
|
||||
));
|
||||
md.push_str(
|
||||
"\nThe phase was approved, but its changes are not committed. The mark was taken back, so the spec still shows the phase open. Fix what git says, then press Resume to try the commit again.\n",
|
||||
"\nThe phase was approved, but its changes are not committed. The mark was taken back, so the spec still shows the phase open. Fix what git says, then press Continue building to try the commit again.\n",
|
||||
);
|
||||
}
|
||||
StopCause::MarkedNotCommitted(file) => {
|
||||
@@ -3013,7 +3021,7 @@ pub fn evidence_markdown(cause: &StopCause, line: &str, rec: &RunningRecord) ->
|
||||
rec.failure_output.as_deref().unwrap_or("(no output)"),
|
||||
));
|
||||
md.push_str(&format!(
|
||||
"\nThe phase is marked done in `{file}` (and in overview.md), but its changes are not committed, and the mark could not be taken back. Set the phase back to in progress by hand, or press Resume: it checks every done mark against the commit log and builds this phase again.\n"
|
||||
"\nThe phase is marked done in `{file}` (and in overview.md), but its changes are not committed, and the mark could not be taken back. Set the phase back to in progress by hand, or press Continue building: it checks every done mark against the commit log and builds this phase again.\n"
|
||||
));
|
||||
}
|
||||
StopCause::UnsafeFiles(files) => {
|
||||
@@ -3024,7 +3032,7 @@ pub fn evidence_markdown(cause: &StopCause, line: &str, rec: &RunningRecord) ->
|
||||
md.push_str(&format!("- `{file}` ({reason})\n"));
|
||||
}
|
||||
md.push_str(
|
||||
"\nThe phase was approved, but these files were staged and the loop does not commit secrets or files over 5 MB. Nothing was marked done or committed, and everything was taken out of the index again (unless the stop line says otherwise). Remove the files, or add them to `.gitignore`, then press Resume.\n",
|
||||
"\nThe phase was approved, but these files were staged and the loop does not commit secrets or files over 5 MB. Nothing was marked done or committed, and everything was taken out of the index again (unless the stop line says otherwise). Remove the files, or add them to `.gitignore`, then press Continue building.\n",
|
||||
);
|
||||
}
|
||||
StopCause::Refused(_) => {
|
||||
@@ -3046,11 +3054,11 @@ pub fn evidence_markdown(cause: &StopCause, line: &str, rec: &RunningRecord) ->
|
||||
}
|
||||
StopCause::WatcherFailed(_) => {
|
||||
md.push_str(
|
||||
"\nThe loop's own watcher stopped working, so the agent was ended. Whatever was committed stays committed; nothing more was. Press Resume to carry on from the spec.\n",
|
||||
"\nThe loop's own watcher stopped working, so the agent was ended. Whatever was committed stays committed; nothing more was. Press Continue building to carry on from the spec.\n",
|
||||
);
|
||||
}
|
||||
StopCause::Question if rec.setup.on_question == OnQuestion::Guess => {
|
||||
md.push_str("\nBest guess was on, but the phase asked a question it could not guess, so the loop stopped rather than wait. Answer it with Fix it by hand, or settle it in the spec, then press Resume.\n");
|
||||
md.push_str("\nBest guess was on, but the phase asked a question it could not guess, so the loop stopped rather than wait. Answer it with Fix together with an agent, or settle it in the spec, then press Continue building.\n");
|
||||
}
|
||||
StopCause::Question => {
|
||||
md.push_str("\nThe setup says to stop when a phase asks something.\n");
|
||||
@@ -3207,11 +3215,88 @@ fn stop_loop(ctx: &Ctx, cause: StopCause, line: String, can: &[&str]) {
|
||||
"phases": phase_rows(&rec),
|
||||
"uncommitted": uncommitted,
|
||||
"can": stop_can(can),
|
||||
"reason": stop_reason(&cause, rec.phases[at].n, built),
|
||||
"recommend": stop_recommend(&cause, can),
|
||||
"phase": continue_phase(
|
||||
&rec.phases.iter().map(|p| p.n).collect::<Vec<_>>(),
|
||||
at,
|
||||
built
|
||||
),
|
||||
},
|
||||
});
|
||||
post_end(ctx, &rec, &patch);
|
||||
}
|
||||
|
||||
/// The phase Continue building (and Fix together) starts on, for the stop
|
||||
/// screen's button lines: the stopped phase, or, when that phase was already
|
||||
/// built (Stop after this phase), the next one in the run. `numbers` are the
|
||||
/// run's phase numbers in order and `at` the stopped phase's index.
|
||||
pub fn continue_phase(numbers: &[u32], at: usize, built: bool) -> u32 {
|
||||
let next = if built { at + 1 } else { at };
|
||||
numbers
|
||||
.get(next)
|
||||
.or_else(|| numbers.get(at))
|
||||
.copied()
|
||||
.unwrap_or(1)
|
||||
}
|
||||
|
||||
/// The stop screen's heading: one short plain sentence saying where the loop
|
||||
/// stopped and why, with no detail that could run long (the `line` under it
|
||||
/// carries the detail). `built` is a phase already built and recorded.
|
||||
pub fn stop_reason(cause: &StopCause, phase: u32, built: bool) -> String {
|
||||
match cause {
|
||||
StopCause::StoppedByPerson if built => {
|
||||
format!("Phase {phase} is built. The loop stopped there, as you asked.")
|
||||
}
|
||||
StopCause::StoppedByPerson => format!("You stopped the loop during Phase {phase}."),
|
||||
StopCause::Crash => format!("Phase {phase} stopped because the agent crashed."),
|
||||
StopCause::Silence => {
|
||||
format!("Phase {phase} stopped because the agent went quiet for too long.")
|
||||
}
|
||||
StopCause::NoSession => {
|
||||
format!("Phase {phase} stopped because the agent never opened its page.")
|
||||
}
|
||||
StopCause::WatcherFailed(_) => {
|
||||
format!("The loop stopped during Phase {phase} because of an error in the app.")
|
||||
}
|
||||
StopCause::Refused(_) => {
|
||||
format!("Phase {phase} stopped on a problem the loop cannot fix by itself.")
|
||||
}
|
||||
StopCause::QuickCheck => format!("Phase {phase} stopped because the quick check failed."),
|
||||
StopCause::Commit => format!("Phase {phase} is built, but git refused its commit."),
|
||||
StopCause::MarkedNotCommitted(_) => {
|
||||
format!("Phase {phase} is marked done, but its work is not committed.")
|
||||
}
|
||||
StopCause::UnsafeFiles(_) => {
|
||||
format!("Phase {phase} is built, but some files look unsafe to commit.")
|
||||
}
|
||||
StopCause::Question => format!("Phase {phase} stopped to ask you something."),
|
||||
}
|
||||
}
|
||||
|
||||
/// The one button the stop screen recommends, from `can` (the buttons it
|
||||
/// offers). A soft stop (the agent crashed or went quiet, the person stopped
|
||||
/// it, the watcher failed) recommends Continue building: nothing in the work
|
||||
/// needs changing. A hard stop (a refused phase, failing checks, a refused or
|
||||
/// unsafe commit, a question) recommends Fix together with an agent, since
|
||||
/// continuing would meet the same wall. When that button is not offered, the
|
||||
/// first of Continue building, Fix together and Finalize that is.
|
||||
pub fn stop_recommend(cause: &StopCause, can: &[&str]) -> Option<String> {
|
||||
let soft = matches!(
|
||||
cause,
|
||||
StopCause::Crash
|
||||
| StopCause::Silence
|
||||
| StopCause::NoSession
|
||||
| StopCause::StoppedByPerson
|
||||
| StopCause::WatcherFailed(_)
|
||||
);
|
||||
let first = if soft { "resume" } else { "fix" };
|
||||
[first, "resume", "fix", "finalize"]
|
||||
.into_iter()
|
||||
.find(|key| can.contains(key))
|
||||
.map(String::from)
|
||||
}
|
||||
|
||||
fn finish(ctx: &Ctx) {
|
||||
let rec = {
|
||||
let guard = lock(&ctx.slot);
|
||||
@@ -4631,7 +4716,7 @@ second line"
|
||||
);
|
||||
assert_eq!(
|
||||
stop_line(&StopCause::Commit, 4, "lint says no", false),
|
||||
"Phase 4 was not committed: lint says no. The work is uncommitted; Resume tries the commit again"
|
||||
"Phase 4 was not committed: lint says no. The work is uncommitted; Continue building tries the commit again"
|
||||
);
|
||||
assert_eq!(
|
||||
stop_line(
|
||||
@@ -5657,7 +5742,7 @@ second line"
|
||||
assert_eq!(entry.result, EntryResult::Stopped);
|
||||
assert_eq!(
|
||||
entry.line,
|
||||
"Phase 2 was not committed: lint says no. The work is uncommitted; Resume tries the commit again"
|
||||
"Phase 2 was not committed: lint says no. The work is uncommitted; Continue building tries the commit again"
|
||||
);
|
||||
assert_eq!(
|
||||
git_in(&repo, &["log", "-1", "--format=%s"]),
|
||||
@@ -6230,7 +6315,7 @@ second line"
|
||||
fn a_commit_that_gives_no_reason_still_reads_as_a_sentence() {
|
||||
assert_eq!(
|
||||
stop_line(&StopCause::Commit, 2, "", false),
|
||||
"Phase 2 was not committed: git gave no reason. The work is uncommitted; Resume tries the commit again"
|
||||
"Phase 2 was not committed: git gave no reason. The work is uncommitted; Continue building tries the commit again"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6389,7 +6474,7 @@ second line"
|
||||
assert_eq!(entry.result, EntryResult::Stopped);
|
||||
assert_eq!(
|
||||
entry.line,
|
||||
"The loop's watcher failed: boom inside the lock. Nothing more was committed; Resume starts again"
|
||||
"The loop's watcher failed: boom inside the lock. Nothing more was committed; Continue building starts again"
|
||||
);
|
||||
// A new loop can take the slot.
|
||||
*lock(&ctx.slot) = Some(record("specs/lunch", vec![phase(2), phase(3)]));
|
||||
@@ -6878,7 +6963,7 @@ second line"
|
||||
let cause = StopCause::WatcherFailed("index out of bounds".into());
|
||||
assert_eq!(
|
||||
stop_line(&cause, 3, "", false),
|
||||
"The loop's watcher failed: index out of bounds. Nothing more was committed; Resume starts again"
|
||||
"The loop's watcher failed: index out of bounds. Nothing more was committed; Continue building starts again"
|
||||
);
|
||||
assert!(!should_retry(&cause, &setup(), 0));
|
||||
let line = stop_line(&cause, 3, "", false);
|
||||
@@ -7201,6 +7286,85 @@ second line"
|
||||
assert!(!prompt.contains("--workflow implement"), "{prompt}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_soft_stop_recommends_continue_building_and_a_hard_stop_recommends_fixing_together() {
|
||||
let both = ["resume", "fix"];
|
||||
for soft in [
|
||||
StopCause::Crash,
|
||||
StopCause::Silence,
|
||||
StopCause::NoSession,
|
||||
StopCause::StoppedByPerson,
|
||||
StopCause::WatcherFailed("x".into()),
|
||||
] {
|
||||
assert_eq!(
|
||||
stop_recommend(&soft, &both).as_deref(),
|
||||
Some("resume"),
|
||||
"{soft:?}"
|
||||
);
|
||||
}
|
||||
for hard in [
|
||||
StopCause::Refused("1 test failed".into()),
|
||||
StopCause::QuickCheck,
|
||||
StopCause::Commit,
|
||||
StopCause::MarkedNotCommitted("phase-2.md".into()),
|
||||
StopCause::UnsafeFiles(vec![".env".into()]),
|
||||
StopCause::Question,
|
||||
] {
|
||||
assert_eq!(
|
||||
stop_recommend(&hard, &both).as_deref(),
|
||||
Some("fix"),
|
||||
"{hard:?}"
|
||||
);
|
||||
}
|
||||
// Only an offered button is ever recommended.
|
||||
assert_eq!(
|
||||
stop_recommend(&StopCause::Question, &["resume"]).as_deref(),
|
||||
Some("resume")
|
||||
);
|
||||
assert_eq!(
|
||||
stop_recommend(&StopCause::StoppedByPerson, &["finalize"]).as_deref(),
|
||||
Some("finalize")
|
||||
);
|
||||
assert_eq!(stop_recommend(&StopCause::Crash, &[]), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn continue_building_starts_on_the_stopped_phase_or_the_one_after_a_built_phase() {
|
||||
// A run over Phases 2 to 5, stopped in Phase 3: never the last phase.
|
||||
assert_eq!(continue_phase(&[2, 3, 4, 5], 1, false), 3);
|
||||
// Phase 3 built, then stopped as asked: the next phase is where it goes on.
|
||||
assert_eq!(continue_phase(&[2, 3, 4, 5], 1, true), 4);
|
||||
// The last phase built: nothing after it, so the phase itself.
|
||||
assert_eq!(continue_phase(&[2, 3, 4, 5], 3, true), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_stop_reason_is_one_short_sentence_naming_the_phase() {
|
||||
let causes = [
|
||||
StopCause::Crash,
|
||||
StopCause::Silence,
|
||||
StopCause::NoSession,
|
||||
StopCause::StoppedByPerson,
|
||||
StopCause::WatcherFailed("a very long panic text ".repeat(20)),
|
||||
StopCause::Refused("a very long reason ".repeat(20)),
|
||||
StopCause::QuickCheck,
|
||||
StopCause::Commit,
|
||||
StopCause::MarkedNotCommitted("specs/x/phase-3.md".into()),
|
||||
StopCause::UnsafeFiles(vec![".env".into()]),
|
||||
StopCause::Question,
|
||||
];
|
||||
for cause in &causes {
|
||||
let reason = stop_reason(cause, 3, false);
|
||||
assert!(reason.contains("Phase 3"), "{reason}");
|
||||
assert!(reason.chars().count() <= 80, "{reason}");
|
||||
assert!(!reason.contains('\u{2014}'), "{reason}");
|
||||
}
|
||||
assert_eq!(
|
||||
stop_reason(&StopCause::StoppedByPerson, 4, true),
|
||||
"Phase 4 is built. The loop stopped there, as you asked."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_resumable_stop_offers_ask_first_and_a_finalize_only_stop_does_not() {
|
||||
assert_eq!(
|
||||
@@ -7214,7 +7378,25 @@ second line"
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn asking_leaves_the_session_on_screen_and_fix_it_by_hand_still_forgets_it() {
|
||||
fn asking_twice_keeps_the_ask_agent_and_is_never_refused() {
|
||||
let (agent, seen) = fake_agent_manager(Path::new("."));
|
||||
let launch = fake_agent_launch();
|
||||
start_asking(&agent, &launch, ask_prompt("specs/x")).unwrap();
|
||||
wait_until("the Ask agent ready", || {
|
||||
lock(&seen).matches("FAKE-AGENT ready").count() >= 1
|
||||
});
|
||||
// The refusal the stopped screen once showed came from this second press.
|
||||
start_asking(&agent, &launch, ask_prompt("specs/x")).unwrap();
|
||||
assert_eq!(
|
||||
launched_prompts(&seen),
|
||||
vec![ask_prompt("specs/x")],
|
||||
"the running Ask agent answers the second press; no second agent starts"
|
||||
);
|
||||
agent.stop();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn asking_leaves_the_session_on_screen_and_fixing_together_still_forgets_it() {
|
||||
let (agent, seen) = fake_agent_manager(Path::new("."));
|
||||
let forgets = Arc::new(Mutex::new(0));
|
||||
let counter = Arc::clone(&forgets);
|
||||
@@ -7228,12 +7410,16 @@ second line"
|
||||
assert_eq!(*lock(&forgets), 0, "Ask must join the session on screen");
|
||||
|
||||
// The Ask agent is still running when the next button is pressed, as in
|
||||
// the app: Fix it by hand replaces it and forgets the session.
|
||||
// the app: Fix together with an agent replaces it and forgets the session.
|
||||
start_with(&agent, &launch, fix_prompt("specs/x")).unwrap();
|
||||
wait_until("the fix agent ready", || {
|
||||
lock(&seen).matches("FAKE-AGENT ready").count() >= 2
|
||||
});
|
||||
assert_eq!(*lock(&forgets), 1, "Fix it by hand must forget the session");
|
||||
assert_eq!(
|
||||
*lock(&forgets),
|
||||
1,
|
||||
"Fix together with an agent must forget the session"
|
||||
);
|
||||
let prompts = launched_prompts(&seen);
|
||||
assert_eq!(
|
||||
prompts,
|
||||
|
||||
@@ -56,7 +56,7 @@ struct AppState {
|
||||
// restart ends it (NFR-5).
|
||||
loop_run: LoopSlot,
|
||||
// The last loop's project, spec, launch choice and confirmed quick check,
|
||||
// kept after the running record is gone so Resume, Fix it by hand and
|
||||
// kept after the running record is gone so Resume, Fix together with an agent and
|
||||
// Finalize still work. Memory only.
|
||||
last_loop: Mutex<Option<LastLoop>>,
|
||||
}
|
||||
@@ -1257,7 +1257,7 @@ async fn loop_resume(app: tauri::AppHandle, state: State<'_, AppState>) -> Resul
|
||||
start_loop(&app, &state, last.spec, true).await.map(|_| ())
|
||||
}
|
||||
|
||||
// Fix it by hand: an ordinary Implement session on the stopped phase, with no
|
||||
// Fix together with an agent: an ordinary Implement session on the stopped phase, with no
|
||||
// `--loop`, so the person talks to the agent as usual.
|
||||
#[tauri::command]
|
||||
fn loop_fix(state: State<'_, AppState>) -> Result<(), String> {
|
||||
|
||||
@@ -478,6 +478,17 @@ test("loopEnd: ask is accepted in can, so a stopped loop can offer a question be
|
||||
assert.deepEqual(next.loopEnd.can, ["resume", "ask", "fix", "dashboard"]);
|
||||
});
|
||||
|
||||
test("loopEnd: a short reason and a recommended button are stored, and both stay optional", () => {
|
||||
const { problems, next } = tryPatch(loopState(), {
|
||||
loopEnd: goodEnd({ can: ["ask", "resume", "fix", "dashboard"], reason: "Phase 2 stopped because the quick check failed.", recommend: "fix", phase: 2 }),
|
||||
});
|
||||
assert.deepEqual(problems, []);
|
||||
assert.equal(next.loopEnd.phase, 2);
|
||||
assert.equal(next.loopEnd.reason, "Phase 2 stopped because the quick check failed.");
|
||||
assert.equal(next.loopEnd.recommend, "fix");
|
||||
assert.deepEqual(tryPatch(loopState(), { loopEnd: goodEnd() }).problems, [], "an older app sends neither");
|
||||
});
|
||||
|
||||
test("loopEnd: an unknown evidence id, a push in can, and the other bad fields are refused, each named", () => {
|
||||
const cases = [
|
||||
["an unknown evidence id", goodEnd({ evidence: "nope" }), /loopEnd\.evidence must be the id of a doc on the page/],
|
||||
@@ -489,6 +500,10 @@ test("loopEnd: an unknown evidence id, a push in can, and the other bad fields a
|
||||
["a bad decision count", goodEnd({ phases: [{ n: 1, name: "Setup", commit: "abc1234", unfixed: 0, retries: 0, assumed: -1 }] }), /loopEnd\.phases\[0\]\.assumed must be a non-negative integer/],
|
||||
["a bad commit hash", goodEnd({ phases: [{ n: 1, name: "Setup", commit: "zzz", unfixed: 0, retries: 0 }] }), /loopEnd\.phases\[0\]\.commit must be a short hex hash or null/],
|
||||
["a forbidden completion marker in line", goodEnd({ line: "TASK_COMPLETE" }), /loopEnd\.line: contains a loop completion marker/],
|
||||
["a two-line reason", goodEnd({ reason: "one\ntwo" }), /loopEnd\.reason must be one line/],
|
||||
["a recommend the screen does not offer", goodEnd({ can: ["resume", "dashboard"], recommend: "fix" }), /loopEnd\.recommend must be resume, fix or finalize, and one of can/],
|
||||
["a recommend that is not a choice", goodEnd({ can: ["ask", "resume"], recommend: "ask" }), /loopEnd\.recommend must be resume, fix or finalize/],
|
||||
["a phase that is not a positive integer", goodEnd({ phase: 0 }), /loopEnd\.phase must be a positive integer/],
|
||||
];
|
||||
for (const [what, end, expected] of cases) {
|
||||
const { problems } = tryPatch(loopState(), { loopEnd: end });
|
||||
|
||||
@@ -284,10 +284,140 @@ test("a stopped loop offers Ask a question, which tells the app and wakes no loo
|
||||
if (ask) ask.click();
|
||||
return { labels: buttons.map((b) => b.textContent), told: window.__told.map((x) => x.plan2code) };
|
||||
});
|
||||
assert.deepEqual(seen.labels, ["Ask a question", "Resume the loop", "Fix it by hand", "Back to the dashboard"]);
|
||||
assert.deepEqual(seen.labels, ["Ask a question", "Continue building", "Fix together with an agent", "Back to the dashboard"]);
|
||||
assert.deepEqual(seen.told, ["loop-ask"]);
|
||||
});
|
||||
|
||||
// Draws a stopped card in the page and reads what a person sees on it.
|
||||
async function drawStop(s, end) {
|
||||
return s.page.evaluate(async (end) => {
|
||||
const m = await import(new URL("screens/ending.js", document.baseURI).href);
|
||||
const card = m.renderLoopEnd(end);
|
||||
const choices = [...card.querySelectorAll(".loop-end-choice")];
|
||||
const details = card.querySelector("details.loop-end-details");
|
||||
return {
|
||||
heading: card.querySelector("h2").textContent,
|
||||
line: card.querySelector(".loop-line")?.textContent ?? null,
|
||||
safe: card.querySelector(".loop-end-safe")?.textContent ?? null,
|
||||
choices: choices.map((c) => ({ label: c.querySelector("button").textContent, primary: c.querySelector("button").classList.contains("primary"), hint: c.querySelector(".loop-end-hint").textContent })),
|
||||
details: details ? { open: details.open, summary: details.querySelector("summary").textContent, hasTable: Boolean(details.querySelector("table")), files: details.querySelectorAll("li").length } : null,
|
||||
tableOutside: Boolean(card.querySelector(":scope > table")),
|
||||
order: [...card.children].map((c) => c.className || c.tagName),
|
||||
};
|
||||
}, end);
|
||||
}
|
||||
|
||||
const HARD_STOP = {
|
||||
kind: "stopped",
|
||||
line: "Phase 3 stopped: 1 test outside this spec failed (test-web-console-shape.mjs: a raw locator.evaluate reads a style and the redraw replaced the card in between)",
|
||||
reason: "Phase 3 stopped on a problem the loop cannot fix by itself.",
|
||||
recommend: "fix",
|
||||
phase: 3,
|
||||
// Phase 4 is still to come: the button lines must name Phase 3, not the last row.
|
||||
phases: [{ n: 2, name: "API", commit: "abc1234", unfixed: 0, retries: 0 }, { n: 3, name: "Docs", commit: null, unfixed: 0, retries: 0 }, { n: 4, name: "Polish", commit: null, unfixed: 0, retries: 0 }],
|
||||
uncommitted: ["src/a.js", "src/b.js"],
|
||||
can: ["ask", "resume", "fix", "dashboard"],
|
||||
};
|
||||
|
||||
test("a stopped loop leads with its short reason and puts the long line under it", async (t) => {
|
||||
const s = await openSetup(t);
|
||||
const seen = await drawStop(s, HARD_STOP);
|
||||
assert.equal(seen.heading, HARD_STOP.reason);
|
||||
assert.equal(seen.line, HARD_STOP.line, "the full line is still there, under the heading");
|
||||
const old = await drawStop(s, { ...HARD_STOP, reason: undefined, recommend: undefined });
|
||||
assert.equal(old.heading, HARD_STOP.line, "an older app without a reason keeps its line as the heading");
|
||||
});
|
||||
|
||||
test("every stop-screen button carries one plain line saying what it does", async (t) => {
|
||||
const s = await openSetup(t);
|
||||
const seen = await drawStop(s, HARD_STOP);
|
||||
assert.deepEqual(
|
||||
seen.choices.map((c) => [c.label, c.hint]),
|
||||
[
|
||||
["Ask a question", "Wake an agent that answers your questions in the Ask tab. It changes nothing."],
|
||||
["Continue building", "Carry on unattended from Phase 3, the way the loop was running."],
|
||||
["Fix together with an agent", "Open a normal session on Phase 3 to fix this together with an agent."],
|
||||
["Back to the dashboard", "Leave this screen and pick another skill. Your work stays as it is."],
|
||||
],
|
||||
);
|
||||
const old = await drawStop(s, { ...HARD_STOP, phase: undefined });
|
||||
assert.equal(old.choices[1].hint, "Carry on unattended from where it stopped, the way the loop was running.", "an older app names no phase, and the line guesses none");
|
||||
const fin = await drawStop(s, { kind: "finished", line: "All 2 phases built", phases: [], uncommitted: [], can: ["finalize", "dashboard"] });
|
||||
assert.deepEqual(fin.choices.map((c) => c.hint), ["Write the feature's summary and move its spec to specs--completed/.", "Leave this screen and pick another skill. Your work stays as it is."]);
|
||||
assert.deepEqual(fin.choices.map((c) => c.primary), [true, false], "Finalize is the finish screen's one primary button");
|
||||
});
|
||||
|
||||
test("only the recommended button is primary: Fix together after a hard stop, Continue building after a soft one", async (t) => {
|
||||
const s = await openSetup(t);
|
||||
const hard = await drawStop(s, HARD_STOP);
|
||||
assert.deepEqual(hard.choices.filter((c) => c.primary).map((c) => c.label), ["Fix together with an agent"]);
|
||||
const soft = await drawStop(s, { ...HARD_STOP, reason: "Phase 3 stopped because the agent crashed.", recommend: "resume" });
|
||||
assert.deepEqual(soft.choices.filter((c) => c.primary).map((c) => c.label), ["Continue building"]);
|
||||
const old = await drawStop(s, { ...HARD_STOP, recommend: undefined });
|
||||
assert.deepEqual(old.choices.filter((c) => c.primary).map((c) => c.label), ["Continue building"], "an older app's stop keeps Continue building as the one primary");
|
||||
});
|
||||
|
||||
test("a stop says nothing is lost and keeps the phases and files under a closed Details, below the buttons", async (t) => {
|
||||
const s = await openSetup(t);
|
||||
const seen = await drawStop(s, HARD_STOP);
|
||||
assert.equal(seen.safe, "Nothing is lost. Your work stays on disk.");
|
||||
assert.deepEqual(seen.details, { open: false, summary: "Details: 3 phases, 2 uncommitted files", hasTable: true, files: 2 });
|
||||
assert.equal(seen.tableOutside, false, "no commit table between the reason and the buttons");
|
||||
const at = (cls) => seen.order.findIndex((c) => String(c).includes(cls));
|
||||
assert.ok(at("loop-end-safe") < at("loop-end-actions") && at("loop-end-actions") < at("loop-end-details"), seen.order.join(" > "));
|
||||
const fin = await drawStop(s, { kind: "finished", line: "All 1 phases built", phases: [{ n: 1, name: "API", commit: "abc1234", unfixed: 0, retries: 0 }], uncommitted: [], can: ["finalize", "dashboard"] });
|
||||
assert.equal(fin.safe, null, "the finish screen has nothing to reassure about");
|
||||
assert.equal(fin.details, null);
|
||||
assert.equal(fin.tableOutside, true, "the finish keeps its counts open");
|
||||
});
|
||||
|
||||
test("once the app starts the Ask agent, Ask a question opens the Ask tab and never asks the app twice", async (t) => {
|
||||
const s = await openSetup(t);
|
||||
await frameInFakeApp(s);
|
||||
const seen = await s.page.evaluate(async (end) => {
|
||||
const m = await import(new URL("screens/ending.js", document.baseURI).href);
|
||||
const { page } = await import(new URL("state.js", document.baseURI).href);
|
||||
const askOf = (card) => [...card.querySelectorAll(".loop-end-choice")].find((c) => c.querySelector("button").textContent.includes("Ask"));
|
||||
const first = askOf(m.renderLoopEnd(end));
|
||||
first.querySelector("button").click();
|
||||
page.loopAction = { kind: "loop-ask-result", ok: true, error: null };
|
||||
const after = askOf(m.renderLoopEnd(end));
|
||||
const label = after.querySelector("button").textContent;
|
||||
const hint = after.querySelector(".loop-end-hint").textContent;
|
||||
after.querySelector("button").click();
|
||||
const view = page.view;
|
||||
page.view = "questions";
|
||||
page.loopAction = null;
|
||||
return { label, hint, view, told: window.__told.map((x) => x.plan2code) };
|
||||
}, HARD_STOP);
|
||||
assert.equal(seen.label, "Open the Ask tab");
|
||||
assert.equal(seen.hint, "The Ask agent is ready. Type your question in the Ask tab.");
|
||||
assert.equal(seen.view, "ask");
|
||||
assert.deepEqual(seen.told, ["loop-ask"], "the second press went to the Ask tab, not to the app");
|
||||
});
|
||||
|
||||
test("after Continue building replaces the Ask agent, the same stop again offers Ask a question afresh", async (t) => {
|
||||
const s = await openSetup(t);
|
||||
await frameInFakeApp(s);
|
||||
const seen = await s.page.evaluate(async (end) => {
|
||||
const m = await import(new URL("screens/ending.js", document.baseURI).href);
|
||||
const { page } = await import(new URL("state.js", document.baseURI).href);
|
||||
const button = (card, text) => [...card.querySelectorAll(".loop-end-choice button")].find((b) => b.textContent.includes(text));
|
||||
button(m.renderLoopEnd(end), "Ask").click();
|
||||
page.loopAction = { kind: "loop-ask-result", ok: true, error: null };
|
||||
const asked = button(m.renderLoopEnd(end), "Ask").textContent;
|
||||
button(m.renderLoopEnd(end), "Continue building").click();
|
||||
page.loopAction = { kind: "loop-resume-result", ok: true, error: null };
|
||||
// The loop ran and stopped again, the same way.
|
||||
const again = button(m.renderLoopEnd(end), "Ask").textContent;
|
||||
page.loopAction = null;
|
||||
return { asked, again, told: window.__told.map((x) => x.plan2code) };
|
||||
}, HARD_STOP);
|
||||
assert.equal(seen.asked, "Open the Ask tab");
|
||||
assert.equal(seen.again, "Ask a question", "no Ask agent is left to open");
|
||||
assert.deepEqual(seen.told, ["loop-ask", "loop-resume"]);
|
||||
});
|
||||
|
||||
// A real loop session: `open --loop` under the app's signal stamps the lock.
|
||||
async function openLoopPage(t) {
|
||||
return openSession(await suite.browser(), {
|
||||
@@ -353,7 +483,7 @@ test("a finished loop and a stop with no Ask keep the notes panel's old words",
|
||||
assert.ok(!aside.text.includes(ASK_HINT), "a finished loop does not offer Ask");
|
||||
assert.match(aside.text, /Nothing was said about this one/);
|
||||
s.post({ loopEnd: { ...STOPPED, can: ["resume", "fix", "dashboard"] } });
|
||||
await s.page.getByRole("button", { name: "Resume the loop" }).waitFor();
|
||||
await s.page.getByRole("button", { name: "Continue building" }).waitFor();
|
||||
aside = await asideOf(s);
|
||||
assert.ok(!aside.text.includes(ASK_HINT), "no Ask button, so no hint to press it");
|
||||
assert.match(aside.text, /Nothing was said about this one/);
|
||||
|
||||
@@ -266,7 +266,7 @@ export async function cmdOpen() {
|
||||
s.setup = { forCli: args["for-cli"] || null, token: newToken(), created: nowIso() };
|
||||
}
|
||||
// The loop lock follows the flag: --loop locks the page, and a resume
|
||||
// without it (Fix it by hand, from a stop screen) is an ordinary,
|
||||
// without it (Fix together with an agent, from a stop screen) is an ordinary,
|
||||
// unlocked session. `loopExpect` goes with the lock: the app restamps it
|
||||
// on its next look, so a stale setup never judges a new run.
|
||||
if (loopMode) s.loop = loopLock();
|
||||
|
||||
@@ -1369,6 +1369,19 @@ export function loopEndProblems(e, state) {
|
||||
if (!Array.isArray(e.can) || !e.can.every((c) => LOOP_CAN.includes(c))) {
|
||||
bad("can", `must be an array with entries from ${LOOP_CAN.join(", ")}`);
|
||||
}
|
||||
// `reason` (the stop screen's short heading) and `recommend` (the one button
|
||||
// drawn as primary) are optional: an older app sends neither.
|
||||
if (e.reason !== undefined) {
|
||||
if (!oneLine(e.reason, 200)) bad("reason", "must be one line of 1 to 200 characters");
|
||||
else prose("reason", e.reason);
|
||||
}
|
||||
if (e.phase !== undefined && !isPosInt(e.phase)) bad("phase", "must be a positive integer");
|
||||
if (e.recommend !== undefined && e.recommend !== null) {
|
||||
const offered = Array.isArray(e.can) ? e.can : [];
|
||||
if (!["resume", "fix", "finalize"].includes(e.recommend) || !offered.includes(e.recommend)) {
|
||||
bad("recommend", "must be resume, fix or finalize, and one of can");
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
@@ -2314,15 +2314,21 @@
|
||||
the loop stops.
|
||||
</li>
|
||||
<li>
|
||||
A stop screen says what failed and shows the evidence.
|
||||
<strong>Resume the loop</strong> carries on from that phase;
|
||||
<strong>Fix it by hand</strong> opens an ordinary Implement session
|
||||
on it.
|
||||
A stop screen leads with why it stopped, and the evidence is one
|
||||
button away. Every button has a line saying what it does, and the
|
||||
one that fits the stop is highlighted.
|
||||
<strong>Continue building</strong> carries on unattended from that
|
||||
phase (recommended when the agent crashed, went quiet or you
|
||||
stopped it); <strong>Fix together with an agent</strong> opens an
|
||||
ordinary Implement session on it (recommended when a check failed,
|
||||
a task is blocked or the commit was refused).
|
||||
<strong>Ask a question</strong> wakes an agent that only answers,
|
||||
in the Ask tab. Nothing is lost on a stop: your work stays on disk.
|
||||
</li>
|
||||
</ul>
|
||||
<h4>The report</h4>
|
||||
<p>
|
||||
One report follows the whole build, across stops and Resume: what each
|
||||
One report follows the whole build, across stops and Continue building: what each
|
||||
phase built and committed, the findings it fixed, the findings it chose
|
||||
not to fix and why, the findings left open, each assumption, any other
|
||||
decisions the agent reported, and every retry and stop. The agent writes
|
||||
|
||||
@@ -163,18 +163,55 @@ function closeGuideHeld() {
|
||||
// second press cannot send the same request twice.
|
||||
let loopPressed = null;
|
||||
|
||||
// The stop screen's Ask agent is up once the app answered a press of Ask a
|
||||
// question: from then on the button opens the Ask tab, so it can never ask the
|
||||
// app for a second agent. Keyed by the ending it was pressed on.
|
||||
let askUpFor = null;
|
||||
|
||||
// Whether the stop screen's Details is open, kept across redraws (keyed like askUpFor).
|
||||
let loopDetailsOpen = null;
|
||||
|
||||
const LOOP_BUTTONS = [
|
||||
["ask", "loop-ask", "Ask a question", ""],
|
||||
["resume", "loop-resume", "Resume the loop", "primary"],
|
||||
["fix", "loop-fix", "Fix it by hand", ""],
|
||||
["finalize", "loop-finalize", "Finalize", "primary"],
|
||||
["dashboard", "loop-dashboard", "Back to the dashboard", ""],
|
||||
["ask", "loop-ask", "Ask a question"],
|
||||
["resume", "loop-resume", "Continue building"],
|
||||
["fix", "loop-fix", "Fix together with an agent"],
|
||||
["finalize", "loop-finalize", "Finalize"],
|
||||
["dashboard", "loop-dashboard", "Back to the dashboard"],
|
||||
];
|
||||
|
||||
/** One plain sentence under each stop-screen button: what pressing it does. */
|
||||
function loopButtonLine(key, phase, askUp) {
|
||||
const at = phase ? `Phase ${phase}` : "the stopped phase";
|
||||
switch (key) {
|
||||
case "ask":
|
||||
return askUp ? "The Ask agent is ready. Type your question in the Ask tab." : "Wake an agent that answers your questions in the Ask tab. It changes nothing.";
|
||||
case "resume":
|
||||
return phase ? `Carry on unattended from Phase ${phase}, the way the loop was running.` : "Carry on unattended from where it stopped, the way the loop was running.";
|
||||
case "fix":
|
||||
return `Open a normal session on ${at} to fix this together with an agent.`;
|
||||
case "finalize":
|
||||
return "Write the feature's summary and move its spec to specs--completed/.";
|
||||
case "dashboard":
|
||||
return "Leave this screen and pick another skill. Your work stays as it is.";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/** The one button drawn as primary: the app's pick when it offers it, else Continue building or Finalize. */
|
||||
function loopRecommended(end, can) {
|
||||
if (typeof end.recommend === "string" && can.includes(end.recommend)) return end.recommend;
|
||||
return ["resume", "finalize"].find((k) => can.includes(k)) || null;
|
||||
}
|
||||
|
||||
function shortHash(h) {
|
||||
return typeof h === "string" ? h.slice(0, 7) : "";
|
||||
}
|
||||
|
||||
function loopEndKey(end) {
|
||||
return `${end.kind}|${end.line}|${end.reason || ""}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* How the Implementation Loop ended, drawn from the app's `loopEnd`: a stop
|
||||
* (why, what was committed, what is left uncommitted, what can be done next) or
|
||||
@@ -185,8 +222,11 @@ export function renderLoopEnd(end) {
|
||||
const card = el("article", "card handoff loop-end");
|
||||
const finished = end.kind === "finished";
|
||||
card.appendChild(el("p", "card-kicker", finished ? "Loop finished" : "Loop stopped"));
|
||||
card.appendChild(el("h2", null, finished ? "Every phase is built" : end.line));
|
||||
if (finished && end.line) card.appendChild(el("p", "loop-line", end.line));
|
||||
// A stop leads with the app's short reason; the full line, which can run
|
||||
// long, goes under it rather than in the heading.
|
||||
const reason = !finished && typeof end.reason === "string" && end.reason ? end.reason : "";
|
||||
card.appendChild(el("h2", "loop-end-heading", finished ? "Every phase is built" : reason || end.line));
|
||||
if ((finished || reason) && end.line) card.appendChild(el("p", "loop-line", end.line));
|
||||
|
||||
const evidence = end.evidence && docs().find((d) => d.id === end.evidence);
|
||||
if (evidence) {
|
||||
@@ -199,7 +239,12 @@ export function renderLoopEnd(end) {
|
||||
card.appendChild(read);
|
||||
}
|
||||
|
||||
// The record (phases with their commits, files left uncommitted). On a stop
|
||||
// it sits under Details, below the choice, so the reason and the buttons come
|
||||
// first; the finish screen keeps its table open, since the counts are its point.
|
||||
const phases = Array.isArray(end.phases) ? end.phases : [];
|
||||
const files = Array.isArray(end.uncommitted) ? end.uncommitted : [];
|
||||
const record = [];
|
||||
if (phases.length) {
|
||||
const table = el("table", "loop-end-phases");
|
||||
const head = el("tr");
|
||||
@@ -220,46 +265,83 @@ export function renderLoopEnd(end) {
|
||||
}
|
||||
table.appendChild(row);
|
||||
}
|
||||
card.appendChild(table);
|
||||
record.push(table);
|
||||
}
|
||||
|
||||
const files = Array.isArray(end.uncommitted) ? end.uncommitted : [];
|
||||
if (files.length) {
|
||||
card.appendChild(el("h3", null, "Uncommitted in this phase"));
|
||||
record.push(el("h3", null, "Uncommitted in this phase"));
|
||||
const list = el("ul", "loop-end-files");
|
||||
const fill = (items, into) => items.forEach((f) => into.appendChild(el("li", null, f)));
|
||||
fill(files.slice(0, 10), list);
|
||||
record.push(list);
|
||||
if (files.length > 10) {
|
||||
const more = el("details");
|
||||
more.appendChild(el("summary", null, `${files.length - 10} more files`));
|
||||
const rest = el("ul", "loop-end-files");
|
||||
fill(files.slice(10), rest);
|
||||
more.appendChild(rest);
|
||||
card.append(list, more);
|
||||
} else {
|
||||
card.appendChild(list);
|
||||
record.push(more);
|
||||
}
|
||||
}
|
||||
if (finished) record.forEach((node) => card.appendChild(node));
|
||||
|
||||
const can = Array.isArray(end.can) ? end.can : [];
|
||||
const key = loopEndKey(end);
|
||||
if (page.loopAction && page.loopAction.kind === "loop-ask-result" && page.loopAction.ok) askUpFor = key;
|
||||
const askUp = askUpFor === key;
|
||||
const recommended = loopRecommended(end, can);
|
||||
// The phase Continue building starts on, as the app names it: the last row of
|
||||
// `phases` can be a phase the run never reached.
|
||||
const stoppedPhase = Number.isInteger(end.phase) && end.phase > 0 ? end.phase : null;
|
||||
|
||||
// A stop never throws work away: the app only ends the agent and, at most,
|
||||
// takes files back out of the index.
|
||||
if (!finished && can.length) card.appendChild(el("p", "loop-end-safe", "Nothing is lost. Your work stays on disk."));
|
||||
|
||||
const actions = el("div", "loop-end-actions");
|
||||
for (const [key, message, label, kind] of LOOP_BUTTONS) {
|
||||
if (!can.includes(key)) continue;
|
||||
const b = el("button", "btn" + (kind ? " " + kind : ""), label);
|
||||
for (const [k, message, label] of LOOP_BUTTONS) {
|
||||
if (!can.includes(k)) continue;
|
||||
const choice = el("div", "loop-end-choice" + (k === recommended ? " is-recommended" : ""));
|
||||
const asked = k === "ask" && askUp;
|
||||
const b = el("button", "btn" + (k === recommended ? " primary" : ""), asked ? "Open the Ask tab" : label);
|
||||
b.type = "button";
|
||||
b.disabled = page.gone || (loopPressed === message && !page.loopAction);
|
||||
b.disabled = page.gone || (!asked && loopPressed === message && !page.loopAction);
|
||||
b.addEventListener("click", () => {
|
||||
if (asked) {
|
||||
page.view = "ask";
|
||||
redraw();
|
||||
return;
|
||||
}
|
||||
// Any other press replaces the Ask agent, so its button must ask again on
|
||||
// the next stop, even one that reads the same.
|
||||
askUpFor = null;
|
||||
loopDetailsOpen = null;
|
||||
loopPressed = message;
|
||||
page.loopAction = null;
|
||||
tellApp(message);
|
||||
redraw();
|
||||
});
|
||||
actions.appendChild(b);
|
||||
choice.appendChild(b);
|
||||
choice.appendChild(el("p", "loop-end-hint", loopButtonLine(k, stoppedPhase, asked)));
|
||||
actions.appendChild(choice);
|
||||
}
|
||||
if (actions.childElementCount) card.appendChild(actions);
|
||||
if (page.loopAction && !page.loopAction.ok) {
|
||||
card.appendChild(el("p", "loop-error", page.loopAction.error));
|
||||
}
|
||||
|
||||
if (!finished && record.length) {
|
||||
const details = el("details", "loop-end-details");
|
||||
details.open = loopDetailsOpen === key;
|
||||
details.addEventListener("toggle", () => {
|
||||
loopDetailsOpen = details.open ? key : null;
|
||||
});
|
||||
const parts = [];
|
||||
if (phases.length) parts.push(phases.length === 1 ? "1 phase" : `${phases.length} phases`);
|
||||
if (files.length) parts.push(files.length === 1 ? "1 uncommitted file" : `${files.length} uncommitted files`);
|
||||
details.appendChild(el("summary", null, `Details: ${parts.join(", ")}`));
|
||||
record.forEach((node) => details.appendChild(node));
|
||||
card.appendChild(details);
|
||||
}
|
||||
return card;
|
||||
}
|
||||
|
||||
|
||||
@@ -701,4 +701,13 @@
|
||||
.loop-end-phases th, .loop-end-phases td { text-align: left; padding: 5px 10px 5px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
|
||||
.loop-end-phases code { font-family: var(--mono); font-size: 12px; }
|
||||
.loop-end-files { margin: 0; padding-left: 18px; font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
|
||||
.loop-end-actions { display: flex; flex-wrap: wrap; gap: 10px; }
|
||||
.loop-end-heading, .loop-end .loop-line { overflow-wrap: anywhere; }
|
||||
/* Each button with one plain line under it saying what it does. */
|
||||
.loop-end-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
|
||||
.loop-end-choice { display: grid; gap: 6px; align-content: start; justify-items: start; }
|
||||
.loop-end-choice .btn { max-width: 100%; }
|
||||
.loop-end-hint { margin: 0; font-size: 13px; line-height: 1.45; color: var(--ink-2); }
|
||||
.loop-end-safe { margin: 0; font-size: 13.5px; color: var(--ink-2); }
|
||||
.loop-end-details { display: grid; gap: 10px; }
|
||||
.loop-end-details > summary { cursor: pointer; font-size: 13.5px; color: var(--ink-2); }
|
||||
.loop-end-details[open] > summary { margin-bottom: 8px; }
|
||||
Reference in new issue
Block a user