import logging
from pathlib import Path
from core.config import config

logger = logging.getLogger("core.conductor.identity")

class Identity:
    """
    Manages the Agent Persona and Rules.
    Source of Truth: .agent/rules/project-goals.md
    """
    def __init__(self):
        self.persona_name = "Antigravity"
        self.rules_content = ""
        
    def load(self) -> bool:
        """
        Load the immutable project rules.
        """
        rules_path = config.RULES_DIR / "project-goals.md"
        if not rules_path.exists():
            logger.error(f"FATAL: Identity Rules missing at {rules_path}")
            return False
            
        try:
            self.rules_content = rules_path.read_text(encoding='utf-8')
            logger.info(f"Identity Loaded: {self.persona_name}")
            return True
        except Exception as e:
            logger.error(f"Failed to load Identity: {e}")
            return False
            
    def get_system_instruction(self) -> str:
        """
        Returns the compiled system prompt.
        """
        return f"""
        IDENTITY: {self.persona_name}
        
        MANDATE:
        {self.rules_content}
        """
