Machine-readable CLI

AI and agents•8 min read|
|

Every command an agent needs in the authoring loop can print JSON, never prompts, and uses its exit code to say whether anything failed. This page shows real output.

Command Machine-readable form Exit code 1 when
docslit components [tag] --json the tag is unknown
docslit schema [config\|frontmatter] always JSON the kind is unknown
docslit new <id> --json the page exists or the id is missing
docslit validate --format json there are errors, or warnings with --strict
docslit lint --format json there are errors, or warnings with --strict
docslit agents init --json the project has no docslit.json or a tool name is unknown

With --json or --format json, stdout holds only the JSON document. Errors from components, new and agents init also arrive as JSON: { "error": "..." }.

components

List every built-in component, or describe one. This is the source of truth for tags, attributes, allowed values, nesting and examples. It is generated from the same manifest the MCP server uses.

docslit components # grouped list for people docslit components wc-callout # one component, readable docslit components --json # all components as a JSON array docslit components wc-callout --json { "tag": "wc-callout", "category": "callouts", "description": "Highlighted block for tips, warnings, notes and other asides. Body supports full Markdown.", "attributes": [ { "name": "type", "type": "string", "description": "Visual style of the callout.", "values": ["info", "tip", "warning", "error", "success", "note"], "default": "info" }, { "name": "title", "type": "string", "description": "Heading shown at the top of the callout. Omit for body-only." } ], "content": "markdown", "example": "<wc-callout type=\"tip\" title=\"...\">...</wc-callout>" }

The output is shortened here: a real entry also has a theme attribute and a full example. Each entry has these fields:

The element name, for example wc-tabs. One of callouts, layout, navigation, code, media, data, content, utility or authoring. Each attribute has name, type, description, and where they apply required, default and values (the allowed values). What goes between the tags: markdown, text, code, children, none and so on. Tags this component must sit inside, such as wc-steps for wc-step. Tags this component accepts as children. A working snippet to copy.

schema

Print the JSON Schema for docslit.json or for page frontmatter:

docslit schema # docslit.json (same as: docslit schema config) docslit schema frontmatter

New projects get a $schema key in docslit.json that points at the published schema, so editors validate and autocomplete the file:

{ "$schema": "https://unpkg.com/docslit/schema/docslit.schema.json", "name": "My Docs", "sidebar": [] }

The schema allows unknown top-level keys so a newer CLI does not break an older editor. The frontmatter schema lists every key validate accepts. See Frontmatter.

new

Create a page and register it in the sidebar. It never asks questions:

docslit new guides/webhooks --title "Webhooks" \ --description "How to receive and verify webhook events." \ --group "Guides" --json { "id": "guides/webhooks", "file": "docs/guides/webhooks.md", "sidebarUpdated": true, "group": "Guides" }

With an autogenerated sidebar the result has "sidebarUpdated": false and "autogenerated": true, because the page appears on its own. Failures print { "error": "Page already exists: docs/guides/webhooks.md" } and exit with code 1.

--position <n> writes sidebar_position: n into the frontmatter, which orders an autogenerated sidebar. For an explicit sidebar it also inserts the page at that 1-based position in the group's pages array in docslit.json. A position past the end appends the page. --group finds a group at any nesting depth, including sub-groups.

validate

validate answers "is it broken?". Run it from the project root, or pass a directory.

docslit validate --format json { "ok": false, "summary": { "errors": 3, "warnings": 3, "infos": 1, "pages": 2 }, "issues": [ { "level": "error", "code": "broken-link", "message": "Broken internal link → \"webhooks\" (no page with slug \"webhooks\")", "file": "docs/setup.md", "line": 7, "fix": "Fix the link target \"webhooks\" or create the missing page and add it to the sidebar" }, { "level": "error", "code": "code-import-missing-file", "message": "Code import file not found: src/server.js", "file": "docs/setup.md", "line": 11, "fix": "Create the file, or fix the file= path (paths are relative to the project root, next to docslit.json)" } ] }

Two issues are shown from a sample run that reported more. ok is false when there is at least one error, or any warning in --strict mode. Each issue has:

