dsh-windows-parallel-mcp 0.4.0 → 0.5.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.pt.md CHANGED
@@ -5,23 +5,21 @@
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
- > **0.2.0 — the promise changes shape, deliberately.** Through 0.1.x this plugin's claim was "no
9
- > physical input at all". 0.2.0 keeps that as the **default** and adds an **opt-in takeover tier**:
10
- > with `takeoverAllowed` on and `takeover:true` on the call, the real cursor is moved to the action
11
- > point (so you can see where the agent points) and always restored, the focus is held for the
12
- > duration, and a three-phase HUD with a stop button and a global abort key is mandatory. Keyboard
13
- > injection exists only inside that tier, only when asked (`keyInput:"inject"`), and only for
14
- > targets with no other door — and, measured, it does **not** work on this host's terminal, so the
15
- > terminal stays refused rather than becoming a promise. Both gates default off: an upgrade cannot
16
- > start moving your cursor by itself. 0.1.6 split `unreachable` into `uia_tree_empty` and
17
- > `uia_probe_failed`; 0.1.5 made a click act on the point it names; 0.1.3 added `effect=` — who
18
- > reported the success — and let it enter the judgment. Full history: [CHANGELOG.md](CHANGELOG.md).
8
+ > **Current release: 0.5.0** — this document describes the contract as of that version. What
9
+ > changed in it, and in every version before it, is in [CHANGELOG.md](CHANGELOG.md), newest first.
19
10
 
20
11
  A DSH plugin that lets an agent drive **its own** Windows windows — quietly by default, and visibly
21
12
  on request. Where a window accepts a window message, you never lose focus at all. Where it only
22
13
  exposes UI Automation, you lose focus for one bounded flash that is reversed automatically. Where you
23
14
  explicitly ask for the takeover tier, the cursor moves to the point and is always restored, with a
24
- HUD that can stop it three ways. Everywhere else it refuses, with a code and a reason.
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.
17
+
18
+ **The takeover tier defaults off, and that is structural.** The cursor is only ever moved because you
19
+ opened `takeoverAllowed` **and** asked for it on the call (`takeover:true`), so an upgrade cannot
20
+ start moving your cursor by itself. Keyboard injection lives inside that tier only, only when asked
21
+ (`keyInput:"inject"`), and only for targets with no other door — and, measured, it does **not** work
22
+ on this host's terminal, so the terminal stays refused rather than becoming a promise.
25
23
 
26
24
  Source, the measurement scripts behind every number below, and the release history live at
27
25
  **<https://github.com/drscrewdriver/dsh-windows-parallel-mcp>** — issues are the right place for
@@ -33,15 +31,18 @@ bundle with a broad tool surface; this one is a single action tool whose entire
33
31
 
34
32
  ## What it does
35
33
 
36
- One tool, five actions:
34
+ One tool, eight actions:
37
35
 
38
36
  | action | what it returns |
39
37
  |---|---|
40
38
  | `windows` | live windows that can be driven: hwnd, title, class, pid, rect |
41
39
  | `status` | what currently holds the foreground and the keyboard focus, and whether the engine is paused |
42
- | `click` | click at a screen coordinate inside the named window |
43
- | `type` | write text into the target (a classic edit child, or a named UIA element) |
44
- | `focus` | move keyboard focus to a named control inside the target |
40
+ | `click` | click at a screen coordinate inside the named window, or at a snapshot `label` |
41
+ | `type` | write text into the target (a classic edit child, a named UIA element, or a `label`) |
42
+ | `focus` | move keyboard focus to a named control inside the target, or to a `label` |
43
+ | `snapshot` | the accessibility tree as a NUMBERED element table: continuous `label`, control type, name, automation id, screen rect, patterns |
44
+ | `screenshot` | the window rect captured to a PNG, plus the coordinate mapping as data (`screenRect`, `imageSize`, `scale`, `identity`, `frame`, `dpiAware`) |
45
+ | `preview` | the marker drawn at a point, and the element under it reported as TEXT — no picture needed |
45
46
 
46
47
  The engine picks the cheapest available door per call:
47
48
 
@@ -74,8 +75,69 @@ flag itself is engine-side and refuses actions with `paused`.
74
75
 
75
76
  Refusals are a normal result, not an error: `no_hwnd`, `paused`, `elevated_target`, `unreachable`,
76
77
  `uia_tree_empty`, `uia_probe_failed`, `terminal_no_door`, `needs_facts`, `takeover_unavailable`,
