agentty 0.14.1

Agentty is an ADE (Agentic Development Environment) for structured, controllable AI-assisted software development.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
use std::collections::HashMap;
use std::path::Path;

use ratatui::Frame;
use ratatui::layout::Rect;
use ratatui::widgets::TableState;

use crate::app::session::session_branch;
use crate::app::session_state::SessionGitStatus;
use crate::app::{AssignedIssueState, RequestedReviewState, Tab, UpdateStatus};
use crate::domain::agent::{AgentCliInfo, ReasoningLevel};
use crate::domain::project::ProjectListItem;
use crate::domain::session::{DailyActivity, Session, SessionId};
use crate::presentation::app_mode::{AppMode, ConfirmationViewMode, HelpContext};
use crate::presentation::frame_time::FrameTime;
use crate::ui::{RenderCacheStore, component, layout, page, router};

/// Focused-review display state projected from the app cache for one visible
/// session.
pub struct SessionReviewSnapshot<'a> {
    /// Stable identifier of the session owning the cached review.
    pub session_id: &'a str,
    /// Focused-review markdown, when generated.
    pub text: Option<&'a str>,
}

/// A trait for UI pages that enforces a standard rendering interface.
pub trait Page {
    /// Renders a page in the provided frame and area.
    fn render(&mut self, f: &mut Frame, area: Rect);
}

/// A trait for UI components that enforces a standard rendering interface.
pub trait Component {
    /// Renders a component in the provided frame and area.
    fn render(&self, f: &mut Frame, area: Rect);
}

/// Immutable data required to draw a single UI frame.
pub struct RenderContext<'a> {
    /// Selected assigned-issue row index.
    pub assigned_issue_selected_index: Option<usize>,
    /// Table selection and viewport state for the assigned-issue list.
    pub assigned_issue_table_state: &'a mut TableState,
    /// Account-wide assigned GitHub issue list state.
    pub assigned_issues: &'a AssignedIssueState,
    /// Exact prompt transcript blocks keyed by session id for active turns.
    pub active_prompt_outputs: &'a HashMap<SessionId, String>,
    /// Identifier of the currently active project.
    pub active_project_id: i64,
    /// Locally available agent CLI executables and detected versions.
    pub available_agent_clis: &'a [AgentCliInfo],
    /// Active top-level tab selection.
    pub current_tab: Tab,
    /// Active project-scoped reasoning level used by session pages.
    pub default_reasoning_level: ReasoningLevel,
    /// One coherent wall-clock snapshot used by this render pass.
    pub(crate) frame_time: FrameTime,
    /// Current local branch name for the active project.
    pub git_branch: Option<&'a str>,
    /// Current upstream reference tracked by the active project branch.
    pub git_upstream_ref: Option<&'a str>,
    /// Latest ahead/behind counts for the active project branch.
    pub git_status: Option<(u32, u32)>,
    /// Newer stable version when one is available.
    pub latest_available_version: Option<&'a str>,
    /// Current app mode and its transient state.
    pub mode: &'a AppMode,
    /// Cached most-recently-opened ordering over `projects`, reused by the
    /// project switcher popup instead of re-sorting each frame.
    pub mru_project_order: &'a [usize],
    /// UI-owned cache resources shared by every page in this frame.
    pub render_cache_store: &'a RenderCacheStore,
    /// Table selection state for the projects list.
    pub project_table_state: &'a mut TableState,
    /// Project rows available for rendering.
    pub projects: &'a [ProjectListItem],
    /// Focused-review state for the visible session, projected from the app
    /// cache for this render pass.
    pub session_review_snapshot: Option<&'a SessionReviewSnapshot<'a>>,
    /// Project-scoped requested PR/MR review list state.
    pub requested_reviews: &'a RequestedReviewState,
    /// Selected requested-review item index for the review list, excluding
    /// section headers.
    pub requested_review_selected_index: Option<usize>,
    /// Table selection and viewport state for the review list.
    pub requested_review_table_state: &'a mut TableState,
    /// Detected session worktree branch names keyed by session id.
    pub session_branch_names: &'a HashMap<SessionId, String>,
    /// Latest session-branch ahead/behind snapshots keyed by session id,
    /// including both base-branch and tracked-remote comparisons.
    pub session_git_statuses: &'a HashMap<SessionId, SessionGitStatus>,
    /// Cached session list positions keyed by stable session id.
    pub session_index_by_id: &'a HashMap<SessionId, usize>,
    /// Background thinking messages keyed by session id.
    pub session_progress_messages: &'a HashMap<SessionId, String>,
    /// Latest observable update versions keyed by session id.
    pub session_update_versions: &'a HashMap<SessionId, u64>,
    /// Whether each rendered session currently has a materialized worktree on
    /// disk, keyed by session id.
    pub session_worktree_availability: &'a HashMap<SessionId, bool>,
    /// Settings-screen projection when the active tab can render it.
    pub(crate) settings_screen: Option<&'a crate::presentation::settings::SettingsScreenSnapshot>,
    /// Daily session activity series used by dashboard activity summaries.
    pub stats_activity: &'a [DailyActivity],
    /// Session rows available for rendering.
    pub sessions: &'a [Session],
    /// Table selection state for the session list.
    pub table_state: &'a mut TableState,
    /// Background auto-update progress state for the status bar.
    pub update_status: Option<&'a UpdateStatus>,
    /// Absolute one-minute rotation slot used for page-scoped status-bar FYIs.
    pub status_bar_fyi_rotation_index: u64,
    /// Working directory for the active project.
    pub working_dir: &'a Path,
}

