Skip to main content

Module workspace_store

Module workspace_store 

Source
Expand description

Persistence adapter — reads / writes the Workspace from disk (or other backing stores) so crate::Engine::from_mounts can consume an in-memory mount list without owning the disk format.

§Two-layer file adapter (default)

FileWorkspaceStore is the default adapter. It splits the workspace’s persisted state across two files under <workspace>/.memstead/:

  • workspace.toml — operator-edited. Carries the persistence- adapter declaration plus (in later sessions) cross-mem permissions, workspace-level policy, plugin hooks. The engine never writes to this file.
  • state/mounts.json — engine-managed. Carries the mount list (per-mount mem name, schema pin, capability, lifecycle, cross-linkable flag, and the backend-specific storage reference — folder path, gitdir+branch pair, or archive path). The operator does not edit this file during normal operation.

The split mirrors the natural authorship: the operator edits rules that change rarely; the engine writes mount-list entries that change often (planning mems, ingest scratch mems, …). Sharing one file would force two authors with different update frequencies through the same merge surface.

§Adapter trait

WorkspaceStoreAdapter is the seam. Future adapters (SQLite, remote, in-memory test fixture) implement it without changing the engine API. The adapter is selected at startup via the persistence-adapter declaration in workspace.toml — the file adapter is the only built-in V1.

§Backend instantiation

The adapter produces a Workspace (mount list + operator policy). Turning each Mount’s MountStorage into a Box<dyn MemBackend> is a separate concern — handled by instantiate_lean_backend for folder + archive variants. The git-branch backend lives in the memstead-git-branch crate behind the mem-repo Cargo feature; consumers in the lean flavour cannot materialise a MountStorage::GitBranch mount and surface InstantiateError::GitBranchRequiresMemRepoFeature.

Structs§

FileWorkspaceStore
Two-layer file adapter — the default. Reads .memstead/workspace.toml (operator) + .memstead/state/mounts.json (engine). Constructed without arguments; everything is keyed off the workspace root passed per-call.

Enums§

InstantiateError
Errors surfaced by instantiate_lean_backend.
Layout
On-disk layout the workspace root carries today.
StoreError
Errors surfaced by WorkspaceStoreAdapter::load and WorkspaceStoreAdapter::save_state. Backend-specific failures surface as StoreError::Other with a string message; structured per-adapter errors can extend the enum later.

Constants§

WORKSPACE_STORE_DIR
The engine-managed workspace store directory under the workspace root — <workspace_root>/.memstead/ holds workspace.toml, state/mounts.json, and the tier-3 install cache. Distinct from the per-mem meta directory (memstead_schema::MEM_META_DIR, re-exported as crate::mem::MEM_META_DIR) and from the literal ".memstead/..." member paths inside sealed archives, which are a separate on-disk format and never use this constant.

Traits§

WorkspaceStoreAdapter
Adapter trait — the seam between the engine and the persisted workspace state. Implementations decide where the mount list lives (two files under .memstead/, a SQLite database, a remote service, an in-memory test fixture); the engine consumes the produced Workspace uniformly.

Functions§

detect_layout
Detect the on-disk layout at workspace_root. The returned Layout discriminator is total: every workspace falls into exactly one variant.
instantiate_lean_backend
Materialise a MemBackend for mount using the lean-flavour backends (folder + archive). Returns an error for the git-branch variant — full consumers handle that with a feature-gated counterpart in memstead-git-branch.
is_mem_repo_shaped
True when the workspace root carries mem-repo/.git/ — the multi-mem, git-backed shape. False for the single-mem, history-free filesystem-mem shape. The .memstead/workspace.toml marker is shape-neutral, so this directory probe is what distinguishes the two.
is_workspace_root
True when dir is a workspace root: it carries .memstead/workspace.toml. The shared recognition primitive for every workspace walk-up (MCP boot, CLI setup, per-command walkers) — keep them all on this helper so workspaces resolve uniformly.
parse_workspace_settings
Parse the operator-edited .memstead/workspace.toml at workspace_root into a fresh WorkspaceSettings. Exposed so MCP- and CLI-driven policy-mutation tools (the workspace_config_edit::{grant,revoke}_* family) can refresh the engine’s in-memory settings after writing to disk — closing the stale-cache footgun where the next call into the engine after a successful policy mutation still saw the pre-mutation policy.
standalone_workspace
Synthesize a one-mount Workspace from a bare standalone folder mem — a directory carrying .memstead/config.json but no .memstead/workspace.toml. The mem root is the workspace root (the collapsed single-mem form), so the lone mount is a folder backend pointed at workspace_root itself.
workspace_shape_label
The one spelling of a workspace’s shape, for any surface that names it to a human or an agent: "mem-repo" or "filesystem-mem". Both spellings match the vocabulary the refusals use (UNSUPPORTED_WORKSPACE_SHAPE) and the commands that create each shape (memstead mem-repo init / memstead quickstart).