Skip to content

API Reference

This page documents the public APIs of cuenv’s Rust crates. For schema definitions, see Configuration Schema.

The CUE evaluation engine crate provides the interface to evaluate CUE configurations through the Go FFI bridge.

Builder for configuring a CueEvaluator. The usual entry point is CueEvaluator::builder(), which returns this type.

use cuengine::{CueEvaluator, RetryConfig};
use cuenv_core::manifest::Cuenv;
use std::{path::Path, time::Duration};
let evaluator = CueEvaluator::builder()
.max_output_size(10 * 1024 * 1024)
.retry_config(RetryConfig {
max_attempts: 5,
initial_delay: Duration::from_millis(50),
max_delay: Duration::from_secs(2),
exponential_base: 1.5,
})
.build()?;
let manifest: Cuenv = evaluator.evaluate_typed(Path::new("./project"), "cuenv")?;

Builder methods:

MethodDescription
new() / CueEvaluator::builder()Create a builder with default limits, retry config, and cache size
max_path_length(len)Clamp the maximum accepted path length for evaluated directories
max_package_name_length(len)Limit the package name length validated before evaluation
max_output_size(bytes)Bound the JSON payload size returned from the bridge
retry_config(RetryConfig)Customize retry behavior (see below)
no_retry()Disable retries entirely
cache_capacity(entries)Configure the in-memory evaluation cache (set to 0 to disable)
cache_ttl(duration)Set the TTL for cached evaluation results
build()Create a CueEvaluator

The main type for evaluating CUE packages.

use std::path::Path;
let evaluator = CueEvaluator::builder().no_retry().build()?;
let json = evaluator.evaluate(Path::new("./project"), "cuenv")?;

Key methods:

MethodDescription
builder()Returns a CueEvaluatorBuilder
evaluate(&self, dir: &Path, package: &str)Evaluates the package and returns the raw JSON string from CUE
evaluate_typed<T>(&self, dir: &Path, package: &str)Evaluates the package and deserializes it into T
clear_cache()Drops any cached evaluation results held by this evaluator

The crate also exposes free functions when you don’t need a cached evaluator:

use cuengine::{evaluate_cue_package, evaluate_cue_package_typed};
use cuenv_core::manifest::Cuenv;
use std::path::Path;
let json = evaluate_cue_package(Path::new("./project"), "cuenv")?;
let manifest: Cuenv = evaluate_cue_package_typed(Path::new("./project"), "cuenv")?;

Fetches the Go bridge version string for diagnostics:

let version = cuengine::get_bridge_version()?;
println!("bridge reports {version}");

Configuration for retry behavior on transient failures.

use cuengine::RetryConfig;
use std::time::Duration;
let config = RetryConfig {
max_attempts: 4,
initial_delay: Duration::from_millis(100),
max_delay: Duration::from_secs(5),
exponential_base: 2.0,
};

Fields:

FieldTypeDefaultDescription
max_attemptsu323Maximum retry attempts
initial_delayDuration100 msDelay before the first retry
max_delayDuration10 sUpper bound for the backoff delay
exponential_basef322.0Multiplier applied to each successive delay

Core library with types for tasks, environments, hooks, and secrets.

The root configuration type parsed from CUE.

use cuenv_core::manifest::Cuenv;
let manifest: Cuenv = evaluator.evaluate()?;

Fields:

FieldTypeDescription
configOption<Config>Global configuration
envOption<Env>Environment variables
hooksOption<Hooks>Shell hooks
tasksHashMap<String, Tasks>Task definitions
workspacesOption<Workspaces>Workspace configuration

Represents a single executable command pulled from CUE.

use cuenv_core::tasks::Task;
use serde_json::json;
use std::collections::HashMap;
let mut env = HashMap::new();
env.insert("RUST_LOG".into(), json!("info"));
let build = Task {
command: "cargo".into(),
args: vec!["build".into(), "--release".into()],
shell: None,
env,
depends_on: vec!["lint".into(), "test".into()],
inputs: vec!["src".into(), "Cargo.toml".into()],
outputs: vec!["target/release/app".into()],
inputs_from: None,
external_inputs: None,
workspaces: vec![],
description: Some("Build release binaries".into()),
};

Fields:

