dsh-windows-parallel-mcp 0.8.2 → 0.9.0-rc.2

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.
Files changed (53) hide show
  1. package/CHANGELOG.de.md +444 -419
  2. package/CHANGELOG.es.md +444 -419
  3. package/CHANGELOG.fr.md +444 -419
  4. package/CHANGELOG.it.md +444 -419
  5. package/CHANGELOG.ja.md +444 -419
  6. package/CHANGELOG.ko.md +444 -419
  7. package/CHANGELOG.md +965 -940
  8. package/CHANGELOG.pt.md +444 -419
  9. package/CHANGELOG.ru.md +444 -419
  10. package/CHANGELOG.zh.md +444 -419
  11. package/INSTALL.de.md +126 -126
  12. package/INSTALL.es.md +126 -126
  13. package/INSTALL.fr.md +126 -126
  14. package/INSTALL.it.md +126 -126
  15. package/INSTALL.ja.md +126 -126
  16. package/INSTALL.ko.md +126 -126
  17. package/INSTALL.md +122 -122
  18. package/INSTALL.pt.md +126 -126
  19. package/INSTALL.ru.md +126 -126
  20. package/INSTALL.zh.md +126 -126
  21. package/README.de.md +684 -684
  22. package/README.es.md +684 -684
  23. package/README.fr.md +684 -684
  24. package/README.it.md +684 -684
  25. package/README.ja.md +684 -684
  26. package/README.ko.md +684 -684
  27. package/README.md +680 -680
  28. package/README.pt.md +684 -684
  29. package/README.ru.md +684 -684
  30. package/README.zh.md +684 -684
  31. package/cordis.patch.yml +15 -15
  32. package/docs/refusals.md +90 -90
  33. package/docs/takeover.md +128 -128
  34. package/dsh.plugin.json +18 -18
  35. package/lib/config.js +275 -275
  36. package/lib/engine.js +252 -252
  37. package/lib/host-tools.js +365 -338
  38. package/lib/index.js +1275 -1249
  39. package/lib/peers-schemastery.js +23 -23
  40. package/lib/peers-tools.js +15 -15
  41. package/lib/proof-window.mjs +427 -427
  42. package/package.json +122 -122
  43. package/server.json +110 -110
  44. package/src/engine/decide.ps1 +356 -356
  45. package/src/engine/engine.ps1 +1208 -1208
  46. package/src/engine/hud.ps1 +411 -411
  47. package/src/engine/input-inject.ps1 +176 -176
  48. package/src/engine/overlay.ps1 +389 -389
  49. package/src/engine/takeover.ps1 +144 -144
  50. package/src/engine/win.ps1 +1881 -1881
  51. package/src/engine/worker.ps1 +310 -310
  52. package/src/schema/tools.json +533 -533
  53. package/types/index.d.ts +190 -187
