Skip to main content

memstead_git_branch/
lib.rs

1//! Git-branch storage backend for Memstead — sibling to the folder and
2//! archive backends in `memstead-base`. Implements
3//! [`memstead_base::backend::MemBackend`] over a multi-root
4//! `mem-repo-git` repository: each mem lives on its own branch
5//! (`refs/heads/<mem>` for flat layouts, `refs/heads/<path>/<mem>`
6//! for hierarchical), entities are blobs in the per-mem tree,
7//! provenance is encoded in commit objects (subject = mutation kind +
8//! entity, trailer block = actor / client / tool, body paragraph =
9//! agent note). Workspace-level state — per-mem config, schema
10//! bodies — lives on the `__MEMSTEAD` umbrella ref.
11//!
12//! ## Crate role
13//!
14//! This crate is one of three storage backends. The workspace
15//! concept itself, the unified `Engine`, the entity loader, the
16//! schema registry, and the runtime validator all live in
17//! `memstead-base`. This crate's exports are:
18//!
19//! - [`storage::git_tree::GitTreeMemWriter`] — the
20//!   [`memstead_base::backend::MemBackend`] implementation that buffers
21//!   mutations and applies them via `gix::object::tree::Editor`
22//!   against the per-mem branch.
23//! - [`storage::instantiate_full_backend`] — the [`memstead_base::BackendFactory`]
24//!   full consumers install on the unified `Engine` at boot
25//!   ([`workspace_store::engine_from_workspace_root`]) so the
26//!   factory can materialise git-branch backends in addition to
27//!   folder + archive.
28//! - [`workspace_store::engine_from_workspace_root`] — full-flavour
29//!   workspace boot path that loads the two-layer file adapter
30//!   (`.memstead/workspace.toml` + `.memstead/state/mounts.json`).
31//! - Full-side helpers consumed by the unified surface:
32//!   `mem_repo_config::commit_config_at_gitdir` (per-mem config
33//!   writes into `__MEMSTEAD` for git-branch mounts),
34//!   `ops::agent_notes::agent_notes_since`,
35//!   `ops::changes::changes_since`, and `ops::export::export_mem`
36//!   (consumed through the trait or directly by `memstead_base::Engine`).
37//!
38//! Built only with the `mem-repo` Cargo feature on `memstead-mcp` /
39//! `memstead-cli` (or via the workspace-level `--features mem-repo`).
40//! Lean builds skip this crate entirely; the lean MCP / CLI
41//! binaries link only `memstead-base`.
42
43pub use memstead_base::chunking;
44pub use memstead_base::graph;
45pub use memstead_base::mem;
46pub use memstead_base::render;
47pub use memstead_base::search_index;
48pub use memstead_base::store;
49pub use memstead_base::validator;
50pub use memstead_base::workspace_root;
51
52pub mod discover;
53pub mod entity;
54pub mod mem_cache;
55pub mod mem_repo_config;
56pub mod mem_repo_schemas;
57pub mod ops;
58pub mod repair;
59pub mod storage;
60pub mod storage_memstead;
61pub mod vcs;
62pub mod workspace_store;
63
64#[cfg(any(test, feature = "test-support"))]
65pub mod test_support;
66
67use std::path::PathBuf;
68
69use memstead_schema::SchemaRef;
70
71pub use entity::{Entity, EntityId, MetadataValue, ParseResult, Relationship};
72pub use graph::{ClusterInfo, LouvainOutput};
73pub use mem::{MemOrigin, MemRouterSnapshot};
74pub use ops::agent_notes::{AgentNotesReport, CommitNote};
75pub use ops::changes::{
76    ChangeEnvelope, ChangesReport, EMPTY_TREE_SHA, RENAME_SIMILARITY_DEFAULT,
77    RENAME_SIMILARITY_MAX, RENAME_SIMILARITY_MIN,
78};
79pub use ops::export::MemExportError;
80pub use ops::{
81    BatchResult, ContextResult, CreateArgs, CreateResult, DeleteResult, ExportResult, Facets,
82    HealthReport, HealthSummary, ListResult, MemExportResult, ModifiedMetadata, ModifiedSections,
83    Query, RelateArg, RelateResult, ReloadReport, ReloadResult, RenameResult, SearchHit,
84    SearchResult, SearchScope, UpdateArgs, UpdateResult, WarningHint,
85};
86pub use store::{Edge, EdgeSource, InEdge, Store};
87pub use vcs::{Actor, ClientId, CommitContext, Vcs, VcsError};
88
89/// Description of a mem discovered on a git-branch backend. Produced
90/// by [`mem_repo_config::mem_init_from_branch`] for the macOS
91/// `discover_mems` UniFFI helper, which seeds the UI's mem list
92/// before the engine itself is constructed.
93#[derive(Debug, Clone)]
94pub struct MemInit {
95    pub name: String,
96    pub dir: Option<PathBuf>,
97    /// Schema this mem is pinned to. Mirrors `.memstead/config.json`
98    /// `schema: "name@version"`.
99    pub schema_ref: SchemaRef,
100}
101
102pub use memstead_base::engine_fallback_type;