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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,140 @@ 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.2.0 — 2026-11-23
8
+
9
+ > Date note: this entry is written before publishing, so the date is the working date. The file's own
10
+ > rule is that a released version carries the registry `time` value — replace this line at publish time
11
+ > (task_36/task_37 in the plan) rather than leaving a commit date here.
12
+
13
+ **The promise changes shape, so the version changes major-minor.** 0.1.x said: no physical input at
14
+ all, ever. That was true and cheap to enforce by absence. 0.2.0 keeps it as the DEFAULT and adds an
15
+ opt-in tier that can move the cursor and type into the foreground window — which means the old claim
16
+ cannot stay as written, and a release that quietly kept the old wording would be the exact failure
17
+ mode this project keeps writing gates against.
18
+
19
+ ### Added — the takeover tier (`takeover:true`)
20
+
21
+ - **A fourth tier.** `quiet` (window messages) and `bounded-flash` (UIA pattern, one reversed flash)
22
+ are unchanged. `takeover` is entered only by an explicit request AND with both settings gates on;
23
+ it places the real cursor on the action point, holds the focus for the duration, and always
24
+ restores. `refuse` is unchanged.
25
+ - **The HUD's phase is a colour, not a sentence.** `arming` is amber, `active` red, `done` green —
26
+ encoded twice (whole surface tint + a 5px accent bar) because the owner is looking at the target
27
+ window, not at a 470×104 window in the corner. `test/hud-test.ps1` asserts it from the real pixels
28
+ (C18, five arms: each phase's dominant hue, all three distinct, and the surface tint changing too).
29
+ - **A three-phase HUD as a hard precondition.** `arming` (default 800 ms, cancellable) → `active`
30
+ (elapsed/limit clock and injected-character count) → `done`. `WS_EX_TOPMOST|WS_EX_NOACTIVATE`,
31
+ `ShowActivated=false`, measured to leave `GetForegroundWindow()` unchanged. Empty space is
32
+ click-through via a `WNDPROC` subclass returning `HTTRANSPARENT`; the button stays clickable.
33
+ No HUD ⇒ `takeover_unavailable`, never a silent takeover.
34
+ - **Three interruption paths, one flag.** HUD stop button, a global abort chord (candidates from
35
+ `Ctrl+Alt+X`; the one that actually registered is displayed and reported as `abortChord=`), and the
36
+ host's cancellation (`exec.signal` → `%LOCALAPPDATA%/wpm/takeover-abort.<pid>` latch file, because
37
+ the worker is single-threaded and cannot read a request mid-action). Interruption returns
38
+ `takeover_aborted` WITH `cursorRestored` and `injectedChars`.
39
+ - **Keyboard injection, takeover-only** (`keyInput:"inject"`). `SendInput` + `KEYEVENTF_UNICODE`,
40
+ per character, interruptible every 8 characters or 50 ms. The foreground is asserted to BE the
41
+ target before sending and re-asserted at send time — measured: text sent while another window was
42
+ in front landed in that window. Success reports `effect=reported-by-send`, never "verified".
43
+ No hardware scancode is carried; a scancode-only target would ignore it (documented limitation).
44
+ - **New refusals, three copies kept in step:** `takeover_unavailable` and `keyinject_unavailable`
45
+ (decision layer), `takeover_aborted` (runtime layer).
46
+ - **New settings:** `takeoverAllowed=false`, `keyInjectAllowed=false`, `takeoverMaxMs=10000`,
47
+ `takeoverArmMs=800`. Both gates default OFF so an upgrade cannot start moving the cursor by itself.
48
+ - **New gates:** `check-no-cursor-control.mjs` became a whitelist (`SetCursorPos` only in
49
+ `takeover.ps1`, `SendInput` only in `input-inject.ps1`, mouse events banned everywhere), and a new
50
+ `check-takeover-path.mjs` asserts G1–G5 (file confinement, branch-scoped loading,
51
+ HUD-checked-before-act, move-and-restore in one `try/finally`, keyboard-only events) and proves
52
+ itself non-vacuous by injecting one violation per assertion. `check.mjs` now runs 11 gates.
53
+ - **`proof` grew a declared takeover:** cursor motion on this tier is reported as `declared`, but
54
+ `cursorRestored=false` is a hard `proof=fail` with the reason 「借了未还」.
55
+
56
+ ### Withdrawn — the terminal claim was measured false
57
+
58
+ The plan for this release was to drive a terminal by typing into it. Two probes disagree, on this
59
+ host, with everything else held correct: `scripts/probe-console-inject.ps1` sent 242 Unicode events
60
+ into a dedicated Windows Terminal window (foreground verified, Enter sent) and the shell executed
61
+ nothing; `scripts/probe-console-scan.ps1` repeated it with layout scan codes (262 events) and got the
62
+ same result. GUI targets are unaffected — the same code types Chinese text into a WinForms edit
63
+ successfully. So `terminal_no_door` stays, its reason now points at what DOES work (a target with a
64
+ real door), and the documentation says plainly that the terminal is neither writable nor readable
65
+ here. A capability that cannot be demonstrated is not shipped as a promise.
66
+
67
+ ### Fixed / hardened
68
+
69
+ - **The marker had a white square behind it.** `overlay.ps1` set `AllowsTransparency` but never set
70
+ `Background`, and a WPF `Window`'s default background is `SystemColors.WindowBrush` (white) — so the
71
+ 22px marker painted an opaque white tile with the blue ring inside it. Geometry could not see this
72
+ (the rect was correct and click-through still worked), which is why it survived every existing arm.
73
+ Fixed with an explicit `Transparent` background and pinned by a NEW PIXEL ARM in
74
+ `test/overlay-test.ps1`: `PrintWindow(PW_RENDERFULLCONTENT)` the marker and assert the corners are
75
+ unpainted while the centre still carries the ring. Measured before/after with the same probe — corner
76
+ rgb **217,217,217 → 0,0,0**, centre rgb **166,204,217 → 0,38,51**; removing the fix turns the arm red.
77
+ - `lib/config.js`: on the Schemastery path, unknown setting keys were silently carried into the
78
+ validated value (a typo looked accepted while doing nothing). They are now rejected, matching the
79
+ shim's rule that the plugin test already pinned.
80
+ - `docs/refusals.md`: `terminal_no_door` no longer claims "no child HWND" — the measured truth is
81
+ "three child HWNDs, none writable" (drag bar, DirectComposition target, 0×0 input sink).
82
+
83
+ ### Measured for this release (re-runnable from `scripts/`)
84
+
85
+ - `SetCursorPos(+40,+20)` read back exactly, restore landed exactly (`probe-setcursor-pos.ps1`).
86
+ The elevated-foreground arm could not be arranged from a non-elevated process — recorded as
87
+ unmeasured, not guessed.
88
+ - Injected text goes to the FOREGROUND window, not the intended one (`probe-sendinput-unicode.ps1`, B
89
+ in front ⇒ text in B and nothing in A; A in front with Chinese ⇒ landed in A).
90
+ - HUD click-through: `HwndSource` hook receives `WM_NCHITTEST` but cannot change hit-testing; a
91
+ `WNDPROC` subclass works (`probe-hittest-children.ps1`).
92
+ - Desktop test arms (manual, because they move the real pointer): `test/hud-test.ps1` 19/19,
93
+ `test/takeover-test.ps1` 22/22, `test/keyinject-test.ps1` 11/11 with one skip (the real-console
94
+ arm, superseded by the two console probes above).
95
+ ## 0.1.6 — 2026-11-21
96
+
97
+ Two failures that shared one refusal code are split — because the reader's next step differs.
98
+
99
+ **The defect.** Everything door-less came back `unreachable`. Two of its causes are opposites: a
100
+ tree that was never populated (the application has UI Automation off — measured on this desktop:
101
+ uTools walks to zero content elements on three in-place reads spanning 2.2 s and never grows one),
102
+ and a probe that threw (the tree could not be measured at all). The probe's own diagnostic was
103
+ already being produced and then wasted: `uiaErr` reached the result object only as a reason-string
104
+ suffix that nothing branched on — 0.1.5's point-probe work found it as dead data. A caller reading
105
+ `unreachable` could not tell "pick another target" from "make the app enable accessibility" from
106
+ "read the exception".
107
+
108
+ **Fixed**
109
+ - **`uia_tree_empty`** — the walked tree holds **zero content elements**. The criterion is
110
+ structural, not numeric: Pane/Group/Image/Text/Thumb/Separator/TitleBar are the window's own
111
+ shell; anything else (Button, Edit, Document, Custom) is something an application chose to
112
+ expose. Count alone lies — an a11y-off Chromium window still exposes one
113
+ `Chrome_RenderWidgetHostHWND` shell pane, and the same uTools window measured raw=0 and raw=1
114
+ the same day depending on its own state while content stayed 0 throughout. The reason states
115
+ the observation, not an exclusive cause: a provider that answers nothing (a hung pump) reads as
116
+ empty too, instantly, without throwing — that second cause is documented, not hidden.
117
+ - **`uia_probe_failed`** — the probe threw before it could measure; no conclusion about the
118
+ target is licensed. The exception text rides the reason as `[uia: …]`. Measured: WM_CLOSE
119
+ landing 40 ms into the call (between the `IsWindow` check and `FromHandle`) returns this code
120
+ with the original exception text, not `unreachable`. Probe failure outranks tree-empty — a
121
+ measurement that threw cannot also certify emptiness — and a usable door outranks both.
122
+ - **The refusal reason carries the probe's context for all three codes**: which point was probed
123
+ and what it found there, plus the exception when one exists. A diagnosis with the evidence
124
+ redacted is not a diagnosis.
125
+
126
+ **Also**
127
+ - The reverse assertion about Chromium's "lazy" accessibility is written where the next reader
128
+ will trip over it (`scripts/chromium-a11y-flag.mjs` conclusion, README's measurement section):
129
+ the same window re-read in place three times (+0/+700/+1500 ms) never grew content, an a11y-on
130
+ tree answers completely on the first query — so the engine does NOT re-query with a deadline
131
+ and no retry exists anywhere. The instrument ships:
132
+ `scripts/uia-tree-content.ps1` reads the same two counters with the same shell-type table the
133
+ engine decides on.
134
+
135
+ Measured instances behind every claim above: real-window end-to-end refusals for all three codes
136
+ (`uia_tree_empty` via both the scan and the point path on uTools; `unreachable` on a tree-alive
137
+ window; `uia_probe_failed` on a mid-probe destroy), decision-table arms for each new branch and
138
+ its precedence, and `refusals-test` 11 passed with 2 codes still declared uncovered
139
+ (`action_failed`, `restore_failed`).
140
+
7
141
  ## 0.1.5 — 2026-11-21
8
142
 
9
143
  A click that acted on the wrong control, and returned `ok:true` while doing it.
@@ -230,4 +364,4 @@ gives you a README and nothing else. Kept for history, not for use.
230
364
 
231
365
  ## 0.0.0-stage — 2026-11-18
232
366
 
233
- The first reservation, same story as 0.0.1.
367
+ The first reservation, same story as 0.0.1.
package/README.md CHANGED
@@ -1,16 +1,22 @@
1
1
  # dsh-windows-parallel-mcp
2
2
 
3
- > **0.1.3 — the proof now says who reported the success, not just that you were undisturbed.** The
4
- > name was reserved earlier under a weaker claim (see [CHANGELOG.md](CHANGELOG.md)); the claim below
5
- > is the measured one. 0.1.1 is 0.1.0's behaviour with a corrected packaging chain; 0.1.2 added the
6
- > runtime proof chain (`proof=` verdict and `proofDimensions`, measured against the desktop around
7
- > your own call); 0.1.3 adds the second half — `effect=` — and lets it enter the judgment, so a call
8
- > that accomplished nothing can no longer read as `proof=pass`.
9
-
10
- A DSH plugin that lets an agent drive **its own** Windows windows without moving your cursor. Where
11
- a window accepts a window message, you never lose focus at all. Where it only exposes UI Automation,
12
- you lose focus for one bounded flash that is reversed automatically. Everywhere else it refuses, with
13
- a code and a reason.
3
+ > **0.2.0 — the promise changes shape, deliberately.** Through 0.1.x this plugin's claim was "no
4
+ > physical input at all". 0.2.0 keeps that as the **default** and adds an **opt-in takeover tier**:
5
+ > with `takeoverAllowed` on and `takeover:true` on the call, the real cursor is moved to the action
6
+ > point (so you can see where the agent points) and always restored, the focus is held for the
7
+ > duration, and a three-phase HUD with a stop button and a global abort key is mandatory. Keyboard
8
+ > injection exists only inside that tier, only when asked (`keyInput:"inject"`), and only for
9
+ > targets with no other door — and, measured, it does **not** work on this host's terminal, so the
10
+ > terminal stays refused rather than becoming a promise. Both gates default off: an upgrade cannot
11
+ > start moving your cursor by itself. 0.1.6 split `unreachable` into `uia_tree_empty` and
12
+ > `uia_probe_failed`; 0.1.5 made a click act on the point it names; 0.1.3 added `effect=` — who
13
+ > reported the success — and let it enter the judgment. Full history: [CHANGELOG.md](CHANGELOG.md).
14
+
15
+ A DSH plugin that lets an agent drive **its own** Windows windows — quietly by default, and visibly
16
+ on request. Where a window accepts a window message, you never lose focus at all. Where it only
17
+ exposes UI Automation, you lose focus for one bounded flash that is reversed automatically. Where you
18
+ explicitly ask for the takeover tier, the cursor moves to the point and is always restored, with a
19
+ HUD that can stop it three ways. Everywhere else it refuses, with a code and a reason.
14
20
 
15
21
  Source, the measurement scripts behind every number below, and the release history live at
16
22
  **<https://github.com/drscrewdriver/dsh-windows-parallel-mcp>** — issues are the right place for
@@ -62,8 +68,9 @@ silently claims the documented key works. `overlay=true` in settings controls th
62
68
  flag itself is engine-side and refuses actions with `paused`.
63
69
 
64
70
  Refusals are a normal result, not an error: `no_hwnd`, `paused`, `elevated_target`, `unreachable`,
65
- `terminal_no_door`, `needs_facts`, `action_failed`, `restore_failed`. Each carries a reason and a
66
- next step — see [docs/refusals.md](docs/refusals.md).
71
+ `uia_tree_empty`, `uia_probe_failed`, `terminal_no_door`, `needs_facts`, `takeover_unavailable`,
72
+ `keyinject_unavailable`, `action_failed`, `restore_failed`, `takeover_aborted`. Each carries a reason
73
+ and a next step — see [docs/refusals.md](docs/refusals.md).
67
74
 
68
75
  **Every real click carries its own disturbance proof.** `click` returns a `proof=pass|inconclusive|…`
69
76
  verdict plus a `proofDimensions` field (cursor / foreground / focus). Around your call the engine
@@ -75,9 +82,13 @@ a switch of foreground on a quiet tier fails — the control shows the desktop w
75
82
  is the action's to explain; a cursor jump is *reported*, never accused, because with nothing running
76
83
  this desktop's cursor showed multi-gap unexplained motion on its own (a re-runnable probe ships:
77
84
  `scripts/idle-baseline.mjs`). The cursor promise therefore lives where blame is decidable: a build
