mahbot 0.11.1

An autonomous agentic engineering system that manages software development through role separation, subagents, and deterministic diagnostics.
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
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
//! The content of a chart, as text, printed where the chart sits.
//!
//! A chart part carries the values its last rendering drew beside the table it points at: a classic
//! chart (`c:chartSpace`) caches each series' name, its category labels and its numbers in
//! `c:strCache`/`c:numCache`/`c:numLit`, with the number format the value was shown under. This
//! module reads that content — the chart's kind, its title and other text, and one line per series
//! of category and value — so a reading tells a model what a chart says instead of only that one is
//! there. Nothing is drawn, and nothing beside the chart part is opened.
//!
//! # What is not described
//! A chart part that carries only references to its attached table (no caches) says per series that
//! its values are in that table, and a part that cannot be read says so: neither is passed off as a
//! chart with no content, and both keep their place in the package's report
//! ([`crate::reader_output::Unshown`]). The modern extended parts (`chartEx`) have a schema of
//! their own — `cx:` rather than `c:` — which this reading does not parse, so they are that same
//! case.
//!
//! A chart whose values are printed is no longer a loss the report names; the readers exclude every
//! part this module describes from their census. The parts read are the ones that census names —
//! `charts/chart<N>.xml` and the `chartEx<N>.xml` beside them — so a part a producer files under
//! another name is outside the reading and its report alike, as it was before this module.
//!
//! # Invariants
//!
//! - **A value is shown the way the reading shows a spreadsheet cell**: a cached
//!   point keeps the format its cache states, through the same formatter
//!   ([`numfmt`]), and a number under a format that cannot be reproduced is shown
//!   as stored, under the same mark ([`MARK_STORED`]), never invented.
//! - **Bounded rather than document-decided**: the walk keeps at most
//!   [`MAX_SERIES`] series and [`MAX_POINTS`] points of each list — the rest is
//!   counted, not allocated or formatted — and prints at most [`MAX_TEXTS`] of
//!   the chart's other texts, saying how much more it holds rather than cutting
//!   it off silently. At most [`MAX_CHARTS`] of a package's parts are read, and
//!   the ones left out stay in the report.
//! - **The notation the model reads is stated in [`crate::reader_output`]** — the
//!   block's header, its field labels, the marks standing in for values and the
//!   annotations a value carries — and printed from there, so this module and the
//!   other readers cannot name one mark two ways. The model-facing wording is a
//!   hand-kept copy in `src/prompt/reference/read.md` (the on-demand detail behind
//!   the `read` tool's short description): a mark renamed in [`crate::reader_output`]
//!   has to be renamed there too. The counts standing in for what the bounds above
//!   leave out are what that reference calls an excess counted.

use super::{
    Relationship, ZipEntry, append_entity, attr, entry_names, is_chart_part, numfmt, part_text,
    read_zip_entry, rel_id, resolve_part, scan_elements,
};
use crate::reader_output::{
    CHART_EXTENDED, CHART_LABEL, CHART_NO_VALUES, CHART_TEXT, CHART_TITLE, CHART_UNREADABLE,
    CHART_VALUES_ATTACHED, MARK_STORED, chart_excess, chart_header, chart_series, chart_size,
};
use crate::util::one_line;
use quick_xml::Reader;
use quick_xml::events::{BytesRef, BytesStart, Event};
use std::borrow::Cow;
use std::collections::{BTreeMap, HashMap};
use std::fmt::Write as _;
use std::io::{Read, Seek};
use zip::ZipArchive;

/// How many chart parts of one package are read. A package that holds more keeps the rest as a loss
/// its census still names, so the number of parts a crafted package carries cannot decide the
/// reading's cost.
const MAX_CHARTS: usize = 64;
const MAX_SERIES: usize = 8;
const MAX_POINTS: usize = 25;
const MAX_TEXTS: usize = 6;
/// How deep a part's elements may nest before it is read as unreadable: the walk keeps one stack
/// entry per level, so a crafted part must not decide its size.
const MAX_DEPTH: usize = 128;

#[derive(Debug)]
pub(crate) enum ChartRead {
    Content {
        kind: Option<String>,
        body: Vec<String>,
        /// Whether the part carried the values its lines show. When it did not, each series' line
        /// says where its values are instead of printing them, and the chart stays in the report
        /// because what it says did not reach the answer.
        values: bool,
    },
    /// The part cannot be read, or is a kind whose own schema this reading does not parse.
    Unreadable(ChartLoss),
}

/// Why a chart part's content is not described.
#[derive(Debug, Clone, Copy)]
pub(crate) enum ChartLoss {
    Part,
    /// The part is a modern extended chart, whose `cx:` schema this reading does not parse.
    Extended,
}

impl ChartLoss {
    const fn mark(self) -> &'static str {
        match self {
            Self::Part => CHART_UNREADABLE,
            Self::Extended => CHART_EXTENDED,
        }
    }
}

impl ChartRead {
    pub(crate) fn described(&self) -> bool {
        matches!(self, Self::Content { values: true, .. })
    }

    /// The chart's lines: a `Chart (<kind>):` header over its content indented by two spaces — or
    /// the one line naming why there is no content.
    pub(crate) fn lines(&self) -> Vec<String> {
        match self {
            Self::Content { kind, body, .. } => {
                let mut lines = vec![chart_header(kind.as_deref())];
                lines.extend(body.iter().map(|line| format!("  {line}")));
                lines
            }
            Self::Unreadable(loss) => vec![format!("{} {}", chart_header(None), loss.mark())],
        }
    }
}