77
- `keyinject_unavailable`, `action_failed`, `restore_failed`, `takeover_aborted`. Each carries a reason
78
- and a next step — see [docs/refusals.md](docs/refusals.md).
78
+ `keyinject_unavailable`, `action_failed`, `restore_failed`, `takeover_aborted`, `stale_ref`. Each
79
+ carries a reason and a next step — see [docs/refusals.md](docs/refusals.md).
80
+
81
+ ## Reading the frame instead of guessing
82
+
83
+ The three read actions exist so the two halves of a click — *where the thing is* and *where the
84
+ picture is* — stop being the caller's arithmetic.
85
+
86
+ `label` is not a coordinate in disguise. It is resolved back to the UIA **element** by its runtime id
87
+ (measured stable across queries, 71 of 71), so `click`/`type`/`focus` with `label` + `snapId` still
88
+ take the silent pattern path. A labelled `click` keeps `x`/`y` required, and the point must fall
89
+ inside the labelled element's rect — the point stays the contract. A label whose `snapId` was
90
+ superseded is refused with `stale_ref`: element numbers only mean something in the frame that printed
91
+ them.
92
+
93
+ Image coordinates are never multiplied by the caller:
94
+
95
+ ```jsonc
96
+ {"action":"screenshot","hwnd":"1310720"}
97
+ // -> screenRect=0,0,1920,1032 imageSize=1920x1032 scale=1 identity=true frame=dwm
98
+ {"action":"click","hwnd":"1310720","space":"image","shotId":"shot-…","x":350,"y":250}
99
+ // the ENGINE converts, then still asserts the point belongs to the target window
100
+ ```
101
+
102
+ The picture is not returned inline — a plugin cannot mint an inline image block without the host's
103
+ attachment service — so the PNG is written to `%LOCALAPPDATA%\wpm\shots\` (newest `shotsKeep` kept)
104
+ and read with the host's image reader. `preview` is the cheaper confirmation: it draws the marker at
105
+ the point and answers, as text, which element the OS says is there. Confirming a point therefore
106
+ never depends on looking at a picture, and a preview writes no input-queue entry, takes no focus and
107
+ produces no proof window.
108
+
109
+ ### The frame rule, and why 8px mattered
110
+
111
+ One rectangle decides everything: `DwmGetWindowAttribute(EXTENDED_FRAME_BOUNDS)`. Measured here,
112
+ `GetWindowRect` is **8px larger on every edge** — the invisible resize shadow — and the accessibility
113
+ tree mixes the two spaces: its root element reports the shadow-inclusive rect while its children
114
+ report the real one, so arithmetic that mixes them is 8px wrong and *looks right*. Labels and the
115
+ captured picture therefore come from the same function. When DWM is unavailable (RDP, Basic theme)
116
+ the fallback to `GetWindowRect` is **reported** as `frame=win32` rather than swallowed, and
117
+ `frameInset` prints the shadow width as data.
118
+
119
+ The plan for this release proposed a runtime invariant — "every element rect is inside `screenRect`" —
120
+ and measurement refuted it: real Chromium/Electron trees report virtualized content far outside the
121
+ viewport (overhangs of 3px, 18px, 287px and 2720px measured here). What replaced it: elements that do
122
+ not overlap the capture are **excluded and counted** (`outsideFrame=…`, because a number you cannot
123
+ point at would be a trap), the frame is cross-checked against the window rect the tree itself reports
124
+ (`frameCheck=pass|fail|unknown`), and a structural gate pins the single-source rule by mutating a copy
125
+ of the engine and requiring the corresponding red.
126
+
127
+ ### Deciding outside the main context
128
+
129
+ The expensive habit this replaces is re-reading a 70-row table on every step. Hand the frame to a
130
+ clean deciding side and take back one number:
131
+
132
+ 1. `snapshot` with `intent:"close the settings dialog"` — the intent travels with the frame, and is
133
+ written to `%LOCALAPPDATA%\wpm\last-snapshot.json`;
134
+ 2. give the numbered table and the intent to a clean subagent;
135
+ 3. it answers with a single `label` — not a selector, not a coordinate;
136
+ 4. click with that `label` + `snapId`.
137
+
138
+ `sinceSnapId` serves the same goal: an unchanged tree answers `no changes since <id>` instead of
139
+ repeating itself, and a delta names only what actually moved (`added` / `removed` / `changed`, keyed
140
+ by runtime id).
79
141
 
80
142
  **Every real click carries its own disturbance proof.** `click` returns a `proof=pass|inconclusive|…`
81
143
  verdict plus a `proofDimensions` field (cursor / foreground / focus). Around your call the engine
@@ -188,6 +250,29 @@ call, not at plugin load.
188
250
  `engines.dsh` is an explicit two-sided range. There is no runtime version probing and no silent
189
251
  degradation.
190
252
 
253
+ ## Typed surface
254
+
255
+ `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.
258
+
259
+ Its wiring is measured in both resolution modes a consumer can use, rather than assumed from the
260
+ presence of a file:
261
+
262
+ - a `nodenext` consumer resolves it through the `types` condition inside `exports`. That condition is
263
+ load-bearing: delete it and the same consumer fails with `TS7016`, because once `exports` exists it
264
+ is the only entry point and the legacy field below is never consulted;
265
+ - a classic resolver falls back to the top-level `types` field. Delete `exports` entirely and the
266
+ consumer still type-checks.
267
+
268
+ Neither field is decoration, so neither is removable on the assumption that the other covers it.
269
+
270
+ The declarations are also checked against the implementation, in the direction that catches drift:
271
+ `lib/` is type-checked under `allowJs + checkJs + strict` **against those same declarations**, so
272
+ renaming a field in one without the other fails a repo gate instead of a user's build. This stays
273
+ inside the package's zero-install-dependency promise — the compiler is borrowed from the workspace
274
+ when one is present, and the gate reports a named SKIP rather than a red when one is not.
275
+
191
276
  ## Settings
