aidaemon 0.11.12

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
use super::*;

#[test]
fn reply_defers_file_access_detects_upload_requests() {
    for reply in [
        "I don't have access to that specific PDF file yet. Could you please upload the file or provide the full path to it on your system?",
        "Please provide the path to the file and I'll take a look.",
        "Could you attach the file so I can read it?",
        "I don't have direct access to that file just by its name.",
    ] {
        assert!(
            reply_defers_file_access(reply),
            "should detect deferred file access: {reply:?}"
        );
    }
}

#[test]
fn reply_defers_file_access_ignores_real_answers() {
    for reply in [
        "The offer letter is from WebFirst for a Lead Developer position starting in July.",
        "I found the file and read it — here's the summary.",
        "Done. The script now parses the path argument correctly.",
    ] {
        assert!(
            !reply_defers_file_access(reply),
            "false positive on: {reply:?}"
        );
    }
}

#[test]
fn user_text_references_file_detects_filenames_and_paths() {
    for text in [
        "Can you read the file and tell me what it's about? David Loor  WebFirst Offer Letter Lead Developer (1).pdf",
        "summarize ~/Downloads/report.docx",
        "what's in /tmp/output.log",
        "check notes.md please",
    ] {
        assert!(
            user_text_references_file(text),
            "should detect file reference: {text:?}"
        );
    }
}

#[test]
fn user_text_references_file_ignores_plain_chat() {
    for text in [
        "write me a poem about rust",
        "what's my cat's name?",
        "how do I improve my resume for tech jobs",
    ] {
        assert!(
            !user_text_references_file(text),
            "false positive on: {text:?}"
        );
    }
}

#[test]
fn test_infer_intent_gate_no_textual_fallback_inference() {
    // With lexical fallback inference disabled, an unarmed turn stays None.
    let gate = infer_intent_gate("check the site", "I can look it up.");
    assert_eq!(gate.needs_tools, None);
}

#[test]
fn test_infer_intent_gate_path_still_forces_tools() {
    // Deterministic rule: filesystem paths always require tools.
    let gate = infer_intent_gate("check /tmp/app.log", "I can look it up.");
    assert_eq!(gate.needs_tools, Some(true));
}

#[test]
fn test_user_text_references_filesystem_path_ignores_fractions_and_shorthand() {
    assert!(!user_text_references_filesystem_path("3/4"));
    assert!(!user_text_references_filesystem_path("2/14"));
    assert!(!user_text_references_filesystem_path("yes/no"));
    assert!(!user_text_references_filesystem_path("w/o"));
}

#[test]
fn test_user_text_references_filesystem_path_detects_common_paths_and_files() {
    assert!(user_text_references_filesystem_path(
        "/Users/alice/project/file.txt"
    ));
    assert!(user_text_references_filesystem_path("~/project/file.txt"));
    assert!(user_text_references_filesystem_path(
        "src/agent/main_loop.rs"
    ));
    assert!(user_text_references_filesystem_path("Cargo.toml"));
    assert!(user_text_references_filesystem_path(
        r"C:\\Users\\alice\\file.txt"
    ));
}

#[test]
fn test_user_explicitly_requests_local_file_inspection_detects_explicit_requests() {
    assert!(user_explicitly_requests_local_file_inspection(
        "Inspect Cargo.toml and read src/main.rs"
    ));
    assert!(user_explicitly_requests_local_file_inspection(
        "Search the repo for OAuth callback code"
    ));
}

#[test]
fn test_user_explicitly_requests_local_file_inspection_does_not_flag_api_only_turns() {
    assert!(!user_explicitly_requests_local_file_inspection(
        "Use the Twitter API to post a tweet"
    ));
    assert!(!user_explicitly_requests_local_file_inspection(
        "Check the connected API status"
    ));
}

