Add plan2code uninstall to remove everything the installer put in place

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-08 17:25:40 -08:00
1 parent bd2bbc2764
commit e5155778bf
9 files changed
+260 -25

No files matched your search

+1 -1
View File
@@ -197,7 +197,7 @@ Typing `plan2code` in any directory opens the dashboard skill against the curren
The bracketed flags (each entry's `bypassArgs`; a custom agent's own `bypassArgs`) go in only when permission prompts are off. Right after the agent is chosen, and only when it has such a flag, `chooseBypass()` asks `Turn <CLI>'s permission prompts off?` (Codex: `approval prompts and its sandbox`, worded by `bypassQuestion()`) on every launch, with Yes as the default and no answer remembered; `--keep-permissions` answers no and `--bypass-permissions` answers yes (neither is forwarded; keep wins when both are given), and with no TTY on stdin the prompts stay on unless `--bypass-permissions` is given. When the desktop app will take over, the question is skipped (its launch card has its own tick) and asked only if the app fails to start. The installer prints no warning about it.
On a terminal it first prints a Planny banner (`renderBanner()`). With more than one on `PATH` it asks `Plan2Code opens inside an AI coding agent. Pick which one to use:` as a numbered menu, the last pick pre-selected and marked `(last used)` (Enter keeps it; a number or a CLI id also works); with one installed it uses that without asking, printing `Opening with <CLI>…` (as does a `--cli` pick); with none it runs the setup flow when a person can see a page (`hasDisplay()` and a TTY or the shortcut; the desktop app first when it is installed, else the console's agent-less `setup` page in the browser) and otherwise prints the install steps (`printNoAgentGuidance()`: each built-in's install command and page, how to add another agent in `~/.plan2code/agents.json`, and to run `plan2code` again) and exits 127. An uninstalled `--cli` pick goes to the same setup flow on that agent when a page can open, else prints that CLI's own steps after its error. `--cli claude` / `devin` / `codex` (or `--cli=<name>`) skips the menu and is never forwarded; an unknown name exits 2, an uninstalled one 127. The pick is saved as `lastCli` in `~/.plan2code/launcher.json`, merged beside `lastFolder`. Before spawning, unless the forwarded args carry `--model` / `--model=` (or, for Codex, `-m`), it asks `Which model should <CLI> use?` from `models.json` plus the user's additions, Enter keeping the model the CLI last used — Ctrl+C at any launcher prompt exits 130. With no TTY on stdin there is no menu (last pick, else the first installed) and no model question: it prints that the CLI will use the model last used in it (switch it in that CLI on its own, or pass `--model <name>`). Headings, numbers, defaults, retry lines and the `plan2code:` error prefixes are colored with `paint()` (the escape values of `install.js`'s `COLORS`, copied), stdout only when stdout is a TTY and stderr only when stderr is, and never when `NO_COLOR` is set; piped runs print plain text and no banner. Other arguments are forwarded to the CLI (`plan2code --model opus`), and its exit code is passed back. `plan2code update` is the one subcommand: it is never forwarded and opens no agent, it runs `npx --yes --allow-git=all git+https://github.com/jparkerweb/plan2code.git --update`, so `install.js --update` reinstalls what `~/.plan2code/install.json` lists. On every other start, before spawning the CLI, it prints one line when a newer release is out (`Plan2Code v<latest> is out (you have v<installed>). Run: plan2code update`), compared against `~/.plan2code/bin/version.json` and read from the console's cached release check (`~/.plan2code/console/update-check.json`); it never waits on the network, and when the cache is missing or stale it refreshes it in a detached background process so the next start knows. Tests: `scripts/test-launcher.mjs` (run by `npm test`) spawns the launcher against stand-in `claude`/`devin`/`codex` commands and a temp home.
On a terminal it first prints a Planny banner (`renderBanner()`). With more than one on `PATH` it asks `Plan2Code opens inside an AI coding agent. Pick which one to use:` as a numbered menu, the last pick pre-selected and marked `(last used)` (Enter keeps it; a number or a CLI id also works); with one installed it uses that without asking, printing `Opening with <CLI>…` (as does a `--cli` pick); with none it runs the setup flow when a person can see a page (`hasDisplay()` and a TTY or the shortcut; the desktop app first when it is installed, else the console's agent-less `setup` page in the browser) and otherwise prints the install steps (`printNoAgentGuidance()`: each built-in's install command and page, how to add another agent in `~/.plan2code/agents.json`, and to run `plan2code` again) and exits 127. An uninstalled `--cli` pick goes to the same setup flow on that agent when a page can open, else prints that CLI's own steps after its error. `--cli claude` / `devin` / `codex` (or `--cli=<name>`) skips the menu and is never forwarded; an unknown name exits 2, an uninstalled one 127. The pick is saved as `lastCli` in `~/.plan2code/launcher.json`, merged beside `lastFolder`. Before spawning, unless the forwarded args carry `--model` / `--model=` (or, for Codex, `-m`), it asks `Which model should <CLI> use?` from `models.json` plus the user's additions, Enter keeping the model the CLI last used — Ctrl+C at any launcher prompt exits 130. With no TTY on stdin there is no menu (last pick, else the first installed) and no model question: it prints that the CLI will use the model last used in it (switch it in that CLI on its own, or pass `--model <name>`). Headings, numbers, defaults, retry lines and the `plan2code:` error prefixes are colored with `paint()` (the escape values of `install.js`'s `COLORS`, copied), stdout only when stdout is a TTY and stderr only when stderr is, and never when `NO_COLOR` is set; piped runs print plain text and no banner. Other arguments are forwarded to the CLI (`plan2code --model opus`), and its exit code is passed back. `plan2code update` and `plan2code uninstall [--yes] [--purge]` are the two subcommands: neither is forwarded and neither opens an agent. Update runs `npx --yes --allow-git=all git+https://github.com/jparkerweb/plan2code.git --update`, so `install.js --update` reinstalls what `~/.plan2code/install.json` lists; uninstall runs the same npx line with `--uninstall` (an unknown flag exits 2 before npx runs), and `install.js` confirms, removes everything the menu's U option does, then asks about `~/.plan2code` (see `--uninstall` in Development Commands). On every other start, before spawning the CLI, it prints one line when a newer release is out (`Plan2Code v<latest> is out (you have v<installed>). Run: plan2code update`), compared against `~/.plan2code/bin/version.json` and read from the console's cached release check (`~/.plan2code/console/update-check.json`); it never waits on the network, and when the cache is missing or stale it refreshes it in a detached background process so the next start knows. Tests: `scripts/test-launcher.mjs` (run by `npm test`) spawns the launcher against stand-in `claude`/`devin`/`codex` commands and a temp home.
**Design constraints:**
- **Stable copy, not the package dir** — the installer normally runs from an npx cache directory npm may delete, so `installLauncher()` copies `src/launcher/plan2code.js` to `~/.plan2code/bin/plan2code.js` and the shims point there. Beside it go `update-check.mjs` (the web console's release check, for the terminal notice), `agents.json` and `agent-lookup.mjs` (the shared agent list and lookup rule; `plan2code update` restores a missing copy) and a `version.json` (the installed version). (The metrics/bot wrappers point into `__dirname` and don't have this protection.)
+2 -1
View File
@@ -114,7 +114,7 @@ The root `npm test` does not run the metrics or bot vitest suites; run them in t
| Option | Action |
|--------|--------|
| `I` | Install the Plan2Code skills globally via the `skills` CLI, plus the global `plan2code` command (opens the dashboard in Claude Code, Devin or Codex), then print the getting-started steps. No dev tools |
| `U` | Uninstall Plan2Code: skills + `plan2code` command + `plan2code-metrics` + `plan2code-bot` + Claude Code status line (confirmation required) |
| `U` | Uninstall Plan2Code: skills + `plan2code` command + `plan2code-metrics` + `plan2code-bot` + Claude Code status line + desktop app (confirmation required; `plan2code uninstall` runs the same removal, see `--uninstall` below) |
| `A` | Open the ADVANCED sub-menu |
| `Q` | Quit |
@@ -139,6 +139,7 @@ The root `npm test` does not run the metrics or bot vitest suites; run them in t
| `--build-skills` | Regenerate `skills/` from `src/`, pruning stale skills and reference files |
| `--verify-skills` | Diff local `skills/` against `src/`; exits 1 on drift. Diagnostic only, the installer rebuilds anyway |
| `--update` | No menu: reinstall what `~/.plan2code/install.json` lists (skills, launcher, app, statusline; metrics and bot only when run from a git checkout, since they run from the install folder, which npx's cache is not), never uninstalling; with no record, the skills and the `plan2code` command. `plan2code update` runs it through npx |
| `--uninstall [--yes] [--purge]` | No menu: confirm y/N (`--yes` skips it), run `uninstallAll()` (the menu's U sequence: skills, dev tools, status line, `plan2code` command, desktop app), then ask whether to also delete `~/.plan2code` (`purgeData()`; `--purge` says yes without asking, `--yes` alone keeps the data). `plan2code uninstall [--yes] [--purge]` runs it through npx |
## How the Installer Works
+1
View File
@@ -17,6 +17,7 @@ The web console is the main way in: a local page where questions, documents, bui
| Inside any agent | `/plan2code` (`$plan2code` in Codex) | Opens the dashboard: a card for every skill, launched on the same page |
| Install | `npx --allow-git=all git+https://github.com/jparkerweb/plan2code.git` | Installs the skills and the `plan2code` command (re-run it to update without the `plan2code` command) |
| Update | `plan2code update` | Updates the skills, command, app and status line, with no menu (metrics and the bot only from a git checkout: `node install.js`); never uninstalls anything |
| Uninstall | `plan2code uninstall` | Removes the skills, command, app and dev tools after a Y/N; then asks whether `~/.plan2code/` (your notebooks, handoffs, settings) goes too. `--yes` skips the questions and keeps your data, `--purge` deletes it |
| Straight into a skill | `/plan2code-1-plan --web` (any step) | Skips the "web console or terminal?" question and opens the page |
The install command always opens a menu. Back at your prompt with no output at all? npm could not reach the repository and hid the reason: run `git ls-remote https://github.com/jparkerweb/plan2code.git` to see it (usually the network, a proxy or the VPN).
+4 -4
View File
@@ -37,7 +37,7 @@ The dashboard, in a project halfway through a build. It suggests the next step f
- **Ways in.** `plan2code` (Claude Code, Devin or Codex), or type `/plan2code` in your agent (`$plan2code` in Codex).
- **No agent yet?** Install Claude Code, Codex or Devin first, or let the `plan2code` command's setup page walk you through it.
Installation needs network access and runs through the [skills CLI](https://skills.sh). To update, run `plan2code update` (or re-run the install command).
Installation needs network access and runs through the [skills CLI](https://skills.sh). To update, run `plan2code update` (or re-run the install command). To remove everything, run `plan2code uninstall`: it asks first, then asks whether your own data in `~/.plan2code/` (notebooks, handoffs, settings) goes too. `--yes` skips the questions and keeps your data; add `--purge` to delete it.
```bash
npx --allow-git=all git+https://github.com/jparkerweb/plan2code.git
@@ -89,7 +89,7 @@ custom agent that has none; for Codex the question names its sandbox, which that
launch and remembers no answer. `plan2code --keep-permissions` keeps the prompts without asking, and
`plan2code --bypass-permissions` turns them off without asking. With no terminal to ask on (a script or a pipe) the
prompts stay on unless `--bypass-permissions` is given. The installer then offers a desktop shortcut (answer `y`),
which opens a folder picker first. Uninstalling (`U`) removes both.
which opens a folder picker first. Uninstalling (`U`, or `plan2code uninstall` from any terminal) removes both.
</details>
<details>
@@ -132,7 +132,7 @@ session is getting long. Once it is installed, `plan2code` opens the app instead
in your terminal. `plan2code --classic` keeps the terminal flow, and so does a Linux machine with no
display (over SSH, say) or any machine over an SSH session. `plan2code update` updates the skills, the
command and the app together, and the bar offers the same **Update skills** when the app and the
installed skills disagree.
installed skills disagree. `plan2code uninstall` removes all three.
The app can also build a whole spec unattended with the Implementation Loop; see [docs/desktop-app.md](docs/desktop-app.md#implementation-loop).
@@ -150,7 +150,7 @@ Gemini CLI · Cline · Roo · Kilo · Goose · Trae · Qwen Code.
**Launched by `plan2code`:** the `plan2code` command and the desktop app open the dashboard directly in Claude Code, Devin and Codex (the built-ins in `src/launcher/agents.json`). GitHub Copilot CLI, OpenCode, Gemini CLI and Pi come as starter templates, and you can add any other agent CLI as a custom agent in User Preferences → Agents & models.
The installer keeps one canonical copy of each skill under `~/.agents/skills/` and links it into
agents that maintain their own directory. To update, run `plan2code update` (or re-run the install command).
agents that maintain their own directory. To update, run `plan2code update` (or re-run the install command); to remove it all, run `plan2code uninstall`.
Use the installer rather than calling `skills add` against the repository root: recursive discovery
would also find maintainer-only skills under `.claude/skills/`. The installer targets `skills/`
+14 -4
View File
@@ -156,7 +156,8 @@ not), so your own edits never end up inside a phase's commit.
session, count the agent as stuck (20). Waiting on your answer does not count.
- **Send a notification** (no address, so off): a message from the loop when it waits on your answer or
ends. Send it to a Discord, Slack, Microsoft Teams or Google Chat webhook, or to any `http` or `https`
address with the message in its query string or a JSON body.
address with the message in its query string or a JSON body. With an address set, **Also tell me when each
phase is complete** (off) adds a message after every phase that passes.
- **Commit each phase** (on): one local commit per phase, with the subject and `AI Assisted`.
The last setup is remembered per project in `~/.plan2code/console/loop-setup.json`, so the next loop
@@ -164,9 +165,13 @@ starts from it. The quick check is typed text the page never runs: the app reads
itself and names it in its own window before the loop begins. The notification gets the same treatment,
and Resume asks again if either one changed.
**The notification.** The loop says a question is waiting, that it is complete, or why it stopped. Nothing
is sent when you stopped it yourself, and with **Take the agent's best guess** no question ever waits on
you. What the app sends depends on the **Send to** choice:
**The notification.** The loop says a question is waiting, that it is complete, or why it stopped, and,
when you turn on **Also tell me when each phase is complete**, that a phase passed. Nothing is sent when you
stopped it yourself, and with **Take the agent's best guess** no question ever waits on you. Every message
names the project and spec and the phase as `Phase 2 of 4 (name)`, and ends with the time the phase and the
whole run have taken. A phase message also says how many tasks are done, the commit's subject and short id,
and what comes next, for example: `Plan2Code loop on plan2code / lunch-vote: Phase 2 of 4 (Votes) is complete.
Done: 5 tasks, committed "Add votes" (abc1234). Next: Phase 3, Results. Elapsed: phase 6m, run 14m.` What the app sends depends on the **Send to** choice:
| Send to | Request | Where the message goes |
| --- | --- | --- |
@@ -241,6 +246,11 @@ clean tree. The in-app **Help** has a matching topic, **Implementation Loop**, w
and the installed skills ever differ in version, the app's top bar says so and offers **Update
skills**, which runs that same update when you press it. It never updates on its own.
To remove the app along with the skills and the command, run `plan2code uninstall`. It asks first,
then asks whether your own data in `~/.plan2code/` (notebooks, handoffs, settings) goes too.
`--yes` skips both questions and keeps that data; add `--purge` to delete it. Close the app first:
Windows cannot delete a running file.
## The first release is unsigned
The app is not code-signed yet, so your system may stop it the first time it starts. It is the same
+81 -11
View File
@@ -1418,15 +1418,7 @@ function runInteractive() {
if (confirmInput === 'Y') {
rl.close();
const uninstallResult = uninstallSkills();
removeLegacyLoopShims();
const metricsResult = uninstallPlan2CodeMetrics();
const botResult = uninstallPlan2CodeBot();
const statusLineResult = uninstallStatusLine();
const launcherResult = uninstallLauncher();
uninstallDesktopApp();
const exitCode = uninstallResult !== 0 ? uninstallResult : metricsResult !== 0 ? metricsResult : botResult !== 0 ? botResult : statusLineResult !== 0 ? statusLineResult : launcherResult;
process.exit(exitCode);
process.exit(uninstallAll());
} else {
console.log(`\n${COLORS.YELLOW}${SYMBOLS.WARNING} CANCELED${COLORS.RESET}\n`);
rl.close();
@@ -2954,6 +2946,82 @@ function uninstallDesktopApp() {
return 0;
}
// ============================================================================
// UNINSTALL ALL (`plan2code uninstall` runs the npx install with --uninstall)
// ============================================================================
/**
* Everything Plan2Code installed, in the order the menu's U option has always removed it.
* Your own data under ~/.plan2code (notebooks, handoffs, console settings) stays; see
* purgeData(). Returns the first non-zero exit code, else 0.
*/
function uninstallAll() {
const uninstallResult = uninstallSkills();
removeLegacyLoopShims();
const metricsResult = uninstallPlan2CodeMetrics();
const botResult = uninstallPlan2CodeBot();
const statusLineResult = uninstallStatusLine();
const launcherResult = uninstallLauncher();
uninstallDesktopApp();
return uninstallResult !== 0 ? uninstallResult : metricsResult !== 0 ? metricsResult : botResult !== 0 ? botResult : statusLineResult !== 0 ? statusLineResult : launcherResult;
}
/** The folder purgeData() empties: Plan2Code's own home, which holds the data uninstallAll() keeps. */
const PLAN2CODE_HOME = path.join(os.homedir(), '.plan2code');
/**
* Delete ~/.plan2code and everything left in it (notebooks, handoffs, console settings and
* the installed console). Returns 0 when it is gone, 1 when something could not be removed.
*/
function purgeData(home = PLAN2CODE_HOME) {
displaySectionHeader('PLAN2CODE DATA', '[ DELETE ]');
if (!fs.existsSync(home)) {
console.log(` ${COLORS.DIM}${SYMBOLS.INFO} No ${home} folder found${COLORS.RESET}\n`);
return 0;
}
try {
fs.rmSync(home, { recursive: true, force: true });
console.log(` ${COLORS.GREEN}${SYMBOLS.SUCCESS}${COLORS.RESET} Removed: ${home}\n`);
return 0;
} catch (error) {
console.log(` ${COLORS.RED}${SYMBOLS.ERROR}${COLORS.RESET} Failed to remove ${home}: ${error.message}\n`);
return 1;
}
}
/** One y/N question on the terminal; false without a terminal (nothing can answer it). */
async function askYesNo(prompt, { input = process.stdin, output = process.stdout } = {}) {
if (!input.isTTY) return false;
const rl = readline.createInterface({ input, output });
const answer = await new Promise((resolve) => rl.question(prompt, resolve));
rl.close();
return answer.trim().toLowerCase().startsWith('y');
}
/**
* `plan2code uninstall`: confirm, remove everything, then ask whether your data goes too.
* `yes` skips the confirmation (the data stays unless `purge` is set); `purge` deletes the
* data without asking. `ask` is the y/N prompt, replaced in tests. Returns the exit code.
*/
async function uninstall({ yes = false, purge = false, ask = askYesNo, remove = uninstallAll, purgeIt = purgeData } = {}) {
displaySectionHeader(' UNINSTALLING PLAN2CODE ');
console.log(`${COLORS.DIM}This removes the skills, the plan2code command, the desktop app and any dev tools.${COLORS.RESET}\n`);
if (!yes && !process.stdin.isTTY && ask === askYesNo) {
console.log(`${COLORS.YELLOW}${SYMBOLS.WARNING} Not a terminal, so nothing can answer the questions. Run plan2code uninstall --yes (add --purge to delete your data too).${COLORS.RESET}\n`);
return 1;
}
if (!yes && !(await ask(`${COLORS.RED}${SYMBOLS.SELECT} CONFIRM UNINSTALL${COLORS.RESET} (y/N): `))) {
console.log(`\n${COLORS.YELLOW}${SYMBOLS.WARNING} CANCELED${COLORS.RESET}\n`);
return 0;
}
let code = remove();
const wipe = purge || (!yes && (await ask(`${COLORS.CYAN}Also delete your Plan2Code data (notebooks, handoffs, settings) in ${PLAN2CODE_HOME}?${COLORS.RESET} (y/N): `)));
if (wipe) code = purgeIt() || code;
else console.log(`${COLORS.DIM}${SYMBOLS.INFO} Your data in ${PLAN2CODE_HOME} was kept. Delete the folder to remove it.${COLORS.RESET}\n`);
if (code === 0) console.log(`${COLORS.GREEN}${SYMBOLS.SUCCESS} Plan2Code is uninstalled${COLORS.RESET}\n`);
return code;
}
// ============================================================================
// UPDATE (`plan2code update` runs the npx install with --update)
// ============================================================================
@@ -3052,9 +3120,11 @@ if (require.main === module) {
process.exit(verifySkillsSync() ? 0 : 1);
} else if (argv.length === 1 && argv[0] === '--update') {
update().then((code) => process.exit(code));
} else if (argv[0] === '--uninstall' && argv.slice(1).every((a) => a === '--yes' || a === '--purge')) {
uninstall({ yes: argv.includes('--yes'), purge: argv.includes('--purge') }).then((code) => process.exit(code));
} else if (argv.length > 0) {
console.error(`Unknown option(s): ${argv.join(' ')}`);
console.error('Usage: node install.js [--build-skills | --verify-skills | --update]');
console.error('Usage: node install.js [--build-skills | --verify-skills | --update | --uninstall [--yes] [--purge]]');
console.error('Run with no options for the interactive installer.');
process.exit(1);
} else {
@@ -3062,4 +3132,4 @@ if (require.main === module) {
}
}
module.exports = { installSharedConsole, sweepOldConsoles, consoleHomeDir, CONSOLE_SHARED_DIR, update, installDesktopApp, offerDesktopApp, recordSkipped, appAssetName, checksumFor, APP_DEST, UPDATE_STEPS, INSTALL_RECORD, INSTALL_PIECES, readInstallRecord, recordInstalled, forgetInstalled, SOURCE_PROMPTS, generateSkillName };
module.exports = { uninstall, uninstallAll, purgeData, installSharedConsole, sweepOldConsoles, consoleHomeDir, CONSOLE_SHARED_DIR, update, installDesktopApp, offerDesktopApp, recordSkipped, appAssetName, checksumFor, APP_DEST, UPDATE_STEPS, INSTALL_RECORD, INSTALL_PIECES, readInstallRecord, recordInstalled, forgetInstalled, SOURCE_PROMPTS, generateSkillName };
+99 -2
View File
@@ -183,10 +183,10 @@ test("update: every step is an install function, never an uninstall", () => {
}
});
test("install.js: --update is in the usage line, and an unknown option still exits 1", () => {
test("install.js: --update and --uninstall are in the usage line, and an unknown option still exits 1", () => {
const result = spawnSync(process.execPath, [INSTALL, "--bogus"], { encoding: "utf8" });
assert.equal(result.status, 1);
assert.ok(result.stderr.includes("Usage: node install.js [--build-skills | --verify-skills | --update]"), result.stderr);
assert.ok(result.stderr.includes("Usage: node install.js [--build-skills | --verify-skills | --update | --uninstall [--yes] [--purge]]"), result.stderr);
});
// ---------------------------------------------------------------------------------------------
@@ -605,3 +605,100 @@ test("the skills CLI is pinned to one exact version, and every doc line that run
}
}
});
/** Run uninstall() with console output captured and the answers to its y/N questions scripted. */
async function runUninstall(options, answers = []) {
const lines = [];
const asked = [];
const calls = [];
const log = console.log;
console.log = (...args) => lines.push(args.join(" "));
try {
const code = await installer.uninstall({
ask: async (prompt) => {
asked.push(prompt.replace(/\x1b\[[0-9;]*m/g, ""));
return answers.shift() ?? false;
},
remove: () => (calls.push("remove"), 0),
purgeIt: () => (calls.push("purge"), 0),
...options,
});
return { code, asked, calls, out: lines.join("\n").replace(/\x1b\[[0-9;]*m/g, "") };
} finally {
console.log = log;
}
}
test("uninstall: a no at the confirmation removes nothing", async () => {
const r = await runUninstall({}, [false]);
assert.equal(r.code, 0);
assert.deepEqual(r.calls, []);
assert.equal(r.asked.length, 1);
assert.match(r.out, /CANCELED/);
});
test("uninstall: a yes removes everything, then asks about the data and keeps it on a no", async () => {
const r = await runUninstall({}, [true, false]);
assert.equal(r.code, 0);
assert.deepEqual(r.calls, ["remove"]);
assert.equal(r.asked.length, 2);
assert.match(r.asked[1], /Also delete your Plan2Code data/);
assert.match(r.out, /data in .* was kept/);
});
test("uninstall: a yes to the data question purges it", async () => {
const r = await runUninstall({}, [true, true]);
assert.deepEqual(r.calls, ["remove", "purge"]);
});
test("uninstall: --yes skips both questions and keeps the data", async () => {
const r = await runUninstall({ yes: true });
assert.deepEqual(r.asked, []);
assert.deepEqual(r.calls, ["remove"]);
});
test("uninstall: --yes --purge deletes the data without a question", async () => {
const r = await runUninstall({ yes: true, purge: true });
assert.deepEqual(r.asked, []);
assert.deepEqual(r.calls, ["remove", "purge"]);
});
test("uninstall: --purge alone still confirms the uninstall but never asks about the data", async () => {
const r = await runUninstall({ purge: true }, [true]);
assert.equal(r.asked.length, 1);
assert.deepEqual(r.calls, ["remove", "purge"]);
});
test("uninstall: a failing removal or purge makes the exit code non-zero", async () => {
assert.equal((await runUninstall({ yes: true, remove: () => 1 })).code, 1);
assert.equal((await runUninstall({ yes: true, purge: true, purgeIt: () => 1 })).code, 1);
});
test("purgeData: deletes the folder and everything in it, and copes with it missing", () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-purge-"));
fs.mkdirSync(path.join(dir, "notepads"));
fs.writeFileSync(path.join(dir, "notepads", "a.json"), "{}");
const log = console.log;
console.log = () => {};
try {
assert.equal(installer.purgeData(dir), 0);
assert.equal(fs.existsSync(dir), false);
assert.equal(installer.purgeData(dir), 0);
} finally {
console.log = log;
}
});
test("install.js --uninstall: an unknown extra option is refused", () => {
const r = spawnSync(process.execPath, [INSTALL, "--uninstall", "--nuke"], { encoding: "utf8", env: { ...process.env, HOME, USERPROFILE: HOME } });
assert.equal(r.status, 1);
assert.match(r.stderr, /Unknown option\(s\): --uninstall --nuke/);
});
test("install.js --uninstall: with no terminal and no --yes it explains, exits 1 and removes nothing", () => {
fs.mkdirSync(path.join(HOME, ".plan2code"), { recursive: true });
const r = spawnSync(process.execPath, [INSTALL, "--uninstall"], { encoding: "utf8", input: "", env: { ...process.env, HOME, USERPROFILE: HOME } });
assert.equal(r.status, 1, r.stderr);
assert.match(r.stdout, /Run plan2code uninstall --yes/);
assert.ok(fs.existsSync(path.join(HOME, ".plan2code")));
});
+28
View File
@@ -475,6 +475,34 @@ test("launcher: update passes npx's exit code through", (t) => {
assert.equal(box.run(["update"], { P2C_TEST_EXIT: "3" }).status, 3);
});
test("launcher: uninstall runs the npx install with --uninstall and starts no agent", (t) => {
const box = sandbox(["npx", "claude"]);
t.after(box.cleanup);
const result = box.run(["uninstall", "--yes", "--purge"]);
assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /Uninstalling Plan2Code\.\.\./);
const args = box.argsOf("npx");
assert.ok(args, "npx was not run");
assert.ok(args.includes("--uninstall") && args.includes("--yes") && args.includes("--purge"), args.join(" "));
assert.ok(!args.includes("--update"), args.join(" "));
assert.equal(box.argsOf("claude"), null);
});
test("launcher: uninstall passes npx's exit code through", (t) => {
const box = sandbox(["npx"]);
t.after(box.cleanup);
assert.equal(box.run(["uninstall"], { P2C_TEST_EXIT: "4" }).status, 4);
});
test("launcher: uninstall refuses an unknown option without running npx", (t) => {
const box = sandbox(["npx"]);
t.after(box.cleanup);
const result = box.run(["uninstall", "--nuke"]);
assert.equal(result.status, 2);
assert.match(result.stderr, /unknown option\(s\) for uninstall: --nuke/);
assert.equal(box.argsOf("npx"), null);
});
test("launcher: release notice prints from a fresh cache", (t) => {
const box = sandbox(["claude"], { installed: "1.0.0" });
t.after(box.cleanup);
+30 -2
View File
@@ -50,7 +50,9 @@
* again, and the run carries on as if that agent had been found all along.
*
* `plan2code update` starts no agent: it re-runs the npx install with `--update`, which
* reinstalls whatever ~/.plan2code/install.json lists (the desktop app included). Before an agent starts, one line says
* reinstalls whatever ~/.plan2code/install.json lists (the desktop app included).
* `plan2code uninstall [--yes] [--purge]` starts no agent either: it runs the same npx install
* with `--uninstall`. Before an agent starts, one line says
* when a newer release is out (releaseNotice), read from the web console's cached release check
* and never waiting on the network.
*
@@ -84,6 +86,7 @@ const USER_AGENTS_FILE = path.join(os.homedir(), '.plan2code', 'agents.json');
const MODELS_MENU_COMPACT_AT = 30;
const PICKER_PROMPT = 'Choose the project folder to open Plan2Code in';
const UPDATE_COMMAND = 'update';
const UNINSTALL_COMMAND = 'uninstall';
// The same URL src/web-console/update-check.mjs exports as REPO_URL. Apart from the
// agent-lookup.mjs import noted in the header, this file may require nothing but Node
// built-ins (and update-check.mjs is ESM), so it keeps its own copy.
@@ -1516,13 +1519,28 @@ function spawnCommand(file, args, options) {
function runUpdate(tag) {
console.log('Updating Plan2Code...');
console.log(c.dim('One update covers the skills, the plan2code command and the desktop app (when installed).'));
return runInstaller(['--update'], tag);
}
/**
* `plan2code uninstall [--yes] [--purge]`: the npx install with --uninstall, which asks before
* it removes anything (--yes skips that) and then whether your data in ~/.plan2code goes too
* (--purge says yes). The prompts run on this terminal, so stdio is inherited.
*/
function runUninstall(flags) {
console.log('Uninstalling Plan2Code...');
return runInstaller(['--uninstall', ...flags]);
}
/** Run install.js through npx with the given flags, passing npx's exit code through. */
function runInstaller(installerArgs, tag) {
const npx = findOnPath('npx');
if (!npx) {
console.error(`${ce.red('plan2code:')} npx was not found on your PATH. It comes with Node.js 18+ (https://nodejs.org).`);
return process.exit(127);
}
const spec = tag ? `git+${REPO_URL}#${tag}` : `git+${REPO_URL}`;
const child = spawnCommand(npx, ['--yes', '--allow-git=all', spec, '--update'], { stdio: 'inherit' });
const child = spawnCommand(npx, ['--yes', '--allow-git=all', spec, ...installerArgs], { stdio: 'inherit' });
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
process.on(signal, () => {});
}
@@ -1581,6 +1599,16 @@ async function launch() {
const tagAt = argv.indexOf('--tag');
return runUpdate(tagAt >= 0 ? argv[tagAt + 1] : undefined);
}
if (argv[0] === UNINSTALL_COMMAND) {
const flags = argv.slice(1);
const unknown = flags.filter((flag) => flag !== '--yes' && flag !== '--purge');
if (unknown.length > 0) {
console.error(`${ce.red('plan2code:')} unknown option(s) for uninstall: ${unknown.join(' ')}`);
console.error('Usage: plan2code uninstall [--yes] [--purge]');
return process.exit(2);
}
return runUninstall(flags);
}
const fromShortcut = argv.includes(PICK_FOLDER_FLAG);
const classic = argv.includes(CLASSIC_FLAG);
const permissions = {