Providers, Tool Plane & Scoping
This page covers how Hya talks to different LLM APIs (crates/hya-provider), loads and sandboxes tool paths (crates/hya-tool, crates/hya-tool-loader), and scopes bundles/plugins per Project (crates/hya-app).
1. Provider Routing & Stream Normalization (hya-provider)
Models vary wildly on the wire—OpenAI Chat Completions, OpenAI Responses (/responses), ChatGPT Codex OAuth, xAI Grok Build, Anthropic Messages, and Google Gemini each encode tool calls, reasoning blocks, prompt caching, and token counts differently.
hya-provider (R0) holds the Provider and Protocol traits, ProviderRouter, preflight, the one HTTP+SSE transport (HttpProvider), the bounded model-list discovery loop, and two providers: OpenAI-compatible Chat Completions (kind: openai) and the offline dev/fake providers. Every other wire is a provider kind a bundle registers through NativeRegistrations.providers (a ProviderKindEntry: the Protocol with its headers, compaction wire, and model-list adapter, plus an optional ProviderAuthFlow): hya/provider-anthropic, hya/provider-google, hya/provider-openai (Responses and Codex, sharing the hya-provider-openai-core wire with hya/provider-grok), and hya/provider-grok. hya_app::provider_kinds::load loads the enabled provider bundles once, before the providers resolve; the engine-time native load skips provider-only bundles. The router hides the wire differences:
- Shared HTTP transport: The first
HttpProviderrequest initializes the process-wide HTTP client and its TLS roots. Subsequent routes reuse the client and its connection pool. - One canonical event stream: Every upstream SSE stream decodes into the exact same
hya_proto::Eventsequence (StepStarted,ReasoningDelta,TextDelta,ToolCallRequested,UsageRecorded,MessageFinished). - Normalized token accounting: Across every vendor,
TokenUsage.inputexcludes cached tokens (prompt_total = input + cache_read + cache_write) andoutputincludesreasoning(thinking + visible + unknown == output). - Reasoning effort & model overrides:
HttpProvider::with_model_reasoning_defaultsinstalls per-model defaults frommodels.tomloverrides.Provider::reasoning_defaultandProvider::supports_reasoning_effortresolve metadata from the first match in the router. Non-Workflow model refs accept#variantsuffixes (stripped before upstream dispatch), whileWorkflowstage routes validate explicitreasoning:fields per candidate during admission. - Tool-result images: Images read by tools (
png,jpeg,gif,webp) are attached only on the round immediately following thereadcall (up to 2 MiB per round) and replaced by a compact text note on subsequent rounds so history size doesn’t explode.
2. Native Bundle Tools & Lockstep ABI (hya-tool, hya-tool-loader)
The core keeps the five standard tools (read, write, edit, bash, grep) plus todo, rewrite, and skill. The official default profile supplies the native bundles for the other tools.
- One load path:
hya-tool-loaderloads every native bundle the same way, first-party or installed (load_native_bundle): the library comes from beside the executable (load_v2) or from the installed package (load_v2_from_path), and its exported tools are registered from the bundle’s ownresources.toolsdescriptors (schema_version: 2): visibility, default permission posture (read_only,task,tool,command,mcp), aliases, prompt hint, view, protected, file-operations rule, andoverrides:. A tool registers under its own name; when two enabled bundles export one name, exactly one of them must declareoverrides:(hya/hashline’s file tools declareoverrides: hya/bare), or the load fails. No bundle id selects a branch. - Core tests load no first-party library: tests of
hya-core,hya-tool,hya-tool-loader, andhya-engineusestandard_registry(), in-test tools, or in-crate fixtures; a bundle’s behaviour is tested in its own crate or in Track P (see Testing). - Lockstep ABI guard:
hya-tool-loaderverifies a 32-byte ABI digest (abi_digest_v2across all seventeen first-party native ABI v2 bundles:hya/hashline,hya/coding-extras,hya/multi-agent,hya/network,hya/agent-channels,hya/compaction,hya/plan,hya/goal,hya/loop,hya/workflow,hya/workspace-files,hya/session-title,hya/direct-shell,hya/provider-anthropic,hya/provider-google,hya/provider-openai, andhya/provider-grok) before calling registration, preventing mismatched.so/.dyliblibraries from ever loading. - Slim single-agent
ToolCtx(hya_tool::ToolCtx): Tool execution receives only core single-agent planes (workdir,roots,cancel,session,operation,permission,interaction,skills,artifacts,schemas: UriSchemaPlane,nested) plusextensions: ExtensionPlanes(a type-indexed container for optional planes such as the caller’s spawn rosterArc<[AgentDef]>andParentSession).project_activityis ahya/coding-extrastool that reads the kernel’sHostSessionStore::project_changes; the core has no project-activity plane. Corehya-bareruns with an emptyExtensionPlanesand zero domain fields onToolCtx. - LSP and formatting belong to
hya/coding-extras: the bundle builds its LSP and formatter planes from its ownconfig.tomland keeps them as private state for itslspandapply_patchtools, itstool.execute.afterpost-edit hook, and itsGET /lsp/symbolsBundleApi; the core neither constructs nor injects them. The engine takes a tool call’s file capture (stamps and revert snapshot) after thetool.execute.afterchain, so a file a hook rewrote (formatted) is recorded as that call’s own change, not as an external one. - Output caps: Every tool output passes through host envelope bounds (50 KiB coding text caps, 5,000-char default plugin/bundle caps with automatic spill to
.hya/tool-output/orartifact://) so one noisy command can never blow out a model’s context window.
3. Multi-Root ProjectScope & PermissionPlane
File tools (read, write, edit, ls, glob, find, grep, apply_patch, lsp) enforce workspace containment through hya_tool::ProjectScope:
- Every target path—and its nearest existing ancestor for not-yet-created files—is canonicalized on disk resolving all symlinks. A symlink inside your repo pointing to
/etc/passwdresolves to/etc/passwd(outside!). - If the canonical path sits inside any ordered root of the session’s Project, no outside-directory prompt is needed.
- Otherwise,
ProjectScoperaises anExternalDirectorypermission check for<canonical-parent-dir>/*before running the tool’s normal read/edit check. Saving Always allow scopes that grant strictly to the activeproject_id.
4. Lazy Per-Project CatalogScope (hya-app & hya-engine)
Because one persistent daemon serves many Projects on your machine, Hya never loads .hya/ folders from the directory hya server happened to start in.
Instead, RuntimeRegistry maintains an LRU + idle-TTL cache (catalog_scopes: { max: 32, idle_ttl_secs: 1800 }) keyed by CatalogScope:
Global: Built-in presets + user-installed bundles + globalconfig.tomlMCP/plugins + user skills/commands.Directory(path): Adds disk skills/commands/AGENTS.mdfor an unregistered folder (never spawns untrusted project processes).Project { id, roots }: Layers<root>/.hya/bundlesand<root>/.hya/pluginsacross all roots of the registered Project (first root wins on ID collisions) on top of the user and built-in tiers. When a Project sits idle pastidle_ttl_secswith no active turns, its project-scoped sidecar processes are cleanly stopped and reclaimed.