use io_harness::{resume, run, RunStatus, Store, TaskContract, Verification};
#[tokio::main]
async fn main() -> io_harness::Result<()> {
let provider = io_harness::OpenRouter::from_env()?;
let dir = tempfile::tempdir()?;
let db = dir.path().join("runs.db");
let file = dir.path().join("hello.rs");
let goal = "Write a Rust file with a public function `hello` returning the u32 42.";
let verify = Verification::Command {
argv: vec![
"rustc".into(),
"--edition".into(),
"2021".into(),
"--crate-type".into(),
"lib".into(),
"hello.rs".into(),
],
expect_exit: 0,
};
let run_id = {
let store = Store::open(&db)?;
let contract = TaskContract::new(goal, &file, verify.clone()).with_max_steps(1);
let r = run(&contract, &provider, &store).await?;
println!("[process 1] stopped: {:?}", r.outcome);
println!(
"[process 1] committed {} step(s); status = {:?}",
store.last_step(r.run_id)?,
store.run_status(r.run_id)?.unwrap_or(RunStatus::Running),
);
r.run_id
};
let store = Store::open(&db)?;
let contract = TaskContract::new(goal, &file, verify).with_max_steps(8);
let r = resume(&contract, &provider, &store, run_id).await?;
println!("[process 2] resumed to: {:?}", r.outcome);
let events = store.checkpoint_events(run_id)?;
let skipped = events.iter().filter(|e| e.kind == "skipped").count();
let checkpoints = events.iter().filter(|e| e.kind == "checkpoint").count();
println!(
"[process 2] {checkpoints} step(s) checkpointed, {skipped} skipped as already-done on resume",
);
println!(
"[process 2] final status = {:?}",
store.run_status(run_id)?.unwrap()
);
Ok(())
}