mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-18 13:01:18 -08:00
Add Suggest for me to the loop setup's strength per phase and release 3.1.2
AI Assisted
This commit is contained in:
1 parent
9cbb970552
commit
e6d5075101
21 files changed
+357
-24
No files matched your search
@@ -145,6 +145,14 @@ The card: post `list`'s `card` as one `lessons` item with `--wait` (the page sho
|
||||
|
||||
Then `node "<D>/console.mjs" open --resume <sid> --no-open --workflow dashboard` to rescan, and post the menu again with `"settle":true` and `--wait`, its note saying what changed (after the card, `decide`'s `closing` line). Never stage or commit.
|
||||
|
||||
## A strength suggestion arrives
|
||||
|
||||
The loop setup's **Suggest for me** sends `__loopSuggest` with `id`, `spec`, `phases` (`[{ n, name }]`, the phases left) and `strengths` (the words mapped for the loop's agent). No hop: you stay the dashboard and the setup screen stays up. The page gives up after two minutes, so answer before anything else:
|
||||
|
||||
1. Read `<spec>/overview.md` and each phase file in `phases`: its tasks, the files it touches, what later phases build on it.
|
||||
2. Pick one word per phase, from `strengths` only: `thrifty` for small, mechanical or copy-only work; `balanced` for an ordinary feature; `best` for tricky logic, a wide refactor, security, concurrency or data migrations. `""` (Match my session) when none fits.
|
||||
3. Post with `--wait`: `{"loopSuggest":{"id":"<the send's id>","spec":"<spec>","picks":[{"n":1,"strength":"thrifty","why":"Label and copy changes only."}]},"agent":{"status":"waiting"}}`, one pick per phase, `why` one plain line the person reads under the row. The page fills the rows; the person can still change any of them.
|
||||
|
||||
## Coming back from another skill
|
||||
|
||||
You arrive here mid-conversation after a `__dashboard` press — from a finished screen, or mid-workflow from the top bar's triangle once that skill saved its place — having already run `open --resume <sid> --no-open --workflow dashboard` (the send's `resume`; it cleared the last skill's page, its finish included — console-finish.md, console-stop.md). Skip Interface steps 1–2; your first job is the menu judgment, then post the menu with `--wait`: re-read `state.scan`, which the resume refreshed — the spec you just worked on is usually the most recently touched. Then the usual wait loop and launches.
|
||||
|
||||
@@ -27,3 +27,7 @@ The ✕ on a chip (after the page's two-step confirm) sends `session:[{"i":"__de
|
||||
## A Learning action
|
||||
|
||||
The Learning row and banner send `session:[{"i":"__learning","do":"switch-on"}]` (`do` is `review`, `switch-on`, `switch-off`, `move-log` or `remove`; Remove was confirmed on the page). No hop: you stay the dashboard. Run `lessons.mjs` as the dashboard skill's "A Learning action arrives" says (a `review` while Learning is not set up is `list --first-ask` and the first ask, before anything is kept; the lessons card is the only question this page shows), then `open --resume <sid> --no-open --workflow dashboard` and post the menu again with `--wait`. Pause for me never reaches you: the page saves it itself. A `__launch` with `fromBanner: true` came from a dashboard showing lessons waiting.
|
||||
|
||||
## A strength suggestion
|
||||
|
||||
The loop setup's **Suggest for me** sends `session:[{"i":"__loopSuggest","id":"ls-m3x1","spec":"specs/<name>","phases":[{"n":1,"name":"..."}],"strengths":["thrifty","best"]}]`. No hop: you stay the dashboard. Read the phase files, then post `loopSuggest` (`{ id, spec, picks: [{ n, strength, why }] }`, `id` echoed, `strength` from `strengths` or `""`) with `--wait`, as the dashboard skill's "A strength suggestion arrives" says. Within two minutes, or the page gives up.
|
||||
@@ -1197,6 +1197,8 @@ export function validate(state) {
|
||||
if (state.loopExpect !== undefined) problems.push(...loopExpectProblems(state.loopExpect));
|
||||
if (state.loopOutcome !== undefined) problems.push(...loopOutcomeProblems(state.loopOutcome, state.loopExpect));
|
||||
if (state.loopEnd !== undefined) problems.push(...loopEndProblems(state.loopEnd, state));
|
||||
// The dashboard agent's answer to Suggest for me on the loop setup screen.
|
||||
if (state.loopSuggest !== undefined) problems.push(...loopSuggestProblems(state.loopSuggest));
|
||||
|
||||
// A note on a card is unanswered the moment no agent words follow it in its
|
||||
// thread. Once that is true, no patch may move past it except one that
|
||||
@@ -1621,6 +1623,39 @@ export function loopOutcomeProblems(o, expect) {
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Problems with a `loopSuggest`: the dashboard agent's strength per phase for
|
||||
* the loop setup's Suggest for me, answering the page's `__loopSuggest` send.
|
||||
* `{ id, spec, picks: [{ n, strength, why }] }`; `id` echoes the send's, and
|
||||
* an empty `strength` is Match my session.
|
||||
*/
|
||||
export const SUGGEST_STRENGTHS = ["", "thrifty", "balanced", "best"];
|
||||
export function loopSuggestProblems(v) {
|
||||
const p = [];
|
||||
const bad = (field, rule) => p.push(`loopSuggest.${field} ${rule}`);
|
||||
const right = ' Like this: {"loopSuggest":{"id":"<the send id>","spec":"specs/<name>","picks":[{"n":1,"strength":"thrifty","why":"A small copy change."}]}}';
|
||||
if (!isPlainObject(v)) return ["loopSuggest must be an object." + right];
|
||||
if (typeof v.id !== "string" || !/^[a-z0-9-]{1,40}$/.test(v.id)) bad("id", "must be the id the __loopSuggest send carried");
|
||||
if (typeof v.spec !== "string" || !/^specs\/[^/\\\r\n]+$/.test(v.spec)) bad("spec", "must be the send's spec, specs/<name>");
|
||||
if (!Array.isArray(v.picks) || v.picks.length === 0) {
|
||||
bad("picks", "must be a non-empty array, one { n, strength, why } per phase left");
|
||||
return p;
|
||||
}
|
||||
const seen = new Set();
|
||||
v.picks.forEach((pick, i) => {
|
||||
if (!isPlainObject(pick)) return bad(`picks[${i}]`, "must be an object { n, strength, why }");
|
||||
if (!isPosInt(pick.n)) bad(`picks[${i}].n`, "must be a positive integer, the phase number");
|
||||
else if (seen.has(pick.n)) bad(`picks[${i}].n`, `names phase ${pick.n} twice`);
|
||||
else seen.add(pick.n);
|
||||
if (!SUGGEST_STRENGTHS.includes(pick.strength)) bad(`picks[${i}].strength`, 'must be one of "thrifty", "balanced", "best", or "" for Match my session');
|
||||
if (pick.why !== undefined) {
|
||||
if (!oneLine(pick.why, 160)) bad(`picks[${i}].why`, "must be one line of 1 to 160 characters");
|
||||
else p.push(...proseProblems(pick.why, `loopSuggest.picks[${i}].why`));
|
||||
}
|
||||
});
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Problems with a `loopEnd` (the app's word on how the loop ended), given the
|
||||
* merged state so `evidence` can be checked against the docs on the page.
|
||||
|
||||
@@ -90,7 +90,8 @@ export function pointersForSend(result, state, changes, chat = []) {
|
||||
else if (a.i === "__dashboard") topics.push(state && state.finish ? "finish" : "stop");
|
||||
else if (a.i === "__stop") topics.push("stop");
|
||||
else if (a.i === "__review") topics.push("review");
|
||||
else if (a.i === "__learning") topics.push("learning");
|
||||
// Both no-hop dashboard actions are explained in console-launches.md.
|
||||
else if (a.i === "__learning" || a.i === "__loopSuggest") topics.push("learning");
|
||||
else if (a.type === "answer" && typeof a.i === "string" && !a.i.startsWith("__")) {
|
||||
const item = items.find((x) => x && x.id === a.i);
|
||||
if (item && item.kind === "review" && verdictOf(a)) topics.push("review");
|
||||
|
||||
@@ -7,12 +7,15 @@
|
||||
// runs or sends to the app.
|
||||
|
||||
import { el } from "../render.js";
|
||||
import { hooks, page, redraw } from "../state.js";
|
||||
import { hooks, page, redraw, saveNow } from "../state.js";
|
||||
import { SKILL_CATALOG } from "../answers.js";
|
||||
import { postJson } from "../net.js";
|
||||
import { tellApp, wireLoopMessages } from "../app-bridge.js";
|
||||
|
||||
let justPicked = ""; // the strength node picked a moment ago, which alone plays its grow
|
||||
// Suggest for me was pressed and has just come back (answer, time-out or failed
|
||||
// send): the next draw puts focus back on the button the busy redraw replaced.
|
||||
let refocusSuggest = false;
|
||||
|
||||
const LEVELS = [
|
||||
["critical", "Critical"],
|
||||
@@ -37,6 +40,8 @@ const STRENGTH_WORDS = [
|
||||
["best", "Best"],
|
||||
];
|
||||
const MATCH_SESSION = "Match my session";
|
||||
// How long Suggest for me waits on the dashboard agent before it gives the field back.
|
||||
export const SUGGEST_WAIT_MS = 120000;
|
||||
|
||||
const DEFAULT_NOTIFY_PARAM = "message";
|
||||
// What the setup can send a notification to. `name` is the label for the field
|
||||
@@ -66,7 +71,7 @@ export async function openLoopSetup(spec) {
|
||||
const dir = spec.dir;
|
||||
page.loopStart = null;
|
||||
page.loopNotifyTest = null;
|
||||
page.loopSetup = { spec: dir, loaded: false, failed: false, form: null, facts: null, problems: [], starting: false, resolvedFor: undefined };
|
||||
page.loopSetup = { spec: dir, loaded: false, failed: false, form: null, facts: null, problems: [], starting: false, resolvedFor: undefined, suggest: null, why: {}, suggestNote: "" };
|
||||
tellApp("loop-facts");
|
||||
redraw();
|
||||
const mine = page.loopSetup;
|
||||
@@ -186,6 +191,7 @@ export function pickModelText(resolved, word, appFacts) {
|
||||
|
||||
function close() {
|
||||
stopWatchingLine();
|
||||
if (page.loopSetup && page.loopSetup.suggest) clearTimeout(page.loopSetup.suggest.timer);
|
||||
page.loopSetup = null;
|
||||
page.loopStart = null;
|
||||
redraw();
|
||||
@@ -450,6 +456,70 @@ function watchStrengthLine(grid) {
|
||||
if (document.fonts && document.fonts.ready) document.fonts.ready.then(redrawLine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Suggest for me: ask the dashboard's agent to pick a strength per phase left.
|
||||
* It goes as a `__loopSuggest` send (no hop: the agent stays the dashboard),
|
||||
* carrying the phases and the words this agent has mapped; the agent reads the
|
||||
* phase files and posts `loopSuggest` back, which applySuggestion() fills in.
|
||||
*/
|
||||
async function askForSuggestion(s, words) {
|
||||
if (s.suggest || page.pendingResult || page.gone) return;
|
||||
const id = "ls-" + Date.now().toString(36);
|
||||
const mine = { id, timer: 0 };
|
||||
s.suggest = mine;
|
||||
s.suggestNote = "";
|
||||
mine.timer = setTimeout(() => {
|
||||
if (s.suggest !== mine) return;
|
||||
s.suggest = null;
|
||||
refocusSuggest = true;
|
||||
s.suggestNote = "The agent did not answer in time. Your picks are as they were.";
|
||||
redraw();
|
||||
}, SUGGEST_WAIT_MS);
|
||||
redraw();
|
||||
const action = {
|
||||
i: "__loopSuggest",
|
||||
type: "loopSuggest",
|
||||
id,
|
||||
spec: s.spec,
|
||||
phases: s.facts.phasesLeft.map((p) => ({ n: p.n, name: p.name })),
|
||||
strengths: words,
|
||||
};
|
||||
try {
|
||||
const res = await fetch("/submit", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ actions: [action], reply: `Suggest a strength for each phase left in ${s.spec}.` }),
|
||||
});
|
||||
if (!res.ok) throw new Error(String(res.status));
|
||||
page.pendingResult = true;
|
||||
saveNow();
|
||||
} catch {
|
||||
if (s.suggest !== mine) return;
|
||||
clearTimeout(mine.timer);
|
||||
s.suggest = null;
|
||||
refocusSuggest = true;
|
||||
s.suggestNote = "The agent could not be asked just now. Try again in a moment.";
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
/** Fill in the agent's answer to this screen's own request: mapped words only, a reason per row. */
|
||||
function applySuggestion(s, answer, resolved) {
|
||||
clearTimeout(s.suggest.timer);
|
||||
s.suggest = null;
|
||||
refocusSuggest = true;
|
||||
s.why = {};
|
||||
const picks = Array.isArray(answer.picks) ? answer.picks : [];
|
||||
for (const p of s.facts.phasesLeft) {
|
||||
const hit = picks.find((x) => x && x.n === p.n);
|
||||
if (!hit || typeof hit.strength !== "string") continue;
|
||||
if (hit.strength && !(resolved && resolved[hit.strength])) continue;
|
||||
setPick(s.form, s.spec, p, hit.strength);
|
||||
if (typeof hit.why === "string" && hit.why.trim()) s.why[p.n] = hit.why.trim();
|
||||
}
|
||||
s.problems = [];
|
||||
}
|
||||
|
||||
/** The "Strength per phase" field: the toggle, Set all to, and one row per phase left. */
|
||||
function strengthField(s, redo) {
|
||||
stopWatchingLine();
|
||||
@@ -481,6 +551,15 @@ function strengthField(s, redo) {
|
||||
}
|
||||
if (!f.phaseStrength) return box;
|
||||
|
||||
const answer = page.S && page.S.loopSuggest;
|
||||
if (s.suggest && answer && answer.id === s.suggest.id && answer.spec === s.spec) applySuggestion(s, answer, resolved);
|
||||
const busy = Boolean(s.suggest);
|
||||
if (busy) {
|
||||
box.classList.add("is-suggesting");
|
||||
box.setAttribute("aria-busy", "true");
|
||||
sw.querySelector("input").disabled = true;
|
||||
}
|
||||
|
||||
// An unmapped word stays in the list, grayed, so a saved one is seen and changed.
|
||||
const options = [
|
||||
["", MATCH_SESSION],
|
||||
@@ -492,10 +571,29 @@ function strengthField(s, redo) {
|
||||
const everyone = select("loop-strength-all", "Set all phases to", [["-", "Choose..."], ...options.map(([v, t, d]) => [v === "" ? "match" : v, t, d])], "-", (v) => {
|
||||
if (v === "-") return;
|
||||
for (const p of s.facts.phasesLeft) setPick(f, s.spec, p, v === "match" ? "" : v);
|
||||
s.why = {};
|
||||
redraw();
|
||||
});
|
||||
everyone.disabled = busy;
|
||||
all.appendChild(everyone);
|
||||
const words = STRENGTH_WORDS.map(([word]) => word).filter((word) => resolved[word]);
|
||||
const suggest = el("button", "btn loop-strength-suggest", "Suggest for me");
|
||||
suggest.type = "button";
|
||||
suggest.id = "loop-strength-suggest";
|
||||
suggest.title = "The agent reads each phase and picks a strength for it";
|
||||
suggest.disabled = busy || page.pendingResult || page.gone || !s.facts.phasesLeft.length;
|
||||
suggest.addEventListener("click", () => askForSuggestion(s, words));
|
||||
all.appendChild(suggest);
|
||||
if (refocusSuggest && !busy) {
|
||||
refocusSuggest = false;
|
||||
// Only when nothing else took focus meanwhile: the busy redraw dropped it on the body.
|
||||
requestAnimationFrame(() => {
|
||||
const a = document.activeElement;
|
||||
if (suggest.isConnected && (!a || a === document.body)) suggest.focus();
|
||||
});
|
||||
}
|
||||
box.appendChild(all);
|
||||
if (s.suggestNote && !busy) box.appendChild(el("p", "loop-hint loop-suggest-note", s.suggestNote));
|
||||
|
||||
// One column per option, in rank order: level 0 is Match my session.
|
||||
const columns = [["", MATCH_SESSION], ...STRENGTH_WORDS].map(([value, label], level) => ({ value, label, level, mapped: value === "" || Boolean(resolved[value]) }));
|
||||
@@ -528,11 +626,12 @@ function strengthField(s, redo) {
|
||||
input.id = `loop-strength-${p.n}-${c.value || "match"}`;
|
||||
input.value = c.value;
|
||||
input.checked = word === c.value;
|
||||
input.disabled = !c.mapped;
|
||||
input.disabled = !c.mapped || busy;
|
||||
input.setAttribute("aria-label", `Phase ${p.n} ${c.label}`);
|
||||
input.addEventListener("change", () => {
|
||||
if (!input.checked) return;
|
||||
setPick(f, s.spec, p, c.value);
|
||||
delete s.why[p.n];
|
||||
s.problems = [];
|
||||
justPicked = input.id; // only this redraw plays the grow
|
||||
redraw();
|
||||
@@ -544,6 +643,7 @@ function strengthField(s, redo) {
|
||||
row.appendChild(cell);
|
||||
}
|
||||
row.appendChild(el("span", "loop-strength-model", pickModelText(resolved, word, page.loopFacts)));
|
||||
if (s.why[p.n]) row.appendChild(el("span", "loop-strength-why", s.why[p.n]));
|
||||
rows.appendChild(row);
|
||||
}
|
||||
grid.appendChild(rows);
|
||||
@@ -552,6 +652,12 @@ function strengthField(s, redo) {
|
||||
watchStrengthLine(grid);
|
||||
}
|
||||
box.appendChild(grid);
|
||||
if (busy) {
|
||||
const veil = el("div", "loop-suggest-overlay");
|
||||
veil.setAttribute("role", "status");
|
||||
veil.append(el("span", "spinner"), el("span", null, "The agent is reading each phase and picking a strength..."));
|
||||
box.appendChild(veil);
|
||||
}
|
||||
return box;
|
||||
}
|
||||
|
||||
|
||||
@@ -579,6 +579,13 @@
|
||||
.loop-switch[hidden] { display: none; }
|
||||
.loop-strength-none .linky { font-size: inherit; }
|
||||
.loop-strength-all { display: flex; align-items: center; gap: 10px; margin-top: 4px; font-size: var(--fs-sm); color: var(--ink-2); }
|
||||
.loop-strength-suggest { padding: 6px 12px; font-size: var(--fs-sm); }
|
||||
/* Suggest for me, waiting on the agent: the field stays visible under a veil with a spinner. */
|
||||
.loop-field.is-suggesting { position: relative; }
|
||||
.loop-field.is-suggesting > :not(.loop-suggest-overlay) { opacity: 0.45; pointer-events: none; }
|
||||
.loop-suggest-overlay { position: absolute; inset: 0; z-index: 3; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 16px; text-align: center; font-size: var(--fs-sm); color: var(--ink); background: color-mix(in srgb, var(--bg) 55%, transparent); border-radius: 8px; cursor: progress; }
|
||||
.loop-suggest-overlay .spinner { margin: 0; flex: none; }
|
||||
.loop-strength-why { grid-column: 1 / -2; padding: 0 8px 8px 0; font-size: var(--fs-sm); color: var(--ink-3); overflow-wrap: anywhere; }
|
||||
.loop-strength-grid { position: relative; display: grid; gap: 6px; margin-top: 6px; }
|
||||
.loop-strength-line { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 0; }
|
||||
.loop-strength-line .step { fill: none; stroke: var(--ink-3); stroke-width: 3px; stroke-linecap: round; stroke-linejoin: round; }
|
||||
@@ -620,6 +627,8 @@
|
||||
.loop-strength-head, .loop-strength-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
||||
.loop-strength-spacer, .loop-strength-model { display: none; }
|
||||
.loop-strength-phase { grid-column: 1 / -1; padding-top: 8px; }
|
||||
.loop-strength-why { grid-column: 1 / -1; }
|
||||
.loop-strength-all { flex-wrap: wrap; }
|
||||
.loop-strength-chip { font-size: var(--fs-2xs); padding: 4px 6px; gap: 4px; flex-wrap: wrap; justify-content: center; }
|
||||
}
|
||||
.loop-ticks { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-left: 4px; }
|
||||
|
||||
Reference in new issue
Block a user