Skip to content

chore(cli): lint the CLI structure rules - #6617

Merged
josephfarina merged 1 commit into
mainfrom
chore/cli-structure-lint
Sep 28, 2026
Merged

josephfarina merged 1 commit into
mainfrom
chore/cli-structure-lint

Conversation

@josephfarina

@josephfarina josephfarina commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

The CLI architecture invariants (INV20–23) and the command admission spec (AST-042 FR1–FR3) are current authority with no mechanical enforcement. Review applies them, but a new violation slips past when review misses it. This change adds lint checks so they fail in CI.

Intended invariant

architecture:cli-surface INV21–23 and spec:AST-042 FR1–FR3.

Change

Six checks, all running inside pnpm lint via check:repo:

Check Rule Mechanism Allowlisted
INV22 Handlers must not import environment modules (fs, child_process, Project, discovery) check-cli-structure.mjs exact-entry allowlist 8 files
INV21 API modules (except adapters) must not import environment modules check-cli-structure.mjs exact-entry allowlist 30 files
INV23 / FR3 Handlers must not use .padEnd(), .padStart(), .repeat(), or new Block() for text layout ESLint no-restricted-syntax + check-cli-structure.mjs 2 files
FR1 Every executable CommandDoc fn must name a function exported from api/index.mjs check-cli-structure.mjs exact-entry allowlist 1 fn (themeTemplate)
FR2 Every api/index.mjs function export must have a FunctionDoc whose name matches check-cli-structure.mjs 0 (clean)
CONTRIBUTING.md Six new rows in the "enforced for you" table documentation —

Current-main baseline: Two imports landed after this PR was first drafted: the integration validator reads discovery, and the upgrade runner reads the filesystem. The initial gate records those existing categories. After the gate lands, any new category or stale entry fails, so the list only shrinks. The contributor table and script now say that an underscore helper is exempt only if adapters alone import it.

Allowlist design: each entry tracks the exact violation categories a file has. A new category in an allowlisted file fails. A stale entry (the violation was fixed but the entry remains) also fails. The list can only shrink.

If #6616 merges first and removes handler violations, this PR’s stale-entry check will fail on the removed entries — delete them and the check passes. If this PR merges first, #6616 must delete the entries it makes stale.

Order with the other open CLI PRs: Prefer #6616 first, then rebase this PR and remove the now-stale build-theme.mjs padEnd allowlist entry; the combined structure check and focused parity tests pass with that entry removed. #6626 also rewrites docs.list and edits cli-surface; whichever lands second must rebase and preserve the package text projection. If #6626 changes the docs.mjs text-layout calls, refresh this PR’s exact-category entry. #6702 exports themeTemplate, so if it lands before this PR, remove the now-stale FR1 gap too. These are order-dependent maintenance steps, not four independent approvals.

Evidence

  • Failure before the change: review-only; no CI gate
  • Success after the change: pnpm lint catches each violation kind

Mutation proofs (each introduced a deliberate violation, confirmed the check failed, then restored):

  1. INV22 new violation in clean handler → caught
  2. INV22 new category in allowlisted handler → caught
  3. INV21 new violation in clean API module → caught
  4. INV23 .padStart() in clean handler → caught by both ESLint and script
  5. FR1 fn not exported → caught
  6. FR2 export without FunctionDoc → caught
  7. INV23 new .padStart() in allowlisted docs.mjs → caught by script
  8. Stale INV22 entry (removed import) → caught

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

Current-head local evidence:

  • pnpm check:repo: passed (includes check:cli-structure)
  • Exact-head CI lint passed; isolated local whole-repo ESLint crashed after the repository checks had passed
  • pnpm check:cli-structure: 10 doc-types, 17 api folders, 17 handlers INV22, 74 api modules INV21, 28 CommandDoc fns FR1, 37 exports FR2
  • pnpm -F @astryxdesign/cli typecheck:strict: 0 errors
  • prettier --check CONTRIBUTING.md and git diff --check: clean

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 24, 2026
@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 Sep 28, 2026 8:45pm UTC

Request Review

@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) Sep 28, 2026, 8:57 PM UTC

@github-actions

github-actions Bot commented Sep 24, 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

1 of 420 shot(s) changed. View the report

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
SideNav Resizable in AppShell probe dark 3,208
SideNav — Resizable in AppShell — probe dark
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame

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

@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 adding the mechanical gate — enforcing these already-agreed CLI structure rules in pnpm lint is the right direction, and the exact-category allowlist that fails when an entry goes stale is a strong design. It matches the governing direction: "The checks and the closure of the gaps above land as separate changes."

