aidaemon_memory/
policy.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum TurnAuthor {
8 Person,
10 Synthetic,
13}
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum MemoryPipelinePolicy {
18 Allowed,
19 SuppressedByCurrentContract,
21 RecallOnlyNonUserTurn,
25}
26
27impl MemoryPipelinePolicy {
28 pub const fn compile(author: TurnAuthor, user_memory_forbidden: bool) -> Self {
32 if user_memory_forbidden {
33 Self::SuppressedByCurrentContract
34 } else if matches!(author, TurnAuthor::Person) {
35 Self::Allowed
36 } else {
37 Self::RecallOnlyNonUserTurn
38 }
39 }
40
41 pub const fn allows_memory(self) -> bool {
43 matches!(self, Self::Allowed)
44 }
45
46 pub const fn allows_recall(self) -> bool {
48 matches!(self, Self::Allowed | Self::RecallOnlyNonUserTurn)
49 }
50
51 pub const fn reason_code(self) -> &'static str {
52 match self {
53 Self::Allowed => "allowed_by_compiled_contract",
54 Self::SuppressedByCurrentContract => "inherited_contract_denies_user_memory",
55 Self::RecallOnlyNonUserTurn => "non_user_turn_recall_only",
56 }
57 }
58}
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn a_forbidding_request_wins_and_synthetic_turns_only_recall() {
66 let person = MemoryPipelinePolicy::compile(TurnAuthor::Person, false);
67 assert!(person.allows_memory() && person.allows_recall());
68 let synthetic = MemoryPipelinePolicy::compile(TurnAuthor::Synthetic, false);
69 assert!(synthetic.allows_recall() && !synthetic.allows_memory());
70 for author in [TurnAuthor::Person, TurnAuthor::Synthetic] {
71 let denied = MemoryPipelinePolicy::compile(author, true);
72 assert!(!denied.allows_recall() && !denied.allows_memory());
73 }
74 }
75}