Skip to content

feat(protocol): share role and text locator contracts - #3190

Open
supremeboxlogos wants to merge 6 commits into
amel/role-text-locators-integrationfrom
amel/role-text-locators-protocol
Open

supremeboxlogos wants to merge 6 commits into
amel/role-text-locators-integrationfrom
amel/role-text-locators-protocol

Conversation

@supremeboxlogos

Copy link
Copy Markdown
Member

why

Give the SDKs one canonical locator query contract before introducing language-specific builders. Stacked on #3189. Approximately 1,060 changed lines, primarily generated contracts, with public SDK methods deliberately held for separate PRs.

what changed

  • Move the existing private query module into the protocol package; no duplicate extension schema or forwarding shim.
  • Generate the schema catalog and Python/Go option models from the canonical definitions.
  • Add Go's typed string-or-regex representation with strict JSON validation and non-mutating decode failures.
  • Switch extension imports, retaining type-only imports in browser code, and refresh the embedded ZIP.
  • Keep builders, language-specific API documentation, and public-builder tests out of this foundation.

test plan

  • 1,530 extension/protocol/docs/discovery tests passed; 10 existing todos.
  • 59 real-Chrome semantic-selector cases passed.
  • Python: 787 passed, 1 skipped; typecheck and generator freshness passed.
  • Go SDK/internal package tests and generator/archive freshness passed. Examples are standalone programs, not one compilable Go package.
  • Extension/protocol typechecks, extension/SDK builds, packaged attribution checks, and independent atomic-boundary review passed.

…t-locators-protocol

# Conflicts:
#	packages/sdk-go/internal/extensionassets/stagehand-extension.zip
@changeset-bot

changeset-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f74395e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 25 packages
Name Type
@browserbasehq/stagehand-protocol Minor
@browserbasehq/stagehand-extension Patch
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-python Patch
@browserbasehq/stagehand-go Patch
browse Patch
@browserbasehq/stagehand-examples Patch
@browserbasehq/stagehand-integrations-claude-cua-sdk Patch
@browserbasehq/stagehand-integrations Patch
@browserbasehq/eve Patch
@browserbasehq/stagehand-integrations-gemini-cua-sdk Patch
@browserbasehq/stagehand-integrations-example-pi-facade Patch
@browserbasehq/stagehand-integrations-claude-agent-sdk Patch
@browserbasehq/stagehand-integrations-example-claude-code-facade Patch
@browserbasehq/stagehand-integrations-codex-sdk Patch
@browserbasehq/stagehand-integrations-example-codex-facade Patch
@browserbasehq/stagehand-integrations-cursor-sdk Patch
@browserbasehq/stagehand-integrations-example-cursor-facade Patch
@browserbasehq/stagehand-integrations-deepagents-sdk Patch
@browserbasehq/stagehand-integrations-eve-sdk Patch
@browserbasehq/stagehand-integrations-fx-sdk Patch
@browserbasehq/stagehand-integrations-mastra-sdk Patch
@browserbasehq/stagehand-integrations-example-mastra-facade Patch
@browserbasehq/stagehand-integrations-pi-sdk Patch
@browserbasehq/stagehand-integrations-example-vercel-ai-facade Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 32 files

Confidence score: 3/5

  • build-json-rpc-schema.ts drops custom refinements, so generated SDKs can accept locator queries that decodeLocatorQuery rejects, including queries starting with nth or containing a nested semantic envelope. Preserve those refinements in the emitted schema.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/protocol/json-rpc/build-json-rpc-schema.ts">

<violation number="1" location="packages/protocol/json-rpc/build-json-rpc-schema.ts:64">
P2: The emitted schema drops `SemanticLocatorQuerySchema`'s custom refinements, so generated SDK models accept queries starting with `nth` or selectors containing a nested semantic envelope that `decodeLocatorQuery` rejects. Preserve these invariants in the published schema so generated models reflect the query contract.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant Ext as Extension
    participant Proto as Protocol Package
    participant SDKTs as TS SDK
    participant SDKPy as Python SDK
    participant SDKGo as Go SDK
    participant Gen as Generator

    Note over Ext,Proto: NEW: Shared Locator Query Contract
    Ext->>Proto: Import decodeLocatorQuery/encodeLocatorQuery
    Ext->>Proto: Import QueryStep/TextPattern types
    Proto-->>Ext: Canonical query contract

    Note over Proto: NEW: Schema generation
    Proto->>Proto: Generate stagehand.v4.json locator_builder_models
    Proto->>Proto: Export ./locator-query subpath

    Note over SDKPy: NEW: Generated Python models
    Proto-->>SDKPy: Schema catalog
    SDKPy->>SDKPy: Generate AriaRole, GetByRoleOptions, GetByTextOptions
    SDKPy->>SDKPy: Generate QueryStep, TextPattern, SemanticLocatorQuery
    SDKPy->>SDKPy: WireModel with extra="forbid" validation

    Note over SDKGo: NEW: Generated Go models
    Proto-->>SDKGo: Schema catalog
    SDKGo->>SDKGo: Generate typed structs with omitempty
    SDKGo->>SDKGo: NEW: TextMatch string-or-regex type
    SDKGo->>SDKGo: Strict JSON validation on unmarshal
    SDKGo->>SDKGo: Non-mutating decode failures

    Note over Ext: CHANGED: Import path relocation
    Ext->>Ext: Switch to protocol package imports
    Ext->>Ext: Generate embedded ZIP refresh

    Note over Gen: NEW: Include locator models
    SDKGo->>Gen: reachableDefinitions includes locator_builder_models
    Gen-->>SDKGo: Generate model catalog entries
    Gen-->>SDKPy: Generate model classes

    alt SDK Go encoding TextMatch
        SDKGo->>SDKGo: Marshal literal string or regex object
    else SDK Go decoding TextMatch
        SDKGo->>SDKGo: Validate strict shape without mutation
    end

    Note over Ext,SDKGo: Runtime usage in semantic selectors
    Ext->>Ext: encodeLocatorQuery to wire format
    Ext->>Ext: decodeLocatorQuery from wire format
    Ext-->>SDKTs: Shared contract for integration tests
Loading

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

.strictObject({
roleOptions: GetByRoleOptionsSchema,
textOptions: GetByTextOptionsSchema,
query: SemanticLocatorQuerySchema,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The emitted schema drops SemanticLocatorQuerySchema's custom refinements, so generated SDK models accept queries starting with nth or selectors containing a nested semantic envelope that decodeLocatorQuery rejects. Preserve these invariants in the published schema so generated models reflect the query contract.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/protocol/json-rpc/build-json-rpc-schema.ts, line 64:

<comment>The emitted schema drops `SemanticLocatorQuerySchema`'s custom refinements, so generated SDK models accept queries starting with `nth` or selectors containing a nested semantic envelope that `decodeLocatorQuery` rejects. Preserve these invariants in the published schema so generated models reflect the query contract.</comment>

<file context>
@@ -52,6 +57,13 @@ const StagehandProtocolDocumentSchema = z
+      .strictObject({
+        roleOptions: GetByRoleOptionsSchema,
+        textOptions: GetByTextOptionsSchema,
+        query: SemanticLocatorQuerySchema,
+      })
+      .optional(),
</file context>

Comment thread packages/sdk-go/text_match.go Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant