O6: telemetry report and eval task set (#14)

This commit was merged in pull request #14.
This commit is contained in:
hermes committed 2026-11-13 00:19:52 +00:00
1 parent bea07e82bb
commit b2d72f2dc9
31 files changed
+809 -3

No files matched your search

+140 -2
View File
@@ -2,6 +2,7 @@ mod adapter;
mod lock;
mod policy;
mod profile;
mod report;
mod run;
mod state;
@@ -37,6 +38,30 @@ enum Cmd {
#[arg(long)]
limit: Option<usize>,
},
/// Success rate, tokens, retries and duration per profile and hx version, from the telemetry log.
Report {
/// Telemetry file (default: <state>/telemetry.jsonl).
file: Option<PathBuf>,
},
/// Compare two telemetry files per case; exit 1 when B's success rate is below A's.
Eval { a: PathBuf, b: PathBuf },
/// Run the eval cases in DIR (task.md, files/, gate.sh each) through a profile; writes telemetry to --out.
Bench {
dir: PathBuf,
#[arg(long, default_value = "default")]
profile: String,
#[arg(long)]
out: Option<PathBuf>,
/// Runs per case.
#[arg(long, default_value_t = 1)]
repeat: u32,
/// Only this case.
#[arg(long)]
case: Option<String>,
/// No hx: check that every case fails untouched and passes with its solution/ overlay.
#[arg(long)]
check: bool,
},
/// hx extension that enforces a run's tool allowlist (started by hx, not by hand).
#[command(hide = true)]
Guard { policy: PathBuf },
@@ -82,7 +107,7 @@ fn main() -> Result<std::process::ExitCode> {
let p = profile::Profile::load(&profile)?;
let id = task.file_stem().and_then(|s| s.to_str()).unwrap_or("task");
let t = adapter::parse_task_md(id, &std::fs::read_to_string(&task)?);
let r = process(&t, &repo, &profile, &p, None)?;
let r = process(&t, &repo, &profile, &p, None, &report::default_path())?;
Ok(code(r.status == state::Status::Done))
}
Cmd::Pull { profile, limit } => {
@@ -125,7 +150,14 @@ fn main() -> Result<std::process::ExitCode> {
if !src.claim(&t)? {
continue;
}
let r = process(&t, &repo, &profile, &p, Some(src.as_ref()))?;
let r = process(
&t,
&repo,
&profile,
&p,
Some(src.as_ref()),
&report::default_path(),
)?;
if r.status != state::Status::Done
&& r.status != state::Status::Requeued
{
@@ -142,6 +174,31 @@ fn main() -> Result<std::process::ExitCode> {
});
Ok(code(ok.load(Ordering::SeqCst)))
}
Cmd::Report { file } => {
print!(
"{}",
report::report(&report::load(&file.unwrap_or_else(report::default_path))?)
);
Ok(0.into())
}
Cmd::Eval { a, b } => {
let (text, regressed) = report::compare(
&report::load(&a)?,
&report::load(&b)?,
&a.to_string_lossy(),
&b.to_string_lossy(),
);
print!("{text}");
Ok(code(!regressed))
}
Cmd::Bench {
dir,
profile,
out,
repeat,
case,
check,
} => bench(&dir, &profile, out, repeat, case.as_deref(), check),
Cmd::Guard { policy } => {
policy::guard(&policy)?;
Ok(0.into())
@@ -195,6 +252,7 @@ fn process(
profile: &str,
p: &profile::Profile,
src: Option<&dyn adapter::Source>,
telemetry: &Path,
) -> Result<state::Run> {
let mut r = run::new_run(t, repo, profile)?;
if p.allow.is_none() && !p.sandbox {
@@ -213,6 +271,10 @@ fn process(
"run_end",
serde_json::json!({"status": r.status, "reason": r.reason, "attempts": r.attempts}),
);
// a telemetry failure must not lose the run
if let Err(e) = report::append(telemetry, &report::rec(&r, &report::hx_version(p))) {
eprintln!("{}: telemetry: {e:#}", r.id);
}
if r.status == state::Status::Done {
match adapter::sink(p.sink.as_ref()).and_then(|s| s.publish(t, &r)) {
Ok(note) => r.published = note,
@@ -243,3 +305,79 @@ fn process(
);
Ok(r)
}
/// `orch bench`: every case gets a fresh git repo of its files and its own gate (`gate.sh`); the profile decides
/// everything else (hx, allowlist, retries, budget). Sink and source are ignored: nothing is published.
fn bench(
dir: &Path,
profile: &str,
out: Option<PathBuf>,
repeat: u32,
only: Option<&str>,
check: bool,
) -> Result<std::process::ExitCode> {
let mut cases = report::cases(dir)?;
if let Some(o) = only {
cases.retain(|c| c.name == o);
anyhow::ensure!(!cases.is_empty(), "no case named {o:?}");
}
if check {
return bench_check(&cases);
}
let mut p = profile::Profile::load(profile)?;
(p.source, p.sink) = (None, None);
let out = out.unwrap_or_else(|| state_dir().join("bench.jsonl"));
let mut ok = true;
for c in &cases {
for _ in 0..repeat {
let repo = report::fixture(c)?;
let gate = c.dir.join("gate.sh").canonicalize()?;
p.gate = Some(format!("sh {}", gate.display()));
let t =
adapter::parse_task_md(&c.name, &std::fs::read_to_string(c.dir.join("task.md"))?);
ok &= process(&t, &repo, profile, &p, None, &out)?.status == state::Status::Done;
}
}
println!("telemetry: {}", out.display());
Ok(code(ok))
}
/// Case-set sanity without an agent: the gate must fail on the untouched files and pass after `solution/`.
fn bench_check(cases: &[report::Case]) -> Result<std::process::ExitCode> {
let gate = |dir: &Path, g: &Path| -> Result<bool> {
Ok(std::process::Command::new("sh")
.arg(g)
.current_dir(dir)
.output()?
.status
.success())
};
let mut ok = true;
for c in cases {
let g = c.dir.join("gate.sh").canonicalize()?;
let repo = report::fixture(c)?;
let before = gate(&repo, &g)?;
let sol = c.dir.join("solution");
let after = if sol.is_dir() {
std::process::Command::new("cp")
.arg("-R")
.arg(format!("{}/.", sol.display()))
.arg(&repo)
.status()?;
Some(gate(&repo, &g)?)
} else {
None
};
let good = !before && after != Some(false);
let solved = match after {
None => "no solution/",
Some(true) => "pass",
Some(false) => "FAIL (bad)",
};
let untouched = if before { "PASS (bad)" } else { "fail" };
let flag = if good { "" } else { " <-- broken case" };
println!("{:<20} untouched={untouched} solved={solved}{flag}", c.name);
ok &= good;
}
Ok(code(ok))
}