Skip to main content

harn_cli/cli/
eval.rs

1//! Clap definitions for `harn eval` and its subcommands.
2//!
3//! The bare form `harn eval <path>` evaluates a run record, run directory,
4//! eval manifest, or `.harn` pipeline (legacy entrypoint, dispatched through
5//! `eval_run_record`). The `harn eval prompt <file> --fleet <models>`
6//! subcommand renders (and optionally runs / judges) a single
7//! `.harn.prompt` template against a fleet of models so authors can compare
8//! the wire envelope each capability profile materializes.
9
10use std::path::PathBuf;
11
12use clap::{Args, Subcommand, ValueEnum};
13
14#[derive(Debug, Args)]
15#[command(args_conflicts_with_subcommands = true)]
16pub struct EvalArgs {
17    /// Run record path, run directory, eval manifest path, or `.harn` pipeline.
18    /// Required unless a subcommand (e.g. `prompt`) is used.
19    pub path: Option<String>,
20    /// Optional baseline run record for diffing.
21    #[arg(long)]
22    pub compare: Option<String>,
23    /// Run a pipeline twice and compare the baseline against this structural experiment.
24    #[arg(long = "structural-experiment")]
25    pub structural_experiment: Option<String>,
26    /// Replay LLM responses from a JSONL fixture file when `path` is a `.harn` pipeline.
27    #[arg(
28        long = "llm-mock",
29        value_name = "PATH",
30        conflicts_with = "llm_mock_record"
31    )]
32    pub llm_mock: Option<String>,
33    /// Record executed LLM responses into a JSONL fixture file when `path` is a `.harn` pipeline.
34    #[arg(
35        long = "llm-mock-record",
36        value_name = "PATH",
37        conflicts_with = "llm_mock"
38    )]
39    pub llm_mock_record: Option<String>,
40    /// Positional arguments forwarded to `harn run <pipeline.harn> -- ...` when
41    /// `path` is a pipeline file and `--structural-experiment` is set.
42    #[arg(last = true)]
43    pub argv: Vec<String>,
44    #[command(subcommand)]
45    pub command: Option<EvalCommand>,
46}
47
48#[derive(Debug, Subcommand)]
49pub enum EvalCommand {
50    /// Benchmark coding-agent fixtures across providers and tool formats.
51    CodingAgent(EvalCodingAgentArgs),
52    /// Run deterministic context-engineering modes over task fixtures.
53    Context(EvalContextArgs),
54    /// Render and optionally run a `.harn.prompt` across a fleet of models.
55    Prompt(EvalPromptArgs),
56    /// Run tool-call accuracy, latency, and cost evals over a dataset.
57    ToolCalls(EvalToolCallsArgs),
58}
59
60#[derive(Debug, Args)]
61pub struct EvalContextArgs {
62    /// Context eval manifest JSON or TOML.
63    pub manifest: PathBuf,
64    /// Output directory for summary.json, per_run.jsonl, and summary.md.
65    #[arg(long)]
66    pub output: Option<PathBuf>,
67    /// Print the aggregate summary JSON to stdout.
68    #[arg(long)]
69    pub json: bool,
70}
71
72#[derive(Debug, Args)]
73pub struct EvalCodingAgentArgs {
74    /// Fixture ids to run (comma-separated, repeatable). Use `all` for the full suite.
75    #[arg(long = "fixture", value_delimiter = ',', default_value = "all")]
76    pub fixtures: Vec<String>,
77    /// Model selectors to run (comma-separated, repeatable). Each entry may be
78    /// an alias, `provider:model`, or `provider=...,model=...`.
79    #[arg(long = "model", value_delimiter = ',', default_value = "mock:mock")]
80    pub models: Vec<String>,
81    /// Tool-call rendering modes to compare.
82    #[arg(
83        long = "tool-format",
84        value_delimiter = ',',
85        default_value = "native,text"
86    )]
87    pub tool_formats: Vec<String>,
88    /// Output directory for summary.json, per_run.jsonl, transcripts, and markdown reports.
89    #[arg(long)]
90    pub output: Option<PathBuf>,
91    /// Optional .env file(s) to load for provider credentials. Values are never written to artifacts.
92    #[arg(long = "env-file")]
93    pub env_files: Vec<PathBuf>,
94    /// Append reachable local Ollama/llama.cpp/MLX/vLLM models to the selected matrix.
95    #[arg(long = "include-local")]
96    pub include_local: bool,
97    /// Restrict local discovery to one provider id. Repeatable.
98    #[arg(long = "local-provider")]
99    pub local_providers: Vec<String>,
100    /// Maximum discovered local models to append.
101    #[arg(long = "max-local-models", default_value_t = 2)]
102    pub max_local_models: usize,
103    /// Leave newly-loaded Ollama models running after each local benchmark run.
104    #[arg(long = "keep-local-after-run")]
105    pub keep_local_after_run: bool,
106    /// Stop after N matrix entries, useful for cost-capped smoke runs.
107    #[arg(long = "max-runs")]
108    pub max_runs: Option<usize>,
109    /// Maximum repair-agent loop iterations per run.
110    #[arg(long = "max-iterations", default_value_t = 8)]
111    pub max_iterations: usize,
112    /// Python executable used by the fixture and verification command.
113    #[arg(long, default_value = "python3")]
114    pub python: String,
115    /// Treat missing credentials as an error instead of skipping the run.
116    #[arg(long = "fail-on-unauthorized")]
117    pub fail_on_unauthorized: bool,
118    /// Print the aggregate summary JSON to stdout.
119    #[arg(long)]
120    pub json: bool,
121    /// Optional step_judge config applied to every run in this invocation.
122    /// Accepts a preset name (`symmetric-cheap`, `asymmetric`,
123    /// `symmetric-strong`) which expands to a known {model, provider}
124    /// pair, or `custom:<json>` for a literal JSON object passed verbatim
125    /// to `agent_loop({step_judge: ...})`. Omit (or pass `none` / `off`) to disable.
126    /// For matrix sweeps across presets, the step-judge experiment driver
127    /// at experiments/step-judge/run.sh invokes the eval runner once per
128    /// preset and aggregates.
129    #[arg(long = "step-judge")]
130    pub step_judge: Option<String>,
131    /// Override the on_veto remediation shape for the step-judge config
132    /// (`replace` or `retain`). Default is `replace`.
133    #[arg(long = "step-judge-on-veto")]
134    pub step_judge_on_veto: Option<String>,
135    /// Use the adversarial rubric variant.
136    #[arg(long = "step-judge-adversarial")]
137    pub step_judge_adversarial: bool,
138    /// Free-form reason attached when forcing a tool format against catalog guidance.
139    #[arg(long = "override-reason")]
140    pub override_reason: Option<String>,
141    /// Structural-validator config applied to every run in this invocation.
142    /// Omit to use the suite default (currently the 4-rule validator).
143    /// Accepts `on` / `default`, `off` / `none`, or `custom:<json>` for a
144    /// literal JSON object passed to `with_structural_validator(...)`.
145    #[arg(long = "structural-validator")]
146    pub structural_validator: Option<String>,
147    /// Free-form label persisted in summary.json for grouping repeat runs
148    /// (e.g. "replicate-1", "probe-judge-arch-gpt"). Defaults to empty.
149    #[arg(long = "run-label", default_value = "")]
150    pub run_label: String,
151    /// Path to a previous coding-agent `summary.json` (or its parent dir).
152    /// When present, the new summary embeds a `baseline_comparison` block
153    /// listing per-fixture regressions (baseline passed but this cell
154    /// failed) and recoveries (baseline failed but this cell passed),
155    /// plus aggregate counts and a net lift in percentage points.
156    /// Useful for cross-cell A/Bs (provider sweep, prompt change, step
157    /// judge on/off) where net pass-rate hides destructive interactions
158    /// like the cli-help-flag regression the step-judge experiment
159    /// surfaced (harn#2318).
160    #[arg(long = "baseline-comparison-against")]
161    pub baseline_comparison_against: Option<PathBuf>,
162}
163
164#[derive(Debug, Args)]
165pub struct EvalToolCallsArgs {
166    #[command(subcommand)]
167    pub command: Option<EvalToolCallsCommand>,
168    /// Dataset directory or JSON file. Directories prefer a `cases/` child.
169    #[arg(long, default_value = "conformance/tool-call-eval")]
170    pub dataset: PathBuf,
171    /// Planner model selector: alias, `provider:model`, or `provider=...,model=...`.
172    #[arg(long)]
173    pub planner: Option<String>,
174    /// Optional binder model selector. When set, a second model canonicalizes
175    /// the planner's response into a call/refusal decision before scoring.
176    #[arg(long)]
177    pub binder: Option<String>,
178    /// Judge model used only for predicate cases.
179    #[arg(long = "judge-model", default_value = "claude-opus-4-7")]
180    pub judge_model: String,
181    /// Output directory for `summary.json` and `per_case.jsonl`.
182    #[arg(long)]
183    pub output: Option<PathBuf>,
184    /// Override tool rendering for the planner (`native` or `text`).
185    #[arg(long = "tool-format")]
186    pub tool_format: Option<String>,
187    /// Maximum planner response tokens.
188    #[arg(long = "max-tokens", default_value_t = 512)]
189    pub max_tokens: i64,
190    /// Maximum binder response tokens. Default is sized to leave room for
191    /// reasoning-emitting models (e.g. GPT-OSS-120B emits ~200 tokens of
192    /// chain-of-thought before the JSON payload); non-reasoning binders
193    /// will under-fill this budget at no extra cost.
194    #[arg(long = "binder-max-tokens", default_value_t = 1024)]
195    pub binder_max_tokens: i64,
196    /// Run only cases whose id or tag contains this string.
197    #[arg(long)]
198    pub filter: Option<String>,
199    /// Stop after N selected cases, useful for smoke runs.
200    #[arg(long = "max-cases")]
201    pub max_cases: Option<usize>,
202    /// Treat missing credentials as an immediate preflight error.
203    #[arg(long = "fail-on-unauthorized")]
204    pub fail_on_unauthorized: bool,
205}
206
207#[derive(Debug, Subcommand)]
208pub enum EvalToolCallsCommand {
209    /// Compare a current summary against a pinned baseline.
210    RegressionCheck(EvalToolCallsRegressionArgs),
211}
212
213#[derive(Debug, Args)]
214pub struct EvalToolCallsRegressionArgs {
215    /// Current run summary. Defaults to `.harn-runs/tool-call-eval/latest/summary.json`.
216    #[arg(long)]
217    pub current: Option<PathBuf>,
218    /// Optional planner label for diagnostics.
219    #[arg(long)]
220    pub planner: Option<String>,
221    /// Baseline summary JSON to compare against.
222    #[arg(long)]
223    pub against: PathBuf,
224    /// Maximum allowed pass-rate drop in percentage points.
225    #[arg(long = "max-drop-pp", default_value_t = 2.0)]
226    pub max_drop_pp: f64,
227}
228
229#[derive(Debug, Args)]
230pub struct EvalPromptArgs {
231    /// Path to a `.harn.prompt` (or `.prompt`) template.
232    pub file: PathBuf,
233    /// Fleet of model selectors (comma-separated, repeatable).
234    /// Each entry is either a model alias (`claude-opus-4-7`) or a
235    /// `provider:model` selector (`ollama:qwen3.5`). Mutually exclusive
236    /// with `--fleet-name`.
237    #[arg(
238        long,
239        value_delimiter = ',',
240        required_unless_present = "fleet_name",
241        conflicts_with = "fleet_name"
242    )]
243    pub fleet: Vec<String>,
244    /// Named fleet from `harn.toml` `[eval.fleets.<name>]`.
245    #[arg(long = "fleet-name")]
246    pub fleet_name: Option<String>,
247    /// JSON file with bindings injected into the template scope.
248    #[arg(long)]
249    pub bindings: Option<PathBuf>,
250    /// Prompt context-quality fixture(s) that score artifact selection,
251    /// stale/noisy rejection, budget adherence, and logical-section shape.
252    #[arg(long = "context-fixture")]
253    pub context_fixture: Vec<PathBuf>,
254    /// Evaluation mode.
255    #[arg(long, value_enum, default_value_t = EvalPromptMode::Render)]
256    pub mode: EvalPromptMode,
257    /// Output format.
258    #[arg(long, value_enum, default_value_t = EvalPromptOutput::Terminal)]
259    pub output: EvalPromptOutput,
260    /// Output destination for HTML / JSON (defaults to stdout).
261    #[arg(long = "out-file", short = 'o')]
262    pub out_file: Option<PathBuf>,
263    /// Maximum concurrent model invocations in run/judge modes.
264    #[arg(long, default_value_t = 4)]
265    pub max_concurrent: usize,
266    /// Optional judge prompt template. When unset, a built-in equivalence
267    /// judge is used.
268    #[arg(long = "judge-template")]
269    pub judge_template: Option<PathBuf>,
270    /// Model used for `--mode judge` evaluation.
271    #[arg(long = "judge-model", default_value = "claude-opus-4-7")]
272    pub judge_model: String,
273    /// Maximum tokens for `--mode run` / `--mode judge` calls.
274    #[arg(long = "max-tokens", default_value_t = 1024)]
275    pub max_tokens: i64,
276    /// Treat unauthenticated providers as errors rather than skipping them.
277    #[arg(long = "fail-on-unauthorized")]
278    pub fail_on_unauthorized: bool,
279}
280
281#[derive(Debug, Clone, Copy, ValueEnum)]
282pub enum EvalPromptMode {
283    /// Render the template against each model's capability profile.
284    Render,
285    /// Render + execute against each model and collect outputs.
286    Run,
287    /// Render + run + LLM-as-judge equivalence scoring.
288    Judge,
289}
290
291#[derive(Debug, Clone, Copy, ValueEnum)]
292pub enum EvalPromptOutput {
293    Terminal,
294    Json,
295    Html,
296}