Skip to main content

vpf_runner/
lib.rs

1//! The reference runner of the Verifiable Plan Format (VPF).
2//!
3//! A [`Runner`] runs a checked plan in a folder: it starts each step when the steps it waits for are done and its
4//! time has come, takes the path a choice gives, does a step for each item of a list, asks each step's proofs,
5//! sends refused work back with the points against it, asks the person when work keeps being refused or a
6//! deadline passes, keeps to the plan's limits, and keeps a [`Record`] of the run. A run that waits for people or
7//! for a time holds nothing: it ends as [`Outcome::Waiting`], takes replies with [`Record::reply`] and new versions
8//! of its plan with [`Record::change`], and goes on with [`Runner::resume`].
9//!
10//! A host that keeps runs in its own store gives the runner a [`Keeper`], handed each [`Entry`] as soon as the run
11//! keeps it, and rebuilds a run that stopped in the middle with [`Record::add_entries`]:
12//!
13//! ```
14//! use vpf_runner::{AgentAnswer, AgentRequest, Entry, Keeper, Outcome, Record, Runner, Terminal};
15//!
16//! #[derive(Default)]
17//! struct Store {
18//!     begun: Option<Record>,
19//!     entries: Vec<Entry>,
20//! }
21//!
22//! impl Keeper for Store {
23//!     fn begin(&mut self, record: &Record) {
24//!         self.begun = Some(record.clone());
25//!     }
26//!     fn kept(&mut self, entry: &Entry) {
27//!         self.entries.push(entry.clone());
28//!     }
29//! }
30//!
31//! let plan = vpf::check(
32//!     r#"{ "$schema": "vpf/1.1", "wish": "A note",
33//!          "steps": [ { "id": "note", "do": "Write a note.", "by": "agent",
34//!                       "proof": [ { "by": "algorithm", "run": "true" } ] } ] }"#,
35//! )
36//! .plan
37//! .expect("a plan");
38//! let agent = |request: &AgentRequest<'_>| {
39//!     Ok(AgentAnswer::new(format!("wrote the note for {}", request.step)).with_cost(0.01))
40//! };
41//! let folder = tempfile::tempdir().expect("a folder");
42//! let mut person = Terminal::new(std::io::empty(), std::io::sink());
43//! let mut store = Store::default();
44//! let record = Runner::new(folder.path(), &agent, &mut person)
45//!     .detach(true)
46//!     .keeper(&mut store)
47//!     .run(&plan, "");
48//! assert_eq!(record.outcome, Outcome::Done);
49//!
50//! // Should the run have stopped in the middle, it goes on from the store.
51//! let mut rebuilt = store.begun.take().expect("the run began");
52//! rebuilt.add_entries(store.entries.drain(..));
53//! let again = Runner::new(folder.path(), &agent, &mut person).resume(&rebuilt);
54//! assert_eq!(again.steps[0].answer, record.steps[0].answer);
55//! ```
56
57mod agent;
58mod command;
59mod fill;
60mod folder;
61mod journal;
62pub mod needs;
63mod person;
64mod record;
65mod run;
66pub mod start;
67mod time;
68
69pub use agent::{Agent, AgentAnswer, AgentRequest, CommandAgent, Role};
70pub use fill::{fill, names_asked};
71pub use journal::{Entry, Keeper};
72pub use person::{Ask, Person, Terminal, Verdict};
73pub use record::{
74    Attempt, Decision, ItemRecord, Outcome, ProofRecord, Record, Reply, StepRecord, Version, Wait,
75    Waiting,
76};
77pub use run::Runner;
78pub use time::{Clock, Moment, SystemClock};