192
277
 
193
278
  | key | default | effect |
@@ -201,6 +286,9 @@ degradation.
201
286
  | `keyInjectAllowed` | `false` | allow `keyInput:"inject"` inside the takeover tier (keyboard only, foreground asserted) |
202
287
  | `takeoverMaxMs` | `10000` | hard ceiling for one takeover action (500–60000); the HUD shows the clock |
203
288
  | `takeoverArmMs` | `800` | length of the arming phase: the window in which you can cancel before anything moves |
289
+ | `snapshotMaxElements` | `300` | cap on elements per snapshot (1–5000); a tighter cap is a smaller frame for a deciding subagent |
290
+ | `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
+ | `shotsKeep` | `10` | how many PNGs stay in `%LOCALAPPDATA%\wpm\shots`; older files are deleted after each capture |
204
292
 
205
293
  ## What measurement established
206
294
 
package/README.ru.md CHANGED
@@ -5,23 +5,21 @@
5
5
  > Плагин DSH, позволяющий агенту управлять **своими** окнами Windows — по умолчанию тихо, по запросу видимо. Когда окно принимает сообщения Windows, фокус никогда не перехватывается. Когда доступен только UI Automation, фокус претерпевает одну ограниченную вспышку и автоматически возвращается. При явном запросе режима takeover курсор перемещается в точку действия и всегда восстанавливается, а HUD предлагает три способа прерывания. Во всех остальных случаях действие отклоняется с кодом и причиной.
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
- > **0.2.0 — the promise changes shape, deliberately.** Through 0.1.x this plugin's claim was "no
9
- > physical input at all". 0.2.0 keeps that as the **default** and adds an **opt-in takeover tier**:
10
- > with `takeoverAllowed` on and `takeover:true` on the call, the real cursor is moved to the action
11
- > point (so you can see where the agent points) and always restored, the focus is held for the
12
- > duration, and a three-phase HUD with a stop button and a global abort key is mandatory. Keyboard
13
- > injection exists only inside that tier, only when asked (`keyInput:"inject"`), and only for
14
- > targets with no other door — and, measured, it does **not** work on this host's terminal, so the
15
- > terminal stays refused rather than becoming a promise. Both gates default off: an upgrade cannot
16
- > start moving your cursor by itself. 0.1.6 split `unreachable` into `uia_tree_empty` and
17
- > `uia_probe_failed`; 0.1.5 made a click act on the point it names; 0.1.3 added `effect=` — who
18
- > reported the success — and let it enter the judgment. Full history: [CHANGELOG.md](CHANGELOG.md).
8
+ > **Current release: 0.5.0** — this document describes the contract as of that version. What
9
+ > changed in it, and in every version before it, is in [CHANGELOG.md](CHANGELOG.md), newest first.
19
10
 
20
11
  A DSH plugin that lets an agent drive **its own** Windows windows — quietly by default, and visibly
21
12
  on request. Where a window accepts a window message, you never lose focus at all. Where it only
22
13
  exposes UI Automation, you lose focus for one bounded flash that is reversed automatically. Where you
23
14
  explicitly ask for the takeover tier, the cursor moves to the point and is always restored, with a
24
- HUD that can stop it three ways. Everywhere else it refuses, with a code and a reason.
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.
17
+
18
+ **The takeover tier defaults off, and that is structural.** The cursor is only ever moved because you
19
+ opened `takeoverAllowed` **and** asked for it on the call (`takeover:true`), so an upgrade cannot
20
+ start moving your cursor by itself. Keyboard injection lives inside that tier only, only when asked
21
+ (`keyInput:"inject"`), and only for targets with no other door — and, measured, it does **not** work
22
+ on this host's terminal, so the terminal stays refused rather than becoming a promise.
25
23
 
26
24
  Source, the measurement scripts behind every number below, and the release history live at
27
25
  **<https://github.com/drscrewdriver/dsh-windows-parallel-mcp>** — issues are the right place for
@@ -33,15 +31,18 @@ bundle with a broad tool surface; this one is a single action tool whose entire
33
31
 
34
32
  ## What it does
35
33
 
36
- One tool, five actions:
34
+ One tool, eight actions:
37
35
 
38
36
  | action | what it returns |
39
37
  |---|---|
40
38
  | `windows` | live windows that can be driven: hwnd, title, class, pid, rect |
41
39
  | `status` | what currently holds the foreground and the keyboard focus, and whether the engine is paused |
42
- | `click` | click at a screen coordinate inside the named window |
43
- | `type` | write text into the target (a classic edit child, or a named UIA element) |
44
- | `focus` | move keyboard focus to a named control inside the target |
40
+ | `click` | click at a screen coordinate inside the named window, or at a snapshot `label` |
41
+ | `type` | write text into the target (a classic edit child, a named UIA element, or a `label`) |
42
+ | `focus` | move keyboard focus to a named control inside the target, or to a `label` |
43
+ | `snapshot` | the accessibility tree as a NUMBERED element table: continuous `label`, control type, name, automation id, screen rect, patterns |
44
+ | `screenshot` | the window rect captured to a PNG, plus the coordinate mapping as data (`screenRect`, `imageSize`, `scale`, `identity`, `frame`, `dpiAware`) |
45
+ | `preview` | the marker drawn at a point, and the element under it reported as TEXT — no picture needed |
45
46
 
46
47
  The engine picks the cheapest available door per call:
47
48
 
@@ -74,8 +75,69 @@ flag itself is engine-side and refuses actions with `paused`.
74
75
 
75
76
  Refusals are a normal result, not an error: `no_hwnd`, `paused`, `elevated_target`, `unreachable`,
76
77
  `uia_tree_empty`, `uia_probe_failed`, `terminal_no_door`, `needs_facts`, `takeover_unavailable`,
77
- `keyinject_unavailable`, `action_failed`, `restore_failed`, `takeover_aborted`. Each carries a reason
78
- and a next step — see [docs/refusals.md](docs/refusals.md).
78
+ `keyinject_unavailable`, `action_failed`, `restore_failed`, `takeover_aborted`, `stale_ref`. Each
79
+ carries a reason and a next step — see [docs/refusals.md](docs/refusals.md).
80
+
81
+ ## Reading the frame instead of guessing
82
+
83
+ The three read actions exist so the two halves of a click — *where the thing is* and *where the
84
+ picture is* — stop being the caller's arithmetic.
85
+
86
+ `label` is not a coordinate in disguise. It is resolved back to the UIA **element** by its runtime id
87
+ (measured stable across queries, 71 of 71), so `click`/`type`/`focus` with `label` + `snapId` still
88
+ take the silent pattern path. A labelled `click` keeps `x`/`y` required, and the point must fall
89
+ inside the labelled element's rect — the point stays the contract. A label whose `snapId` was
90
+ superseded is refused with `stale_ref`: element numbers only mean something in the frame that printed
91
+ them.
92
+
93
+ Image coordinates are never multiplied by the caller:
94
+
95
+ ```jsonc
96
+ {"action":"screenshot","hwnd":"1310720"}
97
+ // -> screenRect=0,0,1920,1032 imageSize=1920x1032 scale=1 identity=true frame=dwm
98
+ {"action":"click","hwnd":"1310720","space":"image","shotId":"shot-…","x":350,"y":250}
99
+ // the ENGINE converts, then still asserts the point belongs to the target window
100
+ ```
101
+
102
+ The picture is not returned inline — a plugin cannot mint an inline image block without the host's
103
+ attachment service — so the PNG is written to `%LOCALAPPDATA%\wpm\shots\` (newest `shotsKeep` kept)
104
+ and read with the host's image reader. `preview` is the cheaper confirmation: it draws the marker at
105
+ the point and answers, as text, which element the OS says is there. Confirming a point therefore
106
+ never depends on looking at a picture, and a preview writes no input-queue entry, takes no focus and
107
+ produces no proof window.
108
+
109
+ ### The frame rule, and why 8px mattered
110
+
111
+ One rectangle decides everything: `DwmGetWindowAttribute(EXTENDED_FRAME_BOUNDS)`. Measured here,
112
+ `GetWindowRect` is **8px larger on every edge** — the invisible resize shadow — and the accessibility
113
+ tree mixes the two spaces: its root element reports the shadow-inclusive rect while its children
114
+ report the real one, so arithmetic that mixes them is 8px wrong and *looks right*. Labels and the
115
+ captured picture therefore come from the same function. When DWM is unavailable (RDP, Basic theme)
116
+ the fallback to `GetWindowRect` is **reported** as `frame=win32` rather than swallowed, and
117
+ `frameInset` prints the shadow width as data.
118
+
119
+ The plan for this release proposed a runtime invariant — "every element rect is inside `screenRect`" —
120
+ and measurement refuted it: real Chromium/Electron trees report virtualized content far outside the
121
+ viewport (overhangs of 3px, 18px, 287px and 2720px measured here). What replaced it: elements that do
122
+ not overlap the capture are **excluded and counted** (`outsideFrame=…`, because a number you cannot
123
+ point at would be a trap), the frame is cross-checked against the window rect the tree itself reports
124
+ (`frameCheck=pass|fail|unknown`), and a structural gate pins the single-source rule by mutating a copy
125
+ of the engine and requiring the corresponding red.
126
+
127
+ ### Deciding outside the main context
128
+
129
+ The expensive habit this replaces is re-reading a 70-row table on every step. Hand the frame to a
130
+ clean deciding side and take back one number:
131
+
132
+ 1. `snapshot` with `intent:"close the settings dialog"` — the intent travels with the frame, and is
133
+ written to `%LOCALAPPDATA%\wpm\last-snapshot.json`;
134
+ 2. give the numbered table and the intent to a clean subagent;
135
+ 3. it answers with a single `label` — not a selector, not a coordinate;
136
+ 4. click with that `label` + `snapId`.
137
+
138
+ `sinceSnapId` serves the same goal: an unchanged tree answers `no changes since <id>` instead of
139
+ repeating itself, and a delta names only what actually moved (`added` / `removed` / `changed`, keyed
140
+ by runtime id).
79
141
 
80
142
  **Every real click carries its own disturbance proof.** `click` returns a `proof=pass|inconclusive|…`
81
143
  verdict plus a `proofDimensions` field (cursor / foreground / focus). Around your call the engine
@@ -188,6 +250,29 @@ call, not at plugin load.
188
250
  `engines.dsh` is an explicit two-sided range. There is no runtime version probing and no silent
189
251
  degradation.
190
252
 
253
+ ## Typed surface
254
+
255
+ `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.
258
+
259
+ Its wiring is measured in both resolution modes a consumer can use, rather than assumed from the
260
+ presence of a file:
261
+
262
+ - a `nodenext` consumer resolves it through the `types` condition inside `exports`. That condition is
263
+ load-bearing: delete it and the same consumer fails with `TS7016`, because once `exports` exists it
264
+ is the only entry point and the legacy field below is never consulted;
265
+ - a classic resolver falls back to the top-level `types` field. Delete `exports` entirely and the
266
+ consumer still type-checks.
267
+
268
+ Neither field is decoration, so neither is removable on the assumption that the other covers it.
269
+
270
+ The declarations are also checked against the implementation, in the direction that catches drift:
271
+ `lib/` is type-checked under `allowJs + checkJs + strict` **against those same declarations**, so
272
+ renaming a field in one without the other fails a repo gate instead of a user's build. This stays
273
+ inside the package's zero-install-dependency promise — the compiler is borrowed from the workspace
274
+ when one is present, and the gate reports a named SKIP rather than a red when one is not.
275
+
191
276
  ## Settings
