Skip to content

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

Closed
xyos wants to merge 3 commits into
aws:mainfrom
xyos:feat/cdk-blocks-docs
Closed

xyos wants to merge 3 commits into
aws:mainfrom
xyos:feat/cdk-blocks-docs

Conversation

@xyos

@xyos xyos commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Problem

Coding agents working in an AWS Blocks app find a block's docs by resolving paths in node_modules (node_modules/@aws-blocks/blocks/docs/<block>/README.md, then API.md, then the installed .d.ts files) and reading whole files to find one signature. That takes several calls, breaks when npm hoists the package somewhere else, and still leaves the agent guessing which entry (@aws-blocks/blocks, /client, /utils, …) to import a name from.

Issue #, if available: none

Changes

cdk-blocks docs (@aws-blocks/blocks, minor): prints the docs that ship in @aws-blocks/blocks by name, for the installed version, wherever npm put the package.

npx --no -- cdk-blocks docs                          # the blocks, their classes and what each does
npx --no -- cdk-blocks docs DistributedTable core    # each block's README, several in one call
npx --no -- cdk-blocks docs DistributedTable --api   # its API report (exact signatures)
npx --no -- cdk-blocks docs ifFieldEquals            # an export or option: import line, declaration, its docs
npx --no -- cdk-blocks docs Secret.get               # Owner.member, inherited members included
npx --no -- cdk-blocks docs KVStore --section local  # one section; a bare --section lists the headings
npx --no -- cdk-blocks docs --exports Error          # importable names, and which entry to import each from
npx --no -- cdk-blocks docs --search ConditionalCheckFailed   # matching lines in every doc, with their section
  • 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; guide and troubleshooting print the package README and TROUBLESHOOTING.md.
  • A name prints import type for a type and the @aws-blocks/blocks/client import when browser code needs it. Declarations an API report leaves out and doc comments come from the installed type files.
  • Every printed doc starts with # <folder>/<file> (<path>), so the reader can cite or re-read it. An unknown name or section is a usage error (exit 2) that names the closest matches.
  • CLI plumbing (parse.ts, registry.ts): a string option can declare a bare meaning (--section with no topic lists headings), --search drops grep's own flags (-i, --) before its term, and for docs the arguments after -- are names. bin.ts exits 0 on EPIPE, so cdk-blocks docs … | head ends quietly.
  • The guide's CLI table lists the command.

Pointers (@aws-blocks/create-blocks-app, patch; @aws-blocks/blocks): the scaffolded AGENTS.md "AWS Blocks docs" bullet now names npx --no -- cdk-blocks docs and says to use it instead of reading node_modules, .d.ts and API.md files; its other docs pointers, every template's README and code comments, the Swift demo, the guide's "Building Block documentation" paragraph and the Full docs: JSDoc of the @aws-blocks/blocks re-exports name the command instead of the docs path.

Docs content fixes (separate commit; bb-distributed-table, bb-kv-store, bb-app-setting, core, blocks, patch): which conditional writes are atomic (one item or key on AWS, and in KVStore's mock; not a multi-item transaction), what a local 502 Frontend server unavailable means and how to fix it, withAuth's cookie read and RawRoute params under npm run dev, and where AppSetting's mock keeps its values. A failed condition is JSON-RPC 409, and HTTP 409 only with httpErrorStatus: true.

The command's shape and the AGENTS.md wording were refined against coding-agent sessions on scaffolded apps.

No breaking change: cdk-blocks docs is a new command, and the bundled docs/ folder and its paths are unchanged.

Validation

Run locally on the final branch with Node 22 (.nvmrc), each exiting 0:

  • npm ci, npm run build, npm run lint (warnings only, in template files this PR touches but did not change on those lines), npm run lint:deps
  • npm test: 13,189 tests, 13,179 pass, 0 fail, 10 skipped
  • npm run test:e2e:local: 557 tests, 551 pass, 0 fail, 6 skipped

New tests: packages/blocks/src/cli/docs.test.ts runs the command on a fixture docs folder (listing, blocks by class and folder, --api, names and Owner.member including inherited and aliased members, --section, --exports, --search, usage errors and their suggestions) and, through the built CLI, grep's flags before --search's term and names after --; parse.test.ts covers a bare --section before another option; bin.test.ts checks that the bin exits 0 when its reader closes the pipe early; docs-pointers.test.ts checks that each Full docs: JSDoc names cdk-blocks docs <package> for a package that ships docs.

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 added 3 commits November 15, 2026 18:37
… server's frontend 502

- DistributedTable and KVStore: a conditional put or delete is an atomic check-and-write on one item or
  key on AWS (and, for KVStore, in the local mock); it is not a multi-item transaction (use
  DistributedDatabase or Database). KVStore's Local Development section says how the mock handles
  concurrent conditional writes; both say where the mock keeps its data, and DistributedTable's says how
  limit behaves locally. A failed condition is JSON-RPC 409 (HTTP 409 only with httpErrorStatus: true).
- TROUBLESHOOTING: what the local dev server's '502 Frontend server unavailable' means, its causes and fixes.
- core: withAuth reads Next.js cookies() itself; RawRoute params are the same locally and deployed.
- AppSetting: the mock's data lives in .bb-data/settings.json.
…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.

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.
…s docs

- The scaffolded AGENTS.md's "AWS Blocks docs" bullet names `npx --no -- cdk-blocks docs`
  (a block, a name such as an export, a type or Owner.member, `--api`, `--section`, `--exports`,
  `--search`) and says to use it instead of reading node_modules, .d.ts and API.md files. Its
  other docs pointers (troubleshooting, a block's own docs) name the command too.
- Every template's README and code comments, the Swift demo, the guide's "Building Block
  documentation" paragraph and the `Full docs:` JSDoc of the @aws-blocks/blocks re-exports name
  `cdk-blocks docs <package>` instead of the docs path in node_modules; docs-pointers.test.ts
  checks the JSDoc.
@changeset-bot

changeset-bot Bot commented Nov 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c5f9d84

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

This PR includes changesets to release 6 packages
Name Type
@aws-blocks/blocks Minor
@aws-blocks/create-blocks-app Minor
@aws-blocks/bb-distributed-table Patch
@aws-blocks/bb-kv-store Patch
@aws-blocks/bb-app-setting Patch
@aws-blocks/core Patch

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

assert.ok(usage.includes(`\n ${form} `), form);
}
for (const option of ['--api', '--section <topic>', '--exports [filter...]', '--search <term>']) {
assert.match(usage, new RegExp(`^ {2}${option.replace(/[.[\]]/g, '\\$&')} +\\S`, 'm'), option);
@xyos

xyos commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Split into a stack of four draft PRs, starting with #1509 (then #1510, #1511 and #1512). The fork branch stays in place.

@xyos xyos closed this Nov 15, 2026
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.

2 participants