Skip to main content

agent_trace/commands/
rm.rs

1use crate::git_store::CommitInfo;
2use crate::observability::CliOutput;
3use crate::store::Store;
4use crate::types::{Action, Actor, DocType};
5use anyhow::Result;
6use std::path::Path;
7
8pub fn run(store_root: &Path, file: &Path, output: &dyn CliOutput) -> Result<()> {
9    let mut store = Store::open(store_root)?;
10
11    let doc_type = store
12        .manifest
13        .find_by_path(file)
14        .map(|d| d.doc_type.clone())
15        .unwrap_or(DocType::Scratch);
16
17    store.manifest.untrack(file)?;
18    store.manifest.save(store_root)?;
19
20    let full_path = store_root.join(file);
21    if full_path.exists() {
22        std::fs::remove_file(&full_path)?;
23    }
24
25    let info = CommitInfo {
26        action: Action::Delete,
27        files: vec![(file.to_path_buf(), Action::Delete, doc_type)],
28        actor: Actor::User,
29        summary: format!("rm {}", file.display()),
30        agent_name: None,
31        session_id: None,
32    };
33    store.commit(&info)?;
34
35    output.line(&format!("Removed {}", file.display()))?;
36    Ok(())
37}