canact 0.1.2

Probe an LLM and return host policy: max tools, edit format, XML fallback, JSON repair
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
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
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
//! Vision capability probe.

use crate::ProbeError;
use crate::client::{
    ProbeClient, ProbeContent, ProbeContentPart, ProbeMessage, ProbeRequest, ProbeRole,
};
use crate::types::{ProbeResult, classify};

use super::refuse_truncated_incomplete;

/// Minimal 16x16 PNG with "BL" text pattern (white on black), base64-encoded.
/// Used as the test image for the vision capability probe.
const PROBE_IMAGE_BASE64: &str = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAIklEQVR4nGNgYGD4jwQYkAAaF7sELj\
     bFGoaQk3BJjYIhBwBFt1ykBOQgDQAAAABJRU5ErkJggg==";

/// Probe whether the model can process image input (vision capability).
///
/// Sends a small test image containing the text "BL" and asks the model
/// to describe what it sees. This validates the minimum-viable vision path
/// using inline base64 images.
///
/// Scoring:
/// - `1.0` - response mentions "BL" or "BLINE" (case-insensitive)
/// - `0.5` - response describes image content (letters, text, pattern)
///   but does not identify the exact text
/// - `0.0` - response indicates inability to process images, or gives
///   a generic answer ignoring the image
///
/// Note: vision probes are more expensive than text probes due to image
/// token costs. The cache prevents repeated probing.
pub async fn probe_vision<C: ProbeClient>(llm: &C) -> Result<ProbeResult, ProbeError> {
    let request = ProbeRequest {
        messages: vec![ProbeMessage {
            role: ProbeRole::User,
            content: ProbeContent::Parts(vec![
                ProbeContentPart::Text {
                    text: "What text or letters appear in this image? Reply with ONLY the text \
                           you see, nothing else."
                        .to_string(),
                },
                ProbeContentPart::ImageBase64 {
                    media_type: "image/png".to_string(),
                    data: PROBE_IMAGE_BASE64.to_string(),
                },
            ]),
            tool_calls: None,
            tool_call_id: None,
        }],
        tools: vec![],
        model: llm.model_id().to_string(),
        temperature: Some(0.0),
        max_tokens: Some(256),
    };

    let response = llm.chat(request).await?;
    let text = response.text;
    let raw = text.to_lowercase();
    let folded = fold_format_marks(&raw);
    let stripped = strip_format_marks(&raw);
    let lower = folded.as_str();

    // Check if the model identified the text. Be careful not to match "black",
    // "blue", "blank", etc. - only match "BL" as a standalone word or "BLINE".
    let trimmed_lower = lower.trim().trim_matches(|c: char| c == '"' || c == '\'');
    let letter_tokens: Vec<&str> = lower
        .split(|c: char| !c.is_ascii_alphanumeric())
        .filter(|t| !t.is_empty())
        .collect();
    let identified_text = trimmed_lower == "bl"
        || lower.contains("bline")
        || lower.contains("\"bl\"")
        || lower.contains("'bl'")
        || letter_tokens.iter().any(|word| *word == "bl")
        || letter_tokens.as_slice() == ["b", "l"];

    // User-facing details only. Ground-truth text in the probe image stays
    // internal (see PROBE_IMAGE_BASE64 / scoring above); do not echo it or
    // the raw model reply in default details.
    let font_hedge = vision_font_hedge(&folded) || vision_font_hedge(&stripped);
    let refused = (vision_refused(&folded) || vision_refused(&stripped)) && !font_hedge;
    // Partial reads name glyphs. "no letters" is a refusal, not a read.
    // Do not gate on `refused`: "I see letters but cannot make them out"
    // and "I see letters but cannot read them" are still Medium.
    let negated_glyphs = vision_negated_glyphs(&folded) || vision_negated_glyphs(&stripped);
    let make_out_negated = cannot_make_token_out(&folded) || cannot_make_token_out(&stripped);
    let leftover_unread =
        leftover_read_blocks_strong(&folded) || leftover_read_blocks_strong(&stripped);
    let saw_glyphs = !negated_glyphs
        && (has_surface_word(lower, "letter")
            || has_surface_word(lower, "letters")
            || has_surface_word(lower, "character")
            || has_surface_word(lower, "characters"));
    // Word tokens only. "whitespace" is not "white"; "context" is not "text".
    let processed_surface = has_surface_word(lower, "pattern")
        || has_surface_word(lower, "pixel")
        || has_surface_word(lower, "pixels")
        || has_surface_word(lower, "black")
        || has_surface_word(lower, "white")
        || has_surface_word(lower, "text");

    let echoed_question = lower.contains("what text or letters appear");

    // Strong is a read, not any "don't"/"cannot" hedge (font, typeface).
    // See-denial still blocks Strong via negated_glyphs ("I don't see BL").
    // Infix leftover read verbs ("cannot quite read BL") are not Strong.
    let (score, details) =
        if identified_text && !negated_glyphs && !make_out_negated && !leftover_unread {
            (1.0, "Can read text from images".to_string())
        } else if echoed_question {
            (0.0, "Did not use the image (generic reply)".to_string())
        } else if saw_glyphs
            || (processed_surface && (make_out_negated || leftover_unread) && !negated_glyphs)
        {
            (
                0.5,
                "Processed the image but could not read the text clearly".to_string(),
            )
        } else if refused {
            (0.0, "Cannot process images".to_string())
        } else if processed_surface {
            (
                0.5,
                "Processed the image but could not read the text clearly".to_string(),
            )
        } else {
            (0.0, "Did not use the image (generic reply)".to_string())
        };

    refuse_truncated_incomplete(response.finish, score)?;
    Ok(ProbeResult {
        name: "vision".to_string(),
        score,
        max_score: 1.0,
        level: classify(score),
        details,
    })
}

fn fold_format_marks(s: &str) -> String {
    s.chars()
        .map(|c| match c {
            '\u{200B}' | '\u{200C}' | '\u{200D}' | '\u{2060}' | '\u{FEFF}' => ' ',
            '\u{2019}' => '\'',
            _ => c,
        })
        .collect::<String>()
        .split_whitespace()
        .collect::<Vec<_>>()
        .join(" ")
}

fn strip_format_marks(s: &str) -> String {
    s.chars()
        .filter(|c| {
            !matches!(
                c,
                '\u{200B}' | '\u{200C}' | '\u{200D}' | '\u{2060}' | '\u{FEFF}'
            )
        })
        .map(|c| if c == '\u{2019}' { '\'' } else { c })
        .collect()
}

fn vision_refused(lower: &str) -> bool {
    lower.contains("cannot")
        || lower.contains("can't")
        || lower.contains("can not")
        || lower.contains("unable")
        || lower.contains("not able")
        || lower.contains("don't")
        || lower.contains("didn't")
        || lower.contains("did not")
        || lower.contains("couldn't")
        || lower.contains("could not")
        || lower.contains("no image")
        || lower.contains("no text")
        || lower.contains("no readable")
        || lower.contains("no visible")
        || lower.contains("no letter")
        || lower.contains("no character")
        || lower.contains("text-only")
        || lower.contains("text only")
        || lower.contains("text-based")
        || lower.contains("text model")
        || lower.contains("processes text")
        || lower.contains("process text")
        || lower.contains("work with text")
        || lower.contains("isn't any text")
        || lower.contains("is not any text")
        || lower.contains("black box")
        || lower.contains("white box")
        || lower.contains("white-box")
        || lower.contains("white space")
        || lower.contains("white-space")
        || lower.contains("no discernible text")
        || lower.contains("text-processing")
        || lower.contains("text processing")
}

