Skip to main content

rinne_types/
evaluator.rs

1//! The `Evaluator` trait seam (`MCP_SKILLS.md` §15).
2//!
3//! An evaluator grades a node and emits a gate decision. Tool, AI, and human
4//! evaluators are impls behind this trait; the loop selects one by the node's
5//! evaluator kind and grades through the seam, never through a concrete type.
6//! The engine-specific services an evaluator needs (run a command, run an AI
7//! worker) are provided by an [`EvalContext`] the loop implements, so the
8//! evaluators stay free of engine internals.
9
10use std::path::Path;
11
12use async_trait::async_trait;
13
14use crate::dag::{Node, OnFail};
15use crate::Result;
16
17/// An evaluator's decision on a node.
18pub enum Gate {
19    /// The node passes; the graph advances.
20    Pass,
21    /// The node fails; `on_fail` runs with this critique.
22    Fail { critique: String, policy: OnFail },
23    /// A human evaluator with no input yet — park for the user.
24    Park { question: String },
25}
26
27/// Engine services an evaluator can call. The loop implements this; the
28/// evaluator impls depend only on it, not on the engine. `?Send` because the
29/// engine runs on a single-threaded runtime over a `!Sync` blackboard.
30#[async_trait(?Send)]
31pub trait EvalContext {
32    /// The workspace the run operates on.
33    fn workspace(&self) -> &Path;
34
35    /// Run a tool evaluator's acceptance command for `node`; returns
36    /// `(passed, combined_output)`.
37    async fn run_tool(&self, node: &Node, command: &str, must_exit: i32) -> Result<(bool, String)>;
38
39    /// Run an AI worker on evaluator `node` with `extra_instruction` appended;
40    /// returns its review text, or `None` if no capable worker is available.
41    async fn run_ai(&self, node: &Node, extra_instruction: &str) -> Result<Option<String>>;
42}
43
44/// One evaluation strategy. The loop dispatches grading through this seam.
45#[async_trait(?Send)]
46pub trait Evaluator {
47    /// Grade `node`, using `ctx` for any engine services, into a [`Gate`].
48    async fn grade(&self, node: &Node, ctx: &dyn EvalContext) -> Result<Gate>;
49}