1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! 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);
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Runner;
pub use ;