78
- gate asserts no shipped file contains `SetCursorPos`/`SendInput`/`mouse_event`/`keybd_event`, so a
79
- regression that adds cursor control fails at build time with certainty instead of being hunted at
80
- runtime among ambient motion.
85
+ gate confines `SetCursorPos` to `takeover.ps1` and `SendInput` to `input-inject.ps1`, bans
86
+ `MOUSEEVENTF_*`/`mouse_event`/`keybd_event` everywhere, and a second gate asserts the structural
87
+ promises around them (the HUD is checked before any primitive runs; the cursor move and its restore
88
+ share one `try/finally`). A regression fails at build time with certainty instead of being hunted at
89
+ runtime among ambient motion. In the takeover tier the cursor motion is **declared**, so it is
90
+ reported rather than accused — but `cursorRestored=false` (borrowed and not returned) is a hard
91
+ `proof=fail`.
81
92
 
82
93
  **And it says who reported the success.** Every action result carries `effect=` in the text and
83
94
  `effect` in the structured output. The three values are not degrees of confidence in the
@@ -97,19 +108,67 @@ disturb you; it never proves we accomplished anything. A single `reported-by-*`
97
108
  the caveat spelled out in the reason field (`未独立验证` — nobody observed the app), because turning
98
109
  weak-but-real evidence into a red would train its readers to ignore the verdict.
99
110
 
111
+ ## The takeover tier (opt-in)
112
+
113
+ Off by default (`takeoverAllowed=false`, `keyInjectAllowed=false`), because moving someone's pointer
114
+ is not something an upgrade should switch on. When you turn it on and pass `takeover:true`:
115
+
116
+ 1. **arming** — **amber** HUD (`#3A2C0C` surface, `#F0AD18` accent bar). Says what is about to be
117
+ borrowed (cursor / keyboard / focus), with the interrupt key that actually registered. Default
118
+ 800 ms; this is the cancellation window.
119
+ 2. **active** — **red** HUD (`#3A1212` / `#E84040`). The cursor is placed on the action point, the
120
+ action runs through the cheapest existing door, and the HUD counts elapsed/limit and characters
121
+ injected.
122
+ 3. **done** — **green** HUD (`#0E2E1E` / `#34C77B`). The cursor is restored (read-back verified), the
123
+ focus is returned through the same one-shot table, and the HUD says so.
124
+
125
+ The colour is not decoration: while an agent borrows the pointer the owner is looking at the *target*
126
+ window, so the phase is encoded twice — the whole surface tint **and** a 5px accent bar — and
127
+ `test/hud-test.ps1` reads the real pixels to assert the three are distinct (C18). Amber = not yet
128
+ (cancellable), red = holding something of yours right now, green = returned.
129
+
130
+ **The keys, which are easy to mix up:**
131
+
132
+ | | key |
133
+ |---|---|
134
+ | interrupt the running takeover | **`Ctrl+Alt+X`** (the one that registered; candidates `X→Z→C→V→B→N` then `Ctrl+Shift+X`, displayed as `abortChord=`) |
135
+ | same thing, no keyboard | the HUD's 取消 / 停止 button (same flag, no priority) |
136
+ | pause the whole engine (also aborts a running takeover) | **`Ctrl+Alt+Q`**, here **`Ctrl+Alt+W`** because another app owns Q; `status` reports `pauseHotkey=` |
137
+
138
+ The abort chord lives only while the HUD exists (its window owns the registration); the pause key is a
139
+ permanent server-side switch. Three interruption paths, all writing the same flag/file: HUD button,
140
+ abort chord, and the host's cancellation (`exec.signal` → a latch file the engine polls, because the
141
+ worker is single-threaded and cannot read a request while an action is running). Interruption returns
142
+ `takeover_aborted` **with** `cursorRestored` and `injectedChars` — it is not a fault, it is the feature.
143
+
144
+ Keyboard injection (`keyInput:"inject"`) exists only inside this tier, because `SendInput` writes to
145
+ the **foreground** window: measured, text sent while another window was in front landed in that
146
+ window and not in the intended one. The engine therefore asserts `GetForegroundWindow() == target`
147
+ before sending, re-asserts at send time, and refuses with `keyinject_unavailable` otherwise. It never
148
+ injects mouse events — `MOUSEEVENTF_*` is banned repo-wide, so the module is structurally unable to
149
+ click. Success is reported as `effect=reported-by-send`, never as "verified". Unicode injection
150
+ carries no hardware scancode, which is why a rare scancode-only target would ignore it — documented,
151
+ not a bug.
152
+
100
153
  ## What it does not do
101
154
 
102
- - **No synthetic input.** There is no `physical` option: it is absent from the schema, not disabled
103
- by default. No `SendInput`, no `keybd_event`, no `mouse_event`.
155
+ - **No mouse injection.** `MOUSEEVENTF_*`, `mouse_event` and `keybd_event` are banned in every
156
+ shipped file. The takeover tier moves the cursor instead of clicking synthetically — that is why
157
+ "the agent can type into the foreground" does not become "the agent can click anything".
158
+ - **No takeover without the HUD.** `takeover_unavailable` is a refusal, not a warning, and the
159
+ request is never downgraded silently into the quiet tier.
104
160
  - **No forged-Alt foreground trick.** That route works and other plugins use it, but it injects a
105
161
  real key event — a keystroke you make in that window can land in whichever window the trick just
106
162
  raised.
107
163
  - **No OCR / Set-of-Marks / pixel fallback.** Not part of this claim, and already done well elsewhere.
108
164
  - **No watchdog.** The restore is one-shot and happens inline. A watchdog that keeps chasing the
