Skip to main content

agent_trace/commands/
ls.rs

1use crate::observability::CliOutput;
2use crate::store::Store;
3use crate::types::DocType;
4use anyhow::Result;
5use std::path::Path;
6
7pub fn run(
8    store_root: &Path,
9    type_filter: Option<&DocType>,
10    json: bool,
11    output: &dyn CliOutput,
12) -> Result<()> {
13    let store = Store::open(store_root)?;
14    let docs = store.manifest.list(type_filter);
15
16    if json {
17        let entries: Vec<serde_json::Value> = docs
18            .iter()
19            .map(|d| {
20                serde_json::json!({
21                    "id": d.id,
22                    "path": d.path,
23                    "doc_type": d.doc_type.to_string(),
24                    "tags": d.tags,
25                    "description": d.description,
26                    "agent_name": d.agent_name,
27                })
28            })
29            .collect();
30        output.raw_stdout(&format!("{}\n", serde_json::to_string_pretty(&entries)?))?;
31        return Ok(());
32    }
33
34    if docs.is_empty() {
35        output.line("No documents tracked.")?;
36        return Ok(());
37    }
38
39    for doc in docs {
40        output.line(&format!(
41            "[{}] {}",
42            doc.doc_type.indicator(),
43            doc.path.display()
44        ))?;
45    }
46    Ok(())
47}