dsh-windows-parallel-mcp 0.1.0 → 0.1.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.
@@ -0,0 +1,241 @@
1
+ // proof-window.mjs — the ONE implementation of "did the action disturb the owner".
2
+ //
3
+ // WHY THIS EXISTS AS A PURE MODULE. The product's central claim is that driving a window never
4
+ // moves the user's cursor and never keeps their foreground. That claim is only worth anything if it
5
+ // is MEASURED per call, not asserted in a README. The measurement is a window of samples
6
+ // { ts, cx, cy, fg, focus, inputAgeMs }
7
+ // taken around the action, and the judgment is arithmetic on that window. All of it is pure: no
8
+ // file, no process, no syscall. So it can be unit-tested against SYNTHETIC samples where the right
9
+ // answer is known by construction -- which is exactly what a claim this load-bearing needs.
10
+ //
11
+ // THE ATTRIBUTION RULE (why the raw cursor delta cannot be the test). GetLastInputInfo returns "ms
12
+ // since the last PHYSICAL input". Between two samples, if that implied event timestamp MOVED, a
13
+ // human touched the mouse or keyboard inside the gap -- and any motion there belongs to the human.
14
+ // Motion in a gap with no physical event is UNEXPLAINED. So far, so standard.
15
+ //
16
+ // WHAT THE REAL DESKTOP RUNS AND AN IDLE BASELINE TAUGHT US. Unexplained does NOT mean "ours".
17
+ // Real clean clicks measured isolated 3.16px and 7.07px cursor jumps while nobody touched anything --
18
+ // another process nudging the cursor is routine. Against a hardcoded 1px that was a FALSE RED (the
19
+ // gate-cries-wolf failure this repo's doctrine names); against a "generous" threshold it is laundering.
20
+ // The decisive measurement was an IDLE BASELINE (scripts/idle-baseline.mjs (re-runnable)): with NOTHING of ours running,
21
+ // over windows the same length as an action, the cursor already showed unexplained motion across up to
22
+ // 3 separate gaps at ~11px (four idle windows: 0, 3, 0, 0 gaps). So even SUSTAINED multi-gap motion
23
+ // cannot be blamed on our action from a coordinate stream -- GetLastInputInfo excludes the HUMAN and
24
+ // nothing in a position delta excludes ANOTHER PROCESS. ">=2 gaps => fail" is therefore a wolf-cry the
25
+ // idle baseline disproves. The cursor dimension reports:
26
+ // 0 unexplained motion gaps => pass (direct evidence: nothing moved while we acted)
27
+ // >=1 unexplained gap => inconclusive (something moved; the build-time gate says it was not
28
+ // our code, so we surface the number and resolve nothing by blame)
29
+ // THE CURSOR GUARANTEE LIVES WHERE IT IS DECIDABLE: scripts/check-no-cursor-control.mjs asserts the
30
+ // shipped engine contains no SetCursorPos / SendInput / mouse_event / keybd_event -- a byte-level,
31
+ // zero-false-positive build gate. A regression that ADDS cursor control is caught at build time with
32
+ // certainty, strictly stronger than sampling at runtime on a desktop that moves on its own. Same
33
+ // architecture as the schema DROPPING the `physical` field rather than detecting a disabled one:
34
+ // enforce by structure, measure only what structure cannot settle.
35
+ //
36
+ // FOREGROUND/FOCUS keep a fail verdict because they are different: the product CAN legitimately touch
37
+ // them (the UIA flash tier raises, then restores OUTSIDE the sample window; a regression could keep
38
+ // it), and an ambient focus steal is rarer than cursor jitter -- the control window characterises it.
39
+ // A switch is failed only when the control shows the desktop was NOT already switching seconds before;
40
+ // a desktop that steals during the control makes it inconclusive instead of a false red.
41
+ //
42
+ // Verdict ordering: fail > inconclusive > pass. A dimension that cannot be judged is reported, not
43
+ // assumed innocent: silence has never been evidence here.
44
+ //
45
+ // sampler.mjs and the engine both feed samples here. Two copies of this math would mean the
46
+ // reachability numbers and the per-action proof were measured by different instruments while
47
+ // carrying the same name -- the drift this repo already killed once (see sampler.mjs header).
48
+
49
+ const round = (v) => Math.round(v * 100) / 100;
50
+
51
+ /** Absolute timestamp of the last PHYSICAL input at sample x, or null if unreadable. */
52
+ export function physEventAt(x) {
53
+ return typeof x.inputAgeMs === 'number' && x.inputAgeMs >= 0 ? x.ts - x.inputAgeMs : null;
54
+ }
55
+
56
+ /** Was there physical input inside the gap between b and a? Unreadable age => NOT human (fail closed). */
57
+ export function isHumanGap(b, a, humanGapFactor = 0.6) {
58
+ const ea = physEventAt(b), eb = physEventAt(a);
59
+ if (ea === null || eb === null) return false;
60
+ return eb > ea + Math.max(2, (a.ts - b.ts) * humanGapFactor);
61
+ }
62
+
63
+ /**
64
+ * Evaluate one proof window. Pure.
65
+ * @param {Array} samples the ACTION window
66
+ * @param {{minSamples?:number, humanGapFactor?:number, control?:Array}} [opts]
67
+ * control = the pre-action window (sampled while nothing was done). It cannot excuse motion in the
68
+ * action window -- the structural rule already handles that -- but it decides whether the
69
+ * foreground/focus dimensions are evaluable at all.
70
+ */
71
+ export function evaluateProof(samples, opts = {}) {
72
+ const minSamples = opts.minSamples ?? 3;
73
+ const humanGap = opts.humanGapFactor ?? 0.6;
74
+
75
+ const r = (Array.isArray(samples) ? samples : [])
76
+ .map((x) => (x && typeof x.ts === 'number' ? x : null))
77
+ .filter(Boolean);
78
+
79
+ if (r.length < minSamples) {
80
+ return {
81
+ samples: r.length, windowMs: 0,
82
+ cursorMaxDeltaPx: null, cursorMaxDeltaAt: null, cursorTotalPathPx: null,
83
+ foregroundSwitches: null, focusChanges: null, attribution: null, control: null,
84
+ verdict: 'insufficient', reason: `proof needs >=${minSamples} samples, got ${r.length}`,
85
+ };
86
+ }
87
+
88
+ let maxD = 0, maxAt = r[0].ts, total = 0;
89
+ let fg = 0, fc = 0, unexplained = 0, unexplainedMax = 0, unexplainedMaxAt = 0;
90
+ let motionGaps = 0;
91
+ let physEvents = 0, humanMs = 0, quietMs = 0, unexplainedFg = 0, unexplainedFc = 0;
92
+ let physUnreadable = 0;
93
+
94
+ for (let i = 1; i < r.length; i++) {
95
+ const a = r[i], b = r[i - 1];
96
+ const gap = a.ts - b.ts;
97
+ const ea = physEventAt(b), eb = physEventAt(a);
98
+ let human = false;
99
+ if (ea === null || eb === null) physUnreadable++;
100
+ else human = eb > ea + Math.max(2, gap * humanGap);
101
+
102
+ if (human) { physEvents++; humanMs += gap; } else quietMs += gap;
103
+
104
+ const d = Math.hypot(a.cx - b.cx, a.cy - b.cy);
105
+ if (d > maxD) { maxD = d; maxAt = a.ts; }
106
+ total += d;
107
+ if (!human && d > 0.5) {
108
+ motionGaps += 1;
109
+ unexplained += d;
110
+ if (d > unexplainedMax) { unexplainedMax = d; unexplainedMaxAt = a.ts; }
111
+ }
112
+
113
+ // A gap with NO physical input in it is the only one where a switch could be OURS: if a human
114
+ // touched something in the gap, the desktop changed hands for reasons that have nothing to do
115
+ // with the door call, and counting that against the action is a false red (a click cannot fail
116
+ // because the user alt-tabbed during the settle sleep).
117
+ if (a.fg !== b.fg) { fg++; if (!human) unexplainedFg++; }
118
+ if (a.focus !== b.focus) { fc++; if (!human) unexplainedFc++; }
119
+ }
120
+
121
+ const attribution = {
122
+ physicalInputEvents: physEvents,
123
+ humanActiveMs: round(humanMs),
124
+ quietMs: round(quietMs),
125
+ unexplainedCursorMotionGaps: motionGaps,
126
+ unexplainedCursorMaxDeltaPx: round(unexplainedMax),
127
+ unexplainedCursorMaxDeltaAt: unexplainedMaxAt,
128
+ unexplainedCursorPathPx: round(unexplained),
129
+ unexplainedForegroundSwitches: unexplainedFg,
130
+ unexplainedFocusChanges: unexplainedFc,
131
+ unreadableInputAgeGaps: physUnreadable,
132
+ };
133
+
134
+ let control = null;
135
+ if (Array.isArray(opts.control) && opts.control.length >= minSamples) {
136
+ const c = evaluateProof(opts.control, { minSamples });
137
+ if (c.attribution) control = c.attribution;
138
+ }
139
+
140
+ const v = verdictFor(attribution, control, r.length, { declaredFlash: opts.declaredFlash === true });
141
+ return {
142
+ samples: r.length,
143
+ windowMs: r[r.length - 1].ts - r[0].ts,
144
+ cursorMaxDeltaPx: round(maxD),
145
+ cursorMaxDeltaAt: maxAt,
146
+ cursorTotalPathPx: round(total),
147
+ foregroundSwitches: fg,
148
+ focusChanges: fc,
149
+ attribution,
150
+ control,
151
+ verdict: v.verdict,
152
+ reason: v.reason,
153
+ dimensions: v.dimensions,
154
+ };
155
+ }
156
+
157
+ /**
158
+ * The judgment, from the action window's attribution and (optionally) the control window's.
159
+ * cursor : 0 unexplained motion gaps => pass (nothing moved during the action -- direct evidence)
160
+ * >=1 => inconclusive (the IDLE BASELINE measured up to 3 gaps / 11px
161
+ * with nothing of ours running, so motion -- even multi-gap
162
+ * -- cannot be blamed on the action from position data. The
163
+ * number is surfaced. The real guarantee is the build-time
164
+ * check-no-cursor-control gate, not this sensor.)
165
+ * fg/focus: 0 unexplained switches => pass
166
+ * action >0, control also => inconclusive (the desktop was switching on its own seconds
167
+ * before; this switch cannot be pinned on us)
168
+ * action >0, control clean => fail (the desktop was demonstrably not doing this; a
169
+ * FOREGROUND/FOCUS steal is not ambient the way a cursor
170
+ * nudge is -- and unlike the cursor, the product's touch on
171
+ * focus is DECLARED, see declaredFlash below)
172
+ * declaredFlash:true => a foreground switch is EXPECTED for the bounded-flash tier
173
+ * (the engine raises, then restores after the sample window;
174
+ * "we never touch your foreground" was never the promise for
175
+ * that tier -- "we never KEEP it" is, and the restore table
176
+ * owns it, surfacing restore_failed separately). Reported,
177
+ * not failed.
178
+ * unreadable instrument on most gaps => inconclusive (silence is not innocence)
179
+ * Overall = worst dimension: fail > inconclusive > pass.
180
+ */
181
+ export function verdictFor(attribution, control, sampleCount, opts = {}) {
182
+ const a = attribution || {};
183
+ const unreadableCap = opts.unreadableCap ?? Math.max(1, Math.floor((sampleCount - 1) * 0.3));
184
+ const dims = {};
185
+
186
+ if ((a.unreadableInputAgeGaps ?? 0) > unreadableCap) {
187
+ return {
188
+ verdict: 'inconclusive',
189
+ reason: `input-age unreadable for ${a.unreadableInputAgeGaps} gaps; cannot attribute anything`,
190
+ dimensions: { cursor: 'unreadable', foreground: 'unreadable', focus: 'unreadable' },
191
+ };
192
+ }
193
+
194
+ const gaps = a.unexplainedCursorMotionGaps ?? 0;
195
+ const ux = a.unexplainedCursorMaxDeltaPx ?? 0;
196
+ // No 'fail' on the cursor dimension: see the header. The idle baseline proved the desktop itself
197
+ // produces multi-gap unexplained motion, so blaming it on the action is a false red by construction.
198
+ dims.cursor = gaps === 0 ? 'pass' : 'inconclusive';
199
+
200
+ const cFg = control ? (control.unexplainedForegroundSwitches ?? 0) : 0;
201
+ const cFc = control ? (control.unexplainedFocusChanges ?? 0) : 0;
202
+ const aFg = a.unexplainedForegroundSwitches ?? 0;
203
+ const aFc = a.unexplainedFocusChanges ?? 0;
204
+ if (aFg === 0) dims.foreground = 'pass';
205
+ else if (opts.declaredFlash) dims.foreground = 'declared';
206
+ else dims.foreground = control && cFg > 0 ? 'inconclusive' : 'fail';
207
+ if (aFc === 0) dims.focus = 'pass';
208
+ else dims.focus = control && cFc > 0 ? 'inconclusive' : 'fail';
209
+
210
+ const parts = [];
211
+ if (dims.cursor === 'inconclusive') parts.push(`cursor moved ${ux}px in ${gaps} gap(s) with no physical input -- not attributable to the action (the desktop itself does this: idle baseline measured up to 3 gaps/11px with nothing running); the cursor promise is enforced at build time by check-no-cursor-control`);
212
+ if (dims.foreground === 'declared') parts.push(`foreground switched, but this tier DECLARED a bounded flash (raise then restore) -- the promise is never to KEEP the foreground, owned by the restore table`);
213
+ if (dims.foreground === 'fail') parts.push(`${aFg} unexplained foreground switch(es) while the control showed the desktop was not switching and this tier did not declare a flash -- ours to explain`);
214
+ if (dims.foreground === 'inconclusive') parts.push(`${aFg} foreground switch(es), but the desktop was switching on its own during the control too -- unattributable`);
215
+ if (dims.focus === 'fail') parts.push(`${aFc} unexplained focus change(s) with a clean control`);
216
+ if (dims.focus === 'inconclusive') parts.push(`${aFc} focus change(s) mirroring the desktop's own behaviour during the control`);
217
+
218
+ const values = Object.values(dims);
219
+ // 'declared' is informational, never the worst value: it cannot drag the verdict down on its own.
220
+ const verdict = values.includes('fail') ? 'fail' : values.includes('inconclusive') ? 'inconclusive' : 'pass';
221
+ // A 'pass' verdict must never print a reason that contradicts the dimensions. The bounded-flash
222
+ // case passes WITH foreground switches (authorized by the tier's contract); claiming "no switches"
223
+ // would be the README-in-a-tool-result failure mode this whole module exists to prevent.
224
+ const reason = parts.length
225
+ ? parts.join('; ')
226
+ : `no unexplained cursor motion in ${sampleCount - 1} gaps, no unexplained foreground/focus switches`;
227
+ return { verdict, reason, dimensions: dims };
228
+ }
229
+
230
+ /** The software-attributable quantities, flattened for callers that only want the numbers. */
231
+ export function softwareCursorEvidence(summary) {
232
+ const a = (summary && summary.attribution) || {};
233
+ return {
234
+ motionGaps: a.unexplainedCursorMotionGaps ?? null,
235
+ maxPx: a.unexplainedCursorMaxDeltaPx ?? null,
236
+ pathPx: a.unexplainedCursorPathPx ?? null,
237
+ foregroundSwitches: a.unexplainedForegroundSwitches ?? null,
238
+ focusChanges: a.unexplainedFocusChanges ?? null,
239
+ quietMs: a.quietMs ?? null,
240
+ };
241
+ }
package/package.json CHANGED
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "name": "dsh-windows-parallel-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
+ "publishConfig": {
5
+ "access": "public",
6
+ "tag": "latest"
7
+ },
4
8
  "description": "Drive a Windows window without moving the cursor or stealing the keyboard: one tool, five actions, a channel decision table that prefers the quiet door, and a bounded self-reversing focus flash when only UI Automation can reach the control. Windows PowerShell 5.1 sidecar, zero install dependencies, no synthetic input.",
5
9
  "keywords": [
6
10
  "deepseek",
@@ -28,6 +32,7 @@
28
32
  "src/engine/",
29
33
  "src/schema/",
30
34
  "docs/refusals.md",
35
+ "CHANGELOG.md",
31
36
  "cordis.patch.yml",
32
37
  "dsh.plugin.json",
33
38
  "INSTALL.md",