Skip to content

feat(cli): add integration init command - #6961

Closed
josephfarina wants to merge 2 commits into
mainfrom
feat/integration-init
Closed

josephfarina wants to merge 2 commits into
mainfrom
feat/integration-init

Conversation

@josephfarina

@josephfarina josephfarina commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What this does

astryx integration init [name] creates or completes the package.json for an Astryx integration package in one command. It replaces the 5 manual steps from the quick-start doc (mkdir, npm init, set name, set exports, install dependencies).

After init, integration add, integration verify, and every other CLI command work immediately.

AST-042 FR4 subcommand justification

  • Question it answers: "How do I start a new integration package?" No existing command answers this.
  • Why extending an existing command is wrong: init is for consumer apps (index.mjs explicitly skips integration packages). integration add requires a package.json to already exist — its findPackageDir() throws if none is found. Creating the package is a distinct step that logically precedes any add.
  • FR1 function: integrationInit() exported from @astryxdesign/cli/api.

Behavior

Creates/completes package.json:

  • name — from argument, existing value, or directory name
  • version — 1.0.0 (only when creating)
  • exports — {} (the empty map that integration add populates)
  • The Core peer (@astryxdesign/core: ^<installed>) is written by the first integration add component, add template, or add theme, not by init. It never overwrites an existing range.

Install step (unless --dry-run or --no-install):

  • Adds only the missing packages as dev dependencies (<pm> add -D <missing>); if both are declared but not installed, runs a plain <pm> install. Declared entries stay in their field (dependencies, devDependencies or optionalDependencies).

Idempotent: re-running on an initialized package reports unchanged.

JSON type: integration.init with {name, packageCreated, fieldsAdded, installed, dryRun}.

Design decisions

  1. Core peer from add, not init — a Core peer from init causes npm ERESOLVE on the next Core minor for doc/codemod integrations that never import Core. The first component, template, or theme add writes ^<installed> once.
  2. No extra fields (no type, description, license) — theme-neutral has authored content; auto-generating it invites wrong values. The author adds what they mean.
  3. Install by default — declared dependencies are installed where they are declared; missing ones are added as dev dependencies. --no-install for environments that want control.
  4. No manifest creation — integration add creates astryx.integration.mjs on first contribution. Init creates the package; add creates the integration content.

Bootstrap

From an empty directory with no CLI installed:

npx @astryxdesign/cli@latest integration init @acme/astryx-widgets

Tested

  • init --dry-run --json ✅
  • init --no-install ✅
  • init with install (npm via proxy) ✅
  • Idempotency (re-run on existing package) ✅
  • Existing package.json with some fields ✅
  • Invalid package name ✅
  • init → integration add component → integration verify (full journey, zero issues) ✅
  • check:repo ✅
  • check:knowledge ✅
  • typecheck:json-api ✅
  • cli-api-types-verify ✅
  • Full CLI test suite (5622 tests, all pass) ✅

Multi-selector admission (AST-042 FR7)

integration init is not batch-eligible under AST-053 FR11. It fails E1 (it writes package.json and runs an install, so it is not read-only) and E4 (an install per selector has no single safe aggregate work bound for two or more selectors).

@vercel

vercel Bot commented Oct 5, 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 12, 2026 8:16pm UTC

Request Review

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

astracat-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Oct 12, 2026, 8:35 PM UTC

@github-actions

github-actions Bot commented Oct 5, 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

44 of 448 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
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 754,077
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,188
Chat Full AI Chat probe light 238,081
Chat Full AI Chat probe dark 237,048
Markdown Default probe light 159,625
Markdown Default probe dark 158,986
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
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,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
TableRowExpansion Detail Panel neutral dark 5,150
TableRowExpansion Detail Panel neutral light 4,068

and 24 more.


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 building the missing first step for integration authors — the case for a dedicated integration init subcommand is clear, and the thin command over integrationInit() with --dry-run, --no-install, and JSON support is the right shape.

