Skip to content

Conversation

@shrey150
Copy link
Contributor

@shrey150 shrey150 commented Jan 14, 2026

Summary

Eliminates code duplication in screenshot masking functionality by extracting shared utilities and consolidating helper methods:

  • Extracted selectorsToLocators() and DEFAULT_MASK_COLOR to shared screenshotUtils.ts
  • Unified ToolMaskConfig as a type alias for AgentMaskConfig
  • Consolidated screenshot capture logic in V3CuaAgentHandler into reusable helpers

Test Plan

  • ✅ TypeScript compilation passes
  • ✅ ESLint and Prettier checks pass
  • ✅ Public API type tests pass
  • ✅ No functional changes to screenshot masking behavior

🤖 Generated with Claude Code


Summary by cubic

Unifies screenshot masking behind shared helpers and a single mask config, removing duplicated logic across tools and handlers. Defaults stay the same; masking is optional and off unless provided.

  • Refactors
    • Added AgentMaskConfig and mask option on execute/stream.
    • Threaded mask config from V3AgentHandler into createAgentTools and all relevant tools (screenshot and vision).
    • waitAndCaptureScreenshot now accepts a number or { delayMs, mask }, where mask = { selectors, color }.
    • Introduced captureWithMask and moved selectorsToLocators and DEFAULT_MASK_COLOR to screenshotUtils; centralized apply/cleanup flow.
    • Both CUA and V3 handlers now use captureWithMask; CUA updates screenshot dimensions via a helper.

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

Extract selectorsToLocators() and DEFAULT_MASK_COLOR constant to shared
screenshotUtils.ts. Unify ToolMaskConfig as a type alias for AgentMaskConfig.
Extract v3CuaAgentHandler screenshot logic into reusable helper methods
(captureScreenshotWithMask and updateScreenshotDimensions) to eliminate
duplication between setupAgentClient and captureAndSendScreenshot.

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
@changeset-bot
Copy link

changeset-bot bot commented Jan 14, 2026

⚠️ No Changeset found

Latest commit: c1d9ad6

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

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 14, 2026

Greptile Summary

This PR successfully consolidates screenshot masking functionality by extracting shared utilities (selectorsToLocators, DEFAULT_MASK_COLOR) into screenshotUtils.ts and unifying the ToolMaskConfig type as an alias for AgentMaskConfig.

Key improvements:

  • Eliminated code duplication across 8+ tool files by centralizing masking logic
  • Maintained backward compatibility in waitAndCaptureScreenshot() by supporting both legacy number parameter and new options object
  • Added proper cleanup handling with try/finally blocks to ensure mask overlays are removed
  • Refactored V3CuaAgentHandler screenshot capture into reusable helper methods (captureScreenshotWithMask, updateScreenshotDimensions)

Minor observation:

  • clickAndHold tool accepts maskConfig parameter but doesn't capture screenshots, making the parameter unused (though this maintains API consistency)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The refactoring is well-executed with proper abstraction, maintains backward compatibility, includes appropriate error handling with cleanup blocks, and passes all type checks. The changes are purely structural with no functional behavior changes to screenshot masking.
  • No files require special attention

Important Files Changed

Filename Overview
packages/core/lib/v3/understudy/screenshotUtils.ts Added selectorsToLocators() and DEFAULT_MASK_COLOR utilities for screenshot masking
packages/core/lib/v3/agent/utils/screenshotHandler.ts Enhanced waitAndCaptureScreenshot() with masking support and backward compatibility
packages/core/lib/v3/handlers/v3CuaAgentHandler.ts Extracted screenshot capture logic into reusable helper methods with masking support
packages/core/lib/v3/agent/tools/clickAndHold.ts Added unused maskConfig parameter without screenshot capture functionality

Sequence Diagram

sequenceDiagram
    participant Agent as Agent Handler
    participant Tool as Vision Tool
    participant Handler as Screenshot Handler
    participant Utils as Screenshot Utils
    participant Page as Browser Page

    Agent->>Agent: Set maskConfig from execute options
    Agent->>Tool: Pass maskConfig to tool
    Tool->>Handler: Call waitAndCaptureScreenshot(page, options)
    Handler->>Utils: selectorsToLocators(page, maskConfig.selectors)
    Utils-->>Handler: Return Locator[]
    Handler->>Utils: applyMaskOverlays(locators, color)
    Utils->>Page: Inject mask overlay elements
    Utils-->>Handler: Return cleanup function
    Handler->>Page: page.screenshot()
    Page-->>Handler: Buffer
    Handler->>Utils: runScreenshotCleanups(cleanupTasks)
    Utils->>Page: Remove mask overlay elements
    Handler-->>Tool: base64 screenshot
    Tool-->>Agent: Tool result with screenshot
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

15 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 15 files

shrey150 and others added 3 commits January 13, 2026 17:09
- Remove unnecessary ToolMaskConfig type alias, use AgentMaskConfig directly
- Remove unused maskConfig parameter from clickAndHold tool
- Centralize mask logic into captureWithMask helper in screenshotUtils
- Simplify screenshot tool, screenshotHandler, and CUA handler to use shared helper

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Change ScreenshotCaptureOptions to accept { mask: MaskConfig } directly
- Remove verbose { maskSelectors, maskColor } spread pattern from tools
- Reduces boilerplate in click, type, scroll, wait, dragAndDrop, fillFormVision

Co-Authored-By: Claude Opus 4.5 <[email protected]>
captureAndEmitScreenshot in v3AgentHandler was not applying mask overlays,
unlike the equivalent in v3CuaAgentHandler. This ensures consistency.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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