feat: add Stagehand code-mode guidance - #2620
Open
shrey150 wants to merge 18 commits into
Open
Conversation
|
This was referenced Aug 6, 2026
shrey150
marked this pull request as ready for review
August 6, 2026 08:57
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 9 files
Architecture diagram
sequenceDiagram
participant Agent as AI Agent
participant MCP as MCP Server
participant Executor as Code Executor
participant GenScript as generate-codemode-content.mjs
participant Markdown as codemode/*.md
participant Bundle as generated-content.ts
participant Package as @browserbasehq/stagehand-integrations
participant Consumer as Downstream Package
participant Test as Test Suite
Note over Agent,Test: Build-time guidance generation
GenScript->>Markdown: Read SKILL.md & REFERENCE.md
GenScript->>GenScript: Escape special characters (\, quotes, tabs)
GenScript->>Bundle: Write STAGEHAND_CODEMODE_SKILL & STAGEHAND_CODEMODE_REFERENCE
alt --check flag
GenScript->>Bundle: Compare generated content
alt Content stale
GenScript-->>Build: Throw error (block build)
else Content current
GenScript-->>Build: Pass
end
end
Note over Agent,Test: Package exports
Package->>Consumer: Export raw ./codemode/SKILL.md
Package->>Consumer: Export raw ./codemode/REFERENCE.md
Package->>Consumer: Export STAGEHAND_CODEMODE_SKILL
Package->>Consumer: Export STAGEHAND_CODEMODE_REFERENCE
Note over Agent,Test: Runtime MCP tool description
Agent->>MCP: Discover available tools
MCP->>Executor: Load tool definitions
Executor->>Bundle: Import STAGEHAND_CODEMODE_SKILL
Executor->>Executor: Append skill to code_execute description
MCP-->>Agent: Return tool list (with code_execute + guidance)
Agent->>MCP: Call code_execute({ code: "..." })
MCP->>Executor: Execute async function body
Executor-->>MCP: Return result
MCP-->>Agent: Return execution result
Note over Agent,Test: Test validation
Test->>Bundle: Import STAGEHAND_CODEMODE_SKILL
Test->>Markdown: Read raw SKILL.md
Test->>Test: Compare byte parity
Test->>Package: Resolve @browserbasehq/stagehand-integrations/codemode/SKILL.md
Test->>Test: Verify package export resolution
Test->>Executor: Check CODE_EXECUTE_DESCRIPTION ends with skill
Test->>GenScript: Run with --check on fixture
alt Content matches
Test-->>Test: Pass
else Content stale
Test-->>Test: Expect error
end
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
This was referenced Aug 6, 2026
miguelg719
added a commit
that referenced
this pull request
Aug 9, 2026
## Why The code-mode product work spans three distinct review domains: process hosting, browser code execution, and agent guidance. This bottom PR isolates the package and Model Context Protocol (MCP) host so its build, transport, and shutdown behavior can be reviewed without the execution engine or prompt content. ## Stack 1. **This PR:** private package, MCP stdio host, lifecycle, repository build/test wiring 2. #2619: Stagehand executor, local and Browserbase configuration, schemas, queueing, and `code_execute` registration 3. #2620: `SKILL.md`, `REFERENCE.md`, generated exports, package assets, and guidance loading checks 4. [#2626](#2626) — Vercel AI SDK MCP example and smoke flows 5. [#2627](#2627) — Mastra MCP example and smoke flows 6. [#2628](#2628) — CrewAI MCP example and smoke flows 7. [#2629](#2629) — LangChain Deep Agents MCP example and smoke flows Each PR is intended to build, test, and make a truthful claim independently. ## What changed - adds the private `@browserbasehq/stagehand-integrations` workspace package - adds a compiled stdio entrypoint backed by the MCP SDK - negotiates MCP server metadata without advertising capabilities that do not exist yet - bounds concurrent shutdown cleanup to five seconds - preserves conventional process exit codes for `SIGINT` and `SIGTERM` - wires the package into workspace, Turbo, Vitest, and CI discovery ## Intentionally not included - no MCP tools - no browser or model configuration - no Stagehand executor - no skill or reference content - no published package surface; the package remains private ## E2E Test Matrix | Command / flow | Observed output | Confidence / sufficiency | | --- | --- | --- | | `pnpm --filter @browserbasehq/stagehand-integrations typecheck && pnpm --filter @browserbasehq/stagehand-integrations build && pnpm --filter @browserbasehq/stagehand-integrations test:unit` | Package typecheck and build passed; 3 test files and 9 tests passed. | Covers host construction, bounded cleanup, compiled stdio startup, end-of-file shutdown, and signal exit codes. It intentionally does not prove a tool or browser session. | | Manual MCP client connected to the compiled stdio entrypoint | `{"initialized":true,"toolsCapability":null,"readyMessage":true}` | Proves the built artifact starts as a child process, negotiates MCP, emits its readiness message, and truthfully advertises no tools. | | `pnpm exec turbo run test:unit --filter=@browserbasehq/stagehand-integrations` | 2/2 Turbo tasks passed; package build plus 9/9 tests passed. | Proves the repository task graph builds the package before compiled-child tests. | | `pnpm check` | 9/9 repository tasks passed. | Supports repository-wide formatting, lint, and type compatibility for this layer. | ## Changeset None. This introduces a private workspace package and does not publish a release. --------- Co-authored-by: miguel <miguelg71921@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
This third stack layer distributes the canonical instructions an agent needs to use
code_executewell. It stays separate from the execution engine so reviewers can evaluate prompt content, generated-code integrity, package loading, and distribution without re-reviewing browser lifecycle code.Stack
code_execute, Stagehand executor, local/Browserbase configuration, schemas, and runtime testsSKILL.md,REFERENCE.md, generated exports, package assets, and guidance loading checksWhat changed
SKILL.mdused as the tool-facing agent guideREFERENCE.mdfor Stagehand, page, context, event, and schema lookupcode_executeMCP descriptionLoading paths
Consumers can use either representation without reading repository source files:
@browserbasehq/stagehand-integrations/codemode/SKILL.md@browserbasehq/stagehand-integrations/codemode/REFERENCE.mdSTAGEHAND_CODEMODE_SKILLandSTAGEHAND_CODEMODE_REFERENCEcode_executetool descriptionIntentionally not included
E2E Test Matrix
pnpm --filter @browserbasehq/stagehand-integrations typecheck && pnpm --filter @browserbasehq/stagehand-integrations test{"status":"PASS","rawSkill":true,"rawReference":true,"bundledGuidance":true,"runtimeFilesystemDependency":false}code_executewas discovered, its description ended with the generated skill, and a real navigation returned the expected title and URL.pnpm exec turbo run fmt:check lint typecheck --concurrency=1Changeset
None. This changes a private workspace package and does not publish a release.