Skip to main content

agent_trace/commands/
status.rs

1use crate::config::MergedConfig;
2use crate::llm::Llm;
3use crate::observability::CliOutput;
4use crate::store::Store;
5use crate::types::FileChange;
6use anyhow::Result;
7use std::path::Path;
8
9pub fn run(store_root: &Path, output: &dyn CliOutput) -> Result<()> {
10    let store = Store::open(store_root)?;
11
12    if let Ok(merged) = MergedConfig::load(store_root) {
13        let info = Llm::backend_info_from_config(&merged);
14        let line = if info.degraded {
15            "Synthesis: degraded (no backend) — run `agent-trace model ensure`".to_string()
16        } else {
17            format!("Synthesis: {} (ok)", info.label)
18        };
19        output.line(&line)?;
20    }
21
22    let changes = store.git.detect_changes()?;
23
24    if changes.is_empty() {
25        output.line(&format!(
26            "Store is clean. {} document(s) tracked.",
27            store.manifest.len()
28        ))?;
29        return Ok(());
30    }
31
32    output.line("Changes detected:")?;
33    for change in &changes {
34        match change {
35            FileChange::New(p) => {
36                let indicator = if store.manifest.is_tracked(p) {
37                    "+"
38                } else {
39                    "?"
40                };
41                output.line(&format!("  [{}] {}", indicator, p.display()))?;
42            }
43            FileChange::Modified(p) => output.line(&format!("  [~] {}", p.display()))?,
44            FileChange::Deleted(p) => output.line(&format!("  [x] {}", p.display()))?,
45            FileChange::Renamed { from, to } => {
46                output.line(&format!("  [>] {} -> {}", from.display(), to.display()))?
47            }
48        }
49    }
50
51    let untracked = changes
52        .iter()
53        .filter(|c| {
54            if let FileChange::New(p) = c {
55                !store.manifest.is_tracked(p)
56            } else {
57                false
58            }
59        })
60        .count();
61    if untracked > 0 {
62        output.line(&format!(
63            "\n{untracked} untracked file(s). Use `agent-trace add <type> <file>` to register."
64        ))?;
65    }
66
67    Ok(())
68}