Skip to main content

codetether_agent/tui/utils/
workspace.rs

1//! Workspace snapshot: directory listing + git status for the webview sidebar.
2//!
3//! Captured synchronously on demand. Types live in [`super::workspace_types`],
4//! FS scanning in [`super::workspace_entries`], git queries in
5//! [`super::workspace_helpers`].
6
7use std::path::Path;
8
9use super::workspace_entries::{collect_entries, sort_entries};
10use super::workspace_helpers::{detect_git_branch, detect_git_dirty_files};
11
12pub use super::workspace_types::{WorkspaceEntry, WorkspaceEntryKind, WorkspaceSnapshot};
13
14impl WorkspaceSnapshot {
15    /// Capture the current state of `root` truncated to `max_entries`.
16    pub fn capture(root: &Path, max_entries: usize) -> Self {
17        let mut entries = collect_entries(root);
18        sort_entries(&mut entries);
19        entries.truncate(max_entries);
20        Self {
21            root_display: root.to_string_lossy().to_string(),
22            git_branch: detect_git_branch(root),
23            git_dirty_files: detect_git_dirty_files(root),
24            entries,
25            captured_at: chrono::Local::now().format("%H:%M:%S").to_string(),
26        }
27    }
28}