feat(docs): emit CLI schema JSON + docs wiring for docs-builder#264
Draft
Mpdreamz wants to merge 1 commit into
Draft
feat(docs): emit CLI schema JSON + docs wiring for docs-builder#264Mpdreamz wants to merge 1 commit into
Mpdreamz wants to merge 1 commit into
Conversation
Adds a `cli-schema` command and `npm run build:schema` script that walk the full Commander command tree and emit the CLI structure as a checked-in JSON artifact (docs/cli/schema.json) conforming to the argh CLI schema format. Key design choices: - `src/namespaces.ts` is the single source of truth for top-level namespace registration; adding a new namespace only requires one edit - `src/factory.ts` attaches `_commandConfig` (typed options + Zod schema + schemaArgs) to every leaf command so the emitter can recover full type/validation metadata without re-parsing Commander strings - ES API schemas are loaded eagerly only for `cli-schema`; all other invocations retain the existing lazy-load optimisation - Per-parameter fields emitted: `type`, `defaultValue`, `repeatable`, `separator`, `enumValues` (from Zod), `elementType`, `hidden` - Enum choices and array element types are extracted via the same `z.toJSONSchema()` call already used by `--help --json` Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2c41cdc to
f05dc83
Compare
❌MegaLinter analysis: Error
Detailed Issues❌ TYPESCRIPT / eslint - 1 errorSee detailed reports in MegaLinter artifacts MegaLinter is graciously provided by OX Security |
JoshMock
reviewed
May 1, 2026
| load: (opts?: LoadOptions) => Promise<OpaqueCommandHandle> | ||
| } | ||
|
|
||
| export const NAMESPACES: NamespaceEntry[] = [ |
Comment on lines
+104
to
+108
| if (firstArg === 'cli-schema') { | ||
| const { registerCliSchemaCommand } = await import('./cli-schema.ts') | ||
| program.addCommand(await registerCliSchemaCommand(VERSION, program)) | ||
| } else { | ||
| program.addCommand(defineGroup({ name: 'config', description: 'Author and maintain the elastic config file' })) | ||
| program.addCommand(defineGroup({ name: 'cli-schema', description: 'Emit the CLI structure as argh-schema JSON' })) |
Member
There was a problem hiding this comment.
Is there a reason why this can't also live in namespaces.ts?
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes elastic/agentic-interface-program#54 · Supersedes #245
What is this?
Adds
elastic cli-schema— a native command that emits the full CLI structure (namespaces, commands, flags, types, defaults, enum choices) as a single checked-in JSON file:docs/cli/schema.json.That file is the only thing docs-builder needs to generate a complete, navigable CLI reference. No docs generator to maintain in this repo.
cursorful-video-1777577780994.mp4
Why this replaces #245
PR #245 added a docs generator inside this repo — a TypeScript walker that produces Markdown and per-command JSON schema files. This PR takes a different approach:
docs/cli/schema.jsonis the single artifact. docs-builder turns it into a full reference site with no further involvement from this repo.npm run build:schemaand diffs against the committed file. Add a command, rename a flag, change a description — CI fails until the schema is regenerated. The docs can never silently lag behind the CLI.docs-buildersupports injecting more context into generated docs for namespaces / commands.docs-builderwill know these are CLI docs, helpful for LLM output (the .md variant we always emit for each docs) and search.What's in this PR
elastic cli-schemaA new top-level command, consistent with the existing lazy-load pattern:
Prints the full CLI structure as JSON to stdout.
npm run build:schemapipes it todocs/cli/schema.json.Loads all namespaces eagerly and walks the Commander tree. For each leaf command it extracts:
typeOptionDefinition.type/SchemaArgDefinition.typedefaultValuerepeatable/separatoracceptsArrayForm(comma-split array fields)enumValuesz.toJSONSchema()— same call used by--help --jsonelementTypealiases.aliases()src/namespaces.ts— single source of truthAll top-level namespace registrations live here. Both
cli.ts(lazy stubs) andcli-schema(eager load-all) consume the same list. Adding a new namespace requires editing one file.docs/docset.ymltells docs-builder where the schema lives and which hand-written pages appear alongside the generated reference:Hand-written pages under
docs/cli/can inject additional context into generated namespace and command pages without touching the schema. For example,docs/cli/index.mdoverrides the root CLI page body, and a file nameddocs/cli/stack/es/search.mdwould inject content into the generatedelastic stack es searchcommand page — the schema-driven heading, usage block, and parameter tables still render; the file adds human context on top.Test plan
npm run build:schemaregeneratesdocs/cli/schema.jsoncleanlyelastic cli-schema | jq '.namespaces[].segment'→stack,cloud,docs,configexpand-wildcards,refresh)npm testpasses (1017/1017)docs/as a CLI reference (prerequisite: feat(cli-docs): auto-generate CLI reference from schema JSON docs-builder#3221)Follow-up: CI schema-freshness check
Add to CI so the committed schema can never silently lag behind the CLI: