Skip to content

Add exact window modes to App - #331

Open
zengfanfan wants to merge 5 commits into
CursorTouch:mainfrom
zengfanfan:feature/exact-window-control
Open

zengfanfan wants to merge 5 commits into
CursorTouch:mainfrom
zengfanfan:feature/exact-window-control

Conversation

@zengfanfan

@zengfanfan zengfanfan commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add deterministic native window operations as explicit modes of the existing App tool:

App(mode="find_window", title="Target", title_match="exact")
App(mode="activate_window", handle=12345, process_id=6789)
App(mode="set_window_bounds", handle=12345, outer=[100, 120, 800, 600])
  • find_window filters by HWND, process ID, process basename, and exact or partial title, and returns native identity and outer/client geometry.
  • activate_window requires an HWND, supports optional identity assertions, and verifies the foreground HWND after activation.
  • set_window_bounds requires an HWND and exactly one outer or client rectangle, and reads back the resulting geometry.
  • Explicit HWNDs must identify top-level windows. Windows that disappear during enumeration are skipped; an invalid explicit HWND still produces an error.
  • Existing launch, launch_executable, resize, and switch modes keep their current contracts. Exact-mode parameters cannot silently fall through to a legacy mode.

The implementation uses an internal ExactWindowController; it does not register a new public MCP tool. On the current main (which includes #445), exact activation and resizing check control ownership before each Win32 state-changing step. If the user takes over, remaining steps stop; legacy App modes retain their existing behavior.

Motivation

The existing name-based modes are useful for convenient interactive automation, but fuzzy selection is unsuitable when a caller already has a native window identity. Explicit modes keep exact operations in the existing application/window tool.

Testing

  • ruff check and ruff format --check passed on all six changed Python files.
  • Focused App and exact-window tests: 72 passed after the final formatting-only commit.
  • Local suite with two environment-dependent test files excluded: 915 passed. The excluded files are tests/test_analytics.py (cannot create a directory inside this environment's read-only worktree) and tests/test_cli_legacy_flags.py (requires Windows scheduled-task registration privileges). This is not an unfiltered full-suite result.
  • Real Windows smoke test passed on a temporary Tk window: exact lookup, outer-bounds update, and activation. The test window was closed afterward. Takeover interleavings are covered by deterministic tests, not a physical takeover smoke test.
  • Local interpreter: Python 3.13; pyproject.toml requires Python >=3.14. The GitHub CI run for this PR head passed on Python 3.14: 929 passed, 7 warnings.

Screenshots

Not applicable; no UI is added.

Related Issues

None.

@zengfanfan
zengfanfan marked this pull request as ready for review July 13, 2026 12:06
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@zengfanfan
zengfanfan force-pushed the feature/exact-window-control branch from 866f2aa to 7358578 Compare July 18, 2026 13:21
@zengfanfan zengfanfan changed the title Add exact window discovery, activation, and bounds control Add exact window modes to App Jul 18, 2026
@zengfanfan
zengfanfan force-pushed the feature/exact-window-control branch from 7358578 to d090126 Compare October 2, 2026 17:00
@zengfanfan
zengfanfan force-pushed the feature/exact-window-control branch from d090126 to 5587e8d Compare October 3, 2026 09:44

This branch has not been deployed

No deployments
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