cargo-port 0.1.3

A TUI for inspecting and managing Rust projects
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
use std::collections::HashSet;
use std::time::Instant;

use ratatui::style::Color;

use super::orchestrator::StartupPlan;
use super::orchestrator::StartupReadiness;
use super::orchestrator::StartupToast;
use super::toast_bodies;
use crate::project;
use crate::project::AbsolutePath;
use crate::project::LanguageStats;
use crate::project::TestCounts;
use crate::tui::app::App;
use crate::tui::app::Startup;
use crate::tui::app::phase_state::FailureReason;
use crate::tui::app::phase_state::PhaseCompletion;
use crate::tui::app::phase_state::ProgressRow;
use crate::tui::app::phase_state::ProgressState;
use crate::tui::app::startup;
use crate::tui::constants::STARTUP_PHASE_CRATES_IO;
use crate::tui::constants::STARTUP_PHASE_DISK;
use crate::tui::constants::STARTUP_PHASE_GIT;
use crate::tui::constants::STARTUP_PHASE_GITHUB;
use crate::tui::constants::STARTUP_PHASE_LANGUAGES;
use crate::tui::constants::STARTUP_PHASE_LINT;
use crate::tui::constants::STARTUP_PHASE_METADATA;
use crate::tui::constants::STARTUP_PHASE_TESTS;
use crate::tui::constants::STARTUP_ROW_DETAIL_DELAY;
use crate::tui::constants::STARTUP_ROW_MIN_VISIBLE;
use crate::tui::constants::STARTUP_ROW_TIMEOUT;
impl Startup {
    pub(super) fn log_phase_plan(&self) {
        tracing::trace!(
            target: tui_pane::PERF_LOG_TARGET,
            disk_expected = self.disk.expected_len(),
            git_expected = self.git.expected_len(),
            repo_expected = self.repo.expected_len(),
            crates_io_expected = self.crates_io.expected_len(),
            detail_declaration_expected = self.details_declared.expected_len(),
            lint_expected = self.lint_phase.expected_len(),
            languages_expected = self.languages.expected_len(),
            tests_expected = self.tests.expected_len(),
            metadata_expected = self.metadata.expected_len(),
            "startup_phase_plan"
        );
    }
    /// The panel rows, sorted alphabetically by label (case-insensitive) for
    /// display. The phase array below is in phase order — matching the gate
    /// and timeout arrays — and the result is sorted before returning. Each
    /// phase contributes a row only when it is not omitted (lint and crates.io
    /// are omitted until they have work). The repo row renders `Waiting` until
    /// its denominator stabilizes. The phases are keyed differently, so the
    /// array is over `&dyn PhaseCompletion`.
    pub(super) fn startup_panel_rows(
        &self,
        now: Instant,
        github_detail: Option<&str>,
        crates_io_detail: Option<&str>,
    ) -> Vec<ProgressRow> {
        let phases: [(&'static str, &dyn PhaseCompletion); 8] = [
            (STARTUP_PHASE_DISK, &self.disk),
            (STARTUP_PHASE_GIT, &self.git),
            (STARTUP_PHASE_GITHUB, &self.repo),
            (STARTUP_PHASE_CRATES_IO, &self.crates_io),
            (STARTUP_PHASE_METADATA, &self.metadata),
            (STARTUP_PHASE_LINT, &self.lint_phase),
            (STARTUP_PHASE_LANGUAGES, &self.languages),
            (STARTUP_PHASE_TESTS, &self.tests),
        ];
        let mut rows: Vec<ProgressRow> = phases
            .into_iter()
            .filter_map(|(label, phase)| {
                let state = phase.progress_state(now, STARTUP_ROW_MIN_VISIBLE)?;
                let detail = row_wants_detail(now, phase.first_seen(), state)
                    .then(|| self.row_detail(label, github_detail, crates_io_detail))
                    .flatten();
                Some(ProgressRow {
                    label,
                    state,
                    detail,
                })
            })
            .collect();
        rows.sort_by(|a, b| {
            a.label
                .bytes()
                .map(|byte| byte.to_ascii_lowercase())
                .cmp(b.label.bytes().map(|byte| byte.to_ascii_lowercase()))
        });
        rows
    }
    /// The item a slow row is currently working on (or about to): the live
    /// in-flight fetch for the network rows, the lexically-first pending key
    /// for the keyed batch rows.
    fn row_detail(
        &self,
        label: &str,
        github_detail: Option<&str>,
        crates_io_detail: Option<&str>,
    ) -> Option<String> {
        let home = |path: &AbsolutePath| project::home_relative_path(path.as_path());
        match label {
            STARTUP_PHASE_DISK => self.disk.pending_sample(home),
            STARTUP_PHASE_GIT => self.git.pending_sample(home),
            STARTUP_PHASE_GITHUB => github_detail
                .map(ToString::to_string)
                .or_else(|| self.repo.pending_sample(ToString::to_string)),
            STARTUP_PHASE_CRATES_IO => crates_io_detail
                .map(ToString::to_string)
                .or_else(|| self.crates_io.pending_sample(Clone::clone)),
            STARTUP_PHASE_METADATA => self.metadata.pending_sample(home),
            STARTUP_PHASE_TESTS => self.tests.pending_sample(home),
            _ => None,
        }
    }
    /// `true` once every tracked phase no longer holds the panel open —
    /// omitted, or complete past its minimum-visible floor. Iterating the
    /// phases (rather than naming each) means a row added in a later phase
    /// cannot silently miss the gate. `repo` is keyed differently, so the
    /// array is over `&dyn PhaseCompletion`.
    pub(super) fn all_rows_gate_satisfied(&self, now: Instant) -> bool {
        let phases: [&dyn PhaseCompletion; 8] = [
            &self.disk,
            &self.git,
            &self.repo,
            &self.crates_io,
            &self.metadata,
            &self.lint_phase,
            &self.languages,
            &self.tests,
        ];
        phases
            .iter()
            .all(|phase| phase.gate_satisfied(now, STARTUP_ROW_MIN_VISIBLE))
    }
}
impl App {
    pub(super) fn begin_startup_phase_tracker(&mut self, lint_registered: usize) {
        let crates_io_plan = self.collect_crates_io_fetch_plan();
        let startup_plan = self.build_startup_plan(lint_registered, crates_io_plan.names());
        self.initialize_startup_phase_tracker_with_plan(&startup_plan);
        // When nothing will ever increment `seen` (lint runtime disabled or
        // no eligible projects), no later message drives completion. This runs
        // after plan installation, so every startup obligation has already
        // been declared before readiness can be considered.
        if lint_registered == 0 {
            self.maybe_complete_startup_lint_cache();
        }
        self.schedule_startup_project_details(crates_io_plan);
        self.schedule_git_first_commit_refreshes();
    }

