ever-brain / brain /commands /delete.py
AlexKurian's picture
feat: implement cross-platform brain management system including backend API, CLI, and web installer
279ebac
Raw
History Blame Contribute Delete
1.59 kB
"""ever-brain delete <name> — Permanently delete a Brain Instance."""
import shutil
import typer
from brain.paths import get_brain_path
from brain.config import get_active_brain, load_config, save_config
from brain.utils.display import error, success, info
def delete(
name: str = typer.Argument(..., help="Name of the Brain Instance to delete"),
force: bool = typer.Option(
False,
"--force",
"-f",
help="Skip confirmation prompt.",
),
) -> None:
"""Permanently delete an Ever Brain Instance and all its project memory."""
brain_path = get_brain_path(name)
if not brain_path.exists():
error(f"Ever Brain instance '{name}' does not exist.")
raise typer.Exit(code=1)
# Safety: warn if deleting the active brain
active = get_active_brain()
is_active = active is not None and active.resolve() == brain_path.resolve()
if is_active:
info(f"'{name}' is the currently active Ever Brain.")
# Confirmation
if not force:
confirm = typer.confirm(
f"Permanently delete Ever Brain '{name}' at {brain_path}? This cannot be undone"
)
if not confirm:
info("Aborted.")
raise typer.Exit()
# Delete the brain directory
shutil.rmtree(brain_path)
# Clear active brain if it was the one deleted
if is_active:
cfg = load_config()
cfg.pop("active_brain", None)
save_config(cfg)
info("Active brain cleared. Run: ever-brain use <name>")
success(f"Ever Brain instance '{name}' deleted.")