/// Project-scoped footer inputs used when no session-specific footer override
/// is active.
#[derive(Clone, Copy)]
struct ProjectFooterContext<'a> {
    /// Current local branch name for the active project.
    git_branch: Option<&'a str>,
    /// Latest ahead/behind counts for the active project branch.
    git_status: Option<(u32, u32)>,
    /// Current upstream reference tracked by the active project branch.
    git_upstream_ref: Option<&'a str>,
    /// Working directory displayed in the footer.
    working_dir: &'a Path,
}

/// Borrowed data required to render the footer bar for one frame.
#[derive(Clone, Copy)]
struct FooterBarRenderContext<'a> {
    /// Active top-level tab used to suppress workspace context on dashboard
    /// pages.
    current_tab: Tab,
    /// Active app mode used to resolve session-scoped footer overrides.
    mode: &'a AppMode,
    /// Project footer values used when the active mode is not session-scoped.
    project: ProjectFooterContext<'a>,
    /// Detected session worktree branch names keyed by session id.
    session_branch_names: &'a HashMap<SessionId, String>,
    /// Latest session-branch ahead/behind snapshots keyed by session id.
    session_git_statuses: &'a HashMap<SessionId, SessionGitStatus>,
    /// Cached session list positions keyed by stable session id.
    session_index_by_id: &'a HashMap<SessionId, usize>,
    /// Session rows available for resolving the active footer session.
    sessions: &'a [Session],
}

/// Renders a complete frame including status bar, content area, and footer.
pub fn render(f: &mut Frame, context: RenderContext<'_>) {
    let layout::AppFrameAreas {
        content_area,
        footer_bar_area,
        status_bar_area,
    } = layout::app_frame_areas(f.area());

    component::status_bar::StatusBar::new(current_version_display_text())
        .latest_available_version(
            context
                .latest_available_version
                .map(std::string::ToString::to_string),
        )
        .page_fyis(page::fyi::current_page_messages(
            context.current_tab,
            context.mode,
        ))
        .fyi_rotation_index(context.status_bar_fyi_rotation_index)
        .update_status(context.update_status.cloned())
        .render(f, status_bar_area);
    render_footer_bar(
        f,
        footer_bar_area,
        FooterBarRenderContext {
            current_tab: context.current_tab,
            mode: context.mode,
            project: ProjectFooterContext {
                git_branch: context.git_branch,
                git_status: context.git_status,
                git_upstream_ref: context.git_upstream_ref,
                working_dir: context.working_dir,
            },
            session_branch_names: context.session_branch_names,
            session_git_statuses: context.session_git_statuses,
            session_index_by_id: context.session_index_by_id,
            sessions: context.sessions,
        },
    );

    router::route_frame(f, content_area, context);
}

/// Returns the current app version as displayed in the status bar.
fn current_version_display_text() -> String {
    format!("v{}", env!("CARGO_PKG_VERSION"))
}

