Skip to main content

onerig_core/
run.rs

1//! The run state machine of design sections 5 and 6: plan, execute, review,
2//! commit, pause and resume. It talks to harnesses only through `Runner`, so
3//! it is tested with the scripted runner.
4
5use std::collections::{BTreeMap, HashSet};
6use std::path::{Path, PathBuf};
7
8use crate::config::Config;
9use crate::halt::Halt;
10use crate::plan::{
11    FormatError, PLAN_SCHEMA, Plan, Task, VERDICT_SCHEMA, Verdict, VerdictKind, parse_plan,
12    parse_verdict,
13};
14use crate::policy::{self, AfterFailure, LaneView, Selected, Selection};
15use crate::prompt::{self, Previous, WorkerPrompt};
16use crate::runner::{FailureKind, HarnessEvent, Job, Outcome, ProbeError, Role, Runner};
17use crate::store::{
18    LaneMark, LastEnd, Lock, LockError, LogEntry, LogRecord, PauseReason, Paused, Phase,
19    PolicyEvent, RunDir, STATE_VERSION, State, StateEvent, StoreError,
20};
21use crate::worktree::{Committed, Git, GitError, worktree_path};
22
23/// How many times a planner or reviewer job is tried before the run gives up.
24const ASK_TRIES: usize = 2;
25
26/// What a run needs from the world. The binary passes the real things; tests
27/// pass a scripted runner, a fixed clock and a temporary data home.
28pub struct Env<'a> {
29    pub git: &'a Git,
30    pub runner: &'a mut dyn Runner,
31    /// Unix milliseconds.
32    pub clock: &'a dyn Fn() -> u64,
33    pub pid: u32,
34    pub stop: &'a Halt,
35    /// Receives every log record as it is written.
36    pub sink: &'a mut dyn FnMut(&LogRecord),
37    /// `$XDG_DATA_HOME` or its default; worktrees go below it.
38    pub data_home: &'a Path,
39}
40
41#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42pub enum Exit {
43    Done,
44    Failed,
45    Paused,
46}
47
48#[derive(Debug)]
49pub struct Finished {
50    pub exit: Exit,
51    pub run_id: String,
52    pub state: State,
53}
54
55#[derive(Debug, thiserror::Error)]
56pub enum RunError {
57    #[error(transparent)]
58    Git(#[from] GitError),
59    #[error(transparent)]
60    Store(#[from] StoreError),
61    #[error(transparent)]
62    Lock(#[from] LockError),
63    #[error("lane {lane} cannot run: {message}")]
64    Probe { lane: String, message: String },
65    #[error("there is no run to resume in this repository")]
66    NothingToResume,
67    #[error("run {0} has already finished")]
68    AlreadyFinished(String),
69}
70
71/// What a new run starts from.
72#[derive(Debug, Clone)]
73pub struct NewRun<'g> {
74    pub goal: &'g str,
75    /// A plan the owner already approved; the run then skips planning.
76    pub plan: Option<Plan>,
77    /// The ref the run's branch starts from; the main checkout's HEAD if `None`.
78    pub base: Option<&'g str>,
79}
80
81/// Starts a new run for `goal` in the repository that contains `cwd`.
82pub fn start<'a>(
83    config: &'a Config,
84    cwd: &Path,
85    goal: &str,
86    env: Env<'a>,
87) -> Result<Finished, RunError> {
88    let new = NewRun {
89        goal,
90        plan: None,
91        base: None,
92    };
93    start_with(config, cwd, new, env)
94}
95
96/// Starts a new run as `new` describes.
97pub fn start_with<'a>(
98    config: &'a Config,
99    cwd: &Path,
100    new: NewRun<'_>,
101    env: Env<'a>,
102) -> Result<Finished, RunError> {
103    let (main, is_git) = env.git.workspace(cwd)?;
104    if is_git {
105        env.git.preflight(&main)?;
106    }
107    let probes = probe_lanes(config, env.runner)?;
108    let (dir, lock, state) = create_run(&env, main, is_git, new.goal, new.base)?;
109    let mut machine = Machine::new(config, env, dir, lock, state, probes, None);
110    machine.note_run();
111    machine.begin(new.plan)?;
112    machine.finish()
113}
114
115/// Creates the run's directory, lock, and (for git repos) branch and worktree.
116fn create_run(
117    env: &Env<'_>,
118    main: PathBuf,
119    is_git: bool,
120    goal: &str,
121    base: Option<&str>,
122) -> Result<(RunDir, Lock, State), RunError> {
123    let now = (env.clock)();
124    let run_id = crate::store::run_id(now, env.pid);
125    let dir = RunDir::create(&main, &run_id)?;
126    let lock = Lock::acquire(&dir)?;
127    let (worktree, branch) = if is_git {
128        env.git.ensure_excluded(&main)?;
129        let worktree = worktree_path(env.data_home, &main, &run_id);
130        let branch = format!("onerig/{run_id}");
131        env.git
132            .create_run_worktree(&main, &worktree, &branch, base.unwrap_or("HEAD"))?;
133        (worktree, branch)
134    } else {
135        (main.clone(), String::new())
136    };
137    let state = new_state(&run_id, goal, now, main, worktree, branch);
138    Ok((dir, lock, state))
139}
140
141/// Continues the given run, or the latest one that has not finished.
142pub fn resume<'a>(
143    config: &'a Config,
144    cwd: &Path,
145    run_id: Option<&str>,
146    env: Env<'a>,
147) -> Result<Finished, RunError> {
148    let (dir, lock, mut state) = open_run(env.git, cwd, run_id)?;
149    let probes = probe_lanes(config, env.runner)?;
150    let plan = state.task_index.map(|_| dir.read_plan()).transpose()?;
151    prepare_resume(&mut state);
152    let mut machine = Machine::new(config, env, dir, lock, state, probes, plan);
153    machine.note_run();
154    machine.note_plan();
155    machine.note(LogEntry::State(StateEvent::Phase {
156        phase: machine.state.phase,
157    }));
158    machine.save()?;
159    machine.finish()
160}
161
162/// Finds the run, takes its lock and reads its state.
163fn open_run(
164    git: &Git,
165    cwd: &Path,
166    run_id: Option<&str>,
167) -> Result<(RunDir, Lock, State), RunError> {
168    let (main, _) = git.workspace(cwd)?;
169    let run_id = given_or_latest(&main, run_id)?;
170    let dir = RunDir::open(&main, &run_id)?;
171    let lock = Lock::acquire(&dir)?;
172    let state = dir.read_state()?;
173    if exit_of(state.phase).is_some_and(|exit| exit != Exit::Paused) {
174        return Err(RunError::AlreadyFinished(run_id));
175    }
176    Ok((dir, lock, state))
177}
178
179fn given_or_latest(main: &Path, run_id: Option<&str>) -> Result<String, RunError> {
180    match run_id {
181        Some(id) => Ok(id.to_string()),
182        None => crate::store::latest_resumable(main)?.ok_or(RunError::NothingToResume),
183    }
184}
185
186fn new_state(
187    run_id: &str,
188    goal: &str,
189    now: u64,
190    repo: PathBuf,
191    worktree: PathBuf,
192    branch: String,
193) -> State {
194    State {
195        v: STATE_VERSION,
196        run_id: run_id.to_string(),
197        goal: goal.to_string(),
198        updated_at: now,
199        repo,
200        worktree,
201        branch,
202        phase: Phase::Planning,
203        paused: None,
204        task_index: None,
205        task_base: None,
206        attempt: None,
207        attempts_used: 0,
208        lane: None,
209        unknown_streak: 0,
210        skipped: Vec::new(),
211        last_end: None,
212        approved: false,
213        issues: Vec::new(),
214        last_output_tail: String::new(),
215        job_seq: 0,
216        lanes: BTreeMap::new(),
217    }
218}
219
220/// A run found in a working phase had no live process: it was interrupted.
221fn prepare_resume(state: &mut State) {
222    let resume_phase = match state.paused.take() {
223        Some(paused) if state.phase == Phase::Paused => paused.resume_phase,
224        _ => {
225            if state.phase == Phase::Executing {
226                state.last_end = Some(LastEnd::Interrupted);
227            }
228            state.phase
229        }
230    };
231    state.phase = resume_phase;
232    state
233        .lanes
234        .values_mut()
235        .for_each(|mark| *mark = LaneMark::default());
236    state.skipped.clear();
237    state.unknown_streak = 0;
238    state.attempts_used = 0;
239}
240
241/// At least one planner lane and one reviewer lane must pass preflight; a
242/// worker lane that fails its probe is only unavailable. Manual and off lanes
243/// are never probed.
244fn probe_lanes(config: &Config, runner: &mut dyn Runner) -> Result<Probes, RunError> {
245    let mut probes = Probes::default();
246    let mut seen = HashSet::new();
247    for name in config
248        .roles
249        .planner
250        .iter()
251        .chain(&config.roles.reviewer)
252        .chain(&config.roles.worker)
253    {
254        if !seen.insert(name.clone()) {
255            continue;
256        }
257        let lane = &config.lanes[name];
258        if lane.is_off() || lane.is_manual() {
259            continue;
260        }
261        let result = runner.preflight(name);
262        if let Err(error) = &result {
263            probes.failed.insert(name.clone(), error.to_string());
264        }
265        probes.results.push((name.clone(), result));
266    }
267    require_usable_role(&config.roles.planner, &probes)?;
268    require_usable_role(&config.roles.reviewer, &probes)?;
269    Ok(probes)
270}
271
272fn require_usable_role(lanes: &[String], probes: &Probes) -> Result<(), RunError> {
273    if lanes.iter().any(|name| !probes.failed.contains_key(name)) {
274        return Ok(());
275    }
276    let first = &lanes[0];
277    let message = probes
278        .failed
279        .get(first)
280        .cloned()
281        .unwrap_or_else(|| "no usable lane".to_string());
282    Err(RunError::Probe {
283        lane: first.clone(),
284        message,
285    })
286}
287
288#[derive(Default)]
289struct Probes {
290    results: Vec<(String, Result<crate::runner::Probe, ProbeError>)>,
291    /// Worker lanes whose probe failed, with the message.
292    failed: BTreeMap<String, String>,
293}
294
295/// Appends records to the run log and passes them to the sink. A write error
296/// is kept and reported when the current step ends.
297struct Log<'a> {
298    dir: RunDir,
299    sink: &'a mut dyn FnMut(&LogRecord),
300    clock: &'a dyn Fn() -> u64,
301    error: Option<StoreError>,
302}
303
304impl Log<'_> {
305    fn record(
306        &mut self,
307        task: Option<usize>,
308        attempt: Option<u32>,
309        lane: Option<&str>,
310        entry: LogEntry,
311    ) {
312        let record = LogRecord {
313            ts: (self.clock)(),
314            task,
315            attempt,
316            lane: lane.map(str::to_string),
317            entry,
318        };
319        if let Err(error) = self.dir.append_log(&record) {
320            self.error.get_or_insert(error);
321        }
322        (self.sink)(&record);
323    }
324}
325
326/// The answer of a planner or reviewer job.
327enum Asked<T> {
328    Answer(T),
329    Pause(PauseReason, String, Option<u64>),
330    Failed(String),
331    Stopped,
332}
333
334/// Why a planner or reviewer answer cannot be used.
335enum Unusable {
336    Pause(PauseReason, String, Option<u64>),
337    Retry(String),
338}
339
340fn classify<T>(
341    outcome: Outcome,
342    parse: fn(&serde_json::Value) -> Result<T, FormatError>,
343) -> Result<T, Unusable> {
344    match outcome {
345        Outcome::Failed {
346            kind: FailureKind::Quota,
347            message,
348            reset_at,
349        } => Err(Unusable::Pause(PauseReason::Quota, message, reset_at)),
350        Outcome::Failed {
351            kind: FailureKind::Auth,
352            message,
353            ..
354        } => Err(Unusable::Pause(PauseReason::Auth, message, None)),
355        Outcome::Failed { message, .. } => Err(Unusable::Retry(message)),
356        Outcome::Done {
357            structured: Some(value),
358            ..
359        } => parse(&value).map_err(|error| Unusable::Retry(error.to_string())),
360        Outcome::Done {
361            structured: None, ..
362        } => Err(Unusable::Retry(
363            "the answer had no structured result".to_string(),
364        )),
365    }
366}
367
368struct Machine<'a> {
369    config: &'a Config,
370    git: &'a Git,
371    runner: &'a mut dyn Runner,
372    stop: &'a Halt,
373    clock: &'a dyn Fn() -> u64,
374    log: Log<'a>,
375    /// Held for the whole run; records the running harness's process group.
376    lock: Lock,
377    probes: Probes,
378    plan: Option<Plan>,
379    state: State,
380}
381
382impl<'a> Machine<'a> {
383    fn new(
384        config: &'a Config,
385        env: Env<'a>,
386        dir: RunDir,
387        lock: Lock,
388        state: State,
389        probes: Probes,
390        plan: Option<Plan>,
391    ) -> Machine<'a> {
392        let mut machine = Machine {
393            config,
394            git: env.git,
395            runner: env.runner,
396            stop: env.stop,
397            clock: env.clock,
398            log: Log {
399                dir,
400                sink: env.sink,
401                clock: env.clock,
402                error: None,
403            },
404            lock,
405            probes,
406            plan,
407            state,
408        };
409        machine.log_probes();
410        machine
411    }
412
413    fn log_probes(&mut self) {
414        let results = std::mem::take(&mut self.probes.results);
415        for (lane, result) in results {
416            let (ok, message) = match result {
417                Ok(probe) => (true, probe.version),
418                Err(error) => (false, error.to_string()),
419            };
420            self.note(LogEntry::Policy(PolicyEvent::Probe { lane, ok, message }));
421        }
422    }
423
424    fn finish(mut self) -> Result<Finished, RunError> {
425        let exit = self.drive()?;
426        Ok(Finished {
427            exit,
428            run_id: self.state.run_id.clone(),
429            state: self.state,
430        })
431    }
432
433    fn drive(&mut self) -> Result<Exit, RunError> {
434        loop {
435            if let Some(exit) = exit_of(self.state.phase) {
436                return Ok(exit);
437            }
438            if self.stop.is_set() {
439                self.pause_interrupted()?;
440                continue;
441            }
442            self.step()?;
443            if let Some(error) = self.log.error.take() {
444                return Err(error.into());
445            }
446        }
447    }
448
449    fn step(&mut self) -> Result<(), RunError> {
450        match self.state.phase {
451            Phase::Planning => self.plan(),
452            Phase::Executing => self.execute(),
453            Phase::Reviewing => self.review(),
454            Phase::Paused | Phase::Done | Phase::Failed => Ok(()),
455        }
456    }
457
458    fn now(&self) -> u64 {
459        (self.clock)()
460    }
461
462    fn note(&mut self, entry: LogEntry) {
463        let lane = self.state.lane.clone();
464        self.log.record(
465            self.state.task_index,
466            self.state.attempt,
467            lane.as_deref(),
468            entry,
469        );
470    }
471
472    fn note_run(&mut self) {
473        let state = &self.state;
474        let entry = LogEntry::State(StateEvent::Run {
475            run_id: state.run_id.clone(),
476            goal: state.goal.clone(),
477            branch: state.branch.clone(),
478        });
479        self.note(entry);
480    }
481
482    /// Nothing before the plan exists.
483    fn note_plan(&mut self) {
484        let Some(plan) = &self.plan else {
485            return;
486        };
487        let titles: Vec<String> = plan.tasks.iter().map(|task| task.title.clone()).collect();
488        self.note(LogEntry::State(StateEvent::Plan {
489            tasks: titles.len(),
490            titles,
491        }));
492    }
493
494    fn set_phase(&mut self, phase: Phase) {
495        self.state.phase = phase;
496        self.note(LogEntry::State(StateEvent::Phase { phase }));
497    }
498
499    fn save(&mut self) -> Result<(), RunError> {
500        self.state.updated_at = self.now();
501        self.log.dir.write_state(&self.state)?;
502        Ok(())
503    }
504
505    fn task(&self) -> Option<&Task> {
506        let index = self.state.task_index?;
507        self.plan.as_ref()?.tasks.get(index.checked_sub(1)?)
508    }
509
510    // ---- planning
511
512    fn plan(&mut self) -> Result<(), RunError> {
513        let lanes = self.config.roles.planner.clone();
514        let prompt = prompt::planner_prompt(&self.state.goal);
515        match self.ask(&lanes, Role::Planner, &prompt, PLAN_SCHEMA, parse_plan)? {
516            Asked::Answer(plan) => self.accept_plan(plan),
517            Asked::Pause(reason, message, until) => {
518                self.pause(reason, Phase::Planning, message, until)
519            }
520            Asked::Failed(problem) => self.fail(format!("the planner failed twice: {problem}")),
521            Asked::Stopped => Ok(()),
522        }
523    }
524
525    /// A new run plans first, or starts from a plan the owner approved.
526    fn begin(&mut self, plan: Option<Plan>) -> Result<(), RunError> {
527        let Some(plan) = plan else {
528            self.note(LogEntry::State(StateEvent::Phase {
529                phase: Phase::Planning,
530            }));
531            return self.save();
532        };
533        self.accept_plan(plan)
534    }
535
536    fn accept_plan(&mut self, plan: Plan) -> Result<(), RunError> {
537        self.log.dir.write_plan(&plan)?;
538        self.plan = Some(plan);
539        self.note_plan();
540        self.start_task(1)
541    }
542
543    fn start_task(&mut self, index: usize) -> Result<(), RunError> {
544        let state = &mut self.state;
545        state.task_index = Some(index);
546        state.task_base = None;
547        state.attempt = None;
548        state.attempts_used = 0;
549        // Clearing the lane also restarts the Unknown streak at the next attempt.
550        state.lane = None;
551        state.skipped.clear();
552        state.issues.clear();
553        state.last_output_tail.clear();
554        state.last_end = None;
555        state.approved = false;
556        self.set_phase(Phase::Executing);
557        self.save()
558    }
559
560    /// Runs a planner or reviewer job across `lanes` in fail-over order.
561    fn ask<T>(
562        &mut self,
563        lanes: &[String],
564        role: Role,
565        prompt: &str,
566        schema: &'static str,
567        parse: fn(&serde_json::Value) -> Result<T, FormatError>,
568    ) -> Result<Asked<T>, RunError> {
569        let mut last_pause = None;
570        let mut last_failed = None;
571        for lane in lanes {
572            if !self.role_lane_usable(lane) {
573                continue;
574            }
575            match self.ask_one(lane, role, prompt, schema, parse)? {
576                Asked::Answer(answer) => return Ok(Asked::Answer(answer)),
577                Asked::Stopped => return Ok(Asked::Stopped),
578                Asked::Pause(reason, message, until) => {
579                    self.record_role_pause(lane, reason, until);
580                    last_pause = Some((reason, message, until));
581                }
582                Asked::Failed(problem) => last_failed = Some(problem),
583            }
584        }
585        Ok(finish_unanswered(last_pause, last_failed))
586    }
587
588    fn record_role_pause(&mut self, lane: &str, reason: PauseReason, until: Option<u64>) {
589        if reason == PauseReason::Quota {
590            self.mark_exhausted(lane, until);
591        }
592    }
593
594    fn role_lane_usable(&self, lane: &str) -> bool {
595        if self.probes.failed.contains_key(lane) {
596            return false;
597        }
598        let now = self.now();
599        !self
600            .state
601            .lanes
602            .get(lane)
603            .copied()
604            .is_some_and(|mark| policy::is_exhausted(mark, now))
605    }
606
607    /// Runs a planner or reviewer job on one lane, retried once.
608    fn ask_one<T>(
609        &mut self,
610        lane: &str,
611        role: Role,
612        prompt: &str,
613        schema: &'static str,
614        parse: fn(&serde_json::Value) -> Result<T, FormatError>,
615    ) -> Result<Asked<T>, RunError> {
616        let mut problem = String::new();
617        for _ in 0..ASK_TRIES {
618            let Some((outcome, _)) = self.job(lane, role, prompt.to_string(), Some(schema))? else {
619                return Ok(Asked::Stopped);
620            };
621            match classify(outcome, parse) {
622                Ok(answer) => return Ok(Asked::Answer(answer)),
623                Err(Unusable::Pause(reason, message, until)) => {
624                    return Ok(Asked::Pause(reason, message, until));
625                }
626                Err(Unusable::Retry(message)) => problem = message,
627            }
628        }
629        Ok(Asked::Failed(problem))
630    }
631
632    /// Runs one job. `None` means the stop flag was set: the outcome is
633    /// discarded and the caller returns so the loop can pause.
634    fn job(
635        &mut self,
636        lane: &str,
637        role: Role,
638        prompt: String,
639        schema: Option<&'static str>,
640    ) -> Result<Option<(Outcome, String)>, RunError> {
641        self.state.job_seq += 1;
642        self.save()?;
643        let job = Job {
644            role,
645            prompt,
646            cwd: self.state.worktree.clone(),
647            run_dir: self.log.dir.path().to_path_buf(),
648            raw_log: self.log.dir.raw_log_path(self.state.job_seq),
649            schema,
650        };
651        let (task, attempt) = (self.state.task_index, self.state.attempt);
652        let mut texts: Vec<String> = Vec::new();
653        let log = &mut self.log;
654        let lock = &mut self.lock;
655        // A lock that cannot be updated only weakens the orphan check of the
656        // next start, so the job goes on.
657        let outcome = self.runner.run(
658            lane,
659            &job,
660            &mut |pgid| {
661                let _ = lock.set_pgid(Some(pgid));
662            },
663            &mut |event| {
664                if let HarnessEvent::Text { text } = &event {
665                    texts.push(text.clone());
666                }
667                log.record(task, attempt, Some(lane), LogEntry::Harness(event));
668            },
669        );
670        let _ = self.lock.set_pgid(None);
671        if self.stop.is_set() {
672            return Ok(None);
673        }
674        self.log.record(
675            task,
676            attempt,
677            Some(lane),
678            LogEntry::Outcome(outcome.clone()),
679        );
680        Ok(Some((outcome, texts.join("\n"))))
681    }
682
683    // ---- ending
684
685    fn fail(&mut self, message: String) -> Result<(), RunError> {
686        self.set_phase(Phase::Failed);
687        self.note(LogEntry::State(StateEvent::Failed { message }));
688        self.save()
689    }
690
691    fn pause_interrupted(&mut self) -> Result<(), RunError> {
692        let phase = self.state.phase;
693        if phase == Phase::Executing {
694            self.state.last_end = Some(LastEnd::Interrupted);
695        }
696        let message = "stopped by the user or a signal".to_string();
697        self.pause(PauseReason::Interrupted, phase, message, None)
698    }
699
700    /// When the next step is a worker attempt, the hand-over it would get is
701    /// written first, so a person can continue by hand.
702    fn pause(
703        &mut self,
704        reason: PauseReason,
705        resume_phase: Phase,
706        mut message: String,
707        until: Option<u64>,
708    ) -> Result<(), RunError> {
709        if resume_phase == Phase::Executing && self.write_pause_handover()? {
710            message.push_str(&format!(
711                "\nBy hand: cd {}, then tell any agent: Read .onerig/handover.md and follow its \
712                 Instruction section.\nAfterwards: onerig resume {}",
713                self.state.worktree.display(),
714                self.state.run_id
715            ));
716        }
717        self.state.phase = Phase::Paused;
718        self.state.paused = Some(Paused {
719            reason,
720            resume_phase,
721            message: message.clone(),
722            until,
723        });
724        self.note(LogEntry::State(StateEvent::Paused { reason, message }));
725        self.save()
726    }
727
728    /// False when there is no task yet, or git cannot give the diff.
729    fn write_pause_handover(&mut self) -> Result<bool, RunError> {
730        let next = self.state.attempt.unwrap_or(0) + 1;
731        match self.worker_prompt(next, true) {
732            Ok(prompt) => self.write_handover(next, &prompt).map(|()| true),
733            Err(_) => Ok(false),
734        }
735    }
736}
737
738fn finish_unanswered<T>(
739    last_pause: Option<(PauseReason, String, Option<u64>)>,
740    last_failed: Option<String>,
741) -> Asked<T> {
742    match last_pause {
743        Some((reason, message, until)) => Asked::Pause(reason, message, until),
744        None => Asked::Failed(last_failed.unwrap_or_else(|| "no usable lane".to_string())),
745    }
746}
747
748/// The phases a run stops in; the others are working phases.
749fn exit_of(phase: Phase) -> Option<Exit> {
750    match phase {
751        Phase::Paused => Some(Exit::Paused),
752        Phase::Done => Some(Exit::Done),
753        Phase::Failed => Some(Exit::Failed),
754        Phase::Planning | Phase::Executing | Phase::Reviewing => None,
755    }
756}
757
758fn handover_note(worktree: &Path) -> PathBuf {
759    worktree.join(".onerig").join("handover.md")
760}
761
762fn remove_if_present(path: &Path) -> Result<(), StoreError> {
763    match std::fs::remove_file(path) {
764        Err(e) if e.kind() != std::io::ErrorKind::NotFound => Err(StoreError::Io {
765            path: path.to_path_buf(),
766            message: e.to_string(),
767        }),
768        _ => Ok(()),
769    }
770}
771
772mod execute;
773mod review;
774#[cfg(test)]
775mod tests;