opencrabs 0.5.11

The autonomous, self-improving AI agent. Single Rust binary. Every channel. Recommended: the 40MB prebuilt binary for macOS, Linux and Windows: https://github.com/opencrabs/opencrabs/releases
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
//! Per-dialog scoped keymaps — the single source of truth for which keys
//! do what inside each modal surface (#1775).
//!
//! Before this module, every dialog hand-rolled its own footer `Span` list
//! (three formats, five stylings), and nothing tied the displayed hints to
//! the keys the input handler actually consumed, so the two drifted: the
//! Inbox detail popup showed a CLI command that is not even on the PATH,
//! and the tool-approval dialog advertised none of its D/Esc deny keys.
//!
//! Now one table per dialog feeds both directions: the render side builds
//! every footer and the Ctrl+C command panel from [`dialog_keys`], and the
//! drift tests replay each declared event into the surface's real input
//! decision function to prove the handler still consumes it. A key that
//! stops being handled fails the test; a hint that was never true cannot
//! be written.

use crossterm::event::{KeyCode, KeyModifiers};

/// Which dialog's keys we are describing. One variant per surface that
/// takes over input while open — the ticket's locked definition of
/// "modal = dialog = popup". Full-area views (help, settings, usage)
/// count: they capture input and Esc returns, which is the behavior even
/// if the chrome is a mode switch.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DialogScope {
    FilePicker,
    DirectoryPicker,
    RestartPending,
    UpdatePrompt,
    ThemePicker,
    PlanOverlay,
    Help,
    Settings,
    UsageDashboard,
    /// The usage dashboard's cache price breakdown, open over the grid
    /// (#2027). Esc backs out to the dashboard, and that is the only key
    /// it has.
    UsageCacheBreakdown,
    SkillsDialog,
    ProfilesDialog,
    MissionControl,
    /// Inbox proposal detail — the one detail popup with verbs.
    McDetailPopup,
    /// Activity / schedule / analytics detail — read-and-close only.
    McDetailRead,
    McLogViewer,
    /// Inline tool approval (Yes / Always / No) in the chat.
    ToolApproval,
    /// The `/approve` policy selector menu.
    ApprovePolicyMenu,
    /// The SSH password prompt. No inline footer (it renders inside the
    /// input area); the scope exists so Ctrl+C can show its keys.
    SshPassword,
}

impl DialogScope {
    /// Human name shown in the Ctrl+C command panel title.
    pub fn title(self) -> &'static str {
        match self {
            DialogScope::FilePicker => "File picker",
            DialogScope::DirectoryPicker => "Directory picker",
            DialogScope::RestartPending => "Restart",
            DialogScope::UpdatePrompt => "Update",
            DialogScope::ThemePicker => "Theme picker",
            DialogScope::PlanOverlay => "Plan",
            DialogScope::Help => "Help",
            DialogScope::Settings => "Settings",
            DialogScope::UsageDashboard => "Usage",
            DialogScope::UsageCacheBreakdown => "Cache prices",
            DialogScope::SkillsDialog => "Skills",
            DialogScope::ProfilesDialog => "Profiles",
            DialogScope::MissionControl => "Mission Control",
            DialogScope::McDetailPopup => "Inbox detail",
            DialogScope::McDetailRead => "Detail",
            DialogScope::McLogViewer => "Log viewer",
            DialogScope::ToolApproval => "Tool approval",
            DialogScope::ApprovePolicyMenu => "Approval policy",
            DialogScope::SshPassword => "SSH password",
        }
    }
}

/// One key binding: the events that fire it, plus how it is displayed.
///
/// `Copy` so a surface that shows a state-filtered subset of its table can
/// hand the footer the entries directly (#2027).
#[derive(Debug, Clone, Copy)]
pub struct DialogKey {
    /// Key events the surface's input handler recognizes for this
    /// binding. The drift tests replay each of these into the handler.
    /// Empty for pseudo-bindings ("type to filter") that have no single
    /// key event. No runtime code reads this: it exists for the
    /// `#[cfg(test)]` drift tests, which is the whole point of the
    /// catalog — the footer can only advertise keys the handler consumes.
    #[allow(dead_code)] // read exclusively by the drift tests in src/tests/
    pub events: &'static [(KeyCode, KeyModifiers)],
    /// Footer display form, e.g. `a`, `Esc`, `↑↓`.
    pub label: &'static str,
    /// What the key does, e.g. `apply`.
    pub verb: &'static str,
}