error, warning or info. A stable, kebab-case identifier. Match on this, not on the message text. A human-readable description. Path relative to the project root, or null for project-wide issues. The line in the file, counted from the first line of the file including frontmatter. Omitted when the issue has no line. A suggested fix. Present when the validator knows one.

Other formats are --format pretty (the default) and --format github, which prints Actions annotations. In json and github modes stdout holds only the report, with no progress lines. An unknown --format value, or an unknown option, is rejected with a message on stderr and exit code 1. See Validation.

Issue codes

Code Meaning
config-missing No docslit.json
config-invalid-json docslit.json is not valid JSON
config-missing-sidebar No sidebar array
sidebar-group-unnamed A sidebar group has no group name
sidebar-group-no-pages A group has no pages array
sidebar-invalid-page A page entry is not a string or page object
sidebar-slug-unusual A slug has unusual characters
sidebar-duplicate-slug A page appears in the sidebar twice
sidebar-missing-file A sidebar slug has no matching file
orphan-page A page file is not in any sidebar group
docs-dir-missing No docs/ directory
directory-not-found The directory you passed does not exist
announcement-invalid The announcement block is invalid
theme-unknown theme names no theme or palette. The fix suggests the nearest one
theme-unknown-theme, theme-unknown-palette, theme-unknown-preset A theme, palette or preset named inside a theme object does not exist
theme-name-typo A theme object's name looks like a mistyped theme id (warning)
theme-appearance-invalid, theme-strict-invalid, theme-radius-invalid appearance, strict or radius has an invalid value
theme-low-contrast An explicit theme color fails WCAG AA contrast (warning)
theme-invalid-value A theme value is not a string
theme-invalid-type theme has the wrong type
theme-file-missing The theme file was not found
theme-file-invalid The theme file has invalid contents
openapi-spec-missing The OpenAPI spec file was not found
openapi-spec-unset openapi is set without a spec
openapi-overlay-missing The overlay file was not found
openapi-invalid-ref A wc-endpoint ref does not exist in the spec
openapi-undocumented-endpoint An operation in the spec has no page
openapi-validation-failed The spec could not be checked
Code Meaning
tabs-invalid tabs is not a usable array (error)
tab-duplicate-name, tab-duplicate-page, tab-empty Two tabs share a name, a page is listed in two tabs, or a tab has no pages
tab-landing-missing, tab-path-missing A tab's landing page or path folder does not exist
tab-href-with-pages A link tab also has a sidebar
tabs-sidebar-ignored A top-level sidebar is ignored because tabs is set
anchor-invalid An anchor is missing its label or href
navbar-link-invalid A navbar entry cannot be used, for example a dropdown with no links
layout-invalid A layout setting has an invalid length or value
logo-invalid A logo object has no light, dark or text
contextual-option-invalid An unknown or incomplete contextual menu option
frontmatter-invalid-layout, frontmatter-invalid-toc-depth, frontmatter-invalid-flag, frontmatter-invalid-text A page layout name, toc_depth, boolean switch or text key has an invalid value
frontmatter-unknown-tab The frontmatter tab matches no tab
unknown-icon An icon name exists in neither Lucide nor Font Awesome Free. The suggestion is the nearest name
Code Meaning
frontmatter-parse-error The frontmatter is not valid YAML
frontmatter-missing-title No title
frontmatter-unknown-key A key the schema does not know
frontmatter-invalid-readtime readtime is not a string
frontmatter-invalid-icon icon is not a non-empty string
frontmatter-invalid-redirect redirect is not a string
page-redirect The page redirects elsewhere (info)
broken-link A Markdown link points to a page that does not exist
broken-href An href in a component may point to a missing page
missing-asset An image path does not exist. Markdown images and HTML img tags are each reported once. Bare relative paths such as images/x.png are checked too
unknown-component A wc-* tag that is neither built in nor in components/
component-mapping-unregistered A component mapping points at a missing file
external-link-status An external link returned an error status (--external)
external-link-failed An external link could not be reached (--external)
Code Meaning
include-not-self-closing wc-include must be written <wc-include src="..." />
include-in-reusable A reusable file contains a wc-include
include-missing-src wc-include has no src
include-invalid-path The include path is invalid
include-outside-reusables The include resolves outside docs/_reusables
include-not-markdown The include target is not a .md file
include-target-missing The include target does not exist
include-nested A nested include was found
include-reusable-frontmatter A reusable file has frontmatter, which is ignored
var-invalid-name A wc-var declaration has an invalid name
var-invalid-placeholder A {{...}} placeholder has an invalid name
var-undefined A {{NAME}} placeholder has no definition. A build-time value (config, frontmatter or a self-closing wc-var) or a runtime <wc-var name="NAME" default="..."> on the page both count

