Skip to content

feat(cli): add Astro framework support#242

Open
ardasoyturk wants to merge 5 commits intoaidenybai:mainfrom
ardasoyturk:feat/astro-support
Open

feat(cli): add Astro framework support#242
ardasoyturk wants to merge 5 commits intoaidenybai:mainfrom
ardasoyturk:feat/astro-support

Conversation

@ardasoyturk
Copy link

@ardasoyturk ardasoyturk commented Mar 14, 2026

Summary

Add full Astro framework support to React Grab's init command. Closes #224

Features Implemented

  • Astro Detection: Automatically detects Astro projects by checking for the astro package in devDependencies
  • Layout File Discovery: Finds Astro layout files in common locations (src/layouts/, layouts/, src/pages/)
  • Code Injection: Injects React Grab initialization code into the <head> tag of Astro layout files
  • Agent Support: Full support for adding and removing AI agents (MCP, Claude Code, Cursor, etc.)
  • Options Configuration: Support for configuring React Grab options in Astro projects
  • Existing Configuration Detection: Detects if React Grab is already installed in Astro projects

How It Works

For Astro projects, React Grab is initialized using dynamic imports that only run in development mode:

{import.meta.env.DEV && (
  <script>
    if (import.meta.env.DEV) {
      import("react-grab");
      import("@react-grab/mcp/client");
    }
  </script>
)}

Usage

# Initialize in an Astro project
npx -y grab@latest init

# Add a specific agent
npx -y grab@latest init --agent mcp

Note

Medium Risk
Adds a new supported framework path that detects Astro projects and rewrites .astro layout/page files to inject/remove scripts and update options; mistakes could lead to incorrect code injection or missed configs in user projects.

Overview
Adds Astro as a first-class supported framework in the CLI init flow, including updated user-facing messaging and removal of Astro from the unsupported-framework list.

Extends project detection and React Grab presence checks to recognize Astro projects (including prioritizing astro over vite) and to scan common .astro layout/page locations.

Implements Astro-specific transforms to inject a dev-only <script> into an .astro file’s <head>, plus support for adding/removing agents and updating options by rewriting the dynamic import("react-grab") block; includes new tests covering Astro detection and precedence.

Written by Cursor Bugbot for commit 84d7195. This will update automatically on new commits. Configure here.


Summary by cubic

Adds Astro support to the CLI init flow so astro projects auto-detect, inject a dev-only setup, and manage agents/options. Also fixes detection precedence and improves Astro transforms, including --force handling and consistent indentation.

  • New Features

    • Detects astro projects and treats Astro as a supported framework in init.
    • Injects a dev-only <script> into <head> of common .astro layout files to load react-grab (and @react-grab/<agent>/client when selected).
    • Adds/removes agents and updates options in .astro files; detects existing setup to avoid duplicates.
    • Updates templates/transforms/tests and removes Astro from the unsupported list.
  • Bug Fixes

    • Prioritizes astro over vite in detection to avoid misidentification (with a test to prevent regression).
    • Places agent import next to the existing react-grab import; escapes regex for agent package during removal.
    • Updates options by matching the full .then((m) => m.init(...)) block.
    • Finds the .astro file that contains react-grab and continues scanning files if already configured.
    • Adds Astro to the supported frameworks message when detection fails.
    • Fixes --force guard behavior and ensures consistent indentation when injecting Astro script.

Written for commit 84d7195. Summary will update on new commits.

- Add Astro detection in detectFramework() and detectReactGrab()
- Add transformAstro() for injecting React Grab code into Astro layouts
- Add findAstroLayoutFile() and findAllAstroLayoutFile() to locate layout files
- Add addAgentToExistingAstro() and removeAgentFromAstro() for agent management
- Add addOptionsToAstroScript() for options configuration
- Add ASTRO_EFFECT and ASTRO_EFFECT_WITH_AGENT templates
- Update FRAMEWORK_NAMES to include Astro
- Remove Astro from UNSUPPORTED_FRAMEWORK_NAMES
- Update tests for Astro support
@pullfrog
Copy link
Contributor

pullfrog bot commented Mar 14, 2026

Error

agent completed without reporting progress

Pullfrog  | Rerun failed job ➔View workflow run | Triggered by Pullfrogpullfrog.com𝕏

@vercel
Copy link
Contributor

vercel bot commented Mar 14, 2026

@ardasoyturk is attempting to deploy a commit to the Million Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f715dfd58

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 issues found across 5 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/cli/test/detect.test.ts">

<violation number="1" location="packages/cli/test/detect.test.ts:53">
P2: Missing priority test for Astro vs Vite detection. Since `detectFramework` checks for `vite` before `astro` in the implementation, Astro projects with both dependencies would be misidentified as Vite. A test like "should prioritize Astro over Vite if both are present" should be added to match the existing Next.js vs Vite priority test.</violation>
</file>

