from pathlib import Path from config import settings # Files loaded per tier — mirrors CONTEXT_TIERS.md TIER_FILES: dict[int, list[str]] = { 1: ["SOUL.md", "IDENTITY.md"], # + USER.md summary only 2: ["SOUL.md", "IDENTITY.md", "USER.md", "MEMORY.md", "PROTOCOLS.md"], 3: ["SOUL.md", "IDENTITY.md", "USER.md", "MEMORY.md", "PROTOCOLS.md"], 4: ["SOUL.md", "IDENTITY.md", "USER.md", "MEMORY.md", "PROTOCOLS.md"], } # Lines of USER.md to include at Tier 1 (just identity + what he cares about) TIER_1_USER_LINES = 30 def _read(path: Path) -> str: if path.exists(): return path.read_text() return f"[missing: {path.name}]" def load_context(tier: int = 2) -> str: inara_dir = settings.inara_path() parts = [] files = TIER_FILES.get(tier, TIER_FILES[2]) for filename in files: path = inara_dir / filename if not path.exists(): continue if filename == "USER.md" and tier == 1: # Tier 1: include only the first N lines lines = path.read_text().splitlines()[:TIER_1_USER_LINES] content = "\n".join(lines) else: content = path.read_text() parts.append(f"--- {filename} ---\n{content}") if tier >= 3: # Add recent session logs sessions_dir = inara_dir / "sessions" if sessions_dir.exists(): count = 2 if tier == 3 else 7 session_files = sorted(sessions_dir.glob("*.md"), reverse=True)[:count] for sf in session_files: parts.append(f"--- Session: {sf.name} ---\n{sf.read_text()}") return "\n\n".join(parts)