--- part_of: '[prov](/README.md)' --- # prov — design & vision > A *self-describing plaintext workspace*: a set of documents whose structure > lives in the documents' own embedded metadata, not in the filesystem layout or > an app-private sidecar folder. This document captures the reasoning behind prov — what it is, the positions it takes, the positions it deliberately leaves open, and why. It is the crate's north star; when a decision is unclear, it should be resolvable from here. --- ## 1. The thesis **prov** — *Plaintext Records, Organized & Verifiable* (and the usual short form of *provenance*) — describes itself the way its documents do. A prov workspace is one you can hand to *any* tool and it explains itself. Follow the links declared in each document's metadata and the whole structure unfolds, anchored by a distinguished root that describes the whole. The one inversion that defines the crate: > **The edges of the document graph are declared *inside* the nodes > (frontmatter), not by the container (the filesystem).** That single move is the entire value proposition. A filesystem has no self-description (structure is imposed from outside, by directory nesting). A database has a schema, but it lives outside the data. A prov workspace keeps the structure *in the documents*, in plaintext, in the open — portable, diffable, and legible without the app that produced it. ## 2. Opinionated mechanism, flexible vocabulary The crate is opinionated about *how* structure works and agnostic about *what* the structure is called. - **Opinionated mechanism** — links live in embedded metadata; parsing goes through `fig`; there is a canonical containment tree; identity is additive; integrity is a first-class, checkable property. These are not configurable. - **Flexible vocabulary** — *which* frontmatter fields are links (`contents`/`part_of`, `links`, or an entirely different set), their cardinality, their inverses, and which one is the canonical tree. This is configured per workspace via `RelationSet`. - **Flexible source** (planned) — where the graph comes from: frontmatter links, the filesystem tree, or a hybrid, behind a `StructureSource` seam. Same downstream graph, different intake. Nothing about "diary", "journal", or even "contents" is baked into the core. `RelationSet::diaryx()` is merely a preset; the test suite proves a `part`/`whole` vocabulary works identically with zero diaryx assumptions. ### Where configuration starts and ends — *does prov read it back?* The line above ("mechanism fixed, vocabulary flexible") raises a recurring question every new field forces: is *this* thing configurable, and how far? The operative test is one question — **does prov read the value back and reason about it?** — and it sorts every field into three tiers: 1. **Mechanism — not configurable.** How structure works, that integrity is checkable, that identity is additive, and *the format of anything prov itself maintains*. A prov-maintained value must be machine-standard because prov has to parse, compare, and rewrite it reliably — years later, on another tool, after a merge. The `sha256:` fixity digest, the opaque id, the registry, an RFC 3339 `updated` or `created` timestamp: all live here. They are standardized *precisely because* they are not for human eyes but for machine reasoning. Owning the format means owning the *resolution* too — timestamps carry six fractional digits, fixed width, so two of them written in the same second are orderable rather than tied. 2. **Vocabulary & representation — configurable.** The *names and surface spellings* of those mechanisms: which fields are relations, the spanning one, reference styles, id storage, embed format, which fields are stamped on creation and on edit (`fields..stamp`), whether a feature is on. Configuring a workspace means re-spelling prov's fixed mechanisms for your vault — never redefining them. Essentially all prov config lives here. 3. **Content — not prov's business.** Everything prov merely *carries*: `title`, a user's own `date`, arbitrary frontmatter, the body. prov never reasons about these, so there is nothing to standardize and nothing to configure — the user owns them completely, today, just by writing them. The tension this resolves is the seductive middle option: a prov-*maintained* field that the user also *formats*. That combination is incoherent — the moment prov must round-trip a value it has to understand the format, and parsing arbitrary user formats (ambiguous, locale-dependent, lossy) is exactly the fragility an archive cannot afford. So the real boundary is: > **prov-maintained ⟹ prov owns the format. User-formatted ⟹ the user > maintains it.** There is no "prov maintains a field whose format it does not > understand." The corollary — **store canonical, render pretty**: human-friendly formatting is a *presentation* concern (a viewer, an export), never a storage one. prov stores the canonical machine value (RFC 3339 `…Z`, six fractional digits); a UI displays it however the reader likes — which is also the answer to "microseconds in my frontmatter are noisy": that is a rendering complaint, and rendering is not where the value lives. This is why "let users choose the timestamp format" never becomes a storage-config question: a user who wants a pretty date authors a `date` field prov never reads (tier 3), while the maintained `updated` field (tier 1/2 — fixed format, configurable *name*) stays trustworthy. The two pulls stop fighting because they are aimed at two different fields. One stamp crosses that line on purpose, and the line holds. A stamped field declared `type: date` is written the calendar date (`2026-09-28`) rather than the instant — the creation date a journal shows and a person backdates. That is not the incoherent middle: the format is still prov's, ISO 8601's calendar date, the one `check` holds every `type: date` to, and what the declaration chooses is the *resolution*. What it costs is that a date is not a fact about an instant but about whose wall the instant fell on, so the caller hands over its clock's offset with the time (`Now`) — prov stays clockless and does only the arithmetic — and a reader of the stamp reads it at the resolution it was written: a confirmation is stale against a date edit stamp once a *later day* is recorded, and an edit the same day cannot be ordered against it. So: **config exists to rename and re-spell prov's mechanisms — never to reformat its machine-state (fixed) or to manage your content (already yours).** ## 3. Structure: a spanning tree with an overlay graph Containment is a **tree**, not a general DAG — but that is a feature, not a limitation, and the distinction is subtle enough to state precisely. - Exactly one relation is marked **spanning**: single-parent, and the inverse of a "contains" relation. This is the workspace's *discovery spine*. Because every node has a unique path to a unique root, the question "what describes this workspace?" has one unambiguous answer. A pure DAG loses that — multiple parents, multiple roots, ambiguous discovery — and with it the self-describing property that motivates the whole crate. - Every **other** relation may be many-to-many. Multi-membership ("this note belongs to two projects") is expressed through non-spanning relations, i.e. the overlay graph. So the honest model is: **a single-parent containment tree (the backbone) with an arbitrary reference graph laid over it.** The materialized index (§6) is what makes the overlay edges as fast and first-class to query as the tree — so the tree is a spine, never a ceiling. Nobody should *feel* limited to a hierarchy. Framing rule: it is never "tree vs DAG." It is "one spanning relation + N overlay relations," where cardinality is per-relation config and exactly one relation is designated spanning. The spanning relation, cardinalities, and inverses are now **declared in the root's `prov:` block** (the self-description layer, `docs/spec.md`), not merely built into a preset — so a foreign reader learns the vocabulary from the document (`WorkspaceConfig::relation_set`). The diaryx preset is the **base** the declarations overlay, not a fallback they displace: a declared name is added or redefined, `: off` retracts one, and a workspace that declares nothing gets the preset unchanged. Wholesale replacement is declare-plus-`off`, spelled out, because the alternative made extending the vocabulary by one pair cost a restatement of the other four — and made a block that forgot to do so lose its spine. The single-parent invariant is *checked*: `check` flags a spanning relation whose declared inverse is `cardinality: many` (`ConfigIssueKind::SpanningNotSingleParent`), catching an incoherent vocabulary at author time rather than as a runtime `DuplicateContainment`. ## 4. Identity is a strictly-additive layer The load-bearing architectural commitment: > **The graph, traversal, and mutation layers operate on paths and never require > an ID. Identity is a resolver + a registry bolted *on top* of a fully > functional path-only workspace.** This is what makes identity genuinely optional rather than "technically a no-op." A move rewrites path-based frontmatter links because that is inherent to a linked workspace; *if* an identity layer is present, it also updates `id → path` in the registry — an optional step, gated on whether a registry exists. Nothing in containment, traversal, ordering, or validation ever dereferences an ID. In the type system: `Workspace`. Paths-only is the *absence* of the subsystem — it monomorphizes out, produces no sidecar artifact, and (crucially, see §5) writes no ID into any document. Opting in flips a type parameter via one builder line. ### Derived vs registered — the minimal authoritative set An ID is registered only when something creates a **durable, out-of-location reference** to a document. Everything else stays derived and costs nothing. So: > **The registry contains exactly the set of IDs that something external depends > on being stable.** This is the same idea as the original "IDs are rederivable unless published" plan, seen from the publish side. Publishing (a `permalink`) and linking-by-ID are the registration triggers; the other ~95% of files nothing points at pay no identity-maintenance tax. It also shrinks the dangerous, merge-critical, must-not-lose surface to its minimum. ### Model B — IDs are minted at registration, not derived Two coherent schemes were considered: - **A — derived-then-frozen.** Every file has a deterministic ID (a hash of its path); registration snapshots it. Requires collision handling and makes "stable" a happy accident of not-moving. - **B — minted at registration (chosen).** Unregistered files have *no* opaque ID at all — they are addressed by path (`[./notes/file]`). The opaque ID is *born* the moment a document is linked-by-id or published. B is chosen because the model falls out clean: - Every opaque ID is authoritative **by construction** — there are no derived opaque IDs to reconcile, no path-hash collision dance. - "Rederivable unless published" becomes literally true: unregistered = addressed by path (nothing stored); registered = minted, in the registry. - It cleanly separates the two identity layers: the **internal prov ID** (minted opaque, for in-workspace stable links) and the **published permalink** (an ARK blade in diaryx, for external URLs). Publishing implies registration; linking-by-id implies registration; they are distinct events, and the internal ID need not equal the permalink. The one cost — a UI cannot show a stable short handle for a file until it is linked — is judged negligible. ### The registration lifecycle `Registration { on_create, on_link, on_publish }` is the dial: - **OFF** — paths only. - **LAZY** (recommended default) — register on link-by-id or publish. - **EAGER** — also register on create. This regrows the registry to *every* file, forfeiting the minimal-authoritative-set benefit; it is a legitimate choice for users who want stable-identity-from-birth, and it is one flag. Registration needs **two paths**, and both must exist: 1. **Eager** — when prov itself authors an ID reference, it registers atomically. 2. **Reconciling** — a validation pass scans for `[[prov:id]]` references that arrived out-of-band (paste, `git merge`, another editor) and registers/repairs them. This reuses the validation module (§7). **Known hazard:** the one unrecoverable case is an out-of-band edit that inserts a raw ID reference and then moves the target *before* prov ever reconciles. The durable reference was created behind prov's back; nothing can save it. The mitigation is reconcile-on-load, and this is documented as a limitation rather than pretended airtight. ## 5. The index: one artifact, two natures The ID registry, the materialized graph, and the resolution cache all want to be the *same* artifact — one `IndexStore` that prov keeps consistent as part of its normal mutation job, serialized (via `fig`) to any supported format and stored anywhere. That convergence is elegant, but it hides a sharp edge that the design must respect: > **The index fuses two natures. The graph/resolution parts are a *derived > cache* — a pure function of the documents, always rebuildable, harmless when > stale. The `id → path` registry (under model B, where IDs live only in the > index) is *authoritative, non-derivable state* — it cannot be rebuilt from the > documents.** Consequences the implementation must honor: - **Structurally separate the two even inside one store.** A `derived` section (disposable, blow-away-and-regenerate) and a `registry` section (durable, backed up, merge-critical). Fusing them into one undifferentiated blob loses the cache's safety valve. - **The registry's write belongs in the same unit as the documents it describes.** This falls straight out of the two natures. A derived cache may lag: if it is stale, rebuild it. Authoritative state may not — a mutation that maintains three documents' links but loses its `id → path` update leaves every `id:` reference to the moved document resolving to nothing, and *nothing in the workspace can repair it*, because the mapping was never in the documents to begin with. So a mutation stages its registry write into the same `ChangeSet` (`prov/src/change.rs`) as its document edits, and the two land or fail together. The corollary is the honest half: the frontmatter *shadow* copy (`id_storage: frontmatter`) is derived — idempotently re-stamped from the registry on any later run — so it is deliberately left outside that unit. What can be rebuilt need not be transactional; what cannot, must be. - **A single central index file is a merge/write-contention hotspot.** Every mutation on every device touches it, so every sync touches it — re-concentrating exactly the contention that per-file frontmatter avoids. This is why `IndexStore` is a trait: sync can back the registry with something non-file-shaped (per-doc sidecars, an append-only log, a Durable Object). When the store *is* a file, its on-disk format must be designed for clean diffs (stable/sorted ordering, one record per line). - **Optional escape hatch.** A "stamp IDs back into frontmatter" operation gives the index's cleanliness as the working model *plus* a durable, portable, rebuildable backup. If frontmatter carries a shadow copy of the ID, the registry becomes rebuildable again — i.e. back to a pure cache. (This trades away some of model B's document-cleanliness; it is a per-deployment choice, not a crate-level default.) **Implemented** as the `id_storage` axis (`IdStorage`): `frontmatter` keeps the shadow copy *and* the cache; `frontmatter_only` drops the registry entirely and rebuilds id→path from a scan (`Workspace::scan_ids`), at the cost of tombstones. The ID then travels with the file — copy- and out-of-band-move-robust — since a move no longer needs a registry update. The materialization also serves performance: today the graph is derived by walking the spanning relation from a root on demand; an optional materialized index (id/path → node, adjacency, precomputed inverses) serves callers doing many queries — an LSP, a static-site builder, a TUI — without re-walking. One precomputed inverse exists now, and it is deliberately *not* in the store. `retitle` and `rename` need every document that links to one, and the census answered that by reading the whole reachable tree on every call. The **inbound index** (`prov/src/workspace/inbound.rs`) is that census's inverse, held in memory on the `Workspace` from one verb to the next — never persisted, because a file every mutation rewrites is exactly the contention hotspot above, and the CLI builds a fresh workspace per command anyway. It is derived, so it heals toward the census and never the reverse: the public `backlinks` still reads the census. What invalidates it is the two writers there are. prov's own writes all land through `apply_set`, which re-derives each rewritten document's edges from the staged bytes and drops the index whole when a set changes a spanning entry, writes a document it does not know, moves or removes anything, carries a registry write, or fails. Writes prov did not make — a consumer's own filesystem handle, a sync — are found by a **stat sweep** on every ask: each document's modification time and length as read, and each spanning target that was missing confirmed still missing. A stat opens nothing, so on a coordinated filesystem it is the one probe that costs no download; what it cannot see is a same-length rewrite inside one modification-time tick, which leaves one label or link for `check` to report. A backend with no modification times gets no index and pays the census, as before. The census the index is built from is the read that visits everything, and a backend priced per *call* — a coordinated filesystem under a sync daemon, where every read is a round trip before the first byte — pays for it once per document unless it is told a whole-tree read is happening. The **bulk-read hook** (`prov-graph/src/bulk.rs`, `BulkReads`, installed through the builder or `Workspace::set_bulk_reads`) is that notice: the walk announces `begin` under the graph's root before its first read and `end` after its last, and *before it returns*, so a verb that walks and then writes has closed the backend's scope by the time its change set lands, and a backend whose scope is a read lock over the root is never asked to write inside it. The read memo keeps what the walk read for the rest of the operation, so the rewrites a mutation loads afterwards cost the backend nothing. A graph built without a hook is told nothing and behaves as before. ## 6. Wikilinks and positioning The user-facing payoff of registered identity is stable, location-independent links: `[[prov:ajp7eq|My file]]`. Authoring such a link, or publishing, *is* the registration event. This is deliberately Obsidian-shaped, with one decisive difference: > **Obsidian, except the user owns what `.obsidian/` used to own.** Obsidian's link-rewrite-on-rename, its graph, its block IDs — all of that intelligence lives *in the app*, and the state lives in an opaque dotfolder the user cannot read with another tool. prov inverts exactly that: the same superpowers (stable IDs, backlinks, rename-safety), but the identity state is *data the user owns* — in their tree, in any `fig` format, versioned with their content. prov is that vault intelligence as a portable, embeddable library. Ownership alone is not enough, though: a readable registry in an unlinked dotfolder is still `.obsidian/` with a nicer file format. The property that actually distinguishes a prov workspace is **reachability** — the root document links its registry through the `registry` relation, so following the links from the root discovers the identity state like everything else. Where the registry lives is a fact about the workspace, declared in the workspace; the registry document self-describes with a `title` and is validated by `check` like any other reached file. It carries **no `part_of` back-link**, though: the registry is *machinery*, reached one-way through the root's `registry` pointer — not a content node in the spanning tree — so a `part_of` would assert a tree membership it does not have (the "link target kinds" typology in `docs/spec.md`; the same one-way rule governs the `config` document, the deletion log, and flat vocabulary stores). Because it is a **record store** (prov re-lays-out its sorted records), it must be a *whole-file config document* (`registry.yaml`, fig-native, …), never markdown-with- frontmatter: prose has no stable home in a file prov re-sorts, and the whole-file carrier makes extension→format sniffing unambiguous. prov refuses a markdown carrier at load (`require_whole_file`) and `check` reports it (`MalformedStore`). The same rule governs the deletion log and *flat* vocabulary stores; a *reified* vocabulary's term nodes are ordinary content and stay markdown. ## 7. Serialization and embedded formats - **`fig` value tree is the common currency.** Access is dynamic (link fields are configurable, so a fixed struct will not do). The parse/serialize paths are serde-free — they walk `fig`'s native tree — which keeps serde out of the call graph and out of a WASM binary. This mirrors the proven approach in `diaryx_core`'s `yaml` module (including the `width(1)` block-layout fix for fig 2.0's flow-style default). - **`fig` and `serde` both behind features.** `fig` has its own `serde` feature, so targeting the value tree as the common currency makes the backend a build-time choice the core never sees. `fig` is already published in multiple places; shipping it natively is defensible (the "fig + prov" ecosystem), and since fig 7 it is pure Rust, so it asks nothing of the build. - **Multi-format embedded metadata.** The crate is agnostic about the *format* of the embedded block — YAML (`---`), TOML (`+++`), JSON (`---json`) or figl (`---figl`). The **fence layer** lived in `fig` through fig 5 (`fig::detect`, `fig::Embed`, `EmbedType`, upstreamed from this project's needs); fig 6 took embedding out of fig and twig took it in, as `twig::meta`, which locates a document's frontmatter and splices fig's editor back between its fences. prov records the block's format (`MetaCarrier::Fenced(MetaFormat)`) on every `Document` so writes **preserve the original format and layout** (never rewrite a `+++` block as YAML). twig reads frontmatter and, in an HTML page, a `