dsh-windows-parallel-mcp 0.5.0 → 0.7.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # dsh-windows-parallel-mcp
2
2
 
3
3
  **English** · [中文](README.zh.md) · [日本語](README.ja.md) · [한국어](README.ko.md) · [Français](README.fr.md) · [Deutsch](README.de.md) · [Italiano](README.it.md) · [Español](README.es.md) · [Português](README.pt.md) · [Русский](README.ru.md)
4
- > **Current release: 0.5.0** — this document describes the contract as of that version. What
4
+ > **Current release: 0.7.0** — this document describes the contract as of that version. What
5
5
  > changed in it, and in every version before it, is in [CHANGELOG.md](CHANGELOG.md), newest first.
6
6
 
7
7
  A DSH plugin that lets an agent drive **its own** Windows windows — quietly by default, and visibly
@@ -9,7 +9,7 @@ on request. Where a window accepts a window message, you never lose focus at all
9
9
  exposes UI Automation, you lose focus for one bounded flash that is reversed automatically. Where you
10
10
  explicitly ask for the takeover tier, the cursor moves to the point and is always restored, with a
11
11
  HUD that can stop it three ways. Everywhere else it refuses, with a code and a reason — never with
12
- silence: every refusal carries a code from a closed set of fourteen and the next step.
12
+ silence: every refusal carries a code from a closed set of seventeen and the next step.
13
13
 
14
14
  **The takeover tier defaults off, and that is structural.** The cursor is only ever moved because you
15
15
  opened `takeoverAllowed` **and** asked for it on the call (`takeover:true`), so an upgrade cannot
@@ -27,7 +27,7 @@ bundle with a broad tool surface; this one is a single action tool whose entire
27
27
 
28
28
  ## What it does
29
29
 
30
- One tool, eight actions:
30
+ One tool, eleven actions:
31
31
 
32
32
  | action | what it returns |
33
33
  |---|---|
@@ -39,6 +39,9 @@ One tool, eight actions:
39
39
  | `snapshot` | the accessibility tree as a NUMBERED element table: continuous `label`, control type, name, automation id, screen rect, patterns |
40
40
  | `screenshot` | the window rect captured to a PNG, plus the coordinate mapping as data (`screenRect`, `imageSize`, `scale`, `identity`, `frame`, `dpiAware`) |
41
41
  | `preview` | the marker drawn at a point, and the element under it reported as TEXT — no picture needed |
42
+ | `launch` | start a whitelisted program; reports the pid, and the window only once it really exists |
43
+ | `clipboard` | read or write the system clipboard — a read reports lengths and never the payload |
44
+ | `window` | minimize / restore / move / resize / topmost ONE named window, verified by reading its state back |
42
45
 
43
46
  The engine picks the cheapest available door per call:
44
47
 
@@ -90,7 +93,7 @@ Image coordinates are never multiplied by the caller:
90
93
 
91
94
  ```jsonc
92
95
  {"action":"screenshot","hwnd":"1310720"}
93
- // -> screenRect=0,0,1920,1032 imageSize=1920x1032 scale=1 identity=true frame=dwm
96
+ // -> screenRect=0,0,1920,1032 imageSize=1920x1032 scale=1 identity=true frame=dwm captureBackend=bitblt
94
97
  {"action":"click","hwnd":"1310720","space":"image","shotId":"shot-…","x":350,"y":250}
95
98
  // the ENGINE converts, then still asserts the point belongs to the target window
96
99
  ```
@@ -120,6 +123,23 @@ point at would be a trap), the frame is cross-checked against the window rect th
120
123
  (`frameCheck=pass|fail|unknown`), and a structural gate pins the single-source rule by mutating a copy
121
124
  of the engine and requiring the corresponding red.
122
125
 
126
+ ### Which capture path painted the picture
127
+
128
+ `captureBackend` names the producer: `bitblt` is a direct GDI `BitBlt` off the screen DC, `gdiplus` is
129
+ `Graphics.CopyFromScreen` — either the fallback after BitBlt was refused, or nothing else. The cheap
130
+ path replaced the old one on measured grounds (16–21 ms against 22–33 ms for a 1920×1080 grab), and the
131
+ encoder was deliberately left alone: the PNG encode is the bottleneck (37–39 ms), so JPEG (6 ms, and it
132
+ smears text), WIC (158 ms) and 24bpp (7 % smaller) were each measured and each rejected.
133
+
134
+ Equivalence was established on a **static** scene, not by file hash — two captures of a live desktop
135
+ happen at different instants, so their bytes cannot match, and that difference says nothing about the
136
+ paths: identical size, both non-blank, **0 maximum per-channel difference over 17 388 sampled points**,
137
+ byte-identical PNGs (8940 = 8940), with the comparator's self-check (two reads of one HBITMAP) also at
138
+ 0. The one difference is reported rather than assumed away: `FromHbitmap` yields `Format32bppRgb` where
139
+ `CopyFromScreen` yields `Format32bppArgb`. A gate keeps both halves honest — the fallback reachable and
140
+ `captureBackend` produced, forwarded and printed (`scripts/check-shot-backend.mjs`, seven mutations each
141
+ seen red).
142
+
123
143
  ### Deciding outside the main context
124
144
 
125
145
  The expensive habit this replaces is re-reading a 70-row table on every step. Hand the frame to a
