Skip to main content

termivar_scanner/decision_loop/
receipts.rs

1//! Immutable reasoning, planning, and outcome audit receipts.
2
3use super::{
4    AdaptiveDecision, AttackPlan, BTreeSet, DecisionLoopCommand, DecisionSessionTransition,
5    EntityId, ExperienceWrite, KnowledgeWrite, RuleApplication, Serialize, VerificationReport,
6};
7
8/// Reasoning applications committed before a later planning-stage failure.
9///
10/// This receipt describes one successful in-memory [`crate::RuleEngine::apply`]
11/// transaction and its exact [`KnowledgeWrite`] statuses. It does not imply
12/// durable persistence. A rule evaluation remains the pre-commit candidate;
13/// hosts must query the knowledge base when verifier-owned terminal-state
14/// preservation makes the stored hypothesis relevant.
15#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
16pub struct DecisionReasoningCommitReceipt {
17    pub(super) subject: EntityId,
18    pub(super) planner_subject_revision: u64,
19    pub(super) planner_ontology_revision: u64,
20    pub(super) rule_applications: Vec<RuleApplication>,
21}
22
23impl DecisionReasoningCommitReceipt {
24    /// Returns the subject whose hypotheses were evaluated and committed.
25    pub fn subject(&self) -> &EntityId {
26        &self.subject
27    }
28
29    /// Returns the subject revision captured by the attempted planner snapshot.
30    pub fn planner_subject_revision(&self) -> u64 {
31        self.planner_subject_revision
32    }
33
34    /// Returns the ontology revision captured by the attempted planner snapshot.
35    pub fn planner_ontology_revision(&self) -> u64 {
36        self.planner_ontology_revision
37    }
38
39    /// Returns deterministic applications and their exact write results.
40    pub fn rule_applications(&self) -> &[RuleApplication] {
41        &self.rule_applications
42    }
43}
44
45/// Audit record produced by a reasoning and planning turn.
46#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
47pub struct DecisionPlanningReport {
48    pub(super) rule_applications: Vec<RuleApplication>,
49    pub(super) plan: AttackPlan,
50    #[serde(skip_serializing)]
51    pub(super) policy_authorized_plan: AttackPlan,
52    pub(super) suppressed_actions: BTreeSet<String>,
53    #[serde(skip_serializing)]
54    pub(super) session_transition: DecisionSessionTransition,
55    pub(super) command: DecisionLoopCommand,
56}
57
58impl DecisionPlanningReport {
59    /// Returns deterministic reasoning applications in rule-ID order.
60    pub fn rule_applications(&self) -> &[RuleApplication] {
61        &self.rule_applications
62    }
63
64    /// Returns the complete planner audit record.
65    pub fn plan(&self) -> &AttackPlan {
66        &self.plan
67    }
68
69    pub(crate) fn policy_authorized_plan(&self) -> &AttackPlan {
70        &self.policy_authorized_plan
71    }
72
73    /// Returns suppressions applied to this planning cycle.
74    pub fn suppressed_actions(&self) -> &BTreeSet<String> {
75        &self.suppressed_actions
76    }
77
78    /// Returns the session transition committed by this successful planning turn.
79    ///
80    /// This audit summary is intentionally excluded from the existing serialized
81    /// planning-report shape.
82    pub fn session_transition(&self) -> &DecisionSessionTransition {
83        &self.session_transition
84    }
85
86    /// Returns the runner command selected for this turn.
87    pub fn command(&self) -> &DecisionLoopCommand {
88        &self.command
89    }
90}
91
92/// Audit record produced by a passive or active verification turn.
93#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
94pub struct DecisionOutcomeReport {
95    pub(super) verification: VerificationReport,
96    pub(super) adaptive: AdaptiveDecision,
97    pub(super) experience_write: ExperienceWrite,
98    pub(super) hypothesis_write: Option<KnowledgeWrite>,
99    #[serde(skip_serializing)]
100    pub(super) session_transition: DecisionSessionTransition,
101    pub(super) command: DecisionLoopCommand,
102}
103
104impl DecisionOutcomeReport {
105    /// Returns the verifier outcome and rule trace.
106    pub fn verification(&self) -> &VerificationReport {
107        &self.verification
108    }
109
110    /// Returns the adaptive policy decision.
111    pub fn adaptive(&self) -> &AdaptiveDecision {
112        &self.adaptive
113    }
114
115    /// Returns whether experience inserted or already knew the outcome.
116    pub fn experience_write(&self) -> ExperienceWrite {
117        self.experience_write
118    }
119
120    /// Returns the verifier-owned hypothesis state write when the outcome is
121    /// conclusive and its case authorizes a transition.
122    pub fn hypothesis_write(&self) -> Option<KnowledgeWrite> {
123        self.hypothesis_write
124    }
125
126    /// Returns the session transition applied during successful outcome processing.
127    ///
128    /// Candidate state makes normal returned-error paths error-atomic. This is
129    /// not a cross-store or crash-atomic persistence guarantee.
130    pub fn session_transition(&self) -> &DecisionSessionTransition {
131        &self.session_transition
132    }
133
134    /// Returns the next runner command.
135    pub fn command(&self) -> &DecisionLoopCommand {
136        &self.command
137    }
138}