Repository navigation
refactor(cli,core): one dep-free source for the astryx-init setup check - #4162
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
bc9d54f to
369eabe
Compare
cixzhang
left a comment
There was a problem hiding this comment.
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]
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.
e1c2d67 to
47d35d8
Compare
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.
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.
Problem
isAstryxInitialized("has this project runinit?") backs all three foolproof layers, but each resolved it a different way: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, theimport()throws, gets swallowed by the best-effortcatch, and the nudge silently fires on already-initialized projects.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(nodefs/pathonly): the agent-doc locations, markers,discoverAgentDocs,isAstryxInitialized.agent-docs.mjsimports + re-exports it →init/upgrade, the layer-3 hook (clients/cli/index.mjs), and every existing test are unchanged.Verification
agent-docs.mjs= 8 modules,agent-doc-state.mjs= 1, zero external imports.expected [...5] to deeply equal [...4].postinstall,agent-docs, andsetup-nudgesuites: 110 passed.