Expand description
locode — the facade crate: the public surface for consumers (the future
locode-app, and locode-exec as the reference consumer).
Two curated surfaces (Task 14, SPEC Users #3/#4):
- The driving API — assemble and run one session:
Session+EngineConfig, harness selection (resolve/available+PackContext), the providers (AnthropicProvider/MockProvider), the host (Host/HostConfig/PathPolicy), and the report/event types (Report/Status/Event/Usage). - The tool surface — use our typed tools in your own loop:
Tool,Registry(+ theRegistry::dispatchdoor),ToolCtx,ToolOutput,ToolSpec, and the packs’ concrete tool sets viaPack::build_registry.
Downstream code should depend on this crate, not the locode-* internals —
the internals may churn; this surface is the stable contract.
Modules§
- grok
- The
grokpack — a faithful port of Grok Build’sxai-grok-toolstoolset, trimmed to headless-minimal (ADR-0012), overlocode-host. Task 13 renders its real system prompt; all five grok tools are wired here.
Structs§
- Anthropic
Provider - The live Anthropic Messages
Provider(non-streaming). - Built
Provider - A constructed provider plus the model name it resolved (for the report envelope and engine config).
- Completion
- One normalized completion: the parsed result of a single model call (ADR-0007).
- Conversation
- A full conversation: one uniform stream of role-tagged messages (ADR-0013).
- Conversation
Request - One provider-neutral sampling request (ADR-0007).
- Dispatched
- The outcome of one
Registry::dispatch: both the history and report views, plus a fatal signal. - Engine
Config - Everything the loop needs that isn’t the provider, registry, preamble, or sink.
- Exec
Limits - Limits on shell execution. Defaults mirror Grok Build (the primary model).
- FnSink
- Forwards each event to a closure — e.g. a JSONL stdout writer for
stream-json, or aVec-pushing closure in tests. - Grok
Pack - The grok harness pack (a zero-sized
&'staticsingleton). - Host
- The injectable side-effect seam (ADR-0008). Construct once per session, share behind
an
Arc; holds the jail root + policy and the exec/truncation limits. - Host
Config - Construction-time configuration for a
Host. - Message
- One message: a role plus an ordered list of content blocks.
- Mock
Provider - A provider that replays a fixed script of results, one per
complete()call. - Model
Config - The per-model wire configuration record (ADR-0007 + plan §3.1/§9).
- Null
Sink - Drops every event — for the
json/textoutput modes that only want the report. - Open
AiModel Config - The per-model config record for the OpenAI wire family (plan §3.2 + §A.5).
- Open
AiResponses Provider - The live OpenAI Responses
Provider(non-streaming, stateless). - Pack
Context - Dynamic, per-run context a pack’s preamble is rendered against.
- Provider
Build Error - A provider construction failure (missing env, bad config, unknown name): pre-run by nature — surfaced before any session starts.
- Provider
Init - Per-run inputs a factory may use when constructing its provider.
- Provider
Registry - The
--api-schemaname space: ordered name → factory entries. - Registry
- A set of tools keyed by their model-facing wire names, plus the one
dispatchdoor every call funnels through (ADR-0008). - Report
- The single JSON document
locode-execprints to stdout (ADR-0009). - Retry
Policy - Transport-retry knobs (Task-12 plan §3.6; sources: Claude Code 500ms·2ⁿ cap
32s, grok’s 429-cap-2 and 120s
Retry-Aftercap, codex’s ±10% jitter). - Sampling
Args - Provider-neutral sampling knobs — the common core only.
- Session
- One driven agent session. Owns the conversation history for the run (ephemeral).
- Tool
Call Record - A report-side record of one tool call (distinct from the in-conversation
ContentBlock::ToolUse): the structuredoutputview, not the model-facing text. - ToolCtx
- The context handed to a tool for one call.
- Tool
Spec - A provider-neutral tool spec: name + description + args JSON Schema.
- Unknown
Harness - An unknown
--harnessselector — a caller/config error (soft, never a panic). - Usage
- Token accounting parsed from the provider’s terminal usage event.
Enums§
- ApiBackend
- Which endpoint family the wire talks to — selects auth header + quirks.
- Auth
Scheme - The resolved credential and how to present it.
- Cache
Hint - Where the wire should place prompt-cache breakpoints (ADR-0007).
- Content
Block - A typed piece of message content, modeled on Anthropic’s content blocks.
- Developer
Rendering - How
Role::Developermessages are rendered on the wire (plan §4.1). - Event
- One event in the
stream-jsontrajectory (one JSON object per line). - Grammar
Syntax - The grammar language of a
ToolInputFormat::Freeformtool. - Image
Source - The source of an image block.
- Open
AiBackend - Endpoint family — quirks only; auth is always Bearer here.
- Path
Policy - Whether the filesystem tools are jailed to the workspace root (ADR-0008 amendment).
- Provider
Error - Why a model call failed (ADR-0007).
- Reasoning
Effort - A neutral reasoning-effort level, mapped per-wire (ADR-0007).
- Reasoning
Encoding - How
reasoning_effortis encoded on the wire (plan §4.4). - Reasoning
Format - The encoding/replay contract of a
ContentBlock::Reasoningblock. - Result
Chunk - A single chunk of a tool result (a restricted set of block kinds).
- Role
- The author of a message (ADR-0013).
- Status
- The terminal state of a run. Serializes to the exact strings in ADR-0009.
- Stop
Reason - Why the model stopped generating (Anthropic-shaped, provider-neutral).
- System
Placement - Where the hoisted System prompt is placed on the Responses wire.
- Tool
Error - How a tool call failed, split into exactly two recovery paths (ADR-0004).
- Tool
Input Format - How a tool’s input is specified: a JSON-schema function tool, or a freeform
tool whose raw-text input is constrained by a server-side grammar (OpenAI
Responses
customtools — codex’sapply_patch). Exactly one of the two — an enum, not optional fields, so invalid states are unrepresentable. - Tool
Kind - A canonical classification tag for a tool, used only to align comparable tools across harness packs for A/B analysis (ADR-0003) — it is not the wire name (that is assigned per-pack at registration) and not the Rust type name.
Constants§
- MODEL_
OUTPUT_ BUDGET - Default model-facing byte budget. Matches Grok’s shell output cap.
Traits§
- Auth
Refresh - Re-resolve the credential after a 401/403 (plan §4.5).
- DynTool
- The object-safe, type-erased tool the registry stores.
- Event
Sink - A sink for the loop’s
Events.&mut selfso a writer sink can buffer/flush; object-safe solocode-execcan pick one at runtime by--output-format. - Pack
- A faithful reproduction of one harness: its real toolset + its base prompt, selected
whole via
--harness(ADR-0012). One pack is active per run. - Provider
- A model-sampling wire: builds a request, calls the model, normalizes the response.
- Tool
- A tool authored against concrete types; the wire schema is derived from
Tool::Args, never hand-written (ADR-0003). - Tool
Output - The model-facing rendering of a tool’s output.
Functions§
- available
- The registered
--harnessnames, in stable order. - reconstruct_
conversation - Reconstruct the full
Conversationfrom astream-jsonevent trajectory. - resolve
- Resolve a
--harness <name>to its pack. - truncate_
for_ model - Bound
textto roughlybudgetbytes for model consumption, keeping the head and tail and eliding the middle (middle-truncation, Codex-style) with a byte-count marker in the seam.
Type Aliases§
- Provider
Factory - A named provider constructor: env/config resolution belongs inside the factory so selection stays lazy — only the chosen wire pays its setup.