Skip to content

feat: add wait_for_change and screen_diff (#116) - #144

Merged
TMHSDigital merged 1 commit into
mainfrom
feat/screen-diff-116
Oct 24, 2026
Merged

TMHSDigital merged 1 commit into
mainfrom
feat/screen-diff-116

Conversation

@TMHSDigital

Copy link
Copy Markdown
Owner

Closes #116.

What

wait_for_change { target, mode: change | settle, timeoutSec, settleSec, intervalMs, pixelThreshold }

  • Resolves the target once, then polls with a raw grayscale gdigrab grab at ~320 px wide (~0.2 s each, using Capture target resolution blocks the event loop for about 1.5 s per call (synchronous PowerShell Add-Type) #88's 30 fps grab).
  • change: returns as soon as the target differs from the starting frame. settle: returns once consecutive frames have been still for settleSec.
  • Returns outcome (changed / settled / timeout / cancelled), elapsedSec, changed regions in screen coordinates, window match info for window: targets, and a final screenshot inline. A timeout is a normal result; cancellation (extra.signal) stops the loop.

screen_diff { a, b, pixelThreshold }

  • SSIM via ffmpeg's ssim filter, plus meanDiff, changedFraction, and bounding boxes of changed areas in b's pixel coordinates; b comes back inline with the boxes outlined (drawbox).

Shared src/utils/diff.ts (pure): analysis sizing, target → screen rect (full = union of monitors), an 8 px cell grid with mean-abs-diff threshold (default 12/255, which catches a caret and ignores encoder noise), 8-neighbour grouping into boxes (largest first), scaling and offsetting back to source pixels. A new runFfmpegBuffer returns raw stdout bytes; runCapture decodes text and would corrupt them.

I used a cell grid rather than the blend=difference + connected-components-in-ffmpeg route the issue sketched: it's one tiny raw frame per check and pure, testable JS.

Tests

  • Unit (diff.test.ts): sizing, full/monitor/region rects, identical frames, sub-threshold noise ignored, a box landing on the expected cells with scale + origin, two separate changes as two boxes (largest first), size mismatches, arg builders, SSIM parsing.
  • Integration (real ffmpeg): a box drawn onto an image is found where it was drawn; SSIM < 1 for the changed pair, ≈ 1 for identical.
  • Live (Windows): a PowerShell topmost window turns red → blue after 1.5 s. wait_for_change reports changed with regions inside it, then settle reports settled with an inline screenshot. Also screen_diff of a screenshot with itself → identical, SSIM ≈ 1. Harness 12/12.
  • Full suite 263.

Version 0.18.0; README (29 tools), Pages, mcp-tools.json, CHANGELOG.

🤖 Generated with Claude Code

wait_for_change polls a target with ~0.2 s low-res grabs and returns when
it changes or settles, with the changed regions and a final screenshot,
so agents stop guessing sleeps. screen_diff compares two images: SSIM,
changed share, and bounding boxes of the changes, outlined inline. Both
share a pure cell-grid differ in utils/diff.ts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 24, 2026
@TMHSDigital
TMHSDigital merged commit ff0c305 into main Oct 24, 2026
8 checks passed
@TMHSDigital
TMHSDigital deleted the feat/screen-diff-116 branch October 24, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wait_for_change and screen_diff: let agents wait for and verify on-screen changes

1 participant