Skip to content

fix(cli): generate manifest examples and response types from the docs - #6585

Merged
josephfarina merged 9 commits into
mainfrom
cli-spec/runtime/manifest-from-docs
Oct 5, 2026
Merged

josephfarina merged 9 commits into
mainfrom
cli-spec/runtime/manifest-from-docs

Conversation

@josephfarina

@josephfarina josephfarina commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

User impact

astryx manifest --json (and the manifest embedded in bare astryx --json) is how an agent learns the CLI without scraping --help. Two of its per-command facts were written by hand in clients/cli/lib/manifest.mjs and had drifted from the docs every command is built from:

  • Examples. A hand-kept EXAMPLES map disagreed with the CommandDoc examples for 25 of the 34 documented commands. component showed astryx component and astryx component XDSButton where its CommandDoc shows astryx component --list; blog, layout, theme, integration, theme palette, and doctor integration showed none at all.
  • Response types. A hand-kept RESPONSE_TYPES map left out upgrade.registry. astryx --json upgrade --registry emits it (and upgrade()'s FunctionDoc lists it), but the manifest, the response-types doc, and the README response-type table did not, so an agent reading the manifest could not expect it:
$ astryx --json upgrade --registry | jq -r .type
upgrade.registry
$ astryx manifest --json | jq -c '.data.responseTypes.upgrade'
["upgrade.list","upgrade.status","upgrade.run"]

This folds in the upgrade.registry registration: once response types are derived, the manifest lists it by construction, and the response-types doc must name it in the same change, so the two cannot ship as separate branches without editing the same lines.

Problem and solution fit

  • Why does it happen? The manifest took examples and response types from two maps maintained next to it rather than from the CommandDoc and the FunctionDoc it wraps, so a doc edit never reached the manifest and nothing compared them.
  • Why does it harm the task? An agent copies manifest examples as representative invocations and switches on the listed response types; stale examples mislead it and a missing type looks like an undocumented envelope.
  • Why does that matter? The manifest is the CLI's machine-readable contract. It is only trustworthy if it is generated from the same docs as help, which is what the surface record requires.

Expected behavior and authority

docs/architecture/cli-surface.md (current):

INV7 — Every command ships a CommandDoc, and the generated surfaces come from it. Help text, the README command and error-code tables, and the manifest are generated. None of them is written by hand.

docs/specs/AST-017/spec.md (current), DEC-4:

Treat every field in a stable machine-readable CLI response—including nested entry fields—as public schema. Keep its canonical type, contract tests, applicable text output, and complete consumer documentation aligned in the same change.

and FR14: "Commands and options MUST appear in generated help and the machine-readable manifest."

Smallest restoration

  • defineCommand records the CommandDoc and FunctionDoc a command is built from (commandDocsOf(cmd)).
  • buildManifest takes each entry's examples from the CommandDoc (examples[].cli) and its responseTypes from the FunctionDoc's returns. The one remaining hand-kept list, CLI_LAYER_RESPONSE_TYPES, holds the two envelopes no API function returns: manifest (it wraps no API function) and theme.build.batch (built by the theme build command around several themeBuild() receipts). A test fails as soon as a FunctionDoc declares either, so the list only shrinks. manifest is registered by hand in index.mjs, so its CommandDoc is read directly.
  • The flat responseTypes index is built from the described command tree.
  • upgrade.registry gets its response-types entry, which regenerates one README table row. The README's paragraph on how the manifest is built, and the file headers that described the old maps, now say where each fact comes from.

Unchanged: command names, descriptions, arguments, options, json flags, the manifest's shape and types, and every other command's set of response types. Two lists now follow their FunctionDoc's order (docs: docs.detail before docs.index; theme add: theme.add before theme.list), and the flat index's keys follow the command tree; neither order is part of the contract.

Compatibility: responseTypes gains one entry and examples values change; no field is added or removed (AST-017 FR5, contract-restoring).

Evidence

  • Reproduction before the change: the two commands above; the new tests below fail on the base commit (examples for blog first, upgrade.registry missing, and the FunctionDoc order for docs).
  • Result after the change: astryx manifest --json | jq -c '.data.responseTypes.upgrade' prints ["upgrade.list","upgrade.registry","upgrade.status","upgrade.run"], and every manifest examples list equals its CommandDoc's.
  • Representative unchanged path: the drift harness (test/drift/docs-drift.test.mjs) still checks that the response-types doc equals the manifest's set; astryx manifest text output is unchanged.
  • Regression test or other mutation-sensitive proof: clients/cli/lib/manifest.test.mjs loads every CommandDoc under commands/ and every FunctionDoc under api/ from disk and requires the manifest's examples and response types to equal them, requires every FunctionDoc return to be listed, runs upgrade --registry --json and checks its type is listed, and pins the CLI-layer list. Restoring the base manifest.mjs fails 4 of these tests.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

pnpm -F @astryxdesign/cli sync:api-types
pnpm check:cli-structure
pnpm -F @astryxdesign/cli readme:check
pnpm -F @astryxdesign/cli typecheck:json-api
ASTRYX_STRICT_LINT=1 pnpm exec eslint <changed files>
pnpm check:repo
pnpm exec vitest run packages/cli

All pass; the CLI suite is 4303 passed, 5 skipped (base 4298 + 5 new).

Before and after

Ran astryx manifest --json on main at d88274b and on this branch (that commit plus this change), then compared every command:

  • 34 commands before and after. No field other than examples and responseTypes changed.
  • responseTypes: upgrade gains upgrade.registry, the type astryx --json upgrade --registry already emits. docs and theme add list the same types, now in FunctionDoc order. The top-level responseTypes set is unchanged.
  • examples: 26 commands now show exactly their CommandDoc examples, including 8 that showed none before (for example blog, theme, doctor integration).
Full comparison
commands: 34 before, 34 after; examples differ on 26; responseTypes differ on 3; any other field differs on 0
top-level responseTypes equal: False
  added: [] removed: []
RT `docs`: ['docs.list', 'docs.index', 'docs.detail', 'docs.detail.section', 'docs.node'] -> ['docs.list', 'docs.detail', 'docs.index', 'docs.detail.section', 'docs.node']
RT `theme add`: ['theme.list', 'theme.add'] -> ['theme.add', 'theme.list']
RT `upgrade`: ['upgrade.list', 'upgrade.status', 'upgrade.run'] -> ['upgrade.list', 'upgrade.registry', 'upgrade.status', 'upgrade.run']
EX `blog`: None -> ['astryx blog', 'astryx blog introducing-astryx --json']
EX `component`: ['astryx component', 'astryx component XDSButton', 'astryx component XDSButton --props --json'] -> ['astryx component --list', 'astryx component XDSButton --props --json']
EX `discover`: ['astryx discover --json'] -> ['astryx discover --json', 'astryx discover --components', 'astryx discover @acme/ui']
EX `docs`: ['astryx docs', 'astryx docs spacing --json', 'astryx docs theme', 'astryx docs theme quick-start', 'astryx docs cli/integrations --full'] -> ['astryx docs', 'astryx docs theme', 'astryx docs spacing --json', 'astryx docs theme quick-start', 'astryx docs cli', 'astryx docs cli/api/functions/search', 'astryx docs cli/integrations --full']
EX `doctor`: ['astryx doctor', 'astryx doctor --json'] -> ['astryx doctor', 'astryx doctor --json', 'astryx doctor integration validate @acme/widgets', 'astryx doctor integration templates @acme/widgets', 'astryx doctor integration components @acme/widgets', 'astryx doctor integration docs @acme/widgets']
EX `doctor integration`: None -> ['astryx doctor integration validate', 'astryx doctor integration templates', 'astryx doctor integration components', 'astryx doctor integration docs']
EX `gap-report`: ['astryx gap-report --list-categories', "astryx gap-report Button --category docs_gap --reason 'Missing keyboard example'"] -> ['astryx gap-report --list-categories', "astryx gap-report Button --category missing_variant --reason 'Need a compact size'", "astryx gap-report Button --category docs_gap --reason 'Missing keyboard example' --confirm-public"]
EX `hook`: ['astryx hook', 'astryx hook useFocusTrap --json'] -> ['astryx hook --list', 'astryx hook useFocusTrap --json']
EX `init`: ['astryx init', 'astryx init --all --json'] -> ['astryx init', 'astryx init --all', 'astryx init --json']
EX `integration`: None -> ['astryx integration add component AcmeWidget', 'astryx integration pack --check']
EX `integration add`: ['astryx integration add component AcmeWidget', 'astryx integration add doc deploying --dry-run --json'] -> ['astryx integration add component AcmeWidget', 'astryx integration add doc deploying', 'astryx integration add template dashboard', 'astryx integration add template account-card --type block', 'astryx integration add doc acme-getting-started --replaces getting-started', 'astryx integration add doc acme-theming --extends theme', 'astryx integration add doc deploying --parent acme', 'astryx integration add codemod rename-widget --to 1.2.0', "astryx integration add agent-doc 'Run acme verify before finishing.'", 'astryx integration add theme ocean', 'astryx integration add component AcmeWidget --dry-run --json']
EX `integration pack`: ['astryx integration pack --check --json'] -> ['astryx integration pack --check', 'astryx integration pack --check --json']
EX `layout`: None -> ['astryx layout grammar', "astryx layout expand 'V[g6] > C{card-callout}*4' ./src/Page.tsx"]
EX `layout expand`: ["astryx layout expand 'V[g6] > C{card-callout}*4' ./src/Page.tsx"] -> ["astryx layout expand 'V[g6] > C{card-callout}*4' ./src/Page.tsx", 'astryx layout expand --file layout.xlo --name Dashboard']
EX `search`: ['astryx search modal --json', 'astryx search button --type component --json'] -> ['astryx search button', 'astryx search "data table" --type template --json']
EX `swizzle`: ['astryx swizzle XDSButton'] -> ['astryx swizzle --list', 'astryx swizzle XDSButton']
EX `template`: ['astryx template --json', 'astryx template dashboard ./src/app', 'astryx template --cdn'] -> ['astryx template --json', 'astryx --json template --list --package @astryxdesign/core', 'astryx template dashboard ./src/app', 'astryx template shell-side-nav ./src/app --package @astryxdesign/core', 'astryx template --cdn', 'astryx template --cdn public/demo.html']
EX `theme`: None -> ['astryx theme list', 'astryx theme add matcha', 'astryx theme palette generate palette.config.json', 'astryx theme targets']
EX `theme add`: ['astryx theme add matcha', 'astryx theme add matcha ./src/themes/matcha'] -> ['astryx theme add matcha', 'astryx theme add ocean --package @acme/themes']
EX `theme build`: ['astryx theme build ./src/themes/ocean.ts --out ./dist/ocean.css', 'astryx theme build ./src/themes/ocean.ts --check'] -> ['astryx theme build ./src/themes/ocean.ts --out ./dist/ocean.css', 'astryx theme build --family ./themes/ocean.mjs ./themes/ocean-calm.mjs --family-key ocean-family', 'astryx theme build ./src/themes/*.ts', 'astryx theme build ./src/themes/ocean.ts --check', 'astryx theme build ./src/themes/ocean.ts --icons-specifier ./icons.mjs']
EX `theme list`: ['astryx theme list --json'] -> ['astryx theme list --json', 'astryx theme list --package @acme/themes']
EX `theme palette`: None -> ['astryx theme palette generate palette.config.json']
EX `theme palette generate`: ['astryx theme palette generate palette.config.json', 'astryx theme palette generate palette.config.json --out ocean.palette.json'] -> ['astryx theme palette generate themes/ocean/palette.config.json', 'astryx theme palette generate themes/ocean/palette.config.json --out themes/ocean/tokens/ocean.palette.ts', 'astryx theme palette generate themes/ocean/palette.config.json --out themes/ocean/tokens/ocean.palette.ts --preview themes/ocean/tokens/ocean.palette.html']
EX `theme targets`: ['astryx theme targets Switch', 'astryx --json theme targets'] -> ['astryx theme targets', 'astryx theme targets Switch', 'astryx theme targets thumb', 'astryx --json theme targets']
EX `theme template`: ['astryx theme template', 'astryx theme template --json'] -> ['astryx theme template', 'astryx theme template src/themes/starter.ts']
EX `upgrade`: ['astryx upgrade --json'] -> ['astryx upgrade --list --json', 'astryx upgrade --registry --apply', 'astryx upgrade --from 0.1.0 --apply']

Refreshed on main 9143f03

Main merged in again. #6867 added component.batch to the old hand-kept response-type map. Under this PR, the manifest takes response types from each FunctionDoc's returns, and the component FunctionDoc on main already declares component.batch, so the manifest still lists it and no hand-kept entry is needed. The README tables are regenerated, adding this PR's upgrade.registry row, and the hand-written manifest paragraph is kept. On main 9143f03 plus this head: the full CLI node suite (353 files, 5,576 tests, including the manifest drift tests), check:cli-structure, check:changesets, readme:check, both typechecks, cli-api-types-verify, eslint and prettier pass.

Refreshed on main 5bb03cf

#6615 removed the layout entries from the old hand-kept maps in manifest.mjs, and this PR replaces those maps, so they conflicted. The resolution keeps this PR's derivation, which has no layout entries, because the layout docs are gone. component.batch and its astryx component Button Badge Text example still come from the component docs on main. Regenerating the README changed nothing. On main 5bb03cf plus this head: the full CLI node suite (346 files, 5,513 tests, including the manifest drift tests) and every gate listed above pass.

Refreshed on main ebd939b, and one regression fixed

Main merged in again: #6737 and the layout restore (#6887). #6737 added ROOT_RESPONSE_TYPES (help and version), which test/drift/docs-drift.mjs imports. That export stays here as a second hand-kept list, and the response-types enum header now names both lists. upgrade.registry appears once, with #6737's wording.

Regression found and fixed. A diff of astryx manifest --json against main showed that deriving response types from the wrapped FunctionDoc dropped theme.list from theme add. A bare theme add (or --list) answers with themeListAvailable()'s theme.list instead of calling themeAdd(), and the published 0.6.4 manifest lists both. It is now a CLI-layer envelope, like theme.build.batch. New test: a bare theme add --json emits theme.list and the manifest lists it. Removing the entry fails it and the derivation test.

Against the published 0.6.4 manifest, no command loses a response type. Added since then: component.batch, discover.item, integration verify's integration.pack-check, and upgrade.registry.

On main ebd939b plus this head: the full CLI node suite (342 files, 5,321 tests) and every gate listed above pass.

The manifest's examples and response types came from hand-written maps that
had drifted from the CommandDocs and FunctionDocs, and `upgrade` was missing
`upgrade.registry`. Both now come from the docs each command is built from.
@vercel

vercel Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 2, 2026 4:58pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 24, 2026
@astracat-bot

astracat-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 2, 2026, 5:14 PM UTC

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval recommended: the manifest is now generated from the docs each command is built from, as the CLI surface record requires.

  • Examples come from each command's CommandDoc and response types from the FunctionDoc it wraps, replacing the hand-kept maps that had drifted for most commands.
  • upgrade.registry — already emitted by upgrade --registry --json — is now listed in the manifest, the response-types doc, and the README table, so agents can expect it.
  • The only remaining hand-kept list covers the two envelopes no API function returns (manifest and theme.build.batch), and a test fails if a FunctionDoc ever declares either.
  • New tests load every CommandDoc and FunctionDoc from disk and require exact equality, check the runtime upgrade.registry envelope, and fail against the previous implementation. Command behavior, manifest shape, and text output are unchanged.

[Automated review]

* Example invocations per fully-qualified command. Optional, agent-facing.
* @type {Record<string, string[]>}
*/
const EXAMPLES = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure to actually run before and after before merging this and comparing output

# Conflicts:
#	packages/cli/README.md
#	packages/cli/clients/cli/lib/manifest.mjs
#	packages/cli/foundation/response/response-types.doc.mjs
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

15 of 420 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Chat Full AI Chat probe light 155,733
Chat Full AI Chat probe dark 155,005
Chat Default neutral dark 33,205
Chat Default neutral light 32,876
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,229
Chat With Attachments probe dark 11,065
SideNav Resizable in AppShell probe dark 3,208
Markdown Default probe dark 897
Markdown Default probe light 897
Markdown Default neutral dark 882
Markdown Default neutral light 858

Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

# Conflicts:
#	packages/cli/clients/cli/lib/manifest.mjs

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for restoring the manifest as a generated surface — deriving examples from each CommandDoc and response types from the wrapped FunctionDoc, and listing upgrade.registry, matches the CLI surface record and was verified at this revision (doc-equality tests, generated-table check, and a direct manifest run all pass).

One fix is needed before approval: the README paragraph beginning “The manifest is derived from Commander metadata” still says response types come from a small declarative RESPONSE_TYPES map in src/lib/manifest.mjs. That map and path no longer exist after this change, so the paragraph now points readers at the old hand-kept source. Please update it to describe the new derivation (examples from the CommandDoc, response types from the FunctionDoc returns plus the CLI-built envelopes, JSON support from the allowlist).

No command behavior or manifest shape change is being requested.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for restoring the manifest as a generated surface — deriving examples from each CommandDoc and response types from the wrapped FunctionDoc, and listing upgrade.registry, matches the CLI surface record and was verified at this revision (doc-equality tests and a direct manifest run both pass).

One fix is needed before approval: the README paragraph beginning “The manifest is derived from Commander metadata” still says response types come from a small declarative RESPONSE_TYPES map in src/lib/manifest.mjs. That map and path no longer exist after this change, so the paragraph now points readers at the old hand-kept source. Please update it to describe the new derivation (examples from the CommandDoc, response types from the FunctionDoc returns plus the CLI-built envelopes, JSON support from the allowlist).

No command behavior or manifest shape change is being requested.

[Automated review]

The merge with main took main's README to regenerate the tables and dropped
this PR's paragraph, which still described the removed RESPONSE_TYPES map.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval recommended: the manifest is now generated from the docs each command is built from, as the CLI surface record requires.

  • Examples come from each command's CommandDoc and response types from the FunctionDoc it wraps, replacing the hand-kept maps that had drifted for most commands.
  • upgrade.registry — already emitted by upgrade --registry --json — is now listed in the manifest, the response-types doc, and the README table, so agents can expect it.
  • The README paragraph describing how the manifest is built now matches the new derivation, and the generated README tables check in sync.
  • The only remaining hand-kept list covers the two envelopes no API function returns (manifest and theme.build.batch), and a test fails if a FunctionDoc ever declares either.
  • New tests load every CommandDoc and FunctionDoc from disk and require exact equality, check the runtime upgrade.registry envelope, and pass at this revision alongside the docs-drift check. Command behavior, manifest shape, and text output are unchanged.

[Automated review]

# Conflicts:
#	packages/cli/clients/cli/lib/manifest.mjs

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval recommended: the manifest is now generated from the docs each command is built from, as the CLI surface record requires.

  • Examples come from each command's CommandDoc and response types from the FunctionDoc it wraps, replacing the hand-kept maps that had drifted for most commands.
  • The registry envelope — already emitted by the registry mode — is now listed in the manifest, the response-types doc, and the README table, so agents can expect it.
  • The README paragraph describing how the manifest is built now matches the new derivation, and the generated README tables check in sync.
  • The only remaining hand-kept list covers the two envelopes no API function returns, and a test fails if a FunctionDoc ever declares either.
  • New tests load every CommandDoc and FunctionDoc from disk and require exact equality, check the runtime registry envelope, and pass at this revision alongside the docs-drift check. Command behavior, manifest shape, and text output are unchanged.

[Automated review]

# Conflicts:
#	packages/cli/README.md
#	packages/cli/clients/cli/lib/manifest.mjs
#	packages/cli/foundation/response/response-types.doc.mjs
`theme add` with no slug, or with --list, answers with themeListAvailable()'s
theme.list instead of calling themeAdd(), so the wrapped FunctionDoc cannot
declare it. Deriving response types from that FunctionDoc alone dropped it:
the manifest listed only theme.add, while the released 0.6.4 manifest lists
both. It is now a CLI-layer envelope like theme.build.batch. New test: a bare
`theme add --json` emits theme.list and the manifest lists it; it fails
without the entry.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval recommended: the manifest is now generated from the docs each command is built from, as the CLI surface record requires.

  • Examples come from each command's CommandDoc and response types from the FunctionDoc it wraps, replacing the hand-kept maps that had drifted for most commands.
  • The only remaining pinned list covers the envelopes no wrapped API function returns — the manifest itself, the theme-build batch, and the list answer from theme add with no slug — and a test fails if a FunctionDoc ever declares one of them.
  • A direct before-and-after run at this revision shows the same commands and the same response-type sets, with examples corrected and only ordering changes for two response-type lists; no other manifest field changed.
  • The README paragraph describing how the manifest is built now matches the new derivation, and the generated tables check in sync.
  • New tests load every CommandDoc and FunctionDoc from disk and require exact equality, check the runtime registry and theme-add list envelopes, and pass at this revision alongside the docs-drift check. Command behavior, manifest shape, and text output are unchanged.

[Automated review]

@josephfarina
josephfarina merged commit 9fc9e58 into main Oct 5, 2026
41 checks passed
@github-actions
github-actions Bot deleted the cli-spec/runtime/manifest-from-docs branch October 6, 2026 06:25

This branch was successfully deployed

1 active deployment
Preview — a3066817 Deployed Oct 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant