dsh-windows-parallel-mcp 0.3.0 → 0.4.1

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/lib/index.js CHANGED
@@ -30,6 +30,70 @@ import { WorkerClient, workerScript } from './engine.js';
30
30
  import { ACTIONS, PARAMETERS, TOOL_NAME, resolveDefineTool } from './host-tools.js';
31
31
  import { evaluateProof } from './proof-window.mjs';
32
32
 
33
+ // ---- THE PUBLIC CONTRACT IS THE SOURCE OF TRUTH, AND THIS FILE IS CHECKED AGAINST IT ----------
34
+ //
35
+ // types/index.d.ts is what a consumer imports and what `scripts/check-types.mjs` proves a strict
36
+ // client accepts. The typedef block below IMPORTS that same file, so the annotations in this
37
+ // implementation are checked against the shipped promise rather than against a private copy of it:
38
+ // rename a field in types/index.d.ts and `scripts/check-jsdoc.mjs` turns this file red. That
39
+ // direction is the whole point -- a generated .d.ts (what a TypeScript rewrite would emit here) has
40
+ // no `WpmAction`/`RefusalCode`/`WpmArgs` at all, so it could not do this.
41
+ //
42
+ // (The first version of this block used `// @typedef` lines. Those are comments, not JSDoc: nothing
43
+ // was declared, and the checker answered "Cannot find name 'WpmArgs'". A JSDoc block is required.)
44
+ /**
45
+ * @typedef {import('../types/index.d.ts').WpmAction} WpmAction
46
+ * @typedef {import('../types/index.d.ts').WpmArgs} WpmArgs
47
+ * @typedef {import('../types/index.d.ts').RefusalCode} RefusalCode
48
+ * @typedef {import('../types/index.d.ts').WpmResult} WpmResult
49
+ * @typedef {import('../types/index.d.ts').WpmExec} WpmExec
50
+ */
51
+
52
+ /**
53
+ * The settings object `apply` derives from the Cordis config. Spelled out because the config VALUE is
54
+ * `{}` at the type level -- config.js validates it at runtime, and a validator's output is not a
55
+ * static fact -- so without this every one of the ten reads under `apply` reports "does not exist on
56
+ * type '{}'". The property list here must match `FIELDS` in config.js; both are checked by
57
+ * test/plugin-test.mjs.
58
+ * @typedef {object} WpmSettings
59
+ * @property {boolean} enabled
60
+ * @property {number} settleMs
61
+ * @property {number} requestTimeoutMs
62
+ * @property {string} powershellPath
63
+ * @property {boolean} overlay
64
+ * @property {boolean} logWorkerStderr
65
+ * @property {boolean} takeoverAllowed
66
+ * @property {boolean} keyInjectAllowed
67
+ * @property {number} takeoverMaxMs
68
+ * @property {number} takeoverArmMs
69
+ */
70
+
71
+ /**
72
+ * A refusal thrown before the worker is reached. The two extra fields are the whole point: the caller
73
+ * path reads `err.refusal` for the code and `err.reason` for the sentence, so typing this as a plain
74
+ * `Error` would lose the vocabulary that makes a refusal actionable.
75
+ * @typedef {Error & {refusal?: RefusalCode, reason?: string}} WpmError
76
+ */
77
+
78
+ /**
79
+ * One worker envelope, as engine.js documents it. `result` is deliberately `any`: its shape is the
80
+ * PowerShell engine's JSON-lines protocol, and pretending to type it from this side would be the
81
+ * "type safety over half the system" mistake in miniature.
82
+ * @typedef {object} Envelope
83
+ * @property {boolean} [ok]
84
+ * @property {string} [error]
85
+ * @property {any} [result]
86
+ */
87
+
88
+ /**
89
+ * The Cordis context surface this plugin touches, and nothing more. `logger` is optional everywhere it
90
+ * is used (`logger.warn?.(...)`) because a host that supplies no logger must still work.
91
+ * @typedef {object} CordisContext
92
+ * @property {{register: (tool: any) => void}} tools
93
+ * @property {{info?: (m: string) => void, warn?: (m: string) => void}} [logger]
94
+ * @property {(event: string, fn: () => void) => void} [on]
95
+ */
96
+
33
97
  /** Stable Cordis plugin name (this is what a profile entry points at). */
