dsh-windows-parallel-mcp 0.1.1 → 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.
- package/CHANGELOG.md +70 -0
- package/README.md +19 -5
- package/lib/index.js +70 -7
- package/lib/proof-window.mjs +241 -0
- package/package.json +1 -1
- package/src/engine/engine.ps1 +52 -2
- package/src/engine/overlay.ps1 +17 -2
- package/src/engine/win.ps1 +40 -0
- package/src/engine/worker.ps1 +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,76 @@ Dates are the registry `time` values for each version, not git commit dates —
|
|
|
4
4
|
when someone typed, a publish time records when a version became installable, and only the second
|
|
5
5
|
one is a promise to anyone installing it.
|
|
6
6
|
|
|
7
|
+
## 0.1.2 — 2026-11-21
|
|
8
|
+
|
|
9
|
+
The proof chain became real: what started as "the README says the cursor never moves" ended as a
|
|
10
|
+
per-call measurement, a build-time guarantee, and — recorded honestly — three judgment designs that
|
|
11
|
+
the real desktop rejected before one survived.
|
|
12
|
+
|
|
13
|
+
**Added**
|
|
14
|
+
- Every `click` carries a disturbance proof: `proof=pass|inconclusive|fail|insufficient(…)` in the
|
|
15
|
+
text plus structured `proof` / `proofDimensions`. The engine samples cursor/foreground/focus/
|
|
16
|
+
last-physical-input-age in two windows — a pre-action control (nothing running, by construction)
|
|
17
|
+
and inside the settle wait it already pays; four read-only syscalls, no new process.
|
|
18
|
+
- `lib/proof-window.mjs` — the one pure implementation of the judgment. `sampler.mjs` delegates to
|
|
19
|
+
it too: the fleet reachability numbers and the per-action proof cannot drift into two instruments
|
|
20
|
+
sharing one name. 32 synthetic unit arms pin the semantics, including cases that must FAIL —
|
|
21
|
+
a verdict function that only ever says pass is worthless, and the arms check it can say otherwise.
|
|
22
|
+
- `scripts/check-no-cursor-control.mjs` — build gate: no shipped engine file may contain
|
|
23
|
+
`SetCursorPos` / `SendInput` / `mouse_event` / `keybd_event`. Verified non-vacuous (injecting
|
|
24
|
+
SetCursorPos turns it red; removing it turns it green, no residue).
|
|
25
|
+
- `scripts/idle-baseline.mjs` — re-runnable probe of what the cursor does with NOTHING running.
|
|
26
|
+
Measured answer on the authoring machine: up to 3 unexplained gaps / 11 px. This is why the
|
|
27
|
+
runtime cursor dimension reports and never accuses.
|
|
28
|
+
- Marker placement through the shipped plugin is verified end-to-end against an independent oracle:
|
|
29
|
+
a real click puts the marker over the point it hit in physical pixels, and the marker is proven
|
|
30
|
+
(via `EnumWindows`) topmost-over-the-target while `GetForegroundWindow` stays unchanged.
|
|
31
|
+
|
|
32
|
+
**Corrected**
|
|
33
|
+
- The cursor guarantee was MEASURED OUT of the runtime sensor and INTO the build gate. Two runtime
|
|
34
|
+
rules failed on clean clicks (a strict 1 px bar: 3.16 px; a control-window noise floor: 7.07 px,
|
|
35
|
+
the floor itself duration-biased). Positions cannot attribute motion to a cause; the idle baseline
|
|
36
|
+
proves even multi-gap motion is ambient on a live desktop. Tuning the number until reds disappear
|
|
37
|
+
would have been laundering, so the rule changed shape instead: zero unexplained gaps passes,
|
|
38
|
+
anything else is inconclusive with the number surfaced, and the actual promise (no cursor control
|
|
39
|
+
exists in the shipped code) is decidable at build time.
|
|
40
|
+
- The disturbance sensor no longer contradicts the product contract: the bounded-flash tier raises
|
|
41
|
+
foreground deliberately and restores it; those switches are reported as `declared`, not failed.
|
|
42
|
+
("Never KEEP the foreground" is owned by the restore table — `restore_failed` — not by sampling.)
|
|
43
|
+
A pass verdict can no longer print "no switches" while carrying declared ones.
|
|
44
|
+
- Overlay cold-start wait raised to 6 s: the runspace JITs WPF past the old 2.5 s budget on a cold
|
|
45
|
+
worker, and the caller read a false "overlay not running".
|
|
46
|
+
- Gate philosophy for occluded desktops, applied to a TOCTOU case (a fullscreen video window moving
|
|
47
|
+
over the point between premise-probe and click): the engine's refusal is correct behaviour, so the
|
|
48
|
+
arms re-probe and convert to a NAMED SKIP. Desktop the test doesn't control never reads as red;
|
|
49
|
+
and a silent skip never reads as tested either.
|
|
50
|
+
- A real product bug in the marker path, caught by the gate going red intermittently (and fixed at
|
|
51
|
+
the cause, not the symptom): the overlay's readiness handshake **polled one flag and judged
|
|
52
|
+
another**. It waited for `OverlayHwnd` — assigned right after `Show()`, before the ex-style trio
|
|
53
|
+
is applied — but reported `running = OverlayOn`, set only after trio + hotkey + pump. So during
|
|
54
|
+
that window `status` said "not running" about an overlay that was initialising, AND read back a
|
|
55
|
+
half-styled window (`exStyle=0x00080008`, TOPMOST|LAYERED but NO TRANSPARENT — WPF's own bits
|
|
56
|
+
before the explicit trio lands). The Node half's fire-and-forget `markPoint` sequenced placement
|
|
57
|
+
behind the handshake; the handshake rejected; the marker request was skipped for a click that had
|
|
58
|
+
already answered, so nobody ever retried and the marker stayed parked at (-2000,-2000). One
|
|
59
|
+
warning, then silence forever. That was not a flake to be slept past:
|
|
60
|
+
the readiness flag is now the judgment flag (`OverlayOn`), a budget that merely expired reports a
|
|
61
|
+
third state (`starting`) instead of masquerading as a crash, and placement retries on a bounded
|
|
62
|
+
6 s deadline that stops immediately when the start is *provably* dead (a reason + not starting).
|
|
63
|
+
Patience lives where a stop condition can be named — the worker-side sleep cannot.
|
|
64
|
+
|
|
65
|
+
**Verified for this version**
|
|
66
|
+
- 12-arm gate green; live clicks through the SHIPPED plugin: proof=pass across 18–22 sample gaps
|
|
67
|
+
with `[cursor=pass fg=pass focus=pass]`; four-run stability: 3 pass + 1 ambient inconclusive
|
|
68
|
+
surfaced as WARN (anti-vacuity: weaker-than-pass never prints as INFO).
|
|
69
|
+
- The independent marker oracle now ANCHORS on the overlay handle the product reports via
|
|
70
|
+
`status` (`overlayHwnd=...`). Matching by title alone could grade a leaked same-titled window from
|
|
71
|
+
an earlier run — certifying a marker we never placed; more than one candidate is now reported as
|
|
72
|
+
ambiguous rather than silently resolved to `$hits[0]`.
|
|
73
|
+
- `lib/proof-window.mjs` confirmed inside the tarball (20 entries).
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
7
77
|
## 0.1.1 — 2026-11-20
|
|
8
78
|
|
|
9
79
|
The same product as 0.1.0. This version exists to fix the packaging chain, not the behaviour.
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# dsh-windows-parallel-mcp
|
|
2
2
|
|
|
3
|
-
> **0.1.
|
|
4
|
-
> [CHANGELOG.md](CHANGELOG.md)); the claim below is the measured one.
|
|
5
|
-
>
|
|
6
|
-
>
|
|
7
|
-
>
|
|
3
|
+
> **0.1.2 — every real click now carries its own disturbance proof.** The name was reserved earlier
|
|
4
|
+
> under a weaker claim (see [CHANGELOG.md](CHANGELOG.md)); the claim below is the measured one.
|
|
5
|
+
> 0.1.1 is 0.1.0's behaviour with a corrected packaging chain; 0.1.2 adds the runtime proof chain —
|
|
6
|
+
> `wpm click` returns a `proof=` verdict and `proofDimensions`, measured against the desktop around
|
|
7
|
+
> your own call.
|
|
8
8
|
|
|
9
9
|
A DSH plugin that lets an agent drive **its own** Windows windows without moving your cursor. Where
|
|
10
10
|
a window accepts a window message, you never lose focus at all. Where it only exposes UI Automation,
|
|
@@ -58,6 +58,20 @@ Refusals are a normal result, not an error: `no_hwnd`, `paused`, `elevated_targe
|
|
|
58
58
|
`terminal_no_door`, `needs_facts`, `action_failed`, `restore_failed`. Each carries a reason and a
|
|
59
59
|
next step — see [docs/refusals.md](docs/refusals.md).
|
|
60
60
|
|
|
61
|
+
**Every real click carries its own disturbance proof.** `click` returns a `proof=pass|inconclusive|…`
|
|
62
|
+
verdict plus a `proofDimensions` field (cursor / foreground / focus). Around your call the engine
|
|
63
|
+
samples cursor position, foreground window, keyboard focus and last-physical-input age — in a short
|
|
64
|
+
pre-action control window (when, by construction, nothing was running) and inside the settle wait it
|
|
65
|
+
already pays. The judgment is one pure function (`lib/proof-window.mjs`, unit-tested against 32
|
|
66
|
+
synthetic windows whose answers are known by construction). What it honestly can and cannot say:
|
|
67
|
+
a switch of foreground on a quiet tier fails — the control shows the desktop was not doing it, so it
|
|
68
|
+
is the action's to explain; a cursor jump is *reported*, never accused, because with nothing running
|
|
69
|
+
this desktop's cursor showed multi-gap unexplained motion on its own (a re-runnable probe ships:
|
|
70
|
+
`scripts/idle-baseline.mjs`). The cursor promise therefore lives where blame is decidable: a build
|
|
71
|
+
gate asserts no shipped file contains `SetCursorPos`/`SendInput`/`mouse_event`/`keybd_event`, so a
|
|
72
|
+
regression that adds cursor control fails at build time with certainty instead of being hunted at
|
|
73
|
+
runtime among ambient motion.
|
|
74
|
+
|
|
61
75
|
## What it does not do
|
|
62
76
|
|
|
63
77
|
- **No synthetic input.** There is no `physical` option: it is absent from the schema, not disabled
|
package/lib/index.js
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
import { createConfigSchema, CONFIG_DEFAULTS } from './config.js';
|
|
26
26
|
import { WorkerClient, workerScript } from './engine.js';
|
|
27
27
|
import { ACTIONS, PARAMETERS, TOOL_NAME, resolveDefineTool } from './host-tools.js';
|
|
28
|
+
import { evaluateProof } from './proof-window.mjs';
|
|
28
29
|
|
|
29
30
|
/** Stable Cordis plugin name (this is what a profile entry points at). */
|
|
30
31
|
export const name = 'windows-parallel';
|
|
@@ -102,12 +103,49 @@ export function apply(ctx, config = {}) {
|
|
|
102
103
|
});
|
|
103
104
|
return overlayReady;
|
|
104
105
|
};
|
|
105
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Place the marker at a PHYSICAL screen point. Never awaited by the caller path.
|
|
108
|
+
* Placement RETRIES until the overlay reports running or a 6 s deadline passes -- not as a
|
|
109
|
+
* bandage but because the old single-shot silently broke the shipped promise: a cold worker's
|
|
110
|
+
* handshake can expire while the overlay is genuinely still starting (measured: WPF JIT past the
|
|
111
|
+
* budget), the marker request was then skipped, and the click had already answered so nobody ever
|
|
112
|
+
* retried. A promise with a race window is a promise that loses the race sometimes. The deadline
|
|
113
|
+
* is BOUNDED and a confirmed-dead start (a reason with starting=false) stops the loop immediately
|
|
114
|
+
* and warns -- endless patience would just hide a broken surface.
|
|
115
|
+
*/
|
|
106
116
|
const markPoint = (x, y) => {
|
|
107
117
|
if (!settings.overlay || !Number.isFinite(x) || !Number.isFinite(y)) return;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
118
|
+
const mx = Math.round(x);
|
|
119
|
+
const my = Math.round(y);
|
|
120
|
+
void (async () => {
|
|
121
|
+
await ensureOverlay().catch(() => {}); // kick the start; its own failures are warned there
|
|
122
|
+
const deadline = Date.now() + 6000;
|
|
123
|
+
for (;;) {
|
|
124
|
+
const env = await client.request({ action: 'marker', x: mx, y: my }).catch(() => null);
|
|
125
|
+
const res = env?.result;
|
|
126
|
+
if (env?.ok && res?.ok !== false) return; // placed
|
|
127
|
+
if (res && res.reason === 'overlay not running') {
|
|
128
|
+
const st = await client.request({ action: 'overlay', on: true }).catch(() => null);
|
|
129
|
+
const state = st?.result?.state;
|
|
130
|
+
if (state && state.running) continue; // up now; retry placement
|
|
131
|
+
if (state && !state.starting && state.reason) {
|
|
132
|
+
if (!overlayWarned) {
|
|
133
|
+
overlayWarned = true;
|
|
134
|
+
logger.warn?.(`[windows-parallel] marker overlay failed to start (${state.reason}); actions still work`);
|
|
135
|
+
}
|
|
136
|
+
return; // dead for a named reason: stop
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (Date.now() >= deadline) {
|
|
140
|
+
if (!overlayWarned) {
|
|
141
|
+
overlayWarned = true;
|
|
142
|
+
logger.warn?.('[windows-parallel] marker was not placed within 6s of the click; actions still work');
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
await new Promise((r) => setTimeout(r, 150));
|
|
147
|
+
}
|
|
148
|
+
})().catch(() => { /* warned inside; a marker must never become an unhandled rejection */ });
|
|
111
149
|
};
|
|
112
150
|
logger.info?.(`[windows-parallel] config schema: ${configSource}`);
|
|
113
151
|
const client = new WorkerClient({
|
|
@@ -260,8 +298,8 @@ function refusal(code, reason) {
|
|
|
260
298
|
return err;
|
|
261
299
|
}
|
|
262
300
|
|
|
263
|
-
function result(action, ok, refusalCode, text) {
|
|
264
|
-
return { action, ok, refusal: refusalCode, text: refusalCode ? `${refusalCode}: ${text}` : text };
|
|
301
|
+
function result(action, ok, refusalCode, text, extra) {
|
|
302
|
+
return { action, ok, refusal: refusalCode, text: refusalCode ? `${refusalCode}: ${text}` : text, ...(extra || {}) };
|
|
265
303
|
}
|
|
266
304
|
|
|
267
305
|
/**
|
|
@@ -295,6 +333,11 @@ function format(action, r) {
|
|
|
295
333
|
// registered" are claims the user cannot check -- and this machine's desktop already owns
|
|
296
334
|
// Ctrl+Alt+Q, so the real chord is not the documented one. Silence here would be a lie.
|
|
297
335
|
bits.push(`overlay=${r.overlayRunning === true ? 'on' : 'off'}`);
|
|
336
|
+
// The overlay's hwnd, so an INDEPENDENT oracle can verify the exact window the product thinks
|
|
337
|
+
// it is showing. Title-matching alone cannot do this: a leaked overlay from an earlier run is
|
|
338
|
+
// also titled WpmOverlay, and grading that instead of ours would make the marker arms grade
|
|
339
|
+
// homework that is not even in this class.
|
|
340
|
+
if (r.overlayHwnd && r.overlayHwnd !== '0') bits.push(`overlayHwnd=${r.overlayHwnd}`);
|
|
298
341
|
bits.push(`pauseHotkey=${r.hotkeyRegistered === true ? (r.hotkeyLabel || 'registered') : 'unavailable'}`);
|
|
299
342
|
if (r.overlayReason) bits.push(`overlayNote=${r.overlayReason}`);
|
|
300
343
|
if (r.pauseReason) bits.push(`pauseReason=${r.pauseReason}`);
|
|
@@ -315,11 +358,31 @@ function format(action, r) {
|
|
|
315
358
|
`tier=${r.tier || '?'}`,
|
|
316
359
|
`focusTaken=${r.focusTaken === 'true' || r.focusTaken === true}`,
|
|
317
360
|
];
|
|
361
|
+
// THE PROOF. The engine sampled cursor/foreground/focus/last-input-age in TWO windows: a short
|
|
362
|
+
// pre-action CONTROL (captured while, by construction, nothing was done) and the settle window
|
|
363
|
+
// AFTER the door call. The judgment is arithmetic and lives in one pure implementation
|
|
364
|
+
// (proof-window.mjs), never here and never in the README. Three verdicts, and their asymmetry is
|
|
365
|
+
// the whole point -- see proof-window.mjs's header for the idle-baseline measurement behind it:
|
|
366
|
+
// pass no unexplained cursor gap, no unexplained foreground/focus switch;
|
|
367
|
+
// inconclusive the desktop moved or switched in a way position data cannot attribute to the
|
|
368
|
+
// action (the idle baseline proved our absence does not imply desktop stillness);
|
|
369
|
+
// fail a foreground/focus switch the control shows the desktop was NOT doing, on a tier
|
|
370
|
+
// that did not DECLARE a bounded flash.
|
|
371
|
+
// `declaredFlash` is the decision table's own needsRestore: on the bounded-flash tier the engine
|
|
372
|
+
// DELIBERATELY raises foreground inside the window and restores it after -- the promise of that
|
|
373
|
+
// tier was never "don't touch", it is "don't keep", and the restore table owns that promise
|
|
374
|
+
// (restore_failed surfaces separately). Sampling cannot be allowed to contradict the contract.
|
|
375
|
+
// A missing/short window is 'insufficient': silence is not innocence.
|
|
376
|
+
const proof = evaluateProof(r.proofSamples || [], {
|
|
377
|
+
control: r.proofControl || [],
|
|
378
|
+
declaredFlash: r.tier === 'bounded-flash',
|
|
379
|
+
});
|
|
380
|
+
bits.push(`proof=${proof.verdict}(${proof.reason})`);
|
|
318
381
|
if (r.restoreOutcome) bits.push(`restore=${r.restoreOutcome}`);
|
|
319
382
|
if (r.flashMs !== undefined) bits.push(`flashMs=${r.flashMs}`);
|
|
320
383
|
if (r.latencyMs !== undefined) bits.push(`latencyMs=${r.latencyMs}`);
|
|
321
384
|
if (r.detail) bits.push(`detail=${r.detail}`);
|
|
322
|
-
return result(action, true, '', bits.join(' '));
|
|
385
|
+
return result(action, true, '', bits.join(' '), { proof: proof.verdict, proofDimensions: proof.dimensions });
|
|
323
386
|
}
|
|
324
387
|
|
|
325
388
|
function truncate(s, n) {
|
|
@@ -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
package/src/engine/engine.ps1
CHANGED
|
@@ -44,6 +44,7 @@ function Get-WpmStatus {
|
|
|
44
44
|
# whether the hotkey actually registered. A silent 'overlay off' would make the README's
|
|
45
45
|
# Ctrl+Alt+Q promise untrue with no way to notice.
|
|
46
46
|
overlayRunning = [bool][WpmCtl]::OverlayOn
|
|
47
|
+
overlayHwnd = [string][WpmCtl]::OverlayHwnd
|
|
47
48
|
hotkeyRegistered = [bool][WpmCtl]::HotkeyOk
|
|
48
49
|
hotkeyLabel = [string][WpmCtl]::HotkeyLabel
|
|
49
50
|
overlayReason = [string][WpmCtl]::Reason
|
|
@@ -98,6 +99,38 @@ function Resolve-WpmChildAtPoint([IntPtr]$Hwnd, [int]$X, [int]$Y) {
|
|
|
98
99
|
return $hit
|
|
99
100
|
}
|
|
100
101
|
|
|
102
|
+
function Get-WpmProofWindow {
|
|
103
|
+
<#
|
|
104
|
+
Sample cursor / foreground / focused-control / last-PHYSICAL-input-age for a fixed window.
|
|
105
|
+
Four read-only syscalls per sample, no process, so it costs nothing the engine would not already
|
|
106
|
+
pay while parked in a wait. Attribution is arithmetic and lives in lib/proof-window.mjs; this
|
|
107
|
+
only produces the raw samples. If a read throws (secure desktop, transient) we stop early and
|
|
108
|
+
return what we have -- the caller then reports 'insufficient' rather than inventing a verdict.
|
|
109
|
+
Returns an array; the leading comma keeps it an array even when there is exactly one element.
|
|
110
|
+
#>
|
|
111
|
+
param([int]$Ms, [int]$EveryMs = 15)
|
|
112
|
+
$samples = @()
|
|
113
|
+
$base = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
|
|
114
|
+
$deadline = $base + $Ms
|
|
115
|
+
$next = $base
|
|
116
|
+
while ($true) {
|
|
117
|
+
$now = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
|
|
118
|
+
if ($now -ge $deadline) { break }
|
|
119
|
+
if ($now -lt $next) { Start-Sleep -Milliseconds ([Math]::Max(1, [int]($next - $now))); continue }
|
|
120
|
+
try {
|
|
121
|
+
$s = [WpmWin]::Sample()
|
|
122
|
+
$samples += (@{ ts = $now; cx = [int]$s[0]; cy = [int]$s[1]; fg = [string]$s[2]; focus = [string]$s[3]; inputAgeMs = [long]$s[4] })
|
|
123
|
+
} catch { break }
|
|
124
|
+
$next = $now + $EveryMs
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
$tEnd = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
|
|
128
|
+
$s2 = [WpmWin]::Sample()
|
|
129
|
+
$samples += (@{ ts = $tEnd; cx = [int]$s2[0]; cy = [int]$s2[1]; fg = [string]$s2[2]; focus = [string]$s2[3]; inputAgeMs = [long]$s2[4] })
|
|
130
|
+
} catch { }
|
|
131
|
+
return ,$samples
|
|
132
|
+
}
|
|
133
|
+
|
|
101
134
|
function Invoke-WpmAction {
|
|
102
135
|
param(
|
|
103
136
|
[Parameter(Mandatory)][string]$Hwnd,
|
|
@@ -115,7 +148,7 @@ function Invoke-WpmAction {
|
|
|
115
148
|
ok = $false; action = $Action; hwnd = $Hwnd; channel = ''; tier = ''
|
|
116
149
|
refusal = ''; reason = ''; detail = ''; latencyMs = 0
|
|
117
150
|
focusTaken = 'false'; restoreOutcome = ''; restoreSetFg = ''; restoreJoined = ''
|
|
118
|
-
effect = 'unverified'
|
|
151
|
+
effect = 'unverified'; proofSamples = @()
|
|
119
152
|
}
|
|
120
153
|
|
|
121
154
|
# A QUERY IS NOT AN ACTION, and this branch is early on purpose. It used to sit inside the action
|
|
@@ -170,6 +203,18 @@ function Invoke-WpmAction {
|
|
|
170
203
|
# before-value to be falsifiable.
|
|
171
204
|
$entry = Get-WpmFocusEntry
|
|
172
205
|
$raisedHwnd = ''
|
|
206
|
+
# THE PRE-ACTION CONTROL WINDOW. Sampled here, immediately BEFORE the door call, so that during it,
|
|
207
|
+
# by construction, WE have done nothing. WHY A CONTROL IS REQUIRED AND NOT JUST A THRESHOLD:
|
|
208
|
+
# "unexplained motion" from GetLastInputInfo proves no PHYSICAL input happened in the gap -- it
|
|
209
|
+
# cannot tell our action apart from some background app nudging the cursor or stealing focus. A
|
|
210
|
+
# hardcoded threshold is the vacuous-control trap this repo wrote down once (P0 task_5(f): "the
|
|
211
|
+
# reset control passed vacuously"), and three real clicks proved it: a clean click measured isolated
|
|
212
|
+
# 3.16px and 7.07px cursor jumps. So the judgment is STRUCTURAL, decided in lib/proof-window.mjs
|
|
213
|
+
# using BOTH windows: sustained multi-gap cursor motion fails (no ambient correction drags across
|
|
214
|
+
# gaps), an isolated single jump is inconclusive (a position delta cannot name its cause), and a
|
|
215
|
+
# foreground/focus switch is blamed on us (fail) only when the control window shows the desktop was
|
|
216
|
+
# NOT already doing it. Kept short (80ms): a few samples, no perceptible slowdown.
|
|
217
|
+
$controlSamples = Get-WpmProofWindow -Ms 80
|
|
173
218
|
$tAct = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
|
|
174
219
|
|
|
175
220
|
try {
|
|
@@ -257,7 +302,12 @@ function Invoke-WpmAction {
|
|
|
257
302
|
$result.latencyMs = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() - $started
|
|
258
303
|
}
|
|
259
304
|
|
|
260
|
-
|
|
305
|
+
# THE ACTION WINDOW. Sampled DURING the settle sleep the engine already performed, so collecting
|
|
306
|
+
# proof costs no extra delay. This is the window the claim is made about; it is judged against the
|
|
307
|
+
# pre-action control captured above (proof-window decides how, from both). Attribution is arithmetic
|
|
308
|
+
# and lives in lib/proof-window.mjs -- the engine only produces samples.
|
|
309
|
+
$result.proofControl = $controlSamples
|
|
310
|
+
$result.proofSamples = Get-WpmProofWindow -Ms $SettleMs
|
|
261
311
|
|
|
262
312
|
# Did the action actually take the owner's focus? Measured, not assumed -- the quiet tier is
|
|
263
313
|
# expected to say no and the flash tier yes, and a run where both say the same thing is a broken
|
package/src/engine/overlay.ps1
CHANGED
|
@@ -249,15 +249,30 @@ function Start-WpmOverlay {
|
|
|
249
249
|
|
|
250
250
|
function Get-WpmOverlayState {
|
|
251
251
|
param([int]$WaitMs = 2500)
|
|
252
|
+
# THE READINESS FLAG MUST BE THE FLAG THE VERDICT USES. The first version polled OverlayHwnd --
|
|
253
|
+
# set right after Show(), BEFORE the ex-style trio is applied -- but reported `running = OverlayOn`,
|
|
254
|
+
# set only after the trio, the hotkey and the pump are all up. Inside that window the state read
|
|
255
|
+
# back a HALF-STYLED window (measured: exStyle=0x00080008 -- WPF's own TOPMOST|LAYERED, no
|
|
256
|
+
# TRANSPARENT) and declared an initialising overlay "not running"; the caller's marker request was
|
|
257
|
+
# then skipped for a click that had already answered, and the fire-and-forget path never retried
|
|
258
|
+
# (measured in the gate: marker parked at (-2000,-2000) with one WARN, then silence forever).
|
|
259
|
+
# So: wait for OverlayOn -- the same flag the verdict reports. A budget that merely EXPIRED is a
|
|
260
|
+
# third state, not a crash: `starting` below, from the runspace handle, keeps "slow" and "dead for
|
|
261
|
+
# a named reason" from sharing one message.
|
|
252
262
|
$deadline = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() + $WaitMs
|
|
253
|
-
while ([DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() -lt $deadline -and [WpmCtl]::
|
|
254
|
-
Start-Sleep -Milliseconds
|
|
263
|
+
while ([DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() -lt $deadline -and -not [WpmCtl]::OverlayOn) {
|
|
264
|
+
Start-Sleep -Milliseconds 50
|
|
255
265
|
}
|
|
256
266
|
$hwnd = [WpmCtl]::OverlayHwnd
|
|
257
267
|
$ex = 0
|
|
258
268
|
if ($hwnd -ne 0) { $ex = [WpmWin]::GetWindowLong([IntPtr]$hwnd, [WpmWin]::GWL_EXSTYLE) }
|
|
259
269
|
return @{
|
|
260
270
|
running = [bool][WpmCtl]::OverlayOn
|
|
271
|
+
# A timeout is not a crash, and the caller must be able to tell them apart. Before this, a
|
|
272
|
+
# wait that expired mid-init produced `running=false` with an empty reason -- indistinguishable
|
|
273
|
+
# from a body that threw. 'starting' names the third state: still alive, just not done.
|
|
274
|
+
starting = (-not [WpmCtl]::OverlayOn) -and ($script:WpmOvHandle -ne $null) -and
|
|
275
|
+
(-not $script:WpmOvHandle.AsyncWaitHandle.WaitOne(0))
|
|
261
276
|
hwnd = [string]$hwnd
|
|
262
277
|
hotkeyRegistered = [bool][WpmCtl]::HotkeyOk
|
|
263
278
|
hotkeyLabel = [string][WpmCtl]::HotkeyLabel
|
package/src/engine/win.ps1
CHANGED
|
@@ -216,6 +216,25 @@ public static class WpmWin
|
|
|
216
216
|
return SetWindowPos(h, IntPtr.Zero, x, y, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE);
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
/// <summary>
|
|
220
|
+
/// Put THIS window at the top of the topmost band without activating it. Exists for the desktop
|
|
221
|
+
/// test arms, which assert facts about a screen point ("WindowFromPoint at the marker returns my
|
|
222
|
+
/// base"; "the click lands on my target's button"). A third-party full-screen window -- a video
|
|
223
|
+
/// player that went fullscreen while these lines were written (measured live: PotPlayer owned every
|
|
224
|
+
/// test point) -- makes WindowFromPoint return the OCCLUDER. When that happens the ENGINE IS RIGHT
|
|
225
|
+
/// to refuse: it must never act under a window the caller did not name. What broke is the arm's
|
|
226
|
+
/// PREMISE, not the product. Raising the test's OWN window into the topmost band uses the same
|
|
227
|
+
/// mechanism the overlay relies on (HWND_TOPMOST + SWP_NOACTIVATE): z-order changes,
|
|
228
|
+
/// GetForegroundWindow does not. This is a test-support primitive, NOT a product surface -- there is
|
|
229
|
+
/// no reason to let a model topmost-raise arbitrary windows, so no such action exists in
|
|
230
|
+
/// tools.json; scripts/raise-topmost.ps1 is the only product-adjacent caller and it is a test
|
|
231
|
+
/// helper under scripts/, not exposed through wpm.
|
|
232
|
+
/// </summary>
|
|
233
|
+
public static bool MakeTopmostNoActivate(IntPtr h) {
|
|
234
|
+
// SWP_NOMOVE(0x2) | SWP_NOSIZE(0x1) | SWP_NOACTIVATE(0x10), insert after HWND_TOPMOST(-1).
|
|
235
|
+
return SetWindowPos(h, new IntPtr(-1), 0, 0, 0, 0, 0x2u | 0x1u | 0x10u);
|
|
236
|
+
}
|
|
237
|
+
|
|
219
238
|
/// <summary>Add ex-style bits and return the new value (the trio lives here, once).</summary>
|
|
220
239
|
public static int AddExStyles(IntPtr h, int bits) {
|
|
221
240
|
int v = GetWindowLong(h, GWL_EXSTYLE);
|
|
@@ -233,6 +252,27 @@ public static class WpmWin
|
|
|
233
252
|
public static IntPtr FgHandle() { return GetForegroundWindow(); }
|
|
234
253
|
public static string Cursor() { POINT p; GetCursorPos(out p); return p.X + "," + p.Y; }
|
|
235
254
|
public static uint PidOf(IntPtr h) { uint p; GetWindowThreadProcessId(h, out p); return p; }
|
|
255
|
+
|
|
256
|
+
// One proof sample: cursor x/y, foreground HWND, focused-control HWND, and the age of the last
|
|
257
|
+
// PHYSICAL input. Every read is a non-disturbing query (GetCursorPos, GetForegroundWindow,
|
|
258
|
+
// GetGUIThreadInfo, GetLastInputInfo change nothing), which is the property that makes it safe to
|
|
259
|
+
// call in a tight loop DURING an action -- unlike spawning a fresh PowerShell per poll, which can
|
|
260
|
+
// itself steal the foreground and contaminate the measured quantity (src/lib/sampler.mjs).
|
|
261
|
+
public static string[] Sample()
|
|
262
|
+
{
|
|
263
|
+
POINT cp; GetCursorPos(out cp);
|
|
264
|
+
IntPtr fg = GetForegroundWindow();
|
|
265
|
+
GUITHREADINFO g = new GUITHREADINFO();
|
|
266
|
+
g.cbSize = (uint)Marshal.SizeOf(typeof(GUITHREADINFO));
|
|
267
|
+
uint pid; uint tid = GetWindowThreadProcessId(fg, out pid);
|
|
268
|
+
long focusHwnd = 0;
|
|
269
|
+
if (GetGUIThreadInfo(tid, ref g)) focusHwnd = g.hwndFocus.ToInt64();
|
|
270
|
+
long age = LastInputAgeMs(); // the one tick-difference calculation; -1 when unreadable
|
|
271
|
+
return new string[] {
|
|
272
|
+
cp.X.ToString(), cp.Y.ToString(),
|
|
273
|
+
fg.ToInt64().ToString(), focusHwnd.ToString(), age.ToString()
|
|
274
|
+
};
|
|
275
|
+
}
|
|
236
276
|
public static IntPtr Root(IntPtr h) { IntPtr r = GetAncestor(h, 2); return r == IntPtr.Zero ? h : r; }
|
|
237
277
|
|
|
238
278
|
public static List<long> Children(IntPtr parent)
|
package/src/engine/worker.ps1
CHANGED
|
@@ -92,6 +92,10 @@ while ($true) {
|
|
|
92
92
|
$on = [bool](Get-Arg $req 'on' $true)
|
|
93
93
|
if ($on) {
|
|
94
94
|
$r = Start-WpmOverlay
|
|
95
|
+
# The handshake now waits for the SAME flag the verdict reports (OverlayOn, not the hwnd)
|
|
96
|
+
# and says 'starting' when the budget merely expired -- so it can stay short and honest.
|
|
97
|
+
# Patience above a genuinely slow start lives in the Node half's placement retry loop,
|
|
98
|
+
# where a stop condition exists; a worker-side sleep cannot name one.
|
|
95
99
|
$st = Get-WpmOverlayState -WaitMs 2500
|
|
96
100
|
} else {
|
|
97
101
|
$r = Stop-WpmOverlay
|