Expand description
Git-branch storage backend for Memstead — sibling to the folder and
archive backends in memstead-base. Implements
memstead_base::backend::MemBackend over a multi-root
mem-repo-git repository: each mem lives on its own branch
(refs/heads/<mem> for flat layouts, refs/heads/<path>/<mem>
for hierarchical), entities are blobs in the per-mem tree,
provenance is encoded in commit objects (subject = mutation kind +
entity, trailer block = actor / client / tool, body paragraph =
agent note). Workspace-level state — per-mem config, schema
bodies — lives on the __MEMSTEAD umbrella ref.
§Crate role
This crate is one of three storage backends. The workspace
concept itself, the unified Engine, the entity loader, the
schema registry, and the runtime validator all live in
memstead-base. This crate’s exports are:
storage::git_tree::GitTreeMemWriter— thememstead_base::backend::MemBackendimplementation that buffers mutations and applies them viagix::object::tree::Editoragainst the per-mem branch.storage::instantiate_full_backend— thememstead_base::BackendFactoryfull consumers install on the unifiedEngineat boot (workspace_store::engine_from_workspace_root) so the factory can materialise git-branch backends in addition to folder + archive.workspace_store::engine_from_workspace_root— full-flavour workspace boot path that loads the two-layer file adapter (.memstead/workspace.toml+.memstead/state/mounts.json).- Full-side helpers consumed by the unified surface:
mem_repo_config::commit_config_at_gitdir(per-mem config writes into__MEMSTEADfor git-branch mounts),ops::agent_notes::agent_notes_since,ops::changes::changes_since, andops::export::export_mem(consumed through the trait or directly bymemstead_base::Engine).
Built only with the mem-repo Cargo feature on memstead-mcp /
memstead-cli (or via the workspace-level --features mem-repo).
Lean builds skip this crate entirely; the lean MCP / CLI
binaries link only memstead-base.
Re-exports§
pub use ops::changes::ChangesReport;pub use vcs::Vcs;pub use vcs::VcsError;
Modules§
- chunking
- Token-budget chunking for large MCP responses.
- discover
- Branch enumeration for the workspace’s
mem-repo/.git/. - entity
- Re-export shim over
memstead_base::entityplus the git-touchinggit_tree_sourcesubmodule that stays in this crate. - graph
- Graph algorithms — BFS traversal, community detection, neighborhood queries.
- mem
- Multi-mem routing, visibility filtering, mem config.
- mem_
cache - Read-mem cache resolution, published-config reads, and the install-to-cache side effect.
- mem_
repo_ config - Read mem configs from
mem-repo-git:__MEMSTEAD:mems/<path>/<leaf>/config.json. - mem_
repo_ schemas - Read workspace-level schemas from the unified
__MEMSTEADref. - ops
- Re-export shim over
memstead_base::ops(request/response types,WarningHint, plus the gix-freehealthandsearchsubmodules) plus the git-touching operation submodules that stay in this crate. - render
- Markdown rendering of Engine result types.
- search_
index - Per-mem tantivy search indexes.
- storage
- Re-export shim over
memstead_base::storage(theMemWritertrait andMemWriterError) plus the git-tree adapter that stays in this crate. - storage_
memstead - Unified
__MEMSTEADref — schemas + per-mem configs in one tree. - store
- In-memory graph store. Dumb data structure — no validation, no side effects. All mutations go through Engine methods.
- validator
- Strict ingress validator for sealed
.memarchives. - vcs
- Per-mem version control via
gix. Each mem owns a gix repository whose gitdir and worktree are resolved from the mem’s config atEngine::inittime — isolated from any outer project repo and from the developer’s~/.gitconfig. - workspace_
root - Workspace-root utilities. Today’s only consumer is the
memstead_healthOUTER_REPO_NOT_IGNORING_MEM_REPOwarning surfaced by the MCP layer: when the workspace is embedded inside another git repository, the mem-repo-git directory must be excluded by the outer repo’s.gitignoreto avoid the gitlink trap. - workspace_
store - Full-flavour workspace boot helper.
Structs§
- Agent
Notes Report - Walked output of
agent_notes_since.headechoes the resolved branch tip so callers record it as the next polling cursor without a follow-upmemstead_healthround-trip.memstead_refcarries the workspace-level__MEMSTEADref tip (unified schemas + per-mem configs) so consumers — today the outer-repo auto-commit cursor block — anchor it alongside the per-mem head without a second round-trip.Nonewhen the workspace has not been migrated to the unified layout yet. - Batch
Result - Result of an atomic batch update — all-or-nothing.
- Client
Id - Identity of the process speaking to the engine. For MCP, this is the
clientInfofrom the initialize handshake (e.g.ClientId { name: "claude-code", version: "2.1.0" }). For CLI-direct mutations, the crate populates it with its own name and version. - Cluster
Info - Info about a single community cluster.
- Commit
Context - Provenance bundle for a single commit. Produced at the caller boundary
(
memstead-mcptool handler,memstead-clisubcommand, engine-internal drift flush) and threaded through to the VCS commit path. - Commit
Note - One commit’s worth of structured agent-note state. Fields are
populated best-effort: a body that doesn’t match the
memstead: <verb> <id>subject shape leavestool_verb/entity_idNone; absent trailers leave the corresponding fieldsNone. Callers branch onactorfor agent-vs-external classification. - Context
Result - Context around an entity — neighbors, community, related entities.
- Create
Args - Arguments for creating an entity.
- Create
Result - Result of a create operation.
- Delete
Result - Result of a delete operation.
- Edge
- Edge in the graph.
- Entity
- A parsed entity with metadata, sections, and relationships.
- Entity
Id - Unique entity identifier:
mem--entity-path. - Export
Result - Export result.
- Facets
- Fixed set of facet dimensions computed over the unpaginated hit set. Tier 1 freezes the dimensions; extend later only if empirical use demands it. Zero-count entries are excluded to keep the payload small.
- Health
Report - Health check result for one entity.
- Health
Summary - Aggregated health report for the whole graph.
- InEdge
- Incoming edge — stored in in_edges for efficient reverse lookups.
- List
Result - List result with token totals.
- Louvain
Output - Output of Louvain community detection: clusters, reverse lookup, and
quality metrics. Computed on demand by
Engine::communities()and cached in an in-memory memo that is invalidated whenever the graph mutates (seeEngine::invalidate_communities). - MemExport
Result - Result of a
.memmem-archive export. - MemInit
- Description of a mem discovered on a git-branch backend. Produced
by
mem_repo_config::mem_init_from_branchfor the macOSdiscover_memsUniFFI helper, which seeds the UI’s mem list before the engine itself is constructed. - MemRouter
Snapshot - Mem configuration for the engine runtime — cloneable snapshot.
- Modified
Metadata - Metadata-level mutations applied by a single
memstead_updatecall. Same empty-vec-omit convention asModifiedSections; auto-timestamp metadata fields written by the engine are NOT surfaced here (they are engine-driven, not user-driven — the caller has nothing to react to). - Modified
Sections - Section-level mutations applied by a single
memstead_updatecall. Each vec lists the section keys that landed in that mutation mode. Empty inner vecs are serde-omitted so the wire stays quiet; the struct itself always serialises so the outermodified_sectionskey is a stable shape regardless of what the call actually touched. - Parse
Result - Result of parsing a markdown file. Includes the entity, extracted inline links, and parse-time warnings (e.g. duplicate section headings).
- Query
- Flat query shape for full-text search. Four optional fields, all combined with implicit AND across fields.
- Relate
Arg - Arguments for a relate/unrelate operation.
- Relate
Result - Result of a relate operation.
- Relationship
- A declared relationship in the Relationships section.
- Reload
Report - Per-mem reload outcome — produced by [
Engine::reload_one_mem] and surfaced verbatim in thememstead_reloadMCP tool’s response when an explicit operator-triggered reload runs against a single mem. Auto-reloads on the read path consume this internally and emit aWarningHint::MemReloaded(which carriesmem,old_head,new_head,entities_loaded— the diff list is intentionally omitted from the lean warning payload; agents that need it callmemstead_changes_sincethemselves with the suppliedold_head). - Reload
Result - Rename
Result - Result of a rename operation.
- Search
Hit - A search result hit.
- Search
Result - Search result with metadata.
- Search
Scope - Scope filters for search and list operations.
- Store
- The graph store. Three maps: nodes, outgoing edges, incoming edges.
- Update
Args - Arguments for updating an entity.
- Update
Result - Result of an update operation.
Enums§
- Actor
- Caller categories for the
Actor:trailer and for picking an author signature.AgentandCliget their author from the pairedClientIdwhen one is present;Externalalways uses the syntheticexternal <external@memstead.io>identity (no client is known);Unknownfalls back to the committer identity. - Change
Envelope - Single delta entry between two snapshots.
Renamedcollapses what would otherwise appear as aRemoved+Addedpair so agents see one semantic event per filesystem rename. - Edge
Source - Where an edge was declared. Under the alias model every authored
edge is
Explicit(an entry in the auto-managed## Relationshipssection);Hierarchyis a derived view overPART_OFrather than an authoring channel;BodyLinkis engine-emitted from a body wiki-link via the alias-synthesis pass (rel-type equals the source schema’salias_target_rel_typepointer). - MemExport
Error - MemOrigin
- Provenance record attached to every writable-mem registration.
- Metadata
Value - A metadata value with type coercion matching the JS parser behavior.
- Warning
Hint - Typed non-fatal issue surfaced from engine operations. Serialises as the
uniform
{ code, message, details }envelope so a generic warning handler (log sink, UI, alerting) can readcode+messagewithout branching on variant.Displayrenders the agent-facing text, reachable viaWarningHint::message; per-variant structured fields land underdetails, their shape keyed bycode.
Constants§
- EMPTY_
TREE_ SHA - Canonical git empty-tree hash. Callers without a prior cursor pass
this to get “every entity in the current state as added”. Both
the git-branch backend (special-cased to bypass
rev_parse) and any future folder-backend implementation honour the same sentinel. - RENAME_
SIMILARITY_ DEFAULT - Default content-similarity threshold for rename detection (60%).
Callers override per-call via
changes_since’srename_similarityparameter; the engine wrapper accepts[0.1, 1.0]and emits aLIMIT_CLAMPEDwarning for out-of-range values. Higher values miss edited renames; lower values risk false-positive rename pairing. - RENAME_
SIMILARITY_ MAX - Upper bound for
rename_similarity— 1.0 means “only paired up on a byte-identical match”; above that there is no semantic meaning. - RENAME_
SIMILARITY_ MIN - Lower bound for
rename_similarity— anything below 0.1 produces nearly-random rewrite pairing on a modest diff.
Functions§
- engine_
fallback_ type - Engine-wide sentinel type. Used by ops that need a shared reference
type at the Engine level (search, health, list) — always resolves to
default@1.0.0::spec. Per-entity resolution still goes throughtype_by_name+ schema lookup.