dsh-windows-parallel-mcp 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,9 +4,74 @@ Dates are the registry `time` values for each version, not git commit dates —
4
4
  when someone typed, a publish time records when a version became installable, and only the second
5
5
  one is a promise to anyone installing it.
6
6
 
7
+ ## 0.1.5 — 2026-11-21
8
+
9
+ A click that acted on the wrong control, and returned `ok:true` while doing it.
10
+
11
+ **The defect.** The contract (`src/schema/tools.json`) makes `x`/`y` **required** for `click` and says
12
+ a point that does not resolve inside the target is refused "instead of being sent somewhere else".
13
+ The message tier honours that (`Resolve-WpmChildAtPoint`). The **UIA tier did not read `x`/`y` at
14
+ all**: it scanned descendants and invoked the FIRST element carrying any usable pattern, then
15
+ reported success. On any target without a message door — WPF, UWP, WinUI3, i.e. most modern
16
+ applications — `click` at the coordinates of one control operated on a different one entirely, and
17
+ the marker was still drawn at the requested point, so the product's own evidence pointed at a place
18
+ it had not acted on. This is worse than a refusal: a refusal is honest, this was a wrong action
19
+ wearing a success report.
20
+
21
+ Measured, not inferred. A two-button WPF target at known coordinates, with the click counters
22
+ written by the handlers themselves:
23
+ - pre-fix engine, click aimed at **Bravo**: `alpha 0->1`, `bravo 0->0`, `last='alpha'`, result `ok:true`
24
+ - fixed engine, same call: `bravo 0->1`, `alpha 0->0`, `last='bravo'`, `channel=uia tier=bounded-flash`
25
+
26
+ **Fixed**
27
+ - The UIA tier resolves the element **at the point** (`Resolve-WpmUiaElementAtPoint`,
28
+ `AutomationElement.FromPoint`), climbs to the nearest ancestor carrying a usable pattern, and
29
+ refuses when the point does not belong to the named window. Naming an element with
30
+ `elementName` still takes the by-name path: there the caller asked for that control.
31
+ - **Ancestry is proven before the pattern is looked for.** The first version of this fix searched
32
+ while climbing and returned on the first pattern — which reproduced the original defect one level
33
+ down: a point outside the target climbed into the taskbar, found a patterned button there,
34
+ invoked it and answered `ok:true`. Caught by the "point outside the target" arm of the new test,
35
+ not by review.
36
+ - `uiaErr` was produced and read by nobody (`grep` found zero consumers), so a walk that *threw*
37
+ reached the caller as "no message door and no usable UIA pattern" — a factual claim that may be
38
+ false. The probe now also carries `uiaReason`, and a refusal appends what the point probe found,
39
+ so `unreachable` no longer collapses two different worlds into one sentence.
40
+
41
+ **Added**
42
+ - `test/uia-click-target.ps1` — a two-button WPF target that publishes its button centres in
43
+ **physical pixels** (the test that computed them itself was 1.5x off; that DPI lesson is written
44
+ into the file) and writes click counts from the handlers that fired.
45
+ - `test/uia-click-truth.mjs` — 12 arms, and a new gate (`scripts/check.mjs`, now 13). It fails in
46
+ both directions: point-at-Bravo must bump Bravo and not Alpha; a point outside the target must be
47
+ refused, must fire neither button, and must say *why*.
48
+
49
+ **Unchanged** — the refusal-code set, the pure judgment, the message tier, the marker.
50
+
51
+ ## 0.1.4 — 2026-11-21
52
+
53
+ (Registry time is the authority for the timestamp; same convention as below.)
54
+
55
+ The source became reachable. Until now the package had **no repository, homepage or bugs field** —
56
+ not an oversight at authoring time, but a consequence of the repo not existing: there was no URL to
57
+ put there. `git remote -v` was empty through 0.1.0–0.1.3, so every claim in the README pointed at a
58
+ tarball and nowhere else. Creating the repository is what unblocks this, and it is the only reason
59
+ this release exists.
60
+
61
+ **Added**
62
+ - `repository`, `homepage` and `bugs` in `package.json`, so npmjs.com links to the source and to an
63
+ issue tracker instead of leaving a reader with a download and no way to report a refusal that
64
+ should not have happened.
65
+ - README now names the repository in its opening section, next to the non-affiliation notice.
66
+
67
+ **Unchanged**
68
+ - No behaviour. `lib/`, `src/engine/` and the schema are byte-identical to 0.1.3 — this release only
69
+ makes the existing artifact findable. The gate is still green (12 checks), and the profile on the
70
+ authoring machine keeps running 0.1.3 code with an identical `lib` hash.
71
+
7
72
  ## 0.1.3 — 2026-11-21
8
73
 
9
- (Registry time `2026-11-21T…Z` UTC; same convention as below — the publish time is the promise.)
74
+ (Registry time `2026-11-21T01:20:58Z` UTC (= `2026-11-21 09:20` Beijing; the date follows the same UTC convention as the entries below — the publish time is the promise.)
10
75
 
11
76
  0.1.2 shipped a proof that answered "did we disturb you". It never answered "did the thing happen" —
12
77
  the engine computed `effect` on every action call and the Node half dropped it on the floor, so
package/README.md CHANGED
@@ -12,6 +12,10 @@ a window accepts a window message, you never lose focus at all. Where it only ex
12
12
  you lose focus for one bounded flash that is reversed automatically. Everywhere else it refuses, with
13
13
  a code and a reason.
14
14
 
15
+ Source, the measurement scripts behind every number below, and the release history live at
16
+ **<https://github.com/drscrewdriver/dsh-windows-parallel-mcp>** — issues are the right place for
17
+ "this target refused and I think it should not have".
18
+
15
19
  Not affiliated with `dsh-windows-mcp`. Different plugin, different trade-off: that one is a carrier
16
20
  bundle with a broad tool surface; this one is a single action tool whose entire design is about
17
21
  *not* disturbing the desktop.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-windows-parallel-mcp",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "tag": "latest"
@@ -18,6 +18,14 @@
18
18
  "computer-use"
19
19
  ],
20
20
  "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/drscrewdriver/dsh-windows-parallel-mcp.git"
24
+ },
25
+ "homepage": "https://github.com/drscrewdriver/dsh-windows-parallel-mcp#readme",
26
+ "bugs": {
27
+ "url": "https://github.com/drscrewdriver/dsh-windows-parallel-mcp/issues"
28
+ },
21
29
  "type": "module",
22
30
  "main": "lib/index.js",
23
31
  "exports": {
@@ -1,4 +1,4 @@
1
- # engine.ps1 -- the only place where a decision becomes a syscall.
1
+ # engine.ps1 -- the only place where a decision becomes a syscall.
2
2
  #
3
3
  # One entry point, Invoke-WpmAction, and it always returns a result object rather than throwing on
4
4
  # a refusal: 'refused' is a normal outcome of this product, not an error path, and R3.2 requires
@@ -178,7 +178,9 @@ function Invoke-WpmAction {
178
178
  return $result
179
179
  }
180
180
 
181
- $probe = Get-WpmFacts -Hwnd $h -Action $Action -ElementName $ElementName
181
+ # Coordinates travel into the probe: the UIA tier resolves the element AT THE POINT. Without them
182
+ # an unnamed click had no way to be anything other than "first control in tree order".
183
+ $probe = Get-WpmFacts -Hwnd $h -Action $Action -ElementName $ElementName -X $X -Y $Y
182
184
  $facts = $probe.facts
183
185
  $facts.paused = [bool][WpmCtl]::Paused
184
186
  if ($ElementName) {
@@ -194,6 +196,14 @@ function Invoke-WpmAction {
194
196
  $result.family = $probe.family; $result.cls = $probe.cls
195
197
  if ($decision.channel -eq 'refuse') {
196
198
  $result.refusal = $decision.refusal; $result.reason = $decision.reason
199
+ # A refusal that says only 'unreachable' makes the reader guess which of two very different
200
+ # things happened. When the point probe ran, it knows: the point is outside the target, or the
201
+ # element there has no pattern, or the tree could not be walked at all. Carry that out -- a
202
+ # refusal is a normal product outcome and its reason is the product (R3.2).
203
+ if ($decision.refusal -eq 'unreachable' -and $probe.uiaReason) {
204
+ $result.reason = "$($decision.reason) -- at that point: $($probe.uiaReason)"
205
+ }
206
+ if ($probe.uiaErr) { $result.reason = "$($result.reason) [uia: $($probe.uiaErr)]" }
197
207
  $result.latencyMs = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() - $started
198
208
  return $result
199
209
  }
@@ -1,4 +1,4 @@
1
- # win.ps1 -- the IO half of the R2' engine: probe a target's doors, act through the cheapest
1
+ # win.ps1 -- the IO half of the R2' engine: probe a target's doors, act through the cheapest
2
2
  # door it has, and put the owner's focus back when the action cost them a flash.
3
3
  #
4
4
  # Layering is deliberate. decide.ps1 owns every judgement (pure, unit-tested). This file owns
@@ -449,6 +449,87 @@ function Get-WpmFamily([IntPtr]$Hwnd, [string]$Cls) {
449
449
  return 'unknown'
450
450
  }
451
451
 
452
+ function Resolve-WpmUiaElementAtPoint {
453
+ <#
454
+ WHICH UIA ELEMENT SITS UNDER A SCREEN POINT -- the UIA twin of Resolve-WpmChildAtPoint.
455
+
456
+ WHY THIS EXISTS. The UIA tier used to take the FIRST descendant carrying any usable pattern and
457
+ invoke that, while the contract (src/schema/tools.json) says x/y are REQUIRED and that a point
458
+ which does not resolve inside the target is refused "instead of being sent somewhere else". On a
459
+ target with no message door -- WPF, UWP, WinUI3, i.e. most modern apps -- 'click 500,300' would
460
+ therefore Invoke whichever control happened to come first in tree order and return ok:true. That
461
+ is not a refusal, it is a wrong action reported as a right one, and it also breaks the marker's
462
+ promise (the marker is drawn at the requested point, which was then not the point acted on).
463
+
464
+ THE WALK-UP. AutomationElement.FromPoint returns the DEEPEST element at the point, which for a
465
+ button is usually its text child; the Invoke pattern lives on the ancestor. So the search climbs
466
+ from the hit element towards the target root and takes the nearest ancestor that has a usable
467
+ pattern. Climbing stops at the target's own root element: beyond it lies the caller's other
468
+ windows, and acting there would be acting on a window nobody named.
469
+
470
+ ANCESTRY IS PROVEN, NOT ASSUMED. If the climb reaches a null parent without meeting the target
471
+ root, the point belongs to a different window and the answer is a refusal -- the same rule the
472
+ message tier enforces with Root(hit) -ne Hwnd.
473
+ #>
474
+ param([IntPtr]$Hwnd, [int]$X, [int]$Y)
475
+
476
+ $out = @{ element = $null; patternKind = 'none'; err = ''; atPoint = $false; reason = '' }
477
+ try {
478
+ $root = [System.Windows.Automation.AutomationElement]::FromHandle($Hwnd)
479
+ if (-not $root) { $out.err = 'target window has no UIA element'; $out.reason = 'target element unavailable'; return $out }
480
+
481
+ $pt = New-Object System.Windows.Point([double]$X, [double]$Y)
482
+ $hitEl = [System.Windows.Automation.AutomationElement]::FromPoint($pt)
483
+ if (-not $hitEl) { $out.reason = 'nothing at that point is exposed to UI Automation'; return $out }
484
+ $out.atPoint = $true
485
+
486
+ # ANCESTRY FIRST, PATTERN SECOND. The first version of this function searched for a pattern
487
+ # while climbing and returned the moment it found one -- which re-created the very bug it was
488
+ # written to kill, one level down: a click at a point OUTSIDE the target climbed into the
489
+ # taskbar, found a patterned button there, invoked it, and reported ok:true. Caught by the
490
+ # 'point outside the target' arm of test/uia-click-truth.mjs. The order is the invariant:
491
+ # prove the point belongs to THIS window, and only then ask what at the point can be driven.
492
+ $walker = [System.Windows.Automation.TreeWalker]::ControlViewWalker
493
+ $path = @()
494
+ $el = $hitEl
495
+ $sawRoot = $false
496
+ $hop = 0
497
+ while ($el -and $hop -lt 24) {
498
+ if ($el -eq $root) { $sawRoot = $true; break }
499
+ $path += $el
500
+ try { $el = $walker.GetParent($el) } catch { $el = $null }
501
+ $hop++
502
+ }
503
+ if ($el -eq $root) { $sawRoot = $true }
504
+
505
+ if (-not $sawRoot) {
506
+ # The climb ended without meeting the target root: the point is in another window, and
507
+ # acting there would be acting on a window nobody named.
508
+ $out.element = $null
509
+ $out.patternKind = 'none'
510
+ $out.reason = 'the element under that point does not belong to the target window'
511
+ return $out
512
+ }
513
+
514
+ $pats = Get-WpmUiaCached
515
+ foreach ($node in $path) {
516
+ foreach ($k in @('invoke', 'value', 'toggle', 'select', 'legacy')) {
517
+ if (-not $pats.ContainsKey($k)) { continue }
518
+ $obj = $null
519
+ $has = $false
520
+ try { $has = $node.TryGetCurrentPattern($pats[$k], [ref]$obj) } catch { $has = $false; $obj = $null }
521
+ if ($has -and $obj) { $out.element = $node; $out.patternKind = $k; return $out }
522
+ }
523
+ }
524
+ $out.reason = 'the element under that point exposes no usable UIA pattern'
525
+ return $out
526
+ } catch {
527
+ $out.err = $_.Exception.Message
528
+ $out.reason = 'the point probe threw'
529
+ return $out
530
+ }
531
+ }
532
+
452
533
  function Get-WpmFacts {
453
534
  <#
454
535
  Measure a target's doors. Returns the hashtable decide.ps1 consumes, plus the raw handles the
@@ -456,7 +537,7 @@ function Get-WpmFacts {
456
537
  clicks must not pay it 50 times -- but the cache is keyed on hwnd AND invalidated by the caller
457
538
  when the window set changes, never assumed fresh.
458
539
  #>
459
- param([IntPtr]$Hwnd, [string]$Action = 'click', [string]$ElementName = '', [switch]$NoCache)
540
+ param([IntPtr]$Hwnd, [string]$Action = 'click', [string]$ElementName = '', [int]$X = -1, [int]$Y = -1, [switch]$NoCache)
460
541
 
461
542
  $cls = [WpmWin]::Cls($Hwnd)
462
543
  $fam = Get-WpmFamily $Hwnd $cls
@@ -495,7 +576,25 @@ function Get-WpmFacts {
495
576
  $patKind = 'none'
496
577
  $uiaElement = $null
497
578
  $uiaErr = ''
498
- if ($doorKinds.Count -eq 0 -or $ElementName) {
579
+ $uiaReason = ''
580
+
581
+ # A CLICK WITH COORDINATES IS RESOLVED AT THE POINT, never by tree order. See
582
+ # Resolve-WpmUiaElementAtPoint for what went wrong before this: the first descendant carrying a
583
+ # pattern was invoked regardless of x/y, so an unnamed click on a WPF/UWP/WinUI target acted on a
584
+ # control the caller never pointed at -- and answered ok:true. Naming an element (ElementName) is
585
+ # a different contract: there the caller asked for that control, so tree scan is correct.
586
+ $pointResolved = $false
587
+ if ($doorKinds.Count -eq 0 -and -not $ElementName -and $Action -eq 'click' -and $X -ge 0 -and $Y -ge 0) {
588
+ $pr = Resolve-WpmUiaElementAtPoint -Hwnd $Hwnd -X $X -Y $Y
589
+ $uiaErr = $pr.err
590
+ $uiaReason = $pr.reason
591
+ $pointResolved = $true
592
+ if ($pr.element) {
593
+ $hasPattern = $true
594
+ $patKind = $pr.patternKind
595
+ $uiaElement = $pr.element
596
+ }
597
+ } elseif ($doorKinds.Count -eq 0 -or $ElementName) {
499
598
  try {
500
599
  $root = [System.Windows.Automation.AutomationElement]::FromHandle($Hwnd)
501
600
  $cond = New-Object System.Windows.Automation.PropertyCondition(
@@ -552,6 +651,12 @@ function Get-WpmFacts {
552
651
  doorKinds = @($doorKinds | Sort-Object -Unique)
553
652
  uiaElement = $uiaElement
554
653
  uiaErr = $uiaErr
654
+ # Why there is no element, when there is none. Previously uiaErr was produced and then read by
655
+ # nobody (grep found zero consumers), so a point that resolved outside the target and a target
656
+ # whose tree cannot be walked at all reached the caller as the same sentence: 'no message door
657
+ # and no usable UIA pattern'. Two different worlds, one string -- and the fixes differ.
658
+ uiaReason = $uiaReason
659
+ pointResolved = $pointResolved
555
660
  pid = [WpmWin]::PidOf($Hwnd)
556
661
  }
557
662
  }