Sources file¶
TL;DR
exactdocs.sources.yamldeclares an instance's libraries in a file you review and keep in git.exactdocs sources planshows the diff and writes nothing;exactdocs sources applymakes the change and is idempotent.- What an entry leaves out is not managed, and nothing is removed without
--prune. - Only operators (the
adminrole) may plan or apply. The file has no credential field.
exactdocs.sources.yaml declares the libraries an instance should have.
- The set of imported docs goes through code review like the rest of your infrastructure.
- A second instance (staging, a fresh volume after a restore) can be rebuilt from it.
exactdocs sources planshows what would change;exactdocs sources applymakes the change.
# yaml-language-server: $schema=https://raw.githubusercontent.com/SirCypkowskyy/ExactDocs/main/docs/schemas/exactdocs.sources.schema.json
version: 1
libraries:
- url: https://github.com/acme/payments
refs: [main, v1.4.0] # tags, branches or full commit SHAs
include_paths: [docs/]
exclude_paths: [docs/archive/]
tag_rules:
- {pattern: "docs/api/**", tag: api}
chunking: {split_level: 2}
title: Payments # default: named after the repository's README
description: Payment APIs and the ledger.
auto_sync: {tag_pattern: "v*", keep_last: 3}
- url: https://gitlab.com/acme/ledger.git
id: /acme/ledger-docs # default: the ID derived from the URL, as when adding a library
refs: ["2.1"] # quote what YAML would read as a number
auto_sync: false # turn the scheduled check off
The JSON Schema is generated from the server's model:
- committed as
docs/schemas/exactdocs.sources.schema.json(just sources-schemaregenerates it; a test fails when it drifts); - served at
GET /api/v1/sources/schema.
With the yaml-language-server modeline above, which points at the committed file on GitHub,
editors that use it (VS Code's YAML extension, for one) complete and check the file.
Pin the schema to the version you run
Point the modeline at a copy of the file in your repository instead (a relative path works). Do not point it at your instance: the endpoint is operator-only like plan and apply, and the editor sends no session or token.
Operators only
Only operators (accounts with the admin role) may plan or apply a sources file, with a
session or an API token; anyone else gets 403 (CLI exit code 5).
What the file says¶
version: 1andlibraries, a list of at most 300 entries. Unknown keys are refused, so a typo is a 422 naming the field (CLI exit code 2).- Each entry has a
urlandrefs(at least one).- A commit is declared by its full SHA: 40 hex characters, or 64 in a SHA-256 repository, in any letter case.
- A short SHA is refused because the version would be named after the full SHA and every plan would show it again.
iddefaults to the ID derived from the URL; one ID may appear once.
include_paths,exclude_paths,tag_rules,chunking,title,descriptionandauto_syncare optional.- What an entry leaves out is not managed: plan never reports it and apply never changes it, so a library can be tuned in the UI for the settings the file does not declare.
- Path lists and tag rules are compared as sets after the server's normalization: reordering them or spelling a tag in other letter case is no change.
- A declared empty
include_pathsmeans every file: the repository'scontext7.jsondoes not fill it in.
title(one line, at most 120 characters) anddescription(at most 500; empty means none) name a library that the repository README would name wrongly, for example six libraries from one repository limited byinclude_paths.- A declared value is stored like an edit by hand (
PATCH /libraries/{owner}/{repo}, with the same cleaning), so a later import keeps it. - Plan shows a changed one as an update of the library, and it queues no job.
- Left out, the README (or
context7.json) still names and describes the library.
- A declared value is stored like an edit by hand (
- Supported formats: Markdown (
.md,.mdx) and reStructuredText (.rst, the Sphinx source ofdoc/build/ordocs/).- A
.txtfile is read as reStructuredText, but only when aninclude_pathsentry names.txt(doc/**/*.txt), so a folder never brings inrequirements.txt. - Both formats in one library are imported into the same version.
- Files that reStructuredText
include/literalincludemust be inside the selected paths to be read; one that is not is listed as amarkupproblem and the article is imported without it.
- A
chunkingtakes the fields of the library settings'chunkingas a whole set: what it leaves out takes its default,split_level3 andmax_chars4,000 since #381 (6 and no bound before).- A file that declares only
split_level: 2therefore meansmax_chars4,000 now, andplanshows the change for a library stored without a bound. - Declare
max_chars: nullto keep none.
- A file that declares only
auto_synctakes the fields ofPUT /libraries/{owner}/{repo}/auto-syncas a whole set (what it leaves out takes its default), orfalseto turn the check off.autoversions belong to the check and are never listed.- There is no credential field: secrets do not belong in a reviewed file. Add a private library in the UI with its credential, then manage it with the file.
Plan¶
uvx exactdocs sources plan exactdocs.sources.yaml # readable diff
uvx exactdocs sources plan exactdocs.sources.yaml --json # the server's answer
The CLI reads the YAML locally and sends it as JSON to POST /api/v1/sources/plan; the server
never parses YAML.
- The file may be at most 1 MB.
- It may not use anchors or aliases (
&a,*a): a few hundred bytes of nested aliases expand to gigabytes, and a sources file has no use for them (exit code 2). - Plan writes nothing and queues nothing, and it does not ask the git remote, so it is fast and works offline: a ref that does not exist fails at apply.
The diff has four parts:
create: declared libraries that do not exist.update: per library,- each managed setting that changes (before and after);
- the refs to add;
- the scheduled-check change;
- the job the settings change queues (
reprocess,rechunkorretag); - the
manualversions the file does not declare.
unchanged.undeclared: libraries the file does not declare.
errors lists entries apply leaves alone, such as source_mismatch: the id exists with another
repository URL.
- A trailing
/or.gitand the letter case of the scheme and host do not count. - The path's letter case does, because forges differ on whether it matters.
- A declared ref counts as present when it is a version or its import is queued or running.
Apply¶
uvx exactdocs sources apply exactdocs.sources.yaml
uvx exactdocs sources apply exactdocs.sources.yaml --prune # also removes what is undeclared
Apply computes the plan again and applies it one library at a time, in this order:
- Creations. The first ref is imported with the declared paths, tag rules and chunking, then the other refs are added, then the scheduled check is set.
- Updates.
-
Removals, only with
--prune("prune": true): undeclared libraries and undeclaredmanualversions. Without it nothing is ever removed. -
When a setting changes, the settings the file does not manage are sent as stored.
- One library failing does not stop the others. Each result has its
action(created,updated,unchanged,removed,failed), the jobs it queued and itserror. - The CLI exits 1 when any library failed.
Apply is idempotent: a second apply of the same file, also while the first one's imports are still
queued or running, reports every library as unchanged and writes nothing. Apply does not wait for
the imports; follow them in the UI or with GET /api/v1/jobs/{id}.
How long the CLI waits
The server answers once the whole file is applied, about a second or two per new library, so
the CLI's sources plan and sources apply wait 15 s plus 15 s per declared library for that
answer (other commands wait 15 s). If even that runs out, the server may still be applying the
file: run sources plan to see what is left, or sources apply again.
Out of scope for now:
- a drift check between plan and apply;
- a lock against two concurrent applies;
- waiting for the queued jobs;
- the pinned default version;
- retrieval settings;
- manual tags;
- webhooks.