@ayanpartan/cortexa
v0.1.2
Published
CORTEXA developer cognition system scaffold
Downloads
75
Readme
CORTEXA is a local-first memory runtime for software development workflows. It ingests code and chat history, stores optimized memory units, retrieves relevant context with hybrid ranking, and compiles prompt-ready context for coding agents and tools.
CX-LINK is CORTEXA’s context exchange protocol: a stable contract for turning retrieval results + constraints into agent-ready envelopes (/cxlink/context, /cxlink/query, /cxlink/plan).
This README is fully updated for:
- primary
cortexaCLI wiring (ingestion, resurrection, compaction, dashboard) - primary
cortexaprogression evolve command telemetry - compaction + deterministic resurrection pipeline
- third-wave compaction dashboard payload with trend snapshots and per-project risk/anomaly reporting
- daemon HTTP/WS routes and operational scripts
- branch-aware memory forking/merge workflows (
main+ custom branches) - temporal retrieval + diff APIs for time-travel context reconstruction (
asOf) - intent-aware proactive context suggestions and daemon stream events (
contextSuggested,branchSwitched)
What’s in CORTEXA today
- Hybrid memory store (
Mempalace)- SQLite metadata (
better-sqlite3) - vector index provider:
qdrant/chroma/ in-memory fallback - branch-aware overlay model with copy-on-write rows + branch tombstones
- temporal snapshot timeline for as-of retrieval and memory diffs
- SQLite metadata (
- Ingestion pipeline
- code parsing/chunking + AST-derived hints
- optional Copilot chat transcript/session ingestion
- Compaction + resurrection
- compact envelope format:
cortexa://mem/compact/v1/ - Brotli payload + checksum verification
- deterministic resurrection at read/retrieval time
- compact envelope format:
- Compaction analytics
- stats, dry-run/apply backfill, dashboard payloads
- persisted trend snapshots (
memory_compaction_snapshots) - integrity anomaly tracking (
invalidChecksum,decodeError)
- Self-healing scheduler hardening
- persisted scheduler run history (
self_healing_run_history) across restarts - exponential backoff on repeated run failures
- rolling-window SLO counters for
applied/dry-run-only/skipped/error
- persisted scheduler run history (
- Observability + hardening
- structured JSON logging for daemon HTTP and scheduler lifecycle
- Prometheus metrics export (
/metrics) with HTTP + self-healing dimensions - built-in rate limiting controls for daemon APIs
- Context compiler
- token-bounded packing
- copilot-friendly content summaries (
copilotContent) for lower token cost - branch/as-of aware retrieval threading
- intent-aware proactive suggestion hints (topK/tokens/scope/constraints)
- MCP stdio transport
- full JSON-RPC framing over stdio for MCP-compatible clients
- modular tool catalog bridging daemon + CX-LINK APIs
- MCP context codec tools (
cortexa_encode_mcp_ctx/cortexa_decode_mcp_ctx)
- Daemon APIs + WS stream
- query/context/evolve/cxlink + compaction endpoints
- branch management and temporal diff/query endpoints
- stream deltas for proactive suggestion + branch switch notifications
Architecture (high level)
Primary CLI (cortexa)
├── ingest (code/chat ingestion)
├── query (hybrid retrieval)
├── context (token-bounded context compile)
├── memory (list/search/get/resurrect/delete/stats/backfill/dashboard)
├── dashboard (alias => memory dashboard)
└── daemon (local HTTP + WS runtime)
↓
Mempalace (core memory engine)
├── SQLite metadata + snapshots
├── Vector index (Qdrant/Chroma/InMemory)
├── Compaction + resurrection layer
└── Retrieval + ranking + context formattingPrerequisites
- Node.js
^20.11.1or^22.0.0 [email protected]
Setup
git clone <your-repo-url>
cd Cortexta
pnpm install
pnpm run buildOptional health checks:
pnpm run doctor
pnpm run typecheckDocs Index
docs/api-examples.md— Copy/paste JSON request and response examples for all daemon endpoints.docs/operator-runbook.md— Day-1 and Day-2 operational workflows (setup, maintenance, compaction, troubleshooting).docs/cxlink-spec.md— CX-LINK protocol spec (concepts, contract, versioning, route semantics).docs/mcp-server.md— MCP stdio transport setup, tool surface, and client wiring.docs/observability.md— Structured logs + Prometheus metrics + scrape guidance.docs/security.md— Security hardening controls for auth, rate limiting, inputs, and container sandboxing.docs/containerization.md— Docker/Docker Compose setup for daemon + Qdrant.CONTRIBUTING.md— Contribution workflow, quality gates, and PR checklist.CHANGELOG.md— Release history and notable change tracking.
5-minute workflow (end-to-end)
pnpm install
pnpm run doctor
# 1) ingest project memory
pnpm run cortexa -- ingest . --project-id=my-project --max-files=500 --no-include-chats
# 2) retrieve and compile context
pnpm run cortexa -- query "how is cxlink context assembled?"
pnpm run cortexa -- context "add a new daemon route with tests"
# 3) run progression telemetry
pnpm run cortexa -- evolve "improve progression selection quality" --project-id=my-project --dry-run --json
# 4) run daemon for API clients
pnpm run cortexa:daemon
# 5) (optional) run MCP stdio transport for external MCP clients
pnpm run cortexa:mcpIn another terminal (optional API smoke check):
curl -s http://localhost:4312/health
curl -s -X POST http://localhost:4312/cxlink/context -H "content-type: application/json" -d '{"query":"wire telemetry","projectId":"my-project"}'Primary CLI (source of truth)
Use the primary CLI through:
pnpm run cortexa -- <command> [args]The
--delimiter is intentionally supported/normalized in the primary CLI.
Command reference
init
Initialize SQLite schema + vector collection bootstrap.
pnpm run cortexa -- initingest
Ingest code and (by default) chat sessions.
pnpm run cortexa -- ingest <path> [options]Options:
--project-id=<id>--branch=<name>(defaultmain)--no-include-chats--no-skip-unchanged(force full re-ingest)--skip-unchanged=<true|false>--max-files=<n>--max-chat-files=<n>--chat-root=<path>
Examples:
pnpm run cortexa -- ingest .
pnpm run cortexa -- ingest . --project-id=my-service --max-files=1500 --max-chat-files=500
pnpm run cortexa -- ingest . --no-include-chatsquery
Hybrid memory retrieval.
pnpm run cortexa -- query "how did we harden websocket streaming?"
pnpm run cortexa -- query "why is auth flow failing" --project-id=my-service --branch=feature/auth --top-k=12 --min-score=0.4 --as-of=1713433000000context
Compile a prompt-ready context payload.
pnpm run cortexa -- context "add retry-safe checkpointing"
pnpm run cortexa -- context "stabilize flaky integration tests" --project-id=my-service --branch=release/next --as-of=1713433000000 --top-k=14 --max-tokens=5200evolve
Run progression-aware memory evolution from freeform text and surface stage telemetry.
pnpm run cortexa -- evolve "upgrade evolution progression telemetry"Options:
--project-id=<id>(defaultdefault)--context=<text>(optional context hint)--dry-run(compute progression without persisting)--jsonor--format=json(emit full telemetry payload)
daemon
Manage local daemon runtime.
pnpm run cortexa -- daemon start
pnpm run cortexa -- daemon status
pnpm run cortexa -- daemon stopmemory
Memory lifecycle + compaction ops.
pnpm run cortexa -- memory <action> [args/options]Actions:
list [projectId] [--limit=<n>] [--branch=<name>] [--as-of=<unix-ms>]search <query> [--project-id=<id>] [--branch=<name>] [--as-of=<unix-ms>] [--top-k=<n>] [--min-score=<0..1>]get <id> [--project-id=<id>] [--branch=<name>] [--as-of=<unix-ms>] [--full]resurrect <id> [--project-id=<id>] [--branch=<name>] [--as-of=<unix-ms>] [--full]delete <id> [--project-id=<id>] [--branch=<name>]branch list --project-id=<id>branch create <branch> --project-id=<id> [--from-branch=<name>] [--forked-from-commit=<sha>]branch merge <source> <target> --project-id=<id> [--strategy=<source-wins|target-wins>]branch switch <target> --project-id=<id> [--from-branch=<name>]temporal diff --project-id=<id> [--branch=<name>] --from=<unix-ms> --to=<unix-ms> [--limit=<n>]stats [--project-id=<id>]audit [--project-id=<id>] [--limit=<n>] [--max-issues=<n>] [--json]backfill [--project-id=<id>] [--limit=<n>] [--apply]dashboard [dashboard-options]
Examples:
pnpm run cortexa -- memory list --limit=20
pnpm run cortexa -- memory search "compaction checksum"
pnpm run cortexa -- memory branch create feature/auth-refactor --project-id=Cortexta --from-branch=main
pnpm run cortexa -- memory branch merge feature/auth-refactor release/next --project-id=Cortexta --strategy=source-wins
pnpm run cortexa -- memory temporal diff --project-id=Cortexta --branch=feature/auth-refactor --from=1713432000000 --to=1713434000000
pnpm run cortexa -- memory resurrect <id>
pnpm run cortexa -- memory stats --project-id=Cortexta
pnpm run cortexa -- memory audit --project-id=Cortexta --limit=5000 --max-issues=10
pnpm run cortexa -- memory backfill --limit=2000 # dry-run by default
pnpm run cortexa -- memory backfill --limit=2000 --apply # persist updatesdashboard (alias)
Equivalent to memory dashboard ....
pnpm run cortexa -- dashboard --no-persist-snapshot --trend-rows=10 --top-projects=20Dashboard options (primary CLI):
--jsonor--format=json--project-id=<id>--lookback-days=<n>--max-trend-points=<n>--max-projects=<n>--no-persist-snapshot--per-project-snapshot-limit=<n>--snapshot-retention-days=<n>--top-projects=<n>--trend-rows=<n>--out-json=<path>--out-human=<path>
Standalone scripts
Compaction maintenance script
pnpm run compact:memory -- --limit=1000
pnpm run compact:memory -- --projectId=Cortexta --limit=5000 --apply- dry-run by default
--applyto persist
Dashboard script
pnpm run dashboard:compaction -- --help
pnpm run dashboard:compaction -- --no-persist-snapshot
pnpm run dashboard:compaction -- --json --out-json=./tmp/dashboard.json
pnpm run dashboard:compaction -- --out-human=./tmp/dashboard.txtOutput modes:
- human-readable terminal report (default)
- JSON payload for automation (
--json/--format=json)
Daemon APIs
Start daemon:
pnpm run cortexa -- daemon startBase default:
- HTTP:
http://localhost:4312 - WS:
ws://localhost:4321
Auth
- If
CORTEXA_DAEMON_TOKENis set (and not placeholder), send either:- header
x-cortexa-token: <token> - or
Authorization: Bearer <token>
- header
Routes
GET /healthGET /metricsPOST /ingestPOST /queryPOST /contextPOST /context/suggestPOST /evolvePOST /evolve/progressionPOST /cxlink/contextPOST /cxlink/queryPOST /cxlink/planPOST /cxlink/branch/listPOST /cxlink/branch/createPOST /cxlink/branch/mergePOST /cxlink/branch/switchPOST /cxlink/temporal/queryPOST /cxlink/temporal/diffPOST /cxlink/compaction/statsPOST /cxlink/compaction/backfillPOST /cxlink/compaction/dashboardPOST /cxlink/compaction/auditPOST /cxlink/compaction/self-heal/statusPOST /cxlink/compaction/self-heal/trigger
/cxlink/context, /cxlink/query, and /cxlink/plan responses now also include a memoryHealth signal so agent runtimes can react to compaction/anomaly posture.
/query, /context, /cxlink/context, /cxlink/query, and /cxlink/plan accept branch-aware and temporal options (branch, asOf).
/context and /query now return an intent-aware suggestion; /context/suggest provides a dedicated proactive endpoint with optional warmup context compilation.
The daemon health payload now includes summarized self-healing scheduler status (enabled, started, running, nextRunAt, lastScheduledDelayMs, consecutiveFailures, lastOutcome, runCount, slo).
POST /evolve supports two modes:
- consolidate mode (existing behavior): no
textfield, runs compaction-style consolidation preview/apply over stored memories. - progression mode (new): include
text(and optionalcontext) to runevolveWithProgression(...)and return stage telemetry (progression).
POST /evolve/progression is a strict alias for progression mode and always requires text (returns 400 when missing).
Compaction + resurrection model
Envelope format
- Prefix:
cortexa://mem/compact/v1/ - Encoded envelope includes:
- codec (
br64) - original char count
- preview text
- payload (Brotli)
- optional checksum
- codec (
Read-time behavior
getMemoryById()and memory retrieval paths resurrect compacted content.copilotContentis generated as token-bounded preview content for context compilation.- Integrity anomalies are tracked as:
invalidChecksumdecodeError
Dashboard snapshot persistence
- Snapshot table:
memory_compaction_snapshots - Stores global + selected per-project snapshots
- Drives trend views and risk/anomaly reporting
Self-healing run history persistence
- Scheduler history table:
self_healing_run_history - Persists every scheduler/manual run payload so status survives daemon restarts
- Powers rolling-window SLO counters exposed by status + health payloads
Configuration (env vars)
Core storage/vector
CORTEXA_DB_PATH(default:data/cortexa.db)CORTEXA_VECTOR_PROVIDER(qdrant|chroma|memory, defaultqdrant)CORTEXA_VECTOR_URL(Qdrant endpoint, defaulthttp://localhost:6333)CORTEXA_CHROMA_URL(Chroma endpoint, defaulthttp://localhost:8001)CORTEXA_EMBEDDING_URL(optional external embedding service)
Ingestion
CORTEXA_INGEST_MAX_FILE_BYTES(default:786432)
Compaction tuning
CORTEXA_MEM_COMPACT_MIN_CHARSCORTEXA_MEM_COMPACT_MIN_WIN_RATIOCORTEXA_MEM_COMPACT_PREVIEW_CHARSCORTEXA_MEM_COPILOT_PREVIEW_CHARSCORTEXA_MEM_COMPACT_BROTLI_QUALITY
Daemon
CORTEXA_DAEMON_PORT(default4312)CORTEXA_WS_PORT(default4321)CORTEXA_DAEMON_TOKENCORTEXA_DAEMON_BODY_LIMIT(default6mb)CORTEXA_DAEMON_AUTOSTART(0disables module auto-start)
Observability + rate limiting
CORTEXA_LOG_ENABLED(defaulttrue)CORTEXA_LOG_LEVEL(trace|debug|info|warn|error|fatal, defaultinfo)CORTEXA_METRICS_ENABLED(defaulttrue)CORTEXA_METRICS_PATH(default/metrics)CORTEXA_METRICS_REQUIRE_AUTH(defaulttrue)CORTEXA_METRICS_COLLECT_DEFAULTS(defaulttrue)CORTEXA_DAEMON_RATE_LIMIT_ENABLED(defaulttrue)CORTEXA_DAEMON_RATE_LIMIT_WINDOW_MS(default60000)CORTEXA_DAEMON_RATE_LIMIT_MAX(default240)
MCP server transport
CORTEXA_MCP_SERVER_NAME(defaultcortexa-mcp)CORTEXA_MCP_SERVER_VERSION(default0.1.0)CORTEXA_MCP_PROTOCOL_VERSION(default2024-11-05)CORTEXA_MCP_DAEMON_URL(defaulthttp://127.0.0.1:4312)CORTEXA_MCP_DAEMON_TOKEN(optional daemon auth token)CORTEXA_MCP_TIMEOUT_MS(default20000)CORTEXA_MCP_ENABLE_MUTATIONS(defaultfalse)CORTEXA_MCP_LOG_LEVEL(debug|info|warn|error, defaultinfo)
Self-healing scheduler
CORTEXA_SELF_HEAL_ENABLED(defaultfalse)CORTEXA_SELF_HEAL_PROJECT_ID(optional; default all projects)CORTEXA_SELF_HEAL_INTERVAL_MS(default1800000)CORTEXA_SELF_HEAL_JITTER_MS(default60000)CORTEXA_SELF_HEAL_RUN_ON_START(defaultfalse)CORTEXA_SELF_HEAL_AUDIT_LIMIT(default5000)CORTEXA_SELF_HEAL_AUDIT_MAX_ISSUES(default20)CORTEXA_SELF_HEAL_BACKFILL_LIMIT(default5000)CORTEXA_SELF_HEAL_APPLY_ENABLED(defaultfalse)CORTEXA_SELF_HEAL_MAX_ALLOWED_ANOMALIES(default0)CORTEXA_SELF_HEAL_MIN_OPPORTUNITY_RATE(default0.2)CORTEXA_SELF_HEAL_MIN_DRY_RUN_COMPACTED_ROWS(default50)CORTEXA_SELF_HEAL_MAX_APPLY_ROWS(default2000)CORTEXA_SELF_HEAL_APPLY_WINDOW_START_HOUR(default1)CORTEXA_SELF_HEAL_APPLY_WINDOW_END_HOUR(default5)CORTEXA_SELF_HEAL_HISTORY_LIMIT(default50)CORTEXA_SELF_HEAL_PERSIST_HISTORY(defaulttrue)CORTEXA_SELF_HEAL_PERSISTED_HISTORY_LIMIT(default2000)CORTEXA_SELF_HEAL_BACKOFF_ENABLED(defaulttrue)CORTEXA_SELF_HEAL_BACKOFF_MULTIPLIER(default2)CORTEXA_SELF_HEAL_BACKOFF_MAX_INTERVAL_MS(defaultmin(8x interval, 24h))CORTEXA_SELF_HEAL_SLO_WINDOWS_MINUTES(default60,1440,10080)
Testing and verification
pnpm run typecheck
pnpm run test:unit
pnpm run test:observability
pnpm run test:mcp
pnpm run test:self-healing
pnpm run test:compaction
pnpm run test:branch-temporal
pnpm run test:daemonsCI runs on GitHub Actions with a Node matrix (20, 22) and an integration suite gate on Node 22.
Open-source and distribution
- License: MIT
- npm package metadata is configured for public distribution (
cortexa) - Runtime support: Node
^20.11.1and^22.0.0 - release automation is available via tag-driven GitHub workflow (
v*.*.*)
For containerized deployments, see docs/containerization.md.
Troubleshooting
- Unexpected daemon startup while running CLI command
- primary CLI now lazy-loads daemon command; non-daemon commands should not auto-start daemon.
- Vector backend unavailable messages
- CORTEXA falls back to SQLite lexical behavior and deterministic embeddings where possible.
- Backfill did not persist
memory backfillandcompact:memorydefault to dry-run; use--apply.
- No dashboard trend points
- enable snapshot persistence (don’t use
--no-persist-snapshot) and run dashboard repeatedly.
- enable snapshot persistence (don’t use
- Self-healing runs but never applies backfill
- check safety gates in status/last run reasons (
/cxlink/compaction/self-heal/status), especially anomaly guardrail, opportunity threshold, and apply-window hours.
- check safety gates in status/last run reasons (
- Self-healing scheduler keeps failing repeatedly
- check
consecutiveFailures,lastScheduledDelayMs, andslo.windowsin/cxlink/compaction/self-heal/statusor/health. - if needed, widen
CORTEXA_SELF_HEAL_BACKOFF_MAX_INTERVAL_MSand inspect latesterrorrun payload in persisted history.
- check
Package scripts quick list
pnpm run doctor
pnpm run build
pnpm run dev
pnpm run typecheck
pnpm run test:self-healing
pnpm run test:observability
pnpm run test:mcp
pnpm run test:compaction
pnpm run test:branch-temporal
pnpm run test:daemons
pnpm run cortexa -- <command>
pnpm run cortexa:daemon
pnpm run cortexa:mcp
pnpm run compact:memory -- --limit=1000
pnpm run dashboard:compaction -- --help