mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Let the dashboard start Pathfinder, Plan, Quick Task or Revise plan from a Notebook tab
AI Assisted
This commit is contained in:
1 parent
7973bc093b
commit
720758a7ee
29 files changed
+1416
-47
No files matched your search
+1
-1
@@ -23,7 +23,7 @@ The install command always opens a menu. Back at your prompt with no output at a
|
||||
|
||||
Pick a skill on the dashboard and the same page becomes that session. Details: [.readme/web-console.md](.readme/web-console.md) · worked example: [.readme/walkthrough.md](.readme/walkthrough.md).
|
||||
|
||||
The **Notebook** icon in the top bar opens a private scratch pad for the folder you are in (Markdown and pictures, kept in `~/.plan2code/notepads/`, never shown to the agent).
|
||||
The **Notebook** icon in the top bar opens a private scratch pad for the folder you are in (Markdown and pictures, kept in `~/.plan2code/notepads/`). Private: the agent never reads your Notebook. A tab reaches it only when you start a workflow with it.
|
||||
|
||||
## Commands
|
||||
|
||||
|
||||
@@ -48,6 +48,11 @@ import {
|
||||
handoffText,
|
||||
launchReply,
|
||||
launchTarget,
|
||||
noteSwitchShows,
|
||||
noteTabEmpty,
|
||||
defaultNoteTicks,
|
||||
toggleNoteTick,
|
||||
NOTE_LONG_BYTES,
|
||||
deleteAction,
|
||||
deleteReply,
|
||||
chipDetail,
|
||||
@@ -1500,6 +1505,17 @@ test("validate: templates only as \"idea\", only on a text item", () => {
|
||||
assert.ok(validate(item({ templates: "yes" })).includes(message));
|
||||
});
|
||||
|
||||
test("validate: fill only as \"note\", only on a text item", () => {
|
||||
const item = (extra) => ({ items: [{ id: "idea", kind: "text", title: "What's the idea?", ...extra }] });
|
||||
const message = 'item "idea" has "fill": only a text item can carry it, and its only value is "note".';
|
||||
assert.deepEqual(validate(item({ fill: "note" })), []);
|
||||
assert.deepEqual(validate(item({ fill: "note", templates: "idea" })), []);
|
||||
assert.ok(validate(item({ kind: "choice", options: [{ k: "A", text: "a" }], fill: "note" })).includes(message));
|
||||
assert.ok(validate(item({ kind: "confirm", fill: "note" })).includes(message));
|
||||
assert.ok(validate(item({ fill: "idea" })).includes(message));
|
||||
assert.ok(validate(item({ fill: true })).includes(message));
|
||||
});
|
||||
|
||||
test("attachmentName: slug of the original name, 8 characters of the upload id, the upload's own extension", () => {
|
||||
const up = (uuid, ext) => path.join(HOME, "sessions", "x", "uploads", `${uuid}${ext}`);
|
||||
const a = up("3f2b9c1e-8a4d-4f6e-9b7a-2c5d1e0f4a6b", ".jpg");
|
||||
@@ -2320,3 +2336,45 @@ test("meter: the weights and labels built from the skill list are the ones writt
|
||||
});
|
||||
for (const t of [WEIGHTS, LAUNCH_LABELS, RUN_LABELS]) assert.ok(Object.isFrozen(t));
|
||||
});
|
||||
|
||||
test("noteSwitchShows: Pathfinder, Plan and Quick Task on Start fresh, Revise plan on a picked spec with no brief waiting", () => {
|
||||
const entry = (skill) => SKILL_CATALOG.find((e) => e.skill === skill);
|
||||
const scan = { hasAgents: true, isGit: true, pending: 0, specs: [] };
|
||||
const sel = (state, extra = {}) => ({ dir: "specs/x", name: "x", state, ...extra });
|
||||
const fresh = ["plan2code-0-pathfinder", "plan2code-1-plan", "plan2code-quick-task"];
|
||||
for (const skill of fresh) {
|
||||
assert.equal(noteSwitchShows(entry(skill), scan, null), true, `${skill} on Start fresh`);
|
||||
assert.equal(noteSwitchShows(entry(skill), scan, sel("exploring")), false, `${skill} on a picked spec`);
|
||||
assert.equal(noteSwitchShows(entry(skill), scan, sel("exploring", { planChange: true })), false, `${skill} on a picked spec with a brief`);
|
||||
}
|
||||
const revise = entry("plan2code-1b-revise-plan");
|
||||
assert.equal(noteSwitchShows(revise, scan, null), false, "Revise plan is grayed on Start fresh");
|
||||
for (const state of ["documented", "building", "built"]) {
|
||||
assert.equal(noteSwitchShows(revise, scan, sel(state)), true, `Revise plan on ${state}`);
|
||||
assert.equal(noteSwitchShows(revise, scan, sel(state, { planChange: true })), false, `Revise plan on ${state} with a brief waiting`);
|
||||
}
|
||||
assert.equal(noteSwitchShows(revise, scan, sel("exploring")), false, "never on a grayed card");
|
||||
for (const skill of ["plan2code-3-implement", "plan2code-2-document", "plan2code-git", "plan2code-xray"]) {
|
||||
assert.equal(noteSwitchShows(entry(skill), scan, null), false, `${skill} on Start fresh`);
|
||||
assert.equal(noteSwitchShows(entry(skill), scan, sel("documented")), false, `${skill} on a picked spec`);
|
||||
}
|
||||
assert.equal(noteSwitchShows(null, scan, null), false);
|
||||
});
|
||||
|
||||
test("Notebook pick rules: an empty tab, the first five pictures ticked, and no sixth tick", () => {
|
||||
assert.equal(noteTabEmpty({ text: "", images: [] }), true);
|
||||
assert.equal(noteTabEmpty({ text: " \n", images: [] }), true, "whitespace is nothing to send");
|
||||
assert.equal(noteTabEmpty({ text: "", images: [{ id: "a" }] }), false);
|
||||
assert.equal(noteTabEmpty({ text: "idea", images: [] }), false);
|
||||
assert.equal(noteTabEmpty(null), true);
|
||||
const imgs = ["a", "b", "c", "d", "e", "f", "g"].map((id) => ({ id }));
|
||||
assert.deepEqual(defaultNoteTicks(imgs), ["a", "b", "c", "d", "e"]);
|
||||
assert.deepEqual(defaultNoteTicks(imgs.slice(0, 2)), ["a", "b"]);
|
||||
assert.deepEqual(defaultNoteTicks(undefined), []);
|
||||
const five = defaultNoteTicks(imgs);
|
||||
assert.deepEqual(toggleNoteTick(five, "f"), five, "a sixth tick changes nothing");
|
||||
const four = toggleNoteTick(five, "c");
|
||||
assert.deepEqual(four, ["a", "b", "d", "e"]);
|
||||
assert.deepEqual(toggleNoteTick(four, "f"), ["a", "b", "d", "e", "f"], "untick one to tick another");
|
||||
assert.equal(NOTE_LONG_BYTES, 51200);
|
||||
});
|
||||
@@ -917,6 +917,79 @@ test("the tab routes refuse bad bodies, unknown tabs and every foreign caller",
|
||||
assert.equal((await getJson(s, "/notepad")).body.last, other.id);
|
||||
});
|
||||
|
||||
test("markTabSent records, replaces and validates a tab's last send, and listTabs and readNotepad return it", () => {
|
||||
const folder = freshFolder();
|
||||
const a = tabOf(folder, "A");
|
||||
const b = tabOf(folder, "B");
|
||||
assert.deepEqual(listTabs(folder).tabs, [{ id: a, name: "A" }, { id: b, name: "B" }], "no sent until a send");
|
||||
|
||||
const first = store.markTabSent(folder, a, { workflow: "plan" });
|
||||
assert.equal(first.id, a);
|
||||
assert.deepEqual(Object.keys(first.sent).sort(), ["at", "workflow"]);
|
||||
assert.equal(first.sent.workflow, "plan");
|
||||
assert.ok(!Number.isNaN(Date.parse(first.sent.at)));
|
||||
assert.deepEqual(listTabs(folder).tabs[0], { id: a, name: "A", sent: first.sent });
|
||||
assert.equal(listTabs(folder).tabs[1].sent, undefined, "only the sent tab carries it");
|
||||
|
||||
const second = store.markTabSent(folder, a, { workflow: "revise-plan", spec: "specs/lunch-vote" });
|
||||
assert.deepEqual(second.sent, { workflow: "revise-plan", spec: "specs/lunch-vote", at: second.sent.at }, "replaces the earlier one");
|
||||
const read = readNotepad(folder, a);
|
||||
assert.deepEqual(read.tabs[0].sent, second.sent);
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(notepadFolder(folder), "tabs.json"), "utf8")).tabs[a].sent, second.sent);
|
||||
|
||||
// A rename keeps the record; it is the tab's, not the name's.
|
||||
renameTab(folder, a, "A2");
|
||||
assert.deepEqual(listTabs(folder).tabs[0].sent, second.sent);
|
||||
|
||||
for (const bad of [{}, { workflow: "implement" }, { workflow: "plan", spec: "lunch-vote" }, { workflow: "plan", spec: "specs/a/b" }, { workflow: "plan", spec: 5 }]) {
|
||||
refusal(() => store.markTabSent(folder, b, bad), "bad-sent");
|
||||
}
|
||||
refusal(() => store.markTabSent(folder, "ffffffffffff", { workflow: "plan" }), "no-such-tab");
|
||||
refusal(() => store.markTabSent(folder, "nope", { workflow: "plan" }), "no-such-tab");
|
||||
assert.equal(listTabs(folder).tabs[1].sent, undefined, "refusals recorded nothing");
|
||||
});
|
||||
|
||||
test("a sent record that does not hold up is dropped on read, never the index", () => {
|
||||
const folder = freshFolder();
|
||||
const a = tabOf(folder, "A");
|
||||
const file = path.join(notepadFolder(folder), "tabs.json");
|
||||
const index = JSON.parse(fs.readFileSync(file, "utf8"));
|
||||
index.tabs[a].sent = { workflow: "implement", at: "2026-10-27T00:00:00.000Z" };
|
||||
fs.writeFileSync(file, JSON.stringify(index));
|
||||
assert.deepEqual(listTabs(folder).tabs, [{ id: a, name: "A" }]);
|
||||
});
|
||||
|
||||
test("POST /notepad/tab/sent answers 200, 400 and 404, and GET /notepad carries the record", async (t) => {
|
||||
const s = openSession();
|
||||
t.after(() => fs.rmSync(notepadFolder(ROOT), { recursive: true, force: true }));
|
||||
fs.rmSync(notepadFolder(ROOT), { recursive: true, force: true });
|
||||
const post = async (body) => {
|
||||
const res = await s.send("/notepad/tab/sent", body);
|
||||
return { status: res.status, body: await res.json() };
|
||||
};
|
||||
const id = (await (await s.send("/notepad/tab", { name: "Idea" })).json()).id;
|
||||
const ok = await post({ id, workflow: "quick-task" });
|
||||
assert.equal(ok.status, 200);
|
||||
assert.equal(ok.body.ok, true);
|
||||
assert.equal(ok.body.sent.workflow, "quick-task");
|
||||
assert.deepEqual((await getJson(s, "/notepad")).body.tabs, [{ id, name: "Idea", sent: ok.body.sent }]);
|
||||
assert.deepEqual(await post({ id, workflow: "document" }), { status: 400, body: { error: "bad-sent" } });
|
||||
assert.deepEqual(await post({ id, workflow: "revise-plan", spec: "../x" }), { status: 400, body: { error: "bad-sent" } });
|
||||
assert.deepEqual(await post({ id: "ffffffffffff", workflow: "plan" }), { status: 404, body: { error: "no-such-tab" } });
|
||||
assert.deepEqual(await post({ workflow: "plan" }), { status: 404, body: { error: "no-such-tab" } });
|
||||
|
||||
const body = JSON.stringify({ id, workflow: "plan" });
|
||||
const noCookie = await fetch(`${s.base}/notepad/tab/sent`, { method: "POST", headers: { "content-type": "application/json", connection: "close" }, body });
|
||||
assert.equal(noCookie.status, 403);
|
||||
const foreign = await fetch(`${s.base}/notepad/tab/sent`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json", cookie: s.cookie, origin: "http://evil.example", connection: "close" },
|
||||
body,
|
||||
});
|
||||
assert.equal(foreign.status, 403);
|
||||
assert.equal((await getJson(s, "/notepad")).body.tabs[0].sent.workflow, "quick-task", "the refused calls changed nothing");
|
||||
});
|
||||
|
||||
test("pictures through ?tab=: upload, thumb, fetch and delete, each under the tab that holds it", async (t) => {
|
||||
const s = openSession();
|
||||
t.after(() => fs.rmSync(notepadFolder(ROOT), { recursive: true, force: true }));
|
||||
|
||||
@@ -12,7 +12,8 @@ import path from "node:path";
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { pageSuite, openSession, tempProject, textOf, styleOf } from "./page-test-helpers.mjs";
|
||||
import { cli, until, CONSOLE_CLI, HOME } from "./web-console-test-helpers.mjs";
|
||||
import { cli, until, CONSOLE_CLI, HOME, JPEG } from "./web-console-test-helpers.mjs";
|
||||
import { addImage, createTab, deleteTab, markTabSent, saveNote } from "../src/web-console/notepads.mjs";
|
||||
|
||||
const suite = pageSuite(test);
|
||||
|
||||
@@ -537,3 +538,140 @@ test("a quick-task build's waiting pane points at its Plan tab, and a plan sessi
|
||||
await otherPane.waitFor();
|
||||
assert.equal(await otherPane.getByRole("button", { name: "Plan", exact: true }).count(), 0, "a plan session has no live task list to point at");
|
||||
});
|
||||
|
||||
// A project with a drafted plan (demo), a documented spec (ready) and one
|
||||
// paused mid-build with a Plan change brief waiting (paused).
|
||||
const NOTE_PROJECT = {
|
||||
...DRAFT_PROJECT,
|
||||
"specs/ready/overview.md": "# Overview\n\n## Phase Checklist\n\n- [ ] Phase 1: One\n",
|
||||
"specs/ready/phase-1.md": "# Phase 1\n\n- [ ] **Task 1.1:** One\n",
|
||||
"specs/paused/overview.md": "# Overview\n\n## Phase Checklist\n\n- [/] Phase 1: One\n",
|
||||
"specs/paused/phase-1.md":
|
||||
"# Phase 1\n\n- [x] **Task 1.1:** One\n- [ ] **Task 1.2:** Two\n\n## Notes\n\n### Paused 2026-10-27\n**Plan change:** add a phase first\n",
|
||||
};
|
||||
|
||||
const noteSwitch = (main) => main.getByRole("checkbox", { name: "Start with a note from your Notebook" });
|
||||
|
||||
// Picks `chip` in the picker, opens `command`'s card and says whether its
|
||||
// confirm pane offers the switch; Back returns to the menu.
|
||||
async function offersNote(main, chip, command) {
|
||||
await chipFor(main, chip).click();
|
||||
await pickedChip(main, chip).waitFor();
|
||||
const card = lightOf(main, command);
|
||||
if (!(await card.isVisible()) || (await card.isDisabled())) return null;
|
||||
await card.click();
|
||||
await main.getByRole("button", { name: "Back" }).waitFor();
|
||||
const shows = (await noteSwitch(main).count()) === 1;
|
||||
await main.getByRole("button", { name: "Back" }).click();
|
||||
await main.getByRole("heading", { name: "What are we doing today?" }).waitFor();
|
||||
return shows;
|
||||
}
|
||||
|
||||
test("the Notebook switch shows on Start fresh for Pathfinder, Plan and Quick Task, and on Revise plan only with no brief waiting", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(NOTE_PROJECT) });
|
||||
const main = await toTheMenu(s);
|
||||
await hideUnavailable(main, false);
|
||||
for (const command of ["/plan2code-0-pathfinder", "/plan2code-1-plan", "/plan2code-quick-task"]) {
|
||||
assert.equal(await offersNote(main, "Start from scratch", command), true, `${command} on Start fresh`);
|
||||
}
|
||||
assert.equal(await offersNote(main, "demo", "/plan2code-1-plan"), false, "Plan on a picked spec");
|
||||
assert.equal(await offersNote(main, "ready", "/plan2code-1b-revise-plan"), true, "Revise plan with no brief waiting");
|
||||
assert.equal(await offersNote(main, "paused", "/plan2code-1b-revise-plan"), false, "Revise plan with a brief waiting");
|
||||
assert.equal(await offersNote(main, "ready", "/plan2code-3-implement"), false, "Implement never");
|
||||
assert.equal(await offersNote(main, "Start from scratch", "/plan2code-xray"), false, "a utility never");
|
||||
});
|
||||
|
||||
test("the switch lists the Notebook's tabs beside a preview: an empty tab grayed, five ticks at most, a Long tab note, and + note: on the command", async (t) => {
|
||||
const project = tempProject(DRAFT_PROJECT);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project });
|
||||
createTab(s.project, "Empty");
|
||||
const big = createTab(s.project, "Big").id;
|
||||
const small = createTab(s.project, "Small").id;
|
||||
saveNote(s.project, big, "# Big idea\n\n" + "x".repeat(52 * 1024));
|
||||
for (let i = 0; i < 7; i++) addImage(s.project, big, JPEG);
|
||||
saveNote(s.project, small, "A small **idea**.");
|
||||
markTabSent(s.project, small, { workflow: "plan" });
|
||||
|
||||
const main = await toTheMenu(s);
|
||||
await chipFor(main, "Start from scratch").click();
|
||||
await pickedChip(main, "Start from scratch").waitFor();
|
||||
await lightOf(main, "/plan2code-0-pathfinder").click();
|
||||
const toggle = noteSwitch(main);
|
||||
assert.equal(await toggle.isChecked(), false, "off by default");
|
||||
const cmd = main.locator(".confirm-cmd");
|
||||
assert.equal(await cmd.locator(".confirm-cmd-note").isHidden(), true);
|
||||
await toggle.check();
|
||||
|
||||
const tabs = main.locator(".confirm-note-tabs");
|
||||
await tabs.locator(".confirm-note-tab").nth(2).waitFor();
|
||||
const tab = (name) => tabs.locator(".confirm-note-tab", { has: s.page.locator(".confirm-note-tab-name", { hasText: new RegExp(`^${name}$`) }) });
|
||||
assert.equal(await tab("Empty").isDisabled(), true, "an empty tab cannot be picked");
|
||||
assert.ok(parseFloat(await styleOf(tab("Empty"), "opacity")) < 1, "and is grayed");
|
||||
assert.equal(await tab("Big").isEnabled(), true);
|
||||
assert.equal(await tab("Small").locator(".notepad-sent-badge").count(), 1, "a sent tab shows its badge");
|
||||
assert.equal(await tab("Big").locator(".notepad-sent-badge").count(), 0);
|
||||
|
||||
// Small: its text, rendered, and no Long tab note.
|
||||
await tab("Small").click();
|
||||
const preview = main.locator(".confirm-note-preview");
|
||||
await preview.locator("strong", { hasText: "idea" }).waitFor();
|
||||
assert.equal(await preview.locator(".confirm-note-long").count(), 0);
|
||||
assert.equal(await textOf(cmd.locator(".confirm-cmd-note")), "+ note: Small");
|
||||
|
||||
// Big: over 50 KB, seven pictures, the first five ticked.
|
||||
await tab("Big").click();
|
||||
await preview.locator(".md-h", { hasText: "Big idea" }).waitFor();
|
||||
assert.match(await textOf(preview.locator(".confirm-note-long")), /^Long tab: /);
|
||||
assert.equal(await textOf(cmd.locator(".confirm-cmd-note")), "+ note: Big");
|
||||
const ticks = preview.locator(".confirm-note-pic input[type=checkbox]");
|
||||
assert.equal(await ticks.count(), 7);
|
||||
const states = async () => ticks.evaluateAll((bs) => bs.map((b) => (b.checked ? "x" : b.disabled ? "-" : "o")).join(""));
|
||||
assert.equal(await states(), "xxxxx--", "the first five ticked, no more can be");
|
||||
await ticks.nth(1).uncheck();
|
||||
await until(async () => (await states()) === "xoxxxoo", 3000);
|
||||
await ticks.nth(6).check();
|
||||
await until(async () => (await states()) === "x-xxx-x", 3000);
|
||||
|
||||
// Off again: no note on the command line.
|
||||
await noteSwitch(main).uncheck();
|
||||
await until(async () => await cmd.locator(".confirm-cmd-note").isHidden(), 3000);
|
||||
assert.equal(await tabs.count(), 0);
|
||||
});
|
||||
|
||||
test("the switch reads the Notebook again when it closes, and starts off again after Back", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(DRAFT_PROJECT) });
|
||||
const keep = createTab(s.project, "Keep").id;
|
||||
const gone = createTab(s.project, "Gone").id;
|
||||
saveNote(s.project, keep, "first words");
|
||||
saveNote(s.project, gone, "soon deleted");
|
||||
|
||||
const main = await toTheMenu(s);
|
||||
await chipFor(main, "Start from scratch").click();
|
||||
await pickedChip(main, "Start from scratch").waitFor();
|
||||
await lightOf(main, "/plan2code-1-plan").click();
|
||||
await noteSwitch(main).check();
|
||||
const tabs = main.locator(".confirm-note-tabs");
|
||||
const tab = (name) => tabs.locator(".confirm-note-tab", { has: s.page.locator(".confirm-note-tab-name", { hasText: new RegExp(`^${name}$`) }) });
|
||||
await tab("Keep").click();
|
||||
const preview = main.locator(".confirm-note-preview");
|
||||
await preview.getByText("first words").waitFor();
|
||||
assert.equal(await preview.getAttribute("role"), "region");
|
||||
|
||||
// Changed in the Notebook while the pane is open: closing it reads again.
|
||||
saveNote(s.project, keep, "second words");
|
||||
deleteTab(s.project, gone);
|
||||
await s.page.click("#btn-notepad");
|
||||
await s.page.locator("#notepad-modal[open]").waitFor();
|
||||
await s.page.click("#notepad-close");
|
||||
await preview.getByText("second words").waitFor();
|
||||
await until(async () => (await tab("Gone").count()) === 0, 5000);
|
||||
assert.equal(await textOf(main.locator(".confirm-cmd-note")), "+ note: Keep", "the pick survives a read that still has its tab");
|
||||
|
||||
// Back, then the same card again: the switch is off and nothing is picked.
|
||||
await main.getByRole("button", { name: "Back" }).click();
|
||||
await main.getByRole("heading", { name: "What are we doing today?" }).waitFor();
|
||||
await lightOf(main, "/plan2code-1-plan").click();
|
||||
assert.equal(await noteSwitch(main).isChecked(), false);
|
||||
assert.equal(await main.locator(".confirm-cmd-note").isHidden(), true);
|
||||
assert.equal(await tabs.count(), 0);
|
||||
});
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
defaultTabId,
|
||||
deleteTab,
|
||||
listTabs,
|
||||
markTabSent,
|
||||
notepadFolder,
|
||||
notepadKey,
|
||||
readNotepad,
|
||||
@@ -1173,3 +1174,39 @@ test("Help's Getting around panel describes the notepad", async (t) => {
|
||||
assert.ok(text.includes(words), `the panel mentions ${words}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("a sent tab wears a badge after its name, and the open tab shows Sent to <Skill> · <Date>", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
const sent = createTab(s.project, "Sent one").id;
|
||||
createTab(s.project, "Plain");
|
||||
saveNoteTo(s.project, sent, "an idea");
|
||||
const { sent: record } = markTabSent(s.project, sent, { workflow: "revise-plan", spec: "specs/lunch-vote" });
|
||||
// The page draws its own short date; the line must carry the same one.
|
||||
const day = await s.page.evaluate((at) => new Date(at).toLocaleDateString(undefined, { month: "short", day: "numeric" }), record.at);
|
||||
const line = s.page.locator("#notepad-sent");
|
||||
|
||||
await openNotepad(s);
|
||||
// Plain was made last, so it opens first: no badge, no line.
|
||||
assert.equal(await selectedName(s).then((n) => n.join()), "Plain");
|
||||
assert.equal(await line.isHidden(), true, "no Sent to line on a tab never sent");
|
||||
const badges = s.page.locator("#notepad-tabs .notepad-sent-badge");
|
||||
assert.equal(await badges.count(), 1, "one badge, on the sent tab only");
|
||||
assert.equal(await badges.first().textContent(), "sent");
|
||||
const wrapOf = (name) => s.page.locator("#notepad-tabs .notepad-tabwrap").filter({ has: s.page.locator(".notepad-tab", { hasText: new RegExp(`^${name}$`) }) });
|
||||
assert.equal(await wrapOf("Sent one").locator(".notepad-sent-badge").count(), 1);
|
||||
assert.equal(await wrapOf("Plain").locator(".notepad-sent-badge").count(), 0);
|
||||
assert.equal(await tabNamed(s, "Sent one").getAttribute("aria-label"), "Sent one, sent");
|
||||
assert.equal(await tabNamed(s, "Plain").getAttribute("aria-label"), null);
|
||||
assert.ok(parseFloat(await styleOf(badges.first(), "font-size")) < 13, "the badge is small");
|
||||
|
||||
await tabNamed(s, "Sent one").click();
|
||||
assert.equal(await shows(s, "an idea"), "an idea");
|
||||
await line.waitFor({ state: "visible" });
|
||||
assert.equal(await line.textContent(), `Sent to Revise plan (lunch-vote) · ${day}`);
|
||||
// Under the editor and above the pictures.
|
||||
const order = await s.page.evaluate(() => [...document.getElementById("notepad-body").children].map((c) => c.id));
|
||||
assert.ok(order.indexOf("notepad-sent") === order.indexOf("notepad-editor") + 1 && order.indexOf("notepad-sent") < order.indexOf("notepad-images"), order.join(", "));
|
||||
|
||||
await tabNamed(s, "Plain").click();
|
||||
await line.waitFor({ state: "hidden" });
|
||||
});
|
||||
@@ -0,0 +1,253 @@
|
||||
// Page tests for starting a skill with a Notebook tab: the dashboard's confirm
|
||||
// pane picks a tab, Start launches, the launched skill's `fill: "note"` box
|
||||
// arrives filled with the tab's text and ticked pictures, and only the Send
|
||||
// of that box reaches the agent and marks the tab sent. Run with:
|
||||
// node --test scripts/test-web-console-page-send.mjs
|
||||
//
|
||||
// Each test drives the real console in a real Chrome or Edge through
|
||||
// scripts/page-test-helpers.mjs: one browser for the file, a fresh console
|
||||
// session per test.
|
||||
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { pageSuite, openSession, tempProject, drawn, sendAndCollect, itemCard } from "./page-test-helpers.mjs";
|
||||
import { cli, until, CONSOLE_CLI } from "./web-console-test-helpers.mjs";
|
||||
import { addImage, createTab, deleteTab, listTabs, readNotepad, removeImage, saveNote } from "../src/web-console/notepads.mjs";
|
||||
|
||||
const suite = pageSuite(test);
|
||||
|
||||
// Set up (AGENTS.md), with one documented spec for Revise plan to target.
|
||||
const PROJECT = {
|
||||
"AGENTS.md": "# AGENTS.md\n\nA small demo project.\n",
|
||||
"specs/ready/overview.md": "# Overview\n\n## Phase Checklist\n\n- [ ] Phase 1: One\n",
|
||||
"specs/ready/phase-1.md": "# Phase 1\n\n- [ ] **Task 1.1:** One\n",
|
||||
};
|
||||
|
||||
const MENU = { menu: { note: "Ready when you are." }, agent: { status: "waiting" } };
|
||||
|
||||
// Words no screen or file holds unless the tab put them there.
|
||||
const MARKER = "Lunch vote by emoji, idea 7Q2X";
|
||||
const TEXT = `# Lunch vote\n\n${MARKER}.\n`;
|
||||
|
||||
// A real JPEG drawn in the page, one color per call: the box re-encodes each
|
||||
// picture the way a pasted one is, so a stub that only looks like a JPEG
|
||||
// would never attach.
|
||||
const jpeg = async (s, color) =>
|
||||
Buffer.from(
|
||||
await s.page.evaluate(async (fill) => {
|
||||
const c = document.createElement("canvas");
|
||||
c.width = 160;
|
||||
c.height = 100;
|
||||
const ctx = c.getContext("2d");
|
||||
ctx.fillStyle = fill;
|
||||
ctx.fillRect(0, 0, 160, 100);
|
||||
const blob = await new Promise((resolve) => c.toBlob(resolve, "image/jpeg"));
|
||||
let bin = "";
|
||||
for (const b of new Uint8Array(await blob.arrayBuffer())) bin += String.fromCharCode(b);
|
||||
return btoa(bin);
|
||||
}, color),
|
||||
"base64"
|
||||
);
|
||||
|
||||
// A Notebook tab named `name` holding `text` and `pictures` real pictures.
|
||||
async function noteTab(s, name, text, pictures) {
|
||||
const id = createTab(s.project, name).id;
|
||||
if (text) saveNote(s.project, id, text);
|
||||
for (let i = 0; i < pictures; i++) addImage(s.project, id, await jpeg(s, `hsl(${i * 40}, 60%, 50%)`));
|
||||
return id;
|
||||
}
|
||||
|
||||
// Past Planny's wake-up and, on this console home's first run, the Welcome,
|
||||
// to the menu.
|
||||
async function toTheMenu(s) {
|
||||
const skip = s.page.getByRole("button", { name: "Skip the intro" });
|
||||
await skip.click();
|
||||
await skip.waitFor({ state: "hidden" });
|
||||
const main = s.page.locator("#main");
|
||||
await main.getByRole("heading", { name: "What are we doing today?" }).waitFor();
|
||||
const welcomeDone = s.page.getByRole("button", { name: "Start building" });
|
||||
if (await welcomeDone.isVisible()) {
|
||||
await welcomeDone.click();
|
||||
await welcomeDone.waitFor({ state: "hidden" });
|
||||
}
|
||||
return main;
|
||||
}
|
||||
|
||||
const chipFor = (main, name) => main.getByRole("button").filter({ hasText: new RegExp(`^${name}`) });
|
||||
const pickedChip = (main, name) => main.locator('button[aria-current="true"]', { hasText: new RegExp(`^${name}`) });
|
||||
const lightOf = (main, command) => main.getByRole("button").filter({ has: main.page().locator("code", { hasText: new RegExp(`^${command}$`) }) });
|
||||
|
||||
// Every file under the session folder that holds `words`.
|
||||
function filesHolding(dir, words) {
|
||||
const found = [];
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true, recursive: true })) {
|
||||
if (!entry.isFile()) continue;
|
||||
const file = path.join(entry.parentPath ?? entry.path, entry.name);
|
||||
if (fs.readFileSync(file).includes(words)) found.push(path.relative(dir, file));
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
const sentOf = (project, tab) => (listTabs(project).tabs.find((t) => t.id === tab) || {}).sent || null;
|
||||
|
||||
// From the menu: picks `chip`, opens `command`'s card, switches the Notebook
|
||||
// on, picks `tabName` and presses Start; then collects the launch and runs its
|
||||
// resume, as the dashboard agent does. Returns the launch send.
|
||||
async function startWith(s, main, { chip, command, tabName }) {
|
||||
await chipFor(main, chip).click();
|
||||
await pickedChip(main, chip).waitFor();
|
||||
await lightOf(main, command).click();
|
||||
await main.getByRole("checkbox", { name: "Start with a note from your Notebook" }).check();
|
||||
const tab = main.locator(".confirm-note-tab", { has: s.page.locator(".confirm-note-tab-name", { hasText: new RegExp(`^${tabName}$`) }) });
|
||||
await tab.click();
|
||||
await main.locator(".confirm-cmd-note", { hasText: `+ note: ${tabName}` }).waitFor();
|
||||
await main.locator(".confirm-actions .btn.primary").click();
|
||||
const got = s.wait(10);
|
||||
assert.equal(got.code, 0, `nothing was sent (wait exit ${got.code}): ${got.message || ""}`);
|
||||
const head = `node "${CONSOLE_CLI}" `;
|
||||
assert.ok(got.resume.startsWith(head), `resume runs this console: ${got.resume}`);
|
||||
const r = cli(got.resume.slice(head.length).split(" "), { cwd: s.project });
|
||||
assert.equal(r.status, 0, `resume failed: ${r.stderr}`);
|
||||
return got;
|
||||
}
|
||||
|
||||
// The launched skill's first card: the box the page fills.
|
||||
const BOX = { items: [{ id: "idea", kind: "text", title: "What should change", body: "Say it in your own words.", fill: "note" }] };
|
||||
|
||||
const boxOf = (s) => s.page.locator("#text-idea");
|
||||
const readyPictures = (s) => itemCard(s.page, "idea").locator(".attach-thumb.is-ready");
|
||||
|
||||
const CASES = [
|
||||
{ workflow: "pathfinder", chip: "Start from scratch", command: "/plan2code-0-pathfinder" },
|
||||
{ workflow: "plan", chip: "Start from scratch", command: "/plan2code-1-plan" },
|
||||
{ workflow: "quick-task", chip: "Start from scratch", command: "/plan2code-quick-task" },
|
||||
{ workflow: "revise-plan", chip: "ready", command: "/plan2code-1b-revise-plan", spec: "specs/ready" },
|
||||
];
|
||||
|
||||
for (const c of CASES) {
|
||||
test(`${c.workflow}: the box arrives with the tab's text and five pictures, the agent reads it only on Send, and only then is the tab marked sent`, async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(PROJECT) });
|
||||
const tab = await noteTab(s, "Idea", TEXT, 7);
|
||||
const main = await toTheMenu(s);
|
||||
const launch = await startWith(s, main, { chip: c.chip, command: c.command, tabName: "Idea" });
|
||||
|
||||
// Nothing of the tab rides the launch, and nothing of it is in the session.
|
||||
assert.ok(!JSON.stringify(launch).includes(MARKER), "the launch send carries no tab text");
|
||||
assert.deepEqual(filesHolding(s.session, MARKER), [], "no session file holds the tab's text after Start");
|
||||
assert.equal(sentOf(s.project, tab), null, "Start alone marks nothing");
|
||||
|
||||
s.post(BOX);
|
||||
await until(async () => (await boxOf(s).inputValue()) === TEXT, 10000);
|
||||
await until(async () => (await readyPictures(s).count()) === 5, 15000);
|
||||
assert.equal(await boxOf(s).isEditable(), true, "the filled box stays editable");
|
||||
|
||||
// Still nothing for the agent before Send.
|
||||
const result = path.join(s.session, "result.json");
|
||||
assert.ok(!fs.existsSync(result) || !fs.readFileSync(result, "utf8").includes(MARKER), "result.json holds no tab text before Send");
|
||||
assert.equal(s.wait(1).code, 10, "the agent has nothing to collect before Send");
|
||||
assert.equal(sentOf(s.project, tab), null);
|
||||
|
||||
const got = await sendAndCollect(s);
|
||||
assert.ok(got.reply.includes(MARKER), `the send carries the box: ${got.reply}`);
|
||||
const note = got.actions.find((a) => a.i === "idea" && a.type === "comment");
|
||||
assert.equal(note && note.images.length, 5, "the five pictures go with it");
|
||||
await until(() => sentOf(s.project, tab) !== null, 5000);
|
||||
const sent = sentOf(s.project, tab);
|
||||
assert.equal(sent.workflow, c.workflow);
|
||||
assert.equal(sent.spec, c.spec);
|
||||
});
|
||||
}
|
||||
|
||||
test("a pictures-only tab arrives as an empty box with its pictures, and its Send marks the tab sent", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(PROJECT) });
|
||||
const tab = await noteTab(s, "Shots", "", 2);
|
||||
const main = await toTheMenu(s);
|
||||
await startWith(s, main, { chip: "Start from scratch", command: "/plan2code-1-plan", tabName: "Shots" });
|
||||
s.post(BOX);
|
||||
await until(async () => (await readyPictures(s).count()) === 2, 15000);
|
||||
assert.equal(await boxOf(s).inputValue(), "");
|
||||
const got = await sendAndCollect(s);
|
||||
const note = got.actions.find((a) => a.i === "idea" && a.type === "comment");
|
||||
assert.equal(note && note.images.length, 2, "the pictures go on their own");
|
||||
await until(() => sentOf(s.project, tab) !== null, 5000);
|
||||
assert.equal(sentOf(s.project, tab).workflow, "plan");
|
||||
});
|
||||
|
||||
test("a picture deleted between Start and the box is skipped, and the rest still attach", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(PROJECT) });
|
||||
const tab = await noteTab(s, "Idea", TEXT, 3);
|
||||
const main = await toTheMenu(s);
|
||||
await startWith(s, main, { chip: "Start from scratch", command: "/plan2code-1-plan", tabName: "Idea" });
|
||||
const first = readNotepad(s.project, tab).images[0].id;
|
||||
removeImage(s.project, tab, first);
|
||||
s.post(BOX);
|
||||
await until(async () => (await boxOf(s).inputValue()) === TEXT, 10000);
|
||||
await until(async () => (await readyPictures(s).count()) === 2, 15000);
|
||||
assert.equal(await itemCard(s.page, "idea").locator(".attach-thumb").count(), 2, "no failed or empty slot for the missing one");
|
||||
});
|
||||
|
||||
test("Back to the dashboard after the box fills takes the box with it, as its dialog says, and marks the tab sent", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(PROJECT) });
|
||||
const tab = await noteTab(s, "Idea", TEXT, 0);
|
||||
const main = await toTheMenu(s);
|
||||
await startWith(s, main, { chip: "Start from scratch", command: "/plan2code-0-pathfinder", tabName: "Idea" });
|
||||
s.post(BOX);
|
||||
await until(async () => (await boxOf(s).inputValue()) === TEXT, 10000);
|
||||
await s.page.click("#btn-home");
|
||||
await s.page.locator("#home-modal[open]").waitFor();
|
||||
await s.page.click("#home-go");
|
||||
const got = s.wait(10);
|
||||
assert.equal(got.code, 0, `nothing was sent (wait exit ${got.code})`);
|
||||
assert.ok(got.actions.some((a) => a.i === "__dashboard"), "the send goes home");
|
||||
assert.ok(got.reply.includes(MARKER), "and carries the filled box");
|
||||
await until(() => sentOf(s.project, tab) !== null, 5000);
|
||||
});
|
||||
|
||||
test("the box is filled once: a redraw or a reload keeps what the person typed, and the pictures are not added again", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(PROJECT) });
|
||||
await noteTab(s, "Idea", TEXT, 3);
|
||||
const main = await toTheMenu(s);
|
||||
await startWith(s, main, { chip: "Start from scratch", command: "/plan2code-0-pathfinder", tabName: "Idea" });
|
||||
s.post(BOX);
|
||||
await until(async () => (await readyPictures(s).count()) === 3, 15000);
|
||||
await boxOf(s).fill("My own words now.");
|
||||
|
||||
s.post({ agent: { status: "waiting", activity: "Still here" } });
|
||||
await s.page.reload({ waitUntil: "domcontentloaded" });
|
||||
await drawn(s.page);
|
||||
await boxOf(s).waitFor();
|
||||
assert.equal(await boxOf(s).inputValue(), "My own words now.");
|
||||
await until(async () => (await readyPictures(s).count()) === 3, 5000);
|
||||
// A second marked box later in the session is left alone.
|
||||
s.post({ items: [{ id: "idea2", kind: "text", title: "Anything else", fill: "note" }] });
|
||||
await s.page.locator("#text-idea2").waitFor();
|
||||
assert.equal(await s.page.locator("#text-idea2").inputValue(), "");
|
||||
});
|
||||
|
||||
test("a launch that goes back to the dashboard before Send marks nothing", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(PROJECT) });
|
||||
const tab = await noteTab(s, "Idea", TEXT, 1);
|
||||
const main = await toTheMenu(s);
|
||||
await startWith(s, main, { chip: "Start from scratch", command: "/plan2code-quick-task", tabName: "Idea" });
|
||||
s.post(BOX);
|
||||
await until(async () => (await boxOf(s).inputValue()) === TEXT, 10000);
|
||||
const r = cli(["open", "--resume", s.sid, "--no-open", "--workflow", "dashboard"], { cwd: s.project });
|
||||
assert.equal(r.status, 0, `resume failed: ${r.stderr}`);
|
||||
s.post(MENU);
|
||||
await main.getByRole("heading", { name: "What are we doing today?" }).waitFor();
|
||||
assert.equal(sentOf(s.project, tab), null);
|
||||
});
|
||||
|
||||
test("a tab deleted between Start and the box leaves the box empty, with a banner", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(PROJECT) });
|
||||
const tab = await noteTab(s, "Idea", TEXT, 1);
|
||||
const main = await toTheMenu(s);
|
||||
await startWith(s, main, { chip: "Start from scratch", command: "/plan2code-1-plan", tabName: "Idea" });
|
||||
deleteTab(s.project, tab);
|
||||
s.post(BOX);
|
||||
await s.page.locator("#banner", { hasText: "That Notebook tab is gone; the box starts empty." }).waitFor();
|
||||
assert.equal(await boxOf(s).inputValue(), "");
|
||||
assert.equal(await readyPictures(s).count(), 0);
|
||||
});
|
||||
@@ -187,7 +187,7 @@ const ROUTE_ORDER = [
|
||||
"/health", "/s/", "/", "SERVABLE", "/overview", "/handoff", "/version", "/state", "/events", "/draft",
|
||||
"/looks", "/looks", "/subagents", "/pr-host", "/models", "/models", "/agents", "/agents", "/agents/test", "/cleanup", "/upload",
|
||||
"/notepad", "/notepad/text", "/notepad/image", "/notepad/thumb", "/notepad/image/delete", "/notepad/tab",
|
||||
"/notepad/tab/rename", "/notepad/tab/delete", "/notepad/tab/order", "/notepad/tab/last", "/notepad/images/",
|
||||
"/notepad/tab/rename", "/notepad/tab/delete", "/notepad/tab/order", "/notepad/tab/last", "/notepad/tab/sent", "/notepad/images/",
|
||||
"/attachments/", "/shots/", "/uploads/", "/submit", "/open-link", "/chat", "/chat/decision", "/workspace",
|
||||
"WORKSPACE_EDITS", "/workspace/scope", "/workspace/browse", "/cancel", "/ping", "/bye",
|
||||
];
|
||||
|
||||
@@ -442,6 +442,46 @@ test("the scan: an assumed task counts as done and is named, and numbered task l
|
||||
}
|
||||
});
|
||||
|
||||
test("the scan: planChange is true for a waiting Plan change brief, and absent once it is applied or dropped", () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-spec-brief-"));
|
||||
const notes = (line) => "# Phase 1\n\n- [x] **Task 1.1:** One\n- [ ] **Task 1.2:** Two\n\n## Notes\n\n### Paused 2026-10-27\n" + line + "\n\n## Phase Completion Summary\n";
|
||||
const checklist = (mark) => `# Overview\n\n## Phase Checklist\n\n- [${mark}] Phase 1: One\n- [ ] Phase 2: Two\n`;
|
||||
const specs = {
|
||||
waiting: { "overview.md": checklist("/"), "phase-1.md": notes("**Plan change:** add a phase first"), "phase-2.md": PHASE([false]) },
|
||||
applied: { "overview.md": checklist("/"), "phase-1.md": notes("**Plan change (applied 2026-10-27):** add a phase first"), "phase-2.md": PHASE([false]) },
|
||||
dropped: { "overview.md": checklist("/"), "phase-1.md": notes("**Plan change (dropped 2026-10-27):** add a phase first"), "phase-2.md": PHASE([false]) },
|
||||
// No phase marked [/]: every phase file is read.
|
||||
unmarked: { "overview.md": checklist(" "), "phase-1.md": PHASE([false]), "phase-2.md": notes("**Plan change:** rename a task") },
|
||||
// A brief in a phase that is not the one in progress is not waiting on it.
|
||||
otherPhase: { "overview.md": checklist("/"), "phase-1.md": notes("Nothing to change."), "phase-2.md": notes("**Plan change:** later") },
|
||||
// Outside the Notes section it is only prose.
|
||||
notInNotes: { "overview.md": checklist("/"), "phase-1.md": "# Phase 1\n\n**Plan change:** quoted in the overview\n\n- [ ] **Task 1.1:** One\n", "phase-2.md": PHASE([false]) },
|
||||
built: { "overview.md": checklist("x"), "phase-1.md": notes("**Plan change:** found in the last checks").replace("- [ ] **Task 1.2:**", "- [x] **Task 1.2:**"), "phase-2.md": PHASE([true]) },
|
||||
planned: { "PLAN-DRAFT-20261027.md": "# Plan draft\n\n**Status:** Draft\n\n## Notes\n\n**Plan change:** not a phased spec\n" },
|
||||
};
|
||||
try {
|
||||
for (const [name, files] of Object.entries(specs))
|
||||
for (const [rel, text] of Object.entries(files)) {
|
||||
fs.mkdirSync(path.join(root, "specs", name), { recursive: true });
|
||||
fs.writeFileSync(path.join(root, "specs", name, rel), text);
|
||||
}
|
||||
const by = Object.fromEntries(scanProject(root).specs.map((sp) => [sp.name, sp]));
|
||||
assert.equal(by.waiting.planChange, true);
|
||||
assert.equal(by.waiting.state, "building");
|
||||
assert.equal("planChange" in by.applied, false);
|
||||
assert.equal("planChange" in by.dropped, false);
|
||||
assert.equal(by.unmarked.planChange, true);
|
||||
assert.equal(by.unmarked.state, "building");
|
||||
assert.equal("planChange" in by.otherPhase, false);
|
||||
assert.equal("planChange" in by.notInNotes, false);
|
||||
assert.equal(by.built.state, "built");
|
||||
assert.equal(by.built.planChange, true, "a built spec can still have a brief waiting");
|
||||
assert.equal("planChange" in by.planned, false);
|
||||
} finally {
|
||||
fs.rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
// The states no card names in its `states` list: a card that is on for "any"
|
||||
// spec does not count, since it would take a state nobody thought about. A
|
||||
// finished state is taken by no card on purpose.
|
||||
|
||||
@@ -22,6 +22,8 @@ test("state: page starts as app.js always started it", () => {
|
||||
homeward: null,
|
||||
launching: null,
|
||||
deleting: null,
|
||||
noteSend: null,
|
||||
noteSent: null,
|
||||
retract: {},
|
||||
chat: { draft: "", history: [], about: null, pending: [], lastSeenReplyId: null, images: [], conversation: null },
|
||||
});
|
||||
|
||||
@@ -320,6 +320,11 @@ An option is `{ "k": "A", "text": "short label", "detail": "the trade-off", "rec
|
||||
it, with a one-line summary in `placeholder`. A resumed map, PLAN-DRAFT or
|
||||
checkpoint gets no idea card. Only the box's text comes back; never mention
|
||||
templates in the terminal.
|
||||
- **Fill from a Notebook tab:** on a `text` item, `"fill": "note"` (its only
|
||||
value; any other kind or value is exit 3) has the page fill the first open one
|
||||
once, with the tab's text and ticked pictures, when the person started from a
|
||||
Notebook tab. You read it only when they send that box (Send, or Stop or
|
||||
Back to the dashboard, which carry ready answers).
|
||||
- **Recommend only when you genuinely know better and can say why.** "Which
|
||||
format survives Excel?" is yours; "Who is this for?" is not — there a
|
||||
recommendation is an anchor people rubber-stamp. At most one per question.
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
//
|
||||
// ~/.plan2code/notepads/<folder-name>-<12 hex>/
|
||||
// meta.json { v: 2, folder, created }
|
||||
// tabs.json { v: 1, order: [id], last: id|null, tabs: { id: { name, created } } }
|
||||
// tabs/<id>/note.md the tab's text, UTF-8, written atomically
|
||||
// tabs.json { v: 1, order: [id], last: id|null, tabs: { id: { name, created, sent? } } }
|
||||
// tabs/<id>/note.md the tab's text, UTF-8, written atomically
|
||||
// tabs/<id>/images/<uuid>.jpg a picture, JPEG from the page
|
||||
// tabs/<id>/images/<uuid>.thumb.jpg its thumbnail, when the page sent one
|
||||
//
|
||||
@@ -17,7 +17,8 @@
|
||||
//
|
||||
// This module is the only code that names, reads, writes, lists and removes
|
||||
// them. The page reaches it through the /notepad routes; the agent CLI never
|
||||
// imports it, so nothing in a notepad can reach the agent. Reading never
|
||||
// imports it, so a tab leaves it only through a send the person starts on the
|
||||
// dashboard (a test checks the imports). Reading never
|
||||
// creates or touches a file, so only a person's own edits age a notepad.
|
||||
// PLAN2CODE_NOTEPADS_DIR moves the folder, for tests.
|
||||
//
|
||||
@@ -48,7 +49,7 @@ export const LEGACY_TAB_ID = "0000000000a1";
|
||||
|
||||
// A refusal the routes turn into `{ error: code }` with this status. Codes:
|
||||
// bad, too-long, too-many, not-jpeg, not-found, and for tabs bad-name (400),
|
||||
// duplicate-name (409), too-many-tabs (409), no-such-tab (404).
|
||||
// bad-sent (400), duplicate-name (409), too-many-tabs (409), no-such-tab (404).
|
||||
export class NotepadError extends Error {
|
||||
constructor(code, status) {
|
||||
super(code);
|
||||
@@ -111,8 +112,21 @@ const isFile = (p) => {
|
||||
}
|
||||
};
|
||||
|
||||
// `{ order, last, tabs: { id: { name, created } } }` from tabs.json with every
|
||||
// part of its shape checked, or null when it is missing or does not hold up.
|
||||
// The workflows a tab can be sent to from the dashboard, and the spec a Revise
|
||||
// plan send names.
|
||||
export const SENT_WORKFLOWS = ["pathfinder", "plan", "quick-task", "revise-plan"];
|
||||
const SENT_SPEC_RE = /^specs\/[A-Za-z0-9._-]+$/;
|
||||
|
||||
// A tab's `sent` record as stored, or null when it does not hold up.
|
||||
function readSent(sent) {
|
||||
if (!sent || typeof sent !== "object" || !SENT_WORKFLOWS.includes(sent.workflow) || typeof sent.at !== "string") return null;
|
||||
if (sent.spec !== undefined && !(typeof sent.spec === "string" && SENT_SPEC_RE.test(sent.spec))) return null;
|
||||
return { workflow: sent.workflow, ...(sent.spec ? { spec: sent.spec } : {}), at: sent.at };
|
||||
}
|
||||
|
||||
// `{ order, last, tabs: { id: { name, created, sent? } } }` from tabs.json with
|
||||
// every part of its shape checked, or null when it is missing or does not hold
|
||||
// up. A `sent` record that does not hold up is dropped, never the whole index.
|
||||
function readIndex(dir) {
|
||||
const raw = readJson(path.join(dir, INDEX_FILE));
|
||||
if (!raw || typeof raw !== "object" || !Array.isArray(raw.order)) return null;
|
||||
@@ -125,6 +139,8 @@ function readIndex(dir) {
|
||||
if (!t || typeof t !== "object") return null;
|
||||
try {
|
||||
tabs[id] = { name: normalizeTabName(t.name), created: typeof t.created === "string" ? t.created : null };
|
||||
const sent = readSent(t.sent);
|
||||
if (sent) tabs[id].sent = sent;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
@@ -333,14 +349,18 @@ function imageEntries(dirs) {
|
||||
const imageUrl = (tab, id, thumb) => "/notepad/images/" + tab + "/" + id + (thumb ? ".thumb" : "") + ".jpg";
|
||||
|
||||
/**
|
||||
* The tabs, as `[{ id, name }]` in order, and the one last used. Read only; a
|
||||
* notepad still in the first shape answers one virtual tab, Notes.
|
||||
* The tabs, as `[{ id, name, sent? }]` in order (`sent` only on a tab sent
|
||||
* from the dashboard), and the one last used. Read only; a notepad still in
|
||||
* the first shape answers one virtual tab, Notes, never sent.
|
||||
*/
|
||||
export function listTabs(folder) {
|
||||
const dir = notepadFolder(folder);
|
||||
if (!fs.existsSync(dir)) return { tabs: [], last: null };
|
||||
const index = readIndex(dir);
|
||||
if (index) return { tabs: index.order.map((id) => ({ id, name: index.tabs[id].name })), last: index.last };
|
||||
if (index) {
|
||||
const tabs = index.order.map((id) => ({ id, name: index.tabs[id].name, ...(index.tabs[id].sent ? { sent: index.tabs[id].sent } : {}) }));
|
||||
return { tabs, last: index.last };
|
||||
}
|
||||
if (legacyShape(dir)) return { tabs: [{ id: LEGACY_TAB_ID, name: "Notes" }], last: LEGACY_TAB_ID };
|
||||
return { tabs: [], last: null };
|
||||
}
|
||||
@@ -353,7 +373,8 @@ export function defaultTabId(folder) {
|
||||
|
||||
/**
|
||||
* What the page shows:
|
||||
* `{ tabs: [{ id, name }], last, tab: { id, text, savedAt, images } | null }`
|
||||
* `{ tabs: [{ id, name, sent? }], last, tab: { id, text, savedAt, images } | null }`
|
||||
* (`sent` is `{ workflow, spec?, at }`, the tab's last send from the dashboard)
|
||||
* for the tab asked for (else the default one), plus that tab's `text`,
|
||||
* `savedAt` and `images` at the top, where the first page read them. A named
|
||||
* tab that does not exist is a `no-such-tab` refusal. Never creates or writes
|
||||
@@ -426,6 +447,26 @@ export function renameTab(folder, id, name) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Record that a tab was sent to a workflow from the dashboard, replacing any
|
||||
* earlier record. `workflow` is one of SENT_WORKFLOWS and `spec`, when given,
|
||||
* a `specs/<name>` path. Resolves to `{ id, sent }`.
|
||||
*/
|
||||
export function markTabSent(folder, tab, { workflow, spec } = {}) {
|
||||
requireTab(folder, tab);
|
||||
return withNotepad(folder, (dir, index) => {
|
||||
if (!Object.hasOwn(index.tabs, tab)) throw new NotepadError("no-such-tab", 404);
|
||||
if (!SENT_WORKFLOWS.includes(workflow)) throw new NotepadError("bad-sent", 400);
|
||||
if (spec !== undefined && spec !== null && !(typeof spec === "string" && SENT_SPEC_RE.test(spec))) {
|
||||
throw new NotepadError("bad-sent", 400);
|
||||
}
|
||||
const sent = { workflow, ...(spec ? { spec } : {}), at: nowIso() };
|
||||
index.tabs[tab].sent = sent;
|
||||
commit(dir, index);
|
||||
return { id: tab, sent };
|
||||
});
|
||||
}
|
||||
|
||||
/** Remember which tab was open last. */
|
||||
export function setLastTab(folder, id) {
|
||||
requireTab(folder, id);
|
||||
|
||||
@@ -7,7 +7,7 @@ Workflow notes for `pathfinder`, part of the web console contract (`console.md`)
|
||||
once it does, and `"specDir": "specs/<idea>"` when the folder is created
|
||||
(`console-stop.md` → Saying what stopping would cost).
|
||||
- The menu after a decision is a `menu` card: its `options` are `trail --form C`'s, and the `Start fresh` one keeps its `"fresh": true` (the page words it "Start New Session" under the desktop app and asks the app for one on Send). Set the card's `command` to the resume command printed under `OR START FRESH`: the page copies it first. A declined confirm leaves you the pick: carry on as for any `Start fresh`.
|
||||
- The fresh-idea card carries `"templates": "idea"` (`console.md` → The kinds).
|
||||
- The fresh-idea card carries `"templates": "idea"` and `"fill": "note"` (`console.md` → The kinds): the page fills that box from a Notebook tab when the person started with one.
|
||||
- A doc that is a file exactly as written (the map once it is on disk, a
|
||||
brief) goes up as a `file` block (`{ "id": "body", "file":
|
||||
"specs/<idea>/pathfinder/map.md" }`) rather than pasted. Keep `md` blocks
|
||||
|
||||
@@ -4,7 +4,7 @@ Workflow notes for `plan`, part of the web console contract (`console.md`).
|
||||
|
||||
- Open with `--workflow plan`, first thing. Every question and sign-off gate
|
||||
goes through the page, phase breakdowns as an editable `list`.
|
||||
- The fresh-idea card carries `"templates": "idea"` (`console.md` → The kinds).
|
||||
- The fresh-idea card carries `"templates": "idea"` and `"fill": "note"` (`console.md` → The kinds): the page fills that box from a Notebook tab when the person started with one.
|
||||
- Planning has no mid-session save before the Large checkpoint or Phase 7, so for
|
||||
a stop before then say plainly in `finish.body` that nothing was kept, and use
|
||||
`"command": "/plan2code-1-plan"`. After the checkpoint, post
|
||||
|
||||
@@ -7,7 +7,7 @@ Workflow notes for `quick-task`, part of the web console contract
|
||||
|
||||
- Open with the first clarifying question. Clarifying questions go out as
|
||||
`text` or `choice`, at most three at a time. The first, asking what to build,
|
||||
carries `"templates": "idea"` (`console.md` → The kinds).
|
||||
carries `"templates": "idea"` and `"fill": "note"` (`console.md` → The kinds): the page fills that box from a Notebook tab when the person started with one.
|
||||
- Post `"stopWarning": "A quick task saves nothing until it is built, so stopping now loses what we have worked out."`
|
||||
at the start, and `"stopWarning": ""` once the build is under way.
|
||||
- **Scope check:** a `choice`, "Too big for a quick task?", options
|
||||
|
||||
@@ -6,7 +6,7 @@ Revision is a short run of gates, and each maps onto a kind you already know:
|
||||
|
||||
| Step | On the page |
|
||||
| --- | --- |
|
||||
| 1, Change Analysis | A `recap` item, "Is this the change?", with the affected-areas table in `summary`. Found a waiting `**Plan change:**` brief? Quote it at the top of that `summary` and post no open "what should change" card first. |
|
||||
| 1, Change Analysis | A `recap` item, "Is this the change?", with the affected-areas table in `summary`. Found a waiting `**Plan change:**` brief? Quote it at the top of that `summary` and post no open "what should change" card first. With none waiting, the first card is a `text` item titled "What should change", `"fill": "note"`, asking what to change; its answer feeds the "Is this the change?" recap. |
|
||||
| 2, Impact Assessment | The Revision Impact Summary as a doc (`id: "impact"`), and a `review` item "Approve the spec changes" pointing at it: verdicts `approve` ("Approve these spec changes"), `refine` ("Refine the plan") and `abort` ("Abort", `"danger": true`), `nothingYet`: "No spec file changes until you approve." |
|
||||
| 3 to 5 | Nothing to ask. Post `activity` while you edit, then the Revision Complete summary as a doc. |
|
||||
| 6, Cleanup | A `confirm` per rename or removal, the paths in `consequences`. |
|
||||
|
||||
@@ -648,6 +648,10 @@ export function validate(state) {
|
||||
if (item.templates != null && (item.kind !== "text" || item.templates !== "idea")) {
|
||||
problems.push(`item "${item.id}" has "templates": only a text item can carry it, and its only value is "idea".`);
|
||||
}
|
||||
// The box the page fills from a Notebook tab picked at Start.
|
||||
if (item.fill != null && (item.kind !== "text" || item.fill !== "note")) {
|
||||
problems.push(`item "${item.id}" has "fill": only a text item can carry it, and its only value is "note".`);
|
||||
}
|
||||
// The page compiles it as the person types, and a pattern that does not
|
||||
// compile throws there, on every keystroke, with nothing on screen to say why.
|
||||
if (item.pattern != null) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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. -->
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -54,6 +54,7 @@ import {
|
||||
defaultTabId,
|
||||
deleteTab,
|
||||
imagePath,
|
||||
markTabSent,
|
||||
readNotepad,
|
||||
removeImage,
|
||||
renameTab,
|
||||
@@ -101,6 +102,7 @@ const ROUTES = [
|
||||
{ path: "/notepad/tab/delete", method: "POST", origin: true, run: notepadTabDelete },
|
||||
{ path: "/notepad/tab/order", method: "POST", origin: true, run: notepadTabOrder },
|
||||
{ path: "/notepad/tab/last", method: "POST", origin: true, run: notepadTabLast },
|
||||
{ path: "/notepad/tab/sent", method: "POST", origin: true, run: notepadTabSent },
|
||||
{ match: (p, req) => p.startsWith("/notepad/images/") || req.url.startsWith("/notepad/images/"), method: "GET", run: notepadImageGet },
|
||||
{ match: (p, req) => p.startsWith("/attachments/") || req.url.startsWith("/attachments/"), run: attachment },
|
||||
{ match: (p, req) => p.startsWith("/shots/") || req.url.startsWith("/shots/"), run: shot },
|
||||
@@ -652,7 +654,8 @@ function cleanup(req, res, ctx) {
|
||||
|
||||
// The person's private notepad for the folder this session runs in, kept by
|
||||
// notepads.mjs outside the session. Nothing here writes to ctx.dir or the
|
||||
// event log: the agent reads both, and the notepad is never the agent's.
|
||||
// event log: the agent reads both, and the agent CLI never imports the store.
|
||||
// A tab leaves it only through a send the person starts on the dashboard.
|
||||
const notepadRoot = (ctx) => ctx.worktree() || ctx.project;
|
||||
|
||||
function notepadFail(res, e) {
|
||||
@@ -766,6 +769,9 @@ function notepadTabOrder(req, res, ctx) {
|
||||
function notepadTabLast(req, res, ctx) {
|
||||
return notepadTabRoute((root, body) => setLastTab(root, body.id))(req, res, ctx);
|
||||
}
|
||||
function notepadTabSent(req, res, ctx) {
|
||||
return notepadTabRoute((root, body) => markTabSent(root, body.id, { workflow: body.workflow, spec: body.spec }))(req, res, ctx);
|
||||
}
|
||||
|
||||
// Matched on the raw request line too, as /uploads/ is: URL parsing folds
|
||||
// `..` away, and nothing that needed folding is a notepad picture.
|
||||
|
||||
@@ -58,6 +58,29 @@ function maxMtime(dir, depth = 4, budget = { n: 400 }, tally = null) {
|
||||
return best;
|
||||
}
|
||||
|
||||
// A waiting Revise plan brief: a `**Plan change:**` line in a phase file's
|
||||
// Notes. Applied or dropped, it reads `**Plan change (applied <date>):**` or
|
||||
// `(dropped <date>)`, which this never matches.
|
||||
const PLAN_CHANGE_RE = /^\s*\*\*Plan change:\*\*/m;
|
||||
|
||||
// The Notes section of a phase file: from its `## Notes` heading to the next
|
||||
// `## ` heading, or "" when it has none.
|
||||
function notesOf(text) {
|
||||
const at = text.search(/^## Notes\b/m);
|
||||
if (at < 0) return "";
|
||||
const rest = text.slice(at).replace(/^## Notes[^\n]*\n?/, "");
|
||||
const end = rest.search(/^## /m);
|
||||
return end < 0 ? rest : rest.slice(0, end);
|
||||
}
|
||||
|
||||
// Whether a phased spec has a brief waiting for Revise plan: in the phase file
|
||||
// overview.md marks `[/]`, or in each phase file when none is marked.
|
||||
function planChangeWaiting(dir, phases) {
|
||||
const marked = [...readText(path.join(dir, "overview.md")).matchAll(/^\s*-\s*\[\/\]\s*Phase\s+(\d+)\b/gim)].map((m) => Number(m[1]));
|
||||
const files = marked.length ? phases.filter((f) => marked.includes(Number((f.match(/^phase-0*(\d+)\.md$/i) || [])[1]))) : phases;
|
||||
return files.some((f) => PLAN_CHANGE_RE.test(notesOf(readText(path.join(dir, f)))));
|
||||
}
|
||||
|
||||
// A spec folder's pipeline position, from its files alone. Furthest artifact
|
||||
// wins: an overview beats a draft beats a map, so a spec mid-way through two
|
||||
// stages reports the later one.
|
||||
@@ -89,11 +112,15 @@ function classifySpec(dir, names) {
|
||||
const finished = done + assumed;
|
||||
const total = finished + open;
|
||||
const suffix = assumed > 0 ? `, ${assumed} assumed` : "";
|
||||
if (open === 0 && finished > 0) return { state: "built", detail: `all tasks done${suffix}` };
|
||||
if (finished > 0) return { state: "building", detail: `${finished} of ${total} tasks done${suffix}` };
|
||||
// Documented, building and built specs all land here: each says whether a
|
||||
// Revise plan brief is waiting, and only when one is.
|
||||
const brief = planChangeWaiting(dir, phases) ? { planChange: true } : {};
|
||||
if (open === 0 && finished > 0) return { state: "built", detail: `all tasks done${suffix}`, ...brief };
|
||||
if (finished > 0) return { state: "building", detail: `${finished} of ${total} tasks done${suffix}`, ...brief };
|
||||
return {
|
||||
state: "documented",
|
||||
detail: `${phases.length} phase${phases.length === 1 ? "" : "s"}, ${total || "?"} tasks ready`,
|
||||
...brief,
|
||||
};
|
||||
}
|
||||
// An overview with no phase files means Document was interrupted mid-write;
|
||||
|
||||
Reference in new issue
Block a user