Spaces:
Sleeping
Sleeping
feat: implement core system status, configuration management, and workspace-to-brain attachment functionality
37b748e | """ever-brain init — Interactive project initialization wizard.""" | |
| from pathlib import Path | |
| import typer | |
| from rich.console import Console | |
| from rich.panel import Panel | |
| from rich.text import Text | |
| from brain.paths import get_global_projects_dir, get_brains_dir, get_global_brains_dir | |
| from brain.utils.display import success, info, error | |
| from brain.commands.create import create as create_brain | |
| from brain.commands.persona import set_persona | |
| console = Console() | |
| def init() -> None: | |
| """Initialize Ever Brain for the current project.""" | |
| console.print(Panel( | |
| Text("Ever Brain Initialization Wizard", style="bold cyan"), | |
| subtitle="A Cognition Operating System for AI Agents" | |
| )) | |
| # 1. Storage Mode | |
| console.print("\n[bold]1. Project Storage Mode[/bold]") | |
| console.print("Choose where to store this project's memory (docs, logs, tasks):") | |
| console.print(" [1] Local (.brain/ folder in this project) - Best for portability & Git") | |
| console.print(" [2] Global (~/.ever-brain/workspaces/...) - Best for a clean project folder") | |
| choice = typer.prompt("Select option", default="1") | |
| is_local = choice == "1" | |
| # 2. Core Brain Location | |
| console.print("\n[bold]2. Core Brain Location[/bold]") | |
| console.print("Choose where the 'Core Brain' (personas, global history) should live:") | |
| console.print(" [1] Global (~/.ever-brain/brains/) - Shared across all your projects") | |
| console.print(" [2] Local (.brains/ folder) - Isolated strictly to this project") | |
| brain_loc_choice = typer.prompt("Select option", default="1") | |
| is_brain_local = brain_loc_choice == "2" | |
| if is_brain_local: | |
| brains_dir = Path.cwd() / ".brains" | |
| brains_dir.mkdir(exist_ok=True) | |
| else: | |
| brains_dir = get_global_brains_dir() | |
| # 3. Brain Selection | |
| console.print("\n[bold]3. Core Brain Selection[/bold]") | |
| console.print(f"Which brain in [cyan]{brains_dir}[/cyan] should handle this project?") | |
| # List existing brains | |
| existing_brains = [] | |
| if brains_dir.exists(): | |
| existing_brains = [d.name for d in brains_dir.iterdir() if d.is_dir()] | |
| options = [] | |
| if "work-brain" not in existing_brains: | |
| options.append("Create 'work-brain'") | |
| else: | |
| options.append("Use existing 'work-brain'") | |
| if "personal-brain" not in existing_brains: | |
| options.append("Create 'personal-brain'") | |
| else: | |
| options.append("Use existing 'personal-brain'") | |
| options.append("Create custom brain") | |
| for i, opt in enumerate(options, 1): | |
| console.print(f" [{i}] {opt}") | |
| brain_choice = typer.prompt("Select option", default="1") | |
| selected_brain = "" | |
| idx = int(brain_choice) - 1 | |
| if idx < len(options): | |
| opt_text = options[idx] | |
| if "work-brain" in opt_text: | |
| selected_brain = "work-brain" | |
| elif "personal-brain" in opt_text: | |
| selected_brain = "personal-brain" | |
| else: | |
| selected_brain = typer.prompt("Enter name for custom brain") | |
| # Create brain if it doesn't exist | |
| brain_path = brains_dir / selected_brain | |
| if not brain_path.exists(): | |
| info(f"Creating new core brain: {selected_brain}") | |
| # Pass the specific directory to create to ensure it respects our choice | |
| from brain.templates.brain_instance import scaffold_brain_instance | |
| scaffold_brain_instance(brain_path) | |
| success(f"Ever Brain instance '{selected_brain}' created at {brain_path}") | |
| # 4. Persona Selection | |
| console.print("\n[bold]4. Persona Selection[/bold]") | |
| console.print("Choose an initial persona (you can change this later):") | |
| console.print(" [1] Architect (Software Engineering specialist)") | |
| console.print(" [2] Researcher (Data & Synthesis specialist)") | |
| console.print(" [3] General (Standard Assistant)") | |
| persona_choice = typer.prompt("Select option", default="1") | |
| persona_map = {"1": "architect", "2": "researcher", "3": "general"} | |
| selected_persona = persona_map.get(persona_choice, "general") | |
| # 5. Finalizing | |
| project_name = Path.cwd().name | |
| from brain.config import set_active_brain, set_storage_mode | |
| if is_local: | |
| workspace_dir = Path.cwd() / ".brain" | |
| workspace_dir.mkdir(exist_ok=True) | |
| # Store current project link | |
| (workspace_dir / "current_project").write_text(project_name, encoding="utf-8") | |
| set_storage_mode("local") | |
| success(f"Initialized Local storage in [cyan]{workspace_dir}[/cyan]") | |
| else: | |
| # Create global project marker locally | |
| (Path.cwd() / ".ever-brain").write_text(f"project: {project_name}\nmode: global", encoding="utf-8") | |
| set_storage_mode("global") | |
| # Workspace dir will be resolved by get_workspace_dir() later | |
| success(f"Initialized Global storage (Local folder stays clean)") | |
| # Set the brain as active for this project | |
| set_active_brain(brain_path) | |
| # Apply persona | |
| set_persona(selected_persona) | |
| console.print("\n[bold green]SUCCESS![/bold green] Ever Brain is ready.") | |
| info(f"Active Brain: {selected_brain} ({'Local' if is_brain_local else 'Global'})") | |
| info(f"Storage Mode: {'Local' if is_local else 'Global'}") | |
| info(f"Persona: {selected_persona}") | |
| info("Next step: Run 'ever-brain status'") | |