Skip to content

Commit ae24cd0

Browse files
authored
fix: add uninstall cleanup script for state outside plugin files (#226) (#228)
1 parent 8cff216 commit ae24cd0

3 files changed

Lines changed: 123 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,17 @@ VS Code with the Codex extension reads `AGENTS.md`, which this repo ships, so it
210210

211211
Which files map to which agent: [Agent portability](docs/agent-portability.md).
212212

213+
### Uninstall
214+
215+
| Host | Command |
216+
|------|---------|
217+
| Claude Code | `/plugin remove ponytail` |
218+
| Codex | `codex plugin remove ponytail` |
219+
| Pi agent | `pi uninstall ponytail` |
220+
| Cursor / Windsurf / Cline / etc. | Delete the copied rule file |
221+
222+
These remove the plugin's own files. They leave behind a small amount of state ponytail writes outside the plugin folder: the mode flag, `~/.config/ponytail/config.json`, and (if you accepted the setup nudge) a `statusLine` entry in `~/.claude/settings.json`. Run `node scripts/uninstall.js` (from this repo, or wherever it was installed) to clean those up too. It only removes the statusLine entry if it points at ponytail's own script, so a statusline you set up yourself is left untouched.
223+
213224
## Commands
214225

215226
| Command | What it does |

‎scripts/uninstall.js‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env node
2+
// ponytail — removes state ponytail wrote outside the plugin's own files:
3+
// the mode flag, the config file, and the statusLine entry it added to
4+
// settings.json. Plugin files themselves are removed by each host's own
5+
// uninstall command (see README); this only cleans up what those commands
6+
// can't see.
7+
8+
const fs = require('fs');
9+
const path = require('path');
10+
const { getConfigPath, getClaudeDir } = require('../hooks/ponytail-config');
11+
12+
function removeIfExists(filePath, label) {
13+
try {
14+
fs.unlinkSync(filePath);
15+
console.log(`Removed ${label}: ${filePath}`);
16+
} catch (e) {
17+
if (e.code !== 'ENOENT') throw e;
18+
}
19+
}
20+
21+
removeIfExists(path.join(getClaudeDir(), '.ponytail-active'), 'mode flag');
22+
removeIfExists(getConfigPath(), 'config file');
23+
24+
const settingsPath = path.join(getClaudeDir(), 'settings.json');
25+
try {
26+
const raw = fs.readFileSync(settingsPath, 'utf8').replace(/^\uFEFF/, '');
27+
const settings = JSON.parse(raw);
28+
const cmd = settings.statusLine && settings.statusLine.command;
29+
if (typeof cmd === 'string' && cmd.includes('ponytail-statusline')) {
30+
delete settings.statusLine;
31+
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
32+
console.log(`Removed ponytail statusLine entry from ${settingsPath}`);
33+
}
34+
} catch (e) {
35+
if (e.code !== 'ENOENT') throw e;
36+
}

‎tests/uninstall.test.js‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env node
2+
3+
const assert = require('assert');
4+
const fs = require('fs');
5+
const os = require('os');
6+
const path = require('path');
7+
const { spawnSync } = require('child_process');
8+
9+
const root = path.join(__dirname, '..');
10+
11+
function runUninstall(env) {
12+
return spawnSync(process.execPath, [path.join(root, 'scripts', 'uninstall.js')], {
13+
env: { ...process.env, ...env },
14+
encoding: 'utf8',
15+
});
16+
}
17+
18+
delete process.env.CLAUDE_CONFIG_DIR;
19+
20+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'ponytail-uninstall-'));
21+
process.on('exit', () => fs.rmSync(temp, { recursive: true, force: true }));
22+
23+
const home = path.join(temp, 'home');
24+
const claudeDir = path.join(home, '.claude');
25+
fs.mkdirSync(claudeDir, { recursive: true });
26+
27+
const flagPath = path.join(claudeDir, '.ponytail-active');
28+
fs.writeFileSync(flagPath, 'full');
29+
30+
const configDir = path.join(temp, 'config-home', 'ponytail');
31+
fs.mkdirSync(configDir, { recursive: true });
32+
const configPath = path.join(configDir, 'config.json');
33+
fs.writeFileSync(configPath, JSON.stringify({ defaultMode: 'ultra' }));
34+
35+
const settingsPath = path.join(claudeDir, 'settings.json');
36+
fs.writeFileSync(settingsPath, JSON.stringify({
37+
statusLine: { type: 'command', command: 'bash /some/path/ponytail-statusline.sh' },
38+
}));
39+
40+
const env = {
41+
HOME: home,
42+
USERPROFILE: home,
43+
XDG_CONFIG_HOME: path.join(temp, 'config-home'),
44+
};
45+
46+
let result = runUninstall(env);
47+
assert.equal(result.status, 0, result.stderr);
48+
assert.equal(fs.existsSync(flagPath), false, 'mode flag must be removed');
49+
assert.equal(fs.existsSync(configPath), false, 'config file must be removed');
50+
51+
const settingsAfter = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
52+
assert.equal(
53+
settingsAfter.statusLine,
54+
undefined,
55+
'ponytail statusLine entry must be removed',
56+
);
57+
58+
// A user's own, unrelated statusLine must survive untouched.
59+
fs.writeFileSync(settingsPath, JSON.stringify({
60+
statusLine: { type: 'command', command: 'bash ~/my-custom-statusline.sh' },
61+
}));
62+
63+
result = runUninstall(env);
64+
assert.equal(result.status, 0, result.stderr);
65+
const settingsAfter2 = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
66+
assert.equal(
67+
settingsAfter2.statusLine.command,
68+
'bash ~/my-custom-statusline.sh',
69+
"a user's own statusLine must not be touched",
70+
);
71+
72+
// Running on an already-clean machine must not throw.
73+
result = runUninstall({ HOME: path.join(temp, 'home-empty'), USERPROFILE: path.join(temp, 'home-empty') });
74+
assert.equal(result.status, 0, result.stderr);
75+
76+
console.log('uninstall script checks passed');

0 commit comments

Comments
 (0)