/// Every chart part under `prefix` — the same parts the package's census counts — read into the
/// content a reading prints where the chart sits. `date1904` is the workbook's date system, used
/// for a part that does not state its own.
pub(crate) fn read_charts<R: Read + Seek>(
    archive: &mut ZipArchive<R>,
    prefix: &str,
    date1904: bool,
) -> HashMap<String, ChartRead> {
    let parts: Vec<String> = entry_names(archive)
        .filter(|name| is_chart_part(name, prefix))
        .take(MAX_CHARTS)
        .map(Cow::into_owned)
        .collect();
    parts
        .into_iter()
        .map(|part| {
            let read = match read_zip_entry(archive, &part) {
                ZipEntry::Bytes(xml) => read_part(&xml, date1904),
                ZipEntry::Missing | ZipEntry::Unreadable => ChartRead::Unreadable(ChartLoss::Part),
            };
            (part, read)
        })
        .collect()
}

/// The chart parts `xml` names through `rels`, resolved against the part's own directory (`base`) —
/// in the order the part draws them, and never the same part twice. The reference is the `chart`
/// element of a slide, a worksheet's drawing or a Word body, whichever namespace wraps it.
pub(crate) fn chart_parts(xml: &[u8], rels: &[Relationship], base: &str) -> Vec<String> {
    let mut parts = Vec::new();
    for id in scan_elements(xml, "chart", rel_id).unwrap_or_default() {
        let Some(rel) = rels.iter().find(|rel| rel.id == id) else {
            continue;
        };
        let part = resolve_part(base, &rel.target);
        if !parts.contains(&part) {
            parts.push(part);
        }
    }
    parts
}

/// The content of every chart among `parts` the package holds — printed lines, ready to place where
/// the charts sit — and the parts whose content those lines are, which the package's census leaves
/// out. A caller that does not deliver its block (a slide or a sheet it could not read) records
/// none of them, so no chart leaves both the reading and the report.
pub(crate) fn lines(
    charts: &HashMap<String, ChartRead>,
    parts: &[String],
) -> (Vec<String>, Vec<String>) {
    let mut lines = Vec::new();
    let mut described = Vec::new();
    for part in parts {
        let Some(read) = charts.get(part) else {
            continue;
        };
        if read.described() {
            described.push(part.clone());
        }
        lines.extend(read.lines());
    }
    (lines, described)
}

/// Read one chart part's content. A part that is not a classic chart — an extended one, or one with
/// no chart space at all — is [`ChartRead::Unreadable`], never a chart with no content.
fn read_part(xml: &[u8], date1904: bool) -> ChartRead {
    let mut parser = Parser::new(date1904);
    match parser.run(xml) {
        Ok(()) => parser.finish(),
        Err(loss) => ChartRead::Unreadable(loss),
    }
}

#[derive(Default)]
struct Cache {
    numeric: bool,
    format: Option<String>,
    points: BTreeMap<usize, String>,
    /// How many points the cache held past [`MAX_POINTS`]: counted, never kept.
    more: usize,
}

#[derive(Default)]
struct Series {
    name: Option<String>,
    categories: Vec<Cache>,
    values: Vec<Cache>,
    sizes: Vec<Cache>,
}

