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

+43
View File
@@ -695,6 +695,49 @@ export function cardAvailability(entry, scan, sel, lookup = stateFor) {
return off(rule.greyed[taken] || (lookup(taken)?.finished && rule.greyed.finished) || rule.greyed.default);
}
// The cards whose confirm pane offers "Start with a note from your Notebook"
// on Start fresh: the three that open on an idea box.
const NOTE_FRESH_CARDS = new Set(["plan2code-0-pathfinder", "plan2code-1-plan", "plan2code-quick-task"]);
/**
* Whether a lit card's confirm pane offers the Notebook switch: Pathfinder,
* Plan and Quick Task on Start fresh (no spec picked), and Revise plan on a
* picked spec with no plan change brief waiting (a waiting brief is what that
* revision is about). Never on a grayed card, never on any other card.
*/
export function noteSwitchShows(entry, scan, sel) {
if (!entry || !cardAvailability(entry, scan, sel).on) return false;
if (NOTE_FRESH_CARDS.has(entry.skill)) return !sel;
if (entry.skill === "plan2code-1b-revise-plan") return Boolean(sel) && sel.planChange !== true;
return false;
}
// A Notebook tab's text over this many UTF-8 bytes gets a "Long tab" note in
// the confirm pane's preview, so the person can trim it before it is sent.
export const NOTE_LONG_BYTES = 51200;
/** Whether a Notebook tab, as GET /notepad?tab= reads it, holds nothing to send. */
export function noteTabEmpty(tab) {
const text = tab && typeof tab.text === "string" ? tab.text : "";
const images = tab && Array.isArray(tab.images) ? tab.images : [];
return text.trim() === "" && images.length === 0;
}
/** The pictures ticked when a tab is first picked: its first MAX_ATTACHMENTS, in its own order. */
export function defaultNoteTicks(images) {
return (Array.isArray(images) ? images : []).slice(0, MAX_ATTACHMENTS).map((img) => img.id);
}
/**
* The ticked ids after a click on `id`: unticked if it was ticked, else ticked
* while fewer than MAX_ATTACHMENTS are; past that the click changes nothing.
*/
export function toggleNoteTick(ticked, id) {
const list = Array.isArray(ticked) ? ticked : [];
if (list.includes(id)) return list.filter((t) => t !== id);
return list.length < MAX_ATTACHMENTS ? [...list, id] : list;
}
/**
* The spec a card's launch carries: the picker's selection for the cards that
* take a spec, and for Quick Task only a diagnosed bug, whose write-up it reads
+199 -15
View File
@@ -35,6 +35,9 @@
<link rel="modulepreload" href="/screens/workspace.js" />
<link rel="modulepreload" href="/screens/ask.js" />
<link rel="modulepreload" href="/screens/notepad.js" />
<link rel="modulepreload" href="/screens/activities.js" />
<link rel="modulepreload" href="/activities.js" />
<link rel="modulepreload" href="/tones.js" />
<link rel="modulepreload" href="/net.js" />
<link rel="modulepreload" href="/render.js" />
<link rel="modulepreload" href="/palette.js" />
@@ -184,6 +187,19 @@
<path class="mg-line" d="M4.6 9.8l.9 3.4h1.6l-.6-2.7M12.4 6.1a2.6 2.6 0 0 1 0 3.8M13.8 4.5a5 5 0 0 1 0 7" />
</svg>
</a>
<!-- Activities: small games for a long wait. Opens a dialog that pauses
the moment Plan2Code needs the person; nothing in it reaches the agent. -->
<button type="button" class="icon-btn" id="btn-activities" title="Activities" aria-label="Activities">
<!-- A die: a rounded square and five pips. -->
<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false">
<rect class="dc-body" x="2" y="2" width="12" height="12" rx="2.6" />
<circle class="dc-pip" cx="5.4" cy="5.4" r="1" />
<circle class="dc-pip" cx="10.6" cy="5.4" r="1" />
<circle class="dc-pip" cx="8" cy="8" r="1" />
<circle class="dc-pip" cx="5.4" cy="10.6" r="1" />
<circle class="dc-pip" cx="10.6" cy="10.6" r="1" />
</svg>
</button>
</div>
<div class="topbar-row second">
<div class="row-left">
@@ -216,7 +232,8 @@
</svg>
</button>
<!-- Notebook: every screen, never hidden. The person's private notes for this
folder; nothing in it reaches the agent. -->
folder; a tab reaches the agent only through a send the person
starts on the dashboard. -->
<button type="button" class="btn ghost small notepad-btn" id="btn-notepad" title="Notebook" aria-label="Notebook">
<!-- A pocket notebook: a closed cover with a spine line and an elastic band. -->
<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false">
@@ -778,6 +795,10 @@
<path d="M4 5h16v11H10l-4 4v-4H4z" />
<path d="M8 9.5h8M8 12.5h5" />
</symbol>
<symbol id="hi-activities" viewBox="0 0 24 24" fill="none">
<rect x="4" y="4" width="16" height="16" rx="3.5" />
<path d="M8.5 8.5h.01M15.5 8.5h.01M12 12h.01M8.5 15.5h.01M15.5 15.5h.01" />
</symbol>
<symbol id="hi-finishing" viewBox="0 0 24 24" fill="none">
<path d="M6 21V4" />
<path d="M6 4h11l-2 4 2 4H6" />
@@ -1144,16 +1165,20 @@
<li>
The <strong>?</strong> button opens this Help, and the gear button
beside it opens <strong>User Preferences</strong>: your role first,
then your colors, theme, card width and sounds.
then your colors, theme, card width, sounds and whether Activities shows.
</li>
<li class="for-browser">
The <strong>megaphone</strong> button at the far right opens GitHub in a
The <strong>megaphone</strong> button opens GitHub in a
new tab, where you can report a bug or suggest an idea.
</li>
<li class="for-app">
The <strong>megaphone</strong> button at the far right opens Plan2Code's
The <strong>megaphone</strong> button opens Plan2Code's
GitHub issues, where you can report a bug or suggest an idea.
</li>
<li>
The <strong>die</strong> beside it opens <strong>Activities</strong>,
small games to play while you wait. See "Activities".
</li>
<li>
<strong>Stop session</strong> ends the session and saves your place.
See "Stopping and finishing".
@@ -1248,8 +1273,16 @@
folder per tab on disk. There is no Save button.
</li>
<li>
It is private to this machine and never sent to Plan2Code. Nothing
in it is shown to the agent.
It is private to this machine and never sent to Plan2Code.
Private: the agent never reads your Notebook. A tab reaches it only
when you start a workflow with it.
</li>
<li>
A lit card's confirm pane can offer <strong>Start with a note from
your Notebook</strong>. On the dashboard, Pathfinder, Plan and Quick
Task offer it on Start fresh, and Revise plan on a picked spec with
no plan change waiting. A tab you started a workflow with wears a
small <strong>sent</strong> badge.
</li>
<li>
Two open pages on the same folder share one notebook. If both change
@@ -2253,7 +2286,120 @@
</p>
</section>
<!-- Tab 16: Stopping and finishing -->
<!-- Tab 16: Activities -->
<section class="help-panel" data-tab="activities">
<h3>Activities</h3>
<p class="help-lead">
The <strong>die</strong> in the top bar opens
<strong>Activities</strong>: small games to play while you wait, say
through a long build. Two games ship: <strong>Snake</strong> and
<strong>Mini golf</strong>. Pick one with the buttons above the board;
the window opens on your last pick next time. Nothing you do in it
reaches Plan2Code.
</p>
<h4>The games</h4>
<ul>
<li>
<strong>Snake</strong>: steer to the food and grow. The snake speeds
up as it grows, and a wall, a rock, a comet or your own tail ends
the round. Food eaten quickly builds a combo of up to x5. Every 5
foods is a new level, and each of the first few brings something
new: rocks (a flashing cell turns to stone), mystery boxes, portals,
comets that cut your tail, then chaos. Power-ups turn up on their
own: Shield, Turbo, Slow-mo, Magnet, Ghost and Scissors, and a
mystery box can hold any of ten surprises, good or bad. The start
and end screens count how many of them you have found so far.
</li>
<li>
<strong>Mini golf</strong>: eighteen silly holes seen from above.
The front nine is <strong>Pirate Cove</strong>, greens afloat in a
shark sea with cannonballs, barrels, a kraken and a ghost ship. The
back nine is the <strong>Caves of Doom</strong>, lit only around
your ball, with lava, a bottomless pit, mine carts and stone
crushers. The aim follows your mouse. Click (or press
<kbd>Space</kbd>) to start the power meter, then click again to
set the power: the gold <strong>MAX</strong> band near the top
gives a boosted putt, but go past it into the red and you shank it.
Dawdle for 6 seconds and the meter starts by itself. Hold the mouse
button or <kbd>Space</kbd> while the ball rolls to speed it up.
Each hole has a par, and after 8
strokes the ball is picked up. The scorecard between holes shows how
the round stands against par.
</li>
<li>
<strong>Power-ups</strong>: roll over a glowing pad to hold it for
your next putt. A <strong>Lucky Doubloon</strong> makes it free, a
<strong>Cannonball</strong> fires it 1.6 times as hard, a
<strong>Ghost Ball</strong> floats over water, sand and bumpers, a
<strong>Parrot Magnet</strong> bends it toward the cup, a
<strong>Rubber Duck</strong> bounces off walls at full speed, a
<strong>Treasure Map</strong> makes the cup huge, and a
<strong>Spyglass</strong> shows where it will roll while the meter runs.
You hold one at a time, and it carries over to the next hole.
</li>
</ul>
<h4>It never hides your turn</h4>
<ul>
<li>
A new question, a sign-off or a finish pauses the game at once, and
a banner above the board says Plan2Code needs you.
<strong>Go to it</strong> closes the window on that question.
</li>
<li class="for-browser">
Switching to another tab, or clicking outside the page, also pauses it.
</li>
<li class="for-app">
Hiding the window, or clicking outside the page (the app's own bar
too), also pauses it.
</li>
<li>
Nothing resumes by itself. Any game key plays on, and so does a
click on the Mini golf board. Playing on puts the banner away until
the next new question.
</li>
<li>
Starting a round, and playing on after a pause, counts down 3, 2, 1
first, so the game never moves before you are ready.
</li>
</ul>
<h4>Keys</h4>
<ul>
<li>
Snake: the arrow keys, or <kbd>W</kbd> <kbd>A</kbd> <kbd>S</kbd>
<kbd>D</kbd>, steer.
</li>
<li>
Mini golf: hold left or right to turn the aim (faster the longer
you hold), press <kbd>Space</kbd> once to start the power meter and
again to set the power, and hold <kbd>Space</kbd> while the ball
rolls to speed it up.
</li>
<li><kbd>Space</kbd> starts a round, and plays again after a pause.</li>
<li><kbd>P</kbd> pauses and plays.</li>
<li><kbd>Esc</kbd> closes the window, with the game paused where it was.</li>
</ul>
<p>Activities need a keyboard: on a touch-only screen the window says so instead of showing the board.</p>
<h4>Best scores</h4>
<p>
The window's title shows the best for the game on screen, and the
line under the board shows it beside your score. For Snake the best
is your highest score; for Mini golf it is your lowest full round of
eighteen holes, and a round left halfway never counts.
<strong>Reset best scores</strong>, at the bottom of the window,
clears both after a second click to confirm.
</p>
<h4>Hiding it</h4>
<p>
Don't want the die? Untick <strong>Show Activities</strong> in User
Preferences (the gear) and it is gone from every screen.
</p>
<p>
Best scores, Snake's surprises found, your last pick and that switch are saved privately on
this machine, with your other preferences, and never sent anywhere.
</p>
</section>
<!-- Tab 17: Stopping and finishing -->
<section class="help-panel" data-tab="finishing">
<h3>Stopping and finishing</h3>
<p class="help-lead">
@@ -2360,7 +2506,7 @@
</p>
</section>
<!-- Tab 17: Keyboard and preferences -->
<!-- Tab 18: Keyboard and preferences -->
<section class="help-panel" data-tab="prefs">
<h3>Keyboard and preferences</h3>
<p class="help-lead">
@@ -2441,6 +2587,11 @@
joining the strip. Keep only the ones you want; ticking a box plays
its sound.
</li>
<li>
<strong>Activities</strong>: <strong>Show Activities</strong> puts
the die in the top bar, which opens small games to play while you
wait. Untick it to hide the die on every screen.
</li>
<li>
<strong>Cleanup</strong>: <strong>Find files to clean up</strong>
lists what Plan2Code doesn't need in your
@@ -2457,7 +2608,9 @@
</li>
<li>
<strong>Back to default</strong> puts everything back as it was, and
sets Role back to Not set.
sets Role back to Not set. Your Activities best scores stay: only
<strong>Reset best scores</strong>, in the Activities window, clears
them.
</li>
</ul>
<p>
@@ -2481,7 +2634,7 @@
</ul>
</section>
<!-- Tab 18: Privacy and where things are saved -->
<!-- Tab 19: Privacy and where things are saved -->
<section class="help-panel" data-tab="privacy">
<h3>Privacy and where things are saved</h3>
<p class="help-lead">
@@ -2533,8 +2686,9 @@
and attachments");
</li>
<li>
your role, theme, colors, card width and sounds, in
<code>looks.json</code>;
your role, theme, colors, card width and sounds, the Show
Activities switch, the last activity you picked and your best
scores, in <code>looks.json</code>;
</li>
<li>
your Subagents switch for each project and skill, in
@@ -2620,6 +2774,11 @@
</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-activities">
<legend>Activities</legend>
<label><input type="checkbox" id="looks-activities" checked /> <span>Show Activities</span></label>
<p class="help">The die in the top bar opens small games to play while you wait.</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. It also lists this project's <code>specs--completed/</code> folders nobody has touched for 30 days; deleting one is permanent, since that folder is usually gitignored and git can't restore it. You see the list before anything is deleted. Your preferences, saved folders, models, the launcher and this session always stay.</p>
@@ -2744,11 +2903,12 @@
<!-- The Notebook: the person's own notes for this folder, autosaved under
~/.plan2code/notepads/ by the /notepad routes. Never part of the
session, so nothing in it reaches the agent. screens/notepad.js fills
the editor on open. -->
session, and the agent CLI never imports the store: a tab leaves it
only through a send the person starts on the dashboard. screens/notepad.js
fills the editor on open. -->
<dialog class="modal notepad" id="notepad-modal" aria-labelledby="notepad-title">
<h2 id="notepad-title">Notebook</h2>
<p class="modal-blurb">A private space to keep track of notes and uploaded images related to your in-progress work on this project. Saved on this machine and <strong class="private-note">never shared to the AI Agent</strong>.</p>
<p class="modal-blurb">A private space to keep track of notes and uploaded images related to your in-progress work on this project. Saved on this machine. <strong class="private-note">Private</strong>: the agent never reads your Notebook. A tab reaches it only when you start a workflow with it.</p>
<div class="notepad-tabbar">
<div class="notepad-tabs" id="notepad-tabs" role="tablist" aria-label="Notebook tabs"></div>
<button type="button" class="btn small ghost notepad-tab-new" id="notepad-tab-new">+ New tab</button>
@@ -2759,6 +2919,7 @@
</div>
<div class="notepad-body" id="notepad-body">
<div class="notepad-editor" id="notepad-editor"></div>
<p class="help notepad-sent" id="notepad-sent" hidden></p>
<div class="notepad-images" id="notepad-images">
<button type="button" class="btn small ghost notepad-add" id="notepad-add">Add image</button>
<input type="file" accept="image/*" multiple id="notepad-file" hidden />
@@ -2807,6 +2968,29 @@
</div>
</dialog>
<!-- Activities: small built-in games for a long wait. Play is private to
this page and never reaches the agent; screens/activities.js runs the
game, and pauses it whenever Plan2Code needs the person. -->
<dialog class="modal activities" id="activities-modal" aria-labelledby="activities-title">
<h2 id="activities-title">Activities<span id="activities-title-best" class="activities-title-best"></span></h2>
<p class="modal-blurb">Something to play while you wait. Private to this page, and it pauses whenever Plan2Code needs you.</p>
<div class="activities-banner" id="activities-banner" role="status" hidden>
<span class="activities-banner-text" id="activities-banner-text"></span>
<button type="button" class="btn small primary" id="activities-goto">Go to it</button>
</div>
<div class="activities-picker" id="activities-picker" role="group" aria-label="Pick an activity" hidden></div>
<div class="activities-board" id="activities-board" tabindex="-1">
<canvas id="activities-canvas"></canvas>
<div class="activities-overlay" id="activities-overlay"></div>
</div>
<p class="activities-score" id="activities-score"></p>
<p class="help activities-note" id="activities-note" aria-live="polite" hidden></p>
<div class="modal-actions">
<button type="button" class="btn ghost" id="activities-reset">Reset best scores</button>
<button type="button" class="btn ghost" id="activities-close">Close</button>
</div>
</dialog>
<!-- The Workspace: the folder this session started in plus any added as
context. The list is drawn by app.js from the frame's `workspace`;
every change goes through the server's /workspace routes. -->
+12 -2
View File
@@ -1,6 +1,6 @@
// Plan2Code Web Console - the Notebook's tab bar.
//
// Draws #notepad-tabs from a list of { id, name } and tells screens/notepad.js
// Draws #notepad-tabs from a list of { id, name, sent? } and tells screens/notepad.js
// what the person did: pick a tab (onSwitch), reorder with a drag, ask to
// rename (a double-click or F2) or ask to delete (the x beside the name, or the
// Delete key) (onChange). No fetches here: the screen owns every request, and
@@ -96,7 +96,17 @@ export function createTabs({ onSwitch, onChange }) {
x.addEventListener("click", () => onChange({ type: "delete", id: tab.id }));
const wrap = el("div", "notepad-tabwrap");
wrap.setAttribute("role", "presentation");
wrap.append(b, x);
wrap.append(b);
// A tab sent from the dashboard wears a small badge after its name, outside
// the button so a long name's ellipsis never cuts it; the button's name
// says it for a screen reader.
if (tab.sent) {
b.setAttribute("aria-label", tab.name + ", sent");
const badge = el("span", "notepad-sent-badge", "sent");
badge.setAttribute("aria-hidden", "true");
wrap.append(badge);
}
wrap.append(x);
wrap.addEventListener("dragover", (e) => {
if (dragging === null) return;
e.preventDefault();
+2
View File
@@ -25,6 +25,7 @@ export const ERROR_CODES = Object.freeze([
"too-many",
"not-found",
"bad-name",
"bad-sent",
"duplicate-name",
"too-many-tabs",
"no-such-tab",
@@ -136,6 +137,7 @@ const ERROR_SENTENCES = Object.freeze({
"too-many": `This notepad already holds ${NOTEPAD_MAX_IMAGES} pictures, the most it can keep. Delete one to add another.`,
"not-found": "That picture is no longer in this notepad.",
"bad-name": `A tab name needs 1 to ${TAB_NAME_MAX} characters, with no control characters.`,
"bad-sent": "Plan2Code could not record where that tab was sent, so nothing was changed.",
"duplicate-name": "There is already a tab with that name.",
"too-many-tabs": `This notepad already has ${NOTEPAD_MAX_TABS} tabs, the most it can have. Delete one to add another.`,
"no-such-tab": "That tab is no longer in this notepad.",
+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();
}
+6
View File
@@ -46,6 +46,12 @@ export function fresh() {
launching: null,
// A picker Delete sent and not yet answered by a rescan: { dir, scanAt }.
deleting: null,
// A Notebook tab picked at Start, riding the hop until the launched
// skill's `fill: "note"` box takes it: { tab, text, pictures, workflow, spec? }.
noteSend: null,
// The box it filled, until a send carrying that box marks the tab sent:
// { item, tab, workflow, spec? }.
noteSent: null,
retract: {},
chat: freshChat(),
};
@@ -423,8 +423,60 @@
border-radius: 6px;
padding: 4px 10px;
}
.confirm-cmd-note { margin-left: 8px; font-family: var(--mono); font-size: 12.5px; color: var(--accent); }
.confirm-actions { display: flex; gap: 10px; margin-top: 10px; }
/* "Start with a note from your Notebook": the switch, then the tabs beside a
preview of the picked one, its pictures each with a tick. */
.confirm-note-box { display: grid; gap: 8px; }
.confirm-note-switch { display: flex; gap: 8px; align-items: center; color: var(--ink-2); cursor: pointer; }
.confirm-note-switch input { accent-color: var(--accent, currentColor); }
.confirm-note { display: grid; grid-template-columns: minmax(130px, 200px) minmax(0, 1fr); gap: 10px; }
.confirm-note > .confirm-note-msg { grid-column: 1 / -1; }
.confirm-note-msg { margin: 0; font-size: 13px; color: var(--ink-3); }
.confirm-note-tabs { display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow-y: auto; }
.confirm-note-tab {
display: flex;
align-items: center;
gap: 6px;
padding: 6px 10px;
border: 1px solid var(--rule-2);
border-radius: 8px;
background: var(--panel-2);
color: var(--ink-2);
font: inherit;
font-size: 13px;
text-align: left;
cursor: pointer;
}
.confirm-note-tab:hover:not(:disabled) { border-color: var(--accent-line); color: var(--accent); }
.confirm-note-tab.is-picked { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.confirm-note-tab:disabled { opacity: 0.5; cursor: not-allowed; }
.confirm-note-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.confirm-note-tab-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.confirm-note-preview {
display: grid;
gap: 8px;
align-content: start;
min-width: 0;
max-height: 320px;
overflow-y: auto;
padding: 8px 10px;
border: 1px solid var(--rule-2);
border-radius: 8px;
background: var(--panel);
}
.confirm-note-text { font-size: 13.5px; }
.confirm-note-long { margin: 0; font-size: 12.5px; font-weight: 600; color: var(--warn); }
.confirm-note-pics { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.confirm-note-pic label { position: relative; display: block; cursor: pointer; }
.confirm-note-pic img { display: block; width: 72px; height: 72px; object-fit: cover; border: 1px solid var(--rule-2); border-radius: 6px; }
.confirm-note-pic input { position: absolute; top: 4px; left: 4px; margin: 0; accent-color: var(--accent, currentColor); }
.confirm-note-pic input:disabled + img { opacity: 0.45; }
@media (max-width: 560px) {
.confirm-note { grid-template-columns: minmax(0, 1fr); }
}
/* ------------------------------------------------------- launching pane */
.launching {
+14
View File
@@ -43,6 +43,9 @@
background: var(--panel);
}
.notepad-editor:focus-within { border-color: var(--accent-line); }
/* The open tab's last send from the dashboard, muted under the editor. */
.notepad-sent { flex: none; margin: 6px 0 0; font-size: 12.5px; color: var(--ink-3); }
.notepad-sent[hidden] { display: none; }
/* The pictures under the editor: the Add image button, then the thumbnails,
wrapping. Capped at two rows, so 200 pictures never squeeze the editor
away; the strip scrolls instead. The whole region lights while pictures are
@@ -203,6 +206,17 @@
white-space: nowrap;
}
.notepad-tab[aria-selected="true"] { font-weight: 600; }
.notepad-sent-badge {
flex: none;
margin: 0 2px 0 2px;
padding: 1px 5px;
border: 1px solid var(--rule-2);
border-radius: 999px;
color: var(--ink-3);
font-size: 10.5px;
line-height: 1.3;
white-space: nowrap;
}
.notepad-tab-x {
flex: none;
width: 20px;