Expand description
store — walk, locate, and shard a db.md store.
A db.md store is one directory marked by an uppercase DB.md at its root.
Store::open is the single gate every store-walking subcommand goes
through; a missing DB.md is the NotAStore error (NOT_A_STORE). The
toolkit never guesses a store root.
Scale discipline lives here: Store::walk and the layer/type-folder
walks are SWEEP primitives used only by validate --all,
index rebuild, and stats. The interactive loop instead uses
Store::find_links_to / Store::find_links_to_any (a single
presence-only content scan) and the index.jsonl sidecar readers
(Store::find_by_type / Store::find_by_where /
Store::read_type_index) — never a whole-store parse. The batch
Store::find_links_to_any is what keeps the working-set validate’s
incoming-linker discovery a single store scan rather than one scan per
changed object.
Link edges are defined once, here, by the shared extract_edge_targets /
canonical_link_target / link_edge_key helpers (fence-aware,
whitespace-trimmed, case-folded to the filesystem), so the forward view
(graph::forwardlinks), the backward view (Store::find_links_to_any),
rename, and validate all agree on exactly which [[...]] is an edge.
ensure_path_within_store is the within-store containment gate every
caller-influenced path passes through before it is read or traversed.
Structs§
- NotA
Store - Returned when a path is opened as a store but has no
DB.mdat its root. Surfaced as the structured codeNOT_A_STOREwith a non-zero exit. - Store
- An opened db.md store: its root path plus the parsed
DB.mdConfig.
Enums§
- Layer
- The three canonical layers of a db.md store.
- Store
Error - Errors from store-level operations (walk, locate, shard, sidecar read).
Functions§
- canonical_
link_ target - Canonicalize a raw
[[...]]inner target into the wiki-link key: forward slashes, no leading./or/, no trailing.md, inner whitespace trimmed. The single key forward and backward edges are compared on. Pairs withlink_edge_keyfor the case-fold step. - ensure_
path_ within_ store - Canonicalize
candidate(resolving symlinks; for a not-yet-existing leaf, canonicalize its existing parent chain and re-append the leaf) and return it only if it resolves insidestore_root; otherwiseErr. - extract_
edge_ targets - Extract every wiki-link edge target from a markdown body, fence-aware and
whitespace-trimmed, in document order (duplicates kept — callers dedup).
Returns canonical targets (see
canonical_link_target); the case-fold for comparison is applied separately vialink_edge_keyso the canonical form (used for rewrites/output) stays case-preserving. - fence_
closes - True if
linecloses the currently openfence: same char, run at least as long, nothing but trailing whitespace after. Mirrors validate’sfence_closes/ the parser’sis_closing_fence, so an inner fence of the other character (a```line inside a~~~block) does NOT close the outer fence. - fence_
opens - If
lineopens a fenced code block, return(fence byte, run length). The single fence-open rule shared byextract_edge_targetsand graph’srewrite_links_to, mirroring validate’sfence_opensand the parser’sopening_fenceso every link op tracks fences identically: a fence is```or~~~(run ≥ 3) at ≤ 3 spaces of indent, and a backtick fence’s info string may not itself contain a backtick. - infer_
type_ from_ path - Infer a content file’s canonical
typefrom its store-relative path — the inverse of [default_type_folder] and the single source of truth for path→type inference (the CLI’sfm initcalls this, never re-derives it). - layer_
for_ type - The canonical
Layeratype_belongs to, derived from its default type-folder (email→Sources,contact→Records,wiki-page→Wiki, unrecognized →Records). The write path uses this to decide whether an agent-supplied folder is in the right layer for the type before honouring its sub-folder choice. - link_
edge_ key - The comparison key for a canonical link target: identity on a case-sensitive
filesystem, ASCII-lowercased on a case-insensitive one (macOS/Windows), so
the string-keyed edge comparison agrees with the filesystem’s case-folding
is_file()resolution. Callers comparelink_edge_key(a) == link_edge_key(b).