How tura-ai/tura works
Purpose and entry points
Tura is a local, open-source coding-agent system. It provides an interactive terminal UI, direct and gateway-backed CLI runs, a local HTTP/SSE gateway, and a desktop GUI. User-facing launch paths are tura/tura run in apps/tui/src/cli.ts, gateway binary crates/gateway/src/bin/gateway.rs, direct executor crates/gateway/src/bin/tura_exec.rs, and Tauri desktop host apps/tauri/src-tauri/src/main.rs.
Client surfaces
The TUI is a TypeScript terminal client with command parsing, gateway lifecycle/autostart, event-driven reducer state, and terminal rendering: apps/tui/src/index.ts, apps/tui/src/gateway/client.ts, apps/tui/src/tui/app.ts. The GUI is a React/Vite application using a typed gateway SDK; it renders conversation, files, plans, and settings from shared gateway state: apps/gui/app/src/entry.tsx, apps/gui/app/src/app.tsx, apps/gui/sdk/gateway/src/client.ts. Tauri packages the GUI and grants narrowly declared native capabilities, including gateway startup and local file input.
Gateway: API and orchestration boundary
The Rust gateway is the clients’ local HTTP/SSE boundary. It defines stable contracts, routes API resources (sessions, prompts, files, providers, agents, commands), streams runtime events, and manages the router/runtime processes: crates/gateway/src/web/server.rs, crates/gateway/src/api/session.rs, crates/gateway/src/contracts/event.rs. It also owns provider auth/OAuth lifecycle at the API boundary: crates/gateway/src/api/provider/oauth_flow.rs, crates/gateway/src/api/provider/auth_scheduler.rs.
Router and worker process control
The router is a local daemon/process supervisor and IPC dispatcher. It resolves registered agents, personas, and tools; starts worker runtimes; scopes managed processes; handles recovery and shutdown; and exposes session-db services: crates/router/src/main.rs, crates/router/src/runtime_dispatch.rs, crates/router/src/services/manager.rs. This is the principal isolation boundary between gateway requests and execution workers.
Agent runtime turn loop
The runtime executes session turns as a state machine. It bootstraps or restores sessions, builds bounded context, selects prompt/agent behavior, calls providers, interprets streaming/tool requests, executes tools, checkpoints state, and emits gateway events: crates/runtime/src/worker.rs, crates/runtime/src/turn_loop/mod.rs, crates/runtime/src/context/build.rs. Runtime prompt styles and agent modes are embedded/configured under crates/runtime/src/prompt_style/ and agents/src/.
Provider integration
The provider crate normalizes heterogeneous LLM APIs into runtime-facing streaming and response behavior, with provider-specific implementations for OpenAI-compatible services, ChatGPT/Codex, Claude Code, Google, Bedrock, Cohere, MiniMax, Qwen, and xAI: crates/provider/src/tura_llm.rs, crates/provider/src/streaming.rs, crates/provider/src/llm/providers/mod.rs. Credentials are external user configuration; providers are network-service boundaries.
Tools, commands, and execution safety
The primary model tool is structured command_run, which can represent multi-step shell, patch, planning, and task-status work in one model turn. Tool dispatch enforces command manifests/policies and routes external commands or shell execution: crates/tools/src/command_run/handler.rs, crates/tools/src/runtime/dispatch.rs, crates/tools/src/shell_executor/execution.rs. Built-in media/web commands are separate Rust executables—commands/read_media/src/main.rs, commands/web_discover/src/main.rs, commands/generate_media/src/main.rs—and may invoke local processing or external provider/web services.
Persistence and event flow
Session state, messages, logs, checkpoints, task plans, and snapshots flow runtime → router/session-db → gateway → SSE clients. The dedicated session-log service persists queued writes and supports recovery across process lifecycle changes: crates/session_log/src/service.rs, crates/session_log/src/store.rs, crates/runtime/src/checkpoint/runtime.rs. Gateway session stores bridge persisted state to frontend-oriented session APIs: crates/gateway/src/session/store.rs, crates/gateway/src/session/store_frontend.rs.
Main entry points: server.rs HTTP/SSE API · worker.rs Worker runtime · mod.rs Turn state machine · runtime_dispatch.rs Router daemon
Components 19
Client surfaces
- Terminal UI & CLI · Interactive UI plus direct and gateway-backed runs.
apps/tui/src/cli.ts - React desktop UI · Renders shared session, file, plan, and settings state.
apps/gui/app/src/app.tsx - Tauri desktop host · Packages the GUI and grants scoped native capabilities.
apps/tauri/src-tauri/src/main.rs
Gateway & control
- Gateway binary · Launches the local HTTP/SSE gateway.
crates/gateway/src/bin/gateway.rs - HTTP/SSE API · Routes session, prompt, file, provider, agent, and command APIs.
crates/gateway/src/web/server.rs - Frontend session store · Adapts persisted session state for frontend APIs.
crates/gateway/src/session/store_frontend.rs - Provider auth lifecycle · Owns provider authentication at the API boundary.
crates/gateway/src/api/provider/oauth_flow.rs - Router daemon · IPC dispatcher and isolation boundary for worker runtimes.
crates/router/src/runtime_dispatch.rs
Agent execution
- Worker runtime · Bootstraps or restores session execution.
crates/runtime/src/worker.rs - Turn state machine · Builds context, invokes models, handles streams and checkpoints.
crates/runtime/src/turn_loop/mod.rs - Bounded context builder
crates/runtime/src/context/build.rs - Tool dispatcher · Validates manifests and dispatches model tool requests.
crates/tools/src/runtime/dispatch.rs - command_run · Represents shell, patch, planning, and task-status work.
crates/tools/src/command_run/handler.rs - Shell executor
crates/tools/src/shell_executor/execution.rs
State & integrations
- LLM provider adapter · Normalizes heterogeneous streaming LLM APIs.
crates/provider/src/tura_llm.rs - LLM services · OpenAI-compatible, Claude, Google, Bedrock, and other providers.
- Router session DB services · Serves session state across managed processes.
crates/router/src/services/manager.rs - Session log store · Queues writes and supports lifecycle recovery.
crates/session_log/src/service.rs - Runtime checkpoints
crates/runtime/src/checkpoint/runtime.rs
Connections 23
- Tauri desktop host → React desktop UI: hosts
- Terminal UI & CLI → Gateway binary: autostarts
- Gateway binary → HTTP/SSE API: serves
- Terminal UI & CLI → HTTP/SSE API: HTTP/SSE
- React desktop UI → HTTP/SSE API: typed SDK
- HTTP/SSE API → Frontend session store: session APIs
- HTTP/SSE API → Provider auth lifecycle: provider auth
- HTTP/SSE API → Router daemon: dispatches work
- Router daemon → Worker runtime: starts isolated worker
- Worker runtime → Turn state machine: executes turns
- Turn state machine → Bounded context builder: builds context
- Turn state machine → LLM provider adapter: model streaming
- LLM provider adapter → LLM services: network calls
- Turn state machine → Tool dispatcher: tool requests
- Tool dispatcher → command_run: structured command
- command_run → Shell executor: shell actions
- Worker runtime → Runtime checkpoints: checkpoints
- Worker runtime → Session log store: events and logs
- Router daemon → Router session DB services: session services
- Session log store → Router session DB services: recovery state
- Router session DB services → Frontend session store: persisted sessions
- HTTP/SSE API → Terminal UI & CLI: SSE events
- HTTP/SSE API → React desktop UI: SSE events