FieldTypeDescription
commandStringExecutable to run
argsVec<String>Arguments for the command
shellOption<Shell>Override shell invocation (defaults to direct exec)
envHashMap<String, serde_json::Value>Task-specific environment additions
depends_onVec<String>Other tasks that must finish first
inputsVec<String>Files/globs tracked for hermetic execution
outputsVec<String>Declared outputs that become cacheable artifacts
inputs_fromOption<Vec<TaskOutput>>Consume outputs from other tasks in the same project
external_inputsOption<Vec<ExternalInput>>Consume outputs from another project in the repo
workspacesVec<String>Workspace names to enable (see schema)
descriptionOption<String>Human-friendly summary
use cuenv_core::tasks::{TaskDefinition, TaskGroup};
let test_task = build.clone(); // assume another Task definition exists
let group = TaskDefinition::Group(TaskGroup::Sequential(vec![
TaskDefinition::Single(Box::new(build.clone())),
TaskDefinition::Single(Box::new(test_task)),
]));
  • TaskDefinition::Single(Task) represents one command.
  • TaskDefinition::Group(TaskGroup) represents sequential (Vec<TaskDefinition>) or parallel (HashMap<String, TaskDefinition>) sub-tasks.

Tasks is the top-level map of task names to their definitions (flattened when parsed from CUE).

use cuenv_core::tasks::{TaskDefinition, Tasks};
let mut tasks = Tasks::new();
tasks.tasks.insert("build".into(), TaskDefinition::Single(Box::new(build)));

Environment variable definitions.

use cuenv_core::environment::Env;

Environment values can be:

  • Simple values (strings, numbers, booleans)
  • Structured values with policies
  • Secret references

Shell hook definitions.

use cuenv_core::hooks::{Hooks, ExecHook};

Fields:

FieldTypeDescription
on_enterOption<Vec<ExecHook>>Hooks to run on directory entry
on_exitOption<Vec<ExecHook>>Hooks to run on directory exit

A single hook execution.

Fields:

FieldTypeDefaultDescription
commandStringrequiredCommand to execute
argsVec<String>[]Command arguments
orderi320Execution order (lower = earlier)
propagateboolfalseExport to child processes
sourceboolfalseSource output as shell script
inputsVec<String>[]Input files for cache tracking

Secret reference with exec-based resolution.

use cuenv_core::secrets::Secret;

Fields:

FieldTypeDescription
resolverStringResolver type (always “exec”)
commandStringCommand to retrieve secret
argsVec<String>Command arguments

Access control policy for secrets.

use cuenv_core::secrets::Policy;

Fields:

FieldTypeDescription
allow_tasksVec<String>Tasks that can access
allow_execVec<String>Exec commands that can access

Shell integration types.

Supported shell types.

use cuenv_core::shell::Shell;
match shell {
Shell::Bash => { /* Bash shell */ }
Shell::Zsh => { /* Zsh shell */ }
Shell::Fish => { /* Fish shell */ }
Shell::PowerShell => { /* PowerShell */ }
}
assert!(Shell::Bash.is_supported());
assert!(!Shell::PowerShell.is_supported());

The main error type with diagnostic information.

use cuenv_core::Error;

Variants:

VariantDescription
ConfigurationConfiguration parsing/validation error
FfiFFI operation failure
CueParseCUE parsing error
IoI/O operation failure
TaskTask execution error
SecretSecret resolution error
ShellShell integration error

All errors implement miette::Diagnostic for rich error reporting:

use miette::Result;
fn run() -> Result<()> {
let evaluator = CueEvaluatorBuilder::new()
.directory(".")
.package("cuenv")
.build()?;
let manifest = evaluator.evaluate()?;
Ok(())
}

Validated directory path.

use cuenv_core::PackageDir;
use std::path::Path;
let pkg_dir = PackageDir::try_from(Path::new("./project"))?;

Validated CUE package name.

use cuenv_core::PackageName;
let pkg_name = PackageName::try_from("cuenv")?;

The task cache utilities live under cuenv_core::cache::tasks.

use cuenv_core::cache::tasks::{
compute_cache_key, lookup, materialize_outputs, CacheKeyEnvelope,
};
use std::{collections::BTreeMap, path::Path};
let envelope = CacheKeyEnvelope {
inputs: BTreeMap::new(),
command: "cargo".into(),
args: vec!["build".into()],
shell: None,
env: BTreeMap::new(),
cuenv_version: cuenv_core::VERSION.to_string(),
platform: format!("{}-{}", std::env::consts::OS, std::env::consts::ARCH),
workspace_lockfile_hashes: None,
workspace_package_hashes: None,
};
let (key, _) = compute_cache_key(&envelope)?;
if let Some(entry) = lookup(&key, None) {
println!("cache hit stored at {}", entry.path.display());
materialize_outputs(&key, Path::new("artifacts"), None)?;
}

Additional helpers such as save_result, record_latest, and lookup_latest are available when integrating custom executors with cuenv’s cache layout.

The cuenv CLI uses structured exit codes:

CodeNameDescription
0SuccessCommand completed successfully
2ConfigErrorCLI/configuration error (CliError::Config)
3EvalErrorEvaluation, task, or other runtime error (CliError::Eval / CliError::Other)