@merlon-docs/merlon-docs-cli
v1.2.0
Published
Merlon Docs CLI: compile and check a sharded documentation tree
Maintainers
Readme
@merlon-docs/merlon-docs-cli
About @merlon-docs/merlon-docs-cli
The command-line interface for Merlon Docs, a documentation system for software projects.
Install this package when you need the merlon binary: compile shards into guides, check the docs tree, manage refs, and optionally lint / prose.
Not the Agent Skill
This npm package is not the Merlon Docs Agent Skill. Each piece of Merlon Docs has its own job:
- This CLI: the shell command
merlon(merlon compile,merlon check, …) from@merlon-docs/merlon-docs-clion npm - Core: the programmatic library the CLI is built on,
@merlon-docs/merlon-docs-core - Agent Skill: the host instructions (
SKILL.mdand its workflows) an agent loads for/merlon-docs, which decide when the agent edits docs and which workflow it follows
The CLI and the skill are separate installs with separate docs. Get started in the project README shows how to install the skill and start its bootstrap session, and the skill catalog lists its workflows. The skill doesn't include the merlon binary, so a repository that runs merlon compile or merlon check in scripts or CI installs this package as well. Repo-root npm scripts shows the npm scripts.
Why Merlon Docs for coding agents
Common docs failures when agents edit the repo, and what helps:
| Pain | What goes wrong | What helps |
| -------------------------- | -------------------------------------- | ----------------------------------------------------------- |
| Single-file docs | Merge conflicts, stale TOC | merlon compile; merlon check catches orphans |
| Broken cross-links | Agents guess #anchor slugs | merlon check (optional merlon refs-list for slugs) |
| Context overload | Whole compiled output pasted each turn | Host search, then read one shard |
| Docs drift | Committed outputs lag their shards | merlon compile in CI, then fail on git diff --exit-code |
| Custom compile scripts | Bash/Python glue nobody owns | compile, check, @merlon-docs/merlon-docs-presets |
Typical loop: edit shards → merlon compile → merlon check → optional merlon refs-list → read one shard when the next turn needs doc context.
Install and quick start covers install and flags, and the Agent Skill (skill workflows) contains the docs workflows an agent follows (see Not the Agent Skill for how the CLI and the skill fit together).
Install and quick start
This package installs the merlon CLI for use in your repo or CI. It works in any codebase, whatever its stack or layout, because Merlon Docs manages only your documentation shards and compile pipeline.
To install the Agent Skill instead, see Get started and the skill catalog (or Not the Agent Skill).
Requirements
- Node.js 22 or later. Use the latest release of your major version for its security fixes.
Install
# Dev dependency (recommended)
npm install -D @merlon-docs/merlon-docs-cli
# Or run without installing
npx @merlon-docs/merlon-docs-cli check --config merlon.config.json
# Global install
npm install -g @merlon-docs/merlon-docs-cliSeveral commands run peer tools that you install in your repository, such as markdownlint-cli2 for merlon lint and Vale for merlon prose. Optional linters lists the peer tools each command runs and how to install them.
Stability
On 1.0.0 and later, CLI commands, flags, the merlon.config.json schema, and compile output follow semver: breaking changes ship only in major releases, as Versioning and releases describes for the move past 1.0.0. On 0.x.y, those surfaces could change in any release with no API stability guarantee under the same policy.
Before upgrading, read the changelog and release notes of each Merlon Docs package you use. They hold the upgrade notes for earlier releases, which the feature catalog doesn't repeat.
Quick start
Create
merlon.config.jsonin your docs root. Start with this minimal config for two guides,overviewandadmin-guide. SetconfigVersionto the version of@merlon-docs/merlon-docs-coreyou install; when it's missing, loading the config fails and names the value to add. Minimal config says what each field does:{ "configVersion": "1.0.0", "compileOrder": ["overview", "admin-guide"], "guides": [{ "name": "overview" }, { "name": "admin-guide" }] }Once you install markdownlint-cli2 and
@merlon-docs/merlon-docs-presetswith the npm command in Optional linters, add alintkey that lints the shards with the shard preset. The whole file then reads:{ "configVersion": "1.0.0", "compileOrder": ["overview", "admin-guide"], "guides": [{ "name": "overview" }, { "name": "admin-guide" }], "lint": { "markdownlint": { "shardsConfig": "../node_modules/@merlon-docs/merlon-docs-presets/markdownlint-shards.markdownlint-cli2.jsonc" } } }This path works when the docs root is a direct child of the directory that holds
node_modules, and Optional linters says how Merlon Docs resolves it. When markdownlint-cli2 is missing,merlon checkskips the shard pass with an info line unless you pass--require-lint. When the preset file is missing, the pass fails. Optional linters also covers the compiled-output preset and Vale.Lay out shards under guide directories (each with
index.mdand chapter files). The sample guides in the Merlon Docs repository show a layout, and you can copy single keys from their config.Run:
# When your shell is in the docs root merlon compile --config merlon.config.json merlon check --config merlon.config.json --skip-valeFrom the repository root (typical npm scripts), pass both
--configand--docs-root:merlon compile --config docs/merlon.config.json --docs-root docs merlon check --config docs/merlon.config.json --docs-root docs --skip-vale--configvs--docs-rootsays what each flag resolves from, and Global options lists the options that every command accepts.--skip-valeleaves Vale out of the check. Without it,merlon checkruns Vale whenever it findsvale, and Vale stops with a runtime error when it can't find a config. Drop the flag once you set up Vale as Optional linters describes.Add
docs:compileanddocs:checkscripts to your repo-rootpackage.json, as Repo-root npm scripts shows. The check script runsmerlon check --require-lint. Add--skip-valeto it until Vale is set up, then replace that flag with--require-vale.Run the same compile and check scripts in CI. The verification checklist lists what to confirm once they pass.
If your repository commits compiled outputs, such as a package README that is a publish output, add a CI step that runs
git diff --exit-codeaftermerlon compile. That step fails when a committed output differs from what its shards compile to.merlon checkwrites every output again before it checks them, so it passes on a stale one.
Verification checklist
After you set up a repository, confirm each item:
merlon compile: per-guide outputs under_build/(or explicitcompile.outputFiletargets); optional monolith whenoutputFileis setmerlon check --require-lint: passes the check gate with markdownlint-cli2 required for each configured markdownlint stagemerlon check --require-vale: when Vale is configured- Hook output: diagram tables inlined (
inlineInserts), code evidence blocks resolved (codeEvidence), cross-guide links rewritten to#slugtargets in compiled output (a link to a guide incompile.crossGuideLinks.ignoreGuideskeeps its shard.mdpath, except in the cases that its config section points to)
Project layout
One subdirectory = one guide
Each folder directly under the docs root (--docs-root) is a guide when its name appears in compileOrder. The guide name in config matches the directory name.
| Piece | Role |
| --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Guide directory (features/, client-cli/, …) | One logical guide, made of human-edited shards |
| index.md, or the file compile.manifest names, such as shards.md | Human table of contents. Its link order sets the compile order, as Manifest compile order explains |
| chapter-*.md (typical) | One topic or chapter per file |
| about-this-guide.md | Optional preamble shard: compile drops its # About this guide heading and keeps the text. compile.preambleSection names another file for this role |
Support directories such as styles/ for Vale are not guides unless listed in compileOrder. Compile doesn't write output for them. Shard markdownlint and Vale skip them too unless your config names them, as In-scope guide fileset explains. A guide whose compile.scopeRoot points into one still stitches the shards it links, as the shared glossary does.
Compile writes compiled guides, the optional monolith, the refs registry and opt-in backups under outputDir. A publish output goes where its compile.outputFile points, which can be outside outputDir. Path layout gives the defaults and path rules.
When a manifest has preamble prose with example links, set compile.sectionsHeading. See Manifest compile order.
Config essentials
merlon.config.json names the guides to compile and where their outputs go. This page covers the paths every command resolves from and a minimal config with its path layout. Config reference is the lookup material for every key.
--config vs --docs-root
These two global options answer different questions:
| Option | Resolved from | Purpose |
| ----------------- | ----------------------------------------------------------------------------------- | ------------------------------------ |
| --config | Invocation directory, where you run the command (repo root in most npm scripts) | Locates merlon.config.json on disk |
| --docs-root | Invocation directory, which is also the docs root when you omit the option | Root of guide directories |
--config is never prefixed with --docs-root. A command run from the repository root without --docs-root treats the root as the docs root, so repo-root scripts pass --docs-root docs. Path layout describes the docs root.
Repo-root npm scripts
{
"scripts": {
"docs:compile": "merlon compile --config docs/merlon.config.json --docs-root docs",
"docs:check": "merlon check --config docs/merlon.config.json --docs-root docs --require-lint"
}
}When you are already inside docs/
cd docs
merlon compile
merlon compile --config merlon.config.json --docs-root .Programmatic API
The core library takes the same two bases, and Config API says which one each function needs.
Minimal config
Step 1 of Quick start shows a minimal merlon.config.json for two guides, overview and admin-guide. The fields it leaves out take their defaults, so that config writes overview.md and admin-guide.md to _build/ under the docs root and builds no monolith. Path layout gives each default and says how each path resolves.
| Field | Purpose |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| configVersion | Required. The config format version the file follows: the version of @merlon-docs/merlon-docs-core it was written for. A file that declares only a former name, standardVersion or protocolVersion, migrates to the installed version, and those names are read until 2.0.0 |
| compileOrder | Guide directories to compile, in stitch order for optional monolith |
| guides | Per-guide options (hooks, manifests, publish paths) |
| outputDir | Generated output root (relative to --docs-root) |
| outputFile | Optional stitched monolith |
| refs.registryFile | Refs registry file (default .caches/refs.json) |
| sourceTags | Wrap shards in HTML comments with relative paths (default true) |
| banner | Global banner prepended to outputs (has default warning text) |
| compile.outputFile | Override per-guide output path |
| compile.scopeRoot | Shared tree (relative to the docs root) that guide links pull from |
| compile.sourceTags | Per-guide override of the global sourceTags setting |
Path layout
Two roots (NPM-style):
| Root | CLI / config | Role |
| --------------- | ------------------------------ | ------------------------------------------------ |
| Docs root | --docs-root | Human shard trees — one subdirectory = one guide |
| Output root | outputDir (default _build) | Generated markdown and cache — safe to delete |
One rule for generated paths: compile.outputFile, top-level outputFile and refs.registryFile are relative to outputDir unless they are absolute. The exception is a relative value that, read from the docs root, already lands inside outputDir: compile then uses that docs-root path. With outputDir: "_build", refs.registryFile: "_build/refs.json" names docs/_build/refs.json, the same file as "refs.json", and not docs/_build/_build/refs.json. A relative backup.dir or --backup-dir is read from outputDir with no docs-root exception, and an absolute one is used as is.
docs/ ← --docs-root
merlon.config.json
features/ ← guide "features" (shards)
client-cli/ ← guide "client-cli"
styles/ ← support dir (not in compileOrder)
_build/ ← outputDir (generated; gitignore it)
features.md
client-cli.md
guides.md ← optional monolith (when outputFile set)
.caches/
refs.json
backups/ ← opt-in prior output (--backup)Resolution bases
Project layout says which directories are guides. Omit guides[].path unless a guide's shards live somewhere other than the directory of the same name.
| Config field | Resolved from | Example (--docs-root docs) |
| --------------------- | ------------- | ----------------------------------- |
| Default guide shards | docsRoot | docs/features/ |
| guides[].path | docsRoot | docs/features/ |
| outputDir | docsRoot | docs/_build/ |
| Per-guide output | outputDir | docs/_build/features.md |
| Monolith outputFile | outputDir | docs/_build/guides.md (opt-in) |
| refs.registryFile | outputDir | docs/_build/.caches/refs.json |
| compile.outputFile | outputDir | ../../DEVELOPERS.md from _build |
Delete _build/ to clean everything compile writes under outputDir. A publish output outside it, such as ../../DEVELOPERS.md, stays where it is. .caches/ holds derived state (refs registry) and, when --backup is used, prior compile output at the paths Backup path layout gives.
Default per-guide outputs
When compile.outputFile is omitted:
| Guides in compileOrder | Default file under outputDir |
| ------------------------ | ------------------------------ |
| 1 | guide.md |
| 2+ | {name}.md per guide |
When compile.outputFile is set, that guide writes only to that path (for example npm README publish via ../../packages/foo/README.md) and is excluded from an optional monolith.
Optional monolith
Set top-level outputFile (such as "guides.md") to also stitch guides without explicit compile.outputFile into one file under outputDir. See monolith.
Consumer migration
Use these steps to move an existing Markdown document into shards. For a new repo with no docs to migrate, the Quick start covers setup.
Map the document to guides
merlon shard splits the source document at its H1 headings, then splits each guide's part into shards. Set top-level source to the document's path from the docs root, and give each guide in guides its own source, which picks the H1 sections that guide takes. A guide without one stops the command with Guide <name> needs h1Extract, merge, or directory source for shard, and a config without guides doesn't write any shards.
| source.type | Fields | What the guide gets |
| ------------- | ----------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| h1Extract | index, and optional preamble | The H1 section at that position, counting from 1 |
| merge | parts, each { "fromH1Extract": n } with optional "demoteFirstH1": true, and optional preamble | Those H1 sections in order, each part's H1 made an H2 when it sets demoteFirstH1 |
| directory | path, outside the guide's own directory | A copy of the .md files in that directory, read from the docs root |
Set "demoteFirstH1": true on every merge part after the first. A later part whose H1 stays an H1 loses that heading and the text before its first ## heading, and merlon shard still exits 0. With the flag, the part's H1 becomes an H2 and starts a shard of its own.
merlon shard starts a new shard at each ## heading in a guide's part, and deeper headings stay in the shard above them. The schema accepts a guide's splitLevel, an integer from 1 to 6 that defaults to 2, but merlon shard doesn't apply it, because the md-tree explode command it runs takes no level. Each shard is a file named after its heading, and the guide's index.md links the shards in order.
The text between a guide's H1 and its first ## heading becomes the preamble shard, about-this-guide.md, and the about-this-guide.md row in Project layout says what compile does with it. An h1Extract or merge source can set "preamble": { "promoteToH2": "<heading>" } to give that shard another heading. Compile then treats it as an ordinary shard named after that heading. merlon shard reads preamble from the first guide in guides only and gives every guide's preamble shard its heading. The core API page Shard and peers says how the library reads these mappings.
This config makes the first H1 section the overview guide, and the second and third the admin guide:
{
"configVersion": "1.0.0",
"source": "old.md",
"compileOrder": ["overview", "admin"],
"guides": [
{ "name": "overview", "source": { "type": "h1Extract", "index": 1 } },
{
"name": "admin",
"source": {
"type": "merge",
"parts": [{ "fromH1Extract": 2 }, { "fromH1Extract": 3, "demoteFirstH1": true }]
}
}
]
}merlon shard deletes and rewrites the directory of each guide it shards, so commit any shards already there first. That deletion comes before a directory source is copied, so with the guide's own directory as path, the guide ends up empty and merlon shard still exits 0. It writes a guide's shards to the directory named after the guide under the docs root and ignores guides[].path, so for a guide that sets path, move the shards there before you compile. It also writes compile-order.txt at the docs root, a list of compileOrder that compile doesn't read, so you can delete it. It runs @kayvan/markdown-tree-parser through npx --yes, which downloads the package on the first run unless the npx cache already holds it. Then run:
merlon shard
merlon compile
merlon checkGuide manifests and compile order
There is no separate manifest sync step, so rerun merlon compile and merlon check after a manifest change. Manifest compile order says how link order in the manifest sets compile order and when to set compile.sectionsHeading.
Shared glossary
A glossary directory can feed several guides without its own entry in compileOrder. Set compile.scopeRoot on each guide that should include glossary terms. The value is a directory relative to the docs root:
{
"name": "developer",
"compile": { "scopeRoot": "glossary" }
}Compile follows .md links from that guide's shards into the glossary tree and stitches each linked term shard into the output. Link ../glossary/index.md from the guide manifest to publish the full glossary table of contents. A lean guide can skip that link and link individual terms. Compile also follows links from term to term. The output contains the linked terms plus every term reachable from them.
A large glossary can move groups of term links into sub-index files that index.md links. The scopeRoot walk follows those links too.
To publish the glossary as its own file, add glossary to compileOrder and set compile.outputFile. That guide's index.md must link every term shard in the directory directly, because the orphan check reports a term that only a sub-index links. The term shards then belong to the glossary guide. Guides that keep compile.scopeRoot: glossary still stitch the terms they link, but their term links point at the glossary's output file instead of the copy in their own output.
Commands reference
Global options
Every command accepts:
| Option | Default | Purpose |
| ------------------------- | -------------------- | -------------------------------------------------------------------------------- |
| -c, --config <path> | merlon.config.json | Config file path, resolved from the invocation directory (not --docs-root) |
| --docs-root <path> | current directory | Docs root — one subdirectory per guide shard tree |
| --warn-broken-links | off | Report broken internal links but exit 0 (overrides lint.links.severity) |
| --backup | off | Move existing output files to the cache before overwriting them |
| --backup-dir <path> | from config | Backup directory, relative to outputDir or absolute |
| --backup-ext <ext> | from config | Suffix for backup file names |
| --diagnostics-dir <dir> | from config | Write split errors.txt and warnings.txt diagnostic files into <dir> |
| --errors-file <path> | from config | Write error-severity diagnostics to <path> |
| --warnings-file <path> | from config | Write warning-severity diagnostics to <path> |
Repo-root npm scripts pass both --config and --docs-root, as --config vs --docs-root explains.
Daily workflow
# Compile every guide from its shards (link order from each guide's manifest, index.md by default)
merlon compile
# Run the full validation gate
merlon checkmerlon compile and merlon check exit 1 when broken internal links are found (default). Use --warn-broken-links to surface link-warn: diagnostics without failing CI. See Link validation.
When a continuing stage of merlon check fails, the run ends with a stderr failure summary of the failed steps and how to fix each one, and any non-fatal warnings are summarized in a merlon check warnings block right above it. A CI log or coding agent then sees both warnings and why the run failed at the tail of the output. Check gate lists the stages in order and says which of them stop the run.
Command summary
| Command | When you need it |
| ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| merlon compile | Regenerate compiled outputs and refs.json under outputDir (exits 1 on broken links by default) |
| merlon check | Run the full validation gate (exits 1 when any stage fails) |
| merlon review | Report documentation sprawl signals across guide shards (report-only; --strict to fail) |
| merlon shard | Split a source document into shards (requires top-level source and a source on each guide; see Consumer migration) |
| merlon refs-gen, merlon refs-check, merlon refs-list | Generate, verify or list the refs registry, as Refs subcommands describes |
| merlon lint | markdownlint-cli2 on shards and compiled output (peer, if installed) |
| merlon prose | Vale prose lint (peer, if installed) |
| merlon links | markdown-link-check on compiled output (peer, if installed) |
| merlon fix | Prettier + markdownlint --fix; needs a markdownlint-cli2 config with globs and always exits 0 (Optional linters) |
Sprawl review
merlon review reads every shard compile reads for the guides in compileOrder, including nested shards and each guide manifest (index.md by default), and reports signals that a shard or index needs a human or agent to look at it. It never writes files and skips paths matched by scan.ignore. The signals point at idea mitosis candidates; deciding whether to split, merge, or regroup stays with the reviewer (see Shard single responsibility and idea mitosis).
merlon review --config docs/merlon.config.json --docs-root docs
merlon review --config docs/merlon.config.json --docs-root docs --json
merlon review --config docs/merlon.config.json --docs-root docs --guide client-cli| Signal | Fires when | Fix |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| index-size | One group of an index lists more than review.maxIndexEntries shard links. A group is the links under one ## or deeper heading, or the links before any such heading | Group entries under headings named for the reader's task |
| long-shard | A shard holds more than review.maxShardWords prose words | Check whether it serves two audiences or jobs; split it if so (idea mitosis) |
| duplicate-paragraph | The same paragraph of at least review.minDuplicateWords words appears in two or more shards | Keep the paragraph in the shard that owns the rule and link to it from the others |
| similar-titles | Two shards in one guide have the same first # heading | Merge the shards, or retitle them so each title names its one job |
Prose words exclude fenced code, front matter, HTML comments, and link targets. Table cell text and headings count as prose. Paragraphs and titles compare after folding case and whitespace and dropping emphasis markers and link targets; titles also drop punctuation. Each list item is its own paragraph.
Text output groups findings by signal and lists docs-root-relative paths. --json prints an array of { signal, severity, files, detail, fix } objects, where severity is always "warning". A duplicate paragraph's detail names every path:line location.
| Option | Effect |
| ---------------- | ------------------------------------------------------------------------------------------- |
| --json | Print findings as a JSON array |
| --strict | Exit 1 when there is at least one finding |
| --guide <name> | Review one guide from compileOrder; keep findings that involve at least one of its shards |
| --no-compile | Review the config's sources in any format, with file and line on each finding |
With --guide, a duplicate paragraph is reported when any copy sits in that guide, so duplication across guides still shows up. The shard count covers that guide only. An unknown guide name exits 1 and lists the guide names.
--no-compile reads the files that config sources lists, in any format, instead of the guides in compileOrder, and adds a locations list of { file, line } to each finding. merlon check --no-compile is its gate counterpart. Both are for a tree another tool builds, as Non-Markdown sources describes.
Without --strict, merlon review exits 0. Thresholds live under review in config, as Review thresholds shows.
Refs subcommands
| Command | Purpose |
| ------------------- | -------------------------------------------------------------------------------------------------------------- |
| merlon refs-gen | Generate refs.json from compiled output |
| merlon refs-check | Verify refs.json matches compiled output |
| merlon refs-list | List each compiled output's heading slugs and file (--format json or table; run it after merlon compile) |
Cross-links and refs shows where merlon refs-list fits after compile and check, and Refs explains what refs are for.
Config reference
This page is the lookup material for merlon.config.json. It gives the feature keys' defaults and the page that documents each key, then the review thresholds, the schema-only fields and the JSON Schema file. Config essentials covers the minimal config and the paths every command resolves from.
Feature settings
Each feature's spec defines its config keys and what they do. This table gives their defaults, and Config key map links each spec.
| Key | Default |
| -------------------------- | ----------------- |
| compile.links.markBroken | true |
| lint.links.enabled | true |
| lint.links.severity | "error" |
| lint.links.config | none |
| lint.links.target | none |
| lint.codeExtensions | [] |
| lint.dataExtensions | [] |
| lint.paths.severity | "off" |
| lint.paths.searchRoots | [] |
| lint.paths.generated | [] |
| lint.paths.vocabulary | [] |
| backup.enabled | false |
| backup.dir | .caches/backups |
| backup.ext | "" |
| diagnostics.splitFiles | false |
| diagnostics.dir | none |
| diagnostics.errorsFile | none |
| diagnostics.warningsFile | none |
Config key map
This table links the page that documents each key:
| Key | Documented in |
| ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| compileOrder, guides[].name, guides[].path, outputDir, outputFile, refs.registryFile, compile.outputFile | Minimal config and Path layout |
| compile.scopeRoot | Shared glossary |
| review.* | Review thresholds on this page |
| sources, roots, manifestHook, sphinx.*, man.quiet | Non-Markdown sources |
| configVersion, standardVersion, protocolVersion | Minimal config |
| refs.slugAlgorithm | Schema-only fields on this page |
| source, guides[].source, guides[].splitLevel | Consumer migration |
| compile.preambleSection | Project layout |
| banner, sourceTags, compile.includeBanner, compile.sourceTags | Source tags and banner |
| compile.manifest, compile.sectionsHeading | Manifest compile order |
| compile.title | Compile API |
| compile.hooks, compile.hooksConfig | Default compile hooks, and the core Compile hooks index for the hook pipeline |
| compile.stripAnchors | stripAnchors |
| compile.crossGuideLinks | Cross-guide link rewriting |
| compile.links.*, lint.links.enabled, lint.links.severity, lint.codeExtensions, lint.dataExtensions | Built-in link validation |
| lint.paths.* | Path resolution in prose |
| lint.links.config, lint.links.target, lint.markdownlint.*, vale.* | Optional linters |
| scan.* | Documentation coverage scan |
| standaloneGuides | Coverage in check |
| backup.* and the --backup flags | Compile output backup |
| diagnostics.* and --diagnostics-dir, --errors-file, --warnings-file | Check gate and Commands reference |
Review thresholds
merlon review reads optional thresholds from a top-level review object. Each value is a positive integer, and omitted keys keep their defaults.
{
"review": {
"maxIndexEntries": 12,
"maxShardWords": 2500,
"minDuplicateWords": 25
}
}| Field | Default | Role |
| -------------------------- | ------- | ------------------------------------------------------------------------------------- |
| review.maxIndexEntries | 12 | Most shard links one index group lists before index-size fires |
| review.maxShardWords | 2500 | Most prose words one shard holds before long-shard fires |
| review.minDuplicateWords | 25 | Fewest words a paragraph needs before duplicate-paragraph compares it across shards |
| review.guides | none | Per-guide overrides of the three keys above, keyed by guide name |
merlon review also honors scan.ignore and scan.root, so paths the coverage scan skips stay out of the review. Sprawl review in Commands reference defines each signal.
Schema-only fields
| Field | Notes |
| -------------------- | ------------------------------------------- |
| refs.slugAlgorithm | Informational; only github is implemented |
Full schema and sample config
merlon.config.schema.json, a file in the Merlon Docs repository that the npm packages leave out, is the JSON Schema for every key. The sample guides' config is a longer example. Its paths resolve only from the Merlon Docs repository root, so copy single keys from it.
Coverage in check
merlon check reports markdown files that no guide accounts for, so nothing drifts out of your documentation set unnoticed. By default the report is non-fatal. Set scan.strict: true when CI should fail on gaps.
What it reports
- Uncaptured: files under the scan root that no guide,
compile.scopeRoot, orstandaloneGuides[]entry covers (uncaptured: <path>). - Missing standalone:
standaloneGuides[]entries that match no file on disk (missing-standalone: <path>). An entry whose path is a symlink is reported here too, as Check surface explains. - Summary: when gaps exist, a one-line
coverage:count.
merlon check --config docs/merlon.config.json --docs-root docsThe full captured / standalone inventory lives in core (computeCoverage); use that API when you need a machine-readable result. For the capability contract, see Documentation coverage scan.
Registering standalone files
When a file is intentionally standalone — a hand-authored README or a top-level policy file — list it under standaloneGuides[] so the scan treats it as captured:
{
"standaloneGuides": ["packages/*/README.md", "SECURITY.md"],
"scan": {
"ignore": ["legacy"],
"strict": true
}
}standaloneGuides accepts file paths or globs. What the scan skips lists the paths the scan leaves out and the scan.* keys that change them. Standalone guide behavior says what compile, link validation and the linters do with a registered file, and what a broad glob matches. Don't list a compiled guide's output, such as a generated README.md, because compiled guides are already captured.
Compile and the refs registry
merlon compile writes the refs registry to refs.registryFile, which resolves by the rule in Path layout. A guide's compile.outputFile doesn't move the registry. merlon refs-list reads it right after compile, with no merlon refs-gen run first. Refs registry path is the spec and has an example. Cross-links and refs shows when to run each command while you write cross-links.
Registry contents
The registry lists every file compile writes, each slugged on its own. Its outputs array has an entry for each compiled guide in compileOrder, publish outputs included, then one for the monolith when compile writes it. Each entry has these fields:
| Field | Holds |
| ----------- | --------------------------------------------------------------------- |
| file | The output's path relative to the docs root, with / separators |
| guideName | The guide whose compiled guide this is; the monolith's entry has none |
| headings | The output's headings, each with its slug and its line in that file |
| slugs | The semantic key of each slug |
Each output numbers its headings without the others. So when two guides in the monolith both have a Setup heading, each compiled guide lists setup, and the monolith lists setup and setup-1. A heading's line counts the banner, so it is a line of the file as compile writes it.
The top-level headings and slugs hold the headings of one text. That text is the monolith when the config sets top-level outputFile, and otherwise every compiled guide joined in compileOrder, without banners. So a publish output's headings reach the top level only in a config without a monolith. Read outputs to find the slugs of one file.
merlon refs-list prints the headings of every entry in outputs, each with its file. With --format table, it prints one tab-separated line for each heading, which starts with the file and ends with the heading's slug and title. A registry without outputs, such as one that genRefsFromCompiled writes from one text, has no files to give. merlon refs-list then prints the top-level headings, and on stderr it gives the registry's path and says to run merlon refs-gen.
Cross-links and refs
When writing `[link text](#anchor)` in a shard, the fragment must match the heading slug in compiled output. Refs keep those cross-links checkable after stitch.
merlon compile --config docs/merlon.config.json --docs-root docs
merlon check --config docs/merlon.config.json --docs-root docs
merlon refs-list --config docs/merlon.config.json --docs-root docsmerlon check fails on dead # fragments and bad paths. merlon refs-list lists the heading slugs of each compiled output, with the output's file, from the refs registry that merlon compile writes. When merlon check reports a dead anchor on a link into a compiled output, look up that file's slugs with merlon refs-list --format table. A #fragment has to match a slug of the file the link points at. For a bare #fragment in a shard, that is each output that stitches the shard. Compile stitches a guide's shard into the guide's compiled guide and, for a guide in the monolith, into the monolith too, where the same heading can take another slug, such as setup-1 for setup. A bare #fragment may also point at the id of a section in that output, such as a FIND-* finding id. merlon refs-list doesn't print those ids. Compile doesn't write its own output for a standalone guide, so its headings are in the registry only when a guide stitches the file through its manifest or a compile.scopeRoot walk, as Standalone guide behavior says.
Heading slugs (GitHub rules)
Authoring rules (CLI consumers):
- Prefer unique subheadings. A repeated title gets a
-1or-2suffix on its slug, the way GitHub numbers duplicates. - Validate with
merlon check— do not guess anchors from shard-only titles. - Link a heading by the slug of its text. GFM scope sets that contract and says not to write an explicit
{#id}after a heading.
Slug algorithm, examples, and programmatic APIs: Core — heading slugs.
Optional linters
These commands use tools installed in your repo (not bundled with Merlon Docs):
| Command | Peer tool | Purpose |
| -------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| merlon lint | markdownlint-cli2 | Lint shards and compiled output (GFM / Markdown structure) |
| merlon prose | vale (install separately) | Prose style lint with the Vale styles your .vale.ini names |
| merlon links | markdown-link-check | Optional HTTP URL checks (peer; not built-in internal link validation) |
| merlon fix | prettier, markdownlint-cli2 | Run prettier --write . then markdownlint-cli2 --fix (no config paths) |
| merlon check | markdownlint-cli2, vale, markdown-link-check | The check gate's lint, prose and URL stages, each run when its peer is installed and configured |
merlon fix does not bundle formatters. Install Prettier and markdownlint-cli2 in your repo first (node_modules/.bin or PATH). Each step is skipped with an info message if the peer is missing. Merlon Docs passes markdownlint-cli2 no file paths. Its fix step needs a .markdownlint-cli2.jsonc (or another markdownlint-cli2 config file) in the docs root that lists globs. Without one, markdownlint-cli2 prints its usage text and fixes nothing. merlon fix exits 0 whatever either tool returns, so read its output to see whether both steps ran.
merlon lint --require-lint # fail if markdownlint-cli2 is missing
merlon prose --require-vale # fail if Vale is missing
merlon check --require-lint --require-vale # CI gate with markdownlint + Vale
merlon check --skip-vale # structural checks onlymerlon check runs built-in internal link validation by default (lint.links.enabled). Peer markdown-link-check runs only when lint.links.config is set and the peer is installed. merlon links checks the file that lint.links.target names, or else the monolith that top-level outputFile names, and exits 1 when the config sets neither. A relative lint.links.target is read from the docs root, not from outputDir, so to check a monolith under the default outputDir, write _build/guides.md. When the peer is missing, it prints an info line and exits 0.
Install npm peers with:
npm install -D prettier markdownlint-cli2 @merlon-docs/merlon-docs-presetsInstall Vale separately so vale is on your PATH, using one of the methods in Vale installation. After adding a .vale.ini, run vale sync in that directory. Merlon Docs looks for vale in node_modules/.bin, from the docs root up, before it looks on PATH. merlon prose and merlon check run Vale in the docs root and pass it the config file that vale.config names, .vale.ini by default.
lint.markdownlint.shardsConfig names the markdownlint-cli2 config file for the shard pass, and lint.markdownlint.compiledConfig names the one for the compiled pass. merlon lint and merlon check run each pass only when its key is set, and Check gate stages lists both passes in the check. A relative path is read from the docs root, so a docs/ root next to node_modules uses ../node_modules/@merlon-docs/merlon-docs-presets/..., as step 1 of Quick start shows.
A locale pack is Merlon Docs’ compile-time wording, not a Vale style. The MerlonDocs Vale style in @merlon-docs/merlon-docs-presets (vale/MerlonDocs/) holds the en-US prose cues. Its rules flag a numbered heading mention with no link, MerlonDocs.DatedClaim flags as of or until before an ISO date, and the warning-level MerlonDocs.UnformattedCode flags a code-shaped name, such as field_init or set_field_fore(), outside backticks. See Locale and language boundary.
Vale alert level
merlon prose passes no alert level to Vale, so the MinAlertLevel in your .vale.ini sets what it shows. merlon prose --strict and merlon check pass --minAlertLevel from vale.strictMinAlertLevel, which defaults to error. To show warnings in those runs too:
{
"vale": {
"strictMinAlertLevel": "warning"
}
}Of Vale's alerts, only error-level ones fail merlon prose or merlon check, so a lower vale.strictMinAlertLevel adds warnings or suggestions to the output and leaves the exit code as it was. A Vale runtime error, such as a missing style, also fails both commands. To make a rule fail the check, set its level to error in .vale.ini. A rule set to warning, such as MerlonDocs.DatedClaim = warning, no longer fails merlon check, and merlon prose still shows it when the .vale.ini MinAlertLevel is warning or lower.
In-scope guide fileset
Merlon Docs knows the full fileset it manages. The guides in compileOrder resolve via guides[].path or {docsRoot}/{name}/, and standaloneGuides registers the standalone guides. Shard markdownlint lints the Markdown files in the guide directories. Vale prose lints the guide directories and the standalone guides, because a file that never compiles still reaches readers as written. Both linters skip markdown that the config does not name, such as legacy flat .md files or unregistered sibling folders under --docs-root.
| Command | Default scope | Out of scope (skipped) |
| -------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------------- |
| Shard markdownlint (merlon lint, merlon check) | Markdown in compileOrder guide directories | Legacy flat docs, unrelated subdirs under --docs-root |
| Vale prose (merlon prose, merlon check) | Guide directories plus standaloneGuides files | Same |
| Compiled markdownlint | Compiled outputs listed in compiledConfig globs | Shard trees (covered by the shard pass) |
Optional overrides replace the guide directories with the paths you list, so scope never reaches past what the config names:
| Config field | Purpose |
| ------------------------------- | ----------------------------------------------------------------------------------------------------- |
| lint.markdownlint.shardsGlobs | Shard markdownlint paths relative to --docs-root (default: the Markdown in compileOrder guide dirs) |
| vale.scanGlobs | Vale prose paths relative to --docs-root in place of the guide dirs; standalone guides stay in |
Both markdownlint passes run with the docs root as their cwd. For each guide directory, Merlon Docs passes the shard pass a glob for the .md and .markdown files in it, such as features/**/*.{md,markdown}, so an image or text file beside the shards stays out of the shard pass. For a guide under the docs root, the glob is relative to the docs root and leaves the checkout path out. A relative or absolute --docs-root then lints the same shards, even under a directory whose name has glob characters, such as repo (copy). A guide outside the docs root gets an absolute glob. With it, the shard preset's exclusions still apply to the guide, and markdownlint-cli2 still finds the guide under a symlinked docs root. Merlon Docs escapes the glob characters and quotes in each path it puts in a glob.
A lint.markdownlint.shardsGlobs entry goes to markdownlint-cli2 as written, and markdownlint-cli2 resolves it against the docs root. The exceptions are ., which Merlon Docs passes as **, and an entry that starts with ../, negated or not, which Merlon Docs makes absolute for the same reasons as a guide outside the docs root. Given . as its only path, markdownlint-cli2 would lint the Markdown files at the top of the docs root and nothing below them. It lints every file under any other directory entry, and an entry that starts with ! or # excludes the files it matches. The compiled pass gets only --config from Merlon Docs, and markdownlint-cli2 resolves the globs in compiledConfig against its cwd, the docs root.
Vale lints each standalone guide once, even when it is inside a scanned directory or two standaloneGuides entries match it. The exception is a guide that a scanned directory
