Pin the lessons dialog buttons, spin while asking, widen the reply and outline suggested choices

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-17 19:19:15 -08:00
1 parent 26a87bec32
commit bf8dea9942
11 files changed
+214 -26

No files matched your search

+1 -1
View File
@@ -59,7 +59,7 @@ The seven noting skills only (and any skill sent here by Start's Review now), be
2. `items` empty and no `firstAsk`: say nothing and skip this step.
3. `firstAsk` present: see The first ask below, instead of 4 to 7.
4. Show `opening` first when present.
5. **On the web console:** post the returned `card` as one `lessons` item with `--wait` (a new `id` when an earlier lessons card is in the session). Its reply has one line per decision ("Keep: ...", "Reword: ...") and a `Decisions:` line holding them as JSON: that JSON is step 6's file, plus what a choice still needs. **In a terminal:** ask each group in `rounds` with your question tool, one question per item with exactly its `choices` and nothing pre-selected (`heading`, `text`, `why`, `origin` and `note` are what the person reads; an area shows its `name` and `paths`); with no question tool, a numbered list. A choice that needs more (step 6) asks the person for it.
5. **On the web console:** post the returned `card` as one `lessons` item with `--wait` (a new `id` when an earlier lessons card is in the session). Its reply has one line per decision ("Keep: ...", "Reword: ...") and a `Decisions:` line holding them as JSON: that JSON is step 6's file, plus what a choice still needs. A `Suggestions wanted on` line for it: reply in its `thread` and, in the same patch, send `suggested` (row id to one of that row's `choices`, such as `{"w1":"Keep"}`), which outlines those buttons without choosing them. **In a terminal:** ask each group in `rounds` with your question tool, one question per item with exactly its `choices` and nothing pre-selected (`heading`, `text`, `why`, `origin` and `note` are what the person reads; an area shows its `name` and `paths`); with no question tool, a numbered list. A choice that needs more (step 6) asks the person for it.
6. Write the decisions, one `{ "id", "choice" }` per answered item plus what its choice needs, to a JSON file in the console session folder, or the OS temp folder in a terminal, never in the project. Run `decide --file <path>` and print its `closing` line, such as "Kept 2 (1 reworded), retired 1. 1 still waiting." What a choice needs:
- Reword of a lesson, a doubt or a lesson whose files are gone: the new `text`, plus `why`, `kind`, `about` or `area` when they change.
- Rename of an area: the new `name`, plus `paths` when they change.
+1 -1
View File
@@ -65,7 +65,7 @@ Every item: `id` (new for each question, whole session), `kind`, `title` (2 to 4
| `review` | read, then approve | `doc` (required), `summary`, `verdicts:[{id,label,danger?}]`, `nothingYet` (false once the change is on disk) | `{verdict,text?}` |
| `checklist` | steps only they can do | `steps`, `valuesLabel` | `{done?,state?,text?}` |
| `list` | reorder or edit a breakdown | `rows:[{id,title,body}]` | `{rows}` or `{text}` |
| `lessons` | approve noted lessons | `rows`, `opening`, `firstAsk` (from `lessons.mjs list`) | `{decisions}` or `{firstAsk}` |
| `lessons` | approve noted lessons | `rows`, `opening`, `firstAsk` (from `lessons.mjs list`), `suggested` (row id to a choice: outlined, not picked) | `{decisions}` or `{firstAsk}` |
| `notice` | read, no answer | none | none |
Items show in the order sent, so send them in answering order.
+16
View File
@@ -924,6 +924,22 @@ function lessonsProblems(item, at) {
problems.push(rule(at, `${name} refused`, "must be the { pattern, part } lessons.mjs gave, or null", { refused: { pattern: "aws-access-key", part: "AKIA" } }));
}
});
// The agent's answer to Ask for suggestions, readable by the page: row id to
// one of that row's own choice words. It outlines a button; it never picks.
const sug = item.suggested;
const SUGGESTED_RIGHT = { suggested: { w1: "Keep", w2: "Drop" } };
if (sug != null && !isPlainObject(sug)) {
problems.push(rule(at, "suggested", "must be an object of row id to one of that row's choice words, or null", SUGGESTED_RIGHT));
} else if (sug != null) {
const byId = new Map((hasRows ? item.rows : []).filter(isPlainObject).map((r) => [r.id, r]));
for (const [id, word] of Object.entries(sug)) {
const row = byId.get(id);
if (!row) problems.push(rule(at, `suggested "${id}"`, "names no row on this card. Use the row ids the card was posted with", SUGGESTED_RIGHT));
else if (typeof word !== "string" || !(row.choices || []).includes(word)) {
problems.push(rule(at, `suggested "${id}"`, `must be one of that row's choices (${(row.choices || []).join(", ")})`, SUGGESTED_RIGHT));
}
}
}
return problems;
}
+9 -1
View File
@@ -1905,12 +1905,20 @@ function lessonRow(item, row, draft, commit) {
const group = el("div", "lessons-choices");
group.setAttribute("role", "group");
group.setAttribute("aria-label", "Choices for: " + (row.text || row.id));
// The agent's suggestion (Ask for suggestions) outlines its word; it is
// never a pick, so nothing is chosen for the person.
const suggested = item.suggested && typeof item.suggested === "object" ? item.suggested[row.id] : null;
choices.forEach((word, i) => {
const on = pick === word;
const b = el("button", "btn sm" + (on ? " primary" : ""), word);
const hint = suggested === word;
const b = el("button", "btn sm" + (on ? " primary" : "") + (hint ? " is-suggested" : ""), word);
b.type = "button";
b.id = `lesson-${item.id}-${row.id}-${i}`;
b.setAttribute("aria-pressed", String(on));
if (hint) {
b.title = "Suggested by Plan2Code";
b.setAttribute("aria-description", "Suggested");
}
if (row.refused && word === keepWord && !reworded) {
b.disabled = true;
b.title = "Reword it first: part of it was refused.";
+67 -15
View File
@@ -201,6 +201,12 @@ function wireOutside() {
// was asked for while something is chosen.
let saving = false;
let askingClose = false;
// Ask for suggestions pressed and its send still in flight: the button spins
// from the press, before the card's thread shows the request.
let asking = false;
// The key of the agent reply last shown in the Suggestions box, so a new one is scrolled
// into view once and not again on every redraw.
let shownReply = null;
// The card the dialog shows now, for the handlers made once with the dialog.
let shownItem = null;
@@ -348,17 +354,29 @@ export function renderLessonsDialog(on) {
ask.appendChild(row);
actions.appendChild(ask);
} else {
const suggest = suggestionsBox(item);
if (suggest) actions.appendChild(suggest);
// The Notes panel is not on this dialog, so its Ask for suggestions chip
// is here: the same request, answered in the Suggestions box above.
const st = suggestState(item);
const ask = el("button", "btn ghost", "Ask for suggestions");
const ask = el("button", "btn ghost");
ask.type = "button";
ask.id = "lessons-suggest";
ask.disabled = saving || st.disabled;
if (asking || suggestWaiting(item)) {
ask.classList.add("is-asking");
ask.appendChild(spinnerLabel("Asking…"));
} else ask.textContent = "Ask for suggestions";
ask.disabled = saving || asking || st.disabled;
ask.title = st.why || "";
ask.addEventListener("click", () => hooks.askSuggestions(item.id));
ask.addEventListener("click", async () => {
if (asking) return;
asking = true;
redraw();
try {
await hooks.askSuggestions(item.id);
} finally {
asking = false;
redraw();
}
});
const later = el("button", "btn ghost", "Not now");
later.type = "button";
later.id = "lessons-later";
@@ -373,32 +391,66 @@ export function renderLessonsDialog(on) {
actions.append(ask, later, go);
if (stagedCount() > 1) actions.appendChild(el("p", "help", "Anything else ready to send goes with it."));
}
dlg.replaceChildren(card, actions, x);
// The Suggestions box sits in the scrolling body, after the card, so the
// button bar below it can stay pinned to the dialog's bottom edge.
const suggest = askingClose && !saving ? null : suggestionsBox(item);
dlg.replaceChildren(...[card, suggest, actions, x].filter(Boolean));
refreshLessonsSend();
if (!dlg.open) dlg.showModal();
dlg.scrollTop = scroll;
// A new answer lands below the lessons: bring it into view once.
const reply = suggest && !suggestWaiting(item) ? suggestReply(item) : null;
// Keyed on what the reply says: every state push parses fresh objects, so
// the same reply is a new object each time.
const replyKey = reply ? `${item.id}|${reply.at || ""}|${threadText(reply)}` : null;
if (replyKey && replyKey !== shownReply) {
shownReply = replyKey;
suggest.scrollIntoView({ block: "nearest" });
}
}
/**
* The Suggestions box above the dialog's buttons: "Asking Plan2Code…" while a
* request waits, then the agent's latest reply in the card's thread after the
* last request. Null when nothing was asked.
*/
function suggestionsBox(item) {
/** Where the last request for suggestions sits in the card's thread, and the thread. */
function lastAsk(item) {
const thread = Array.isArray(item.thread) ? item.thread : [];
let asked = -1;
thread.forEach((m, i) => {
if (m && m.suggest === true && threadWho(m) === "user") asked = i;
});
const waiting = item.sentNote && item.sentNote.suggest === true && !thread.slice(asked + 1).some((m) => threadWho(m) === "agent");
const reply = asked >= 0 ? thread.slice(asked + 1).filter((m) => threadWho(m) === "agent").pop() : null;
return { thread, asked };
}
/** A request for suggestions sent and not answered yet. */
function suggestWaiting(item) {
const { thread, asked } = lastAsk(item);
return Boolean(item.sentNote && item.sentNote.suggest === true && !thread.slice(asked + 1).some((m) => threadWho(m) === "agent"));
}
/** The agent's latest reply after the last request, or null. */
function suggestReply(item) {
const { thread, asked } = lastAsk(item);
return asked >= 0 ? thread.slice(asked + 1).filter((m) => threadWho(m) === "agent").pop() || null : null;
}
/**
* The Suggestions box above the dialog's buttons: a spinner and "Asking
* Plan2Code…" while a request waits, then the agent's latest reply in the
* card's thread after the last request. Null when nothing was asked.
*/
function suggestionsBox(item) {
const waiting = suggestWaiting(item);
const reply = suggestReply(item);
if (!waiting && !reply) return null;
const box = el("div", "callout is-info lessons-suggestions");
box.id = "lessons-suggestions";
box.setAttribute("role", "status");
box.setAttribute("aria-busy", waiting ? "true" : "false");
box.appendChild(el("h3", null, "Suggestions"));
if (reply && !waiting) box.appendChild(md(threadText(reply), "md"));
else box.appendChild(el("p", "help", "Asking Plan2Code. Its answer shows here."));
else {
const p = el("p", "help lessons-asking");
p.appendChild(spinnerLabel("Asking Plan2Code. Its answer shows here."));
box.appendChild(p);
}
return box;
}
+29 -4
View File
@@ -149,6 +149,11 @@
.lessons-flag,
.lessons-refused { padding: 5px 9px; font-size: var(--fs-sm); }
.lessons-choices { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
/* The agent's suggestion: a dashed accent ring, apart from focus's solid one;
it stays once the person picks that word. */
.lessons-choices .btn.is-suggested { outline: 2px dashed var(--accent); outline-offset: 2px; }
/* Keyboard focus still shows as the page's solid focus ring. */
.lessons-choices .btn.is-suggested:focus-visible { outline: 2px solid var(--focus); outline-offset: var(--focus-offset); }
.lessons-edit { margin-top: 10px; display: grid; gap: 8px; }
.lessons-field { margin: 0; }
.lessons-input,
@@ -173,13 +178,33 @@
.modal.lessons-dialog { width: min(1200px, 90vw); max-width: none; }
.lessons-dialog .card { margin: 0; box-shadow: none; border: 0; padding: 0; max-width: none; }
/* Closable (corner x, Not now, Escape), locked while saving. */
/* Closable (corner x, Not now, Escape), locked while saving. The button bar
is pinned to the dialog's bottom edge while the lessons scroll under it:
the negative margins run it to the dialog's edges over its padding. */
.lessons-dialog .modal-actions { align-items: center; justify-content: flex-end; }
.lessons-suggestions { flex: 1 1 100%; }
.lessons-dialog > .modal-actions {
position: sticky;
/* Chrome sticks inside the dialog's 24px bottom padding; this reaches its edge. */
bottom: -24px;
z-index: 1;
margin: 20px -26px -24px;
padding: 14px 26px 20px;
background: var(--panel);
border-top: 1px solid var(--rule);
}
/* After the card, in the scrolling body; the margin keeps a reply scrolled
into view clear of the pinned buttons. The page-wide .md 68ch cap is lifted
so the reply fills the box. */
.lessons-suggestions { margin: 16px 0 0; scroll-margin-bottom: 96px; }
.lessons-suggestions h3 { margin: 0 0 6px; font-size: var(--fs-md); }
.lessons-suggestions .md { max-height: 40vh; overflow: auto; font-size: var(--fs-md); }
.lessons-suggestions .md { max-width: none; max-height: 40vh; overflow: auto; font-size: var(--fs-md); }
.lessons-asking { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.lessons-asking .spinner { margin: 0; }
.lessons-dialog .modal-actions { flex-wrap: wrap; }
.lessons-dialog .modal-actions .btn .spinner { margin-right: 8px; }
/* A span is inline, so the ring needs a box to show at its size in a button. */
.lessons-dialog .modal-actions .btn .spinner { display: inline-block; vertical-align: -2px; margin-right: 8px; }
/* Asking: held, but at full strength so the spinning ring reads as working. */
.lessons-dialog #lessons-suggest.is-asking:disabled { opacity: 1; cursor: progress; }
.modal-x {
position: absolute;
top: 10px;