mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-17 04:45:33 -08:00
Sync upstream web console updates into v2.4.2: on-demand Cleanup of unused ~/.plan2code files, an UPDATE AVAILABLE banner from the release tags, a colored launcher with a Planny banner, Notes threads that keep the person's notes and read older reply shapes, the repo-local plan2code-model-update maintainer skill, and review fixes (413 for oversize bodies, notes kept on skip, scoped reconnect banner, live Overview tab, busy state on 409, menu keyboard focus, case-insensitive mentions)
This commit is contained in:
1 parent
f968aeded8
commit
c19a072a3a
165 files changed
+13025
-1234
No files matched your search
@@ -243,7 +243,7 @@ summarise it back.
|
||||
Then, in ONE `post`, do all of:
|
||||
|
||||
- mark each answered item `"status": "answered"` and record its `answer`
|
||||
- add your replies to any comment threads
|
||||
- reply to every note in that item's `thread` (shape below)
|
||||
- answer any Quick questions that came with it, in `chat.replies` (see Quick
|
||||
questions)
|
||||
- publish the next batch of questions
|
||||
@@ -251,6 +251,26 @@ Then, in ONE `post`, do all of:
|
||||
|
||||
One post is one atomic update, so the page never shows a half-changed state.
|
||||
|
||||
### Replying to a note
|
||||
|
||||
A `comment` is the person talking to you about that card, often asking
|
||||
something. It shows in the card's **Notes on this** panel, and so does your
|
||||
answer:
|
||||
|
||||
```jsonc
|
||||
{ "items": [{ "id": "p4", "thread": [
|
||||
{ "who": "agent", "text": "A proxy is the server some company networks route traffic through. **Markdown** is fine." }
|
||||
] }] }
|
||||
```
|
||||
|
||||
- Every entry is `{ "who": "agent", "text": "<markdown>" }`. `text`, not
|
||||
`md`: the page reads nothing else. An entry with no `text` is rejected.
|
||||
- The server writes their note into the thread as it arrives. Do not repeat
|
||||
it, and send only your new entries: `thread` appends.
|
||||
- Answer what they asked, in the thread, even when you also change a doc or
|
||||
re-ask the question. "I've updated the doc" alone leaves the question in the
|
||||
panel with no answer under it.
|
||||
|
||||
### Recording the answer
|
||||
|
||||
`answer` takes the same shape the item gave back: `{ "k": "A" }`, `{ "ks": ["A","C"] }`,
|
||||
@@ -661,9 +681,17 @@ finish are dropped, so you start on a blank page and post your own. A skill
|
||||
run inline from another (a quick task's review) keeps the page it was
|
||||
handed. A
|
||||
fresh `open` would strand the page the person is watching on the dashboard's
|
||||
session while your questions went to a page nobody has open. Then run the
|
||||
skill normally: its Interface question was already answered by being
|
||||
launched, so start where its real work starts.
|
||||
session while your questions went to a page nobody has open.
|
||||
|
||||
> **Never hand this to a skill-invocation tool. Open its `SKILL.md` with your
|
||||
> own file-read tool and follow it from the top instead.** Every Plan2Code
|
||||
> skill below the dashboard ships `disable-model-invocation: true` on
|
||||
> purpose — it exists to be read and followed inline, not launched as a
|
||||
> sub-skill — and calling one through a skill-invocation tool errors out and
|
||||
> strands the hand-off mid-launch.
|
||||
|
||||
Its Interface step is already answered by having been launched, so start
|
||||
where its real work starts.
|
||||
|
||||
The menu itself is the page's own list — you never send it. The page knows
|
||||
the repo too: `open` scans `AGENTS.md` and `specs/` into `state.scan`
|
||||
@@ -829,6 +857,12 @@ know:
|
||||
| 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). |
|
||||
|
||||
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
|
||||
implementation — the same way Review does. A step with no card of its own
|
||||
(2, 3) is otherwise a stretch of silence the page can only show as "Starting
|
||||
Finalize".
|
||||
|
||||
Pass `--spec specs/<feature>` to `open`, or post `specDir` once you know it.
|
||||
Stopping mid-finalize loses nothing
|
||||
— the specs are untouched until Step 3's summary write — so a stop's finish
|
||||
@@ -859,7 +893,7 @@ question or doc lands:
|
||||
`{"agent":{"status":"working","activity":"Reading the plan"}}`.
|
||||
|
||||
The patch merges: scalars replace, `null` deletes a key, `items` / `topics` / `docs`
|
||||
merge by `id` (an unknown id is added), and `thread` / `comments` append. Send only
|
||||
merge by `id` (an unknown id is added), and `thread` appends. Send only
|
||||
what changed. A whole-file rewrite would put the entire session back into your
|
||||
context on every turn.
|
||||
|
||||
@@ -1239,7 +1273,7 @@ answers were submitted but never picked up.
|
||||
| You started subagents or background jobs | Wait for every one to report back before `finish`, posting `working` with a count meanwhile. A finish while they run tells the person it is safe to close the terminal, and that kills them. |
|
||||
| Any session end, not only the last one | Also post `finish`: an off-ramp that routes elsewhere, a checkpoint that saves and stops, a stop request. Anything that ends the session without it leaves the page promising a question that is not coming. |
|
||||
| Picking up a paused session | `open --resume <sid>` (or `open --session <sid>`) clears a paused `finish` itself, and the questions left open at the pause with it: the finish body already said what was still open, so re-ask whatever the new session needs in your own words rather than leaving the old asks on the page as duplicates. Settled items stay. For any other ending you are deliberately taking back, post `"finish": null` in your first patch. |
|
||||
| The same result arrives twice | Your harness killed `wait` after it handed the result over but before it recorded that. Handle it once. Most of a repeated patch is harmless, because items merge by id, but `thread` and `comments` **append**: leave out any thread entry you already sent, or the person sees your reply twice. |
|
||||
| The same result arrives twice | Your harness killed `wait` after it handed the result over but before it recorded that. Handle it once. Most of a repeated patch is harmless, because items merge by id, but `thread` **appends**: leave out any thread entry you already sent, or the person sees your reply twice. |
|
||||
| The same chat arrives twice | Replies merge by `id`, so re-post the same reply if it is not on the page yet; do not answer the question a second time. |
|
||||
| `node` is missing, or older than 18 | One line, then the terminal. Do not try to install anything. |
|
||||
|
||||
|
||||
@@ -48,6 +48,10 @@ export const USER_MODELS_FILE = path.join(PLAN2CODE_DIR, "models.json");
|
||||
|
||||
export const LOOKS_FILE = path.join(HOME_DIR, "looks.json");
|
||||
|
||||
// The newest Plan2Code release tag, as last asked of GitHub (update-check.mjs),
|
||||
// so every session within the hour reuses one lookup.
|
||||
export const UPDATE_CHECK_FILE = path.join(HOME_DIR, "update-check.json");
|
||||
|
||||
// The runtime dir has to follow PLAN2CODE_CONSOLE_HOME too. Without that, a
|
||||
// test run (or a second sandboxed instance) shares one handle directory with
|
||||
// the real thing, and `stop --all` reaches outside its own world and kills a
|
||||
@@ -487,9 +491,9 @@ export async function removeSessions(sessionsDir, sids) {
|
||||
}
|
||||
|
||||
// The console folder's own files that no sweep may ever remove: the person's
|
||||
// looks, the folders remembered per project and spec, and the pointer to
|
||||
// this console's directory.
|
||||
export const PROTECTED_CONSOLE_FILES = new Set(["looks.json", "workspaces.json", "console-dir"]);
|
||||
// looks, the folders remembered per project and spec, the pointer to this
|
||||
// console's directory, and the cached release check.
|
||||
export const PROTECTED_CONSOLE_FILES = new Set(["looks.json", "workspaces.json", "console-dir", "update-check.json"]);
|
||||
|
||||
function isScratchName(name) {
|
||||
return (
|
||||
@@ -536,6 +540,148 @@ export async function removeScratch(consoleDir, names) {
|
||||
return removed;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- cleanup */
|
||||
|
||||
// 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.
|
||||
const KEPT_CONSOLE_ENTRIES = new Set([...PROTECTED_CONSOLE_FILES, "sessions", "runtime"]);
|
||||
export const KEPT_PLAN2CODE_ENTRIES = new Set(["console", "bin", "launcher.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
|
||||
// rename -- and removing one mid-write loses another session's change.
|
||||
export const STRAY_GRACE_MS = 60 * 60 * 1000;
|
||||
|
||||
// Bytes under `p`, never following a symlink: a link counts as itself.
|
||||
async function diskBytes(p) {
|
||||
let st;
|
||||
try {
|
||||
st = await fs.promises.lstat(p);
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
if (!st.isDirectory()) return st.size;
|
||||
let entries;
|
||||
try {
|
||||
entries = await fs.promises.readdir(p);
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
let total = 0;
|
||||
for (const name of entries) total += await diskBytes(path.join(p, name));
|
||||
return total;
|
||||
}
|
||||
|
||||
// The newest mtime of anything under `p`, never following a symlink. A folder
|
||||
// counts by its files, since rewriting a file never touches its folder's
|
||||
// mtime; an empty folder counts by its own. Anything unreadable on the way
|
||||
// down answers Infinity, so it reads as just touched and stays.
|
||||
function newestMtime(p) {
|
||||
let st;
|
||||
try {
|
||||
st = fs.lstatSync(p);
|
||||
} catch {
|
||||
return Infinity;
|
||||
}
|
||||
if (!st.isDirectory()) return st.mtimeMs;
|
||||
let entries;
|
||||
try {
|
||||
entries = fs.readdirSync(p);
|
||||
} catch {
|
||||
return Infinity;
|
||||
}
|
||||
if (!entries.length) return st.mtimeMs;
|
||||
let newest = 0;
|
||||
for (const name of entries) newest = Math.max(newest, newestMtime(path.join(p, name)));
|
||||
return newest;
|
||||
}
|
||||
|
||||
function entryKind(entry) {
|
||||
if (entry.isSymbolicLink()) return "link";
|
||||
return entry.isDirectory() ? "folder" : "file";
|
||||
}
|
||||
|
||||
function strayEntries(dir, kept, where, now) {
|
||||
let entries;
|
||||
try {
|
||||
entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
const settled = (p) => now - newestMtime(p) >= STRAY_GRACE_MS;
|
||||
return entries
|
||||
.filter((e) => !kept.has(e.name))
|
||||
.map((e) => ({ id: where + ":" + e.name, where, name: e.name, kind: entryKind(e), path: path.join(dir, e.name) }))
|
||||
.filter((e) => settled(e.path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Everything Cleanup would remove, worked out on the server and never taken
|
||||
* from a client: sessions untouched for `maxAgeMs` (never `skipSid`; the rule
|
||||
* `open` sweeps by, plus every file in the folder that old, so a resumed
|
||||
* session or a saved draft keeps it), anything at the top of the console folder that is
|
||||
* not kept, and -- only when the console runs from its default home inside
|
||||
* `plan2codeDir` -- anything at the top of `plan2codeDir` that is not kept. Strays
|
||||
* touched within `STRAY_GRACE_MS` are left for a later scan. A
|
||||
* console running from another home (tests, dev) never reaches ~/.plan2code.
|
||||
* Resolves to `{ items: [{ id, where, name, kind, bytes }], bytes }`.
|
||||
*/
|
||||
export async function cleanupFindings({
|
||||
consoleDir = HOME_DIR,
|
||||
plan2codeDir = PLAN2CODE_DIR,
|
||||
now = Date.now(),
|
||||
maxAgeMs = SESSION_MAX_AGE_MS,
|
||||
skipSid,
|
||||
} = {}) {
|
||||
const found = [];
|
||||
const sessionsDir = path.join(consoleDir, "sessions");
|
||||
for (const sid of staleSessions(sessionsDir, now, maxAgeMs, skipSid)) {
|
||||
if (now - newestMtime(path.join(sessionsDir, sid)) <= maxAgeMs) continue;
|
||||
found.push({ id: "session:" + sid, where: "session", name: sid, kind: "folder", path: path.join(sessionsDir, sid) });
|
||||
}
|
||||
found.push(...strayEntries(consoleDir, KEPT_CONSOLE_ENTRIES, "console", now));
|
||||
if (path.resolve(consoleDir) === path.resolve(plan2codeDir, "console")) {
|
||||
found.push(...strayEntries(plan2codeDir, KEPT_PLAN2CODE_ENTRIES, "root", now));
|
||||
}
|
||||
const items = [];
|
||||
let bytes = 0;
|
||||
for (const f of found) {
|
||||
const size = await diskBytes(f.path);
|
||||
bytes += size;
|
||||
items.push({ id: f.id, where: f.where, name: f.name, kind: f.kind, bytes: size, path: f.path });
|
||||
}
|
||||
return { items, bytes };
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove what Cleanup found, limited to `ids` the page was shown. The list is
|
||||
* worked out afresh first and only ids on it are touched, so a name from the
|
||||
* page is never a path, and anything that stopped qualifying since the scan
|
||||
* (a session touched again) stays. A link is unlinked, never followed.
|
||||
* Resolves to `{ removed: [id], bytes, failed: [id] }`.
|
||||
*/
|
||||
export async function removeCleanup(ids, opts = {}) {
|
||||
const wanted = new Set((Array.isArray(ids) ? ids : []).filter((id) => typeof id === "string"));
|
||||
const { items } = await cleanupFindings(opts);
|
||||
const removed = [];
|
||||
const failed = [];
|
||||
let bytes = 0;
|
||||
for (const item of items) {
|
||||
if (!wanted.has(item.id)) continue;
|
||||
try {
|
||||
if (item.kind === "link") await fs.promises.unlink(item.path);
|
||||
else await fs.promises.rm(item.path, { recursive: true, force: true });
|
||||
removed.push(item.id);
|
||||
bytes += item.bytes;
|
||||
} catch {
|
||||
failed.push(item.id);
|
||||
}
|
||||
}
|
||||
return { removed, bytes, failed };
|
||||
}
|
||||
|
||||
/**
|
||||
* A spec's overview.md, read-only, or null. `specDir` is relative to `root`;
|
||||
* the file's realpath must sit inside the root's, so `../`, an absolute path
|
||||
@@ -871,7 +1017,7 @@ export function handOff(child, pre) {
|
||||
|
||||
/* ----------------------------------------------------------- patch merge */
|
||||
|
||||
const APPEND_KEYS = new Set(["thread", "comments"]);
|
||||
const APPEND_KEYS = new Set(["thread"]);
|
||||
|
||||
function isPlainObject(v) {
|
||||
return v !== null && typeof v === "object" && !Array.isArray(v);
|
||||
@@ -896,7 +1042,7 @@ function mergeOne(target, patch, where) {
|
||||
}
|
||||
|
||||
// Merge a keyed collection: a known id merges one level, an unknown id appends.
|
||||
// Named fields are replaced whole; thread/comments append.
|
||||
// Named fields are replaced whole; thread appends.
|
||||
function mergeKeyed(current, patchList, idKey, defaults, where) {
|
||||
const out = Array.isArray(current) ? current.map((x) => ({ ...x })) : [];
|
||||
for (const entry of patchList) {
|
||||
@@ -955,6 +1101,42 @@ function dropStaleSubmissions(currentItems, before, patchList) {
|
||||
return merged;
|
||||
}
|
||||
|
||||
// A thread entry is `{ who, text }`, and the page reads nothing else. Models
|
||||
// borrow the shape of the replies and doc blocks they also write, so `from` /
|
||||
// `role` and `md` / `body` / `content` are lifted into place: left as they came,
|
||||
// each became a "Plan2Code" bubble with nothing in it. An entry with no words
|
||||
// at all is refused. The person's own notes are recorded by the server when
|
||||
// they send, so an agent that echoes one back is not shown it twice.
|
||||
const THREAD_TEXT_KEYS = ["text", "md", "body", "content"];
|
||||
|
||||
function normalizeThreads(patchList, currentItems) {
|
||||
return patchList.map((entry) => {
|
||||
if (!isPlainObject(entry) || entry.thread == null) return entry;
|
||||
if (!Array.isArray(entry.thread)) throw new Error(`item "${entry.id}" "thread" must be an array`);
|
||||
const prev = (currentItems || []).find((x) => x && x.id === entry.id);
|
||||
const said = new Set(
|
||||
((prev && prev.thread) || []).filter((m) => m && m.who === "user").map((m) => String(m.text || "").trim()),
|
||||
);
|
||||
const thread = [];
|
||||
for (const m of entry.thread) {
|
||||
if (!isPlainObject(m)) throw new Error(`item "${entry.id}" thread entries must be objects`);
|
||||
guard(m, "thread");
|
||||
const key = THREAD_TEXT_KEYS.find((k) => typeof m[k] === "string" && m[k].trim());
|
||||
if (!key) {
|
||||
throw new Error(
|
||||
`item "${entry.id}" thread entry has no "text". Write { "who": "agent", "text": "<markdown>" }; the page shows nothing else.`,
|
||||
);
|
||||
}
|
||||
const { from, role, md, body, content, ...rest } = m;
|
||||
const who = (m.who || from || role) === "user" ? "user" : "agent";
|
||||
const text = m[key];
|
||||
if (who === "user" && said.has(text.trim())) continue;
|
||||
thread.push({ ...rest, who, text });
|
||||
}
|
||||
return { ...entry, thread };
|
||||
});
|
||||
}
|
||||
|
||||
const DOC_DEFAULTS = { version: 1, stale: false, blocks: [] };
|
||||
|
||||
// Blocks merge by id like docs do, so a patch that only settles a block's
|
||||
@@ -996,7 +1178,7 @@ export function applyPatch(state, patch) {
|
||||
break;
|
||||
case "items":
|
||||
if (!Array.isArray(v)) throw new Error('"items" must be an array');
|
||||
next.items = dropStaleSubmissions(next.items, state.items, v);
|
||||
next.items = dropStaleSubmissions(next.items, state.items, normalizeThreads(v, state.items));
|
||||
break;
|
||||
case "topics":
|
||||
if (!Array.isArray(v)) throw new Error('"topics" must be an array');
|
||||
@@ -1048,15 +1230,11 @@ function stampTimes(before, next) {
|
||||
if (changed && !next.agent.since) next.agent = { ...next.agent, since: now };
|
||||
else if (!next.agent.since) next.agent = { ...next.agent, since: before.agent?.since || now };
|
||||
}
|
||||
for (const list of [next.items, next.docs]) {
|
||||
if (!Array.isArray(list)) continue;
|
||||
for (const entry of list) {
|
||||
if (Array.isArray(next.items)) {
|
||||
for (const entry of next.items) {
|
||||
if (Array.isArray(entry.thread)) {
|
||||
for (const m of entry.thread) if (!m.at) m.at = now;
|
||||
}
|
||||
if (Array.isArray(entry.comments)) {
|
||||
for (const m of entry.comments) if (!m.at) m.at = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Array.isArray(next.docs)) {
|
||||
@@ -1289,7 +1467,10 @@ export function validate(state) {
|
||||
// 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
|
||||
// would be rejected and the session would wedge with no way out.
|
||||
const authored = state.items.map(({ submitted, sentNote, ...rest }) => rest);
|
||||
const authored = state.items.map(({ submitted, sentNote, thread, ...rest }) => ({
|
||||
...rest,
|
||||
thread: Array.isArray(thread) ? thread.filter((m) => !m || m.who !== "user") : thread,
|
||||
}));
|
||||
const prose =
|
||||
JSON.stringify(authored) +
|
||||
JSON.stringify(state.docs || []) +
|
||||
|
||||
@@ -65,7 +65,7 @@ export function submittedAwaiting(item) {
|
||||
if (!s || typeof s !== "object") return null;
|
||||
if (item.answer && typeof item.answer === "object") return null;
|
||||
const thread = Array.isArray(item.thread) ? item.thread : [];
|
||||
const replied = thread.some((m) => m && m.who === "agent" && (!s.at || !m.at || m.at >= s.at));
|
||||
const replied = thread.some((m) => m && threadWho(m) === "agent" && (!s.at || !m.at || m.at >= s.at));
|
||||
return replied ? null : s;
|
||||
}
|
||||
|
||||
@@ -74,17 +74,33 @@ export function submittedAwaiting(item) {
|
||||
* agent has yet to say anything after it. The server records it as `sentNote`
|
||||
* on every send, so the page can show it in the Notes pane and in the Sent
|
||||
* box instead of letting it vanish into a send that shows no sign of arriving.
|
||||
* Any thread message from the send onwards, or none with a clock to compare,
|
||||
* means it has been picked up.
|
||||
* Any agent message from the send onwards, or one with no clock to compare,
|
||||
* means it has been picked up. The person's own entries never count: the
|
||||
* server writes their note into the thread as it arrives.
|
||||
*/
|
||||
export function noteAwaiting(item) {
|
||||
const n = item && item.sentNote;
|
||||
if (!n || typeof n !== "object") return null;
|
||||
const thread = Array.isArray(item.thread) ? item.thread : [];
|
||||
const picked = thread.some((m) => m && (!n.at || !m.at || m.at >= n.at));
|
||||
const picked = thread.some((m) => m && threadWho(m) === "agent" && (!n.at || !m.at || m.at >= n.at));
|
||||
return picked ? null : n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Who said a thread entry and what they said. The contract is `{ who, text }`
|
||||
* and the server lifts anything else into it, but sessions written before that
|
||||
* hold `{ from, md }` replies, which would otherwise draw as empty bubbles.
|
||||
*/
|
||||
export function threadWho(m) {
|
||||
return m && (m.who || m.from || m.role) === "user" ? "user" : "agent";
|
||||
}
|
||||
|
||||
export function threadText(m) {
|
||||
if (!m) return "";
|
||||
for (const k of ["text", "md", "body", "content"]) if (typeof m[k] === "string" && m[k].trim()) return m[k];
|
||||
return "";
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- labels */
|
||||
|
||||
export function optionLabel(item, k) {
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
--warn-soft: #fbe7e3;
|
||||
--focus: #1f6feb;
|
||||
--shadow: 0 1px 2px rgba(29, 26, 23, 0.05), 0 8px 24px rgba(29, 26, 23, 0.06);
|
||||
/* A soft accent halo for the things that want noticing: the update banner
|
||||
and an enabled Send. Built from --accent, so a picked accent glows too. */
|
||||
--glow: 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent), 0 0 12px color-mix(in srgb, var(--accent) 35%, transparent);
|
||||
--sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
--serif: "Iowan Old Style", Charter, Georgia, Cambria, serif;
|
||||
--mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
|
||||
@@ -61,6 +64,7 @@
|
||||
--warn-soft: #34201d;
|
||||
--focus: #6aa3ff;
|
||||
--shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
|
||||
--glow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent), 0 0 14px color-mix(in srgb, var(--accent) 45%, transparent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +89,7 @@
|
||||
--warn-soft: #34201d;
|
||||
--focus: #6aa3ff;
|
||||
--shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
|
||||
--glow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent), 0 0 14px color-mix(in srgb, var(--accent) 45%, transparent);
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
@@ -1097,10 +1102,11 @@ h1 {
|
||||
.ask-disabled-note.is-offline { color: var(--warn); background: var(--warn-soft); border: 1px solid var(--warn); }
|
||||
|
||||
/* Waiting on Plan2Code (an Ask answer, or answers sent from Questions):
|
||||
the tiny ring, left of the label. */
|
||||
.view-tab .tab-spin {
|
||||
the tiny ring, left of the label. The extra .spinner is for specificity:
|
||||
.spinner.tiny comes later and zeroes the margin otherwise. */
|
||||
.view-tab .spinner.tab-spin {
|
||||
display: inline-block;
|
||||
margin-right: 6px;
|
||||
margin-right: 7px;
|
||||
vertical-align: -1px;
|
||||
}
|
||||
|
||||
@@ -1657,11 +1663,13 @@ input[type="text"].invalid { border-color: var(--warn); }
|
||||
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
|
||||
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
|
||||
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
|
||||
/* Send breathes while there is something to send: a soft accent ring that
|
||||
spreads and fades. Off under reduced motion, below. */
|
||||
/* Send glows and breathes while there is something to send: the steady
|
||||
--glow, plus a soft accent ring that spreads and fades. The ring is off
|
||||
under reduced motion, below; the glow stays. */
|
||||
#btn-send:not(:disabled) { box-shadow: var(--glow); }
|
||||
@keyframes send-pulse {
|
||||
0% { box-shadow: 0 0 0 0 var(--accent-line); }
|
||||
100% { box-shadow: 0 0 0 6px transparent; }
|
||||
0% { box-shadow: var(--glow), 0 0 0 0 var(--accent-line); }
|
||||
100% { box-shadow: var(--glow), 0 0 0 6px transparent; }
|
||||
}
|
||||
#btn-send.primary:not(:disabled) { animation: send-pulse 2.4s ease-out infinite; }
|
||||
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
|
||||
@@ -2219,6 +2227,7 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
|
||||
.modal.help[open] { display: flex; }
|
||||
.modal.help .modal-actions { flex: none; margin-top: 16px; align-items: center; }
|
||||
.help-version { margin-right: auto; font-size: 12.5px; color: var(--ink-3); }
|
||||
.help-version a { color: inherit; }
|
||||
|
||||
.help-layout {
|
||||
display: grid;
|
||||
@@ -2668,6 +2677,74 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
|
||||
border-left-width: 4px;
|
||||
color: var(--ink);
|
||||
}
|
||||
/* A newer release: the same slot, in the accent, with the label as the way
|
||||
into the update modal and a small × that hides it for this session. */
|
||||
.dash-nudge.update-banner {
|
||||
position: relative;
|
||||
padding-left: 40px;
|
||||
padding-right: 40px;
|
||||
border-left-width: 4px;
|
||||
border-left-color: var(--accent-line);
|
||||
color: var(--ink);
|
||||
box-shadow: var(--glow);
|
||||
}
|
||||
.update-banner-open {
|
||||
flex: 1 1 16em;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.02em;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
.update-banner-open:hover { text-decoration: underline; }
|
||||
/* Pinned to the right edge, out of the flow, so the label centres on the
|
||||
whole banner rather than on what the × leaves of it. */
|
||||
.update-banner-dismiss {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 10px;
|
||||
transform: translateY(-50%);
|
||||
padding: 0 6px;
|
||||
border: 0;
|
||||
border-radius: var(--radius);
|
||||
background: none;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
font-size: 16px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
.update-banner-dismiss:hover { background: var(--accent-line); }
|
||||
/* Wide enough that the update command sits on one line beside Copy; a
|
||||
narrow window still wraps it rather than overflowing. */
|
||||
#update-modal { max-width: 720px; }
|
||||
.update-steps { margin: 0 0 12px; padding-left: 1.4em; color: var(--ink); }
|
||||
.update-steps li { margin: 4px 0; }
|
||||
/* The hand-off copy row, in the modal's first step: the command and its Copy
|
||||
side by side. */
|
||||
.update-command {
|
||||
margin: 6px 0 4px;
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.update-command code {
|
||||
flex: 1 1 260px;
|
||||
min-width: 0;
|
||||
font: 13px/1.5 var(--mono);
|
||||
color: var(--ink);
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--rule-2);
|
||||
border-radius: 8px;
|
||||
padding: 10px 12px;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.dash-nudge-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
|
||||
.dash-nudge-actions .btn.tiny { margin-bottom: 0; }
|
||||
.dash-working {
|
||||
@@ -3394,6 +3471,18 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
|
||||
.models-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
||||
.models-actions .help.error { color: var(--danger, #d64545); }
|
||||
|
||||
/* User Preferences: Cleanup's list of what would go, shown before anything
|
||||
is deleted. */
|
||||
.cleanup-list { display: grid; gap: 4px; max-height: 200px; overflow: auto; font-size: 0.88em; }
|
||||
.cleanup-list:empty { display: none; }
|
||||
.cleanup-summary { margin: 0 0 2px; font-weight: 600; }
|
||||
.cleanup-row { display: flex; justify-content: space-between; gap: 12px; }
|
||||
.cleanup-row span:first-child { min-width: 0; overflow-wrap: anywhere; font-family: var(--mono); }
|
||||
.cleanup-size { flex: none; color: var(--ink-3); }
|
||||
.cleanup-more { display: grid; gap: 4px; }
|
||||
.cleanup-more summary { cursor: pointer; color: var(--ink-2); }
|
||||
#cleanup-delete[hidden] { display: none; }
|
||||
|
||||
/* A word the person has to type, bold and in their highlight color so it
|
||||
does not get lost in the status sentence. */
|
||||
.agent-key {
|
||||
|
||||
@@ -66,6 +66,8 @@ import {
|
||||
submittedAwaiting,
|
||||
noteAwaiting,
|
||||
suggestionFrom,
|
||||
threadText,
|
||||
threadWho,
|
||||
THUMB_EDGE,
|
||||
turnGate,
|
||||
verdictText,
|
||||
@@ -446,6 +448,10 @@ document.addEventListener("click", (e) => {
|
||||
|
||||
|
||||
const GONE_AFTER_MS = 8000;
|
||||
// Named so a reconnect can clear only THIS banner: a bare banner(null) would
|
||||
// wipe an unrelated warning that landed while the page was gone (an upload
|
||||
// failure, a refused send).
|
||||
const GONE_BANNER = "Lost contact with Plan2Code. Nothing you have typed is lost. This page reconnects by itself.";
|
||||
const WORKING_GRACE_MS = 5 * 60 * 1000;
|
||||
// Two minutes with the agent mid-turn, three when it is merely meant to be
|
||||
// listening. The difference is the cost of being wrong: a working agent that
|
||||
@@ -521,6 +527,9 @@ let chatFrame = null;
|
||||
// sends them.
|
||||
let wsFrame = null;
|
||||
let meterFrame = null;
|
||||
// The frame's update ({ installed, latest }), present only when a newer
|
||||
// release is out; null otherwise.
|
||||
let updateFrame = null;
|
||||
let chatDot = false;
|
||||
let chatSending = false;
|
||||
let chatResetting = false;
|
||||
@@ -566,7 +575,6 @@ function fresh() {
|
||||
drafts: {},
|
||||
images: {},
|
||||
sent: {},
|
||||
sentAt: null,
|
||||
stopping: null,
|
||||
afterBuild: null,
|
||||
homeward: null,
|
||||
@@ -870,10 +878,12 @@ function adopt(body) {
|
||||
chatFrame = body.chat || null;
|
||||
if (body.workspace) wsFrame = body.workspace;
|
||||
if (body.meter) meterFrame = body.meter;
|
||||
// Always replaced: an absent key means no update.
|
||||
updateFrame = body.update || null;
|
||||
lastContact = Date.now();
|
||||
if (gone) {
|
||||
gone = false;
|
||||
banner(null);
|
||||
if ($("banner").textContent === GONE_BANNER) banner(null);
|
||||
}
|
||||
if (firstLoad) {
|
||||
load();
|
||||
@@ -1016,7 +1026,9 @@ function adopt(body) {
|
||||
render();
|
||||
if ($("workspace-modal").open) renderWorkspace();
|
||||
tellFolderIssues();
|
||||
if (firstLoad || S.specDir !== prevSpecDir || S.workflow !== prevWorkflow) loadOverview();
|
||||
// The Overview tab's file changes under a build, so a tab you are watching
|
||||
// refetches on every new frame too, not only on the click that opened it.
|
||||
if (firstLoad || S.specDir !== prevSpecDir || S.workflow !== prevWorkflow || view === "overview") loadOverview();
|
||||
if (announce) showArrival(announce);
|
||||
// New entries land at the bottom of the rail. Gliding down to them beats
|
||||
// leaving the list parked where it was while it grew underneath.
|
||||
@@ -1149,15 +1161,12 @@ function markGone() {
|
||||
// of the server means there, and a banner promising a reconnect would
|
||||
// argue with it.
|
||||
if (!finish() && !stopInProgress()) {
|
||||
banner(
|
||||
"Lost contact with Plan2Code. Nothing you have typed is lost. This page reconnects by itself.",
|
||||
"warn"
|
||||
);
|
||||
banner(GONE_BANNER, "warn");
|
||||
}
|
||||
render();
|
||||
} else if (!bad && gone) {
|
||||
gone = false;
|
||||
banner(null);
|
||||
if ($("banner").textContent === GONE_BANNER) banner(null);
|
||||
render();
|
||||
}
|
||||
}
|
||||
@@ -1182,7 +1191,6 @@ function connect() {
|
||||
} catch {}
|
||||
});
|
||||
es.addEventListener("submitted", (e) => {
|
||||
local.sentAt = Date.now();
|
||||
// Drop only what was actually sent.
|
||||
//
|
||||
// This event fires for a send from ANY tab of this session, which is why it
|
||||
@@ -1799,14 +1807,19 @@ async function sendBrief() {
|
||||
reply: briefPhrase(choice.range),
|
||||
}),
|
||||
});
|
||||
if (res.status === 409) throw Object.assign(new Error("pending"), { pending: true });
|
||||
if (!res.ok) throw new Error(String(res.status));
|
||||
$("brief-modal").close();
|
||||
banner("Asked for a brief. It will appear as a tab when it is written.", "good");
|
||||
setTimeout(() => banner(null), 5000);
|
||||
pendingResult = true;
|
||||
render();
|
||||
} catch {
|
||||
why.textContent = "That did not go through. Try again in a moment.";
|
||||
} catch (err) {
|
||||
if (err && err.pending) pendingResult = true;
|
||||
why.textContent =
|
||||
err && err.pending
|
||||
? "Your last answers are still being picked up. Try again in a moment."
|
||||
: "That did not go through. Try again in a moment.";
|
||||
} finally {
|
||||
go.disabled = false;
|
||||
go.textContent = "Write the brief";
|
||||
@@ -2515,6 +2528,51 @@ function roleNudge() {
|
||||
return nudge;
|
||||
}
|
||||
|
||||
// × on the update banner hides it for this console session only, and only
|
||||
// for the release it named. Blocked storage means "not dismissed".
|
||||
function updateDismissKey() {
|
||||
try {
|
||||
return "p2c-update-dismissed:" + S.sid;
|
||||
} catch {
|
||||
return "p2c-update-dismissed:";
|
||||
}
|
||||
}
|
||||
|
||||
function updateDismissed() {
|
||||
try {
|
||||
return sessionStorage.getItem(updateDismissKey()) === updateFrame.latest;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const RELEASES_URL = "https://github.com/jparkerweb/plan2code/releases/";
|
||||
const UPDATE_COMMAND = "npx --allow-git=all git+https://github.com/jparkerweb/plan2code.git";
|
||||
|
||||
function releasesLink(text) {
|
||||
const a = el("a", null, text);
|
||||
a.href = RELEASES_URL;
|
||||
a.target = "_blank";
|
||||
a.rel = "noopener noreferrer";
|
||||
return a;
|
||||
}
|
||||
|
||||
function openUpdateModal() {
|
||||
if (!updateFrame) return;
|
||||
const versions = $("update-versions");
|
||||
versions.replaceChildren(
|
||||
document.createTextNode("Version "),
|
||||
releasesLink("v" + updateFrame.latest),
|
||||
document.createTextNode(" is out — you have "),
|
||||
el("code", null, updateFrame.installed),
|
||||
document.createTextNode(".")
|
||||
);
|
||||
const row = $("update-command");
|
||||
const code = el("code", null, UPDATE_COMMAND);
|
||||
row.replaceChildren(code, copyButton(UPDATE_COMMAND, "btn small ghost handoff-copy", code));
|
||||
$("update-modal").showModal();
|
||||
}
|
||||
|
||||
function renderDashboard(main) {
|
||||
maybeWake();
|
||||
const menu = (S && S.menu) || {};
|
||||
@@ -2526,6 +2584,25 @@ function renderDashboard(main) {
|
||||
warn.setAttribute("role", "status");
|
||||
wrap.appendChild(warn);
|
||||
}
|
||||
// Built here only, so no other workflow's page ever shows it.
|
||||
if (updateFrame && !updateDismissed()) {
|
||||
const notice = el("div", "dash-nudge update-banner");
|
||||
notice.setAttribute("role", "status");
|
||||
const open = el("button", "update-banner-open", "UPDATE AVAILABLE · v" + updateFrame.latest);
|
||||
open.type = "button";
|
||||
open.addEventListener("click", openUpdateModal);
|
||||
const dismiss = el("button", "update-banner-dismiss", "×");
|
||||
dismiss.type = "button";
|
||||
dismiss.setAttribute("aria-label", "Dismiss until next time");
|
||||
dismiss.addEventListener("click", () => {
|
||||
try {
|
||||
sessionStorage.setItem(updateDismissKey(), updateFrame.latest);
|
||||
} catch {}
|
||||
render();
|
||||
});
|
||||
notice.append(open, dismiss);
|
||||
wrap.appendChild(notice);
|
||||
}
|
||||
wrap.appendChild(el("p", "card-kicker", "Plan2Code"));
|
||||
wrap.appendChild(el("h2", "dash-title", "What are we doing today?"));
|
||||
if (typeof menu.note === "string" && menu.note.trim()) {
|
||||
@@ -3223,7 +3300,11 @@ document.addEventListener("keydown", cancelSkipMove, true);
|
||||
function skipAndMoveOn(id) {
|
||||
cancelSkipMove();
|
||||
local.skipFlash = id;
|
||||
stage(id, { type: "skip", skipped: true });
|
||||
// A note already typed goes along: skipping the question is not retracting
|
||||
// the comment. Dropping it would leave the text in the box but out of the
|
||||
// send, which looks kept and is not.
|
||||
const cur = local.staged[id];
|
||||
stage(id, { type: "skip", skipped: true, ...(cur && cur.text ? { text: cur.text } : {}) });
|
||||
skipTimer = setTimeout(() => {
|
||||
skipTimer = null;
|
||||
local.skipFlash = null;
|
||||
@@ -3340,19 +3421,24 @@ function renderWaiting(main) {
|
||||
}
|
||||
pane.appendChild(title);
|
||||
pane.appendChild(el("p", null, doing));
|
||||
const ask = "If Plan2Code needs you, the question appears here on its own.";
|
||||
if (!docs().length) {
|
||||
pane.appendChild(el("p", null, "If Plan2Code needs you, the question appears here on its own."));
|
||||
pane.appendChild(el("p", null, ask));
|
||||
return;
|
||||
}
|
||||
// "Task" and the tasks tab's own name both open that tab, so the pointer is
|
||||
// one click from what it points at. A build posts it as `phase` ("Phase N
|
||||
// tasks"), a quick task as `tasks`; with neither the words stay plain.
|
||||
// tasks"), a quick task as `tasks`. A skill with no task list (Document,
|
||||
// Plan) has nothing live to follow, so it gets no pointer at all.
|
||||
const list =
|
||||
docs().find((d) => d.id === "phase") ||
|
||||
docs().find((d) => d.id === "tasks") ||
|
||||
docs().find((d) => /\btasks\b/i.test(d.title || ""));
|
||||
if (!list) {
|
||||
pane.appendChild(el("p", null, "The tabs above fill in as it goes. " + ask));
|
||||
return;
|
||||
}
|
||||
const jump = (word) => {
|
||||
if (!list) return el("strong", "waiting-jump", word);
|
||||
const b = el("button", "waiting-jump", word);
|
||||
b.type = "button";
|
||||
b.addEventListener("click", () => {
|
||||
@@ -3366,8 +3452,8 @@ function renderWaiting(main) {
|
||||
"The tabs above fill in as it goes. You can follow along with live ",
|
||||
jump("Task"),
|
||||
" updates in the ",
|
||||
jump((list && list.title) || "Phase tasks"),
|
||||
" tab. If Plan2Code needs you, the question appears here on its own."
|
||||
jump(list.title || "Phase tasks"),
|
||||
" tab. " + ask
|
||||
);
|
||||
pane.appendChild(p);
|
||||
}
|
||||
@@ -3505,8 +3591,8 @@ function renderSettled(card, item) {
|
||||
// would misreport which of the two was the answer.
|
||||
let prose = text;
|
||||
if (!prose && !lines.length) {
|
||||
const mine = (item.thread || []).filter((m) => m.who === "user");
|
||||
if (mine.length) prose = String(mine[mine.length - 1].text || "").trim();
|
||||
const mine = (item.thread || []).filter((m) => threadWho(m) === "user");
|
||||
if (mine.length) prose = threadText(mine[mine.length - 1]).trim();
|
||||
}
|
||||
|
||||
const nothing = !lines.length && !prose;
|
||||
@@ -4322,6 +4408,10 @@ function buildChecklist(card, item, staged) {
|
||||
const commitList = (change) => {
|
||||
const cur = local.staged[item.id];
|
||||
const next = { ...(cur || {}), type: "answer", kind: "checklist", ...change };
|
||||
// A tick or a state IS the answer, so it ends a skip staged earlier:
|
||||
// left in place, `skipped` would collapse the reply to "skip" while the
|
||||
// card showed ticked steps on their way.
|
||||
delete next.skipped;
|
||||
const empty = !(next.done && next.done.length) && !next.state && !next.text;
|
||||
stage(item.id, empty ? null : next);
|
||||
};
|
||||
@@ -4371,7 +4461,7 @@ function buildChecklist(card, item, staged) {
|
||||
function buildMenu(card, item, staged) {
|
||||
const list = el("ul", "options");
|
||||
const name = "menu-" + item.id;
|
||||
for (const o of item.options || []) {
|
||||
for (const [i, o] of (item.options || []).entries()) {
|
||||
const picked = staged && staged.k === o.k;
|
||||
const li = el("li", "option" + (picked ? " is-picked" : ""));
|
||||
const label = el("label");
|
||||
@@ -4379,7 +4469,13 @@ function buildMenu(card, item, staged) {
|
||||
const radio = el("input");
|
||||
radio.type = "radio";
|
||||
radio.name = name;
|
||||
// The same id buildChoice gives its radios: withFocus finds the focused
|
||||
// input by id after the render this change() sets off, and without one a
|
||||
// keyboard user arrowing through the menu lands on <body> every time.
|
||||
radio.id = optionId(item, o, i);
|
||||
radio.value = o.k;
|
||||
radio.checked = Boolean(picked);
|
||||
radio.setAttribute("aria-label", o.k ? `${o.k}: ${o.text}` : o.text);
|
||||
radio.addEventListener("change", () => stage(item.id, { type: "answer", kind: "menu", k: o.k }));
|
||||
const body = el("div", "option-body");
|
||||
const head = el("div", "option-label");
|
||||
@@ -5276,20 +5372,30 @@ function renderAside() {
|
||||
)
|
||||
);
|
||||
}
|
||||
// A note that has been sent but not yet picked up: marked as waiting, so the
|
||||
// send is seen to have gone, until the agent replies. The server writes the
|
||||
// note into the thread as it arrives; a session from before that has only
|
||||
// `sentNote`, which gets a box of its own below.
|
||||
const waiting = isOpen(item) && !finish() ? noteAwaiting(item) : null;
|
||||
let waitingShown = false;
|
||||
for (const m of thread) {
|
||||
const box = el("div", "msg " + (m.who === "user" ? "you" : ""));
|
||||
const mine = threadWho(m) === "user";
|
||||
const pending = Boolean(waiting && mine && m.at && m.at === waiting.at);
|
||||
if (pending) waitingShown = true;
|
||||
const box = el("div", "msg" + (mine ? " you" : "") + (pending ? " pending" : ""));
|
||||
const who = el("div", "msg-who");
|
||||
who.appendChild(el("span", null, m.who === "user" ? "You" : "Plan2Code"));
|
||||
if (m.at) who.appendChild(el("span", null, shortTime(m.at)));
|
||||
who.appendChild(el("span", null, mine ? "You" : "Plan2Code"));
|
||||
if (pending) who.appendChild(el("span", null, "Sent, waiting for Plan2Code"));
|
||||
else if (m.at) who.appendChild(el("span", null, shortTime(m.at)));
|
||||
box.appendChild(who);
|
||||
box.appendChild(md(m.text, "md"));
|
||||
const text = threadText(m);
|
||||
if (text) box.appendChild(md(text, "md"));
|
||||
const tray = mine ? sentAttachments(m) : null;
|
||||
if (tray) box.appendChild(tray);
|
||||
aside.appendChild(box);
|
||||
}
|
||||
|
||||
// A note that has been sent but not yet picked up: shown at once, so the
|
||||
// send is seen to have gone, and gone when the agent replies.
|
||||
const waiting = isOpen(item) && !finish() ? noteAwaiting(item) : null;
|
||||
if (waiting) {
|
||||
if (waiting && !waitingShown) {
|
||||
const box = el("div", "msg you pending");
|
||||
const who = el("div", "msg-who");
|
||||
who.appendChild(el("span", null, "You"));
|
||||
@@ -5589,7 +5695,10 @@ async function attachFiles(itemId, files) {
|
||||
const taken = wanted.slice(0, room);
|
||||
// One banner at a time, so every refusal goes into it, each by name.
|
||||
const said = refused.map((r) => (r.reason === "too-large" ? tooLargeText(r.name) : notAllowedText(r.name)));
|
||||
if (taken.length < wanted.length) said.push(chat ? "Up to 5 attachments per question." : "Up to 5 attachments per note.");
|
||||
if (taken.length < wanted.length)
|
||||
said.push(
|
||||
chat ? `Up to ${CHAT_MAX_ATTACHMENTS} attachments per question.` : `Up to ${MAX_ATTACHMENTS} attachments per note.`
|
||||
);
|
||||
if (said.length) banner(said.join(" "), refused.length ? "warn" : "info");
|
||||
await Promise.all(
|
||||
taken.map(async (file) => {
|
||||
@@ -6439,6 +6548,10 @@ async function goHome() {
|
||||
$("home-modal").close();
|
||||
} catch (err) {
|
||||
$("home-modal").close();
|
||||
// The server is holding an uncollected result: Send, Home and Stop all
|
||||
// need to read as busy until the frame or the ping says otherwise, same
|
||||
// as send() and sendAfterBuild() do on a 409.
|
||||
if (err && err.pending) pendingResult = true;
|
||||
banner(
|
||||
err && err.pending
|
||||
? "Your last answers are still being picked up, so that could not go yet. Try again in a moment."
|
||||
@@ -6499,6 +6612,7 @@ async function stopSession() {
|
||||
stoppingHidden = false;
|
||||
} catch (err) {
|
||||
$("stop-modal").close();
|
||||
if (err && err.pending) pendingResult = true;
|
||||
banner(
|
||||
err && err.pending
|
||||
? "Your last answers are still being picked up, so the stop could not go yet. Try again in a moment."
|
||||
@@ -6653,7 +6767,6 @@ function markSent({ sentIds, sentNotes = {}, summaries, values }) {
|
||||
local.sent[id] = { at: Date.now(), summary: summaries[id] || "", value: values[id] || null };
|
||||
}
|
||||
local.staged = {};
|
||||
local.sentAt = Date.now();
|
||||
save();
|
||||
}
|
||||
|
||||
@@ -6706,7 +6819,7 @@ const STATE_WORDS = { done: "all done", blocked: "blocked", help: "need help", d
|
||||
// something the agent never hears.
|
||||
function tokenFor(item, v) {
|
||||
const map = item.token || {};
|
||||
if (v.skipped) return "skip";
|
||||
if (v.skipped) return v.text ? `skip; ${v.text}` : "skip";
|
||||
const parts = [];
|
||||
if (v.k) parts.push(map[v.k] || v.k);
|
||||
if (Array.isArray(v.ks) && v.ks.length) parts.push(v.ks.map((k) => map[k] || k).join(", "));
|
||||
@@ -6938,14 +7051,14 @@ function renderAbout() {
|
||||
let helpBuilt = false;
|
||||
|
||||
async function renderHelpVersion() {
|
||||
const el = $("help-version");
|
||||
const slot = $("help-version");
|
||||
try {
|
||||
const res = await fetch("/version", { cache: "no-store" });
|
||||
const { version } = res.ok ? await res.json() : {};
|
||||
el.textContent = version ? "Plan2Code v" + version : "";
|
||||
el.hidden = !version;
|
||||
slot.replaceChildren(...(version ? [releasesLink("Plan2Code v" + version)] : []));
|
||||
slot.hidden = !version;
|
||||
} catch {
|
||||
el.hidden = true;
|
||||
slot.hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7053,6 +7166,7 @@ function openHelpOn(id) {
|
||||
}
|
||||
|
||||
$("btn-home").addEventListener("click", openHomeConfirm);
|
||||
$("update-done").addEventListener("click", () => $("update-modal").close());
|
||||
$("home-cancel").addEventListener("click", () => $("home-modal").close());
|
||||
$("home-go").addEventListener("click", goHome);
|
||||
$("btn-stop").addEventListener("click", openStopConfirm);
|
||||
@@ -7132,6 +7246,7 @@ $("btn-looks").addEventListener("click", () => {
|
||||
});
|
||||
$("looks-done").addEventListener("click", () => $("looks-modal").close());
|
||||
$("looks-modal").addEventListener("close", () => {
|
||||
resetCleanup();
|
||||
if (isDashboard() && !needsRoleNudge(looks) && $("main").querySelector(".dash-nudge")) render();
|
||||
});
|
||||
$("looks-reset").addEventListener("click", () => {
|
||||
@@ -7278,6 +7393,111 @@ $("models-reset").addEventListener("click", () => {
|
||||
renderModels();
|
||||
});
|
||||
|
||||
// Cleanup: the server works out what in ~/.plan2code is not needed and
|
||||
// shows it first; Delete these sends back only the ids it was shown, and the
|
||||
// server re-checks every one before removing it.
|
||||
let cleanupFound = null;
|
||||
// Bumped by every scan, delete and reset: a response from an older one is
|
||||
// dropped, so a scan still in flight when Preferences closes cannot refill it.
|
||||
let cleanupGen = 0;
|
||||
const CLEANUP_SHOWN = 8;
|
||||
|
||||
function setCleanupStatus(text, isError) {
|
||||
const status = $("cleanup-status");
|
||||
status.textContent = text;
|
||||
status.classList.toggle("error", Boolean(isError));
|
||||
}
|
||||
|
||||
function cleanupLabel(item) {
|
||||
if (item.where === "session") return "Session " + item.name;
|
||||
const where = item.where === "root" ? "~/.plan2code/" : "~/.plan2code/console/";
|
||||
return where + item.name + (item.kind === "folder" ? "/" : "");
|
||||
}
|
||||
|
||||
function cleanupSummary(items, bytes) {
|
||||
const sessions = items.filter((i) => i.where === "session").length;
|
||||
const strays = items.length - sessions;
|
||||
const parts = [];
|
||||
if (sessions) parts.push(sessions + (sessions === 1 ? " old session" : " old sessions"));
|
||||
if (strays) parts.push(strays + (strays === 1 ? " stray file or folder" : " stray files and folders"));
|
||||
return parts.join(", ") + " · " + formatBytes(bytes);
|
||||
}
|
||||
|
||||
function resetCleanup() {
|
||||
cleanupGen++;
|
||||
cleanupFound = null;
|
||||
$("cleanup-list").replaceChildren();
|
||||
$("cleanup-delete").hidden = true;
|
||||
$("cleanup-delete").disabled = false;
|
||||
$("cleanup-scan").disabled = false;
|
||||
setCleanupStatus("", false);
|
||||
}
|
||||
|
||||
function renderCleanup() {
|
||||
const list = $("cleanup-list");
|
||||
list.replaceChildren();
|
||||
const items = (cleanupFound && cleanupFound.items) || [];
|
||||
$("cleanup-delete").hidden = !items.length;
|
||||
if (!items.length) return;
|
||||
const rows = (some) => some.map((item) => {
|
||||
const row = el("div", "cleanup-row");
|
||||
row.append(el("span", null, cleanupLabel(item)), el("span", "cleanup-size", formatBytes(item.bytes)));
|
||||
return row;
|
||||
});
|
||||
list.append(el("p", "cleanup-summary", cleanupSummary(items, cleanupFound.bytes)), ...rows(items.slice(0, CLEANUP_SHOWN)));
|
||||
if (items.length > CLEANUP_SHOWN) {
|
||||
const more = el("details", "cleanup-more");
|
||||
more.append(el("summary", null, (items.length - CLEANUP_SHOWN) + " more"), ...rows(items.slice(CLEANUP_SHOWN)));
|
||||
list.appendChild(more);
|
||||
}
|
||||
}
|
||||
|
||||
async function scanCleanup() {
|
||||
const gen = ++cleanupGen;
|
||||
$("cleanup-scan").disabled = true;
|
||||
$("cleanup-delete").disabled = true;
|
||||
setCleanupStatus("Looking…", false);
|
||||
const { status, body } = await postJson("/cleanup", { scan: true });
|
||||
if (gen !== cleanupGen) return;
|
||||
$("cleanup-scan").disabled = false;
|
||||
$("cleanup-delete").disabled = false;
|
||||
if (status !== 200 || !body.ok) {
|
||||
cleanupFound = null;
|
||||
renderCleanup();
|
||||
return setCleanupStatus(status ? body.error || "Could not look." : "Plan2Code isn't reachable.", true);
|
||||
}
|
||||
cleanupFound = { items: body.items || [], bytes: body.bytes || 0 };
|
||||
renderCleanup();
|
||||
// Left in the status line, not cleared: it is the live region, so this is
|
||||
// what a screen reader hears when the scan finishes.
|
||||
const found = cleanupFound.items.length;
|
||||
setCleanupStatus(found ? "Found " + found + (found === 1 ? " item." : " items.") : "Nothing to clean up.", false);
|
||||
}
|
||||
|
||||
async function deleteCleanup() {
|
||||
if (!cleanupFound || !cleanupFound.items.length) return;
|
||||
const gen = ++cleanupGen;
|
||||
$("cleanup-delete").disabled = true;
|
||||
$("cleanup-scan").disabled = true;
|
||||
setCleanupStatus("Deleting…", false);
|
||||
const { status, body } = await postJson("/cleanup", { delete: cleanupFound.items.map((i) => i.id) });
|
||||
if (gen !== cleanupGen) return;
|
||||
$("cleanup-delete").disabled = false;
|
||||
$("cleanup-scan").disabled = false;
|
||||
if (status !== 200 || !body.ok) {
|
||||
return setCleanupStatus(status ? body.error || "Could not delete." : "Plan2Code isn't reachable.", true);
|
||||
}
|
||||
const removed = (body.removed || []).length;
|
||||
const failed = (body.failed || []).length;
|
||||
cleanupFound = null;
|
||||
renderCleanup();
|
||||
const done = removed ? "Deleted " + removed + (removed === 1 ? " item" : " items") + " · " + formatBytes(body.bytes) + " freed." : "Nothing was deleted.";
|
||||
setCleanupStatus(failed ? done + " " + failed + " could not be removed." : done, Boolean(failed));
|
||||
}
|
||||
|
||||
$("cleanup-scan").addEventListener("click", scanCleanup);
|
||||
$("cleanup-delete").addEventListener("click", deleteCleanup);
|
||||
|
||||
$("btn-brief").addEventListener("click", openBrief);
|
||||
$("brief-cancel").addEventListener("click", () => $("brief-modal").close());
|
||||
$("brief-go").addEventListener("click", sendBrief);
|
||||
|
||||
@@ -1291,6 +1291,14 @@
|
||||
come back, and you can change your role any time from the swatch
|
||||
button.
|
||||
</p>
|
||||
<h4>When an update is out</h4>
|
||||
<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
|
||||
<code>/plan2code</code>. The version at the bottom of Help links to
|
||||
the Releases page.
|
||||
</p>
|
||||
<h4>The cards</h4>
|
||||
<p>They come in three groups.</p>
|
||||
<p><strong>First, the project</strong></p>
|
||||
@@ -1845,6 +1853,15 @@
|
||||
joining the strip. Keep only the ones you want; ticking a box plays
|
||||
its sound.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Cleanup</strong>: <strong>Find files to clean up</strong>
|
||||
lists 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
|
||||
shows each one with its size, and <strong>Delete these</strong>
|
||||
removes exactly that list. Your preferences, saved folders, models,
|
||||
the launcher and the session you are in always stay.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Back to default</strong> puts everything back as it was, and
|
||||
sets Role back to Not set.
|
||||
@@ -1983,6 +2000,16 @@
|
||||
</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-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. You see the list before anything is deleted. Your preferences, saved folders, models, the launcher and this session always stay.</p>
|
||||
<div class="cleanup-list" id="cleanup-list" aria-label="What would be deleted"></div>
|
||||
<div class="models-actions">
|
||||
<button type="button" class="btn small" id="cleanup-scan">Find files to clean up</button>
|
||||
<button type="button" class="btn small danger" id="cleanup-delete" hidden>Delete these</button>
|
||||
<span class="help" id="cleanup-status" role="status"></span>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset class="modal-ranges looks-models">
|
||||
<legend>Models</legend>
|
||||
<div class="models-tabs" role="group" aria-label="Which agent">
|
||||
@@ -2181,6 +2208,24 @@
|
||||
</div>
|
||||
</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
|
||||
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>
|
||||
<p class="modal-blurb" id="update-versions"></p>
|
||||
<ol class="update-steps">
|
||||
<li>
|
||||
Run this in your terminal (not in this page or your agent):
|
||||
<div class="update-command" id="update-command"></div>
|
||||
</li>
|
||||
<li>When it finishes, close this console and start <code>plan2code</code> again.</li>
|
||||
</ol>
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn primary" id="update-done">Close</button>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<footer class="footer">
|
||||
<div class="footer-summary" id="footer-summary" aria-live="polite">
|
||||
Nothing to send yet.
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
// popover; this file owns the rules. No DOM access at module scope and no
|
||||
// imports: the page and `node --test` both import this file.
|
||||
|
||||
const NAME_CHAR = /[a-z0-9-]/;
|
||||
// Uppercase too: "@Repo" must still name @repo — names are forced lowercase
|
||||
// by the workspace rules, and a query typed with a capital otherwise matches
|
||||
// nothing and opens no suggestions at all.
|
||||
const NAME_CHAR = /[a-z0-9-]/i;
|
||||
const MAX_MATCHES = 6;
|
||||
|
||||
/**
|
||||
@@ -23,11 +26,13 @@ export function mentionAt(text, caret) {
|
||||
}
|
||||
|
||||
// Names starting with the query first, then names containing it, in the
|
||||
// order given, at most six.
|
||||
// order given, at most six. Case-folded: folder names are lowercase by rule,
|
||||
// and "@Repo" should still find @repo rather than claim nothing matches.
|
||||
export function matchNames(names, query) {
|
||||
const q = String(query || "");
|
||||
const prefix = names.filter((n) => n.startsWith(q));
|
||||
const inside = names.filter((n) => !n.startsWith(q) && n.includes(q));
|
||||
const q = String(query || "").toLowerCase();
|
||||
const fold = (n) => String(n).toLowerCase();
|
||||
const prefix = names.filter((n) => fold(n).startsWith(q));
|
||||
const inside = names.filter((n) => !fold(n).startsWith(q) && fold(n).includes(q));
|
||||
return [...prefix, ...inside].slice(0, MAX_MATCHES);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,12 +25,14 @@ import {
|
||||
LOOKS_FILE,
|
||||
PUBLIC_DIR,
|
||||
SHIPPED_MODELS_FILE,
|
||||
UPDATE_CHECK_FILE,
|
||||
USER_MODELS_FILE,
|
||||
WORKSPACE_FILE,
|
||||
appendChat,
|
||||
appendEvent,
|
||||
chatForFrame,
|
||||
checkDocument,
|
||||
cleanupFindings,
|
||||
currentConversation,
|
||||
ensureDir,
|
||||
fileStamp,
|
||||
@@ -47,6 +49,7 @@ import {
|
||||
readWorkspace,
|
||||
rememberWorkspace,
|
||||
rememberedWorkspace,
|
||||
removeCleanup,
|
||||
remoteWarning,
|
||||
specKey,
|
||||
typedCount,
|
||||
@@ -59,6 +62,7 @@ import { CHAT_LIMIT, CHAT_MAX_CHARS, chatOffline } from "./public/chat.js";
|
||||
import { meterView } from "./public/meter.js";
|
||||
import { ACCENTS, DEFAULT_ACCENT, DEFAULT_CARD_WIDTH, cardWidth } from "./public/palette.js";
|
||||
import { defaultName, freeName, nameProblem } from "./public/workspace.js";
|
||||
import { checkForUpdate } from "./update-check.mjs";
|
||||
import { WORKSPACE_PICKER_PROMPT, pickFolder, pickerCommand } from "./picker.mjs";
|
||||
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
@@ -611,6 +615,7 @@ function stateFrame(state) {
|
||||
chat: { ...chatForFrame(chatEntries(), state), pickedUp: chatPickedUp(), offline: chatOfflineNow(state) },
|
||||
workspace: workspaceView(),
|
||||
meter: meterView(ledgerEntries()),
|
||||
...(updateInfo ? { update: updateInfo } : {}),
|
||||
have: haveKey(),
|
||||
};
|
||||
}
|
||||
@@ -623,7 +628,7 @@ function haveKey() {
|
||||
ledgerEntries();
|
||||
return (
|
||||
`${STARTED}.${rev}.${pending ? 1 : 0}${stop ? 1 : 0}.${chatSeen.stamp || ""}.${cursorSeen.stamp || ""}` +
|
||||
`.${workspaceSeen.stamp || ""}.${ledgerSeen.stamp || ""}`
|
||||
`.${workspaceSeen.stamp || ""}.${ledgerSeen.stamp || ""}.${updateInfo ? updateInfo.latest : ""}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -648,6 +653,12 @@ function recordSubmitted(state, actions) {
|
||||
if (action.type === "comment") {
|
||||
const pick = (list) => (Array.isArray(list) ? list.map(({ path, name }) => ({ path, name })) : []);
|
||||
item.sentNote = { at, text: String(action.text || ""), images: pick(action.images), files: pick(action.files) };
|
||||
// The person's side of the Notes thread. Left to the agent it was never
|
||||
// written, so a question asked in a note vanished once it was picked up
|
||||
// and the reply under it answered nothing on the page.
|
||||
if (item.sentNote.text.trim() || item.sentNote.images.length || item.sentNote.files.length) {
|
||||
item.thread = [...(Array.isArray(item.thread) ? item.thread : []), { who: "user", ...item.sentNote }];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const { i, type, ...rest } = action;
|
||||
@@ -933,6 +944,38 @@ function pushState() {
|
||||
if (stateNow) broadcast("state", stateFrame(stateNow));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------- update check */
|
||||
|
||||
// The version this console was installed as: install.js writes version.json
|
||||
// beside console.mjs; a dev checkout falls back to the repo root's.
|
||||
function installedVersion() {
|
||||
for (const file of [path.join(HERE, "version.json"), path.join(HERE, "..", "..", "version.json")]) {
|
||||
const version = readJson(file, {}).version;
|
||||
if (typeof version === "string" && version) return version;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Filled in once the boot-time check answers; until then, and whenever it
|
||||
// fails, the frame carries no `update` and the page shows no banner.
|
||||
let updateInfo = null;
|
||||
let updateLatest = null;
|
||||
|
||||
// Started at boot and never awaited: git may take up to its 10 s limit, and
|
||||
// nothing the person sees waits on it. The catch is not optional: a throw in
|
||||
// pushState() would otherwise be an unhandled rejection, which ends the server.
|
||||
function startUpdateCheck() {
|
||||
const installed = installedVersion();
|
||||
if (!installed) return;
|
||||
checkForUpdate({ installed, cacheFile: UPDATE_CHECK_FILE })
|
||||
.then((result) => {
|
||||
updateLatest = result?.latest ?? null;
|
||||
updateInfo = result?.updateAvailable ? { installed: result.installed, latest: result.latest } : null;
|
||||
if (updateInfo) pushState();
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
let agentSeenAt = Date.now();
|
||||
function agentLastSeen() {
|
||||
return new Date(agentSeenAt).toISOString();
|
||||
@@ -1039,10 +1082,8 @@ const server = http.createServer((req, res) => {
|
||||
}
|
||||
|
||||
if (pathname === "/version" && req.method === "GET") {
|
||||
for (const file of [path.join(HERE, "version.json"), path.join(HERE, "..", "..", "version.json")]) {
|
||||
const version = readJson(file, {}).version;
|
||||
if (typeof version === "string" && version) return json(res, 200, { version });
|
||||
}
|
||||
const version = installedVersion();
|
||||
if (version) return json(res, 200, { version, latest: updateLatest });
|
||||
return json(res, 404, { error: "no version" });
|
||||
}
|
||||
|
||||
@@ -1090,7 +1131,7 @@ const server = http.createServer((req, res) => {
|
||||
if (pathname === "/draft" && req.method === "POST") {
|
||||
if (!originOk(req, port)) return json(res, 403, { error: "bad origin" });
|
||||
return readBody(req, (err, body) => {
|
||||
if (err) return json(res, 400, { error: "body must be JSON" });
|
||||
if (err) return json(res, err.tooBig ? 413 : 400, { error: err.tooBig ? "too large" : "body must be JSON" });
|
||||
// Debounced client-side; this is just the durable mirror. Twenty minutes
|
||||
// of someone's structured answers must not die with a closed tab.
|
||||
try {
|
||||
@@ -1115,7 +1156,7 @@ const server = http.createServer((req, res) => {
|
||||
if (pathname === "/looks" && req.method === "POST") {
|
||||
if (!originOk(req, port)) return json(res, 403, { error: "bad origin" });
|
||||
return readBody(req, (err, body) => {
|
||||
if (err) return json(res, 400, { error: "body must be JSON" });
|
||||
if (err) return json(res, err.tooBig ? 413 : 400, { error: err.tooBig ? "too large" : "body must be JSON" });
|
||||
// `set` carries only the keys one tab changed, merged onto what is on
|
||||
// disk, so a tab holding stale settings cannot undo another tab's change.
|
||||
const set = body && body.set !== undefined ? cleanLooks(body.set) : null;
|
||||
@@ -1141,7 +1182,7 @@ const server = http.createServer((req, res) => {
|
||||
if (pathname === "/models" && req.method === "POST") {
|
||||
if (!originOk(req, port)) return json(res, 403, { error: "bad origin" });
|
||||
return readBody(req, (err, body) => {
|
||||
if (err) return json(res, 400, { error: "body must be JSON" });
|
||||
if (err) return json(res, err.tooBig ? 413 : 400, { error: err.tooBig ? "too large" : "body must be JSON" });
|
||||
const { models, error } = cleanModels(body && body.models);
|
||||
if (error) return json(res, 400, { error });
|
||||
try {
|
||||
@@ -1154,6 +1195,24 @@ const server = http.createServer((req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
// User Preferences -> Cleanup. `{ scan: true }` lists what is not needed in
|
||||
// ~/.plan2code; `{ delete: [id] }` removes those of the ids a fresh scan
|
||||
// still finds. Never this session, never a path the page sent.
|
||||
if (pathname === "/cleanup" && req.method === "POST") {
|
||||
if (!originOk(req, port)) return json(res, 403, { error: "bad origin" });
|
||||
return readBody(req, (err, body) => {
|
||||
if (err) return json(res, err.tooBig ? 413 : 400, { error: err.tooBig ? "too large" : "body must be JSON" });
|
||||
if (body && Array.isArray(body.delete)) {
|
||||
return removeCleanup(body.delete, { skipSid: SID })
|
||||
.then((done) => json(res, 200, { ok: true, ...done }))
|
||||
.catch((e) => json(res, 500, { error: String(e.message) }));
|
||||
}
|
||||
return cleanupFindings({ skipSid: SID })
|
||||
.then(({ items, bytes }) => json(res, 200, { ok: true, bytes, items: items.map(({ path: _p, ...item }) => item) }))
|
||||
.catch((e) => json(res, 500, { error: String(e.message) }));
|
||||
});
|
||||
}
|
||||
|
||||
if (pathname === "/upload" && req.method === "POST") {
|
||||
if (!originOk(req, port)) return json(res, 403, { error: "bad origin" });
|
||||
const contentType = String(req.headers["content-type"] || "");
|
||||
@@ -1260,7 +1319,7 @@ const server = http.createServer((req, res) => {
|
||||
if (pathname === "/submit" && req.method === "POST") {
|
||||
if (!originOk(req, port)) return json(res, 403, { error: "bad origin" });
|
||||
return readBody(req, (err, body) => {
|
||||
if (err) return json(res, 400, { error: "body must be JSON" });
|
||||
if (err) return json(res, err.tooBig ? 413 : 400, { error: err.tooBig ? "too large" : "body must be JSON" });
|
||||
if (!body || !Array.isArray(body.actions) || body.actions.length === 0) {
|
||||
return json(res, 400, { error: "actions must be a non-empty array" });
|
||||
}
|
||||
@@ -1361,6 +1420,7 @@ const server = http.createServer((req, res) => {
|
||||
if (pathname === "/chat" && req.method === "POST") {
|
||||
if (!originOk(req, port)) return json(res, 403, { error: "bad origin" });
|
||||
return readBody(req, (err, body) => {
|
||||
if (err && err.tooBig) return json(res, 413, { error: "too large" });
|
||||
if (err || !body || typeof body !== "object" || Array.isArray(body)) return json(res, 400, { error: "bad" });
|
||||
const state = readState() || {};
|
||||
const current = currentConversation(chatEntries()).conversation;
|
||||
@@ -1424,6 +1484,7 @@ const server = http.createServer((req, res) => {
|
||||
if (pathname === "/chat/decision" && req.method === "POST") {
|
||||
if (!originOk(req, port)) return json(res, 403, { error: "bad origin" });
|
||||
return readBody(req, (err, body) => {
|
||||
if (err && err.tooBig) return json(res, 413, { error: "too large" });
|
||||
if (err || !body || typeof body !== "object" || Array.isArray(body)) return json(res, 400, { error: "bad" });
|
||||
if (body.decision !== "approve" && body.decision !== "decline") return json(res, 400, { error: "bad" });
|
||||
if (body.text !== undefined && typeof body.text !== "string") return json(res, 400, { error: "bad" });
|
||||
@@ -1472,6 +1533,7 @@ const server = http.createServer((req, res) => {
|
||||
if (Object.hasOwn(workspaceRoutes, pathname) && req.method === "POST") {
|
||||
if (!originOk(req, port)) return json(res, 403, { error: "bad origin" });
|
||||
return readBody(req, (err, body) => {
|
||||
if (err && err.tooBig) return json(res, 413, { error: "too large" });
|
||||
if (err || !body || typeof body !== "object" || Array.isArray(body)) return json(res, 400, { error: "bad" });
|
||||
let answer;
|
||||
try {
|
||||
@@ -1489,6 +1551,7 @@ const server = http.createServer((req, res) => {
|
||||
if (pathname === "/workspace/scope" && req.method === "POST") {
|
||||
if (!originOk(req, port)) return json(res, 403, { error: "bad origin" });
|
||||
return readBody(req, (err, body) => {
|
||||
if (err && err.tooBig) return json(res, 413, { error: "too large" });
|
||||
if (err || !body || typeof body !== "object" || Array.isArray(body)) return json(res, 400, { error: "bad" });
|
||||
const spec = typeof body.spec === "string" ? body.spec : "";
|
||||
if (spec && !/^specs\/[^/\\]+$/.test(specKey(spec))) return json(res, 400, { reason: "bad-spec" });
|
||||
@@ -1589,15 +1652,19 @@ function readBody(req, cb) {
|
||||
let tooBig = false;
|
||||
req.on("data", (c) => {
|
||||
size += c.length;
|
||||
// Drain past the cap rather than destroy, exactly like readRaw: a
|
||||
// destroyed request emits 'close', never 'end' or 'error', so cb would
|
||||
// never run and the page would see a reset instead of the 413 that names
|
||||
// the problem.
|
||||
if (size > MAX_BODY) {
|
||||
tooBig = true;
|
||||
req.destroy();
|
||||
chunks.length = 0;
|
||||
return;
|
||||
}
|
||||
chunks.push(c);
|
||||
});
|
||||
req.on("end", () => {
|
||||
if (tooBig) return cb(new Error("too large"));
|
||||
if (tooBig) return cb(Object.assign(new Error("too large"), { tooBig: true }));
|
||||
try {
|
||||
cb(null, JSON.parse(Buffer.concat(chunks).toString("utf8")));
|
||||
} catch (e) {
|
||||
@@ -1834,6 +1901,9 @@ function onListening(port) {
|
||||
bootWorkspace();
|
||||
} catch {}
|
||||
process.stdout.write(JSON.stringify({ type: "ready", url, port, sid: SID }) + "\n");
|
||||
try {
|
||||
startUpdateCheck();
|
||||
} catch {}
|
||||
try {
|
||||
process.send?.({ type: "listening", port });
|
||||
} catch {}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
// Plan2Code Web Console - is a newer Plan2Code release out?
|
||||
//
|
||||
// `git ls-remote --tags` needs no API token and no rate-limited REST call,
|
||||
// rides on the person's own git and proxy setup, and the newest `vX.Y.Z`
|
||||
// release tag is "latest". The server
|
||||
// starts this at boot and never waits on it; the answer, failures included, is
|
||||
// cached for an hour so a burst of sessions asks GitHub once.
|
||||
//
|
||||
// Nothing here reads, stores or sends a credential: git authenticates itself,
|
||||
// with every prompt turned off so a missing login fails fast instead of
|
||||
// opening a window nobody asked for.
|
||||
//
|
||||
// Node built-ins only.
|
||||
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { spawn } from "node:child_process";
|
||||
|
||||
export const REPO_URL = "https://github.com/jparkerweb/plan2code.git";
|
||||
export const RELEASES_URL = "https://github.com/jparkerweb/plan2code/releases/";
|
||||
export const CACHE_MS = 60 * 60 * 1000;
|
||||
|
||||
const SEMVER = /^\d+\.\d+\.\d+$/;
|
||||
const TAG_REF = /refs\/tags\/v(\d+\.\d+\.\d+)$/;
|
||||
|
||||
/** -1, 0 or 1 comparing two plain X.Y.Z versions numerically; null unless both are X.Y.Z. */
|
||||
export function compareVersions(a, b) {
|
||||
if (typeof a !== "string" || typeof b !== "string" || !SEMVER.test(a) || !SEMVER.test(b)) return null;
|
||||
const x = a.split(".").map(Number);
|
||||
const y = b.split(".").map(Number);
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (x[i] !== y[i]) return x[i] < y[i] ? -1 : 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The highest `vX.Y.Z` tag in `git ls-remote --tags` output, without the `v`.
|
||||
* Peeled lines (`^{}`) never match, so an annotated tag counts once, and
|
||||
* pre-releases or other tag names are ignored. Null when nothing matches.
|
||||
*/
|
||||
export function latestTag(text) {
|
||||
if (typeof text !== "string") return null;
|
||||
let best = null;
|
||||
for (const line of text.split(/\r?\n/)) {
|
||||
const m = TAG_REF.exec(line.trim());
|
||||
if (m && (best === null || compareVersions(m[1], best) > 0)) best = m[1];
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
function readCache(cacheFile, now) {
|
||||
try {
|
||||
const cached = JSON.parse(fs.readFileSync(cacheFile, "utf8"));
|
||||
if (!cached || typeof cached.checkedAt !== "number" || now - cached.checkedAt >= CACHE_MS) return undefined;
|
||||
return typeof cached.latest === "string" ? cached.latest : null;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function writeCache(cacheFile, data) {
|
||||
const tmp = cacheFile + "." + process.pid + ".tmp";
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(cacheFile), { recursive: true });
|
||||
fs.writeFileSync(tmp, JSON.stringify(data, null, 2));
|
||||
fs.renameSync(tmp, cacheFile);
|
||||
} catch {
|
||||
try {
|
||||
fs.rmSync(tmp, { force: true });
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* `git ls-remote --tags` against the repo: resolves its stdout, or null when
|
||||
* git is missing, fails, or is still going after `timeoutMs`. No shell, no
|
||||
* window, no prompt.
|
||||
*/
|
||||
export function runLsRemote({ timeoutMs = 10000 } = {}) {
|
||||
return new Promise((resolve) => {
|
||||
let settled = false;
|
||||
const done = (value) => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
clearTimeout(timer);
|
||||
resolve(value);
|
||||
};
|
||||
const env = { ...process.env, GIT_TERMINAL_PROMPT: "0", GCM_INTERACTIVE: "never" };
|
||||
if (!process.env.GIT_SSH_COMMAND) env.GIT_SSH_COMMAND = "ssh -o BatchMode=yes";
|
||||
let child;
|
||||
try {
|
||||
child = spawn("git", ["ls-remote", "--tags", REPO_URL], {
|
||||
shell: false,
|
||||
windowsHide: true,
|
||||
stdio: ["ignore", "pipe", "ignore"],
|
||||
env,
|
||||
});
|
||||
} catch {
|
||||
return resolve(null);
|
||||
}
|
||||
const timer = setTimeout(() => {
|
||||
try {
|
||||
child.kill();
|
||||
} catch {}
|
||||
done(null);
|
||||
}, timeoutMs);
|
||||
timer.unref?.();
|
||||
let out = "";
|
||||
child.stdout.setEncoding("utf8");
|
||||
child.stdout.on("data", (chunk) => {
|
||||
out += chunk;
|
||||
});
|
||||
child.on("error", () => done(null));
|
||||
child.on("close", (code) => done(code === 0 ? out : null));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether `installed` is behind the newest release: `{ installed, latest,
|
||||
* updateAvailable }`, or null when either version is unknown. Reuses a cache
|
||||
* under an hour old, and caches a failed lookup as `latest: null` so it is
|
||||
* not retried until the hour is up. Never throws.
|
||||
*/
|
||||
export async function checkForUpdate({ installed, cacheFile, now = Date.now(), run = runLsRemote }) {
|
||||
try {
|
||||
let latest = readCache(cacheFile, now);
|
||||
if (latest === undefined) {
|
||||
latest = latestTag(await run());
|
||||
writeCache(cacheFile, { checkedAt: now, latest });
|
||||
}
|
||||
const order = compareVersions(installed, latest);
|
||||
if (latest === null || order === null) return null;
|
||||
return { installed, latest, updateAvailable: order < 0 };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Plan2Code",
|
||||
"version": "2.4.1",
|
||||
"version": "2.4.2",
|
||||
"description": "A structured 4-step workflow methodology for AI-assisted software development",
|
||||
"keywords": [
|
||||
"ai",
|
||||
@@ -17,6 +17,6 @@
|
||||
"url": "https://github.com/jparkerweb/plan2code"
|
||||
},
|
||||
"homepage": "https://github.com/jparkerweb/plan2code",
|
||||
"releaseDate": "2026-10-04",
|
||||
"releaseDate": "2026-10-05",
|
||||
"mode": "utility"
|
||||
}
|
||||
Reference in new issue
Block a user