fleetcom 0.12.1

A fleet-view supervisor for concurrent shell commands.
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
//! Generates the four README dashboard fixtures under `docs/img`.
//!
//! The ignored test writes repository files on demand. Fabricated tasks and
//! fixed durations keep its output deterministic for a given `$HOME`.

use super::*;

/// Fixture dimensions. Thirty rows fit every section; 107 columns produce a
/// 71-column preview cell and an 80-column peek box.
const FIXTURE_ROWS: u16 = 30;
const FIXTURE_COLS: u16 = 107;

/// Transport stub for fixtures that assign app state directly.
struct NoTransport;

impl Transport for NoTransport {
    fn send(&mut self, _cmd: Command) {}

    fn poll(&mut self) -> Vec<Event> {
        Vec::new()
    }

    fn connected(&self) -> bool {
        true
    }

    fn shutdown(&mut self, _intent: ExitIntent) {}
}

/// Constant fixture duration in seconds.
const fn secs(n: u64) -> Duration {
    Duration::from_secs(n)
}

/// Constant fixture duration in minutes.
const fn mins(n: u64) -> Duration {
    Duration::from_secs(n * 60)
}

/// Live anchor preview with its matcher ID.
fn anchor(text: &str, rule: &'static str) -> Preview {
    Preview {
        text: text.to_string(),
        source: PreviewSource::Anchor,
        rule: Some(rule),
        frozen: false,
    }
}

/// Live window-title preview.
fn title(text: &str) -> Preview {
    Preview {
        text: text.to_string(),
        source: PreviewSource::Title,
        rule: None,
        frozen: false,
    }
}

/// Live last-row preview.
fn floor(text: &str) -> Preview {
    Preview {
        text: text.to_string(),
        source: PreviewSource::Floor,
        rule: None,
        frozen: false,
    }
}

/// Frozen last-row preview for a finished task.
fn frozen(text: &str) -> Preview {
    Preview {
        text: text.to_string(),
        source: PreviewSource::Floor,
        rule: None,
        frozen: true,
    }
}

/// Working directories rooted at `$HOME` for `~`-abbreviated section labels.
struct Dirs {
    home: PathBuf,
    fleetcom: PathBuf,
    turret: PathBuf,
    crabapple: PathBuf,
    crabstep: PathBuf,
    imessage: PathBuf,
    logria: PathBuf,
}

impl Dirs {
    fn new(home: &Path) -> Self {
        let code = home.join("Documents/Code");
        Self {
            home: home.to_path_buf(),
            fleetcom: code.join("Rust/fleetcom"),
            turret: code.join("Apple/turret"),
            crabapple: code.join("Rust/crabapple"),
            crabstep: code.join("Rust/crabstep"),
            imessage: code.join("Rust/imessage-exporter"),
            logria: code.join("Rust/Logria"),
        }
    }
}

/// Build a daemon-backed fixture with fleetcom as the invocation directory.
fn fixture_app(dirs: &Dirs, group_mode: GroupMode, views: Vec<TaskView>) -> App {
    let mut app = App::assemble(FIXTURE_ROWS, FIXTURE_COLS, |_, _, _| Box::new(NoTransport));
    app.daemon_backed = true;
    app.invocation_label = path::abbreviate(&dirs.fleetcom);
    app.invocation_dir = dirs.fleetcom.clone();
    app.spawn_cwd = dirs.fleetcom.clone();
    app.group_mode = group_mode;
    app.views = views;
    app
}

