feat: add Stagehand code-mode guidance - #2620
Open
shrey150 wants to merge 6 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
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.