"""Brain system — unified memory for Vincent (Hermes Agent).

Modular architecture (split from 3469-line monolith):
  config.py      — Constants and paths
  cache.py       — Entity LRU cache
  storage.py     — SQLite DB init, file operations
  events.py      — log_event, query_events, compact_events
  entities.py    — Entity/edge CRUD (create, get, update, delete, list)
  search.py      — Full-text search, semantic edges, hierarchy
  context.py     — get_context_summary, session context
  self_model.py  — Self-model loading, updating, introspection

All public symbols re-exported here for backward compatibility.
"""

# ── Configuration ──
from config import (
    BRAIN_DIR,
    EVENTS_DIR,
    SYNAPSES_DIR,
    INDEX_DIR,
    SELF_MODEL_PATH,
    RETENTION_DAYS,
    SYNAPSE_HALF_LIFE_DAYS,
    SYNAPSE_PRUNE_THRESHOLD,
    SYNAPSE_MAX_NODES,
    SYNAPSE_BROAD_TAG_THRESHOLD,
    SYNAPSE_MAX_EDGES_PER_NODE,
    MAX_EVENT_PAYLOAD_BYTES,
    TRUNCATE_MARKER,
    EVENTS_PER_SUMMARY,
    SELF_MODEL_UPDATE_INTERVAL,
)

# ── Storage ──
from storage import (
    init_brain,
    get_session_id,
    set_session_id,
    get_current_date_dir,
    atomic_write_json,
    atomic_append_jsonl,
    get_db_path,
    init_db,
    close_db,
    _db_connection,
    _lock,
)

# ── Cache ──
from cache import (
    _entity_cache_get,
    _entity_cache_set,
    _entity_cache_clear,
)

# ── Events ──
from events import (
    log_event,
    query_events,
    compact_events,
)

# ── Entities ──
from entities import (
    search_entities,
    get_entity_events,
    entity_timeline,
    create_entity,
    get_entity,
    update_entity,
    delete_entity,
    add_edge,
    get_edges,
    get_edges_incoming,
    list_relationships,
    delete_edge,
    list_entities,
)

# ── Search ──
from search import (
    search,
    _preprocess_query,
    _get_semantic_edges,
    _get_hierarchy,
)

# ── Context ──
from context import (
    get_context_summary,
)

# ── Self Model ──
from self_model import (
    _load_self_model,
    update_self_model,
    introspect,
)

# ── Public API ──
__all__ = [
    # Core
    "init_brain",
    "log_event",
    "query_events",
    "compact_events",
    "get_context_summary",
    # Entities
    "create_entity",
    "get_entity",
    "update_entity",
    "delete_entity",
    "add_edge",
    "get_edges",
    "get_edges_incoming",
    "list_relationships",
    "delete_edge",
    "list_entities",
    "search_entities",
    "get_entity_events",
    "entity_timeline",
    # Search
    "search",
    # Session
    "get_session_id",
    "set_session_id",
    "get_current_date_dir",
    # Storage
    "atomic_write_json",
    "atomic_append_jsonl",
    "get_db_path",
    "init_db",
    "close_db",
    # Self-model
    "_load_self_model",
    "update_self_model",
    "introspect",
    # Constants
    "BRAIN_DIR",
    "EVENTS_DIR",
    "INDEX_DIR",
    "SELF_MODEL_PATH",
    "RETENTION_DAYS",
    "MAX_EVENT_PAYLOAD_BYTES",
    "TRUNCATE_MARKER",
    "EVENTS_PER_SUMMARY",
]