#[test]
fn test_sanitize_response_analysis_strips_marker_and_pseudo_tool_block() {
    let input = "I recall it was deployed to Cloudflare Workers.\n\n\
                 [TEXT_ONLY_RESPONSE_MODE]\n\
                 [tool_use: terminal]\n\
                 cmd: find $HOME -name wrangler.toml\n\
                 args: {\"x\":1}";
    let out = sanitize_response_analysis(input);
    assert!(out.contains("I recall it was deployed to Cloudflare Workers."));
    assert!(!out.contains("TEXT_ONLY_RESPONSE_MODE"));
    assert!(!out.contains("[tool_use:"));
    assert!(!out.contains("cmd:"));
    assert!(!out.contains("args:"));
}

#[test]
fn test_sanitize_response_analysis_keeps_normal_cmd_text_without_tool_block() {
    let input = "Run this command manually:\ncmd: wrangler whoami";
    let out = sanitize_response_analysis(input);
    assert!(out.contains("cmd: wrangler whoami"));
}

#[test]
fn test_sanitize_response_analysis_strips_arguments_name_terminal_block() {
    let input = "I'll check config.\n\narguments:\nname: terminal";
    let out = sanitize_response_analysis(input);
    assert_eq!(out, "I'll check config.");
}

#[test]
fn test_sanitize_response_analysis_strips_echoed_important_instruction() {
    let input = "I don't have the exact URL yet.\n\n\
        [IMPORTANT: You are being consulted for your knowledge and reasoning. Respond with TEXT ONLY. Do NOT call any functions or tools. Do NOT output functionCall or tool_use blocks. Answer the user's question directly from your knowledge and the context provided.]";
    let out = sanitize_response_analysis(input);
    assert_eq!(out, "I don't have the exact URL yet.");
}

#[test]
fn test_looks_like_deferred_action_response_detects_planning_text() {
    // Action promises — any verb after "I'll" / "Let me" / "I will" that isn't knowledge-only
    assert!(looks_like_deferred_action_response(
        "I'll check the configuration for the Cloudflare Worker."
    ));
    assert!(looks_like_deferred_action_response(
        "Let me search and get back to you."
    ));
    assert!(looks_like_deferred_action_response(
        "I'll create a Python script to check the status."
    ));
    assert!(looks_like_deferred_action_response(
        "I'll run the tests and report back."
    ));
    assert!(looks_like_deferred_action_response(
        "Let me write a script for that."
    ));
    assert!(looks_like_deferred_action_response(
        "I will deploy the changes now."
    ));
    assert!(looks_like_deferred_action_response(
        "I'll need to check the full content of the audit report."
    ));
    assert!(looks_like_deferred_action_response(
        "I'll retrieve the complete text now."
    ));
    assert!(looks_like_deferred_action_response(
        "Let me read the file and send it to you."
    ));
    assert!(looks_like_deferred_action_response(
        "Shall I scan your projects folder?"
    ));
    assert!(looks_like_deferred_action_response(
        "Would you like me to install the dependencies?"
    ));
    assert!(looks_like_deferred_action_response(
        "I'll find your resume and send it over right away. Starting the send-resume workflow."
    ));
    // Structural markers
    assert!(looks_like_deferred_action_response(
        "I recall deploying to Workers.\n\n[Consultation]\nTo find the URL, I would typically inspect wrangler.toml."
    ));

    // Knowledge-only verbs — these DON'T need tools
    assert!(!looks_like_deferred_action_response(
        "I'll explain how it works."
    ));
    assert!(!looks_like_deferred_action_response(
        "Let me describe the architecture."
    ));
    assert!(!looks_like_deferred_action_response(
        "I will summarize the key points for you."
    ));
    assert!(!looks_like_deferred_action_response(
        "I'll clarify what that means."
    ));

    // Not action promises at all
    assert!(!looks_like_deferred_action_response(
        "The URL is https://example.workers.dev"
    ));
    assert!(!looks_like_deferred_action_response(
        "I checked the configuration already and it looks fine."
    ));
    assert!(!looks_like_deferred_action_response(
        "The searching process was completed successfully."
    ));
}

