Skip to main content

agent_trace/commands/
reclassify.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(
9    store_root: &Path,
10    file: &Path,
11    new_type: DocType,
12    output: &dyn CliOutput,
13) -> Result<()> {
14    let mut store = Store::open(store_root)?;
15
16    if !store.manifest.is_tracked(file) {
17        anyhow::bail!("File not tracked: {}", file.display());
18    }
19
20    if matches!(new_type, DocType::Context | DocType::Log) {
21        output.warn(&format!(
22            "Warning: '{new_type}' is system-managed. Agents/system control this type."
23        ))?;
24    }
25
26    store.manifest.reclassify(file, new_type.clone())?;
27    store.manifest.save(store_root)?;
28
29    let info = CommitInfo {
30        action: Action::Modify,
31        files: vec![(file.to_path_buf(), Action::Modify, new_type.clone())],
32        actor: Actor::User,
33        summary: format!("reclassify {} -> {}", file.display(), new_type),
34        agent_name: None,
35        session_id: None,
36    };
37    store.commit(&info)?;
38
39    output.line(&format!("Reclassified {} as {}", file.display(), new_type))?;
40    Ok(())
41}