Contributing Guide
Relevant source files
The following files were used as context for generating this wiki page:
This guide provides instructions and best practices for contributing to the React Grab project. React Grab is an open-source tool designed to select context for coding agents directly from your website, and contributions from the community are welcome. This document covers setting up the development environment, understanding the project structure, following the development workflow, and adhering to code style and submission guidelines.
By following these guidelines, you can help maintain the quality and consistency of the codebase. For community discussion and support, you can join the project's Discord or check the existing issues.
Sources: CONTRIBUTING.md:3-4, README.md:310-314
Getting Started
To begin contributing, you need to set up the development environment on your local machine. This involves meeting prerequisites, cloning the repository, and installing dependencies.
Sources: CONTRIBUTING.md:6-7
Prerequisites
Ensure you have the following software installed on your system:
- Node.js version 18 or higher
- pnpm version 8 or higher
Sources: CONTRIBUTING.md:10-11
Setup Workflow
The initial setup involves forking and cloning the repository, installing dependencies with ni (from @antfu/ni), and building all the packages.
Sources: CONTRIBUTING.md:13-25
The following diagram illustrates the setup process:
Sources: CONTRIBUTING.md:15-25
The specific commands are:
- Fork and clone the repository:
git clone https://github.com/YOUR_USERNAME/react-grab.git cd react-grab - Install dependencies:
ni - Build all packages:
nr build - Start development mode:
nr dev
Sources: CONTRIBUTING.md:15-25
Project Structure
The react-grab repository is a monorepo managed with pnpm workspaces. The core logic, CLI, agent providers, and documentation are organized into separate packages within the packages/ directory.
Sources: CONTRIBUTING.md:27-28
The following diagram shows the high-level structure of the monorepo:
Sources: CONTRIBUTING.md:29-44
Key Packages
The table below describes the purpose of the main packages in the repository.
| Package | Description |
|---|---|
react-grab/ | The core library for element selection and context grabbing. |
cli/ | The CLI installer (@react-grab/cli) for easy project integration. |
provider-* | A collection of packages for integrating with various coding agents like Cursor, Claude, and Gemini. |
website/ | The documentation and marketing site available at react-grab.com. |
*-playground/ | Development environments (Vite, Next.js, Agent) for testing changes. |
benchmarks/ | Contains code for performance benchmarks. |
web-extension/ | The browser extension for React Grab. |
Sources: CONTRIBUTING.md:29-44
The grab package is a special case; its build process involves copying distribution files from react-grab and transforming the README.md to rebrand it as grab. This is handled by a build script.
Sources: packages/grab/scripts/build.js:1-103
Development Workflow
The development process involves making changes, testing them in isolated playgrounds, running automated tests, and ensuring code quality through linting and formatting.
Sources: CONTRIBUTING.md:46-47
Running Playgrounds
To test your changes in a live environment, you can use one of the provided playgrounds. Each playground is tailored for a specific framework or use case.
- Vite Playground:
pnpm --filter vite-playground dev - Next.js Playground:
pnpm --filter next-playground dev - Agent Playground:
pnpm --filter @react-grab/agent-playground dev:<agent_name>(e.g.,dev:claude,dev:cursor)
The agent playground, which runs at http://localhost:5174, is specifically for testing integrations with different agent provider backends.
Sources: CONTRIBUTING.md:49-64
Running Tests
Automated tests are available for certain packages, such as the CLI. Tests are written using vitest.
- Run CLI tests:
pnpm --filter @react-grab/cli test
Sources: CONTRIBUTING.md:66-68, packages/cli/test/diff.test.ts
Linting & Formatting
The project uses ESLint for linting and Prettier for code formatting.
- Check for lint errors:
nr lint - Fix lint errors:
nr lint:fix - Format code:
nr format
Sources: CONTRIBUTING.md:70-74
Code Style and Conventions
All contributions must adhere to the project's code style and conventions to maintain consistency and readability.
Sources: CONTRIBUTING.md:76, AGENTS.md
General Rules
The following table summarizes the main coding style rules.
| Rule | Description |
|---|---|
| Interfaces over Types | Use TypeScript interface instead of type for object shapes. |
| Arrow Functions | Prefer arrow functions over function declarations. |
| File Naming | Use kebab-case for all file names. |
| Variable Naming | Use descriptive variable names (e.g., innerElement instead of el). |
| Type Casting | Avoid type casting (as) unless absolutely necessary. |
| Type Scope | Keep interfaces and types at the global scope. |
| Comments | Avoid comments unless explaining a necessary hack, prefixed with // HACK:. |
| DRY Principle | Remove unused code and avoid repetition. |
Sources: CONTRIBUTING.md:77-89, AGENTS.md:4-15
UI and Accessibility Guidelines
The project also enforces strict rules for UI, interactions, and accessibility to ensure a high-quality user experience. Key mandates include:
- Full Keyboard Support: All interactive components must be fully keyboard-accessible per WAI-ARIA APG.
- Visible Focus: Focus rings must be visible using
:focus-visible. - Hit Targets: Minimum hit target size is
24px(or44pxon mobile). - State in URL: Application state (filters, tabs, etc.) must be reflected in the URL.
- Reduced Motion: Animations must respect the
prefers-reduced-motionuser preference. - Semantic HTML: Prefer native elements (
<button>,<a>) before using ARIA roles.
Sources: packages/website/AGENTS.md:4-10, packages/website/AGENTS.md:40-41, packages/website/AGENTS.md:52-53, packages/website/AGENTS.md:88-89
Submitting Changes
Once your changes are complete and tested, you can submit them for review by creating a pull request.
Sources: CONTRIBUTING.md:91
Pull Request Workflow
The following diagram shows the process for submitting a pull request:
Sources: CONTRIBUTING.md:93-97
Commit Convention
This project uses Conventional Commits. This helps in generating automated changelogs and makes the commit history more readable.
| Prefix | Description |
|---|---|
feat: | A new feature. |
fix: | A bug fix. |
docs: | Documentation changes only. |
chore: | Maintenance tasks (e.g., dependency updates). |
refactor: | A code change that neither fixes a bug nor adds a feature. |
test: | Adding missing tests or correcting existing tests. |
Sources: CONTRIBUTING.md:99-106
Adding a Changeset
For any changes that affect the functionality or API of a published package, you must add a changeset. This is crucial for versioning and generating accurate changelogs.
To add a changeset, run the following command and follow the prompts:
nr changeset
Sources: CONTRIBUTING.md:108-112
License
By contributing to React Grab, you agree that your contributions will be licensed under the MIT License.
Sources: CONTRIBUTING.md:127-128