impl Series {
    fn slot(&mut self, slot: Slot) -> &mut Vec<Cache> {
        match slot {
            Slot::Category => &mut self.categories,
            Slot::Value => &mut self.values,
            Slot::Size => &mut self.sizes,
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq)]
enum Slot {
    Category,
    Value,
    Size,
}

struct Capture {
    depth: usize,
    kind: CaptureKind,
    text: String,
}

#[derive(Clone, Copy, PartialEq, Eq)]
enum CaptureKind {
    Title,
    Axis,
    Label,
}

struct KindBuilder {
    depth: usize,
    kind: Kind,
    bar_dir: Option<String>,
    grouping: Option<String>,
    of_pie: Option<String>,
}

impl KindBuilder {
    fn name(&self) -> String {
        let grouping = match self.grouping.as_deref() {
            Some("stacked") => "stacked ",
            Some("percentStacked") => "100% stacked ",
            _ => "",
        };
        match self.kind {
            Kind::Area => format!("{grouping}area chart"),
            Kind::Area3D => format!("{grouping}3-D area chart"),
            Kind::Bar => {
                let bars = if self.bar_dir.as_deref() == Some("bar") {
                    "bar"
                } else {
                    "column"
                };
                format!("{grouping}{bars} chart")
            }
            Kind::Bar3D => {
                let bars = if self.bar_dir.as_deref() == Some("bar") {
                    "bar"
                } else {
                    "column"
                };
                format!("{grouping}3-D {bars} chart")
            }
            Kind::Bubble => "bubble chart".to_owned(),
            Kind::Doughnut => "doughnut chart".to_owned(),
            Kind::Line => format!("{grouping}line chart"),
            Kind::Line3D => format!("{grouping}3-D line chart"),
            Kind::OfPie if self.of_pie.as_deref() == Some("bar") => "bar-of-pie chart".to_owned(),
            Kind::OfPie => "pie-of-pie chart".to_owned(),
            Kind::Pie => "pie chart".to_owned(),
            Kind::Pie3D => "3-D pie chart".to_owned(),
            Kind::Radar => "radar chart".to_owned(),
            Kind::Scatter => "scatter chart".to_owned(),
            Kind::Stock => "stock chart".to_owned(),
            Kind::Surface => "surface chart".to_owned(),
            Kind::Surface3D => "3-D surface chart".to_owned(),
        }
    }
}

#[derive(Clone, Copy)]
enum Kind {
    Area,
    Area3D,
    Bar,
    Bar3D,
    Bubble,
    Doughnut,
    Line,
    Line3D,
    OfPie,
    Pie,
    Pie3D,
    Radar,
    Scatter,
    Stock,
    Surface,
    Surface3D,
}

fn kind_of(name: &str) -> Option<Kind> {
    Some(match name {
        "areaChart" => Kind::Area,
        "area3DChart" => Kind::Area3D,
        "barChart" => Kind::Bar,
        "bar3DChart" => Kind::Bar3D,
        "bubbleChart" => Kind::Bubble,
        "doughnutChart" => Kind::Doughnut,
        "lineChart" => Kind::Line,
        "line3DChart" => Kind::Line3D,
        "ofPieChart" => Kind::OfPie,
        "pieChart" => Kind::Pie,
        "pie3DChart" => Kind::Pie3D,
        "radarChart" => Kind::Radar,
        "scatterChart" => Kind::Scatter,
        "stockChart" => Kind::Stock,
        "surfaceChart" => Kind::Surface,
        "surface3DChart" => Kind::Surface3D,
        _ => return None,
    })
}

struct Parser {
    /// The workbook's date system, for a part that does not state its own.
    date1904: bool,
    part_date1904: Option<bool>,
    /// Whether the part's root was a chart space — a part that is no chart at all is not a chart
    /// with no values.
    root: bool,
    stack: Vec<String>,
    kinds: Vec<String>,
    kind: Option<KindBuilder>,
    capture: Option<Capture>,
    title: Option<String>,
    texts: Vec<String>,
    labels: Vec<String>,
    more_texts: usize,
    series: Option<Series>,
    series_depth: Option<usize>,
    series_done: Vec<Series>,
    /// How many series the part held past [`MAX_SERIES`]: counted, never kept.
    more_series: usize,
    slot: Option<(Slot, usize)>,
    point: Option<(usize, usize)>,
    tx_depth: Option<usize>,
    attached: bool,
}

impl Parser {
    fn new(date1904: bool) -> Self {
        Self {
            date1904,
            part_date1904: None,
            root: false,
            stack: Vec::new(),
            kinds: Vec::new(),
            kind: None,
            capture: None,
            title: None,
            texts: Vec::new(),
            labels: Vec::new(),
            more_texts: 0,
            series: None,
            series_depth: None,
            series_done: Vec::new(),
            more_series: 0,
            slot: None,
            point: None,
            tx_depth: None,
            attached: false,
        }
    }

    fn run(&mut self, xml: &[u8]) -> Result<(), ChartLoss> {
        let text = part_text(xml);
        let mut reader = Reader::from_reader(text.as_bytes());
        let mut buffer = Vec::new();
        loop {
            match reader.read_event_into(&mut buffer) {
                Ok(Event::Start(event)) => {
                    let name = event.local_name().as_ref().to_string();
                    self.stack.push(name.clone());
                    self.start(&event, &name)?;
                }
                Ok(Event::Empty(event)) => {
                    let name = event.local_name().as_ref().to_string();
                    self.stack.push(name.clone());
                    self.start(&event, &name)?;
                    self.stack.pop();
                    self.end();
                }
                Ok(Event::Text(event)) => {
                    self.text(&event.xml10_content());
                }
                Ok(Event::CData(event)) => {
                    self.text(&event.xml10_content());
                }
                Ok(Event::GeneralRef(reference)) => self.entity(&reference),
                Ok(Event::End(_)) => {
                    self.stack.pop();
                    self.end();
                }
                Ok(Event::Eof) => break,
                Err(_) => return Err(ChartLoss::Part),
                Ok(_) => {}
            }
            buffer.clear();
        }
        // A part that ended inside an element was cut short, and what it did not reach is a loss
        // rather than a chart with nothing else.
        if !self.root || !self.stack.is_empty() {
            return Err(ChartLoss::Part);
        }
        Ok(())
    }

    fn ancestor(&self, back: usize) -> Option<&str> {
        let index = self.stack.len().checked_sub(back)?;
        self.stack.get(index).map(String::as_str)
    }