<file name="packages/cli/src/utils/transform.ts">

<violation number="1" location="packages/cli/src/utils/transform.ts:809">
P1: addAgentToExistingAstro duplicates the React Grab initialization instead of appending only the agent import. When adding an agent to an existing Astro React Grab configuration, the function inserts the entire ASTRO_EFFECT_WITH_AGENT template (which includes both `import("react-grab")` and `import("@react-grab/${agent}/client")`) after the `<head>` tag, creating a duplicate `import("react-grab")`. When the agent is later removed via `removeAgentFromAstro`, only the agent import is removed, leaving the duplicate react-grab import permanently. This differs from the correct implementation in `addAgentToExistingVite`, `addAgentToExistingWebpack`, and `addAgentToExistingTanStack`, which find the existing react-grab import and append only the agent import.</violation>

<violation number="2" location="packages/cli/src/utils/transform.ts:869">
P2: When `reactGrabAlreadyConfigured` is true but the current file doesn't contain React Grab code, the loop falls through and injects a new full script block into this file instead of continuing to search for the file that already has the configuration. This can create a duplicate config block in the wrong file. Add a `continue` when `reactGrabAlreadyConfigured` is true but `hasReactGrabInFile` is false.</violation>

<violation number="3" location="packages/cli/src/utils/transform.ts:1287">
P2: `findReactGrabFile` for Astro returns the first existing layout file, but `transformAstro` skips files without a `<head>` tag and installs React Grab in the first file that *has* one. If the first layout file exists but lacks `<head>`, React Grab gets installed in a later file, while this function still returns the first file. Subsequent options or agent-removal operations then target the wrong file. This should find the file that actually contains the React Grab code.</violation>

<violation number="4" location="packages/cli/src/utils/transform.ts:1450">
P2: The regex for matching an existing `.then(...)` block only captures up to the inner closing `)` of `m.init(...)` but misses the outer `)` of `.then(...)`. When re-applying options, the replacement leaves a dangling `)` in the output, producing invalid syntax. The `[^}]*\}\s*\)` portion needs an additional `\s*\)` to capture the `.then(` closing parenthesis.</violation>
</file>

<file name="packages/cli/src/utils/detect.ts">

<violation number="1" location="packages/cli/src/utils/detect.ts:76">
P1: The `astro` check is placed after the `vite` check, but Astro uses Vite internally (and as of Astro v6, `vite` can appear as a peer dependency in the user's `package.json`). When both `vite` and `astro` are listed, the project will be misidentified as Vite. Move the `astro` check before the `vite` check, consistent with how more-specific frameworks (e.g., `@tanstack/react-start`) are already checked before `vite`.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

- Move Astro detection before Vite to fix misidentification
- Fix addAgentToExistingAstro to only add agent import, not full block
- Fix addOptionsToAstroScript regex to match full .then() block
- Fix findReactGrabFile to find file with React Grab code
- Continue scanning Astro files when reactGrabAlreadyConfigured is true
];

return possiblePaths.filter((filePath) => existsSync(filePath));
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated Astro layout path lists across files

Low Severity

The same 13 Astro layout file paths are hardcoded in both findAllAstroLayoutFiles in transform.ts and detectReactGrab in detect.ts, but in different order. These duplicate lists can easily drift out of sync. A shared constant or utility function would avoid this maintenance risk.

Additional Locations (1)
Fix in Cursor Fix in Web

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to change the constants.ts file for this reason and left the issue as is.

- Add regex escaping for agent package in removeAgentFromAstro
- Add Astro to supported frameworks error message
originalContent,
newContent,
};
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Astro functions duplicate existing Vite implementations verbatim

Low Severity

addOptionsToAstroScript is an exact duplicate of addOptionsToViteScript, removeAgentFromAstro is identical to removeAgentFromVite, and addAgentToExistingAstro is functionally identical to addAgentToExistingVite. All three share the same regex, logic, and replacement strategy. This triples the maintenance surface — a bug fix in one copy risks being missed in the others.

Additional Locations (2)
Fix in Cursor Fix in Web

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

matchedText,
`${hasSemicolon ? matchedText.slice(0, -1) : matchedText};
${agentImport}`,
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent addition corrupts import when options already configured

Medium Severity

The regex in addAgentToExistingAstro/import\s*\(\s*["']react-grab["']\s*\);?/ — only matches the import("react-grab") portion of a chained expression. If options were previously configured (turning the import into import("react-grab").then((m) => m.init({...}))), the replacement splits the .then() chain away from the react-grab import and leaves it dangling after the newly inserted agent import line, producing broken JavaScript.

Fix in Cursor Fix in Web

if (newContent === originalContent) {
return {
success: false,
filePath,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple framework-specific functions (Vite, Webpack, Astro) are functionally identical or nearly identical, violating the DRY principle and creating maintenance burden

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No support for astro

1 participant