    fn build_startup_plan(
        &self,
        lint_registered: usize,
        crates_io_expected: HashSet<String>,
    ) -> StartupPlan {
        let disk_expected = startup::initial_disk_roots(&self.project_list);
        let git_expected = self
            .project_list
            .git_directories()
            .into_iter()
            .collect::<HashSet<_>>();
        let git_seen = self
            .project_list
            .iter()
            .filter(|entry| entry.item.git_info().is_some())
            .filter_map(|entry| entry.item.git_directory())
            .collect::<HashSet<_>>();
        let metadata_expected = startup::initial_metadata_roots(&self.project_list);
        let lint_history = self.lint_history_project_paths();
        let mut detail_expected = HashSet::new();
        self.project_list.for_each_leaf_path(|path, _| {
            detail_expected.insert(AbsolutePath::from(path));
        });
        StartupPlan {
            disk_expected,
            git_expected,
            git_seen,
            metadata_expected,
            lint_history,
            lint_count_expected: lint_registered,
            crates_io_expected,
            detail_expected,
            github_running: self.net.startup_github_running_repos(),
            crates_io_running: self.net.startup_crates_io_running_names(),
        }
    }

    fn initialize_startup_phase_tracker_with_plan(&mut self, startup_plan: &StartupPlan) {
        self.reset_startup_phase_state(startup_plan);
        self.start_startup_toast();
        self.startup.log_phase_plan();
        self.maybe_log_startup_phase_completions();
    }

