Make the Loop stopped screen say why and recommend one button

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-09 15:32:04 -08:00
1 parent b585eccd5a
commit 785a4dc8b9
11 files changed
+500 -54

No files matched your search

+1 -1
View File
@@ -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();
+13
View File
@@ -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;
}
+11 -5
View File
@@ -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
+101 -19
View File
@@ -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;
}
+10 -1
View File
@@ -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; }