109
165
  foreground would fight you.
110
- - **Terminals are refused** (`terminal_no_door`): their text surface exposes neither a child window
111
- nor a `Document` element. That is the target a developer most wants driven quietly, and it is the
112
- one that cannot be.
166
+ - **Terminals are still refused** (`terminal_no_door`), and now for a measured reason. The 0.2.0 plan
167
+ was to drive one by typing into it; two probes say otherwise on this host: 242 `KEYEVENTF_UNICODE`
168
+ events with the terminal in the foreground and Enter sent produced nothing, and a scan-code arm
169
+ (262 events, layout-correct) produced nothing either. Their text surface also exposes no writable
170
+ child and no `Document` element. The code stays, the reason names what does work (a target with a
171
+ real door), and the claim is withdrawn rather than shipped as a promise.
113
172
 
114
173
  ## Install
115
174
 
@@ -133,6 +192,10 @@ degradation.
133
192
  | `requestTimeoutMs` | `20000` | a worker that stops answering is killed and restarted on the next call |
134
193
  | `powershellPath` | `""` | override the interpreter (pwsh accepted) |
135
194
  | `logWorkerStderr` | `false` | forward worker diagnostics to the host log |
195
+ | `takeoverAllowed` | `false` | allow `takeover:true`: cursor may move (always restored), focus held, HUD mandatory |
196
+ | `keyInjectAllowed` | `false` | allow `keyInput:"inject"` inside the takeover tier (keyboard only, foreground asserted) |
197
+ | `takeoverMaxMs` | `10000` | hard ceiling for one takeover action (500–60000); the HUD shows the clock |
198
+ | `takeoverArmMs` | `800` | length of the arming phase: the window in which you can cancel before anything moves |
136
199
 
137
200
  ## What measurement established
138
201
 
@@ -156,12 +219,52 @@ goal statement did not survive it. Kept here rather than quietly dropped:
156
219
  UIA `Invoke` was foreground-neutral in 0 of 12 rounds — the earlier 6/6 and 12/12 were measured
157
220
  under a construction that first took the foreground away. The flash tier is a fuse, not a promise
158
221
  of disturbance.
222
+ - **An empty accessibility tree is a switch, not a delay.** The alternative reading — Chromium
223
+ activates renderer accessibility on demand, so the tree might be merely slow — was tested, not
224
+ assumed away: the same window was re-read in place three times (+0/+700/+1500 ms,
225
+ `scripts/uia-tree-content.ps1`). uTools read **0/0/0** descendants, zero interactive content
226
+ elements every time (one earlier peek the same day saw a single `Chrome Legacy Window` shell
227
+ pane appear, content still 0); DSH on the same desktop read a real tree on the **first** query
228
+ (514 at census time, 1019 raw / 85 content on re-read). Nothing ever trickled in. So the
229
+ engine refuses with `uia_tree_empty` and does **not** poll — there is nothing to wait for — and
230
+ the actual switch is a launch-time state (`--force-renderer-accessibility`) the engine cannot
231
+ impose on a browser the user already has open. `unreachable` is the other world: the tree is
232
+ alive and offers nothing at the named point or element.
159
233
 
160
234
  `elevated_target` is measured live: the engine compares the target's integrity RID against its own
161
235
  and refuses before acting (verified on an elevated Task Manager; 19 medium windows, zero
162
236
  misrefusals). The **restore-failure path on an elevated target** (`restore_failed`) remains
163
237
  unmeasured end-to-end and is stated as such in [docs/refusals.md](docs/refusals.md).
164
238
 
239
+ ### 0.2.0's four new measurements (all re-runnable from `scripts/`)
240
+
241
+ - **The cursor can be placed exactly and put back** — `scripts/probe-setcursor-pos.ps1`:
242
+ `SetCursorPos(+40,+20)` read back as exactly the requested point and the restore landed on the
243
+ original point. The elevated-foreground arm could not be arranged (a non-elevated process cannot
244
+ raise Task Manager), so it is recorded as unmeasured rather than guessed — the decision table
245
+ refuses elevated targets before this primitive anyway.
246
+ - **Injected characters go to the FOREGROUND window, not to the window you meant** —
247
+ `scripts/probe-sendinput-unicode.ps1`: with window B in front, the text landed in B and window A
248
+ received nothing; the reverse arm (A in front, including Chinese characters) landed in A. That is
249
+ the measurement S1 rests on.
250
+ - **The terminal cannot be typed into from here** — `scripts/probe-console-inject.ps1` and
251
+ `scripts/probe-console-scan.ps1`: Unicode and scan-code arms both accepted by `SendInput`, both
252
+ with the terminal in the foreground, neither executed. This is why the terminal claim is withdrawn.
253
+ - **A WPF window can be click-through on empty space while its button stays clickable** —
254
+ `scripts/probe-hittest-children.ps1`: the naive `HwndSource` hook received `WM_NCHITTEST` but its
255
+ return value did not reach hit-testing (empty point still answered `HTCLIENT`); a `WNDPROC`
256
+ subclass returning `HTTRANSPARENT` outside the button rect works — measured `-1` on empty space,
257
+ `WindowFromPoint` no longer returning the HUD, and `HTCLIENT` on the button. That is what
258
+ `hud.ps1` ships.
259
+
260
+ ## Verifying the copy you actually installed
261
+
262
+ Every test above imports the repository checkout, so a package that installs to the wrong place or ships
263
+ a stale `lib/` would still pass all of them. `node test/smoke-installed.mjs <path-to-installed-package>`
264
+ drives the **installed** copy: it lists a real window, runs a takeover click, asserts
265
+ `takeover=on cursorRestored=true abortChord=…`, and checks that the HUD is torn down afterwards. Run once
266
+ against the desktop profile after installing, as the last step of a release.
267
+
165
268
  ## License
166
269
 
167
270
  MIT
