Sync upstream web console updates into v2.4.2: on-demand Cleanup of unused ~/.plan2code files, an UPDATE AVAILABLE banner from the release tags, a colored launcher with a Planny banner, Notes threads that keep the person's notes and read older reply shapes, the repo-local plan2code-model-update maintainer skill, and review fixes (413 for oversize bodies, notes kept on skip, scoped reconnect banner, live Overview tab, busy state on 409, menu keyboard focus, case-insensitive mentions)

This commit is contained in:
jparkerweb committed 2026-10-05 19:10:45 -07:00
1 parent e4d58d07c9
commit 57587db41c
165 files changed
+13025 -1234

No files matched your search

@@ -65,7 +65,7 @@ export function submittedAwaiting(item) {
if (!s || typeof s !== "object") return null;
if (item.answer && typeof item.answer === "object") return null;
const thread = Array.isArray(item.thread) ? item.thread : [];
const replied = thread.some((m) => m && m.who === "agent" && (!s.at || !m.at || m.at >= s.at));
const replied = thread.some((m) => m && threadWho(m) === "agent" && (!s.at || !m.at || m.at >= s.at));
return replied ? null : s;
}
@@ -74,17 +74,33 @@ export function submittedAwaiting(item) {
* agent has yet to say anything after it. The server records it as `sentNote`
* on every send, so the page can show it in the Notes pane and in the Sent
* box instead of letting it vanish into a send that shows no sign of arriving.
* Any thread message from the send onwards, or none with a clock to compare,
* means it has been picked up.
* Any agent message from the send onwards, or one with no clock to compare,
* means it has been picked up. The person's own entries never count: the
* server writes their note into the thread as it arrives.
*/
export function noteAwaiting(item) {
const n = item && item.sentNote;
if (!n || typeof n !== "object") return null;
const thread = Array.isArray(item.thread) ? item.thread : [];
const picked = thread.some((m) => m && (!n.at || !m.at || m.at >= n.at));
const picked = thread.some((m) => m && threadWho(m) === "agent" && (!n.at || !m.at || m.at >= n.at));
return picked ? null : n;
}
/**
* Who said a thread entry and what they said. The contract is `{ who, text }`
* and the server lifts anything else into it, but sessions written before that
* hold `{ from, md }` replies, which would otherwise draw as empty bubbles.
*/
export function threadWho(m) {
return m && (m.who || m.from || m.role) === "user" ? "user" : "agent";
}
export function threadText(m) {
if (!m) return "";
for (const k of ["text", "md", "body", "content"]) if (typeof m[k] === "string" && m[k].trim()) return m[k];
return "";
}
/* -------------------------------------------------------------- labels */
export function optionLabel(item, k) {
@@ -23,6 +23,9 @@
--warn-soft: #fbe7e3;
--focus: #1f6feb;
--shadow: 0 1px 2px rgba(29, 26, 23, 0.05), 0 8px 24px rgba(29, 26, 23, 0.06);
/* A soft accent halo for the things that want noticing: the update banner
and an enabled Send. Built from --accent, so a picked accent glows too. */
--glow: 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent), 0 0 12px color-mix(in srgb, var(--accent) 35%, transparent);
--sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
--serif: "Iowan Old Style", Charter, Georgia, Cambria, serif;
--mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
@@ -61,6 +64,7 @@
--warn-soft: #34201d;
--focus: #6aa3ff;
--shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
--glow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent), 0 0 14px color-mix(in srgb, var(--accent) 45%, transparent);
}
}
@@ -85,6 +89,7 @@
--warn-soft: #34201d;
--focus: #6aa3ff;
--shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
--glow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent), 0 0 14px color-mix(in srgb, var(--accent) 45%, transparent);
}
* { box-sizing: border-box; }
@@ -1097,10 +1102,11 @@ h1 {
.ask-disabled-note.is-offline { color: var(--warn); background: var(--warn-soft); border: 1px solid var(--warn); }
/* Waiting on Plan2Code (an Ask answer, or answers sent from Questions):
the tiny ring, left of the label. */
.view-tab .tab-spin {
the tiny ring, left of the label. The extra .spinner is for specificity:
.spinner.tiny comes later and zeroes the margin otherwise. */
.view-tab .spinner.tab-spin {
display: inline-block;
margin-right: 6px;
margin-right: 7px;
vertical-align: -1px;
}
@@ -1657,11 +1663,13 @@ input[type="text"].invalid { border-color: var(--warn); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
/* Send breathes while there is something to send: a soft accent ring that
spreads and fades. Off under reduced motion, below. */
/* Send glows and breathes while there is something to send: the steady
--glow, plus a soft accent ring that spreads and fades. The ring is off
under reduced motion, below; the glow stays. */
#btn-send:not(:disabled) { box-shadow: var(--glow); }
@keyframes send-pulse {
0% { box-shadow: 0 0 0 0 var(--accent-line); }
100% { box-shadow: 0 0 0 6px transparent; }
0% { box-shadow: var(--glow), 0 0 0 0 var(--accent-line); }
100% { box-shadow: var(--glow), 0 0 0 6px transparent; }
}
#btn-send.primary:not(:disabled) { animation: send-pulse 2.4s ease-out infinite; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
@@ -2219,6 +2227,7 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
.modal.help[open] { display: flex; }
.modal.help .modal-actions { flex: none; margin-top: 16px; align-items: center; }
.help-version { margin-right: auto; font-size: 12.5px; color: var(--ink-3); }
.help-version a { color: inherit; }
.help-layout {
display: grid;
@@ -2668,6 +2677,74 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
border-left-width: 4px;
color: var(--ink);
}
/* A newer release: the same slot, in the accent, with the label as the way
into the update modal and a small × that hides it for this session. */
.dash-nudge.update-banner {
position: relative;
padding-left: 40px;
padding-right: 40px;
border-left-width: 4px;
border-left-color: var(--accent-line);
color: var(--ink);
box-shadow: var(--glow);
}
.update-banner-open {
flex: 1 1 16em;
padding: 0;
border: 0;
background: none;
color: inherit;
font: inherit;
font-weight: 600;
letter-spacing: 0.02em;
text-align: center;
cursor: pointer;
}
.update-banner-open:hover { text-decoration: underline; }
/* Pinned to the right edge, out of the flow, so the label centres on the
whole banner rather than on what the × leaves of it. */
.update-banner-dismiss {
position: absolute;
top: 50%;
right: 10px;
transform: translateY(-50%);
padding: 0 6px;
border: 0;
border-radius: var(--radius);
background: none;
color: inherit;
font: inherit;
font-size: 16px;
line-height: 1;
cursor: pointer;
}
.update-banner-dismiss:hover { background: var(--accent-line); }
/* Wide enough that the update command sits on one line beside Copy; a
narrow window still wraps it rather than overflowing. */
#update-modal { max-width: 720px; }
.update-steps { margin: 0 0 12px; padding-left: 1.4em; color: var(--ink); }
.update-steps li { margin: 4px 0; }
/* The hand-off copy row, in the modal's first step: the command and its Copy
side by side. */
.update-command {
margin: 6px 0 4px;
display: flex;
align-items: stretch;
gap: 10px;
flex-wrap: wrap;
}
.update-command code {
flex: 1 1 260px;
min-width: 0;
font: 13px/1.5 var(--mono);
color: var(--ink);
background: var(--panel);
border: 1px solid var(--rule-2);
border-radius: 8px;
padding: 10px 12px;
white-space: pre-wrap;
overflow-wrap: anywhere;
}
.dash-nudge-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.dash-nudge-actions .btn.tiny { margin-bottom: 0; }
.dash-working {
@@ -3394,6 +3471,18 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
.models-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.models-actions .help.error { color: var(--danger, #d64545); }
/* User Preferences: Cleanup's list of what would go, shown before anything
is deleted. */
.cleanup-list { display: grid; gap: 4px; max-height: 200px; overflow: auto; font-size: 0.88em; }
.cleanup-list:empty { display: none; }
.cleanup-summary { margin: 0 0 2px; font-weight: 600; }
.cleanup-row { display: flex; justify-content: space-between; gap: 12px; }
.cleanup-row span:first-child { min-width: 0; overflow-wrap: anywhere; font-family: var(--mono); }
.cleanup-size { flex: none; color: var(--ink-3); }
.cleanup-more { display: grid; gap: 4px; }
.cleanup-more summary { cursor: pointer; color: var(--ink-2); }
#cleanup-delete[hidden] { display: none; }
/* A word the person has to type, bold and in their highlight color so it
does not get lost in the status sentence. */
.agent-key {
@@ -66,6 +66,8 @@ import {
submittedAwaiting,
noteAwaiting,
suggestionFrom,
threadText,
threadWho,
THUMB_EDGE,
turnGate,
verdictText,
@@ -446,6 +448,10 @@ document.addEventListener("click", (e) => {
const GONE_AFTER_MS = 8000;
// Named so a reconnect can clear only THIS banner: a bare banner(null) would
// wipe an unrelated warning that landed while the page was gone (an upload
// failure, a refused send).
const GONE_BANNER = "Lost contact with Plan2Code. Nothing you have typed is lost. This page reconnects by itself.";
const WORKING_GRACE_MS = 5 * 60 * 1000;
// Two minutes with the agent mid-turn, three when it is merely meant to be
// listening. The difference is the cost of being wrong: a working agent that
@@ -521,6 +527,9 @@ let chatFrame = null;
// sends them.
let wsFrame = null;
let meterFrame = null;
// The frame's update ({ installed, latest }), present only when a newer
// release is out; null otherwise.
let updateFrame = null;
let chatDot = false;
let chatSending = false;
let chatResetting = false;
@@ -566,7 +575,6 @@ function fresh() {
drafts: {},
images: {},
sent: {},
sentAt: null,
stopping: null,
afterBuild: null,
homeward: null,
@@ -870,10 +878,12 @@ function adopt(body) {
chatFrame = body.chat || null;
if (body.workspace) wsFrame = body.workspace;
if (body.meter) meterFrame = body.meter;
// Always replaced: an absent key means no update.
updateFrame = body.update || null;
lastContact = Date.now();
if (gone) {
gone = false;
banner(null);
if ($("banner").textContent === GONE_BANNER) banner(null);
}
if (firstLoad) {
load();
@@ -1016,7 +1026,9 @@ function adopt(body) {
render();
if ($("workspace-modal").open) renderWorkspace();
tellFolderIssues();
if (firstLoad || S.specDir !== prevSpecDir || S.workflow !== prevWorkflow) loadOverview();
// The Overview tab's file changes under a build, so a tab you are watching
// refetches on every new frame too, not only on the click that opened it.
if (firstLoad || S.specDir !== prevSpecDir || S.workflow !== prevWorkflow || view === "overview") loadOverview();
if (announce) showArrival(announce);
// New entries land at the bottom of the rail. Gliding down to them beats
// leaving the list parked where it was while it grew underneath.
@@ -1149,15 +1161,12 @@ function markGone() {
// of the server means there, and a banner promising a reconnect would
// argue with it.
if (!finish() && !stopInProgress()) {
banner(
"Lost contact with Plan2Code. Nothing you have typed is lost. This page reconnects by itself.",
"warn"
);
banner(GONE_BANNER, "warn");
}
render();
} else if (!bad && gone) {
gone = false;
banner(null);
if ($("banner").textContent === GONE_BANNER) banner(null);
render();
}
}
@@ -1182,7 +1191,6 @@ function connect() {
} catch {}
});
es.addEventListener("submitted", (e) => {
local.sentAt = Date.now();
// Drop only what was actually sent.
//
// This event fires for a send from ANY tab of this session, which is why it
@@ -1799,14 +1807,19 @@ async function sendBrief() {
reply: briefPhrase(choice.range),
}),
});
if (res.status === 409) throw Object.assign(new Error("pending"), { pending: true });
if (!res.ok) throw new Error(String(res.status));
$("brief-modal").close();
banner("Asked for a brief. It will appear as a tab when it is written.", "good");
setTimeout(() => banner(null), 5000);
pendingResult = true;
render();
} catch {
why.textContent = "That did not go through. Try again in a moment.";
} catch (err) {
if (err && err.pending) pendingResult = true;
why.textContent =
err && err.pending
? "Your last answers are still being picked up. Try again in a moment."
: "That did not go through. Try again in a moment.";
} finally {
go.disabled = false;
go.textContent = "Write the brief";
@@ -2515,6 +2528,51 @@ function roleNudge() {
return nudge;
}
// × on the update banner hides it for this console session only, and only
// for the release it named. Blocked storage means "not dismissed".
function updateDismissKey() {
try {
return "p2c-update-dismissed:" + S.sid;
} catch {
return "p2c-update-dismissed:";
}
}
function updateDismissed() {
try {
return sessionStorage.getItem(updateDismissKey()) === updateFrame.latest;
} catch {
return false;
}
}
const RELEASES_URL = "https://github.com/jparkerweb/plan2code/releases/";
const UPDATE_COMMAND = "npx --allow-git=all git+https://github.com/jparkerweb/plan2code.git";
function releasesLink(text) {
const a = el("a", null, text);
a.href = RELEASES_URL;
a.target = "_blank";
a.rel = "noopener noreferrer";
return a;
}
function openUpdateModal() {
if (!updateFrame) return;
const versions = $("update-versions");
versions.replaceChildren(
document.createTextNode("Version "),
releasesLink("v" + updateFrame.latest),
document.createTextNode(" is out — you have "),
el("code", null, updateFrame.installed),
document.createTextNode(".")
);
const row = $("update-command");
const code = el("code", null, UPDATE_COMMAND);
row.replaceChildren(code, copyButton(UPDATE_COMMAND, "btn small ghost handoff-copy", code));
$("update-modal").showModal();
}
function renderDashboard(main) {
maybeWake();
const menu = (S && S.menu) || {};
@@ -2526,6 +2584,25 @@ function renderDashboard(main) {
warn.setAttribute("role", "status");
wrap.appendChild(warn);
}
// Built here only, so no other workflow's page ever shows it.
if (updateFrame && !updateDismissed()) {
const notice = el("div", "dash-nudge update-banner");
notice.setAttribute("role", "status");
const open = el("button", "update-banner-open", "UPDATE AVAILABLE · v" + updateFrame.latest);
open.type = "button";
open.addEventListener("click", openUpdateModal);
const dismiss = el("button", "update-banner-dismiss", "×");
dismiss.type = "button";
dismiss.setAttribute("aria-label", "Dismiss until next time");
dismiss.addEventListener("click", () => {
try {
sessionStorage.setItem(updateDismissKey(), updateFrame.latest);
} catch {}
render();
});
notice.append(open, dismiss);
wrap.appendChild(notice);
}
wrap.appendChild(el("p", "card-kicker", "Plan2Code"));
wrap.appendChild(el("h2", "dash-title", "What are we doing today?"));
if (typeof menu.note === "string" && menu.note.trim()) {
@@ -3223,7 +3300,11 @@ document.addEventListener("keydown", cancelSkipMove, true);
function skipAndMoveOn(id) {
cancelSkipMove();
local.skipFlash = id;
stage(id, { type: "skip", skipped: true });
// A note already typed goes along: skipping the question is not retracting
// the comment. Dropping it would leave the text in the box but out of the
// send, which looks kept and is not.
const cur = local.staged[id];
stage(id, { type: "skip", skipped: true, ...(cur && cur.text ? { text: cur.text } : {}) });
skipTimer = setTimeout(() => {
skipTimer = null;
local.skipFlash = null;
@@ -3340,19 +3421,24 @@ function renderWaiting(main) {
}
pane.appendChild(title);
pane.appendChild(el("p", null, doing));
const ask = "If Plan2Code needs you, the question appears here on its own.";
if (!docs().length) {
pane.appendChild(el("p", null, "If Plan2Code needs you, the question appears here on its own."));
pane.appendChild(el("p", null, ask));
return;
}
// "Task" and the tasks tab's own name both open that tab, so the pointer is
// one click from what it points at. A build posts it as `phase` ("Phase N
// tasks"), a quick task as `tasks`; with neither the words stay plain.
// tasks"), a quick task as `tasks`. A skill with no task list (Document,
// Plan) has nothing live to follow, so it gets no pointer at all.
const list =
docs().find((d) => d.id === "phase") ||
docs().find((d) => d.id === "tasks") ||
docs().find((d) => /\btasks\b/i.test(d.title || ""));
if (!list) {
pane.appendChild(el("p", null, "The tabs above fill in as it goes. " + ask));
return;
}
const jump = (word) => {
if (!list) return el("strong", "waiting-jump", word);
const b = el("button", "waiting-jump", word);
b.type = "button";
b.addEventListener("click", () => {
@@ -3366,8 +3452,8 @@ function renderWaiting(main) {
"The tabs above fill in as it goes. You can follow along with live ",
jump("Task"),
" updates in the ",
jump((list && list.title) || "Phase tasks"),
" tab. If Plan2Code needs you, the question appears here on its own."
jump(list.title || "Phase tasks"),
" tab. " + ask
);
pane.appendChild(p);
}
@@ -3505,8 +3591,8 @@ function renderSettled(card, item) {
// would misreport which of the two was the answer.
let prose = text;
if (!prose && !lines.length) {
const mine = (item.thread || []).filter((m) => m.who === "user");
if (mine.length) prose = String(mine[mine.length - 1].text || "").trim();
const mine = (item.thread || []).filter((m) => threadWho(m) === "user");
if (mine.length) prose = threadText(mine[mine.length - 1]).trim();
}
const nothing = !lines.length && !prose;
@@ -4322,6 +4408,10 @@ function buildChecklist(card, item, staged) {
const commitList = (change) => {
const cur = local.staged[item.id];
const next = { ...(cur || {}), type: "answer", kind: "checklist", ...change };
// A tick or a state IS the answer, so it ends a skip staged earlier:
// left in place, `skipped` would collapse the reply to "skip" while the
// card showed ticked steps on their way.
delete next.skipped;
const empty = !(next.done && next.done.length) && !next.state && !next.text;
stage(item.id, empty ? null : next);
};
@@ -4371,7 +4461,7 @@ function buildChecklist(card, item, staged) {
function buildMenu(card, item, staged) {
const list = el("ul", "options");
const name = "menu-" + item.id;
for (const o of item.options || []) {
for (const [i, o] of (item.options || []).entries()) {
const picked = staged && staged.k === o.k;
const li = el("li", "option" + (picked ? " is-picked" : ""));
const label = el("label");
@@ -4379,7 +4469,13 @@ function buildMenu(card, item, staged) {
const radio = el("input");
radio.type = "radio";
radio.name = name;
// The same id buildChoice gives its radios: withFocus finds the focused
// input by id after the render this change() sets off, and without one a
// keyboard user arrowing through the menu lands on <body> every time.
radio.id = optionId(item, o, i);
radio.value = o.k;
radio.checked = Boolean(picked);
radio.setAttribute("aria-label", o.k ? `${o.k}: ${o.text}` : o.text);
radio.addEventListener("change", () => stage(item.id, { type: "answer", kind: "menu", k: o.k }));
const body = el("div", "option-body");
const head = el("div", "option-label");
@@ -5276,20 +5372,30 @@ function renderAside() {
)
);
}
// A note that has been sent but not yet picked up: marked as waiting, so the
// send is seen to have gone, until the agent replies. The server writes the
// note into the thread as it arrives; a session from before that has only
// `sentNote`, which gets a box of its own below.
const waiting = isOpen(item) && !finish() ? noteAwaiting(item) : null;
let waitingShown = false;
for (const m of thread) {
const box = el("div", "msg " + (m.who === "user" ? "you" : ""));
const mine = threadWho(m) === "user";
const pending = Boolean(waiting && mine && m.at && m.at === waiting.at);
if (pending) waitingShown = true;
const box = el("div", "msg" + (mine ? " you" : "") + (pending ? " pending" : ""));
const who = el("div", "msg-who");
who.appendChild(el("span", null, m.who === "user" ? "You" : "Plan2Code"));
if (m.at) who.appendChild(el("span", null, shortTime(m.at)));
who.appendChild(el("span", null, mine ? "You" : "Plan2Code"));
if (pending) who.appendChild(el("span", null, "Sent, waiting for Plan2Code"));
else if (m.at) who.appendChild(el("span", null, shortTime(m.at)));
box.appendChild(who);
box.appendChild(md(m.text, "md"));
const text = threadText(m);
if (text) box.appendChild(md(text, "md"));
const tray = mine ? sentAttachments(m) : null;
if (tray) box.appendChild(tray);
aside.appendChild(box);
}
// A note that has been sent but not yet picked up: shown at once, so the
// send is seen to have gone, and gone when the agent replies.
const waiting = isOpen(item) && !finish() ? noteAwaiting(item) : null;
if (waiting) {
if (waiting && !waitingShown) {
const box = el("div", "msg you pending");
const who = el("div", "msg-who");
who.appendChild(el("span", null, "You"));
@@ -5589,7 +5695,10 @@ async function attachFiles(itemId, files) {
const taken = wanted.slice(0, room);
// One banner at a time, so every refusal goes into it, each by name.
const said = refused.map((r) => (r.reason === "too-large" ? tooLargeText(r.name) : notAllowedText(r.name)));
if (taken.length < wanted.length) said.push(chat ? "Up to 5 attachments per question." : "Up to 5 attachments per note.");
if (taken.length < wanted.length)
said.push(
chat ? `Up to ${CHAT_MAX_ATTACHMENTS} attachments per question.` : `Up to ${MAX_ATTACHMENTS} attachments per note.`
);
if (said.length) banner(said.join(" "), refused.length ? "warn" : "info");
await Promise.all(
taken.map(async (file) => {
@@ -6439,6 +6548,10 @@ async function goHome() {
$("home-modal").close();
} catch (err) {
$("home-modal").close();
// The server is holding an uncollected result: Send, Home and Stop all
// need to read as busy until the frame or the ping says otherwise, same
// as send() and sendAfterBuild() do on a 409.
if (err && err.pending) pendingResult = true;
banner(
err && err.pending
? "Your last answers are still being picked up, so that could not go yet. Try again in a moment."
@@ -6499,6 +6612,7 @@ async function stopSession() {
stoppingHidden = false;
} catch (err) {
$("stop-modal").close();
if (err && err.pending) pendingResult = true;
banner(
err && err.pending
? "Your last answers are still being picked up, so the stop could not go yet. Try again in a moment."
@@ -6653,7 +6767,6 @@ function markSent({ sentIds, sentNotes = {}, summaries, values }) {
local.sent[id] = { at: Date.now(), summary: summaries[id] || "", value: values[id] || null };
}
local.staged = {};
local.sentAt = Date.now();
save();
}
@@ -6706,7 +6819,7 @@ const STATE_WORDS = { done: "all done", blocked: "blocked", help: "need help", d
// something the agent never hears.
function tokenFor(item, v) {
const map = item.token || {};
if (v.skipped) return "skip";
if (v.skipped) return v.text ? `skip; ${v.text}` : "skip";
const parts = [];
if (v.k) parts.push(map[v.k] || v.k);
if (Array.isArray(v.ks) && v.ks.length) parts.push(v.ks.map((k) => map[k] || k).join(", "));
@@ -6938,14 +7051,14 @@ function renderAbout() {
let helpBuilt = false;
async function renderHelpVersion() {
const el = $("help-version");
const slot = $("help-version");
try {
const res = await fetch("/version", { cache: "no-store" });
const { version } = res.ok ? await res.json() : {};
el.textContent = version ? "Plan2Code v" + version : "";
el.hidden = !version;
slot.replaceChildren(...(version ? [releasesLink("Plan2Code v" + version)] : []));
slot.hidden = !version;
} catch {
el.hidden = true;
slot.hidden = true;
}
}
@@ -7053,6 +7166,7 @@ function openHelpOn(id) {
}
$("btn-home").addEventListener("click", openHomeConfirm);
$("update-done").addEventListener("click", () => $("update-modal").close());
$("home-cancel").addEventListener("click", () => $("home-modal").close());
$("home-go").addEventListener("click", goHome);
$("btn-stop").addEventListener("click", openStopConfirm);
@@ -7132,6 +7246,7 @@ $("btn-looks").addEventListener("click", () => {
});
$("looks-done").addEventListener("click", () => $("looks-modal").close());
$("looks-modal").addEventListener("close", () => {
resetCleanup();
if (isDashboard() && !needsRoleNudge(looks) && $("main").querySelector(".dash-nudge")) render();
});
$("looks-reset").addEventListener("click", () => {
@@ -7278,6 +7393,111 @@ $("models-reset").addEventListener("click", () => {
renderModels();
});
// Cleanup: the server works out what in ~/.plan2code is not needed and
// shows it first; Delete these sends back only the ids it was shown, and the
// server re-checks every one before removing it.
let cleanupFound = null;
// Bumped by every scan, delete and reset: a response from an older one is
// dropped, so a scan still in flight when Preferences closes cannot refill it.
let cleanupGen = 0;
const CLEANUP_SHOWN = 8;
function setCleanupStatus(text, isError) {
const status = $("cleanup-status");
status.textContent = text;
status.classList.toggle("error", Boolean(isError));
}
function cleanupLabel(item) {
if (item.where === "session") return "Session " + item.name;
const where = item.where === "root" ? "~/.plan2code/" : "~/.plan2code/console/";
return where + item.name + (item.kind === "folder" ? "/" : "");
}
function cleanupSummary(items, bytes) {
const sessions = items.filter((i) => i.where === "session").length;
const strays = items.length - sessions;
const parts = [];
if (sessions) parts.push(sessions + (sessions === 1 ? " old session" : " old sessions"));
if (strays) parts.push(strays + (strays === 1 ? " stray file or folder" : " stray files and folders"));
return parts.join(", ") + " · " + formatBytes(bytes);
}
function resetCleanup() {
cleanupGen++;
cleanupFound = null;
$("cleanup-list").replaceChildren();
$("cleanup-delete").hidden = true;
$("cleanup-delete").disabled = false;
$("cleanup-scan").disabled = false;
setCleanupStatus("", false);
}
function renderCleanup() {
const list = $("cleanup-list");
list.replaceChildren();
const items = (cleanupFound && cleanupFound.items) || [];
$("cleanup-delete").hidden = !items.length;
if (!items.length) return;
const rows = (some) => some.map((item) => {
const row = el("div", "cleanup-row");
row.append(el("span", null, cleanupLabel(item)), el("span", "cleanup-size", formatBytes(item.bytes)));
return row;
});
list.append(el("p", "cleanup-summary", cleanupSummary(items, cleanupFound.bytes)), ...rows(items.slice(0, CLEANUP_SHOWN)));
if (items.length > CLEANUP_SHOWN) {
const more = el("details", "cleanup-more");
more.append(el("summary", null, (items.length - CLEANUP_SHOWN) + " more"), ...rows(items.slice(CLEANUP_SHOWN)));
list.appendChild(more);
}
}
async function scanCleanup() {
const gen = ++cleanupGen;
$("cleanup-scan").disabled = true;
$("cleanup-delete").disabled = true;
setCleanupStatus("Looking…", false);
const { status, body } = await postJson("/cleanup", { scan: true });
if (gen !== cleanupGen) return;
$("cleanup-scan").disabled = false;
$("cleanup-delete").disabled = false;
if (status !== 200 || !body.ok) {
cleanupFound = null;
renderCleanup();
return setCleanupStatus(status ? body.error || "Could not look." : "Plan2Code isn't reachable.", true);
}
cleanupFound = { items: body.items || [], bytes: body.bytes || 0 };
renderCleanup();
// Left in the status line, not cleared: it is the live region, so this is
// what a screen reader hears when the scan finishes.
const found = cleanupFound.items.length;
setCleanupStatus(found ? "Found " + found + (found === 1 ? " item." : " items.") : "Nothing to clean up.", false);
}
async function deleteCleanup() {
if (!cleanupFound || !cleanupFound.items.length) return;
const gen = ++cleanupGen;
$("cleanup-delete").disabled = true;
$("cleanup-scan").disabled = true;
setCleanupStatus("Deleting…", false);
const { status, body } = await postJson("/cleanup", { delete: cleanupFound.items.map((i) => i.id) });
if (gen !== cleanupGen) return;
$("cleanup-delete").disabled = false;
$("cleanup-scan").disabled = false;
if (status !== 200 || !body.ok) {
return setCleanupStatus(status ? body.error || "Could not delete." : "Plan2Code isn't reachable.", true);
}
const removed = (body.removed || []).length;
const failed = (body.failed || []).length;
cleanupFound = null;
renderCleanup();
const done = removed ? "Deleted " + removed + (removed === 1 ? " item" : " items") + " · " + formatBytes(body.bytes) + " freed." : "Nothing was deleted.";
setCleanupStatus(failed ? done + " " + failed + " could not be removed." : done, Boolean(failed));
}
$("cleanup-scan").addEventListener("click", scanCleanup);
$("cleanup-delete").addEventListener("click", deleteCleanup);
$("btn-brief").addEventListener("click", openBrief);
$("brief-cancel").addEventListener("click", () => $("brief-modal").close());
$("brief-go").addEventListener("click", sendBrief);
@@ -1291,6 +1291,14 @@
come back, and you can change your role any time from the swatch
button.
</p>
<h4>When an update is out</h4>
<p>
When a newer Plan2Code release is out, the dashboard shows
<strong>UPDATE AVAILABLE</strong> at the top. Click it for the command
to run in your terminal; × hides it until the next
<code>/plan2code</code>. The version at the bottom of Help links to
the Releases page.
</p>
<h4>The cards</h4>
<p>They come in three groups.</p>
<p><strong>First, the project</strong></p>
@@ -1845,6 +1853,15 @@
joining the strip. Keep only the ones you want; ticking a box plays
its sound.
</li>
<li>
<strong>Cleanup</strong>: <strong>Find files to clean up</strong>
lists what Plan2Code doesn't need in your
<code>~/.plan2code</code> folder: sessions nobody has opened for
30 days, and files or folders that ended up there by mistake. It
shows each one with its size, and <strong>Delete these</strong>
removes exactly that list. Your preferences, saved folders, models,
the launcher and the session you are in always stay.
</li>
<li>
<strong>Back to default</strong> puts everything back as it was, and
sets Role back to Not set.
@@ -1983,6 +2000,16 @@
</div>
<p class="help">Ticking one plays it. Play sounds switches them all off at once and keeps your picks for when you switch back on.</p>
</fieldset>
<fieldset class="modal-ranges looks-cleanup">
<legend>Cleanup</legend>
<p class="help">Finds what Plan2Code doesn't need in your <code>~/.plan2code</code> folder: sessions nobody has opened for 30 days, and files or folders that ended up there by mistake. You see the list before anything is deleted. Your preferences, saved folders, models, the launcher and this session always stay.</p>
<div class="cleanup-list" id="cleanup-list" aria-label="What would be deleted"></div>
<div class="models-actions">
<button type="button" class="btn small" id="cleanup-scan">Find files to clean up</button>
<button type="button" class="btn small danger" id="cleanup-delete" hidden>Delete these</button>
<span class="help" id="cleanup-status" role="status"></span>
</div>
</fieldset>
<fieldset class="modal-ranges looks-models">
<legend>Models</legend>
<div class="models-tabs" role="group" aria-label="Which agent">
@@ -2181,6 +2208,24 @@
</div>
</dialog>
<!-- Opened from the dashboard's UPDATE AVAILABLE banner. The versions and
the copy row are filled by app.js; the update itself runs in a
terminal, never from this page. -->
<dialog class="modal" id="update-modal" aria-labelledby="update-title">
<h2 id="update-title">A new Plan2Code is available</h2>
<p class="modal-blurb" id="update-versions"></p>
<ol class="update-steps">
<li>
Run this in your terminal (not in this page or your agent):
<div class="update-command" id="update-command"></div>
</li>
<li>When it finishes, close this console and start <code>plan2code</code> again.</li>
</ol>
<div class="modal-actions">
<button type="button" class="btn primary" id="update-done">Close</button>
</div>
</dialog>
<footer class="footer">
<div class="footer-summary" id="footer-summary" aria-live="polite">
Nothing to send yet.
@@ -5,7 +5,10 @@
// popover; this file owns the rules. No DOM access at module scope and no
// imports: the page and `node --test` both import this file.
const NAME_CHAR = /[a-z0-9-]/;
// Uppercase too: "@Repo" must still name @repo — names are forced lowercase
// by the workspace rules, and a query typed with a capital otherwise matches
// nothing and opens no suggestions at all.
const NAME_CHAR = /[a-z0-9-]/i;
const MAX_MATCHES = 6;
/**
@@ -23,11 +26,13 @@ export function mentionAt(text, caret) {
}
// Names starting with the query first, then names containing it, in the
// order given, at most six.
// order given, at most six. Case-folded: folder names are lowercase by rule,
// and "@Repo" should still find @repo rather than claim nothing matches.
export function matchNames(names, query) {
const q = String(query || "");
const prefix = names.filter((n) => n.startsWith(q));
const inside = names.filter((n) => !n.startsWith(q) && n.includes(q));
const q = String(query || "").toLowerCase();
const fold = (n) => String(n).toLowerCase();
const prefix = names.filter((n) => fold(n).startsWith(q));
const inside = names.filter((n) => !fold(n).startsWith(q) && fold(n).includes(q));
return [...prefix, ...inside].slice(0, MAX_MATCHES);
}