⛰️ LifeOS — The AI-powered Life Operating System that helps you hill climb to wherever you're going.
fix(installer): deduplicate bun shell config entries on retry (#954)
Christaufff33521940ee6
diff --git a/Releases/v4.0.3/.claude/PAI-Install/engine/actions.ts b/Releases/v4.0.3/.claude/PAI-Install/engine/actions.tsindex 73ab5e21..742bc478 100644--- a/Releases/v4.0.3/.claude/PAI-Install/engine/actions.ts+++ b/Releases/v4.0.3/.claude/PAI-Install/engine/actions.ts@@ -13,6 +13,48 @@ import { PAI_VERSION, ALGORITHM_VERSION } from "./types";import { detectSystem, validateElevenLabsKey } from "./detect";import { generateSettingsJson } from "./config-gen";+/**+ * Remove duplicate bun PATH entries from shell config.+ * The bun.sh installer appends entries on every run — if install is+ * interrupted and retried, the config file accumulates duplicates.+ * Fixes: https://github.com/danielmiessler/Personal_AI_Infrastructure/issues/954+ */+function deduplicateBunShellEntries(): void {+ const home = homedir();+ const shell = process.env.SHELL || "/bin/zsh";++ let rcFile: string;+ if (shell.includes("fish")) {+ rcFile = join(home, ".config", "fish", "config.fish");+ } else if (shell.includes("bash")) {+ rcFile = join(home, ".bashrc");+ } else {+ rcFile = join(home, ".zshrc");+ }++ if (!existsSync(rcFile)) return;++ try {+ const content = readFileSync(rcFile, "utf-8");++ // Match bun config blocks: "# bun" line followed by export/set lines+ const bunBlockPattern = shell.includes("fish")+ ? /\n?# bun\nset --export BUN_INSTALL "[^"]*"\nset --export PATH \$BUN_INSTALL\/bin \$PATH\n?/g+ : /\n?# bun\nexport BUN_INSTALL="[^"]*"\nexport PATH="?\$BUN_INSTALL\/bin:\$PATH"?\n?/g;++ const matches = content.match(bunBlockPattern);+ if (!matches || matches.length <= 1) return; // No duplicates++ // Remove all bun blocks, then add back exactly one+ let cleaned = content.replace(bunBlockPattern, "");+ cleaned = cleaned.trimEnd() + "\n" + matches[0].trim() + "\n";++ writeFileSync(rcFile, cleaned);+ } catch {+ // Non-fatal — duplicates are cosmetic, not breaking+ }+}+/*** Search existing .claude directories and config locations for a given env key.* Returns the value if found, or empty string.@@ -291,6 +333,7 @@ export async function runPrerequisites(const bunBin = join(homedir(), ".bun", "bin");process.env.PATH = `${bunBin}:${process.env.PATH}`;await emit({ event: "message", content: "Bun installed successfully." });+ deduplicateBunShellEntries(); // Fix #954: clean up duplicate entries from retries}} else {await emit({ event: "progress", step: "prerequisites", percent: 50, detail: `Bun found: v${det.tools.bun.version}` });