@@ -154,7 +174,7 @@ reported rather than accused — but `cursorRestored=false` (borrowed and not re
154
174
  `proof=fail`.
155
175
 
156
176
  **And it says who reported the success.** Every action result carries `effect=` in the text and
157
- `effect` in the structured output. The three values are not degrees of confidence in the
177
+ `effect` in the structured output. The four values are not degrees of confidence in the
158
178
  application — they name the speaker:
159
179
 
160
180
  | `effect` | who is speaking | it proves | it does **not** prove |
@@ -162,6 +182,7 @@ application — they name the speaker:
162
182
  | `unverified` | nobody | nothing | anything |
163
183
  | `reported-by-send` | the window-message channel | the message was **delivered** | that the target app processed it |
164
184
  | `reported-by-pattern` | the UI Automation pattern call | the call **returned** without throwing | that the interface actually changed |
185
+ | `readback-verified` | the control itself, read back | the value now in the field **equals the value predicted from the field's own measurements** | that the app is *happy* — only that its value is what we said |
165
186
 
166
187
  Since 0.1.3 the effect also enters the judgment, which closes the one honest gap 0.1.2 still had:
167
188
  a still desktop could outvote a total no-op. A call whose channel reported nothing is capped at
@@ -171,6 +192,49 @@ disturb you; it never proves we accomplished anything. A single `reported-by-*`
171
192
  the caveat spelled out in the reason field (`未独立验证` — nobody observed the app), because turning
172
193
  weak-but-real evidence into a red would train its readers to ignore the verdict.
173
194
 
195
+ ### The fourth value has to be earned (0.6.0)
196
+
197
+ `readback-verified` is granted only by the engine, and only when a **prediction** matches a **read**.
198
+ The prediction is computed from measurements the control itself reported — the value it held before,
199
+ its own `WM_GETTEXTLENGTH`, its own `EM_GETSEL` answer for where a typed character lands — and the read
200
+ happens *after* the settle window, so an app that commits its text asynchronously is not judged against
201
+ a half-written buffer:
202
+
203
+ ```jsonc
204
+ {"action":"type","hwnd":"…","text":"XY","caretPosition":"start"}
205
+ // -> type ok channel=message tier=quiet effect=readback-verified
206
+ // detail=msg=char|2 child=… caret=start asked=0 applied=0,0 readback=XYabc readbackLen=5 focusMoved=false
207
+ ```
208
+
209
+ Three things it refuses to do, each measured rather than assumed:
210
+
211
+ * **it does not upgrade what it cannot read.** A masked field (`ES_PASSWORD`) returns an empty string
212
+ while `WM_GETTEXTLENGTH` still reports the real length. That is "the control hides its text", not
213
+ "the field is empty": the result says `readback=unavailable`, the effect keeps whatever the write
214
+ earned, and no value is printed anywhere.
215
+ * **a mismatch is data, not a failure.** A read-only WinForms edit silently refuses `WM_CHAR` — every
216
+ character is accepted by the API and the value never moves — while honouring `WM_SETTEXT`. On the
217
+ refusal the result is still `ok:true` with `readbackMismatch=true` and no upgrade; on the write that
218
+ lands it is `readback-verified`. No refusal code changed for this batch, on purpose: "the application
219
+ formatted my input" is not an error in the call. `test/readback-truth.mjs` asserts both arms against
220
+ the value the *application* wrote about itself, from inside its own process — a readback test that
221
+ compared our write to our read would be grading homework in our own class, and this repo has already
222
+ been caught doing exactly that.
223
+ * **the naive guess is not the model.** Text is not appended: it lands at the caret, and a field that
224
+ never held focus has its caret at 0 (so `abc` + `XY` is `XYabc`). That is why `caretPosition` exists
225
+ and why the result prints `asked=` and `applied=` separately — `EM_SETSEL(-1,-1)` is documented as
226
+ "document end" and measured as a no-op on WinForms EDIT, so `end` is `EM_SETSEL(len,len)` with `len`
227
+ read from the control. On a buffer containing newlines that numeric end can land inside the text
228
+ (`asked=6 applied=4,4`), which is reported instead of hidden; `idle` touches nothing at all. The UIA
229
+ `value` channel replaces the whole value and has no caret to move, so it answers
230
+ `caretIgnored=value-pattern` rather than pretending to honour it.
231
+
232
+ Two more facts ride in the same `detail`, both warnings and neither a refusal: `focusMoved=true` when
233
+ the foreground or the focused control differs between the two measurements taken around the send, and
234
+ `disabled=true` for a target window that is greyed out — Windows keeps answering our messages while
235
+ throwing the input away, so a disabled target loses the right to an `effect` claim
236
+ (`effect=unverified`) without becoming an error.
237
+
174
238
  ## The takeover tier (opt-in)
175
239
 
176
240
  Off by default (`takeoverAllowed=false`, `keyInjectAllowed=false`), because moving someone's pointer
@@ -213,6 +277,93 @@ click. Success is reported as `effect=reported-by-send`, never as "verified". Un
213
277
  carries no hardware scancode, which is why a rare scancode-only target would ignore it — documented,
214
278
  not a bug.
215
279
 
280
+ ## Desktop actions: launch, clipboard, window (0.7.0)
281
+
282
+ Three capabilities that were missing outright — "you cannot even start a program" was the honest answer
283
+ — and none of them is a door action. They choose no channel, cost no tier, and produce no proof window,
284
+ so they live beside `Invoke-WpmAction` rather than inside it, and the door discipline (point ownership,
285
+ the restore table, the proof window) is not widened by any of them.
286
+
287
+ **`launch` — two switches, neither of which implies the other.** `appLaunchAllowed` opens the
288
+ capability; `appLaunchAllow` lists the exact program names or absolute paths that may run, and an
289
+ **empty list means nothing may launch even with the gate on**. Matching is exact and case-folded: there
290
+ is no wildcard, and `notepad` does not authorise `notepad-helper.exe` — a whitelist that grows by prefix
291
+ is a whitelist that authorises more than it says. A refusal is `app_launch_denied` and is raised before
292
+ any worker request, so a refused launch started nothing (asserted with a request counter in
293
+ `test/plugin-test.mjs` and re-checked inside the engine against the same table). The engine's own
294
+ vocabulary for the window is the interesting part: `Process.Start` returns while the app is still
295
+ loading (measured: `MainWindowHandle=0` for 1348 ms on a cold notepad), so a program that has not
296
+ published a window yet answers `ok:true` with `hwnd=""` and `detail=window-not-yet` — neither a fake
297
+ failure nor a fake readiness. Arguments are passed through as given and written to the audit log,
298
+ because listing a program does not vouch for what it is told to do.
299
+
300
+ **`clipboard` — the most private read in this product.** What is on the clipboard may be a password or
301
+ a token the owner copied seconds ago, so a text read reports its **length**, its result text never
302
+ contains the payload, the audit line records `op`/`format`/`chars`, and values are capped at 64 KB with
303
+ `truncated` stated rather than silently cut. An image write accepts a `shotId`, so a screenshot can go
304
+ straight into the clipboard without the caller handling pixels; the read-back compares the size the
305
+ clipboard reports against the size the shot recorded. A clipboard holding neither is refused with the
306
+ format names it did find — an empty success would be indistinguishable from "the clipboard is empty".
307
+
308
+ **`window` — one named window, five ops, each verified by reading the window back.** `IsIconic`,
309
+ `GetWindowRect`, the `WS_EX_TOPMOST` bit — not `ShowWindow`'s return value, because a syscall's answer
310
+ describes the CALL and this product has been burned repeatedly by reporting that as a state. `move` and
311
+ `resize` pass `SWP_NOACTIVATE`, and the result carries `foregroundTaken=true|false` measured on both
312
+ sides of that specific call: `restore` activates by definition (that is what restoring is), and the
313
+ honest answer is to report it, not to hide it or to refuse the op the caller asked for. There is no
314
+ "all windows" op and no `#32770` discovery: acting on a window nobody named is not a convenience.
315
+
316
+ ### One ceiling, eleven actions
317
+
318
+ The old shape of this problem was a boolean per capability, which does not scale past the number of
319
+ settings anyone will actually read. Instead the two axes are independent:
320
+
321
+ ```
322
+ the action declares the lowest rung it can ever need (src/schema/tools.json#requiresTier)
323
+ the owner sets one ceiling (settings: policy)
324
+
325
+ readonly < quiet < flash < takeover
326
+ reads message bounded-UIA real cursor / held focus / launch
327
+ door flash
328
+ ```
329
+
330
+ | `policy` | permits | refuses |
331
+ |---|---|---|
332
+ | `readonly` | `windows`, `status`, `snapshot`, `screenshot`, `preview`, `clipboard` read | every write |
333
+ | `quiet` | + `click` / `type` / `focus` through the message door | the flash tier, `clipboard` write, `window`, `launch` |
334
+ | `balanced` *(default)* | + the bounded-flash tier, `clipboard` write, `window` ops | `takeover:true`, `keyInput:"inject"`, `launch` |
335
+ | `full` | + the takeover tier and `launch` | nothing extra |
336
+
337
+ Above the ceiling a call is refused with **`policy_denied`** and the reason names both numbers (what the
338
+ action needed, what the policy allows), because the correct next step is a settings change and the wrong
339
+ one is a retry. The gate order is `paused → policy → takeoverAllowed/keyInjectAllowed → launch gate +
340
+ whitelist → idle check → the door table`, and every step in it is tested by making two gates disagree
341
+ about which one spoke (`test/plugin-test.mjs`). Two consequences are worth stating plainly rather than
342
+ leaving to discovery: **`takeover:true` now needs `policy:'full'` as well as `takeoverAllowed`** (0.7.0
343
+ raised the bar for the loudest tier on purpose), and `clipboard`'s halves are graded separately
344
+ (`requiresTierFor`), so a `readonly` owner can still read.
345
+
346
+ **Idle instead of a dialog.** When the last *physical* input is younger than `policyIdleMs` (default
347
+ 3000 ms) and the action needs the takeover tier, it is refused with **`user_active`** and nothing is
348
+ clicked — no popup, no countdown. The upstream design asks the owner to consent by interrupting them;
349
+ an interrupt presented as consent is just a second disturbance. The escape hatch is explicit
350
+ (`forceUserActive:true`), it does not bypass any other gate, and the audit line records `forced:true` so
351
+ an interruption caused on purpose stays distinguishable from one caused by accident. An unattended run
352
+ is never blocked by this: with nobody typing, the age grows past the window and the call goes through.
353
+
354
+ ### The audit log
355
+
356
+ Every action appends one JSONL line to `%LOCALAPPDATA%\wpm\audit.log` — allow **and** deny, because a
357
+ trail that records only refusals documents the times the guard worked and is silent about the times it
358
+ had nothing to do with. Fields: `ts, action, hwnd, tier, policy, decision, code, userActiveAgeMs,
359
+ effect, latencyMs`, plus `target`/`args` for a launch and `op`/`format`/`chars` for a clipboard call.
360
+ What is deliberately absent is content: no typed text, no clipboard payload — the second copy of a
361
+ secret is the one nobody protects. `auditKeep` (default 2000) bounds the file, pruning oldest-first when
362
+ a write pushes it past budget. An audit that cannot be written is reported (`auditNote=n write(s)
363
+ failed`) rather than swallowed: a log that looks complete and is not is worse than one that admits it
364
+ is missing lines. This is the only artifact that survives a call, and it is the one thing that can
365
+ answer "what did the agent do to this machine" after the fact.
366
+
216
367
  ## What it does not do
217
368
 
218
369
  - **No mouse injection.** `MOUSEEVENTF_*`, `mouse_event` and `keybd_event` are banned in every
@@ -249,8 +400,10 @@ degradation.
249
400
  ## Typed surface
250
401
 
251
402
  `types/index.d.ts` is written by hand, not emitted from an implementation. It covers the whole
252
- contract: the eight actions, every argument including the takeover fields and the image-space /
253
- label surface, and all fourteen refusal codes as a closed union.
403
+ contract: the eleven actions, every argument including the takeover fields, the image-space / label
404
+ surface, 0.6.0's `caretPosition` and 0.7.0's `target`/`op`/`format`/`forceUserActive`, all seventeen
405
+ refusal codes as a closed union, and `effect` as its own four-value union (`WpmEffect`) beside
406
+ `WpmCaptureBackend`, `WpmClipboardOp`, `WpmWindowOp`, `WpmPolicy` and `WpmFrameSource`.
254
407
 
255
408
  Its wiring is measured in both resolution modes a consumer can use, rather than assumed from the
256
409
  presence of a file:
@@ -285,6 +438,11 @@ when one is present, and the gate reports a named SKIP rather than a red when on
285
438
  | `snapshotMaxElements` | `300` | cap on elements per snapshot (1–5000); a tighter cap is a smaller frame for a deciding subagent |
286
439
  | `screenshotMaxWidth` | `0` | downscale captures to this width; `0` means no scaling and `scale=1` — a resized image is a different coordinate system, so it is never chosen silently |
287
440
  | `shotsKeep` | `10` | how many PNGs stay in `%LOCALAPPDATA%\wpm\shots`; older files are deleted after each capture |
441
+ | `policy` | `balanced` | the ceiling over all eleven actions: `readonly` < `quiet` < `balanced` < `full`. Above it a call is refused with `policy_denied`, whose next step is to raise THIS setting and not to retry. An unrecognizable value falls back to `balanced`, never to `full` |
442
+ | `policyIdleMs` | `3000` | how recently a physical input counts as "the owner is here". A takeover-tier call then refuses with `user_active` and opens no dialog; `0` disables the check |
443
+ | `appLaunchAllowed` | `false` | allow `action=launch` at all. Independent of `takeoverAllowed`: being allowed to move a pointer is not being allowed to start a program |
444
+ | `appLaunchAllow` | `[]` | the launch whitelist — exact names or absolute paths, matched case-insensitively and in full. Empty means nothing may launch even with the gate on; no wildcard, no prefix |
445
+ | `auditKeep` | `2000` | how many lines `%LOCALAPPDATA%\wpm\audit.log` holds before the oldest are pruned |
288
446
 
289
447
  ## What measurement established
290
448
 
@@ -346,6 +504,59 @@ unmeasured end-to-end and is stated as such in [docs/refusals.md](docs/refusals.
346
504
  `WindowFromPoint` no longer returning the HUD, and `HTCLIENT` on the button. That is what
347
505
  `hud.ps1` ships.
348
506
 
507
+ ### 0.6.0's measurements (all re-runnable, probe scripts under `.tmp/` in the repository)
508
+
509
+ - **The read-back exists and is truthful** — three window classes (`Edit`,
510
+ `WindowsForms10.EDIT.app.*`, `WindowsForms10.RichEdit20W.app.*`) all return the written value through
511
+ `WM_GETTEXT` cross-process, and in four cases the value equals what the *application* reported about
512
+ itself from inside its own process (168–241 ms to observe, on the app's 400 ms timer).
513
+ - **A password field reports a length but no text** — `ES_PASSWORD`: `WM_GETTEXT` returns the empty
514
+ string while `WM_GETTEXTLENGTH` returns the real length. Hence `readback=unavailable`, never "empty".
515
+ - **`EM_SETSEL(-1,-1)` does not mean "the end" on WinForms EDIT** — the selection stayed `0,0` and the
516
+ typed character went to the front; `EM_SETSEL(len,len)` gave `abcY`. On a buffer holding `CRLF` the
517
+ numeric end landed at `4,4` for a reported length of `6` — measured, therefore reported as
518
+ `asked=`/`applied=` rather than papered over. A plain Win32 `EDIT` that never held focus accepts every
519
+ `WM_CHAR` and changes nothing, even with `ES_NOHIDESEL`: the case the old `reported-by-send` was
520
+ laundering, and the reason this batch exists.
521
+ - **A read-only edit refuses `WM_CHAR` and honours `WM_SETTEXT`** — the falsification arm of
522
+ `test/readback-truth.mjs`, chosen over two candidates that measurement eliminated (a bare `LF` is
523
+ preserved verbatim, so it agrees; WinForms enforces `MaxLength` in its own `WM_CHAR` handler, so a
524
+ programmatic `WM_SETTEXT` bypasses it, as does `EM_SETLIMITTEXT` set from outside).
525
+ - **BitBlt halves the capture and leaves the bottleneck where it is** — 16–21 ms against 22–33 ms for a
526
+ 1920×1080 grab, PNG encode 37–39 ms in both paths, capture+encode 12–16 ms on a 642×432 window. JPEG
527
+ (6 ms) and WIC (158 ms) measured and rejected, 24bpp measured at 7 % of the size and rejected.
528
+ - **`replace:true` threw on every target until 0.6.0** — the `WM_SETTEXT` binding was declared as
529
+ `SendMessageStrW`, an export `user32.dll` does not have: the call raised
530
+ `EntryPointNotFoundException` on first use and surfaced as `action_failed`. No test in the repository
531
+ exercised `replace:true` through the message door, which is why the fix ships with an arm that does
532
+ (`test/readback-truth.mjs` A1). Found by running the import instead of trusting its name.
533
+
534
+ ### 0.7.0's measurements
535
+
536
+ - **A cold `Process.Start` has no window for over a second** — notepad: pid present,
537
+ `MainWindowHandle=0`, **1348 ms**, and the window only reachable by polling the pid. Hence
538
+ `waitMs`/`window-not-yet` rather than an hwnd claim at return time.
539
+ - **The STA clipboard works in the worker and is not instant** — text write+read identical, first call
540
+ **138 ms**; `SetDataObject`/`GetDataObject` for images (40×20 verified). `Clipboard.Flush()` does NOT
541
+ exist on Windows PowerShell 5.1's runtime (.NET Framework): the first version of this branch threw
542
+ "Clipboard does not contain a method named 'Flush'", which is a method present in the documentation
543
+ people read and absent from the platform the product targets. `SetDataObject($v, $true)` is the
544
+ supported way to make the data outlive the process.
545
+ - **`SW_RESTORE` activates.** Measured around a restore on a real notepad window:
546
+ `foregroundBefore=<other> foregroundAfter=<target>`. Reported as `foregroundTaken=true` on that call
547
+ instead of being attributed to something else; `move`/`resize`/`topmost` measured
548
+ `foregroundTaken=false` with `SWP_NOACTIVATE`.
549
+ - **The whitelist is only a whitelist if it is exact.** `notepad` against `notepad-helper.exe`: a
550
+ prefix or substring rule authorises the second one, so membership is a case-folded full-string test
551
+ and `test/plugin-test.mjs` asserts the refusal for an unlisted name while the gate is on.
552
+ - **The refusal vocabulary is unchanged in shape by `requiresTier`** — a rung comparison is arithmetic
553
+ over one ordered list, so the cost of an action's classification is one number, not one new code per
554
+ action. Three codes were added for the whole batch (`app_launch_denied`, `policy_denied`,
555
+ `user_active`), each naming a setting rather than a symptom.
556
+ - `Check-no-cursor-control` is still green with the same two whitelisted primitive uses and an
557
+ unchanged whitelist file list: adding `launch`/`window` did not open a door to `MOUSEEVENTF_*`,
558
+ `mouse_event` or `keybd_event`.
559
+
349
560
  ## Verifying the copy you actually installed
350
561
 
351
562
  Every test above imports the repository checkout, so a package that installs to the wrong place or ships
package/README.pt.md CHANGED
@@ -5,7 +5,7 @@
5
5
  > Um plugin DSH que permite a um agente controlar **as suas próprias** janelas Windows — silencioso por padrão, visível sob demanda. Quando uma janela aceita mensagens do Windows, o foco nunca é roubado. Quando apenas a Automação de UI a alcança, o foco sofre um único lampejo limitado, revertido automaticamente. Quando você solicita explicitamente o modo takeover, o cursor move-se para o ponto de ação e é sempre restaurado, com um HUD que oferece três formas de interrupção. Em todos os outros casos, recusa com um código e um motivo.
6
6
 
7
7
  > **English canonical text follows.** The localized summary above is the orientation; the text below is the authoritative specification (structure, commands and numbers are identical across all 10 languages).
8
- > **Current release: 0.5.0** — this document describes the contract as of that version. What
8
+ > **Current release: 0.7.0** — this document describes the contract as of that version. What
9
9
  > changed in it, and in every version before it, is in [CHANGELOG.md](CHANGELOG.md), newest first.
10
10
 
11
11
  A DSH plugin that lets an agent drive **its own** Windows windows — quietly by default, and visibly
@@ -13,7 +13,7 @@ on request. Where a window accepts a window message, you never lose focus at all
13
13
  exposes UI Automation, you lose focus for one bounded flash that is reversed automatically. Where you
14
14
  explicitly ask for the takeover tier, the cursor moves to the point and is always restored, with a
15
15
  HUD that can stop it three ways. Everywhere else it refuses, with a code and a reason — never with
16
- silence: every refusal carries a code from a closed set of fourteen and the next step.
16
+ silence: every refusal carries a code from a closed set of seventeen and the next step.
17
17
 
18
18
  **The takeover tier defaults off, and that is structural.** The cursor is only ever moved because you
19
19
  opened `takeoverAllowed` **and** asked for it on the call (`takeover:true`), so an upgrade cannot
@@ -31,7 +31,7 @@ bundle with a broad tool surface; this one is a single action tool whose entire
31
31
 
32
32
  ## What it does
33
33
 
34
- One tool, eight actions:
34
+ One tool, eleven actions:
35
35
 
36
36
  | action | what it returns |
37
37
  |---|---|
@@ -43,6 +43,9 @@ One tool, eight actions:
43
43
  | `snapshot` | the accessibility tree as a NUMBERED element table: continuous `label`, control type, name, automation id, screen rect, patterns |
44
44
  | `screenshot` | the window rect captured to a PNG, plus the coordinate mapping as data (`screenRect`, `imageSize`, `scale`, `identity`, `frame`, `dpiAware`) |
45
45
  | `preview` | the marker drawn at a point, and the element under it reported as TEXT — no picture needed |
46
+ | `launch` | start a whitelisted program; reports the pid, and the window only once it really exists |
47
+ | `clipboard` | read or write the system clipboard — a read reports lengths and never the payload |
48
+ | `window` | minimize / restore / move / resize / topmost ONE named window, verified by reading its state back |
46
49
 
47
50
  The engine picks the cheapest available door per call:
48
51
 
@@ -94,7 +97,7 @@ Image coordinates are never multiplied by the caller:
94
97
 
95
98
  ```jsonc
96
99
  {"action":"screenshot","hwnd":"1310720"}
97
- // -> screenRect=0,0,1920,1032 imageSize=1920x1032 scale=1 identity=true frame=dwm
100
+ // -> screenRect=0,0,1920,1032 imageSize=1920x1032 scale=1 identity=true frame=dwm captureBackend=bitblt
98
101
  {"action":"click","hwnd":"1310720","space":"image","shotId":"shot-…","x":350,"y":250}
99
102
  // the ENGINE converts, then still asserts the point belongs to the target window
100
103
  ```
@@ -124,6 +127,23 @@ point at would be a trap), the frame is cross-checked against the window rect th
124
127
  (`frameCheck=pass|fail|unknown`), and a structural gate pins the single-source rule by mutating a copy
125
128
  of the engine and requiring the corresponding red.
126
129
 
130
+ ### Which capture path painted the picture
131
+
132
+ `captureBackend` names the producer: `bitblt` is a direct GDI `BitBlt` off the screen DC, `gdiplus` is
133
+ `Graphics.CopyFromScreen` — either the fallback after BitBlt was refused, or nothing else. The cheap
134
+ path replaced the old one on measured grounds (16–21 ms against 22–33 ms for a 1920×1080 grab), and the
135
+ encoder was deliberately left alone: the PNG encode is the bottleneck (37–39 ms), so JPEG (6 ms, and it
136
+ smears text), WIC (158 ms) and 24bpp (7 % smaller) were each measured and each rejected.
137
+
138
+ Equivalence was established on a **static** scene, not by file hash — two captures of a live desktop
139
+ happen at different instants, so their bytes cannot match, and that difference says nothing about the
140
+ paths: identical size, both non-blank, **0 maximum per-channel difference over 17 388 sampled points**,
141
+ byte-identical PNGs (8940 = 8940), with the comparator's self-check (two reads of one HBITMAP) also at
142
+ 0. The one difference is reported rather than assumed away: `FromHbitmap` yields `Format32bppRgb` where
143
+ `CopyFromScreen` yields `Format32bppArgb`. A gate keeps both halves honest — the fallback reachable and
144
+ `captureBackend` produced, forwarded and printed (`scripts/check-shot-backend.mjs`, seven mutations each
145
+ seen red).
146
+
127
147
  ### Deciding outside the main context
128
148
 
129
149
  The expensive habit this replaces is re-reading a 70-row table on every step. Hand the frame to a
@@ -158,7 +178,7 @@ reported rather than accused — but `cursorRestored=false` (borrowed and not re
158
178
  `proof=fail`.
159
179
 
160
180
  **And it says who reported the success.** Every action result carries `effect=` in the text and
161
- `effect` in the structured output. The three values are not degrees of confidence in the
181
+ `effect` in the structured output. The four values are not degrees of confidence in the
162
182
  application — they name the speaker:
163
183
 
164
184
  | `effect` | who is speaking | it proves | it does **not** prove |
@@ -166,6 +186,7 @@ application — they name the speaker:
166
186
  | `unverified` | nobody | nothing | anything |
167
187
  | `reported-by-send` | the window-message channel | the message was **delivered** | that the target app processed it |
168
188
  | `reported-by-pattern` | the UI Automation pattern call | the call **returned** without throwing | that the interface actually changed |
189
+ | `readback-verified` | the control itself, read back | the value now in the field **equals the value predicted from the field's own measurements** | that the app is *happy* — only that its value is what we said |
169
190
 
170
191
  Since 0.1.3 the effect also enters the judgment, which closes the one honest gap 0.1.2 still had:
171
192
  a still desktop could outvote a total no-op. A call whose channel reported nothing is capped at
@@ -175,6 +196,49 @@ disturb you; it never proves we accomplished anything. A single `reported-by-*`
175
196
  the caveat spelled out in the reason field (`未独立验证` — nobody observed the app), because turning
176
197
  weak-but-real evidence into a red would train its readers to ignore the verdict.
177
198
 
199
+ ### The fourth value has to be earned (0.6.0)
200
+
201
+ `readback-verified` is granted only by the engine, and only when a **prediction** matches a **read**.
202
+ The prediction is computed from measurements the control itself reported — the value it held before,
203
+ its own `WM_GETTEXTLENGTH`, its own `EM_GETSEL` answer for where a typed character lands — and the read
204
+ happens *after* the settle window, so an app that commits its text asynchronously is not judged against
205
+ a half-written buffer:
206
+
207
+ ```jsonc
208
+ {"action":"type","hwnd":"…","text":"XY","caretPosition":"start"}
209
+ // -> type ok channel=message tier=quiet effect=readback-verified
210
+ // detail=msg=char|2 child=… caret=start asked=0 applied=0,0 readback=XYabc readbackLen=5 focusMoved=false
211
+ ```
212
+
213
+ Three things it refuses to do, each measured rather than assumed:
214
+
215
+ * **it does not upgrade what it cannot read.** A masked field (`ES_PASSWORD`) returns an empty string
216
+ while `WM_GETTEXTLENGTH` still reports the real length. That is "the control hides its text", not
217
+ "the field is empty": the result says `readback=unavailable`, the effect keeps whatever the write
218
+ earned, and no value is printed anywhere.
219
+ * **a mismatch is data, not a failure.** A read-only WinForms edit silently refuses `WM_CHAR` — every
220
+ character is accepted by the API and the value never moves — while honouring `WM_SETTEXT`. On the
221
+ refusal the result is still `ok:true` with `readbackMismatch=true` and no upgrade; on the write that
222
+ lands it is `readback-verified`. No refusal code changed for this batch, on purpose: "the application
223
+ formatted my input" is not an error in the call. `test/readback-truth.mjs` asserts both arms against
224
+ the value the *application* wrote about itself, from inside its own process — a readback test that
225
+ compared our write to our read would be grading homework in our own class, and this repo has already
226
+ been caught doing exactly that.
227
+ * **the naive guess is not the model.** Text is not appended: it lands at the caret, and a field that
228
+ never held focus has its caret at 0 (so `abc` + `XY` is `XYabc`). That is why `caretPosition` exists
229
+ and why the result prints `asked=` and `applied=` separately — `EM_SETSEL(-1,-1)` is documented as
230
+ "document end" and measured as a no-op on WinForms EDIT, so `end` is `EM_SETSEL(len,len)` with `len`
231
+ read from the control. On a buffer containing newlines that numeric end can land inside the text
232
+ (`asked=6 applied=4,4`), which is reported instead of hidden; `idle` touches nothing at all. The UIA
233
+ `value` channel replaces the whole value and has no caret to move, so it answers
234
+ `caretIgnored=value-pattern` rather than pretending to honour it.
235
+
236
+ Two more facts ride in the same `detail`, both warnings and neither a refusal: `focusMoved=true` when
237
+ the foreground or the focused control differs between the two measurements taken around the send, and
238
+ `disabled=true` for a target window that is greyed out — Windows keeps answering our messages while
239
+ throwing the input away, so a disabled target loses the right to an `effect` claim
240
+ (`effect=unverified`) without becoming an error.
241
+
178
242
  ## The takeover tier (opt-in)
179
243
 
180
244
  Off by default (`takeoverAllowed=false`, `keyInjectAllowed=false`), because moving someone's pointer
@@ -217,6 +281,93 @@ click. Success is reported as `effect=reported-by-send`, never as "verified". Un
217
281
  carries no hardware scancode, which is why a rare scancode-only target would ignore it — documented,
218
282
  not a bug.
219
283
 
284
+ ## Desktop actions: launch, clipboard, window (0.7.0)
285
+
286
+ Three capabilities that were missing outright — "you cannot even start a program" was the honest answer
287
+ — and none of them is a door action. They choose no channel, cost no tier, and produce no proof window,
288
+ so they live beside `Invoke-WpmAction` rather than inside it, and the door discipline (point ownership,
289
+ the restore table, the proof window) is not widened by any of them.
290
+
291
+ **`launch` — two switches, neither of which implies the other.** `appLaunchAllowed` opens the
292
+ capability; `appLaunchAllow` lists the exact program names or absolute paths that may run, and an
293
+ **empty list means nothing may launch even with the gate on**. Matching is exact and case-folded: there
294
+ is no wildcard, and `notepad` does not authorise `notepad-helper.exe` — a whitelist that grows by prefix
295
+ is a whitelist that authorises more than it says. A refusal is `app_launch_denied` and is raised before
296
+ any worker request, so a refused launch started nothing (asserted with a request counter in
297
+ `test/plugin-test.mjs` and re-checked inside the engine against the same table). The engine's own
298
+ vocabulary for the window is the interesting part: `Process.Start` returns while the app is still
299
+ loading (measured: `MainWindowHandle=0` for 1348 ms on a cold notepad), so a program that has not
300
+ published a window yet answers `ok:true` with `hwnd=""` and `detail=window-not-yet` — neither a fake
301
+ failure nor a fake readiness. Arguments are passed through as given and written to the audit log,
302
+ because listing a program does not vouch for what it is told to do.
303
+
304
+ **`clipboard` — the most private read in this product.** What is on the clipboard may be a password or
305
+ a token the owner copied seconds ago, so a text read reports its **length**, its result text never
306
+ contains the payload, the audit line records `op`/`format`/`chars`, and values are capped at 64 KB with
307
+ `truncated` stated rather than silently cut. An image write accepts a `shotId`, so a screenshot can go
308
+ straight into the clipboard without the caller handling pixels; the read-back compares the size the
309
+ clipboard reports against the size the shot recorded. A clipboard holding neither is refused with the
310
+ format names it did find — an empty success would be indistinguishable from "the clipboard is empty".
311
+
312
+ **`window` — one named window, five ops, each verified by reading the window back.** `IsIconic`,
313
+ `GetWindowRect`, the `WS_EX_TOPMOST` bit — not `ShowWindow`'s return value, because a syscall's answer
314
+ describes the CALL and this product has been burned repeatedly by reporting that as a state. `move` and
315
+ `resize` pass `SWP_NOACTIVATE`, and the result carries `foregroundTaken=true|false` measured on both
316
+ sides of that specific call: `restore` activates by definition (that is what restoring is), and the
317
+ honest answer is to report it, not to hide it or to refuse the op the caller asked for. There is no
318
+ "all windows" op and no `#32770` discovery: acting on a window nobody named is not a convenience.
319
+
320
+ ### One ceiling, eleven actions
321
+
322
+ The old shape of this problem was a boolean per capability, which does not scale past the number of
323
+ settings anyone will actually read. Instead the two axes are independent:
324
+
325
+ ```
326
+ the action declares the lowest rung it can ever need (src/schema/tools.json#requiresTier)
327
+ the owner sets one ceiling (settings: policy)
328
+
329
+ readonly < quiet < flash < takeover
330
+ reads message bounded-UIA real cursor / held focus / launch
331
+ door flash
332
+ ```
333
+
334
+ | `policy` | permits | refuses |
335
+ |---|---|---|
336
+ | `readonly` | `windows`, `status`, `snapshot`, `screenshot`, `preview`, `clipboard` read | every write |
337
+ | `quiet` | + `click` / `type` / `focus` through the message door | the flash tier, `clipboard` write, `window`, `launch` |
338
+ | `balanced` *(default)* | + the bounded-flash tier, `clipboard` write, `window` ops | `takeover:true`, `keyInput:"inject"`, `launch` |
339
+ | `full` | + the takeover tier and `launch` | nothing extra |
340
+
341
+ Above the ceiling a call is refused with **`policy_denied`** and the reason names both numbers (what the
342
+ action needed, what the policy allows), because the correct next step is a settings change and the wrong
343
+ one is a retry. The gate order is `paused → policy → takeoverAllowed/keyInjectAllowed → launch gate +
344
+ whitelist → idle check → the door table`, and every step in it is tested by making two gates disagree
345
+ about which one spoke (`test/plugin-test.mjs`). Two consequences are worth stating plainly rather than
346
+ leaving to discovery: **`takeover:true` now needs `policy:'full'` as well as `takeoverAllowed`** (0.7.0
347
+ raised the bar for the loudest tier on purpose), and `clipboard`'s halves are graded separately
348
+ (`requiresTierFor`), so a `readonly` owner can still read.
349
+
350
+ **Idle instead of a dialog.** When the last *physical* input is younger than `policyIdleMs` (default
351
+ 3000 ms) and the action needs the takeover tier, it is refused with **`user_active`** and nothing is
352
+ clicked — no popup, no countdown. The upstream design asks the owner to consent by interrupting them;
353
+ an interrupt presented as consent is just a second disturbance. The escape hatch is explicit
354
+ (`forceUserActive:true`), it does not bypass any other gate, and the audit line records `forced:true` so
355
+ an interruption caused on purpose stays distinguishable from one caused by accident. An unattended run
356
+ is never blocked by this: with nobody typing, the age grows past the window and the call goes through.
357
+
358
+ ### The audit log
359
+
360
+ Every action appends one JSONL line to `%LOCALAPPDATA%\wpm\audit.log` — allow **and** deny, because a
361
+ trail that records only refusals documents the times the guard worked and is silent about the times it
362
+ had nothing to do with. Fields: `ts, action, hwnd, tier, policy, decision, code, userActiveAgeMs,
363
+ effect, latencyMs`, plus `target`/`args` for a launch and `op`/`format`/`chars` for a clipboard call.
364
+ What is deliberately absent is content: no typed text, no clipboard payload — the second copy of a
365
+ secret is the one nobody protects. `auditKeep` (default 2000) bounds the file, pruning oldest-first when
366
+ a write pushes it past budget. An audit that cannot be written is reported (`auditNote=n write(s)
367
+ failed`) rather than swallowed: a log that looks complete and is not is worse than one that admits it
368
+ is missing lines. This is the only artifact that survives a call, and it is the one thing that can
369
+ answer "what did the agent do to this machine" after the fact.
370
+
220
371
  ## What it does not do
221
372
 
222
373
  - **No mouse injection.** `MOUSEEVENTF_*`, `mouse_event` and `keybd_event` are banned in every
@@ -253,8 +404,10 @@ degradation.
253
404
  ## Typed surface
254
405
 
255
406
  `types/index.d.ts` is written by hand, not emitted from an implementation. It covers the whole
256
- contract: the eight actions, every argument including the takeover fields and the image-space /
257
- label surface, and all fourteen refusal codes as a closed union.
407
+ contract: the eleven actions, every argument including the takeover fields, the image-space / label
408
+ surface, 0.6.0's `caretPosition` and 0.7.0's `target`/`op`/`format`/`forceUserActive`, all seventeen
409
+ refusal codes as a closed union, and `effect` as its own four-value union (`WpmEffect`) beside
410
+ `WpmCaptureBackend`, `WpmClipboardOp`, `WpmWindowOp`, `WpmPolicy` and `WpmFrameSource`.
258
411
 
259
412
  Its wiring is measured in both resolution modes a consumer can use, rather than assumed from the
260
413
  presence of a file:
@@ -289,6 +442,11 @@ when one is present, and the gate reports a named SKIP rather than a red when on
289
442
  | `snapshotMaxElements` | `300` | cap on elements per snapshot (1–5000); a tighter cap is a smaller frame for a deciding subagent |
290
443
  | `screenshotMaxWidth` | `0` | downscale captures to this width; `0` means no scaling and `scale=1` — a resized image is a different coordinate system, so it is never chosen silently |
291
444
  | `shotsKeep` | `10` | how many PNGs stay in `%LOCALAPPDATA%\wpm\shots`; older files are deleted after each capture |
445
+ | `policy` | `balanced` | the ceiling over all eleven actions: `readonly` < `quiet` < `balanced` < `full`. Above it a call is refused with `policy_denied`, whose next step is to raise THIS setting and not to retry. An unrecognizable value falls back to `balanced`, never to `full` |
446
+ | `policyIdleMs` | `3000` | how recently a physical input counts as "the owner is here". A takeover-tier call then refuses with `user_active` and opens no dialog; `0` disables the check |
447
+ | `appLaunchAllowed` | `false` | allow `action=launch` at all. Independent of `takeoverAllowed`: being allowed to move a pointer is not being allowed to start a program |
448
+ | `appLaunchAllow` | `[]` | the launch whitelist — exact names or absolute paths, matched case-insensitively and in full. Empty means nothing may launch even with the gate on; no wildcard, no prefix |
449
+ | `auditKeep` | `2000` | how many lines `%LOCALAPPDATA%\wpm\audit.log` holds before the oldest are pruned |
292
450
 
293
451
  ## What measurement established
294
452
 
@@ -350,6 +508,59 @@ unmeasured end-to-end and is stated as such in [docs/refusals.md](docs/refusals.
350
508
  `WindowFromPoint` no longer returning the HUD, and `HTCLIENT` on the button. That is what
351
509
  `hud.ps1` ships.
352
510
 
511
+ ### 0.6.0's measurements (all re-runnable, probe scripts under `.tmp/` in the repository)
512
+
513
+ - **The read-back exists and is truthful** — three window classes (`Edit`,
514
+ `WindowsForms10.EDIT.app.*`, `WindowsForms10.RichEdit20W.app.*`) all return the written value through
515
+ `WM_GETTEXT` cross-process, and in four cases the value equals what the *application* reported about
516
+ itself from inside its own process (168–241 ms to observe, on the app's 400 ms timer).
517
+ - **A password field reports a length but no text** — `ES_PASSWORD`: `WM_GETTEXT` returns the empty
518
+ string while `WM_GETTEXTLENGTH` returns the real length. Hence `readback=unavailable`, never "empty".
519
+ - **`EM_SETSEL(-1,-1)` does not mean "the end" on WinForms EDIT** — the selection stayed `0,0` and the
520
+ typed character went to the front; `EM_SETSEL(len,len)` gave `abcY`. On a buffer holding `CRLF` the
521
+ numeric end landed at `4,4` for a reported length of `6` — measured, therefore reported as
522
+ `asked=`/`applied=` rather than papered over. A plain Win32 `EDIT` that never held focus accepts every
523
+ `WM_CHAR` and changes nothing, even with `ES_NOHIDESEL`: the case the old `reported-by-send` was
524
+ laundering, and the reason this batch exists.
525
+ - **A read-only edit refuses `WM_CHAR` and honours `WM_SETTEXT`** — the falsification arm of
526
+ `test/readback-truth.mjs`, chosen over two candidates that measurement eliminated (a bare `LF` is
527
+ preserved verbatim, so it agrees; WinForms enforces `MaxLength` in its own `WM_CHAR` handler, so a
528
+ programmatic `WM_SETTEXT` bypasses it, as does `EM_SETLIMITTEXT` set from outside).
529
+ - **BitBlt halves the capture and leaves the bottleneck where it is** — 16–21 ms against 22–33 ms for a
530
+ 1920×1080 grab, PNG encode 37–39 ms in both paths, capture+encode 12–16 ms on a 642×432 window. JPEG
531
+ (6 ms) and WIC (158 ms) measured and rejected, 24bpp measured at 7 % of the size and rejected.
532
+ - **`replace:true` threw on every target until 0.6.0** — the `WM_SETTEXT` binding was declared as
533
+ `SendMessageStrW`, an export `user32.dll` does not have: the call raised
534
+ `EntryPointNotFoundException` on first use and surfaced as `action_failed`. No test in the repository
535
+ exercised `replace:true` through the message door, which is why the fix ships with an arm that does
536
+ (`test/readback-truth.mjs` A1). Found by running the import instead of trusting its name.
537
+
538
+ ### 0.7.0's measurements
539
+
540
+ - **A cold `Process.Start` has no window for over a second** — notepad: pid present,
541
+ `MainWindowHandle=0`, **1348 ms**, and the window only reachable by polling the pid. Hence
542
+ `waitMs`/`window-not-yet` rather than an hwnd claim at return time.
543
+ - **The STA clipboard works in the worker and is not instant** — text write+read identical, first call
544
+ **138 ms**; `SetDataObject`/`GetDataObject` for images (40×20 verified). `Clipboard.Flush()` does NOT
545
+ exist on Windows PowerShell 5.1's runtime (.NET Framework): the first version of this branch threw
546
+ "Clipboard does not contain a method named 'Flush'", which is a method present in the documentation
547
+ people read and absent from the platform the product targets. `SetDataObject($v, $true)` is the
548
+ supported way to make the data outlive the process.
549
+ - **`SW_RESTORE` activates.** Measured around a restore on a real notepad window:
550
+ `foregroundBefore=<other> foregroundAfter=<target>`. Reported as `foregroundTaken=true` on that call
551
+ instead of being attributed to something else; `move`/`resize`/`topmost` measured
552
+ `foregroundTaken=false` with `SWP_NOACTIVATE`.
553
+ - **The whitelist is only a whitelist if it is exact.** `notepad` against `notepad-helper.exe`: a
554
+ prefix or substring rule authorises the second one, so membership is a case-folded full-string test
555
+ and `test/plugin-test.mjs` asserts the refusal for an unlisted name while the gate is on.
556
+ - **The refusal vocabulary is unchanged in shape by `requiresTier`** — a rung comparison is arithmetic
557
+ over one ordered list, so the cost of an action's classification is one number, not one new code per
558
+ action. Three codes were added for the whole batch (`app_launch_denied`, `policy_denied`,
559
+ `user_active`), each naming a setting rather than a symptom.
560
+ - `Check-no-cursor-control` is still green with the same two whitelisted primitive uses and an
561
+ unchanged whitelist file list: adding `launch`/`window` did not open a door to `MOUSEEVENTF_*`,
562
+ `mouse_event` or `keybd_event`.
563
+
353
564
  ## Verifying the copy you actually installed
354
565
 
355
566
  Every test above imports the repository checkout, so a package that installs to the wrong place or ships