Skip to content

Feat/bridge uia capture - #15

Merged
rrader26 merged 2 commits into
mainfrom
feat/bridge-uia-capture
May 11, 2026
Merged

Feat/bridge uia capture#15
rrader26 merged 2 commits into
mainfrom
feat/bridge-uia-capture

Conversation

@rrader26

Copy link
Copy Markdown
Contributor

No description provided.

rrader26-sys and others added 2 commits May 11, 2026 13:05
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>
@rrader26
rrader26 merged commit 0471aa3 into main May 11, 2026
4 checks passed
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