dsh-windows-parallel-mcp 0.1.5 → 0.2.0

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.
@@ -0,0 +1,144 @@
1
+ # takeover.ps1 -- the ONE file allowed to move the real cursor, and the ONE place an interruption is
2
+ # read from. (R3, spec.md §1)
3
+ #
4
+ # WHY THIS IS A SEPARATE MODULE RATHER THAN A FUNCTION IN win.ps1. The product's safety claim is now
5
+ # "the cursor moves only when takeover was requested, and is ALWAYS put back". A claim like that is
6
+ # only checkable if the primitive is confined: scripts/check-no-cursor-control.mjs plus
7
+ # scripts/check-takeover-path.mjs G1 assert that SetCursorPos appears in this file and nowhere else.
8
+ # Structural confinement beats a promise in a comment -- the same reasoning the repo already used for
9
+ # the original "no injection" gate.
10
+ #
11
+ # THE THREE FACTS CALLERS NEED, and the honest shape of each:
12
+ # * the position BEFORE the move (so a restore targets a measured point, not "here-ish");
13
+ # * whether the move was actually applied (read-back == request), because a silently refused call
14
+ # must not be reported as a moved cursor;
15
+ # * whether the restore actually landed (read-back == the saved point), because "restored: true" in
16
+ # a log while the pointer sits 40px away is worse than a red verdict.
17
+ #
18
+ # INTERRUPTION has two channels and both are read here (spec.md §1): the in-process volatile flag
19
+ # [WpmCtl]::TakeoverAbort, written by the HUD button / the global chord / the worker's abort command,
20
+ # and a latch FILE written by the host half, because the worker is single-threaded and cannot read a
21
+ # request while it is inside an action. Volatile is a request; the file is the one that survives a
22
+ # wedged notification. Either is sufficient; the flag alone is not treated as the only path.
23
+
24
+ Set-StrictMode -Version 2.0
25
+
26
+ if (-not ('WpmCtl' -as [type])) {
27
+ . (Join-Path $PSScriptRoot 'win.ps1')
28
+ }
29
+
30
+ if (-not ('WpmTakeover' -as [type])) {
31
+ Add-Type -TypeDefinition @'
32
+ using System;
33
+ using System.Runtime.InteropServices;
34
+
35
+ public static class WpmTakeover
36
+ {
37
+ [StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; }
38
+
39
+ [DllImport("user32.dll", SetLastError = true)] public static extern bool GetCursorPos(out POINT p);
40
+ [DllImport("user32.dll", SetLastError = true)] public static extern bool SetCursorPos(int x, int y);
41
+
42
+ public static int[] Read() {
43
+ POINT p;
44
+ if (!GetCursorPos(out p)) return null;
45
+ return new int[] { p.X, p.Y };
46
+ }
47
+ public static int Apply(int x, int y) {
48
+ if (SetCursorPos(x, y)) return 1;
49
+ return 0;
50
+ }
51
+ public static int LastError() { return Marshal.GetLastWin32Error(); }
52
+ }
53
+ '@
54
+ }
55
+
56
+ function Get-WpmCursorPos {
57
+ # Read-only. Returns the raw point plus 'ok', because a null from the API must not be read as (0,0).
58
+ $p = [WpmTakeover]::Read()
59
+ if (-not $p) { return @{ ok = $false; x = -1; y = -1; reason = 'GetCursorPos failed' } }
60
+ return @{ ok = $true; x = [int]$p[0]; y = [int]$p[1]; reason = '' }
61
+ }
62
+
63
+ function Set-WpmCursorTakeover {
64
+ # MOVE, THEN READ BACK. The request is remembered separately from the read-back on purpose: a
65
+ # refusal (UIPI on an elevated foreground, for example) shows up as applied=false with the cursor
66
+ # still at 'before', and the caller decides whether that is a refusal or a degraded takeover.
67
+ param([int]$X, [int]$Y)
68
+ $before = Get-WpmCursorPos
69
+ if (-not $before.ok) {
70
+ return @{ ok = $false; applied = $false; requestedX = $X; requestedY = $Y
71
+ beforeX = -1; beforeY = -1; x = -1; y = -1; reason = 'could not read the cursor before moving it' }
72
+ }
73
+ $okSet = ([WpmTakeover]::Apply($X, $Y) -eq 1)
74
+ # A read-back immediately after the call is the measurement; SetCursorPos' own return value is only
75
+ # a hint (it can succeed into a queued move that a later warp overrides).
76
+ Start-Sleep -Milliseconds 20
77
+ $after = Get-WpmCursorPos
78
+ $exact = ($after.ok -and $after.x -eq $X -and $after.y -eq $Y)
79
+ return @{
80
+ ok = [bool]($after.ok)
81
+ applied = [bool]($exact)
82
+ setReturned = [bool]$okSet
83
+ requestedX = $X; requestedY = $Y
84
+ beforeX = [int]$before.x; beforeY = [int]$before.y
85
+ x = [int]$after.x; y = [int]$after.y
86
+ deltaX = [int]($after.x - $X); deltaY = [int]($after.y - $Y)
87
+ reason = if ($exact) { '' } else { 'the cursor did not land on the requested point (win32=' + [WpmTakeover]::LastError() + ')' }
88
+ }
89
+ }
90
+
91
+ function Restore-WpmCursorTakeover {
92
+ # RESTORE IS NOT CONDITIONAL ON THE ACTION HAVING SUCCEEDED. It is also not conditional on the move
93
+ # having been recorded as applied: if the request was issued, the pointer may have been warped by the
94
+ # OS anyway, so the restore is attempted whenever a 'before' point exists. The verdict is the
95
+ # read-back, and a restore that failed is reported as restored=false rather than retried forever
96
+ # (a watchdog here would fight the owner -- the same decision R2'.7 made about focus).
97
+ param([hashtable]$Entry)
98
+ if (-not $Entry -or -not $Entry.ok) {
99
+ return @{ restored = $false; attempted = $false; x = -1; y = -1
100
+ reason = 'no saved cursor position; nothing to restore' }
101
+ }
102
+ $bx = [int]$Entry.beforeX
103
+ $by = [int]$Entry.beforeY
104
+ [void][WpmTakeover]::Apply($bx, $by)
105
+ Start-Sleep -Milliseconds 20
106
+ $now = Get-WpmCursorPos
107
+ $landed = ($now.ok -and $now.x -eq $bx -and $now.y -eq $by)
108
+ return @{
109
+ restored = [bool]$landed
110
+ attempted = $true
111
+ targetX = $bx; targetY = $by
112
+ x = [int]$now.x; y = [int]$now.y
113
+ deltaX = [int]($now.x - $bx); deltaY = [int]($now.y - $by)
114
+ reason = if ($landed) { '' } else { 'the cursor did not return to the saved point (win32=' + [WpmTakeover]::LastError() + ')' }
115
+ }
116
+ }
117
+
118
+ function Get-WpmTakeoverLatchPath {
119
+ # Per-process latch so two workers cannot confuse each other's interruption, and so a stale file from
120
+ # a crashed worker can never abort a live one. The host half writes the same path (lib/index.js).
121
+ param([int]$ProcessId = $PID)
122
+ $base = $env:LOCALAPPDATA
123
+ if (-not $base) { $base = [System.IO.Path]::GetTempPath() }
124
+ return (Join-Path (Join-Path $base 'wpm') ('takeover-abort.' + $ProcessId))
125
+ }
126
+
127
+ function Test-WpmTakeoverAbort {
128
+ param([int]$ProcessId = $PID)
129
+ if ([WpmCtl]::TakeoverAbort) { return $true }
130
+ $latch = Get-WpmTakeoverLatchPath -ProcessId $ProcessId
131
+ if (Test-Path -LiteralPath $latch) { return $true }
132
+ return $false
133
+ }
134
+
135
+ function Reset-WpmTakeoverAbort {
136
+ param([int]$ProcessId = $PID)
137
+ [WpmCtl]::TakeoverAbort = $false
138
+ [WpmCtl]::InjectedChars = 0
139
+ $latch = Get-WpmTakeoverLatchPath -ProcessId $ProcessId
140
+ if (Test-Path -LiteralPath $latch) {
141
+ try { Remove-Item -LiteralPath $latch -Force -ErrorAction Stop } catch { }
142
+ }
143
+ return @{ cleared = $true; latch = $latch; latchExists = (Test-Path -LiteralPath $latch) }
144
+ }
@@ -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
@@ -379,6 +379,23 @@ public static class WpmCtl {
379
379
  public static object Dispatcher = null; // overlay thread's WPF dispatcher (set by that thread)
380
380
  public static object Window = null; // the marker window (touched ONLY on its own thread)
381
381
  public static object Timer = null; // auto-hide timer (same rule)
382
+
383
+ // ---- R3 takeover surface (spec.md §2) ------------------------------------------------------
384
+ // Same rule as the marker fields: the HUD thread owns the window and reads these; the engine writes
385
+ // the request fields. No scriptblock is ever marshalled across the threads.
386
+ public static volatile bool HudOn = false;
387
+ public static volatile bool TakeoverAbort = false; // HUD button / abort chord / worker abort
388
+ public static volatile bool AbortChordOk = false;
389
+ // volatile is ILLEGAL on string in C# (like long below): a reference write is atomic, so a plain
390
+ // static is the honest declaration and not a weaker one.
391
+ public static string HudPhase = "";
392
+ public static string HudAction = "";
393
+ public static string AbortChordLabel = "";
394
+ public static volatile int HudElapsedMs = 0;
395
+ public static volatile int HudMaxMs = 0;
396
+ public static volatile int HudSeq = 0;
397
+ public static volatile int InjectedChars = 0;
398
+ public static long HudHwnd = 0;
382
399
  }