const fn k(code: KeyCode) -> (KeyCode, KeyModifiers) {
    (code, KeyModifiers::NONE)
}

/// The scoped keymap for `scope`, in footer display order.
///
/// Order is part of the contract: the footer renders exactly this order,
/// and where a surface shows a state-dependent subset (plan overlay), the
/// subsets are suffixes so slicing stays honest.
const TABLE_1: &[DialogKey] = &[
    DialogKey {
        events: &[k(KeyCode::Up), k(KeyCode::Down)],
        label: "↑↓",
        verb: "navigate",
    },
    DialogKey {
        events: &[k(KeyCode::Enter), k(KeyCode::Tab)],
        label: "Enter/Tab",
        verb: "select",
    },
    DialogKey {
        events: &[],
        label: "type",
        verb: "filter",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "cancel",
    },
];

const TABLE_2: &[DialogKey] = &[
    DialogKey {
        events: &[k(KeyCode::Up), k(KeyCode::Down)],
        label: "↑↓",
        verb: "navigate",
    },
    DialogKey {
        events: &[k(KeyCode::Enter)],
        label: "Enter",
        verb: "open",
    },
    DialogKey {
        events: &[k(KeyCode::Char(' ')), k(KeyCode::Tab)],
        label: "Space/Tab",
        verb: "select here",
    },
    DialogKey {
        events: &[k(KeyCode::Char('.')), k(KeyCode::Char('>'))],
        label: ".",
        verb: "hidden",
    },
    DialogKey {
        events: &[],
        label: "type",
        verb: "filter",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "cancel",
    },
];

const TABLE_3: &[DialogKey] = &[
    DialogKey {
        events: &[k(KeyCode::Enter)],
        label: "Enter",
        verb: "confirm",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "cancel",
    },
];

const TABLE_4: &[DialogKey] = &[
    DialogKey {
        events: &[
            k(KeyCode::Up),
            k(KeyCode::Down),
            k(KeyCode::PageUp),
            k(KeyCode::PageDown),
        ],
        label: "↑↓",
        verb: "preview",
    },
    DialogKey {
        events: &[k(KeyCode::Enter)],
        label: "Enter",
        verb: "apply",
    },
    DialogKey {
        events: &[k(KeyCode::Esc), k(KeyCode::Char('q'))],
        label: "Esc/q",
        verb: "cancel",
    },
];

const TABLE_5: &[DialogKey] = &[
    DialogKey {
        events: &[k(KeyCode::Char('a'))],
        label: "a",
        verb: "approve",
    },
    DialogKey {
        events: &[k(KeyCode::Char('d'))],
        label: "d",
        verb: "discard",
    },
    DialogKey {
        events: &[
            k(KeyCode::Up),
            k(KeyCode::Down),
            k(KeyCode::PageUp),
            k(KeyCode::PageDown),
        ],
        label: "↑↓",
        verb: "scroll",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "close",
    },
];

const TABLE_6: &[DialogKey] = &[
    DialogKey {
        events: &[
            k(KeyCode::Up),
            k(KeyCode::Down),
            k(KeyCode::PageUp),
            k(KeyCode::PageDown),
        ],
        label: "↑↓",
        verb: "scroll",
    },
    DialogKey {
        events: &[k(KeyCode::Char('/'))],
        label: "/",
        verb: "search",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "back",
    },
];

const TABLE_7: &[DialogKey] = &[
    DialogKey {
        events: &[
            k(KeyCode::Up),
            k(KeyCode::Down),
            k(KeyCode::PageUp),
            k(KeyCode::PageDown),
        ],
        label: "↑↓",
        verb: "scroll",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "back",
    },
];

