aidaemon 0.11.5

A personal AI agent that runs as a background daemon, accessible via Telegram, Slack, or Discord, with tool use, MCP integration, and persistent memory
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
// ==========================================================================
// Channel-Scoped Memory Privacy Tests
//
// These tests verify the privacy model: facts are scoped by channel,
// cross-channel hints work correctly, DMs access everything, and
// PublicExternal is fully locked down.
// ==========================================================================

/// Facts are NOT bulk-injected into the system prompt — accessed on demand via tools.
/// The system prompt should contain the memory capabilities summary instead.
#[tokio::test]
async fn test_same_channel_fact_recall() {
    let harness = setup_test_agent(MockProvider::new()).await.unwrap();

    harness
        .state
        .upsert_fact(
            "project",
            "framework",
            "NextJS with TypeScript",
            "user",
            Some("slack:C_ABC"),
            crate::types::FactPrivacy::Channel,
        )
        .await
        .unwrap();

    harness
        .agent
        .handle_message(
            "same_ch_session",
            "what framework are we using?",
            None,
            UserRole::Owner,
            ChannelContext {
                visibility: ChannelVisibility::Public,
                platform: "slack".to_string(),
                channel_name: Some("#dev".to_string()),
                channel_id: Some("slack:C_ABC".to_string()),
                sender_name: None,
                sender_id: None,
                channel_member_names: vec![],
                user_id_map: std::collections::HashMap::new(),
                trusted: false,
            },
            None,
        )
        .await
        .unwrap();

    let call_log = harness.provider.call_log.lock().await;
    let content_owned: String = call_log[0]
        .messages
        .iter()
        .filter(|m| m["role"] == "system")
        .filter_map(|m| m["content"].as_str())
        .collect::<Vec<_>>()
        .join("\n");
    let content = content_owned.as_str();
    // Facts are on-demand now, NOT injected into prompt
    assert!(
        !content.contains("NextJS"),
        "Facts should NOT be bulk-injected into system prompt"
    );
    assert!(
        content.contains("Your Memory"),
        "System prompt should contain memory capabilities summary"
    );
}

/// Store a channel-scoped fact, query from a DIFFERENT channel → fact NOT in prompt.
#[tokio::test]
async fn test_cross_channel_fact_blocked() {
    let harness = setup_test_agent(MockProvider::new()).await.unwrap();

    // Store a channel-scoped fact in channel A
    harness
        .state
        .upsert_fact(
            "project",
            "secret_plan",
            "Launch product in March",
            "user",
            Some("slack:C_ALPHA"),
            crate::types::FactPrivacy::Channel,
        )
        .await
        .unwrap();

    // Query from a DIFFERENT channel B
    harness
        .agent
        .handle_message(
            "cross_ch_session",
            "what is our launch plan?",
            None,
            UserRole::Owner,
            ChannelContext {
                visibility: ChannelVisibility::Public,
                platform: "slack".to_string(),
                channel_name: Some("#general".to_string()),
                channel_id: Some("slack:C_BETA".to_string()),
                sender_name: None,
                sender_id: None,
                channel_member_names: vec![],
                user_id_map: std::collections::HashMap::new(),
                trusted: false,
            },
            None,
        )
        .await
        .unwrap();

    let call_log = harness.provider.call_log.lock().await;
    let content_owned: String = call_log[0]
        .messages
        .iter()
        .filter(|m| m["role"] == "system")
        .filter_map(|m| m["content"].as_str())
        .collect::<Vec<_>>()
        .join("\n");
    let content = content_owned.as_str();

    // The fact should NOT be in the main facts section
    // (It may appear in cross-channel hints section, which is expected)
    let facts_section_end = content
        .find("Cross-Channel Context")
        .unwrap_or(content.len());
    let facts_section = &content[..facts_section_end];
    assert!(
        !facts_section.contains("Launch product in March"),
        "Channel-scoped fact from another channel should NOT appear in main facts"
    );
}

/// DM conversations: facts are accessed on demand via tools, not bulk-injected.
#[tokio::test]
async fn test_dm_recalls_all_facts() {
    let harness = setup_test_agent(MockProvider::new()).await.unwrap();

    harness
        .agent
        .handle_message(
            "dm_all_facts",
            "what do you know about my guitar hobby",
            None,
            UserRole::Owner,
            ChannelContext::private("telegram"),
            None,
        )
        .await
        .unwrap();

    let call_log = harness.provider.call_log.lock().await;
    let content_owned: String = call_log[0]
        .messages
        .iter()
        .filter(|m| m["role"] == "system")
        .filter_map(|m| m["content"].as_str())
        .collect::<Vec<_>>()
        .join("\n");
    let content = content_owned.as_str();

    // Facts are on-demand — system prompt has capabilities, not data
    assert!(
        content.contains("manage_memories"),
        "DM prompt should reference manage_memories for on-demand fact retrieval"
    );
}