    fn start(&mut self, event: &BytesStart<'_>, name: &str) -> Result<(), ChartLoss> {
        let depth = self.stack.len();
        if depth > MAX_DEPTH {
            return Err(ChartLoss::Part);
        }
        if depth == 1 {
            if name != "chartSpace" {
                return Err(ChartLoss::Part);
            }
            // An extended chart's own root: a schema this reading does not parse, said plainly
            // rather than read as a chart with none.
            if event.name().prefix().is_some_and(|p| p.as_ref() == "cx") {
                return Err(ChartLoss::Extended);
            }
            self.root = true;
        }
        match name {
            "chartData" => return Err(ChartLoss::Extended),
            "title" => {
                let kind = if self.ancestor(2) == Some("chart") {
                    CaptureKind::Title
                } else {
                    CaptureKind::Axis
                };
                if self.capture.is_none() {
                    self.capture = Some(Capture {
                        depth,
                        kind,
                        text: String::new(),
                    });
                }
            }
            // A paragraph or a line break inside a captured run starts a new line of it: rich text
            // is joined with a space, never glued.
            "p" | "br" => self.separate(),
            "ser" if self.series.is_none() => {
                if self.series_done.len() < MAX_SERIES {
                    self.series = Some(Series::default());
                    self.series_depth = Some(depth);
                } else {
                    self.more_series += 1;
                }
            }
            "tx" => match self.ancestor(2) {
                Some("ser") => self.tx_depth = Some(depth),
                Some("dLbl") if self.capture.is_none() => {
                    self.capture = Some(Capture {
                        depth,
                        kind: CaptureKind::Label,
                        text: String::new(),
                    });
                }
                _ => {}
            },
            "cat" | "val" | "xVal" | "yVal" | "bubbleSize" => {
                if self.series.is_some() {
                    let slot = match name {
                        "cat" | "xVal" => Slot::Category,
                        "val" | "yVal" => Slot::Value,
                        _ => Slot::Size,
                    };
                    self.slot = Some((slot, depth));
                }
            }
            "numCache" | "strCache" | "numLit" | "strLit" => {
                self.open_cache(matches!(name, "numCache" | "numLit"));
            }
            "lvl" => self.open_cache(false),
            "pt" => {
                if self.slot.is_some()
                    && let Some(index) = attr(event, "idx").and_then(|idx| idx.trim().parse().ok())
                {
                    self.keep_point(index, depth);
                }
            }
            "externalData" => self.attached = true,
            "date1904" => {
                self.part_date1904 =
                    Some(matches!(attr(event, "val").as_deref(), Some("1" | "true")));
            }
            "barDir" | "grouping" | "ofPieType" => {
                if let Some(kind) = self.kind.as_mut() {
                    let value = attr(event, "val");
                    match name {
                        "barDir" => kind.bar_dir = value,
                        "grouping" => kind.grouping = value,
                        _ => kind.of_pie = value,
                    }
                }
            }
            _ => {
                if self.ancestor(2) == Some("plotArea")
                    && let Some(kind) = kind_of(name)
                {
                    self.kind = Some(KindBuilder {
                        depth,
                        kind,
                        bar_dir: None,
                        grouping: None,
                        of_pie: None,
                    });
                }
            }
        }
        Ok(())
    }

    /// Open the next cache of the series slot being read; a cache outside one (a series' own name,
    /// a title's) is not a value this reading prints.
    fn open_cache(&mut self, numeric: bool) {
        let Some((slot, _)) = self.slot else {
            return;
        };
        let Some(series) = self.series.as_mut() else {
            return;
        };
        series.slot(slot).push(Cache {
            numeric,
            ..Cache::default()
        });
    }

    /// Keep the point at `index` of the cache now being read — unless the cache already holds
    /// [`MAX_POINTS`] of them, which the cache counts instead of allocating and formatting. A point
    /// past the cap is read but not kept, so its value reaches nothing.
    fn keep_point(&mut self, index: usize, depth: usize) {
        let Some((slot, _)) = self.slot else {
            return;
        };
        let kept = match self
            .series
            .as_mut()
            .and_then(|series| series.slot(slot).last_mut())
        {
            Some(cache) if cache.points.contains_key(&index) || cache.points.len() < MAX_POINTS => {
                true
            }
            Some(cache) => {
                cache.more += 1;
                false
            }
            None => false,
        };
        if kept {
            self.point = Some((index, depth));
        }
    }

    /// Start a new line of a captured run of text: a rich-text paragraph and a line break both
    /// separate what came before from what follows.
    fn separate(&mut self) {
        if let Some(capture) = self.capture.as_mut() {
            push_break(&mut capture.text);
        } else if self.tx_depth.is_some()
            && let Some(series) = self.series.as_mut()
            && let Some(name) = series.name.as_mut()
        {
            push_break(name);
        }
    }

    fn target(&mut self) -> Option<&mut String> {
        let depth = self.stack.len();
        let leaf = self.stack.last()?.as_str();
        // A title, an axis title or a data label: its rich text runs and its cached string, never
        // the reference it points at.
        if let Some(capture) = self.capture.as_mut()
            && capture.depth < depth
        {
            return matches!(leaf, "t" | "v").then_some(&mut capture.text);
        }
        if let Some(tx) = self.tx_depth
            && tx < depth
        {
            if !matches!(leaf, "t" | "v") {
                return None;
            }
            let series = self.series.as_mut()?;
            return Some(series.name.get_or_insert_with(String::new));
        }
        if leaf == "v"
            && let (Some((index, _)), Some((slot, _))) = (self.point, self.slot)
        {
            let series = self.series.as_mut()?;
            let cache = series.slot(slot).last_mut()?;
            return Some(cache.points.entry(index).or_default());
        }
        match leaf {
            "formatCode" => {
                let (slot, _) = self.slot?;
                let series = self.series.as_mut()?;
                let cache = series.slot(slot).last_mut()?;
                Some(cache.format.get_or_insert_with(String::new))
            }
            _ => None,
        }
    }

    fn text(&mut self, text: &str) {
        if let Some(target) = self.target() {
            target.push_str(text);
        }
    }

    /// File one finished run of text: the title, an axis title or a data label. The last two are
    /// bounded together, so a label per point cannot crowd the axis titles out or grow the
    /// description without limit.
    fn text_read(&mut self, kind: CaptureKind, text: String) {
        if kind == CaptureKind::Title {
            self.title = Some(text);
            return;
        }
        if self.texts.len() + self.labels.len() >= MAX_TEXTS {
            self.more_texts += 1;
            return;
        }
        if kind == CaptureKind::Axis {
            self.texts.push(text);
        } else {
            self.labels.push(text);
        }
    }

    fn entity(&mut self, reference: &BytesRef<'_>) {
        if let Some(target) = self.target() {
            append_entity(target, reference);
        }
    }

