Skip to content

refactor(cli,core): one dep-free source for the astryx-init setup check - #4162

Merged
josephfarina merged 3 commits into
mainfrom
navi/vibe/unify-setup-check
Sep 3, 2026
Merged

josephfarina merged 3 commits into
mainfrom
navi/vibe/unify-setup-check

Conversation

@josephfarina

@josephfarina josephfarina commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Hardening follow-up to the three enforcement-layer PRs (#4153 / #4154 / #4155, all merged). No behavior change — one clean resolution instead of three ad-hoc ones.

Rebased onto the CLI restructure. This PR originally targeted packages/cli/src/lib/, which no longer exists. It has been re-applied on top of the current foundation/ / api/ / clients/ layout; the leaf now lives beside its consumer at packages/cli/foundation/agent-docs/agent-doc-state.mjs.

Problem

isAstryxInitialized ("has this project run init?") backs all three foolproof layers, but each resolved it a different way:

  • Layer 2 (CLI postinstall) dynamically imports foundation/agent-docs/agent-docs.mjs — which drags its whole static graph (component discovery, package-manager detection, the response layer) into an npm-install-time context where only node builtins are guaranteed. It works today only because that graph currently happens to be builtins-only. The moment any module in it gains an external import, the import() throws, gets swallowed by the best-effort catch, and the nudge silently fires on already-initialized projects.
  • Layer 1 (core postinstall) hand-inlines its own copy of the paths + markers.
  • Layer 3 (per-command nudge) imports from agent-docs.mjs (fine at runtime).

The restructure made the first point worse, not better: that install-time graph is now 8 modules deep.

The one resolution

Extract the pure contract into a dependency-free leaf, packages/cli/foundation/agent-docs/agent-doc-state.mjs (node fs/path only): the agent-doc locations, markers, discoverAgentDocs, isAstryxInitialized.

  • agent-docs.mjs imports + re-exports it → init / upgrade, the layer-3 hook (clients/cli/index.mjs), and every existing test are unchanged.
  • The CLI postinstall imports the leaf → safe at install time by construction. Install-time surface drops from 8 modules to 1.
  • Core can't import the CLI (dependency cycle — the CLI peer-depends on core), so it keeps its one necessary mirror. That mirror is now exported and pinned to the leaf by a drift test, so the two can never silently diverge.

Verification

  • Install-time import graph measured before/after: agent-docs.mjs = 8 modules, agent-doc-state.mjs = 1, zero external imports.
  • The drift test is mutation-tested: adding a path to core's mirror and not the leaf turns it red with expected [...5] to deeply equal [...4].
  • postinstall, agent-docs, and setup-nudge suites: 110 passed.

@vercel

vercel Bot commented Jul 22, 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 3, 2026 5:24pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 22, 2026
@josephfarina
josephfarina marked this pull request as draft July 22, 2026 05:31
github-actions Bot added a commit that referenced this pull request Jul 22, 2026
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.


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

@josephfarina
josephfarina force-pushed the navi/vibe/unify-setup-check branch from bc9d54f to 369eabe Compare August 7, 2026 23:04
@josephfarina josephfarina changed the title astryx init foolproof: one dep-free source for the setup check (layers 1-3) refactor(cli,core): one dep-free source for the astryx-init setup check Aug 7, 2026
github-actions Bot added a commit that referenced this pull request Aug 11, 2026
@josephfarina
josephfarina marked this pull request as ready for review September 1, 2026 21:23

@cixzhang cixzhang 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—the install-time dependency reduction is good. The next setup-contract change can still give Core and CLI users contradictory nudges because packages/core/scripts/postinstall.mjs:28 remains a separately edited copy of the paths, markers, and predicate. The new guard checks constants and one happy path, so it does not prevent semantic drift. Could both package-local copies come from one authoritative source while preserving current output, legacy-marker handling, and zero-exit behavior?

[Reviewed by Robohands]

josephfarina and others added 3 commits September 3, 2026 10:19
isAstryxInitialized backs all three init-enforcement layers, but each
layer resolved it differently. The CLI postinstall dynamically imported
agent-docs.mjs, pulling an 8-module graph (component discovery,
package-manager detection, the response layer) into an npm-install-time
context where only node builtins are guaranteed. That works today only
because the graph happens to still be builtins-only; the first external
import anywhere in it makes the import() throw, get swallowed by the
best-effort catch, and the nudge fire on already-initialized projects.

Extract the contract into agent-doc-state.mjs, a leaf importing only
node fs/path: the agent-doc locations, markers, discoverAgentDocs, and
isAstryxInitialized. agent-docs.mjs re-exports it so init, upgrade, the
layer-3 nudge, and every existing test keep their import paths. The CLI
postinstall imports the leaf, cutting its install-time surface from 8
modules to 1.

Core can't import the CLI without a dependency cycle, so it keeps its
one necessary mirror. That mirror is now exported and pinned to the leaf
by a drift test, so the two copies can no longer silently disagree about
whether a project is set up.

Co-authored-by: Cursor <[email protected]>
MARKER_START moved into the imported leaf, and the generated declaration
types it as the literal '<!-- ASTRYX:START -->' rather than string. That
made `const lines = [MARKER_START]` infer an array of that one literal,
so every later push failed typecheck:strict with TS2345.

Co-authored-by: Cursor <[email protected]>
Core's postinstall hand-mirrored the agent-doc paths, the markers, the
isAstryxInitialized predicate and the shouldNudge matrix. The drift test
compared the two constant lists, so only a new path or a new marker was
caught; the predicate and the decision matrix could still diverge and leave
layer 1 and layer 2 disagreeing about "is this project set up?".

packages/core/scripts/agent-doc-state.mjs is now generated byte-for-byte from
packages/cli/foundation/agent-docs/agent-doc-state.mjs, which also gains
shouldNudge and the nudge string. check:setup-contract, wired into check:repo,
fails on any difference and on core dropping the file from "files".

Output, legacy-marker handling and zero-exit behaviour are unchanged.
@josephfarina
josephfarina force-pushed the navi/vibe/unify-setup-check branch from e1c2d67 to 47d35d8 Compare September 3, 2026 17:20
github-actions Bot added a commit that referenced this pull request Sep 3, 2026
@josephfarina
josephfarina dismissed cixzhang’s stale review September 3, 2026 18:22

Addressed in 47d35d8 (review was against ea56330). Core no longer hand-mirrors the setup contract: packages/core/scripts/agent-doc-state.mjs is generated byte-for-byte from the CLI leaf, shouldNudge and the nudge string moved into that one contract, and pnpm check:setup-contract (in check:repo) fails on any difference and on core dropping the file from files. Behaviour verified unchanged. Re-requesting review on the current head.

@josephfarina
josephfarina merged commit 7157187 into main Sep 3, 2026
27 checks passed
@github-actions
github-actions Bot deleted the navi/vibe/unify-setup-check branch September 4, 2026 06:23

This branch was successfully deployed

1 active deployment
Preview — 47d35d8a Deployed Sep 3, 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.

2 participants