How 33zepha/cortexlab_ works
Purpose and entry points
Cortex Lab is a Node.js governance/runtime system for disciplined AI-agent execution: policy-controlled routing, traceable event recording, and mission-state projection. The core entry points are the runtime modules under runtime/, the HTTP/SSE server at server/index.mjs, and the Vite-based operational console rooted at web/src/main.jsx.
Governance source of truth
Constitution files define agent roles and core rules, while generated manifests and registry data provide runtime-consumable policy metadata. This separates human-authored governance from executable lookup structures.
• constitution/core.yaml
• constitution/agents.yaml
• manifests/agents.json
• registry/registry.json
Registry compilation and controls
Build scripts compile the constitution/control definitions into registry and bundle artifacts used by the runtime. Control schemas encode enforceable invariants such as prohibited debug logging or label conventions, rather than relying on agent discretion.
• generate-registry.mjs
• compile-bundle.mjs
• manifests/controls.json
• schemas/ctrl-no-debug-log.yaml
Agent routing and authority boundary
The router is the primary authorization/control boundary: it determines whether an agent action is allowed under registered authority and controls. The chief-of-staff module coordinates mission-level agent work, while checks evaluate runtime constraints before or during execution.
• runtime/router.mjs
• runtime/chief-of-staff.mjs
• runtime/checks.mjs
Durable event ledger and projections
Execution is captured as newline-delimited ledger events. The event store owns append/read behavior; mission projection derives current mission state from the append-only event history. This makes decisions, transitions, and closures auditable rather than stored only as mutable state.
• runtime/event-store.mjs
• runtime/mission-projection.mjs
• ledger/events.ndjson
Service/API and live delivery
The Node server exposes the backend API, runs missions, and streams runtime changes over Server-Sent Events. It is the integration boundary between governance/runtime logic and the browser console; no external hosted service is indicated.
• server/index.mjs
• runtime/chief-of-staff.mjs
• runtime/event-store.mjs
Mission-control web console
A separate React/Vite frontend consumes API, router, ledger, and derived dashboard view models to render operational status. Mission Control focuses on execution topology, timeline, health, inspection, and terminal/event docks; Console Overview provides broader operational visibility.
• web/src/main.jsx
• web/src/pages/MissionControl.jsx
• web/src/components/dashboard/ExecutionCanvas.jsx
• web/src/lib/dashboard-view-model.js
Runtime and infrastructure
Core execution requires Node.js 18+. The frontend is a Vite React application with a development proxy to the backend and production static assets served alongside the Node API/SSE service. CI includes a visual-proof workflow, while tests lock core authority, registry, routing, runtime, and ledger contracts.
• package.json
• web/package.json
• web/vite.config.js
• .github/workflows/ui-visual-proof.yml
Main entry points: index.mjs Node API & SSE server · event-store.mjs Event store · router.mjs Authority router · controls.json Control manifest
Components 20
Governance
Human rules and executable policy metadata.
- Constitution rules · Defines core rules and agent roles.
constitution/core.yaml - Agent roles
constitution/agents.yaml - Registry generator · Compiles governance into runtime lookup data.
generate-registry.mjs - Authority registry · Runtime-consumable agent authority metadata.
registry/registry.json - Control schema · Encodes enforceable runtime invariants.
schemas/ctrl-no-debug-log.yaml - Control manifest
manifests/controls.json - Bundle compiler
compile-bundle.mjs - Agent manifest
manifests/agents.json
Runtime
Authorization, orchestration, and auditable state.
- Authority router · Primary action authorization and control boundary.
runtime/router.mjs - Runtime checks · Evaluates execution constraints.
runtime/checks.mjs - Chief of staff · Coordinates mission-level agent work.
runtime/chief-of-staff.mjs - Event store · Owns ledger append and read operations.
runtime/event-store.mjs - Event ledger · Append-only audit history.
ledger/events.ndjson - Mission projection · Derives current mission state from events.
runtime/mission-projection.mjs
Service & Console
API/SSE delivery and operational UI.
- Node API & SSE server · Runs missions and bridges runtime to the browser.
server/index.mjs - Console entry
web/src/main.jsx - Mission Control · Operational execution and timeline console.
web/src/pages/MissionControl.jsx - Execution canvas
web/src/components/dashboard/ExecutionCanvas.jsx - Dashboard view model · Transforms runtime data for operational views.
web/src/lib/dashboard-view-model.js - Vite proxy & build · Proxies development traffic and builds production assets.
web/vite.config.js
Connections 22
- Constitution rules → Registry generator: compiled into
- Agent roles → Registry generator: compiled into
- Registry generator → Authority registry: produces
- Control schema → Control manifest: defines
- Control manifest → Bundle compiler: bundled by
- Agent manifest → Bundle compiler: bundled by
- Authority registry → Authority router: authorizes against
- Control manifest → Runtime checks: enforces
- Authority router → Runtime checks: evaluates constraints
- Chief of staff → Authority router: routes agent actions
- Chief of staff → Event store: records execution
- Authority router → Event store: records decisions
- Event store → Event ledger: appends and reads
- Event store → Mission projection: supplies event history
- Node API & SSE server → Chief of staff: runs missions
- Node API & SSE server → Event store: reads and streams events
- Node API & SSE server → Console entry: API and SSE
- Console entry → Mission Control: renders
- Mission Control → Execution canvas: composes
- Dashboard view model → Mission Control: feeds view data
- Node API & SSE server → Dashboard view model: supplies runtime data
- Vite proxy & build → Node API & SSE server: development proxy