feat(vision): add screenshot diff and stability helpers
All checks were successful
python-syntax / syntax-check (push) Successful in 9s

This commit is contained in:
2026-05-01 16:24:46 +02:00
parent f00c525721
commit 02bf069425
4 changed files with 206 additions and 0 deletions

View File

@@ -282,6 +282,70 @@ Notes:
- If `wait_for_window=true`, the server polls for a matching window and returns `window_found`.
- `dry_run=true` returns the resolved argv/cwd without launching.
## `POST /vision/diff`
Measure whether a screen region changed meaningfully between two captures.
Query params:
- `screen` (int, default `0`) - used for `mode=screen` and `mode=region`
Compare live captures:
```json
{
"mode": "region",
"region_x": 120,
"region_y": 80,
"region_width": 600,
"region_height": 300,
"delay_ms": 400,
"diff_threshold": 0.01
}
```
Compare provided images:
```json
{
"mode": "image",
"before_image_base64": "iVBORw0KGgoAAA...",
"after_image_base64": "iVBORw0KGgoBBB...",
"diff_threshold": 0.01
}
```
Response includes:
- `diff_ratio` — average normalized pixel difference
- `changed` — whether `diff_ratio >= diff_threshold`
- `region` — compared region
## `POST /vision/stability`
Measure whether a screen region stays visually stable over a short interval.
Query params:
- `screen` (int, default `0`)
```json
{
"region_x": 0,
"region_y": 0,
"region_width": 1920,
"region_height": 1080,
"sample_interval_ms": 250,
"duration_ms": 1200,
"diff_threshold": 0.005
}
```
Response includes:
- `stable`
- `sample_count`
- `max_diff_ratio`
- `avg_diff_ratio`
## `POST /wait`
Wait on a structured UI condition instead of guessing sleep durations.