mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
Add Diagnose and X-ray, shared building habits, fresh-helper reviews, and a Bug fixed spec state
AI Assisted
This commit is contained in:
1 parent
80ae3decdd
commit
33a0dbd34a
58 files changed
+3270
-236
No files matched your search
@@ -51,6 +51,9 @@ for whichever comes first:
|
||||
session (files created or modified by the phase or the quick task, plus the
|
||||
tests and docs changed for it). Do not ask about scope. Use overview.md and
|
||||
the phase file for spec compliance; they do not widen the scope.
|
||||
- **The helper rule still applies:** a fresh helper runs the analysis when
|
||||
available, you verify every finding, and the report carries its Reviewed by
|
||||
line.
|
||||
- **No commit instructions and no next-conversation routing** mid-review. The
|
||||
way back out carries both.
|
||||
- The page takes the whole report, so the "top 10 of 15+" rule does not apply,
|
||||
@@ -116,15 +119,18 @@ review set it to its own stage):
|
||||
"items": [{ "id": "signoff", "status": "reopened",
|
||||
"body": "Reviewed and ready for sign-off. The review found 3 issues: 2 fixed, 1 still open in the Review findings tab. The report is updated.",
|
||||
"verdicts": [
|
||||
{ "id": "show", "label": "Show me it working" },
|
||||
{ "id": "approve", "label": "Approve this phase" },
|
||||
{ "id": "changes", "label": "I want changes" }
|
||||
],
|
||||
"token": { "approve": "approved", "changes": "needs changes", "show": "show me" },
|
||||
"thread": [{ "who": "agent", "text": "Review done: 2 of 3 findings fixed; the rest is written up in the findings tab." }]
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
Review Mode's own closing gate ("Reply approved to commit") is this card:
|
||||
`show` runs as `notes/implement.md` → Show me it working says, then reopens
|
||||
this card without it. Review Mode's own closing gate ("Reply approved to commit") is this card:
|
||||
approving the phase now covers the fixes too, so there is no separate "Check
|
||||
the fixes" step. On approval, continue at `notes/implement.md` → After
|
||||
approval: the finish.
|
||||
|
||||
@@ -17,7 +17,7 @@ menu judgment and the launch steps; this is what the page does around them.
|
||||
```
|
||||
|
||||
`spec` is the picker's selected spec dir, present only when the launched skill
|
||||
takes a spec and the person picked one. `resume` is the one command to run
|
||||
takes a spec (or is Quick Task on a `diagnosed` spec) and the person picked one. `resume` is the one command to run
|
||||
first, before reading anything: it reuses the live server and turns the page
|
||||
from the menu into the skill's starting screen while you read. `skillFile` is
|
||||
the skill to read next (absent outside an install: then
|
||||
@@ -63,3 +63,18 @@ person's turn by itself.
|
||||
|
||||
A `__stop` before a pick ends the session the usual way: `finish` (paused
|
||||
headline, `"command": "/plan2code"`) then `stop` (`console-stop.md`).
|
||||
|
||||
## A delete
|
||||
|
||||
The ✕ on a picker chip, after the page's two-step confirm (what goes, then
|
||||
the spec's name typed), sends `{ "i": "__delete", "type": "delete", "spec":
|
||||
"specs/<name>" }` with a `reply` saying it is for good. It is no hop: it
|
||||
carries no `resume`, and you stay the dashboard. The console never writes into
|
||||
a project, so the page only asks; delete through
|
||||
`node "<CONSOLE>" delete-spec --spec <spec>`, never your own `rm`. It takes
|
||||
only an existing `specs/<name>` folder inside the worktree (never a link,
|
||||
never deeper, never `specs--completed/`), exits 3 with `message` on a refusal
|
||||
having touched nothing, and drops the workspace remembered for that spec.
|
||||
Then `open --resume <sid> --no-open --workflow dashboard` to rescan, and post
|
||||
the menu again with `--wait`, its note saying what went or why it did not.
|
||||
The page shows the chip as "Deleting…" until that rescan lands.
|
||||
@@ -9,7 +9,7 @@ The page's top bar shows a meter of how much work this console session has
|
||||
done (green, yellow, red), so the person knows when a fresh session would be
|
||||
sharper. It is advice only and never blocks anything. The console counts
|
||||
launches itself: Plan, Revise plan, Document, Review, Quick task, Init, Init
|
||||
update, Finalize, Git and Changelog score when their session opens, and there is nothing to
|
||||
update, Finalize, Git, Changelog, X-ray and Diagnose score when their session opens, and there is nothing to
|
||||
post for them.
|
||||
|
||||
It counts answers itself too: every card the person answers in a send adds to
|
||||
@@ -27,7 +27,7 @@ Per-unit work is yours to report, with `run` in any post:
|
||||
nothing now: answers count instead), `pathfinder-research`, `plan`,
|
||||
`revise-plan`, `document`, `implement-phase`, `implement-review-phase`,
|
||||
`review`, `quick-task`, `init`, `init-update`, `finalize`, `handoff`,
|
||||
`git`, `changelog`, `git-commits` and `git-conflict` (Git's own, see
|
||||
`git`, `changelog`, `xray`, `diagnose`, `git-commits` and `git-conflict` (Git's own, see
|
||||
`notes/git.md`).
|
||||
An unknown event is exit `3`. Post only the events your notes name: a skill
|
||||
that scores when its session opens (the list above this one) already has its
|
||||
|
||||
@@ -39,7 +39,7 @@ several are due at once (a build's start), read them in one batch.
|
||||
| --- | --- |
|
||||
| `building.md` (`building`) | You run `implement`, `implement-review` or `quick-task`: right after `open`, then `notes/implement.md` or `notes/quick-task.md`. |
|
||||
| `building-review.md` (`building-review`) | A build's review is asked for on the page (a `review` verdict, `__review`, Implement + Review's Stage 2). |
|
||||
| `notes/<workflow>.md` (`<workflow>`) | Right after `open`: `init` (also init-update), `pathfinder`, `plan`, `revise-plan`, `document`, `implement` (also implement-review), `quick-task`, `review`, `finalize`, `handoff`, `changelog`, `git`. The dashboard's is `console-launches.md`. |
|
||||
| `notes/<workflow>.md` (`<workflow>`) | Right after `open`: `init` (also init-update), `pathfinder`, `plan`, `revise-plan`, `document`, `implement` (also implement-review), `quick-task`, `review`, `finalize`, `handoff`, `changelog`, `git`, `xray`, `diagnose`. The dashboard's is `console-launches.md`. |
|
||||
| `console-launches.md` (`launches`) | You are the dashboard. |
|
||||
| `console-finish.md` (`finish`) | Before your first `finish` post, and when a send carries `__commit`, or `__dashboard` from a finished screen. |
|
||||
| `console-stop.md` (`stop`) | A send carries `__stop`, or `__dashboard` with no finish up; or your notes say to post a `stopWarning`. |
|
||||
@@ -65,7 +65,7 @@ terminal — that path loses nothing, and they can switch either way at any time
|
||||
1. `node "<CONSOLE>" open --workflow <w>`, where `<w>` is one of `dashboard`,
|
||||
`init`, `init-update`, `pathfinder`, `quick-task`, `plan`, `revise-plan`,
|
||||
`document`, `implement`, `implement-review`, `review`, `finalize`,
|
||||
`handoff`, `git`, `changelog`. Get it right: the page decides from it what
|
||||
`handoff`, `git`, `changelog`, `xray`, `diagnose`. Get it right: the page decides from it what
|
||||
to offer and what stopping costs. `--title` defaults to the folder name;
|
||||
`--spec specs/<idea>` when you already know the spec. It prints
|
||||
`{"ok":true,"sid":"...","session":"...","url":"...","terminalLine":"→ Look at the web console: ..."}`
|
||||
@@ -164,6 +164,7 @@ An action whose `i` starts with `__` is about the session, not a question:
|
||||
| `__stop`, `__dashboard` (no finish up) | `console-stop.md` |
|
||||
| `__commit`, `__dashboard` (from a finished screen) | `console-finish.md` |
|
||||
| `__launch` | `console-launches.md` |
|
||||
| `__delete` | `console-launches.md` (the dashboard only) |
|
||||
| `__brief` | `notes/pathfinder.md` |
|
||||
| `__review`, `__done` | `building-review.md` |
|
||||
| `__git` | `notes/git.md` |
|
||||
@@ -352,6 +353,10 @@ with `"_delete": true` removes the whole tab).
|
||||
(relative to the project, never outside it). Re-send the block, or the doc
|
||||
with `"refresh": true`, after the file changes. `"select": "tasks"` keeps only
|
||||
its `- [ ] **Task N.M:**` lines. Never paste a file you could name.
|
||||
- **`image`** instead of `md`: `{ "id", "image": "shots/run.png", "alt": "..." }`
|
||||
shows a PNG, JPEG or WebP (5 MB at most) saved directly in the session's
|
||||
`shots/` folder (the `session` path `open` printed), named with letters,
|
||||
digits, `.`, `_` or `-`; anything else is exit `3`.
|
||||
- **`version`** moves by itself: a known doc whose content changed is the next
|
||||
version. Send one only to jump; it never goes back. Write a one-line `note`
|
||||
when you change a doc, and `"stale": true` while answers it does not reflect
|
||||
|
||||
@@ -42,6 +42,7 @@ import {
|
||||
ensureDir,
|
||||
fileStamp,
|
||||
forgetWorkspace,
|
||||
removeSpec,
|
||||
handOff,
|
||||
handleFile,
|
||||
healthOk,
|
||||
@@ -88,6 +89,7 @@ import {
|
||||
updateState,
|
||||
UPLOAD_MAX_AGE_MS,
|
||||
resolveDocFiles,
|
||||
resolveDocImages,
|
||||
validate,
|
||||
validateChat,
|
||||
workspaceForAgent,
|
||||
@@ -267,6 +269,7 @@ async function cmdOpen() {
|
||||
// refresh never re-reads the last skill's files into the new page.
|
||||
try {
|
||||
patch = resolveDocFiles(patch, base(structuredClone(state)), worktree);
|
||||
patch = resolveDocImages(patch, base(structuredClone(state)), dir);
|
||||
} catch (e) {
|
||||
die(e.message, 3);
|
||||
}
|
||||
@@ -656,6 +659,7 @@ function postOnce() {
|
||||
if (!before) die("that session has no state", 1);
|
||||
try {
|
||||
patch = resolveDocFiles(patch, before, before.worktree || repoRoots().worktree);
|
||||
patch = resolveDocImages(patch, before, dir);
|
||||
} catch (e) {
|
||||
die(e.message, 3);
|
||||
}
|
||||
@@ -1301,6 +1305,24 @@ function cmdForget() {
|
||||
print({ ok: true, spec, forgot: forgetWorkspace(worktree, spec) });
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------- delete-spec */
|
||||
|
||||
// The dashboard's Delete button, carried out by the agent: the page never
|
||||
// writes into a project. removeSpec() does every check; a refusal is exit 3
|
||||
// with the reason, and the remembered workspace for the spec goes with it.
|
||||
function cmdDeleteSpec() {
|
||||
if (typeof args.spec !== "string" || !args.spec.trim()) die("delete-spec needs --spec specs/<name>", 2);
|
||||
const worktree = repoRoots().worktree;
|
||||
try {
|
||||
const done = removeSpec(worktree, args.spec);
|
||||
forgetWorkspace(worktree, args.spec);
|
||||
print(done);
|
||||
} catch (err) {
|
||||
print({ ok: false, message: err.message });
|
||||
process.exit(3);
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------- help */
|
||||
|
||||
function cmdHelp() {
|
||||
@@ -1370,6 +1392,12 @@ port, and the filesystem as transport; this CLI is the whole agent surface.
|
||||
Drop the workspace folders remembered for that spec, in this
|
||||
folder (Finalize, after archiving it). Prints { ok, spec, forgot };
|
||||
forgot is false when nothing was saved. Exit 2 = bad usage.
|
||||
delete-spec --spec specs/<name>
|
||||
Delete that spec folder for good (the dashboard's Delete button, a
|
||||
__delete action). Only an existing specs/<name> folder inside this
|
||||
worktree: never a link, never deeper, never specs--completed/.
|
||||
Prints { ok, removed }; exit 2 = bad usage, 3 = refused, with
|
||||
{ ok: false, message } saying why. Nothing is touched on a refusal.
|
||||
status [--session <sid>] [--all]
|
||||
One session, or (--all) every session on this machine, every project.
|
||||
stop --session <sid> | --all
|
||||
@@ -1377,7 +1405,7 @@ port, and the filesystem as transport; this CLI is the whole agent surface.
|
||||
|
||||
workflows: dashboard · init · init-update · pathfinder · quick-task · plan ·
|
||||
revise-plan · document · implement · implement-review · review ·
|
||||
finalize · handoff · git · changelog
|
||||
finalize · handoff · git · changelog · xray · diagnose
|
||||
|
||||
A session handed to you by the dashboard (a --session id): resume it with
|
||||
"open --resume <sid> --no-open --workflow <yours>" (the resume it carries) -- never a
|
||||
@@ -1636,6 +1664,7 @@ const COMMANDS = {
|
||||
chat: cmdChat,
|
||||
keep: cmdKeep,
|
||||
forget: cmdForget,
|
||||
"delete-spec": cmdDeleteSpec,
|
||||
status: cmdStatus,
|
||||
stop: cmdStop,
|
||||
help: cmdHelp,
|
||||
@@ -1655,7 +1684,7 @@ if (Number.isFinite(nodeMajor) && nodeMajor < 18) {
|
||||
|
||||
if (!cmd || !Object.hasOwn(COMMANDS, cmd)) {
|
||||
process.stderr.write(
|
||||
"console: usage: console.mjs <open|post|wait|chat|keep|forget|status|stop|help> [--session <id>] [--file <patch.json>] [--seconds N]\n"
|
||||
"console: usage: console.mjs <open|post|wait|chat|keep|forget|delete-spec|status|stop|help> [--session <id>] [--file <patch.json>] [--seconds N]\n"
|
||||
);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
+167
-15
@@ -24,7 +24,7 @@ import { fileURLToPath } from "node:url";
|
||||
|
||||
import { countPending } from "./git-repo.mjs";
|
||||
import { CHAT_LIMIT } from "./public/chat.js";
|
||||
import { DOC_TYPES } from "./public/answers.js";
|
||||
import { DOC_TYPES, isDeletableSpecDir } from "./public/answers.js";
|
||||
import { defaultName } from "./public/workspace.js";
|
||||
import { checkHelpers, cleanSetting, defaultSetting, offered } from "./public/subagents.js";
|
||||
|
||||
@@ -579,9 +579,10 @@ export async function removeScratch(consoleDir, names) {
|
||||
// What User Preferences -> Cleanup never removes. The console folder keeps its
|
||||
// protected files, its sessions dir (old sessions go one by one, by age) and,
|
||||
// under PLAN2CODE_CONSOLE_HOME, its runtime dir; ~/.plan2code keeps the
|
||||
// console, the launcher (bin/, launcher.json) and the models the person added.
|
||||
// console, the launcher (bin/, launcher.json), the install record that
|
||||
// `plan2code update` reads (install.json) and the models the person added.
|
||||
const KEPT_CONSOLE_ENTRIES = new Set([...PROTECTED_CONSOLE_FILES, "sessions", "runtime"]);
|
||||
export const KEPT_PLAN2CODE_ENTRIES = new Set(["console", "bin", "launcher.json", "models.json"]);
|
||||
export const KEPT_PLAN2CODE_ENTRIES = new Set(["console", "bin", "launcher.json", "install.json", "models.json"]);
|
||||
// A stray must sit untouched this long before Cleanup lists it. The same
|
||||
// folders hold files that live for milliseconds -- a held
|
||||
// `workspaces.json.lock`, a `<file>.<pid>.tmp` between its write and its
|
||||
@@ -785,8 +786,13 @@ export function newToken() {
|
||||
// Where a spec folder stands, named after the step its files are ready for.
|
||||
// "unrecognized" is a folder with files but no pipeline shape: it launches
|
||||
// Pathfinder or Plan (the files may be reference docs) but unlocks nothing
|
||||
// else, exactly like picking no spec at all.
|
||||
// else, exactly like picking no spec at all. "diagnosed" is a bug Diagnose
|
||||
// wrote up and nobody has fixed or planned yet: it lights Quick Task and Plan.
|
||||
// "fixed" is that bug once Quick Task marked it Fixed: finished, so the
|
||||
// dashboard never picks or suggests it, and Quick Task offers to archive it.
|
||||
export const SPEC_STATES = new Set([
|
||||
"diagnosed",
|
||||
"fixed",
|
||||
"exploring",
|
||||
"mapped",
|
||||
"planned",
|
||||
@@ -796,7 +802,9 @@ export const SPEC_STATES = new Set([
|
||||
"unrecognized",
|
||||
]);
|
||||
|
||||
function maxMtime(dir, depth = 4, budget = { n: 400 }) {
|
||||
// The newest mtime under dir. `tally.files` counts the files the same walk
|
||||
// sees (within its depth and budget), for the dashboard's delete dialog.
|
||||
function maxMtime(dir, depth = 4, budget = { n: 400 }, tally = null) {
|
||||
let best = 0;
|
||||
if (depth < 0 || budget.n <= 0) return best;
|
||||
let entries;
|
||||
@@ -810,8 +818,11 @@ function maxMtime(dir, depth = 4, budget = { n: 400 }) {
|
||||
if (e.name.startsWith(".")) continue;
|
||||
const p = path.join(dir, e.name);
|
||||
try {
|
||||
if (e.isDirectory()) best = Math.max(best, maxMtime(p, depth - 1, budget));
|
||||
else best = Math.max(best, fs.statSync(p).mtimeMs);
|
||||
if (e.isDirectory()) best = Math.max(best, maxMtime(p, depth - 1, budget, tally));
|
||||
else {
|
||||
best = Math.max(best, fs.statSync(p).mtimeMs);
|
||||
if (tally) tally.files++;
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
return best;
|
||||
@@ -825,6 +836,16 @@ function readText(file) {
|
||||
}
|
||||
}
|
||||
|
||||
// A spec file's Status line value, in any of the forms the skill scripts
|
||||
// accept (`**Status:**`, `**Status**:`, `Status:`). Same pattern as STATUS_RE
|
||||
// in src/skill-scripts/specs.mjs; the console cannot import it, so keep the
|
||||
// two copies in step. A CRLF file's trailing `\r` is dropped.
|
||||
const STATUS_LINE_RE = /^[ \t]*(?:[-*][ \t]*)?(?:\*\*Status:\*\*|\*\*Status\*\*:|Status:)[ \t]*(.+?)[ \t\r]*$/m;
|
||||
function statusOf(text) {
|
||||
const m = text.match(STATUS_LINE_RE);
|
||||
return m ? m[1] : "";
|
||||
}
|
||||
|
||||
// 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.
|
||||
@@ -837,9 +858,7 @@ function classifySpec(dir, names) {
|
||||
const planDraft = drafts.length > 0;
|
||||
const planConv = has(/^PLAN-CONVERSATION.*\.md$/i);
|
||||
const liveDraft = drafts.filter((n) => !/-prev\.md$/i.test(n)).sort().reverse()[0] || drafts[0];
|
||||
const draftStatus = liveDraft
|
||||
? (readText(path.join(dir, liveDraft)).match(/\*\*Status:\*\*\s*([^\n]+)/) || [])[1] || ""
|
||||
: "";
|
||||
const draftStatus = liveDraft ? statusOf(readText(path.join(dir, liveDraft))) : "";
|
||||
const resumeAt = draftStatus.match(/Resume at Phase\s*(\d+)/i);
|
||||
|
||||
if (phases.length) {
|
||||
@@ -870,10 +889,19 @@ function classifySpec(dir, names) {
|
||||
// Status line: Plan still has phases to run before Document can start.
|
||||
if (resumeAt) return { state: "mapped", detail: `plan draft, resume at Phase ${resumeAt[1]}` };
|
||||
if (planDraft) return { state: "planned", detail: "plan drafted" };
|
||||
// A bug Diagnose wrote up, with nothing after it yet. A pathfinder map or a
|
||||
// plan conversation means planning has started, so the usual states win.
|
||||
// Quick Task marks the write-up Fixed once the bug is gone: then the bug is
|
||||
// done, and the folder waits only to be archived.
|
||||
const diagnosis = names.filter((n) => /^DIAGNOSIS-.*\.md$/i.test(n)).sort().reverse()[0];
|
||||
const diagnosisStatus = diagnosis ? statusOf(readText(path.join(dir, diagnosis))).replace(/\*+/g, "").trim() : "";
|
||||
if (diagnosis && !planConv && !fs.existsSync(path.join(pfDir, "map.md")))
|
||||
return /^fixed/i.test(diagnosisStatus)
|
||||
? { state: "fixed", detail: "bug fixed" }
|
||||
: { state: "diagnosed", detail: "bug diagnosed, not fixed" };
|
||||
if (isDir(pfDir)) {
|
||||
const mapText = readText(path.join(pfDir, "map.md"));
|
||||
const m = mapText.match(/\*\*Status:\*\*\s*([^\n]+)/);
|
||||
const status = m ? m[1].replace(/\*+/g, "").trim() : "";
|
||||
const status = statusOf(mapText).replace(/\*+/g, "").trim();
|
||||
if (/^cleared/i.test(status)) return { state: "mapped", detail: "all decisions made" };
|
||||
let qTotal = 0;
|
||||
let qDone = 0;
|
||||
@@ -930,11 +958,13 @@ export function scanProject(root) {
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
const tally = { files: 0 };
|
||||
specs.push({
|
||||
dir: `specs/${name}`,
|
||||
name,
|
||||
...classifySpec(dir, files),
|
||||
touched: maxMtime(dir),
|
||||
touched: maxMtime(dir, 4, { n: 400 }, tally),
|
||||
files: tally.files,
|
||||
});
|
||||
}
|
||||
specs.sort((a, b) => b.touched - a.touched || a.name.localeCompare(b.name));
|
||||
@@ -948,6 +978,38 @@ export function scanProject(root) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete one spec folder, for the dashboard's Delete button (`delete-spec`).
|
||||
* Only an existing `specs/<name>` folder, as isDeletableSpecDir() spells it,
|
||||
* whose real path sits directly in the worktree's own specs/: never a link to
|
||||
* somewhere else, never specs--completed/, never anything deeper. specs/ is
|
||||
* gitignored, so a mistake here cannot be undone; every refusal throws with
|
||||
* the reason, and nothing is touched.
|
||||
*/
|
||||
export function removeSpec(worktree, dir) {
|
||||
if (!isDeletableSpecDir(dir)) throw new Error(`"${dir}" is not a spec folder: only specs/<name> can be deleted`);
|
||||
const fold = (p) => (process.platform === "win32" || process.platform === "darwin" ? p.toLowerCase() : p);
|
||||
const root = path.resolve(worktree);
|
||||
const target = path.join(root, dir);
|
||||
let st;
|
||||
try {
|
||||
st = fs.lstatSync(target);
|
||||
} catch {
|
||||
throw new Error(`there is no ${dir} to delete`);
|
||||
}
|
||||
if (st.isSymbolicLink()) throw new Error(`${dir} is a link to another folder, so it is not deleted from here`);
|
||||
if (!st.isDirectory()) throw new Error(`${dir} is not a folder`);
|
||||
const real = fs.realpathSync.native(target);
|
||||
const realSpecs = fs.realpathSync.native(path.join(root, "specs"));
|
||||
const realRoot = fs.realpathSync.native(root);
|
||||
const rel = path.relative(fold(realRoot), fold(realSpecs));
|
||||
if (rel !== "specs" || fold(path.dirname(real)) !== fold(realSpecs)) {
|
||||
throw new Error(`${dir} resolves outside the project's specs/ folder, so it is not deleted`);
|
||||
}
|
||||
fs.rmSync(real, { recursive: true });
|
||||
return { ok: true, removed: dir };
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- liveness */
|
||||
|
||||
// PID reuse is real, so process.kill(pid, 0) is necessary but not sufficient.
|
||||
@@ -1246,7 +1308,7 @@ function mergeDocs(current, patchList) {
|
||||
// version: the agent no longer has to track what the page holds, and a
|
||||
// repost of unchanged content is not a new version.
|
||||
if (prev && typeof entry.version !== "number" && typeof prev.version === "number") {
|
||||
const text = (blocks) => JSON.stringify((blocks || []).map((b) => [b.id, b.md, b.state]));
|
||||
const text = (blocks) => JSON.stringify((blocks || []).map((b) => [b.id, b.md, b.state, b.image, b.alt]));
|
||||
if (text(prev.blocks) !== text(doc.blocks)) doc.version = prev.version + 1;
|
||||
}
|
||||
}
|
||||
@@ -1410,6 +1472,83 @@ export function resolveDocFiles(patch, state, worktree) {
|
||||
return { ...patch, docs };
|
||||
}
|
||||
|
||||
/**
|
||||
* Image blocks: `{ "id", "image": "shots/run.png", "alt": "..." }` shows a
|
||||
* screenshot the agent saved under the session's `shots/` folder (Show me it
|
||||
* working). The path resolves against the session folder and must land, after
|
||||
* `realpath`, directly inside `<session>/shots/` under a plain name, so the page
|
||||
* can only ever be pointed at the agent's own pictures. The bytes decide the
|
||||
* type, as checkDocument() does for documents: a text file renamed `.png` is
|
||||
* refused. Stored session-relative; an image block never carries `md` or `file`.
|
||||
* Runs in the CLI beside resolveDocFiles(), so applyPatch never touches the disk.
|
||||
*/
|
||||
export const SHOTS_DIR_NAME = "shots";
|
||||
export const SHOT_MAX = 5 * 1024 * 1024;
|
||||
export const SHOT_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}\.(png|jpe?g|webp)$/i;
|
||||
|
||||
// What an image's first bytes say it is ("png", "jpeg", "webp"), or null.
|
||||
export function shotType(buf) {
|
||||
if (buf.length >= 8 && buf.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]))) return "png";
|
||||
if (buf.length >= 3 && buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff) return "jpeg";
|
||||
if (buf.length >= 12 && buf.toString("ascii", 0, 4) === "RIFF" && buf.toString("ascii", 8, 12) === "WEBP") return "webp";
|
||||
return null;
|
||||
}
|
||||
|
||||
export function resolveDocImages(patch, state, dir) {
|
||||
if (!isPlainObject(patch) || !Array.isArray(patch.docs)) return patch;
|
||||
const fold = (p) => (process.platform === "win32" || process.platform === "darwin" ? p.toLowerCase() : p);
|
||||
const shotsDir = path.join(path.resolve(dir), SHOTS_DIR_NAME);
|
||||
const check = (image, docId) => {
|
||||
if (typeof image !== "string" || !image.trim()) throw new Error(`doc "${docId}": an image block's "image" must be a path`);
|
||||
const where = `doc "${docId}": image ${image}`;
|
||||
let real;
|
||||
try {
|
||||
real = fs.realpathSync.native(path.resolve(dir, image));
|
||||
} catch {
|
||||
throw new Error(`${where} does not exist. Save it under the session's ${SHOTS_DIR_NAME}/ folder first.`);
|
||||
}
|
||||
let realShots;
|
||||
try {
|
||||
realShots = fs.realpathSync.native(shotsDir);
|
||||
} catch {
|
||||
realShots = shotsDir;
|
||||
}
|
||||
const name = path.basename(real);
|
||||
if (fold(path.dirname(real)) !== fold(realShots)) {
|
||||
throw new Error(`${where} is outside the session's ${SHOTS_DIR_NAME}/ folder (${shotsDir}); only pictures saved there can be shown.`);
|
||||
}
|
||||
if (!SHOT_NAME.test(name)) throw new Error(`${where}: name it with letters, digits, dots, dashes or underscores, ending .png, .jpg, .jpeg or .webp`);
|
||||
const stat = fs.statSync(real);
|
||||
if (!stat.isFile()) throw new Error(`${where} is not a file`);
|
||||
if (stat.size > SHOT_MAX) throw new Error(`${where} is larger than ${SHOT_MAX / 1024 / 1024} MB`);
|
||||
const ext = path.extname(name).slice(1).toLowerCase();
|
||||
const want = ext === "jpg" ? "jpeg" : ext;
|
||||
if (shotType(fs.readFileSync(real)) !== want) throw new Error(`${where} is not a ${want.toUpperCase()} image (its bytes say otherwise)`);
|
||||
return `${SHOTS_DIR_NAME}/${name}`;
|
||||
};
|
||||
const docs = patch.docs.map((entry) => {
|
||||
if (!isPlainObject(entry) || !Array.isArray(entry.blocks)) return entry;
|
||||
const prevBlocks = (state.docs || []).find((d) => d && d.id === entry.id)?.blocks || [];
|
||||
return {
|
||||
...entry,
|
||||
blocks: entry.blocks.map((b) => {
|
||||
if (!isPlainObject(b)) return b;
|
||||
const prevBlock = prevBlocks.find((x) => x && x.id === b.id);
|
||||
if (b.image === undefined || b.image === null) {
|
||||
// Text or a file over what was an image: it stops being one.
|
||||
return ("md" in b || "file" in b) && prevBlock && typeof prevBlock.image === "string" ? { ...b, image: null, alt: null } : b;
|
||||
}
|
||||
if (("md" in b && b.md != null) || ("file" in b && b.file != null)) {
|
||||
throw new Error(`doc "${entry.id}": block "${b.id}" is an image; it cannot also carry "md" or "file"`);
|
||||
}
|
||||
if (b.alt != null && typeof b.alt !== "string") throw new Error(`doc "${entry.id}": block "${b.id}" "alt" must be text`);
|
||||
return { state: prevBlock?.state || "settled", ...b, image: check(b.image, entry.id), md: null, file: null };
|
||||
}),
|
||||
};
|
||||
});
|
||||
return { ...patch, docs };
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an agent patch to the session state.
|
||||
*
|
||||
@@ -1556,12 +1695,15 @@ const JARGON = [
|
||||
];
|
||||
|
||||
// The loop parses these out of agent output; pathfinder forbids them under specs/.
|
||||
// The other copy is LOOP_TOKENS in src/skill-scripts/common.mjs: the console is
|
||||
// not a skill script and cannot import it, so keep the two in step.
|
||||
const FORBIDDEN_TOKENS =
|
||||
/\b(TASK_COMPLETE|PHASE_COMPLETE|ALL_TASKS_COMPLETE|IMPLEMENTATION_COMPLETE|SPEC_COMPLETE|WORK_COMPLETE)\b/;
|
||||
|
||||
// plan2code-metrics scrapes confidence with patterns that do NOT require a
|
||||
// percent sign, so a bare "Requirements 22" in a rendered doc can poison a run's
|
||||
// metrics. Keep those four words away from bare numbers.
|
||||
// metrics. Keep those four words away from bare numbers. The skill scripts'
|
||||
// copy is SCRAPE in src/skill-scripts/common.mjs; keep the two in step.
|
||||
const METRICS_BAIT = /\b(Requirements?|Feasibility|Integration|Risk)[:\s|]+\d{1,2}\b/;
|
||||
|
||||
// The marker and metrics-bait scan on its own, for agent text that never
|
||||
@@ -1761,6 +1903,16 @@ export function validate(state) {
|
||||
);
|
||||
}
|
||||
|
||||
// An image block's alt text is its caption, read by the same newcomers a
|
||||
// title is.
|
||||
for (const d of state.docs || []) {
|
||||
for (const b of (isPlainObject(d) && Array.isArray(d.blocks) ? d.blocks : [])) {
|
||||
if (!isPlainObject(b) || typeof b.image !== "string" || typeof b.alt !== "string") continue;
|
||||
const hit = JARGON.find((re) => re.test(b.alt));
|
||||
if (hit) problems.push(`doc "${d.id}" image "${b.id}" alt text contains internal vocabulary (${hit.source})`);
|
||||
}
|
||||
}
|
||||
|
||||
// Scan what the AGENT wrote, never what the person typed. `submitted` is the
|
||||
// server's record of an answer someone pressed Send on; if their own words
|
||||
// happened to contain "TASK_COMPLETE" or "Risk 3", every later agent patch
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
# Diagnose on the Web Console
|
||||
|
||||
Workflow notes for `diagnose`, part of the web console contract (`console.md`).
|
||||
|
||||
## The bug
|
||||
|
||||
A typed argument that already describes the bug skips the cards it answers.
|
||||
Otherwise ask in one batch (at most three open), posted with `--wait`:
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"title": "Diagnose a bug",
|
||||
"headline": { "stage": "The bug", "cleared": 0, "total": 3 },
|
||||
"items": [
|
||||
{ "id": "bug", "kind": "text", "title": "What is wrong",
|
||||
"body": "The bug, in a sentence or two.",
|
||||
"placeholder": "The CSV export drops the last row when the report has more than 100 rows." },
|
||||
{ "id": "expected", "kind": "text", "title": "Expected and actual",
|
||||
"body": "What should happen, and what happens instead.",
|
||||
"placeholder": "Expected 150 rows in the file; it has 149, and the last order is missing." },
|
||||
{ "id": "see-it", "kind": "text", "title": "How to see it",
|
||||
"body": "The steps, command, page or input that shows it, and since when if you know.",
|
||||
"placeholder": "Run npm run export -- --month 2026-09 and count the rows. It worked last month." }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
No `"templates"` on these cards: the starter templates are for a fresh idea,
|
||||
and a bug report is not one. A follow-up the answers leave open is a new card
|
||||
with a new id.
|
||||
|
||||
## The cause
|
||||
|
||||
Post the cause as a doc, `id` `"cause"`, as soon as there is something to show,
|
||||
and grow it as evidence lands, with `"agent": { "status": "working",
|
||||
"activity": "..." }` while you reproduce and narrow:
|
||||
|
||||
```jsonc
|
||||
"docs": [{ "id": "cause", "title": "The cause", "note": "Reproduced; narrowing", "blocks": [
|
||||
{ "id": "repro", "state": "settled", "md": "## Reproduction\n\n`node scripts/export-check.mjs` fails: 149 rows, expected 150." },
|
||||
{ "id": "found", "state": "settled", "md": "## The cause\n\n`src/export.ts` `writeRows()`: the loop stops at `rows.length - 1`. **Proven** by the reproduction." },
|
||||
{ "id": "fix", "state": "settled", "md": "## Suggested fix\n\nLoop to `rows.length`. **Size:** Small (Quick Task)." }
|
||||
]}]
|
||||
```
|
||||
|
||||
- **Unproven** guesses are `assumed` blocks, one per guess, ranked, each with
|
||||
its evidence and what would confirm it. A guess the evidence proves becomes
|
||||
`settled`; one it rules out is removed (`"_delete": true`).
|
||||
- Keeping a failing test inside the project is a `confirm` card pointing at
|
||||
the doc (`"doc": "cause"`), `yesLabel` "Keep it", `noLabel` "Throw it away".
|
||||
|
||||
## The bug name
|
||||
|
||||
With the cause written, ask the folder name, posted with `--wait`:
|
||||
|
||||
```jsonc
|
||||
{ "id": "name", "kind": "text", "title": "Name for the write-up", "doc": "cause",
|
||||
"body": "The diagnosis is saved as `specs/<name>/DIAGNOSIS-<date>.md`. Lowercase words joined by dashes.",
|
||||
"placeholder": "csv-export-drops-rows",
|
||||
"pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
|
||||
"patternHint": "Lowercase letters, numbers and dashes, like csv-export-drops-rows." }
|
||||
```
|
||||
|
||||
Once written, re-send the doc with
|
||||
`"saved": "specs/<name>/DIAGNOSIS-<date>.md"` and its blocks replaced by one
|
||||
`file` block for that path (delete the old ids).
|
||||
|
||||
## The finish
|
||||
|
||||
`command` is `/plan2code-quick-task specs/<name>` (small fix) or
|
||||
`/plan2code-1-plan specs/<name>` (big fix) with the real folder filled in
|
||||
(`/plan2code-quick-task specs/csv-export-drops-rows`), never a placeholder: a
|
||||
copied command must reach the diagnosis. `body` names the cause, how sure, and that the
|
||||
next step reads the diagnosis first. `doc` is `"cause"`. `"dashboard": true`,
|
||||
then keep waiting for the press (`console-finish.md`): back on the dashboard
|
||||
the folder shows as "Bug diagnosed", with that card lit.
|
||||
|
||||
Nothing kept (the bug did not reproduce and no guess held up): leave
|
||||
`command` out and say so in `body`.
|
||||
|
||||
A stop before the file is written ends on a finish whose `body` says nothing
|
||||
was kept (and names any throwaway script or kept test you wrote), with
|
||||
`"command": "/plan2code-diagnose"` (`console-stop.md`).
|
||||
@@ -12,7 +12,7 @@ know:
|
||||
| 3, Implementation Summary | Written to `overview.md` as usual; mirror it as a doc (marked `saved`, as a `file` block on `overview.md`) so the page reader sees it land. |
|
||||
| 4, Documentation Review | The proposed-updates table as a doc, and a `multi` naming the documents to update — every option ticked is "approve", unticked ones are skipped. A `review` works instead when the set is all-or-nothing. |
|
||||
| 5, User Feedback | Optional items, `required: false`: the rating as a `choice` of 1 to 10 or a `text`, the three reasons as `text`. The submit-to-maintainer consent is a `confirm`. |
|
||||
| 6, Spec Cleanup | A `confirm` before moving anything, the archive paths in `consequences`, and a line that the spec's remembered workspace folders are forgotten too (`console.mjs forget --spec specs/<feature>` after the move). |
|
||||
| 6, Spec Cleanup | A `review` item before moving anything (`doc`: Step 3's summary), verdicts `yes` ("Archive it"), `show` ("Show me it working", token `show me`) and `no`, the archive paths in `body`, and a line that the spec's remembered workspace folders are forgotten too (`console.mjs forget --spec specs/<feature>` after the move). On `show`, run it as `notes/implement.md` → Show me it working says (the summary line goes into `overview.md`'s Completion Summary), then reopen the card without `show`. |
|
||||
|
||||
Post `activity` as each step starts, before its doc or question lands — reading
|
||||
the spec, running `specs.mjs status` or `archive --dry-run`, checking the
|
||||
|
||||
@@ -64,13 +64,14 @@ only ever be offered once nothing could come of it:
|
||||
]}],
|
||||
"items": [{
|
||||
"id": "signoff", "kind": "review", "title": "Approve this phase", "doc": "report",
|
||||
"body": "Phase 3 is built. Read the report, try the checks, then approve it, review the code first, or say what to change.",
|
||||
"body": "Phase 3 is built. Read the report, try the checks, then approve it, review the code first, see it running, or say what to change.",
|
||||
"verdicts": [
|
||||
{ "id": "review", "label": "Review the code first" },
|
||||
{ "id": "show", "label": "Show me it working" },
|
||||
{ "id": "approve", "label": "Approve this phase" },
|
||||
{ "id": "changes", "label": "I want changes" }
|
||||
],
|
||||
"token": { "approve": "approved", "changes": "needs changes" },
|
||||
"token": { "approve": "approved", "changes": "needs changes", "show": "show me" },
|
||||
"nothingYet": "Nothing is marked complete until you approve.",
|
||||
"gate": { "id": "signoff", "authoritative": true }
|
||||
}]
|
||||
@@ -83,7 +84,19 @@ change, treat it as "describe any issues": do the change first and ask again.
|
||||
`changes` means exactly what it says: address it, update the report, and reopen
|
||||
the item (`"status": "reopened"`) with a reply in its `thread`. `review` is the
|
||||
person asking for the code review before they approve anything — read
|
||||
`building-review.md`.
|
||||
`building-review.md`. `show` is the terminal's `show me`: see below.
|
||||
|
||||
### Show me it working
|
||||
|
||||
On `show`, run the workflow's **Show me it working** paragraph (start the app,
|
||||
look at the change, stop it, one summary line in `phase-X.md`). Save each
|
||||
screenshot under the session's `shots/` folder, never under `specs/`, and post
|
||||
them as image blocks in a `shown` doc (`console.md` → Documents), with what was
|
||||
run in a `md` block above them; no browser tool means that block alone says
|
||||
what the command printed. Then reopen the same card (`"status": "reopened"`)
|
||||
without the `show` verdict, a `thread` reply naming what was seen. The same
|
||||
holds on Finalize's card and the one `building-review.md` reopens; Quick
|
||||
Task's card is settled instead (`notes/quick-task.md`).
|
||||
|
||||
`gate` marks the one approval that counts. The server refuses a second open
|
||||
authoritative gate, which is what keeps a composed workflow from asking for
|
||||
@@ -172,7 +185,7 @@ Stage 3 fixes, with no "Check the fixes" item: Stage 4 is the only gate. The
|
||||
post that starts Stage 2's review carries `"run": { "event": "review", "id":
|
||||
"review" }`: in this workflow it scores the review stage's 1 point on the meter
|
||||
as it begins, and the phase's final `run` leaves that point out. Stage 4 is the
|
||||
sign-off above **without the review verdict** — the phase was already reviewed
|
||||
sign-off above (`show` included) **without the review verdict** — the phase was already reviewed
|
||||
— with the review results and unresolved findings in the report doc, header
|
||||
"Reviewed and ready for sign-off" in the item's `body`. The finish never
|
||||
carries `review`, and its post carries `"run": { "event":
|
||||
|
||||
@@ -70,6 +70,21 @@ Workflow notes for `quick-task`, part of the web console contract
|
||||
Check for a Quick question between steps, and do not call `wait` until the
|
||||
build is done. Tick the Verify block's boxes too as the checks pass, in the
|
||||
post that reports them.
|
||||
- **See it running, before the finish:** a finished screen freezes every open
|
||||
card, so ask first. Once the build is done, post a `review` item "See it
|
||||
running" (`"doc": "plan"`, verdicts `show` ("Show me it working") and `fine`
|
||||
("No need, finish up"), token `show me` / `no`) with `--wait`. On `show`, run
|
||||
it as `notes/implement.md` → Show me it working says, its one line going into
|
||||
the work summary (the finish's `body`); then, or on `fine`, settle the card in
|
||||
the same post as the finish.
|
||||
- **Archive a fixed bug, before the finish:** launched on a diagnosed folder
|
||||
and now Fixed with nothing past the diagnosis, post a `confirm` card
|
||||
"Archive this bug?" in the same post as "See it running": the dry run's
|
||||
`files` in `body`, `yesLabel` "Archive it", `noLabel` "Keep it in specs/",
|
||||
and `consequences` naming `specs--completed/<bug>/`. On yes, run
|
||||
`node "<S>/specs.mjs" archive <spec>` (the skill file says where `<S>` is),
|
||||
and say where it went in the finish's `body`. On no, the
|
||||
dashboard lists the folder as "Bug fixed", never pre-selected.
|
||||
- **The finish after the build:** `command` is the commit command, filled in,
|
||||
in the project's commit format (AGENTS.md), with
|
||||
`"where": "When you are happy with it, commit it from your terminal:"`, and
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
# X-ray on the Web Console
|
||||
|
||||
Workflow notes for `xray`, part of the web console contract (`console.md`).
|
||||
|
||||
## The mode question
|
||||
|
||||
A typed argument that names the mode and area skips it. Otherwise ask both in
|
||||
one batch, posted with `--wait`:
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"title": "Codebase X-ray",
|
||||
"headline": { "stage": "Choosing", "cleared": 0, "total": 2 },
|
||||
"items": [
|
||||
{ "id": "mode", "kind": "choice", "title": "What you want to know", "allowOther": false,
|
||||
"body": "Explain one area, or rank what makes this code hard to change.",
|
||||
"options": [
|
||||
{ "k": "1", "text": "Explain an area", "detail": "How it works and why it is that way, citing files and the commits behind it." },
|
||||
{ "k": "2", "text": "Find the rough spots", "detail": "Ranked spots that make change hard. You pick the ones worth fixing; they become a brief for Pathfinder or Plan." }
|
||||
] },
|
||||
{ "id": "area", "kind": "text", "title": "Which area", "required": false,
|
||||
"body": "A folder, file or feature. Needed to explain; leave it empty to survey the whole repository.",
|
||||
"placeholder": "src/exporter, the code that builds the CSV reports" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Explain picked with the area left empty: ask for it again as a required `text`
|
||||
card. No recommendation on the mode: only the person knows what they came for.
|
||||
|
||||
## Explain mode
|
||||
|
||||
The answer is a doc, `id` `"answer"`, one block per section (`In one paragraph`,
|
||||
`How it works`, `Why it is this way`, `Worth knowing`), with the `Sources:` line
|
||||
at the top of the first. Then the save offer as a `confirm` card pointing at it:
|
||||
|
||||
```jsonc
|
||||
{ "id": "keep", "kind": "confirm", "title": "Keep this answer", "doc": "answer",
|
||||
"body": "Save it as `specs/exporter/XRAY-exporter-20261016.md`, as input for Pathfinder or Plan?",
|
||||
"yesLabel": "Save it", "noLabel": "No, just reading" }
|
||||
```
|
||||
|
||||
Ask the folder name in the same batch as a `text` card with `pattern`
|
||||
`^[a-z0-9]+(-[a-z0-9]+)*$` when it is not obvious. Once written, re-send the doc
|
||||
with `"saved": "specs/<name>/XRAY-<area-slug>-<date>.md"`.
|
||||
|
||||
## Rough-spots mode
|
||||
|
||||
The ranked list is a doc, `id` `"spots"`, one block per spot (its files, why it
|
||||
hurts, the "to change X today" example). The pick is one `multi` card pointing
|
||||
at it, posted with `--wait`:
|
||||
|
||||
```jsonc
|
||||
{ "id": "pick", "kind": "multi", "title": "Worth fixing", "doc": "spots", "required": false,
|
||||
"body": "Tick the spots worth fixing. Add a note for any of them in the box (\"1: the exporter part only\"). Only ticked spots go into the brief.",
|
||||
"options": [
|
||||
{ "k": "1", "text": "Exporter and its formatter always change together", "detail": "src/export.ts, src/format.ts: together in 14 of 16 commits." }
|
||||
] }
|
||||
```
|
||||
|
||||
Nothing ticked: nothing is written. Otherwise write the brief, then add it as a
|
||||
second doc with `"saved": "specs/<name>/ARCHITECTURE-BRIEF-<date>.md"` and a
|
||||
`file` block.
|
||||
|
||||
## The finish
|
||||
|
||||
`command` is `/plan2code-0-pathfinder` (big or unclear) or `/plan2code-1-plan`
|
||||
(settled), never with a placeholder; leave it out when nothing was kept. `doc`
|
||||
is the brief or the saved answer when there is one. `"dashboard": true`, then
|
||||
keep waiting for the press (`console-finish.md`).
|
||||
|
||||
A stop before anything was written ends on a finish whose `body` says nothing
|
||||
was kept, with `"command": "/plan2code-xray"` (`console-stop.md`).
|
||||
@@ -270,6 +270,8 @@ export const WORKFLOW_LABEL = {
|
||||
handoff: "Handoff",
|
||||
git: "Git",
|
||||
changelog: "Changelog",
|
||||
xray: "X-ray",
|
||||
diagnose: "Diagnosing",
|
||||
};
|
||||
|
||||
export function workflowLabel(workflow) {
|
||||
@@ -296,6 +298,8 @@ export const CONSOLE_WORKFLOWS = [
|
||||
"/plan2code-handoff",
|
||||
"/plan2code-git",
|
||||
"/plan2code-changelog",
|
||||
"/plan2code-xray",
|
||||
"/plan2code-diagnose",
|
||||
];
|
||||
|
||||
// Rides on the end of the command as part of the skill's argument. Every
|
||||
@@ -465,6 +469,10 @@ export function resumeCommand({ workflow, specDir } = {}) {
|
||||
return "/plan2code-git";
|
||||
case "changelog":
|
||||
return "/plan2code-changelog";
|
||||
case "xray":
|
||||
return "/plan2code-xray";
|
||||
case "diagnose":
|
||||
return "/plan2code-diagnose";
|
||||
default:
|
||||
return dir ? `/plan2code-0-pathfinder ${dir}/pathfinder` : "/plan2code-0-pathfinder";
|
||||
}
|
||||
@@ -680,15 +688,26 @@ export const SKILL_CATALOG = [
|
||||
"A fresh-eyes pass over what changed: bugs, gaps, and the things the builder was too close to see. Problems come back ranked with a suggestion each, you pick which ones get fixed, and it fixes them.",
|
||||
},
|
||||
{
|
||||
skill: "plan2code-handoff",
|
||||
command: "/plan2code-handoff",
|
||||
workflow: "handoff",
|
||||
skill: "plan2code-xray",
|
||||
command: "/plan2code-xray",
|
||||
workflow: "xray",
|
||||
group: "extra",
|
||||
chip: "Utility",
|
||||
title: "Handoff",
|
||||
blurb: "Pack the current session into a document a fresh session can pick up cold.",
|
||||
title: "Codebase X-ray",
|
||||
blurb: "Explain how and why an area works, or find the rough spots worth fixing.",
|
||||
about:
|
||||
"Writes down everything a new session would need, as a single document: what was decided, what is done, what is left. Use it when a conversation got long, a machine changed, or tomorrow-you deserves the context today-you has.",
|
||||
"Two ways into code you did not write. Explain an area: how it works, step by step, and why it is that way, citing the files and the commits and pull requests behind it. Or find the rough spots: files that always change together, thin layers, tangled boundaries and busy code with no tests, ranked with a concrete example each. You tick the ones worth fixing and they become a brief for Pathfinder or Plan. It never changes code.",
|
||||
},
|
||||
{
|
||||
skill: "plan2code-diagnose",
|
||||
command: "/plan2code-diagnose",
|
||||
workflow: "diagnose",
|
||||
group: "extra",
|
||||
chip: "Utility",
|
||||
title: "Diagnose a bug",
|
||||
blurb: "Find a bug's cause and write it up, without fixing it.",
|
||||
about:
|
||||
"Something is broken and nobody knows why. Diagnose asks what goes wrong and how to see it, then builds a command that fails on the bug before it forms a theory. It narrows the cause down to a file and a function, says how sure it is, and sizes the fix. The write-up lands in a spec folder, and the dashboard then offers Quick Task to fix it, or Plan when the fix is big. It never changes code.",
|
||||
},
|
||||
{
|
||||
skill: "plan2code-changelog",
|
||||
@@ -712,6 +731,17 @@ export const SKILL_CATALOG = [
|
||||
about:
|
||||
"Shows your branch, what is ahead or behind, and every local and remote branch. Switch, create, delete or clean up branches, pull (rebasing when they have split, with help on conflicts), push or publish, and commit with a clear message. It asks before every push, publish and delete, and never force-pushes.",
|
||||
},
|
||||
{
|
||||
skill: "plan2code-handoff",
|
||||
command: "/plan2code-handoff",
|
||||
workflow: "handoff",
|
||||
group: "extra",
|
||||
chip: "Utility",
|
||||
title: "Handoff",
|
||||
blurb: "Pack the current session into a document a fresh session can pick up cold.",
|
||||
about:
|
||||
"Writes down everything a new session would need, as a single document: what was decided, what is done, what is left. Use it when a conversation got long, a machine changed, or tomorrow-you deserves the context today-you has.",
|
||||
},
|
||||
];
|
||||
|
||||
// A workflow by the name its dashboard card gives it ("Implement"), for the
|
||||
@@ -736,6 +766,8 @@ export const START_POSES = [
|
||||
"handoff",
|
||||
"git",
|
||||
"changelog",
|
||||
"xray",
|
||||
"diagnose",
|
||||
];
|
||||
|
||||
const POSE_ALIASES = { "init-update": "init", "revise-plan": "plan", "implement-review": "implement" };
|
||||
@@ -754,6 +786,8 @@ export function catalogEntry(skill) {
|
||||
// What the picker shows next to a spec's name — the pipeline position the
|
||||
// server's scan worked out, in plain words.
|
||||
export const SPEC_STATE_LABELS = {
|
||||
diagnosed: "Bug diagnosed",
|
||||
fixed: "Bug fixed",
|
||||
exploring: "Exploring",
|
||||
mapped: "Ready to plan",
|
||||
planned: "Ready to document",
|
||||
@@ -766,6 +800,7 @@ export const SPEC_STATE_LABELS = {
|
||||
// The card each spec state exists to light up. Used as the fallback for the
|
||||
// "Suggested" pill when the agent's menu payload names nothing.
|
||||
const NEXT_FOR_STATE = {
|
||||
diagnosed: "plan2code-quick-task",
|
||||
exploring: "plan2code-0-pathfinder",
|
||||
mapped: "plan2code-1-plan",
|
||||
planned: "plan2code-2-document",
|
||||
@@ -778,6 +813,16 @@ const ON = { on: true };
|
||||
export const GIT_INIT_NOTE = "Not a git repository yet: it offers to start one";
|
||||
export const pendingNote = (n) => `${n} file${n === 1 ? "" : "s"} to commit`;
|
||||
const off = (reason) => ({ on: false, reason });
|
||||
const FIXED_REASON = "This bug is fixed. Delete it with ✕, or move it to specs--completed/.";
|
||||
|
||||
/**
|
||||
* The spec the picker opens on: the most recently touched one that is still
|
||||
* in play. A fixed bug is finished, so it is never the default; with nothing
|
||||
* else on disk the picker opens on "start from scratch" (null).
|
||||
*/
|
||||
export function defaultSpec(specs) {
|
||||
return (Array.isArray(specs) ? specs : []).find((s) => s && s.state !== "fixed") || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a catalog card is clickable for the current picker selection.
|
||||
@@ -803,9 +848,13 @@ export function cardAvailability(entry, scan, sel) {
|
||||
case "plan2code-init-update":
|
||||
return hasAgents ? ON : off("Needs an AGENTS.md. Set the project up first.");
|
||||
case "plan2code-quick-task":
|
||||
// Always on; a diagnosed bug is the one spec it is the next step for.
|
||||
return next ? { ...ON, next } : ON;
|
||||
case "plan2code-review":
|
||||
case "plan2code-handoff":
|
||||
case "plan2code-changelog":
|
||||
case "plan2code-xray":
|
||||
case "plan2code-diagnose":
|
||||
return ON;
|
||||
case "plan2code-git":
|
||||
// Never greyed: a clean tree still has branches to switch, pull and push.
|
||||
@@ -814,9 +863,12 @@ export function cardAvailability(entry, scan, sel) {
|
||||
return ON;
|
||||
case "plan2code-0-pathfinder":
|
||||
if (!state || state === "exploring") return { ...ON, next };
|
||||
if (state === "diagnosed") return off("The cause is found. Fix it in a quick task, or plan it.");
|
||||
if (state === "fixed") return off(FIXED_REASON);
|
||||
return off("This spec is already past the questions");
|
||||
case "plan2code-1-plan":
|
||||
if (state === "exploring") return off("Pathfinder is not finished with this spec yet");
|
||||
if (state === "fixed") return off(FIXED_REASON);
|
||||
if (state === "documented" || state === "building" || state === "built")
|
||||
return off("The plan is written. Revise it instead if it moved.");
|
||||
return { ...ON, next };
|
||||
@@ -840,10 +892,21 @@ export function cardAvailability(entry, scan, sel) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* first. Every other card launches untargeted.
|
||||
*/
|
||||
export function launchTarget(entry, sel) {
|
||||
if (!entry || !sel) return null;
|
||||
if (entry.spec) return sel;
|
||||
return entry.skill === "plan2code-quick-task" && sel.state === "diagnosed" ? sel : null;
|
||||
}
|
||||
|
||||
export function cardPresentation(entry, scan, sel, menu = {}) {
|
||||
const availability = cardAvailability(entry, scan, sel);
|
||||
const specs = scan && Array.isArray(scan.specs) ? scan.specs : [];
|
||||
const initial = specs.length ? Boolean(sel && sel.dir === specs[0].dir) : !sel;
|
||||
const first = defaultSpec(scan && scan.specs);
|
||||
const initial = first ? Boolean(sel && sel.dir === first.dir) : !sel;
|
||||
const requested = initial && typeof menu.recommend === "string" ? catalogEntry(menu.recommend) : null;
|
||||
const recommendation = requested && cardAvailability(requested, scan, sel).on ? requested.skill : null;
|
||||
const recommended = availability.on && (recommendation ? entry.skill === recommendation : availability.next);
|
||||
@@ -871,6 +934,38 @@ export function launchReply(entry, spec) {
|
||||
return `Start ${entry.title} (${entry.command})${target}, right here in this session.`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deleting a spec from the picker. The page only names the folder; the agent
|
||||
* deletes it (`console.mjs delete-spec`, which runs lib.mjs's removeSpec() on
|
||||
* this same rule), because the console never writes into a project. A
|
||||
* deletable dir is exactly `specs/<one name>`: no deeper path, no `.` or `..`,
|
||||
* no dotfolder, no backslash, never specs--completed/.
|
||||
*/
|
||||
export function isDeletableSpecDir(dir) {
|
||||
return typeof dir === "string" && /^specs\/[^/\\]+$/.test(dir) && !/^specs\/\./.test(dir);
|
||||
}
|
||||
|
||||
export function deleteAction(spec) {
|
||||
return { i: "__delete", type: "delete", spec: spec.dir };
|
||||
}
|
||||
|
||||
export function deleteReply(spec) {
|
||||
return `Delete the spec folder ${spec.dir}/ for good, right here in this session.`;
|
||||
}
|
||||
|
||||
// What the delete dialog says about the spec, from the scan alone. `touched`
|
||||
// stays a number: the page formats it in the person's own locale.
|
||||
export function deleteSummary(spec) {
|
||||
const label = SPEC_STATE_LABELS[spec.state] || spec.state || "";
|
||||
const n = spec.files;
|
||||
return {
|
||||
folder: `${spec.dir}/`,
|
||||
stage: spec.detail ? `${label}: ${spec.detail}` : label,
|
||||
files: Number.isInteger(n) ? `${n} file${n === 1 ? "" : "s"}` : "",
|
||||
touched: Number.isFinite(spec.touched) && spec.touched > 0 ? spec.touched : null,
|
||||
};
|
||||
}
|
||||
|
||||
export function staleLaunchFeedback(title, adrift) {
|
||||
if (!adrift) return null;
|
||||
return {
|
||||
|
||||
@@ -2043,6 +2043,9 @@ h4.md-h, h5.md-h, h6.md-h { font-size: 15px; }
|
||||
.md-table th, .md-table td { border: 1px solid var(--rule); padding: 8px 11px; text-align: left; }
|
||||
.md-table th { background: var(--panel-2); font-weight: 600; }
|
||||
.md-img { max-width: 100%; border-radius: 8px; }
|
||||
.doc-figure { margin: 0 0 13px; }
|
||||
.doc-img { display: block; max-width: 100%; height: auto; border: 1px solid var(--rule); border-radius: 8px; }
|
||||
.doc-figure figcaption { font-size: 13px; color: var(--ink-2); margin-top: 6px; }
|
||||
.md a { color: var(--accent); }
|
||||
|
||||
/* ------------------------------------------------------------- footer */
|
||||
@@ -3053,6 +3056,50 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
|
||||
}
|
||||
.spec-chip:not(.is-sel) .spec-chip-state { color: var(--ink-3); }
|
||||
.spec-chip-detail { font-size: 11.5px; color: var(--ink-3); }
|
||||
/* A spec's Delete button sits beside its chip, not inside it: a button cannot
|
||||
hold a button. Quiet until the chip is hovered or focused. */
|
||||
.spec-chip-wrap { position: relative; display: flex; }
|
||||
.spec-chip-wrap.is-fixed .spec-chip:not(.is-sel) { opacity: 0.6; }
|
||||
.spec-chip-wrap .spec-chip { padding-right: 36px; }
|
||||
.spec-chip-del {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 6px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 0;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
color: var(--ink-3);
|
||||
font: inherit;
|
||||
font-size: 15px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.spec-chip-wrap:hover .spec-chip-del,
|
||||
.spec-chip-del:focus-visible { opacity: 1; }
|
||||
.spec-chip-del:hover { color: var(--warn); border-color: var(--warn); opacity: 1; }
|
||||
.spec-chip-del:focus-visible { outline: 2px solid var(--warn); outline-offset: 1px; }
|
||||
.spec-chip-del:disabled { cursor: default; opacity: 0.3; }
|
||||
.spec-chip-wrap.is-deleting .spec-chip { opacity: 0.5; }
|
||||
.delete-facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 14px 0 0; font-size: 13.5px; }
|
||||
.delete-facts dt { color: var(--ink-3); }
|
||||
.delete-facts dd { margin: 0; overflow-wrap: anywhere; }
|
||||
.delete-confirm { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; }
|
||||
.delete-confirm[hidden] { display: none; }
|
||||
.delete-confirm input {
|
||||
padding: 8px 10px;
|
||||
border: 1px solid var(--rule-2);
|
||||
border-radius: var(--radius);
|
||||
background: var(--panel);
|
||||
color: var(--ink);
|
||||
font: inherit;
|
||||
}
|
||||
.delete-confirm input:focus-visible { outline: 2px solid var(--warn); outline-offset: 1px; }
|
||||
|
||||
/* ------------------------------------------------- dashboard confirm */
|
||||
|
||||
@@ -3524,6 +3571,68 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
|
||||
/* Changelog -- the arm reaches the page and the newest line is written in step. */
|
||||
.pose .cl-line { animation: gc-dot 2.4s ease-in-out infinite; }
|
||||
|
||||
/* Codebase X-ray -- the scan line sweeps down the file, the rough spot lights
|
||||
up as it passes, and the lens and his star follow it down. */
|
||||
.pose .xr-scan { animation: xr-scan 4s ease-in-out infinite; }
|
||||
@keyframes xr-scan {
|
||||
0%, 10% { opacity: 0; transform: translateY(0); }
|
||||
16% { opacity: 1; }
|
||||
74% { opacity: 1; }
|
||||
80%, 100% { opacity: 0; transform: translateY(88px); }
|
||||
}
|
||||
.pose .xr-spot { animation: xr-spot 4s ease-out infinite; }
|
||||
@keyframes xr-spot {
|
||||
0%, 50% { opacity: 0; transform: scale(0.3); }
|
||||
56% { opacity: 1; transform: scale(1.3); }
|
||||
62%, 90% { opacity: 1; transform: scale(1); }
|
||||
100% { opacity: 0; transform: scale(1); }
|
||||
}
|
||||
.pose .xr-lens { animation: xr-lens 4s ease-in-out infinite; }
|
||||
@keyframes xr-lens {
|
||||
0%, 10%, 100% { transform: translate(0, -3px); }
|
||||
56%, 80% { transform: translate(0, 4px); }
|
||||
}
|
||||
.pose .xr-look { animation: xr-look 4s ease-in-out infinite; }
|
||||
@keyframes xr-look {
|
||||
0%, 10%, 100% { transform: translate(4px, -1px); }
|
||||
56%, 80% { transform: translate(4px, 2px); }
|
||||
}
|
||||
|
||||
/* Diagnose a bug -- the bug scuttles along its line, the magnifier and his
|
||||
star follow it until it is caught, and the red mark under the line shows
|
||||
once it holds still. Held still, the bug sits caught under the lens. */
|
||||
.pose .dg-mark { fill: none; stroke: var(--warn); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.pose .dg-leg { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
|
||||
.pose .dg-body { fill: var(--warn); }
|
||||
.pose .dg-head { fill: var(--ink); }
|
||||
.pose .dg-bug { animation: dg-bug 4s ease-in-out infinite; }
|
||||
@keyframes dg-bug {
|
||||
0%, 100% { transform: translate(-7px, 0) rotate(-12deg); }
|
||||
14% { transform: translate(-2px, 0) rotate(10deg); }
|
||||
26% { transform: translate(4px, 0) rotate(-10deg); }
|
||||
36% { transform: translate(1px, 0) rotate(8deg); }
|
||||
44%, 88% { transform: translate(0, 0) rotate(0deg); }
|
||||
}
|
||||
.pose .dg-lens { animation: dg-lens 4s ease-in-out infinite; }
|
||||
@keyframes dg-lens {
|
||||
0%, 100% { transform: translate(-9px, -2px); }
|
||||
18% { transform: translate(-3px, -1px); }
|
||||
30% { transform: translate(3px, 0); }
|
||||
44%, 88% { transform: translate(0, 0); }
|
||||
}
|
||||
.pose .dg-mark { animation: dg-mark 4s ease-out infinite; }
|
||||
@keyframes dg-mark {
|
||||
0%, 44% { opacity: 0; }
|
||||
52%, 88% { opacity: 1; }
|
||||
96%, 100% { opacity: 0; }
|
||||
}
|
||||
.pose .dg-look { animation: dg-look 4s ease-in-out infinite; }
|
||||
@keyframes dg-look {
|
||||
0%, 100% { transform: translate(2px, 0); }
|
||||
30% { transform: translate(5px, 0); }
|
||||
44%, 88% { transform: translate(4px, 1px); }
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.dash { padding-top: 0; }
|
||||
.launch-stage { height: 140px; }
|
||||
|
||||
+170
-18
@@ -22,6 +22,7 @@ import {
|
||||
briefPhrase,
|
||||
cardAvailability,
|
||||
cardPresentation,
|
||||
defaultSpec,
|
||||
CATALOG_GROUPS,
|
||||
choiceAnswer,
|
||||
DASHBOARD_COMMAND,
|
||||
@@ -42,6 +43,11 @@ import {
|
||||
IMAGE_QUALITY,
|
||||
lastOpenCard,
|
||||
launchReply,
|
||||
launchTarget,
|
||||
deleteAction,
|
||||
deleteReply,
|
||||
deleteSummary,
|
||||
isDeletableSpecDir,
|
||||
MAX_ATTACHMENTS,
|
||||
nextOpenAfter,
|
||||
MAX_DOC_BYTES,
|
||||
@@ -597,6 +603,8 @@ function fresh() {
|
||||
afterBuild: null,
|
||||
homeward: null,
|
||||
launching: null,
|
||||
// A picker Delete sent and not yet answered by a rescan: { dir, scanAt }.
|
||||
deleting: null,
|
||||
retract: {},
|
||||
chat: freshChat(),
|
||||
};
|
||||
@@ -812,13 +820,14 @@ const specList = () => {
|
||||
};
|
||||
|
||||
// The spec the picker currently targets. Absent `specSel` means the picker
|
||||
// has not been touched, so it defaults to the most recently touched spec —
|
||||
// the first entry of the server's already-sorted list. An explicit "start
|
||||
// from scratch" is stored as null, which is different.
|
||||
// has not been touched, so it defaults to the most recently touched spec
|
||||
// still in play (defaultSpec: the server's list is already sorted, and a
|
||||
// fixed bug is skipped). An explicit "start from scratch" is stored as null,
|
||||
// which is different.
|
||||
const selSpec = () => {
|
||||
const specs = specList();
|
||||
if (!specs.length) return null;
|
||||
if (local.specSel === undefined) return specs[0];
|
||||
if (local.specSel === undefined) return defaultSpec(specs);
|
||||
return specs.find((s) => s.dir === local.specSel) || null;
|
||||
};
|
||||
|
||||
@@ -1054,8 +1063,8 @@ function adopt(body) {
|
||||
const viaDashboard = prevWorkflow === "dashboard" || S.workflow === "dashboard";
|
||||
if (prevWorkflow && prevWorkflow !== S.workflow && viaDashboard) {
|
||||
// The pick rides into the skill it launched, never back home: arriving at
|
||||
// the dashboard, the picker starts on the most recently touched spec, the
|
||||
// one the agent's fresh menu recommends for.
|
||||
// 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 = S.workflow !== "dashboard" && "specSel" in local;
|
||||
local = { ...fresh(), launching: local.launching, ...(keepPick ? { specSel: local.specSel } : {}) };
|
||||
save();
|
||||
@@ -3056,7 +3065,9 @@ function updateDismissed() {
|
||||
}
|
||||
|
||||
const RELEASES_URL = "https://github.com/jparkerweb/plan2code/releases/";
|
||||
const UPDATE_COMMAND = "npx --allow-git=all git+https://github.com/jparkerweb/plan2code.git";
|
||||
const UPDATE_COMMAND = "plan2code update";
|
||||
// For a machine without the plan2code command: the full installer, menu and all.
|
||||
const UPDATE_FALLBACK_COMMAND = "npx --allow-git=all git+https://github.com/jparkerweb/plan2code.git";
|
||||
|
||||
function releasesLink(text) {
|
||||
const a = el("a", null, text);
|
||||
@@ -3079,6 +3090,9 @@ function openUpdateModal() {
|
||||
const row = $("update-command");
|
||||
const code = el("code", null, UPDATE_COMMAND);
|
||||
row.replaceChildren(code, copyButton(UPDATE_COMMAND, "btn small ghost handoff-copy", code));
|
||||
const fallbackRow = $("update-fallback");
|
||||
const fallback = el("code", null, UPDATE_FALLBACK_COMMAND);
|
||||
fallbackRow.replaceChildren(fallback, copyButton(UPDATE_FALLBACK_COMMAND, "btn small ghost handoff-copy", fallback));
|
||||
$("update-modal").showModal();
|
||||
}
|
||||
|
||||
@@ -3117,9 +3131,9 @@ function renderDashboard(main) {
|
||||
// The agent's note reads the spec the picker opened on (the same "initial"
|
||||
// test cardPresentation uses): another pick, or Start from scratch, gets
|
||||
// the neutral line rather than context about a spec no longer shown.
|
||||
const specsNow = (scan() && scan().specs) || [];
|
||||
const first = defaultSpec(scan() && scan().specs);
|
||||
const picked = selSpec();
|
||||
const onInitial = specsNow.length ? Boolean(picked && picked.dir === specsNow[0].dir) : !picked;
|
||||
const onInitial = first ? Boolean(picked && picked.dir === first.dir) : !picked;
|
||||
if (typeof menu.note === "string" && menu.note.trim() && onInitial) {
|
||||
wrap.appendChild(el("p", "dash-note", menu.note));
|
||||
} else if (!S.menu && agentWorking()) {
|
||||
@@ -3681,13 +3695,26 @@ function renderSpecPicker(specs) {
|
||||
});
|
||||
row.appendChild(scratch);
|
||||
|
||||
// A delete in flight ends when the agent's rescan lands (a new scan), gone
|
||||
// or refused: either way the picker below is the truth again.
|
||||
const sc = scan();
|
||||
if (local.deleting && sc && sc.at !== local.deleting.scanAt) {
|
||||
local.deleting = null;
|
||||
save();
|
||||
}
|
||||
for (const spec of specs) {
|
||||
const on = sel && sel.dir === spec.dir;
|
||||
// A fixed bug is finished: hidden while unavailable workflows are, dimmed
|
||||
// otherwise. A pick already on it stays visible, so it is never lost.
|
||||
const fixed = spec.state === "fixed";
|
||||
if (fixed && looks.hideUnavailable && !on) continue;
|
||||
const deleting = Boolean(local.deleting && local.deleting.dir === spec.dir);
|
||||
const wrap = el("div", "spec-chip-wrap" + (deleting ? " is-deleting" : "") + (fixed ? " is-fixed" : ""));
|
||||
const b = el("button", "spec-chip" + (on ? " is-sel" : ""));
|
||||
b.type = "button";
|
||||
b.setAttribute("aria-current", String(Boolean(on)));
|
||||
b.appendChild(el("span", "spec-chip-name", spec.name));
|
||||
b.appendChild(el("span", "spec-chip-state", SPEC_STATE_LABELS[spec.state] || spec.state));
|
||||
b.appendChild(el("span", "spec-chip-state", deleting ? "Deleting…" : SPEC_STATE_LABELS[spec.state] || spec.state));
|
||||
if (spec.detail) b.appendChild(el("span", "spec-chip-detail", spec.detail));
|
||||
b.addEventListener("click", () => {
|
||||
local.specSel = spec.dir;
|
||||
@@ -3695,7 +3722,17 @@ function renderSpecPicker(specs) {
|
||||
render();
|
||||
loadOverview();
|
||||
});
|
||||
row.appendChild(b);
|
||||
wrap.appendChild(b);
|
||||
if (isDeletableSpecDir(spec.dir)) {
|
||||
const del = el("button", "spec-chip-del", "✕");
|
||||
del.type = "button";
|
||||
del.title = `Delete ${spec.dir}/`;
|
||||
del.setAttribute("aria-label", `Delete the spec ${spec.name}`);
|
||||
del.disabled = deleting || Boolean(local.deleting) || gone || pendingResult || Boolean(local.launching);
|
||||
del.addEventListener("click", () => openDeleteConfirm(spec));
|
||||
wrap.appendChild(del);
|
||||
}
|
||||
row.appendChild(wrap);
|
||||
}
|
||||
box.appendChild(row);
|
||||
return box;
|
||||
@@ -3781,7 +3818,7 @@ function renderConfirm(main, entry) {
|
||||
|
||||
// A card that takes a spec names the one the picker is holding, so START
|
||||
// reads as "build THIS spec", not the skill in the abstract.
|
||||
const target = entry.spec ? selSpec() : null;
|
||||
const target = launchTarget(entry, selSpec());
|
||||
if (target) {
|
||||
const specLine = el("p", "confirm-spec");
|
||||
specLine.appendChild(el("span", null, "for "));
|
||||
@@ -3821,7 +3858,7 @@ function renderConfirm(main, entry) {
|
||||
// through the same wait loop. The dashboard reads `skill` off it.
|
||||
async function launchSkill(entry) {
|
||||
if (gone || pendingResult || local.launching || finish()) return;
|
||||
const target = entry.spec ? selSpec() : null;
|
||||
const target = launchTarget(entry, selSpec());
|
||||
// The card was clickable, so this should never fire — but a spec picked in
|
||||
// one tab could have shifted the ground under a stale render in another.
|
||||
if (!cardAvailability(entry, scan(), selSpec()).on) {
|
||||
@@ -3839,7 +3876,7 @@ async function launchSkill(entry) {
|
||||
};
|
||||
// The picker's spec goes to the skill being launched, not to the card:
|
||||
// cards that take no spec (utilities, setup) launch untargeted even while
|
||||
// a spec is selected.
|
||||
// a spec is selected, save Quick Task on a diagnosed bug.
|
||||
if (target) action.spec = target.dir;
|
||||
// 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
|
||||
@@ -5614,11 +5651,27 @@ function renderDoc(main, id) {
|
||||
box.appendChild(el("span", "block-tag", "Assumed for now, still open"));
|
||||
}
|
||||
if (b.state === "draft") box.appendChild(el("span", "block-tag", "Draft"));
|
||||
box.appendChild(md(b.md, "md"));
|
||||
box.appendChild(blockBody(b));
|
||||
main.appendChild(box);
|
||||
});
|
||||
}
|
||||
|
||||
// A block's content: its markdown, or for an image block (a screenshot the
|
||||
// agent saved under the session's shots/ folder) a captioned picture.
|
||||
function blockBody(b) {
|
||||
if (typeof b.image !== "string") return md(b.md, "md");
|
||||
const fig = el("figure", "doc-figure");
|
||||
const img = el("img", "doc-img");
|
||||
img.src = "/shots/" + b.image.split("/").pop();
|
||||
// The caption already says it: an alt repeating it is read twice, and shows
|
||||
// twice in an export whose picture would not load.
|
||||
img.alt = "";
|
||||
img.loading = "lazy";
|
||||
fig.appendChild(img);
|
||||
if (b.alt) fig.appendChild(el("figcaption", null, b.alt));
|
||||
return fig;
|
||||
}
|
||||
|
||||
function printButton() {
|
||||
const print = el("button", "btn small", "Print");
|
||||
print.type = "button";
|
||||
@@ -7495,6 +7548,88 @@ function openHomeConfirm() {
|
||||
$("home-modal").showModal();
|
||||
}
|
||||
|
||||
// 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.
|
||||
// Cancel, Escape or a click on Keep it at either step changes nothing.
|
||||
let deleteTarget = null;
|
||||
|
||||
function openDeleteConfirm(spec) {
|
||||
if (!isDeletableSpecDir(spec.dir) || gone || pendingResult || local.launching || local.deleting) return;
|
||||
deleteTarget = spec;
|
||||
const sum = deleteSummary(spec);
|
||||
$("delete-blurb").textContent = `Everything in ${sum.folder} will be deleted from this project.`;
|
||||
const facts = $("delete-facts");
|
||||
facts.replaceChildren();
|
||||
const fact = (term, value) => {
|
||||
if (!value) return;
|
||||
facts.appendChild(el("dt", "", term));
|
||||
facts.appendChild(el("dd", "", value));
|
||||
};
|
||||
fact("Spec", spec.name);
|
||||
fact("Folder", sum.folder);
|
||||
fact("Stage", sum.stage);
|
||||
fact("Files", sum.files);
|
||||
fact("Last changed", sum.touched ? new Date(sum.touched).toLocaleString() : "");
|
||||
$("delete-name-hint").textContent = spec.name;
|
||||
$("delete-name").value = "";
|
||||
$("delete-confirm").hidden = true;
|
||||
const go = $("delete-go");
|
||||
go.textContent = "Delete this spec…";
|
||||
go.classList.remove("is-on");
|
||||
go.disabled = false;
|
||||
$("delete-modal").showModal();
|
||||
}
|
||||
|
||||
function deleteStep() {
|
||||
const go = $("delete-go");
|
||||
if (!deleteTarget) return;
|
||||
if ($("delete-confirm").hidden) {
|
||||
$("delete-confirm").hidden = false;
|
||||
go.textContent = "Delete for good";
|
||||
go.classList.add("is-on");
|
||||
go.disabled = true;
|
||||
$("delete-name").focus();
|
||||
return;
|
||||
}
|
||||
if ($("delete-name").value.trim() !== deleteTarget.name) return;
|
||||
sendDelete(deleteTarget);
|
||||
}
|
||||
|
||||
async function sendDelete(spec) {
|
||||
const go = $("delete-go");
|
||||
go.disabled = true;
|
||||
try {
|
||||
const res = await fetch("/submit", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ actions: [deleteAction(spec)], reply: deleteReply(spec) }),
|
||||
});
|
||||
if (res.status === 409) throw Object.assign(new Error("pending"), { pending: true });
|
||||
if (!res.ok) throw new Error(String(res.status));
|
||||
const sc = scan();
|
||||
local.deleting = { dir: spec.dir, scanAt: sc ? sc.at : null };
|
||||
// The selection must not outlive the folder: back to the default pick,
|
||||
// which the agent's fresh menu recommends for.
|
||||
if (local.specSel === spec.dir) delete local.specSel;
|
||||
pendingResult = true;
|
||||
save();
|
||||
$("delete-modal").close();
|
||||
} catch (err) {
|
||||
$("delete-modal").close();
|
||||
if (err && err.pending) pendingResult = true;
|
||||
banner(
|
||||
err && err.pending
|
||||
? "Your last pick is still being picked up, so that could not go yet. Nothing was deleted; try again in a moment."
|
||||
: "That did not go through. Nothing was deleted; try again.",
|
||||
"warn"
|
||||
);
|
||||
} finally {
|
||||
deleteTarget = null;
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
async function goHome() {
|
||||
const go = $("home-go");
|
||||
go.disabled = true;
|
||||
@@ -7847,7 +7982,7 @@ function downloadDoc(doc) {
|
||||
// assumptions or drafts. Without the marks a half-finished document reads,
|
||||
// once it leaves the page, as a set of decisions.
|
||||
const mark = { assumed: "> **Assumed for now, still open.**\n\n", draft: "> **Draft.**\n\n" };
|
||||
const blocks = (doc.blocks || []).map((b) => (mark[b.state] || "") + (b.md || ""));
|
||||
const blocks = (doc.blocks || []).map((b) => (mark[b.state] || "") + (typeof b.image === "string" ? b.alt || "" : b.md || ""));
|
||||
const first = (doc.blocks || [])[0];
|
||||
const titled = first && /^\s*#\s/.test(first.md || "");
|
||||
const body = [titled || !doc.title ? null : `# ${doc.title}`, ...blocks].filter((x) => x != null).join("\n\n");
|
||||
@@ -7910,6 +8045,9 @@ h4.md-h, h5.md-h, h6.md-h { font-size: 15px; }
|
||||
.md-table th, .md-table td { border: 1px solid #e4ddd1; padding: 8px 11px; text-align: left; }
|
||||
.md-table th { background: #fbf9f6; font-weight: 600; }
|
||||
.md-img { max-width: 100%; border-radius: 8px; }
|
||||
.doc-figure { margin: 0 0 13px; }
|
||||
.doc-img { display: block; max-width: 100%; border: 1px solid #e4ddd1; border-radius: 8px; }
|
||||
.doc-figure figcaption { font-size: 13px; color: #5d564d; margin-top: 6px; }
|
||||
.md a { color: #206cc3; }
|
||||
@media print {
|
||||
body { background: #fff; }
|
||||
@@ -7922,7 +8060,7 @@ h4.md-h, h5.md-h, h6.md-h { font-size: 15px; }
|
||||
// address on this origin (/state, say) would copy session data into something
|
||||
// meant to be shared. A remote image keeps its own address; anything else on
|
||||
// this origin becomes its alt text.
|
||||
const INLINE_UPLOAD = /^\/uploads\/[0-9a-f-]{36}\.jpg$/;
|
||||
const INLINE_UPLOAD = /^\/(?:uploads\/[0-9a-f-]{36}\.jpg|shots\/[A-Za-z0-9][A-Za-z0-9._-]{0,99}\.(?:png|jpe?g|webp))$/i;
|
||||
|
||||
function imageToAlt(img) {
|
||||
const alt = img.getAttribute("alt") || "";
|
||||
@@ -7977,7 +8115,7 @@ async function downloadDocHtml(doc) {
|
||||
const box = el("div", "block " + (b.state || "settled"));
|
||||
if (b.state === "assumed") box.appendChild(el("span", "block-tag", "Assumed for now, still open"));
|
||||
if (b.state === "draft") box.appendChild(el("span", "block-tag", "Draft"));
|
||||
box.appendChild(md(b.md, "md"));
|
||||
box.appendChild(blockBody(b));
|
||||
body.appendChild(box);
|
||||
}
|
||||
// Copy buttons only work inside the console.
|
||||
@@ -8160,6 +8298,20 @@ function openHelpOn(id) {
|
||||
|
||||
$("btn-home").addEventListener("click", openHomeConfirm);
|
||||
$("update-done").addEventListener("click", () => $("update-modal").close());
|
||||
$("delete-cancel").addEventListener("click", () => $("delete-modal").close());
|
||||
$("delete-go").addEventListener("click", deleteStep);
|
||||
$("delete-name").addEventListener("input", () => {
|
||||
$("delete-go").disabled = !deleteTarget || $("delete-name").value.trim() !== deleteTarget.name;
|
||||
});
|
||||
$("delete-name").addEventListener("keydown", (e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
deleteStep();
|
||||
}
|
||||
});
|
||||
$("delete-modal").addEventListener("close", () => {
|
||||
deleteTarget = null;
|
||||
});
|
||||
$("home-cancel").addEventListener("click", () => $("home-modal").close());
|
||||
$("home-go").addEventListener("click", goHome);
|
||||
$("btn-stop").addEventListener("click", openStopConfirm);
|
||||
|
||||
@@ -595,6 +595,75 @@
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
<!-- Codebase X-ray: seeing how it works. He holds a lens up to a file,
|
||||
a scan line sweeps down it to show the structure inside, and a rough
|
||||
spot lights up as the scan passes over it. -->
|
||||
<svg class="pose pose-xray" data-pose="xray" viewBox="0 4 240 216" aria-hidden="true" focusable="false">
|
||||
<ellipse class="shadow" cx="126" cy="198" rx="44" ry="5" />
|
||||
<g class="prop">
|
||||
<rect class="sh" x="182" y="60" width="44" height="112" rx="6" />
|
||||
<line class="lt" x1="196" y1="76" x2="196" y2="152" />
|
||||
<path class="lt" d="M196 96 L212 96 M196 124 L212 124" />
|
||||
<circle class="ac" cx="196" cy="76" r="4" />
|
||||
<circle class="ac" cx="212" cy="96" r="3.5" />
|
||||
<circle class="ac" cx="212" cy="124" r="3.5" />
|
||||
<circle class="ac" cx="196" cy="152" r="4" />
|
||||
<g class="xr-spot"><circle class="as" cx="212" cy="124" r="8" /></g>
|
||||
<line class="as xr-scan" x1="188" y1="70" x2="220" y2="70" />
|
||||
</g>
|
||||
<g class="bob">
|
||||
<g transform="translate(-14 0)">
|
||||
<rect class="fl foot f1" x="94" y="179" width="20" height="10" rx="5" />
|
||||
<rect class="fl foot f2" x="126" y="179" width="20" height="10" rx="5" />
|
||||
<rect class="sh" x="80" y="72" width="80" height="108" rx="16" />
|
||||
<path class="ln" d="M80 126 L66 150" /><circle class="fl" cx="66" cy="150" r="5.5" />
|
||||
<g class="xr-look"><path class="ey blink" d="M126 86 L129.64 94.98 L139.31 95.67 L131.9 101.92 L134.23 111.33 L126 106.2 L117.77 111.33 L120.1 101.92 L112.69 95.67 L122.36 94.98 Z" /></g>
|
||||
<path class="es" d="M110 120 Q122 129 134 120" />
|
||||
<line class="ln" x1="160" y1="126" x2="192" y2="132" />
|
||||
<g class="xr-lens">
|
||||
<line class="ln" x1="192" y1="132" x2="204" y2="120" />
|
||||
<circle class="lt" cx="214" cy="110" r="14" />
|
||||
</g>
|
||||
<circle class="fl" cx="192" cy="132" r="5.5" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
<!-- Diagnose a bug: finding the cause. A small bug scuttles along one
|
||||
line of a file, his magnifier follows it until it is caught, and the
|
||||
line it sits on is marked in red. He looks, he does not fix. -->
|
||||
<svg class="pose pose-diagnose" data-pose="diagnose" viewBox="0 4 240 216" aria-hidden="true" focusable="false">
|
||||
<ellipse class="shadow" cx="126" cy="198" rx="44" ry="5" />
|
||||
<g class="prop">
|
||||
<rect class="sh" x="176" y="60" width="46" height="112" rx="6" />
|
||||
<line class="lt" x1="184" y1="78" x2="208" y2="78" />
|
||||
<line class="lt" x1="188" y1="96" x2="214" y2="96" />
|
||||
<path class="dg-mark" d="M184 124 Q187 120 190 124 T196 124 T202 124 T208 124 T214 124" />
|
||||
<line class="lt" x1="188" y1="142" x2="208" y2="142" />
|
||||
<line class="lt" x1="184" y1="158" x2="202" y2="158" />
|
||||
<g class="dg-bug">
|
||||
<path class="dg-leg" d="M195 111 L189 108 M195 115 L189 115 M195 119 L189 122 M205 111 L211 108 M205 115 L211 115 M205 119 L211 122 M198 104 L195 99 M202 104 L205 99" />
|
||||
<ellipse class="dg-body" cx="200" cy="115" rx="5.5" ry="7" />
|
||||
<circle class="dg-head" cx="200" cy="106" r="3.2" />
|
||||
</g>
|
||||
</g>
|
||||
<g class="bob">
|
||||
<g transform="translate(-14 0)">
|
||||
<rect class="fl foot f1" x="94" y="179" width="20" height="10" rx="5" />
|
||||
<rect class="fl foot f2" x="126" y="179" width="20" height="10" rx="5" />
|
||||
<rect class="sh" x="80" y="72" width="80" height="108" rx="16" />
|
||||
<path class="ln" d="M80 126 L66 150" /><circle class="fl" cx="66" cy="150" r="5.5" />
|
||||
<g class="dg-look"><path class="ey blink" d="M126 86 L129.64 94.98 L139.31 95.67 L131.9 101.92 L134.23 111.33 L126 106.2 L117.77 111.33 L120.1 101.92 L112.69 95.67 L122.36 94.98 Z" /></g>
|
||||
<path class="ln" d="M113 82 Q126 77 139 83" />
|
||||
<line class="es" x1="114" y1="124" x2="128" y2="124" />
|
||||
<line class="ln" x1="160" y1="126" x2="174" y2="140" />
|
||||
<g class="dg-lens">
|
||||
<line class="ln" x1="174" y1="140" x2="180" y2="127" />
|
||||
<circle class="lt" cx="186" cy="114" r="14" />
|
||||
</g>
|
||||
<circle class="fl" cx="174" cy="140" r="5.5" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
<!-- The Help dialog's content, cloned into #help-modal the first time ? is
|
||||
@@ -1546,7 +1615,7 @@
|
||||
<p>
|
||||
When a newer Plan2Code release is out, the dashboard shows
|
||||
<strong>UPDATE AVAILABLE</strong> at the top. Click it for the command
|
||||
to run in your terminal; × hides it until the next
|
||||
to run in your terminal, <code>plan2code update</code>; × hides it until the next
|
||||
<code>/plan2code</code>. The version at the bottom of Help links to
|
||||
the Releases page.
|
||||
</p>
|
||||
@@ -1574,6 +1643,8 @@
|
||||
<li><strong>Handoff.</strong> Pack the current session into a document a fresh session can pick up cold.</li>
|
||||
<li><strong>Changelog.</strong> Checks the CHANGELOG version against the main branch and suggests entries for what is new.</li>
|
||||
<li><strong>Git.</strong> Branches, pull, push and commits on one board, asking before anything leaves your machine. See "The git board".</li>
|
||||
<li><strong>Codebase X-ray.</strong> Explains how and why an area of the code works, or finds the rough spots worth fixing.</li>
|
||||
<li><strong>Diagnose a bug.</strong> Finds a bug's cause and writes it up without fixing it, ready to hand to Quick Task or Plan.</li>
|
||||
</ul>
|
||||
<h4>Picking a spec</h4>
|
||||
<p>
|
||||
@@ -2520,6 +2591,24 @@
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<!-- Deleting a spec from the dashboard's picker. Two deliberate steps: the
|
||||
first says what goes and that it is for good, the second wants the
|
||||
spec's name typed. The page only asks; the agent deletes. -->
|
||||
<dialog class="modal" id="delete-modal" aria-labelledby="delete-title">
|
||||
<h2 id="delete-title">Delete this spec?</h2>
|
||||
<p class="modal-blurb" id="delete-blurb"></p>
|
||||
<dl class="delete-facts" id="delete-facts"></dl>
|
||||
<p class="modal-why" id="delete-warn">This is permanent. <code>specs/</code> is not tracked by git, so nothing can bring these files back.</p>
|
||||
<div class="delete-confirm" id="delete-confirm" hidden>
|
||||
<label for="delete-name">To delete it for good, type <strong id="delete-name-hint"></strong></label>
|
||||
<input type="text" id="delete-name" autocomplete="off" spellcheck="false" />
|
||||
</div>
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn ghost" id="delete-cancel">Keep it</button>
|
||||
<button type="button" class="btn danger" id="delete-go">Delete this spec…</button>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<dialog class="modal" id="home-modal" aria-labelledby="home-title">
|
||||
<h2 id="home-title">Leave this workflow?</h2>
|
||||
<p class="modal-blurb" id="home-blurb"></p>
|
||||
@@ -2570,7 +2659,7 @@
|
||||
</dialog>
|
||||
|
||||
<!-- Opened from the dashboard's UPDATE AVAILABLE banner. The versions and
|
||||
the copy row are filled by app.js; the update itself runs in a
|
||||
the two copy rows are filled by app.js; the update itself runs in a
|
||||
terminal, never from this page. -->
|
||||
<dialog class="modal" id="update-modal" aria-labelledby="update-title">
|
||||
<h2 id="update-title">A new Plan2Code is available</h2>
|
||||
@@ -2579,7 +2668,11 @@
|
||||
<li>
|
||||
Run this in your terminal (not in this page or your agent):
|
||||
<div class="update-command" id="update-command"></div>
|
||||
It opens the installer's menu. Back at your prompt with no output at all? npm
|
||||
It updates everything that was installed (the skills, the <code>plan2code</code>
|
||||
command and any extras you added), with no menu. If the <code>plan2code</code>
|
||||
command is not installed, run this instead:
|
||||
<div class="update-command" id="update-fallback"></div>
|
||||
Back at your prompt with no output at all? npm
|
||||
could not reach the repository and hid the reason: run
|
||||
<code>git ls-remote https://github.com/jparkerweb/plan2code.git</code> to see it.
|
||||
</li>
|
||||
|
||||
@@ -30,14 +30,16 @@ export const WEIGHTS = Object.freeze({
|
||||
"git-commits": 0,
|
||||
"git-conflict": 1,
|
||||
changelog: 1,
|
||||
xray: 1,
|
||||
diagnose: 1,
|
||||
});
|
||||
|
||||
// Workflows whose launch itself scores WEIGHTS[workflow]. Pathfinder,
|
||||
// implement and implement-review score only through the agent's `run`
|
||||
// reports; dashboard and handoff never score; git and changelog score 1 on
|
||||
// reports; dashboard and handoff never score; git, changelog, xray and diagnose score 1 on
|
||||
// launch (Git then adds its commit tally and conflict help).
|
||||
export const LAUNCH_COUNTED = Object.freeze(
|
||||
new Set(["plan", "revise-plan", "document", "review", "quick-task", "init", "init-update", "finalize", "git", "changelog"])
|
||||
new Set(["plan", "revise-plan", "document", "review", "quick-task", "init", "init-update", "finalize", "git", "changelog", "xray", "diagnose"])
|
||||
);
|
||||
|
||||
// Git's commits weigh what they add up to: each `git-commits` run carries
|
||||
@@ -140,6 +142,8 @@ const WORKFLOW_NAMES = Object.freeze({
|
||||
handoff: "Handoff",
|
||||
git: "Git",
|
||||
changelog: "Changelog",
|
||||
xray: "X-ray",
|
||||
diagnose: "Diagnose",
|
||||
});
|
||||
|
||||
// The skill run an entry belongs to, from its ledger id ("L3:..." -> "L3").
|
||||
@@ -157,6 +161,8 @@ const LAUNCH_LABELS = Object.freeze({
|
||||
finalize: "Finalize started",
|
||||
git: "Git started",
|
||||
changelog: "Changelog started",
|
||||
xray: "X-ray started",
|
||||
diagnose: "Diagnose started",
|
||||
});
|
||||
const RUN_LABELS = Object.freeze({
|
||||
"pathfinder-chart": "Pathfinder map written",
|
||||
@@ -177,6 +183,8 @@ const RUN_LABELS = Object.freeze({
|
||||
"git-commits": "Commits in Git",
|
||||
"git-conflict": "Git conflict help",
|
||||
changelog: "Changelog run",
|
||||
xray: "X-ray run",
|
||||
diagnose: "Diagnose run",
|
||||
});
|
||||
|
||||
// The unit a run names, from its ledger id ("L3:phase-2" -> "phase-2").
|
||||
|
||||
@@ -24,7 +24,7 @@ export const SUBAGENT_WORKFLOWS = Object.freeze({
|
||||
}),
|
||||
review: Object.freeze({
|
||||
instruction:
|
||||
"Split the review across helpers by area (for example correctness, tests and security), then merge and de-duplicate their findings yourself before you report.",
|
||||
"Run the review's analysis in one fresh helper briefed only with the spec and the change set (references/reviewer-brief.md); verify every finding yourself before you report.",
|
||||
}),
|
||||
pathfinder: Object.freeze({
|
||||
instruction:
|
||||
|
||||
@@ -54,6 +54,9 @@ import {
|
||||
rememberedWorkspace,
|
||||
removeCleanup,
|
||||
remoteWarning,
|
||||
SHOTS_DIR_NAME,
|
||||
SHOT_NAME,
|
||||
shotType,
|
||||
saveSubagentStoreEntry,
|
||||
PR_HOST_KINDS,
|
||||
savePrHost,
|
||||
@@ -131,6 +134,25 @@ const EXT_ALT = UPLOAD_EXTS.join("|");
|
||||
const UPLOAD_ANY_ROUTE = new RegExp(`^/uploads/([0-9a-f-]{36})\\.(${EXT_ALT})$`);
|
||||
const UPLOAD_NAME = new RegExp(`^[0-9a-f-]{36}\\.(${EXT_ALT})$`);
|
||||
|
||||
// Screenshots the agent saved for a doc's image block (Show me it working),
|
||||
// only ever directly inside <session>/shots/ under SHOT_NAME's plain shape.
|
||||
const SHOTS_DIR = path.join(DIR, SHOTS_DIR_NAME);
|
||||
const SHOT_TYPES = { png: "image/png", jpeg: "image/jpeg", webp: "image/webp" };
|
||||
|
||||
function shotPath(name) {
|
||||
if (!SHOT_NAME.test(name)) return null;
|
||||
const file = path.resolve(SHOTS_DIR, name);
|
||||
if (!file.startsWith(path.resolve(SHOTS_DIR) + path.sep)) return null;
|
||||
try {
|
||||
const real = fs.realpathSync.native(file);
|
||||
const fold = (p) => (process.platform === "win32" || process.platform === "darwin" ? p.toLowerCase() : p);
|
||||
if (fold(path.dirname(real)) !== fold(fs.realpathSync.native(SHOTS_DIR))) return null;
|
||||
return fs.statSync(real).isFile() ? real : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// A kept attachment's name, as attachmentName() in lib.mjs writes it:
|
||||
// <slug>-<first 8 of the upload id>.<the upload's extension>.
|
||||
const KEPT_ROUTE = new RegExp(`^/attachments/([a-z0-9-]{1,40}-[0-9a-f-]{8}\\.(${EXT_ALT}))$`);
|
||||
@@ -1468,6 +1490,25 @@ const server = http.createServer((req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
// A screenshot for a doc's image block. Matched on the raw request line too,
|
||||
// like uploads: anything URL parsing had to fold (`..`) is not a shot.
|
||||
if (pathname.startsWith("/shots/") || req.url.startsWith("/shots/")) {
|
||||
if (req.method !== "GET") return json(res, 405, { error: "method" });
|
||||
const name = pathname.slice("/shots/".length);
|
||||
const file = req.url === pathname ? shotPath(name) : null;
|
||||
if (!file) return json(res, 404, { error: "not found" });
|
||||
let buf;
|
||||
try {
|
||||
buf = fs.readFileSync(file);
|
||||
} catch {
|
||||
return json(res, 404, { error: "not found" });
|
||||
}
|
||||
// The bytes, not the name, pick the type: the file may have changed since it was posted.
|
||||
const type = SHOT_TYPES[shotType(buf)];
|
||||
if (!type) return json(res, 404, { error: "not found" });
|
||||
return send(res, 200, buf, type, { "cache-control": "no-store" });
|
||||
}
|
||||
|
||||
// Matched on the raw request line as well as the parsed path: URL parsing
|
||||
// folds `..` segments away, and nothing that needed folding is an upload.
|
||||
// GET and DELETE take images and documents alike.
|
||||
|
||||
Reference in new issue
Block a user