dsh-windows-parallel-mcp 0.2.0 → 0.4.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.
@@ -46,14 +46,97 @@
46
46
  // reachability numbers and the per-action proof were measured by different instruments while
47
47
  // carrying the same name -- the drift this repo already killed once (see sampler.mjs header).
48
48
 
49
+ /**
50
+ * One sampler reading. `inputAgeMs` is `undefined` when the instrument could not read it, which is
51
+ * NOT the same as 0 ("input just happened") -- the whole fail-closed rule below depends on that.
52
+ * @typedef {object} ProofSample
53
+ * @property {number} ts
54
+ * @property {number} [inputAgeMs]
55
+ * @property {number} cx
56
+ * @property {number} cy
57
+ * @property {number|string} [fg]
58
+ * @property {number|string} [focus]
59
+ */
60
+
61
+ /**
62
+ * The software-attributable counts. Named rather than inferred because `{}` fragments this object at
63
+ * every consumer (`attribution.x`, `summary.attribution.y`), and a checker that cannot see the keys
64
+ * reports each read as an error against a type nobody wrote down.
65
+ * @typedef {object} Attribution
66
+ * @property {number} physicalInputEvents
67
+ * @property {number} humanActiveMs
68
+ * @property {number} quietMs
69
+ * @property {number} unexplainedCursorMotionGaps
70
+ * @property {number} unexplainedCursorMaxDeltaPx
71
+ * @property {number|null} unexplainedCursorMaxDeltaAt
72
+ * @property {number} unexplainedCursorPathPx
73
+ * @property {number} unexplainedForegroundSwitches
74
+ * @property {number} unexplainedFocusChanges
75
+ * @property {number} unreadableInputAgeGaps
76
+ */
77
+
78
+ /**
79
+ * One attempt's outcome, as the engine reported it.
80
+ * @typedef {object} ActionAttempt
81
+ * @property {boolean} [ok]
82
+ * @property {string} [effect]
83
+ */
84
+
85
+ /**
86
+ * @typedef {object} ProofOpts
87
+ * @property {number} [minSamples]
88
+ * @property {number} [humanGapFactor]
89
+ * @property {ProofSample[]} [control]
90
+ * @property {boolean} [declaredFlash]
91
+ * @property {string} [effect]
92
+ * @property {ActionAttempt[]} [actions]
93
+ * @property {boolean} [declaredTakeover]
94
+ * @property {boolean} [cursorRestored]
95
+ * @property {number} [unreadableCap]
96
+ */
97
+
98
+ /**
99
+ * @typedef {object} VerdictResult
100
+ * @property {'pass'|'fail'|'inconclusive'|'insufficient'} verdict
101
+ * @property {string} reason
102
+ * @property {Record<string,string>} [dimensions]
103
+ */
104
+
105
+ /**
106
+ * @typedef {object} ProofResult
107
+ * @property {number} samples
108
+ * @property {number} windowMs
109
+ * @property {number|null} cursorMaxDeltaPx
110
+ * @property {number|null} cursorMaxDeltaAt
111
+ * @property {number|null} cursorTotalPathPx
112
+ * @property {number|null} foregroundSwitches
113
+ * @property {number|null} focusChanges
114
+ * @property {Attribution|null} attribution
115
+ * @property {Attribution|null} control
116
+ * @property {'pass'|'fail'|'inconclusive'|'insufficient'} verdict
117
+ * @property {string} reason
118
+ * @property {Record<string,string>} [dimensions]
119
+ */
120
+
121
+ /** @param {number} v @returns {number} */
49
122
  const round = (v) => Math.round(v * 100) / 100;
50
123
 
51
- /** Absolute timestamp of the last PHYSICAL input at sample x, or null if unreadable. */
124
+ /**
125
+ * Absolute timestamp of the last PHYSICAL input at sample x, or null if unreadable.
126
+ * @param {ProofSample} x
127
+ * @returns {number|null}
128
+ */
52
129
  export function physEventAt(x) {
53
130
  return typeof x.inputAgeMs === 'number' && x.inputAgeMs >= 0 ? x.ts - x.inputAgeMs : null;
54
131
  }