383
400
  '@
384
401
  }
@@ -437,6 +454,47 @@ function Get-WpmUiaCached {
437
454
  return $script:WpmUia
438
455
  }
439
456
 
457
+ function Test-WpmUiaTreeHasContent([IntPtr]$Hwnd, [int]$MaxElements = 200) {
458
+ <#
459
+ Does this target's accessibility tree contain ANY content element, or is it shell only?
460
+ Returns $true when at least one element carries a content control type, $false when the
461
+ walked tree is only structural chrome, and $false when the walk itself cannot run (a walk
462
+ that failed must not be reported as "measured empty" -- the caller distinguishes that world
463
+ through the probe error, not through this answer).
464
+
465
+ WHY CONTENT, NOT COUNT. "The tree is empty" cannot mean Count == 0: a Chromium window with
466
+ renderer accessibility off still exposes ONE shell element -- the Chrome_RenderWidgetHostHWND
467
+ pane ("Chrome Legacy Window") -- so uTools measures raw=1 while carrying zero drivable
468
+ content, and the same window measured raw=0 earlier the same day depending on its own state.
469
+ What never changed across every re-read was the CONTENT count: 0 for the a11y-off window,
470
+ hundreds for the a11y-on ones (DSH 514 at census time, 1019 later; ZCode 497). The stable
471
+ boundary is structural, not numeric: shell types (Pane/Group/Image/Text/Thumb/Separator/
472
+ TitleBar) are the window's own chrome; anything else -- Button, Edit, Document, Custom --
473
+ is something an application chose to expose. Custom counts as content deliberately: it may
474
+ be undrivable, but calling it "empty" would claim the app has a11y off, and a wrong
475
+ uia_tree_empty is a worse lie than an honest unreachable.
476
+
477
+ Measured on 2026-11-21 (see scripts/uia-tree-content.ps1, which reads the same two counters
478
+ with the same shell list). This is also why NO retry/polling exists for a tree that answers
479
+ empty: three in-place reads over 2.2s produced zero content elements every time -- there is
480
+ nothing to wait for. The switch is launch-time: --force-renderer-accessibility.
481
+ #>
482
+ try {
483
+ $rootEl = [System.Windows.Automation.AutomationElement]::FromHandle($Hwnd)
484
+ $all = $rootEl.FindAll([System.Windows.Automation.TreeScope]::Descendants,
485
+ [System.Windows.Automation.Condition]::TrueCondition)
486
+ $n = [Math]::Min($all.Count, $MaxElements)
487
+ for ($i = 0; $i -lt $n; $i++) {
488
+ $t = ''
489
+ try { $t = $all[$i].Current.ControlType.ProgrammaticName -replace 'ControlType\.', '' } catch { continue }
490
+ if (@('Pane', 'Group', 'Image', 'Text', 'Thumb', 'Separator', 'TitleBar') -notcontains $t) { return $true }
491
+ }
492
+ return $false
493
+ } catch {
494
+ return $false
495
+ }
496
+ }
497
+
440
498
  function Get-WpmFamily([IntPtr]$Hwnd, [string]$Cls) {
441
499
  # Family decides which door is even possible, so it is measured from the class name rather than
442
500
  # guessed from the title: a title is the user's text, a class is the toolkit's identity.
@@ -577,6 +635,7 @@ function Get-WpmFacts {
577
635
  $uiaElement = $null
578
636
  $uiaErr = ''
579
637
  $uiaReason = ''
638
+ $scanProbed = $false
580
639
 
581
640
  # A CLICK WITH COORDINATES IS RESOLVED AT THE POINT, never by tree order. See
582
641
  # Resolve-WpmUiaElementAtPoint for what went wrong before this: the first descendant carrying a
@@ -595,6 +654,7 @@ function Get-WpmFacts {
595
654
  $uiaElement = $pr.element
596
655
  }
597
656
  } elseif ($doorKinds.Count -eq 0 -or $ElementName) {
657
+ $scanProbed = $true
598
658
  try {
599
659
  $root = [System.Windows.Automation.AutomationElement]::FromHandle($Hwnd)
600
660
  $cond = New-Object System.Windows.Automation.PropertyCondition(
@@ -629,6 +689,18 @@ function Get-WpmFacts {
629
689
  }
630
690
  }
631
691
 
692
+ # EMPTY TREE vs PATTERN-LESS CONTENT, measured rather than folded into one word. When the UIA
693
+ # probe ran and found nothing usable, two different worlds produce the same hasPattern=false:
694
+ # a tree that was never populated (the app has a11y off -- uTools walks to one shell Pane and
695
+ # zero content elements, and no amount of re-querying changes that), and a tree that is alive
696
+ # but offers nothing at the named point or element (ZCode/DSH walk to hundreds of elements).
697
+ # They get different refusal codes (decide.ps1), so this measurement runs only when the probe
698
+ # actually ran -- never to decorate a target whose message door already decided the route.
699
+ $uiaTreeEmpty = $false
700
+ if (-not $hasPattern -and ($pointResolved -or $scanProbed)) {
701
+ $uiaTreeEmpty = -not (Test-WpmUiaTreeHasContent $Hwnd)
702
+ }
703
+
632
704
  # Elevation is now measured, not assumed. WpmWin::IsElevatedTarget compares the target's
633
705
  # integrity RID against ours; a failure to read either side returns false rather than guessing,
634
706
  # because guessing 'elevated' would refuse every window whose handle read failed. The flag is
@@ -640,7 +712,8 @@ function Get-WpmFacts {
640
712
 
641
713
  $facts = New-WpmFacts -Hwnd ($Hwnd.ToInt64().ToString()) -Family $fam `
642
714
  -MessageDoor ($doorKinds.Count -gt 0) -HasPattern $hasPattern -PatternKind $patKind `
643
- -Action $Action -FactsMeasured $true -ElevatedTarget $elevated
715
+ -Action $Action -FactsMeasured $true -ElevatedTarget $elevated `
716
+ -UiaTreeEmpty $uiaTreeEmpty -UiaProbeFailed ($uiaErr -ne '')
644
717
 
645
718
  return @{
646
719
  facts = $facts
@@ -656,6 +729,11 @@ function Get-WpmFacts {
656
729
  # whose tree cannot be walked at all reached the caller as the same sentence: 'no message door
657
730
  # and no usable UIA pattern'. Two different worlds, one string -- and the fixes differ.
658
731
  uiaReason = $uiaReason
732
+ # The two booleans that decide.ps1 splits 'unreachable' on travel INSIDE $facts, built through
733
+ # the typed constructor above -- deliberately NOT duplicated here. A second copy of a measured
734
+ # value in the same return object is the two-copies-drift bug this repo keeps meeting; the
735
+ # first live-instance run of this very change caught exactly that shape (facts said False
736
+ # while the raw measurement said True, because the constructor call had not been extended).
659
737
  pointResolved = $pointResolved
660
738
  pid = [WpmWin]::PidOf($Hwnd)
661
739
  }
@@ -1,4 +1,4 @@
1
- # worker.ps1 -- the sidecar's line protocol: one JSON request in, one JSON response out.
1
+ # worker.ps1 -- the sidecar's line protocol: one JSON request in, one JSON response out.
2
2
  #
3
3
  # WHY A WORKER AND NOT A DIRECT CALL. Two constraints collide in this process model:
4
4
  # * UIA COM wants a single-threaded apartment (powershell.exe -STA), and
@@ -123,22 +123,81 @@ while ($true) {
123
123
  Write-Response $id @{ id = $id; ok = $true; result = @{ paused = $on } }
124
124
  }
125
125
  'click' {
126
+ # R3: takeover/keyInput travel as explicit request fields. The HOST half is what enforces the
127
+ # settings gates (lib/index.js) and strips these fields when a gate is off, so a request that
128
+ # arrives here with takeover=true was already authorised; the engine still re-checks the HUD.
126
129
  $r = Invoke-WpmAction -Hwnd ([string](Get-Arg $req 'hwnd' '')) -Action click `
127
130
  -X ([int](Get-Arg $req 'x' -1)) -Y ([int](Get-Arg $req 'y' -1)) `
128
- -SettleMs ([int](Get-Arg $req 'settleMs' 350))
131
+ -SettleMs ([int](Get-Arg $req 'settleMs' 350)) `
132
+ -Takeover:([bool](Get-Arg $req 'takeover' $false)) `
133
+ -TakeoverMaxMs ([int](Get-Arg $req 'takeoverMaxMs' 10000)) `
134
+ -KeyInject:([bool](([string](Get-Arg $req 'keyInput' 'none')) -eq 'inject')) `
135
+ -TakeoverArmMs ([int](Get-Arg $req 'takeoverArmMs' 800)) `
136
+ -HudDoneMs ([int](Get-Arg $req 'hudDoneMs' 1500))
129
137
  Write-Response $id @{ id = $id; ok = $true; result = $r }
130
138
  }
131
139
  'type' {
132
140
  $r = Invoke-WpmAction -Hwnd ([string](Get-Arg $req 'hwnd' '')) -Action type `
133
141
  -Text ([string](Get-Arg $req 'text' '')) -ElementName ([string](Get-Arg $req 'elementName' '')) `
134
- -Replace:([bool](Get-Arg $req 'replace' $false)) -SettleMs ([int](Get-Arg $req 'settleMs' 350))
142
+ -Replace:([bool](Get-Arg $req 'replace' $false)) -SettleMs ([int](Get-Arg $req 'settleMs' 350)) `
143
+ -Takeover:([bool](Get-Arg $req 'takeover' $false)) `
144
+ -TakeoverMaxMs ([int](Get-Arg $req 'takeoverMaxMs' 10000)) `
145
+ -KeyInject:([bool](([string](Get-Arg $req 'keyInput' 'none')) -eq 'inject')) `
146
+ -TakeoverArmMs ([int](Get-Arg $req 'takeoverArmMs' 800)) `
147
+ -HudDoneMs ([int](Get-Arg $req 'hudDoneMs' 1500))
135
148
  Write-Response $id @{ id = $id; ok = $true; result = $r }
136
149
  }
137
150
  'focus' {
138
151
  $r = Invoke-WpmAction -Hwnd ([string](Get-Arg $req 'hwnd' '')) -Action focus `
139
- -ElementName ([string](Get-Arg $req 'elementName' '')) -SettleMs ([int](Get-Arg $req 'settleMs' 350))
152
+ -ElementName ([string](Get-Arg $req 'elementName' '')) -SettleMs ([int](Get-Arg $req 'settleMs' 350)) `
153
+ -Takeover:([bool](Get-Arg $req 'takeover' $false)) `
154
+ -TakeoverMaxMs ([int](Get-Arg $req 'takeoverMaxMs' 10000))
140
155
  Write-Response $id @{ id = $id; ok = $true; result = $r }
141
156
  }
157
+ 'hud' {
158
+ # Product surface for tests and for the owner: start/stop the HUD on its own, so its window
159
+ # properties can be measured without an action in flight (test/hud-test.ps1).
160
+ . (Join-Path $EngineRoot 'hud.ps1')
161
+ $on = [bool](Get-Arg $req 'on' $true)
162
+ if ($on) {
163
+ $r = Start-WpmHud -Action ([string](Get-Arg $req 'action' 'hud')) -MaxMs ([int](Get-Arg $req 'maxMs' 10000)) -ArmMs ([int](Get-Arg $req 'armMs' 0))
164
+ $st = if ($r.state) { $r.state } else { Get-WpmHudState -WaitMs 100 }
165
+ } else {
166
+ $r = Stop-WpmHud
167
+ $st = $r.state
168
+ }
169
+ Write-Response $id @{ id = $id; ok = $true; result = @{ hud = $st } }
170
+ }
171
+ 'takeover' {
172
+ # Alias of 'hud' on purpose: the HUD IS the takeover precondition, so "takeover on" and "hud on"
173
+ # are the same operation. Reported separately from the settings gate, which lives in the host.
174
+ . (Join-Path $EngineRoot 'hud.ps1')
175
+ $on = [bool](Get-Arg $req 'on' $true)
176
+ if ($on) {
177
+ $r = Start-WpmHud -Action 'takeover' -MaxMs ([int](Get-Arg $req 'maxMs' 10000)) -ArmMs 0
178
+ $st = if ($r.state) { $r.state } else { Get-WpmHudState -WaitMs 100 }
179
+ } else {
180
+ $r = Stop-WpmHud
181
+ $st = $r.state
182
+ }
183
+ Write-Response $id @{ id = $id; ok = $true; result = @{ hud = $st; stance = 'takeover requires the host setting takeoverAllowed; the HUD is the hard precondition' } }
184
+ }
185
+ 'abort' {
186
+ # IMMEDIATE ANSWER, and it must not wait for anything. This is the host's signal -> worker path;
187
+ # the FILE latch is the path the engine actually polls, so both are written here and the answer
188
+ # goes out before any cleanup work could delay it.
189
+ . (Join-Path $EngineRoot 'takeover.ps1')
190
+ [WpmCtl]::TakeoverAbort = $true
191
+ $latch = Get-WpmTakeoverLatchPath
192
+ $written = $false
193
+ try {
194
+ $dir = Split-Path -Parent $latch
195
+ if (-not (Test-Path -LiteralPath $dir)) { New-Item -ItemType Directory -Force -Path $dir | Out-Null }
196
+ Set-Content -LiteralPath $latch -Value 'abort' -Encoding ASCII -ErrorAction Stop
197
+ $written = $true
198
+ } catch { }
199
+ Write-Response $id @{ id = $id; ok = $true; result = @{ aborted = $true; latch = $latch; latchWritten = $written; flagSet = [bool][WpmCtl]::TakeoverAbort } }
200
+ }
142
201
  'ping' {
143
202
  # `text` is echoed back verbatim. That is not decoration: the protocol's encoding is a real
144
203
  # failure surface on this host (ANSI codepage GBK), and an echo is the only way to prove a
@@ -28,20 +28,27 @@
28
28
  "The `refusalCases` array is executable: test/refusals-test.ps1 iterates it and binds the placeholders, so a documented refusal path cannot rot into fiction."
29
29
  ],
30
30
  "stance": {
31
- "inputQueue": "no OS input-queue writes: no SendInput, no keybd_event, no mouse_event",
32
- "focus": "no forged Alt key, no synthetic activation code",
33
- "cursor": "the cursor is never moved: 0 px across 24 measured rounds (scripts/channel-raise-matrix.ps1)",
34
- "tiers": "quiet (window messages) preferred over bounded-flash (UIA patterns); the flash tier must reverse itself once, and never pulls focus from a window the owner chose"
31
+ "inputQueue": "quiet and bounded-flash tiers write nothing to the OS input queue. The takeover tier (opt-in, takeoverAllowed) may send KEYBOARD input (SendInput + KEYEVENTF_UNICODE) only when keyInput='inject' was requested; mouse injection is structurally impossible (MOUSEEVENTF_* is banned repo-wide and the gate enforces it)",
32
+ "focus": "no forged Alt key, no synthetic activation code. The bounded-flash tier reverses its one flash; the takeover tier holds the focus until the action ends and then restores it through the same table",
33
+ "cursor": "the cursor is 0 px in the quiet and bounded-flash tiers (24 measured rounds, scripts/channel-raise-matrix.ps1). The takeover tier moves it to the action point BY REQUEST and always restores it; a restore that fails is reported as cursorRestored=false and turns proof=fail",
34
+ "keyboard": "keyboard injection exists only inside the takeover tier, only for targets with no message door and no UIA pattern (terminals, measured), only after asserting GetForegroundWindow() is the target. It does not carry hardware scancodes (KEYEVENTF_UNICODE), so a target that reads scancodes only will ignore it -- documented, not a bug",
35
+ "tiers": "quiet (window messages) preferred over bounded-flash (UIA patterns) preferred over takeover (explicit request, HUD mandatory, always restored); the flash tier must reverse itself once and never pulls focus from a window the owner chose",
36
+ "hud": "the takeover tier cannot run without the HUD: it is a hard precondition (refuse takeover_unavailable), not a decoration. Three phases (arming/active/done), no-activate, click-through outside its button, and three independent interruption paths"
35
37
  },
36
38
  "refusals": [
37
39
  { "code": "no_hwnd", "layer": "decision", "summary": "no usable target window handle" },
38
40
  { "code": "paused", "layer": "decision", "summary": "the owner paused input; server-side refusal" },
39
41
  { "code": "elevated_target", "layer": "decision", "summary": "target runs at a higher integrity level" },
40
- { "code": "unreachable", "layer": "decision", "summary": "no message door and no usable UIA pattern" },
41
- { "code": "terminal_no_door", "layer": "decision", "summary": "terminal text surface exposes neither a child window nor a document element" },
42
+ { "code": "unreachable", "layer": "decision", "summary": "no message door and no usable UIA pattern; the tree is alive but offers nothing at the named point or element" },
43
+ { "code": "uia_tree_empty", "layer": "decision", "summary": "the accessibility tree holds no content element at all; in every measured instance the cause is the application having UI Automation disabled, which only a launch-time switch changes" },
44
+ { "code": "uia_probe_failed", "layer": "decision", "summary": "the accessibility probe threw before it could measure this target; the exception text rides the reason" },
45
+ { "code": "terminal_no_door", "layer": "decision", "summary": "terminal text surface has child windows but none of them is writable, and keyboard injection into this host's terminal was measured not to work (findings G3: Unicode and scan-code arms both accepted by SendInput, neither executed). Pick a target with a real door" },
42
46
  { "code": "needs_facts", "layer": "decision", "summary": "the caller supplied no measured facts for this target" },
47
+ { "code": "takeover_unavailable", "layer": "decision", "summary": "takeover was requested but cannot run safely: the takeoverAllowed gate is off or the HUD is not up. The request is refused rather than silently downgraded" },
48
+ { "code": "keyinject_unavailable", "layer": "decision", "summary": "keyboard injection was requested outside the takeover tier, with the keyInjectAllowed gate off, or with the target not in the foreground (SendInput writes to the foreground, so a blind injection would type into another application)" },
43
49
  { "code": "action_failed", "layer": "runtime", "summary": "the chosen channel threw while acting", "uncoveredReason": "needs a target whose channel reliably throws; not constructed this round (docs/refusals.md, gap 2)" },
44
- { "code": "restore_failed", "layer": "runtime", "summary": "the OS refused to return the foreground after a flash", "uncoveredReason": "needs a real elevated window; task_52 (docs/refusals.md, gap 2)" }
50
+ { "code": "restore_failed", "layer": "runtime", "summary": "the OS refused to return the foreground after a flash", "uncoveredReason": "needs a real elevated window; task_52 (docs/refusals.md, gap 2)" },
51
+ { "code": "takeover_aborted", "layer": "runtime", "summary": "the owner or the host interrupted a takeover (HUD button, abort chord, host cancellation). Not a fault: the result still carries cursorRestored and injectedChars so the reader knows exactly how far it got", "uncoveredReason": "fires from a real interruption inside a live takeover action; test/takeover-test.ps1 covers the three interruption paths at the engine level (volatile flag, latch file, and the send-time abort probe), and the schema case is declared uncovered because the refusal vocabulary gate needs an executable decision-mode instance and this is a runtime outcome" }
45
52
  ],
46
53
  "tools": [
47
54
  {
@@ -69,12 +76,14 @@
69
76
  "hwnd": { "type": "string", "description": "Target top-level window handle, as returned by wpm_windows." },
70
77
  "x": { "type": "integer", "description": "Screen X coordinate. Must resolve to a child window of the target, otherwise the action is refused instead of being sent somewhere else." },
71
78
  "y": { "type": "integer", "description": "Screen Y coordinate." },
72
- "settleMs": { "type": "integer", "minimum": 0, "maximum": 2000, "default": 350, "description": "How long to let the app commit its state before the effect is judged." }
79
+ "settleMs": { "type": "integer", "minimum": 0, "maximum": 2000, "default": 350, "description": "How long to let the app commit its state before the effect is judged." },
80
+ "takeover": { "type": "boolean", "default": false, "description": "Take the takeover tier: the real cursor moves to the action point and is always restored, the focus is held until the action ends, and a three-phase HUD is mandatory. Requires the takeoverAllowed setting or the call is refused with takeover_unavailable." },
81
+ "takeoverMaxMs": { "type": "integer", "minimum": 500, "maximum": 60000, "default": 10000, "description": "Takeover only: how long the action may hold the cursor/focus." }
73
82
  },
74
83
  "required": ["hwnd", "x", "y"],
75
84
  "additionalProperties": false
76
85
  },
77
- "refusals": ["no_hwnd", "paused", "elevated_target", "unreachable", "terminal_no_door", "action_failed", "restore_failed"]
86
+ "refusals": ["no_hwnd", "paused", "elevated_target", "unreachable", "uia_tree_empty", "uia_probe_failed", "terminal_no_door", "action_failed", "restore_failed", "takeover_unavailable", "keyinject_unavailable", "takeover_aborted"]
78
87
  },
79
88
  {
80
89
  "name": "wpm_type",
@@ -88,12 +97,15 @@
88
97
  "text": { "type": "string", "description": "Text to write. Empty string is refused: it cannot be distinguished from a channel that silently did nothing." },
89
98
  "elementName": { "type": "string", "description": "Optional UIA Name or AutomationId of the control to write into. Naming an element forces the UIA tier, because a message tier cannot address 'the control called X'." },
90
99
  "replace": { "type": "boolean", "default": false, "description": "Replace the existing value instead of appending to it." },
91
- "settleMs": { "type": "integer", "minimum": 0, "maximum": 2000, "default": 350, "description": "How long to let the app commit its state before the effect is judged." }
100
+ "settleMs": { "type": "integer", "minimum": 0, "maximum": 2000, "default": 350, "description": "How long to let the app commit its state before the effect is judged." },
101
+ "takeover": { "type": "boolean", "default": false, "description": "Take the takeover tier: the HUD is shown, the focus is held until the action ends, and (with keyInput) text may be typed into the foreground target." },
102
+ "takeoverMaxMs": { "type": "integer", "minimum": 500, "maximum": 60000, "default": 10000, "description": "Takeover only: how long the action may hold the cursor/focus." },
103
+ "keyInput": { "type": "string", "enum": ["none", "inject"], "default": "none", "description": "Takeover only: 'inject' types the text with synthetic keyboard input into the foreground target, for windows with no message door and no UIA pattern (terminals). Requires keyInjectAllowed and the target in the foreground; otherwise the call is refused with keyinject_unavailable. The cursor is never moved by this path." }
92
104
  },
93
105
  "required": ["hwnd", "text"],
94
106
  "additionalProperties": false
95
107
  },
96
- "refusals": ["no_hwnd", "paused", "elevated_target", "unreachable", "terminal_no_door", "action_failed", "restore_failed"]
108
+ "refusals": ["no_hwnd", "paused", "elevated_target", "unreachable", "uia_tree_empty", "uia_probe_failed", "terminal_no_door", "action_failed", "restore_failed", "takeover_unavailable", "keyinject_unavailable", "takeover_aborted"]
97
109
  },
98
110
  {
99
111
  "name": "wpm_focus",
@@ -105,12 +117,14 @@
105
117
  "properties": {
106
118
  "hwnd": { "type": "string", "description": "Target top-level window handle." },
107
119
  "elementName": { "type": "string", "description": "UIA Name or AutomationId of the control that should hold focus." },
108
- "settleMs": { "type": "integer", "minimum": 0, "maximum": 2000, "default": 350, "description": "How long to let the app commit its state before the effect is judged." }
120
+ "settleMs": { "type": "integer", "minimum": 0, "maximum": 2000, "default": 350, "description": "How long to let the app commit its state before the effect is judged." },
121
+ "takeover": { "type": "boolean", "default": false, "description": "Take the takeover tier: the HUD is shown and the focus is held until the action ends, then restored. Requires the takeoverAllowed setting." },
122
+ "takeoverMaxMs": { "type": "integer", "minimum": 500, "maximum": 60000, "default": 10000, "description": "Takeover only: how long the action may hold the cursor/focus." }
109
123
  },
110
124
  "required": ["hwnd", "elementName"],
111
125
  "additionalProperties": false
112
126
  },
113
- "refusals": ["no_hwnd", "paused", "elevated_target", "unreachable", "terminal_no_door", "action_failed", "restore_failed"]
127
+ "refusals": ["no_hwnd", "paused", "elevated_target", "unreachable", "uia_tree_empty", "uia_probe_failed", "terminal_no_door", "action_failed", "restore_failed", "takeover_unavailable", "takeover_aborted"]
114
128
  },
115
129
  {
116
130
  "name": "wpm_status",
@@ -175,7 +189,23 @@
175
189
  "tool": "wpm_type",
176
190
  "facts": { "hwnd": "$liveHwnd", "family": "terminal" },
177
191
  "expect": "terminal_no_door",
178
- "note": "Decision-table instance only. A real terminal window is not launched in this run because findings.md:311-316 records a leftover-dialog accident on this host; the real evidence is the coverage census."
192
+ "note": "Decision-table instance, and now a conclusion verified by measurement rather than by caution: the takeover + keyInput path was measured NOT to drive this host's terminal (scripts/probe-console-inject.ps1: 242 Unicode events with the terminal in the foreground and Enter sent, nothing executed; scripts/probe-console-scan.ps1: same with layout scan codes). The code stays because its next step is still actionable -- use a target with a door."
193
+ },
194
+ {
195
+ "id": "click-uia-tree-empty",
196
+ "mode": "decision",
197
+ "tool": "wpm_click",
198
+ "facts": { "hwnd": "$liveHwnd", "family": "chromium", "uiaTreeEmpty": true },
199
+ "expect": "uia_tree_empty",
200
+ "note": "Decision-table instance of the 2026-11-21 census: a Chromium window with renderer accessibility off walks to a tree with ZERO content elements (uTools measured one Chrome Legacy Window shell Pane, 0 interactive elements, identical across three in-place reads). Distinct from unreachable because the fix differs: nothing a re-query can find -- the app must relaunch with a11y on (--force-renderer-accessibility) or a different target must be picked. Real instance: scripts/uia-tree-content.ps1 plus a live engine call against uTools."
201
+ },
202
+ {
203
+ "id": "click-uia-probe-failed",
204
+ "mode": "decision",
205
+ "tool": "wpm_click",
206
+ "facts": { "hwnd": "$liveHwnd", "uiaProbeFailed": true },
207
+ "expect": "uia_probe_failed",
208
+ "note": "Decision-table instance. The UIA probe threw between the IsWindow check and the tree walk (element destroyed under the probe), so door measurement is impossible and no conclusion about the target is licensed. The engine appends the exception text to the reason as [uia: ...]. Before this code existed a thrown probe and a genuinely pattern-less target shared 'unreachable', and uiaErr arrived here as dead data."
179
209
  },
180
210
  {
181
211
  "id": "needs-facts",
@@ -185,6 +215,38 @@
185
215
  "expect": "needs_facts",
186
216
  "note": "The absence of facts must refuse, not default to the quiet branch. Unreachable through the engine (facts are always measured), so this one guards the table when it is used on its own."
187
217
  },
218
+ {
219
+ "id": "takeover-unavailable",
220
+ "mode": "decision",
221
+ "tool": "wpm_click",
222
+ "facts": { "hwnd": "$liveHwnd", "takeoverRequested": true, "hudReady": false },
223
+ "expect": "takeover_unavailable",
224
+ "note": "Takeover was asked for but the HUD is not up. The HUD is a hard precondition, so the request is refused instead of being served silently by the quiet tier -- the point of the code is that the caller learns the request did not happen."
225
+ },
226
+ {
227
+ "id": "keyinject-unavailable",
228
+ "mode": "decision",
229
+ "tool": "wpm_type",
230
+ "facts": { "hwnd": "$liveHwnd", "takeoverRequested": true, "hudReady": true, "keyInjectRequested": true, "keyInjectAllowed": false },
231
+ "expect": "keyinject_unavailable",
232
+ "note": "Injection requested with the keyInjectAllowed gate off. Measured fact behind the refusal: SendInput writes to the FOREGROUND window (scripts/probe-sendinput-unicode.ps1 arm B: text landed in the foreground window and not in the window the caller had in mind), so an unauthorised injection is refused rather than attempted."
233
+ },
234
+ {
235
+ "id": "keyinject-not-foreground",
236
+ "mode": "decision",
237
+ "tool": "wpm_type",
238
+ "facts": { "hwnd": "$liveHwnd", "takeoverRequested": true, "hudReady": true, "keyInjectRequested": true, "keyInjectAllowed": true, "foregroundIsTarget": false },
239
+ "expect": "keyinject_unavailable",
240
+ "note": "Injection requested, gate open, but the target is not the foreground window and could not be raised. The engine refuses: blind injection would type into whatever the owner was using (same measured fact as keyinject-unavailable)."
241
+ },
242
+ {
243
+ "id": "takeover-aborted",
244
+ "mode": "none",
245
+ "tool": "wpm_click",
246
+ "args": { "hwnd": "$liveHwnd", "x": 100, "y": 100 },
247
+ "expect": "takeover_aborted",
248
+ "note": "NOT covered by an executable schema case: it is a RUNTIME outcome of an interruption (HUD button / abort chord / host cancellation), and constructing one needs a live takeover in progress. test/takeover-test.ps1 covers the three interruption paths at the engine level; the reason is declared in tools.json refusals."
249
+ },
188
250
  {
189
251
  "id": "action-failed",
190
252
  "mode": "none",