fn vision_negated_glyphs(lower: &str) -> bool {
    lower.contains("no letter")
        || lower.contains("no character")
        || lower.contains("no readable")
        || lower.contains("no visible letter")
        || lower.contains("no visible character")
        || lower.contains("no discernible letter")
        || lower.contains("no discernible character")
        || lower.contains("doesn't contain character")
        || lower.contains("does not contain character")
        || lower.contains("aren't any character")
        || lower.contains("are not any character")
        || lower.contains("don't see")
        || lower.contains("do not see")
        || lower.contains("can't see")
        || lower.contains("cannot see")
        || recognize_negates_glyphs(lower)
        || lower.contains("can't decipher")
        || lower.contains("cannot decipher")
        || lower.contains("unable to read")
        || lower.contains("unable to see")
        || lower.contains("unable to identify")
        || lower.contains("unable to decipher")
        || lower.contains("not able to read")
        || lower.contains("not able to see")
        || lower.contains("not able to identify")
        || lower.contains("not able to decipher")
        || lower.contains("can not read")
        || lower.contains("can not see")
        || lower.contains("can not identify")
        || lower.contains("can not decipher")
        || lower.contains("couldn't read")
        || lower.contains("couldn't see")
        || lower.contains("couldn't identify")
        || lower.contains("could not read")
        || lower.contains("could not see")
        || lower.contains("could not identify")
        || lower.contains("didn't identify")
        || lower.contains("did not identify")
        || lower.contains("couldn't decipher")
        || lower.contains("could not decipher")
        || lower.contains("didn't decipher")
        || lower.contains("did not decipher")
        || lower.contains("wasn't able to read")
        || lower.contains("wasn't able to see")
        || lower.contains("wasn't able to identify")
        || lower.contains("wasn't able to decipher")
        || lower.contains("didn't see")
        || lower.contains("didn't read")
        || lower.contains("did not see")
        || lower.contains("did not read")
        || lower.contains("doesn't contain letter")
        || lower.contains("does not contain letter")
        || lower.contains("aren't any letter")
        || lower.contains("are not any letter")
}

fn recognize_negates_glyphs(lower: &str) -> bool {
    const STEMS: &[&str] = &[
        "don't recognize",
        "do not recognize",
        "can't recognize",
        "cannot recognize",
        "can not recognize",
        "unable to recognize",
        "not able to recognize",
        "didn't recognize",
        "did not recognize",
        "couldn't recognize",
        "could not recognize",
        "don't recognise",
        "do not recognise",
        "can't recognise",
        "cannot recognise",
        "can not recognise",
        "unable to recognise",
        "not able to recognise",
        "didn't recognise",
        "did not recognise",
        "couldn't recognise",
        "could not recognise",
        "wasn't able to recognize",
        "wasn't able to recognise",
    ];
    for stem in STEMS {
        let mut search = 0;
        while let Some(rel) = lower.get(search..).and_then(|s| s.find(stem)) {
            let after = lower[search + rel + stem.len()..].trim_start();
            if rest_is_font_hedge(after) {
                search += rel + stem.len();
                continue;
            }
            return true;
        }
    }
    false
}

fn rest_is_font_hedge(after: &str) -> bool {
    let after = after
        .strip_prefix("the ")
        .or_else(|| after.strip_prefix("this "))
        .or_else(|| after.strip_prefix("that "))
        .or_else(|| after.strip_prefix("these "))
        .or_else(|| after.strip_prefix("those "))
        .or_else(|| after.strip_prefix("a "))
        .or_else(|| after.strip_prefix("any "))
        .or_else(|| after.strip_prefix("its "))
        .unwrap_or(after);
    after.starts_with("font") || after.starts_with("typeface")
}

/// Infix leftover read verbs plus BL are not a read.
/// Font hedges (`cannot identify the font`) stay Strong.
fn leftover_read_blocks_strong(lower: &str) -> bool {
    if lower.contains("not readable")
        || lower.contains("isn't readable")
        || lower.contains("is not readable")
        || lower.contains("aren't readable")
        || lower.contains("are not readable")
        || lower.contains("unreadable")
    {
        return true;
    }
    if lower.contains("trouble reading")
        || lower.contains("trouble identifying")
        || lower.contains("trouble discerning")
    {
        return true;
    }
    cannot_plus_read_verb(lower)
}

fn cannot_plus_read_verb(lower: &str) -> bool {
    const NEGS: &[&str] = &["cannot", "can't", "can not"];
    const VERBS: &[&str] = &["read", "identify", "discern"];
    const ADVERBS: &[&str] = &["quite", "clearly", "really", "fully", "easily"];
    for neg in NEGS {
        let mut search = 0;
        while let Some(rel) = lower.get(search..).and_then(|s| s.find(neg)) {
            let after = lower[search + rel + neg.len()..].trim_start();
            let rest = skip_one_adverb(after, ADVERBS);
            if let Some(verb) = VERBS
                .iter()
                .copied()
                .find(|verb| starts_with_word(rest, verb))
            {
                let after_verb = rest[verb.len()..].trim_start();
                if rest_is_font_hedge(after_verb) {
                    search += rel + neg.len();
                    continue;
                }
                return true;
            }
            search += rel + neg.len();
        }
    }
    false
}