/// Private facts should NEVER appear in any channel — not even hinted.
#[tokio::test]
async fn test_private_facts_never_in_channels() {
    let harness = setup_test_agent(MockProvider::new()).await.unwrap();

    harness
        .state
        .upsert_fact(
            "preference",
            "travel",
            "Prefers window seats on flights",
            "user",
            None,
            crate::types::FactPrivacy::Private,
        )
        .await
        .unwrap();

    // Query from a public channel
    harness
        .agent
        .handle_message(
            "priv_fact_session",
            "what health info do you have about me?",
            None,
            UserRole::Owner,
            ChannelContext {
                visibility: ChannelVisibility::Public,
                platform: "slack".to_string(),
                channel_name: Some("#general".to_string()),
                channel_id: Some("slack:C_GEN".to_string()),
                sender_name: None,
                sender_id: None,
                channel_member_names: vec![],
                user_id_map: std::collections::HashMap::new(),
                trusted: false,
            },
            None,
        )
        .await
        .unwrap();

    let call_log = harness.provider.call_log.lock().await;
    let content_owned: String = call_log[0]
        .messages
        .iter()
        .filter(|m| m["role"] == "system")
        .filter_map(|m| m["content"].as_str())
        .collect::<Vec<_>>()
        .join("\n");
    let content = content_owned.as_str();

    assert!(
        !content.contains("window seats") && !content.contains("Prefers window"),
        "Private facts must NEVER appear in public channel prompts"
    );
}

/// Cross-channel hints: channel-scoped fact from another channel should
/// appear in the hints section (not the main facts section).
#[tokio::test]
async fn test_cross_channel_hints() {
    let harness = setup_test_agent(MockProvider::new()).await.unwrap();

    // Store a channel-scoped fact in channel A
    harness
        .state
        .upsert_fact(
            "project",
            "framework",
            "Uses React for frontend",
            "user",
            Some("slack:C_DEV"),
            crate::types::FactPrivacy::Channel,
        )
        .await
        .unwrap();

    // Query from a DIFFERENT public channel B about something related
    harness
        .agent
        .handle_message(
            "hints_session",
            "what frontend framework should we use?",
            None,
            UserRole::Owner,
            ChannelContext {
                visibility: ChannelVisibility::Public,
                platform: "slack".to_string(),
                channel_name: Some("#general".to_string()),
                channel_id: Some("slack:C_GEN".to_string()),
                sender_name: None,
                sender_id: None,
                channel_member_names: vec![],
                user_id_map: std::collections::HashMap::new(),
                trusted: false,
            },
            None,
        )
        .await
        .unwrap();

    let call_log = harness.provider.call_log.lock().await;
    let content_owned: String = call_log[0]
        .messages
        .iter()
        .filter(|m| m["role"] == "system")
        .filter_map(|m| m["content"].as_str())
        .collect::<Vec<_>>()
        .join("\n");
    let content = content_owned.as_str();

    // The cross-channel hint section may or may not appear depending on embedding similarity.
    // What matters is that the fact does NOT appear in the main facts section as a normal fact.
    // If it does appear, it should only be in the cross-channel hints section.
    if content.contains("React") {
        assert!(
            content.contains("Cross-Channel Context"),
            "If React appears, it should be in cross-channel hints section, not main facts"
        );
    }
}

