mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-30 23:59:20 -08:00
Remember the terminal or web console choice, refresh the launcher model menus (v3.2.2)
AI Assisted
This commit is contained in:
1 parent
f1d087ba47
commit
ccf82c4eb7
60 files changed
+477
-317
No files matched your search
@@ -1,6 +1,6 @@
|
||||
// Fails when the console opening paragraph of a skill drifts from the shared one.
|
||||
//
|
||||
// Eighteen skills open with the same "web console or terminal?" paragraph. Only
|
||||
// Twenty-one skills open with the same "terminal or web console?" paragraph. Only
|
||||
// the workflow name, the notes file and a few skill-specific clauses may differ;
|
||||
// the shared sentences below must read the same in every one, so a fix to one
|
||||
// skill's opening cannot silently skip the others. Matching ignores case and
|
||||
@@ -15,19 +15,16 @@ import { fileURLToPath } from "node:url";
|
||||
// own words on purpose is listed in EXEMPT with the reason.
|
||||
export const SHARED = [
|
||||
{ id: "first", text: "The FIRST thing you do, before anything else in this file" },
|
||||
{ id: "ask", text: "**web console** (browser page, suggested) or **terminal**?" },
|
||||
{ id: "ask", text: '**terminal** or **web console**? Run `node "<D>/console.mjs" interface`' },
|
||||
{ id: "rule", text: "and follow its rule: the request or the saved default decides; ask only if it says so or the command fails." },
|
||||
{ id: "run", text: 'run `node "<D>/console.mjs" open --workflow {w}` before reading' },
|
||||
{ id: "dir", text: "<D>: references/web-console/ beside this SKILL.md" },
|
||||
{ id: "dirfile", text: "or the dir in ~/.plan2code/console/console-dir" },
|
||||
{ id: "read", text: "then read <D>/console.md" },
|
||||
{ id: "switch", text: "Switchable anytime." },
|
||||
{ id: "web", text: "If the argument already says which (`--web` or `Use the web console for this session.`), take it and do not ask; drop the flag." },
|
||||
{ id: "dash", text: "Launched by the dashboard? Its session is already open: resume it (console-launches.md)" },
|
||||
];
|
||||
|
||||
export const EXEMPT = {
|
||||
// Implement + Review defers to Implementation Mode's own Interface question.
|
||||
"plan2code-3-implement-review": { ask: "defers to Implementation Mode's Interface question", run: "the question is Implementation Mode's" , switch: "Implementation Mode's Interface section says it" },
|
||||
// Git runs an instruction in the argument in the terminal at once and has its own hand-off lines.
|
||||
"plan2code-git": { dash: "also resumes from Commit it now and the Changelog hand-off", first: "opens with the run-at-once rule for an argument" },
|
||||
};
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// Fails when a built prompt names an agent product's tool by its product name.
|
||||
// Fails when a built prompt names an agent product's tool by its product name,
|
||||
// or bakes --web into a skill command.
|
||||
//
|
||||
// Prompts are read by many agents, and each one calls the same tool something
|
||||
// else. Prompt text says what to do ("ask with the question tool", "list the
|
||||
// folder") and never what one product's tool is called. This reads every
|
||||
// Markdown file in the built skills/ tree, so run it after
|
||||
// `node install.js --build-skills`.
|
||||
// folder") and never what one product's tool is called. Skill commands are
|
||||
// printed bare so the person's saved terminal or web console default decides;
|
||||
// a baked --web overrides it. This reads every Markdown file in the built
|
||||
// skills/ tree, so run it after `node install.js --build-skills`.
|
||||
// Usage: node scripts/check-prompt-wording.mjs [skillsDir] (defaults to ./skills)
|
||||
|
||||
import fs from "node:fs";
|
||||
@@ -29,6 +31,7 @@ export const BANNED = [
|
||||
];
|
||||
|
||||
const PATTERN = new RegExp(`(?<![A-Za-z0-9_])(${BANNED.join("|")})(?![A-Za-z0-9_])`);
|
||||
const BAKED_WEB_PATTERN = /`[^`\n]*\/plan2code[\w-]*[^`\n]*--web\b[^`\n]*`/g;
|
||||
|
||||
function* markdownFiles(dir) {
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
@@ -52,6 +55,21 @@ export function findBanned(dir) {
|
||||
return hits;
|
||||
}
|
||||
|
||||
// Returns [{ file, line, text }] for every skill command with --web baked in.
|
||||
export function findBakedWeb(dir) {
|
||||
const hits = [];
|
||||
for (const file of markdownFiles(dir)) {
|
||||
fs.readFileSync(file, "utf8")
|
||||
.split("\n")
|
||||
.forEach((lineText, i) => {
|
||||
for (const m of lineText.matchAll(BAKED_WEB_PATTERN)) {
|
||||
hits.push({ file: path.relative(dir, file).split(path.sep).join("/"), line: i + 1, text: m[0] });
|
||||
}
|
||||
});
|
||||
}
|
||||
return hits;
|
||||
}
|
||||
|
||||
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||||
const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
||||
const dir = process.argv[2] ? path.resolve(process.argv[2]) : path.join(root, "skills");
|
||||
@@ -60,10 +78,18 @@ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.me
|
||||
process.exit(1);
|
||||
}
|
||||
const hits = findBanned(dir);
|
||||
const baked = findBakedWeb(dir);
|
||||
if (hits.length) {
|
||||
for (const h of hits) console.error(` FAIL ${h.file}:${h.line} names a product tool: ${h.name}`);
|
||||
console.error(" Say what to do in neutral words (\"the question tool\", \"list the folder\").");
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log("Built prompts name no product tool.");
|
||||
}
|
||||
console.log("Built prompts name no product tool.");
|
||||
if (baked.length) {
|
||||
for (const h of baked) console.error(` FAIL ${h.file}:${h.line} bakes --web into a skill command: ${h.text}`);
|
||||
console.error(" Write the command bare and add \"(add `--web` for the web console)\" after it: a baked flag overrides the person's saved terminal or web console default.");
|
||||
} else {
|
||||
console.log("Built prompts bake no --web into skill commands.");
|
||||
}
|
||||
if (hits.length || baked.length) process.exit(1);
|
||||
}
|
||||
@@ -9,7 +9,6 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import http from "node:http";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { looksFromMessage, terminalFontStep, TERMINAL_FONT_DEFAULT, TERMINAL_FONT_MIN, TERMINAL_FONT_MAX, splitterFraction, splitterAria, terminalTitle, barFit, terminalAnsi, TERMINAL_ANSI, hexToRgba, helloRetryAction, retryLabel, RETRY_AFTER_SECONDS, attentionSignal, commandSegments, plainCommandText, menuStep, pageNotShownView, pageDetailsLine, redactSessionUrl, barNextSteps, continueKeys, defaultRightFraction, folderName, folderPickerRows, pickDefaultAgent, taskbarSwitch, windowTitleFor, deadConsoleAction, loopBanner, loopRunText, loopLocks, loopStopLabels, loopWindowTitle, CONSOLE_ASIDE_BREAKPOINT_PX, NEXT_STEP_LABELS, NEW_RELEASE_COMMAND, STILL_WAITING_MS, STILL_WAITING_TEXT, waitingView, friendlyError, endedView, confirmButtons, trapTab, SHORTCUTS, shortcutAction, shortcutLabel, tipWithShortcut, shortcutFromMessage, clipboardAction, releaseAfterCheck, releaseNotesUrl, reasonSentence, UPDATE_RECHECK_MS } from "../plan2code-app/ui/meter.js";
|
||||
@@ -1136,117 +1135,6 @@ test("barFit drops the model text first, then the status line, and only when the
|
||||
assert.deepEqual(barFit({ available: 500, needed: 800 }), { model: false, status: false }, "no parts measured, none claimed");
|
||||
});
|
||||
|
||||
// The app's ui/ folder over HTTP on a free local port, for a test that needs app.js to run.
|
||||
function serveFolder(dir) {
|
||||
const TYPES = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".woff2": "font/woff2" };
|
||||
const server = http.createServer((req, res) => {
|
||||
const file = path.join(dir, decodeURIComponent(new URL(req.url, "http://x").pathname));
|
||||
if (!file.startsWith(dir) || !fs.existsSync(file) || !fs.statSync(file).isFile()) {
|
||||
res.writeHead(404).end();
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, { "content-type": TYPES[path.extname(file)] || "application/octet-stream" });
|
||||
fs.createReadStream(file).pipe(res);
|
||||
});
|
||||
return new Promise((resolve) => server.listen(0, "127.0.0.1", () => resolve(server)));
|
||||
}
|
||||
|
||||
test("the bar's step text uses the room the row has; model and status drop before it is cut, and its buttons never shrink", async (t) => {
|
||||
if (!findBrowser()) return t.skip("no Chrome or Edge installed");
|
||||
const browser = await launchBrowser();
|
||||
try {
|
||||
const page = await browser.newPage({ viewport: { width: 1800, height: 600 } });
|
||||
// Later start-up steps trip over the stub's nulls; the bar is wired before them,
|
||||
// and "the model alone drops" below shows fitBar() ran.
|
||||
page.on("pageerror", () => {});
|
||||
// Enough of __TAURI__ for app.js to run, so its real fitBar() lays out the row:
|
||||
// every command answers null (platform_info a platform), every window call resolves.
|
||||
await page.addInitScript(() => {
|
||||
const resolved = () => Promise.resolve();
|
||||
const win = new Proxy({}, { get: () => resolved });
|
||||
const known = {
|
||||
core: { invoke: (cmd) => Promise.resolve(cmd === "platform_info" ? { os: "linux" } : null), Channel: class {} },
|
||||
window: { getCurrentWindow: () => win },
|
||||
event: { listen: () => Promise.resolve(() => {}) },
|
||||
};
|
||||
window.__TAURI__ = new Proxy(known, { get: (all, key) => all[key] || new Proxy({}, { get: () => resolved }) });
|
||||
});
|
||||
// app.js is a module, which Chrome will not load from file://: serve the folder.
|
||||
const server = await serveFolder(path.dirname(INDEX_HTML_PATH));
|
||||
t.after(() => server.close());
|
||||
await page.goto(`http://127.0.0.1:${server.address().port}/index.html`, { waitUntil: "networkidle" });
|
||||
await page.evaluate(() => {
|
||||
const show = (id, text) => {
|
||||
const el = document.getElementById(id);
|
||||
el.hidden = false;
|
||||
if (text !== undefined) el.textContent = text;
|
||||
};
|
||||
document.getElementById("agent-none").hidden = true;
|
||||
show("project-menu-button");
|
||||
document.getElementById("project-name").textContent = "plan2code";
|
||||
show("agent-restart");
|
||||
show("agent-menu-button");
|
||||
document.getElementById("agent-name").textContent = "Claude Code";
|
||||
show("agent-model", "opus 5.5 xhigh");
|
||||
document.getElementById("agent-status").textContent = "Working: reading the plan and every phase file";
|
||||
show("next-step");
|
||||
const text = document.getElementById("next-step-text");
|
||||
text.textContent = "npx fetches it quietly first, which can take a minute or two.";
|
||||
text.className = "is-warn is-busy";
|
||||
show("next-step-button", "Update and restart");
|
||||
show("next-step-more", "+1 more");
|
||||
show("next-step-notes");
|
||||
});
|
||||
const settle = () => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
||||
const measure = () =>
|
||||
page.evaluate(() => {
|
||||
const row = document.getElementById("bar-row");
|
||||
const text = document.getElementById("next-step-text");
|
||||
const box = (id) => document.getElementById(id).getBoundingClientRect();
|
||||
const menu = box("app-menu-button");
|
||||
const buttons = ["next-step-button", "next-step-more", "next-step-notes"].map(box);
|
||||
return {
|
||||
noModel: row.classList.contains("no-model"),
|
||||
noStatus: row.classList.contains("no-status"),
|
||||
cut: text.scrollWidth > text.clientWidth,
|
||||
textWidth: text.clientWidth,
|
||||
buttonWidths: buttons.map((b) => Math.round(b.width)),
|
||||
overlap: buttons.some((b) => b.right > menu.left + 0.5),
|
||||
menuInside: menu.width > 0 && menu.right <= row.getBoundingClientRect().right + 0.5,
|
||||
};
|
||||
});
|
||||
await settle();
|
||||
const wide = await measure();
|
||||
assert.deepEqual([wide.noModel, wide.noStatus, wide.cut], [false, false, false], "a wide window shows everything, the whole line included");
|
||||
assert.ok(wide.textWidth > 320, `wider than the old 320px cap (${wide.textWidth}px)`);
|
||||
const seen = new Set();
|
||||
// Down to the app's minimum width (tauri.conf.json minWidth 960).
|
||||
for (let width = 1800; width >= 960; width -= 20) {
|
||||
await page.setViewportSize({ width, height: 600 });
|
||||
await settle();
|
||||
const at = await measure();
|
||||
if (at.cut) assert.ok(at.noModel && at.noStatus, `${width}px: the line is cut only after the model and status dropped`);
|
||||
if (at.noStatus) assert.ok(at.noModel, `${width}px: the model drops before the status`);
|
||||
assert.deepEqual(at.buttonWidths, wide.buttonWidths, `${width}px: the step buttons keep their width`);
|
||||
assert.equal(at.overlap, false, `${width}px: no step button runs under the menu button`);
|
||||
assert.equal(at.menuInside, true, `${width}px: the menu button stays inside the row`);
|
||||
seen.add(`${at.noModel}/${at.noStatus}/${at.cut}`);
|
||||
}
|
||||
assert.ok(seen.has("true/false/false"), `the model alone drops at some width (${[...seen]})`);
|
||||
assert.ok(seen.has("true/true/true"), `the line is cut at the narrowest widths (${[...seen]})`);
|
||||
assert.equal(await page.evaluate(() => getComputedStyle(document.getElementById("next-step-text")).textOverflow), "ellipsis");
|
||||
// Below the minimum, the row runs out at its end as it always did: the text
|
||||
// has shrunk to nothing, but its buttons are never squeezed under the menu.
|
||||
await page.setViewportSize({ width: 400, height: 600 });
|
||||
await settle();
|
||||
const tight = await measure();
|
||||
assert.deepEqual(tight.buttonWidths, wide.buttonWidths, "400px: the step buttons keep their width");
|
||||
assert.equal(tight.overlap, false, "400px: no step button runs under the menu button");
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("the top bar collapses instead of scrolling, and +N more is a button that lists the other steps", () => {
|
||||
assert.doesNotMatch(INDEX_HTML, /#bar-row \{[^}]*overflow-x: auto/, "no sideways scrolling row");
|
||||
assert.match(INDEX_HTML, /#bar-row\.no-model #agent-model, #bar-row\.no-status #agent-status \{ display: none; \}/);
|
||||
|
||||
@@ -32,15 +32,15 @@ test("the real prompts pass", () => {
|
||||
|
||||
test("a drifted shared sentence is named with its skill", () => {
|
||||
const dir = copySrc();
|
||||
edit(dir, "plan2code-review.md", "Switchable anytime.", "You can switch whenever.");
|
||||
edit(dir, "plan2code-review.md", "and follow its rule", "and follow its nose");
|
||||
const problems = check(dir);
|
||||
assert.equal(problems.length, 1);
|
||||
assert.match(problems[0], /plan2code-review\.md: shared sentence "switch"/);
|
||||
assert.match(problems[0], /plan2code-review\.md: shared sentence "rule"/);
|
||||
});
|
||||
|
||||
test("punctuation and case alone do not count as drift", () => {
|
||||
const dir = copySrc();
|
||||
edit(dir, "plan2code-test.md", "Switchable anytime.", "switchable anytime.");
|
||||
edit(dir, "plan2code-test.md", "and follow its rule:", "AND FOLLOW ITS RULE;");
|
||||
edit(dir, "plan2code-test.md", "Its session is already open: resume it", "Its session is already open \u2014 resume it");
|
||||
assert.deepEqual(check(dir), []);
|
||||
});
|
||||
@@ -73,7 +73,7 @@ test("helpers", () => {
|
||||
|
||||
test("the CLI exits 1 on drift", () => {
|
||||
const dir = copySrc();
|
||||
edit(dir, "plan2code-git.md", "Switchable anytime.", "Whenever.");
|
||||
edit(dir, "plan2code-git.md", "ask only if it says so", "ask only if it wants");
|
||||
const r = spawnSync(process.execPath, [path.join(HERE, "check-console-openings.mjs"), dir], { encoding: "utf8" });
|
||||
assert.equal(r.status, 1);
|
||||
assert.match(r.stderr, /plan2code-git\.md/);
|
||||
|
||||
@@ -5,7 +5,7 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { BANNED, findBanned } from "./check-prompt-wording.mjs";
|
||||
import { BANNED, findBanned, findBakedWeb } from "./check-prompt-wording.mjs";
|
||||
|
||||
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
||||
const ROOT = path.dirname(HERE);
|
||||
@@ -37,6 +37,16 @@ test("a longer word that contains a banned name is not a hit", () => {
|
||||
assert.deepEqual(findBanned(dir), []);
|
||||
});
|
||||
|
||||
test("a baked --web in a skill command is found, with its file and line", () => {
|
||||
const dir = fixture({ "x/SKILL.md": "fine\n`NEXT STEP: /plan2code-1-plan --web`\n" });
|
||||
assert.deepEqual(findBakedWeb(dir), [{ file: "x/SKILL.md", line: 2, text: "`NEXT STEP: /plan2code-1-plan --web`" }]);
|
||||
});
|
||||
|
||||
test("a bare command with the web-console note is not a hit", () => {
|
||||
const dir = fixture({ "a.md": "Run `/plan2code-1-plan` (add `--web` for the web console)\n`--web` is the console flag\n" });
|
||||
assert.deepEqual(findBakedWeb(dir), []);
|
||||
});
|
||||
|
||||
test("the CLI exits 1 on a hit and 0 on a clean tree", () => {
|
||||
const bad = fixture({ "a.md": "never use Glob\n" });
|
||||
const r = spawnSync(process.execPath, [path.join(HERE, "check-prompt-wording.mjs"), bad], { encoding: "utf8" });
|
||||
@@ -49,3 +59,7 @@ test("the CLI exits 1 on a hit and 0 on a clean tree", () => {
|
||||
test("the built skills tree names no product tool", { skip: !fs.existsSync(path.join(ROOT, "skills")) }, () => {
|
||||
assert.deepEqual(findBanned(path.join(ROOT, "skills")), []);
|
||||
});
|
||||
|
||||
test("the built skills tree bakes no --web into skill commands", { skip: !fs.existsSync(path.join(ROOT, "skills")) }, () => {
|
||||
assert.deepEqual(findBakedWeb(path.join(ROOT, "skills")), []);
|
||||
});
|
||||
@@ -695,7 +695,10 @@ test("launcher: on Windows the saved user PATH fills in folders the inherited PA
|
||||
addSavedWindowsPath();
|
||||
const dirs = process.env[pathKey].split(";");
|
||||
assert.equal(dirs[0], "C:\\stale-terminal-path", "the inherited PATH keeps its place in front");
|
||||
assert.ok(dirs.includes(first), `${first} is added from the saved PATH`);
|
||||
// Compared as the launcher dedupes them: the machine PATH may already hold the
|
||||
// same folder spelled another way (a trailing backslash, another case), and that copy wins.
|
||||
const id = (dir) => path.resolve(dir.replace(/^"|"$/g, "")).toLowerCase();
|
||||
assert.ok(dirs.map(id).includes(id(first)), `${first} is added from the saved PATH`);
|
||||
const length = dirs.length;
|
||||
addSavedWindowsPath();
|
||||
assert.equal(process.env[pathKey].split(";").length, length, "a second call adds nothing twice");
|
||||
@@ -1793,8 +1796,8 @@ test("launcher menus: the agent tip shows once, and the model menu prints ids in
|
||||
assert.doesNotMatch(first.stdout, /That runs outside the desktop app/, "no app installed, so no line about it");
|
||||
// ids padded to the longest (opusplan), then the description; the first run's Enter is the agent's.
|
||||
assert.match(first.stdout, /^ {2}1\) default {3}your account setting$/m);
|
||||
assert.match(first.stdout, /^ {2}2\) sonnet {4}latest Sonnet$/m);
|
||||
assert.match(first.stdout, /^ {2}5\) opusplan {2}Opus in plan mode, Sonnet otherwise$/m);
|
||||
assert.match(first.stdout, /^ {2}3\) sonnet {4}latest Sonnet$/m);
|
||||
assert.match(first.stdout, /^ {2}7\) opusplan {2}Opus in plan mode, Sonnet otherwise$/m);
|
||||
assert.match(first.stdout, /Choice \[agent default\]: /);
|
||||
assert.ok(box.argsOf("claude").includes("opus"), "a typed description picks its model");
|
||||
const state = JSON.parse(fs.readFileSync(box.stateFile, "utf8"));
|
||||
@@ -1806,8 +1809,8 @@ test("launcher menus: the agent tip shows once, and the model menu prints ids in
|
||||
assert.equal(second.status, 0, second.stderr);
|
||||
assert.equal(second.sent, 3, second.stdout);
|
||||
assert.doesNotMatch(second.stdout, /skip this launcher/);
|
||||
assert.match(second.stdout, /^ {2}3\) opus {6}latest Opus \(last used\)$/m);
|
||||
assert.match(second.stdout, /Choice \[3\]: /);
|
||||
assert.match(second.stdout, /^ {2}4\) opus {6}latest Opus \(last used\)$/m);
|
||||
assert.match(second.stdout, /Choice \[4\]: /);
|
||||
assert.ok(box.argsOf("claude").includes("opus"));
|
||||
});
|
||||
|
||||
|
||||
@@ -166,12 +166,12 @@ test("pathfinder trail: exact footer for forms A, B and C", () => {
|
||||
assert.equal(P("trail", "audit-export", "--form", "B", "--item", "1", "--item", "2", "--item", "3", "--item", "4").code, 5, "three-probe cap");
|
||||
assert.equal(P("trail", "audit-export", "--form", "C").json.error, "claim-open", "no menu while a claim is open");
|
||||
const a = P("trail", "audit-export", "--form", "A", "--text").stdout;
|
||||
assert.ok(a.endsWith("NEXT STEP · start a new conversation and run:\n`/plan2code-0-pathfinder specs/audit-export/pathfinder --web`\n"), a);
|
||||
assert.ok(a.endsWith("NEXT STEP · start a new conversation and run:\n`/plan2code-0-pathfinder specs/audit-export/pathfinder`\nAdd `--web` for the web console.\n"), a);
|
||||
fs.appendFileSync(path.join(root, pf, "questions/03-testing-posture.md"), "\n## Answer\n\nUnit; `Run after each phase`; `Critical paths`.\n\n**Gist:** Unit tests, run after each phase.\n");
|
||||
P("resolve", "audit-export", "03");
|
||||
const c = P("trail", "audit-export", "--form", "C", "--resolved-this-session", "3");
|
||||
assert.equal(c.code, 0, c.stderr);
|
||||
assert.ok(c.json.text.endsWith("OR START FRESH · new conversation, paste:\n`/plan2code-0-pathfinder specs/audit-export/pathfinder --web`"));
|
||||
assert.ok(c.json.text.endsWith("OR START FRESH · new conversation, paste:\n`/plan2code-0-pathfinder specs/audit-export/pathfinder`\nAdd `--web` for the web console."));
|
||||
assert.deepEqual(c.json.menu.options.map((o) => o.label), ["Row-count ceiling", "Start fresh"]);
|
||||
assert.equal(c.json.menu.recommended, "Start fresh", "the checkpoint after ~3 decisions");
|
||||
assert.equal(c.json.menu.options.find((o) => o.label === "Start fresh").fresh, true, "the page reads it as a clean start");
|
||||
@@ -192,11 +192,12 @@ test("pathfinder trail: a cleared map arrives; init first only while AGENTS.md i
|
||||
" Confidence: solid, but Requirements, Risk are borderline.",
|
||||
"",
|
||||
"NEXT STEP · start a new conversation and run:",
|
||||
"`/plan2code-init`, then `/plan2code-1-plan --web`",
|
||||
"`/plan2code-init`, then `/plan2code-1-plan`",
|
||||
"Add `--web` for the web console.",
|
||||
"",
|
||||
].join("\n"));
|
||||
write(root, "AGENTS.md", "# AGENTS.md\n");
|
||||
assert.match(P("trail", "done", "--form", "A", "--text").stdout, /run:\n`\/plan2code-1-plan --web`\n$/);
|
||||
assert.match(P("trail", "done", "--form", "A", "--text").stdout, /run:\n`\/plan2code-1-plan`\nAdd `--web` for the web console\.\n$/);
|
||||
assert.equal(P("trail", "done", "--form", "C").code, 5, "no menu on a cleared map");
|
||||
});
|
||||
|
||||
|
||||
@@ -351,7 +351,7 @@ test("the session sweep removes only month-old session dirs, never the one being
|
||||
}
|
||||
});
|
||||
|
||||
test("the scratch sweep removes old patches and helpers, never looks, the pointer, the update cache or a directory", async () => {
|
||||
test("the scratch sweep removes old patches and helpers, never looks, the interface, the pointer, the update cache or a directory", async () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-scratch-"));
|
||||
try {
|
||||
const file = (name, stale = true) => {
|
||||
@@ -363,6 +363,7 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
|
||||
const removable = [file("p2.json"), file("helper.mjs")];
|
||||
const kept = [
|
||||
file("looks.json"),
|
||||
file("interface.json"),
|
||||
file("workspaces.json"),
|
||||
file("loop-setup.json"),
|
||||
file("review-loop-setup.json"),
|
||||
@@ -383,13 +384,14 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
|
||||
const stale = staleScratch(dir, Date.now(), SESSION_MAX_AGE_MS).sort();
|
||||
assert.deepEqual(stale, ["helper.mjs", "p2.json"]);
|
||||
assert.deepEqual(
|
||||
(await removeScratch(dir, [...stale, "looks.json", "workspaces.json", "loop-setup.json", "review-loop-setup.json", "loop-reports.json", "subagents.json", "spec-carry.json", "pr-hosts.json", "../p.json", "console-dir", "update-check.json"])).sort(),
|
||||
(await removeScratch(dir, [...stale, "looks.json", "interface.json", "workspaces.json", "loop-setup.json", "review-loop-setup.json", "loop-reports.json", "subagents.json", "spec-carry.json", "pr-hosts.json", "../p.json", "console-dir", "update-check.json"])).sort(),
|
||||
["helper.mjs", "p2.json"]
|
||||
);
|
||||
for (const p of removable) assert.equal(fs.existsSync(p), false, p);
|
||||
for (const p of kept) assert.ok(fs.existsSync(p), p);
|
||||
assert.deepEqual([...PROTECTED_CONSOLE_FILES].sort(), [
|
||||
"console-dir",
|
||||
"interface.json",
|
||||
"looks.json",
|
||||
"loop-reports.json",
|
||||
"loop-setup.json",
|
||||
@@ -435,7 +437,7 @@ test("cleanup finds old sessions and strays in both folders, and keeps every pro
|
||||
const drafted = session("20250801-101010-dddddd", true);
|
||||
put(path.join(drafted, "draft.json"));
|
||||
const kept = [
|
||||
...["looks.json", "workspaces.json", "subagents.json", "console-dir", "update-check.json"].map((n) =>
|
||||
...["looks.json", "interface.json", "workspaces.json", "subagents.json", "console-dir", "update-check.json"].map((n) =>
|
||||
put(path.join(consoleDir, n))
|
||||
),
|
||||
put(path.join(plan2code, "launcher.json")),
|
||||
@@ -1666,3 +1668,76 @@ test("a setup console without the app signal never calls a leftover announce URL
|
||||
stub.close();
|
||||
}
|
||||
});
|
||||
|
||||
/* ------------------------------------------------- terminal or web console */
|
||||
|
||||
// Its own console home, so a default saved here never reaches another test.
|
||||
function interfaceCli(home, args) {
|
||||
return cli(["interface", ...args], { expectFail: true, env: { PLAN2CODE_CONSOLE_HOME: home } });
|
||||
}
|
||||
|
||||
test("interface reports no default on a fresh home, and its rule says to ask and save nothing", () => {
|
||||
const home = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-interface-"));
|
||||
try {
|
||||
const res = interfaceCli(home, []);
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(res.json.interface, null);
|
||||
assert.match(res.json.rule, /Save nothing from the answer/);
|
||||
assert.match(res.json.rule, /make the terminal \(or web console\) my default/);
|
||||
assert.equal(fs.existsSync(path.join(home, "interface.json")), false);
|
||||
assert.match(res.json.rule, /interface --set web\|terminal/);
|
||||
assert.match(res.json.rule, /--web/);
|
||||
assert.match(res.json.rule, /--terminal/);
|
||||
} finally {
|
||||
fs.rmSync(home, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("interface --set saves one default that every later call reads back, and ask clears it", () => {
|
||||
const home = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-interface-"));
|
||||
try {
|
||||
for (const choice of ["terminal", "web"]) {
|
||||
assert.deepEqual(interfaceCli(home, ["--set", choice]).json, { ok: true, interface: choice });
|
||||
const res = interfaceCli(home, []);
|
||||
assert.equal(res.json.interface, choice);
|
||||
assert.match(res.json.rule, /saved default, so do not ask/);
|
||||
assert.doesNotMatch(res.json.rule, /Save nothing/);
|
||||
}
|
||||
assert.deepEqual(interfaceCli(home, ["--set", "ask"]).json, { ok: true, interface: null });
|
||||
assert.equal(fs.existsSync(path.join(home, "interface.json")), false);
|
||||
assert.equal(interfaceCli(home, []).json.interface, null);
|
||||
} finally {
|
||||
fs.rmSync(home, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("interface refuses an unknown or missing value, and reads a damaged file as no default", () => {
|
||||
const home = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-interface-"));
|
||||
try {
|
||||
for (const bad of [["--set", "browser"], ["--set"]]) {
|
||||
const res = interfaceCli(home, bad);
|
||||
assert.equal(res.status, 2, bad.join(" "));
|
||||
assert.equal(fs.existsSync(path.join(home, "interface.json")), false);
|
||||
}
|
||||
for (const body of ["{not json", JSON.stringify({ interface: "browser" }), "[]"]) {
|
||||
fs.writeFileSync(path.join(home, "interface.json"), body);
|
||||
assert.equal(interfaceCli(home, []).json.interface, null, body);
|
||||
}
|
||||
} finally {
|
||||
fs.rmSync(home, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
// The rule lives in the interface command, so no skill may go back to asking
|
||||
// up front or spell out its own version of the rule.
|
||||
test("every skill but the dashboard picks its interface through the interface command", () => {
|
||||
const skills = fs.readdirSync(path.join(ROOT, "src")).filter((f) => /^plan2code-.*\.md$/.test(f));
|
||||
assert.equal(skills.length, 21);
|
||||
for (const f of skills) {
|
||||
const text = fs.readFileSync(path.join(ROOT, "src", f), "utf8");
|
||||
const iface = text.indexOf('console.mjs" interface`');
|
||||
assert.ok(iface > -1, `${f} runs the interface command`);
|
||||
assert.ok(iface < text.search(/console\.mjs" open(?! --resume)/), `${f} runs it before open`);
|
||||
assert.doesNotMatch(text, /ask \*\*web console\*\*/, `${f} no longer asks up front`);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user