/// Active fixture: 12 active, two idle, and seven finished tasks. IDs encode
/// launch order; tags and completion determine row rank within each section.
fn live_fleet(dirs: &Dirs) -> Vec<TaskView> {
    vec![
        TaskView {
            id: 1,
            command: "claude".to_string(),
            cwd: dirs.fleetcom.clone(),
            tagged: true,
            group: Some("dashboard".to_string()),
            name: Some("Dashboard Refine".to_string()),
            lifecycle: Lifecycle::Active,
            parked: false,
            preview: anchor(
                "Scope small fixes for dashboard and CLI",
                "claude:action-row",
            ),
            started_ago: mins(2),
            quiet_ago: Some(secs(3)),
            finished_ago: None,
        },
        TaskView {
            id: 2,
            command: "claude".to_string(),
            cwd: dirs.fleetcom.clone(),
            tagged: true,
            group: Some("dashboard".to_string()),
            name: Some("Summary Refine".to_string()),
            lifecycle: Lifecycle::Active,
            parked: false,
            preview: anchor("Inferring… · thinking with high effort", "claude:spinner"),
            started_ago: mins(5),
            quiet_ago: Some(secs(8)),
            finished_ago: None,
        },
        TaskView {
            id: 3,
            command: "grok".to_string(),
            cwd: dirs.fleetcom.clone(),
            tagged: false,
            group: Some("dashboard".to_string()),
            name: Some("Grok Language".to_string()),
            lifecycle: Lifecycle::Active,
            parked: false,
            preview: anchor("Grok 4.5 (xhigh) · Responding…", "grok:spinner"),
            started_ago: mins(12),
            quiet_ago: Some(secs(4)),
            finished_ago: None,
        },
        TaskView {
            id: 4,
            command: "codex".to_string(),
            cwd: dirs.fleetcom.clone(),
            tagged: false,
            group: Some("dashboard".to_string()),
            name: Some("Codex Language".to_string()),
            lifecycle: Lifecycle::Active,
            parked: false,
            preview: anchor(CODEX_LANGUAGE, "codex:working"),
            started_ago: mins(18),
            quiet_ago: Some(secs(2)),
            finished_ago: None,
        },
        TaskView {
            id: 5,
            command: "codex".to_string(),
            cwd: dirs.fleetcom.clone(),
            tagged: false,
            group: Some("dashboard".to_string()),
            name: Some("Codex Review".to_string()),
            lifecycle: Lifecycle::Active,
            parked: false,
            preview: anchor(CODEX_REVIEW, "codex:working"),
            started_ago: mins(24),
            quiet_ago: Some(secs(6)),
            finished_ago: None,
        },
        TaskView {
            id: 6,
            command: "cargo test".to_string(),
            cwd: dirs.fleetcom.clone(),
            tagged: false,
            group: Some("tests".to_string()),
            name: None,
            lifecycle: Lifecycle::Ok,
            parked: false,
            preview: frozen(FLEETCOM_TESTS),
            started_ago: mins(2),
            quiet_ago: None,
            finished_ago: Some(secs(12)),
        },
        TaskView {
            id: 19,
            command: "cargo clippy".to_string(),
            cwd: dirs.fleetcom.clone(),
            tagged: false,
            group: Some("tests".to_string()),
            name: None,
            lifecycle: Lifecycle::Failed,
            parked: false,
            preview: frozen(FLEETCOM_CLIPPY),
            started_ago: mins(5),
            quiet_ago: None,
            finished_ago: Some(mins(3)),
        },
        TaskView {
            id: 7,
            command: "claude".to_string(),
            cwd: dirs.home.clone(),
            tagged: false,
            group: Some("desktop".to_string()),
            name: Some("claude agents".to_string()),
            lifecycle: Lifecycle::Active,
            parked: false,
            preview: title("2 awaiting input · claude agents"),
            started_ago: mins(63),
            quiet_ago: Some(secs(9)),
            finished_ago: None,
        },
        TaskView {
            id: 8,
            command: "zellij".to_string(),
            cwd: dirs.home.clone(),
            tagged: false,
            group: Some("desktop".to_string()),
            name: Some("Zellij".to_string()),
            lifecycle: Lifecycle::Active,
            parked: false,
            preview: title("Desktop ¦ Utility"),
            started_ago: mins(126),
            quiet_ago: Some(secs(4)),
            finished_ago: None,
        },
        TaskView {
            id: 9,
            command: "python".to_string(),
            cwd: dirs.home.clone(),
            tagged: false,
            group: None,
            name: None,
            lifecycle: Lifecycle::Idle,
            parked: true,
            preview: floor(">>>"),
            started_ago: mins(48),
            quiet_ago: Some(mins(41)),
            finished_ago: None,
        },
        TaskView {
            id: 10,
            command: "brew update && brew upgrade".to_string(),
            cwd: dirs.home.clone(),
            tagged: false,
            group: Some("desktop".to_string()),
            name: None,
            lifecycle: Lifecycle::Ok,
            parked: false,
            preview: frozen("Already up-to-date."),
            started_ago: mins(14),
            quiet_ago: None,
            finished_ago: Some(mins(13)),
        },
        TaskView {
            id: 11,
            command: "grok".to_string(),
            cwd: dirs.turret.clone(),
            tagged: false,
            group: Some("turret".to_string()),
            name: Some("Game Infra Review".to_string()),
            lifecycle: Lifecycle::Active,
            parked: false,
            preview: title("Turret Game Codebase Organization and Ex… - grok"),
            started_ago: mins(8),
            quiet_ago: Some(secs(5)),
            finished_ago: None,
        },
        TaskView {
            id: 12,
            command: "omp".to_string(),
            cwd: dirs.turret.clone(),
            tagged: false,
            group: Some("turret".to_string()),
            name: Some("Missile Nerf".to_string()),
            lifecycle: Lifecycle::Active,
            parked: false,
            // omp's spinner phrase carries no model-label prefix: the
            // adapter's model_label is None.
            preview: anchor("Tuning missile damage falloff", "omp:spinner"),
            started_ago: mins(33),
            quiet_ago: Some(secs(7)),
            finished_ago: None,
        },
        TaskView {
            id: 13,
            command: "omp".to_string(),
            cwd: dirs.turret.clone(),
            tagged: false,
            group: Some("turret".to_string()),
            name: Some("EMP Nerf".to_string()),
            lifecycle: Lifecycle::Active,
            parked: false,
            // At its prompt: the primary-screen title tier renders the
            // conversation label omp announces as `π > <label>`.
            preview: title("EMP arc balance pass"),
            started_ago: mins(35),
            quiet_ago: Some(secs(3)),
            finished_ago: None,
        },
        TaskView {
            id: 14,
            command: "cargo test".to_string(),
            cwd: dirs.crabapple.clone(),
            tagged: false,
            group: Some("tests".to_string()),
            name: None,
            lifecycle: Lifecycle::Ok,
            parked: false,
            preview: frozen(CRABAPPLE_TESTS),
            started_ago: mins(18),
            quiet_ago: None,
            finished_ago: Some(mins(17)),
        },
        TaskView {
            id: 15,
            command: "cargo test".to_string(),
            cwd: dirs.crabstep.clone(),
            tagged: false,
            group: Some("tests".to_string()),
            name: None,
            lifecycle: Lifecycle::Ok,
            parked: false,
            preview: frozen(CRABSTEP_TESTS),
            started_ago: mins(22),
            quiet_ago: None,
            finished_ago: Some(mins(21)),
        },
        TaskView {
            id: 16,
            command: "claude".to_string(),
            cwd: dirs.imessage.clone(),
            tagged: false,
            group: None,
            name: None,
            lifecycle: Lifecycle::Active,
            parked: false,
            preview: anchor("Review GitHub issue 780", "claude:action-row"),
            started_ago: mins(6),
            quiet_ago: Some(secs(2)),
            finished_ago: None,
        },
        TaskView {
            id: 17,
            command: "cargo test".to_string(),
            cwd: dirs.imessage.clone(),
            tagged: false,
            group: Some("tests".to_string()),
            name: None,
            lifecycle: Lifecycle::Ok,
            parked: false,
            preview: frozen(IMESSAGE_TESTS),
            started_ago: mins(20),
            quiet_ago: None,
            finished_ago: Some(mins(19)),
        },
        TaskView {
            id: 18,
            command: "cargo test".to_string(),
            cwd: dirs.logria.clone(),
            tagged: false,
            group: Some("tests".to_string()),
            name: None,
            lifecycle: Lifecycle::Ok,
            parked: false,
            preview: frozen(LOGRIA_TESTS),
            started_ago: mins(32),
            quiet_ago: None,
            finished_ago: Some(mins(31)),
        },
        TaskView {
            id: 20,
            command: "cargo watch -x test".to_string(),
            cwd: dirs.logria.clone(),
            tagged: false,
            group: Some("tests".to_string()),
            name: None,
            lifecycle: Lifecycle::Active,
            parked: false,
            preview: floor(LOGRIA_WATCH),
            started_ago: secs(45),
            quiet_ago: Some(secs(2)),
            finished_ago: None,
        },
        TaskView {
            id: 21,
            command: "cargo doc --open".to_string(),
            cwd: dirs.logria.clone(),
            tagged: false,
            group: Some("tests".to_string()),
            name: None,
            lifecycle: Lifecycle::Idle,
            parked: true,
            preview: floor(LOGRIA_DOC),
            started_ago: mins(28),
            quiet_ago: Some(mins(26)),
            finished_ago: None,
        },
    ]
}