#[test]
fn detects_incomplete_retry_plan_despite_length() {
    let response = "I've started breaking down your goal into specific tasks. I've created a plan \
to first research the 2026 AI job market and then synthesize that into your personalized morning \
briefing.\n\nI attempted to launch a research specialist to begin the first phase, but the request \
timed out. I'm monitoring the system and will retry the research task as soon as the connection is \
stable.\n\nCurrent Plan:\n1. Research Phase: Deep dive into trends, roles, and skills.\n\
2. Synthesis Phase: Organize findings into a morning briefing.";
    assert!(looks_like_incomplete_retry_plan(response));
}

#[test]
fn completed_briefing_with_next_steps_is_not_an_incomplete_retry_plan() {
    let response = "Market Snapshot: AI hiring is concentrating around applied engineering. \
Target Roles: GenAI engineer and AI product manager. Interview Edge: prepare concrete evaluation \
and deployment examples. Next steps: tailor these findings to your experience.";
    assert!(!looks_like_incomplete_retry_plan(response));
}

#[test]
fn queued_background_specialist_ack_is_not_an_incomplete_retry_plan() {
    let response = "A research specialist is running in the background. The result will be \
delivered through this session when it completes.";
    assert!(!looks_like_incomplete_retry_plan(response));
}

#[test]
fn test_has_action_promise() {
    // Action verbs
    assert!(has_action_promise("i'll create a script"));
    assert!(has_action_promise("i will run the tests"));
    assert!(has_action_promise("let me check the file"));
    assert!(has_action_promise("i’ll find your resume and send it"));
    assert!(has_action_promise("shall i scan the folder"));
    assert!(has_action_promise("would you like me to install it"));

    // Knowledge verbs — not action promises
    assert!(!has_action_promise("i'll explain the concept"));
    assert!(!has_action_promise("let me describe it"));
    assert!(!has_action_promise("i will summarize the results"));
    assert!(!has_action_promise("i'll clarify that for you"));
    assert!(!has_action_promise("i'll provide an overview"));
    assert!(!has_action_promise("i'll be happy to help"));

    // No prefix pattern at all
    assert!(!has_action_promise("the file is located at /tmp/test"));
    assert!(!has_action_promise("here is the answer"));
}

#[test]
fn test_is_short_user_correction_detects_simple_correction() {
    assert!(is_short_user_correction("You did send me the pdf"));
    assert!(is_short_user_correction("that's right"));
}

#[test]
fn test_is_short_user_correction_ignores_new_action_requests() {
    assert!(!is_short_user_correction(
        "You did send me the pdf, can you make it nicer?"
    ));
    assert!(!is_short_user_correction("Please regenerate the PDF"));
}

#[test]
fn test_classify_stall_detects_deferred_no_tool_loop() {
    let learning_ctx = LearningContext {
        user_text: "Can you make the PDF nicer?".to_string(),
        intent_domains: vec![],
        tool_calls: vec![],
        errors: vec![(DEFERRED_NO_TOOL_ERROR_MARKER.to_string(), false)],
        first_error: None,
        recovery_actions: vec![],
        start_time: Utc::now(),
        completed_naturally: false,
        explicit_positive_signals: 0,
        explicit_negative_signals: 0,
        task_outcome: None,
        replay_notes: Vec::new(),
    };

    let (label, suggestion) = Agent::classify_stall(&learning_ctx);
    assert_eq!(label, "Deferred No-Tool Loop");
    assert!(suggestion.contains("rephrasing"));
}

#[test]
fn test_parse_wait_task_seconds_parses_supported_units() {
    assert_eq!(parse_wait_task_seconds("Wait for 5 minutes."), Some(300));
    assert_eq!(parse_wait_task_seconds("wait for 45 sec"), Some(45));
    assert_eq!(parse_wait_task_seconds("WAIT FOR 2 hours"), Some(7200));
}

#[test]
fn test_parse_wait_task_seconds_ignores_non_wait_tasks() {
    assert_eq!(parse_wait_task_seconds("Send the second joke."), None);
    assert_eq!(parse_wait_task_seconds("Wait until tomorrow."), None);
}

#[test]
fn test_sanitize_response_analysis_strips_consultation_heading() {
    let input =
        "I don't have the URL yet.\n\n[Consultation]\nTo find it I'd inspect wrangler.toml.";
    let out = sanitize_response_analysis(input);
    assert!(!out.contains("[Consultation]"));
}

