diff --git a/claude-code/bundle/session-start.js b/claude-code/bundle/session-start.js index 600faa9..1574357 100755 --- a/claude-code/bundle/session-start.js +++ b/claude-code/bundle/session-start.js @@ -3,7 +3,7 @@ // dist/src/hooks/session-start.js import { fileURLToPath } from "node:url"; import { dirname, join as join4 } from "node:path"; -import { mkdirSync as mkdirSync2, appendFileSync as appendFileSync2, readFileSync as readFileSync3 } from "node:fs"; +import { mkdirSync as mkdirSync2, appendFileSync as appendFileSync2, readFileSync as readFileSync3, readdirSync, rmSync } from "node:fs"; import { execSync as execSync2 } from "node:child_process"; import { homedir as homedir4 } from "node:os"; @@ -454,8 +454,20 @@ async function main() { log3(`autoupdate: updating ${current} \u2192 ${latest}`); try { const scopes = ["user", "project", "local", "managed"]; - const cmd = scopes.map((s) => `claude plugin update hivemind@hivemind --scope ${s} 2>/dev/null`).join("; "); + const cmd = scopes.map((s) => `claude plugin update hivemind@hivemind --scope ${s} 2>/dev/null || true`).join("; "); execSync2(cmd, { stdio: "ignore", timeout: 6e4 }); + try { + const cacheParent = join4(homedir4(), ".claude", "plugins", "cache", "hivemind", "hivemind"); + const entries = readdirSync(cacheParent, { withFileTypes: true }); + for (const e of entries) { + if (e.isDirectory() && e.name !== latest) { + rmSync(join4(cacheParent, e.name), { recursive: true, force: true }); + log3(`cache cleanup: removed old version ${e.name}`); + } + } + } catch (e) { + log3(`cache cleanup failed: ${e.message}`); + } updateNotice = ` \u2705 Hivemind auto-updated: ${current} \u2192 ${latest}. Run /reload-plugins to apply.`; diff --git a/esbuild.config.mjs b/esbuild.config.mjs index 6b5b5b2..e905c6f 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -114,7 +114,7 @@ await build({ contents: [ 'import { createRequire } from "node:module";', 'const _f = createRequire(import.meta.url)("fs");', - 'export const { existsSync, writeFileSync, mkdirSync, appendFileSync } = _f;', + 'export const { existsSync, writeFileSync, mkdirSync, appendFileSync, unlinkSync } = _f;', 'const _k = ["rea","dFile","Sync"].join("");', 'export const rfs = _f[_k];', 'export { rfs as readFileSync };', diff --git a/src/hooks/session-start.ts b/src/hooks/session-start.ts index 2019615..e22110c 100644 --- a/src/hooks/session-start.ts +++ b/src/hooks/session-start.ts @@ -8,7 +8,7 @@ import { fileURLToPath } from "node:url"; import { dirname, join } from "node:path"; -import { mkdirSync, appendFileSync, readFileSync } from "node:fs"; +import { mkdirSync, appendFileSync, readFileSync, readdirSync, rmSync } from "node:fs"; import { execSync } from "node:child_process"; import { homedir } from "node:os"; import { loadCredentials, saveCredentials, login } from "../commands/auth.js"; @@ -200,9 +200,22 @@ async function main(): Promise { try { const scopes = ["user", "project", "local", "managed"]; const cmd = scopes - .map(s => `claude plugin update hivemind@hivemind --scope ${s} 2>/dev/null`) + .map(s => `claude plugin update hivemind@hivemind --scope ${s} 2>/dev/null || true`) .join("; "); execSync(cmd, { stdio: "ignore", timeout: 60_000 }); + // Clean up old cached versions, keep only the latest + try { + const cacheParent = join(homedir(), ".claude", "plugins", "cache", "hivemind", "hivemind"); + const entries = readdirSync(cacheParent, { withFileTypes: true }); + for (const e of entries) { + if (e.isDirectory() && e.name !== latest) { + rmSync(join(cacheParent, e.name), { recursive: true, force: true }); + log(`cache cleanup: removed old version ${e.name}`); + } + } + } catch (e: any) { + log(`cache cleanup failed: ${e.message}`); + } updateNotice = `\n\n✅ Hivemind auto-updated: ${current} → ${latest}. Run /reload-plugins to apply.`; process.stderr.write(`✅ Hivemind auto-updated: ${current} → ${latest}. Run /reload-plugins to apply.\n`); log(`autoupdate succeeded: ${current} → ${latest}`);