Expand description
Entity ID parsing, generation, and path mapping.
Structs§
- Slug
Derivation - A strict-gate derivation result: the slug plus the distinct title
characters (source order, post NFC + case-fold) the pipeline
dropped on the way.
dropped_charsnon-empty means the title and its id diverge beyond case/whitespace — the mutation surfaces it as the typedTITLE_CHARS_DROPPED_FROM_SLUGwarning so the divergence stays visible without being fatal.
Enums§
- Slug
Error - Error cases for title→slug derivation.
title_to_slugitself is total — any title produces a slug (residual cases like all-emoji collapse to a deterministic short-hash id) — so it never returns these variants directly. The strict mutation-entry gatevalidate_and_derive_slugreturns them for control characters and for input that would have fallen back to the hash slug;enforce_id_lengthreturnsSelf::IdTooLongwhen the derivedmem--slugexceeds the read-path length cap. - Wiki
Link Error - Strict wiki-link grammar refusal. Returned by
wiki_link_to_idwhen the input between[[...]](after alias /.mdstrip) does not resolve to a slug-formEntityId. Two variants matching the two grammars a wiki-link target carries:
Constants§
- ENTITY_
ID_ MAX_ LEN - Cap on the full
mem--slugentity id (Unicode scalar length). 200 leaves headroom formem---style prefixes and the.mdsuffix against the 255-byteNAME_MAXceiling on common filesystems. The read-path validator on the MCP surface and the write-path slug derivation share this constant so an entity that the write side accepts is always readable on the same wire. F2 + F4. - TITLE_
GRAMMAR_ RULE - The accepted title grammar, stated as a rule. THE single sentence
every surface that documents titles carries: the CLI’s
create/rename help embeds it at build time, the MCP
memstead_create/memstead_renamedescriptions contain it verbatim (a tool-surface test asserts the containment), and the handbook quotes it naming this constant as its source. A conformance test in this module assertsvalidate_and_derive_slug’s behaviour matches the sentence’s claim — so neither the prose nor the validator can drift alone.
Functions§
- build_
id - The separator between mem and entity path in IDs. Build an EntityId from mem and title.
- enforce_
id_ length - Reject ids whose Unicode scalar length exceeds
ENTITY_ID_MAX_LEN. Shared bybuild_idand the engine’screate_entity/rename_entitypaths so the write side never produces an id the read side would refuse. The cap is on the composed<mem>--<slug>id (which is also the filename), so the error echoes the id itself — thereason, the echoedinput, and the reportedlengthall describe the id, not the title. F2 + F4. - file_
path_ to_ id - Convert a relative file path to a mem-prefixed entity ID.
- id_
to_ file_ path - Compute the file path for an entity given its ID and base directory. The path is relative to the mem directory.
- title_
to_ slug - Convert a title string to a kebab-case slug.
- validate_
and_ derive_ slug - Strict slug derivation for mutation entry (
memstead_create,memstead_rename). Runs the same pipeline astitle_to_slug— byte-identical slugs for every title — but refuses the residual cases the permissive variant tolerates: - validate_
id_ path_ grammar - Validate that an
EntityId’s path matches the wiki-link grammar (^[\p{Ll}\p{Lo}\p{Lm}\p{N}-]+(/[\p{Ll}\p{Lo}\p{Lm}\p{N}-]+)*$). Same regex the strict ingress validator applies to inline[[...]]targets — keeping the two gates aligned ensures the relate-target path doesn’t admit ids that would fail an in-body wiki-link parse. - validate_
mem_ name_ grammar - Validate a mem name (left side of
--). Hierarchical paths are first-class: mem names accept<segment>(/<segment>)*where each segment matches the single-segment rule ([a-z0-9-]+). Leading slashes, trailing slashes, double slashes, and any character outside the allowed segment alphabet are explicit refusals. - validate_
rel_ type - Validate relationship type. Input is case-insensitive and canonicalised to uppercase; only ASCII letters and underscores are permitted.
- wiki_
link_ to_ id - Convert a wiki-link target to a mem-prefixed entity ID, refusing non-slug-form inputs.
- wiki_
link_ to_ id_ lenient - Permissive wiki-link decoder for read-side scanners that must
tolerate pre-strict-gate on-disk drift (e.g. dangling-link
reporters, body-link scanners on stored entities, archive readers
for non-canonical sources). Returns an
EntityIdeven for non-slug-form input — non-conformant chars flow through unchanged. Mutation paths MUST NOT use this helper; they usewiki_link_to_idand propagate the typed refusal.