/// Per-task state overrides for the quiet fixture.
struct Quiet {
    id: u64,
    lifecycle: Lifecycle,
    parked: bool,
    started_ago: Duration,
    quiet_ago: Option<Duration>,
    finished_ago: Option<Duration>,
    /// Optional replacement anchor preview as `(text, matcher ID)`.
    preview: Option<(&'static str, &'static str)>,
}

impl Quiet {
    /// Idle task timed from its last output.
    const fn idle(id: u64, started: Duration, quiet: Duration) -> Self {
        Self {
            id,
            lifecycle: Lifecycle::Idle,
            parked: true,
            started_ago: started,
            quiet_ago: Some(quiet),
            finished_ago: None,
            preview: None,
        }
    }

    /// Active task timed from launch.
    const fn active(id: u64, started: Duration, quiet: Duration) -> Self {
        Self {
            lifecycle: Lifecycle::Active,
            parked: false,
            ..Self::idle(id, started, quiet)
        }
    }

    /// Successful task timed from exit.
    const fn done(id: u64, started: Duration, finished: Duration) -> Self {
        Self {
            lifecycle: Lifecycle::Ok,
            parked: false,
            quiet_ago: None,
            finished_ago: Some(finished),
            ..Self::idle(id, started, finished)
        }
    }

