All checks were successful
Tests / test (push) Successful in 2s
All ~/clawd/ references replaced with configurable paths: - CORTEX_HOME (default: ~/.cortex) - CORTEX_MEMORY_DIR, CORTEX_CONFIG, CORTEX_GROWTH_LOG, CORTEX_ROADMAP - permanent_files configurable via config.json - Tests pass both with and without env vars set - 169/169 tests green
72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
"""Cortex configuration — all paths and settings resolved here.
|
|
|
|
Priority: CLI args > environment variables > config file > defaults.
|
|
|
|
Environment variables:
|
|
CORTEX_HOME Base directory (default: ~/.cortex)
|
|
CORTEX_MEMORY_DIR Memory files directory
|
|
CORTEX_CONFIG Path to config.json
|
|
CORTEX_GROWTH_LOG Path to growth log file
|
|
CORTEX_ROADMAP Path to roadmap.json
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
from typing import Any, Optional
|
|
|
|
|
|
def _env(key: str, default: str | None = None) -> str | None:
|
|
return os.environ.get(key, default)
|
|
|
|
|
|
def cortex_home() -> Path:
|
|
"""Base directory for cortex data."""
|
|
return Path(_env("CORTEX_HOME", str(Path.home() / ".cortex")))
|
|
|
|
|
|
def memory_dir() -> Path:
|
|
return Path(_env("CORTEX_MEMORY_DIR", str(cortex_home() / "memory")))
|
|
|
|
|
|
def growth_log() -> Path:
|
|
return Path(_env("CORTEX_GROWTH_LOG", str(memory_dir() / "growth-log.md")))
|
|
|
|
|
|
def roadmap_file() -> Path:
|
|
return Path(_env("CORTEX_ROADMAP", str(memory_dir() / "roadmap.json")))
|
|
|
|
|
|
def archive_dir() -> Path:
|
|
return memory_dir() / "archive"
|
|
|
|
|
|
def logs_dir() -> Path:
|
|
return cortex_home() / "logs"
|
|
|
|
|
|
def config_path() -> Path:
|
|
return Path(_env("CORTEX_CONFIG", str(cortex_home() / "config.json")))
|
|
|
|
|
|
def load_config(path: Optional[Path] = None) -> dict[str, Any]:
|
|
"""Load config.json. Returns empty dict if not found."""
|
|
p = path or config_path()
|
|
if p.exists():
|
|
return json.loads(p.read_text())
|
|
return {}
|
|
|
|
|
|
# Default permanent files — overridable via config.json "permanent_files" key
|
|
DEFAULT_PERMANENT_FILES = {
|
|
"README.md",
|
|
}
|
|
|
|
|
|
def permanent_files(config: Optional[dict] = None) -> set[str]:
|
|
"""Files that should never be archived or deleted."""
|
|
cfg = config or load_config()
|
|
custom = cfg.get("permanent_files", [])
|
|
if custom:
|
|
return set(custom)
|
|
return DEFAULT_PERMANENT_FILES
|