aios_core/governance/
mod.rs1use aios_spec::governance::{
9 ActionCoord, ActionOutcome, ActionProposal, AdapterError, EffectClass,
10};
11use aios_spec::intent::SuggestedAction;
12
13#[derive(Debug, Clone, serde::Serialize)]
19pub struct AuthorizedAction {
20 intent_id: String,
21 coord: ActionCoord,
22 action: SuggestedAction,
23 effect: EffectClass,
24 authorized_at_ms: i64,
25}
26
27impl AuthorizedAction {
28 pub(crate) fn seal(proposal: &ActionProposal, authorized_at_ms: i64) -> Self {
30 Self {
31 intent_id: proposal.intent_id.clone(),
32 coord: proposal.coord,
33 action: proposal.action.clone(),
34 effect: proposal.effect,
35 authorized_at_ms,
36 }
37 }
38
39 pub fn intent_id(&self) -> &str {
40 &self.intent_id
41 }
42
43 pub fn coord(&self) -> ActionCoord {
44 self.coord
45 }
46
47 pub fn action(&self) -> &SuggestedAction {
48 &self.action
49 }
50
51 pub fn effect(&self) -> EffectClass {
52 self.effect
53 }
54
55 pub fn authorized_at_ms(&self) -> i64 {
56 self.authorized_at_ms
57 }
58}
59
60pub trait ActionAdapter {
66 fn name(&self) -> &'static str;
67 fn execute(&self, authorized: &AuthorizedAction) -> Result<ActionOutcome, AdapterError>;
68}
69
70#[cfg(test)]
71mod tests {
72 use super::*;
73 use aios_spec::governance::ActionCoord;
74 use aios_spec::intent::{ActionType, ActionUrgency};
75
76 #[test]
77 fn seal_copies_proposal_fields() {
78 let proposal = ActionProposal {
79 intent_id: "intent-1".into(),
80 coord: ActionCoord {
81 window_ordinal: 1,
82 intent_ordinal: 2,
83 action_ordinal: 3,
84 },
85 action: SuggestedAction {
86 action_type: ActionType::NoOp,
87 target: None,
88 urgency: ActionUrgency::Immediate,
89 },
90 effect: EffectClass::PureRead,
91 proposed_at_ms: 1000,
92 };
93
94 let authorized = AuthorizedAction::seal(&proposal, 2000);
95 assert_eq!(authorized.intent_id(), "intent-1");
96 assert_eq!(authorized.coord(), proposal.coord);
97 assert!(matches!(authorized.action().action_type, ActionType::NoOp));
98 assert_eq!(authorized.effect(), EffectClass::PureRead);
99 assert_eq!(authorized.authorized_at_ms(), 2000);
100 }
101}