Skip to content

cli: the real CLI as one tarball that runs with nothing installed - #6507

Closed
josephfarina wants to merge 8 commits into
mainfrom
cli/standalone-runtime
Closed

josephfarina wants to merge 8 commits into
mainfrom
cli/standalone-runtime

Conversation

@josephfarina

@josephfarina josephfarina commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

User need

Tools that scaffold a small app and hand it to an agent want the CLI answering in seconds. Today it only runs after an install, and in a cold or sandboxed environment that install (or the big workspace you reach the CLI through) takes a minute or two before the first astryx component prints anything. That eats most of the time budget for a quick app, so people hand-roll their own CLI tarballs. Those drift from our releases and usually carry only part of the CLI.

Problem and solution fit

  • Primary. scripts/build-cli-standalone.mjs packs @astryxdesign/cli and @astryxdesign/core with pnpm pack, which runs their prepack and rewrites their manifests exactly like pnpm publish does. It extracts those two tarballs unchanged into an installed node_modules layout and adds the third-party dependencies pnpm-lock.yaml pins for them. Nothing in the CLI or Core is rebuilt, bundled or edited. Extract the result anywhere and run node package/bin/astryx.mjs. No package manager, no registry.
  • Supporting. Catalog commands (component, hook, search, build, theme targets) fall back to the Core installed beside the CLI when the project has none. Without that they fail with ERR_CORE_NOT_FOUND in an empty directory. A project's own Core still wins.
  • Supporting. The API reference docs for those five functions describe the fallback, and swizzle's say only the project's own Core counts.
  • Supporting. cli-smoke-test.mjs and cli-json-smoke-test.mjs take --bin and --cwd, so the CLI's own suites can run against a packaged CLI. Their defaults don't change. A CLI Standalone workflow builds the runtime and runs them against it.

Current specification

None governs how the CLI ships or how it finds Core. spec:AST-042 (current) says every command is a thin layer over one @astryxdesign/cli/api function. This PR adds no command, subcommand or option, and the runtime runs those same commands straight from the published package. The fallback lives in the API functions. The text renderer for component --list re-resolves Core on its own (one of the handler gaps AST-042 lists under FR1), so it now uses the same lookup as its API function. Closing that gap is separate. A maintainer still needs to settle the distribution contract, so this stays a draft.

Public delta and caller burden

  • New build output, not published. astryxdesign-cli-standalone-<version>.tgz holds bin/astryx.mjs, the node_modules tree and astryx-standalone.json (versions, the integrity of the packed CLI and Core, source commit, lockfile hash, and every bundled package with its license). The packed astryxdesign-cli-<version>.tgz and astryxdesign-core-<version>.tgz sit beside it. Its package.json is private. Publishing it to npm is a follow-up.
  • With no Core in the project, component, hook, search, build and theme targets used to fail with ERR_CORE_NOT_FOUND. Now they answer from a Core installed beside the CLI when there is one (this runtime, or a global install of both), with the same output that Core gives inside a project.
  • Unchanged. A project's own Core wins. doctor and swizzle still only count the project's Core. The npm packages don't change.

Nothing new for callers to decide.

Design and alternatives

  • It contains the published packages, not a rebuild of them. My first version took the CLI and Core from pnpm deploy, which copies them out of the workspace. pnpm pack output is what npm actually receives (manifest rewritten, publish scripts stripped), so the runtime uses that now, and the test checks it byte for byte.
  • Not a JS bundle. The CLI picks command modules with computed dynamic imports, runs TypeScript configs through Jiti, lets jscodeshift pick parsers at runtime, starts a worker for gap reports and reads 1,600+ data files. An esbuild bundle needed a static command map, sidecars and shims to work, came out only about 3 MB smaller compressed, and ran slower.
  • Core's own dependencies stay nested under Core, so nothing it needs can shadow something the CLI needs. .bin dirs are dropped, so the tree has no symlinks.
  • The script writes the tarball itself (sorted ustar, fixed timestamps, so the same tree always gives the same bytes). npm pack died on a tree this size in CI with "Exit handler never called".

Evidence

