Feat/bridge uia capture - #15
Merged
Merged
Conversation
Adds the `execute` JSON-RPC method to the Windows bridge. Routes
element-targeted actions through UIA patterns and returns the
post-action state where the pattern exposes it.
Action types supported:
- click -> InvokePattern.Invoke (falls back to Toggle,
SelectionItem, ExpandCollapse, or focus+Space keystroke)
- type -> ValuePattern.SetValue (falls back to focus+keystrokes
with optional Ctrl+A/Del clear)
- select -> SelectionItemPattern.Select on the target, or expand
+ locate-by-name on a Selection container, or
ValuePattern for editable combos
- check -> TogglePattern.Toggle with state convergence (up to
3 toggles to reach the requested checked state)
- expand -> ExpandCollapsePattern.Expand / Collapse
- focus -> AutomationElement.Focus
- scroll_to -> ScrollItemPattern.ScrollIntoView with focus fallback
- key -> Keyboard.Type / TypeSimultaneously with modifier
parsing (ctrl|alt|shift|meta|win) and a friendly
key-name vocabulary (enter, tab, esc, F1..F12, arrows,
pgup/pgdn, etc.) falling through to literal typing
Element lookup: Capture() now stashes every walked AutomationElement
into a per-capture session (element_id -> live handle). Execute()
resolves the request's elementId against that session. Errors are
specific and recoverable:
- "No capture session active" -> caller must call capture first
- "Unknown element_id" -> stale binding, re-capture
- ElementNotAvailableException -> UI changed mid-action, re-capture
Defensive throughout: every UIA call wrapped, every exception
returned as a structured ExecuteResult so the agent gets a
deterministic { ok, message, newValue } shape on every call.
Notepad live demo script (`scripts/notepad-demo.ps1`):
1. Launches Notepad
2. list_windows -> find notepad
3. capture -> locate the text_area element
4. execute type -> "Hello from AgentMark Desktop ..."
5. capture -> assert the typed text is in element.value
Designed to run from the interactive Parallels console where UIA
can see the real desktop.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PowerShell's StreamWriter unpredictably prepends a UTF-8 BOM to the
very first WriteLine call on stdin depending on stream-flush timing.
The first JSON request then arrives as `{"jsonrpc":...}` which
System.Text.Json rejects with "'0xEF' is an invalid start of a value".
Defensive fix: TrimStart('') on every read line. Costs nothing
on clean clients, transparently survives BOMed ones.
Demo script (scripts/notepad-demo.ps1):
- Stop auto-launching Notepad. Win 11 UWP Notepad's startup race vs
UIA registration is messy; require the user to open Notepad first.
- Match Notepad by case-insensitive process name OR window title --
Win 11's UWP Notepad ships as process name "Notepad" (capitalized).
- Add raw-JSON diagnostic + visible window list on no-match.
Validated end-to-end on Win 11 ARM64 (Parallels):
- list_windows returned 5 windows (3 Notepad + 2 conhost)
- capture walked 37 elements at depth 6, located text_area
- execute type wrote "Hello from AgentMark Desktop -- phase 0e3 live
demo" via ValuePattern.SetValue
- re-capture verified the typed text in element.value
- LIVE DEMO PASSED
This is the first real end-to-end run of AgentMark Desktop driving
Windows software through the protocol, zero vision/AI involved.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
No description provided.