Skip to main content

agent_trace/state/
store.rs

1use anyhow::{Context, Result};
2use std::path::{Path, PathBuf};
3
4use super::{
5    git::{CommitInfo, GitStore},
6    manifest::Manifest,
7    permissions::Overrides,
8};
9
10/// Bundles GitStore, Manifest, and Overrides for a single store root.
11/// Commands should use this instead of opening each component separately.
12pub struct Store {
13    pub root: PathBuf,
14    pub git: GitStore,
15    pub manifest: Manifest,
16    pub overrides: Overrides,
17}
18
19impl Store {
20    /// Open an existing store at `root`. Returns an error if not initialized.
21    pub fn open(root: &Path) -> Result<Self> {
22        let git = GitStore::open(root)
23            .with_context(|| format!("Not an agent-trace store: {}", root.display()))?;
24        let manifest = Manifest::load(root)
25            .with_context(|| format!("Failed to load manifest at {}", root.display()))?;
26        let overrides = Overrides::load(root).with_context(|| "Failed to load overrides")?;
27        Ok(Self {
28            root: root.to_path_buf(),
29            git,
30            manifest,
31            overrides,
32        })
33    }
34
35    /// Commit changes to the store with a structured commit message.
36    pub fn commit(&self, info: &CommitInfo) -> Result<git2::Oid> {
37        self.git.commit(info)
38    }
39}