55
132
 
56
- /** Was there physical input inside the gap between b and a? Unreadable age => NOT human (fail closed). */
133
+ /**
134
+ * Was there physical input inside the gap between b and a? Unreadable age => NOT human (fail closed).
135
+ * @param {ProofSample} b
136
+ * @param {ProofSample} a
137
+ * @param {number} [humanGapFactor]
138
+ * @returns {boolean}
139
+ */
57
140
  export function isHumanGap(b, a, humanGapFactor = 0.6) {
58
141
  const ea = physEventAt(b), eb = physEventAt(a);
59
142
  if (ea === null || eb === null) return false;
@@ -62,9 +145,13 @@ export function isHumanGap(b, a, humanGapFactor = 0.6) {
62
145
 
63
146
  /**
64
147
  * Evaluate one proof window. Pure.
65
- * @param {Array} samples the ACTION window
66
- * @param {{minSamples?:number, humanGapFactor?:number, control?:Array, declaredFlash?:boolean,
67
- * effect?:string, actions?:Array, declaredTakeover?:boolean, cursorRestored?:boolean}} [opts]
148
+ *
149
+ * The `@param` types below were written as a plain object literal before, which is legal JSDoc but
150
+ * was not applied where `Array` appeared bare: `{Array}` is not a usable type under checkJs (it
151
+ * demands a type argument), so the checker discarded the whole annotation and read `opts` as `{}`.
152
+ * Seven "property does not exist on type '{}'" errors were one symptom of that single mistake.
153
+ * @param {ProofSample[]} samples the ACTION window
154
+ * @param {ProofOpts} [opts]
68
155
  * control = the pre-action window (sampled while nothing was done). It cannot excuse motion in the
69
156
  * action window -- the structural rule already handles that -- but it decides whether the
70
157
  * foreground/focus dimensions are evaluable at all.
@@ -73,14 +160,19 @@ export function isHumanGap(b, a, humanGapFactor = 0.6) {
73
160
  * old behaviour byte for byte.
74
161
  * actions = optional per-attempt results ({ ok, effect }); when EVERY attempt failed to take
75
162
  * effect the verdict is fail regardless of how still the desktop stayed.
163
+ * @returns {ProofResult}
76
164
  */
77
165
  export function evaluateProof(samples, opts = {}) {
78
166
  const minSamples = opts.minSamples ?? 3;
79
167
  const humanGap = opts.humanGapFactor ?? 0.6;
80
168
 
81
- const r = (Array.isArray(samples) ? samples : [])
169
+ // The cast is the point of the filter: `filter(Boolean)` drops the nulls at runtime but is not a
170
+ // type predicate, so the array's declared element type has to be asserted once here rather than
171
+ // sprinkled through the loop as non-null assertions.
172
+ /** @type {ProofSample[]} */
173
+ const r = /** @type {ProofSample[]} */ ((Array.isArray(samples) ? samples : [])
82
174
  .map((x) => (x && typeof x.ts === 'number' ? x : null))
83
- .filter(Boolean);
175
+ .filter(Boolean));
84
176
 
85
177
  if (r.length < minSamples) {
86
178
  return {
@@ -200,9 +292,14 @@ export function evaluateProof(samples, opts = {}) {
200
292
  * the case the pre-0.1.3 gate could read as a green light: 50 failed calls, zero
201
293
  * displacement. Displacement proves we did not disturb; it never proves we accomplished.
202
294
  * Overall = worst dimension: fail > inconclusive > pass.
295
+ * @param {string|null} [effect]
296
+ * @param {ActionAttempt[]} [actions]
297
+ * @returns {{dim: 'pass'|'fail'|'inconclusive', note: string}|null}
203
298
  */
204
299
  function judgeEffect(effect, actions) {
300
+ /** @type {ActionAttempt[]} */
205
301
  const list = Array.isArray(actions) ? actions.filter(Boolean) : [];
302
+ /** @param {ActionAttempt} a @returns {boolean} */
206
303
  const reported = (a) => a.ok !== false
207
304
  && (a.effect === 'reported-by-send' || a.effect === 'reported-by-pattern');
208
305
 
@@ -231,9 +328,20 @@ function judgeEffect(effect, actions) {
231
328
  };
232
329
  }
233
330
 
331
+ /**
332
+ * @param {Attribution|null} attribution
333
+ * @param {Attribution|null} control
334
+ * @param {number} sampleCount
335
+ * @param {ProofOpts} [opts]
336
+ * @returns {VerdictResult}
337
+ */
234
338
  export function verdictFor(attribution, control, sampleCount, opts = {}) {
339
+ // `Partial` because both callers legitimately pass nothing (`null`) for a window they have no
340
+ // control for, and every read below already defends with `?? 0`.
341
+ /** @type {Partial<Attribution>} */
235
342
  const a = attribution || {};
236
343
  const unreadableCap = opts.unreadableCap ?? Math.max(1, Math.floor((sampleCount - 1) * 0.3));
344
+ /** @type {Record<string,string>} */
237
345
  const dims = {};
238
346
 
239
347
  if ((a.unreadableInputAgeGaps ?? 0) > unreadableCap) {
@@ -299,8 +407,14 @@ export function verdictFor(attribution, control, sampleCount, opts = {}) {
299
407
  return { verdict, reason, dimensions: dims };
300
408
  }
301
409
 
302
- /** The software-attributable quantities, flattened for callers that only want the numbers. */
410
+ /**
411
+ * The software-attributable quantities, flattened for callers that only want the numbers.
412
+ * @param {ProofResult|{attribution?: Attribution|null}} [summary]
413
+ * @returns {{motionGaps: number|null, maxPx: number|null, pathPx: number|null,
414
+ * foregroundSwitches: number|null, focusChanges: number|null, quietMs: number|null}}
415
+ */
303
416
  export function softwareCursorEvidence(summary) {
417
+ /** @type {Partial<Attribution>} */
304
418
  const a = (summary && summary.attribution) || {};
305
419
  return {
306
420
  motionGaps: a.unexplainedCursorMotionGaps ?? null,
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "dsh-windows-parallel-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
- "tag": "latest"
6
+ "tag": "latest",
7
+ "registry": "https://registry.npmjs.org/"
7
8
  },
8
9
  "description": "Drive a Windows window quietly by default and visibly on request: one tool, five actions, a channel decision table that prefers the quiet door, a bounded self-reversing focus flash when only UI Automation can reach the control, and an opt-in takeover tier (HUD mandatory, cursor always restored, keyboard injection only when asked and only for the foreground target). Windows PowerShell 5.1 sidecar, zero install dependencies, no mouse injection.",
9
10
  "keywords": [
@@ -28,8 +29,9 @@
28
29
  },
29
30
  "type": "module",
30
31
  "main": "lib/index.js",
32
+ "types": "types/index.d.ts",
31
33
  "exports": {
32
- ".": "./lib/index.js",
34
+ ".": { "types": "./types/index.d.ts", "default": "./lib/index.js" },
33
35
  "./cordis.patch.yml": "./cordis.patch.yml",
34
36
  "./dsh.plugin.json": "./dsh.plugin.json",
35
37
  "./src/engine/*": "./src/engine/*",
@@ -37,6 +39,7 @@
37
39
  },
38
40
  "files": [
39
41
  "lib/",
42
+ "types/",
40
43
  "src/engine/",
41
44
  "src/schema/",
42
45
  "docs/refusals.md",
@@ -45,7 +48,34 @@
45
48
  "cordis.patch.yml",
46
49
  "dsh.plugin.json",
47
50
  "INSTALL.md",
48
- "README.md"
51
+ "README.md",
52
+ "INSTALL.ru.md",
53
+ "CHANGELOG.ru.md",
54
+ "README.ru.md",
55
+ "INSTALL.pt.md",
56
+ "CHANGELOG.pt.md",
57
+ "README.pt.md",
58
+ "INSTALL.es.md",
59
+ "CHANGELOG.es.md",
60
+ "README.es.md",
61
+ "INSTALL.it.md",
62
+ "CHANGELOG.it.md",
63
+ "README.it.md",
64
+ "INSTALL.de.md",
65
+ "CHANGELOG.de.md",
66
+ "README.de.md",
67
+ "INSTALL.fr.md",
68
+ "CHANGELOG.fr.md",
69
+ "README.fr.md",
70
+ "INSTALL.ko.md",
71
+ "CHANGELOG.ko.md",
72
+ "README.ko.md",
73
+ "INSTALL.ja.md",
74
+ "CHANGELOG.ja.md",
75
+ "README.ja.md",
76
+ "INSTALL.zh.md",
77
+ "CHANGELOG.zh.md",
78
+ "README.zh.md"
49
79
  ],
50
80
  "dsh": {
51
81
  "bundle": {
@@ -0,0 +1,68 @@
1
+ // Type declarations for dsh-windows-parallel-mcp (public API surface).
2
+ // Mirrors lib/index.js + lib/host-tools.js + src/schema/tools.json (v0.2.0).
3
+
4
+ export type WpmAction = 'windows' | 'click' | 'type' | 'focus' | 'status';
5
+
6
+ export type RefusalCode =
7
+ | 'no_hwnd' | 'paused' | 'elevated_target' | 'unreachable'
8
+ | 'uia_tree_empty' | 'uia_probe_failed' | 'terminal_no_door' | 'needs_facts'
9
+ | 'takeover_unavailable' | 'keyinject_unavailable' | 'action_failed'
10
+ | 'restore_failed' | 'takeover_aborted';
11
+
12
+ export type KeyInputMode = 'none' | 'inject';
13
+
14
+ export interface WpmWindow {
15
+ hwnd: string; title: string; class: string; pid: number;
16
+ rect: { left: number; top: number; right: number; bottom: number };
17
+ }
18
+
19
+ export interface WpmArgs {
20
+ action: WpmAction;
21
+ hwnd?: string;
22
+ x?: number;
23
+ y?: number;
24
+ text?: string;
25
+ elementName?: string;
26
+ replace?: boolean;
27
+ settleMs?: number;
28
+ takeover?: boolean;
29
+ takeoverMaxMs?: number;
30
+ keyInput?: KeyInputMode;
31
+ }
32
+
33
+ export interface WpmResult {
34
+ text?: string;
35
+ refusal?: RefusalCode;
36
+ channel?: string;
37
+ tier?: string;
38
+ effect?: string;
39
+ proof?: 'pass' | 'fail' | 'inconclusive';
40
+ focusTaken?: boolean;
41
+ takeover?: 'on' | 'off';
42
+ cursorMoved?: boolean;
43
+ cursorRestored?: boolean;
44
+ takeoverMs?: number;
45
+ abortChord?: string;
46
+ keysInjected?: boolean;
47
+ injectedChars?: number;
48
+ [key: string]: unknown;
49
+ }
50
+
51
+ export interface WpmExec { signal?: AbortSignal; [key: string]: unknown; }
52
+
53
+ export interface WpmTool { execute(args: WpmArgs, exec?: WpmExec): Promise<WpmResult>; }
54
+
55
+ export const name: 'windows-parallel';
56
+ export const inject: readonly ['tools'];
57
+ export const Config: unknown;
58
+ export const configSource: string;
59
+ export const toolHelperSource: string;
60
+ export function apply(ctx: Record<string, unknown>, config?: Record<string, unknown>): void;
61
+
62
+ export const TOOL_NAME: 'wpm';
63
+ export const ACTIONS: readonly WpmAction[];
64
+ export const PARAMETERS: Record<string, { type: string; enum?: readonly string[]; required?: boolean; description: string }>;
65
+ export function parametersToJsonSchema(spec?: Record<string, unknown>): Record<string, unknown>;
66
+ export function validateArguments(schema: Record<string, unknown>, args: WpmArgs): boolean | string;
67
+ export function localDefineTool(options: Record<string, unknown>): WpmTool;
68
+ export function resolveDefineTool(): Promise<{ defineTool: (o: Record<string, unknown>) => WpmTool; source: string }>;