    #[cfg(test)]
    pub fn initialize_startup_phase_tracker(&mut self) {
        let crates_io_plan = self.collect_crates_io_fetch_plan();
        let mut startup_plan = self.build_startup_plan(0, crates_io_plan.names());
        startup_plan.detail_expected.clear();
        self.initialize_startup_phase_tracker_with_plan(&startup_plan);
    }
    pub(super) fn reset_startup_phase_state(&mut self, startup_plan: &StartupPlan) {
        self.startup.reset();
        self.startup.scan_complete_at = Some(Instant::now());
        self.startup.toast = None;
        if let Some(planning) = self.startup.take_planning() {
            planning.install(&mut self.startup, startup_plan);
        }
    }
    pub(super) fn start_startup_toast(&mut self) {
        let now = Instant::now();
        // These rows are visible from panel creation; stamp their
        // minimum-visible floor now. Repo renders `Waiting` from the start.
        self.startup.disk.stamp_first_seen(now);
        self.startup.git.stamp_first_seen(now);
        self.startup.repo.stamp_first_seen(now);
        self.startup.crates_io.stamp_first_seen(now);
        self.startup.metadata.stamp_first_seen(now);
        self.startup.lint_phase.stamp_first_seen(now);
        self.startup.languages.stamp_first_seen(now);
        self.startup.tests.stamp_first_seen(now);
        let (lines, colors) = self.startup_panel_lines(now);
        let toast_id = self
            .framework
            .toasts
            .push_colored_persistent("Startup", lines, colors);
        self.startup.toast = Some(StartupToast::new(toast_id));
    }
    /// Build the panel's per-line text and matching per-line colors from the
    /// current phase states and the live in-flight network fetches.
    fn startup_panel_lines(&self, now: Instant) -> (Vec<String>, Vec<Color>) {
        let github_detail = self.in_flight_github_label();
        let crates_io_detail = self.in_flight_crates_io_label();
        let width = tui_pane::toast_body_width(self.framework.toast_settings());
        let rows = self.startup.startup_panel_rows(
            now,
            github_detail.as_deref(),
            crates_io_detail.as_deref(),
        );
        toast_bodies::startup_panel_body(&rows, width)
    }
    /// The GitHub repo fetch that has been in flight longest — the row's
    /// "currently working on" detail.
    fn in_flight_github_label(&self) -> Option<String> {
        self.net
            .github_running()
            .running
            .iter()
            .min_by_key(|(_, started)| **started)
            .map(|(repo, _)| repo.to_string())
    }
    /// The crates.io fetch in flight (one at a time) — the row's detail.
    fn in_flight_crates_io_label(&self) -> Option<String> {
        self.net
            .crates_io_running()
            .running
            .iter()
            .min_by_key(|(_, started)| **started)
            .map(|(name, _)| name.clone())
    }
    pub fn maybe_log_startup_phase_completions(&mut self) {
        let Some(scan_complete_at) = self.startup.scan_complete_at else {
            return;
        };
        // Once the panel has closed, a late phase result must not re-run
        // the gate or touch the (taken) panel toast. The per-phase `seen`
        // bookkeeping in the handlers is idempotent and harmless.
        if !self.startup.is_collecting() {
            return;
        }
        let now = Instant::now();
        self.maybe_complete_startup_disk(now, scan_complete_at);
        self.maybe_complete_startup_git(now, scan_complete_at);
        self.maybe_complete_startup_repo(now, scan_complete_at);
        self.maybe_complete_startup_metadata(now, scan_complete_at);
        self.maybe_complete_startup_lint_history(now, scan_complete_at);
        // crates.io, languages, and test counts have no special logging;
        // just record their completion timestamp (for the min-visible floor)
        // once every expected entry has been seen.
        self.startup.crates_io.complete_once(now);
        self.startup.languages.complete_once(now);
        self.startup.tests.complete_once(now);
        self.startup.details_declared.complete_once(now);
        self.refresh_startup_panel(now);
        self.maybe_complete_startup_ready(now, scan_complete_at);
    }
    /// Repaint the startup panel body from the current phase states. A
    /// no-op once the panel has been closed.
    pub(super) fn refresh_startup_panel(&mut self, now: Instant) {
        let Some(toast) = self.startup.toast else {
            return;
        };
        let (lines, colors) = self.startup_panel_lines(now);
        self.framework
            .toasts
            .update_colored(toast.id(), lines, colors);
    }
    /// Re-evaluate the panel each frame so the minimum-visible floor and
    /// the per-row timeout can close it even when no new `BackgroundMsg`
    /// arrives.
    pub fn tick_startup_panel(&mut self) {
        if !self.startup.is_collecting() {
            return;
        }
        let Some(scan_complete_at) = self.startup.scan_complete_at else {
            return;
        };
        let now = Instant::now();
        self.sweep_startup_timeouts(now);
        self.refresh_startup_panel(now);
        self.maybe_complete_startup_ready(now, scan_complete_at);
    }
    /// Fail any phase that has been visible past `STARTUP_ROW_TIMEOUT`
    /// without completing — the backstop that guarantees startup always
    /// finishes. A newly-timed-out phase pops one warning toast.
    pub(super) fn sweep_startup_timeouts(&mut self, now: Instant) {
        let timeout = STARTUP_ROW_TIMEOUT;
        let timed_out: [(bool, &'static str); 8] = [
            (
                self.startup.disk.time_out(now, timeout).is_some(),
                STARTUP_PHASE_DISK,
            ),
            (
                self.startup.git.time_out(now, timeout).is_some(),
                STARTUP_PHASE_GIT,
            ),
            (
                self.startup.repo.time_out(now, timeout).is_some(),
                STARTUP_PHASE_GITHUB,
            ),
            (
                self.startup.crates_io.time_out(now, timeout).is_some(),
                STARTUP_PHASE_CRATES_IO,
            ),
            (
                self.startup.metadata.time_out(now, timeout).is_some(),
                STARTUP_PHASE_METADATA,
            ),
            (
                self.startup.lint_phase.time_out(now, timeout).is_some(),
                STARTUP_PHASE_LINT,
            ),
            (
                self.startup.languages.time_out(now, timeout).is_some(),
                STARTUP_PHASE_LANGUAGES,
            ),
            (
                self.startup.tests.time_out(now, timeout).is_some(),
                STARTUP_PHASE_TESTS,
            ),
        ];
        for (newly_failed, label) in timed_out {
            if newly_failed {
                self.show_timed_warning_toast(
                    "Startup timed out",
                    format!("{label} did not finish in time"),
                );
            }
        }
    }
    /// Mark the repo row failed (rate-limited or unreachable GitHub) so the
    /// panel finishes without waiting out the timeout. No-op once startup
    /// has completed or the repo row is already terminal; the accompanying
    /// service-unavailable toast already names the reason.
    pub fn fail_startup_repo_phase(&mut self, reason: FailureReason) {
        if !self.startup.is_collecting() {
            return;
        }
        let repo = &mut self.startup.repo;
        if repo.failure.is_some() || repo.complete_at.is_some() || repo.expected.is_unknown() {
            return;
        }
        repo.failure = Some(reason);
        self.maybe_log_startup_phase_completions();
    }
    /// Add counted language scan work to the startup row. The final stats still
    /// arrive as project-root batches; these counted tokens only make progress
    /// reflect long scans without flooding the main queue with one path per file.
    pub const fn mark_startup_languages_expected(&mut self, units: usize) {
        self.startup.languages.add_work_expected(units);
    }
    /// Mark the project-root language tokens from a `LanguageStatsBatch`.
    /// Runs alongside the `ProjectList` handler, which owns the actual stats.
    /// Each batch also completes the counted scan work that produced it.
    pub fn mark_startup_languages_seen(&mut self, entries: &[(AbsolutePath, LanguageStats)]) {
        self.startup.languages.add_work_seen(entries.len());
        for (path, _) in entries {
            self.startup.languages.seen.insert(path.clone());
        }
        if self.startup.languages.is_complete() {
            self.maybe_log_startup_phase_completions();
        }
    }
    /// Mark the tests row's `seen` from a `TestCountsBatch`. Runs alongside
    /// the `ProjectList` handler, which owns the actual counts.
    pub fn mark_startup_tests_seen(&mut self, entries: &[(AbsolutePath, TestCounts)]) {
        for (path, _) in entries {
            self.startup.tests.seen.insert(path.clone());
        }
        self.maybe_log_startup_phase_completions();
    }
    pub fn mark_startup_project_details_declared(&mut self, path: AbsolutePath) {
        self.startup.details_declared.seen.insert(path);
        self.maybe_log_startup_phase_completions();
    }
    pub fn maybe_complete_startup_disk(&mut self, now: Instant, scan_complete_at: Instant) {
        if !self.startup.disk.complete_once(now) {
            return;
        }
        tracing::trace!(
            target: tui_pane::PERF_LOG_TARGET,
            phase = "disk_applied",
            since_scan_complete_ms =
                tui_pane::perf_log_ms(now.duration_since(scan_complete_at).as_millis()),
            seen = self.startup.disk.seen.len(),
            expected = self.startup.disk.expected_len(),
            "startup_phase_complete"
        );
    }
    pub fn maybe_complete_startup_git(&mut self, now: Instant, scan_complete_at: Instant) {
        if !self.startup.git.complete_once(now) {
            return;
        }
        tracing::trace!(
            target: tui_pane::PERF_LOG_TARGET,
            phase = "git_local_applied",
            since_scan_complete_ms =
                tui_pane::perf_log_ms(now.duration_since(scan_complete_at).as_millis()),
            seen = self.startup.git.seen.len(),
            expected = self.startup.git.expected_len(),
            "startup_phase_complete"
        );
    }
    pub fn maybe_complete_startup_repo(&mut self, now: Instant, scan_complete_at: Instant) {
        // Gate repo-phase completion on git being terminal (complete or
        // failed). Without this, a scan that completes before any
        // `RepoFetchQueued` arrives would see `repo.seen (0) >=
        // repo.expected (0)` and mark the phase done prematurely;
        // subsequent staggered git arrivals would then strand their repo
        // fetches outside the startup panel. Treating a timed-out git as
        // terminal releases repo so the panel still finishes.
        if !self.startup.git.is_terminal() {
            return;
        }
        // Git is terminal, so every GitHub remote discovered by local-git has
        // resolved (or git gave up): freeze the denominator so the row
        // switches from `Waiting` to a determinate bar. Idempotent; a later
        // `RepoFetchQueued` still joins the stable denominator and reopens the
        // row while startup is open.
        self.startup.repo.expected.stabilize();
        // Hold the row open while a repo-fetch worker is spawned but has not
        // yet reported. The worker joins this row's denominator only when it
        // sends `RepoFetchQueued`; in the window between spawn and that
        // message the row would otherwise read complete and let the
        // startup→steady-state network handoff fire, stranding the fetch's
        // standalone "Retrieving GitHub repo details" toast outside the panel
        // that is supposed to own it. `RepoInfo` arrives before the
        // `CheckoutInfo` that marks git terminal (same channel, FIFO), so every
        // repo's first fetch is already in `repo_fetch_in_flight` here.
        if self.net.github.has_repo_fetch_in_flight() {
            return;
        }
        if !self.startup.repo.complete_once(now) {
            return;
        }
        tracing::trace!(
            target: tui_pane::PERF_LOG_TARGET,
            phase = "repo_fetch_applied",
            since_scan_complete_ms =
                tui_pane::perf_log_ms(now.duration_since(scan_complete_at).as_millis()),
            seen = self.startup.repo.seen.len(),
            expected = self.startup.repo.expected_len(),
            "startup_phase_complete"
        );
    }
    pub(super) fn maybe_complete_startup_metadata(
        &mut self,
        now: Instant,
        scan_complete_at: Instant,
    ) {
        if !self.startup.metadata.complete_once(now) {
            return;
        }
        tracing::trace!(
            target: tui_pane::PERF_LOG_TARGET,
            phase = "metadata_applied",
            since_scan_complete_ms =
                tui_pane::perf_log_ms(now.duration_since(scan_complete_at).as_millis()),
            seen = self.startup.metadata.seen.len(),
            expected = self.startup.metadata.expected_len(),
            "startup_phase_complete"
        );
    }
    /// Mark the "Lint history" row complete once every Rust project's history
    /// has been read from disk (the single `BackgroundMsg::LintHistoryLoaded`
    /// batch). The row is seeded with the same project set the load reports,
    /// so `seen` always catches up — the panel can't strand on it.
    pub(super) fn maybe_complete_startup_lint_history(
        &mut self,
        now: Instant,
        scan_complete_at: Instant,
    ) {
        if !self.startup.lint_phase.complete_once(now) {
            return;
        }
        tracing::trace!(
            target: tui_pane::PERF_LOG_TARGET,
            phase = "lint_history_applied",
            since_scan_complete_ms =
                tui_pane::perf_log_ms(now.duration_since(scan_complete_at).as_millis()),
            seen = self.startup.lint_phase.seen.len(),
            expected = self.startup.lint_phase.expected_len(),
            "startup_phase_complete"
        );
    }
    pub fn maybe_complete_startup_ready(&mut self, now: Instant, scan_complete_at: Instant) {
        let lint_seen = self.startup.lint_phase.seen.len();
        let lint_expected = self.startup.lint_phase.expected_len();
        if !self.startup.is_collecting() {
            return;
        }
        let network = self.net.startup_network_readiness(
            self.startup.repo.failure.is_some(),
            self.startup.crates_io.failure.is_some(),
        );
        let Some(collecting) = self.startup.take_collecting() else {
            return;
        };
        let ready = match collecting.try_ready(&self.startup, now, scan_complete_at, network) {
            StartupReadiness::Ready(ready) => ready,
            StartupReadiness::RowsPending(collecting)
            | StartupReadiness::DeclarationsPending(collecting) => {
                collecting.restore(&mut self.startup);
                return;
            },
            StartupReadiness::NetworkPending {
                pending,
                collecting,
            } => {
                tracing::debug!(
                    github_running = pending.github,
                    crates_io_running = pending.crates_io,
                    "startup_waiting_for_network_work"
                );
                collecting.restore(&mut self.startup);
                return;
            },
        };
        self.refresh_startup_panel(now);
        let closing = ready.begin_closing(&mut self.startup);
        self.net.begin_steady_state_network_toasts(&closing.network);
        // Paint the final all-complete panel, then switch only the Startup
        // toast into a timed countdown. Startup owns colored rows, not task
        // items, so it must not enter the task linger fade path.
        if let Some(toast) = closing.toast {
            self.finish_startup_toast_with_countdown(toast);
        }
        // The panel no longer owns the network rows: install the steady-state
        // toast slots only after the startup-owned trackers have been drained
        // or explicitly abandoned after a failed startup row.
        self.sync_running_crates_io_toast();
        self.sync_running_repo_fetch_toast();
        // Startup is fully closed: every disk walk has reported, so each
        // project's newest source mtime is in `Startup::source_mtimes`. Now
        // lint the projects that changed since their last run without
        // contending with the startup window.
        self.kick_off_startup_lints();
        let since_scan_ms = tui_pane::perf_log_ms(
            closing
                .completed_at
                .duration_since(closing.scan_complete_at)
                .as_millis(),
        );
        tracing::trace!(
            target: tui_pane::PERF_LOG_TARGET,
            since_scan_complete_ms = since_scan_ms,
            disk_seen = self.startup.disk.seen.len(),
            disk_expected = self.startup.disk.expected_len(),
            git_seen = self.startup.git.seen.len(),
            git_expected = self.startup.git.expected_len(),
            repo_seen = self.startup.repo.seen.len(),
            repo_expected = self.startup.repo.expected_len(),
            lint_seen = lint_seen,
            lint_expected = lint_expected,
            metadata_seen = self.startup.metadata.seen.len(),
            metadata_expected = self.startup.metadata.expected_len(),
            "startup_complete"
        );
        tracing::trace!(
            target: tui_pane::PERF_LOG_TARGET,
            since_scan_complete_ms = since_scan_ms,
            "steady_state_begin"
        );
    }

    fn finish_startup_toast_with_countdown(&mut self, toast: StartupToast) {
        let linger = self.framework.toast_settings().finished_task_visible.get();
        self.framework
            .toasts
            .start_colored_countdown(toast.id(), linger);
        self.prune_toasts();
    }
}

/// A still-in-progress determinate row that has been visible past
/// `STARTUP_ROW_DETAIL_DELAY` warrants showing the item it is working on; a
/// fast row reaches 100% before the delay elapses and so never shows it.
fn row_wants_detail(now: Instant, first_seen: Option<Instant>, state: ProgressState) -> bool {
    let in_progress =
        matches!(state, ProgressState::Progress(percentage) if percentage.get() < 100);
    in_progress
        && first_seen.is_some_and(|first| now.duration_since(first) >= STARTUP_ROW_DETAIL_DELAY)
}