Let the dashboard start Pathfinder, Plan, Quick Task or Revise plan from a Notebook tab

AI Assisted
This commit is contained in:
jparkerweb committed 2026-10-27 18:20:30 -07:00
1 parent 7973bc093b
commit 720758a7ee
29 files changed
+1416 -47

No files matched your search

+4 -2
View File
@@ -1000,8 +1000,10 @@ function buildText(card, item, staged) {
wrap.appendChild(templateRow(item, input, templatesFor(page.S.workflow, looks.role), check));
}
wrap.appendChild(input);
// Fresh-idea boxes take files as context, the same ones the note pane holds.
if (!single && TEMPLATE_WORKFLOWS.includes(page.S.workflow)) {
// 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.
if (!single && (TEMPLATE_WORKFLOWS.includes(page.S.workflow) || item.fill === "note")) {
input.addEventListener("paste", (e) => {
const files = incomingFiles(e.clipboardData && e.clipboardData.files);
if (!files.length) return;
+74 -3
View File
@@ -59,7 +59,7 @@ import {
import { sound } from "../sound.js";
import { renderConfirm, renderDashboard } from "./dashboard.js";
import { renderLaunching, renderWaiting } from "./starting.js";
import { heldNotes, noteImages, pendingNotes, removeImage } from "../uploads.js";
import { attachFiles, heldNotes, noteImages, pendingNotes, removeImage } from "../uploads.js";
import { closeMentions } from "../mention-box.js";
import { buildPager, fitGrowBox, markFor, markMore, renderCard, renderEndItem, renderNotice } from "./cards.js";
import { sendState } from "../send-state.js";
@@ -71,6 +71,7 @@ import { linkLeavesPage, startNewSession, tellApp } from "../app-bridge.js";
import { askOfflineFlipped, askState, declineOpen, renderAside, renderAsk, renderSubagents, renderSubagentsButton } from "./ask.js";
import { renderHandoff, renderHomeButton, renderStopButton, renderStopControls, renderStopping, stopInProgress, stopWarning } from "./ending.js";
import { renderNotepadButton } from "./notepad.js";
import { renderActivities } from "./activities.js";
// What the entry needs from the screens at start-up, handed on from here: only
// the core imports a screen.
@@ -85,6 +86,7 @@ export { wireCleanup } from "./cleanup.js";
export { startLooks, wireLooks } from "./looks.js";
export { wireEnding } from "./ending.js";
export { wireNotepad } from "./notepad.js";
export { wireActivities } from "./activities.js";
const $ = (id) => document.getElementById(id);
@@ -176,6 +178,53 @@ function settleStaleUploads() {
}
}
// A Notebook tab picked at Start (dashboard.js) fills the launched skill's
// first open `fill: "note"` box, once. It is claimed before anything is
// fetched, so a redraw or a reload never fills the box a second time.
function fillNoteBox() {
const ns = page.local.noteSend;
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;
page.local.noteSend = null;
save();
seedNoteBox(item, ns);
}
// The tab's text as the box's draft and staged answer, then its ticked
// pictures through the same path a pasted picture takes. A tab deleted since
// Start leaves the box empty; a picture deleted since is skipped.
async function seedNoteBox(item, ns) {
const tab = encodeURIComponent(ns.tab);
try {
const res = await fetch("/notepad?tab=" + tab, { cache: "no-store" });
if (res.status === 404) {
banner("That Notebook tab is gone; the box starts empty.", "warn");
return;
}
} catch {}
const text = typeof ns.text === "string" ? ns.text : "";
if (text.trim()) {
page.local.drafts["text-" + item.id] = text;
page.local.staged[item.id] = { type: "answer", kind: "text", text: text.trim() };
}
page.local.noteSent = { item: item.id, tab: ns.tab, workflow: ns.workflow, ...(ns.spec ? { spec: ns.spec } : {}) };
save();
redraw();
const files = await Promise.all(
(ns.pictures || []).map(async (id) => {
try {
const r = await fetch("/notepad/images/" + tab + "/" + encodeURIComponent(id) + ".jpg", { cache: "no-store" });
return r.ok ? new File([await r.blob()], id + ".jpg", { type: "image/jpeg" }) : null;
} catch {
return null;
}
}),
);
const found = files.filter(Boolean);
if (found.length) attachFiles(item.id, found);
}
async function pushDraft() {
try {
await fetch("/draft", {
@@ -276,7 +325,16 @@ export function adopt(body) {
// the dashboard, the picker starts on the most recently touched spec still
// in play, the one the agent's fresh menu recommends for.
const keepPick = page.S.workflow !== "dashboard" && "specSel" in page.local;
page.local = { ...fresh(), launching: page.local.launching, ...(keepPick ? { specSel: page.local.specSel } : {}) };
// A Notebook tab picked at Start rides into the skill it was picked for,
// and nowhere else: back home, or a hop to another skill, drops it.
const ns = page.local.noteSend;
const keepNote = Boolean(ns) && page.S.workflow !== "dashboard" && page.S.workflow === ns.workflow;
page.local = {
...fresh(),
launching: page.local.launching,
...(keepPick ? { specSel: page.local.specSel } : {}),
...(keepNote ? { noteSend: ns } : {}),
};
save();
page.selected = null;
page.view = "questions";
@@ -395,6 +453,7 @@ export function adopt(body) {
(r === "any" || (item.submitted && item.submitted.at === r));
if (!live) delete page.local.retract[id];
}
fillNoteBox();
// New work: a question that is theirs to answer now and was not a moment ago.
// That covers a brand new question and one the agent reopened or answered
@@ -707,6 +766,7 @@ export function render() {
renderSubagentsButton();
renderStopButton();
renderNotepadButton();
renderActivities();
renderHomeButton();
tabAdded = renderViews();
renderSidebar();
@@ -1105,7 +1165,7 @@ export function renderStatus() {
$("dock").classList.toggle("is-flying", Boolean(spin));
// The tab icon's bar says the same thing from another tab (favicon.js),
// and the app's taskbar entry from another window.
const icon = faviconState({ mood, spin, finished: Boolean(finish()) });
const icon = faviconState({ mood, spin });
setFavicon(icon);
tellAttention(icon);
};
@@ -1794,6 +1854,17 @@ export function markSent({ sentIds, sentNotes = {}, summaries, values }) {
page.local.sent[id] = { at: Date.now(), summary: summaries[id] || "", value: values[id] || null };
}
page.local.staged = {};
// The box a Notebook tab filled went with this send: only now does the
// Notebook say the tab was sent. A failed mark is not worth a banner.
const ns = page.local.noteSent;
if (ns && sentIds.has(ns.item)) {
page.local.noteSent = null;
fetch("/notepad/tab/sent", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ id: ns.tab, workflow: ns.workflow, ...(ns.spec ? { spec: ns.spec } : {}) }),
}).catch(() => {});
}
save();
}
+277 -2
View File
@@ -39,6 +39,13 @@ import {
deleteHandoffReply,
deleteAction,
deleteReply,
noteSwitchShows,
noteTabEmpty,
defaultNoteTicks,
toggleNoteTick,
formatBytes,
NOTE_LONG_BYTES,
MAX_ATTACHMENTS,
} from "../answers.js";
import { stateFor } from "../spec-states.js";
import { sound, soundOn, fadeSound, dropSounds } from "../sound.js";
@@ -139,6 +146,9 @@ function openUpdateModal() {
export function renderDashboard(main) {
maybeWake();
// The menu is up, so the confirm pane was left: its Notebook switch starts
// off again, with nothing picked, the next time a card is opened.
note = null;
// First, so nothing below reads a pick whose handoff has left the scan, and
// a delete the agent's rescan has finished stops holding the buttons.
selHandoff();
@@ -689,6 +699,220 @@ function dashCard(entry, menu) {
return b;
}
// "Start with a note from your Notebook": the switch a lit card's confirm
// pane offers when noteSwitchShows() says so. The pane is rebuilt on every
// state frame, so what the person did lives here, keyed to the card and the
// picked spec it was done for: `on`, the tabs as read (`null` until then,
// each with its text and pictures once fetched), the picked tab and its
// ticked picture ids. `pick` is the pending pick Phase 2 reads at Start.
let note = null;
const noteKey = (entry) => entry.skill + "|" + ((selSpec() && selSpec().dir) || "");
function noteFor(entry) {
const key = noteKey(entry);
if (!note || note.key !== key) note = { key, on: false, tabs: null, failed: false, picked: null, ticked: [] };
return note;
}
/**
* The tab the confirm pane has picked for this card, as `{ tab, name, text,
* images }` with only the ticked pictures, or null when the switch is off or
* no tab is picked.
*/
export function pendingNotePick(entry) {
if (!entry || !note || note.key !== noteKey(entry) || !note.on || !note.picked || !note.tabs) return null;
const tab = note.tabs.find((t) => t.id === note.picked);
if (!tab || !tab.read) return null;
return {
tab: tab.id,
name: tab.name,
text: tab.read.text,
images: tab.read.images.filter((img) => note.ticked.includes(img.id)),
};
}
// Every tab, then each tab's text and pictures (the list shows an empty tab
// grayed, so each must be read). Read only: GET /notepad never writes.
async function readNoteTabs(state) {
try {
const res = await fetch("/notepad", { cache: "no-store" });
if (!res.ok) throw new Error(String(res.status));
const body = await res.json();
const tabs = Array.isArray(body.tabs) ? body.tabs : [];
const read = await Promise.all(
tabs.map(async (t) => {
try {
const r = await fetch("/notepad?tab=" + encodeURIComponent(t.id), { cache: "no-store" });
if (!r.ok) return null;
const b = await r.json();
return b && b.tab ? { text: typeof b.tab.text === "string" ? b.tab.text : "", images: Array.isArray(b.tab.images) ? b.tab.images : [] } : null;
} catch {
return null;
}
}),
);
state.tabs = tabs.map((t, i) => ({ id: t.id, name: t.name, sent: t.sent || null, read: read[i] }));
state.failed = false;
} catch {
state.tabs = [];
state.failed = true;
}
}
// Read the tabs again (`fresh` shows "Reading…" meanwhile, for a first read).
// The pick survives only while its tab is still there with something in it,
// and its ticks only for pictures still in that tab, so what Start reads is
// never older than the last time the Notebook was closed.
async function refreshNoteTabs(state, fresh = false) {
if (state.reading) return;
state.reading = true;
if (fresh) {
state.tabs = null;
redraw();
}
await readNoteTabs(state);
state.reading = false;
const tab = state.tabs.find((t) => t.id === state.picked);
if (!tab || !tab.read || noteTabEmpty(tab.read)) {
state.picked = null;
state.ticked = [];
} else {
const ids = tab.read.images.map((img) => img.id);
state.ticked = state.ticked.filter((id) => ids.includes(id));
}
// A state frame may have rebuilt the pane while the read was out, so the
// whole page redraws rather than a (perhaps detached) box.
if (note === state) redraw();
}
// The switch, the tab list and the preview, drawn into `box`; `cmdNote` is the
// command line's `+ note: <tab>` span. Each change redraws only this box, so
// the rest of the pane (and the focus on it) stays put.
function drawNoteBox(entry, box, cmdNote) {
const state = noteFor(entry);
const focusKey = document.activeElement && box.contains(document.activeElement) ? document.activeElement.dataset.noteFocus : null;
const again = () => drawNoteBox(entry, box, cmdNote);
box.replaceChildren();
const label = el("label", "confirm-note-switch");
const toggle = el("input");
toggle.type = "checkbox";
toggle.id = "confirm-note-switch";
toggle.dataset.noteFocus = "switch";
toggle.checked = state.on;
toggle.addEventListener("change", () => {
state.on = toggle.checked;
again();
if (state.on && (state.tabs === null || state.failed)) refreshNoteTabs(state, true);
});
label.append(toggle, el("span", null, "Start with a note from your Notebook"));
box.appendChild(label);
const picked = state.on && state.tabs ? state.tabs.find((t) => t.id === state.picked && t.read) : null;
cmdNote.textContent = picked ? " + note: " + picked.name : "";
cmdNote.hidden = !picked;
if (!state.on) return;
const wrap = el("div", "confirm-note");
if (state.tabs === null) {
wrap.appendChild(el("p", "confirm-note-msg", "Reading your Notebook…"));
} else if (state.failed) {
wrap.appendChild(el("p", "confirm-note-msg", "Your Notebook could not be read. Turn the switch off and on to try again."));
} else if (!state.tabs.length) {
wrap.appendChild(el("p", "confirm-note-msg", "Your Notebook has no tabs yet. Open it from the top bar to write one."));
} else {
const list = el("div", "confirm-note-tabs");
list.setAttribute("role", "group");
list.setAttribute("aria-label", "Notebook tabs");
for (const t of state.tabs) {
const empty = !t.read || noteTabEmpty(t.read);
const b = el("button", "confirm-note-tab" + (t.id === state.picked ? " is-picked" : ""));
b.type = "button";
b.dataset.noteFocus = "tab-" + t.id;
b.disabled = empty;
b.setAttribute("aria-pressed", String(t.id === state.picked));
b.appendChild(el("span", "confirm-note-tab-name", t.name));
if (t.sent) {
const badge = el("span", "notepad-sent-badge", "sent");
badge.setAttribute("aria-hidden", "true");
b.appendChild(badge);
}
b.setAttribute("aria-label", t.name + (t.sent ? ", sent" : "") + (empty ? ", empty" : ""));
if (empty) b.title = t.read ? "This tab has no text or pictures." : "This tab could not be read.";
b.addEventListener("click", () => {
if (state.picked === t.id) return;
state.picked = t.id;
state.ticked = defaultNoteTicks(t.read.images);
again();
});
list.appendChild(b);
}
wrap.appendChild(list);
wrap.appendChild(notePreview(picked, state, again));
}
box.appendChild(wrap);
if (focusKey) {
const back = box.querySelector(`[data-note-focus="${focusKey}"]`);
if (back && !back.disabled) back.focus();
}
}
// The picked tab in full: a "Long tab" note over NOTE_LONG_BYTES, its text as
// Markdown, and its pictures, each with a tick (at most MAX_ATTACHMENTS).
function notePreview(picked, state, again) {
const pane = el("div", "confirm-note-preview");
pane.setAttribute("role", "region");
pane.setAttribute("aria-label", "Preview of the picked tab");
if (!picked) {
pane.appendChild(el("p", "confirm-note-msg", "Pick a tab to see it here."));
return pane;
}
const bytes = new TextEncoder().encode(picked.read.text).length;
if (bytes > NOTE_LONG_BYTES) pane.appendChild(el("p", "confirm-note-long", "Long tab: " + formatBytes(bytes)));
const text = el("div", "confirm-note-text md");
if (picked.read.text.trim()) mdInto(text, picked.read.text);
else text.appendChild(el("p", "confirm-note-msg", "No text, only pictures."));
pane.appendChild(text);
const images = picked.read.images;
if (images.length) {
const full = state.ticked.length >= MAX_ATTACHMENTS;
pane.appendChild(
el(
"p",
"confirm-note-msg",
images.length > MAX_ATTACHMENTS
? `Up to ${MAX_ATTACHMENTS} pictures go with it. Untick one to tick another.`
: "Untick a picture to leave it out.",
),
);
const strip = el("ul", "confirm-note-pics");
images.forEach((img, i) => {
const li = el("li", "confirm-note-pic");
const lab = el("label");
const tick = el("input");
tick.type = "checkbox";
tick.dataset.noteFocus = "pic-" + img.id;
tick.checked = state.ticked.includes(img.id);
tick.disabled = !tick.checked && full;
tick.setAttribute("aria-label", `Picture ${i + 1} of ${images.length}`);
tick.addEventListener("change", () => {
state.ticked = toggleNoteTick(state.ticked, img.id);
again();
});
const pic = el("img");
pic.src = img.thumb || img.url;
pic.alt = "";
pic.loading = "lazy";
lab.append(tick, pic);
li.appendChild(lab);
strip.appendChild(li);
});
pane.appendChild(strip);
}
return pane;
}
// The confirm pane. A card or rail click lands here rather than launching
// straight away: picking a skill is the one irreversible-feeling click on the
// dashboard, and it deserves a beat: what it is, what it will do, and a
@@ -757,9 +981,26 @@ export function renderConfirm(main, entry) {
pane.appendChild(label);
}
// The Notebook switch, on the cards and specs noteSwitchShows() names.
const cmdNote = el("span", "confirm-cmd-note");
cmdNote.hidden = true;
if (noteSwitchShows(entry, scan(), selSpec())) {
pane.appendChild(el("hr", "confirm-rule"));
const box = el("div", "confirm-note-box");
// Which control in the box has the focus, so a rebuild of the whole pane
// can hand it back (see the end of this function).
box.addEventListener("focusin", (e) => (noteFor(entry).focus = e.target.dataset.noteFocus || null));
box.addEventListener("focusout", (e) => {
if (e.relatedTarget && !box.contains(e.relatedTarget)) noteFor(entry).focus = null;
});
drawNoteBox(entry, box, cmdNote);
pane.appendChild(box);
}
const cmd = el("p", "confirm-cmd");
const cmdCode = el("code", null, launchVariant(entry, !review || review.checked).command);
cmd.appendChild(cmdCode);
cmd.appendChild(cmdNote);
pane.appendChild(cmd);
const actions = el("div", "confirm-actions");
@@ -780,8 +1021,12 @@ export function renderConfirm(main, entry) {
main.appendChild(pane);
// Focus lands on START after a pick (the clicked control was rebuilt away,
// leaving focus on <body>), but never yanked back from a deliberate click
// elsewhere: a state frame can re-render this pane at any time.
if (document.activeElement === document.body) start.focus();
// elsewhere: a state frame can re-render this pane at any time. A control
// in the Notebook box gets its focus back instead.
if (document.activeElement === document.body) {
const held = note && note.key === noteKey(entry) && note.focus ? pane.querySelector(`[data-note-focus="${note.focus}"]`) : null;
(held && !held.disabled ? held : start).focus();
}
}
// A pick is a send like a brief or a stop: it names no question, so `__launch`
@@ -809,6 +1054,22 @@ async function launchSkill(entry) {
// cards that take no spec (utilities, setup) launch untargeted even while
// a spec is selected, save Quick Task on a diagnosed bug.
if (target) action.spec = target.dir;
// A Notebook tab picked in the pane rides the hop in this page only, never
// on the action: the launched skill's `fill: "note"` box is filled from it
// (core.js), and the agent reads it only when that box is sent.
// Set either way, so a pick left from a launch that never hopped cannot
// fill this one.
const pick = pendingNotePick(entry);
page.local.noteSend = pick
? {
tab: pick.tab,
text: pick.text,
pictures: pick.images.map((img) => img.id),
workflow: entry.workflow,
...(target ? { spec: target.dir } : {}),
}
: null;
saveNow();
// The skill opens on the folders remembered for what it was launched for.
// Held until the launch is in flight: the swap's own frame re-renders the
// dashboard, which would otherwise sync back to the picker's spec.
@@ -825,6 +1086,7 @@ async function launchSkill(entry) {
});
if (res.status === 409) {
page.launchScoping = false;
dropNoteSend();
page.pendingResult = true;
hooks.banner("Your last pick is still being picked up. One moment.", "info");
return;
@@ -838,10 +1100,18 @@ async function launchSkill(entry) {
redraw();
} catch {
page.launchScoping = false;
dropNoteSend();
hooks.banner("That did not go through. Nothing was lost; try again.", "warn");
}
}
// A launch that did not go through takes no Notebook tab anywhere.
function dropNoteSend() {
if (!page.local.noteSend) return;
page.local.noteSend = null;
saveNow();
}
// The picker's Delete: a dialog in two steps. The first says what goes and
// that it is for good; "Delete this spec…" then reveals the second, which
// enables the final button only once the spec's name is typed exactly. A
@@ -1007,6 +1277,11 @@ async function sendDelete(spec) {
// The dialogs' buttons, wired once at start-up: the update notice's Done, the
// handoff preview's close, and the delete dialog's Cancel, name box and go.
export function wireDashboard() {
// Closing the Notebook over an open confirm pane with the switch on reads
// the tabs again, so an edit or a delete made there shows in the preview.
$("notepad-modal").addEventListener("close", () => {
if (note && note.on && page.dashPick) refreshNoteTabs(note);
});
$("update-done").addEventListener("click", () => $("update-modal").close());
$("delete-cancel").addEventListener("click", () => $("delete-modal").close());
$("handoff-close").addEventListener("click", () => $("handoff-modal").close());
+29 -3
View File
@@ -2,7 +2,8 @@
//
// The person's own notes for the folder this session runs in, kept by the
// server under ~/.plan2code/notepads/ through the /notepad routes, never in
// the session, so nothing typed here reaches the agent. A notepad is a row of
// the session. The agent CLI never imports the store: a tab leaves it only
// through a send the person starts on the dashboard. A notepad is a row of
// tabs, each its own note with its own pictures; one tab is on screen. The
// editor is CodeMirror (notepad-editor.js), loaded the first time the Notebook
// opens. When to save, what the status line says, the tab name rules and the
@@ -34,6 +35,7 @@ import { el, lightDismiss } from "../render.js";
import { postJson } from "../net.js";
import { reencode } from "../uploads.js";
import { createTabs } from "../notepad-tabs.js";
import { skillFor } from "../skills.js";
const $ = (id) => document.getElementById(id);
@@ -245,8 +247,32 @@ async function readNote(tab) {
const nameOf = (id) => (tabs.find((t) => t.id === id) || {}).name || "";
// A tab as the bar and the sent line keep it: `sent` only on a tab sent from
// the dashboard.
const tabEntry = (t) => ({ id: t.id, name: t.name, ...(t.sent ? { sent: t.sent } : {}) });
// "Sent to Plan · Oct 27", or "Sent to Revise plan (lunch-vote) · Oct 27",
// for a tab's last send; "" when it has none.
export function sentLine(sent) {
if (!sent || typeof sent.workflow !== "string") return "";
const skill = skillFor(sent.workflow);
const at = new Date(sent.at);
if (!skill || Number.isNaN(at.getTime())) return "";
const spec = typeof sent.spec === "string" && sent.spec ? " (" + sent.spec.replace(/^specs\//, "") + ")" : "";
return "Sent to " + skill.name + spec + " · " + at.toLocaleDateString(undefined, { month: "short", day: "numeric" });
}
// The muted line under the editor for the tab on screen.
function drawSent() {
const line = $("notepad-sent");
const text = sentLine((tabs.find((t) => t.id === activeId) || {}).sent);
line.textContent = text;
line.hidden = !text;
}
function drawTabs() {
tabBar.draw(tabs, activeId);
drawSent();
$("notepad-tab-new").disabled = busy;
$("notepad-empty-new").disabled = busy;
$("notepad-name-save").disabled = busy;
@@ -256,7 +282,7 @@ function drawTabs() {
// the text and the tab alone (the notepad was only reopened while text was
// still unsaved), taking the bar and the pictures from the server.
function show(body, keep = false) {
tabs = body.tabs.map((t) => ({ id: t.id, name: t.name }));
tabs = body.tabs.map(tabEntry);
const tab = body.tab;
if (keep) {
takeStored(tab && tab.id === activeId ? tab.images : [], activeId);
@@ -328,7 +354,7 @@ async function reorder(order, focus) {
inform("");
tell(errorSentence(res.status === 0 ? null : res.body && res.body.error));
const again = await readNote(activeId);
if (again.ok) tabs = again.body.tabs.map((t) => ({ id: t.id, name: t.name }));
if (again.ok) tabs = again.body.tabs.map(tabEntry);
drawTabs();
}