/// Legacy facts (NULL channel_id) should be accessible everywhere — backward compat.
#[tokio::test]
async fn test_legacy_facts_backward_compat() {
    let harness = setup_test_agent(MockProvider::new()).await.unwrap();

    // Store a legacy fact (no channel_id, Global privacy — the default for old facts)
    harness
        .state
        .upsert_fact(
            "preference",
            "editor",
            "Uses Neovim",
            "agent",
            None,
            crate::types::FactPrivacy::Global,
        )
        .await
        .unwrap();

    // Query from a public channel
    harness
        .agent
        .handle_message(
            "legacy_session",
            "what editor do I use?",
            None,
            UserRole::Owner,
            ChannelContext {
                visibility: ChannelVisibility::Public,
                platform: "slack".to_string(),
                channel_name: Some("#dev".to_string()),
                channel_id: Some("slack:C_DEV".to_string()),
                sender_name: None,
                sender_id: None,
                channel_member_names: vec![],
                user_id_map: std::collections::HashMap::new(),
                trusted: false,
            },
            None,
        )
        .await
        .unwrap();

    let call_log = harness.provider.call_log.lock().await;
    let content_owned: String = call_log[0]
        .messages
        .iter()
        .filter(|m| m["role"] == "system")
        .filter_map(|m| m["content"].as_str())
        .collect::<Vec<_>>()
        .join("\n");
    let content = content_owned.as_str();
    // Facts are on-demand now — not bulk-injected into system prompt
    assert!(
        !content.contains("Neovim"),
        "Facts should NOT be bulk-injected into system prompt"
    );
    assert!(
        content.contains("Your Memory"),
        "System prompt should contain memory capabilities summary"
    );
}

/// Privacy upgrade: after update_fact_privacy, a channel-scoped fact becomes globally accessible.
#[tokio::test]
async fn test_privacy_upgrade() {
    let harness = setup_test_agent(MockProvider::new()).await.unwrap();

    // Store a channel-scoped fact
    harness
        .state
        .upsert_fact(
            "project",
            "deadline",
            "March 15th launch",
            "user",
            Some("slack:C_PROJ"),
            crate::types::FactPrivacy::Channel,
        )
        .await
        .unwrap();

    // Verify it's not accessible from another channel
    let facts_before = harness
        .state
        .get_relevant_facts_for_channel(
            "launch deadline",
            10,
            Some("slack:C_OTHER"),
            ChannelVisibility::Public,
            true,
        )
        .await
        .unwrap();
    let _has_deadline_before = facts_before.iter().any(|f| f.value.contains("March 15th"));

    // Upgrade the fact to Global
    let all_facts = harness.state.get_all_facts_with_provenance().await.unwrap();
    let deadline_fact = all_facts.iter().find(|f| f.key == "deadline").unwrap();
    harness
        .state
        .update_fact_privacy(deadline_fact.id, crate::types::FactPrivacy::Global)
        .await
        .unwrap();

    // Now it should be accessible from the other channel
    let facts_after = harness
        .state
        .get_relevant_facts_for_channel(
            "launch deadline",
            10,
            Some("slack:C_OTHER"),
            ChannelVisibility::Public,
            true,
        )
        .await
        .unwrap();
    let _has_deadline_after = facts_after.iter().any(|f| f.value.contains("March 15th"));

    // After upgrade, the fact should be findable (before it may or may not due to embedding similarity)
    // At minimum, verify the privacy was actually updated
    let updated_facts = harness.state.get_all_facts_with_provenance().await.unwrap();
    let updated = updated_facts.iter().find(|f| f.key == "deadline").unwrap();
    assert_eq!(
        updated.privacy,
        crate::types::FactPrivacy::Global,
        "Fact privacy should be upgraded to Global"
    );
}

/// ManageMemoriesTool (list action) should return facts with provenance info.
#[tokio::test]
async fn test_memory_management_list() {
    let harness = setup_test_agent(MockProvider::new()).await.unwrap();

    harness
        .state
        .upsert_fact(
            "project",
            "lang",
            "Rust",
            "user",
            Some("slack:C_DEV"),
            crate::types::FactPrivacy::Channel,
        )
        .await
        .unwrap();
    harness
        .state
        .upsert_fact(
            "personal",
            "name",
            "Alice",
            "user",
            None,
            crate::types::FactPrivacy::Global,
        )
        .await
        .unwrap();

    let all_facts = harness.state.get_all_facts_with_provenance().await.unwrap();
    assert!(all_facts.len() >= 2, "Should have at least 2 facts");

    // Verify facts have the expected provenance
    let lang_fact = all_facts.iter().find(|f| f.key == "lang").unwrap();
    assert_eq!(lang_fact.channel_id.as_deref(), Some("slack:C_DEV"));
    assert_eq!(lang_fact.privacy, crate::types::FactPrivacy::Channel);

    let name_fact = all_facts.iter().find(|f| f.key == "name").unwrap();
    assert_eq!(name_fact.channel_id, None);
    assert_eq!(name_fact.privacy, crate::types::FactPrivacy::Global);
}