Skip to content

Add --type/--root/--class-name to every single-element ui command - #932

Merged
Nikola Metulev (nmetulev) merged 6 commits into
mainfrom
nmetulev-typed-ui-actions
Oct 8, 2026
Merged

Nikola Metulev (nmetulev) merged 6 commits into
mainfrom
nmetulev-typed-ui-actions

Conversation

@nmetulev

@nmetulev Nikola Metulev (nmetulev) commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Description

A label like "Save" often matches more than one element: the button and its own text block, for example. Before this change, only the read commands (search, get-value, get-property, wait-for, inspect) could narrow a selector with --type, --root, or --class-name. Commands that act on an element could not, so agents had to find the slug first and then retry.

Now these winapp ui commands also accept the filters on their element selector: invoke, set-value, click, focus, hover, scroll, scroll-into-view, screenshot, record, touch, pen, and inspect with a selector. drag (two selectors) and send-keys --target do not. With filters, the selector and all filters must match exactly one element in the target app or window.

For invoke:

  • Filters work with or without --action.
  • A filtered invoke acts only on the uniquely matched element. It does not fall back to an invokable ancestor, another window, or a replacement element.
  • Without --action, a filtered invoke still tries the invoke patterns in order on that one element.
  • Without any filters, invoke behaves as before.

Usage Example

winapp ui invoke Save --type Button -a <app>
winapp ui set-value "Text editor" "hello" -a notepad --type Document
winapp ui click Subject -a myapp --root MailRow --type Edit

Failure behavior:

  • More than one match: fails with ambiguous_selector and does not act. Commands that act on the element count matches in every window they search. For example, if the main window and an owned dialog both have a "Subject" field, winapp ui set-value Subject "draft" -a MyApp --type Edit fails instead of editing the main window's field. Narrow the filters or use a unique slug from winapp ui inspect or winapp ui search. search itself still lists every match.
  • No match: fails without acting. A filtered invoke also fails if the matched element is replaced or its window is recycled before it acts; other commands re-read the selector just before acting, as they do without filters.
  • Filters without a selector (inspect, screenshot, and record have an optional selector): rejected with invalid_arguments.
  • Filters with coordinates (touch --at, pen --at or --path): rejected, because coordinates bypass the selector.

Where the element is searched:

  • Filtered inspect and screenshot look only in the window they display.
  • Filtered record also searches the app's popups and owned dialogs, and records from the window where the unique match was found.

The npm uiRecord wrapper forwards type, root, and className, including explicit empty strings, as the CLI does.

Related Issue

N/A

Type of Change

  • ✨ New feature
  • 📝 Documentation
  • 🧪 Test update

Checklist

  • New tests added for new functionality
  • Tested locally on Windows
  • docs/usage.md updated
  • Shipped skills updated in plugins/winapp/skills/

Screenshots / Demo

N/A: CLI-only change. The commands above are illustrative examples, not captured output.

Additional Notes

Validation (local, current head):

  • scripts/build-cli.ps1 -SkipTests -SkipMsix passed. The generated CLI schema and npm docs/wrappers are committed.
  • UiCommandTests and DesktopCaptureTests: 882 passed, 1 skipped (interactive-desktop-only recording test).
  • UI Automation query, gesture, and explicit-action tests: 257 passed.
  • npm test in src/winapp-npm: 312 passed.
  • scripts/validate-plugin-package.ps1 passed.

Compatibility: Filters on invoke without --action were rejected only in this unreleased PR. Allowing them changes no published behavior. All other commands gain new optional flags; omitting them keeps today's behavior.

@nmetulev Nikola Metulev (nmetulev) added the agent-preparing Agent is addressing feedback or completing required validation and CI label Sep 23, 2026
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Build Metrics Report

Validation passed. All required build and validation jobs succeeded.

Binary Sizes

