Skip to content

evals: declare the cdp_code agent mount - #2595

Merged
miguelg719 merged 1 commit into
stg-2671-playwright-code-exposurefrom
stg-2671-cdp-code-exposure
Aug 9, 2026
Merged

evals: declare the cdp_code agent mount#2595
miguelg719 merged 1 commit into
stg-2671-playwright-code-exposurefrom
stg-2671-cdp-code-exposure

Conversation

@shriyatheunicorn

@shriyatheunicorn shriyatheunicorn commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Same shape as #2592 for the CDP surface: prompt instructions carried
over verbatim, code_handles declaration, captureEvidence() for the
terminal screenshot, URL, and aria tree. Behavior is unchanged until the
adapter consumes mounts generically in #2596.

Part of the nondeterministic-evals stack (#2591#2611).


Summary by cubic

Expose cdp_code as an LLMExposure with an agent-mountable cdp runtime, clearer prompt instructions, and richer final-state evidence. Linked to Linear STG-2671 (part 5/6). Requires the LLMExposure contract (1/6).

  • New Features
    • Agent mount: handles.cdp; prompt includes AGENT_RUN_TOOL_NAME, a first navigate/load recipe, run-tool description and code param, and a deny message; captureEvidence collects screenshot, URL, and ariaTree.
    • Runtime: send/browser plus on/off/once/waitForEvent/wait with session scoping, timeouts, safe teardown, and unhandled-rejection guards; exposes targetId/sessionId; createAgentRuntime(logger) initializes it.
    • Representation: adds representation capability; page.represent() returns the accessibility tree with metadata; evidence includes ariaTree.
    • Page management: syncPages keeps session pages current before listPages/activePage; bootstrap only creates a target if none exist.

Written for commit e641edf. Summary will update on new commits.

Review in cubic

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e641edf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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.

All reported issues were addressed across 1 file

Architecture diagram
sequenceDiagram
    participant Eval as Eval Harness
    participant LLMExp as prepareLLMExposure()
    participant Target as prepareCoreBrowserTarget()
    participant CDPCon as CdpConnection
    participant CDP as CDP Browser
    participant Agent as Claude Code Agent

    Note over Eval,Agent: Runtime Flow: cdp_code LLMExposure

    Eval->>LLMExp: prepareLLMExposure(plan, env, logger, startupProfile?)
    LLMExp->>LLMExp: Resolve startup profile (runner_provided_local_cdp | runner_provided_browserbase_cdp)
    alt Invalid profile
        LLMExp->>Eval: Throw EvalsError
    end

    LLMExp->>Target: prepareCoreBrowserTarget({env, toolSurface, startupProfile})
    Target-->>LLMExp: {cleanup, providedEndpoint, metadata?}

    alt Missing endpoint
        LLMExp->>Eval: Throw EvalsError
    end

    LLMExp->>CDPCon: CdpConnection.connect(providedEndpoint)
    CDPCon-->>LLMExp: connection

    LLMExp->>LLMExp: attachActiveCdpPage(connection)
    LLMExp-->>LLMExp: {targetId, sessionId, url}

    LLMExp->>LLMExp: Log init metadata (targetId, sessionId, etc.)

    Note over LLMExp: Build CdpRuntime object

    LLMExp-->>Eval: LLMExposure {kind: "code_handles", handles: {cdp}, promptInstructions, runTool, captureFinalState, cleanup}

    Eval->>Agent: Exposure with runTool + handles

    Note over Agent: Agent executes JavaScript via runTool

    Agent->>Agent: cdp.send("Page.navigate", {url: startUrl})
    Agent->>Agent: cdp.waitForEvent("Page.loadEventFired")
    Agent->>Agent: cdp.send(Page commands...)
    Agent->>CDP: Page-scoped CDP commands
    CDP-->>Agent: Responses

    alt Browser-level commands
        Agent->>CDP: cdp.browser(Browser commands...)
        CDP-->>Agent: Responses
    end

    Note over Agent: Event handling
    Agent->>Agent: cdp.on(method, listener)
    Agent->>Agent: cdp.once(method)
    Agent->>Agent: cdp.waitForEvent(method, timeout)

    Note over Agent,LLMExp: Final state capture

    Eval->>LLMExp: captureFinalState()
    LLMExp->>CDP: Page.captureScreenshot
    alt Success
        CDP-->>LLMExp: Screenshot data
        LLMExp-->>LLMExp: Buffer.from(shot.data, "base64")
    else Failure
        LLMExp-->>LLMExp: Best-effort skip
    end

    LLMExp->>CDP: Runtime.evaluate({expression: "location.href"})
    alt Success
        CDP-->>LLMExp: URL value
    else Failure
        LLMExp-->>LLMExp: Best-effort skip
    end
    LLMExp-->>Eval: {screenshot?, url?}

    Note over Eval,LLMExp: Cleanup

    Eval->>LLMExp: cleanup()
    LLMExp->>CDPCon: connection.close()
    CDPCon-->>LLMExp: Closed
    LLMExp->>LLMExp: targetCleanup()

    Note over LLMExp: Error handling during setup
    alt Error occurs in setup
        LLMExp->>CDPCon: connection?.close()
        LLMExp->>LLMExp: targetCleanup()
        LLMExp->>Eval: Throw original error
    end
Loading

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

Re-trigger cubic

Comment thread packages/evals/core/tools/cdp_code.ts
Comment thread packages/evals/core/tools/cdp_code.ts
Comment thread packages/evals/core/tools/cdp_code.ts Outdated
Comment thread packages/evals/core/tools/cdp_code.ts Outdated
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-cdp-code-exposure branch from 45bb71e to 038235a Compare August 5, 2026 07:14
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-cdp-code-exposure branch 2 times, most recently from c2a9bce to 65ed807 Compare August 5, 2026 08:28
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-cdp-code-exposure branch from 65ed807 to 30769d5 Compare August 5, 2026 17:45
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-cdp-code-exposure branch from 30769d5 to 62aa8ff Compare August 5, 2026 19:06
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-cdp-code-exposure branch from 62aa8ff to 5248155 Compare August 5, 2026 22:40
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-cdp-code-exposure branch from 5248155 to 0c5ae65 Compare August 6, 2026 02:16
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-cdp-code-exposure branch from 0c5ae65 to a369ac7 Compare August 6, 2026 02:46
@miguelg719
miguelg719 force-pushed the stg-2671-cdp-code-exposure branch from a369ac7 to 2d1587d Compare August 6, 2026 22:23
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-cdp-code-exposure branch from 2d1587d to 5dfb54c Compare August 6, 2026 23:12
@miguelg719
miguelg719 force-pushed the stg-2671-cdp-code-exposure branch from 5dfb54c to 6c3826d Compare August 6, 2026 23:27
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-cdp-code-exposure branch from 6c3826d to e641edf Compare August 8, 2026 04:49
@miguelg719 miguelg719 changed the title evals: declare the cdp_code LLMExposure evals: declare the cdp_code agent mount Aug 9, 2026
@miguelg719
miguelg719 merged commit 8f94a58 into v4-spike Aug 9, 2026
26 of 39 checks passed
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.

2 participants