On 0.6.3, rebased on main.

  • CI is green on this revision (29edbaea). The CLI Standalone job passed, and the 43 checks on it came back 31 success, 12 skipped, 0 failing.
  • The runtime contains all 2,403 packed CLI files and all 3,265 packed core files byte for byte, and 772 of the CLI's own 772 tests pass against it unmodified from an empty directory with a scrubbed environment (cli-smoke-test.mjs 760/760, cli-json-smoke-test.mjs 12/12). The workspace CLI gets the same 760 and 12.
  • The one change to those suites is the --bin and --cwd flags above. They only pick which CLI the suite runs and where.
  • Commands that write files work from the runtime in an empty project. init --features agents, template <block> <dir>, theme template and theme build all do.
  • A project with its own (empty) Core gets that Core. doctor still fails core-installed in a project without Core. A second extraction at another depth answers the same. Nothing writes into the runtime. The manifest matches all 125 packages in the tree.
  • The tarball is 14 MB (65 MB unpacked, 9,526 files).

I broke it on purpose three ways and each one got caught. Editing one file in the runtime's CLI fails the byte for byte check. Deleting one of the CLI's dependencies from the runtime fails both suites at the first command. Removing the fallback fails the byte for byte check and cli-smoke-test.mjs, which finds no components in an empty directory.

Scope

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split. The unused gpt-tokenizer peer went out in cli: drop the unused gpt-tokenizer peer #6508.
  • Consumer docs, focused tests, and migration evidence ship with the feature. Focused tests and the API reference docs for the fallback are here. Docs for getting the runtime come with publishing.
  • Public text and artifacts contain no internal Meta context.

Testing

  • node scripts/build-cli-standalone.mjs
  • node .github/scripts/cli-standalone-smoke-test.mjs .astryx-standalone/astryxdesign-cli-standalone-0.6.3.tgz
  • pnpm -F @astryxdesign/cli exec tsc --project tsconfig.api-dts.json
  • pnpm check:repo and strict eslint on the touched files (0 errors)
  • npx vitest run packages/cli scripts (5,840 passed)

@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 24, 2026 8:23pm 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
❓ Needs maintainer input (for maintainers only) Sep 24, 2026, 8:25 PM UTC

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Preview availability: Storybook is not ready on the exact-head Vercel preview. Sandbox was not published for this CI run.

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

25 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
Chat Full AI Chat probe light 42,708
Chat Empty State probe light 42,708
Chat Full AI Chat probe dark 41,786
Chat Empty State probe dark 41,786
Slider Default probe light 15,617
Slider Default probe dark 15,615
Chat With Attachments probe light 12,964
Chat With Attachments probe dark 12,114
InputGroup With Typeahead probe light 11,012
InputGroup With Typeahead probe dark 9,189
ComplexSelector Tree list with search probe light 6,245
TextArea Vertical Form Alignment probe light 5,634
ComplexSelector Tree list with search probe dark 5,602
TextArea Vertical Form Alignment probe dark 5,047
ComplexSelector Fruit ripeness selector neutral light 4,007
ComplexSelector Fruit ripeness selector neutral dark 3,825
ToggleButton Group Single probe dark 1,538
ToggleButton Group Single probe light 1,538
MediaTheme On Dark neutral dark 838
Banner Collapsible Content (Expanded) probe dark 92

and 5 more.

Chat — Full AI Chat — probe light
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame
Chat — Empty State — probe light
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame
Chat — Full AI Chat — probe dark
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame

Generated by PR Enrichment workflow | View full report

component, hook, search and theme targets only need a Core that matches
the CLI's release. When the project has none, they now read the one
installed beside the CLI (a global install of both, or the standalone
runtime) instead of failing with ERR_CORE_NOT_FOUND. The project's own
Core still wins.

doctor, swizzle and theme build keep the project-only lookup: they
describe or write to the project, so a Core it never installed must not
read as installed there. A doctor test pins that.
scripts/build-cli-standalone.mjs lays @astryxdesign/cli, its production
dependencies and the matching @astryxdesign/core out as an installed
node_modules tree and packs it as one npm tarball
(astryxdesign-cli-standalone-<version>.tgz). Extract it and run
node package/bin/astryx.mjs: no package manager, registry or install
step. Versions come from pnpm-lock.yaml through pnpm deploy, and the
tree carries a manifest listing every package it bundles.

It is a plain tree, not a JS bundle: the CLI loads command modules,
parsers and integration configs at runtime, which bundling breaks.