192
277
 
193
278
  | key | default | effect |
@@ -201,6 +286,9 @@ degradation.
201
286
  | `keyInjectAllowed` | `false` | allow `keyInput:"inject"` inside the takeover tier (keyboard only, foreground asserted) |
202
287
  | `takeoverMaxMs` | `10000` | hard ceiling for one takeover action (500–60000); the HUD shows the clock |
203
288
  | `takeoverArmMs` | `800` | length of the arming phase: the window in which you can cancel before anything moves |
289
+ | `snapshotMaxElements` | `300` | cap on elements per snapshot (1–5000); a tighter cap is a smaller frame for a deciding subagent |
290
+ | `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
+ | `shotsKeep` | `10` | how many PNGs stay in `%LOCALAPPDATA%\wpm\shots`; older files are deleted after each capture |
204
292
 
205
293
  ## What measurement established
206
294
 
package/README.zh.md CHANGED
@@ -5,23 +5,21 @@
5
5
  > 一个让代理驱动**自己**的 Windows 窗口的 DSH 插件——默认静默,按需可见。窗口接受窗口消息时完全不夺焦点;只有 UI Automation 可达时,焦点仅发生一次有界闪烁并自动还原;显式请求接管档时,光标移动到目标点并始终还原,HUD 提供三种中断方式。其他情况一律拒绝,并给出代码与原因。
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
- > **0.2.0 — the promise changes shape, deliberately.** Through 0.1.x this plugin's claim was "no
9
- > physical input at all". 0.2.0 keeps that as the **default** and adds an **opt-in takeover tier**:
10
- > with `takeoverAllowed` on and `takeover:true` on the call, the real cursor is moved to the action
11
- > point (so you can see where the agent points) and always restored, the focus is held for the
12
- > duration, and a three-phase HUD with a stop button and a global abort key is mandatory. Keyboard
13
- > injection exists only inside that tier, only when asked (`keyInput:"inject"`), and only for
14
- > targets with no other door — and, measured, it does **not** work on this host's terminal, so the
15
- > terminal stays refused rather than becoming a promise. Both gates default off: an upgrade cannot
16
- > start moving your cursor by itself. 0.1.6 split `unreachable` into `uia_tree_empty` and
17
- > `uia_probe_failed`; 0.1.5 made a click act on the point it names; 0.1.3 added `effect=` — who
18
- > reported the success — and let it enter the judgment. Full history: [CHANGELOG.md](CHANGELOG.md).
8
+ > **Current release: 0.5.0** — this document describes the contract as of that version. What
9
+ > changed in it, and in every version before it, is in [CHANGELOG.md](CHANGELOG.md), newest first.
19
10
 
20
11
  A DSH plugin that lets an agent drive **its own** Windows windows — quietly by default, and visibly
21
12
  on request. Where a window accepts a window message, you never lose focus at all. Where it only
22
13
  exposes UI Automation, you lose focus for one bounded flash that is reversed automatically. Where you
23
14
  explicitly ask for the takeover tier, the cursor moves to the point and is always restored, with a
24
- HUD that can stop it three ways. Everywhere else it refuses, with a code and a reason.
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.
17
+
18
+ **The takeover tier defaults off, and that is structural.** The cursor is only ever moved because you
19
+ opened `takeoverAllowed` **and** asked for it on the call (`takeover:true`), so an upgrade cannot
20
+ start moving your cursor by itself. Keyboard injection lives inside that tier only, only when asked
21
+ (`keyInput:"inject"`), and only for targets with no other door — and, measured, it does **not** work
22
+ on this host's terminal, so the terminal stays refused rather than becoming a promise.
25
23
 
26
24
  Source, the measurement scripts behind every number below, and the release history live at
27
25
  **<https://github.com/drscrewdriver/dsh-windows-parallel-mcp>** — issues are the right place for
@@ -33,15 +31,18 @@ bundle with a broad tool surface; this one is a single action tool whose entire
33
31
 
34
32
  ## What it does
35
33
 
36
- One tool, five actions:
34
+ One tool, eight actions:
37
35
 
38
36
  | action | what it returns |
39
37
  |---|---|
40
38
  | `windows` | live windows that can be driven: hwnd, title, class, pid, rect |
41
39
  | `status` | what currently holds the foreground and the keyboard focus, and whether the engine is paused |
42
- | `click` | click at a screen coordinate inside the named window |
43
- | `type` | write text into the target (a classic edit child, or a named UIA element) |
44
- | `focus` | move keyboard focus to a named control inside the target |
40
+ | `click` | click at a screen coordinate inside the named window, or at a snapshot `label` |
41
+ | `type` | write text into the target (a classic edit child, a named UIA element, or a `label`) |
42
+ | `focus` | move keyboard focus to a named control inside the target, or to a `label` |
43
+ | `snapshot` | the accessibility tree as a NUMBERED element table: continuous `label`, control type, name, automation id, screen rect, patterns |
44
+ | `screenshot` | the window rect captured to a PNG, plus the coordinate mapping as data (`screenRect`, `imageSize`, `scale`, `identity`, `frame`, `dpiAware`) |
45
+ | `preview` | the marker drawn at a point, and the element under it reported as TEXT — no picture needed |
45
46
 
46
47
  The engine picks the cheapest available door per call:
47
48
 
@@ -74,8 +75,69 @@ flag itself is engine-side and refuses actions with `paused`.
74
75
 
75
76
  Refusals are a normal result, not an error: `no_hwnd`, `paused`, `elevated_target`, `unreachable`,
76
77
  `uia_tree_empty`, `uia_probe_failed`, `terminal_no_door`, `needs_facts`, `takeover_unavailable`,
77
- `keyinject_unavailable`, `action_failed`, `restore_failed`, `takeover_aborted`. Each carries a reason
78
- and a next step — see [docs/refusals.md](docs/refusals.md).
78
+ `keyinject_unavailable`, `action_failed`, `restore_failed`, `takeover_aborted`, `stale_ref`. Each
79
+ carries a reason and a next step — see [docs/refusals.md](docs/refusals.md).
80
+
81
+ ## Reading the frame instead of guessing
82
+
83
+ The three read actions exist so the two halves of a click — *where the thing is* and *where the
84
+ picture is* — stop being the caller's arithmetic.
85
+
86
+ `label` is not a coordinate in disguise. It is resolved back to the UIA **element** by its runtime id
87
+ (measured stable across queries, 71 of 71), so `click`/`type`/`focus` with `label` + `snapId` still
88
+ take the silent pattern path. A labelled `click` keeps `x`/`y` required, and the point must fall
89
+ inside the labelled element's rect — the point stays the contract. A label whose `snapId` was
90
+ superseded is refused with `stale_ref`: element numbers only mean something in the frame that printed
91
+ them.
92
+
93
+ Image coordinates are never multiplied by the caller:
94
+
95
+ ```jsonc
96
+ {"action":"screenshot","hwnd":"1310720"}
97
+ // -> screenRect=0,0,1920,1032 imageSize=1920x1032 scale=1 identity=true frame=dwm
98
+ {"action":"click","hwnd":"1310720","space":"image","shotId":"shot-…","x":350,"y":250}
99
+ // the ENGINE converts, then still asserts the point belongs to the target window
100
+ ```
101
+
102
+ The picture is not returned inline — a plugin cannot mint an inline image block without the host's
103
+ attachment service — so the PNG is written to `%LOCALAPPDATA%\wpm\shots\` (newest `shotsKeep` kept)
104
+ and read with the host's image reader. `preview` is the cheaper confirmation: it draws the marker at
105
+ the point and answers, as text, which element the OS says is there. Confirming a point therefore
106
+ never depends on looking at a picture, and a preview writes no input-queue entry, takes no focus and
107
+ produces no proof window.
108
+
109
+ ### The frame rule, and why 8px mattered
110
+
111
+ One rectangle decides everything: `DwmGetWindowAttribute(EXTENDED_FRAME_BOUNDS)`. Measured here,
112
+ `GetWindowRect` is **8px larger on every edge** — the invisible resize shadow — and the accessibility
113
+ tree mixes the two spaces: its root element reports the shadow-inclusive rect while its children
114
+ report the real one, so arithmetic that mixes them is 8px wrong and *looks right*. Labels and the
115
+ captured picture therefore come from the same function. When DWM is unavailable (RDP, Basic theme)
116
+ the fallback to `GetWindowRect` is **reported** as `frame=win32` rather than swallowed, and
117
+ `frameInset` prints the shadow width as data.
118
+
119
+ The plan for this release proposed a runtime invariant — "every element rect is inside `screenRect`" —
120
+ and measurement refuted it: real Chromium/Electron trees report virtualized content far outside the
121
+ viewport (overhangs of 3px, 18px, 287px and 2720px measured here). What replaced it: elements that do
122
+ not overlap the capture are **excluded and counted** (`outsideFrame=…`, because a number you cannot
123
+ point at would be a trap), the frame is cross-checked against the window rect the tree itself reports
124
+ (`frameCheck=pass|fail|unknown`), and a structural gate pins the single-source rule by mutating a copy
125
+ of the engine and requiring the corresponding red.
126
+
127
+ ### Deciding outside the main context
128
+
129
+ The expensive habit this replaces is re-reading a 70-row table on every step. Hand the frame to a
130
+ clean deciding side and take back one number:
131
+
132
+ 1. `snapshot` with `intent:"close the settings dialog"` — the intent travels with the frame, and is
133
+ written to `%LOCALAPPDATA%\wpm\last-snapshot.json`;
134
+ 2. give the numbered table and the intent to a clean subagent;
135
+ 3. it answers with a single `label` — not a selector, not a coordinate;
136
+ 4. click with that `label` + `snapId`.
137
+
138
+ `sinceSnapId` serves the same goal: an unchanged tree answers `no changes since <id>` instead of
139
+ repeating itself, and a delta names only what actually moved (`added` / `removed` / `changed`, keyed
140
+ by runtime id).
79
141
 
80
142
  **Every real click carries its own disturbance proof.** `click` returns a `proof=pass|inconclusive|…`
81
143
  verdict plus a `proofDimensions` field (cursor / foreground / focus). Around your call the engine
@@ -188,6 +250,29 @@ call, not at plugin load.
188
250
  `engines.dsh` is an explicit two-sided range. There is no runtime version probing and no silent
189
251
  degradation.
190
252
 
253
+ ## Typed surface
254
+
255
+ `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.
258
+
259
+ Its wiring is measured in both resolution modes a consumer can use, rather than assumed from the
260
+ presence of a file:
261
+
262
+ - a `nodenext` consumer resolves it through the `types` condition inside `exports`. That condition is
263
+ load-bearing: delete it and the same consumer fails with `TS7016`, because once `exports` exists it
264
+ is the only entry point and the legacy field below is never consulted;
265
+ - a classic resolver falls back to the top-level `types` field. Delete `exports` entirely and the
266
+ consumer still type-checks.
267
+
268
+ Neither field is decoration, so neither is removable on the assumption that the other covers it.
269
+
270
+ The declarations are also checked against the implementation, in the direction that catches drift:
271
+ `lib/` is type-checked under `allowJs + checkJs + strict` **against those same declarations**, so
272
+ renaming a field in one without the other fails a repo gate instead of a user's build. This stays
273
+ inside the package's zero-install-dependency promise — the compiler is borrowed from the workspace
274
+ when one is present, and the gate reports a named SKIP rather than a red when one is not.
275
+
191
276
  ## Settings
