dsh-windows-parallel-mcp 0.4.0 → 0.5.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.
- package/CHANGELOG.de.md +12 -0
- package/CHANGELOG.es.md +12 -0
- package/CHANGELOG.fr.md +12 -0
- package/CHANGELOG.it.md +12 -0
- package/CHANGELOG.ja.md +12 -0
- package/CHANGELOG.ko.md +12 -0
- package/CHANGELOG.md +161 -0
- package/CHANGELOG.pt.md +12 -0
- package/CHANGELOG.ru.md +12 -0
- package/CHANGELOG.zh.md +12 -0
- package/README.de.md +106 -18
- package/README.es.md +106 -18
- package/README.fr.md +106 -18
- package/README.it.md +106 -18
- package/README.ja.md +106 -18
- package/README.ko.md +106 -18
- package/README.md +106 -18
- package/README.pt.md +106 -18
- package/README.ru.md +106 -18
- package/README.zh.md +106 -18
- package/docs/refusals.md +7 -4
- package/dsh.plugin.json +3 -3
- package/lib/config.js +14 -0
- package/lib/host-tools.js +61 -3
- package/lib/index.js +272 -14
- package/package.json +6 -3
- package/src/engine/engine.ps1 +217 -3
- package/src/engine/win.ps1 +588 -1
- package/src/engine/worker.ps1 +35 -1
- package/src/schema/tools.json +115 -9
- package/types/index.d.ts +63 -3
package/lib/host-tools.js
CHANGED
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
// that the caller can branch on the code and read the next step.
|
|
19
19
|
export const TOOL_NAME = 'wpm';
|
|
20
20
|
|
|
21
|
-
/** The
|
|
22
|
-
export const ACTIONS = ['windows', 'click', 'type', 'focus', 'status'];
|
|
21
|
+
/** The eight actions, in the order the contract lists them. */
|
|
22
|
+
export const ACTIONS = ['windows', 'click', 'type', 'focus', 'status', 'snapshot', 'screenshot', 'preview'];
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* One field of the simplified parameter spec -- the shape the host's `defineTool` consumes and the
|
|
@@ -54,7 +54,10 @@ export const PARAMETERS = {
|
|
|
54
54
|
'windows: list live windows that can be driven (hwnd, title, class, pid, rect). '
|
|
55
55
|
+ 'status: read the focus table (foreground window, focused control, last human input age, paused flag). '
|
|
56
56
|
+ 'click: click at a screen coordinate inside the target. type: write text into the target. '
|
|
57
|
-
+ 'focus: move keyboard focus to a named control inside the target.'
|
|
57
|
+
+ 'focus: move keyboard focus to a named control inside the target. '
|
|
58
|
+
+ 'snapshot: read the accessibility tree as a numbered element table (labels you can act on). '
|
|
59
|
+
+ 'screenshot: capture the target rect to a PNG and return its coordinate mapping as data. '
|
|
60
|
+
+ 'preview: draw the marker at a point and report the element under it, without clicking.',
|
|
58
61
|
},
|
|
59
62
|
hwnd: {
|
|
60
63
|
type: 'string',
|
|
@@ -96,6 +99,61 @@ export const PARAMETERS = {
|
|
|
96
99
|
+ 'call is refused with keyinject_unavailable. Never moves the mouse, never clicks. The result '
|
|
97
100
|
+ 'reports effect=reported-by-send, not "verified".',
|
|
98
101
|
},
|
|
102
|
+
// ---- 0.5.0: the frame / label / image-coordinate surface -----------------------------------
|
|
103
|
+
// Every description below says what the field costs or what it refuses, because each one exists to
|
|
104
|
+
// remove a way for the caller to silently act on the wrong thing.
|
|
105
|
+
label: {
|
|
106
|
+
type: 'number',
|
|
107
|
+
description:
|
|
108
|
+
'Element number from action=snapshot (click/type/focus). The label is resolved back to the UIA '
|
|
109
|
+
+ 'ELEMENT by RuntimeId, so the action still takes the silent pattern path instead of degrading to '
|
|
110
|
+
+ 'a coordinate click. For click, x/y stay required and must fall inside the labelled element, so '
|
|
111
|
+
+ '"the point is the contract" remains true.',
|
|
112
|
+
},
|
|
113
|
+
snapId: {
|
|
114
|
+
type: 'string',
|
|
115
|
+
description:
|
|
116
|
+
'The snapId the label came from. A label whose snapId has been superseded is refused with '
|
|
117
|
+
+ 'stale_ref: element numbers only mean something in the frame that printed them.',
|
|
118
|
+
},
|
|
119
|
+
space: {
|
|
120
|
+
type: 'string',
|
|
121
|
+
enum: ['screen', 'image'],
|
|
122
|
+
description:
|
|
123
|
+
'Coordinate space of click x/y. "screen" (default) is physical screen pixels. "image" means image '
|
|
124
|
+
+ 'pixels from the screenshot named by shotId -- the ENGINE converts them, so the caller never '
|
|
125
|
+
+ 'multiplies a scale factor; the point-ownership assertion still runs after conversion.',
|
|
126
|
+
},
|
|
127
|
+
shotId: {
|
|
128
|
+
type: 'string',
|
|
129
|
+
description:
|
|
130
|
+
'The shotId from action=screenshot. Required when space="image" (refused before any worker call); '
|
|
131
|
+
+ 'an id that was already cleaned up by the retention policy is refused with stale_ref.',
|
|
132
|
+
},
|
|
133
|
+
maxElements: {
|
|
134
|
+
type: 'number',
|
|
135
|
+
description: 'snapshot only: hard cap on returned elements (1-5000, default 300). The text then says "truncated at N of M" and truncated is true.',
|
|
136
|
+
},
|
|
137
|
+
interactableOnly: {
|
|
138
|
+
type: 'boolean',
|
|
139
|
+
description: 'snapshot only (default true): return only elements exposing a usable UIA pattern. false returns the whole visible tree.',
|
|
140
|
+
},
|
|
141
|
+
sinceSnapId: {
|
|
142
|
+
type: 'string',
|
|
143
|
+
description: 'snapshot only: return an added/removed/changed diff against this earlier snapId instead of the whole table. An unchanged tree yields an empty delta.',
|
|
144
|
+
},
|
|
145
|
+
intent: {
|
|
146
|
+
type: 'string',
|
|
147
|
+
description: 'snapshot only: what this frame is FOR. It travels with the frame so a deciding subagent can answer with a single label.',
|
|
148
|
+
},
|
|
149
|
+
fullScreen: {
|
|
150
|
+
type: 'boolean',
|
|
151
|
+
description: 'screenshot only (default false): capture the whole virtual screen instead of one window. Off by default so the owner\'s desktop is never captured silently.',
|
|
152
|
+
},
|
|
153
|
+
maxWidth: {
|
|
154
|
+
type: 'number',
|
|
155
|
+
description: 'screenshot only: downscale the saved image to at most this width (0 = no scaling, default). Scaling changes the coordinate system, so it must be asked for explicitly and is reported as scale.',
|
|
156
|
+
},
|
|
99
157
|
};
|
|
100
158
|
|
|
101
159
|
/**
|
package/lib/index.js
CHANGED
|
@@ -7,13 +7,15 @@
|
|
|
7
7
|
// row, no second Node process — the tool is registered here and the only child process is the
|
|
8
8
|
// PowerShell worker, which the engine already needed in either form.
|
|
9
9
|
//
|
|
10
|
-
// WHY ONE TOOL AND NOT FIVE. src/schema/tools.json names
|
|
10
|
+
// WHY ONE TOOL AND NOT FIVE. src/schema/tools.json names eight actions as the contract surface. The
|
|
11
11
|
// host convention (shell / terminal / read / write in this same build) is one tool with an action
|
|
12
|
-
// discriminator, because every registered tool is resident schema on every turn —
|
|
12
|
+
// discriminator, because every registered tool is resident schema on every turn — eight entries
|
|
13
13
|
// describing one engine is a standing token cost for no gain in capability. The contract is
|
|
14
|
-
// preserved exactly: same
|
|
14
|
+
// preserved exactly: same eight actions, same fourteen refusal codes, same required arguments. The
|
|
15
15
|
// mapping is asserted in test/plugin-test.mjs against the contract file, so "we project to one tool"
|
|
16
|
-
// cannot quietly become "we support
|
|
16
|
+
// cannot quietly become "we support seven actions". 0.5.0's three new actions went into the SAME one
|
|
17
|
+
// tool for the same reason the earlier five did: the token argument does not weaken when the surface
|
|
18
|
+
// grows.
|
|
17
19
|
//
|
|
18
20
|
// THE THREE THINGS THIS FILE MUST GET RIGHT, each of which would look like a working plugin while
|
|
19
21
|
// being wrong:
|
|
@@ -66,6 +68,9 @@ import { evaluateProof } from './proof-window.mjs';
|
|
|
66
68
|
* @property {boolean} keyInjectAllowed
|
|
67
69
|
* @property {number} takeoverMaxMs
|
|
68
70
|
* @property {number} takeoverArmMs
|
|
71
|
+
* @property {number} snapshotMaxElements
|
|
72
|
+
* @property {number} screenshotMaxWidth
|
|
73
|
+
* @property {number} shotsKeep
|
|
69
74
|
*/
|
|
70
75
|
|
|
71
76
|
/**
|
|
@@ -144,6 +149,12 @@ export function apply(ctx, config = {}) {
|
|
|
144
149
|
keyInjectAllowed: resolveSetting(config.keyInjectAllowed, false) === true,
|
|
145
150
|
takeoverMaxMs: clampNumber(resolveSetting(config.takeoverMaxMs, 10000), 500, 60000, 10000),
|
|
146
151
|
takeoverArmMs: clampNumber(resolveSetting(config.takeoverArmMs, 800), 0, 5000, 800),
|
|
152
|
+
// ---- 0.5.0 read-path settings. Forwarded, never silently clamped on the caller's behalf: the
|
|
153
|
+
// engine is the one that reports what it actually used (maxElements/shotsKeep ride back on the
|
|
154
|
+
// result), so "the setting took" is observable rather than assumed.
|
|
155
|
+
snapshotMaxElements: clampNumber(resolveSetting(config.snapshotMaxElements, 300), 1, 5000, 300),
|
|
156
|
+
screenshotMaxWidth: clampNumber(resolveSetting(config.screenshotMaxWidth, 0), 0, 7680, 0),
|
|
157
|
+
shotsKeep: clampNumber(resolveSetting(config.shotsKeep, 10), 1, 200, 10),
|
|
147
158
|
};
|
|
148
159
|
|
|
149
160
|
const logger = ctx.logger ?? console;
|
|
@@ -296,6 +307,41 @@ export function apply(ctx, config = {}) {
|
|
|
296
307
|
return { action: 'windows' };
|
|
297
308
|
case 'status':
|
|
298
309
|
return { action: 'status' };
|
|
310
|
+
case 'snapshot':
|
|
311
|
+
// A READ. maxElements is the SETTING unless the caller asked for a specific cap, and
|
|
312
|
+
// interactableOnly defaults ON because the frame exists to be decided on, not to be dumped.
|
|
313
|
+
requireArg(args, 'hwnd', 'snapshot');
|
|
314
|
+
return {
|
|
315
|
+
action: 'snapshot',
|
|
316
|
+
hwnd: args.hwnd,
|
|
317
|
+
maxElements: clampNumber(args.maxElements, 1, 5000, settings.snapshotMaxElements),
|
|
318
|
+
interactableOnly: args.interactableOnly !== false,
|
|
319
|
+
sinceSnapId: typeof args.sinceSnapId === 'string' ? args.sinceSnapId : '',
|
|
320
|
+
intent: typeof args.intent === 'string' ? args.intent : '',
|
|
321
|
+
};
|
|
322
|
+
case 'screenshot':
|
|
323
|
+
// fullScreen is the ONLY way to capture without naming a window, and it must be asked for:
|
|
324
|
+
// silently capturing the owner's whole desktop would be exactly the overreach this product
|
|
325
|
+
// refuses elsewhere. A non-fullscreen capture with no hwnd is refused here, before the worker.
|
|
326
|
+
if (args.fullScreen !== true) requireArg(args, 'hwnd', 'screenshot');
|
|
327
|
+
return {
|
|
328
|
+
action: 'screenshot',
|
|
329
|
+
hwnd: args.fullScreen === true ? (args.hwnd ?? '') : args.hwnd,
|
|
330
|
+
fullScreen: args.fullScreen === true,
|
|
331
|
+
maxWidth: clampNumber(args.maxWidth, 0, 7680, settings.screenshotMaxWidth),
|
|
332
|
+
shotsKeep: settings.shotsKeep,
|
|
333
|
+
};
|
|
334
|
+
case 'preview':
|
|
335
|
+
// Silent by construction: no click, no focus, no input queue entry. The engine draws the
|
|
336
|
+
// marker and answers with the element UNDER the point as text.
|
|
337
|
+
requireArg(args, 'hwnd', 'preview');
|
|
338
|
+
requireArg(args, 'x', 'preview');
|
|
339
|
+
requireArg(args, 'y', 'preview');
|
|
340
|
+
return {
|
|
341
|
+
action: 'preview', hwnd: args.hwnd,
|
|
342
|
+
x: Math.round(/** @type {number} */ (args.x)),
|
|
343
|
+
y: Math.round(/** @type {number} */ (args.y)),
|
|
344
|
+
};
|
|
299
345
|
case 'click':
|
|
300
346
|
requireArg(args, 'hwnd', 'click');
|
|
301
347
|
requireArg(args, 'x', 'click');
|
|
@@ -305,7 +351,23 @@ export function apply(ctx, config = {}) {
|
|
|
305
351
|
// thing that narrows them. A checker cannot see through a separate function's throw, so this
|
|
306
352
|
// is where the guarantee is recorded -- not a suppression, since requireArg throws for both
|
|
307
353
|
// undefined and null before this line is reached.
|
|
308
|
-
|
|
354
|
+
//
|
|
355
|
+
// THE COORDINATE SPACE IS EXPLICIT. 'image' without a shotId is refused HERE, before any worker
|
|
356
|
+
// request: image pixels only mean something relative to a capture, and reinterpreting them as
|
|
357
|
+
// screen pixels would click somewhere plausibly wrong -- the exact failure mode `stale_ref`
|
|
358
|
+
// exists for. A label rides along with its snapId so the engine can resolve the ELEMENT.
|
|
359
|
+
const space = args.space === 'image' ? 'image' : 'screen';
|
|
360
|
+
if (space === 'image' && (typeof args.shotId !== 'string' || args.shotId === '')) {
|
|
361
|
+
throw refusal('stale_ref', 'space:"image" needs the shotId of the screenshot whose pixels you are pointing at; no worker request was made and no coordinate was reinterpreted');
|
|
362
|
+
}
|
|
363
|
+
return {
|
|
364
|
+
action: 'click', hwnd: args.hwnd, x: Math.round(/** @type {number} */ (args.x)), y: Math.round(/** @type {number} */ (args.y)), settleMs,
|
|
365
|
+
...(space === 'image' ? { space: 'image', shotId: args.shotId } : {}),
|
|
366
|
+
...(typeof args.label === 'number' && args.label > 0
|
|
367
|
+
? { label: Math.round(args.label), snapId: typeof args.snapId === 'string' ? args.snapId : '' }
|
|
368
|
+
: {}),
|
|
369
|
+
...takeoverFields,
|
|
370
|
+
};
|
|
309
371
|
case 'type':
|
|
310
372
|
requireArg(args, 'hwnd', 'type');
|
|
311
373
|
if (typeof args.text !== 'string' || args.text.length === 0) {
|
|
@@ -315,12 +377,22 @@ export function apply(ctx, config = {}) {
|
|
|
315
377
|
}
|
|
316
378
|
return {
|
|
317
379
|
action: 'type', hwnd: args.hwnd, text: args.text,
|
|
318
|
-
elementName: args.elementName ?? '', replace: args.replace === true, settleMs,
|
|
380
|
+
elementName: args.elementName ?? '', replace: args.replace === true, settleMs,
|
|
381
|
+
...(typeof args.label === 'number' && args.label > 0
|
|
382
|
+
? { label: Math.round(args.label), snapId: typeof args.snapId === 'string' ? args.snapId : '' }
|
|
383
|
+
: {}),
|
|
384
|
+
...takeoverFields,
|
|
319
385
|
};
|
|
320
386
|
case 'focus':
|
|
321
387
|
requireArg(args, 'hwnd', 'focus');
|
|
322
|
-
requireArg(args, 'elementName', 'focus');
|
|
323
|
-
return {
|
|
388
|
+
if ((typeof args.label !== 'number' || args.label <= 0)) requireArg(args, 'elementName', 'focus');
|
|
389
|
+
return {
|
|
390
|
+
action: 'focus', hwnd: args.hwnd, elementName: args.elementName ?? '', settleMs,
|
|
391
|
+
...(typeof args.label === 'number' && args.label > 0
|
|
392
|
+
? { label: Math.round(args.label), snapId: typeof args.snapId === 'string' ? args.snapId : '' }
|
|
393
|
+
: {}),
|
|
394
|
+
...takeoverFields,
|
|
395
|
+
};
|
|
324
396
|
default:
|
|
325
397
|
throw refusal('no_hwnd', `unknown action '${args.action}'`);
|
|
326
398
|
}
|
|
@@ -338,11 +410,18 @@ export function apply(ctx, config = {}) {
|
|
|
338
410
|
+ 'and -- with keyInput:"inject" -- type into the foreground target through synthetic keyboard input '
|
|
339
411
|
+ 'for windows that have no message door and no accessible pattern (terminals). Takeover is refused '
|
|
340
412
|
+ 'unless the owner enabled it, always shows a three-phase HUD with a stop button and a global abort '
|
|
341
|
-
+ 'key, is interruptible three ways, and never injects mouse events.
|
|
342
|
-
+ '
|
|
343
|
-
+ '
|
|
344
|
-
+ '
|
|
345
|
-
+ '
|
|
413
|
+
+ 'key, is interruptible three ways, and never injects mouse events. '
|
|
414
|
+
+ 'THREE READ ACTIONS make the target legible without guessing: snapshot returns a NUMBERED element '
|
|
415
|
+
+ 'table (a continuous `label`, control type, name, automation id, rect, patterns) that click/type/'
|
|
416
|
+
+ 'focus accept as `label`+`snapId`; screenshot writes the window rect to a PNG and returns '
|
|
417
|
+
+ 'screenRect/imageSize/scale/identity/frame as data so image coordinates can be handed straight '
|
|
418
|
+
+ 'back to click with space:"image" (the engine converts, the caller never multiplies); preview '
|
|
419
|
+
+ 'draws the marker at a point and reports, as TEXT, the element under it -- a reviewable click that '
|
|
420
|
+
+ 'needs no picture. Refusals carry a code (no_hwnd, '
|
|
421
|
+
+ 'paused, elevated_target, unreachable, uia_tree_empty, uia_probe_failed, terminal_no_door, needs_facts, action_failed, '
|
|
422
|
+
+ 'restore_failed, takeover_unavailable, keyinject_unavailable, takeover_aborted, stale_ref) and a reason. '
|
|
423
|
+
+ 'Start with action=windows to get an hwnd, action=snapshot to read a frame, or action=status to see '
|
|
424
|
+
+ 'what currently holds the foreground.',
|
|
346
425
|
parameters: PARAMETERS,
|
|
347
426
|
output: {
|
|
348
427
|
schema: {
|
|
@@ -424,7 +503,12 @@ export function apply(ctx, config = {}) {
|
|
|
424
503
|
// letting a refusal start the overlay would mean a dead hwnd silently spawns a WPF window.
|
|
425
504
|
const r = envelope.result;
|
|
426
505
|
if (request.action === 'click' && r && r.ok !== false && !r.refusal) {
|
|
427
|
-
|
|
506
|
+
// With space:'image' the request coordinates are IMAGE pixels; the engine reports the screen
|
|
507
|
+
// point it actually converted to, and the marker must be drawn THERE. Drawing it at the image
|
|
508
|
+
// pixel would put the visible cursor somewhere other than where the click landed -- a marker
|
|
509
|
+
// that lies is worse than no marker, because the README sells it as the point that was acted on.
|
|
510
|
+
const screen = request.space === 'image' ? parsePoint(r.screenPoint) : null;
|
|
511
|
+
markPoint(screen ? screen.x : request.x, screen ? screen.y : request.y);
|
|
428
512
|
}
|
|
429
513
|
return format(args.action, envelope.result);
|
|
430
514
|
},
|
|
@@ -548,6 +632,11 @@ function format(action, r) {
|
|
|
548
632
|
bits.push(`pauseHotkey=${r.hotkeyRegistered === true ? (r.hotkeyLabel || 'registered') : 'unavailable'}`);
|
|
549
633
|
if (r.overlayReason) bits.push(`overlayNote=${r.overlayReason}`);
|
|
550
634
|
if (r.pauseReason) bits.push(`pauseReason=${r.pauseReason}`);
|
|
635
|
+
// The DPI stance is a FACT the read paths depend on: rects and captured pixels are physical only
|
|
636
|
+
// while this process is per-monitor DPI aware. Reporting it here is what keeps a future deletion of
|
|
637
|
+
// the setter from turning into a silent half-scale coordinate system (the marker already proved
|
|
638
|
+
// that failure mode: 470,410 acted on at 303,263 on this 150% display).
|
|
639
|
+
bits.push(`dpiAware=${r.dpiAware === true}`);
|
|
551
640
|
if (r.stance) bits.push(`stance: ${r.stance}`);
|
|
552
641
|
return result(action, true, '', bits.join('\n'));
|
|
553
642
|
}
|
|
@@ -572,6 +661,14 @@ function format(action, r) {
|
|
|
572
661
|
return result(action, false, code, `${code}${reason}`);
|
|
573
662
|
}
|
|
574
663
|
|
|
664
|
+
// ---- 0.5.0 READ RESULTS ---------------------------------------------------------------------
|
|
665
|
+
// These three have no channel, no tier and no proof window: there is no action to prove. Rendering
|
|
666
|
+
// happens HERE (not in the engine) for the same reason every other action's text does -- one place
|
|
667
|
+
// owns "what the model reads", and the engine stays a JSON protocol.
|
|
668
|
+
if (action === 'snapshot') return formatSnapshot(r);
|
|
669
|
+
if (action === 'screenshot') return formatScreenshot(r);
|
|
670
|
+
if (action === 'preview') return formatPreview(r);
|
|
671
|
+
|
|
575
672
|
// WHO REPORTED THE SUCCESS. The engine sets `effect` when a channel call RETURNS without throwing;
|
|
576
673
|
// this file never upgrades it, and the three values are not degrees of confidence in the app -- they
|
|
577
674
|
// name who is speaking (README's table states the same three lines, keep them in step):
|
|
@@ -638,6 +735,12 @@ function format(action, r) {
|
|
|
638
735
|
proof: proof.verdict,
|
|
639
736
|
proofDimensions: proof.dimensions,
|
|
640
737
|
effect: r.effect || 'unverified',
|
|
738
|
+
// A converted point travels back with the result so the caller can check the arithmetic it never
|
|
739
|
+
// performed. `screenPoint` is the fact the marker is drawn from, too: with space:'image' the
|
|
740
|
+
// request's own x/y are image pixels and would put the visible marker in the wrong place.
|
|
741
|
+
...(r.coordSpace === 'image'
|
|
742
|
+
? { coordSpace: 'image', shotId: r.shotId, imagePoint: r.imagePoint, screenPoint: r.screenPoint, scale: r.scale }
|
|
743
|
+
: {}),
|
|
641
744
|
...(r.takeover === 'true'
|
|
642
745
|
? { takeover: 'on', cursorRestored: r.cursorRestored === 'true', injectedChars: r.injectedChars ?? 0 }
|
|
643
746
|
: {}),
|
|
@@ -649,6 +752,161 @@ function truncate(s, n) {
|
|
|
649
752
|
return s.length <= n ? s : `${s.slice(0, n - 1)}…`;
|
|
650
753
|
}
|
|
651
754
|
|
|
755
|
+
/**
|
|
756
|
+
* One element row of a snapshot frame. The format is the contract the caller reasons on, so it is
|
|
757
|
+
* fixed here: `label ControlType "Name" [AutomationId] rect=l,t,r,b patterns=...`. The label is
|
|
758
|
+
* what a deciding side answers with; the rect is in PHYSICAL screen pixels, in the same space as
|
|
759
|
+
* screenRect, which is what makes `space:"image"` conversion possible without a second coordinate table.
|
|
760
|
+
* @param {any} e @returns {string}
|
|
761
|
+
*/
|
|
762
|
+
function elementLine(e) {
|
|
763
|
+
const rc = e?.rect ?? {};
|
|
764
|
+
const pats = Array.isArray(e?.patterns) ? e.patterns : [];
|
|
765
|
+
return `${e?.label ?? '?'} ${e?.controlType ?? '?'} "${e?.name ?? ''}" [${e?.automationId ?? ''}] `
|
|
766
|
+
+ `rect=${rc.left ?? '?'},${rc.top ?? '?'},${rc.right ?? '?'},${rc.bottom ?? '?'} `
|
|
767
|
+
+ `patterns=${pats.length ? pats.join('|') : 'none'}`;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* Render a snapshot frame.
|
|
772
|
+
*
|
|
773
|
+
* WHY THE DELTA IS A FIRST-CLASS FORM. Repeating an unchanged 70-row table between two steps is the
|
|
774
|
+
* dominant token cost of a multi-step flow, and it is pure noise: nothing in it changed. With
|
|
775
|
+
* `sinceSnapId` the answer is "no changes" plus the three lists that DID move. The full table stays
|
|
776
|
+
* available -- this is an option, not a replacement.
|
|
777
|
+
* @param {any} r @returns {Record<string, any>}
|
|
778
|
+
*/
|
|
779
|
+
function formatSnapshot(r) {
|
|
780
|
+
const rows = Array.isArray(r.elements) ? r.elements : [];
|
|
781
|
+
const count = Number.isFinite(r.count) ? Number(r.count) : rows.length;
|
|
782
|
+
const total = Number.isFinite(r.total) ? Number(r.total) : count;
|
|
783
|
+
const truncated = r.truncated === true || r.truncated === 'true';
|
|
784
|
+
const delta = r.delta && typeof r.delta === 'object' ? r.delta : null;
|
|
785
|
+
const added = Array.isArray(delta?.added) ? delta.added : [];
|
|
786
|
+
const removed = Array.isArray(delta?.removed) ? delta.removed : [];
|
|
787
|
+
const changed = Array.isArray(delta?.changed) ? delta.changed : [];
|
|
788
|
+
|
|
789
|
+
const head = `snapshot ok: ${count} element(s)`
|
|
790
|
+
+ (truncated ? ` (truncated at ${count} of ${total})` : '')
|
|
791
|
+
+ (delta ? ` (delta vs ${delta.sinceSnapId}: +${added.length} -${removed.length} ~${changed.length})` : '');
|
|
792
|
+
const meta = [`snapId=${r.snapId || '?'}`, `frame=${r.frame || '?'}`, `frameCheck=${r.frameCheck || '?'}`, `total=${total}`];
|
|
793
|
+
if (r.frameInset && typeof r.frameInset === 'object') {
|
|
794
|
+
meta.push(`frameInset=${r.frameInset.left ?? '?'},${r.frameInset.top ?? '?'},${r.frameInset.right ?? '?'},${r.frameInset.bottom ?? '?'}`);
|
|
795
|
+
}
|
|
796
|
+
if (Number.isFinite(r.outsideFrame) && Number(r.outsideFrame) > 0) {
|
|
797
|
+
meta.push(`outsideFrame=${r.outsideFrame}`);
|
|
798
|
+
}
|
|
799
|
+
if (r.intent) meta.push(`intent=${r.intent}`);
|
|
800
|
+
const lines = [head, meta.join(' ')];
|
|
801
|
+
|
|
802
|
+
if (delta) {
|
|
803
|
+
if (added.length === 0 && removed.length === 0 && changed.length === 0) {
|
|
804
|
+
lines.push(`no changes since ${delta.sinceSnapId}`);
|
|
805
|
+
} else {
|
|
806
|
+
for (const a of added) lines.push(` + ${elementLine(a)}`);
|
|
807
|
+
for (const m of removed) lines.push(` - ${elementLine(m)}`);
|
|
808
|
+
for (const c of changed) lines.push(` ~ ${elementLine(c)} changed=${(Array.isArray(c.changed) ? c.changed : []).join(',')}`);
|
|
809
|
+
}
|
|
810
|
+
} else if (count === 0) {
|
|
811
|
+
// A REAL ANSWER, said out loud. This deliberately does NOT reuse uia_tree_empty: that code means
|
|
812
|
+
// "UI Automation is switched off in the application" and its next step is relaunching the app.
|
|
813
|
+
// Zero visible elements on a window that answers fine (measured: Clash, Everything) has no such
|
|
814
|
+
// next step, so inventing one would be the canned message this product refuses.
|
|
815
|
+
lines.push('0 element(s) is a real state: this window exposes no visible element to UI Automation right now. '
|
|
816
|
+
+ 'It is not uia_tree_empty (that code is about the application disabling accessibility) and it is not a failure.');
|
|
817
|
+
} else {
|
|
818
|
+
for (const e of rows) lines.push(elementLine(e));
|
|
819
|
+
}
|
|
820
|
+
if (r.frame === 'win32') {
|
|
821
|
+
lines.push('note: frame=win32 -- DWM EXTENDED_FRAME_BOUNDS was unavailable, so this frame came from GetWindowRect and includes the invisible resize shadow. '
|
|
822
|
+
+ 'The frame check above passed (it compares the frame against the window rect the tree reports), but the capture and the labels are both 8px larger than the visible window edge.');
|
|
823
|
+
}
|
|
824
|
+
if (r.frameCheck === 'unknown') {
|
|
825
|
+
lines.push('note: frameCheck=unknown -- the accessibility tree would not report its root rect, so the frame could not be cross-checked. Labels are still in physical screen pixels; treat an edge-of-window label with suspicion.');
|
|
826
|
+
}
|
|
827
|
+
if (Number(r.outsideFrame) > 0) {
|
|
828
|
+
lines.push(`note: ${r.outsideFrame} element(s) were excluded because their rect does not overlap the captured frame; a label you cannot point at inside the capture would be a trap, so they are counted here instead of numbered.`);
|
|
829
|
+
}
|
|
830
|
+
return result('snapshot', true, '', lines.join('\n'), {
|
|
831
|
+
snapId: r.snapId, elements: rows, count, total, truncated, frameCheck: r.frameCheck, intent: r.intent ?? '',
|
|
832
|
+
// The delta travels structurally too: a caller that branches on "did anything move" must not have
|
|
833
|
+
// to parse the text, and the counts are the same numbers the head line prints.
|
|
834
|
+
...(delta ? { delta } : {}),
|
|
835
|
+
...(r.frameInset ? { frameInset: r.frameInset } : {}),
|
|
836
|
+
...(Number.isFinite(r.outsideFrame) ? { outsideFrame: Number(r.outsideFrame) } : {}),
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Render a screenshot: the mapping is the product, the file is the delivery.
|
|
842
|
+
* @param {any} r @returns {Record<string, any>}
|
|
843
|
+
*/
|
|
844
|
+
function formatScreenshot(r) {
|
|
845
|
+
const rect = r.screenRect && typeof r.screenRect === 'object' ? r.screenRect : {};
|
|
846
|
+
const size = r.imageSize && typeof r.imageSize === 'object' ? r.imageSize : {};
|
|
847
|
+
const scale = typeof r.scale === 'number' ? r.scale : 1;
|
|
848
|
+
const identity = r.identity === true || r.identity === 'true';
|
|
849
|
+
const dpiAware = r.dpiAware === true || r.dpiAware === 'true';
|
|
850
|
+
const lines = [
|
|
851
|
+
`screenshot ok: ${size.width ?? '?'}x${size.height ?? '?'} px (scale=${scale} identity=${identity}) frame=${r.frame || '?'} dpiAware=${dpiAware}`,
|
|
852
|
+
`file=${r.file || '?'}`,
|
|
853
|
+
`shotId=${r.shotId || '?'}`,
|
|
854
|
+
`screenRect=${rect.left ?? '?'},${rect.top ?? '?'},${rect.right ?? '?'},${rect.bottom ?? '?'} `
|
|
855
|
+
+ `imageSize=${size.width ?? '?'}x${size.height ?? '?'} bytes=${r.bytes ?? '?'} shotsKeep=${r.shotsKeep ?? '?'} latencyMs=${r.latencyMs ?? '?'}`,
|
|
856
|
+
'mapping: screenX = screenRect.left + round(imageX / scale); screenY = screenRect.top + round(imageY / scale). '
|
|
857
|
+
+ `The ENGINE applies this when a click passes space:"image" with shotId=${r.shotId || '?'}; do not multiply it yourself.`,
|
|
858
|
+
];
|
|
859
|
+
if (identity) {
|
|
860
|
+
lines.push('identity=true means the image was NOT resampled: image pixels and screen pixels differ only by the rect origin.');
|
|
861
|
+
}
|
|
862
|
+
if (r.frame === 'win32') {
|
|
863
|
+
lines.push('note: frame=win32 -- DWM EXTENDED_FRAME_BOUNDS was unavailable, so screenRect came from GetWindowRect and includes the invisible shadow. '
|
|
864
|
+
+ 'Coordinates stay consistent with THIS capture, but a click at the very edge can land on the shadow rather than the client area.');
|
|
865
|
+
}
|
|
866
|
+
return result('screenshot', true, '', lines.join('\n'), {
|
|
867
|
+
shotId: r.shotId, file: r.file, screenRect: rect, imageSize: size,
|
|
868
|
+
scale, identity, frame: r.frame, dpiAware,
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Render a preview. The report is text on purpose: "what is under that point" is answered by the OS,
|
|
874
|
+
* so confirming a point never depends on the model's reading of a picture.
|
|
875
|
+
* @param {any} r @returns {Record<string, any>}
|
|
876
|
+
*/
|
|
877
|
+
function formatPreview(r) {
|
|
878
|
+
const x = r.previewX ?? '?';
|
|
879
|
+
const y = r.previewY ?? '?';
|
|
880
|
+
const atPoint = r.previewAtPoint === true || r.previewAtPoint === 'true';
|
|
881
|
+
const head = atPoint && r.previewControlType
|
|
882
|
+
? `preview: would click ${x},${y} -> ${r.previewControlType} "${r.previewName || ''}"`
|
|
883
|
+
+ (r.previewAutomationId ? ` [${r.previewAutomationId}]` : '')
|
|
884
|
+
: `preview: would click ${x},${y} -> no element is exposed at that point`;
|
|
885
|
+
const rect = r.previewRect && typeof r.previewRect === 'object' ? r.previewRect : {};
|
|
886
|
+
const lines = [
|
|
887
|
+
head,
|
|
888
|
+
`rect=${rect.left ?? '?'},${rect.top ?? '?'},${rect.right ?? '?'},${rect.bottom ?? '?'}`,
|
|
889
|
+
`marker=${r.markerPlaced === true || r.markerPlaced === 'true' ? 'placed' : 'unavailable'}${r.markerReason ? ` (${r.markerReason})` : ''}`,
|
|
890
|
+
];
|
|
891
|
+
if (r.previewReason) lines.push(`reason: ${r.previewReason}`);
|
|
892
|
+
lines.push('no click was sent: a preview writes no input-queue entry, takes no focus, and produces no proof window');
|
|
893
|
+
return result('preview', true, '', lines.join('\n'), {
|
|
894
|
+
preview: {
|
|
895
|
+
x, y,
|
|
896
|
+
name: r.previewName ?? '', controlType: r.previewControlType ?? '', automationId: r.previewAutomationId ?? '',
|
|
897
|
+
},
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/** Parse an engine-emitted "x,y" point. Returns null for anything else rather than guessing 0,0. */
|
|
902
|
+
/** @param {any} s @returns {{x: number, y: number}|null} */
|
|
903
|
+
function parsePoint(s) {
|
|
904
|
+
if (typeof s !== 'string') return null;
|
|
905
|
+
const m = s.match(/^(-?\d+),(-?\d+)$/);
|
|
906
|
+
if (!m) return null;
|
|
907
|
+
return { x: Number(m[1]), y: Number(m[2]) };
|
|
908
|
+
}
|
|
909
|
+
|
|
652
910
|
/** Clamp a possibly-undefined number into [min,max], falling back to `fallback` for non-numbers. */
|
|
653
911
|
/** @param {any} value @param {number} min @param {number} max @param {number} fallback @returns {number} */
|
|
654
912
|
function clampNumber(value, min, max, fallback) {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-windows-parallel-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"tag": "latest",
|
|
7
7
|
"registry": "https://registry.npmjs.org/"
|
|
8
8
|
},
|
|
9
|
-
"description": "Drive a Windows window quietly by default and visibly on request: one tool,
|
|
9
|
+
"description": "Drive a Windows window quietly by default and visibly on request: one tool, eight actions (windows, status, click, type, focus, snapshot, screenshot, preview), a channel decision table that prefers the quiet door, a bounded self-reversing focus flash when only UI Automation can reach the control, an opt-in takeover tier (HUD mandatory, cursor always restored, keyboard injection only when asked and only for the foreground target), and a read surface that hands the model a numbered element frame plus screenshot coordinates as data so it never multiplies a scale factor. Windows PowerShell 5.1 sidecar, zero install dependencies, no mouse injection.",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"deepseek",
|
|
12
12
|
"deepseek-harness",
|
|
@@ -31,7 +31,10 @@
|
|
|
31
31
|
"main": "lib/index.js",
|
|
32
32
|
"types": "types/index.d.ts",
|
|
33
33
|
"exports": {
|
|
34
|
-
".": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./types/index.d.ts",
|
|
36
|
+
"default": "./lib/index.js"
|
|
37
|
+
},
|
|
35
38
|
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
36
39
|
"./dsh.plugin.json": "./dsh.plugin.json",
|
|
37
40
|
"./src/engine/*": "./src/engine/*",
|