package/docs/refusals.md CHANGED
@@ -19,29 +19,34 @@ R2′ 把「拒绝」当成本产品的**正常结果**(`engine.ps1` 首段注
19
19
 
20
20
  | 层 | 出处 | 数量 | 语义 |
21
21
  |---|---|---|---|
22
- | 决定层 | `src/engine/decide.ps1` 的 `$WpmRefusals` | 6 | 动作**在执行之前**被合法否决,目标本身没被碰过 |
23
- | 运行时失败层 | `src/engine/engine.ps1` 执行/回还段 | 2 | 决定说「能做」,做的过程中通道炸了或回还没成 |
22
+ | 决定层 | `src/engine/decide.ps1` 的 `$WpmRefusals` | 10 | 动作**在执行之前**被合法否决,目标本身没被碰过 |
23
+ | 运行时失败层 | `src/engine/engine.ps1` 执行/回还段 | 3 | 决定说「能做」,做的过程中通道炸了、回还没成,或**被所有者/宿主中断** |
24
24
 
25
- 混在一起会让人以为「8 个码都是设计好的分支」,实际后 2 个是**兜底**:它们出现就意味着
25
+ 混在一起会让人以为「10 个码都是设计好的分支」,实际后 2 个是**兜底**:它们出现就意味着
26
26
  引擎的判断与实际能力不一致,属于需要调查的信号,不该被当成正常分支来轮询。
27
27
 
28
- ## 决定层(6 码)
28
+ ## 决定层(10 码)
29
29
 
30
30
  | 码 | 触发条件(代码位置) | 语义 | 下一步动作 | 实测状态 |
31
31
  |---|---|---|---|---|
32
- | `no_hwnd` | `engine.ps1:109`(hwnd 不是活窗口)/`decide.ps1:73`(未给 hwnd) | 没有可用目标 | 先调 `wpm_windows` 拿 hwnd,再重试;不要用屏幕坐标猜 | **REAL** — `test/refusals-test.ps1` R1:`hwnd=1` 直接返回该码 |
33
- | `paused` | `decide.ps1:69`(`$script:WpmPaused`) | 所有者按了暂停 | 停手。这是**服务端**拒绝,不是提示层建议;不要换目标绕过 | **REAL** — R2:真实桌面上把 paused 打开,`status` 返回该码 |
34
- | `elevated_target` | `decide.ps1:77`(`facts.elevatedTarget`);flag 由 `win.ps1` 的 `WpmWin::IsElevatedTarget` 实测置真 | 目标完整性级别更高,当前进程写不进去 | 让所有者用非提权方式重开该程序;不要提权重试 | **REAL** — 2026-11-20 `test/integrity-probe.ps1`:桌面上任务管理器(0x3000 high)被识别,`Get-WpmFacts` → `elevatedTarget=True`,决策 `refuse/elevated_target`;其余 19 个 medium 窗零误判 |
35
- | `unreachable` | `decide.ps1:111`(测过:无消息门、无可用 pattern);运行时窄路 `engine.ps1:150,159,165,185,195` | 目标没有任何可在不注入物理输入的前提下使用的门 | 换目标;或让目标暴露可寻址子窗(原生 Win32/WinForms) | **REAL** — R3:WinForms 目标按名字取控件 → 消息门被抑制、WinForms 无 pattern → 该码 |
36
- | `terminal_no_door` | `decide.ps1:84`(family=terminal 且两门皆无) | 终端文字面既不暴露子 HWND,也没有 Document 元素 | 换目标(浏览器地址栏/记事本等),终端不在可驱动面内 | **SIMULATED** — 判定层注入。真实终端窗实测刻意推迟,理由见下 |
37
- | `needs_facts` | `decide.ps1:65,107` | 调用方没给这个目标的实测事实 | 先测量再决定。**拒绝,而不是默认走安静档** | **REAL(表级)** — 引擎内不可达:`facts` 恒被测量,本码只在表被单独使用时出现 |
38
-
39
- ## 运行时失败层(2 码)
32
+ | `no_hwnd` | `engine.ps1:180`(hwnd 不是活窗口)/`decide.ps1:85`(未给 hwnd) | 没有可用目标 | 先调 `wpm_windows` 拿 hwnd,再重试;不要用屏幕坐标猜 | **REAL** — `test/refusals-test.ps1` R1:`hwnd=1` 直接返回该码 |
33
+ | `paused` | `decide.ps1:79`(`[WpmCtl]::Paused`) | 所有者按了暂停 | 停手。这是**服务端**拒绝,不是提示层建议;不要换目标绕过 | **REAL** — R2:真实桌面上把 paused 打开,`status` 返回该码 |
34
+ | `elevated_target` | `decide.ps1:89`(`facts.elevatedTarget`);flag 由 `win.ps1` 的 `WpmWin::IsElevatedTarget` 实测置真 | 目标完整性级别更高,当前进程写不进去 | 让所有者用非提权方式重开该程序;不要提权重试 | **REAL** — 2026-11-20 `test/integrity-probe.ps1`:桌面上任务管理器(0x3000 high)被识别,`Get-WpmFacts` → `elevatedTarget=True`,决策 `refuse/elevated_target`;其余 19 个 medium 窗零误判 |
35
+ | `unreachable` | `decide.ps1:143`(测过:无消息门、无可用 pattern,**且树里有内容**);运行时窄路 `engine.ps1:246,255,261,275,281,291` | 树是活的、点也认了,但那个点/那个名字上没有任何可用 pattern——「换一处或换目标」的世界 | 换目标、换坐标或换元素名;或让目标暴露可寻址子窗(原生 Win32/WinForms) | **REAL** — R3:WinForms 目标按名字取控件 → 消息门被抑制、WinForms 无 pattern → 该码 |
36
+ | `uia_tree_empty` | `decide.ps1:140`(`facts.uiaTreeEmpty`,由 `win.ps1` 的 `Test-WpmUiaTreeHasContent` 实测:树内 **0 个内容元素**) | 树里只剩壳,一个可驱动的内容元素都没有。**主成因**(2026-11-21 普查实测):应用侧没开无障碍(uTools:raw=1/1/1、其中 0 个可交互元素,三连读全等;同日普查测得 raw=0/0/0——壳来去,内容从不出现)。**已知第二成因**(同轮挂泵靶窗实测):泵挂死的应用对 WM_GETOBJECT 不作答,UIA 立即回 0 个元素——同一观察,成因不同 | 让应用以开启无障碍的方式重启(Chromium:`--force-renderer-accessibility`,启动期开关);或换目标。若目标同时处于「未响应」状态,先等应用恢复。**不要重试轮询**——三次原位重查证明等不出内容 | **REAL** — 2026-11-21 对 uTools 真窗实测引擎端到端返回该码(扫描与点两条路);对照 DSH 同桌首读即出真树(普查 514、复测 1019) |
37
+ | `uia_probe_failed` | `decide.ps1:136`(`facts.uiaProbeFailed`,即探针 `uiaErr` 非空) | 探针本身抛了异常(元素在测量中途被销毁等),**树测没测成**——对目标下任何结论都无凭据 | 读 reason 里 `[uia: …]` 段的异常原文再判断;不要把它当成「目标不可达」的证据,也不要自动重试 | **REAL** — 2026-11-21 探针异常实例:WM_CLOSE 于调用后 40ms 落进探针(`IsWindow` 已过、`FromHandle` 抛「无法识别的错误」),返回该码且 reason 带 `[uia: …]` 异常原文 |
38
+ | `terminal_no_door` | `decide.ps1`(family=terminal 且两门皆无) | 终端文字面**有 3 个子 HWND,但无一可写**:`DRAG_BAR_WINDOW_CLASS` 是标题栏拖拽条,`DesktopWindowContentBridge` 是 DirectComposition 渲染目标(不接受 `WM_CHAR`/`WM_SETTEXT`),`InputSite.WindowClass` 是 0×0 的输入接收器;也没有可用的 UIA pattern | **换目标**(浏览器地址栏/文本框/WinForms 编辑框)。**「改用键盘注入」这条路已被实测否决**:Unicode 与扫描码两臂都被 SendInput 接受、前台也对,终端就是不执行——所以本码不再把注入写成下一步 | **REAL(窗口普查 + 注入实测)** — 2026-11-23:只读枚举 CASCADIA 终端 3 子窗无一可写(findings §B);`scripts/probe-console-inject.ps1`(242 事件、Enter 已发、文件未生成)与 `scripts/probe-console-scan.ps1`(262 事件、同样失败)见 findings §G3 |
39
+ | `needs_facts` | `decide.ps1` | 调用方没给这个目标的实测事实 | 先测量再决定。**拒绝,而不是默认走安静档** | **REAL(表级)** — 引擎内不可达:`facts` 恒被测量,本码只在表被单独使用时出现 |
40
+ | `takeover_unavailable` | `decide.ps1`(`facts.takeoverRequested && !facts.hudReady`);宿主侧 `lib/index.js` 在 `takeoverAllowed=false` 时直接拒,零 worker 请求 | 要求接管档,但**接管面不存在**:HUD 没起来,或设置里 `takeoverAllowed` 关着 | 在设置里打开 `takeoverAllowed`;HUD 是**硬前置**,不是装饰。不想接管就**去掉 `takeover:true`** 走静默档——本码存在的意义正是「绝不静默降级」 | **REAL** — `test/plugin-test.mjs`(宿主闸:默认关 + `takeover:true` ⇒ 该码且工作进程 0 请求);`test/takeover-test.ps1` 决策臂 |
41
+ | `keyinject_unavailable` | `decide.ps1`(注入不在接管档内/`keyInjectAllowed` 关/目标不是前台且抬不起来);`engine.ps1`(发送瞬间前台已变) | 要求键盘注入,但注入会打到**别的窗口**或没被授权。依据是实测:`SendInput` 只写前台(`scripts/probe-sendinput-unicode.ps1` arm B:文本落在前台窗 B,而不是调用方以为的 A) | 先自己把目标切到前台(或用 `focus` 动作把它抬上来),或关掉 `keyInput` 用静默档;不允许「盲注入」 | **REAL** — `test/keyinject-test.ps1` K1(非前台拒绝,注入零次)、K5(双闸独立);判定层两条用例 |
42
+
43
+ ## 运行时失败层(3 码)
40
44
 
41
45
  | 码 | 触发条件 | 语义 | 下一步动作 | 实测状态 |
42
46
  |---|---|---|---|---|
43
47
  | `action_failed` | `engine.ps1:218`(通道调用抛异常) | 决定说能做,实际调用炸了 | 报给所有者并附异常原文;同一目标不要自动重试第二次 | **NOT-COVERED** — 需要可稳定抛错的真实目标,本轮未构造 |
44
- | `restore_failed` | `engine.ps1:266`(表判 restore、OS 拒绝 SetForegroundWindow) | 所有者被留在了一个不是他选的窗口里 | 立刻上报;不要静默重试,也不要启动看门狗抢第三次 | **NOT-COVERED** — 需提权窗配合,属 task_52 |
48
+ | `restore_failed` | `engine.ps1`(表判 restore、OS 拒绝 SetForegroundWindow) | 所有者被留在了一个不是他选的窗口里 | 立刻上报;不要静默重试,也不要启动看门狗抢第三次 | **NOT-COVERED** — 需提权窗配合,属 task_52 |
49
+ | `takeover_aborted` | `engine.ps1`(HUD 按钮/中断键/宿主取消,三路汇聚后置位) | 接管被**人**或**宿主**中止了。这不是故障,是 R3 承诺的能力:结果里仍带 `cursorRestored` 与 `injectedChars`,让读者知道做到哪一步 | 读 `injectedChars` 判断已写入多少;要接着做就**重新发起**一次动作(不会从断点续写)。不要把它当成失败来重试 | **REAL** — `test/takeover-test.ps1` 三臂(volatile 标志/latch 文件/长文本中途中断),每臂都断言光标回位 |
45
50
 
46
51
  ## 三个诚实的缺口(写在文档里,而不是留白)
47
52
 
@@ -54,14 +59,26 @@ R2′ 把「拒绝」当成本产品的**正常结果**(`engine.ps1` 首段注
54
59
  **仍缺的**:`restore_failed` 兜底路径(提权窗 + 抬前台被 OS 拒绝的端到端)需要提权窗口在跑
55
60
  battery 时在场;本轮 Task Manager 在场时测到了识别与拒绝,恢复兜底未触发。
56
61
  2. **`action_failed` / `restore_failed` 没有实测样例。** 表中标 NOT-COVERED,不写「已支持」。
57
- 3. **`terminal_no_door` 只有判定层实测。** 本轮不拉真实终端窗口,是因为 `findings.md:311-316` 记录过一次
58
- `wt --headless` 残留 Error 弹窗事故(单实例转发 + 弹窗归属真实宿主,`Stop-Process` 够不到)。
59
- 真实证据是覆盖率普查:`findings-G0-VERDICT.md` 的 `uap-framed` 30 窗 0 门。
62
+ 3. **`terminal_no_door` 的措辞已在 2026-11-23 依据实测修正**:不再是「不暴露子 HWND」,而是
63
+ 「有 3 个子 HWND 但无一可写」(findings §B 只读枚举)。该码保留的价值是**诊断 + 指出下一步**
64
+ (`takeover:true` + `keyInput:'inject'`),不是死路;终端的**可写不可读**限制写在
65
+ `docs/takeover.md`。
66
+ 4. **`uia_probe_failed` 的可执行用例只有判定层一条**(schema 里 `click-uia-probe-failed`,decision 模式)。
67
+ 引擎级用例需要「探针必然抛异常」的稳定构造,本轮拿到了**真样本**但没固化成可复跑用例:构造是
68
+ 「引擎调用开始后 N ms,由一个原生 OS 线程向靶窗投递 WM_CLOSE」(销毁落在 `IsWindow` 与
69
+ `FromHandle` 之间的窗口里);2026-11-21 扫描 40ms 一档即命中(reason 带 `[uia: …FromHandle…
70
+ 无法识别的错误…]`)。它是竞态:延迟档位选错就落到 `no_hwnd`(先销毁)或 `unreachable`
71
+ (后销毁),而「只销毁控件不销毁窗体」和「泵挂死」两个变体都会被逐元素的内部 catch 吞掉、
72
+ 读成 `uia_tree_empty` 而不是抛错——所以做成 schema 可执行用例需要一个能精确中断跨进程 COM
73
+ 的靶窗,留给后续轮次。
60
74
 
61
75
  ## 与工具 schema 的关系
62
76
 
63
77
  - `src/schema/tools.json` 的 `refusals` 数组是机器可读形态;每个动作型工具(`wpm_click` / `wpm_type` /
64
78
  `wpm_focus`)列出它可能返回的码,并带**可执行**的拒绝路径用例。
79
+ - R3 新增三码(`takeover_unavailable` / `keyinject_unavailable` / `takeover_aborted`)**同批**写进代码、
80
+ schema 与本表,由 `scripts/check-refusals.mjs` 三方对齐检查;`takeover_aborted` 是运行时结果,
81
+ 其 schema 用例声明为 uncovered 并附理由(`tools.json` 的 `uncoveredReason`)。
65
82
  - `wpm_windows` / `wpm_status` 是只读查询,**不产生拒绝码**。与其编造一条假分支,不如在 schema 里写
66
83
  `noRefusalReason` 并让门禁检查它非空。
67
84
  - `test/schema-test.mjs` 校验:码集合三方一致、用例参数能通过该工具的 inputSchema、每个动作型工具至少一条用例。
@@ -0,0 +1,129 @@
1
+ # 接管档(Takeover Tier)
2
+
3
+ > 0.2.0 起,本插件有一个**默认关闭**的第三档:`takeover:true`。本文说明它借走什么、怎么还、怎么被中断,
4
+ > 以及**它明确做不到什么**。所有数字都出自 `scripts/` 里可复跑的探针与 `test/` 里可复跑的测试。
5
+
6
+ ## 四档总表
7
+
8
+ | 档 | 何时进入 | 光标 | 焦点 | 键盘 | HUD |
9
+ |---|---|---|---|---|---|
10
+ | `quiet` | 窗口消息门存在(默认首选) | 0 px | 0 变更 | 零注入 | 无 |
11
+ | `bounded-flash` | 只有 UIA pattern | 0 px | 一次闪光,自动回还(实测净回还 15–95 ms) | 零注入 | 无 |
12
+ | **`takeover`** | 显式 `takeover:true` 且两关都开 | **移到动作点,必复位** | 持有至动作结束,然后按表回还 | 仅 `keyInput:"inject"` 时注入 | **必需,三段式** |
13
+ | `refuse` | 任何前置不满足 | — | — | — | 拒绝码 |
14
+
15
+ **接管档不新增点击通道。** 点击仍走 message/UIA;`SetCursorPos` 只是让所有者**看见** agent 指到哪,
16
+ `SendInput` 只在目标连门都没有时才作为最后手段。**鼠标注入永远不存在**:`MOUSEEVENTF_*` 全仓禁止。
17
+
18
+ ## 两个开关,默认都关
19
+
20
+ | 设置 | 默认 | 含义 |
21
+ |---|---|---|
22
+ | `takeoverAllowed` | `false` | 允许 `takeover:true`;关着时**拒绝** `takeover_unavailable`,**不静默降级** |
23
+ | `keyInjectAllowed` | `false` | 允许接管档内的 `keyInput:"inject"`;关着时拒绝 `keyinject_unavailable` |
24
+ | `takeoverMaxMs` | `10000` | 单次动作上限(500–60000),HUD 实时显示时钟 |
25
+ | `takeoverArmMs` | `800` | 预警段时长:光标移动/按键之前的可取消窗口 |
26
+
27
+ 默认全关是产品决定:升级不该让别人的指针自己动起来。
28
+
29
+ ## 三段式 HUD
30
+
31
+ | 段 | 时长 | 配色(底色 / 左侧 5px 色条 / 文字) | 显示 | 可做的操作 |
32
+ |---|---|---|---|---|
33
+ | `arming` | `takeoverArmMs`(默认 800 ms) | **琥珀** `#3A2C0C` / `#F0AD18` / `#FFD88A` | 「即将使用你的鼠标/键盘/焦点 · <action>」+ **实际注册到的中断键** | 取消 |
34
+ | `active` | 至动作结束或上限 | **红** `#3A1212` / `#E84040` / `#FFBEBE` | 「占用中 · 已用 1.2s / 上限 10s · 已注入 N 字」 | 停止 |
35
+ | `done` | 默认 1500 ms | **绿** `#0E2E1E` / `#34C77B` / `#B2F0CD` | 「已归还:光标已复位」 | 无(按钮禁用) |
36
+
37
+ **为什么是三色而不是三种文案。** 接管期间所有者的注意力在目标窗口,不在右下角这块 470×104 的浮窗上;
38
+ 读一句话的成本远高于扫一眼颜色。所以相位被编码**两遍**:整块底色 + 左侧 5px 色条(只靠底色在屏幕边缘容易漏看)。
39
+ 配色按语义选,不按好看选:**琥珀=还没开始(可取消)**、**红=正在占用(此刻在花你的东西)**、
40
+ **绿=已归还(没占着任何东西)**。`test/hud-test.ps1` 的 C18 五臂直接读像素断言这三色互不相同且各自主导。
41
+
42
+ 窗口属性(`test/hud-test.ps1` 实测):`WS_EX_TOPMOST | WS_EX_NOACTIVATE`,`ShowActivated=false`,
43
+ **不加** `WS_EX_TRANSPARENT`(按钮要能点),启动前后 `GetForegroundWindow()` 不变。
44
+ **空白穿透**用 `WNDPROC` 子类化:按钮矩形外返回 `HTTRANSPARENT`,按钮内交回 WPF。
45
+ (`HwndSource` 的 hook 收得到 `WM_NCHITTEST`,但返回值不影响命中测试——实测失败方案,见
46
+ `scripts/probe-hittest-children.ps1`。)
47
+
48
+ ## 三个键,别记混
49
+
50
+ | 想做什么 | 键 | 说明 |
51
+ |---|---|---|
52
+ | **打断正在进行的接管** | **`Ctrl+Alt+X`** | 本机实测注册成功的那个。候选表:`Ctrl+Alt+X` → `Z` → `C` → `V` → `B` → `N` → `Ctrl+Shift+X` → `Ctrl+Alt+Shift+X`,取第一个能注册的;**HUD 上显示的是真的那个**,不是文档承诺的那个 |
53
+ | 同一件事的备用手段 | **点 HUD 的「取消」/「停止」按钮** | 按钮与热键写的是同一个标志,没有优先级 |
54
+ | **暂停整个引擎**(不只是当前动作) | **`Ctrl+Alt+Q`** | 本机被别的程序占了(Win32 1409),实际注册为 **`Ctrl+Alt+W`**,`status` 里 `pauseHotkey=` 会如实报。**暂停也会立刻中断正在进行的接管** |
55
+ | 宿主取消 | 无键 | `exec.signal` → latch 文件,引擎每 50 ms 轮询 |
56
+
57
+ 中断键与暂停键是**两个不同的东西**,这一点容易混:中断键只在接管期间存在(HUD 窗口拥有它,窗口销毁即注销),
58
+ 暂停键是常驻的服务端开关(拒绝后续所有动作,并打断当前接管)。
59
+ ## 三路中断
60
+
61
+ 三条路写的是**同一个**标志/文件,所以不存在「哪个才算数」:
62
+
63
+ 1. **HUD 的停止按钮** → `[WpmCtl]::TakeoverAbort = true`(跨线程只写 volatile,不做
64
+ `Dispatcher.Invoke`——那条路实测 1818 ms 且有时不返回)。
65
+ 2. **全局中断键** → 候选表从 `Ctrl+Alt+X` 起逐试,注册成功者写进 `AbortChordLabel`,
66
+ **HUD 显示的是真的那个键**;全失败显示「中断键不可用,请点按钮」,不伪造。
67
+ 3. **宿主取消**(`exec.signal`)→ Node 写 latch 文件
68
+ `%LOCALAPPDATA%/wpm/takeover-abort.<worker pid>`,引擎每 50 ms `Test-Path`。
69
+ **为什么是文件**:worker 是单线程的,动作进行中读不到新请求,所以进程内标志不够。
70
+
71
+ 中断结果不是故障:返回 `takeover_aborted`,并**仍带** `cursorRestored` 与 `injectedChars`,
72
+ 让读者知道做到哪一步。要接着做就重新发起(不会从断点续写)。
73
+
74
+ ## 光标:借了必须还
75
+
76
+ - 移动前先读存证(`GetCursorPos`),移动后**读回校验**;读回不等于请求时 `cursorMoved=false`。
77
+ - 复位放在**同一个** `try/finally` 里:成功、异常、拒绝、中断四条路都到那里。
78
+ - 复位结果同样是读回:`cursorRestored=false` ⇒ 下游 `proof=fail`,理由写「借了未还」。
79
+ **这是唯一一条硬红线**:桌面静不静都不能替它辩护。
80
+ - `scripts/check-takeover-path.mjs` 的 G4 把「移动与复位同处一个 try/finally」做成**静态**断言——
81
+ 运行时采样只能证明「这次没发生」。
82
+
83
+ ## 键盘:只在接管档、只在前台、只能打字
84
+
85
+ - **S1 前台即目标。** `SendInput` 把键送进**当前前台**窗口,不看「你以为的目标」。实测
86
+ (`scripts/probe-sendinput-unicode.ps1`):B 在前台时,文本落到 B,A 什么都没收到。
87
+ 所以注入前断言 `GetForegroundWindow()==target`(子窗按根窗比对),抬不起来就拒绝
88
+ `keyinject_unavailable`,**绝不盲注入**;发送瞬间还会再断言一次(预警窗口期间桌面可能变)。
89
+ - **S2 逐字可中断。** 每 8 字符或 50 ms 查一次中断;命中即停,返回**实际**发出的字符数。
90
+ - **S3 不动鼠标。** 只构造 `INPUT_KEYBOARD`;门禁禁止 `MOUSEEVENTF_*` 常量,结构上点不了。
91
+ - **字符方案:** `KEYEVENTF_UNICODE`(逐字),不受键盘布局与死键影响,中文/emoji 可用。
92
+ **代价**:不带硬件扫描码,极少数只认扫描码的目标(某些游戏、远端 IP-KVM)不响应——已知限制。
93
+ - **effect 只能报 `reported-by-send`**:`SendInput` 返回的是「入队事件数」,不证明目标处理了。
94
+
95
+ ## 终端:这条承诺被实测撤回
96
+
97
+ 0.2.0 的计划是「终端无门 → 用键盘注入驱动它」。**实测否决**(2026-11-23,本机):
98
+
99
+ | 探针 | 做法 | 结果 |
100
+ |---|---|---|
101
+ | `scripts/probe-console-inject.ps1` | 新建专用 Windows Terminal 窗,`KEYEVENTF_UNICODE` 逐字注入一条命令 + Enter | SendInput 接受 **242 事件**,`foregroundIsTarget=true`,Enter 已发,**文件未生成** |
102
+ | `scripts/probe-console-scan.ps1` | 同窗口,改用布局扫描码(`KEYEVENTF_SCANCODE` + `VkKeyScanW`) | **262 事件**,前台正确,**同样未执行** |
103
+
104
+ 结论:本机终端**不接受合成输入**(GUI 目标正常——同一套代码在 WinForms 文本框里中文落字成功)。
105
+ 因此 `terminal_no_door` **保留**,理由改成「换一个真有门的目标」,而不是把注入写成下一步。
106
+ **终端仍然不可写、不可读**:没有可用门,也没有 UIA `Document`,注入又无效——
107
+ 不要从本文读出「能驱动终端」的暗示。
108
+
109
+ ## 拒绝码与下一步
110
+
111
+ | 码 | 层 | 触发 | 下一步 |
112
+ |---|---|---|---|
113
+ | `takeover_unavailable` | decision | 请求了接管,但设置关着或 HUD 没起来 | 打开 `takeoverAllowed`;或去掉 `takeover:true` 用静默档 |
114
+ | `keyinject_unavailable` | decision | 注入不在接管档内/开关关着/目标不是前台且抬不起来 | 自己把目标切前台(或先 `focus`),或关掉 `keyInput` |
115
+ | `takeover_aborted` | runtime | HUD 按钮/中断键/宿主取消 | 读 `injectedChars` 知道做到哪;要接着做就重发 |
116
+
117
+ 细节与三方对齐规则见 [refusals.md](refusals.md)。
118
+
119
+ ## 测试与门禁
120
+
121
+ | 命令 | 覆盖 |
122
+ |---|---|
123
+ | `node scripts/check.mjs` | 11 道闸,含「光标/注入白名单」与「接管路径 G1–G5(带注入自测)」 |
124
+ | `powershell -STA -File test/hud-test.ps1` | 窗口属性、**不抢焦点**、三段相位、按钮/热键写同一标志、实际 chord |
125
+ | `powershell -STA -File test/takeover-test.ps1` | I1/I3/I4/I5 不变式、正常与中断路径的光标回位、决策臂 |
126
+ | `powershell -STA -File test/keyinject-test.ps1` | K1(非前台零注入)、K3(长文本可中断)、K4(Unicode 落字)、K5/K6(双闸与 effect) |
127
+
128
+ **这三个桌面测试不在 `check.mjs` 里**:它们会移动真实光标、注入真实按键,而门禁是给「随时可以跑」用的。
129
+ 它们是手动臂,结果记录在计划的 checklist 里。
package/dsh.plugin.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-windows-parallel-mcp",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "main": "./lib/index.js",
5
- "description": "One tool, five actions: drive a Windows window without moving the cursor or stealing the keyboard. Prefers window messages (zero foreground change); falls back to UI Automation with a bounded, self-reversing focus flash (measured net return 15-95 ms).",
5
+ "description": "One tool, five actions: drive a Windows window quietly by default. Prefers window messages (zero foreground change); falls back to UI Automation with a bounded, self-reversing focus flash (measured net return 15-95 ms); offers an opt-in takeover tier (takeoverAllowed) where the cursor moves to the action point and is always restored, with a mandatory three-phase HUD and three interruption paths.",
6
6
  "engines": {
7
7
  "dsh": ">=0.1.7-0 <0.3.0-0"
8
8
  },
@@ -10,7 +10,7 @@
10
10
  "tools": [
11
11
  {
12
12
  "name": "wpm",
13
- "description": "Drive a Windows window without moving the cursor or stealing the keyboard (actions: windows, status, click, type, focus)."
13
+ "description": "Drive a Windows window quietly by default (actions: windows, status, click, type, focus), with an opt-in takeover tier that is visible, interruptible and always restores the cursor."
14
14
  }
15
15
  ],
16
16
  "skills": []