Skip to content

Architecture

LingXiao is a Node.js 24, TypeScript, React, Fastify, SQLite based AI engineering orchestration runtime. The backend source root is src/; the WebUI source root is web/src.

Primary entry: src/cli.ts.

The CLI runs interactive sessions and can create a web server with the same DatabaseManager and SessionManager dependencies. On launch, it prints a tokenized URL and writes the port to ~/.lingxiao/port.

Startup also initializes:

  • Memory maintenance pipeline (runDueMemoryMaintenance)
  • Bundled skill synchronization to the global skill directory

Primary entry: src/server.ts.

Responsibilities:

  • Create Fastify server, register @fastify/websocket
  • Create shared runtime services: DatabaseManager, SessionManager, EventEmitter, ConnectionManager, SseBridge, AcpHandler, browser runtime, file/wiki/git APIs
  • Register MCP Forge routes and MCP Share routes
  • Register Local LLM Gateway routes when llm_gateway.enabled is true
  • Inject window.__LINGXIAO_TOKEN__ into served HTML
  • Serve built web assets from dist/web or development fallback paths

Primary entry: web/src.

The UI is state-driven with Zustand stores:

  • REST endpoints for listing sessions, settings, files, Git, plugins, tasks, workflows, stats, wiki, MCP Forge/Share, design market, etc.
  • ACP JSON-RPC for session actions
  • SSE via ACP connection for real-time state push
ComponentResponsibility
SessionManagerSession lifecycle: create, resume, message dispatch
SessionRuntimeRuntime context: Leader handle, Agent pool, tool registry
LeaderAgentCommander: decompose tasks, build DAG, schedule Workers, verify results
TaskBoard / DAGTask graph: dependencies, parallel scheduling, block/unblock
AgentPoolWorker process pool: spawn, recycle, heartbeat monitoring
ToolRegistryTool registration and invocation: 100+ built-in tools + MCP tools
SQLite DBPersistent storage: sessions, messages, tasks, agent state, memory
RuntimeStateUnified snapshot: session:runtime_state three-way sync source
Memory SystemPersistent memory: FTS5 full-text search + BM25 scoring + AutoDream
Skills CatalogSkill catalog: Phase Loader injects into Agent context on demand
MCP ForgeMCP server generation: stdio/http MCP server from description
Eternal LoopAutonomous mode: IDLE → CHECK → PATROL → THINK → WAIT cycle
Local LLM GatewayLocal LLM proxy: OpenAI/Anthropic dual-format
  1. User sends a goal via TUI/WebUI
  2. SessionManager creates a session, starts SessionRuntime
  3. LeaderAgent receives the goal, decomposes into a DAG task graph
  4. OrchestrationRuntime manages task lifecycle: assign Workers, monitor execution, extract verdicts
  5. Workers execute tasks via ToolRegistry
  6. Results and state written to SQLite, pushed to all clients via RuntimeState
  1. EternalLoop cycles at 30-second base interval (configurable)
  2. CHECK phase: inspect goal status and pending tasks
  3. SKIP/PATROL: skip or patrol when no tasks
  4. THINK: drive Leader execution when tasks exist
  5. WAIT: wait for completion, return to IDLE
  6. Exponential backoff: double interval on no-op, max 960 seconds
  7. Budget circuit breaker: 8 consecutive failures → auto-pause

LingXiao achieves three-way real-time sync (TUI/WebUI/CLI) via session:runtime_state:

  • SSE: Server-Sent Events, unidirectional push for session state changes
  • ACP JSON-RPC: bidirectional, WebUI sends commands and receives results via ACP connection
  • WebSocket: terminal PTY and browser real-time interaction

OrchestrationRuntime subscribes to task lifecycle events and provides:

  • Verdict extraction: parses PASS/FAIL/BLOCKED/UNKNOWN from task results, worker reports, and evaluation payloads
  • Default minimal evaluation policy: tasks without explicit evaluationPolicy receive required_evidence + max_repair: 1
  • Follow-up task creation: on FAIL/BLOCKED with repair budget remaining, creates repair tasks blocked-by the failed task

The Leader can pre-judge results and start downstream tasks before upstream completion (speculative execution), rolling back speculative branches on failure.

ComponentFailure BehaviorRecovery Strategy
Worker process crashAgentPool detects heartbeat timeoutMark task failed, OrchestrationRuntime creates repair task
Leader exceptionSessionRuntime catchesRestore persisted DAG state
Web Server port in useAuto-find available portWrite to ~/.lingxiao/port
Database lockSQLite WAL mode + retryTransaction-level retry
Eternal budget exhausted8 consecutive failuresAuto-pause, await user intervention
LLM call failureRetry + circuit breakerExponential backoff, circuit-breaker degradation
ModuleKey FilesResponsibility
CLI/TUIsrc/cli.ts, src/tui/*Command entry, Ink terminal UI
Web Serversrc/server.ts, src/web-server/*Routes.tsFastify HTTP/SSE/WS routes
Session Runtimesrc/runtime/*, src/core/SessionManager.tsSession lifecycle, state management
Agent Systemsrc/agents/*Leader/Worker, role capabilities, orchestration
Tool Kernelsrc/tools/*ToolRegistry, 100+ built-in tools
LLM Layersrc/llm/*Provider clients, streaming parsers, retry/circuit-breaker
Databasesrc/core/Database.tsSQLite, WAL, FTS5
Memory Systemsrc/core/Memory*.tsPersistent memory, AutoDream
MCPsrc/core/McpForge*.tsServer generation, tool discovery
Skillssrc/core/Skill*.tsPhase Loader, skill injection
Orchestrationsrc/agents/OrchestrationRuntime.tsDAG management, verification, speculative execution
Eternalsrc/core/Eternal*.tsAutonomous loop, supervisor, telemetry
LLM Gatewaysrc/core/LocalLlmGateway*.tsOpenAI/Anthropic proxy
Contextsrc/core/ContextManifest.tsContext assembly, memory index injection
Officesrc/tools/implementations/office/*HTML-first document generation
Permissionssrc/core/PermissionSystem.tsTool permissions, layered control