A few things need work before this can merge:

  • The branch currently conflicts with its base in packages/cli/README.md. Please rebase and resolve it without dropping the landed demo-media receipt wording.
  • The manifest change switches examples and response types from being derived from each command's docs to hand-kept maps. That reverses the generated-manifest design, and the manifest test now fails (blog examples are lost and the docs response types no longer match). Restoring the derived manifest should be enough — the new command's docs already supply its entries.
  • The response-type and README edits remove the descriptions of demoMediaReplaced, sourcePathFound, and validated, but the code still returns those fields. Please restore them and keep only the additions for integration.init and ERR_INSTALL_FAILED.
  • The new function needs its own tests: options, the invalid-name and install-failure errors, a re-run, and a CLI success and failure. Right now only a dry-run parity case covers it.
  • With defaults, re-running installs again and reports updated rather than unchanged, and an install failure leaves the written package file behind. Please either skip an already-satisfied install or align the docs and changeset with that behavior.
  • One small admission item: note in the pull request that this create command is not batch-eligible under the multi-selector rules (E1/E4).

Happy to take another look once those are in.

[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 building the missing first step for integration authors — the case for a dedicated integration init subcommand is clear, and the thin command over integrationInit() with --dry-run, --no-install, and JSON support is the right shape. Deferring the Core peer to the first integration add is a nice refinement, and the existing-package protections are now complete: no rename via a differing name argument, no exports map invented for a package that lacks one, coded errors for a non-object package.json, a non-string name, or a malformed peerDependencies on any of the peer paths (component, template, theme, and doc --parent included), a test proving --dry-run together with --no-install, and the lint layering fix for the shared shape check.

One item remains before this can merge:

  • The guard's refusal cases are well tested, but nothing yet asserts the normal first-add write itself. One add-path test with an installed-Core fixture confirming the ^<installed> peer range is written would keep that documented behavior from regressing unnoticed (it works today — this is about locking it in).

Happy to take another look once that is in.

[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 building the missing first step for integration authors — the case for a dedicated integration init subcommand is clear, and the thin command over integrationInit() with --dry-run, --no-install, and JSON support is the right shape. Deferring the Core peer to the first integration add is a nice refinement, and the existing-package protections are complete: no rename via a differing name argument, no exports map invented for an existing package that lacks one, and coded errors for a non-object package.json, a non-string name, or a malformed peerDependencies on the peer-writing paths.

Tests now also prove the normal first-add Core peer write for component, template, and theme adds, including preserving an existing author range. This looks ready to merge once a CLI code owner has approved and the branch is refreshed onto current main so the hosted UI suite runs with the newer BottomSheet fixes (its one current failure is in that component, which this change does not touch).

[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 building the missing first step for integration authors — the case for a dedicated integration init subcommand is clear, and the thin command over integrationInit() with --dry-run, --no-install, and JSON support is the right shape. Deferring the Core peer to the first integration add is a nice refinement, and the existing-package protections hold up: no rename via a differing name argument, no exports map invented for an existing package that lacks one, and coded errors for a non-object package.json or a non-string name.

One behavior worth being deliberate about: when peerDependencies is not an object, a theme or doc add refuses with a coded error while a component or template add succeeds and leaves the field (and the missing Core peer) as-is until a later add. That never corrupts the file, so it is not a blocker — but either refusing consistently or noting the malformed case in the command description would make the three kinds read the same. Two stale code comments (the peer helper still says it throws, and the init file header still implies init sets the Core peer) could be tidied in passing.

Tests prove the normal first-add Core peer write for component, template, and theme adds, including preserving an existing author range. This looks ready to merge once a CLI code owner has approved and the branch is refreshed onto current main so the hosted UI suite picks up the BottomSheet test fix (its one current failure is in that component, which this change does not touch).

[Automated review]

@josephfarina
josephfarina force-pushed the feat/integration-init branch 3 times, most recently from 844f180 to 0c8d701 Compare October 8, 2026 23:18
@josephfarina
josephfarina force-pushed the feat/integration-init branch 2 times, most recently from f7d4ee3 to 86d34b5 Compare October 8, 2026 23:56
@josephfarina
josephfarina force-pushed the feat/integration-init branch 2 times, most recently from 99a8e91 to 185c6e5 Compare October 9, 2026 00:28

@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 the missing first step for integration authors — the case for a dedicated integration init subcommand is clear, and the thin command over integrationInit() with --dry-run, --no-install, and JSON support is the right shape. Deferring the Core peer to the first integration add, respecting the field each dependency is already declared in, and refusing malformed package shapes before writing all hold up well, and the tests now prove the first-add peer write, the install matrix, and the failure rollback.

One correction before this can merge: when the CLI and Core are already declared under dependencies (or only one of them needed adding), a successful install still prints that both were "installed as devDependencies", although the declarations correctly stay where they were. Making that line field-neutral (or reporting what was actually added), with a text-mode test for the pre-declared case, would keep the human output as truthful as the JSON receipt already is. While you are there, refreshing the pull-request description's peer and install paragraphs to the shipped deferred-peer, declared-field behavior would help human reviewers.

Happy to take another look once that line is fixed — everything else looks ready, subject to code-owner approval, with the hosted suite green.

[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 building the missing first step for integration authors — the case for a dedicated integration init subcommand is clear, and the thin command over integrationInit() with --dry-run, --no-install, and JSON support is the right shape. Deferring the Core peer to the first integration add, respecting the field each dependency is already declared in, and refusing malformed package shapes before writing all hold up well. The install success line now reads field-neutral with a CLI test for the pre-declared case, which closes the last round's item — thank you.

One small edge remains: an existing package.json whose name is empty or only whitespace currently gets a success receipt, even though npm could never have published that name, and passing the correct name is refused as a rename. Refusing that input with ERR_INVALID_ARGUMENT (or treating an empty name as missing), with a test next to the non-string-name cases, would keep the receipt truthful there too.

Happy to take another look once that check is in — everything else looks ready, subject to code-owner approval.

[Automated review]

Comment thread packages/cli/api/integration/init.mjs Outdated
function isAcceptableExistingName(name) {
return (
typeof name === 'string' &&
name.length <= PACKAGE_NAME_MAX_LENGTH &&

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.

An existing package whose name is "" or whitespace-only passes this check, so init reports success (writing version and echoing the blank name in the receipt) for a package npm could never have published — the legacy path exists for names npm already published, such as uppercase ones. Passing a correct name is then refused as a rename (Package "" already exists), leaving hand-editing as the only way forward; a probe in check.log shows both outcomes. The FunctionDoc promises ERR_INVALID_ARGUMENT for an invalid npm name, so please refuse an empty/blank existing name here (or treat it as missing and fill it), with a test alongside the non-string-name cases.

@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 the missing first step for integration authors — the case for a dedicated integration init subcommand is clear, and the thin command over integrationInit() with --dry-run, --no-install, and JSON support is the right shape. Deferring the Core peer to the first integration add, respecting the field each dependency is already declared in, and refusing malformed package shapes before writing all hold up well.

The last round's edge is now closed: an existing package.json with an empty or whitespace-only name is treated as missing and filled (from the argument or the directory), with tests for both cases, and the existing-name checks now name the specific rule they enforce. The field-neutral install success line and its CLI test are in as well — thank you.

This looks ready to merge once a CLI code owner has approved.

[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 building the missing first step for integration authors — the case for a dedicated integration init subcommand is clear, and the thin command over integrationInit() with --dry-run, --no-install, and JSON support is the right shape. Deferring the Core peer to the first integration add, respecting the field each dependency is already declared in, and refusing malformed package shapes before writing all hold up well.

The blank-name edge is fully closed now: an existing package.json with an empty or whitespace-only name is treated as missing and filled under the strict new-name rules, and the new test locks in that a strict-invalid replacement (a Node core-module name) is refused with the file unchanged. One small non-blocking note for a follow-up: init writes through a symlinked package.json while the add writers refuse symlinked targets, so aligning those would make the journey consistent for that setup.

This looks ready to merge once a CLI code owner has approved.

[Automated review]

# Conflicts:
#	packages/cli/README.md
#	packages/cli/api/index.mjs
#	packages/cli/clients/cli/commands/integration.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 turning the quick-start's setup into one command — the case for the subcommand is clear, and init followed by integration add and integration verify works. Approval needs a maintainer decision first: no current spec covers integration add writing a ^<installed> @astryxdesign/core peer on the first component, template, or theme add, so a maintainer needs to provide or identify the governing spec for that write and its range, or the write should leave this PR. Separately from that decision, these changes are needed:

  • Move init's file and subprocess work into api/integration/_adapter.mjs instead of adding a new INV21_KNOWN_GAPS entry, which that list does not allow (cli-surface INV21).
  • Refuse a symlinked package.json the way integration add does; today init edits the link's target outside the package (INV10).
  • Stop creating exports in init, or get INV16 (“Writers never create files or exports”) amended first.
  • Print the receipt with record(...) rather than one Text block per field (AST-042 FR3).
  • At 2,577 authored lines, split the integration add peer changes into their own PR and trim the init tests to get under the 2,000-line scope threshold.

[Automated review]

['integration/add-helpers.mjs', new Set(['fs'])],
['integration/add-theme.mjs', new Set(['fs', 'discovery'])],
['integration/authoring-checks.mjs', new Set(['discovery'])],
['integration/init.mjs', new Set(['fs', 'child_process'])],

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.

This map is documented as known gaps recorded in AST-042 — “remove an entry when the file is fixed; do not add entries”. integration/init.mjs is new, so this line admits a new INV21 violation rather than recording an old one, and main's check fails on the file without it. Please move the fs reads and writes and spawnSync into api/integration/_adapter.mjs (or an underscore helper only it imports) and drop this entry.

Comment on lines +174 to +176
if (!exists && pkg.exports == null) {
pkg.exports = {};
fieldsAdded.push('exports');

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.

cli-surface INV16 reads “Writers never create files or exports” with no new-package exception (theme exports come from AST-050's own claim), so creating exports: {} here contradicts it; the header's “on an existing package” is not in the claim. Please leave exports to the author, as the current quick-start does, or get INV16 amended on main first.

? (originalSource.match(/\n([ \t]+)"/u)?.[1] ?? ' ')
: ' ';
fs.mkdirSync(dir, {recursive: true});
fs.writeFileSync(

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.

This write follows a symlinked package.json to its target, even outside the package directory, and reports success; integration add refuses the same file with ERR_PATH_TRAVERSAL (assertNotSymlink in add-helpers.mjs). cli-surface INV10 requires every write to be confined. Please refuse a symlinked target here and in rollbackPackageJson (the shared applyWrites path would do both), with a test.

Comment on lines +140 to +142
text(`packageCreated: ${data.packageCreated}`),
text(`installed: ${data.installed}`),
text(`dryRun: ${data.dryRun}`),

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.

AST-042 FR3: “A Text block carries prose. Items and field values MUST use Record, Section, or List blocks.” These lines print receipt fields as prose and leave name, fieldsAdded, and notes unlabeled (INV5). record(data, {fields: ['name', 'packageCreated', 'fieldsAdded', 'installed', 'dryRun', 'notes']}) renders the same receipt with keys that match the JSON.

Comment on lines +298 to +305
// Component contributions compose Core components in real integrations.
// Write the Core peer on the first component add when no peer exists yet.
{
const coreExpected =
pkgUpdate?.expectedOriginal ?? fs.readFileSync(packageFile);
const coreText = pkgUpdate?.contents ?? coreExpected.toString('utf-8');
const coreCurrent = JSON.parse(coreText);
const corePeerResult = withCorePeer(coreCurrent, packageDir);

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.

No current spec assigns integration add a Core peer or its ^<installed> range — AST-046 FR11 covers only the @astryxdesign/cli peer. Approval of this write (and of the template and theme copies) waits on a maintainer providing or identifying the governing spec.

@josephfarina

Copy link
Copy Markdown
Contributor Author

Parking this for now; it's tracked separately and can be reopened when picked up.

This branch was successfully deployed

1 active deployment
Preview — 3b9faac9 Deployed Oct 12, 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