The smoke test extracts the tarball twice into empty directories with a
scrubbed environment and checks that 14 read-only commands print exactly
what the workspace CLI prints, that a project's own Core wins, that
doctor still reports Core missing from the project, and that nothing is
written. A new workflow runs both on PRs that touch the CLI, Core or the
lockfile and keeps the tarball as an artifact. Nothing is published.
The api resolves Core through the catalog lookup, but the text renderer
looked it up again project-only. With no Core in the project and one
beside the CLI, --json listed components and text mode crashed. The
renderer now uses the same catalog lookup, and the smoke test runs the
text form of each list command next to its --json form.
npm pack died on the ~9,500-file bundled tree in CI with "Exit handler
never called" while it worked locally. The build now writes the tarball
itself: ustar entries under package/, sorted, with a fixed timestamp and
owner, gzipped with zlib. The same tree always packs to the same bytes,
and npm still installs the result.
The runtime's CLI and Core used to come from pnpm deploy's copy of the
workspace packages. Now they are the tarballs pnpm pack produces, the
same ones pnpm publish uploads, extracted unchanged. pnpm deploy only
supplies their locked third-party dependencies. The packed tarballs
stay beside the runtime and the manifest records their integrity, so
anyone can check that the runtime holds the published packages.

Packing runs each package's prepack, so the workflow no longer builds
Core as a separate step.
The runtime is the published CLI, so testing it against a list of
commands compared with the workspace CLI was the wrong frame. The test
now checks that the runtime holds the packed CLI and Core byte for byte,
then runs cli-smoke-test.mjs and cli-json-smoke-test.mjs against it,
extracted into an empty directory with a scrubbed environment. Both
suites take ASTRYX_SMOKE_BIN and ASTRYX_SMOKE_CWD for that, and default
to the workspace CLI and repo root as before.

It also runs the commands that write files (init, template, theme
template, theme build) in an empty project, and keeps the runtime's own
contract: a project's Core wins, doctor sees only the project, it runs
from anywhere, and nothing writes into it.
@josephfarina josephfarina changed the title cli: standalone runtime that runs with nothing installed cli: the real CLI as one tarball that runs with nothing installed Sep 24, 2026

@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 building this — the empty-directory use case is clear, the runtime now contains the packages exactly as published, and keeping a project's own Core first while doctor, swizzle, and theme build stay project-only are the right boundaries to preserve.

Approval is waiting on a maintainer decision first. As you note, "None governs how the CLI ships or how it finds Core", so a maintainer needs to provide or identify the governing spec for this addition before it can be approved. That spec needs to settle:

  • The standalone runtime itself: tarball layout and name, the bundled manifest, and its unpublished status.
  • The catalog Core fallback: which commands (including Project.components consumers such as gap-report) may answer from a Core beside the CLI, that a project's own Core wins, and which commands stay project-only.
  • Whether a Core beside the CLI must match the CLI version, and what should happen when it does not.

Two independent items also need attention, and would still be needed after that decision:

  • The fallback is automatic behaviour in the shipped CLI (for example, a global install of both packages), so please document it — fallback, project precedence, and the project-only boundary — in the relevant command docs or linked consumer documentation. Deferring consumer docs to standalone publishing does not cover the fallback releasing with the CLI patch.
  • The new CLI Standalone workflow was still running, not yet green, on this revision during review, so parity currently rests on the local report. Please point to a green run for this revision.

Text-mode component --list and the earlier packing failure are fixed in this revision — thank you for those.

[Automated review]

The fallback ships with the CLI itself (a global install of the CLI and
Core gets it too), so it can't be a hidden behavior. The API reference
docs for component, hook, search, build and theme targets now say that a
Core installed beside the CLI answers when the project has none, and
their ERR_CORE_NOT_FOUND entries say when it still happens. Swizzle's
docs say only the project's own Core counts. The changeset also stops
claiming theme build is project-only: it compiles with whatever Core
the CLI resolves, as it always has.
cli-smoke-test.mjs and cli-json-smoke-test.mjs take --bin and --cwd
instead of two ASTRYX_ environment variables. Same behavior, and no new
Astryx-named variables. Defaults are unchanged.

@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 building this — the empty-directory use case is clear, the runtime now contains the packages exactly as published, and keeping a project's own Core first while doctor and swizzle stay project-only are the right boundaries to preserve. The fallback documentation, the text-mode listing fix, the deterministic packing, and switching the smoke suites to --bin/--cwd flags all address the earlier feedback.

