---
phase: 02-window-and-region-targeting
verified: 2026-04-12T18:00:00Z
status: human_needed
score: 7/7
overrides_applied: 0
human_verification:
  - test: "Call list_windows via MCP client and verify visible windows are returned with correct handle, title, processName, x, y, width, height"
    expected: "Array of visible windows matching what is shown on screen, no empty-title or minimized windows"
    why_human: "Requires a running MCP server and real windows on screen to validate output correctness"
  - test: "Start a capture session with target='window' and window_title matching an open application, then retrieve grid"
    expected: "Grid image shows only the targeted window content, not the full desktop"
    why_human: "Visual verification needed -- cannot programmatically confirm grid shows only the window"
  - test: "Start a capture session with target='region' specifying a known screen area, retrieve grid"
    expected: "Grid image shows only the specified rectangular region"
    why_human: "Visual verification of cropped region correctness"
  - test: "Minimize the target window during an active capture session"
    expected: "Session continues, skipped frames reported in metadata, session does not crash"
    why_human: "Requires real-time interaction with a running capture session"
---

# Phase 2: Window and Region Targeting Verification Report

**Phase Goal:** Agents can target specific application windows or screen regions instead of the full desktop
**Verified:** 2026-04-12T18:00:00Z
**Status:** human_needed
**Re-verification:** No -- initial verification

## Goal Achievement

### Observable Truths

| # | Truth | Status | Evidence |
|---|-------|--------|----------|
| 1 | Agent can list all visible windows with titles, handles, and process info | VERIFIED | `list_windows` tool registered in server.ts (line 443-477), calls `Window.all()` with filter for non-empty title, non-zero size, non-minimized; maps to handle/title/processName/x/y/width/height |
| 2 | Agent can capture a specific window by title or handle | VERIFIED | `WindowTarget` class in window-target.ts implements CaptureTarget; `findWindow` in window-utils.ts looks up by handle (exact) or title (case-insensitive substring); server.ts factory creates `new WindowTarget(args.window_handle, args.window_title)` on target="window" |
| 3 | Agent can capture a rectangular screen region or window-relative region | VERIFIED | `RegionTarget` uses Monitor.fromPoint + cropSync for screen-absolute regions; `WindowRegionTarget` captures window then crops to window-relative coordinates; both wired in server.ts factory switch |
| 4 | Graceful handling when target window closes/minimizes during capture | VERIFIED | scheduler.ts catch block records SkippedFrame (line 105-110), continues via scheduleNext(), aborts after 3 consecutive failures (line 117-129); consecutiveFailures resets on success (line 86) |
| 5 | CaptureConfig.target accepts desktop, window, region, window_region | VERIFIED | types.ts line 16: `target: "desktop" \| "window" \| "region" \| "window_region"` |
| 6 | All three new targets return PNG buffers matching DesktopTarget contract | VERIFIED | Each class implements CaptureTarget interface, calls toPngSync() to return Buffer |
| 7 | Session metadata includes skippedFrames count when frames were skipped | VERIFIED | get_capture_status returns `skippedFrames: session.skippedFrames?.length ?? 0` in complete response (server.ts line 393, 413) |

**Score:** 7/7 truths verified

### Required Artifacts

| Artifact | Expected | Status | Details |
|----------|----------|--------|---------|
| `src/types.ts` | Extended CaptureConfig with target union and StartCaptureInputSchema with target fields | VERIFIED | 4-way target union, all coordinate fields, SkippedFrame interface, WindowInfo interface, schema fields for all targeting modes |
| `src/capture/targets/window-utils.ts` | Shared findWindow helper for handle and title lookup | VERIFIED | Exports `findWindow`, uses `Window.all()`, handle-exact and title-substring matching |
| `src/capture/targets/window-target.ts` | WindowTarget implementing CaptureTarget | VERIFIED | Class with capture(), findWindow lookup, minimized/empty-image checks |
| `src/capture/targets/region-target.ts` | RegionTarget implementing CaptureTarget | VERIFIED | Monitor.fromPoint, screen-to-monitor coordinate conversion, cropSync with clamping |
| `src/capture/targets/window-region-target.ts` | WindowRegionTarget implementing CaptureTarget | VERIFIED | Window capture + window-relative crop, bounds validation, clamping |
| `src/server.ts` | list_windows tool, target factory in start_capture, skippedFrames in status | VERIFIED | 3 tools registered, target factory switch, input validation with isError returns, pre-validates window existence |
| `src/capture/scheduler.ts` | Graceful frame skip with consecutive failure abort | VERIFIED | consecutiveFailures counter, skippedFrames array, 3-failure abort, reset on success |

### Key Link Verification

