feat(integrations): add Grok Build integration + Experimental ACP - #2772
feat(integrations): add Grok Build integration + Experimental ACP#2772antonvishal wants to merge 7 commits into
Conversation
|
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
All reported issues were addressed across 25 files
Architecture diagram
sequenceDiagram
participant CLI as Grok CLI (user CLI)
participant ACP as ACP Client (Stagehand)
participant AGENT as Grok Agent Process
participant FACE as Facade MCP Server (Stagehand)
participant STAGE as Stagehand Core
participant BROWSER as Browser
Note over CLI,ACP: User runs: pnpm --dir packages/integrations/grok-build start -- "task"
CLI->>ACP: runGrokBuild(instruction)
ACP->>ACP: Create disposable runtime (home, cwd, GROK_HOME, agent profile)
ACP->>AGENT: Spawn grok CLI with ACP stdio + restricted tools
ACP->>AGENT: ACP initialize
AGENT-->>ACP: Initialize response with auth methods
alt XAI_API_KEY exists
ACP->>AGENT: Authenticate via xai.api_key
else cached auth.json only
ACP->>AGENT: Authenticate via cached_token
end
ACP->>AGENT: session.new with Stagehand facade as only MCP server
AGENT->>FACE: Launch facade stdio server (via launcher binary)
FACE->>STAGE: Initialize Stagehand (lazily start browser)
STAGE->>BROWSER: Start persistent browser session
ACP->>AGENT: Prompt with task + Stagehand instructions
AGENT->>AGENT: Discover MCP tools (run, snapshot, screenshot)
AGENT->>ACP: Permission request for Stagehand tool
alt Tool is stagehand__run/snapshot/screenshot
ACP->>AGENT: Allow once
else Other tool (shell, file, etc.)
ACP->>AGENT: Reject or cancel
end
AGENT->>FACE: MCP tool call (e.g., stagehand__run)
FACE->>STAGE: Execute browser automation
STAGE->>BROWSER: Navigate, act, snapshot, screenshot
BROWSER-->>STAGE: Results
STAGE-->>FACE: Tool result
FACE-->>AGENT: Tool response
AGENT-->>ACP: Stream text messages (agent updates)
ACP-->>CLI: Final assistant response
Note over ACP,AGENT: On abort/signal
ACP->>AGENT: ACP session.cancel
ACP->>AGENT: SIGTERM to process tree
opt No graceful exit
ACP->>AGENT: SIGKILL to process tree
end
ACP->>ACP: Clean up disposable runtime directories
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 8 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Resolve overview.mdx conflicts to include both Grok Build and fx entries. Keep the screenshot base64 budget from browserbase#2791 alongside the ACP facade launcher changes. Also pass --max-screenshot-base64-bytes=60000 to the facade spawned by the ACP launcher so ACP transports get the same frame-cap protection as fx, mark BROWSERBASE_PROJECT_ID optional in the Grok Build README per browserbase#2777, and update the affected ACP arg assertions.
What
Adds a Grok Build example that can use Stagehand through the existing facade.
Grok Build exposes ACP rather than a TypeScript SDK for driving the agent, so this adds a small ACP runner under
integrations/core. The Grok-specific package only handles its CLI setup, authentication, and tool mapping.The ACP process runs with the user's existing Grok login or
XAI_API_KEY. The Stagehand MCP process receives only the environment variables it needs.Question for maintainers
I put the ACP runner in
integrations/corebecause it is not specific to Grok another ACP-compatible agent could use it by providing its own profile.Does that feel like the right place for it?
If ACP is something we want to support as an integration path, I can also add a general ACP docs page. For this PR, I kept the documentation focused on Grok Build.
Testing
pnpm checkSummary by cubic
Adds a Grok Build integration over ACP and a reusable ACP runner, giving one persistent Stagehand browser with
run,snapshot, andscreenshot. Applies the same 60KB base64 screenshot cap to the ACP facade path to align with other transports.@browserbasehq/stagehand-integrations/acpthat initializes/authenticates, mounts the Stagehand facade as the only MCP server, approves onlystagehand__run|snapshot|screenshot, cancels other tool requests and out-of-session prompts, and terminates the full agent process tree if unresponsive (including on Windows).STAGEHAND_*andBROWSERBASE_*plus minimal OS runtime vars reach the facade; host secrets likeXAI_API_KEYnever do. Forwards signals reliably and passes--max-screenshot-base64-bytes=60000to the facade.packages/integrations/grok-buildthat resolves@xai-official/grok, creates a disposable home/workspace and isolatedGROK_HOME, prefersXAI_API_KEYauth then cachedauth.jsonif available, deny-lists shell/file/subagent/plan/memory/web-search, and allowlistssearch_tool/use_toolto discover/invoke the Stagehand tools.BROWSERBASE_PROJECT_IDis optional.@agentclientprotocol/sdkand@xai-official/grok. To try locally: build@browserbasehq/stagehand-integrations, setXAI_API_KEY(or rungrok login), then run thepackages/integrations/grok-buildexample.Written for commit 6219756. Summary will update on new commits.