Something went wrong. Try again.
Plaintext Records, Organized and Verifiable. CLI + Library for managing plaintext information
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862//! The command-line surface: the `clap` argument grammar and the enums that//! mirror the library's config axes.//!//! Every type here is a CLI *spelling* of a library concept — a `--layout` flag//! that maps to [`prov::Layout`], a `--reference` value that maps to//! [`prov::Addressing`], and so on — kept in one module so the argument//! grammar is the CLI's business and the library enums stay free of `clap`. The//! command *handlers* live elsewhere (`main.rs` and its sibling modules); this is//! only the shape of what the user types.
use std::path::PathBuf;
use clap::{Args, Parser, Subcommand, ValueEnum};use prov::{ Addressing, ContentFormat, EmbedStyle, IdStorage, Layout, LinkStyle, MetaFormat as Format, Notation, Registration, RelationStyleConfig, WorkspaceConfig, Wrapper,};
/// `--layout` — the CLI mirror of [`Layout`], so the flag's spelling is the/// CLI's business and the library enum stays free of clap.#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]pub(crate) enum LayoutArg { /// A directory per route segment, each holding an `index` node. Nested, /// Every synthesized node beside the start document. Flat,}
impl From<LayoutArg> for Layout { fn from(arg: LayoutArg) -> Self { match arg { LayoutArg::Nested => Layout::Nested, LayoutArg::Flat => Layout::Flat, } }}
/// The filename stem of the config document the CLI creates on first/// `prov config <k> <v>` (or at `init`) — beside the root, linked via the/// `config` relation (the reachability move the registry uses). Workspace policy/// lives here rather than bloating the root or hiding in a dotfile.pub(crate) const CONFIG_STEM: &str = "prov";
/// The whole-file extension for a metadata format: the config and registry/// sidecars are written in the workspace's *chosen metadata format*, not always/// YAML — `yaml`/`json`/`toml`/`figl`. Mirrors [`prov::document::whole_file_format`],/// which parses them back.pub(crate) fn sidecar_ext(format: Format) -> &'static str { format.extension()}
/// The sidecar filename for `stem` in metadata `format` (e.g. `prov.figl`).pub(crate) fn sidecar_name(stem: &str, format: Format) -> String { format!("{stem}.{}", sidecar_ext(format))}
/// The default `--follow` depth, as clap needs it: a string, because/// `default_missing_value` is parsed from one. Pinned to/// [`prov::crossing::DEFAULT_DEPTH`] by a test below, so the library's bound and/// the flag's cannot drift apart.pub(crate) const DEFAULT_FOLLOW_DEPTH: &str = "8";
/// What `prov help --oneline` prints: what prov is for and when to reach for/// it, in one line, for a tool that lists every command-line tool it may use/// and fetches the full help only for the one it picks.pub(crate) const ONELINE: &str = "prov: maintains a graph of Markdown documents linked through \ frontmatter; use it to add, move or delete a document without breaking links, edit its \ fields, and check the links. More: `prov help`.";
/// The working guide `prov help` and `prov --help` print after the command/// list: the facts about prov that decide *which* command to use, which no/// single command's help is the place for.const GUIDE: &str = "\Working in a workspace:
A workspace is a tree of documents whose structure lives in their own frontmatter: a parent lists its children in `contents`, and each child names its parent in `part_of`. The root is found by walking up from the current directory (or `-C`) to a document with metadata and no parent, unless the workspace's config names it with `root`.
Change the tree through prov, not the filesystem. A plain `mv`, `rm` or new file leaves links broken or a document unreached; `prov new`, `prov mv`, `prov reparent` and `prov rm` update both ends of every link and every inbound reference.
`prov set` and `prov unset` stamp `updated` and restate the checksum. After changing a document's bytes any other way (an editor, a script, another tool), run `prov stamp <file>`.
`prov check` reports broken links, missing inverse links and orphans, and exits 1 on any finding. A workspace can have findings before you start, so judge one change with `prov check --only <file>`. `--fix mechanical` applies only the unambiguous repairs; bare `--fix` prompts on stdin.
A field's closed vocabulary (a `status` with fixed values, say) is enforced only by `check`: `set` and `new --set` accept any value.
Another workspace is referenced as `id:<name>/<id>`, never by path, even one nested inside this directory; `prov -C <dir> id <file>` prints the id to write. `tree --follow` and `check --follow` cross such a reference into a workspace nested in the folder of the one it is written in, as it stands, and into any other only where `prov peer` records it on this device. A nested workspace answers its name ahead of the peer map.
A directory with its own `prov.yaml` (what `prov init` writes) is a workspace, and discovery from inside it stops there even when its root has a `part_of` into an outer workspace, provided the root is named `index` or `readme`. A root named anything else needs `root: <file>` in that config (`prov config root <file>`); without it discovery walks up and opens the outer workspace.
`prov help <command>` prints any command's full help, and `prov help --oneline`one line saying what prov is for.";
/// What `prov --version` prints.////// The package version on a clean build of the release tag, and the package/// version plus the commit it was built from on anything else — see/// `build.rs`, which resolves the git state and emits `PROV_VERSION`. The/// parenthetical is how a bug report distinguishes a dev build from the/// release that shares its version number.pub(crate) const VERSION: &str = env!("PROV_VERSION");
/// A self-describing plaintext workspace, from the command line.#[derive(Parser)]#[command( name = "prov", version = VERSION, about, long_about = None, after_long_help = GUIDE)]pub(crate) struct Cli { /// Run as if started in this directory — discover the workspace root from /// here instead of the current directory (like `git -C`, this goes *before* /// the subcommand: `prov -C ~/vault check`). Also settable via the `PROV_ROOT` /// environment variable; the flag wins. Lets a script or cron operate on a /// vault without `cd`-ing into it. Relative path arguments resolve here too. #[arg(short = 'C', long = "root", value_name = "DIR")] pub(crate) root: Option<PathBuf>, /// Read this device's map of other workspaces from here instead of the /// default location (`prov peer list` prints the file in use). Also settable /// via `PROV_PEERS`, or `XDG_CONFIG_HOME`; the flag wins. The map says where /// a workspace named by a cross-workspace reference (`id:<name>/<id>`) /// lives; it is device-local by design, since the same archive is read from /// different machines. #[arg(long = "peers", value_name = "FILE")] pub(crate) peers: Option<PathBuf>, #[command(subcommand)] pub(crate) command: Command,}
/// What `prov peer` is being asked to do.#[derive(Subcommand)]pub(crate) enum PeerAction { /// List the workspaces this device can resolve, and the file holding them. List, /// Record where a workspace lives on this device. NAME must be what that /// workspace calls itself (its `workspace_id`) — that is the name every /// reference to it will be written with. Add { /// The workspace's own name. name: String, /// Its root directory on this device. dir: PathBuf, }, /// Forget a workspace. Its references keep working exactly as well as they /// did — which is to say they are still carried, just no longer followable. Remove { /// The workspace's own name. name: String, }, /// Resolve a cross-workspace reference (`id:<name>/<id>`) to a file on this /// device, by looking the id up in that workspace's own registry. Run /// inside a workspace, one nested in its folder is found with no entry. The peer /// is asked what it calls itself first: a directory that turns out to be a /// different workspace is reported, never followed. Resolve { /// The reference, with or without the `id:` scheme. #[arg(value_name = "REFERENCE")] reference: String, /// Follow a peer whose name could not be checked — one that is /// anonymous, or that could not be opened as a workspace. Never accepts /// a peer that calls itself something else; that is not missing /// evidence, it is evidence of the wrong archive. #[arg(long)] unverified: bool, },}
#[derive(Subcommand)]pub(crate) enum Command { /// Initialize a new workspace here: write a self-describing root document /// that the other commands can discover. The starting point — `tree`, /// `new`, and `check` all need a root to work from. On a terminal, prompts /// for anything not given as a flag; pass `--yes` to take every default. Init(InitArgs), /// Where the *other* workspaces are — this device's map from a workspace /// name to a directory. /// /// A workspace names itself in its own config (`workspace_id`), and a /// reference across workspaces is written `id:<name>/<id>`. What that name /// resolves to is a fact about *this machine*, not about the archive, so it /// is kept here rather than in `prov.yaml` — the same reasoning that keeps /// the fixity cache's location out of the workspace. /// /// Nothing depends on this map: a cross-workspace reference is carried, left /// alone by moves, and never reported broken, whether or not a peer is /// recorded. The map only makes such a reference *followable*. /// /// A workspace nested in the current one's folder needs no entry: its /// directory travels with the folder, so it is found there, and it answers /// its name ahead of anything recorded here. Peer { #[command(subcommand)] action: PeerAction, }, /// Summarize a document: its metadata, spanning children, and declared links. Show { /// Path to a document (plaintext with embedded metadata). #[arg(value_name = "TARGET")] file: String, }, /// List a document's links as `relation<TAB>target`, one per line. Links { /// Path to a document. #[arg(value_name = "TARGET")] file: String, /// Only show links declared by this relation (e.g. `contents`). #[arg(long)] relation: Option<String>, }, /// Print a document's metadata block (without fences). Meta { /// Path to a document. #[arg(value_name = "TARGET")] file: String, /// Output format (default: the format the document already uses). #[arg(long, value_enum)] format: Option<MetaFormat>, }, /// Print one metadata field by path (e.g. `title`, `contents[0]`). Get { /// Path to a document. #[arg(value_name = "TARGET")] file: String, /// Field path: keys joined by `.`, a list item as `[n]` (`contents[0]`, /// `sources[1].resource`); `contents.0` names the same item. key: String, }, /// Print a document's body (everything outside the metadata block). Body { /// Path to a document. #[arg(value_name = "TARGET")] file: String, }, /// Render a document's body to HTML (Markdown/Djot, via `twig`). Render { /// Path to a document. #[arg(value_name = "TARGET")] file: String, }, /// Open a document in `$EDITOR` and, on save, recompute its content checksum /// (for a document that records one — an attachment sidecar, a separated /// node) so an edit keeps its fixity true rather than becoming a `check` /// finding. The prov-mediated edit path. Edit { /// The document to edit: a path, a title route (`@Daily/2026/07`), or an /// id (`id:fpk38j`). #[arg(value_name = "TARGET")] file: String, }, /// Set a metadata field (comment- and format-preserving; creates the /// block when the document has none). /// /// Inside a workspace the edit is landed the way `edit` lands one: the /// workspace's `updated` field is stamped with the current instant and a /// recorded content checksum is restated, in one crash-safe write. Setting /// the `updated` field itself keeps the value you gave. Outside a /// workspace the file is simply rewritten. /// /// A value outside a field's closed vocabulary is written all the same; /// `prov check` is what reports it. After changing a document's bytes some /// other way than `set`, `unset` or `edit`, run `prov stamp`. Set { /// Path to a document. #[arg(value_name = "TARGET")] file: String, /// Field path: keys joined by `.`, a list item as `[n]` /// (`contents[0]`, or `contents.0`). key: String, /// Value; `true`/`false`, integers, floats, and `null` are typed, /// `[a, b]` is a list (quote an item to keep it text), everything /// else is a string. value: String, }, /// Remove a metadata field (comment- and format-preserving). Stamps /// `updated` inside a workspace as `set` does. Unset { /// Path to a document. #[arg(value_name = "TARGET")] file: String, /// Field path: keys joined by `.`, a list item as `[n]` /// (`contents[0]`, or `contents.0`). key: String, }, /// List the views this workspace declares, or execute one. /// /// A view is the second way through the same documents the containment tree /// already holds — "the entries under Daily, by month": a `where:` /// condition and a `key:`, each a CEL expression. With no NAME, print what /// the workspace declares; with one, print its groups and the documents /// under each. `--json` gives either as machine-readable records. To try a /// query without declaring it, see `prov query`. Views { /// The view to execute (default: list every declared view). #[arg(value_name = "NAME")] name: Option<String>, /// Print to stdout as JSON instead of a line each: one object per /// declared view for the listing, and for an executed view its groups, /// its ungrouped bucket, and both counts. /// /// Each row carries the document's path, its title, and its **whole /// metadata block** — a consumer replacing a per-file loop with a view /// was reading that metadata, and asking it to run `prov meta` over the /// result would put the loop straight back. Empty groups print `[]`, so /// "the view found nothing" and "the command printed nothing" stay /// distinguishable. /// /// A document the view's expressions could not be evaluated on is /// listed under `failures` with the reason, rather than on stderr. #[arg(long)] json: bool, }, /// Ask a question of the workspace without declaring a view: which /// documents meet a condition, optionally grouped. /// /// WHERE and `--key` are CEL expressions, exactly as a view's `where:` and /// `key:` are written: each field of a document is a variable of its own /// name (`status == 'open'`), a field it lacks is `null`, and `doc` is the /// document itself — `doc.path`, `doc.title`, `doc.id`, `doc.meta`, and /// `doc.ancestors`, everything above it in the tree. prov adds `present`, /// `first`, `field`, `under`, `year`, `month`, `day` and `initial`. With no /// WHERE, every document; with no `--key`, a flat list. /// /// prov query "present(draft)" /// prov query "under('Tasks')" --key status /// prov query --key "year(created)" Query { /// The condition a document must meet (default: every document). #[arg(value_name = "WHERE")] condition: Option<String>, /// Group the documents by this expression, as a view's `key:` does. #[arg(long, value_name = "EXPR")] key: Option<String>, /// Print JSON: with `--key`, the record `views NAME --json` prints; /// without, the rows `docs --json` prints, plus the failures. #[arg(long)] json: bool, }, /// List every document the workspace reaches — the root included — one /// per line, in path order. /// /// The census a view narrows: what `views` would select with no `where:`, /// without declaring a view to ask. Reached, not present — /// a file in a directory nothing links into is not listed, for the same /// reason `check` does not report it. `--json` gives the same rows as /// records, which is the surface for a query engine or a shell pipeline /// that wants to build its own table over the workspace. Docs { /// Print to stdout as JSON instead of a line each: one array, one /// object per document, each carrying its path, its title, its id, its /// ancestors, and its **whole metadata block** — the same row a view /// returns. The id is the document's however the /// workspace stores it (its own `id` field, or the registry), so a /// consumer joining on it need not know which. `null` where a /// document has none. /// /// A workspace that reaches nothing prints `[]`, so "no documents" and /// "printed nothing" stay distinguishable. Nothing is written to /// stderr in this mode. #[arg(long)] json: bool, /// With `--json`, carry each document's prose body as a `body` string /// beside its metadata — the whole workspace as text, in one record /// set, for a search table, a corpus dump, or a pipeline that wants /// the words and not only the fields. /// /// The body is prov's reading of it, which is why this is offered at /// all: a combined document's prose is what is left once the metadata /// block is taken out (and the block need not sit at the file's edge), /// and a separated node's prose is in the file its `content` names — /// so `cat` on the `path` column gets the wrong text both ways, and /// `prov body` one document at a time gets the right text N spawns at /// a time. `null` where a document has no prose to carry: an /// attachment sidecar (its `content` is opaque bytes) or a whole-file /// metadata node standing for itself or for a manifest. An empty body /// is `""`, so "has none" and "has nothing in it" stay distinguishable. /// Off by default because bodies are most of a workspace's bytes. #[arg(long, requires = "json")] body: bool, }, /// Find every document that mentions each of the given words, best first. /// /// Plain words, matched as substrings — case and diacritics aside, so /// `alesund` finds `Ålesund` — over the title, the metadata values and /// the body of every document `docs` lists. Every word must occur, but /// not in one place: `ogden pen` finds a letter titled *From Ogden* whose /// body mentions the pen. A document is ranked by how much of the query /// its title holds, then by how much its fields hold, then by path. /// /// A metadata value is searched unless its key carries structure — every /// relation the workspace declares, `id`, `content` and the like — since /// a hit through a link's label would be a hit on another document's /// name. The index is built from the files each time and kept nowhere: /// nothing is written to the workspace. /// /// Each hit is one line: the path, the title, and the passage around the /// match with the match itself between `«` and `»`. A passage cut from a /// field opens with the field's key. `--json` gives the same hits as /// records. Search { /// The words to look for; every one must occur. #[arg(value_name = "WORD", required = true, num_args = 1..)] words: Vec<String>, /// How many hits to show, best first. #[arg(long, default_value_t = 20, value_name = "N")] limit: usize, /// Print to stdout as JSON instead of a line each: one array, one /// object per hit, each carrying its path, its title, the site the /// passage was cut from (`title`, `field` or `body`, with `field` /// naming the key or `null`), and the passage as its `before`, /// `matched` and `after` text. No hits prints `[]`. #[arg(long)] json: bool, }, /// List the exports this workspace declares, or preview one. /// /// An export is a named, closed-by-default set of documents that may leave /// the workspace: a document is in it only if it itself declares the /// export's gate value, and a document that declares nothing leaves in /// nothing. With no NAME, print what the workspace declares; with one, /// print the plan — what leaves, what the gate held back, what the view /// scoped out. A preview moves nothing. Exports { /// The export to preview (default: list every declared export). #[arg(value_name = "NAME")] name: Option<String>, }, /// Show what a preset would write into this workspace, or write it. /// /// A preset is a stencil: a directory laid out like the workspace root, /// holding a `prov.yaml` with the axes it declares and the stores they /// point at. Applying it writes those out, in full, into the workspace's /// own config and files — and then the workspace is ordinary, fully /// spelled-out config that no reader needs the preset to understand. With /// no DIR, the built-in preset (`created` and `updated`, the one `init` /// writes when told nothing else). /// /// Additive, and refuses collisions: an entry the workspace already /// declares the same way is nothing to do; one it declares differently /// is reported, and nothing is written. Without `--write`, prints the /// plan and touches nothing. Presets { /// The preset directory (default: the built-in preset). #[arg(value_name = "DIR")] dir: Option<PathBuf>, /// Write it, rather than only saying what would be written. #[arg(long)] write: bool, }, /// Print the containment tree that unfolds from a root document. Tree { /// The document to discover from (default: the workspace root). #[arg(value_name = "TARGET")] root: Option<String>, /// Follow a cross-workspace reference (`id:<name>/<id>`) into the /// workspace it names and keep walking there, hanging the peer's own /// subtree where the leaf is. Paths under a crossing are printed in /// *that* workspace's terms, with a marker naming it and where it is. /// /// Off by default, and DEPTH counts crossings rather than tree levels /// (default 8). prov's walk is bounded by what one root reaches, which /// is what makes it usable inside a larger repository; crossing on its /// own initiative would cost every invocation the size of the whole /// federation. /// /// Only a peer that is nested in the folder of the workspace the /// reference is written in, or that this device's map records, *and* that the peer itself confirms is /// followed; a nested workspace answers its name ahead of the map. Every other boundary stays the leaf it is without the /// flag, now carrying the reason it was not followed. #[arg(long, value_name = "DEPTH", num_args = 0..=1, default_missing_value = DEFAULT_FOLLOW_DEPTH)] follow: Option<usize>, /// Follow a peer whose name could not be checked — one that is /// anonymous, or that could not be opened as a workspace. Never accepts /// a peer that calls itself something else; that is not missing /// evidence, it is evidence of the wrong archive. #[arg(long, requires = "follow")] unverified: bool, }, /// Interactively explore the workspace: view a document and follow any of its /// links — or its backlinks — moving through the graph from the terminal. /// /// A cross-workspace reference is a step like any other when the workspace /// is nested in this one's folder or this device's peer map records where /// it is, and the peer confirms its own name: the screen moves into that workspace, and Back comes home. Explore { /// The document to start from (default: the workspace root). file: Option<PathBuf>, /// Cross into a peer whose name could not be checked — one that is /// anonymous, or that could not be opened as a workspace. Never accepts /// a peer that calls itself something else; that is not missing /// evidence, it is evidence of the wrong archive. #[arg(long)] unverified: bool, }, /// Check workspace integrity from a root: broken links, case mismatches, /// duplicate containment, missing inverse links, dangling IDs, orphans, /// fixity drift, and values outside a closed vocabulary (the one place /// that is enforced). Exits 1 on findings — or, with `--ignore-warnings`, /// on errors. /// /// The verdict is the whole workspace's, so one that already had findings /// exits 1 before any change of yours. To judge one change, filter with /// `--only <file>`, or compare the output before and after. Check(CheckArgs), /// Record that a document changed **outside prov** — restamp its content /// checksum, and stamp the workspace's `updated` field with the current /// time. What `prov edit` does automatically for an edit it hosted, for the /// edits it did not: another editor, a sync, a script. /// /// `check --fix` is not this. It offers to re-stamp the checksum (as a /// judgment, so `--fix mechanical` skips it), but it never writes /// `updated` — nothing on disk tells it when the edit happened — so it /// repairs the hash while erasing the only remaining sign the file changed. /// /// Idempotent: with a checksum on record, the stamps land only when the /// bytes actually drifted, so re-running changes nothing and this is safe /// in a sync hook. /// /// Refuses a manifest node by name: its checksum covers the manifest /// document, rebuilding which means re-reading every file it lists — /// `prov manifest <target> --update` is the verb that pays that cost on /// purpose. `--all` skips a manifest node it meets rather than paying it /// unasked. Stamp { /// The document to stamp. An attachment's payload is covered through /// its sidecar, so either handle works. Omit with `--all`. #[arg(value_name = "TARGET")] target: Option<String>, /// Bring the whole workspace's fixity up to date: correct every /// checksum whose bytes have drifted, and seed one for every document /// that never had one. /// /// It writes `updated` only for the documents that actually drifted. A /// checksum restates the bytes, so it is owed wherever it is missing or /// wrong; a timestamp claims an edit happened, and a sweep across a /// workspace it merely read has no evidence for that. Naming a single /// target is that evidence — which is the one way `--all` differs from /// running this per file. #[arg(long, conflicts_with = "target")] all: bool, /// Restamp the checksum but leave the timestamp alone — for keeping /// fixity true without claiming an edit time. #[arg(long)] no_timestamp: bool, /// Print what would be stamped, and write nothing. #[arg(long)] dry_run: bool, }, /// Record that someone read a document and found it correct: append a /// dated, attributed entry to its `confirmed` list. The keeper's own ledger /// — a claim in the document, as trustworthy as its `author` field, and /// never proof. /// /// The entry is measured against the workspace's `updated` stamp from then /// on: once the document changes after it, `check` reports the /// confirmation as stale, and the document falls back to whatever its /// remaining confirmations support. Confirming never stamps `updated` /// itself. A document that records a `content_hash` has the entry bound to /// that digest too, and one whose checksum has already drifted is refused /// until `stamp` restates it. /// /// A bare actor is a person (`--by amh`); a tool prefixes itself /// (`agent:claude-opus-5`, `process:nightly`). prov never writes one on its /// own initiative — a green `check` attests bytes and structure, and says /// nothing about whether the content is right. Confirm { /// The document to confirm: a path, a title route, or an id. #[arg(value_name = "TARGET")] target: String, /// Who is confirming. Defaults to `PROV_ACTOR`, then the device-local /// `actor` file beside the peer map; with none of those the command /// refuses rather than writing an unattributed entry. #[arg(long, value_name = "ACTOR")] by: Option<String>, /// Print the document's confirmations — which still stand, which the /// document has changed out from under, and the tier they add up to — /// and write nothing. #[arg(long, conflicts_with = "by")] show: bool, }, /// Create a document as a child of a parent, linking both directions. The /// positional is the new document's **title** — prov derives a readable /// filename from it (a slug plus the workspace's content extension) in the /// parent's directory, and records the title in the document's metadata, /// where structure lives. Override the derived filename with `--as` (an exact /// path) or just its extension with `--ext`. /// /// Use this rather than writing the file yourself: a file nothing lists in /// its `contents` is not reached, and `check` reports it as an orphan. The /// new document's path is printed on stdout. New(NewArgs), /// Give an arbitrary file (an image, a PDF, any binary) workspace-linked /// metadata: write a sidecar `<file>.yaml` beside it carrying its title, /// links, and any ID, and link it as a child of a parent. The file's bytes /// are never read or rewritten — only linked, moved, and validated with it. Attach(AttachArgs), /// Show, refresh or deeply verify the manifest covering a directory — the /// bulk attachment minted by `attach --manifest`. /// /// Bare, it reports what the manifest says and whether the directory still /// agrees with it, reading no covered file. `--update` rebuilds the list /// from the directory as it is now (and re-stamps the node that pins it); /// `--add` records only the files it names, leaving every other row as it /// is; `--verify` re-reads every listed file and compares its checksum, which is /// the pass `check` deliberately leaves out because it costs a full read of /// the archive. Manifest { /// The covered directory, or the node/manifest document that describes /// it — whichever you have to hand. #[arg(value_name = "TARGET")] target: PathBuf, /// Rebuild the list from the directory: record files that appeared, drop /// rows whose file is gone, and re-checksum what is there. Accepts the /// directory as it stands, so a file you have *lost* is written out of /// the record — which is why it is never automatic. #[arg(long, conflicts_with = "add")] update: bool, /// Re-read every listed file and compare its checksum against the /// manifest — the deep integrity pass over the archive. #[arg(long, conflicts_with = "add")] verify: bool, /// Record these files, new under the covered directory, and nothing /// else: every other row stays as it is, its file present or not, and /// only these are checksummed. Refuses a file outside the directory, /// a document, or one already listed. #[arg(long, value_name = "FILE", num_args = 1..)] add: Vec<PathBuf>, }, /// Gather attachments into one manifest: their files move into a new /// directory, their sidecars go, and one node takes the first one's place /// in their index. For photographs added one at a time that turn out to be /// one album. /// /// A field every sidecar shares moves onto the node, and one only some /// carry onto the rows of the files that have it. Refused while a sidecar /// holds something a manifest cannot — a field holding a link, a link to /// it or its file from elsewhere, children — and each is listed; /// `--discard FIELD` accepts losing such a field. Gather { /// The attachments, by sidecar or by file — all in one index. #[arg(required = true, value_name = "ATTACHMENT")] cards: Vec<PathBuf>, /// The new directory the files move into. The node is named for it. #[arg(long, value_name = "DIR")] into: PathBuf, /// The node's title (default: the directory's name read as a title). #[arg(long)] title: Option<String>, /// Drop this field from the sidecars that carry it rather than keep /// it on their rows, or accept losing it. Repeat for several. #[arg(long, value_name = "FIELD")] discard: Vec<String>, /// List what would move, be carried and be lost, and write nothing. #[arg(long)] dry_run: bool, }, /// Scatter a manifest back into one attachment per covered file. The files /// stay where they are; each gains a sidecar, carrying its row's fields. /// /// Bare, the node is kept as the index the sidecars go under — same title, /// same id, every link to it still good — and loses only its manifest. /// With `--into`, the node goes and the sidecars join that index (in the /// node's place, when it is the node's own parent), each carrying the /// node's fields; its title is then a loss to `--discard`. Scatter { /// The covered directory, or the node or manifest document. #[arg(value_name = "TARGET")] target: PathBuf, /// The index the sidecars go under instead of the node: a path, a /// title route (`@Photos`), or an id. #[arg(long, value_name = "INDEX")] into: Option<String>, /// Accept losing this field — of the node, or a row's that a sidecar /// keeps for itself. Repeat for several. #[arg(long, value_name = "FIELD")] discard: Vec<String>, /// List the sidecars that would be written and what would be lost, /// and write nothing. #[arg(long)] dry_run: bool, }, /// Move/rename a document, maintaining every affected link: every inbound /// reference across the workspace (parent entry, children's inverses, /// overlay links, body links and images) and the document's own relative /// links. An attachment's payload travels with its sidecar, and every body /// reference to the payload follows it. /// /// Given a directory, moves the whole directory as one change: every /// document under it is a mover, and a file prov does not read moves as /// bytes. /// /// Moves the *file* and preserves the document's place in the tree. To change /// its place in the tree instead, see `reparent` — or pass `--in` /// here to do both at once. /// /// Use this rather than `mv` or `git mv`, which leave every link to the old /// path broken. Each rewritten link keeps the spelling it had: a root-style /// link stays root-style. A document cannot move into another workspace; /// copy it there, link it in, and `prov rm` the original. Mv { /// The document to move: a path, a title route (`@Daily/2026/07`), or an /// id (`id:fpk38j`). #[arg(value_name = "TARGET")] from: String, /// New path. to: PathBuf, /// Also reparent under this document — the file moves *and* changes /// parent. A path, a title route (`@Daily/2026/08`), or an id. #[arg(long = "in", short = 'i', value_name = "TARGET")] in_target: Option<String>, /// Create missing route segments (when `--in` is a route), like `mkdir -p`. #[arg(long = "parents", short = 'p', requires = "in_target")] parents: bool, /// Where `--parents` writes the nodes it synthesizes. Placement only — /// never the graph. #[arg(long, value_enum, default_value_t = LayoutArg::Nested, requires = "parents")] layout: LayoutArg, }, /// Change a document's parent in the containment tree, leaving the file where /// it is. /// /// The complement of `mv`: `mv` changes a document's path and preserves its /// place in the tree; `reparent` changes its place in the tree and preserves /// its path. Containment is link-shaped, not directory-shaped, so a node may /// live in any directory — moving the file is a separate decision (`mv`, or /// `mv --in` to do both). /// /// The old parent's entry is removed and the new one's added, so the document /// is never contained twice. An unparented document is accepted: there is /// nothing to remove, so this simply links it in. /// /// The two directions are judged separately, so a document that already /// claims this parent while the parent does not list it — the state most /// orphans are actually in — gets the missing entry written rather than a /// success message and no change. It says which of the three happened: it /// moved, it linked, or both directions already held and nothing was /// written. An old parent that is no longer on disk is not an error either; /// there is simply no entry to remove. Reparent { /// The document to reparent: a path, a title route (`@Daily/2026/07`), or /// an id (`id:fpk38j`). #[arg(value_name = "TARGET")] path: String, /// The new parent: a path (`daily.md`), a title route /// (`@Daily/2026/08`), or an id (`id:fpk38j`). #[arg(long = "in", short = 'i', value_name = "TARGET")] in_target: String, /// Create missing route segments (when `--in` is a route), like `mkdir -p`. #[arg(long = "parents", short = 'p', requires = "in_target")] parents: bool, /// Where `--parents` writes the nodes it synthesizes. Placement only — /// never the graph. #[arg(long, value_enum, default_value_t = LayoutArg::Nested, requires = "parents")] layout: LayoutArg, /// Show what `--in` resolves to, and refuse what the reparent would /// refuse, without changing anything. #[arg(long, requires = "in_target")] dry_run: bool, }, /// Put a document's children in the order given, touching nothing else. /// /// The one structural verb that moves no link. The children named are /// permuted into that order; a child not named keeps its place, so naming /// two of ten swaps those two and leaves the other eight where they were. /// The children themselves are not edited — their `part_of` names the /// parent, not a position in it — and a comment beside an entry, or the /// spelling of its link, survives the move. /// /// Every child named must already be listed by the parent: this changes /// where a child sits, never whether it is there (that is `reparent`). A /// document the parent does not list is an error, and so is one named /// twice. Says whether the order changed; an order the parent already /// holds writes nothing. Reorder { /// The parent: a path, a title route (`@Daily/2026/07`), or an id /// (`id:fpk38j`). #[arg(value_name = "PARENT")] parent: String, /// Its children, in the order wanted — each a path, a title route, or /// an id. #[arg(value_name = "CHILD", required = true, num_args = 1..)] children: Vec<String>, }, /// Delete a document, removing its parent's spanning entry. Refuses when /// the document has children unless --force. /// /// The file is destroyed. prov does not keep a copy — getting the bytes back /// is your version-control or backup tool's job — but it records what it /// deleted, and `prov restore` uses that record to put the document back /// into the graph once you have the file again. Recording is governed by the /// `record_deletions` config axis (on unless opted out). /// /// Use this rather than `rm`, which leaves the parent's entry, and every /// other link to the document, pointing at nothing. Rm { /// The document to delete: a path, a title route (`@Daily/2026/07`), or an /// id (`id:fpk38j`). #[arg(value_name = "TARGET")] path: String, /// Delete even when the document still contains children (orphans them). #[arg(long)] force: bool, }, /// Put a deleted document back into the graph: re-register the id it held /// and re-link it under the parent that listed it. /// /// **Restore the file first.** prov did not keep its bytes, so recover them /// however this directory is backed up or version-controlled (`git checkout /// <path>`, a copy out of a snapshot) and put them back at the original /// path; this command does the half no such tool can. It refuses when /// nothing is at that path, and says so. /// /// Also refuses when the record's id has been claimed in the meantime — by /// another document, or by another id at that path. Ids travel in /// frontmatter, so a sync can hand one to a second document while the record /// sat in the log; restoring over that would take the id from a document /// that still spells it, and only you can say which should keep it. /// /// A workspace still on the recycle bin this replaced *did* keep the bytes, /// and restoring one of its records moves them home as before — nothing to /// put back first. Restore { /// The original path of a deleted document (as listed in the deletion /// log). #[arg(value_name = "PATH")] path: String, }, /// Forget every deletion the log records. Irreversible: the records are the /// last evidence of what was deleted, and `prov restore` needs them. /// /// A workspace still on the recycle bin this replaced also has bytes parked /// under it, and this destroys those too — which is what emptying a bin /// always meant. ClearDeletions, /// Convert a document along a config axis. Five axes are supported. /// Two restyle the document's own outbound path links: `notation` (how a /// target is wrapped — `markdown` `[Title](target)` or `bare` `target`) and /// `path_style` (how the path itself is written — `root` / `relative` / /// only the spelling changes; each link's destination, label, /// and wrapper are preserved, and id/external/alias targets are left untouched. /// Two rewrite the metadata block: `metadata.format` re-emits the /// frontmatter in a different language (`yaml` / `json` / `toml` / `fig`), /// keeping its embedding shape; `metadata.embed` re-emits it in a different /// shape (`delimited` / `code_block` / `html_script` / `html_code`), keeping its /// language — so a `delimited` block can become a code block that can then hold /// fig. Both preserve every value (comments do not survive a block rewrite). /// The fifth, `content_format` (`markdown` / `djot` / `html`), transcodes the /// body prose — and, because a body's grammar is declared by its file /// extension, renames the file (`notes.md` → `notes.dj`) and retargets every /// inbound link to it. Converting to or from `html` is lossy and needs `-f`. /// Per file by default (DESIGN §8) — a document's spelling is its own to /// declare; `-r` also converts this file's spanning subtree. Convert { /// The document to convert. #[arg(value_name = "TARGET")] file: String, /// The config axis to convert: `notation`, `path_style`, `metadata.format`, /// `metadata.embed`, or `content_format`. axis: String, /// The target value (e.g. `bare` for `notation`, `relative` for /// `path_style`, `json` for `metadata.format`, `code_block` for /// `metadata.embed`, `djot` for `content_format`). value: String, /// Also convert every document in this file's spanning subtree. #[arg(long, short)] recursive: bool, /// Allow a lossy conversion — converting body prose to or from `html`, /// where the authored markup does not survive the round trip. #[arg(long, short)] force: bool, }, /// Duplicate a document as a fresh sibling under the same parent, linking the /// copy in both directions. The copy takes the next free `-copy` name and /// carries the source's title, body, and metadata — but never its stable ID /// (identity is per-document) nor its children (a shallow copy, so no child is /// left with two parents). A separated node's body file is copied too. #[command(alias = "dup")] Duplicate { /// The document to duplicate: a path, a title route (`@Daily/2026/07`), or /// an id (`id:fpk38j`). #[arg(value_name = "TARGET")] source: String, }, /// Ensure a document has a stable ID and print its `id:<id>` target. /// Registers it in the workspace's registry document (bootstrapping /// registry.yaml + the root's `registry` pointer on first use) — link that /// target from any document and it survives moves. /// /// From another workspace, link it as `id:<workspace>/<id>`, where /// `<workspace>` is this one's `workspace_id`; run `prov -C <dir> id /// <file>` to get the id without leaving the workspace you are in. A path /// link into a workspace nested inside this one is a `check` finding. /// /// With `--workspace`, names the *workspace* instead of a document: the /// `workspace_id` other archives reference this one by (`id:<name>/<id>`). Id { /// Path to a document. #[arg(value_name = "TARGET", required_unless_present = "workspace")] file: Option<String>, /// Name this workspace rather than a document, so another workspace can /// reference it (`id:<NAME>/<id>`). Pass a NAME to choose one; pass the /// flag bare to have prov mint an opaque global one. Either way it is /// written to config and printed. /// /// Idempotent and never destructive: if the workspace is already named, /// that name is printed and nothing is written — a name is what other /// archives have already written their references with, so *changing* /// one is a deliberate `prov config workspace_id <name>`, not a rerun of /// this. #[arg( long = "workspace", value_name = "NAME", num_args = 0..=1, conflicts_with = "file" )] workspace: Option<Option<String>>, }, /// Resolve a stable ID (`id:<id>`, the legacy `colophon:<id>`, or the bare /// id) to its current path. An id in another workspace (`id:<workspace>/<id>`) is /// `prov peer resolve`'s. Resolve { /// The ID to resolve. id: String, }, /// List the documents that link to a document (its backlinks), across the /// workspace, as `source<TAB>site<TAB>path|id`. Backlinks { /// The document whose backlinks to list. #[arg(value_name = "TARGET")] file: String, }, /// Get or set workspace config (e.g. `link_format`, `identity`). With a /// value, writes it to the linked config document — creating and linking /// `prov.yaml` from the root on first use. With a key only, prints that /// value; with no key, prints the effective config. Config { /// The config key — dotted for nested axes (e.g. `references.notation`, /// `identity`). Omit to print the effective config. key: Option<String>, /// The value to set. Omit to read. value: Option<String>, /// Materialize the *full* effective config explicitly into the config /// document — every setting written out at its current (or default) /// value, so nothing relies on invisible defaults. Fills in the keys you /// have not set; existing settings and fields are preserved. #[arg(long, conflicts_with_all = ["key", "value", "home"])] setup: bool, /// Relocate the whole workspace policy to one home, preserving what is /// declared (no defaults baked in): `sidecar` moves it into `prov.yaml` /// and clears the root's `prov:` block ("unclutter my root"); `root` /// inlines it into the root's `prov:` block and removes the sidecar ("one /// less file"). Reading always spans both homes regardless of where policy /// lives. #[arg(long, value_name = "root|sidecar", conflicts_with_all = ["key", "value", "setup"])] home: Option<ConfigHome>, }, /// Copy the entire workspace tree to another filesystem location, for /// redundancy against losing the workspace's own location (a dead disk, a /// deleted cloud folder). A plain, opaque, whole-tree copy — bytes /// verbatim, hidden files included — with no pointer relation, no /// manifest, no config axis: it deliberately depends on nothing living /// inside the workspace, which is the whole point of a backup. An /// imperative one-off, not a standing behavior. Backup { /// Where to write the backup: a directory to copy the tree into /// (created if missing; parent directories are created as needed; an /// *existing* directory here must be empty) — or, with `--zip`, the /// path of the zip file to create. Refused if it resolves inside the /// workspace root (the copy would recurse into itself). #[arg(long = "to", value_name = "PATH")] to: PathBuf, /// Archive into a single store-only (uncompressed) zip file instead of /// copying to a directory. #[arg(long)] zip: bool, }, /// Regenerate `about.md` — the prose page that tells a reader with no prior /// knowledge how to read this directory — from the workspace's own /// configuration, and point the root at it. /// /// The page is the spec *specialized* against this workspace: every rule /// resolved to a concrete fact, every branch this workspace does not take /// left out. It is written for a person who has the directory and nothing /// else, and it is found by its filename rather than by following a link. /// /// Derived from configuration alone, never from the files, so it is rewritten /// when configuration changes and at no other time. A conflicted copy is /// always resolved by regenerating rather than merging — nothing in it is a /// fact about anything but the config. About { /// Exit non-zero if the page is missing or does not match what prov /// would generate, printing what differs. Writes nothing. For CI in a /// repository that wants the page guaranteed current. #[arg(long)] check: bool, /// Write the generated page to stdout, touching nothing. #[arg(long, conflicts_with = "check")] print: bool, }, /// List what a tool copying, syncing or recording this folder should /// leave alone. /// /// The workspace is the graph's bounded reachable walk from the root /// document, so everything else on disk is something a person did not /// mean to hand such a tool: prov's own bookkeeping, an archive a /// manifest already pins by hash, an editor's dotfiles, and files nothing /// links. This prints that difference as gitignore-syntax lines on /// stdout — anchored to the workspace root — for whatever consumes them: /// `.gitignore`, a version-control tool's skiplist, `rsync /// --exclude-from`, a backup job. /// /// prov writes nothing and merges nothing. What rules a tool already /// holds, and what a rule means for a file it has recorded before, are /// that tool's to decide. /// /// A rule reading *unreached* is the one worth acting on from the other /// side: link the file into the graph, and the next run withdraws it. /// `--why` groups the rules under a comment naming each reason; `--json` /// gives the same as structured records. Ignore { /// Group the rules under a comment naming why each set is there. /// Still a valid ignore file, and ordered by reason rather than path. #[arg(long)] why: bool, /// Emit the list as JSON records — path, whether it covers a /// directory whole, the reason, and the rendered line. #[arg(long, conflicts_with = "why")] json: bool, },}
/// The arguments of `prov init` — see [`Command::Init`] for the command.#[derive(Args)]pub(crate) struct InitArgs { /// Directory to initialize (default: the current directory). Created if /// it does not exist. pub(crate) dir: Option<PathBuf>, /// Title for the root document (default: the directory's name, titleized). #[arg(long)] pub(crate) title: Option<String>, /// Author to record in the root's metadata (default: none). #[arg(long)] pub(crate) author: Option<String>, /// Config language for the root's metadata: yaml/toml/json/fig /// (default: yaml). `fig` is unavailable with `--embed delimited`. #[arg(long, value_enum)] pub(crate) meta: Option<MetaFormat>, /// How that metadata is embedded: delimited, code-block, html-script, /// html-code, or separate. Must suit `--content` (default: the first /// style that content grammar offers). #[arg(long, value_enum)] pub(crate) embed: Option<EmbedArg>, /// Body-prose grammar; sets the root file's extension (default: markdown). #[arg(long, value_enum)] pub(crate) content: Option<ContentLang>, /// The syntactic wrapper prov authors references in: markdown /// (`[Title](target)`) or wikilink (`[[target]]`) (default: markdown). /// The first style axis — pick it, then `--reference` picks the target. #[arg(long, value_enum)] pub(crate) wrapper: Option<WrapperArg>, /// What references address their target by: path, id, alias (by title), /// or split (readable `contents` down / durable `part_of` up). `id` and /// `split` require `--identity` ≠ off; `alias`/`split` are by-title links /// with no markdown form, so the interactive menu offers them only under /// `--wrapper wikilink` (default: path). #[arg(long, value_enum)] pub(crate) reference: Option<ReferenceArg>, /// How *path* references are formatted — only used when a target is /// addressed by path (default: markdown-root). #[arg(long, value_enum)] pub(crate) link_style: Option<LinkStyleArg>, /// When documents earn a stable ID: off (paths only), lazy (on /// link-by-id or publish), or eager (at creation) (default: lazy). #[arg(long, value_enum)] pub(crate) identity: Option<IdentityArg>, /// Where IDs live: frontmatter (stamped into each document's `id` field, /// with the registry kept as a cache), registry (only in the registry /// document), or frontmatter-only (no registry document — self-describing, /// but no tombstones) (default: frontmatter). #[arg(long, value_enum)] pub(crate) id_storage: Option<IdStorageArg>, /// Record content checksums for bit-rot detection: on (the default) or /// off. What a checksum covers is not a setting — every node whose /// content is a file of its own gets one. Verified by `prov check`. #[arg(long, value_enum)] pub(crate) fixity: Option<FixityArg>, /// Delete without recording what was deleted. Recording is on by /// default: the delete destroys the file either way, and the record is /// what lets `prov restore` relink it once you have the file back. #[arg(long)] pub(crate) no_record_deletions: bool, /// Frontmatter field prov's own edits (`edit`, `set`, `unset`, `stamp`) /// stamp with an RFC 3339 UTC timestamp on a content change (e.g. /// `updated`). Omitted → the feature is off. #[arg(long, value_name = "FIELD")] pub(crate) updated_field: Option<String>, /// Frontmatter field `prov new` stamps with an RFC 3339 UTC timestamp /// when a document is made (e.g. `created`). Omitted → the feature is /// off. #[arg(long, value_name = "FIELD")] pub(crate) created_field: Option<String>, /// A preset directory to write into the new workspace instead of the /// built-in one: a `prov.yaml` carrying the axes it declares /// (`fields`, `views`, …) and, beside it, the stores those axes /// point at, laid out as the workspace root will be. Omitted → the /// built-in preset, which turns on `created` and `updated`. A flag /// that names an axis the preset also declares (`--updated-field`) /// wins. `prov presets` shows either without writing. #[arg(long, value_name = "DIR")] pub(crate) preset: Option<PathBuf>, /// What this workspace calls itself, so another workspace can reference /// it (`id:<NAME>/<id>`). Omitted → anonymous, which is fine until /// something else needs to point here. No `/`, `:` or whitespace. #[arg(long, value_name = "NAME")] pub(crate) workspace_id: Option<String>, /// What to do with content documents already in the directory: `flat` /// links each one under the new root; `mirror` folds the folder tree into /// the containment tree (each directory becomes a node, synthesizing a /// folder index where none exists); `none` leaves them unlinked. Omit to /// be asked on a terminal (and to leave them unlinked otherwise). #[arg(long, value_enum)] pub(crate) adopt: Option<AdoptArg>, /// Also give the directory's *non-document* files (images, PDFs, data, /// binaries) each a metadata sidecar, linked under the root. Omit to be /// asked on a terminal; non-interactive leaves them alone (they stay /// invisible to `prov check` until attached). #[arg(long)] pub(crate) attach: bool, /// Accept every default without prompting. #[arg(long, short = 'y')] pub(crate) yes: bool,}
/// The arguments of `prov check` — see [`Command::Check`] for the command.#[derive(Args)]pub(crate) struct CheckArgs { /// The document to check from (default: the workspace root). #[arg(value_name = "TARGET")] pub(crate) root: Option<String>, /// Repair findings. Bare `--fix` (or `--fix ask`) walks them and offers /// each finding's repairs to choose from, reading the choice from stdin; /// `--fix mechanical` applies only the repairs that are pure functions of /// an authority — no prompts, for scripts and anything non-interactive. Structure edits only: prose is rewritten solely where the /// parser itself reported a link, so code that looks like one is never /// touched, and no fix ever deletes a file. #[arg(long, value_enum, num_args = 0..=1, default_missing_value = "ask")] pub(crate) fix: Option<FixModeArg>, /// Report only the findings lodged against this document — the ones /// whose repair rewrites it, or that name it as the file to go and look /// at. A filter on the *results*, not on the walk: the whole workspace /// is still checked, because the findings that matter most about one /// document (nothing links to it, its parent dropped it, an inbound /// label went stale) are only visible from the graph. Checking *from* /// the document instead is the positional argument, and cannot see /// them. #[arg(long, value_name = "TARGET")] pub(crate) only: Option<String>, /// Print findings to stdout as a JSON array instead of one line each — /// `kind`, `subject`, the human `message`, and the finding's own /// fields. Empty findings print `[]`, so "clean" and "no output" stay /// distinguishable. /// /// Nothing is written to stderr in this mode: the count line is /// narration for a person, and the array already says how many it holds. /// The exit code is unchanged, though — findings still exit non-zero, so /// `check` keeps working as a CI gate. In a shell that aborts a pipeline /// on a non-zero exit (nushell), capture the status instead of piping /// through it: `(prov check --json | complete).stdout | from json`. /// /// Not available with `--fix`, whose stdout means something else (the /// findings a repair introduced). #[arg(long, conflicts_with = "fix")] pub(crate) json: bool, /// Also check every workspace reachable across a confirmed /// cross-workspace reference, and report them **grouped** — a header /// line per workspace, and every finding line prefixed with the /// workspace it belongs to. Never one merged list: a relative path /// means nothing once it has crossed a root. /// /// This runs each reachable workspace's *own* check. It does not verify /// foreign references, which stays refused for the reason it always /// has been — a finding about a workspace this device cannot see is a /// false positive on every device that lacks it. /// /// DEPTH counts crossings rather than tree levels (default 8), and a /// boundary that was not crossed is narrated to stderr rather than /// reported as a finding: it is the reason the report is shorter than /// the federation, not something wrong with either workspace. The exit /// code is non-zero if *any* reachable workspace has findings. /// /// With `--json` the output is an array of `{workspace, declares, root, /// findings}` objects, the origin first — a different shape from the /// flat array this command prints without the flag, because the /// findings of eighteen workspaces are not one list. /// /// Not available with `--fix`: nothing prov does writes across a /// boundary. Nor with `--only`, whose subject is a path in one /// workspace's terms. #[arg(long, value_name = "DEPTH", num_args = 0..=1, default_missing_value = DEFAULT_FOLLOW_DEPTH, conflicts_with_all = ["fix", "only"])] pub(crate) follow: Option<usize>, /// Cross into a peer whose name could not be checked — one that is /// anonymous, or that could not be opened as a workspace. Never accepts /// a peer that calls itself something else; that is not missing /// evidence, it is evidence of the wrong archive. #[arg(long, requires = "follow")] pub(crate) unverified: bool, /// Exit non-zero only on an **error** — a claim the workspace makes /// that is not so — and not on a warning, which is drift from a claim /// it still keeps: a link that resolves only case-insensitively, a /// stale label on an id link, a near-miss spelling in an open /// vocabulary. Warnings are still reported; only the verdict changes. /// For a CI gate that should fail on a broken link and not on advice. #[arg(long)] pub(crate) ignore_warnings: bool,}
/// The arguments of `prov new` — see [`Command::New`] for the command.#[derive(Args)]pub(crate) struct NewArgs { /// Title of the new document (recorded in its metadata; a readable /// filename is slugged from it unless `--as` overrides). pub(crate) title: String, /// The parent document that gains a spanning link to the new one: a path /// (`daily.md`), a title route (`@Daily/2026/07`), or an id /// (`id:fpk38j`). A route's missing segments are an error unless `-p`. #[arg( long = "in", short = 'i', value_name = "TARGET", required_unless_present_any = ["filing", "filed"], conflicts_with_all = ["filing", "filed"] )] pub(crate) in_target: Option<String>, /// File the new document the way the workspace's `filing.<NAME>` entry /// says, instead of naming a parent: under the entry's anchor, through /// the index for each level of its grain — found by the period it carries, /// made when missing — cut from the new document's own value for the /// entry's field (its `created` stamp, or a `--set`). #[arg(long, value_name = "NAME", conflicts_with = "filed")] pub(crate) filing: Option<String>, /// File the new document through the one filing entry that names /// `kind: page` — the entry a host's "add" files pages by — instead of /// naming the entry. Refused when no entry, or several, name it. #[arg(long)] pub(crate) filed: bool, /// `mkdir -p` for containment — idempotent creation. Creates any missing /// route segments (when `--in` is a route), *and* treats an /// already-existing leaf (a same-titled child) as a no-op instead of an /// error. Safe to re-run — a daily-note cron can call the same command /// every day. A path held by a *different*-titled document still errors. /// (`--filing` makes the indexes it needs without being asked.) #[arg(long = "parents", short = 'p')] pub(crate) parents: bool, /// Where `-p` writes the nodes it creates: `nested` (a directory per /// segment, `daily/2026/index.md`) or `flat` (all beside the start, /// `daily.md`, `2026.md`). File placement only — containment is the links /// either way (default: nested). #[arg(long, value_enum, default_value_t = LayoutArg::Nested, requires = "parents")] pub(crate) layout: LayoutArg, /// Print what `--in` or `--filing` resolves to and what would be /// created, refusing what the real run would refuse, then stop. #[arg(long)] pub(crate) dry_run: bool, /// Use this exact workspace path instead of a title-derived name (the /// title is still taken from the positional). Wins over `--ext`. #[arg(long = "as")] pub(crate) as_path: Option<PathBuf>, /// Override just the derived filename's extension (e.g. `djot`, `yaml`); /// ignored under `--as`. Default: the workspace's content format. #[arg(long)] pub(crate) ext: Option<String>, /// A field the new document opens with, as `KEY=VALUE`; repeatable. /// Typed like `set`'s value (`true`, `12`, `null`, else a string). /// Written after what the workspace itself gives a new document — its /// `created` stamp and each `fields.<name>.default` — and overriding a /// default of the same name. `title`, `id`, `content` and the link /// back to the parent are prov's own and cannot be set here. #[arg(long = "set", value_name = "KEY=VALUE")] pub(crate) set: Vec<String>,}
/// The arguments of `prov attach` — see [`Command::Attach`] for the command.#[derive(Args)]pub(crate) struct AttachArgs { /// The file to attach. Anything prov can't read as a document; a /// readable document should be created with `new` (it carries its own /// metadata) rather than shadowed by a sidecar — unless you mean it, see /// `--opaque`. Omit with `--all`. pub(crate) payload: Option<PathBuf>, /// The parent that gains a spanning link to the attachment (default: the /// workspace root): a path (`daily.md`), a title route /// (`@Daily/2026/07`), or an id (`id:fpk38j`). #[arg( long = "in", short = 'i', value_name = "TARGET", conflicts_with = "filed" )] pub(crate) in_target: Option<String>, /// File the attachment through the one filing entry that names its kind /// (`kind: image` for a photograph, `manifest` with `--manifest`) instead /// of naming a parent. Refused when no entry, or several, name the kind. #[arg(long, conflicts_with = "all")] pub(crate) filed: bool, /// Create any route segments that don't exist yet — `mkdir -p` for /// containment. Only meaningful when `--in` is a route. #[arg(long = "parents", short = 'p', requires = "in_target")] pub(crate) parents: bool, /// Where `-p` writes the nodes it creates. File placement only. #[arg(long, value_enum, default_value_t = LayoutArg::Nested, requires = "parents")] pub(crate) layout: LayoutArg, /// Attach a file prov *can* read as a document, shadowing it: prov links, /// moves and checksums it but never reads it — its title stays out of /// alias resolution and any `id` it shows stays out of the registry. For a /// specimen: an example document, a fixture, a captured export, whose /// metadata block is an exhibit rather than a claim about this workspace. /// `adopt` would instead write a link into that block, editing it. #[arg(long, conflicts_with = "all")] pub(crate) opaque: bool, /// Attach every loose file under the workspace — each opaque file that /// has no sidecar yet — instead of a single payload. Bounded to the /// directories the workspace already reaches (an unlinked subtree, a /// nested workspace, is left alone); pass `--recursive` to sweep the whole /// tree. Mutually exclusive with a positional file. #[arg(long)] pub(crate) all: bool, /// With `--all`, descend into every directory, including ones nothing /// links to yet — the full recursive sweep rather than the reachability- /// bounded default. #[arg(long)] pub(crate) recursive: bool, /// Treat the positional as a *directory* and cover it with a manifest: /// one node and one list of every opaque file under it, instead of one /// sidecar per file. For an archive — ten thousand photographs — where a /// sidecar each is not a workspace anyone can read. #[arg(long, conflicts_with_all = ["all", "opaque"])] pub(crate) manifest: bool, /// With `--manifest`, list the files without checksumming them: an /// inventory rather than a fixity baseline. Hashing reads every file, /// now and at each refresh, which is a real cost over an archive. #[arg(long = "no-hash", requires = "manifest")] pub(crate) no_hash: bool, /// With `--manifest`, claim every file under the directory, documents /// included, and record that in the manifest (`verbatim: true`). For a /// directory that is one artifact carried byte for byte — a built web /// app, whose `index.html` is part of the build — rather than an archive /// whose notes stay documents of the workspace. #[arg(long, requires = "manifest")] pub(crate) verbatim: bool, /// Attach the file *inline*: append a row naming it to the metadata of /// the document `--in` names, in a field the workspace declares /// `type: payload`, instead of minting a sidecar. The document then owns /// the file — it moves with it, is deleted with it, and is checksummed in /// the row. For a picture that is part of a page's text rather than a /// record of its own. #[arg( long, requires = "in_target", conflicts_with_all = ["all", "opaque", "manifest", "filed", "parents"] )] pub(crate) inline: bool, /// With `--inline` or `--demote`, the `type: payload` field the row goes /// in (`attachments[].content`) — needed only when several are declared. #[arg(long, value_name = "PATH")] pub(crate) field: Option<String>, /// Fold an existing card into a row: the positional names the card /// (`photo.jpg.yaml`) or its file, and the row goes into the document /// `--in` names (default: the card's parent). The card's facts move into /// the row, the sidecar and its parent's entry for it go, and the file /// stays where it is. Refused while anything links to the card itself. #[arg( long, conflicts_with_all = ["all", "opaque", "manifest", "filed", "parents", "inline", "promote"] )] pub(crate) demote: bool, /// Give a file a document owns in a row a card of its own: mint its /// sidecar from the row's facts, list it under `--in` (default: the /// document that owned it), and remove the row. #[arg( long, conflicts_with_all = ["all", "opaque", "manifest", "filed", "parents", "inline", "field"] )] pub(crate) promote: bool,}
/// Which home the `config --home` conversion relocates workspace policy to. The/// two homes read identically (DESIGN §2, "two homes, one vocabulary"); this only/// chooses *where the bytes live*.#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]pub(crate) enum ConfigHome { /// Inline in the root document's `prov:` block; the sidecar is removed. Root, /// In the dedicated `prov.yaml` config document; the root's block is cleared. Sidecar,}
/// CLI spelling of the metadata formats prov reads and writes. fig's own/// dialect is `figl`, as fig 6 names it; `fig`, its name through fig 5, is/// still accepted.#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]pub(crate) enum MetaFormat { Yaml, Toml, Json, #[value(alias = "fig")] Figl,}
impl MetaFormat { /// The lowercase spelling for the `init` summary line. pub(crate) fn label(self) -> &'static str { match self { MetaFormat::Yaml => "yaml", MetaFormat::Toml => "toml", MetaFormat::Json => "json", MetaFormat::Figl => "fig", } }}
/// CLI spelling of the body-prose grammars `twig` parses.#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]pub(crate) enum ContentLang { Markdown, Djot, Html,}
impl ContentLang { /// The root document's file extension for this grammar. pub(crate) fn ext(self) -> &'static str { match self { ContentLang::Markdown => "md", ContentLang::Djot => "dj", ContentLang::Html => "html", } }
/// A title heading in this grammar — the seed body of the root document. pub(crate) fn heading(self, title: &str) -> String { match self { // Markdown and Djot share ATX heading syntax. ContentLang::Markdown | ContentLang::Djot => format!("# {title}\n"), ContentLang::Html => format!("<h1>{title}</h1>\n"), } }
pub(crate) fn label(self) -> &'static str { match self { ContentLang::Markdown => "markdown", ContentLang::Djot => "djot", ContentLang::Html => "html", } }
/// The embed styles `init` offers for this grammar, in menu order (the first /// is the default). Every grammar can carry frontmatter or keep metadata in /// a sibling file. Markdown leads with frontmatter, its own convention; /// Djot and HTML lead with the sibling file, since a leading `---` is a /// thematic break to a Djot renderer and visible text to a browser (prov /// reads the block either way, and leaves it out of what it renders). pub(crate) fn embed_styles(self) -> &'static [EmbedStyle] { match self { ContentLang::Markdown => &[EmbedStyle::Delimited, EmbedStyle::Separate], ContentLang::Djot | ContentLang::Html => &[EmbedStyle::Separate, EmbedStyle::Delimited], } }
/// Whether `style` is a sensible embed for this content grammar — the /// validity check the `--embed` flag is held to (the interactive menu only /// ever offers valid styles). pub(crate) fn allows_embed(self, style: EmbedStyle) -> bool { self.embed_styles().contains(&style) }}
/// A menu label + hint for an embed style — the `init` "Embed type" prompt and/// the summary line's spelling.pub(crate) fn embed_labels(style: EmbedStyle) -> (&'static str, &'static str) { match style { EmbedStyle::Delimited => ("Frontmatter", "--- yaml · +++ toml · ---json · ---figl"), EmbedStyle::Separate => ("Separate", "metadata in a sibling file"), }}
/// The config languages `init` offers. Every one can be embedded in every/// style, so `embed` does not narrow them; it is taken so the menu can.pub(crate) fn config_languages(embed: EmbedStyle) -> Vec<(MetaFormat, &'static str)> { let _ = embed; vec![ (MetaFormat::Yaml, "YAML"), (MetaFormat::Toml, "TOML"), (MetaFormat::Json, "JSON"), (MetaFormat::Figl, "figl"), ]}
impl From<ContentLang> for ContentFormat { fn from(c: ContentLang) -> Self { match c { ContentLang::Markdown => ContentFormat::Markdown, ContentLang::Djot => ContentFormat::Djot, ContentLang::Html => ContentFormat::Html, } }}
/// CLI spelling of the metadata *embed type* ([`prov::EmbedStyle`]) — how/// the metadata is carried in (or beside) the document, one level above the/// config language. Which styles make sense depends on the content grammar (see/// [`ContentLang::embed_styles`]); the `--embed` flag accepts any and is/// validated against the chosen content.#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]pub(crate) enum EmbedArg { /// Frontmatter: `---` YAML, `+++` TOML, `---json`, `---figl`. Delimited, /// Metadata in a sibling whole-file document, linked by `content`. Separate,}
impl From<EmbedArg> for EmbedStyle { fn from(e: EmbedArg) -> Self { match e { EmbedArg::Delimited => EmbedStyle::Delimited, EmbedArg::Separate => EmbedStyle::Separate, } }}
/// CLI spelling of the workspace link styles ([`prov::LinkStyle`]).#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]pub(crate) enum LinkStyleArg { MarkdownRoot, MarkdownRelative, PlainRelative, PlainRoot,}
impl From<LinkStyleArg> for LinkStyle { fn from(l: LinkStyleArg) -> Self { match l { LinkStyleArg::MarkdownRoot => LinkStyle::MarkdownRoot, LinkStyleArg::MarkdownRelative => LinkStyle::MarkdownRelative, LinkStyleArg::PlainRelative => LinkStyle::PlainRelative, LinkStyleArg::PlainRoot => LinkStyle::PlainRoot, } }}
/// When a document earns a stable ID — the `identity` config key, one of the/// two independent identity axes `init` asks about. `Off` is paths-only; `Lazy`/// mints on a durable reference (link-by-id or publish); `Eager` mints every/// document at creation. The spellings match the config value (`prov_config`'s `registration_from_str`).#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]pub(crate) enum IdentityArg { /// Paths only — no document ever earns a stable ID. `none` is accepted as a /// synonym, matching the canonical `identity: none` config spelling. #[value(alias = "none")] Off, Lazy, Eager,}
impl IdentityArg { /// The registration trigger set this identity policy selects. pub(crate) fn registration(self) -> Registration { match self { IdentityArg::Off => Registration::OFF, IdentityArg::Lazy => Registration::LAZY, IdentityArg::Eager => Registration::EAGER, } }
pub(crate) fn label(self) -> &'static str { match self { IdentityArg::Off => "off", IdentityArg::Lazy => "lazy", IdentityArg::Eager => "eager", } }}
/// Where a document's stable ID is stored — the `id_storage` config key/// ([`IdStorage`]). `Registry` is the current default (IDs only in the registry);/// `Frontmatter` also stamps each document's own `id` field (a portable,/// self-describing shadow, registry kept as a cache); `FrontmatterOnly` drops the/// registry entirely (self-describing, but no tombstones). `init` offers the/// first two; the third is deliberately flag-only.#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]pub(crate) enum IdStorageArg { Registry, Frontmatter, FrontmatterOnly,}
impl From<IdStorageArg> for IdStorage { fn from(s: IdStorageArg) -> Self { match s { IdStorageArg::Registry => IdStorage::Registry, IdStorageArg::Frontmatter => IdStorage::Frontmatter, IdStorageArg::FrontmatterOnly => IdStorage::FrontmatterOnly, } }}
impl IdStorageArg { /// The lowercase spelling for the `init` summary line. pub(crate) fn label(self) -> &'static str { IdStorage::from(self).as_config_str() }}
/// How `check --fix` decides what to repair.////// The split is [`prov::Warrant`]: a repair that restates an authority/// (regenerate the derived page, rebuild the derived index, spell a link the way/// the file on disk is actually named) chooses nothing and can run unattended,/// while one that picks among rival readings must be picked *by someone*.#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]pub(crate) enum FixModeArg { /// Walk the findings and offer each one's repairs. The default. Ask, /// Apply only the repairs nothing is being chosen in, and prompt for /// nothing — the scriptable mode. Leaves everything else outstanding, and /// says so. Mechanical,}
/// Whether content checksums (fixity) are recorded — the `fixity` config key/// ([`prov::Fixity`]). `On` (the default) checksums every node whose content is/// a file of its own: an attachment's payload, a separated document's prose/// body. `Off` records nothing.////// There is no third value. There was — `full`, which also hashed a combined/// document's own body — and it went because coverage is the *document's*/// question, not the workspace's: a hash is worth recording when it names/// another file, and a hash of a parsed body names nothing an outside tool can/// check. See [`prov::Fixity::covers`].#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]pub(crate) enum FixityArg { Off, On,}
impl From<FixityArg> for prov::Fixity { fn from(f: FixityArg) -> Self { match f { FixityArg::Off => prov::Fixity::Off, FixityArg::On => prov::Fixity::On, } }}
impl FixityArg { /// The lowercase spelling for the `init` summary line. pub(crate) fn label(self) -> &'static str { prov::Fixity::from(self).as_config_str() }}
/// What `init` does with content documents already present in the directory/// (`docs/init-adoption.md`). `Flat` (Phase 1) links each loose file directly/// under the new root; `Mirror` (Phase 2) folds the directory tree into the/// containment tree — every directory becomes a node, synthesizing a folder-note/// index where none exists; `None_` initializes but leaves them unlinked.#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]pub(crate) enum AdoptArg { Flat, #[value(name = "none")] None_, Mirror,}
/// The syntactic wrapper `init` authors references in — the *first* style axis/// (`--wrapper`), chosen before the addressing (see `docs/reference-styles.md`,/// "pick the wrapper first, then the substyle").#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]pub(crate) enum WrapperArg { /// The diaryx/CommonMark form: `[Title](target)` (or bare). Markdown, /// The Obsidian form: `[[target]]` / `[[target|Title]]`. Wikilink,}
impl From<WrapperArg> for Wrapper { fn from(w: WrapperArg) -> Self { match w { WrapperArg::Markdown => Wrapper::Markdown, WrapperArg::Wikilink => Wrapper::Wikilink, } }}
/// What the references `init` authors address their target *by* — the *second*/// style axis (`--reference`), the addressing. `Path` is readable but rewritten/// on move; `Id` is durable and registers its target (so it needs identity);/// `Alias` is by title (readable, never move-safe, never registers); `Split`/// sets *different* addressing for the two spanning directions (the diaryx up≠down/// shape). The wrapper is chosen separately ([`WrapperArg`]).#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]pub(crate) enum ReferenceArg { /// By path — rewritten when a file moves. Rendering follows `--link-style`. Path, /// By durable `id:<id>` handle — survives moves untouched, registers the target. Id, /// By the target's title — readable, but not move/rename-safe (implies wikilink). Alias, /// Readable *down*, durable *up*: `contents` by alias, `part_of` by id. Split,}
impl ReferenceArg { /// Whether this addressing registers targets (link-by-id), so it needs /// identity to mint IDs. `Path` and `Alias` never register. pub(crate) fn needs_identity(self) -> bool { matches!(self, ReferenceArg::Id | ReferenceArg::Split) }
/// Whether a by-path reference is (possibly) authored, so `init` asks the /// path-format question. Only `Path` addresses by path. pub(crate) fn uses_path(self) -> bool { self == ReferenceArg::Path }
/// The lowercase spelling for the `init` summary line and `--reference` flag. pub(crate) fn label(self) -> &'static str { match self { ReferenceArg::Path => "path", ReferenceArg::Id => "id", ReferenceArg::Alias => "alias", ReferenceArg::Split => "split (alias down, id up)", } }
/// The `--reference` flag value (kebab-case), for diagnostics. pub(crate) fn flag(self) -> &'static str { match self { ReferenceArg::Split => "split", other => other.label(), } }
/// Write the addressing axis and per-relation overrides this reference choice /// encodes onto `config`. The workspace `notation`/`path_style` are already set /// (from the wrapper + path-format prompts); this only touches `target`, /// `label`, and the split relations — except `alias`, which forces wikilink. pub(crate) fn write_onto(self, config: &mut WorkspaceConfig) { // Author id links *labeled* — `[Title](id:…)` for markdown, `[[id:…|Title]]` // for wikilink — so a durable reference stays readable, and clickable with // graceful degradation (an `id:` scheme link resolves in tools that know it, // and says "unsupported scheme" in those that don't), rather than an opaque // bare id. The label is a maintained cache of the target's title. let id_label = true; match self { // Path addressing is the default; notation/path_style already carry it. ReferenceArg::Path => {} ReferenceArg::Id => { config.reference_target = Addressing::Id; config.reference_label = id_label; } ReferenceArg::Alias => { // Alias has no markdown/bare spelling; it always renders wikilink. config.notation = Notation::Wikilink; config.reference_target = Addressing::Alias; } // Durable id by default (overlay relations like `links` stay // move-stable), then the two spanning directions diverge: a readable // alias going down, an id link going up in the workspace notation. ReferenceArg::Split => { config.reference_target = Addressing::Id; config.reference_label = id_label; config.relation_styles.insert( "contents".into(), RelationStyleConfig { notation: Some(Notation::Wikilink), path_style: None, target: Some(Addressing::Alias), label: None, }, ); config.relation_styles.insert( "part_of".into(), RelationStyleConfig { notation: None, // inherit the workspace notation path_style: None, target: Some(Addressing::Id), label: Some(id_label), }, ); } } }}
impl From<MetaFormat> for Format { fn from(f: MetaFormat) -> Format { match f { MetaFormat::Yaml => Format::Yaml, MetaFormat::Toml => Format::Toml, MetaFormat::Json => Format::Json, MetaFormat::Figl => Format::Figl, } }}
#[cfg(test)]mod tests { use super::*;
#[test] fn the_follow_flags_default_to_the_library_bound() { // `default_missing_value` is a string clap parses, so the flag carries // its own copy of the depth. This is the one thing keeping that copy // honest. assert_eq!( DEFAULT_FOLLOW_DEPTH.parse::<usize>().unwrap(), prov::crossing::DEFAULT_DEPTH ); }
#[test] fn follow_writes_nothing_and_narrows_nothing() { use clap::Parser; // Both refusals are clap's, so they cost the handler no branch: no // writes across a boundary, and no subject path that means one // workspace's file in another's terms. assert!(Cli::try_parse_from(["prov", "check", "--follow", "--fix"]).is_err()); assert!(Cli::try_parse_from(["prov", "check", "--follow", "--only", "x.md"]).is_err()); // And `--unverified` is a modifier on following, not a mode of its own. assert!(Cli::try_parse_from(["prov", "check", "--unverified"]).is_err()); assert!(Cli::try_parse_from(["prov", "tree", "--unverified"]).is_err()); assert!(Cli::try_parse_from(["prov", "tree", "--follow", "--unverified"]).is_ok()); assert!(Cli::try_parse_from(["prov", "tree", "--follow=2"]).is_ok()); assert!(Cli::try_parse_from(["prov", "explore", "--unverified"]).is_ok()); }}