    /// Failed task timed from exit.
    const fn failed(id: u64, started: Duration, finished: Duration) -> Self {
        Self {
            lifecycle: Lifecycle::Failed,
            ..Self::done(id, started, finished)
        }
    }

    /// Replace the anchor preview.
    const fn saying(mut self, text: &'static str, rule: &'static str) -> Self {
        self.preview = Some((text, rule));
        self
    }
}

/// Overrides for every task in the quiet fixture.
const QUIET: [Quiet; 21] = [
    Quiet::idle(1, mins(22), secs(32)),
    Quiet::idle(2, mins(21), secs(13)).saying(SUMMARY_QUIET, "claude:action-row"),
    Quiet::idle(3, mins(21), mins(1)),
    Quiet::idle(4, mins(21), mins(1)),
    Quiet::idle(5, mins(21), mins(1)),
    Quiet::done(6, mins(21), mins(20)),
    Quiet::idle(7, mins(21), mins(1)),
    // Keep Zellij active so the Running section remains non-empty.
    Quiet::active(8, mins(20), secs(4)),
    Quiet::idle(9, mins(22), mins(20)),
    Quiet::done(10, mins(16), mins(15)),
    Quiet::idle(11, mins(21), mins(1)),
    Quiet::idle(12, mins(21), mins(1)),
    Quiet::idle(13, mins(21), mins(1)),
    Quiet::done(14, mins(20), mins(19)),
    Quiet::done(15, mins(21), mins(20)),
    Quiet::idle(16, mins(21), mins(1)),
    Quiet::done(17, mins(21), mins(20)),
    Quiet::done(18, mins(21), mins(20)),
    Quiet::failed(19, mins(24), mins(21)),
    Quiet::idle(20, mins(4), mins(2)),
    Quiet::idle(21, mins(30), mins(28)),
];

/// Quiet fixture: one active, 13 idle, and seven finished tasks.
fn quiet_fleet(dirs: &Dirs) -> Vec<TaskView> {
    let mut views = live_fleet(dirs);
    assert_eq!(
        views.len(),
        QUIET.len(),
        "every task needs a peek-frame override"
    );
    for v in &mut views {
        let Some(q) = QUIET.iter().find(|q| q.id == v.id) else {
            panic!("no peek-frame override for task {}", v.id);
        };
        v.lifecycle = q.lifecycle;
        v.parked = q.parked;
        v.started_ago = q.started_ago;
        v.quiet_ago = q.quiet_ago;
        v.finished_ago = q.finished_ago;
        if let Some((text, rule)) = q.preview {
            v.preview = anchor(text, rule);
        }
    }
    views
}

// Store full preview text so truncation comes from the renderer.
const CODEX_LANGUAGE: &str =
    "gpt-5.6-sol high · fleetcom · feat/cs/interface-fixes · 387K used · 9.53M in · 61.2K out";
const CODEX_REVIEW: &str =
    "gpt-5.6-sol high · fleetcom · feat/cs/interface-fixes · 221K used · 4.41M in · 38.7K out";
const FLEETCOM_TESTS: &str =
    "test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s";
