CLI Command: `start`
Relevant source files
The following files were used as context for generating this wiki page:
The react-grab ecosystem provides a mechanism to start local servers for various coding agent integrations. This enables a "visual edit" workflow where the browser can communicate directly with an agent to modify the codebase. The main @react-grab/cli package includes a start command for this purpose.
However, the primary and recommended method for managing these agent provider servers is through the grab init command, which automatically configures a project's package.json to launch the required services as part of the standard development workflow (e.g., npm run dev). This document covers the overall architecture of starting agent providers.
Sources: packages/cli/src/cli.ts:25, packages/cli/src/commands/init.ts, packages/website/app/blog/agent/page.tsx:200-209
Agent Integration Architecture
The agent integration feature is built on a client-server model. The react-grab script running in the browser acts as the client. When a user initiates an edit, the client sends the element context (component stack, file paths, etc.) and the user's prompt to a local server. This local server, specific to the chosen agent provider, acts as an adapter, forwarding the request to the agent's actual CLI or SDK, which then performs the code modifications.
Sources: packages/website/app/blog/agent/page.tsx:646-663
The following diagram illustrates the data flow from the browser to the codebase.
Setup via grab init
The grab init command is the primary tool for setting up and managing agent integrations. It automates the process of installing necessary packages and modifying project configuration.
When run, grab init performs the following steps:
- Detects the project's framework (Next.js, Vite, etc.) and package manager.
- Prompts the user to select an agent integration if not specified via flags.
- Previews the required changes to
package.jsonand relevant layout files (e.g.,app/layout.tsx). - Upon confirmation, installs the required agent provider and core
react-grabpackages. - Applies the transformations to the project files.
A key modification is chaining the agent provider's CLI command into the dev script in package.json. This ensures the agent's local server starts automatically with the development server.
Sources: packages/cli/src/commands/init.ts
init Command Flow
This diagram shows the sequence of actions performed by the grab init command.
Example package.json Modification
After running grab init and selecting the Cursor integration, the scripts section of package.json is modified to automatically start the Cursor provider server.
{
"scripts": {
"dev": "npx @react-grab/cursor@latest && next dev"
}
}
Sources: packages/website/app/blog/agent/page.tsx:325-331, README.md:143-149
Agent Provider Scripts
Different coding agents are supported through individual provider packages. Each provider runs a local server on a specific port and has its own CLI that is executed by npx. The grab init command handles the setup for these providers.
| Agent | Package | package.json Command | Default Port |
|---|---|---|---|
| Claude Code | @react-grab/claude-code | npx @react-grab/claude-code@latest | 4567 |
| Cursor | @react-grab/cursor | npx @react-grab/cursor@latest | 5567 |
| OpenCode | @react-grab/opencode | npx @react-grab/opencode@latest | 6567 |
| Codex | @react-grab/codex | npx @react-grab/codex@latest | 7567 |
| Gemini | @react-grab/gemini | npx @react-grab/gemini@latest | 8567 |
| Amp | @react-grab/amp | npx @react-grab/amp@latest | 9567 |
| Factory Droid | @react-grab/droid | npx @react-grab/droid@latest | 10567 |
| Visual Edit | (Integrated) | npx grab@latest init (select option) | N/A |
Sources: packages/website/app/blog/agent/page.tsx:223-616, README.md:122-421, packages/cli/src/commands/init.ts:402-416
The start Command
The main CLI executable, react-grab, registers a start command.
// packages/cli/src/cli.ts
// ...
program.addCommand(start);
// ...
Sources: packages/cli/src/cli.ts:25
While the specific implementation of the start command is not detailed in the provided source files, its purpose can be inferred from the overall architecture. It likely serves as a manual method to launch the agent provider servers, possibly by detecting which agents are installed and starting the corresponding services. This would be an alternative to the automated approach configured by the grab init command, which integrates the server startup into the project's existing dev script.
Summary
The react-grab ecosystem facilitates direct-from-browser code editing by starting local agent provider servers. While the main CLI includes a start command, the standard and automated method for managing these servers is to use grab init. This command intelligently modifies the project's package.json to chain the necessary provider CLI commands with the existing development server script, creating a seamless and integrated workflow for developers.
Sources: packages/cli/src/cli.ts, packages/cli/src/commands/init.ts