anvil · reference

Architecture & core types

Where everything lives and what each piece is responsible for. Names and responsibilities only, with no implementations, so you still write the code. ← course ·

Revised contracts. Native filesystem tools enforce FileAccess grants; plan mode caps mutation authority; project executable config is trusted separately; every session mutation has a reducer record; unfinished side effects recover as unknown; required verifiers and eval graders are independent evidence. Provider switching is conditional on supported replay. See the matching course boundary exercises for the build contract.

Crate map & dependency rule

llm: types

TypeResponsibilityCh
RoleUser · Assistant01
ContentBlockText · Image · Reasoning · ToolCall · ToolResult01
ProviderMetaopaque {provider, data}, replayed only to its own provider01
Message, ToolSpec, ChatRequestcanonical conversation + request01
validate_transcriptmachine-checked integrity01
StreamEvent, Usage, FinishReasonnormalized stream vocabulary02
LlmErrorHttp · Transport · Api · Decode · UnexpectedEof · Config, with is_retryable02
Provider traitname(), stream(&ChatRequest) → Result<EventStream>02
SseDecodersans-IO bytes → SSE events02
MessageBuilder, Completionevents → Message + Usage + Finish03
Registry, Retryalias → provider · backoff decorator06
ScriptedProviderdeterministic test double08

agent: types

TypeResponsibilityCh
Tool / TypedToolruntime contract / typed convenience07
ToolRegistrysorted specs, never-failing dispatch, truncation07
Agent, AgentEvent, TurnOutcomethe loop, its event stream, why a turn ended08
FileTrackerread-before-write freshness10
Policy, Decision, Approverrules + modes → allow/ask/deny → human11
SandboxPolicyOS-enforced limits for subprocesses12
PromptBuilder, ContextBudgetlayered prompt · token accounting13
SessionWriter, Recordappend-only JSONL, resume14
McpToolremote tool as a Tool15
HookRunner, skills loadersensors & guides from config16
TaskTool, todo toolsubagents · planning17
SessionMeter, Pricingcost & budgets18
Checkpointsshadow-git snapshots, /undo20

One step of a turn (data flow)

Invariants (put these in tests)

  1. validate_transcript holds after every step, interruption, compaction and resume.
  2. No provider-specific type appears outside crates/llm.
  3. dispatch never returns Err. Every failure is an is_error result.
  4. Tool specs and system prompt are byte-identical while the context revision is unchanged (cache stability).
  5. Nothing is printed to stdout except the answer (headless) or rendered events (interactive).
  6. Deny rules win in every permission mode. Bash always runs through the sandbox unless the user explicitly approved escalation.
  7. No subprocess inherits API keys. No transcript contains known secret values.