aidaemon_memory/
people_intelligence.rs1use std::sync::Arc;
4
5use tracing::{debug, error, info};
6
7use crate::stores::PeopleStore;
8
9pub struct PeopleIntelligence {
14 state: Arc<dyn PeopleStore>,
15 config: PeopleIntelligenceConfig,
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub struct PeopleIntelligenceConfig {
22 pub fact_retention_days: u32,
23 pub reconnect_reminder_days: u32,
24}
25
26impl PeopleIntelligence {
27 pub fn new(state: Arc<dyn PeopleStore>, config: PeopleIntelligenceConfig) -> Self {
28 Self { state, config }
29 }
30
31 pub async fn run_daily_checks(&self) {
34 match self
36 .state
37 .prune_stale_person_facts(self.config.fact_retention_days)
38 .await
39 {
40 Ok(pruned) => {
41 if pruned > 0 {
42 info!(
43 "People intelligence: pruned {} stale auto-extracted facts (>{} days old, unconfirmed)",
44 pruned, self.config.fact_retention_days
45 );
46 }
47 }
48 Err(e) => {
49 error!("People intelligence: failed to prune stale facts: {}", e);
50 }
51 }
52
53 match self.state.get_people_with_upcoming_dates(14).await {
55 Ok(upcoming) => {
56 if !upcoming.is_empty() {
57 info!(
58 "People intelligence: {} upcoming dates within 14 days",
59 upcoming.len()
60 );
61 for (person, fact) in &upcoming {
62 debug!(
63 "People intelligence: upcoming date for {} — [{}/{}]",
64 person.name, fact.category, fact.key
65 );
66 }
67 }
68 }
69 Err(e) => {
70 error!("People intelligence: failed to check upcoming dates: {}", e);
71 }
72 }
73
74 match self
76 .state
77 .get_people_needing_reconnect(self.config.reconnect_reminder_days)
78 .await
79 {
80 Ok(people) => {
81 if !people.is_empty() {
82 info!(
83 "People intelligence: {} people haven't been contacted in >{} days",
84 people.len(),
85 self.config.reconnect_reminder_days
86 );
87 for person in &people {
88 debug!(
89 "People intelligence: reconnect suggestion — {}",
90 person.name
91 );
92 }
93 }
94 }
95 Err(e) => {
96 error!(
97 "People intelligence: failed to check reconnect suggestions: {}",
98 e
99 );
100 }
101 }
102 }
103}