mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
Offer recent project folders in the launcher and the desktop app
AI Assisted
This commit is contained in:
1 parent
2e2b3e1139
commit
8459836d3b
14 files changed
+1037
-86
No files matched your search
@@ -0,0 +1,208 @@
|
||||
{
|
||||
"$comment": "The rule of the recent-folders list in ~/.plan2code/launcher.json (`recentFolders`, newest first, at most 5) as cases both writers' tests load: the launcher (src/launcher/plan2code.js) and the desktop app (plan2code-app/src-tauri/src/project.rs). A case may carry `platform`: `win32` or `posix`; it runs only with that platform's rule (a case with none runs under both). Paths are plain strings. read: `state` is the launcher.json object, `expect` the list. push: `list`, `dir`, `expect`. list: `list`, `exists` (the folders that exist), `exclude` (a folder or null), `expect`.",
|
||||
"read": [
|
||||
{
|
||||
"name": "the list is used as it is",
|
||||
"state": { "recentFolders": ["/b", "/a"], "lastFolder": "/z" },
|
||||
"expect": ["/b", "/a"]
|
||||
},
|
||||
{
|
||||
"name": "an empty list is used as it is, not replaced by the last folder",
|
||||
"state": { "recentFolders": [], "lastFolder": "/a" },
|
||||
"expect": []
|
||||
},
|
||||
{
|
||||
"name": "no list falls back to the last folder",
|
||||
"state": { "lastFolder": "/a" },
|
||||
"expect": ["/a"]
|
||||
},
|
||||
{
|
||||
"name": "neither key gives an empty list",
|
||||
"state": { "lastCli": "claude" },
|
||||
"expect": []
|
||||
},
|
||||
{
|
||||
"name": "an empty state gives an empty list",
|
||||
"state": {},
|
||||
"expect": []
|
||||
},
|
||||
{
|
||||
"name": "entries that are not strings or are empty are dropped",
|
||||
"state": { "recentFolders": ["/a", 7, "", null, "/b", { "x": 1 }] },
|
||||
"expect": ["/a", "/b"]
|
||||
},
|
||||
{
|
||||
"name": "a list that is not an array falls back to the last folder",
|
||||
"state": { "recentFolders": "/x", "lastFolder": "/a" },
|
||||
"expect": ["/a"]
|
||||
},
|
||||
{
|
||||
"name": "a list that is not an array and no last folder gives an empty list",
|
||||
"state": { "recentFolders": { "0": "/x" } },
|
||||
"expect": []
|
||||
},
|
||||
{
|
||||
"name": "an empty last folder is no folder",
|
||||
"state": { "lastFolder": "" },
|
||||
"expect": []
|
||||
},
|
||||
{
|
||||
"name": "more than 5 entries are cut to 5",
|
||||
"state": { "recentFolders": ["/1", "/2", "/3", "/4", "/5", "/6", "/7"] },
|
||||
"expect": ["/1", "/2", "/3", "/4", "/5"]
|
||||
}
|
||||
],
|
||||
"push": [
|
||||
{
|
||||
"name": "a new folder goes first",
|
||||
"list": ["/b", "/a"],
|
||||
"dir": "/c",
|
||||
"expect": ["/c", "/b", "/a"]
|
||||
},
|
||||
{
|
||||
"name": "a first folder starts the list",
|
||||
"list": [],
|
||||
"dir": "/a",
|
||||
"expect": ["/a"]
|
||||
},
|
||||
{
|
||||
"name": "an existing folder moves to the top without a duplicate",
|
||||
"list": ["/c", "/b", "/a"],
|
||||
"dir": "/a",
|
||||
"expect": ["/a", "/c", "/b"]
|
||||
},
|
||||
{
|
||||
"name": "a sixth folder drops the oldest",
|
||||
"list": ["/5", "/4", "/3", "/2", "/1"],
|
||||
"dir": "/6",
|
||||
"expect": ["/6", "/5", "/4", "/3", "/2"]
|
||||
},
|
||||
{
|
||||
"name": "a folder already first stays first",
|
||||
"list": ["/a", "/b"],
|
||||
"dir": "/a",
|
||||
"expect": ["/a", "/b"]
|
||||
},
|
||||
{
|
||||
"name": "a trailing slash matches the bare path",
|
||||
"list": ["/b", "/a"],
|
||||
"dir": "/a/",
|
||||
"expect": ["/a/", "/b"]
|
||||
},
|
||||
{
|
||||
"name": "a bare path matches a listed trailing slash",
|
||||
"list": ["/b", "/a/"],
|
||||
"dir": "/a",
|
||||
"expect": ["/a", "/b"]
|
||||
},
|
||||
{
|
||||
"name": "a trailing backslash matches the bare path",
|
||||
"list": ["D:\\x", "C:\\a"],
|
||||
"dir": "C:\\a\\",
|
||||
"expect": ["C:\\a\\", "D:\\x"]
|
||||
},
|
||||
{
|
||||
"name": "a drive root keeps its separator",
|
||||
"list": ["C:\\", "C:\\a"],
|
||||
"dir": "C:\\a\\",
|
||||
"expect": ["C:\\a\\", "C:\\"]
|
||||
},
|
||||
{
|
||||
"name": "the root of a posix tree is not stripped to nothing",
|
||||
"list": ["/a"],
|
||||
"dir": "/",
|
||||
"expect": ["/", "/a"]
|
||||
},
|
||||
{
|
||||
"name": "a drive root is not the bare drive",
|
||||
"list": ["C:"],
|
||||
"dir": "C:\\",
|
||||
"expect": ["C:\\", "C:"]
|
||||
},
|
||||
{
|
||||
"name": "a drive root with a slash is not the bare drive",
|
||||
"list": ["C:"],
|
||||
"dir": "C:/",
|
||||
"expect": ["C:/", "C:"]
|
||||
},
|
||||
{
|
||||
"name": "a drive root matches itself",
|
||||
"list": ["C:\\"],
|
||||
"dir": "C:\\",
|
||||
"expect": ["C:\\"]
|
||||
},
|
||||
{
|
||||
"name": "the posix root is not an empty path",
|
||||
"list": ["/a", ""],
|
||||
"dir": "/",
|
||||
"expect": ["/", "/a", ""]
|
||||
},
|
||||
{
|
||||
"platform": "win32",
|
||||
"name": "windows ignores case and keeps the new spelling",
|
||||
"list": ["D:\\x", "c:\\git\\a"],
|
||||
"dir": "C:\\Git\\A",
|
||||
"expect": ["C:\\Git\\A", "D:\\x"]
|
||||
},
|
||||
{
|
||||
"platform": "posix",
|
||||
"name": "posix tells case apart",
|
||||
"list": ["/x", "/git/a"],
|
||||
"dir": "/Git/A",
|
||||
"expect": ["/Git/A", "/x", "/git/a"]
|
||||
}
|
||||
],
|
||||
"list": [
|
||||
{
|
||||
"name": "folders that are gone are skipped and the order is kept",
|
||||
"list": ["/c", "/b", "/a"],
|
||||
"exists": ["/a", "/c"],
|
||||
"exclude": null,
|
||||
"expect": ["/c", "/a"]
|
||||
},
|
||||
{
|
||||
"name": "nothing existing gives an empty list",
|
||||
"list": ["/b", "/a"],
|
||||
"exists": [],
|
||||
"exclude": null,
|
||||
"expect": []
|
||||
},
|
||||
{
|
||||
"name": "the excluded folder is removed",
|
||||
"list": ["/c", "/b", "/a"],
|
||||
"exists": ["/a", "/b", "/c"],
|
||||
"exclude": "/b",
|
||||
"expect": ["/c", "/a"]
|
||||
},
|
||||
{
|
||||
"name": "the excluded folder matches past a trailing slash",
|
||||
"list": ["/c", "/b", "/a"],
|
||||
"exists": ["/a", "/b", "/c"],
|
||||
"exclude": "/b/",
|
||||
"expect": ["/c", "/a"]
|
||||
},
|
||||
{
|
||||
"name": "excluding a drive root leaves the bare drive",
|
||||
"list": ["C:", "C:\\"],
|
||||
"exists": ["C:", "C:\\"],
|
||||
"exclude": "C:\\",
|
||||
"expect": ["C:"]
|
||||
},
|
||||
{
|
||||
"platform": "win32",
|
||||
"name": "windows excludes by folder, not by spelling",
|
||||
"list": ["C:\\Git\\A", "D:\\x"],
|
||||
"exists": ["C:\\Git\\A", "D:\\x"],
|
||||
"exclude": "c:\\git\\a\\",
|
||||
"expect": ["D:\\x"]
|
||||
},
|
||||
{
|
||||
"platform": "posix",
|
||||
"name": "posix keeps a folder that differs only in case",
|
||||
"list": ["/Git/A", "/x"],
|
||||
"exists": ["/Git/A", "/x"],
|
||||
"exclude": "/git/a",
|
||||
"expect": ["/Git/A", "/x"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { helloRetryAction, retryLabel, RETRY_AFTER_SECONDS, attentionSignal, barNextSteps, continueKeys, defaultRightFraction, folderName, pickDefaultAgent, taskbarSwitch, windowTitleFor, deadConsoleAction, loopBanner, loopRunText, loopLocks, loopStopLabels, loopWindowTitle, CONSOLE_ASIDE_BREAKPOINT_PX, NEXT_STEP_LABELS, NEW_RELEASE_COMMAND } from "../plan2code-app/ui/meter.js";
|
||||
import { helloRetryAction, retryLabel, RETRY_AFTER_SECONDS, attentionSignal, barNextSteps, continueKeys, defaultRightFraction, folderName, folderPickerRows, pickDefaultAgent, taskbarSwitch, windowTitleFor, deadConsoleAction, loopBanner, loopRunText, loopLocks, loopStopLabels, loopWindowTitle, CONSOLE_ASIDE_BREAKPOINT_PX, NEXT_STEP_LABELS, NEW_RELEASE_COMMAND } from "../plan2code-app/ui/meter.js";
|
||||
import { findBrowser, launchBrowser } from "./browser.mjs";
|
||||
|
||||
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
||||
@@ -134,6 +134,19 @@ test("the bar reads project menu, New Session, agent menu, with both menus outsi
|
||||
assert.match(INDEX_HTML, /<div id="project-menu"[\s\S]*?<button id="change-project" role="menuitem">/, "Change project lives in the project menu");
|
||||
});
|
||||
|
||||
test("folderPickerRows puts Choose a folder first, then the recent folders in the order given", () => {
|
||||
assert.deepEqual(folderPickerRows([]), [{ kind: "browse", label: "Choose a folder..." }]);
|
||||
const rows = folderPickerRows([
|
||||
{ dir: "C:\\git\\b", name: "b" },
|
||||
{ dir: "/home/me/a", name: "a" },
|
||||
]);
|
||||
assert.deepEqual(rows, [
|
||||
{ kind: "browse", label: "Choose a folder..." },
|
||||
{ kind: "folder", dir: "C:\\git\\b", label: "b", detail: "C:\\git\\b" },
|
||||
{ kind: "folder", dir: "/home/me/a", label: "a", detail: "/home/me/a" },
|
||||
]);
|
||||
});
|
||||
|
||||
test("folderName shows the project folder's own name, or the whole path when it has none", () => {
|
||||
assert.equal(folderName("C:\\git\\azw3-to-pdf"), "azw3-to-pdf");
|
||||
assert.equal(folderName("/home/me/plan2code/"), "plan2code");
|
||||
@@ -530,7 +543,7 @@ test("main.rs guards the window's agent and project commands, and registers loop
|
||||
assert.ok(at > 0, `${name} exists`);
|
||||
return rust.slice(at, rust.indexOf("\n}\n", at));
|
||||
};
|
||||
for (const [name, what] of [["agent_start", "agent"], ["agent_restart", "agent"], ["change_project", "project"], ["pick_project_folder", "project"]]) {
|
||||
for (const [name, what] of [["agent_start", "agent"], ["agent_restart", "agent"], ["change_project", "project"], ["pick_project_folder", "project"], ["open_recent_folder", "project"]]) {
|
||||
assert.ok(body(name).includes(`refuse_while_looping(&state, "${what}")?;`), `${name} refuses while a loop runs`);
|
||||
}
|
||||
assert.ok(!body("agent_input").includes("refuse_while_looping"), "typing stays open for a trust or login prompt");
|
||||
|
||||
+151
-6
@@ -131,6 +131,18 @@ function sandbox(clis, { installed, project = true, lookup = true, agents } = {}
|
||||
|
||||
const NOTICE_LINE = /is out \(you have v/;
|
||||
|
||||
/**
|
||||
* The run's folder was recorded: first in `recentFolders` (compared by real path, since a temp
|
||||
* folder can reach the launcher under another spelling), `lastFolder` equal to it, and `older`
|
||||
* after it in order.
|
||||
*/
|
||||
function assertRecordedFirst({ recentFolders, lastFolder }, folder, older = []) {
|
||||
assert.ok(Array.isArray(recentFolders), "recentFolders is written");
|
||||
assert.equal(fs.realpathSync(recentFolders[0]), fs.realpathSync(folder));
|
||||
assert.equal(lastFolder, recentFolders[0]);
|
||||
assert.deepEqual(recentFolders.slice(1), older);
|
||||
}
|
||||
|
||||
/** Write the console's cached release check, `ageMs` old. */
|
||||
function writeCache(box, latest, ageMs = 0) {
|
||||
fs.mkdirSync(path.dirname(box.cacheFile), { recursive: true });
|
||||
@@ -307,11 +319,9 @@ test("launcher: a launched model is remembered per agent in launcher.json", (t)
|
||||
assert.equal(box.run(["--cli", "claude", "--model", "opus"]).status, 0);
|
||||
assert.equal(box.run(["--cli", "codex", "-m", "x"]).status, 0);
|
||||
assert.equal(box.run(["--cli", "codex", "-my"]).status, 0);
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(box.stateFile, "utf8")), {
|
||||
lastFolder: box.home,
|
||||
lastCli: "codex",
|
||||
lastModels: { claude: "opus", codex: "y" },
|
||||
});
|
||||
const { recentFolders, lastFolder, ...rest } = JSON.parse(fs.readFileSync(box.stateFile, "utf8"));
|
||||
assert.deepEqual(rest, { lastCli: "codex", lastModels: { claude: "opus", codex: "y" } });
|
||||
assertRecordedFirst({ recentFolders, lastFolder }, box.dir, [box.home]);
|
||||
});
|
||||
|
||||
test("launcher: --cli picks the CLI and is never forwarded; the pick is merged into launcher.json", (t) => {
|
||||
@@ -326,7 +336,9 @@ test("launcher: --cli picks the CLI and is never forwarded; the pick is merged i
|
||||
assert.deepEqual(box.argsOf("devin"), ["--", "/plan2code"]);
|
||||
}
|
||||
assert.equal(box.argsOf("claude"), null);
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(box.stateFile, "utf8")), { lastFolder: box.home, lastCli: "devin" });
|
||||
const { recentFolders, lastFolder, ...rest } = JSON.parse(fs.readFileSync(box.stateFile, "utf8"));
|
||||
assert.deepEqual(rest, { lastCli: "devin" });
|
||||
assertRecordedFirst({ recentFolders, lastFolder }, box.dir, [box.home]);
|
||||
});
|
||||
|
||||
test("launcher: with both installed and no terminal to ask in, the last pick wins", (t) => {
|
||||
@@ -1319,3 +1331,136 @@ test("launcher setup: no agent and no display keeps the old 127 and install step
|
||||
assert.match(result.stderr, /none was found/);
|
||||
assert.equal(box.appExists(), false);
|
||||
});
|
||||
|
||||
// The recent-folders rule: the same cases the desktop app's project.rs loads (the fixture holds
|
||||
// both platforms' rules, so each runs on every OS: "win32" and "linux" are passed explicitly).
|
||||
const RECENT_CASES = JSON.parse(fs.readFileSync(path.join(ROOT, "scripts", "fixtures", "recent-folders-cases.json"), "utf8"));
|
||||
const RECENT_PLATFORMS = { win32: "win32", posix: "linux" };
|
||||
|
||||
/** The platform values ("win32" or "linux") a fixture case runs under. */
|
||||
function recentPlatforms(testCase) {
|
||||
return testCase.platform ? [RECENT_PLATFORMS[testCase.platform]] : ["win32", "linux"];
|
||||
}
|
||||
|
||||
test("launcher recent folders: readRecent follows the shared cases", () => {
|
||||
const { readRecent } = require(LAUNCHER);
|
||||
assert.ok(RECENT_CASES.read.length > 0);
|
||||
for (const c of RECENT_CASES.read) assert.deepEqual(readRecent(c.state), c.expect, c.name);
|
||||
});
|
||||
|
||||
test("launcher recent folders: pushRecent follows the shared cases", () => {
|
||||
const { pushRecent } = require(LAUNCHER);
|
||||
assert.ok(RECENT_CASES.push.length > 0);
|
||||
for (const c of RECENT_CASES.push) {
|
||||
for (const platform of recentPlatforms(c)) assert.deepEqual(pushRecent(c.list, c.dir, platform), c.expect, `${c.name} (${platform})`);
|
||||
}
|
||||
});
|
||||
|
||||
test("launcher recent folders: listRecent follows the shared cases", () => {
|
||||
const { listRecent } = require(LAUNCHER);
|
||||
assert.ok(RECENT_CASES.list.length > 0);
|
||||
for (const c of RECENT_CASES.list) {
|
||||
const exists = new Set(c.exists);
|
||||
for (const platform of recentPlatforms(c)) {
|
||||
assert.deepEqual(listRecent(c.list, { exists: (p) => exists.has(p), exclude: c.exclude, platform }), c.expect, `${c.name} (${platform})`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("launcher recent folders: pushRecent returns a new array and leaves its input alone", () => {
|
||||
const { pushRecent } = require(LAUNCHER);
|
||||
const list = ["/b", "/a"];
|
||||
pushRecent(list, "/c", "linux");
|
||||
assert.deepEqual(list, ["/b", "/a"]);
|
||||
});
|
||||
|
||||
test("launcher recent folders: recordFolder writes both keys from a state with only lastFolder and keeps the rest", (t) => {
|
||||
const box = sandbox([]);
|
||||
t.after(box.cleanup);
|
||||
fs.mkdirSync(path.dirname(box.stateFile), { recursive: true });
|
||||
fs.writeFileSync(box.stateFile, JSON.stringify({ lastFolder: "/old", lastCli: "devin" }));
|
||||
const picked = path.join(box.dir, "picked");
|
||||
const script = `require(${JSON.stringify(LAUNCHER)}).recordFolder(${JSON.stringify(picked)});`;
|
||||
const result = spawnSync(process.execPath, ["-e", script], {
|
||||
encoding: "utf8",
|
||||
env: { ...process.env, HOME: box.home, USERPROFILE: box.home },
|
||||
});
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(box.stateFile, "utf8")), {
|
||||
lastFolder: picked,
|
||||
recentFolders: [picked, "/old"],
|
||||
lastCli: "devin",
|
||||
});
|
||||
});
|
||||
|
||||
test("launcher folder menu: from the command, the current folder comes first, then the recents, then browse", () => {
|
||||
const { folderMenuRows } = require(LAUNCHER);
|
||||
const cwd = path.join(os.tmpdir(), "here");
|
||||
const recent = [path.join(os.tmpdir(), "one"), path.join(os.tmpdir(), "two")];
|
||||
assert.deepEqual(folderMenuRows({ fromShortcut: false, cwd, recent }), [
|
||||
{ kind: "folder", dir: cwd, name: "here", detail: `${cwd} (current folder)`, label: `here ${cwd} (current folder)` },
|
||||
{ kind: "folder", dir: recent[0], name: "one", detail: recent[0], label: `one ${recent[0]}` },
|
||||
{ kind: "folder", dir: recent[1], name: "two", detail: recent[1], label: `two ${recent[1]}` },
|
||||
{ kind: "browse", label: "Choose another folder..." },
|
||||
]);
|
||||
});
|
||||
|
||||
test("launcher folder menu: from the shortcut, browse comes first, then the recents", () => {
|
||||
const { folderMenuRows } = require(LAUNCHER);
|
||||
const recent = [path.join(os.tmpdir(), "one")];
|
||||
assert.deepEqual(folderMenuRows({ fromShortcut: true, cwd: os.tmpdir(), recent }), [
|
||||
{ kind: "browse", label: "Choose a folder..." },
|
||||
{ kind: "folder", dir: recent[0], name: "one", detail: recent[0], label: `one ${recent[0]}` },
|
||||
]);
|
||||
});
|
||||
|
||||
test("launcher folder menu: a drive root keeps its full text as its name", () => {
|
||||
const { folderMenuRows } = require(LAUNCHER);
|
||||
const root = path.parse(process.cwd()).root;
|
||||
const [row] = folderMenuRows({ fromShortcut: false, cwd: root, recent: [] });
|
||||
assert.equal(row.label, `${root} ${root} (current folder)`);
|
||||
assert.equal(row.name, root);
|
||||
assert.equal(row.detail, `${root} (current folder)`);
|
||||
});
|
||||
|
||||
test("launcher folder menu: Enter picks row 1, a number its row, anything else asks again", () => {
|
||||
const { folderMenuPick } = require(LAUNCHER);
|
||||
const rows = [{ kind: "folder", dir: "/a", label: "a" }, { kind: "folder", dir: "/b", label: "b" }, { kind: "browse", label: "x" }];
|
||||
assert.equal(folderMenuPick(rows, ""), rows[0]);
|
||||
assert.equal(folderMenuPick(rows, " "), rows[0]);
|
||||
assert.equal(folderMenuPick(rows, "2"), rows[1]);
|
||||
assert.equal(folderMenuPick(rows, " 3 "), rows[2]);
|
||||
for (const answer of ["0", "9", "x", "1.5", "-1"]) assert.equal(folderMenuPick(rows, answer), null, answer);
|
||||
});
|
||||
|
||||
test("launcher folder menu: with recent folders but no terminal, it starts in the current folder without a menu and records it", (t) => {
|
||||
const box = sandbox(["claude"]);
|
||||
t.after(box.cleanup);
|
||||
const older = path.join(box.dir, "older");
|
||||
fs.mkdirSync(older);
|
||||
fs.mkdirSync(path.dirname(box.stateFile), { recursive: true });
|
||||
fs.writeFileSync(box.stateFile, JSON.stringify({ recentFolders: [older], lastFolder: older, lastCli: "claude" }));
|
||||
const result = box.run([]);
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.doesNotMatch(result.stdout, /Which project folder\?/);
|
||||
assert.doesNotMatch(result.stdout, /Opening Plan2Code in/);
|
||||
assert.notEqual(box.argsOf("claude"), null);
|
||||
const { recentFolders, lastFolder, ...rest } = JSON.parse(fs.readFileSync(box.stateFile, "utf8"));
|
||||
assert.deepEqual(rest, { lastCli: "claude" });
|
||||
assertRecordedFirst({ recentFolders, lastFolder }, box.dir, [older]);
|
||||
});
|
||||
|
||||
test("launcher folder menu: a folder that fails the project check is not recorded", (t) => {
|
||||
const box = sandbox(["claude"], { project: false });
|
||||
t.after(box.cleanup);
|
||||
const older = path.join(box.dir, "older");
|
||||
fs.mkdirSync(older);
|
||||
fs.mkdirSync(path.dirname(box.stateFile), { recursive: true });
|
||||
const state = { recentFolders: [older], lastFolder: older, lastCli: "claude" };
|
||||
fs.writeFileSync(box.stateFile, JSON.stringify(state));
|
||||
const result = box.run([]);
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.match(result.stderr, /doesn't look like a project/);
|
||||
assert.equal(box.argsOf("claude"), null);
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(box.stateFile, "utf8")), state);
|
||||
});
|
||||
Reference in new issue
Block a user