Refuse a new question until a noted one is dealt with

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-09 10:08:45 -08:00
1 parent 92d4d880bf
commit 1a17578aa9
19 files changed
+475 -24

No files matched your search

+10 -4
View File
@@ -68,10 +68,16 @@ port, and the filesystem as transport; this CLI is the whole agent surface.
then waits up to N seconds in the same command (two JSON lines;
the exit code is the wait's). The patch may carry settle: true
(or a list of item ids) to mark the latest send's cards answered
with what was sent; doc blocks may carry file: "<path>" (and
select: "tasks"), read from the project, and a doc refresh: true
re-reads them. A doc's version moves up by itself. A patch may
carry run: { event, id, tasks? } (session meter points) and folderIssue:
with what was sent. An item may carry stands: true, saying it
still applies after its note's thread reply: it clears the
item's noted flag (set when the person's note lands on an open
question) and is never stored. While any open item is noted, a
patch adding a new open required question is refused unless it
also rewords, deletes ("_delete": true) or stands each one. Doc
blocks may carry file: "<path>" (and select: "tasks"), read from
the project, and a doc refresh: true re-reads them. A doc's
version moves up by itself. A patch may carry run: { event, id,
tasks? } (session meter points) and folderIssue:
{ name, reason, hint? } (a workspace folder you could not read);
both go to the ledger, never into the state. A patch may also
carry helpers: [{ id, title, ask, state, result?, strength?,
+2
View File
@@ -77,6 +77,8 @@ Items show in the order sent: send them in the order you want them answered.
Every note in an item's `thread` gets a reply: `{"id":"p4","thread":[{"who":"agent","text":"..."}]}`. Send only new entries.
After the person's note on an open question, reword it (same `id`), retire it with `"_delete":true`, or send `"stands":true` if it still applies, in the patch with your reply or your next question. Until you do, a new open required question is refused. Do the same when an Ask reply or your own finding changes what a question assumed.
## What the console refuses (exit 3)
- more than three open required questions at once (optional cards and notices do not count)
+1
View File
@@ -3,6 +3,7 @@
- Post `"stopWarning"` while no map exists (Steps 0 to 4), `""` once it does, and `"specDir":"specs/<idea>"` when the folder is created.
- The menu after a decision is a `menu` card: `options` are `trail --form C`'s, the `Start fresh` one keeps `"fresh":true`. Set the card's `command` to the resume command printed under `OR START FRESH`. A declined confirm leaves you the pick: carry on as for `Start fresh`.
- The fresh-idea card carries `"templates":"idea"`, `"fill":"note"`.
- A note on an open question: reword it (same `id`), `"_delete":true` it or send `"stands":true` on it if it still fits, in the patch with your reply.
- A doc that is a file as written (the map, a brief) is a `file` block (`{"id":"body","file":"specs/<idea>/pathfinder/map.md"}`). Keep `md` where `assumed` / `draft` state matters.
- Step 8 research subagents all report before the finish; the finish `body` names what each found. Report every one as a helper, whatever the Subagents switch says.
- Every session end `finish`es with Form A's command as `command`.
+1
View File
@@ -1,6 +1,7 @@
# Planning
- Phase breakdowns are an editable `list`. The fresh-idea card carries `"templates":"idea"`, `"fill":"note"`.
- A note on an open question: reword it, `"_delete":true` it or send `"stands":true` (still fits), with your reply.
- Nothing is saved before the Large checkpoint or Phase 7: a stop before then has `finish.body` say nothing was kept, `"command":"/plan2code-1-plan"`. After the checkpoint post `"stopWarning":""`.
- Completion finish `command`: `/plan2code-2-document`. The Large checkpoint finish is a pause: headline starts "Paused", `command` `/plan2code-1-plan`, no `dashboard`.
- Helpers are reported as `helpers`, each `done` or `failed` before the sign-off it feeds. Questions, sign-offs and the PLAN-DRAFT stay with you.
+1
View File
@@ -3,6 +3,7 @@
Read `building.md` first.
- Clarifying questions are `text` or `choice`. The first (what to build) carries `"templates":"idea"`, `"fill":"note"`.
- A note on an open question: reword it, `"_delete":true` it or send `"stands":true` (still fits), with your reply.
- Post `"stopWarning":"A quick task saves nothing until it is built, so stopping now loses what we have worked out."` at the start and `""` once the build is under way.
- **Scope check:** `choice` "Too big for a quick task?": `1` Continue (lightweight format), `2` Escalate to a full plan; measured counts against thresholds in `body`.
- **Feature name** (escalating): `text`, `"pattern":"^[a-z0-9]+(-[a-z0-9]+)*$"`, kebab-case placeholder.
+83 -14
View File
@@ -123,10 +123,21 @@ const QUESTION_FIELDS = ["kind", "title", "body", "options", "steps", "rows", "s
* settle it, that record (and any stale `answer`) is dropped, so the page shows
* the new question as open instead of "Sent, waiting for Plan2Code" forever.
*/
function dropStaleSubmissions(currentItems, before, patchList) {
function dropStaleSubmissions(currentItems, before, patchList, stands = new Set()) {
const merged = mergeKeyed(currentItems, patchList, "id", ITEM_DEFAULTS, "items");
for (const entry of patchList) {
const prev = (before || []).find((x) => x.id === entry.id);
// The person's note landed on this question (`noted`, set by the server).
// It stays until the agent deals with the question: rewords it, settles it,
// or says in the patch that the question stands as it is.
if (prev && prev.noted) {
const reworded = ["title", "body", "options"].some(
(f) => f in entry && JSON.stringify(entry[f]) !== JSON.stringify(prev[f]),
);
const settled = entry.status === "answered" || entry.status === "skipped" || "answer" in entry;
const item = merged.find((x) => x.id === entry.id);
if (item && (reworded || settled || stands.has(entry.id))) delete item.noted;
}
// A whole new question under an answered card's id is not a typo fix: the
// card would stay answered and nothing would be left for the person, who
// sees a dead page. Refuse it so the agent picks a new id on the spot.
@@ -296,8 +307,11 @@ function settleItems(items, settle, patchItems, collected) {
// report) means it is not settled: no answer is recorded over the reopen.
if (entry.status === "open" || entry.status === "reopened") return item;
const { at, kind, ...answer } = item.submitted;
// A settled card has been dealt with, so a note on it no longer holds
// anything up, even when it is reopened later.
const { noted: _noted, ...settled } = item;
return {
...item,
...settled,
// A "Skip this one" send settles as skipped, not as an answer.
status: "status" in entry ? item.status : answer.skipped === true ? "skipped" : "answered",
...("answer" in entry ? {} : { answer }),
@@ -531,8 +545,22 @@ export function applyPatch(state, patch) {
break;
case "items":
if (!Array.isArray(v)) throw new Error(rule("", "items", "must be an array", { items: [{ id: "q7", kind: "text", title: "Name" }] }));
next.items = dropStaleSubmissions(next.items, state.items, normalizeThreads(letterOptions(v), state.items));
break;
{
// `stands: true` says "the question is still right after the note". It
// only clears `noted`, so it is never stored.
const stands = new Set();
const list = v.map((entry) => {
if (!isPlainObject(entry) || !("stands" in entry)) return entry;
if (typeof entry.stands !== "boolean") {
throw new Error(rule(`item "${entry.id}"`, "stands", "must be true or false", { stands: true }));
}
if (entry.stands) stands.add(entry.id);
const { stands: _stands, ...rest } = entry;
return rest;
});
next.items = dropStaleSubmissions(next.items, state.items, normalizeThreads(letterOptions(list), state.items), stands);
break;
}
case "topics":
if (!Array.isArray(v)) throw new Error(rule("", "topics", "must be an array", { topics: [{ id: "t2", title: "How it behaves", status: "current" }] }));
next.topics = mergeKeyed(next.topics, v, "id", {}, "topics");
@@ -610,9 +638,59 @@ export function applyPatch(state, patch) {
if (next.finish && !Object.hasOwn(patch, "finish") && asksSomething(patch.items, state.items)) {
delete next.finish;
}
refuseQuestionPastNote(state, next);
return stampTimes(state, settleAgent(next, patch, state));
}
/**
* A question the person put a note on (`noted`, set by the server) stays in
* front of them until the agent deals with it. A new question asked past it
* would be buried behind a card the reply may have made moot, so the patch
* that adds one must also reword, delete or confirm (`stands`) every noted
* card. Only a new open required question counts: a reply alone, an optional
* card or a notice asks nothing new. A finish ends the session, and the
* dashboard draws no cards, so neither is held to it.
*/
function refuseQuestionPastNote(before, next) {
if (next.finish != null || next.workflow === "dashboard" || !Array.isArray(next.items)) return;
const noted = next.items.filter((i) => isPlainObject(i) && i.noted === true && isOpen(i));
if (!noted.length) return;
const had = new Set((Array.isArray(before.items) ? before.items : []).map((i) => i && i.id));
const asksNew = next.items.some(
(i) => isPlainObject(i) && !had.has(i.id) && i.required !== false && i.kind !== "notice" && i.noted !== true && isOpen(i),
);
if (!asksNew) return;
// A note not yet replied to is named too: validate() never runs after this
// throw, and the agent would otherwise fix one and be refused for the other.
throw new Error(
noted
.flatMap((i) => [
...(lastWordIsTheirs(i) ? [unansweredNote(i)] : []),
rule(
`item "${i.id}"`,
"noted",
'has a note from the person that you answered in the thread: reword it, delete it ("_delete": true) or send "stands": true, in the same patch that adds a new question',
{ id: i.id, stands: true },
),
])
.join("\n"),
);
}
// The person had the last word in a card's thread: their note waits for a reply.
function lastWordIsTheirs(item) {
const thread = Array.isArray(item.thread) ? item.thread : [];
const last = thread[thread.length - 1];
return isPlainObject(last) && last.who === "user";
}
function unansweredNote(item) {
return rule(`item "${item.id}"`, "thread", "has an unanswered note from the person; reply in its thread in this patch", {
id: item.id,
thread: [{ who: "agent", text: "..." }],
});
}
// `activity` belongs under `agent`, which is the only place the page reads it.
// Sent at the top level it would be stored where nothing looks, and the page
// would sit on its starting screen while the skill works.
@@ -862,16 +940,7 @@ export function validate(state) {
// nothing further is coming to answer into.
if (state.finish == null) {
for (const item of state.items) {
const thread = Array.isArray(item.thread) ? item.thread : [];
const last = thread[thread.length - 1];
if (isPlainObject(last) && last.who === "user") {
problems.push(
rule(`item "${item.id}"`, "thread", "has an unanswered note from the person; reply in its thread in this patch", {
id: item.id,
thread: [{ who: "agent", text: "..." }],
}),
);
}
if (lastWordIsTheirs(item)) problems.push(unansweredNote(item));
}
}
+9
View File
@@ -760,6 +760,15 @@ export function renderAside() {
aside.appendChild(box);
}
// The agent answered a note and has not yet dealt with the question itself:
// say so, because the reply may have changed what the question asks.
const last = thread[thread.length - 1];
if (item.noted === true && isOpen(item) && !finish() && last && threadWho(last) === "agent") {
const tag = el("p", "pill noted-tag", "Plan2Code replied, check this still fits");
tag.setAttribute("role", "note");
aside.appendChild(tag);
}
if (waiting && !waitingShown) {
const box = el("div", "msg you pending");
const who = el("div", "msg-who");
+37 -2
View File
@@ -523,9 +523,13 @@ export function adopt(body) {
arrived.length === 1
? "A new question from Plan2Code. It is in the list on the left."
: `${arrived.length} new questions from Plan2Code. They are in the list on the left.`;
banner(staleLine ? `${staleLine} ${arrivedLine}` : arrivedLine, "info");
// The notice stays until a click, Escape or opening the question: a
// question that arrives mid-sentence is easy to miss in eight seconds.
// The question already on screen needs no mark: it is where they are looking.
for (const q of arrived) if (!(page.view === "questions" && page.selected === q.id)) page.newQuestions.add(q.id);
arrivalNotice = staleLine ? `${staleLine} ${arrivedLine}` : arrivedLine;
banner(arrivalNotice, "info");
clearTimeout(arrivalBannerTimer);
arrivalBannerTimer = setTimeout(() => !page.gone && banner(null), 8000);
} else {
page.selected = arrived[0].id;
page.view = "questions";
@@ -534,6 +538,7 @@ export function adopt(body) {
}
if (!page.selected || !byId(page.selected)) page.selected = pickDefault();
pruneNewQuestions();
// A reply that lands while another tab is open: a dot on Ask, and one chime.
// Not on the first load, which has nothing new to announce.
const dot = unreadDot({ lastSeenReplyId: page.local.chat.lastSeenReplyId, frameChat: page.chatFrame, viewIsAsk: page.view === "ask" });
@@ -600,6 +605,24 @@ function scrollRail(where) {
}
let arrivalBannerTimer = null;
// The text of a notice that stays up (see adopt), so only that banner is cleared.
let arrivalNotice = "";
function dropArrivalNotice() {
if (arrivalNotice && $("banner").textContent === arrivalNotice) banner(null);
arrivalNotice = "";
}
// Marks that no longer apply: a question that is answered or gone, or the one
// now on screen. The notice goes with the last mark.
function pruneNewQuestions() {
const had = page.newQuestions.size;
for (const id of [...page.newQuestions]) {
const item = byId(id);
if (!item || !isOpen(item) || (page.view === "questions" && page.selected === id)) page.newQuestions.delete(id);
}
if (had && !page.newQuestions.size) dropArrivalNotice();
}
// Typing in any text field, the question's own or the notes beside it. A
// focused Markdown field surfaces as its .md-host (the editor inside its
@@ -819,6 +842,8 @@ export function render() {
if (rendering) return;
rendering = true;
try {
// A question opened by any route (the pager, a tab switch) loses its New mark.
pruneNewQuestions();
trackAbout();
const enteringAsk = page.view === "ask" && drawnView !== "ask";
const switchingTab = drawnView !== null && page.view !== drawnView;
@@ -1606,9 +1631,15 @@ export function renderSidebar() {
mark.title = m.label;
b.appendChild(mark);
b.appendChild(el("span", null, item.title));
if (page.newQuestions.has(item.id)) {
const fresh = el("span", "rail-new", "New");
fresh.title = "arrived while you were typing";
b.appendChild(fresh);
}
b.addEventListener("click", () => {
page.selected = item.id;
page.view = "questions";
pruneNewQuestions();
render();
$("main").focus();
});
@@ -2313,6 +2344,10 @@ export function wireChrome() {
true
);
// A click or Escape puts a staying arrival notice away; the list keeps the "New" mark.
document.addEventListener("pointerdown", () => arrivalNotice && dropArrivalNotice(), true);
document.addEventListener("keydown", (e) => e.key === "Escape" && arrivalNotice && dropArrivalNotice(), true);
$("meter-pill").addEventListener("click", () => toggleMeterPop());
$("meter-help").addEventListener("click", () => {
toggleMeterPop(false);
+3
View File
@@ -155,6 +155,9 @@ export const page = {
// The pose pane on screen when a render began, held back from the clear so
// posePane() can take it up again. See posePane.
heldPose: null,
// Questions that arrived while the person was typing and are not opened yet
// (a "New" mark in the list). Page-local, never saved.
newQuestions: new Set(),
// The workspace scope (a spec dir, "" for the project) this tab last asked
// for: its own pick, not whatever the frame says. And true from a launch's
// scope sync until its send has gone (or failed).
+15
View File
@@ -280,10 +280,14 @@
.card.is-inflight { border-color: var(--stage); }
.card.is-inflight .option.is-locked.is-recorded {
border-color: var(--stage);
text-transform: none;
letter-spacing: 0;
background: var(--stage-soft);
}
.card.is-inflight .option.is-locked.is-recorded:hover {
border-color: var(--stage);
text-transform: none;
letter-spacing: 0;
background: var(--stage-soft);
}
.card.is-inflight .option-mark.on { color: var(--stage); }
@@ -961,3 +965,14 @@ h4.md-h, h5.md-h, h6.md-h { font-size: 15px; }
.modal-actions:has(#stop-cancel) .btn { width: 100%; }
}
/* A noted card whose last word in the thread is the agent's reply. */
.noted-tag {
display: block;
margin: 2px 0 10px;
background: var(--stage-soft);
color: var(--stage);
border-color: var(--stage);
text-transform: none;
letter-spacing: 0;
}
+15
View File
@@ -777,3 +777,18 @@ button.waiting-jump:hover { text-decoration-color: var(--accent); }
}
@keyframes arrival-draw { from { transform: scaleX(0); } to { transform: scaleX(1); } }
/* A question that arrived while the person was typing, until it is opened. */
.rail-new {
flex: none;
align-self: flex-start;
margin-top: 2px;
padding: 0 6px;
border-radius: 999px;
font-size: 10.5px;
font-weight: 700;
letter-spacing: .04em;
text-transform: uppercase;
background: var(--accent-soft);
color: var(--accent);
}
+8 -2
View File
@@ -31,7 +31,7 @@ import {
import { AGENTS_SCHEMA, makeId, normalizeAgents, resolveCommand, validateForSave } from "./agents.mjs";
import { findAgent, loadAgentList } from "./agent-lookup.mjs";
import { checkDocument, cleanupFindings, readAgentsDoc, readSpecFile, removeCleanup } from "./sessions.mjs";
import { SHOTS_DIR_NAME, SHOT_NAME, shotType } from "./patches.mjs";
import { SHOTS_DIR_NAME, SHOT_NAME, shotType, isOpen } from "./patches.mjs";
import { appendChat, currentConversation, pendingChatCount, typedCount } from "./inbox.mjs";
import { specKey } from "./workspace.mjs";
import { readLoopSetup, saveLoopSetup } from "./loop-setup.mjs";
@@ -1395,9 +1395,15 @@ function recordSubmitted(state, actions) {
// written, so a question asked in a note vanished once it was picked up
// and the reply under it answered nothing on the page. A request for
// suggestions is always written, note or not.
if (item.sentNote.text.trim() || item.sentNote.images.length || item.sentNote.files.length || item.sentNote.suggest) {
const hasNote = Boolean(item.sentNote.text.trim() || item.sentNote.images.length || item.sentNote.files.length);
if (hasNote || item.sentNote.suggest) {
item.thread = [...(Array.isArray(item.thread) ? item.thread : []), { who: "user", ...item.sentNote }];
}
// A note on a question still open marks it `noted`: the agent has to deal
// with the question before it can ask another. A request for suggestions
// is not a note on the question, and an empty comment leaves nothing in
// the thread to deal with.
if (isOpen(item) && hasNote && action.suggest !== true) item.noted = true;
continue;
}
const { i, type, ...rest } = action;