@@ -1,176 +1,176 @@
1
- # input-inject.ps1 -- the ONE file allowed to call SendInput, and it can only ever construct a
2
- # KEYBOARD event. (R3, spec.md §1)
3
- #
4
- # WHY KEYBOARD IS ALLOWED WHERE MOUSE IS NOT. Measured (findings §B): a terminal's text surface has
5
- # three child HWNDs and none of them accepts WM_CHAR/WM_SETTEXT, so no message door exists; UIA exposes
6
- # no pattern either. Its text can only be typed. A mouse event has an alternative that already exists
7
- # (SetCursorPos shows the point, the message/UIA tier clicks), so mouse injection buys nothing and stays
8
- # banned -- the gate forbids MOUSEEVENTF_* repo-wide, and this file never names it.
9
- #
10
- # THE THREE CONSTRAINTS THAT MATTER MORE THAN THE CAPABILITY (spec.md §1):
11
- # S1 FOREGROUND IS THE TARGET. SendInput delivers to the current foreground window, not to "the
12
- # window you meant". Measured with this host's own probe (scripts/probe-sendinput-unicode.ps1):
13
- # text sent while window B was foreground landed in B and NOT in A, even though A was the target
14
- # the caller had in mind. So the assertion below is not ceremony -- it is the difference between
15
- # typing into the terminal and typing into whatever the owner was writing.
16
- # S2 INTERRUPTIBLE PER CHARACTER. A 500-character payload must not be an uninterruptible burst: the
17
- # loop checks the caller's abort probe every 8 characters or 50ms and reports how many characters
18
- # actually went out.
19
- # S3 NO MOUSE. Only INPUT_KEYBOARD is constructed; there is no code path here that can move a pointer
20
- # or click (the gate enforces the constants' absence, not the intent).
21
- #
22
- # WHY KEYEVENTF_UNICODE AND NOT SCAN CODES. Unicode mode does not consult the keyboard layout, so it
23
- # works on a DE layout and with Chinese/emoji payloads; scan-code mapping (VkKeyScan) mis-types on
24
- # non-US layouts and dead keys. The price is documented rather than hidden: a Unicode-injected character
25
- # carries no hardware scancode, and the rare target that only reads scancodes (some games, remote KVM)
26
- # will ignore it.
27
-
28
- Set-StrictMode -Version 2.0
29
-
30
- if (-not ('WpmCtl' -as [type])) {
31
- . (Join-Path $PSScriptRoot 'win.ps1')
32
- }
33
-
34
- if (-not ('WpmInject' -as [type])) {
35
- Add-Type -TypeDefinition @'
36
- using System;
37
- using System.Runtime.InteropServices;
38
-
39
- public static class WpmInject
40
- {
41
- [StructLayout(LayoutKind.Sequential)] public struct KEYBDINPUT
42
- {
43
- public ushort wVk; public ushort wScan; public uint dwFlags; public uint time; public IntPtr dwExtraInfo;
44
- }
45
- [StructLayout(LayoutKind.Sequential)] public struct INPUT
46
- {
47
- public uint type; public KEYBDINPUT ki; public int pad0; public int pad1;
48
- }
49
-
50
- [DllImport("user32.dll", SetLastError = true)] public static extern uint SendInput(uint n, INPUT[] inputs, int cbSize);
51
- [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
52
- [DllImport("user32.dll")] public static extern IntPtr GetAncestor(IntPtr h, uint flags);
53
-
54
- public const uint INPUT_KEYBOARD = 1;
55
- public const uint KEYEVENTF_KEYUP = 0x0002;
56
- public const uint KEYEVENTF_UNICODE = 0x0004;
57
-
58
- static INPUT Make(ushort scan, uint flags) {
59
- INPUT i = new INPUT();
60
- i.type = INPUT_KEYBOARD;
61
- i.ki.wVk = 0;
62
- i.ki.wScan = scan;
63
- i.ki.dwFlags = flags;
64
- i.ki.time = 0;
65
- i.ki.dwExtraInfo = IntPtr.Zero;
66
- return i;
67
- }
68
-
69
- // One character = one down + one up, as a single SendInput call so the pair cannot be separated by
70
- // another process's input. Returns the number of events the OS accepted (0..2).
71
- public static uint SendChar(char c) {
72
- INPUT[] pair = new INPUT[2];
73
- pair[0] = Make((ushort)c, KEYEVENTF_UNICODE);
74
- pair[1] = Make((ushort)c, KEYEVENTF_UNICODE | KEYEVENTF_KEYUP);
75
- return SendInput(2, pair, Marshal.SizeOf(typeof(INPUT)));
76
- }
77
-
78
- // A named key with optional modifiers -- used where a target needs RETURN/TAB rather than text.
79
- // The modifiers are held for the duration of the press and released in reverse order.
80
- public static uint SendCombo(ushort vk, ushort[] mods) {
81
- int n = 2 * (mods.Length + 1);
82
- INPUT[] seq = new INPUT[n];
83
- int k = 0;
84
- foreach (ushort m in mods) { INPUT i = Make(m, 0); seq[k++] = i; }
85
- { INPUT d = Make(vk, 0); seq[k++] = d; }
86
- { INPUT u = Make(vk, KEYEVENTF_KEYUP); seq[k++] = u; }
87
- for (int j = mods.Length - 1; j >= 0; j--) { INPUT r = Make(mods[j], KEYEVENTF_KEYUP); seq[k++] = r; }
88
- return SendInput((uint)n, seq, Marshal.SizeOf(typeof(INPUT)));
89
- }
90
-
91
- public static string ForegroundClass() {
92
- IntPtr fg = GetForegroundWindow();
93
- return fg.ToInt64().ToString();
94
- }
95
- public static string RootOf(string hwnd) {
96
- IntPtr h = new IntPtr(long.Parse(hwnd));
97
- IntPtr root = GetAncestor(h, 2);
98
- return root.ToInt64().ToString();
99
- }
100
- }
101
- '@
102
- }
103
-
104
- function Test-WpmTargetForeground {
105
- # S1's assertion. A child of the target counts (the foreground is often the child control), which is
106
- # why this compares ROOTS rather than exact handles.
107
- param([string]$Hwnd)
108
- if (-not $Hwnd) { return @{ ok = $false; foreground = ''; reason = 'no target hwnd' } }
109
- $fg = [WpmInject]::ForegroundClass()
110
- if (-not $fg -or $fg -eq '0') { return @{ ok = $false; foreground = ''; reason = 'no foreground window' } }
111
- $fgRoot = [WpmInject]::RootOf($fg)
112
- $targetRoot = [WpmInject]::RootOf($Hwnd)
113
- $match = ($fg -eq $Hwnd) -or ($fgRoot -eq $targetRoot)
114
- return @{ ok = [bool]$match; foreground = $fg; foregroundRoot = $fgRoot; targetRoot = $targetRoot
115
- reason = if ($match) { '' } else { 'the foreground window is not the target; sending input would write into the wrong application' } }
116
- }
117
-
118
- function Send-WpmKeyText {
119
- # PER-CHARACTER LOOP, by design (S2). The abort probe is a caller-supplied scriptblock so this file
120
- # does not need to know where the interruption comes from (HUD button, global chord, host latch).
121
- param(
122
- [string]$Text = '',
123
- [scriptblock]$ShouldAbort = $null,
124
- [int]$CheckEveryChars = 8,
125
- [int]$CheckEveryMs = 50
126
- )
127
- if (-not $Text) { return @{ ok = $false; sent = 0; chars = 0; aborted = $false; reason = 'empty payload' } }
128
- $chars = 0
129
- $events = 0
130
- $lastCheck = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
131
- for ($i = 0; $i -lt $Text.Length; $i++) {
132
- if ($ShouldAbort) {
133
- $dueByCount = ($CheckEveryChars -gt 0) -and (($i % $CheckEveryChars) -eq 0)
134
- $nowMs = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
135
- $dueByTime = (($nowMs - $lastCheck) -ge $CheckEveryMs)
136
- if ($i -gt 0 -and ($dueByCount -or $dueByTime)) {
137
- $lastCheck = $nowMs
138
- $stop = $false
139
- try { $stop = [bool](& $ShouldAbort) } catch { $stop = $false }
140
- if ($stop) {
141
- return @{ ok = $false; sent = $events; chars = $chars; aborted = $true
142
- reason = 'interrupted after ' + $chars + ' of ' + $Text.Length + ' characters' }
143
- }
144
- }
145
- }
146
- $queued = [WpmInject]::SendChar([char]$Text[$i])
147
- $events += [int]$queued
148
- $chars += 1
149
- # Progress is published per character so a caller watching [WpmCtl]::InjectedChars (the HUD does)
150
- # sees the real count even if the call is later interrupted.
151
- [WpmCtl]::InjectedChars = $chars
152
- if ($queued -eq 0) {
153
- return @{ ok = $false; sent = $events; chars = $chars; aborted = $false
154
- reason = 'SendInput accepted no events for character ' + $i + ' (a higher-integrity foreground refuses input)' }
155
- }
156
- Start-Sleep -Milliseconds 2
157
- }
158
- return @{ ok = $true; sent = $events; chars = $chars; aborted = $false; reason = '' }
159
- }
160
-
161
- function Send-WpmKeyPress {
162
- # Single key + modifiers. Kept because "type" is not the only thing an agent needs: confirming a
163
- # dialog or submitting a form is a RETURN press, and faking it with a text write would be a lie.
164
- param([string]$Key = 'enter')
165
- $map = @{
166
- 'enter' = 0x0D; 'return' = 0x0D; 'tab' = 0x09; 'escape' = 0x1B; 'esc' = 0x1B
167
- 'space' = 0x20; 'backspace' = 0x08; 'delete' = 0x2E; 'up' = 0x26; 'down' = 0x28
168
- 'left' = 0x25; 'right' = 0x27; 'home' = 0x24; 'end' = 0x23
169
- }
170
- $k = $Key.ToLowerInvariant()
171
- if (-not $map.ContainsKey($k)) {
172
- return @{ ok = $false; sent = 0; reason = "unknown key '" + $Key + "'; named keys: " + (($map.Keys | Sort-Object) -join ', ') }
173
- }
174
- $queued = [WpmInject]::SendCombo([uint16]$map[$k], [uint16[]]@())
175
- return @{ ok = [bool]($queued -gt 0); sent = [int]$queued; reason = if ($queued -gt 0) { '' } else { 'SendInput accepted no events' } }
176
- }
1
+ # input-inject.ps1 -- the ONE file allowed to call SendInput, and it can only ever construct a
2
+ # KEYBOARD event. (R3, spec.md §1)
3
+ #
4
+ # WHY KEYBOARD IS ALLOWED WHERE MOUSE IS NOT. Measured (findings §B): a terminal's text surface has
5
+ # three child HWNDs and none of them accepts WM_CHAR/WM_SETTEXT, so no message door exists; UIA exposes
6
+ # no pattern either. Its text can only be typed. A mouse event has an alternative that already exists
7
+ # (SetCursorPos shows the point, the message/UIA tier clicks), so mouse injection buys nothing and stays
8
+ # banned -- the gate forbids MOUSEEVENTF_* repo-wide, and this file never names it.
9
+ #
10
+ # THE THREE CONSTRAINTS THAT MATTER MORE THAN THE CAPABILITY (spec.md §1):
11
+ # S1 FOREGROUND IS THE TARGET. SendInput delivers to the current foreground window, not to "the
12
+ # window you meant". Measured with this host's own probe (scripts/probe-sendinput-unicode.ps1):
13
+ # text sent while window B was foreground landed in B and NOT in A, even though A was the target
14
+ # the caller had in mind. So the assertion below is not ceremony -- it is the difference between
15
+ # typing into the terminal and typing into whatever the owner was writing.
16
+ # S2 INTERRUPTIBLE PER CHARACTER. A 500-character payload must not be an uninterruptible burst: the
17
+ # loop checks the caller's abort probe every 8 characters or 50ms and reports how many characters
18
+ # actually went out.
19
+ # S3 NO MOUSE. Only INPUT_KEYBOARD is constructed; there is no code path here that can move a pointer
20
+ # or click (the gate enforces the constants' absence, not the intent).
21
+ #
22
+ # WHY KEYEVENTF_UNICODE AND NOT SCAN CODES. Unicode mode does not consult the keyboard layout, so it
23
+ # works on a DE layout and with Chinese/emoji payloads; scan-code mapping (VkKeyScan) mis-types on
24
+ # non-US layouts and dead keys. The price is documented rather than hidden: a Unicode-injected character
25
+ # carries no hardware scancode, and the rare target that only reads scancodes (some games, remote KVM)
26
+ # will ignore it.
27
+
28
+ Set-StrictMode -Version 2.0
29
+
30
+ if (-not ('WpmCtl' -as [type])) {
31
+ . (Join-Path $PSScriptRoot 'win.ps1')
32
+ }
33
+
34
+ if (-not ('WpmInject' -as [type])) {
35
+ Add-Type -TypeDefinition @'
36
+ using System;
37
+ using System.Runtime.InteropServices;
38
+
39
+ public static class WpmInject
40
+ {
41
+ [StructLayout(LayoutKind.Sequential)] public struct KEYBDINPUT
42
+ {
43
+ public ushort wVk; public ushort wScan; public uint dwFlags; public uint time; public IntPtr dwExtraInfo;
44
+ }
45
+ [StructLayout(LayoutKind.Sequential)] public struct INPUT
46
+ {
47
+ public uint type; public KEYBDINPUT ki; public int pad0; public int pad1;
48
+ }
49
+
50
+ [DllImport("user32.dll", SetLastError = true)] public static extern uint SendInput(uint n, INPUT[] inputs, int cbSize);
51
+ [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
52
+ [DllImport("user32.dll")] public static extern IntPtr GetAncestor(IntPtr h, uint flags);
53
+
54
+ public const uint INPUT_KEYBOARD = 1;
55
+ public const uint KEYEVENTF_KEYUP = 0x0002;
56
+ public const uint KEYEVENTF_UNICODE = 0x0004;
57
+
58
+ static INPUT Make(ushort scan, uint flags) {
59
+ INPUT i = new INPUT();
60
+ i.type = INPUT_KEYBOARD;
61
+ i.ki.wVk = 0;
62
+ i.ki.wScan = scan;
63
+ i.ki.dwFlags = flags;
64
+ i.ki.time = 0;
65
+ i.ki.dwExtraInfo = IntPtr.Zero;
66
+ return i;
67
+ }
68
+
69
+ // One character = one down + one up, as a single SendInput call so the pair cannot be separated by
70
+ // another process's input. Returns the number of events the OS accepted (0..2).
71
+ public static uint SendChar(char c) {
72
+ INPUT[] pair = new INPUT[2];
73
+ pair[0] = Make((ushort)c, KEYEVENTF_UNICODE);
74
+ pair[1] = Make((ushort)c, KEYEVENTF_UNICODE | KEYEVENTF_KEYUP);
75
+ return SendInput(2, pair, Marshal.SizeOf(typeof(INPUT)));
76
+ }
77
+
78
+ // A named key with optional modifiers -- used where a target needs RETURN/TAB rather than text.
79
+ // The modifiers are held for the duration of the press and released in reverse order.
80
+ public static uint SendCombo(ushort vk, ushort[] mods) {
81
+ int n = 2 * (mods.Length + 1);
82
+ INPUT[] seq = new INPUT[n];
83
+ int k = 0;
84
+ foreach (ushort m in mods) { INPUT i = Make(m, 0); seq[k++] = i; }
85
+ { INPUT d = Make(vk, 0); seq[k++] = d; }
86
+ { INPUT u = Make(vk, KEYEVENTF_KEYUP); seq[k++] = u; }
87
+ for (int j = mods.Length - 1; j >= 0; j--) { INPUT r = Make(mods[j], KEYEVENTF_KEYUP); seq[k++] = r; }
88
+ return SendInput((uint)n, seq, Marshal.SizeOf(typeof(INPUT)));
89
+ }
90
+
91
+ public static string ForegroundClass() {
92
+ IntPtr fg = GetForegroundWindow();
93
+ return fg.ToInt64().ToString();
94
+ }
95
+ public static string RootOf(string hwnd) {
96
+ IntPtr h = new IntPtr(long.Parse(hwnd));
97
+ IntPtr root = GetAncestor(h, 2);
98
+ return root.ToInt64().ToString();
99
+ }
100
+ }
101
+ '@
102
+ }
103
+
104
+ function Test-WpmTargetForeground {
105
+ # S1's assertion. A child of the target counts (the foreground is often the child control), which is
106
+ # why this compares ROOTS rather than exact handles.
107
+ param([string]$Hwnd)
108
+ if (-not $Hwnd) { return @{ ok = $false; foreground = ''; reason = 'no target hwnd' } }
109
+ $fg = [WpmInject]::ForegroundClass()
110
+ if (-not $fg -or $fg -eq '0') { return @{ ok = $false; foreground = ''; reason = 'no foreground window' } }
111
+ $fgRoot = [WpmInject]::RootOf($fg)
112
+ $targetRoot = [WpmInject]::RootOf($Hwnd)
113
+ $match = ($fg -eq $Hwnd) -or ($fgRoot -eq $targetRoot)
114
+ return @{ ok = [bool]$match; foreground = $fg; foregroundRoot = $fgRoot; targetRoot = $targetRoot
115
+ reason = if ($match) { '' } else { 'the foreground window is not the target; sending input would write into the wrong application' } }
116
+ }
117
+
118
+ function Send-WpmKeyText {
119
+ # PER-CHARACTER LOOP, by design (S2). The abort probe is a caller-supplied scriptblock so this file
120
+ # does not need to know where the interruption comes from (HUD button, global chord, host latch).
121
+ param(
122
+ [string]$Text = '',
123
+ [scriptblock]$ShouldAbort = $null,
124
+ [int]$CheckEveryChars = 8,
125
+ [int]$CheckEveryMs = 50
126
+ )
127
+ if (-not $Text) { return @{ ok = $false; sent = 0; chars = 0; aborted = $false; reason = 'empty payload' } }
128
+ $chars = 0
129
+ $events = 0
130
+ $lastCheck = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
131
+ for ($i = 0; $i -lt $Text.Length; $i++) {
132
+ if ($ShouldAbort) {
133
+ $dueByCount = ($CheckEveryChars -gt 0) -and (($i % $CheckEveryChars) -eq 0)
134
+ $nowMs = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
135
+ $dueByTime = (($nowMs - $lastCheck) -ge $CheckEveryMs)
136
+ if ($i -gt 0 -and ($dueByCount -or $dueByTime)) {
137
+ $lastCheck = $nowMs
138
+ $stop = $false
139
+ try { $stop = [bool](& $ShouldAbort) } catch { $stop = $false }
140
+ if ($stop) {
141
+ return @{ ok = $false; sent = $events; chars = $chars; aborted = $true
142
+ reason = 'interrupted after ' + $chars + ' of ' + $Text.Length + ' characters' }
143
+ }
144
+ }
145
+ }
146
+ $queued = [WpmInject]::SendChar([char]$Text[$i])
147
+ $events += [int]$queued
148
+ $chars += 1
149
+ # Progress is published per character so a caller watching [WpmCtl]::InjectedChars (the HUD does)
150
+ # sees the real count even if the call is later interrupted.
151
+ [WpmCtl]::InjectedChars = $chars
152
+ if ($queued -eq 0) {
153
+ return @{ ok = $false; sent = $events; chars = $chars; aborted = $false
154
+ reason = 'SendInput accepted no events for character ' + $i + ' (a higher-integrity foreground refuses input)' }
155
+ }
156
+ Start-Sleep -Milliseconds 2
157
+ }
158
+ return @{ ok = $true; sent = $events; chars = $chars; aborted = $false; reason = '' }
159
+ }
160
+
161
+ function Send-WpmKeyPress {
162
+ # Single key + modifiers. Kept because "type" is not the only thing an agent needs: confirming a
163
+ # dialog or submitting a form is a RETURN press, and faking it with a text write would be a lie.
164
+ param([string]$Key = 'enter')
165
+ $map = @{
166
+ 'enter' = 0x0D; 'return' = 0x0D; 'tab' = 0x09; 'escape' = 0x1B; 'esc' = 0x1B
167
+ 'space' = 0x20; 'backspace' = 0x08; 'delete' = 0x2E; 'up' = 0x26; 'down' = 0x28
168
+ 'left' = 0x25; 'right' = 0x27; 'home' = 0x24; 'end' = 0x23
169
+ }
170
+ $k = $Key.ToLowerInvariant()
171
+ if (-not $map.ContainsKey($k)) {
172
+ return @{ ok = $false; sent = 0; reason = "unknown key '" + $Key + "'; named keys: " + (($map.Keys | Sort-Object) -join ', ') }
173
+ }
174
+ $queued = [WpmInject]::SendCombo([uint16]$map[$k], [uint16[]]@())
175
+ return @{ ok = [bool]($queued -gt 0); sent = [int]$queued; reason = if ($queued -gt 0) { '' } else { 'SendInput accepted no events' } }
176
+ }