fix: pin the loop's phase and keep its session locked on resume

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-03 04:04:09 -08:00
1 parent 2acfd8907d
commit c1e32b8aca
6 files changed
+212 -55

No files matched your search

+24 -10
View File
@@ -15,7 +15,12 @@ approve.
`loopOutcome` and `handledBy` are refused. If it exits 3, the run is not inside
the app: say "Loop mode runs only inside the Plan2Code desktop app." in the
terminal and continue as an ordinary run with the person's sign-off. Skip
nothing below unless that `open` succeeded.
nothing below unless that `open` succeeded. Every later `open --resume` in
this run (the server went away: `chat` or `wait` exit 20) carries `--loop`
too, as `open --resume <sid> --workflow <yours> --loop`: a resume without it
unlocks the session, and the `loopOutcome` post is then refused.
- `--phase <N>`: the phase the app is building. Build exactly that one (see
Choosing the phase); the app refuses a report that names another.
- `--fix <levels>`: a comma list from `critical`, `warning`, `suggestion`, the
levels to fix in the one fix round. Absent means findings are reported, not
fixed.
@@ -30,7 +35,7 @@ approve.
## What changes in loop mode
- Pick the phase without asking (Choosing the phase).
- Build the phase `--phase` names, without asking (Choosing the phase).
- No sign-off card, no "Approve this phase", no Show me it working, no Continue
offer.
- Never run `specs.mjs mark --to done`, and never set `[x]` on the phase in
@@ -61,14 +66,23 @@ shows as Build, so do not invent new ones in loop mode. Keep `cleared` and
## Choosing the phase
Run `node "<S>/specs.mjs" status specs/<feature>`. A phase whose checklist marker
is `[/]` goes first; otherwise take `next.phase.number` (the first of
`next.options` when `next.action` is `choose`). Never post the "Resume?" question
or the parallel-phase pick. Set the phase in progress with
`specs.mjs mark <spec> --phase N --to in-progress`, exactly as an ordinary run
does: that mark is allowed, and only `--to done` is the app's. When `next.action`
is `none` or `checkoff` (no open phase), post a `loopOutcome` with
`result: "failed"`, `reason: "other"` and
The phase is N from `--phase N`, whatever `next` in `specs.mjs status` would
pick. Never post the "Resume?" question or the parallel-phase pick. Run
`node "<S>/specs.mjs" status specs/<feature>` and find phase N in `phases`:
- Its `checklist` is `pending` or `in-progress`: build it. Set it in progress with
`specs.mjs mark <spec> --phase N --to in-progress`, exactly as an ordinary run
does: that mark is allowed, and only `--to done` is the app's.
- It is `blocked` (`[!]`): build nothing; post a `loopOutcome` with
`result: "failed"`, `reason: "blocked"`, its `blockedTasks` ids (like `2.4`)
in `tasks.blocked` and `summary: "Phase N is marked blocked in overview.md"`.
- It is `complete` or `assumed`, or not in the checklist: build nothing; post
`result: "failed"`, `reason: "other"` and
`summary: "Phase N is not an open phase in this spec"`.
No `--phase` (an older app): take `next.phase.number` (the first of
`next.options` when `next.action` is `choose`), and when `next.action` is `none`
or `checkoff` post `result: "failed"`, `reason: "other"` and
`summary: "No open phase left in this spec"`.
## Questions and cards the loop handles
+5 -3
View File
@@ -572,7 +572,9 @@ export function applyPatch(state, patch) {
case "loopOutcome":
// The skill's one report of a phase built under the loop. The shape is
// checked by validate(); here only who may send it, and how often.
if (!state.loop?.driving) throw new Error(rule("", "loopOutcome", "is only accepted in a loop session"));
if (!state.loop?.driving) {
throw new Error(rule("", "loopOutcome", "is only accepted in a loop session; a resume without --loop unlocked it, so run open --resume <sid> --workflow <yours> --loop, then post this again"));
}
if (state.loopOutcome !== undefined) throw new Error(rule("", "loopOutcome", "was already posted for this session"));
next.loopOutcome = v;
break;
@@ -1143,9 +1145,9 @@ export function loopOutcomeProblems(o) {
r.unfixed.forEach((u, i) => {
if (!isPlainObject(u)) return bad(`review.unfixed[${i}]`, "must be an object { level, title, file? }");
if (!LOOP_LEVELS.includes(u.level)) bad(`review.unfixed[${i}].level`, `must be one of ${LOOP_LEVELS.join(", ")}`);
if (typeof u.title !== "string" || !u.title.trim()) bad(`review.unfixed[${i}].title`, "must be a non-empty string");
if (typeof u.title !== "string" || !u.title.trim() || /[\r\n]/.test(u.title)) bad(`review.unfixed[${i}].title`, "must be a non-empty one-line string");
else prose(`review.unfixed[${i}].title`, u.title);
if (u.file !== undefined && typeof u.file !== "string") bad(`review.unfixed[${i}].file`, "must be a string when present");
if (u.file !== undefined && (typeof u.file !== "string" || /[\r\n]/.test(u.file))) bad(`review.unfixed[${i}].file`, "must be a one-line string when present");
else prose(`review.unfixed[${i}].file`, u.file);
});
}
+3 -2
View File
@@ -32,7 +32,7 @@ import { SHOTS_DIR_NAME, SHOT_NAME, shotType } from "./patches.mjs";
import { appendChat, currentConversation, pendingChatCount, typedCount } from "./inbox.mjs";
import { specKey } from "./workspace.mjs";
import { readLoopSetup, saveLoopSetup } from "./loop-setup.mjs";
import { phaseChecklist } from "./spec-files.mjs";
import { MARKERS, phaseChecklist } from "./spec-files.mjs";
import {
PR_HOST_KINDS,
readSubagentSetting,
@@ -1334,8 +1334,9 @@ function loopSetupGet(req, res, ctx, url) {
let phasesLeft = [];
try {
const overview = fs.readFileSync(path.join(loopProject(ctx), spec, "overview.md"), "utf8");
// Done as specs.mjs reads it ([x], [X], [?]), the same rule the app's Start uses.
phasesLeft = phaseChecklist(overview)
.filter((p) => p.marker !== "x" && p.marker !== "X")
.filter((p) => !["complete", "assumed"].includes(MARKERS[p.marker]))
.map((p) => ({ n: p.number, name: p.name }));
} catch {
/* no overview.md: nothing to build */