Render Markdown live in every console answer box

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-03 03:59:50 -08:00
1 parent c26759fd88
commit 2acfd8907d
21 files changed
+598 -177

No files matched your search

+3 -3
View File
@@ -118,9 +118,9 @@ function askStarters(ss) {
saveNow();
redraw();
const ta = $("ask-input");
if (!ta) return;
ta.focus();
ta.setSelectionRange(ta.value.length, ta.value.length);
if (!ta || !ta.field) return;
ta.field.focus();
ta.field.setSelectionRange(ta.field.value.length, ta.field.value.length);
});
box.appendChild(b);
}
+51 -28
View File
@@ -46,6 +46,7 @@ import {
attachTray,
} from "../uploads.js";
import { attachMentions } from "../mention-box.js";
import { makeMdField } from "../md-field.js";
import { TEMPLATE_WORKFLOWS, templatesFor, templateSwap } from "../starters.js";
import { looks } from "../looks.js";
@@ -109,13 +110,13 @@ export function markMore() {
function markGrowBox(card) {
if (!card) return;
const id = card.dataset.item;
const areas = [...card.querySelectorAll("textarea")];
const areas = [...card.querySelectorAll(".md-host")];
// Not over the git board: the column there flows card and board at natural
// height, so there is no free height for a box to grow into.
const box = isGitBoard()
? null
: areas.find((t) => t.id === "text-" + id) ||
card.querySelector(".option.is-other.is-picked textarea.other-text") ||
card.querySelector(".option.is-other.is-picked .md-host.other-text") ||
areas.find((t) => t.id === "note-" + id);
// Only a box that stops being the one gives its fill back, so a keystroke
// that re-marks the same box leaves its height alone.
@@ -148,7 +149,7 @@ function naturalHeight(card) {
// handle only ever make it taller: resize: vertical alone cannot hold a floor
// that moves with the window. Below a 160px fill the card scrolls instead.
export function fitGrowBox() {
const box = $("main").querySelector(":scope > .card.has-grow textarea.grow");
const box = $("main").querySelector(":scope > .card.has-grow .md-host.grow");
if (!box) return;
const card = box.closest(".card");
const other = naturalHeight(card) - box.offsetHeight;
@@ -664,15 +665,18 @@ function otherOption(list, item, staged, name) {
head.appendChild(label);
body.appendChild(head);
const ta = el("textarea", "other-text");
ta.id = id;
ta.placeholder = "If none of the above fit, say what does.";
// A draft survives picking a listed option, so switching back and forth
// never costs someone the sentence they already wrote.
ta.value = (on && staged.text) || page.local.drafts[id] || "";
const ta = makeMdField({
id,
className: "other-text",
placeholder: "If none of the above fit, say what does.",
label: "Something else, in your own words",
// A draft survives picking a listed option, so switching back and forth
// never costs someone the sentence they already wrote.
value: (on && staged.text) || page.local.drafts[id] || "",
});
// Repaint the row highlights without a full render, which would rebuild this
// textarea mid-keystroke. Setting the radio marks the rest of the group off
// box mid-keystroke. Setting the radio marks the rest of the group off
// by itself; only the `is-picked` classes need saying out loud.
const pick = (chosen) => {
for (const node of list.children) node.classList.toggle("is-picked", node === chosen);
@@ -707,7 +711,10 @@ function otherOption(list, item, staged, name) {
ta.focus();
});
body.appendChild(ta);
// htmlFor cannot reach a div the way it reached the textarea: the label's
// click hands the field its focus here instead.
label.addEventListener("click", () => ta.focus());
body.appendChild(ta.el);
li.appendChild(radio);
li.appendChild(body);
list.appendChild(li);
@@ -725,10 +732,12 @@ function otherField(card, item, staged) {
const label = el("label", null, "Anything else, in your own words");
label.htmlFor = id;
wrap.appendChild(label);
const ta = el("textarea");
ta.id = id;
ta.placeholder = "Optional. This adds to the ones you picked above; it does not replace them.";
ta.value = (staged && staged.text) || page.local.drafts[id] || "";
const ta = makeMdField({
id,
placeholder: "Optional. This adds to the ones you picked above; it does not replace them.",
label: "Anything else, in your own words",
value: (staged && staged.text) || page.local.drafts[id] || "",
});
ta.addEventListener("input", () => {
setDraft(id, ta.value);
const cur = page.local.staged[item.id];
@@ -741,7 +750,7 @@ function otherField(card, item, staged) {
}
stagedChanged();
});
wrap.appendChild(ta);
wrap.appendChild(ta.el);
card.appendChild(wrap);
}
@@ -990,11 +999,20 @@ function buildText(card, item, staged) {
} catch {}
}
const single = Boolean(pattern);
const input = el(single ? "input" : "textarea");
if (single) input.type = "text";
input.id = id;
input.placeholder = item.placeholder || "Type here. Plain language is fine.";
input.value = (staged && staged.text) || page.local.drafts[id] || "";
const input = single
? el("input")
: makeMdField({
id,
placeholder: item.placeholder || "Type here. Plain language is fine.",
label: item.inputLabel || "Your answer",
value: (staged && staged.text) || page.local.drafts[id] || "",
});
if (single) {
input.type = "text";
input.id = id;
input.placeholder = item.placeholder || "Type here. Plain language is fine.";
input.value = (staged && staged.text) || page.local.drafts[id] || "";
}
attachMentions(input);
const err = el("p", "field-error");
@@ -1049,7 +1067,9 @@ function buildText(card, item, staged) {
if (item.templates === "idea" && TEMPLATE_WORKFLOWS.includes(page.S.workflow)) {
wrap.appendChild(templateRow(item, input, templatesFor(page.S.workflow, looks.role), check));
}
wrap.appendChild(input);
// A Markdown field's host is .el; the single-line input appends as itself.
wrap.appendChild(input.el || input);
if (!single) label.addEventListener("click", () => input.focus());
// Fresh-idea boxes take files as context, the same ones the note pane holds,
// and so does any box the page fills from a Notebook tab (Revise plan's
// "What should change"), whose ticked pictures land here.
@@ -1573,10 +1593,12 @@ function commentField(card, item, labelText, required, quickAnswers = []) {
wrap.appendChild(b);
return [b, text];
});
const ta = el("textarea");
ta.id = id;
ta.placeholder = required ? "Tell Plan2Code what to change." : "Optional.";
ta.value = (page.local.staged[item.id] && page.local.staged[item.id].text) || page.local.drafts[id] || "";
const ta = makeMdField({
id,
placeholder: required ? "Tell Plan2Code what to change." : "Optional.",
label: labelText,
value: (page.local.staged[item.id] && page.local.staged[item.id].text) || page.local.drafts[id] || "",
});
attachMentions(ta);
ta.addEventListener("input", () => {
setDraft(id, ta.value);
@@ -1592,11 +1614,12 @@ function commentField(card, item, labelText, required, quickAnswers = []) {
stageQuiet(item.id, { type: "answer", kind: item.kind, text: ta.value.trim() });
stagedChanged();
});
wrap.appendChild(ta);
label.addEventListener("click", () => ta.focus());
wrap.appendChild(ta.el);
for (const [b, text] of quicks)
b.addEventListener("click", () => {
ta.value = text;
ta.dispatchEvent(new Event("input", { bubbles: true }));
ta.emitInput();
ta.focus();
});
card.appendChild(wrap);
+68 -15
View File
@@ -44,7 +44,7 @@ import {
unreadDot,
} from "../chat.js";
import { copyButton, el, isMac, textWithCode } from "../render.js";
import { isBuild } from "../skills.js";
import { isBuild, isAgentless } from "../skills.js";
import { startsClean } from "../hops.js";
import { faviconState, setFavicon } from "../favicon.js";
import { helperRows, showTab } from "../subagents.js";
@@ -73,6 +73,8 @@ import { askOfflineFlipped, askState, declineOpen, renderAside, renderAsk, rende
import { renderHandoff, renderLoopEnd, renderHomeButton, renderStopButton, renderStopControls, renderStopping, stopInProgress, stopWarning } from "./ending.js";
import { renderNotepadButton } from "./notepad.js";
import { renderActivities } from "./activities.js";
import { renderSetup, setupMoved } from "./setup.js";
import { mountAgentsView } from "./agents-view.js";
// What the entry needs from the screens at start-up, handed on from here: only
// the core imports a screen.
@@ -187,6 +189,11 @@ function settleStaleUploads() {
// fetched, so a redraw or a reload never fills the box a second time.
function fillNoteBox() {
const ns = page.local.noteSend;
// An agent-less session has nobody to fill a box for; a leftover pick is dropped.
if (ns && isAgentless(page.S.workflow)) {
page.local.noteSend = null;
save();
}
if (!ns || isDashboard() || finish() || page.S.workflow !== ns.workflow) return;
const item = items().find((i) => i.kind === "text" && i.fill === "note" && i.status === "open");
if (!item) return;
@@ -564,11 +571,13 @@ function scrollRail(where) {
let arrivalBannerTimer = null;
// Typing in any text field, the question's own or the notes beside it.
// 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
// shadow root is what document.activeElement cannot see).
function typingHere() {
const a = document.activeElement;
if (!a) return false;
return a.tagName === "TEXTAREA" || (a.tagName === "INPUT" && (a.type === "text" || a.type === "date"));
return Boolean(a.field) || a.tagName === "TEXTAREA" || (a.tagName === "INPUT" && (a.type === "text" || a.type === "date"));
}
// The moment the ball comes back.
@@ -671,6 +680,18 @@ export function connect() {
adopt(JSON.parse(e.data));
} catch {}
});
// The agent-less setup session's hand-over: the console its pick launched
// POSTed /handover, and this page moves itself to that session's url.
es.addEventListener("move", (e) => {
if (!isAgentless(page.S && page.S.workflow)) return;
try {
const u = JSON.parse(e.data).url;
if (typeof u === "string" && /^http:\/\/(127\.0\.0\.1|localhost):\d+\/s\//.test(u)) {
setupMoved(u);
location.assign(u);
}
} catch {}
});
es.addEventListener("submitted", (e) => {
// Drop only what was actually sent.
//
@@ -788,12 +809,13 @@ export function render() {
restoreScroll();
renderAside();
renderFooter();
agentlessChrome();
});
// The box an `@` list belonged to was just redrawn away.
if (page.mentionPop && !page.mentionPop.box.isConnected) closeMentions();
if (enteringAsk) {
const box = $("ask-input");
if (box && !box.disabled) box.focus({ preventScroll: true });
if (box && box.field && !box.field.disabled) box.field.focus();
}
if (switchingTab || tabAdded) replayViewsArrow();
if (tabAdded) sound("newTab");
@@ -803,6 +825,19 @@ export function render() {
}
}
// An agent-less session's top bar is down to Help: every button listed here
// either sends to the agent or reports on it, and there is no agent to reach.
// Runs after the other renders, which may re-show their button each pass.
const AGENTLESS_CHROME = ["meter-pill", "btn-activities", "btn-subagents", "btn-notepad", "btn-home", "btn-stop", "btn-brief"];
function agentlessChrome() {
if (!isAgentless(page.S && page.S.workflow)) return;
for (const id of AGENTLESS_CHROME) {
const n = $(id);
if (n) n.hidden = true;
}
}
// The runway chevrons beside the tabs pulse a few times on load and then rest.
// Moving to another tab, or a new tab turning up, runs them again: clearing
// the animation, forcing a reflow, then handing it back restarts it from the
@@ -901,9 +936,12 @@ function restoreMainPlace(place) {
function withFocus(fn) {
const a = document.activeElement;
// A Markdown field surfaces as its host: its facade (.field) is what keeps
// the caret, and what the restore below focuses.
const box = a && a.field ? a.field : a;
const keep =
a && (a.tagName === "TEXTAREA" || a.tagName === "INPUT" || a.tagName === "SELECT") && a.id
? { id: a.id, start: a.selectionStart, end: a.selectionEnd }
a && (a.field || a.tagName === "TEXTAREA" || a.tagName === "INPUT" || a.tagName === "SELECT") && a.id
? { id: a.id, start: box.selectionStart, end: box.selectionEnd }
: null;
const place = mainPlace();
@@ -914,10 +952,11 @@ function withFocus(fn) {
restoreMainPlace(place);
if (keep) {
const n = $(keep.id);
if (n) {
n.focus();
const f = n && (n.field || n);
if (f) {
f.focus();
try {
n.setSelectionRange(keep.start, keep.end);
f.setSelectionRange(keep.start, keep.end);
} catch {}
}
}
@@ -1094,13 +1133,14 @@ function renderChrome() {
// done the session is over, and there is one thing left to do elsewhere
// adrift the server is up but nothing is listening at the other end
// gone no server, eye shut
// setup the agent-less setup page, waving while it waits on a pick
//
// Each mood is a family: v0 is the plain drawing and the rest are alternates
// (a hop, star-scanning, sparkles, Z's -- see the "mood variants"
// section of app.css). A new variant is rolled only when the mood CHANGES, so
// the once-a-second status tick does not restart his animation every time it
// runs, and the same state keeps the same face until the state itself moves.
const MOOD_VARIANTS = { point: 3, work: 3, happy: 3, done: 2, adrift: 2, gone: 2 };
const MOOD_VARIANTS = { point: 3, work: 3, happy: 3, done: 2, adrift: 2, gone: 2, setup: 1 };
let moodNow = null;
@@ -1197,6 +1237,12 @@ export function renderStatus() {
tellAttention(icon);
};
// An agent-less session has no agent to report on: the setup page IS the
// state, so the dock's line says where it stands and nothing more.
if (isAgentless(page.S.workflow)) {
return say("setup", page.local.setupStart ? "Starting " + page.local.setupStart.label + "…" : "No agent yet. Pick one below to get started.");
}
// Before `gone`, deliberately. Once a session has finished, no server is the
// expected state, and Planny shutting his eye over it reads as a breakage.
if (finish()) {
@@ -1358,7 +1404,7 @@ function renderViews() {
for (const d of docs()) tabs.push({ id: "doc:" + d.id, label: d.title || "Document", count: 0 });
// The helpers the agent reported, from the first one on; cleared by a
// dashboard hop, which sends the person home like the Overview tab does.
if (showTab(page.subagentsFrame, page.S.helpers)) {
if (showTab(page.subagentsFrame, page.S.helpers) && !isAgentless(page.S.workflow)) {
// From the rows the tab draws, so the badge never counts helpers the
// working-alone note hides.
const running = helperRows(page.S.helpers).rows.filter((r) => r.state === "running").length;
@@ -1366,10 +1412,13 @@ function renderViews() {
} else if (page.view === "subagents") page.view = "questions";
// Always last, on every workflow and after a finish: the Quick question chat.
// The ring left of "Ask" shows exactly when the conversation's own ring does:
// a question the agent picked up and has not answered yet.
const ask = askState();
const askBusy = ask.view.rows.some((r) => r.working) && ask.send.state !== "offline" && !agentAdrift();
tabs.push({ id: "ask", label: "Ask", count: 0, dot: page.chatDot, busy: askBusy });
// a question the agent picked up and has not answered yet. An agent-less
// session has nobody to ask, so the tab stays off.
if (!isAgentless(page.S.workflow)) {
const ask = askState();
const askBusy = ask.view.rows.some((r) => r.working) && ask.send.state !== "offline" && !agentAdrift();
tabs.push({ id: "ask", label: "Ask", count: 0, dot: page.chatDot, busy: askBusy });
} else if (page.view === "ask") page.view = "questions";
for (const t of tabs) {
const b = el("button", "view-tab", t.label);
@@ -1541,6 +1590,10 @@ function paintMain(main) {
main.classList.toggle("is-doc", page.view.startsWith("doc:") || isSpecFileView(page.view));
main.classList.toggle("is-ask", page.view === "ask");
// An agent-less session has no questions, docs or board to draw: its whole
// pane is the setup screen.
if (isAgentless(page.S.workflow)) return renderSetup(main, mountAgentsView);
if (page.view.startsWith("doc:")) return renderDoc(main, page.view.slice(4));
if (isSpecFileView(page.view)) return renderOverview(main, page.view);
if (page.view === "ask") return renderAsk(main);