cortex-engine
CLAUDE.md51 starsChanged 8 months agoMITView on GitHub
Portable cognitive engine for AI agents. Published as @fozikio/cortex-engine on npm. Conventional commits with scopes and explanatory bodies, PR-required (no direct pushes to master), the local-ci status (npm run ci:local -- <branch> on the PR's final head) as the merge gate required by the master ruleset, Keep-a-Changelog CHANGELOG.md with semver tags. New clones: run git config core.hooksPath .githooks once to activate the commit-msg lint hook. Root dirs outside src/: reflex-rules/ (reflex YAML rules), skills/ (Claude Code skills), hooks/ (shell hooks),…
In this repository4 other files it gives its agents.
- cortex-memorySkill
- cortex-querySkill
- cortex-reviewSkill
- learn-projectSkill
The file
Files
cortex-engine
Portable cognitive engine for AI agents. Published as @fozikio/cortex-engine on npm.
Workflow tier: Production
Conventional commits with scopes and explanatory bodies, PR-required (no direct
pushes to master), the local-ci status (npm run ci:local -- <branch> on the PR's
final head) as the merge gate required by the master ruleset, Keep-a-Changelog CHANGELOG.md with
semver tags. New clones: run git config core.hooksPath .githooks once to
activate the commit-msg lint hook.
Commands
npm run build # tsc → dist/
npm run dev # tsc --watch
npm run test # vitest (requires --experimental-vm-modules)
npm run test:watch # vitest watch mode
npm run serve # Start MCP server (node dist/bin/serve.js)
npm run docs:tools # Regenerate docs/tools-reference.md from dist/ (build first)
npm run ci:local -- <ref> # Merge gate: CI checks in a clean worktree, posts `local-ci` statusArchitecture
src/
├── bin/ # CLI entry points (serve.js, cortex-engine CLI)
├── bridges/ # Cross-namespace bridging
├── cli/ # CLI command tree, arg parsing, TUI
├── core/ # Config, types, utilities
├── engines/ # Cognitive processing, memory consolidation, FSRS, dream pipeline
├── federation/ # Peer discovery via sigil, cross-instance queries
├── mcp/ # MCP server with 27+ cognitive tools
├── namespace/ # Multi-namespace management
├── plugins/ # Plugin system
├── providers/ # LLM/embedding providers (Anthropic, OpenAI, Vertex, HuggingFace)
├── rest/ # REST API server
├── services/ # Local daemon supervisor, probe, watchdog
├── stores/ # Storage backends
│ ├── sqlite.ts # Local SQLite (better-sqlite3)
│ └── firestore.ts # Cloud Firestore
├── tools/ # Tool definitions
├── triggers/ # Event triggers
└── index.ts # Main entry + re-exportsRoot dirs outside src/: reflex-rules/ (reflex YAML rules), skills/ (Claude Code skills), hooks/ (shell hooks), openclaw-plugin/ (OpenClaw integration), examples/ (example CLAUDE.md, session flow).
Docs
docs/tools-reference.md— generated MCP tool reference (npm run docs:tools)docs/storage-backends.md— SQLite vs Firestore backend contractdocs/concurrency.md— transaction and locking rules (see below)
Key Exports
.— Core engine, types, tools./stores/sqlite— SQLite storage backend./stores/firestore— Firestore storage backend./mcp— MCP server./rest— REST API
Critical Rules
- ESM only (
"type": "module") — all imports need.jsextensions - Target: ES2022, Module: NodeNext
- Strict TypeScript —
noUnusedLocals,noUnusedParameters,noImplicitReturns - LLM/embedding providers are peer dependencies (optional) — don't add them as direct deps
- SQLite via
better-sqlite3(native addon) — needs rebuild on Node version changes
Concurrency invariants
- One cortex-engine process per SQLite database. Cross-process locking is not provided.
- Multi-step writes (memory + edges, belief + memory update, etc.) MUST use
store.withTransaction(async (txn) => { ... }). Single writes do not need wrapping. - Inside the
withTransactionclosure: store ops only. No LLM calls, no embeds, no network. Fetch external data before the transaction and pass it in. - SQLite serializes transactions through a Promise-chained mutex per store instance;
busy_timeout = 5000covers checkpoint contention. - See
docs/concurrency.mdfor the full contract, Firestore parity notes, and call-site rationale.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

