Skip to content

feat(blocks): cdk-blocks docs prints the bundled Building Block docs by name - #1511

Merged
xyos merged 2 commits into
mainfrom
feat/cdk-blocks-docs-command
Nov 18, 2026
Merged

xyos merged 2 commits into
mainfrom
feat/cdk-blocks-docs-command

Conversation

@xyos

@xyos xyos commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A coding agent or developer working in an AWS Blocks app needs a block's docs and exact signatures for the version the app has installed. Those docs ship in @aws-blocks/blocks, but finding them means resolving paths inside node_modules (hoisted or not), and reading a block's API report to find one option's declaration.

Issue #, if available: none

Stack: 3 of 5 (base: #1510). The pointers that send readers to this command are in #1512, and #1521 adds --output json.

Rebased on main after #1453 (KVStore consolidation): the help, examples and CLI tests name KVStore (bb-kv-store) where they named DistributedTable. Review fixes are in their own commit.

Changes

cdk-blocks docs (@aws-blocks/blocks, minor) prints the bundled docs by name, from wherever npm installed the package:

  • cdk-blocks docs lists the blocks, their classes and what each does, then the framework docs (guide, the package README; troubleshooting).
  • cdk-blocks docs <block>... prints each block's README; --api prints its API report instead. A block is its class (KVStore), its folder (bb-kv-store) or the folder without bb-; a doc path (bb-cron-job/DESIGN.md) prints that file.
  • cdk-blocks docs <name> prints the import line, the declaration and the README section of an export, a type, an option or Owner.member (inherited members included; declarations an API report leaves out come from the installed type files).
  • --section <topic>, --exports [filter...] and --search <term> print one section, the importable names and the entry to import each from, or matching lines with their section.

Output names no path on disk. Every printed doc starts with # <folder>/<file> alone on its line (# bb-kv-store/README.md; # README.md for the package README), with a (lines a-b) line under it for a section, and that doc path prints the file again (cdk-blocks docs README.md works too). A type file is named by its package and path (# @aws-blocks/bb-secret/dist/index.mock.d.ts). The listing, --search's first line, errors, Try: hints and --help name no absolute path either, so nothing the command prints points into node_modules. (The text of a few shipped docs mentions node_modules on its own, for example core's README on framework detection; the command prints docs as they are.)

Unknown names, sections and doc files are usage errors (exit 2) that name the closest matches and the doc lines that mention the name; --search and --exports with no match exit 1. A topic with no letters or digits (--section '(') names no section, and a name over 200 characters is unknown before any lookup. Declarations an API report leaves out (SecretImpl for Secret.get) come from the type file of the package's types export, whatever conditions the CLI runs under. The CLI exits 0 when its reader closes the pipe early (| head), and arguments after -- are names for docs. The package README's CLI table and its "Output and exit codes" section describe the command.

No breaking change: a new command; the bundled docs/ folder is unchanged.

Validation

Run locally at the stack top (f05527191, on main at 03778d9f6) with Node 22.23.1 (.nvmrc):

The full suites ran on the previous head (b8a78177a, on main at d01c34c96), Node 22.23.1, before this rebase onto nine more main commits; the rebase changed only bb-kv-store/README.md (a conflict with #1608) in this stack's own diff:

  • npm run test:e2e:local: exit 0; 580 tests, 574 pass, 0 fail, 6 skipped.
  • npm test: 13,802 tests, 13,767 pass, 21 fail, 10 skipped. Every failure is a dev-server, signal or file-watcher test in core, hosting or blocks' cli/context.test.js (none in cdk-blocks docs, bb-auth, bb-kv-store or create-blocks-app), and the log has 46 EMFILE errors from fs.watch: this machine's fs.inotify.max_user_instances (128) was used up by other processes. CI runs these suites.

No sandbox run: nothing here changes deployed behaviour or serialization.

Checklist

  • PR description included
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@xyos
xyos added this pull request to stack #1513 November 15, 2026 22:24
@changeset-bot

changeset-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: aa9bb91

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@aws-blocks/blocks Minor
@aws-blocks/create-blocks-app Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@xyos xyos changed the title feat/cdk blocks docs command feat(blocks): cdk-blocks docs prints the bundled Building Block docs by name Nov 15, 2026
@xyos
xyos force-pushed the feat/cdk-blocks-docs-command branch from 9ea95be to a1fd549 Compare November 16, 2026 01:23
@xyos

xyos commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

The Local Build and Checks failure on this PR, which #1512 inherits, comes from the regex sink guard (scripts/sink-guards/regex.test.mjs). It flags two new RegExp(...) sites in sectionMentioning() in packages/blocks/src/cli/docs.ts:

packages/blocks/src/cli/docs.ts:1885  new RegExp(`(^|[^\\w$])(${alternatives})([^\\w$]|$)`)
packages/blocks/src/cli/docs.ts:1896  new RegExp(`(^|[^\\w$])(${alternatives})\\s*(<[^>]*>)?\\(`)

Both are false positives. alternatives is words.map(escapeRegExp).join('|'), so every alternative is escaped. The guard trusts only direct escapeRegExp(x) calls and does not follow .map(escapeRegExp). A follow-up commit will change these two sites so that the guard sees each escape; the matching stays the same.

Comment thread packages/blocks/src/cli/docs.ts Resolved
Comment thread packages/blocks/src/cli/docs.ts Resolved
Comment thread packages/blocks/src/cli/docs.ts Resolved
Comment thread packages/blocks/src/cli/docs.ts Resolved
Comment thread packages/blocks/src/cli/registry.ts Resolved
xyos added 2 commits November 18, 2026 10:59
…by name

`cdk-blocks docs` reads the docs that ship in @aws-blocks/blocks wherever npm installed the
package, so a coding agent or a developer finds a block's docs and exact signatures in one call
instead of resolving paths in node_modules:

- `cdk-blocks docs` lists the blocks, their classes and what each does, then the framework docs.
- `cdk-blocks docs <block>...` prints each block's README; `--api` prints its API report instead.
  A block is its class (DistributedTable), its folder (bb-distributed-table) or the folder
  without bb-; a doc path (bb-cron-job/DESIGN.md) prints that file.
- `cdk-blocks docs <name>` prints the import line, the declaration and the README section of an
  export, an option or Owner.member (inherited members included).
- `--section <topic>`, `--exports [filter...]` and `--search <term>` print one section, the
  importable names and their entry, or matching lines with their section.

Every printed doc starts with `# <folder>/<file>` alone on its line (`# bb-kv-store/README.md`,
`# README.md`), and that doc path prints the file again. No output names a path on disk: headers,
search preambles, the listing, errors, hints and --help never point into node_modules.

Unknown names and sections are usage errors (exit 2) that name the closest matches. The CLI
exits 0 when its reader closes the pipe early (`| head`), and arguments after `--` are names
for docs. The README's CLI table lists the command.
- Secret.get and other members of a forgotten export resolve from the type file an app reads (the
  package's types export), not the entry the CLI's own conditions pick (cdk, browser).
- --section '(' or '' names no section (exit 2) instead of the doc's first section.
- A doc path the block lacks exits 2, like an unknown name.
- A name over 200 characters is unknown before it reaches a RegExp; the error quotes its start.
- The regex sink guard allowlists sectionMentioning()'s two escaped patterns.
- The help, examples and comments name KVStore now that DistributedTable is folded into it; the CLI
  tests read KVStore's docs. The usage test escapes every regex metacharacter.

This branch was previously deployed

2 inactive deployments
e2e — aa9bb912 Deployed Nov 18, 2026 by xyos via E2E Teardown Verify #7052
agent-bench — aa9bb912 Deployed Nov 18, 2026 by xyos via bench / summary #6126
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants