vpf-runner 0.4.0

The reference runner of the Verifiable Plan Format (VPF): runs a plan step by step and proves each step.
Documentation
//! The reference runner of the Verifiable Plan Format (VPF).
//!
//! A [`Runner`] runs a checked plan in a folder: it starts each step when the steps it waits for are done and its
//! time has come, takes the path a choice gives, does a step for each item of a list, asks each step's proofs,
//! sends refused work back with the points against it, asks the person when work keeps being refused or a
//! deadline passes, keeps to the plan's limits, and keeps a [`Record`] of the run. A run that waits for people or
//! for a time holds nothing: it ends as [`Outcome::Waiting`], takes replies with [`Record::reply`] and new versions
//! of its plan with [`Record::change`], and goes on with [`Runner::resume`].
//!
//! A host that keeps runs in its own store gives the runner a [`Keeper`], handed each [`Entry`] as soon as the run
//! keeps it, and rebuilds a run that stopped in the middle with [`Record::add_entries`]:
//!
//! ```
//! use vpf_runner::{AgentAnswer, AgentRequest, Entry, Keeper, Outcome, Record, Runner, Terminal};
//!
//! #[derive(Default)]
//! struct Store {
//!     begun: Option<Record>,
//!     entries: Vec<Entry>,
//! }
//!
//! impl Keeper for Store {
//!     fn begin(&mut self, record: &Record) {
//!         self.begun = Some(record.clone());
//!     }
//!     fn kept(&mut self, entry: &Entry) {
//!         self.entries.push(entry.clone());
//!     }
//! }
//!
//! let plan = vpf::check(
//!     r#"{ "$schema": "vpf/1.1", "wish": "A note",
//!          "steps": [ { "id": "note", "do": "Write a note.", "by": "agent",
//!                       "proof": [ { "by": "algorithm", "run": "true" } ] } ] }"#,
//! )
//! .plan
//! .expect("a plan");
//! let agent = |request: &AgentRequest<'_>| {
//!     Ok(AgentAnswer::new(format!("wrote the note for {}", request.step)).with_cost(0.01))
//! };
//! let folder = tempfile::tempdir().expect("a folder");
//! let mut person = Terminal::new(std::io::empty(), std::io::sink());
//! let mut store = Store::default();
//! let record = Runner::new(folder.path(), &agent, &mut person)
//!     .detach(true)
//!     .keeper(&mut store)
//!     .run(&plan, "");
//! assert_eq!(record.outcome, Outcome::Done);
//!
//! // Should the run have stopped in the middle, it goes on from the store.
//! let mut rebuilt = store.begun.take().expect("the run began");
//! rebuilt.add_entries(store.entries.drain(..));
//! let again = Runner::new(folder.path(), &agent, &mut person).resume(&rebuilt);
//! assert_eq!(again.steps[0].answer, record.steps[0].answer);
//! ```

mod agent;
mod command;
mod fill;
mod folder;
mod journal;
pub mod needs;
mod person;
mod record;
mod run;
pub mod start;
mod time;

pub use agent::{Agent, AgentAnswer, AgentRequest, CommandAgent, Role};
pub use fill::{fill, names_asked};
pub use journal::{Entry, Keeper};
pub use person::{Ask, Person, Terminal, Verdict};
pub use record::{
    Attempt, Decision, ItemRecord, Outcome, ProofRecord, Record, Reply, StepRecord, Version, Wait,
    Waiting,
};
pub use run::Runner;
pub use time::{Clock, Moment, SystemClock};