/// Renders the footer bar with directory, branch, and project- or
/// session-scoped git status info.
///
/// Project branches show upstream-tracking counts. Session branches reuse the
/// same footer widget but inject counts relative to each session's base
/// branch and, when available, its tracked remote branch.
fn render_footer_bar(f: &mut Frame, footer_bar_area: Rect, context: FooterBarRenderContext<'_>) {
    let FooterBarRenderContext {
        current_tab,
        mode,
        project,
        session_branch_names,
        session_git_statuses,
        session_index_by_id,
        sessions,
    } = context;
    let session_id = match mode {
        AppMode::Confirmation {
            session_id: Some(session_id),
            ..
        }
        | AppMode::View { session_id, .. }
        | AppMode::Prompt { session_id, .. }
        | AppMode::Question { session_id, .. }
        | AppMode::Diff { session_id, .. }
        | AppMode::ReviewComments { session_id, .. }
        | AppMode::ViewInfoPopup {
            restore_view: ConfirmationViewMode { session_id, .. },
            ..
        }
        | AppMode::LaunchConfigurationSelector {
            restore_view: ConfirmationViewMode { session_id, .. },
            ..
        }
        | AppMode::PublishBranchInput {
            restore_view: ConfirmationViewMode { session_id, .. },
            ..
        }
        | AppMode::Help {
            context: HelpContext::View { session_id, .. } | HelpContext::Diff { session_id, .. },
            ..
        } => Some(session_id.as_str()),
        _ => None,
    };
    let session_for_footer = session_id
        .and_then(|session_identifier| session_index_by_id.get(session_identifier).copied())
        .and_then(|session_index| sessions.get(session_index));

    let (
        footer_dir,
        footer_branch,
        footer_base_ref,
        footer_upstream_ref,
        footer_base_status,
        footer_status,
    ) = match session_for_footer {
        Some(session) => {
            let session_status = session_git_statuses
                .get(&session.id)
                .copied()
                .unwrap_or_default();

            (
                session.folder.to_string_lossy().to_string(),
                Some(
                    session_branch_names
                        .get(&session.id)
                        .cloned()
                        .unwrap_or_else(|| session_branch(&session.id)),
                ),
                Some(session.base_branch.clone()),
                session.published_upstream_ref.clone(),
                session_status.base_status,
                session_status.remote_status,
            )
        }
        None => (
            project.working_dir.to_string_lossy().to_string(),
            project.git_branch.map(std::string::ToString::to_string),
            None,
            project
                .git_upstream_ref
                .map(std::string::ToString::to_string),
            None,
            project.git_status,
        ),
    };

    let workspace_context_visible = session_for_footer.is_some() || current_tab != Tab::Projects;

    component::footer_bar::FooterBar::new(footer_dir)
        .git_branch(footer_branch)
        .git_base_ref(footer_base_ref)
        .git_base_status(footer_base_status)
        .git_upstream_ref(footer_upstream_ref)
        .git_status(footer_status)
        .workspace_context_visible(workspace_context_visible)
        .render(f, footer_bar_area);
}

#[cfg(test)]
mod tests {
    use std::path::{Path, PathBuf};

    use super::*;
    use crate::test_support::SessionFixtureBuilder;

    /// Builds one deterministic session fixture for footer render tests.
    fn session_fixture(session_id: &str, folder: &str) -> Session {
        SessionFixtureBuilder::new()
            .id(session_id)
            .folder(PathBuf::from(folder))
            .prompt("prompt")
            .summary(Some("summary".to_string()))
            .title(Some("title".to_string()))
            .build()
    }

    /// Flattens one test backend buffer into plain text for assertions.
    fn buffer_text(buffer: &ratatui::buffer::Buffer) -> String {
        buffer
            .content()
            .iter()
            .map(ratatui::buffer::Cell::symbol)
            .collect()
    }

    /// Builds a deterministic session-id lookup map for footer render tests.
    fn session_index_by_id(sessions: &[Session]) -> HashMap<SessionId, usize> {
        sessions
            .iter()
            .enumerate()
            .map(|(session_index, session)| (session.id.clone(), session_index))
            .collect()
    }

