File size: 1,589 Bytes
279ebac
a02272f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279ebac
a02272f
 
 
279ebac
a02272f
 
 
 
 
 
 
279ebac
a02272f
 
 
 
279ebac
a02272f
 
 
 
 
 
 
 
 
 
 
 
 
279ebac
a02272f
279ebac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""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.")