One issue blocks approval: the gate currently passes while some real environment access is not recorded, so the allowlist is not yet exact. The governing INV21 claim is that environment access happens only in "_adapter.mjs and any underscore-prefixed helper that only it imports", and that the entry and leaves "they do not import filesystem, network, or subprocess modules, the Project seam, or discovery and loader functions".

  • The import scanner in scripts/check-cli-structure.mjs only reads from '...' specifiers, so runtime dynamic imports are invisible to it. packages/cli/api/gap-report/gap-report.mjs already uses await import('node:child_process') to run gh, but its INV21 allowlist entry lists only project and discovery — the new check reports the tree as clean anyway, and a future handler or API module could bypass the check the same way. Please make the scanner classify runtime dynamic imports (without flagging JSDoc type-only imports), then either record this category or move the fallback behind that subject's adapter, and add a mutation test for the dynamic-import case.
  • The API exemption covers every file whose name starts with _, which is broader than INV21. For example, packages/cli/api/swizzle/_github.mjs imports node:child_process and is imported directly by the copy leaf, so that subprocess access also passes with no allowlist entry. Please either narrow the exemption to adapter-only helpers or record this as an explicit known gap.

The other checks correspond to their governing claims: INV22 — "It reads no files, loads no project, runs no discovery, and starts no subprocess or network request"; INV23 — a handler "does not pad strings to a width, align columns, or draw tables"; FR3 — items and values must use the shared blocks, "never columns or tables that a command builds from characters itself"; FR1 — a command "MUST perform it by calling one function exported from @astryxdesign/cli/api"; and FR2 — an exported function "MUST have reference documentation that states its parameters". The counts the check reports, the FR1/FR2 name checks, the text-layout checks, and the stale-entry behaviour for static imports all look right. Once the two gaps above are closed, this should be ready.

