JSON-RPC over stdin/stdout. Implements the MCP protocol with 29 tools covering palace read/write, drawer CRUD, knowledge graph, navigation, tunnels, agent diary, and system operations. Includes the Memory Protocol and AAAK Spec in status responses.
Two functions: `search()` for CLI output and `search_memories()` for programmatic use. Both query ChromaDB with optional wing/room filters and return verbatim drawer content with similarity scores.
### `layers.py` — Memory Stack
Four classes (`Layer0` through `Layer3`) and the unified `MemoryStack`. Layer 0 reads identity, Layer 1 auto-generates from top drawers, Layer 2 does filtered retrieval, Layer 3 does semantic search.
### `knowledge_graph.py` — Temporal KG
SQLite-backed entity-relationship graph with temporal validity windows. Supports add, invalidate, query, timeline, and stats. Auto-creates entities on triple insertion.
### `palace_graph.py` — Navigation Graph
Builds a graph from ChromaDB metadata where nodes = rooms and edges = tunnels (rooms spanning multiple wings). Supports BFS traversal and tunnel finding.
### `dialect.py` — AAAK Compression
Lossy abbreviation system with entity encoding, emotion detection, topic extraction, and flag identification. Works on both plain text and structured zettel data.
## Ingest Modules
### `miner.py` — Project Ingest
Scans project directories for code and doc files. Respects `.gitignore`. Files content as drawers tagged with wing/room metadata.
### `convo_miner.py` — Conversation Ingest
Imports conversation exports (Claude, ChatGPT, Slack, Markdown, plaintext). Chunks by exchange pair. Supports `exchange` and `general` extraction modes.
### `normalize.py` — Format Converter
Converts 5 chat formats to a standard transcript format before mining.
### `general_extractor.py` — Memory Type Extraction
Classifies conversation content into decisions, preferences, milestones, problems, and emotional context.
## Detection Modules
### `entity_detector.py` — Entity Detection
Scans file content to auto-detect people and projects using regex patterns and heuristics.
### `entity_registry.py` — Entity Registry
Manages entity name → code mappings for AAAK dialect.
### `room_detector_local.py` — Room Detection
Detects rooms from folder structure during `mempalace init`.
## Utility Modules
### `config.py` — Configuration
Loads settings from `~/.mempalace/config.json` and environment variables.
### `split_mega_files.py` — Transcript Splitting
Splits concatenated transcripts into per-session files based on session boundary detection.
### `onboarding.py` — Guided Setup
Interactive setup wizard for `mempalace init`. Generates AAAK bootstrap and wing config.