Artifact Baseline Current Delta
CLI (ARM64) 57.49 MB 57.60 MB 📈 +118.5 KB (+0.20%)
CLI (x64) 57.52 MB 57.63 MB 📈 +113.5 KB (+0.19%)
MSIX (ARM64) 23.87 MB 23.93 MB 📈 +63.6 KB (+0.26%)
MSIX (x64) 25.35 MB 25.42 MB 📈 +62.5 KB (+0.24%)
NPM Package 49.80 MB 49.91 MB 📈 +102.8 KB (+0.20%)
NuGet Package 49.90 MB 50.01 MB 📈 +110.6 KB (+0.22%)

.NET Test Results (TRX reports)

Other suites are reflected in the overall validation status above.

✅ 8210 passed, 37 skipped out of 8247 tests in 1255.1s (+99 tests, +163.1s vs. baseline)

Test Coverage

✅ 86.5% line coverage, 81.1% branch coverage · ✅ no change vs. baseline

CLI Startup Time

60ms median (x64, winapp --version) · ✅ no change vs. baseline

Try This Build

Installs the MSIX for your architecture, replacing any previously installed build. Needs the GitHub CLI — the command offers to install it and sign you in if it is missing.

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) 932
Switching between builds often?

Put the tool on your PATH once:

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) -AddToPath

Then this build is just:

winapp-pr 932

Run winapp-pr with no arguments to pick from a list of open PRs.


Updated 2026-10-08 03:42:36 UTC · commit f92b4a0 · workflow run

@nmetulev Nikola Metulev (nmetulev) changed the title Add scoped typed targeting to explicit UI invoke Add --type/--root/--class-name to every single-element ui command Oct 6, 2026
Nikola Metulev (nmetulev) added a commit that referenced this pull request Oct 6, 2026
… aliases

- the -a hosted-app fallback and inspect --interactive editable elements move to their own PR into main
- element filters on every selector command move into #932
- 'find' and 'tree' are no longer aliases; as unknown commands they suggest 'search' and 'inspect'
- remove stray blank lines in record/touch/pen/inspect/screenshot help examples

Co-authored-by: Copilot App <[email protected]>
@nmetulev Nikola Metulev (nmetulev) added ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge and removed agent-preparing Agent is addressing feedback or completing required validation and CI labels Oct 6, 2026
@nmetulev
Nikola Metulev (nmetulev) marked this pull request as ready for review October 6, 2026 02:57
Copilot AI balanced review requested due to automatic review settings October 6, 2026 02:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Filtered capture can silently widen scope, send-keys --target remains unsupported, and npm recording drops explicit empty filters.

Review effort: Balanced
Findings: 1 High severity · 2 Medium severity

Open (3)
What changed in this PR

Extends UI element filters across single-target commands, with strict matching, generated API updates, documentation, and tests.

Changes:

  • Adds --type, --root, and --class-name filtering to action, gesture, inspection, and capture commands.
  • Adds filtered-invoke identity checks and ambiguity handling.
  • Updates npm bindings, schema, documentation, skills, and tests.
