Skip to content

Rust API

The core of hlock is a Rust library, published on crates.io as hlock. Two other crates expose the same API:

Crate Use it when
hlock The default: hlock::Manifest, hlock::Resolver, …
harness-lock An alias for hlock, under harness_lock::…
harness-lock-core You depend on the implementation crate directly
cargo add hlock

The full API documentation, generated from the source, is on docs.rs: docs.rs/hlock (which re-exports docs.rs/harness-lock-core).

Example

Resolve a lock, check it against the manifest, and read the pinned stack and its evidence. This is the same flow as hlock resolve, hlock check, and hlock show.

src/main.rs
use std::path::Path;

use hlock::{Lockfile, Manifest, Resolver};

fn main() -> hlock::Result<()> {
    // Resolve: load the manifest and search it. `resolve()` also writes ./harness.lock.
    let manifest = Manifest::load(Path::new("harness.toml"))?;
    let live_hash = manifest.manifest_hash();
    let lock = Resolver::new(manifest, ".hlock").resolve()?;
    println!("{}", lock.summary());

    // Check: an empty list means the lock matches the manifest.
    let lock = Lockfile::load(Path::new("harness.lock"))?;
    let drift = lock.check_manifest(&live_hash);
    assert!(drift.is_empty(), "drift: {drift:?}");

    // Inspect the pinned stack and its evidence.
    for llm in &lock.llm {
        println!("{} -> {}:{}", llm.role, llm.provider, llm.model);
    }
    let success = lock.evidence.success_rate.get("mean");
    println!("success rate {success:?} over {} trials", lock.evidence.trials);
    Ok(())
}
$ cargo run
stack="demo" harness=reference llm=qwen-7b decision=none success-rate=1.00 trials=2
planner -> reference:qwen-7b
success rate Some(1.0) over 2 trials

Key types

Item What it is
Manifest A parsed harness.toml: load, from_str, manifest_hash, eval_packs, backend_target
Resolver The resolver: new, with_backend, with_executor, enumerate_stacks, run_trial, resolve
Lockfile The harness.lock model: load, from_str, save, check_manifest, summary, and public fields for every section
Backend A backend resolved from its name: Backend::resolve(&manifest, Some("local")), Backend::offline()
worker::Executor The trait a backend implements: describe and call. worker::serve makes an executable out of one; see Write your own backend
Store The content-addressed artifact store under .hlock/
HarnessAdapter The trait a harness implements to run trials
Error, Result The error type, with one variant per kind (Manifest, Lockfile, EvalPack, Tuning, …)
LOCK_VERSION, LOCKFILE_PATH, MANIFEST_PATH Schema version 1, "harness.lock", "harness.toml"

Modules

Module Contents
manifest Manifest schema: candidates, objective, budget
lockfile Lockfile schema: stack, policy, evidence, provenance
resolver The resolver: trial execution and lock construction
search Stacks, trial results, Pareto fronts, winner selection
tasks Eval packs, the search/holdout split, grading
ops upgrade and tune, the engines behind those commands
meta The meta harness: choose, configure, pin, check, job render/prepare/verify
worker Backends: resolving them by name, the versioned JSON contract (TaskRequest, TaskResult, Describe), Executor, ProcessExecutor, and serve
providers The deterministic reference LLM provider
store, hash Content addressing and hashing

The flyte module is behind the flyte cargo feature and is provisional.

Python users

The Python API is built on this crate through PyO3, so the two behave the same. Most users only need the Python package and the CLI.