memstead-base 0.8.0

Engine internals for Memstead — store, parser, validators, filesystem-mem engine. Internal library surface consumed by the memstead binaries — pre-1.0, experimental, no API stability promise.
Documentation
//! Backend-agnostic graph kernel for Memstead.
//!
//! Hosts the parts of the engine that do not assume a git-backed
//! storage: token-budget chunking, workspace-root utilities, the
//! entity types and markdown pipeline (parse / generate / write), the
//! in-memory store, graph queries and community detection, the mem
//! router, the operation request/response types (including the
//! gix-free read paths in `ops::health` / `ops::search`), the search
//! index, validators, and rendering.
//!
//! Consumers that need only graph operations against directory or
//! archive storage depend on this crate alone — its dependency closure
//! does not include `gix`. Code that needs git-backed mems depends on
//! `memstead-git-branch`, which builds on `memstead-base`.

pub mod anchor;
pub mod backend;
pub mod binding;
pub mod binding_migrate;
pub mod build_info;
pub mod check;
pub mod chunking;
pub mod derivation;
pub mod domain_authority_wire;
pub mod engine;
pub mod entity;
pub mod filesystem;
pub mod friction;
pub mod graph;
pub mod ingest;
pub mod mem;
pub mod mem_management;
pub mod ops;
pub mod overview;
pub mod pipeline;
pub mod pipeline_edit;
pub mod pipeline_migrate;
pub mod pipeline_store;
pub mod provenance;
pub mod render;
pub mod runtime_validator;
pub mod schema_source;
#[cfg(not(target_arch = "wasm32"))]
pub mod search_index;
pub mod section_format;
pub mod storage;
pub mod store;
pub mod validator;
pub mod vcs;
pub mod workspace;
pub mod workspace_root;
pub mod workspace_store;

use std::sync::Arc;

use memstead_schema::{TypeDefinition, type_by_name};

pub use anchor::{
    ANCHOR_SIDECAR_PATH, Anchor, AnchorGrain, AnchorHashStability, AnchorInput,
    AnchorProvenanceClass, AnchorSidecar, AnchorState, AnchorValidationError, AnchorVersion,
    ArtifactObservation, EntityAnchorComposition, INVALID_ANCHOR_CODE, compose_entity_anchors,
    resolve_anchor,
};
pub use backend::{BackendError, MemBackend};
pub use binding_migrate::{
    BindingMigrateError, LegacyBindingV1, MigratedBinding, check_all_consumed, fold_v1_binding,
    migrate_gen2_bindings,
};
pub use engine::{
    BackendFactory, BootError, CreateEntityArgs, CreateEntityOutcome, DeleteEntityArgs,
    DeleteEntityOutcome, DeleteReferrers, Engine, EngineError, EntityHistoryReport, EntityTouch,
    FromArchiveBytesError, GitBranchBranchResetFn, GitBranchChangesSinceFn, GitBranchDiffFn,
    GitBranchExportFn, GitBranchExportToBytesFn, GitBranchFetchFn, GitBranchOps, GitBranchPullFn,
    GitBranchPushFn, GitBranchReadTreeFn, HISTORY_PAGE_DEFAULT, HISTORY_PAGE_MAX, INLINE_LIST_CAP,
    MutationClock, ReferrerInfo, RelateAction, RelateEntityArgs, RelateEntityOutcome,
    RenameEntityArgs, RenameEntityOutcome, ReviewMarkStatus, SchemaSourceDiagnostic, SchemaStaging,
    SetReviewMarkOutcome, StoryStart, UpdateEntityArgs, UpdateEntityOutcome,
    format_inline_list_overflow,
};
pub use entity::id::{ENTITY_ID_MAX_LEN, SlugError, TITLE_GRAMMAR_RULE};
pub use entity::{Entity, EntityId, MetadataValue, ParseResult, Relationship};
pub use graph::{ClusterInfo, LouvainOutput};
pub use mem::{MEM_META_DIR, MemOrigin, MemRouterSnapshot};

/// The engine crate SEMVER of the running binary. Version-carrying
/// surfaces — the per-mem mutation stamp (`MemConfig.mutation_stamp`),
/// the boot-time `ENGINE_VERSION_SKEW` comparison, the overview's
/// `_engine_version`, CLI `--version`, MCP `serverInfo.version` — use
/// [`build_info::full_version`] instead (semver plus the git build sha
/// when present), so dev builds between releases stay distinguishable;
/// this constant is the bare semver component.
pub const ENGINE_VERSION: &str = env!("CARGO_PKG_VERSION");
pub use mem_management::{CreateRuleSet, DeleteRuleSet, MatcherSet, MatcherSetError};
pub use ops::{
    BackendChanges, BatchEntry, BatchError, BatchResult, ChangeEnvelope, ChangesReport,
    ContextResult, CreateArgs, CreateResult, DeleteResult, EMPTY_TREE_SHA, ExportResult, Facets,
    HealthReport, HealthSummary, ListResult, MemExportResult, ModifiedMetadata, ModifiedSections,
    Query, RENAME_SIMILARITY_DEFAULT, RENAME_SIMILARITY_MAX, RENAME_SIMILARITY_MIN, RelateArg,
    RelateResult, ReloadReport, ReloadResult, RenameResult, SearchHit, SearchResult, SearchScope,
    SetMemVersionOutcome, UpdateArgs, UpdateResult, WarningHint,
};
pub use pipeline::{
    Facet, IngestTrigger, Medium, MediumType, PatternEntry, PatternMode, Projection,
};
pub use pipeline_edit::PipelineEditError;
pub use pipeline_migrate::{migrate_legacy_pipeline, read_legacy_pipeline_configs};
pub use pipeline_store::{
    BindingConfigs, MemPipelineRecord, PipelineConfigs, PipelineRecord,
    load_legacy_pipeline_configs, load_pipeline_configs,
};
pub use provenance::{Provenance, ProvenanceKind};
pub use store::{Edge, EdgeSource, InEdge, Store};
pub use workspace::{
    CreateRuleSetting, DeleteRuleSetting, Mount, MountCapability, MountLifecycle, MountStorage,
    SCHEMA_WILDCARD, Workspace, WorkspaceSettings,
};
pub use workspace_store::{
    FileWorkspaceStore, InstantiateError, Layout, StoreError, WORKSPACE_STORE_DIR,
    WorkspaceStoreAdapter, detect_layout, instantiate_lean_backend, is_mem_repo_shaped,
    is_workspace_root, standalone_workspace, workspace_shape_label,
};

/// Lowercase hex encoding of a digest. Byte-identical to the `{:x}`
/// formatting that `sha2 < 0.11` digests carried; hash strings persisted
/// under the old encoding must keep matching.
pub fn hex_lower(bytes: &[u8]) -> String {
    use std::fmt::Write;
    bytes
        .iter()
        .fold(String::with_capacity(bytes.len() * 2), |mut s, b| {
            let _ = write!(s, "{b:02x}");
            s
        })
}

/// 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 through
/// `type_by_name` + schema lookup.
pub fn engine_fallback_type() -> Arc<TypeDefinition> {
    type_by_name("spec").expect("spec type must exist in the default builtin schema")
}