These come from the same checker as the check_markup MCP tool. Unclosed, stray and malformed tags are errors because they break rendering. Everything else is a warning.

Code Meaning
unclosed-tag A component tag is never closed (error)
unexpected-closing-tag A closing tag has no matching opening tag (error)
malformed-tag A tag is missing its > or has an unterminated quote (error)
unknown-attribute The component has no such attribute. fix suggests the nearest valid one
invalid-attribute-value The value is not one of the allowed values, or is not a number
missing-required-attribute A required attribute is missing
invalid-parent The component is outside the parent it needs, such as wc-step outside wc-steps
invalid-child The component holds a child it should not, such as wc-callout directly in wc-steps
self-closing-syntax <wc-x /> on a component that must be written with a closing tag. <wc-var name="X" value="..." /> and <wc-include ... /> are valid

Fenced code, inline code, HTML comments and frontmatter are ignored. Custom components from components/ are accepted.

Code Meaning
math-invalid KaTeX cannot parse a formula (warning). The message carries the KaTeX error and line points at the formula. The build prints the same warning
code-import-missing-file The file= target does not exist or is not a file
code-import-missing-region The region= marker pair was not found in the file
code-import-invalid-lines lines= is malformed or outside the file
code-import-conflicting-options lines= and region= were both given
code-import-outside-project The path leaves the project root or targets .git, node_modules or .env*
code-import-invalid-path file= is empty or invalid
Code Meaning
other An issue without a dedicated code. Read the message
missing-asset checks Markdown images and HTML img tags. It does not check wc-image or wc-download paths. Attribute names and values are checked on wc-* components, but only against the built-in manifest, so check an attribute you are unsure of with docslit components <tag> --json.

lint

lint answers "is it good?". It looks at quality: descriptions, headings, code languages, alt text, link text and page length. See Lint for every rule and how to configure it.

docslit lint --format json { "ok": true, "summary": { "errors": 0, "warnings": 3, "infos": 2, "pages": 2 }, "issues": [ { "level": "warning", "code": "missing-description", "file": "docs/setup.md", "line": 2, "message": "Page has no description in its frontmatter", "fix": "Add a one-sentence `description:` (30-200 characters) to the frontmatter; it feeds search, SEO and llms.txt" }, { "level": "info", "code": "page-too-short", "file": "docs/setup.md", "line": 5, "message": "Page has only ~11 words (min 30)", "fix": "Add the missing content, or merge this page into a related one" } ] }

The output has the same shape as validate. No lint rule is an error by default, so lint exits with 0 unless you pass --strict or raise a rule to error in docslit.json.

theme

docslit theme list --json prints { themes, palettes, radius, appearance, current, config }, and docslit theme tokens --json prints every design token with its group, description, default and current value. An agent can pick a look with docslit theme use <theme> [--palette <p>], which edits docslit.json in place. See Themes and Design tokens.

docslit theme list --json docslit theme tokens --json --theme folio

import

docslit import <source> --json prints the migration report as one JSON document: a summary, the components converted, the config mapped and unmapped, items that each have a stable code, file, line, action and fix, and the validation result. Add --dry-run to write nothing. See Import reference.

docslit import ./my-docs --dry-run --json

Use it in CI

Run both checks and fail the build on any finding:

- run: npx docslit validate --strict --format github - run: npx docslit lint --strict --format github

An agent can run the same two commands after each edit and loop until both report "ok": true.