fn skip_one_adverb<'a>(s: &'a str, adverbs: &[&str]) -> &'a str {
    for adv in adverbs {
        if let Some(rest) = s.strip_prefix(adv) {
            if rest.starts_with(|c: char| c.is_whitespace()) || rest.is_empty() {
                return rest.trim_start();
            }
        }
    }
    s
}

fn starts_with_word(s: &str, word: &str) -> bool {
    s.starts_with(word)
        && s[word.len()..]
            .chars()
            .next()
            .is_none_or(|c| !c.is_ascii_alphanumeric())
}

fn vision_font_hedge(lower: &str) -> bool {
    let has_font = has_surface_word(lower, "font")
        || has_surface_word(lower, "fonts")
        || has_surface_word(lower, "typeface")
        || has_surface_word(lower, "typefaces");
    if !has_font {
        return false;
    }
    lower.contains("don't")
        || lower.contains("do not")
        || lower.contains("can't")
        || lower.contains("cannot")
        || lower.contains("can not")
}

fn cannot_make_token_out(lower: &str) -> bool {
    let tokens: Vec<&str> = lower
        .split(|c: char| !c.is_ascii_alphanumeric())
        .filter(|t| !t.is_empty())
        .collect();
    tokens.windows(2).any(|w| w[0] == "make" && w[1] == "out")
        || tokens.windows(3).any(|w| w[0] == "make" && w[2] == "out")
}

