pub fn create_mem(
engine: &mut Engine,
params: MemCreateParams,
) -> Result<MemCreateResponse, FullEngineError>Expand description
Create a new writable mem at runtime. Unified counterpart to
full’s memstead_git_branch::mem_management::create_mem. Routes
through the engine’s installed memstead_base::BackendFactory so the
same call site materialises folder, archive, or git-branch
backends transparently — production full consumers install
memstead_git_branch::storage::instantiate_full_backend at boot via
engine_from_workspace_root.
Pipeline:
0. Input validation (note length, optional path segments).
- 0b. Schema canonicalization against the built-in catalogue. Workspace-authored schemas are resolved by the workspace’s schemas_dir, not yet here.
- Canonicalize location against
engine.workspace_root()(relative paths) or take absolute paths as-is.- 1a. Allowlist match against the composed candidate
(
<path>/<name>whenpathisSome, else<name>). - 1b. Schema gate against matched rule’s
schemaslist.["*"]wildcard admits any schema. - 1c. Basename invariant:
params.nameMUST equal the canonical location’s basename.
- 1a. Allowlist match against the composed candidate
(
- Name collision probe against the current mem_router
snapshot. The rich tree-walk collision detector (with
colliding_pathsenvelope payload) is full-only; unified surfaces collisions through the snapshot probe with the sameEngineError::MemNameCollisiondiscriminant. - Build
memstead_schema::config::MemConfigbytes.- 3b. Pick the storage variant:
params.storagewhen set (explicitStorageKindoverride — folder mems beside git-branch mems in one workspace), else by workspace shape (git-branch when<workspace_root>/mem-repo/.git/exists, folder otherwise). The branch leaf composes as<path>/<name>.
- 3b. Pick the storage variant:
- Write
<location>/.memstead/config.jsonfor folder mounts only. Git-branch mounts skip the on-disk write — the per-mem config travels in the workspace’s__MEMSTEADregistry ref. - Materialise the backend via the engine’s
memstead_base::BackendFactory, commit the seed (real sha for git-branch, synthetic id for folder), and register viamemstead_base::Engine::register_writable_memwithmemstead_base::MemOrigin::RuntimeCreated.