Approval is waiting on a maintainer decision first. As you note, "None governs how the CLI ships or how it finds Core", so a maintainer needs to provide or identify the governing spec for this addition before it can be approved. That spec needs to settle:

  • The standalone runtime itself: tarball layout and name, the bundled manifest, and its unpublished status.
  • The catalog Core fallback: which commands (including Project.components consumers such as gap-report) may answer from a Core beside the CLI, that a project's own Core wins, and which commands stay project-only.
  • Whether a Core beside the CLI must match the CLI version, and what should happen when it does not.

One independent item also needs attention, and would still be needed after that decision:

  • The new CLI Standalone workflow was still running, not yet green, on this revision during review, so parity currently rests on the local report. Please point to a green run for this revision.

[Automated review]

github-actions Bot added a commit that referenced this pull request Sep 24, 2026
josephfarina added a commit that referenced this pull request Sep 24, 2026
Fixes:
- build-theme targets: replace character-drawn formatTargetsTable with
  records() inline layout (INV23); show className field
- docs list: add package field to text projection
- upgrade --list: render from JSON result via records() instead of API
  logger (was printing undefined, showing PR numbers, missing version)

Deferred (open PRs would conflict):
- template: id, isReady fields (#6265)
- component: themeData, findRelatedBlocks, --blocks fields (#6507)
- component --props: type union in formatProps code block

Guard test (text-json-parity.test.mjs):
- manifest-driven: fails on a new JSON-capable command with no case
- checks text->JSON (record keys, text blocks, list items)
- checks JSON->text (leaf fields by label or per-key value presence)
- per-command allowlist with stale-entry check
josephfarina added a commit that referenced this pull request Sep 24, 2026
Fixes:
- build-theme targets: replace character-drawn formatTargetsTable with
  records() inline layout (INV23); show className field
- docs list: add package field to text projection
- upgrade --list: render from JSON result via records() instead of API
  logger (was printing undefined, showing PR numbers, missing version)

Deferred (open PRs would conflict):
- template: id, isReady fields (#6265)
- component: themeData, findRelatedBlocks, --blocks fields (#6507)
- component --props: type union in formatProps code block

Guard test (text-json-parity.test.mjs):
- manifest-driven: fails on a new JSON-capable command with no case
- checks text->JSON (record keys, text blocks, list items)
- checks JSON->text (leaf fields by label or per-key value presence)
- per-command allowlist with stale-entry check
josephfarina added a commit that referenced this pull request Sep 24, 2026
Fixes:
- build-theme targets: replace character-drawn formatTargetsTable with
  records() inline layout (INV23); show className field
- docs list: add package field to text projection
- upgrade --list: render from JSON result via records() instead of API
  logger (was printing undefined, showing PR numbers, missing version)

Deferred (open PRs would conflict):
- template: id, isReady fields (#6265)
- component: themeData, findRelatedBlocks, --blocks fields (#6507)
- component --props: type union in formatProps code block

Guard test (text-json-parity.test.mjs):
- manifest-driven: fails on a new JSON-capable command with no case
- checks text->JSON (record keys, text blocks, list items)
- checks JSON->text (leaf fields by label or per-key value presence)
- per-command allowlist with stale-entry check
josephfarina added a commit that referenced this pull request Sep 24, 2026
Fixes:
- build-theme targets: replace character-drawn formatTargetsTable with
  records() inline layout (INV23); show className field
- docs list: add package field to text projection
- upgrade --list: render from JSON result via records() instead of API
  logger (was printing undefined, showing PR numbers, missing version)

Deferred (open PRs would conflict):
- template: id, isReady fields (#6265)
- component: themeData, findRelatedBlocks, --blocks fields (#6507)
- component --props: type union in formatProps code block

Guard test (text-json-parity.test.mjs):
- manifest-driven: fails on a new JSON-capable command with no case
- checks text->JSON (record keys, text blocks, list items)
- checks JSON->text (leaf fields by label or per-key value presence)
- per-command allowlist with stale-entry check
josephfarina added a commit that referenced this pull request Sep 24, 2026
Fixes:
- build-theme targets: replace character-drawn formatTargetsTable with
  records() inline layout (INV23); show className field
- docs list: add package field to text projection
- upgrade --list: render from JSON result via records() instead of API
  logger (was printing undefined, showing PR numbers, missing version)

Deferred (open PRs would conflict):
- template: id, isReady fields (#6265)
- component: themeData, findRelatedBlocks, --blocks fields (#6507)
- component --props: type union in formatProps code block

Guard test (text-json-parity.test.mjs):
- manifest-driven: fails on a new JSON-capable command with no case
- checks text->JSON (record keys, text blocks, list items)
- checks JSON->text (leaf fields by label or per-key value presence)
- per-command allowlist with stale-entry check
josephfarina added a commit that referenced this pull request Sep 24, 2026
Fixes:
- build-theme targets: replace character-drawn formatTargetsTable with
  records() inline layout (INV23); show className field
- docs list: add package field to text projection
- upgrade --list: render from JSON result via records() instead of API
  logger (was printing undefined, showing PR numbers, missing version)

Deferred (open PRs would conflict):
- template: id, isReady fields (#6265)
- component: themeData, findRelatedBlocks, --blocks fields (#6507)
- component --props: type union in formatProps code block

Guard test (text-json-parity.test.mjs):
- manifest-driven: fails on a new JSON-capable command with no case
- checks text->JSON (record keys, text blocks, list items)
- checks JSON->text (leaf fields by label or per-key value presence)
- per-command allowlist with stale-entry check
josephfarina added a commit that referenced this pull request Sep 24, 2026
Fixes:
- build-theme targets: replace character-drawn formatTargetsTable with
  records() inline layout (INV23); show className field
- docs list: add package field to text projection
- upgrade --list: render from JSON result via records() instead of API
  logger (was printing undefined, showing PR numbers, missing version)

Deferred (open PRs would conflict):
- template: id, isReady fields (#6265)
- component: themeData, findRelatedBlocks, --blocks fields (#6507)
- component --props: type union in formatProps code block

Guard test (text-json-parity.test.mjs):
- manifest-driven: fails on a new JSON-capable command with no case
- checks text->JSON (record keys, text blocks, list items)
- checks JSON->text (leaf fields by label or per-key value presence)
- per-command allowlist with stale-entry check
josephfarina added a commit that referenced this pull request Sep 28, 2026
Fixes:
- build-theme targets: replace character-drawn formatTargetsTable with
  records() inline layout (INV23); show className field
- docs list: add package field to text projection
- upgrade --list: render from JSON result via records() instead of API
  logger (was printing undefined, showing PR numbers, missing version)

Deferred (open PRs would conflict):
- template: id, isReady fields (#6265)
- component: themeData, findRelatedBlocks, --blocks fields (#6507)
- component --props: type union in formatProps code block

Guard test (text-json-parity.test.mjs):
- manifest-driven: fails on a new JSON-capable command with no case
- checks text->JSON (record keys, text blocks, list items)
- checks JSON->text (leaf fields by label or per-key value presence)
- per-command allowlist with stale-entry check
josephfarina added a commit that referenced this pull request Sep 28, 2026
Fixes:
- build-theme targets: replace character-drawn formatTargetsTable with
  records() inline layout (INV23); show className field
- docs list: add package field to text projection
- upgrade --list: render from JSON result via records() instead of API
  logger (was printing undefined, showing PR numbers, missing version)

Deferred (open PRs would conflict):
- template: id, isReady fields (#6265)
- component: themeData, findRelatedBlocks, --blocks fields (#6507)
- component --props: type union in formatProps code block

Guard test (text-json-parity.test.mjs):
- manifest-driven: fails on a new JSON-capable command with no case
- checks text->JSON (record keys, text blocks, list items)
- checks JSON->text (leaf fields by label or per-key value presence)
- per-command allowlist with stale-entry check
josephfarina added a commit that referenced this pull request Sep 28, 2026
Fixes:
- build-theme targets: replace character-drawn formatTargetsTable with
  records() inline layout (INV23); show className field
- docs list: add package field to text projection
- upgrade --list: render from JSON result via records() instead of API
  logger (was printing undefined, showing PR numbers, missing version)

Deferred (open PRs would conflict):
- template: id, isReady fields (#6265)
- component: themeData, findRelatedBlocks, --blocks fields (#6507)
- component --props: type union in formatProps code block

Guard test (text-json-parity.test.mjs):
- manifest-driven: fails on a new JSON-capable command with no case
- checks text->JSON (record keys, text blocks, list items)
- checks JSON->text (leaf fields by label or per-key value presence)
- per-command allowlist with stale-entry check
@josephfarina

Copy link
Copy Markdown
Contributor Author

Closing: running the CLI with nothing installed is now covered by global install mode (#7649) and npx @astryxdesign/cli.

@github-actions
github-actions Bot deleted the cli/standalone-runtime branch October 22, 2026 06:22

This branch was successfully deployed

1 active deployment
Preview — 29edbaea Deployed Sep 24, 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