192
277
 
193
278
  | key | default | effect |
@@ -201,6 +286,9 @@ degradation.
201
286
  | `keyInjectAllowed` | `false` | allow `keyInput:"inject"` inside the takeover tier (keyboard only, foreground asserted) |
202
287
  | `takeoverMaxMs` | `10000` | hard ceiling for one takeover action (500–60000); the HUD shows the clock |
203
288
  | `takeoverArmMs` | `800` | length of the arming phase: the window in which you can cancel before anything moves |
289
+ | `snapshotMaxElements` | `300` | cap on elements per snapshot (1–5000); a tighter cap is a smaller frame for a deciding subagent |
290
+ | `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
+ | `shotsKeep` | `10` | how many PNGs stay in `%LOCALAPPDATA%\wpm\shots`; older files are deleted after each capture |
204
292
 
205
293
  ## What measurement established
206
294
 
package/docs/refusals.md CHANGED
@@ -20,10 +20,12 @@ R2′ 把「拒绝」当成本产品的**正常结果**(`engine.ps1` 首段注
20
20
  | 层 | 出处 | 数量 | 语义 |
21
21
  |---|---|---|---|
22
22
  | 决定层 | `src/engine/decide.ps1` 的 `$WpmRefusals` | 10 | 动作**在执行之前**被合法否决,目标本身没被碰过 |
23
- | 运行时失败层 | `src/engine/engine.ps1` 执行/回还段 | 3 | 决定说「能做」,做的过程中通道炸了、回还没成,或**被所有者/宿主中断** |
23
+ | 运行时失败层 | `src/engine/engine.ps1` 执行/回还段 | 4 | 决定说「能做」,做的过程中通道炸了、回还没成、**被所有者/宿主中断**,或调用里引用的上一代产物**已经不存在了** |
24
24
 
25
- 混在一起会让人以为「10 个码都是设计好的分支」,实际后 2 个是**兜底**:它们出现就意味着
26
- 引擎的判断与实际能力不一致,属于需要调查的信号,不该被当成正常分支来轮询。
25
+ 混在一起会让人以为「10 个码都是设计好的分支」,实际 `action_failed` 与 `restore_failed` 是**兜底**:
26
+ 它们出现就意味着引擎的判断与实际能力不一致,属于需要调查的信号,不该被当成正常分支来轮询。
27
+ `takeover_aborted` 是 R3 明确设计的中断结果(不是故障),`stale_ref` 也是设计好的分支(引用过期,
28
+ 有可执行的下一步)——两者之所以归在运行时层,是因为它们只能在执行的当下被判定,而不是在执行前。
27
29
 
28
30
  ## 决定层(10 码)
29
31
 
@@ -40,11 +42,12 @@ R2′ 把「拒绝」当成本产品的**正常结果**(`engine.ps1` 首段注
40
42
  | `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