    fn end(&mut self) {
        let depth = self.stack.len();
        if self
            .capture
            .as_ref()
            .is_some_and(|capture| capture.depth == depth + 1)
            && let Some(capture) = self.capture.take()
        {
            let text = one_line(capture.text.trim().to_owned());
            if !text.is_empty() {
                self.text_read(capture.kind, text);
            }
        }
        if self.tx_depth == Some(depth + 1) {
            self.tx_depth = None;
        }
        if self
            .slot
            .as_ref()
            .is_some_and(|(_, slot_depth)| *slot_depth == depth + 1)
        {
            self.slot = None;
        }
        if self
            .point
            .as_ref()
            .is_some_and(|(_, point_depth)| *point_depth == depth + 1)
        {
            self.point = None;
        }
        if self
            .kind
            .as_ref()
            .is_some_and(|kind| kind.depth == depth + 1)
            && let Some(kind) = self.kind.take()
        {
            let name = kind.name();
            if !self.kinds.contains(&name) {
                self.kinds.push(name);
            }
        }
        if self.series_depth == Some(depth + 1) {
            self.series_depth = None;
            if let Some(mut series) = self.series.take() {
                series.name = series.name.map(one_line).filter(|name| !name.is_empty());
                self.series_done.push(series);
            }
        }
    }

    /// The part's content: the header's kind and the lines under it — its title, its other text and
    /// one line per series, or the mark standing in for the values a series does not carry.
    fn finish(self) -> ChartRead {
        let date1904 = self.part_date1904.unwrap_or(self.date1904);
        let kind = (!self.kinds.is_empty()).then(|| self.kinds.join(" + "));
        let mut body = Vec::new();
        if let Some(title) = &self.title {
            body.push(format!("{CHART_TITLE} {title}"));
        }
        for text in &self.texts {
            body.push(format!("{CHART_TEXT} {text}"));
        }
        for label in &self.labels {
            body.push(format!("{CHART_LABEL} {label}"));
        }
        if self.more_texts > 0 {
            body.push(chart_excess(self.more_texts, "text(s)"));
        }
        let mut described = false;
        for (index, series) in self.series_done.iter().enumerate() {
            let (line, values) = series_line(index, series, date1904, self.attached);
            described |= values;
            body.push(line);
        }
        if self.more_series > 0 {
            body.push(chart_excess(self.more_series, "series"));
        }
        if self.series_done.is_empty() {
            // A part naming no series at all says what it does not carry the way a series without
            // values does.
            body.push(note(self.attached).to_owned());
        }
        ChartRead::Content {
            kind,
            body,
            values: described,
        }
    }
}

/// The mark standing in for values a chart part does not carry.
const fn note(attached: bool) -> &'static str {
    if attached {
        CHART_VALUES_ATTACHED
    } else {
        CHART_NO_VALUES
    }
}

/// A break between two runs of a captured text, unless `text` is empty or already ends in one.
fn push_break(text: &mut String) {
    if !text.is_empty() && !text.ends_with(' ') {
        text.push(' ');
    }
}

/// One series' line: its label, then its categories and values — `Jan: 10` where the part carries a
/// category label for the value, the value alone where it does not, and a bubble's size beside its
/// value — or, when the part carries none of its values, the categories it does carry and the mark
/// standing in for them. `index` numbers an unnamed series, and the second value says whether the
/// part carried a value for it at all.
fn series_line(index: usize, series: &Series, date1904: bool, attached: bool) -> (String, bool) {
    let label = chart_series(series.name.as_deref(), index);
    let mut stored = false;
    let Some(values) = series
        .values
        .first()
        .filter(|cache| !cache.points.is_empty())
    else {
        // The labels the missing values would be keyed by are the chart's own content, so the
        // categories the part carries are still printed.
        let mut categories = Vec::new();
        for point_index in series
            .categories
            .first()
            .map(|cache| cache.points.keys())
            .into_iter()
            .flatten()
        {
            let (category, category_stored) =
                category_label(&series.categories, *point_index, date1904);
            stored |= category_stored;
            categories.extend(category);
        }
        let mut line = label;
        if !categories.is_empty() {
            let _ = write!(line, " {}", categories.join(", "));
        }
        let _ = write!(line, " {}", note(attached));
        if stored {
            line.push_str(MARK_STORED);
        }
        return (line, false);
    };
    let mut points = Vec::new();
    for point_index in values.points.keys() {
        let Some((value, value_stored)) = point_text(values, *point_index, date1904) else {
            continue;
        };
        stored |= value_stored;
        let (category, category_stored) =
            category_label(&series.categories, *point_index, date1904);
        stored |= category_stored;
        let mut point = match category {
            Some(category) => format!("{category}: {value}"),
            None => value,
        };
        if let Some((size, size_stored)) = series
            .sizes
            .first()
            .and_then(|cache| point_text(cache, *point_index, date1904))
        {
            stored |= size_stored;
            let _ = write!(point, " {}", chart_size(&size));
        }
        points.push(point);
    }
    let mut line = format!("{label} {}", points.join(", "));
    if values.more > 0 {
        let _ = write!(line, ", {}", chart_excess(values.more, "value(s)"));
    }
    if stored {
        line.push_str(MARK_STORED);
    }
    (line, true)
}

/// One cached point as the reading shows it: a number through [`numfmt`] under the cache's own
/// format — the stored text where that format cannot be reproduced, which the second value says —
/// or the text the part wrote.
fn point_text(cache: &Cache, index: usize, date1904: bool) -> Option<(String, bool)> {
    let stored = cache.points.get(&index)?;
    let written = || one_line(stored.trim().to_owned());
    if !cache.numeric {
        return Some((written(), false));
    }
    let format = cache.format.as_deref();
    if numfmt::is_general(0, format) {
        return Some((written(), false));
    }
    let display = stored
        .trim()
        .parse::<f64>()
        .ok()
        .and_then(|value| numfmt::display(value, 0, format, date1904));
    Some(display.map_or_else(|| (written(), true), |text| (text, false)))
}