    #[test]
    fn render_footer_bar_prefers_session_folder_and_branch_for_session_modes() {
        // Arrange
        let backend = ratatui::backend::TestBackend::new(120, 3);
        let mut terminal = ratatui::Terminal::new(backend).expect("failed to create terminal");
        let session_id = "session-view-mode";
        let session = session_fixture(session_id, "/tmp/session-view-folder");
        let modes = [
            AppMode::View {
                session_id: session_id.into(),
                scroll_offset: None,
            },
            AppMode::ReviewComments {
                comment_actions: Vec::new(),
                comment_error: None,
                comment_snapshot: None,
                diff: String::new(),
                is_loading_comments: true,
                selected_comment_index: 0,
                session_id: session_id.into(),
                scroll_offset: 0,
            },
        ];
        let sessions = vec![session];
        let session_index_by_id = session_index_by_id(&sessions);
        let session_branch_names = HashMap::new();

        // Act
        let rendered_texts = modes
            .iter()
            .map(|mode| {
                terminal
                    .draw(|frame| {
                        render_footer_bar(
                            frame,
                            frame.area(),
                            FooterBarRenderContext {
                                current_tab: Tab::Sessions,
                                mode,
                                project: ProjectFooterContext {
                                    git_branch: Some("main"),
                                    git_status: Some((2, 1)),
                                    git_upstream_ref: Some("origin/main"),
                                    working_dir: Path::new("/tmp/workspace-root"),
                                },
                                session_branch_names: &session_branch_names,
                                session_git_statuses: &HashMap::new(),
                                session_index_by_id: &session_index_by_id,
                                sessions: &sessions,
                            },
                        );
                    })
                    .expect("failed to draw");

                buffer_text(terminal.backend().buffer())
            })
            .collect::<Vec<_>>();

        // Assert
        for text in rendered_texts {
            assert!(text.contains("/tmp/session-view-folder"));
            assert!(text.contains(&session_branch(session_id)));
        }
    }

    #[test]
    fn render_footer_bar_prefers_session_upstream_reference_for_view_mode() {
        // Arrange
        let backend = ratatui::backend::TestBackend::new(120, 3);
        let mut terminal = ratatui::Terminal::new(backend).expect("failed to create terminal");
        let session_id = "upstream";
        let mut session = session_fixture(session_id, "/tmp/session-view-folder");
        session.published_upstream_ref = Some("origin/wt/upstream".to_string());
        let mode = AppMode::View {
            session_id: session_id.into(),
            scroll_offset: None,
        };
        let sessions = vec![session];
        let session_index_by_id = session_index_by_id(&sessions);
        let session_branch_names = HashMap::new();

        // Act
        terminal
            .draw(|frame| {
                render_footer_bar(
                    frame,
                    frame.area(),
                    FooterBarRenderContext {
                        current_tab: Tab::Sessions,
                        mode: &mode,
                        project: ProjectFooterContext {
                            git_branch: Some("main"),
                            git_status: Some((2, 1)),
                            git_upstream_ref: Some("origin/main"),
                            working_dir: Path::new("/tmp/workspace-root"),
                        },
                        session_branch_names: &session_branch_names,
                        session_git_statuses: &HashMap::new(),
                        session_index_by_id: &session_index_by_id,
                        sessions: &sessions,
                    },
                );
            })
            .expect("failed to draw");

        // Assert
        let text = buffer_text(terminal.backend().buffer());
        assert!(text.contains("wt/upstream -> origin/wt/upstream"));
    }

    #[test]
    fn render_footer_bar_prefers_session_branch_for_view_info_popup() {
        // Arrange
        let backend = ratatui::backend::TestBackend::new(120, 3);
        let mut terminal = ratatui::Terminal::new(backend).expect("failed to create terminal");
        let session_id = "popup";
        let mut session = session_fixture(session_id, "/tmp/session-popup-folder");
        session.published_upstream_ref = Some("origin/wt/popup".to_string());
        let mode = AppMode::ViewInfoPopup {
            is_loading: false,
            loading_label: "Publishing branch".to_string(),
            message: "Published".to_string(),
            restore_view: ConfirmationViewMode {
                scroll_offset: None,
                session_id: session_id.into(),
            },
            title: "Branch pushed".to_string(),
        };
        let sessions = vec![session];
        let session_index_by_id = session_index_by_id(&sessions);
        let session_branch_names = HashMap::new();

        // Act
        terminal
            .draw(|frame| {
                render_footer_bar(
                    frame,
                    frame.area(),
                    FooterBarRenderContext {
                        current_tab: Tab::Sessions,
                        mode: &mode,
                        project: ProjectFooterContext {
                            git_branch: Some("main"),
                            git_status: Some((2, 1)),
                            git_upstream_ref: Some("origin/main"),
                            working_dir: Path::new("/tmp/workspace-root"),
                        },
                        session_branch_names: &session_branch_names,
                        session_git_statuses: &HashMap::new(),
                        session_index_by_id: &session_index_by_id,
                        sessions: &sessions,
                    },
                );
            })
            .expect("failed to draw");

        // Assert
        let text = buffer_text(terminal.backend().buffer());
        assert!(text.contains("wt/popup -> origin/wt/popup"));
        assert!(!text.contains("main -> origin/main"));
    }