const TABLE_8: &[DialogKey] = &[
    DialogKey {
        events: &[k(KeyCode::Tab), k(KeyCode::BackTab)],
        label: "Tab",
        verb: "switch",
    },
    DialogKey {
        events: &[k(KeyCode::Enter)],
        label: "Enter",
        verb: "details",
    },
    DialogKey {
        events: &[
            k(KeyCode::Char('t')),
            k(KeyCode::Char('w')),
            k(KeyCode::Char('m')),
            k(KeyCode::Char('a')),
        ],
        label: "T/W/M/A",
        verb: "period",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "close",
    },
];

const TABLE_9: &[DialogKey] = &[
    DialogKey {
        events: &[k(KeyCode::Tab), k(KeyCode::Up), k(KeyCode::Down)],
        label: "Tab/↑↓",
        verb: "navigate",
    },
    DialogKey {
        events: &[k(KeyCode::Enter)],
        label: "Enter",
        verb: "run",
    },
    DialogKey {
        events: &[],
        label: "type",
        verb: "filter",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "close",
    },
];

const TABLE_10: &[DialogKey] = &[
    DialogKey {
        events: &[k(KeyCode::Char('n'))],
        label: "n",
        verb: "new",
    },
    DialogKey {
        events: &[k(KeyCode::Char('d'))],
        label: "d",
        verb: "delete",
    },
    DialogKey {
        events: &[k(KeyCode::Char('m'))],
        label: "m",
        verb: "migrate",
    },
    DialogKey {
        events: &[k(KeyCode::Enter)],
        label: "Enter",
        verb: "switch",
    },
    DialogKey {
        events: &[k(KeyCode::Tab), k(KeyCode::Up), k(KeyCode::Down)],
        label: "Tab/↑↓",
        verb: "navigate",
    },
    DialogKey {
        events: &[],
        label: "type",
        verb: "filter",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "close",
    },
];

const TABLE_11: &[DialogKey] = &[
    DialogKey {
        events: &[
            k(KeyCode::Tab),
            (KeyCode::BackTab, KeyModifiers::SHIFT),
            k(KeyCode::Char('h')),
            k(KeyCode::Char('l')),
        ],
        label: "Tab/h/l",
        verb: "switch panel",
    },
    DialogKey {
        events: &[
            k(KeyCode::Up),
            k(KeyCode::Down),
            k(KeyCode::Char('k')),
            k(KeyCode::Char('j')),
        ],
        label: "↑↓",
        verb: "navigate",
    },
    DialogKey {
        events: &[k(KeyCode::Enter)],
        label: "Enter",
        verb: "detail",
    },
    DialogKey {
        events: &[k(KeyCode::Char('a'))],
        label: "a",
        verb: "apply",
    },
    DialogKey {
        events: &[k(KeyCode::Char('r'))],
        label: "r",
        verb: "reject",
    },
    DialogKey {
        events: &[
            k(KeyCode::Char('d')),
            k(KeyCode::Char('w')),
            k(KeyCode::Char('m')),
            k(KeyCode::Char('A')),
        ],
        label: "D/W/M/A",
        verb: "filter",
    },
    DialogKey {
        events: &[k(KeyCode::Char('L'))],
        label: "L",
        verb: "logs",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "close",
    },
];

const TABLE_12: &[DialogKey] = &[
    DialogKey {
        events: &[
            k(KeyCode::Up),
            k(KeyCode::Down),
            k(KeyCode::Char('k')),
            k(KeyCode::Char('j')),
        ],
        label: "↑↓",
        verb: "navigate",
    },
    DialogKey {
        events: &[k(KeyCode::Char('a'))],
        label: "a",
        verb: "apply",
    },
    DialogKey {
        events: &[k(KeyCode::Char('r'))],
        label: "r",
        verb: "reject",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "close",
    },
];

