# Links and citations Declaring the relationships between pages and the citations that tie a claim to its source, with the generated regions that hold both. ## Contents - [`xref add`](#xref-add) - [`xref remove`](#xref-remove) - [`xref link-source`](#xref-link-source) - [`links show`](#links-show) - [`cite id`](#cite-id) - [`cite add`](#cite-add) - [`cite sync`](#cite-sync) ## `xref add` Declare that A B. **Synopsis** - `wikitool xref add --a "" --b "" --rel " --b "" [--dry-run]` **Options** ```text --a Exact title of page A (must exist) [required] --b Title to unlink from A; need not still exist as a page [required] --dry-run Preview changes instead of writing -h, --help Show this message and exit. ``` **Examples** ```bash tools/wikitool xref remove --a "Gitea Actions" --b "act_runner" tools/wikitool xref remove --a "Gitea Actions" --b "Act Runner" --dry-run ``` **Behaviour** - Clears the reference in **both** directions: the cleanup command for a deleted or hand-renamed page rather than the strict inverse of a one-directional `xref add`. - Clears `` from every page-ref frontmatter field ``'s type declares (`related:`, `sources:`, `entities:`, `concepts:`) plus the matching bullets. - Also sweeps a page-ref field the type does *not* declare but some other type does, and drops that key once empty. - `--b` need not still exist as a page, so this clears a reference left by a hand-deleted or hand-renamed page without hand-editing frontmatter. - Idempotent: removing an absent link is a no-op. `--dry-run` reports without writing. **Properties** - Changes files: yes - Idempotent: yes - Atomic: No - writes A then B, both idempotent - Counts toward the session call budget: yes - Can reach the network: no **Exit codes** - `0` - success - `1` - Page A not found (B is allowed not to exist) **See also** - `wikitool xref add` - declares an edge - `wikitool rm` - deletes a page and de-links it ## `xref link-source` Batch-link a source page to every entity/concept it mentions. **Synopsis** - `wikitool xref link-source --source "Source - X" --entities A,B,C [--dry-run]` **Options** ```text --source Exact source page title, e.g. 'Source - Docker Cheatsheet' [required] --entities Comma-separated entity/concept titles the source mentions [required] --dry-run Preview which pages would be linked instead of writing -h, --help Show this message and exit. ``` **Examples** ```bash tools/wikitool xref link-source --source "Source - Docker Cheatsheet" --entities Docker,Podman --dry-run tools/wikitool xref link-source --source "Source - Docker Cheatsheet" --entities Docker,Podman ``` **Behaviour** - Each target gets the source page in its `sources:`, and the source page records each target in its own `entities:` or `concepts:`. No body bullet is written on either side - `sources:` *is* the record. - Which field a target lands in follows its collection (`kb/entities/` -> `entities:`), so a new collection needs no code change. - A target whose collection matches no reference field the source type declares is linked one way and named in the output. - A target that does not exist is skipped and named; the others are still linked, and the run then exits 1. - A target that is itself a source page is refused, named with the `cite add` command to use instead, and handled like a missing page: nothing is written for it, the others are still linked, and the run exits 1. `link-source` means "A mentions X" and writes `X.sources += A`, which for X = another source would claim the citation in the wrong direction; a citation between two sources has a direction only `cite add` records. - Idempotent in both directions. `--dry-run` reports what would be linked. **Properties** - Changes files: yes - Idempotent: yes - Atomic: No - one write per entity plus one for the source page, idempotent per page - Counts toward the session call budget: yes - Can reach the network: no **Exit codes** - `0` - success - `1` - Source page not found - `1` - A page in `--entities` does not exist, or a target could not be written; the others were linked - `1` - A page in `--entities` is itself a source page; the others were linked - `1` - The source page itself could not be written after its targets were **See also** - `wikitool sources trace` - who a source is already linked to - `wikitool xref add` - one labelled edge between two pages - `wiki-ingest` skill - where a source is linked after it is written ## `links show` Show the edges out of and into a page. **Synopsis** - `wikitool links show --page "" [--json]` **Options** ```text --page <str> Exact page title [required] --json Print the edges as JSON -h, --help Show this message and exit. ``` **Examples** ```bash tools/wikitool links show --page "Act Runner" tools/wikitool links show --page "Act Runner" --json ``` **Behaviour** - Shows the declared graph around one page in both directions: the edges it asserts (from its own `related:`, with labels) and the edges other pages assert about it. - The inbound half is computed across the corpus on every call, never stored, so it is complete. - `--json` prints both halves as JSON. - Read-only; exempt from the Iteration Budget Gate. **Properties** - Changes files: no - Idempotent: yes - Atomic: Read-only - Counts toward the session call budget: no - Can reach the network: no **Exit codes** - `0` - success - `1` - Page not found **See also** - `wikitool xref add` / `wikitool xref remove` - change the outbound edges - `wikitool search` - finds the exact title ## `cite id` Print the deterministic footnote id `cite add` would use for this (title, file) pair. **Synopsis** - `wikitool cite id --title "Source - X" [--file <qualifier>]` **Options** ```text --title <str> Source page title, e.g. 'Source - Docker Cheatsheet' [required] --file <str> Qualifier for a multi-file source, e.g. 'storage-model.md' -h, --help Show this message and exit. ``` **Examples** ```bash tools/wikitool cite id --title "Source - Docker Cheatsheet" ``` **Behaviour** - Prints the footnote id `cite add` would use for this (title, file) pair. - A preview only: it does not check that the id is free on any given page. - Never fails; safe to retry freely. Read-only and exempt from the Iteration Budget Gate. **Properties** - Changes files: no - Idempotent: yes - Atomic: Read-only - Counts toward the session call budget: no - Can reach the network: no **Exit codes** - `0` - success **See also** - `wikitool cite add` - writes the definition ## `cite add` Upsert a `[^cite-id]: [[Source - X]]` definition in a page's footnotes region. **Synopsis** - `wikitool cite add --page "<Title>" --source "Source - X" [--file <qualifier>] [--dry-run]` **Options** ```text --page <str> Exact title of the page to add a citation on [required] --source <str> Exact title of the source page being cited, e.g. 'Source - X' [required] --file <str> Qualifier for a multi-file source, e.g. 'storage-model.md' --dry-run Preview instead of writing -h, --help Show this message and exit. ``` **Examples** ```bash tools/wikitool cite add --page "Docker" --source "Source - Docker Cheatsheet" tools/wikitool cite add --page "Docker" --source "Source - Docker Cheatsheet" --file part-2 ``` **Behaviour** - Upserts a `[^cite-id]: [[Source - X]]` definition in the page's generated footnotes region, creating the region between `<!-- wikitool:footnotes -->` markers if absent. - Reuses the id when the page already cites this exact source/file pair, so a repeat changes nothing. - Adds `Source - X` to the page's frontmatter `sources:` - except on `Source - X` itself: a source page citing one of its own raw files (`--file`) gets the definition and leaves `sources:` untouched, since a page never lists its own title there. - A source page may cite another source page this way - `cite add` is the command that records a citation between two sources, in the direction it was made. - Prints the `[^cite-id]` marker; pasting it into the prose is a manual, editorial step. - `--dry-run` reports without writing. **Properties** - Changes files: yes - Idempotent: yes - Atomic: Yes - single file write - Counts toward the session call budget: yes - Can reach the network: no **Exit codes** - `0` - success - `1` - The page is not found - `1` - The source page is not found - citing it would be a dangling reference **See also** - `wikitool cite sync` - prunes and re-orders the region - `wikitool cite id` - previews an id ## `cite sync` Reconcile each page's footnotes region against its actual `[^id]` references. **Synopsis** - `wikitool cite sync [--page "<Title>" | --all] [--dry-run]` **Options** ```text --page <str> Sync just this page --all Sync every page under kb/ --dry-run Report what would change instead of writing -h, --help Show this message and exit. ``` **Examples** ```bash tools/wikitool cite sync --page "Docker" tools/wikitool cite sync --all --dry-run ``` **Behaviour** - Prunes definitions nothing references any more, re-renders the region in first-reference order, and reports every `[^id]` reference left with no definition. - An undefined-reference report is not a failure: fix the reference, or run `cite add`, and re-run. - A page still carrying the pre-4.0.0 undelimited footnote block is converted to a marked region in the same pass. - Each page's re-render is idempotent; safe to retry freely. `--dry-run` reports without writing. **Properties** - Changes files: yes - Idempotent: yes - Atomic: No - one write per page, each idempotent - Counts toward the session call budget: yes - Can reach the network: no **Exit codes** - `0` - success - `1` - Neither or both of `--page`/`--all` given, or the page is not found - `1` - A page write failed partway **See also** - `wikitool cite add` - writes a definition <!-- /wikitool:reference-commands -->