How labcoder/xana works
Purpose and entry points
Xana is a Rust personal AI-agent harness for terminal interaction, workspace tools, provider-backed chat, managed Codex execution, and bounded external integrations. The binary starts at src/main.rs; library composition is in src/lib.rs. Command parsing and mode selection live in src/cli.rs, with application command handlers in src/app.rs. Bare interactive execution chooses TUI or plain terminal; one-shot, JSON, setup, service-host, and administrative commands share the CLI boundary.
Frontend and foreground control
Frontend code separates semantic UI behavior from execution ownership. src/frontend.rs and src/frontend/protocol.rs define frontend/runtime interaction; src/tui.rs implements the full-screen Ratatui surface, while src/plain_terminal.rs supports append-only control-free output. The local foreground host (src/local_host.rs, src/local_host/protocol.rs, src/workspace_host.rs) enables loopback observer/controller attachment with a single controller lease, rather than exposing a network service.
Configuration, identity, and durable local state
Configuration and credential references are validated and atomically managed through src/config.rs, src/config_migration.rs, and src/credential.rs. Profiles, routes, projects, plugins, and private bindings define effective execution without embedding secrets in portable project files. Durable local state is partitioned across src/private_state/store.rs, src/session/store.rs, and immutable artifact handling in src/artifact.rs; workspace/session ownership is a material concurrency boundary.
Native agent execution pipeline
Native conversations freeze prompt/context/tool state, execute a provider turn, stream responses, broker tool calls, and durably record session events. Core responsibilities span src/agent.rs, src/native_runtime.rs, and src/prompt/render.rs. Context construction is bounded and sourced from workspace/project materials through src/context.rs; session records are reduced and persisted via src/session/durable.rs and src/session/reduce.rs. Tool intents/results are operation-aware, enabling explicit—not automatic—recovery.
Model providers and managed runtimes
src/provider.rs abstracts native model connections, with concrete Anthropic and OpenAI-compatible implementations in src/provider/anthropic.rs and src/provider/openai_compat/client.rs. Catalog and model capability resolution reside in src/model_catalog.rs and src/capability.rs. Codex is intentionally a managed runtime, not another native model loop: src/managed/codex.rs supervises its app-server protocol and threads, while src/managed_execution.rs projects managed activity and approval events into Xana’s frontend.
Tool authority, outbound data, and integrations
Native tool definitions are centralized in src/tool.rs, including filesystem, document, shell, child-agent, and orchestration-plan tools. Every effect passes the permission policy/broker boundary in src/permission/broker.rs and src/permission/policy.rs; permission does not sandbox the host process. External data dispatch is separately gated by src/outbound.rs. MCP supports supervised stdio/HTTP/OAuth transports (src/mcp/stdio.rs, src/mcp/http.rs, src/mcp/oauth.rs); remote-agent delegation uses src/a2a.rs; image/vision routes are independent focused services in src/focused_service.rs.
Orchestration, operations, and observability
Child work is admission-controlled, budgeted, routed, and supervised by src/orchestration/plan.rs, src/orchestration/supervisor.rs, and src/orchestration/execution.rs. Children receive bounded handoff data and cannot recursively delegate. Durable operation state and explicit resume planning are in src/operation.rs and src/operation/recovery.rs. Diagnostics, structured metadata, crash reporting, and read-only repair guidance are handled by src/diagnostics.rs and src/doctor.rs; release packaging is driven by Cargo plus .github/workflows/release.yml and installer scripts under install/.
Main entry points: native_runtime.rs Native agent runtime · cli.rs Command dispatch · protocol.rs Frontend protocol · tool.rs Native tool intents
Components 20
Entry & Frontends
- CLI binary
src/main.rs - Command dispatch · Selects interactive, one-shot, service, setup, and admin modes.
src/cli.rs - Frontend protocol
src/frontend/protocol.rs - Terminal frontends
src/tui.rs - Local foreground host · Provides observer attachment and a single controller lease.
src/local_host.rs
State & Configuration
- Config & credentials · Profiles and bindings avoid portable embedded secrets.
src/config.rs - Private and session state · Workspace and session ownership form a concurrency boundary.
src/session/store.rs - Immutable artifacts
src/artifact.rs
Native Execution
- Native agent runtime · Freezes turn state, streams output, and coordinates tools.
src/native_runtime.rs - Prompt & bounded context · Builds bounded workspace and project context.
src/context.rs - Session event reduction · Reduces and records durable session events.
src/session/durable.rs - Native tool intents · Defines filesystem, shell, document, child-agent, and plan tools.
src/tool.rs - Permission broker · Policy-gates effects but does not sandbox the host process.
src/permission/broker.rs
Providers & Integrations
- Model providers · Connects native turns to Anthropic and OpenAI-compatible models.
src/provider.rs - Managed Codex runtime · A separate managed runtime with supervised protocol threads.
src/managed/codex.rs - Outbound data gate
src/outbound.rs - MCP transports · Supports stdio, HTTP, and OAuth transports.
src/mcp/stdio.rs
Orchestration & Operations
- Child orchestration · Budgets, routes, and supervises bounded non-recursive child work.
src/orchestration/supervisor.rs - Operation recovery · Stores operation state and plans explicit resume.
src/operation/recovery.rs - Diagnostics & doctor · Provides crash reporting and read-only repair guidance.
src/doctor.rs
Connections 22
- CLI binary → Command dispatch: starts
- Command dispatch → Frontend protocol: selects mode
- Frontend protocol → Terminal frontends: drives
- Frontend protocol → Local foreground host: attaches locally
- Command dispatch → Config & credentials: loads
- Command dispatch → Native agent runtime: runs native mode
- Command dispatch → Managed Codex runtime: runs managed mode
- Native agent runtime → Prompt & bounded context: builds turn context
- Native agent runtime → Model providers: executes provider turn
- Native agent runtime → Native tool intents: brokers tool calls
- Native agent runtime → Session event reduction: records events
- Prompt & bounded context → Immutable artifacts: reads materials
- Native tool intents → Permission broker: authorizes effects
- Permission broker → Outbound data gate: gates external dispatch
- Outbound data gate → MCP transports: dispatches integration data
- Native tool intents → Child orchestration: starts child work
- Child orchestration → Native agent runtime: routes child execution
- Managed Codex runtime → Frontend protocol: projects activity and approvals
- Native agent runtime → Operation recovery: persists operation state
- Operation recovery → Native agent runtime: plans explicit resume
- Diagnostics & doctor → Private and session state: inspects read-only
- Session event reduction → Private and session state: persists sessions