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§
- Allow
All - The default approver: allows everything, instantly — headless consumers
(
locode-exec, evals) are byte-for-byte unchanged in behavior. - Anthropic
Provider - The live Anthropic Messages
Provider(non-streaming). - Approval
Request - The pre-dispatch view of one tool call — what the studied UIs render their permission prompts from (request args, not host-resolved detail).
- Built
Provider - A constructed provider plus the model name it resolved (for the report envelope and engine config).
- Cancellation
Token - A token which can be used to signal a cancellation request to one or more tasks.
- 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).
- Discovered
Skills - What discovery produced.
- 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. - GitMeta
- Git provenance for the header (grok
summary.json’s git fields). - 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. - Instruction
Entry - One discovered instruction file: where it came from, and its contents.
- Instructions
Config - How project-instruction discovery behaves. All fields have defaults; a caller (the CLI today, a settings layer later) overrides them.
- 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.
- Project
Instructions - Discovered project instructions: ordered entries, lowest-precedence first, so a later (deeper) entry wins on conflict. Neutral — the engine owns rendering/injection.
- 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). - Rollout
Contents - A parsed rollout: the header plus the replayable message history.
- Sampling
Args - Provider-neutral sampling knobs — the common core only.
- Session
- One driven agent session. Owns the conversation history across runs: a
second
Session::runon the same session continues the same conversation (ADR-0016) — the exact call shape an interactive frontend needs for follow-up turns. - Settings
- The typed view of the merged settings (v1 fields, ADR-0024 §1.4). Unknown keys
are tolerated at every layer; absent keys are
None/empty. - Settings
Load - The loader result: the merged settings plus human-readable warnings the caller surfaces on stderr (this crate never prints).
- Skill
- One discovered skill.
- Skills
Config - Inputs for
discover— all of it derived from resolved settings, which is what makes the load order an invariant (ADR-0025 §6.1). - 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.
- Trace
Extras - Construction-time inputs the
Event::Initevent doesn’t carry. - Trace
Writer - The rollout writer: feed it every engine
Event; it materializes the file onInit(header + preamblemessagelines) and appends onemessageline per appendedMessage. All other event types are ignored — deltas are display-only and the report already has its own artifact (ADR-0014). - 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.
- Decision
- The approval vocabulary — deliberately minimal (ADR-0017 Option V1): stickiness and richer choices live in approver implementations.
- Developer
Rendering - How
Role::Developermessages are rendered on the wire (plan §4.1). - Effort
- One rung of the locode effort ladder.
- 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
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).
- Skill
Scope - Where a skill came from — and, on a collision, how it is addressed.
- Skills
Extra Entry - One validated
skills.extraentry (ADR-0024 §1.4). - 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§
- Approver
- Decides whether one tool call may run. Consulted by the engine per call, serially, before dispatch; the await suspends only this call.
- 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. - decode_
cwd_ dirname - Decode a session-directory name back to the cwd it encodes, or
Nonefor a hash-fallback name (recover via the.cwdsidecar) or a malformed escape. - discover_
skills - Discover every skill visible from
cwd. - encode_
cwd_ dirname - Encode a (canonicalized, absolute)
cwdinto its session-directory name. - find_
latest_ rollout - The newest resumable rollout for
cwd(--continue): list the one encoded directory, take rollouts newest-first by filename (the timestamp prefix sorts chronologically), and return the first whose header parses withkind == "main"— unknown kinds are not listed (§2.4 rule 3), but remain reachable by id. - find_
rollout_ by_ id - Locate a rollout by session id (
--resume <id>): the cwd’s directory first, then every other session directory (Claude’s scoped-then-global resolver). Anykindis resumable by id. - load_
project_ instructions - Discover project instructions for
cwdundercfg. - load_
settings - Load and merge the five layers for
cwd.flagis the raw--settingsvalue (a path, or inline JSON when it starts with{). - locode_
home - The resolved home, memoized for the process (env is read once).
- read_
rollout - Read a rollout tolerantly (ADR-0024 §2.4 rules 1-2): unknown record
types and unknown payload fields are skipped/ignored; an unparsable line
(the torn tail) is skipped; a
compactedrecord replaces all prior messages with itsreplacement_history. - 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. - update_
user_ setting - Write
key = valueinto the user settings file, preserving every other key.
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.