    #[test]
    fn render_footer_bar_uses_working_directory_when_mode_has_no_session() {
        // Arrange
        let backend = ratatui::backend::TestBackend::new(120, 3);
        let mut terminal = ratatui::Terminal::new(backend).expect("failed to create terminal");
        let mode = AppMode::List;
        let sessions = Vec::new();
        let session_index_by_id = session_index_by_id(&sessions);
        let session_branch_names = HashMap::new();
        let working_dir = Path::new("/tmp/current-workspace");
        let git_branch = Some("feature/test-render");
        let git_status = Some((0, 0));

        // Act
        terminal
            .draw(|frame| {
                render_footer_bar(
                    frame,
                    frame.area(),
                    FooterBarRenderContext {
                        current_tab: Tab::Sessions,
                        mode: &mode,
                        project: ProjectFooterContext {
                            git_branch,
                            git_status,
                            git_upstream_ref: Some("origin/feature/test-render"),
                            working_dir,
                        },
                        session_branch_names: &session_branch_names,
                        session_git_statuses: &HashMap::new(),
                        session_index_by_id: &session_index_by_id,
                        sessions: &sessions,
                    },
                );
            })
            .expect("failed to draw");

        // Assert
        let text = buffer_text(terminal.backend().buffer());
        assert!(text.contains("/tmp/current-workspace"));
        assert!(text.contains("feature/test-render -> origin/feature/test-render"));
    }

    #[test]
    fn render_footer_bar_hides_project_context_on_projects_tab() {
        // Arrange
        let backend = ratatui::backend::TestBackend::new(120, 1);
        let mut terminal = ratatui::Terminal::new(backend).expect("failed to create terminal");
        let mode = AppMode::List;
        let sessions = Vec::new();
        let session_index_by_id = session_index_by_id(&sessions);
        let session_branch_names = HashMap::new();
        let working_dir = Path::new("/tmp/current-workspace");

        // Act
        terminal
            .draw(|frame| {
                render_footer_bar(
                    frame,
                    frame.area(),
                    FooterBarRenderContext {
                        current_tab: Tab::Projects,
                        mode: &mode,
                        project: ProjectFooterContext {
                            git_branch: Some("feature/test-render"),
                            git_status: Some((0, 0)),
                            git_upstream_ref: Some("origin/feature/test-render"),
                            working_dir,
                        },
                        session_branch_names: &session_branch_names,
                        session_git_statuses: &HashMap::new(),
                        session_index_by_id: &session_index_by_id,
                        sessions: &sessions,
                    },
                );
            })
            .expect("failed to draw");

        // Assert
        let text = buffer_text(terminal.backend().buffer());
        assert_eq!(text.trim(), "");
        assert!(!text.contains("/tmp/current-workspace"));
        assert!(!text.contains("feature/test-render"));
    }

    #[test]
    fn render_footer_bar_uses_session_git_status_when_available() {
        // Arrange
        let backend = ratatui::backend::TestBackend::new(120, 3);
        let mut terminal = ratatui::Terminal::new(backend).expect("failed to create terminal");
        let session_id = "session-status";
        let mut session = session_fixture(session_id, "/tmp/session-status-folder");
        session.published_upstream_ref = Some("origin/wt/session-status".to_string());
        let mode = AppMode::View {
            session_id: session_id.into(),
            scroll_offset: None,
        };
        let sessions = vec![session];
        let session_index_by_id = session_index_by_id(&sessions);
        let session_branch_names: HashMap<SessionId, String> = HashMap::new();
        let session_git_statuses: HashMap<SessionId, SessionGitStatus> = HashMap::from([(
            session_id.to_string().into(),
            SessionGitStatus {
                base_status: Some((3, 2)),
                remote_status: Some((1, 4)),
            },
        )]);

        // Act
        terminal
            .draw(|frame| {
                render_footer_bar(
                    frame,
                    frame.area(),
                    FooterBarRenderContext {
                        current_tab: Tab::Sessions,
                        mode: &mode,
                        project: ProjectFooterContext {
                            git_branch: Some("main"),
                            git_status: Some((0, 0)),
                            git_upstream_ref: Some("origin/main"),
                            working_dir: Path::new("/tmp/workspace-root"),
                        },
                        session_branch_names: &session_branch_names,
                        session_git_statuses: &session_git_statuses,
                        session_index_by_id: &session_index_by_id,
                        sessions: &sessions,
                    },
                );
            })
            .expect("failed to draw");

        // Assert
        let text = buffer_text(terminal.backend().buffer());
        assert!(text.contains("↓2 ↑3 main"));
        assert!(text.contains("↓4 ↑1 wt/session- -> origin/wt/session-status"));
        assert!(!text.contains("↓0"));
    }