/// The label of the point at `index`: the innermost level's own entry for it, with each coarser
/// level's label — the last one at or before the index, since a group label spans the points under
/// it — in front of it (`East / Q1`). A single level is just its own entry, and an empty label is
/// no label. The second value says whether a label is shown as stored.
fn category_label(levels: &[Cache], index: usize, date1904: bool) -> (Option<String>, bool) {
    let Some((innermost, coarse)) = levels.split_first() else {
        return (None, false);
    };
    let mut parts: Vec<String> = Vec::new();
    let mut stored = false;
    for level in coarse.iter().rev() {
        if let Some((group, _)) = level.points.range(..=index).next_back()
            && let Some((text, level_stored)) = point_text(level, *group, date1904)
            && !text.is_empty()
        {
            stored |= level_stored;
            parts.push(text);
        }
    }
    if let Some((text, level_stored)) = point_text(innermost, index, date1904)
        && !text.is_empty()
    {
        stored |= level_stored;
        parts.push(text);
    }
    if parts.is_empty() {
        (None, stored)
    } else {
        (Some(parts.join(" / ")), stored)
    }
}

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

    fn chart_space(plot: &str, chart: &str, space: &str) -> String {
        format!(
            r#"<c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">{space}<c:chart>{chart}<c:plotArea>{plot}</c:plotArea></c:chart></c:chartSpace>"#
        )
    }

    fn series(name: &str, categories: &[&str], values: &[&str]) -> String {
        let categories = cache("strCache", None, categories);
        let values = cache("numCache", None, values);
        format!(
            r#"<c:ser><c:tx><c:strRef><c:f>Sheet1!$B$1</c:f><c:strCache><c:pt idx="0"><c:v>{name}</c:v></c:pt></c:strCache></c:strRef></c:tx><c:cat>{categories}</c:cat><c:val>{values}</c:val></c:ser>"#
        )
    }

    fn cache(kind: &str, format: Option<&str>, points: &[&str]) -> String {
        let format = format.map_or_else(String::new, |format| {
            format!("<c:formatCode>{format}</c:formatCode>")
        });
        let mut cached = String::new();
        for (index, value) in points.iter().enumerate() {
            let _ = write!(cached, r#"<c:pt idx="{index}"><c:v>{value}</c:v></c:pt>"#);
        }
        format!(r"<c:{kind}>{format}{cached}</c:{kind}>")
    }

    fn lines_of(xml: &str) -> Vec<String> {
        read_part(xml.as_bytes(), false).lines()
    }

    /// A chart's content is printed as its kind, its title, its other text and one line per series
    /// of category and value. A rich-text title keeps its paragraphs apart, and a data label's own
    /// text prints under its own label, so a model can tell it from an axis title.
    #[test]
    fn a_chart_is_described_by_its_kind_title_and_series() {
        let plot = format!(
            r#"<c:barChart><c:barDir val="col"/><c:grouping val="clustered"/><c:ser><c:tx><c:strRef><c:f>Sheet1!$B$1</c:f><c:strCache><c:pt idx="0"><c:v>Revenue</c:v></c:pt></c:strCache></c:strRef></c:tx><c:cat>{}</c:cat><c:val>{}</c:val></c:ser>{}</c:barChart><c:catAx><c:title><c:tx><c:rich><a:p><a:r><a:t>Month</a:t></a:r></a:p></c:rich></c:tx></c:title></c:catAx>"#,
            cache("strCache", None, &["Jan", "Feb"]),
            cache("numCache", Some("General"), &["10", "20"]),
            series("Cost", &["Jan", "Feb"], &["4", "8"]),
        );
        let title = r"<c:title><c:tx><c:rich><a:p><a:r><a:t>Sales by region</a:t></a:r></a:p></c:rich></c:tx></c:title>";
        let labelled = format!(
            r#"<c:barChart><c:barDir val="col"/><c:ser>{}</c:ser><c:dLbls><c:dLbl><c:tx><c:rich><a:p><a:r><a:t>Peak</a:t></a:r></a:p></c:rich></c:tx></c:dLbl></c:dLbls></c:barChart>"#,
            r#"<c:val><c:numCache><c:pt idx="0"><c:v>10</c:v></c:pt></c:numCache></c:val>"#,
        );
        let rich_title = r"<c:title><c:tx><c:rich><a:p><a:r><a:t>Sales</a:t></a:r></a:p><a:p><a:r><a:t>by region</a:t></a:r></a:p></c:rich></c:tx></c:title>";
        for (label, xml, shown) in [
            (
                "a kind, a title, an axis text and two series",
                chart_space(&plot, title, ""),
                &[
                    "Chart (column chart):",
                    "  Title: Sales by region",
                    "  Text: Month",
                    "  Series \"Revenue\": Jan: 10, Feb: 20",
                    "  Series \"Cost\": Jan: 4, Feb: 8",
                ][..],
            ),
            (
                "a rich-text title and a data label kept apart",
                chart_space(&labelled, rich_title, ""),
                &[
                    "Chart (column chart):",
                    "  Title: Sales by region",
                    "  Label: Peak",
                    "  Series 1: 10",
                ][..],
            ),
        ] {
            assert_eq!(lines_of(&xml), shown, "{label}");
        }
    }

    /// A series without a name is numbered, a chart without a plot type prints no kind, several
    /// plot types are named together, and a scatter chart's x values are the labels its y values
    /// are paired with. A multi-level category list prints its levels root first, a group label
    /// stated once spanning every point under it, and a bubble chart prints each value's size
    /// beside it.
    #[test]
    fn kinds_names_and_scatter_are_all_printed() {
        let plot = format!(
            r#"<c:barChart><c:barDir val="bar"/><c:grouping val="stacked"/><c:ser><c:cat>{}</c:cat><c:val>{}</c:val></c:ser></c:barChart><c:scatterChart><c:ser><c:tx><c:strRef><c:strCache><c:pt idx="0"><c:v>Points</c:v></c:pt></c:strCache></c:strRef></c:tx><c:xVal>{}</c:xVal><c:yVal>{}</c:yVal></c:ser></c:scatterChart>"#,
            cache("strCache", None, &["A"]),
            cache("numCache", None, &["1"]),
            cache("numCache", None, &["1", "2"]),
            cache("numCache", None, &["10", "20"]),
        );
        let two_levels = format!(
            r"<c:multiLvlStrRef><c:multiLvlStrCache>{}{}</c:multiLvlStrCache></c:multiLvlStrRef>",
            cache("lvl", None, &["Q1", "Q2"]),
            cache("lvl", None, &["East", "West"]),
        );
        let spanning = format!(
            r"<c:multiLvlStrRef><c:multiLvlStrCache>{}{}</c:multiLvlStrCache></c:multiLvlStrRef>",
            cache("lvl", None, &["Q1", "Q2"]),
            cache("lvl", None, &["East"]),
        );
        let sizes = cache("numCache", None, &["5", "7"]);
        let values = cache("numCache", None, &["10", "20"]);
        let bubble = |categories: &str| {
            format!(
                r"<c:bubbleChart><c:ser><c:cat>{categories}</c:cat><c:val>{values}</c:val><c:bubbleSize>{sizes}</c:bubbleSize></c:ser></c:bubbleChart>"
            )
        };
        for (label, xml, shown) in [
            (
                "several kinds, a numbered series and a scatter chart",
                chart_space(&plot, "", ""),
                &[
                    "Chart (stacked bar chart + scatter chart):",
                    "  Series 1: A: 1",
                    "  Series \"Points\": 1: 10, 2: 20",
                ][..],
            ),
            (
                "a chart naming no kind",
                chart_space("", "", ""),
                &["Chart:", "  (no values in the chart part)"][..],
            ),
            (
                "multi-level categories and bubble sizes",
                chart_space(&bubble(&two_levels), "", ""),
                &[
                    "Chart (bubble chart):",
                    "  Series 1: East / Q1: 10 (size 5), West / Q2: 20 (size 7)",
                ][..],
            ),
            (
                "a group label stated once spanning its points",
                chart_space(&bubble(&spanning), "", ""),
                &[
                    "Chart (bubble chart):",
                    "  Series 1: East / Q1: 10 (size 5), East / Q2: 20 (size 7)",
                ][..],
            ),
        ] {
            assert_eq!(lines_of(&xml), shown, "{label}");
        }
    }

    /// A cut chart part is a loss, not a chart whose content happens to end where the package
    /// stopped — and so is a part nested past the depth bound, a walk that would keep a stack entry
    /// per level for a document to decide.
    #[test]
    fn a_cut_part_is_a_loss() {
        let cut = r#"<c:chartSpace xmlns:c="x"><c:chart><c:plotArea><c:barChart><c:ser><c:tx><c:strRef><c:strCache><c:pt idx="0"><c:v>Revenue</c:v>"#;
        let deep = format!(
            r#"<c:chartSpace xmlns:c="x"><c:chart><c:plotArea><c:barChart>{}{}</c:barChart></c:plotArea></c:chart></c:chartSpace>"#,
            "<c:x>".repeat(MAX_DEPTH),
            "</c:x>".repeat(MAX_DEPTH),
        );
        for (label, part) in [
            ("a part cut short", cut),
            ("a part nested past the bound", deep.as_str()),
        ] {
            assert_eq!(
                read_part(part.as_bytes(), false).lines(),
                ["Chart: (the chart part could not be read)"],
                "{label}"
            );
        }
    }

    /// A chart whose values are only referenced states that for the series that carries none, keeps
    /// the names the part does carry, and one whose table is attached says where its values are
    /// instead of claiming the file holds none.
    #[test]
    fn a_chart_without_cached_values_says_where_its_numbers_are() {
        let plot = r#"<c:barChart><c:barDir val="col"/><c:ser><c:tx><c:strRef><c:f>Sheet1!$B$1</c:f></c:strRef></c:tx><c:val><c:numRef><c:f>Sheet1!$B$2:$B$3</c:f></c:numRef></c:val></c:ser></c:barChart>"#;
        let external = r#"<c:externalData r:id="rId1"/>"#;
        let title = r"<c:title><c:tx><c:rich><a:p><a:r><a:t>Sales</a:t></a:r></a:p></c:rich></c:tx></c:title>";
        let named = r#"<c:barChart><c:barDir val="col"/><c:ser><c:tx><c:strRef><c:f>Sheet1!$B$1</c:f><c:strCache><c:pt idx="0"><c:v>Revenue</c:v></c:pt></c:strCache></c:strRef></c:tx><c:val><c:numRef><c:f>Sheet1!$B$2:$B$3</c:f></c:numRef></c:val></c:ser></c:barChart>"#;
        let labelled = format!(
            r#"<c:barChart><c:barDir val="col"/><c:ser><c:cat>{}</c:cat><c:val><c:numRef><c:f>Sheet1!$B$2:$B$3</c:f></c:numRef></c:val></c:ser></c:barChart>"#,
            cache("strCache", None, &["Jan", "Feb"]),
        );
        let uncached = r"<c:ser><c:tx><c:strRef><c:f>Sheet1!$C$1</c:f></c:strRef></c:tx><c:val><c:numRef><c:f>Sheet1!$C$2:$C$3</c:f></c:numRef></c:val></c:ser>";
        let mixed = format!(
            r#"<c:barChart><c:barDir val="col"/><c:ser><c:tx><c:strRef><c:strCache><c:pt idx="0"><c:v>Revenue</c:v></c:pt></c:strCache></c:strRef></c:tx><c:val><c:numCache><c:pt idx="0"><c:v>10</c:v></c:pt></c:numCache></c:val></c:ser>{uncached}</c:barChart>"#
        );
        for (label, xml, shown) in [
            (
                "a series whose values are only referenced",
                chart_space(plot, "", ""),
                &[
                    "Chart (column chart):",
                    "  Series 1: (no values in the chart part)",
                ][..],
            ),
            (
                "a chart with its table attached",
                chart_space(plot, "", external),
                &[
                    "Chart (column chart):",
                    "  Series 1: (values only in the attached table)",
                ][..],
            ),
            (
                "the title and the name the part does carry",
                chart_space(named, title, external),
                &[
                    "Chart (column chart):",
                    "  Title: Sales",
                    "  Series \"Revenue\": (values only in the attached table)",
                ][..],
            ),
            (
                "the categories the part still caches",
                chart_space(&labelled, "", ""),
                &[
                    "Chart (column chart):",
                    "  Series 1: Jan, Feb (no values in the chart part)",
                ][..],
            ),
            (
                "one cached series beside one that is not",
                chart_space(&mixed, "", ""),
                &[
                    "Chart (column chart):",
                    "  Series \"Revenue\": 10",
                    "  Series 2: (no values in the chart part)",
                ][..],
            ),
        ] {
            assert_eq!(lines_of(&xml), shown, "{label}");
        }
        // A chart whose every series is uncached keeps its place in the report.
        assert!(
            !read_part(chart_space(plot, "", "").as_bytes(), false).described(),
            "a chart with no cached values is still described"
        );
    }

    /// The description is bounded: the series, the points and the other texts past their caps are
    /// counted, never silently dropped.
    #[test]
    fn the_description_is_bounded_and_says_what_it_left_out() {
        let values: Vec<String> = (0..(MAX_POINTS + 3)).map(|i| i.to_string()).collect();
        let values: Vec<&str> = values.iter().map(String::as_str).collect();
        let sers: String = (0..(MAX_SERIES + 2))
            .map(|i| series(&format!("S{i}"), &[], &values))
            .collect();
        let axes = (0..=MAX_TEXTS).fold(String::new(), |mut axes, i| {
            let _ = write!(
                axes,
                r"<c:catAx><c:title><c:tx><c:rich><a:p><a:r><a:t>T{i}</a:t></a:r></a:p></c:rich></c:tx></c:title></c:catAx>"
            );
            axes
        });
        let plot = format!(r"<c:lineChart>{sers}{axes}</c:lineChart>");
        let lines = lines_of(&chart_space(&plot, "", ""));
        assert_eq!(lines[0], "Chart (line chart):", "the kind line");
        assert_eq!(
            lines.len(),
            1 + MAX_TEXTS + 1 + MAX_SERIES + 1,
            "one line per kept text and series, and one per excess"
        );
        assert_eq!(
            lines[MAX_TEXTS + 1],
            format!("  {} more text(s)", 1),
            "the texts past the cap are counted"
        );
        assert_eq!(
            lines.last().map(String::as_str),
            Some("  2 more series"),
            "the series past the cap are counted"
        );
        assert!(
            lines[MAX_TEXTS + 2].ends_with(", 3 more value(s)"),
            "{:?}",
            lines[MAX_TEXTS + 2]
        );
    }

    /// The chart block's header, its series label and every mark and annotation a chart's lines
    /// carry are names the document kit's refusals know, so a find copied out of a reading that
    /// carries one is refused for what it is rather than searched for as the document's own text.
    #[test]
    fn the_marks_the_kit_refuses_are_the_ones_a_reading_prints() {
        let patterns: Vec<regex::Regex> = crate::docgen::docx_marks()
            .iter()
            .map(|mark| regex::Regex::new(&mark.pattern).expect("a mark's own pattern"))
            .collect();
        for mark in [
            chart_header(Some("column chart")),
            chart_series(Some("Revenue"), 0),
            chart_size("12"),
            chart_excess(3, "value(s)"),
            chart_excess(1, "series"),
            chart_excess(1, "text(s)"),
            MARK_STORED.trim().to_owned(),
            CHART_NO_VALUES.to_owned(),
            CHART_VALUES_ATTACHED.to_owned(),
            CHART_UNREADABLE.to_owned(),
            CHART_EXTENDED.to_owned(),
        ] {
            assert!(
                patterns.iter().any(|pattern| pattern.is_match(&mark)),
                "{mark:?} is a mark a chart reading prints, which no entry of the shared list \
                 names — a mark the kit refuses belongs in assets/docgen/rules.json's docx_marks"
            );
        }
        assert!(
            !patterns
                .iter()
                .any(|pattern| pattern.is_match(&chart_header(None))),
            "a bare `Chart:` is a document's own word, never a refusal"
        );
    }
}