#[test]
fn test_is_substantive_text_response_accepts_real_content() {
    // A greeting with enough substance should be accepted
    assert!(is_substantive_text_response(
        "Hola! Claro que sí, puedo hablar en español. ¿En qué puedo ayudarte hoy?",
        50
    ));

    // A capability listing should be accepted
    assert!(is_substantive_text_response(
        "Here are my main capabilities:\n\
         1. I can run terminal commands\n\
         2. I can search the web\n\
         3. I can read and write files\n\
         4. I can manage your schedule",
        50
    ));

    // A joke should be accepted
    assert!(is_substantive_text_response(
        "Here's a joke for you: Why do programmers prefer dark mode? Because light attracts bugs!",
        50
    ));
}

#[test]
fn test_is_substantive_text_response_rejects_short_text() {
    // Too short to be substantive
    assert!(!is_substantive_text_response("Sure!", 50));
    assert!(!is_substantive_text_response("OK, I can do that.", 50));
}

#[test]
fn test_is_substantive_text_response_rejects_pure_deferrals() {
    // Pure deferral text: every line is an action promise
    assert!(!is_substantive_text_response(
        "I'll search the web for that information and get back to you right away.",
        50
    ));

    // Short deferral
    assert!(!is_substantive_text_response(
        "Let me check that for you.",
        50
    ));
}

#[test]
fn test_is_substantive_text_response_accepts_mixed_content() {
    // Some deferred-looking phrasing mixed with real content — the
    // substantive parts exceed the min_len threshold.
    assert!(is_substantive_text_response(
        "I'll help you with that.\n\n\
         The capital of France is Paris. It is the largest city in France \
         and serves as the country's political, economic, and cultural center.",
        50
    ));
}

#[test]
fn test_claims_completed_side_effect_detects_past_tense_action_claims() {
    // The exact fabrication from the 2026-06-06 attribution run, turn 10:
    // zero tool calls were made, yet the model claimed the deletion happened.
    assert!(claims_completed_side_effect(
        "I have deleted the cachetest2 folder entirely."
    ));
    assert!(claims_completed_side_effect(
        "I've removed west.txt and cleaned up the directory."
    ));
    assert!(claims_completed_side_effect("I deleted the folder."));
    assert!(claims_completed_side_effect(
        "Done — I created the directory and wrote all four files for you."
    ));
    assert!(claims_completed_side_effect(
        "I have successfully executed the script."
    ));
    // Unicode apostrophe, same as has_action_promise handling.
    assert!(claims_completed_side_effect(
        "I\u{2019}ve updated north.txt."
    ));
}

#[test]
fn test_claims_completed_side_effect_ignores_non_claims() {
    // Future-tense promises are deferred actions, not completion claims.
    assert!(!claims_completed_side_effect("I'll delete the folder."));
    assert!(!claims_completed_side_effect(
        "Let me remove that file for you."
    ));
    // Plain informational replies.
    assert!(!claims_completed_side_effect(
        "Here are the contents of the three files."
    ));
    assert!(!claims_completed_side_effect(
        "The folder was already empty, nothing to do."
    ));
    // "I have" followed by a non-action word is not a claim.
    assert!(!claims_completed_side_effect(
        "I have a summary of the files for you."
    ));
    assert!(!claims_completed_side_effect(
        "I have to check the file before answering."
    ));
    // Knowledge verbs in past tense are not side effects.
    assert!(!claims_completed_side_effect(
        "I have explained the differences between the files above."
    ));
}

#[test]
fn test_claims_delegation_started_detects_unverified_agent_claims() {
    assert!(claims_delegation_started(
        "I've initiated a deep analysis using a specialized review agent."
    ));
    assert!(claims_delegation_started(
        "I started a research sub-agent to investigate this."
    ));
    assert!(claims_delegation_started(
        "A specialist agent is now running in the background."
    ));
    assert!(!claims_delegation_started(
        "I can analyze the resume directly."
    ));
    assert!(!claims_delegation_started(
        "The review agent pattern is useful for complex tasks."
    ));
}