fn has_surface_word(lower: &str, word: &str) -> bool {
    lower
        .split(|c: char| !c.is_ascii_alphanumeric())
        .any(|token| token == word)
}

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

    use crate::probes::test_support::*;
    use crate::types::CapabilityLevel;

    #[tokio::test]
    async fn vision_color_words_are_not_strong() {
        for text in [
            "I see: black and white pixels only",
            "The letters blend together",
            "There is no text black",
        ] {
            let llm = MockLlm {
                response: text_response(text),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_ne!(
                result.level,
                CapabilityLevel::Strong,
                "color/no-read must not set supportsVision Strong: {text:?} -> {result:?}"
            );
        }
    }

    #[tokio::test]
    async fn vision_strong_when_text_identified() {
        let llm = MockLlm {
            response: text_response("BL"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(result.level, CapabilityLevel::Strong);
        assert_eq!(result.score, 1.0);
        assert_eq!(result.details, "Can read text from images");
    }

    #[tokio::test]
    async fn vision_medium_when_image_processed_but_wrong_text() {
        let llm = MockLlm {
            response: text_response("I see some white text on a black background"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(result.level, CapabilityLevel::Medium);
        assert_eq!(result.score, 0.5);
        assert_eq!(
            result.details,
            "Processed the image but could not read the text clearly"
        );
    }

    #[tokio::test]
    async fn vision_weak_when_cannot_process() {
        let llm = MockLlm {
            response: text_response("I cannot process images in this format."),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(result.level, CapabilityLevel::Weak);
        assert_eq!(result.score, 0.0);
        assert_eq!(result.details, "Cannot process images");
    }

    #[tokio::test]
    async fn vision_text_model_does_not_set_medium() {
        for body in [
            "I am a text model",
            "This model processes text",
            "This is a text-only model.",
            "I'm a text-based model.",
            "I only work with text.",
            "There isn't any text.",
        ] {
            let llm = MockLlm {
                response: text_response(body),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_eq!(
                result.level,
                CapabilityLevel::Weak,
                "text-model phrasing must not set supportsVision: {body} {result:?}"
            );
        }
    }

    #[tokio::test]
    async fn vision_text_only_model_does_not_set_medium() {
        let llm = MockLlm {
            response: text_response("This is a text-only model."),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Medium,
            "text-only must not set supportsVision: {result:?}"
        );
        assert_eq!(result.level, CapabilityLevel::Weak);
    }

    #[tokio::test]
    async fn vision_negated_letters_do_not_set_medium() {
        for body in [
            "No visible letters",
            "There are no discernible letters",
            "The image doesn't contain letters",
            "There aren't any letters",
        ] {
            let llm = MockLlm {
                response: text_response(body),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_eq!(
                result.level,
                CapabilityLevel::Weak,
                "negated letters must not set supportsVision: {body} {result:?}"
            );
        }
    }

    #[tokio::test]
    async fn vision_black_box_idiom_does_not_set_medium() {
        let llm = MockLlm {
            response: text_response("This is a black box to me."),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Medium,
            "black box idiom must not set supportsVision: {result:?}"
        );
        assert_eq!(result.level, CapabilityLevel::Weak);
    }

    #[tokio::test]
    async fn vision_question_echo_does_not_set_medium() {
        let llm = MockLlm {
            response: text_response("What text or letters appear in this image?"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Medium,
            "question echo must not set supportsVision: {result:?}"
        );
        assert_eq!(result.level, CapabilityLevel::Weak);
    }

    #[tokio::test]
    async fn vision_weak_when_zwsp_splits_dont_see() {
        for body in [
            "I don\u{200B}'t see letters",
            "I can\u{200B}'t see any text",
        ] {
            let llm = MockLlm {
                response: text_response(body),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_eq!(
                result.level,
                CapabilityLevel::Weak,
                "ZWSP in don't/can't must not set supportsVision: {body} {result:?}"
            );
            assert_eq!(result.score, 0.0, "body={body}");
        }
    }

    #[tokio::test]
    async fn vision_hedged_bl_is_strong() {
        let llm = MockLlm {
            response: text_response("BL (I don't know the font)"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(result.score, 1.0, "{result:?}");
        assert_eq!(result.level, CapabilityLevel::Strong);
    }

    #[tokio::test]
    async fn vision_dont_recognize_the_font_with_bl_is_strong() {
        let llm = MockLlm {
            response: text_response("BL (I don't recognize the font)"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(
            result.score, 1.0,
            "font hedge that uses recognize must stay Strong: {result:?}"
        );
        assert_eq!(result.level, CapabilityLevel::Strong);
    }

    #[tokio::test]
    async fn vision_cannot_identify_the_font_with_bl_is_strong() {
        for text in [
            "BL (I cannot identify the font)",
            "BL (I don't recognize a font)",
            "BL (I don't recognize any typeface)",
        ] {
            let llm = MockLlm {
                response: text_response(text),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_eq!(
                result.score, 1.0,
                "identify/a/any font hedge with BL must stay Strong: {text:?} {result:?}"
            );
            assert_eq!(result.level, CapabilityLevel::Strong, "{text:?}");
        }
    }

    #[tokio::test]
    async fn vision_cannot_quite_read_bl_is_not_strong() {
        for text in [
            "I cannot quite read BL",
            "I cannot clearly identify BL",
            "I cannot discern BL",
            "BL is not readable",
            "I'm having trouble reading BL",
            "I cannot quite read BL (I don't know the font)",
            "BL is not readable. I cannot identify the font",
        ] {
            let llm = MockLlm {
                response: text_response(text),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_ne!(
                result.level,
                CapabilityLevel::Strong,
                "infix leftover read verb that names BL must not be Strong: {text:?} {result:?}"
            );
        }
    }

    #[tokio::test]
    async fn vision_dont_see_bl_is_not_strong() {
        let llm = MockLlm {
            response: text_response("I don't see BL"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(
            result.score, 0.0,
            "refusal that names BL must not be Strong"
        );
        assert_eq!(result.level, CapabilityLevel::Weak);
    }

    #[tokio::test]
    async fn vision_cannot_read_bl_is_not_strong() {
        let llm = MockLlm {
            response: text_response("I cannot read BL"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Strong,
            "cannot-read that names BL must not be Strong: {result:?}"
        );
    }

    #[tokio::test]
    async fn vision_cannot_identify_bl_is_not_strong() {
        let llm = MockLlm {
            response: text_response("I cannot identify BL"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Strong,
            "cannot-identify that names BL must not be Strong: {result:?}"
        );
    }

    #[tokio::test]
    async fn vision_cannot_recognize_bl_is_not_strong() {
        let llm = MockLlm {
            response: text_response("I cannot recognize BL"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Strong,
            "cannot-recognize that names BL must not be Strong: {result:?}"
        );
    }

    #[tokio::test]
    async fn vision_dont_recognize_bl_is_not_strong() {
        for text in [
            "I don't recognize BL",
            "I do not recognize BL",
            "I cannot recognise BL",
            "I don\u{2019}t recognize BL",
            "I can\u{2019}t recognise BL",
        ] {
            let llm = MockLlm {
                response: text_response(text),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_ne!(
                result.level,
                CapabilityLevel::Strong,
                "recognize/recognise refusal that names BL must not be Strong: {text:?} {result:?}"
            );
        }
    }

    #[tokio::test]
    async fn vision_cannot_make_bl_out_is_not_strong() {
        let llm = MockLlm {
            response: text_response("I cannot make BL out"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Strong,
            "cannot-make-BL-out must not be Strong: {result:?}"
        );
    }

    #[tokio::test]
    async fn vision_no_readable_text_or_letters_is_weak() {
        for text in ["no readable text", "no readable letters"] {
            let llm = MockLlm {
                response: text_response(text),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_eq!(
                result.level,
                CapabilityLevel::Weak,
                "no-readable phrasing must not set supportsVision: {text:?} {result:?}"
            );
            assert_eq!(result.score, 0.0, "{text:?}");
        }
    }

    #[tokio::test]
    async fn vision_not_able_to_read_bl_is_not_strong() {
        let llm = MockLlm {
            response: text_response("I'm not able to read BL"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Strong,
            "not-able-to-read that names BL must not be Strong: {result:?}"
        );
    }

    #[tokio::test]
    async fn vision_unable_to_read_bl_is_not_strong() {
        for text in [
            "I am unable to read BL",
            "I can not see BL",
            "I am unable to make out BL",
        ] {
            let llm = MockLlm {
                response: text_response(text),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_ne!(
                result.level,
                CapabilityLevel::Strong,
                "unable/can-not refusal that names BL must not be Strong: {text:?} {result:?}"
            );
        }
    }

    #[tokio::test]
    async fn vision_weak_when_dont_see_letters() {
        let llm = MockLlm {
            response: text_response("I don't see letters"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Medium,
            "don't-see-letters must not set supportsVision: {result:?}"
        );
        assert_eq!(result.level, CapabilityLevel::Weak);
        assert_eq!(result.score, 0.0);
    }

    #[tokio::test]
    async fn vision_weak_when_no_letters_visible() {
        let llm = MockLlm {
            response: text_response("There are no letters visible"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Medium,
            "no-letters refusal must not set supportsVision: {result:?}"
        );
        assert_eq!(result.level, CapabilityLevel::Weak);
        assert_eq!(result.score, 0.0);
    }

    #[tokio::test]
    async fn vision_weak_when_no_visible_text() {
        let llm = MockLlm {
            response: text_response("No visible text"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Medium,
            "no visible text must not set supportsVision: {result:?}"
        );
        assert_eq!(result.level, CapabilityLevel::Weak);
        assert_eq!(result.score, 0.0);
    }

    #[tokio::test]
    async fn vision_weak_when_zwsp_splits_no_text() {
        let llm = MockLlm {
            response: text_response("There is no\u{200B} text visible"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(
            result.level,
            CapabilityLevel::Weak,
            "ZWSP in no-text refusal must not set supportsVision: {result:?}"
        );
        assert_eq!(result.score, 0.0);
    }

    #[tokio::test]
    async fn vision_weak_when_no_text_visible() {
        let llm = MockLlm {
            response: text_response("There is no text visible"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Medium,
            "no-text refusal must not set supportsVision: {result:?}"
        );
        assert_eq!(result.level, CapabilityLevel::Weak);
        assert_eq!(result.score, 0.0);
    }

    #[tokio::test]
    async fn vision_weak_when_refusal_mentions_text() {
        let llm = MockLlm {
            response: text_response("I cannot see any text in this image"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(result.level, CapabilityLevel::Weak);
        assert_eq!(result.score, 0.0);
        assert_eq!(result.details, "Cannot process images");
    }

    #[tokio::test]
    async fn vision_weak_when_refusal_mentions_black_white() {
        let llm = MockLlm {
            response: text_response("I cannot process this black and white image"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(result.level, CapabilityLevel::Weak);
        assert_eq!(result.score, 0.0);
        assert_eq!(result.details, "Cannot process images");
    }

    #[tokio::test]
    async fn vision_can_not_process_black_white_is_weak() {
        let llm = MockLlm {
            response: text_response("I can not process this black and white image"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(
            result.level,
            CapabilityLevel::Weak,
            "can-not process black-and-white must be a vision refusal: {result:?}"
        );
        assert_eq!(result.score, 0.0);
        assert_eq!(result.details, "Cannot process images");
    }

    #[tokio::test]
    async fn vision_medium_when_partial_read_also_says_cannot() {
        let llm = MockLlm {
            response: text_response("I see dark letters but cannot make them out"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(result.level, CapabilityLevel::Medium);
        assert_eq!(result.score, 0.5);
    }

    #[tokio::test]
    async fn vision_letters_but_cannot_read_is_medium() {
        for text in [
            "I see letters but cannot read them",
            "I see characters but cannot identify them",
            "I see text but cannot read it",
            "I see dark letters but cannot make them out",
        ] {
            let llm = MockLlm {
                response: text_response(text),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_eq!(
                result.level,
                CapabilityLevel::Medium,
                "letters/text plus cannot-read/identify must stay Medium: {text:?} {result:?}"
            );
            assert_eq!(result.score, 0.5, "{text:?}");
        }
    }

    #[tokio::test]
    async fn vision_letters_but_cannot_make_out_is_medium() {
        let llm = MockLlm {
            response: text_response("I see letters but cannot make out the text"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(
            result.level,
            CapabilityLevel::Medium,
            "letters plus cannot-make-out is a partial read: {result:?}"
        );
        assert_eq!(result.score, 0.5);
    }

    #[tokio::test]
    async fn vision_could_not_read_bl_is_not_strong() {
        for text in ["I couldn't read BL", "I could not see BL"] {
            let llm = MockLlm {
                response: text_response(text),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_ne!(
                result.level,
                CapabilityLevel::Strong,
                "could-not refusal that names BL must not be Strong: {text:?} {result:?}"
            );
        }
    }

    #[tokio::test]
    async fn vision_did_not_see_letters_is_weak() {
        for text in ["I didn't see any letters", "I did not see any text"] {
            let llm = MockLlm {
                response: text_response(text),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_eq!(
                result.level,
                CapabilityLevel::Weak,
                "did-not-see letters/text must be Weak: {text:?} {result:?}"
            );
            assert_eq!(result.score, 0.0, "{text:?}");
        }
    }

    #[tokio::test]
    async fn vision_dont_recognize_this_font_with_bl_is_strong() {
        for text in [
            "BL (I don't recognize this font)",
            "BL (I don't recognize that typeface)",
        ] {
            let llm = MockLlm {
                response: text_response(text),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_eq!(
                result.score, 1.0,
                "this/that font hedge with BL must stay Strong: {text:?} {result:?}"
            );
            assert_eq!(result.level, CapabilityLevel::Strong, "{text:?}");
        }
    }

    #[tokio::test]
    async fn vision_dont_recognize_these_fonts_with_bl_is_strong() {
        for text in [
            "BL (I don't recognize these fonts)",
            "BL (I don't recognize those typefaces)",
        ] {
            let llm = MockLlm {
                response: text_response(text),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_eq!(
                result.score, 1.0,
                "these/those font hedge with BL must stay Strong: {text:?} {result:?}"
            );
            assert_eq!(result.level, CapabilityLevel::Strong, "{text:?}");
        }
    }

    #[tokio::test]
    async fn vision_didnt_recognize_could_not_identify_is_not_strong() {
        for text in [
            "I didn't recognize BL",
            "I could not recognise BL",
            "I did not identify BL",
            "I couldn't decipher BL",
            "I wasn't able to read BL",
            "I wasn't able to recognize BL",
            "I wasn't able to recognise BL",
        ] {
            let llm = MockLlm {
                response: text_response(text),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_ne!(
                result.level,
                CapabilityLevel::Strong,
                "past-tense recognize/identify that names BL must not be Strong: {text:?} {result:?}"
            );
        }

        let was_not = probe_vision(&MockLlm {
            response: text_response("I was not able to read BL"),
        })
        .await
        .unwrap();
        assert_eq!(
            was_not.level,
            CapabilityLevel::Weak,
            "I was not able to read BL must stay Weak: {was_not:?}"
        );

        let make_out = probe_vision(&MockLlm {
            response: text_response("I see letters but cannot make them out"),
        })
        .await
        .unwrap();
        assert_eq!(
            make_out.level,
            CapabilityLevel::Medium,
            "cannot make them out must stay Medium: {make_out:?}"
        );

        let spaced = probe_vision(&MockLlm {
            response: text_response("B L"),
        })
        .await
        .unwrap();
        assert_eq!(
            spaced.level,
            CapabilityLevel::Strong,
            "spaced B L must stay a read: {spaced:?}"
        );
    }

    #[tokio::test]
    async fn vision_white_text_dont_know_font_is_medium() {
        let llm = MockLlm {
            response: text_response("I see white text but I don't know the font"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(
            result.level,
            CapabilityLevel::Medium,
            "processed surface plus font hedge must be Medium, not Weak: {result:?}"
        );
        assert_eq!(result.score, 0.5);
    }

    #[tokio::test]
    async fn vision_whitespace_word_does_not_set_medium() {
        let llm = MockLlm {
            response: text_response("Looks like whitespace only"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Medium,
            "whitespace must not set supportsVision: {result:?}"
        );
        assert_eq!(result.level, CapabilityLevel::Weak);
    }

    #[tokio::test]
    async fn vision_no_discernible_characters_do_not_set_medium() {
        for body in [
            "No discernible characters",
            "There aren't any characters",
            "The image doesn't contain characters",
        ] {
            let llm = MockLlm {
                response: text_response(body),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_eq!(
                result.level,
                CapabilityLevel::Weak,
                "negated characters must not set supportsVision: {body} {result:?}"
            );
        }
    }

    #[tokio::test]
    async fn vision_no_visible_characters_and_white_hyphen_do_not_set_medium() {
        for body in [
            "No visible characters",
            "There is no discernible text",
            "Looks like white-space only",
        ] {
            let llm = MockLlm {
                response: text_response(body),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_eq!(
                result.level,
                CapabilityLevel::Weak,
                "blank-image phrasing must not set supportsVision: {body} {result:?}"
            );
        }
    }

    #[tokio::test]
    async fn vision_white_space_and_text_processing_do_not_set_medium() {
        for body in [
            "Looks like white space only",
            "This is a white-box to me.",
            "This is a white box to me.",
            "I am a text-processing model",
            "This model does text processing",
        ] {
            let llm = MockLlm {
                response: text_response(body),
            };
            let result = probe_vision(&llm).await.unwrap();
            assert_eq!(
                result.level,
                CapabilityLevel::Weak,
                "blank-image or text-processing phrasing must not set supportsVision: {body} {result:?}"
            );
        }
    }

    #[tokio::test]
    async fn vision_context_word_does_not_set_medium() {
        let llm = MockLlm {
            response: text_response("I need more context"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_ne!(
            result.level,
            CapabilityLevel::Medium,
            "context must not set supportsVision: {result:?}"
        );
        assert_eq!(result.level, CapabilityLevel::Weak);
    }

    #[tokio::test]
    async fn vision_weak_for_generic_response() {
        let llm = MockLlm {
            response: text_response("Sure, I'd be happy to help you with that."),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(result.level, CapabilityLevel::Weak);
        assert_eq!(result.score, 0.0);
        assert_eq!(result.details, "Did not use the image (generic reply)");
    }

    #[tokio::test]
    async fn vision_length_empty_is_transient() {
        let llm = MockLlm {
            response: length_text_response(""),
        };
        let result = probe_vision(&llm).await;
        assert!(
            matches!(result, Err(ProbeError::Transient(_))),
            "Length plus empty vision text must be Transient, not 30-day Weak; got {result:?}"
        );
    }

    #[tokio::test]
    async fn vision_length_complete_bl_stays_strong() {
        let llm = MockLlm {
            response: length_text_response("BL"),
        };
        let result = probe_vision(&llm).await.unwrap();
        assert_eq!(result.score, 1.0);
        assert_eq!(result.level, CapabilityLevel::Strong);
    }
}