File Description
src/​winapp-npm/​src/​winapp-commands.ts Adds generated filter options and forwarding.
src/​winapp-npm/​src/​ui-record-guard.ts Forwards recording filters.
src/​winapp-CLI/​WinApp.UIAutomation/​Services/​UiAutomationService.cs Adds provider identity comparison.
src/​winapp-CLI/​WinApp.UIAutomation/​Services/​IUiAutomation.cs Exposes identity comparison contract.
src/​winapp-CLI/​WinApp.UIAutomation.TestSupport/​FakeUiServices.cs Extends query test instrumentation.
src/​winapp-CLI/​WinApp.UIAutomation.Tests/​RealUiAutomationTests.ExplicitActions.cs Tests strict filtered actions.
src/​winapp-CLI/​WinApp.UIAutomation.Tests/​GestureTargetingTests.cs Updates test implementation contract.
src/​winapp-CLI/​WinApp.Cli/​Helpers/​UiErrors.cs Supports injected error output.
src/​winapp-CLI/​WinApp.Cli/​Helpers/​PointerCommandSupport.cs Applies filters to pointer targets.
src/​winapp-CLI/​WinApp.Cli/​Commands/​UiTouchCommand.cs Adds filtered touch targeting.
src/​winapp-CLI/​WinApp.Cli/​Commands/​UiSetValueCommand.cs Adds filtered value targeting.
src/​winapp-CLI/​WinApp.Cli/​Commands/​UiScrollIntoViewCommand.cs Adds filtered element targeting.
src/​winapp-CLI/​WinApp.Cli/​Commands/​UiScrollCommand.cs Adds filtered scroll targeting.
src/​winapp-CLI/​WinApp.Cli/​Commands/​UiScreenshotCommand.cs Resolves filtered capture targets.
src/​winapp-CLI/​WinApp.Cli/​Commands/​UiRecordCommand.cs Resolves filtered recording targets.
src/​winapp-CLI/​WinApp.Cli/​Commands/​UiQueryOptions.cs Generalizes shared element filters.
src/​winapp-CLI/​WinApp.Cli/​Commands/​UiPenCommand.cs Adds filtered pen targeting.
src/​winapp-CLI/​WinApp.Cli/​Commands/​UiInvokeCommand.cs Enforces unique, stable filtered invocation.
src/​winapp-CLI/​WinApp.Cli/​Commands/​UiInspectCommand.cs Adds filtered subtree inspection.
src/​winapp-CLI/​WinApp.Cli/​Commands/​UiHoverCommand.cs Adds filtered hover targeting.
src/​winapp-CLI/​WinApp.Cli/​Commands/​UiFocusCommand.cs Adds filtered focus targeting.
src/​winapp-CLI/​WinApp.Cli/​Commands/​UiClickCommand.cs Adds filtered click targeting.
src/​winapp-CLI/​WinApp.Cli/​Commands/​GuestDesktopCaptureCommand.cs Updates recording-handler dependencies.
src/​winapp-CLI/​WinApp.Cli.Tests/​UiCommandTests.Screenshot.cs Updates screenshot test construction.
src/​winapp-CLI/​WinApp.Cli.Tests/​UiCommandTests.Record.Stdin.cs Updates recording test construction.
src/​winapp-CLI/​WinApp.Cli.Tests/​UiCommandTests.Query.cs Tests filter scope and command parity.
src/​winapp-CLI/​WinApp.Cli.Tests/​UiCommandTests.Invoke.cs Tests filtered invocation behavior.
src/​winapp-CLI/​WinApp.Cli.Tests/​RealRecordingTests.Helpers.cs Forwards identity comparison in tests.
src/​winapp-CLI/​WinApp.Cli.Tests/​DesktopCaptureTests.cs Updates guest recording tests.
plugins/​winapp/​skills/​winapp-ui-automation/​SKILL.md Documents action-command filtering.
docs/​usage.md Adds shared filter guidance.
docs/​ui-automation.md Documents filtering semantics and failures.
docs/​npm-usage.md Regenerates npm API documentation.
docs/​cli-schema.json Regenerates CLI option schema.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/ui-automation.md Resolved
Comment thread src/winapp-npm/src/ui-record-guard.ts Resolved
@nmetulev Nikola Metulev (nmetulev) added agent-preparing Agent is addressing feedback or completing required validation and CI and removed ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge labels Oct 6, 2026
@nmetulev Nikola Metulev (nmetulev) added ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge agent-preparing Agent is addressing feedback or completing required validation and CI and removed agent-preparing Agent is addressing feedback or completing required validation and CI ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge labels Oct 6, 2026
@nmetulev
Nikola Metulev (nmetulev) requested a balanced review from Copilot October 6, 2026 20:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Filtered focus and coordinate actions can retarget replacement elements instead of failing as stale.

Review effort: Balanced
Findings: 2 High severity

Open (2)
Resolved since last review (3)

@nmetulev Nikola Metulev (nmetulev) added agent-preparing Agent is addressing feedback or completing required validation and CI and removed ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge agent-preparing Agent is addressing feedback or completing required validation and CI labels Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants