Cortex (AIngle)
Cortex is an HTTP sidecar binary (aingle-cortex) that provides Mayros with a persistent RDF triple store built on AIngle. It powers semantic memory, the knowledge graph, P2P synchronization, and observability tracing.
Architecture
mermaidgraph LR A[Mayros CLI / TUI] -->|HTTP| B[CortexClient] B -->|REST API| C[aingle-cortex sidecar] C -->|QUIC gossip| D[Remote Cortex nodes] C -->|RDF store| E[Local data ~/.mayros/cortex-data/]
Mayros communicates with Cortex exclusively through CortexClient, a TypeScript HTTP client that wraps all REST calls with circuit-breaker resilience.
Auto-start lifecycle
Cortex is managed automatically by Mayros:
Health check
On startup, Mayros checks if Cortex is already running on the configured port.
Binary detection
If not running and autoStart is enabled, Mayros locates the binary at ~/.mayros/bin/aingle-cortex (or the configured binaryPath).
Version check
Compares the binary version against REQUIRED_CORTEX_VERSION (currently 0.4.1). Warns on older versions; blocks startup if strictVersionCheck is enabled.
Auto-install
If the binary is missing from ~/.mayros/bin/, Mayros automatically downloads it from GitHub Releases.
Spawn
Starts the sidecar process with --db for persistent Sled storage, plus host, port, and P2P flags. A lock file prevents concurrent instances.
Health polling
Polls GET /health with exponential backoff (100ms to 2s, max 10s total).
Auto-restart
Monitors the process and auto-restarts on crash (up to 3 attempts with exponential backoff).
Graceful shutdown flushes all data (graph + Ineru snapshots) to disk before exiting via SIGTERM/SIGINT.
Seamless binary updates
When Mayros updates the Cortex binary (via mayros update), it coordinates a zero-data-loss flow:
- Flush — sends
POST /api/v1/flushto persist all in-memory data - Stop — SIGTERM with 10s timeout, then SIGKILL if needed
- Replace — new binary is written to
~/.mayros/bin/ - Restart — sidecar restarts with the same
--dbpath, data intact
REST API
Cortex exposes a REST API consumed by CortexClient:
| Endpoint | Method | Purpose |
|---|---|---|
/health | GET | Health check with component statuses |
/api/v1/triples | POST/GET/DELETE | Triple CRUD operations |
/api/v1/query | POST | Pattern-based triple queries |
/api/v1/events | POST/GET | Trace event storage and retrieval |
/api/v1/audit | GET | Audit log queries |
/api/v1/proofs | POST/GET | Proof of Logic verification |
/api/v1/p2p/status | GET | P2P network status |
/api/v1/p2p/peers | GET/POST/DELETE | P2P peer management |
/api/v1/sync/delta | POST | Delta synchronization |
/api/v1/flush | POST | Flush graph and Ineru snapshots to disk |
/stats | GET | Server and graph statistics |
Data model
All data is stored as RDF triples: subject → predicate → object. Values can be strings, numbers, booleans, or node references.
mayros:agent:main → mayros:memory:convention → "Use ESM imports"
mayros:plan:abc123 → mayros:plan:phase → "explore"
file:src/index.ts → defines:function → "main"
Triples are namespaced with a configurable prefix (default: mayros) to enforce isolation between projects and agents.
Paths
| Path | Purpose |
|---|---|
~/.mayros/bin/aingle-cortex | Cortex binary (auto-installed if missing) |
~/.mayros/cortex-data/ | Persistent data directory (Sled graph + Ineru snapshots) |
~/.mayros/cortex-data/cortex-secrets.json | Auto-generated JWT secret and admin password (mode 0600) |
~/.mayros/cortex-data/.cortex.lock | Lock file preventing concurrent sidecar instances |
Configuration
json5{ cortex: { host: "127.0.0.1", // Cortex host port: 19090, // Cortex port autoStart: true, // Auto-spawn sidecar dataDir: undefined, // Data directory (default: ~/.mayros/cortex-data/) binaryPath: undefined, // Override binary location authToken: undefined, // Auth token (or CORTEX_AUTH_TOKEN env) requireAuth: false, // Require authentication strictVersionCheck: false, // Block on version mismatch p2p: { enabled: false, // Enable native P2P port: 19091, // QUIC gossip port seed: undefined, // Shared secret for peer auth manualPeers: [], // Peer addresses mdns: false, // mDNS discovery }, resilience: { timeoutMs: 5000, // Request timeout maxRetries: 2, // Retry count retryDelayMs: 300, // Base retry delay circuitThreshold: 5, // Failures before circuit opens circuitResetMs: 30000, // Recovery timeout }, }, }
Cortex is optional — Mayros works without it, but semantic memory, P2P sync, knowledge graph, rules engine, and observability tracing all require a running Cortex instance.
Related
- P2P Sync — synchronize triples between instances
- Knowledge Graph — code indexing and project memory
- Cortex Resilience — circuit breaker and graceful degradation
- Memory — agent and session memory