| From | To | Via | Status | Details |
|------|----|-----|--------|---------|
| window-target.ts | window-utils.ts | `import { findWindow }` | WIRED | Line 6: `import { findWindow } from "./window-utils.js"` |
| window-region-target.ts | window-utils.ts | `import { findWindow }` | WIRED | Line 6: `import { findWindow } from "./window-utils.js"` |
| server.ts | window-target.ts | `new WindowTarget` | WIRED | Import line 14, instantiation line 246 |
| server.ts | region-target.ts | `new RegionTarget` | WIRED | Import line 15, instantiation line 249 |
| server.ts | window-region-target.ts | `new WindowRegionTarget` | WIRED | Import line 16, instantiation line 257 |
| scheduler.ts | types.ts | `SkippedFrame` | WIRED | Import line 7, push to `session.skippedFrames!` at line 105 |
| server.ts | window-utils.ts | `findWindow` for pre-validation | WIRED | Import line 17, used for window existence check line 225 |

### Data-Flow Trace (Level 4)

Not applicable -- these artifacts are capture targets and scheduler logic, not UI components rendering dynamic data.

### Behavioral Spot-Checks

| Behavior | Command | Result | Status |
|----------|---------|--------|--------|
| TypeScript compiles | `npx tsc --noEmit` | Clean exit, no errors | PASS |
| All 6 commits exist | git log for each hash | All 6 verified (2fd5fdb, d3bdfdf, 31c22d7, 21d0fb4, bb9f010, 63b6374) | PASS |
| getDesktopTarget export removed | grep for export | Not found in server.ts | PASS |

Step 7b note: Cannot test MCP tool execution without running server and native screenshot dependencies. Routed to human verification.

### Requirements Coverage

| Requirement | Source Plan | Description | Status | Evidence |
|-------------|------------|-------------|--------|----------|
| CAPT-02 | 02-01, 02-02 | Capture specific window by title or handle | SATISFIED | WindowTarget class + server.ts factory wiring |
| CAPT-03 | 02-01, 02-02 | Capture rectangular screen region | SATISFIED | RegionTarget class + server.ts factory wiring |
| CAPT-04 | 02-01, 02-02 | Capture region relative to window position | SATISFIED | WindowRegionTarget class + server.ts factory wiring |
| CAPT-05 | 02-02 | List visible windows with title, handle, process info | SATISFIED | list_windows tool in server.ts |
| TIME-05 | 02-02 | Handle target window closing/minimizing gracefully | SATISFIED | Scheduler skip logic with SkippedFrame tracking |

No orphaned requirements. All 5 requirement IDs from REQUIREMENTS.md Phase 2 traceability (CAPT-02 through CAPT-05, TIME-05) are covered by the plans and implemented.

### Anti-Patterns Found

| File | Line | Pattern | Severity | Impact |
|------|------|---------|----------|--------|
| (none) | - | - | - | - |

No TODOs, FIXMEs, placeholders, empty returns, or console.log-only implementations found.

### Human Verification Required

### 1. list_windows Tool Output Correctness

**Test:** Call list_windows via an MCP client and verify the returned window list matches visible applications on screen.
**Expected:** Array of WindowInfo objects with correct handle, title, processName, x, y, width, height; no empty-title or minimized windows included.
**Why human:** Requires a running MCP server with native node-screenshots bindings and real windows on the desktop.

### 2. Window-Targeted Capture Grid

**Test:** Start a capture session with `target="window"` and `window_title` matching an open application (e.g., "Notepad"), wait for completion, retrieve the grid image.
**Expected:** Grid image contains only the targeted window's content, not the full desktop.
**Why human:** Visual verification needed to confirm the grid shows only the correct window.

### 3. Region-Targeted Capture Grid

**Test:** Start a capture session with `target="region"` specifying a known screen area (e.g., x=0, y=0, width=500, height=500), retrieve the grid.
**Expected:** Grid image shows only the specified 500x500 region.
**Why human:** Visual verification of cropped region correctness against known screen area.

### 4. Graceful Skip on Window Minimize

**Test:** Start a capture session targeting a specific window, then minimize that window mid-capture, then restore it.
**Expected:** Session continues; some frames are skipped; `get_capture_status` shows `skippedFrames > 0`; session completes (does not error unless 3+ consecutive failures).
**Why human:** Requires real-time interaction with a running capture session and timing coordination.

### Gaps Summary

No gaps found. All 7 observable truths verified, all 7 artifacts pass existence/substantive/wiring checks, all 5 requirements satisfied, all key links wired, no anti-patterns detected. TypeScript compiles cleanly.

4 items require human verification due to the need for a running MCP server with native screenshot dependencies and visual confirmation of capture output.

---

_Verified: 2026-04-12T18:00:00Z_
_Verifier: Claude (gsd-verifier)_
