Skip to main content

quanttide_work/criterion/
items.rs

1//! 判据翻成「要跑什么」:规则引擎跑,智能体 / 人不跑。
2//!
3//! 模型在 [`super::model`];把一条条判据翻成要跑的东西,
4//! 真去跑(文件系统、起进程)是各自包的事。
5//! 出处:`docs/specification/process/workflow.md`·语法(判据判法)。
6
7use super::model::{Criterion, RuleKind};
8
9/// 一条要跑的判据:说明 + 怎么判(`kind` 为空即不跑,交给智能体或人)。
10#[derive(Debug, Clone)]
11pub struct RuleItem {
12    pub description: String,
13    pub kind: Option<RuleKind>,
14    pub args: Vec<String>,
15}
16
17impl RuleItem {
18    pub fn machine(&self) -> bool {
19        self.kind.is_some()
20    }
21}
22
23/// 把判据翻成要跑的东西:rule 的跑,agent / human 的不跑。
24pub fn items_of(criteria: &[Criterion]) -> Vec<RuleItem> {
25    criteria
26        .iter()
27        .map(|criterion| {
28            let description = criterion.text();
29            let (kind, args) = match criterion {
30                Criterion::PathExists { path, .. } => {
31                    (Some(RuleKind::PathExists), vec![path.clone()])
32                }
33                Criterion::PathAbsent { absent, .. } => {
34                    (Some(RuleKind::PathAbsent), vec![absent.clone()])
35                }
36                Criterion::FileContains { file, contains, .. } => (
37                    Some(RuleKind::FileContains),
38                    vec![file.clone(), contains.clone()],
39                ),
40                Criterion::CommandRun { run, .. } => {
41                    (Some(RuleKind::CommandRun), vec![run.clone()])
42                }
43                Criterion::AgentJudgement { .. } | Criterion::HumanGate { .. } => {
44                    (None, Vec::new())
45                }
46            };
47            RuleItem {
48                description,
49                kind,
50                args,
51            }
52        })
53        .collect()
54}