Neo.mjs Architecture Overview
This guide provides a top-level architectural map of the Neo.mjs Agent OS. It traces the vertical path of intelligence — from a user clicking a button, through the worker threads, up into the Agent OS, through the dream pipeline, and back down as an improved codebase.
For setup and configuration of individual MCP servers, see the dedicated guides linked at the bottom of this document.
The Two Hemispheres
Neo.mjs is a single platform with two distinct hemispheres that share a common nervous system — the Neo Class System:
Both hemispheres are built on the same Neo.core.Base class system. DreamService,
GraphService, Agent, Loop, and every MCP service extend Neo.core.Base and use
Neo.setupClass() exactly like Neo.button.Base or Neo.grid.Container. The AI
infrastructure is not a separate project — it is a native inhabitant of the framework
it maintains.
Left Hemisphere: The Runtime Engine
The runtime is Neo's core value proposition. All application logic runs off the Main Thread inside a multi-worker architecture:
Key Concepts
- App Worker: Hosts all components, controllers, state providers, and business logic. This is where your application code lives.
- VDom Worker: A dedicated thread for the JSON diff engine. It receives VDOM blueprints from the App Worker and computes minimal delta updates.
- Data Worker: Handles stores, models, sorting, filtering, and grouping — keeping heavy data operations off the main thread.
- Main Threads: Thin clients that only apply DOM mutations. Each browser window has its own main thread, but they all connect to the same App Worker.
The Triangular Optimization
VDOM updates follow an optimized triangular path:
- App Worker sends the new JSON VDOM tree to the VDom Worker
- The Main Thread intercepts the VDom Worker's reply and applies delta mutations to the DOM immediately
- Main Thread forwards confirmation back to the App Worker
This eliminates a full round-trip vs naively routing updates through the App Worker.
SharedWorker Mode
When useSharedWorkers: true, the App Worker becomes a SharedWorker. Multiple browser
windows connect to the same App Worker instance, sharing a single JavaScript heap.
Components can be moved between windows — unmounted from one, remounted in another —
without losing state. This is the foundation of Neo's multi-window application support.
Right Hemisphere: The Agent OS
The Agent OS is a Node.js infrastructure that provides AI agents with persistent memory, semantic understanding of the codebase, and the ability to introspect the live running application:
The Cognitive Loop
The agent runtime (ai/agent/Loop.mjs) implements a four-phase cognitive loop:
- Perceive: The
ContextAssemblerfetches long-term memory (session summaries via RAG), short-term memory (recent session history), and skill metadata to build the LLM context window. - Reason: The assembled context is sent to the LLM (e.g., Claude Opus, Gemini) for inference, producing a response that may include tool calls.
- Act: Tool calls are executed via the MCP protocol (for frontier models) or the SDK (for sub-agents with Zod validation).
- Reflect: Every thought, decision, and tool call is persisted via
add_memory(), creating the episodic memory record that the DreamService will later digest.
The SDK Bouncer Pattern
ai/services.mjs is the critical safety layer. It loads OpenAPI specs from each MCP server and
wraps each method with makeSafe() — a function that generates Zod validators at startup.
- Frontier models (Opus, Gemini) access services via MCP protocol (stdio) with unbounded tool access.
- Sub-agents (e.g., Gemma 4-31B for doc patching) access the same services via the SDK, but every call is runtime-validated against the OpenAPI schema, preventing hallucinated JSON from reaching internal databases.
The Five MCP Servers
| Server | Purpose | Key Operations |
|---|---|---|
| Knowledge Base | Semantic RAG over the indexed codebase | ask_knowledge_base, query_documents |
| Memory Core | Episodic memory, session summaries, native edge graph | add_memory, query_raw_memories, get_context_frontier |
| GitHub Workflow | Offline-first issue and PR management | create_issue, sync_all, manage_issue_labels |
| Neural Link | Live application introspection via WebSocket | get_component_tree, patch_code, simulate_event |
| File System | Direct codebase read/write access | Standard file operations |
The Neural Link Bridge
The Neural Link is the connection point between the two hemispheres. It allows the Agent OS to reach into the running browser application:
The AI does not scrape DOM. It queries the semantic component tree directly — asking for
components by ntype, reading store data, inspecting state providers, and even hot-patching
methods on class prototypes at runtime. The same WebSocket bridge serves both AI agents and
Playwright test fixtures, creating a unified "Whitebox E2E" testing architecture.
How it Works
- The
Neo.ai.Clientsingleton lives inside the App Worker (browser-side) - It connects to the Neural Link MCP Server via WebSocket (JSON-RPC 2.0)
- The MCP Server exposes 5 client-side service categories: Component, Data, Instance, Interaction, and Runtime
- When a new browser window connects, the client rehydrates the full window topology to the Agent OS
The Dream Pipeline
The DreamService is an autonomous background daemon that runs when agents are idle.
It is the mechanism by which the system learns from itself:
The Six Phases
File Ingest:
FileSystemIngestor.syncWorkspaceToGraph()scans the repository and ingests issues, markdown files, and source files into the Native Edge Graph (SQLite).Tri-Vector Extraction: A local LLM (MLX / OpenAI-compatible) analyzes undigested session memories and extracts three vectors: semantic graph nodes and edges, the feature namespace being worked on, and any roadmap impact.
Topological Conflict Detection: Another LLM pass scans for tickets that have been rendered obsolete, superseded, or duplicated by recent session decisions. Alerts are written to
sandman_handoff.md.Capability Gap Inference: This phase is deterministic — it does not use an LLM. It cross-references graph nodes directly against the filesystem:
- Does
test/contain files matching this class's tokens? If not: TEST_GAP - Does
learn/guides/have a matching guide? If not: GUIDE_GAP
- Does
Hebbian Decay: Universal edge weight fade and garbage collection of stale nodes, inspired by synaptic pruning in neuroscience.
Golden Path Synthesis: Tri-Vector scoring of all OPEN issues, producing a prioritized roadmap written to
sandman_handoff.md. This file is the strategic dashboard that the next agent instance reads on boot.
The Closed Loop
This is the architecture's gravitational center. Every piece connects into a single self-improving feedback loop:
The agent's improvements to the framework also improve the agent's knowledge base, which improves the agent's future decisions. This is what distinguishes Neo.mjs from tools that provide memory, orchestration, or multi-agent roles in isolation — Neo builds the complete organism where the codebase and the agent co-evolve.
Structural Inventory
Runtime Engine (Browser)
| Package | Purpose | Key Classes | Decisions |
|---|---|---|---|
src/core/ |
Class system, Observable, Logger | Base, Observable |
— |
src/component/ |
UI primitives | Base, Wrapper |
— |
src/container/ |
Layout containers | Base, Viewport |
— |
src/grid/ |
Buffered data grids | Container, View |
— |
src/data/ |
Data layer | Store, Model, RecordFactory |
— |
src/state/ |
State management | Provider |
— |
src/worker/ |
Thread management | App, VDom, Data, Manager |
— |
src/vdom/ |
Virtual DOM engine | Helper |
— |
src/main/ |
Main thread addons | DomEvents, DomAccess |
— |
src/ai/ |
Neural Link client | Client |
— |
Agent OS (Node.js)
Post-M6 (#10986) the per-MCP-server services were lifted from ai/mcp/server/<name>/services/ into the flat SDK boundary at ai/services/<name>/. The ai/mcp/server/<name>/ directories now host only the server entry-point (Server.mjs), config templates, logger, and shared helpers; the service implementations live under ai/services/<name>/. Both rows are listed below for navigability.
| Package | Purpose | Key Classes | Decisions |
|---|---|---|---|
ai/Agent.mjs |
Agent base class | Agent |
— |
ai/agent/ |
Cognitive runtime | Loop, Orchestrator, Scheduler |
— |
ai/config.template.mjs, ai/BaseConfig.mjs |
Tier-1 Agent OS config template and shared config base consumed by top-level and MCP server configs | Config, BaseConfig |
— |
ai/context/ |
Context window management | Assembler |
— |
ai/provider/ |
LLM abstraction | Gemini, Ollama, OpenAiCompatible |
— |
ai/services.mjs |
SDK with Zod validation aggregator | — | — |
ai/services/knowledge-base/ |
Semantic RAG services (post-M6 SDK location) | QueryService, SearchService, KBRecorderService |
— |
ai/services/memory-core/ |
Episodic memory services (post-M6 SDK location) | MemoryService, SessionService, GraphService, MailboxService |
ADR 0001, ADR 0002 |
ai/services/github-workflow/ |
Issue/PR management services (post-M6 SDK location) | IssueService, SyncService, LabelService |
— |
ai/services/neural-link/ |
Live app bridge services (post-M6 SDK location) | ConnectionService, RecorderService |
— |
ai/services/shared/vector/ |
Cross-server vector-engine primitives consumed by per-server ChromaManager classes (KB + MC); functional helpers, not Neo classes | chromaClientPrimitives.mjs (chromaConnect, createSilentExecutor, chromaDeleteCollection) |
— |
ai/scripts/ |
One-shot operator scripts + thin helper wrappers | bridge-daemon.mjs |
ADR 0002 |
ai/daemons/ |
Long-running daemon classes and entry points | Orchestrator, orchestrator/daemon.mjs, DreamService, SwarmHeartbeatService |
ADR 0002 |
ai/graph/ |
Native Edge Graph (SQLite-backed knowledge graph) | Database, Store, NodeModel |
ADR 0001, ADR 0015 |
ai/mcp/server/knowledge-base/ |
KB MCP-server entry point + config | Server, config |
— |
ai/mcp/server/memory-core/ |
MC MCP-server entry point + config | Server, config |
ADR 0001 |
ai/mcp/server/github-workflow/ |
GH-WF MCP-server entry point + config | Server, config |
— |
ai/mcp/server/neural-link/ |
NL MCP-server entry point + config | Server, config |
— |
ai/mcp/server/shared/ |
Cross-cutting MCP infrastructure | BaseServer, AuthMiddleware, RequestContextService, TransportService |
— |
Architectural Decision Records
The Agent OS subsystem records its load-bearing architectural trade-offs in learn/agentos/decisions/. Every cross-system trade-off — i.e. one that touches multiple subsystems, sets a precedent for future code, or affects load-bearing invariants — earns an ADR (per the structural-pre-flight skill's Strategy-vs-Tactics threshold). Per-class localized constraints stay inline as Anchor & Echo guards instead.
The map-as-pointer principle: the Structural Inventory above links each subsystem row to its relevant ADRs so readers who follow the map naturally encounter the architectural-decision substrate without needing to remember to consult decisions/ separately. Authors of new ADRs MUST add the link to the affected Structural Inventory rows in the same PR (per #10449 Sub-Issue 2 / structural-pre-flight map-maintenance discipline).
| ADR | Subject | Subsystems Affected | Status |
|---|---|---|---|
| 0001 | Cross-Process Cache Coherence for Memory Core Graph | ai/services/memory-core/, ai/graph/, ai/mcp/server/memory-core/ |
Proposed (#10186 / #10189) |
| 0002 | Phase 3 Wake-Substrate Standards Alignment (MCP + A2A schema mappings) | ai/scripts/ (bridge-daemon), ai/daemons/, ai/services/memory-core/ (MailboxService A2A primitives) |
Proposed (#10311 / #10355) |
| 0015 | Graph Store Backend Posture - SQLite WAL First, Networked SQL Deferred | ai/graph/, ai/services/memory-core/, cloud deployment docs |
Accepted - 2026-05-22 (#11732; PR #11779) |
Next Steps
- Strategic Workflows — Advanced agent workflow patterns
- Swarm Intelligence & Sub-Agents — Delegation, profiles, and capability gating
- The Dream Pipeline & Golden Path — Forecasting engine and scoring algorithm
- Neural Link: Live Application Mutability — Deep dive into the Neural Link bridge
- The Knowledge Base Server — Semantic RAG architecture
- The Memory Core Server — Episodic memory and graph storage
- The GitHub Workflow Server — Offline-first issue management
- Code Execution (AI SDK) — The SDK Bouncer pattern in detail