const TABLE_13: &[DialogKey] = &[
    DialogKey {
        events: &[
            k(KeyCode::Up),
            k(KeyCode::Down),
            k(KeyCode::Char('k')),
            k(KeyCode::Char('j')),
        ],
        label: "↑↓",
        verb: "navigate",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "close",
    },
];

const TABLE_14: &[DialogKey] = &[
    DialogKey {
        events: &[k(KeyCode::Char('/'))],
        label: "/",
        verb: "search",
    },
    DialogKey {
        events: &[
            k(KeyCode::Up),
            k(KeyCode::Down),
            k(KeyCode::PageUp),
            k(KeyCode::PageDown),
        ],
        label: "↑↓",
        verb: "scroll",
    },
    DialogKey {
        events: &[
            k(KeyCode::Home),
            k(KeyCode::Char('g')),
            k(KeyCode::End),
            k(KeyCode::Char('G')),
        ],
        label: "g/G",
        verb: "top/bottom",
    },
    DialogKey {
        events: &[k(KeyCode::Char('[')), k(KeyCode::Char(']'))],
        label: "[ ]",
        verb: "file",
    },
    DialogKey {
        events: &[
            k(KeyCode::Char('1')),
            k(KeyCode::Char('2')),
            k(KeyCode::Char('3')),
            k(KeyCode::Char('4')),
            k(KeyCode::Char('5')),
            k(KeyCode::Char('e')),
            k(KeyCode::Char('w')),
            k(KeyCode::Char('i')),
            k(KeyCode::Char('d')),
            k(KeyCode::Char('t')),
        ],
        label: "1-5/e/w/i/d",
        verb: "level",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "close",
    },
];

const TABLE_15: &[DialogKey] = &[
    DialogKey {
        events: &[
            k(KeyCode::Up),
            k(KeyCode::Down),
            k(KeyCode::Left),
            k(KeyCode::Right),
        ],
        label: "↑↓",
        verb: "navigate",
    },
    DialogKey {
        events: &[k(KeyCode::Char('a'))],
        label: "a",
        verb: "approve",
    },
    DialogKey {
        events: &[k(KeyCode::Enter)],
        label: "Enter",
        verb: "confirm",
    },
    DialogKey {
        events: &[
            k(KeyCode::Char('D')),
            k(KeyCode::Char('r')),
            k(KeyCode::Esc),
        ],
        label: "D/r/Esc",
        verb: "deny",
    },
    DialogKey {
        events: &[k(KeyCode::Char('V'))],
        label: "V",
        verb: "details",
    },
];

const TABLE_16: &[DialogKey] = &[
    DialogKey {
        events: &[k(KeyCode::Up), k(KeyCode::Down)],
        label: "↑↓",
        verb: "navigate",
    },
    DialogKey {
        events: &[k(KeyCode::Enter)],
        label: "Enter",
        verb: "confirm",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "cancel",
    },
];

const TABLE_17: &[DialogKey] = &[
    DialogKey {
        events: &[k(KeyCode::Enter)],
        label: "Enter",
        verb: "submit",
    },
    DialogKey {
        events: &[],
        label: "type",
        verb: "password",
    },
    DialogKey {
        events: &[k(KeyCode::Esc)],
        label: "Esc",
        verb: "cancel",
    },
];

/// The cache price breakdown on the usage dashboard (#2027). The table is a
/// detail view over the grid: the dashboard's own keys are inert while it is
/// open, so Esc is the whole keymap.
const TABLE_18: &[DialogKey] = &[DialogKey {
    events: &[k(KeyCode::Esc)],
    label: "Esc",
    verb: "close",
}];

