Source of truth:
crates/cli/src/main.rscrates/core/src/agent/mod.rscrates/core/src/tools/mod.rscrates/core/src/agent_manager.rscrates/core/src/context_briefing.rscrates/core/src/workspace/mod.rscrates/tui/src/app.rs
| Crate | Responsibility |
|---|---|
crates/cli |
CLI entrypoint, command dispatch, runtime wiring |
crates/core |
agent runtime, tools, sessions, MCP, teams, hooks, memory |
crates/provider |
provider abstraction, model registry, streaming adapters |
crates/auth |
API key/OAuth/token resolution and rotation |
crates/config |
config schema/defaults/merge rules |
crates/tui |
terminal UI, slash commands, event loop, selectors |
crates/index |
semantic index, embeddings, auto-context retrieval |
flowchart LR
cliEntry["cli::main"] --> workspaceDetect["workspace::detect_workspace"]
cliEntry --> configLoad["Config::load + Config::merge"]
cliEntry --> providerInit["create_provider_async"]
cliEntry --> registryInit["tools::default_registry"]
cliEntry --> mcpInit["McpManager::start_all"]
cliEntry --> modeDispatch["Run Exec Or TUI"]
modeDispatch --> runOnce["run_once"]
modeDispatch --> tuiRun["tui::App::run"]
runOnce --> agentTurn["agent::run_turn"]
tuiRun --> agentTurn
agentTurn --> toolExec["ToolRegistry::execute"]
agentTurn --> streamEvents["AgentEvent stream"]
toolExec --> sessionPersist["session::save_session"]
- Parse CLI arguments.
- Load global config.
- Detect workspace root and rules source.
- If project config exists, merge with global config.
- Create provider (or defer when credentials unavailable).
- Build tool registry (
default_registry), then register MCP tools. - Dispatch to:
run/exec(run_once)- TUI app (
App::run)
Core turn execution is driven by agent::run_turn / run_turn_with_content.
Per turn:
- Prepare system prompt from workspace rules + custom instructions + MCP summaries.
- Inject memory (
memory::load_memory_for_prompt) when enabled. - Add optional auto-context from semantic index when enabled.
- Stream model response.
- Execute tool calls with permission checks.
- Emit
AgentEventupdates for UI/CLI. - Persist session unless ephemeral.
Tool execution gates:
- role filtering (
allowed_tool_names) - trust policy
- sandbox level
- explicit approval workflow for
NeedsApprovaltools
Concurrency:
- read-only tool calls may execute in parallel
- mutating calls execute sequentially
Subagents are managed by AgentManager (interactive runtime).
Lifecycle tools:
spawn_agentsend_inputwaitclose_agentresume_agent
Statuses (AgentStatus):
pending_initrunningcompletederroredshutdownnot_found
Manager limits:
max_threadsmax_depth
Before spawn, parent context can inject a briefing from SharedContext:
- recent file changes
- active todos
- conversation summary
- project memory excerpt
Caps:
MAX_BRIEFING_LINES = 60MAX_CHANGE_ENTRIES = 20MAX_MESSAGE_PREVIEW = 5
Team artifacts are backed by the shared runtime SQLite store:
- team config rows
- per-member inbox message rows
- shared taskboard rows
Team-aware fields in ToolContext:
team_nameagent_nameis_team_lead
This drives tools such as send_team_message, read_inbox, and spawn_teammate.
Workspace detection prioritizes:
.quavil/.claude/.cursorrules.git
Primary rule file priority:
AGENTS.md.quavil/rules.md.quavil/instructions.mdCLAUDE.md.cursorrules
Additional local preferences:
QUAVIL.local.md.quavil/local.md
Modular rules under .quavil/rules/*.md can be unconditional or path-conditional (paths: frontmatter).
| Domain | Location |
|---|---|
| Runtime state | ~/.quavil/runtime/state.db |
| Sessions | sessions, session_messages, and session_message_parts tables in state.db |
| Work orders + routes | work_orders and work_order_routes tables in state.db |
| Gate / review / checkpoints | edit_artifacts_sql, review_verdicts, artifact_state_transitions, and checkpoints tables in state.db |
| Teams / delegation / missions | team, agent-run, worker-assignment, validation, and mission tables in state.db |
| Harness / bench | harness_* and benchmark_* tables in state.db |
| Autopilot state | autopilot_* tables in state.db |
| Auth | ~/.quavil/auth.sqlite3 |
| Memory | ~/.quavil/MEMORY.md plus project memory material under .quavil/ when enabled |
| Tool context offloads | <project>/.quavil/context/ |
- terminal-first UX with non-interactive parity
- strict safety boundaries (trust + sandbox + approvals)
- provider-agnostic runtime with explicit metadata
- transparent state via SQLite-backed runtime facts and replayable sessions
- composable agent model (main agent, subagents, teammate mesh)
Related internals:
docs/internals/subagent-lifecycle.mddocs/internals/workspace-rules.mddocs/internals/roles-and-briefing.md