Expand description
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);Modules§
- needs
- Whether the folder holds what a proof by needs names.
- start
- When runs start: on a schedule, every so many minutes, or when files change.
Structs§
- Agent
Answer - What an agent answered.
- Agent
Request - What an agent is asked.
- Ask
- What a person is asked.
- Attempt
- One try at a step’s work.
- Command
Agent - An agent reached through a command line.
- Decision
- A question the person decided.
- Entry
- One thing a run was given: an agent’s answer, a command’s result, a person’s reply or a time.
- Item
Record - One item of a step done for each item.
- Proof
Record - One proof asked, with its result. A skipped proof is kept without
passed, since it neither passed nor refused. - Record
- One run of a plan.
- Runner
- Runs plans in a folder, with an agent and a person.
- Step
Record - One step of the run.
- System
Clock - The computer’s own clock.
- Terminal
- A person at a terminal: told on one stream and answering on another.
- Version
- One version of the plan a run followed.
- Waiting
- One thing a waiting run waits for.
Enums§
- Moment
- A time as a plan writes it: a date and time, or a wait from some moment.
- Outcome
- How a run ended, or where it stands.
- Reply
- A person’s reply to what a run waits for.
- Role
- Why an agent is asked.
- Verdict
- What the person said of the work.
- Wait
- What a step waits for.
Traits§
- Agent
- Who answers when an agent is asked. Steps that wait for none of each other ask at the same time, from more than one thread.
- Clock
- The clock a run reads, and waits on until a step’s time comes.
- Keeper
- Who keeps a run’s entries as they come, in a store of its own: a host that must not lose what a run was given should the computer go down in the middle of it.
- Person
- The person the plan is for, and the people its steps name.
Functions§
- fill
- The text with each reference to a known name filled. A field that is not there gives an empty text; a name that is not known stays as it is.
- names_
asked - Whether the text names
asked.