Rust runtime API
Configuration, public entry points, and return values for the huggler crate.
The crate uses Rust 1.94.1 and edition 2024. Build the full Rust API reference from the checkout with cargo doc --locked --all-features --no-deps --open.
Runtime options
let options = HugglerOptions::default().with_name("Studio Workbench")?;
let huggler = Huggler::open(options).await?;with_name sets the display name and derives a slug by lowercasing ASCII letters and joining words with hyphens. Use with_name_and_slug("Studio / Lab", "studio_lab") to set the slug explicitly. The slug is the provider and MCP identifier and supplies the default directory ~/.<slug>. It accepts 1–128 ASCII letters, digits, underscores, or hyphens. The default options store the database in userdata/huggler.sqlite3 and managed checkouts in worktrees/{id} under that directory.
Use HugglerOptions::new(state_dir) to choose a state directory with huggler.sqlite3 at its root. Add .with_name("Studio Workbench")? to set the display name and identifier for that directory. To use userdata/huggler.sqlite3 under a custom directory, set storage.database_path to that relative path.
HugglerOptions field | Default and purpose |
|---|---|
state_dir | Base directory for relative storage paths. |
storage | Override the database path, worktree root, or worktree directory name. |
codex, claude_agent | Built-in instance executable configuration. Codex approval requests are opt-in. |
instances | Empty. Adds named ProviderInstance configurations to the built-ins. |
agent_tools | false. Starts the loopback MCP endpoint when enabled. |
agent_policy | Default policy. Controls the built-in tool allowlist, deferred tool discovery, and opt-in secret requests. |
output | Overrides how Huggler and its tools appear to providers, MCP clients, and agents. Set these overrides after setting the name and slug. |
auto_resume_usage_limits | false. Allows one eligible continuation after a provider-reported Codex quota reset. A newer message or stop can cancel it. |
prompt_suggestions | false. Enables extra Codex sampling for an eligible follow-up, exposed as Run.prompt_suggestion. |
Use WorktreeRoot::Shared for an absolute directory or one relative to state_dir. Use WorktreeRoot::ProjectRelative for a directory relative to each registered project. The worktree_name is a single path component containing the literal placeholder {id}. Huggler replaces it with a generated identifier, which includes a branch-derived name for workspaces created with allocate_workspace_on_branch.
let mut options = HugglerOptions::new(state_dir).with_name("Studio Workbench")?;
options.storage.database_path = "sessions/history.db".into();
options.storage.worktree_root = WorktreeRoot::ProjectRelative(".myapp/worktrees".into());
options.storage.worktree_name = "checkout-{id}".into();This places the database and its owner lock, history.db.runtime.lock, under state_dir/sessions/. It creates new checkouts under .myapp/worktrees/ in the registered project. Ignore that directory in Git if it should stay out of checkpoint diffs. Existing reservations keep their recorded checkout paths.
Read and control
| API | Return or effect |
|---|---|
Huggler::open(options).await | Opens the state database, establishes ownership and recovers persisted records. Call from a running Tokio runtime. |
open_project(path) | Registers or resolves the Git working tree and returns its canonical root and project ID. |
launch, send, dispatch | Commit a command and return a Receipt. The optional run ID identifies the run affected by the action. |
threads, wait_for_threads_after | List thread summaries or wait for new thread entries after a position. |
read, detail, read_message | Return a full state snapshot, a bounded conversation page, or a single full message. |
subscribe, wait_for_change | Read events after a thread cursor, or wait for a later cursor. |
wait | Returns the specified terminal run, including a failed or interrupted run. |
command_items, command_output | Read Codex command item IDs and bounded output tails. |
retain_events | Prunes old event records for the thread. Existing replay cursors can expire. |
delete_thread | With the application feature, removes an idle thread and its local history. |
close().await | Waits for managed workers to shut down and releases database ownership. |
RunStatus::terminal() covers Completed, Failed, and Interrupted. In a Receipt, message_id and run_id are optional. event_sequences lists the event positions committed by the command. In a Thread, use provider_instance and worktree_path to identify where subsequent work runs.
Customize provider and agent presentation
Override options.output only when you need to customize what providers and agents see.
nameis the stable provider client identifier and MCP registration key. Change it to match an existing registration. Providers can store permissions under this key.titleis the display name in supported provider metadata, approval prompts, and generated conversation text.versionis advertised in provider and MCP handshakes. It defaults to the Huggler crate version. Set it to your app version if you want providers to see that version.instructionsadds an optional message to MCP initialization.provider_labelsmaps instance IDs to display labels.toolsoverrides the advertised names, titles, and descriptions of built-in tools. Policies use the original built-in keys.
The MCP server name and advertised tool names accept 1–128 ASCII letters, digits, underscores, or hyphens. Give each advertised tool a unique name. Resolve a provider display label with runtime.output().provider_label(id), which falls back to the instance ID.
Implement AgentText to change the host-generated text for history, attachments, peer messages, and other prompts or diagnostics. Store the implementation in an Arc and assign it to options.output.text. Callbacks are synchronous and can run inside a database transaction. Keep them fast and avoid callbacks into the runtime.