43
  | `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
44
 
43
- ## 运行时失败层(3 码)
45
+ ## 运行时失败层(4 码)
44
46
 
45
47
  | 码 | 触发条件 | 语义 | 下一步动作 | 实测状态 |
46
48
  |---|---|---|---|---|
47
49
  | `action_failed` | `engine.ps1:218`(通道调用抛异常) | 决定说能做,实际调用炸了 | 报给所有者并附异常原文;同一目标不要自动重试第二次 | **NOT-COVERED** — 需要可稳定抛错的真实目标,本轮未构造 |
50
+ | `stale_ref` | `engine.ps1`(`space:"image"` 的 `shotId` 不在本进程的截图表里;`label`+`snapId` 不是最新帧;宿主侧 `lib/index.js` 对 `space:"image"` 缺 `shotId` 做前置拒绝) | **引用过期**:这次调用指的是引擎上一代产物(一张已被保留策略删掉的截图,或一帧已被新快照取代的编号表)。编号只在印出它的那一帧里有意义 | 重新 `snapshot` / `screenshot` 拿新 id 再动作。**不要**把图像像素当屏幕像素直接用——那正是本码要挡的「看起来对」的位置错误 | **REAL** — `test/refusals-test.ps1` 执行 `click-stale-shot`:未发过的 `shotId` ⇒ 该码且不进探测 |
48
51
  | `restore_failed` | `engine.ps1`(表判 restore、OS 拒绝 SetForegroundWindow) | 所有者被留在了一个不是他选的窗口里 | 立刻上报;不要静默重试,也不要启动看门狗抢第三次 | **NOT-COVERED** — 需提权窗配合,属 task_52 |
49
52
  | `takeover_aborted` | `engine.ps1`(HUD 按钮/中断键/宿主取消,三路汇聚后置位) | 接管被**人**或**宿主**中止了。这不是故障,是 R3 承诺的能力:结果里仍带 `cursorRestored` 与 `injectedChars`,让读者知道做到哪一步 | 读 `injectedChars` 判断已写入多少;要接着做就**重新发起**一次动作(不会从断点续写)。不要把它当成失败来重试 | **REAL** — `test/takeover-test.ps1` 三臂(volatile 标志/latch 文件/长文本中途中断),每臂都断言光标回位 |
50
53
 
package/dsh.plugin.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-windows-parallel-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.5.0",
4
4
  "main": "./lib/index.js",
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.",
5
+ "description": "One tool, eight actions: drive a Windows window quietly by default, and read the target as a numbered element frame. 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; and adds snapshot/screenshot/preview, where labels address the UIA element itself and image coordinates are converted by the engine.",
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 quietly by default (actions: windows, status, click, type, focus), with an opt-in takeover tier that is visible, interruptible and always restores the cursor."
13
+ "description": "Drive a Windows window quietly by default (actions: windows, status, click, type, focus, snapshot, screenshot, preview), with an opt-in takeover tier that is visible, interruptible and always restores the cursor, and a read surface whose numbered labels address the element itself."
14
14
  }
15
15
  ],
16
16
  "skills": []
package/lib/config.js CHANGED
@@ -68,6 +68,20 @@ const FIELDS = [
68
68
  { key: 'takeoverArmMs', type: 'number', default: 800, min: 0, max: 5000, volatile: true,
69
69
  description: 'Length of the HUD’s arming phase: the window in which the owner can cancel before '
70
70
  + 'the cursor moves or a key is typed. 0 disables the wait (the HUD still shows).' },
71
+ // ---- 0.5.0 read-path settings. Each one is a COST the owner can see, not a hidden default:
72
+ // a snapshot cap, an explicit downscale, and a retention count. Nothing here changes the input
73
+ // stance -- snapshot/screenshot/preview write no input and take no focus.
74
+ { key: 'snapshotMaxElements', type: 'number', default: 300, min: 1, max: 5000, volatile: true,
75
+ description: 'Cap on the number of elements one snapshot returns. Measured trees: 71 visible '
76
+ + 'elements for an 816-node Electron window, so 300 is deliberately loose; a lower value trades '
77
+ + 'completeness for a smaller frame when the deciding side is a clean subagent.' },
78
+ { key: 'screenshotMaxWidth', type: 'number', default: 0, min: 0, max: 7680, volatile: true,
79
+ description: 'Downscale screenshots to at most this width. 0 (default) means no scaling and '
80
+ + 'scale=1: a resized image is a different coordinate system, so it is never chosen silently.' },
81
+ { key: 'shotsKeep', type: 'number', default: 10, min: 1, max: 200, volatile: true,
82
+ description: 'How many screenshot PNGs stay in %LOCALAPPDATA%\\wpm\\shots. Older files are deleted '
83
+ + 'after each capture, so the directory cannot grow without bound; a shotId that was cleaned up '
84
+ + 'is refused with stale_ref rather than reinterpreted.' },
71
85
  ];
72
86
 
73
87
  /** Defaults, for documentation and for tests that must not depend on a resolver. */