lwc 0.17.11

Agent-driven proactive memory CLI for AI agents — autonomously recall, maintain, and evolve persistent, source-grounded knowledge across sessions.
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
const MAX_PROMPT_CHARS: usize = 4_096;

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub(crate) struct ProjectEvidence {
    pub(crate) has_code: bool,
    pub(crate) has_documents: bool,
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub(crate) enum MemoryIntent {
    #[default]
    None,
    Recall,
    Record,
    Status,
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub(crate) enum BookFormatEvidence {
    #[default]
    None,
    Supported,
    Unsupported,
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub(crate) struct IntentSet {
    pub(crate) plan: bool,
    pub(crate) todo: bool,
    pub(crate) work: bool,
    pub(crate) sync: bool,
    pub(crate) ingest: bool,
    pub(crate) changeset: bool,
    pub(crate) memory: bool,
    pub(crate) wiki: bool,
    pub(crate) document_graph: bool,
    pub(crate) code_graph: bool,
    pub(crate) tutor: bool,
    pub(crate) practice: bool,
    pub(crate) book: bool,
    pub(crate) office: bool,
    pub(crate) trans: bool,
    pub(crate) memory_intent: MemoryIntent,
    pub(crate) book_format: BookFormatEvidence,
}

pub(crate) fn classify(prompt: &str, evidence: ProjectEvidence) -> IntentSet {
    let text = prompt
        .chars()
        .take(MAX_PROMPT_CHARS)
        .flat_map(char::to_lowercase)
        .collect::<String>();
    let words = ascii_words(&text);

    let plan = has_word(&words, &["plan", "roadmap", "planning"])
        || has_zh(
            &text,
            &[
                "当前计划",
                "执行计划",
                "制定计划",
                "更新计划",
                "继续计划",
                "创建计划",
                "计划下一步",
            ],
        );
    let todo = has_word(&words, &["todo"])
        || has_any_phrase(
            &words,
            &[
                &["task", "list"],
                &["to", "do", "list"],
                &["add", "a", "todo"],
            ],
        )
        || has_zh(&text, &["待办", "任务清单"]);
    let work = has_any_phrase(
        &words,
        &[
            &["background", "work"],
            &["work", "item"],
            &["long", "running", "work"],
            &["job", "status"],
            &["running", "job"],
            &["resume", "work"],
            &["lwc", "work"],
        ],
    ) || has_zh(
        &text,
        &["后台任务", "长任务", "工作项", "工作状态", "异步任务"],
    );
    let sync = has_word(&words, &["sync", "synchronize", "synchronise"])
        || has_zh(
            &text,
            &["项目同步", "同步项目", "同步到", "跨机器同步", "恢复同步"],
        );
    let ingest = has_word(&words, &["ingest", "ingestion"])
        || has_any_phrase(
            &words,
            &[
                &["import", "source"],
                &["import", "sources"],
                &["add", "source"],
                &["add", "sources"],
                &["source", "import"],
                &["source", "ingestion"],
                &["integrate", "source"],
            ],
        )
        || has_zh(
            &text,
            &[
                "导入资料",
                "导入来源",
                "资料入库",
                "知识入库",
                "摄取来源",
                "整合来源",
            ],
        );
    let changeset = has_word(&words, &["changeset"])
        || has_any_phrase(&words, &[&["change", "set"], &["draft", "changes"]])
        || has_zh(&text, &["变更集", "草稿变更", "原子变更"]);
    let memory_context = has_any_phrase(
        &words,
        &[
            &["lwc", "memory"],
            &["durable", "memory"],
            &["persistent", "memory"],
            &["project", "memory"],
        ],
    ) || has_zh(&text, &["持久记忆", "长期记忆", "项目记忆"]);
    let memory_recall = has_any_phrase(
        &words,
        &[
            &["memory", "recall"],
            &["recall", "our"],
            &["recall", "from", "memory"],
            &["search", "memory"],
        ],
    ) || has_zh(
        &text,
        &["回忆我们", "回忆项目记忆", "回忆持久记忆", "从记忆中回忆"],
    );
    let memory_record = has_any_phrase(
        &words,
        &[
            &["remember", "this"],
            &["remember", "that"],
            &["remember", "decision"],
            &["save", "to", "memory"],
            &["record", "in", "memory"],
            &["store", "in", "memory"],
        ],
    ) || (memory_context
        && has_word(&words, &["save", "record", "store"])
        && has_word(&words, &["to", "in"]))
        || has_zh(
            &text,
            &[
                "保存到记忆",
                "保存到持久记忆",
                "记住这个",
                "记住这项",
                "记录到记忆",
            ],
        );
    let memory_status = has_any_phrase(
        &words,
        &[
            &["memory", "status"],
            &["lwc", "memory", "pressure"],
            &["durable", "memory", "pressure"],
            &["persistent", "memory", "pressure"],
            &["project", "memory", "pressure"],
            &["memory", "maintenance"],
            &["maintain", "lwc", "memory"],
            &["maintain", "durable", "memory"],
            &["maintain", "persistent", "memory"],
            &["maintain", "project", "memory"],
        ],
    ) || has_zh(
        &text,
        &[
            "记忆状态",
            "记忆压力",
            "维护持久记忆",
            "维护长期记忆",
            "维护项目记忆",
        ],
    );
    let memory_intent = match (memory_recall, memory_record, memory_status) {
        (true, false, false) => MemoryIntent::Recall,
        (false, true, false) => MemoryIntent::Record,
        (false, false, true) => MemoryIntent::Status,
        _ => MemoryIntent::None,
    };
    let memory = memory_context || memory_recall || memory_record || memory_status;
    let wiki = has_word(&words, &["wiki"])
        || has_any_phrase(&words, &[&["knowledge", "base"], &["project", "knowledge"]])
        || has_zh(&text, &["项目维基", "维基页面", "知识库", "项目知识"]);

    let document_graph_intent = has_any_phrase(
        &words,
        &[
            &["document", "graph"],
            &["knowledge", "graph"],
            &["wiki", "graph"],
            &["document", "relationships"],
            &["relationships", "between", "documents"],
            &["citation", "graph"],
            &["linked", "documents"],
            &["document", "neighbors"],
            &["document", "impact"],
        ],
    ) || has_zh(
        &text,
        &[
            "文档图",
            "知识图谱",
            "文档关系",
            "页面关系",
            "引用关系",
            "维基链接",
            "文档关联",
            "页面关联",
        ],
    );
    let code_graph_intent = has_any_phrase(
        &words,
        &[
            &["code", "graph"],
            &["call", "graph"],
            &["code", "structure"],
            &["symbol", "references"],
            &["find", "references"],
            &["dependency", "graph"],
            &["class", "hierarchy"],
            &["function", "callers"],
            &["code", "impact"],
        ],
    ) || has_zh(
        &text,
        &[
            "代码图",
            "代码结构",
            "调用图",
            "调用链",
            "符号引用",
            "查找引用",
            "代码依赖图",
            "类层次",
            "函数调用者",
            "代码影响分析",
        ],
    );

    let tutor = has_word(&words, &["tutor"])
        || has_any_phrase(
            &words,
            &[
                &["teach", "me"],
                &["start", "a", "lesson"],
                &["start", "lesson"],
                &["learning", "session"],
            ],
        )
        || has_zh(&text, &["辅导我", "请教我", "教我", "教学会话", "开始学习"]);
    let practice = has_any_phrase(
        &words,
        &[
            &["start", "practice"],
            &["begin", "practice"],
            &["practice", "session"],
            &["practice", "questions"],
            &["quiz", "me"],
            &["flash", "cards"],
            &["spaced", "repetition"],
            &["grade", "my", "answer"],
            &["review", "schedule"],
            &["practice", "paper"],
            &["mock", "exam"],
        ],
    ) || has_word(&words, &["flashcards"])
        || has_zh(
            &text,
            &[
                "开始练习",
                "练习题",
                "测验我",
                "抽认卡",
                "间隔复习",
                "练习记录",
                "答题会话",
                "模拟试卷",
            ],
        );
    let supported_book_file = has_file_extension(&text, &["epub", "txt", "md", "markdown", "pdf"]);
    let unsupported_book_file = has_file_extension(&text, &["html", "htm", "mobi", "azw3"]);
    let book_action = has_word(&words, &["read", "open", "import", "study", "finish"]);
    let book_phrase = has_any_phrase(
        &words,
        &[
            &["read", "this", "book"],
            &["read", "the", "book"],
            &["whole", "book"],
            &["entire", "book"],
            &["book", "reading"],
            &["import", "a", "book"],
            &["import", "this", "book"],
            &["finish", "this", "book"],
            &["study", "this", "book"],
        ],
    ) || (has_word(&words, &["book"]) && book_action)
        || has_zh(
            &text,
            &[
                "读这本书",
                "看这本书",
                "阅读整本书",
                "导入书籍",
                "整本阅读",
                "读完这本书",
            ],
        );
    let book_only_file = has_file_extension(&text, &["epub", "mobi", "azw3"]);
    let book = book_phrase || (book_only_file && book_action);
    let book_format = if !book {
        BookFormatEvidence::None
    } else if unsupported_book_file {
        BookFormatEvidence::Unsupported
    } else if supported_book_file {
        BookFormatEvidence::Supported
    } else {
        BookFormatEvidence::None
    };

    let office_file = has_file_extension(&text, &["docx", "xlsx", "pptx"]);
    let document_file = has_file_extension(
        &text,
        &[
            "pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "odt", "ods", "odp", "rtf", "html",
            "htm", "epub", "mobi", "txt", "md",
        ],
    );
    let file_use = has_word(
        &words,
        &[
            "open",
            "read",
            "inspect",
            "edit",
            "review",
            "summarize",
            "summarise",
            "analyze",
            "analyse",
            "parse",
            "use",
            "convert",
            "extract",
        ],
    ) || has_zh(
        &text,
        &[
            "打开", "读取", "阅读", "编辑", "查看", "分析", "总结", "解析", "处理", "使用", "转换",
            "转成", "转为", "提取",
        ],
    );
    let conversion = has_word(&words, &["convert", "conversion"])
        || has_any_phrase(
            &words,
            &[
                &["extract", "text"],
                &["extract", "content"],
                &["to", "markdown"],
                &["into", "markdown"],
                &["as", "markdown"],
                &["export", "as", "markdown"],
            ],
        )
        || has_zh(
            &text,
            &[
                "转换文件",
                "转成 markdown",
                "转为 markdown",
                "提取文本",
                "提取内容",
                "导出为 markdown",
            ],
        );

    IntentSet {
        plan,
        todo,
        work,
        sync,
        ingest,
        changeset,
        memory,
        wiki,
        document_graph: evidence.has_documents && document_graph_intent,
        code_graph: evidence.has_code && code_graph_intent,
        tutor,
        practice,
        book,
        office: office_file && file_use,
        trans: document_file && conversion,
        memory_intent,
        book_format,
    }
}

fn ascii_words(text: &str) -> Vec<&str> {
    text.split(|character: char| !character.is_ascii_alphanumeric())
        .filter(|word| !word.is_empty())
        .collect()
}

fn has_word(words: &[&str], candidates: &[&str]) -> bool {
    words.iter().any(|word| candidates.contains(word))
}

fn has_any_phrase(words: &[&str], candidates: &[&[&str]]) -> bool {
    candidates.iter().any(|phrase| {
        !phrase.is_empty() && words.windows(phrase.len()).any(|window| window == *phrase)
    })
}

fn has_zh(text: &str, candidates: &[&str]) -> bool {
    candidates.iter().any(|candidate| text.contains(candidate))
}

fn has_file_extension(text: &str, extensions: &[&str]) -> bool {
    extensions.iter().any(|extension| {
        let needle = format!(".{extension}");
        text.match_indices(&needle).any(|(index, _)| {
            let before = &text[..index];
            let after = &text[index + needle.len()..];
            before.chars().next_back().is_some_and(|character| {
                character.is_alphanumeric() || matches!(character, '_' | '-')
            }) && extension_boundary(after)
        })
    })
}

fn extension_boundary(after: &str) -> bool {
    let mut characters = after.chars();
    match characters.next() {
        None => true,
        Some('.') => characters
            .next()
            .is_none_or(|character| !is_filename_continuation(character)),
        Some(character) => !is_filename_continuation(character),
    }
}

fn is_filename_continuation(character: char) -> bool {
    character.is_alphanumeric() || matches!(character, '_' | '-')
}

#[cfg(test)]
mod tests {
    use super::*;

    fn evidence(has_code: bool, has_documents: bool) -> ProjectEvidence {
        ProjectEvidence {
            has_code,
            has_documents,
        }
    }

    fn enabled(intent: &IntentSet) -> Vec<&'static str> {
        let mut names = Vec::new();
        for (name, value) in [
            ("plan", intent.plan),
            ("todo", intent.todo),
            ("work", intent.work),
            ("sync", intent.sync),
            ("ingest", intent.ingest),
            ("changeset", intent.changeset),
            ("memory", intent.memory),
            ("wiki", intent.wiki),
            ("document_graph", intent.document_graph),
            ("code_graph", intent.code_graph),
            ("tutor", intent.tutor),
            ("practice", intent.practice),
            ("book", intent.book),
            ("office", intent.office),
            ("trans", intent.trans),
        ] {
            if value {
                names.push(name);
            }
        }
        names
    }

    #[test]
    fn classifies_each_english_intent_without_broad_keyword_spillover() {
        let fixtures = [
            ("Resume the durable plan.", "plan"),
            ("Add this to my todo list.", "todo"),
            ("Check the background work item status.", "work"),
            ("Sync this project with my laptop.", "sync"),
            ("Ingest these source documents.", "ingest"),
            ("Resume the changeset draft.", "changeset"),
            ("Recall our durable memory.", "memory"),
            ("Update the project wiki.", "wiki"),
            ("Teach me this topic as a tutor.", "tutor"),
            ("Start a practice session with a quiz.", "practice"),
            ("Read this whole book with me.", "book"),
            ("Open quarterly-report.XLSX and summarize it.", "office"),
            ("Convert handbook.pdf to Markdown.", "trans"),
        ];

        for (prompt, expected) in fixtures {
            assert_eq!(
                enabled(&classify(prompt, evidence(false, false))),
                vec![expected],
                "prompt: {prompt}"
            );
        }
    }

    #[test]
    fn classifies_each_chinese_intent_without_returning_prompt_text() {
        let fixtures = [
            ("继续当前计划", "plan"),
            ("把这个加入待办", "todo"),
            ("检查后台任务状态", "work"),
            ("把项目同步到另一台机器", "sync"),
            ("导入这批资料入库", "ingest"),
            ("恢复这个变更集草稿", "changeset"),
            ("把这项决定保存到持久记忆", "memory"),
            ("更新项目知识库", "wiki"),
            ("请教我这个主题", "tutor"),
            ("开始一次练习题测验", "practice"),
            ("陪我阅读整本书", "book"),
            ("打开 季报.xlsx 并总结", "office"),
            ("把 handbook.pdf 转成 Markdown", "trans"),
        ];

        for (prompt, expected) in fixtures {
            let intent = classify(prompt, evidence(false, false));
            assert_eq!(enabled(&intent), vec![expected], "prompt: {prompt}");
            assert!(!format!("{intent:?}").contains(prompt));
        }
    }

    #[test]
    fn graph_applicability_is_independent_and_requires_project_evidence() {
        let document_prompt = "Trace relationships between documents in the knowledge graph.";
        let code_prompt = "Inspect the call graph and code structure.";

        assert!(!classify(document_prompt, evidence(false, false)).document_graph);
        assert!(classify(document_prompt, evidence(false, true)).document_graph);
        assert!(!classify(document_prompt, evidence(true, false)).document_graph);

        assert!(!classify(code_prompt, evidence(false, false)).code_graph);
        assert!(classify(code_prompt, evidence(true, false)).code_graph);
        assert!(!classify(code_prompt, evidence(false, true)).code_graph);

        let both = classify("分析文档关系和代码调用图", evidence(true, true));
        assert!(both.document_graph);
        assert!(both.code_graph);
    }

    #[test]
    fn learning_intent_never_implies_code_graph() {
        for prompt in [
            "Tutor me in Rust.",
            "Start a practice session for coding.",
            "Read this whole programming book.",
            "教我 Rust",
            "开始一次编程练习题测验",
            "陪我阅读整本编程书",
        ] {
            let intent = classify(prompt, evidence(true, false));
            assert!(
                !intent.code_graph,
                "learning leaked into code graph: {prompt}"
            );
        }

        let explicit = classify(
            "Tutor me while we inspect the call graph.",
            evidence(true, false),
        );
        assert!(explicit.tutor);
        assert!(explicit.code_graph);
    }

    #[test]
    fn rejects_english_and_chinese_near_matches() {
        for prompt in [
            "The planner module has a memory allocation bug.",
            "Book a flight and reserve an office.",
            "I practice coding every day.",
            "Wikipedia describes asynchronous workers.",
            "Translate this sentence to Chinese.",
            "What does the .docx extension mean?",
            "Review report.pdf without converting it.",
            "Extract a function from main.rs.",
            "计划器模块存在内存分配问题",
            "预订一张机票并找个办公室",
            "我每天练习编程",
            "翻译这句话,不处理文件",
        ] {
            assert!(
                enabled(&classify(prompt, evidence(true, true))).is_empty(),
                "false positive: {prompt}"
            );
        }
    }

    #[test]
    fn office_and_trans_require_real_file_evidence_and_the_right_action() {
        let office = classify("Please read reports/Q4.PPTX.", evidence(false, true));
        assert!(office.office);
        assert!(!office.trans);

        let trans = classify(
            "Extract text from docs/scanned-report.PDF.",
            evidence(false, true),
        );
        assert!(trans.trans);
        assert!(!trans.office);

        for prompt in [
            "Open a spreadsheet for me.",
            "Please read .xlsx.",
            "Please read report.xlsxx.",
            "Convert this paragraph to Markdown.",
            "The file is report.pdf.",
        ] {
            let intent = classify(prompt, evidence(false, true));
            assert!(!intent.office, "office false positive: {prompt}");
            assert!(!intent.trans, "trans false positive: {prompt}");
        }
    }

    #[test]
    fn supports_multiple_explicit_intents_but_processes_at_most_4096_characters() {
        let combined = classify(
            "Update the wiki, sync the project, then resume the plan.",
            evidence(false, true),
        );
        assert_eq!(enabled(&combined), vec!["plan", "sync", "wiki"]);

        let after_limit = format!("{} plan", "x".repeat(4096));
        assert!(!classify(&after_limit, evidence(false, false)).plan);
        let before_limit = format!("plan {}", "x".repeat(4096));
        assert!(classify(&before_limit, evidence(false, false)).plan);
    }

    #[test]
    fn output_contains_only_typed_flags_not_prompt_fragments() {
        let secret = "PRIVATE_PROMPT_FRAGMENT_9274";
        let intent = classify(
            &format!("Remember this decision in durable memory: {secret}"),
            evidence(false, false),
        );
        assert!(intent.memory);
        assert!(!format!("{intent:?}").contains(secret));
    }

    #[test]
    fn memory_intent_is_typed_by_explicit_english_action() {
        for (prompt, expected) in [
            ("Recall our durable memory.", MemoryIntent::Recall),
            ("Remember this decision for later.", MemoryIntent::Record),
            ("Save this to persistent memory.", MemoryIntent::Record),
            ("Show LWC memory status.", MemoryIntent::Status),
            ("Check durable memory pressure.", MemoryIntent::Status),
            ("Maintain project memory.", MemoryIntent::Status),
            ("Use durable memory for this project.", MemoryIntent::None),
            (
                "Recall our memory and remember this result.",
                MemoryIntent::None,
            ),
        ] {
            let intent = classify(prompt, evidence(false, false));
            assert!(intent.memory, "memory feature missed: {prompt}");
            assert_eq!(intent.memory_intent, expected, "prompt: {prompt}");
        }
    }

    #[test]
    fn memory_intent_is_typed_by_explicit_chinese_action() {
        for (prompt, expected) in [
            ("回忆我们的项目记忆", MemoryIntent::Recall),
            ("把这项决定保存到记忆", MemoryIntent::Record),
            ("记住这个结论", MemoryIntent::Record),
            ("检查持久记忆状态", MemoryIntent::Status),
            ("查看项目记忆压力", MemoryIntent::Status),
            ("维护长期记忆", MemoryIntent::Status),
            ("使用持久记忆", MemoryIntent::None),
            ("回忆项目记忆并记住这个结论", MemoryIntent::None),
        ] {
            let intent = classify(prompt, evidence(false, false));
            assert!(intent.memory, "memory feature missed: {prompt}");
            assert_eq!(intent.memory_intent, expected, "prompt: {prompt}");
        }
    }

    #[test]
    fn book_format_evidence_is_typed_without_retaining_the_filename() {
        for prompt in [
            "Read this book novel.epub.",
            "Read this book novel.txt.",
            "Read this book novel.md.",
            "Read this book novel.markdown.",
            "Read this book novel.pdf.",
            "Read this scanned book scan.pdf.",
        ] {
            let intent = classify(prompt, evidence(false, true));
            assert!(intent.book, "book feature missed: {prompt}");
            assert_eq!(
                intent.book_format,
                BookFormatEvidence::Supported,
                "{prompt}"
            );
        }
        for prompt in [
            "Read this book novel.html.",
            "Read this book novel.htm.",
            "Read this book novel.mobi.",
            "Read this book novel.azw3.",
        ] {
            let intent = classify(prompt, evidence(false, true));
            assert!(intent.book, "book feature missed: {prompt}");
            assert_eq!(
                intent.book_format,
                BookFormatEvidence::Unsupported,
                "{prompt}"
            );
        }

        let no_file = classify("Read this whole book with me.", evidence(false, true));
        assert_eq!(no_file.book_format, BookFormatEvidence::None);
        let not_a_book = classify("Read quarterly-report.pdf.", evidence(false, true));
        assert!(!not_a_book.book);
        assert_eq!(not_a_book.book_format, BookFormatEvidence::None);
    }

    #[test]
    fn unsupported_book_evidence_wins_without_leaking_multi_intent_input() {
        let secret = "PRIVATE_READING_LIST_7391";
        let intent = classify(
            &format!(
                "Sync the project, recall our memory, and read this book {secret}.azw3 after draft.epub."
            ),
            evidence(false, true),
        );
        assert!(intent.sync);
        assert!(intent.memory);
        assert_eq!(intent.memory_intent, MemoryIntent::Recall);
        assert!(intent.book);
        assert_eq!(intent.book_format, BookFormatEvidence::Unsupported);
        assert!(!format!("{intent:?}").contains(secret));
    }

    #[test]
    fn typed_evidence_obeys_the_unicode_prompt_cap_and_defaults_to_none() {
        let default = IntentSet::default();
        assert_eq!(default.memory_intent, MemoryIntent::None);
        assert_eq!(default.book_format, BookFormatEvidence::None);

        let after_limit = format!("{} memory recall novel.azw3", "".repeat(4096));
        let intent = classify(&after_limit, evidence(false, true));
        assert!(!intent.memory);
        assert_eq!(intent.memory_intent, MemoryIntent::None);
        assert!(!intent.book);
        assert_eq!(intent.book_format, BookFormatEvidence::None);

        let before_limit = format!(
            "memory status read this book novel.epub {}",
            "".repeat(4096)
        );
        let intent = classify(&before_limit, evidence(false, true));
        assert_eq!(intent.memory_intent, MemoryIntent::Status);
        assert_eq!(intent.book_format, BookFormatEvidence::Supported);
    }
}