const LOGRIA_TESTS: &str = "test result: ok. 223 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.38s";
const CRABAPPLE_TESTS: &str = "all doctests ran in 0.39s; merged doctests compilation took 0.38s";
const CRABSTEP_TESTS: &str = "all doctests ran in 0.83s; merged doctests compilation took 0.81s";
const IMESSAGE_TESTS: &str = "all doctests ran in 1.99s; merged doctests compilation took 1.95s";
const FLEETCOM_CLIPPY: &str =
    "error: could not compile `fleetcom` (lib test) due to 1 previous error";
const LOGRIA_WATCH: &str = "[Running 'cargo test'] test result: ok. 223 passed; 0 failed";
const LOGRIA_DOC: &str = "Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.41s";
/// Quiet-fixture summary preview.
const SUMMARY_QUIET: &str = "Review fleetcom preview design document";

/// Visible `cargo test` tail used by the peek fixture.
fn cargo_test_screen(id: u64) -> ScreenView {
    let lines = [
        "test util::sanitizers::tests::test_length_clean ... ok",
        "test util::sanitizers::tests::test_row_length_clean ... ok",
        "test util::sanitizers::tests::test_length_dirty ... ok",
        "test util::sanitizers::tests::test_length_wide_chars ... ok",
        "test util::sanitizers::tests::test_sanitize_filename_clean ... ok",
        "test util::sanitizers::tests::test_row_length_dirty ... ok",
        "test util::sanitizers::tests::test_row_length_wide_chars ... ok",
        "test util::sanitizers::tests::test_sanitize_filename_control_chars ... ok",
        "test util::sanitizers::tests::test_sanitize_filename_trim ... ok",
        "test util::sanitizers::tests::test_sanitize_filename_invalid_chars ... ok",
        "test util::sanitizers::tests::test_sanitize_filename_long ... ok",
        "",
        LOGRIA_TESTS,
        "",
    ];
    ScreenView {
        id,
        lines: lines.iter().map(|s| s.to_string()).collect(),
        // Peek reads plain lines; formatted bytes are unused.
        formatted: Vec::new(),
        cursor: (0, 0),
        hide_cursor: true,
        wants_mouse: false,
        alt_screen: false,
        alt_scroll: false,
        scrollback: 0,
    }
}

/// Render one fixture frame.
fn frame(app: &mut App) -> Vec<u8> {
    // Set a stable captured window title.
    let mut out = b"\x1b]0;fleetcom\x07".to_vec();
    let painted = out.len();
    crate::ui::render(&mut out, app).expect("a fixture frame always paints");
    assert!(out.len() > painted, "a fresh App must emit its first frame");
    // Park the cursor outside centered overlays.
    out.extend_from_slice(format!("\x1b[{};1H", app.rows).as_bytes());
    out
}

/// Rewrite the four deterministic README dashboard fixtures under `docs/img`.
#[test]
#[ignore = "writes docs/img/*.ansi; run by hand to refresh the README screenshots"]
fn write_readme_screenshot_fixtures() {
    let home = std::env::var("HOME").expect("HOME must be set to abbreviate the section labels");
    assert!(!home.is_empty(), "HOME must not be empty");
    let dirs = Dirs::new(Path::new(&home));
    let out_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("docs/img");

    // Directory grouping with a live Codex task selected.
    let mut app = fixture_app(&dirs, GroupMode::Dir, live_fleet(&dirs));
    app.selected_id = Some(4);
    std::fs::write(out_dir.join("home.ansi"), frame(&mut app)).unwrap();

    // State grouping with a completed test selected in peek.
    let mut app = fixture_app(&dirs, GroupMode::State, quiet_fleet(&dirs));
    app.mode = Mode::Peek;
    app.selected_id = Some(14);
    // Seed the watched screen because NoTransport emits no frames.
    app.focused_screen = Some(cargo_test_screen(14));
    std::fs::write(out_dir.join("quickpeek.ansi"), frame(&mut app)).unwrap();

    // Custom grouping splits fleetcom tasks between dashboard and tests.
    let mut app = fixture_app(&dirs, GroupMode::Custom, live_fleet(&dirs));
    app.selected_id = Some(4);
    std::fs::write(out_dir.join("groups.ansi"), frame(&mut app)).unwrap();

    // Controls overlay on the directory-grouped fixture.
    let mut app = fixture_app(&dirs, GroupMode::Dir, live_fleet(&dirs));
    app.selected_id = Some(4);
    app.mode = Mode::Controls;
    std::fs::write(out_dir.join("controls.ansi"), frame(&mut app)).unwrap();
}