34
98
  export const name = 'windows-parallel';
35
99
 
@@ -60,8 +124,12 @@ export const toolHelperSource = resolvedTools.source;
60
124
  * Register the tool. `apply` is the whole host half; there is no client half yet, which is
61
125
  * deliberate: the overlay / pill / hotkey layer is task_54 and gets its own commit. A plugin with a
62
126
  * working tool and no UI is usable; a plugin with UI and no working tool is a demo.
127
+ * @param {CordisContext} ctx
128
+ * @param {Record<string, any>} [config]
129
+ * @returns {void}
63
130
  */
64
131
  export function apply(ctx, config = {}) {
132
+ /** @type {WpmSettings} */
65
133
  const settings = {
66
134
  enabled: resolveSetting(config.enabled, true),
67
135
  settleMs: resolveSetting(config.settleMs, 350),
@@ -89,6 +157,7 @@ export function apply(ctx, config = {}) {
89
157
  // make the README's "AI cursor is a click-through overlay" claim silently untrue.
90
158
  // Cost measured over the real worker protocol (.tmp/worker-overlay.mjs): start ~875ms once,
91
159
  // marker 19ms, status 15ms, stop ~660ms.
160
+ /** @type {Promise<any>|null} */
92
161
  let overlayReady = null;
93
162
  let overlayWarned = false;
94
163
  const ensureOverlay = () => {
@@ -122,6 +191,7 @@ export function apply(ctx, config = {}) {
122
191
  * retried. A promise with a race window is a promise that loses the race sometimes. The deadline
123
192
  * is BOUNDED and a confirmed-dead start (a reason with starting=false) stops the loop immediately
124
193
  * and warns -- endless patience would just hide a broken surface.
194
+ * @param {number} x @param {number} y @returns {void}
125
195
  */
126
196
  const markPoint = (x, y) => {
127
197
  if (!settings.overlay || !Number.isFinite(x) || !Number.isFinite(y)) return;
@@ -178,6 +248,7 @@ export function apply(ctx, config = {}) {
178
248
  * Two channels because one of them is a local file write that cannot be lost to a wedged loop.
179
249
  */
180
250
  const activeLatches = new Set();
251
+ /** @param {WpmExec|undefined} exec @returns {() => void} */
181
252
  const armAbort = (exec) => {
182
253
  const signal = exec?.signal;
183
254
  if (!signal || typeof signal.addEventListener !== 'function') return () => {};
@@ -200,6 +271,7 @@ export function apply(ctx, config = {}) {
200
271
  const { defineTool } = resolvedTools;
201
272
 
202
273
  /** Build the worker request for one action. Throws for arguments the action cannot use. */
274
+ /** @param {WpmArgs} args @returns {any} */
203
275
  function toRequest(args) {
204
276
  const settleMs = clampSettle(args.settleMs ?? settings.settleMs);
205
277
  // The takeover fields are attached ONLY when the caller asked for them AND the gate is open. When a
@@ -228,7 +300,12 @@ export function apply(ctx, config = {}) {
228
300
  requireArg(args, 'hwnd', 'click');
229
301
  requireArg(args, 'x', 'click');
230
302
  requireArg(args, 'y', 'click');
231
- return { action: 'click', hwnd: args.hwnd, x: Math.round(args.x), y: Math.round(args.y), settleMs, ...takeoverFields };
303
+ // The two casts state what `requireArg` just enforced: `WpmArgs.x/y` are optional in the
304
+ // public contract (click requires them, windows does not), and the guard above is the only
305
+ // thing that narrows them. A checker cannot see through a separate function's throw, so this
306
+ // is where the guarantee is recorded -- not a suppression, since requireArg throws for both
307
+ // undefined and null before this line is reached.
308
+ return { action: 'click', hwnd: args.hwnd, x: Math.round(/** @type {number} */ (args.x)), y: Math.round(/** @type {number} */ (args.y)), settleMs, ...takeoverFields };
232
309
  case 'type':
233
310
  requireArg(args, 'hwnd', 'type');
234
311
  if (typeof args.text !== 'string' || args.text.length === 0) {
@@ -278,8 +355,14 @@ export function apply(ctx, config = {}) {
278
355
  text: { type: 'string', required: true },
279
356
  },
280
357
  },
281
- render: (_args, value) => [{ type: 'text', text: value.text }],
358
+ // `WpmResult.text` is optional in the public contract (a consumer may hold a partial object),
359
+ // but every value that reaches this render is built by `result()` below, which always sets it.
360
+ // The cast records that invariant instead of substituting '' -- an empty string would be a
361
+ // rendered blank, and the text IS the product here.
362
+ /** @param {WpmArgs} _args @param {WpmResult} value @returns {Array<{type: string, text: string}>} */
363
+ render: (_args, value) => [{ type: 'text', text: /** @type {string} */ (value.text) }],
282
364
  },
365
+ /** @param {WpmArgs} args @param {WpmExec|undefined} exec @returns {Promise<Record<string, any>>} */
283
366
  async execute(args, exec) {
284
367
  // Server-side gates first: a paused or disabled engine must refuse before it spends a worker
285
368
  // call, and the refusal must name the gate rather than describe a symptom.
@@ -308,8 +391,14 @@ export function apply(ctx, config = {}) {
308
391
  try {
309
392
  request = toRequest(args);
310
393
  } catch (err) {
311
- const code = err?.refusal ?? 'action_failed';
312
- return result(args.action, false, code, err?.reason ?? String(err?.message ?? err));
394
+ // `catch` binds `unknown` under strict, which is correct: anything can be thrown. The casts
395
+ // are the narrowing step, kept INLINE so the statements and local names below are exactly what
396
+ // they were -- `scripts`-level AST comparison against the previous revision is a gate here, and
397
+ // a rename would make a comment-only change look like a behaviour change. Safe on this path
398
+ // because the only thrower is `refusal()` above; the `??` fallbacks still keep the vocabulary
399
+ // intact when it is not.
400
+ const code = /** @type {WpmError} */ (err)?.refusal ?? 'action_failed';
401
+ return result(args.action, false, code, /** @type {WpmError} */ (err)?.reason ?? String(/** @type {WpmError} */ (err)?.message ?? err));
313
402
  }
314
403
  let envelope;
315
404
  const disarm = request.takeover ? armAbort(exec) : () => {};
@@ -318,7 +407,11 @@ export function apply(ctx, config = {}) {
318
407
  } catch (err) {
319
408
  // The worker layer failed (crash, timeout, missing engine). This is not a refusal code: the
320
409
  // engine never got to decide. Say exactly that instead of borrowing a code it does not own.
321
- return result(args.action, false, 'action_failed', `engine worker unavailable: ${err.message}`);
410
+ // Cast inline for the same reason as above. No `String(...)` wrapper and no `?.` are added:
411
+ // the original read `err.message` directly, and a non-Error thrown here still renders the
412
+ // same way it always did -- widening the expression would be a behaviour change dressed as
413
+ // type safety, which is exactly what this file refuses to do.
414
+ return result(args.action, false, 'action_failed', `engine worker unavailable: ${/** @type {Error} */ (err).message}`);
322
415
  } finally {
323
416
  disarm();
324
417
  }
@@ -354,6 +447,7 @@ export function apply(ctx, config = {}) {
354
447
  // ---- small helpers ---------------------------------------------------------------------------
355
448
 
356
449
  /** A Cordis settings value may be a live ref (0.1.7+) or a plain value (older lines). */
450
+ /** @param {any} value @param {any} fallback @returns {any} */
357
451
  function resolveSetting(value, fallback) {
358
452
  if (value === undefined || value === null) return fallback;
359
453
  const v = typeof value.get === 'function' ? value.get() : value;
@@ -361,26 +455,49 @@ function resolveSetting(value, fallback) {
361
455
  return v;
362
456
  }
363
457
 
458
+ /** @param {any} value @returns {number} */
364
459
  function clampSettle(value) {
365
460
  const n = Number(value);
366
461
  if (!Number.isFinite(n)) return 350;
367
462
  return Math.max(0, Math.min(2000, Math.round(n)));
368
463
  }
369
464
 
465
+ /**
466
+ * @param {Record<string, any>} args
467
+ * @param {'hwnd'|'x'|'y'|'text'|'elementName'} key
468
+ * @param {string} action
469
+ * @returns {void}
470
+ */
370
471
  function requireArg(args, key, action) {
371
472
  if (args[key] === undefined || args[key] === null || args[key] === '') {
372
473
  throw refusal('no_hwnd', `action=${action} requires '${key}'`);
373
474
  }
374
475
  }
375
476
 
376
- /** A refusal thrown before the worker is reached; caught by the caller path that renders results. */
477
+ /**
478
+ * A refusal thrown before the worker is reached; caught by the caller path that renders results.
479
+ * @param {RefusalCode} code
480
+ * @param {string} reason
481
+ * @returns {WpmError}
482
+ */
377
483
  function refusal(code, reason) {
378
- const err = new Error(`${code}: ${reason}`);
484
+ // The cast is the definition of this function's payload: a plain Error plus the two fields the
485
+ // caller path reads. Writing it after construction (rather than using a subclass) keeps `instanceof
486
+ // Error` true for the host, which is what the catch sites rely on.
487
+ const err = /** @type {WpmError} */ (new Error(`${code}: ${reason}`));
379
488
  err.refusal = code;
380
489
  err.reason = reason;
381
490
  return err;
382
491
  }
383
492
 
493
+ /**
494
+ * @param {string} action
495
+ * @param {boolean} ok
496
+ * @param {RefusalCode|''} refusalCode
497
+ * @param {string} text
498
+ * @param {Record<string, any>} [extra]
499
+ * @returns {Record<string, any>}
500
+ */
384
501
  function result(action, ok, refusalCode, text, extra) {
385
502
  return { action, ok, refusal: refusalCode, text: refusalCode ? `${refusalCode}: ${text}` : text, ...(extra || {}) };
386
503
  }
@@ -391,6 +508,9 @@ function result(action, ok, refusalCode, text, extra) {
391
508
  * The text is the product. A caller that gets `ok:false` with a code and a reason can act; a caller
392
509
  * that gets "the action failed" cannot. Every number reported here is measured by the engine, not
393
510
  * inferred by this file.
511
+ * @param {string} action
512
+ * @param {any} r
513
+ * @returns {Record<string, any>}
394
514
  */
395
515
  function format(action, r) {
396
516
  if (!r) return result(action, false, 'action_failed', 'engine returned no result');
@@ -400,7 +520,7 @@ function format(action, r) {
400
520
  if (list.length === 0) {
401
521
  return result(action, true, '', 'no drivable windows are visible right now (minimised and untitled windows are excluded by design)');
402
522
  }
403
- const lines = list.map((w) => `${w.hwnd} ${truncate(String(w.title), 60)} [${w.cls}] pid=${w.pid} rect=${w.rect}`);
523
+ const lines = list.map(/** @param {any} w @returns {string} */ (w) => `${w.hwnd} ${truncate(String(w.title), 60)} [${w.cls}] pid=${w.pid} rect=${w.rect}`);
404
524
  return result(action, true, '', `${list.length} drivable window(s):\n${lines.join('\n')}`);
405
525
  }
406
526
 
@@ -433,7 +553,11 @@ function format(action, r) {
433
553
  }
434
554
 
435
555
  // Action results. `refusal` is the engine's own code: an empty string means the action ran.
436
- const code = r.refusal ? String(r.refusal) : '';
556
+ // The cast leans on `scripts/check-refusals.mjs`, which pins the engine's emitted codes to the
557
+ // closed set in src/schema/tools.json: the wire format is a string, but the vocabulary is a
558
+ // contract that another gate already enforces. Typing this as plain `string` would push the check
559
+ // to every call site; typing it as `RefusalCode` names where the guarantee actually comes from.
560
+ const code = r.refusal ? /** @type {RefusalCode} */ (String(r.refusal)) : '';
437
561
  if (code) {
438
562
  const reason = r.reason ? ` (${r.reason})` : '';
439
563
  // A takeover refusal still carries the takeover accounting: "aborted after 12 characters, cursor
@@ -520,11 +644,13 @@ function format(action, r) {
520
644
  });
521
645
  }
522
646
 
647
+ /** @param {string} s @param {number} n @returns {string} */
523
648
  function truncate(s, n) {
524
649
  return s.length <= n ? s : `${s.slice(0, n - 1)}…`;
525
650
  }
526
651
 
527
652
  /** Clamp a possibly-undefined number into [min,max], falling back to `fallback` for non-numbers. */
653
+ /** @param {any} value @param {number} min @param {number} max @param {number} fallback @returns {number} */
528
654
  function clampNumber(value, min, max, fallback) {
529
655
  const n = Number(value);
530
656
  if (!Number.isFinite(n)) return fallback;
@@ -532,12 +658,14 @@ function clampNumber(value, min, max, fallback) {
532
658
  }
533
659
 
534
660
  /** The same latch path the engine computes: %LOCALAPPDATA%\wpm\takeover-abort.<worker pid>. */
661
+ /** @param {number|string} pid @returns {string} */
535
662
  function abortLatchPath(pid) {
536
663
  const base = process.env.LOCALAPPDATA || tmpdir();
537
664
  return join(base, 'wpm', `takeover-abort.${pid}`);
538
665
  }
539
666
 
540
667
  /** A one-line target hint for a pre-worker refusal: the caller can retry without the field. */
668
+ /** @param {WpmArgs} args @returns {string} */
541
669
  function hwndHint(args) {
542
670
  return args.hwnd ? ` (target hwnd=${args.hwnd})` : '';
543
671
  }
@@ -12,6 +12,12 @@
12
12
  // combined bridge module would mean the missing dsh-tools throws during evaluation and takes
13
13
  // schemastery down with it -- the plugin would fail to LOAD, which is worse than the shim path it
14
14
  // was meant to fix. Two files, two independent failure domains.
15
+ // @ts-nocheck -- DELIBERATE, same reasoning as peers-tools.js: `@deepseek-ai/schemastery` is a
16
+ // cordis dependency the HOST supplies, and whatever type surface a checker resolves for it here is a
17
+ // property of THIS machine's checkout, not of the package. `z` below is deliberately the shape-agnostic
18
+ // handoff into config.js; pinning it to one installed version's `.default` export would turn a
19
+ // host-version difference into a false red. The barrier is the point.
20
+ // @ts-nocheck
15
21
  import schemasteryNs from '@deepseek-ai/schemastery';
16
22
 
17
23
  export const z = schemasteryNs?.default ?? schemasteryNs;
@@ -1,6 +1,15 @@
1
1
  // peers-tools.js -- the host's defineTool, reached through a STATIC import. See peers-schemastery.js
2
2
  // for why the bridge is split in two and why a dynamic bare specifier does not resolve for a
3
3
  // `link:`-installed package.
4
+ //
5
+ // @ts-nocheck -- DELIBERATE, and the only honest option. `@deepseek-ai/dsh-tools` is a peer the HOST
6
+ // provides; it is not installed in this checkout, so a type checker can only see an unresolved module
7
+ // here. The alternatives are both lies: a `declare module` stub would assert a shape nobody verified
8
+ // against the real package (and this file exists precisely because peer resolution is unpredictable),
9
+ // while dropping the file from the check config makes its IMPORTER fail with TS2307 -- a gate
10
+ // inventing a problem of its own. The barrier is the point: everything downstream of this import is
11
+ // untyped on purpose, and this line says so where a reader will see it.
12
+ // @ts-nocheck
4
13
  import * as toolsNs from '@deepseek-ai/dsh-tools';
5
14
 
6
15
  export const defineTool = toolsNs.defineTool;
@@ -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.3.0",
3
+ "version": "0.4.1",
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": [