pub fn dialog_keys(scope: DialogScope) -> &'static [DialogKey] {
    match scope {
        DialogScope::FilePicker => TABLE_1,
        DialogScope::DirectoryPicker => TABLE_2,
        DialogScope::RestartPending | DialogScope::UpdatePrompt => TABLE_3,
        DialogScope::ThemePicker => TABLE_4,
        // Suffix-ordered: every plan state shows a true suffix of this
        // table (PostInitEditing: all; Active / PreInitEditing: from
        // "d"; NoPlan: from "Esc").
        DialogScope::PlanOverlay => TABLE_5,
        DialogScope::Help => TABLE_6,
        DialogScope::Settings => TABLE_7,
        DialogScope::UsageDashboard => TABLE_8,
        DialogScope::UsageCacheBreakdown => TABLE_18,
        DialogScope::SkillsDialog => TABLE_9,
        DialogScope::ProfilesDialog => TABLE_10,
        DialogScope::MissionControl => TABLE_11,
        DialogScope::McDetailPopup => TABLE_12,
        DialogScope::McDetailRead => TABLE_13,
        DialogScope::McLogViewer => TABLE_14,
        DialogScope::ToolApproval => TABLE_15,
        DialogScope::ApprovePolicyMenu => TABLE_16,
        DialogScope::SshPassword => TABLE_17,
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::tui::app::mission_control::McPanel;
    use crate::tui::app::mission_control::input::{KeyOutcome, decide};
    use crate::tui::app::mission_control::state::McState;

    /// Every scope has a non-empty table with unique labels and non-empty
    /// verbs — a scope with an empty or duplicated table renders a broken
    /// footer or command panel.
    #[test]
    fn every_scope_has_a_unique_table() {
        for scope in all_scopes() {
            let keys = dialog_keys(scope);
            assert!(!keys.is_empty(), "{scope:?} has no keys");
            let mut labels: Vec<&str> = keys.iter().map(|k| k.label).collect();
            labels.sort_unstable();
            let n = labels.len();
            labels.dedup();
            assert_eq!(labels.len(), n, "{scope:?} has duplicate labels");
            for key in keys {
                assert!(!key.verb.is_empty(), "{scope:?} empty verb");
            }
        }
    }

    /// The list of every scope, so catalog-wide tests cannot silently skip
    /// a variant added later.
    fn all_scopes() -> Vec<DialogScope> {
        vec![
            DialogScope::FilePicker,
            DialogScope::DirectoryPicker,
            DialogScope::RestartPending,
            DialogScope::UpdatePrompt,
            DialogScope::ThemePicker,
            DialogScope::PlanOverlay,
            DialogScope::Help,
            DialogScope::Settings,
            DialogScope::UsageDashboard,
            DialogScope::UsageCacheBreakdown,
            DialogScope::SkillsDialog,
            DialogScope::ProfilesDialog,
            DialogScope::MissionControl,
            DialogScope::McDetailPopup,
            DialogScope::McDetailRead,
            DialogScope::McLogViewer,
            DialogScope::ToolApproval,
            DialogScope::ApprovePolicyMenu,
            DialogScope::SshPassword,
        ]
    }

    /// DRIFT TEST — the footer's contract with the input handler.
    ///
    /// For every Mission Control key the footer advertises, replaying it
    /// through the real `decide()` must not fall through as unhandled.
    /// Each event replays against a fresh clone of the base state: the
    /// table is display order, not a user keystroke sequence, and one
    /// advertised key (Enter) opens the popup that would swallow the
    /// next one's routing.
    #[test]
    fn mission_control_footer_keys_are_all_consumed() {
        let base = McState::default();
        let count = 3;
        for key in dialog_keys(DialogScope::MissionControl) {
            for (code, mods) in key.events {
                let mut state = base.clone();
                let event = crossterm::event::KeyEvent::new(*code, *mods);
                let outcome = decide(&mut state, count, event);
                assert_ne!(
                    outcome,
                    KeyOutcome::NotConsumed,
                    "footer advertises {:?} ({}) but decide() does not consume it",
                    code,
                    key.label
                );
            }
        }
    }

    /// DRIFT TEST for the detail popup scope, including the a/r verbs the
    /// popup footer advertises — the exact gap the ticket was filed on:
    /// the popup showed apply/reject guidance while its handler ignored
    /// both keys.
    #[test]
    fn detail_popup_footer_keys_are_all_consumed() {
        let make = |focused| McState {
            detail_open: true,
            focused_panel: focused,
            ..McState::default()
        };
        let count = 2;
        for scope in [DialogScope::McDetailPopup, DialogScope::McDetailRead] {
            for key in dialog_keys(scope) {
                for (code, mods) in key.events {
                    // Fresh state per event: Esc closes the popup and
                    // would re-route every later key.
                    let mut state = make(McPanel::Inbox);
                    let event = crossterm::event::KeyEvent::new(*code, *mods);
                    let outcome = decide(&mut state, count, event);
                    assert_ne!(
                        outcome,
                        KeyOutcome::NotConsumed,
                        "{scope:?}: footer advertises {:?} ({}) but decide_with_popup does not consume it",
                        code,
                        key.label
                    );
                }
            }
        }
    }

    /// The apply/reject verbs must actually fire from inside the popup,
    /// not merely be swallowed.
    #[test]
    fn detail_popup_apply_and_reject_fire() {
        use crossterm::event::KeyCode;
        let mut state = McState {
            detail_open: true,
            ..Default::default()
        };
        let count = 2;
        let apply = decide(
            &mut state,
            count,
            crossterm::event::KeyEvent::new(KeyCode::Char('a'), KeyModifiers::NONE),
        );
        assert_eq!(apply, KeyOutcome::ApplySelected);
        let reject = decide(
            &mut state,
            count,
            crossterm::event::KeyEvent::new(KeyCode::Char('r'), KeyModifiers::NONE),
        );
        assert_eq!(reject, KeyOutcome::RejectSelected);
    }

    /// DRIFT TEST for the log viewer scope. Fresh state per event: `/`
    /// arms search mode and every later printable key would become
    /// search text rather than its own binding.
    #[test]
    fn log_viewer_footer_keys_are_all_consumed() {
        let make = || McState {
            log_viewer: Some(crate::tui::app::mission_control::log_viewer::LogViewerState::open()),
            ..McState::default()
        };
        for key in dialog_keys(DialogScope::McLogViewer) {
            for (code, mods) in key.events {
                let mut state = make();
                let event = crossterm::event::KeyEvent::new(*code, *mods);
                let outcome = decide(&mut state, 5, event);
                assert_ne!(
                    outcome,
                    KeyOutcome::NotConsumed,
                    "log viewer advertises {:?} ({}) but decide_in_log_viewer does not consume it",
                    code,
                    key.label
                );
            }
        }
    }

    /// Plan overlay subsets are suffixes of the table, so a state-filtered
    /// footer can never invent a key the full table does not know.
    #[test]
    fn plan_overlay_state_slices_are_suffixes() {
        let keys = dialog_keys(DialogScope::PlanOverlay);
        // PostInitEditing: the whole table.
        // Active / PreInitEditing: everything from "d".
        let from_d = keys.iter().position(|k| k.label == "d").unwrap();
        // NoPlan: only Esc.
        let from_esc = keys.iter().position(|k| k.label == "Esc").unwrap();
        assert!(from_d < from_esc);
    }

    /// DRIFT TEST for the cache price breakdown scope (#2027): the single key
    /// it advertises must actually close the breakdown.
    #[test]
    fn cache_breakdown_footer_key_closes_the_breakdown() {
        use crate::usage::dashboard::{CACHE_CARD, DashboardState, UsageKeyOutcome, decide};

        for key in dialog_keys(DialogScope::UsageCacheBreakdown) {
            for (code, mods) in key.events {
                let mut state = DashboardState {
                    focused_card: CACHE_CARD,
                    cache_detail_open: true,
                    ..DashboardState::default()
                };
                let event = crossterm::event::KeyEvent::new(*code, *mods);
                assert_eq!(
                    decide(&mut state, event),
                    UsageKeyOutcome::Consumed,
                    "cache breakdown advertises {code:?} ({}) but decide() does not consume it",
                    key.label
                );
                assert!(
                    !state.cache_detail_open,
                    "{code:?} is advertised as close but leaves the breakdown open"
                );
            }
        }
    }
}