Add guarded input target assertions#315
Closed
zengfanfan wants to merge 1 commit into
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds optional shared foreground target assertions to input tools that send foreground input:
ClickTypeScrollMoveShortcutThe new optional parameters are
expected_window_titleandexpected_process. When supplied, Windows-MCP validates the current foreground root window before sending input and fails before the action if the target does not match.Motivation
Agents often observe a target window and then send input in a later tool call. Today the input call trusts whichever window is foreground at execution time. These guards give callers an opt-in fail-closed check for wrong-target input.
Issue: #314
Public API and compatibility
Existing unguarded calls remain unchanged. Guarded calls can opt in like this:
Matching semantics:
expected_window_title: case-insensitive substring match against the foreground root title;expected_process: case-insensitive exact executable basename match;Implementation overview
Desktop.assert_foreground_target(...)centralizes foreground title/process validation.Testing
Focused checks passed:
Focused pytest result:
Full repository gates were also run. They still show pre-existing baseline failures unrelated to this PR:
Notes
This PR is intentionally separate from deterministic drag PR #313. It does not include local planning documents, private consumer details, or unrelated cleanup.