[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 adding the mechanical gate, and for closing the two gaps from the last round — this is ready to approve. Enforcing these already-agreed rules in pnpm lint matches the governing direction: "The checks and the closure of the gaps above land as separate changes."

What was verified at this revision:

  • INV21, where environment access happens only in the adapter — "reading or writing files, network requests, subprocesses, loading the project or its modules, and discovery that reads the disk happen in the subject's adapter: _adapter.mjs and any underscore-prefixed helper that only it imports", and the entry and leaves "they do not import filesystem, network, or subprocess modules, the Project seam, or discovery and loader functions". The scanner now classifies literal dynamic imports, so gap-report's dynamic node:child_process use is recorded in its allowlist entry, and the exemption is computed from the import graph — only adapter-only helpers are exempt, while the subprocess helper imported by the swizzle leaf is scanned and recorded as a gap. The gate passes exactly: 74 API modules checked.
  • INV22 — "It reads no files, loads no project, runs no discovery, and starts no subprocess or network request" — checked over 17 handlers with eight recorded gaps.
  • INV23 — "A handler does not pad strings to a width, align columns, or draw tables" — and FR3 — "Items and field values MUST use Record, Section, or List blocks, never columns or tables that a command builds from characters itself" — checked in the script and in ESLint, with two recorded gaps.
  • FR1 — "Every command or subcommand that performs an operation MUST perform it by calling one function exported from @astryxdesign/cli/api" — checked over 28 CommandDoc functions with one recorded gap.
  • FR2 — "Every function exported from @astryxdesign/cli/api MUST have reference documentation that states its parameters" — checked over 37 exports, currently clean.

One small non-blocking note: the CONTRIBUTING row and the script header describe private helpers as if they were exempt, while the check actually exempts only helpers that adapters alone import and scans the rest. Tightening that wording to match the code would save the next contributor a surprise; it does not change the gate's behaviour, which fails closed here.

[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 adding the mechanical gate — this is ready to approve. Enforcing these already-agreed rules in pnpm lint matches the governing direction: "The checks and the closure of the gaps above land as separate changes."

What was verified at this revision:

  • INV21, where environment access happens only in the adapter — "reading or writing files, network requests, subprocesses, loading the project or its modules, and discovery that reads the disk happen in the subject's adapter: _adapter.mjs and any underscore-prefixed helper that only it imports", and the entry and leaves "they do not import filesystem, network, or subprocess modules, the Project seam, or discovery and loader functions". The scanner classifies literal dynamic imports, so gap-report's dynamic node:child_process use is recorded in its allowlist entry, and the exemption is computed from the import graph — only adapter-only helpers are exempt, while the subprocess helper imported by the swizzle leaf is scanned and recorded as a gap. The gate passes exactly: 74 API modules checked, including the two environment imports that landed on main after this PR was first drafted (the integration validator and the upgrade runner), both recorded with their exact categories.
  • INV22 — "It reads no files, loads no project, runs no discovery, and starts no subprocess or network request" — checked over 17 handlers with eight recorded gaps.
  • INV23 — "A handler does not pad strings to a width, align columns, or draw tables" — and FR3 — "Items and field values MUST use Record, Section, or List blocks, never columns or tables that a command builds from characters itself" — checked in the script and in ESLint, with two recorded gaps.
  • FR1 — "Every command or subcommand that performs an operation MUST perform it by calling one function exported from @astryxdesign/cli/api" — checked over 28 CommandDoc functions with one recorded gap.
  • FR2 — "Every function exported from @astryxdesign/cli/api MUST have reference documentation that states its parameters" — checked over 37 exports, currently clean.

The CONTRIBUTING wording now also matches the implemented rule — a helper is exempt only when adapters alone import it — so the note from the last round is closed too.

[Automated review]

Add mechanical enforcement for the architecture invariants and spec
requirements that were review-only until now.

check-cli-structure.mjs (runs in pnpm lint via check:repo):

- INV22: command handlers must not import environment modules (node:fs,
  node:child_process, Project, discovery). 8 known gaps allowlisted with
  exact category tracking — a new violation in an allowlisted file fails,
  and a stale entry (removed import) also fails.
- INV21: API modules other than adapters (_*.mjs) must not import
  environment modules. 29 known gaps allowlisted the same way.
- INV23/FR3: handlers must not use .padEnd(), .padStart(), .repeat(), or
  new Block() for text layout. 2 known gaps allowlisted.
- FR1: every executable CommandDoc fn must name a function exported from
  api/index.mjs. 1 known gap (themeTemplate).
- FR2: every function exported from api/index.mjs must have a FunctionDoc
  whose name matches. Currently clean.

eslint.config.js:

- INV23/FR3: no-restricted-syntax selectors ban padEnd, padStart, repeat,
  and new Block in command handlers. build-theme.mjs and docs.mjs
  exempted via config block (the script provides the exact-entry gate).

CONTRIBUTING.md:

- Six new rows in the "enforced for you" table documenting each check.

@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 adding the mechanical gate — this is ready to approve. Enforcing these already-agreed rules in pnpm lint matches the governing direction: "The checks and the closure of the gaps above land as separate changes."

What was verified at this revision:

  • INV21, where environment access happens only in the adapter — "reading or writing files, network requests, subprocesses, loading the project or its modules, and discovery that reads the disk happen in the subject's adapter: _adapter.mjs and any underscore-prefixed helper that only it imports", and the entry and leaves "they do not import filesystem, network, or subprocess modules, the Project seam, or discovery and loader functions". The scanner classifies literal dynamic imports, so gap-report's dynamic node:child_process use is recorded in its allowlist entry, and the exemption is computed from the import graph — only adapter-only helpers are exempt, while the subprocess helper imported by the swizzle leaf is scanned and recorded as a gap. The gate passes exactly: 74 API modules checked, including the integration validator and the upgrade runner, both recorded with their exact categories.
  • INV22 — "It reads no files, loads no project, runs no discovery, and starts no subprocess or network request" — checked over 17 handlers with eight recorded gaps.
  • INV23 — "A handler does not pad strings to a width, align columns, or draw tables" — and FR3 — "Items and field values MUST use Record, Section, or List blocks, never columns or tables that a command builds from characters itself" — checked in the script and in ESLint, with one recorded script gap (docs.mjs). At this revision the stale script entry for build-theme.mjs is removed, since that handler no longer uses the banned patterns.
  • FR1 — "Every command or subcommand that performs an operation MUST perform it by calling one function exported from @astryxdesign/cli/api" — checked over 28 CommandDoc functions with one recorded gap.
  • FR2 — "Every function exported from @astryxdesign/cli/api MUST have reference documentation that states its parameters" — checked over 37 exports, currently clean.

One small non-blocking note: the ESLint layout exemption still lists build-theme.mjs even though it no longer needs it; the script gates that file with no allowlist entry, so nothing slips through, but dropping the redundant ESLint entry would keep the two configs in step.

[Automated review]

github-actions Bot added a commit that referenced this pull request Sep 28, 2026
@josephfarina
josephfarina merged commit 665afc1 into main Sep 28, 2026
45 checks passed
@github-actions
github-actions Bot deleted the chore/cli-structure-lint branch September 29, 2026 06:24

This branch was successfully deployed

1 active deployment
Preview — c448a98d Deployed Sep 28, 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