    #[test]
    fn render_footer_bar_uses_session_git_status_without_published_upstream() {
        // Arrange
        let backend = ratatui::backend::TestBackend::new(120, 3);
        let mut terminal = ratatui::Terminal::new(backend).expect("failed to create terminal");
        let session_id = "session-unpublished-status";
        let session = session_fixture(session_id, "/tmp/session-unpublished-status-folder");
        let mode = AppMode::View {
            session_id: session_id.into(),
            scroll_offset: None,
        };
        let sessions = vec![session];
        let session_index_by_id = session_index_by_id(&sessions);
        let session_branch_names: HashMap<SessionId, String> = HashMap::new();
        let session_git_statuses: HashMap<SessionId, SessionGitStatus> = HashMap::from([(
            session_id.to_string().into(),
            SessionGitStatus {
                base_status: Some((5, 1)),
                remote_status: None,
            },
        )]);

        // Act
        terminal
            .draw(|frame| {
                render_footer_bar(
                    frame,
                    frame.area(),
                    FooterBarRenderContext {
                        current_tab: Tab::Sessions,
                        mode: &mode,
                        project: ProjectFooterContext {
                            git_branch: Some("main"),
                            git_status: Some((0, 0)),
                            git_upstream_ref: Some("origin/main"),
                            working_dir: Path::new("/tmp/workspace-root"),
                        },
                        session_branch_names: &session_branch_names,
                        session_git_statuses: &session_git_statuses,
                        session_index_by_id: &session_index_by_id,
                        sessions: &sessions,
                    },
                );
            })
            .expect("failed to draw");

        // Assert
        let text = buffer_text(terminal.backend().buffer());
        assert!(text.contains("↓1 ↑5 main"));
        assert!(text.contains("| ✓ wt/session-"));
        assert!(!text.contains("origin/wt/session-unpublished-status"));
    }

    #[test]
    fn render_footer_bar_uses_detected_session_branch_name_for_legacy_worktrees() {
        // Arrange
        let backend = ratatui::backend::TestBackend::new(120, 3);
        let mut terminal = ratatui::Terminal::new(backend).expect("failed to create terminal");
        let session_id = "legacy";
        let session = session_fixture(session_id, "/tmp/session-legacy-folder");
        let mode = AppMode::View {
            session_id: session_id.into(),
            scroll_offset: None,
        };
        let sessions = vec![session];
        let session_index_by_id = session_index_by_id(&sessions);
        let session_branch_names: HashMap<SessionId, String> =
            HashMap::from([(session_id.to_string().into(), "agentty/legacy".to_string())]);

        // Act
        terminal
            .draw(|frame| {
                render_footer_bar(
                    frame,
                    frame.area(),
                    FooterBarRenderContext {
                        current_tab: Tab::Sessions,
                        mode: &mode,
                        project: ProjectFooterContext {
                            git_branch: Some("main"),
                            git_status: Some((2, 1)),
                            git_upstream_ref: Some("origin/main"),
                            working_dir: Path::new("/tmp/workspace-root"),
                        },
                        session_branch_names: &session_branch_names,
                        session_git_statuses: &HashMap::new(),
                        session_index_by_id: &session_index_by_id,
                        sessions: &sessions,
                    },
                );
            })
            .expect("failed to draw");

        // Assert
        let text = buffer_text(terminal.backend().buffer());
        assert!(text.contains("agentty/legacy"));
        assert!(!text.contains("wt/legacy"));
    }

    #[test]
    fn current_version_display_text_includes_v_prefix() {
        // Arrange

        // Act
        let version = current_version_display_text();

        // Assert
        assert!(version.starts_with('v'));
        assert!(version.len() > 1);
    }
}