|
8 | 8 |
|
9 | 9 | import { fileURLToPath } from "node:url"; |
10 | 10 | import { dirname, join } from "node:path"; |
11 | | -import { mkdirSync, appendFileSync, readFileSync } from "node:fs"; |
| 11 | +import { mkdirSync, appendFileSync, readFileSync, readdirSync, rmSync } from "node:fs"; |
12 | 12 | import { execSync } from "node:child_process"; |
13 | 13 | import { homedir } from "node:os"; |
14 | 14 | import { loadCredentials, saveCredentials, login } from "../commands/auth.js"; |
@@ -200,9 +200,22 @@ async function main(): Promise<void> { |
200 | 200 | try { |
201 | 201 | const scopes = ["user", "project", "local", "managed"]; |
202 | 202 | const cmd = scopes |
203 | | - .map(s => `claude plugin update hivemind@hivemind --scope ${s} 2>/dev/null`) |
| 203 | + .map(s => `claude plugin update hivemind@hivemind --scope ${s} 2>/dev/null || true`) |
204 | 204 | .join("; "); |
205 | 205 | execSync(cmd, { stdio: "ignore", timeout: 60_000 }); |
| 206 | + // Clean up old cached versions, keep only the latest |
| 207 | + try { |
| 208 | + const cacheParent = join(homedir(), ".claude", "plugins", "cache", "hivemind", "hivemind"); |
| 209 | + const entries = readdirSync(cacheParent, { withFileTypes: true }); |
| 210 | + for (const e of entries) { |
| 211 | + if (e.isDirectory() && e.name !== latest) { |
| 212 | + rmSync(join(cacheParent, e.name), { recursive: true, force: true }); |
| 213 | + log(`cache cleanup: removed old version ${e.name}`); |
| 214 | + } |
| 215 | + } |
| 216 | + } catch (e: any) { |
| 217 | + log(`cache cleanup failed: ${e.message}`); |
| 218 | + } |
206 | 219 | updateNotice = `\n\n✅ Hivemind auto-updated: ${current} → ${latest}. Run /reload-plugins to apply.`; |
207 | 220 | process.stderr.write(`✅ Hivemind auto-updated: ${current} → ${latest}. Run /reload-plugins to apply.\n`); |
208 | 221 | log(`autoupdate succeeded: ${current} → ${latest}`); |
|
0 commit comments