termivar_scanner/decision_loop/
command.rs1use super::{Deserialize, Serialize, VerificationCase};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "snake_case")]
8#[non_exhaustive]
9pub enum DecisionActionOrigin {
10 Bootstrap,
12 Planned,
14 Adaptive,
16 Retry,
18}
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
22#[serde(rename_all = "snake_case")]
23#[non_exhaustive]
24pub enum DecisionStopReason {
25 ObjectiveComplete,
27 NoEligibleAction,
29 HumanReview,
31 AdaptationLimit,
33 ActionCycleLimit,
35 RuntimeBudgetLimit,
37 CancelledByHost,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
43#[serde(tag = "command", rename_all = "snake_case")]
44#[non_exhaustive]
45pub enum DecisionLoopCommand {
46 ExecuteAction {
48 case: VerificationCase,
50 executor: Option<String>,
52 origin: DecisionActionOrigin,
54 delay_ms: Option<u64>,
56 },
57 CollectActiveEvidence {
59 case: VerificationCase,
61 },
62 Replan,
64 Complete {
66 case: VerificationCase,
68 },
69 AwaitHumanReview {
71 case: VerificationCase,
73 },
74 Halt {
76 reason: DecisionStopReason,
78 },
79}
80
81pub(crate) fn command_requiring_host_policy_context(
82 command: &DecisionLoopCommand,
83) -> Option<&'static str> {
84 match command {
85 DecisionLoopCommand::ExecuteAction {
86 origin: DecisionActionOrigin::Adaptive,
87 ..
88 } => Some("adaptive_execute_action"),
89 DecisionLoopCommand::ExecuteAction {
90 origin: DecisionActionOrigin::Retry,
91 ..
92 } => Some("retry_execute_action"),
93 DecisionLoopCommand::CollectActiveEvidence { .. } => Some("collect_active_evidence"),
94 DecisionLoopCommand::Replan => Some("replan"),
95 DecisionLoopCommand::ExecuteAction { .. }
96 | DecisionLoopCommand::Complete { .. }
97 | DecisionLoopCommand::AwaitHumanReview { .. }
98 | DecisionLoopCommand::Halt { .. } => None,
99 }
100}
101
102pub(crate) fn execution_command_action_id(command: &DecisionLoopCommand) -> Option<&str> {
103 match command {
104 DecisionLoopCommand::ExecuteAction { case, .. }
105 | DecisionLoopCommand::CollectActiveEvidence { case } => Some(case.action_id()),
106 DecisionLoopCommand::Replan
107 | DecisionLoopCommand::Complete { .. }
108 | DecisionLoopCommand::AwaitHumanReview { .. }
109 | DecisionLoopCommand::Halt { .. } => None,
110 }
111}