dsh-windows-parallel-mcp 0.6.0 → 0.8.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/dsh.plugin.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-windows-parallel-mcp",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "main": "./lib/index.js",
5
- "description": "One tool, eight actions: drive a Windows window quietly by default, and read the target as a numbered element frame. Prefers window messages (zero foreground change); falls back to UI Automation with a bounded, self-reversing focus flash (measured net return 15-95 ms); offers an opt-in takeover tier (takeoverAllowed) where the cursor moves to the action point and is always restored, with a mandatory three-phase HUD and three interruption paths; adds snapshot/screenshot/preview, where labels address the UIA element itself and image coordinates are converted by the engine; and since 0.6.0 reads a write back -- effect=readback-verified only when the field's own value matches a prediction built from the control's measurements -- with caretPosition, disabled/focus reporting, and a BitBlt capture path named in every screenshot as captureBackend.",
5
+ "description": "One tool, eleven actions: drive a Windows window quietly by default, read the target as a numbered element frame, and since 0.7.0 start a whitelisted program, touch the clipboard, and change one named window. Prefers window messages (zero foreground change); falls back to UI Automation with a bounded, self-reversing focus flash (measured net return 15-95 ms); offers an opt-in takeover tier (policy:'full' AND takeoverAllowed) where the cursor moves to the action point and is always restored, with a mandatory three-phase HUD and three interruption paths; adds snapshot/screenshot/preview, where labels address the UIA element itself and image coordinates are converted by the engine; reads a write back (effect=readback-verified only when the field's own value matches a prediction built from the control's measurements) with caretPosition, disabled/focus reporting and a BitBlt capture path named as captureBackend; and gates everything through one ceiling (policy) plus a per-program launch whitelist, an idle check that refuses instead of interrupting, and an append-only JSONL audit log.",
6
6
  "engines": {
7
7
  "dsh": ">=0.1.7-0 <0.3.0-0"
8
8
  },
@@ -10,7 +10,7 @@
10
10
  "tools": [
11
11
  {
12
12
  "name": "wpm",
13
- "description": "Drive a Windows window quietly by default (actions: windows, status, click, type, focus, snapshot, screenshot, preview), with an opt-in takeover tier that is visible, interruptible and always restores the cursor, and a read surface whose numbered labels address the element itself."
13
+ "description": "Drive a Windows window quietly by default through eleven actions (windows, status, click, type, focus, snapshot, screenshot, preview, launch, clipboard, window), with an opt-in takeover tier that is visible, interruptible and always restores the cursor, a read surface whose numbered labels address the element itself, and a read-back that only grants effect=readback-verified when the field's own value agrees. Everything sits under one policy ceiling and every call, allowed or refused, leaves one audit row. The same engine is also reachable as an MCP stdio server (bin: wpm-mcp)."
14
14
  }
15
15
  ],
16
16
  "skills": []
package/lib/audit.js ADDED
@@ -0,0 +1,109 @@
1
+ // audit.js -- one JSONL line per action, appended to %LOCALAPPDATA%\wpm\audit.log.
2
+ //
3
+ // WHY THIS EXISTS AT ALL. Every other field in this product answers "what did the caller get back".
4
+ // None of them answers the question that is asked AFTER something went wrong, at 3 a.m., by someone who
5
+ // needs to know what the agent did to this machine and when: `policy_denied` is visible to the caller
6
+ // and gone a second later. This file is the only artifact that survives the call, and per the plan it is
7
+ // written for ALLOW as well as DENY -- an audit trail that only records refusals documents the times the
8
+ // guard worked and is silent about the times it didn't have to.
9
+ //
10
+ // WHAT IS DELIBERATELY NOT HERE, because an audit log is a copy of what it records:
11
+ // * clipboard CONTENT -- op, format and character count only (R8: the clipboard may hold a token);
12
+ // * typed text -- its LENGTH, never its value, for the same reason;
13
+ // * anything else that is content rather than a decision.
14
+ // The line is a decision record: who asked, what was permitted, what tier it cost, what the engine
15
+ // reported. That is enough to reconstruct an incident and not enough to leak one.
16
+ //
17
+ // BEST-EFFORT WRITE, VISIBLE FAILURE. An audit that can throw would turn a successful action into a
18
+ // failed one -- so failures are counted and reported in the result text (`auditNote=...`) rather than
19
+ // raised. Silently swallowing a broken audit is the exact opposite of what this file is for.
20
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
21
+ import { dirname, join } from 'node:path';
22
+ import { homedir, tmpdir } from 'node:os';
23
+
24
+ /** The same base the engine uses (win.ps1 Get-WpmDataDir) -- one directory to open when reviewing. */
25
+ export function auditDir() {
26
+ const base = process.env.LOCALAPPDATA || join(homedir() || tmpdir(), 'AppData', 'Local');
27
+ return join(base, 'wpm');
28
+ }
29
+ export function auditPath() { return join(auditDir(), 'audit.log'); }
30
+
31
+ /**
32
+ * Build the line. Kept separate from the write so a test can assert the SHAPE without touching the disk,
33
+ * and so the "never content" rule is one function deep rather than a habit.
34
+ * @param {{ts?:number, action:string, hwnd?:string, tier?:string, policy?:string,
35
+ * decision:string, code?:string, userActiveAgeMs?:number, effect?:string, latencyMs?:number,
36
+ * detail?:string, target?:string, args?:string, op?:string, format?:string, chars?:number,
37
+ * resultChars?:number, forced?:boolean}} rec
38
+ * @returns {string} one JSON object, no newline
39
+ */
40
+ export function auditLine(rec) {
41
+ // Built as an open record because the shape is CONDITIONAL by design: a launch line carries target and
42
+ // arguments, a clipboard line carries op/format/length, and an ordinary action carries neither. A
43
+ // closed literal would force every line to carry every field (and so to record a clipboard `text` it is
44
+ // not allowed to record) or force a cast per branch -- which is exactly how a "not here"
45
+ // privacy rule becomes a "here, because the type said so" leak.
46
+ /** @type {Record<string, any>} */
47
+ const out = {
48
+ ts: rec.ts ?? Date.now(),
49
+ action: String(rec.action ?? ''),
50
+ hwnd: String(rec.hwnd ?? ''),
51
+ tier: String(rec.tier ?? ''),
52
+ policy: String(rec.policy ?? ''),
53
+ // decision is one of 'allow' | 'deny'. `code` is the refusal code when it is a deny, empty when it
54
+ // is an allow -- and it is recorded for BOTH so a reader can sort by outcome instead of guessing
55
+ // from a missing field.
56
+ decision: rec.decision === 'deny' ? 'deny' : 'allow',
57
+ code: String(rec.code ?? ''),
58
+ userActiveAgeMs: Number.isFinite(rec.userActiveAgeMs) ? rec.userActiveAgeMs : -1,
59
+ effect: String(rec.effect ?? ''),
60
+ latencyMs: Number.isFinite(rec.latencyMs) ? rec.latencyMs : -1,
61
+ };
62
+ if (rec.target !== undefined) out.target = String(rec.target);
63
+ if (rec.args !== undefined) out.args = String(rec.args);
64
+ if (rec.op !== undefined) out.op = String(rec.op);
65
+ if (rec.format !== undefined) out.format = String(rec.format);
66
+ // Length, never payload. The field name says which, so a reader of the log cannot mistake `chars`
67
+ // for content and neither can a reviewer of this line.
68
+ if (rec.chars !== undefined) out.chars = Number(rec.chars);
69
+ if (rec.forced === true) out.forced = true;
70
+ if (rec.detail) out.detail = String(rec.detail);
71
+ return JSON.stringify(out);
72
+ }
73
+
74
+ /**
75
+ * Append one decision, then keep the file bounded. The prune rewrites the file (read last N lines,
76
+ * write, swap), which is the same newest-first discipline the screenshot retention uses -- a log that
77
+ * grows without bound is a disk problem that arrives at the worst possible moment, and a truncation that
78
+ * drops the NEWEST lines instead of the oldest is a cover-up.
79
+ * @param {string} line @param {{keep?:number}} [opts]
80
+ * @returns {{ok:boolean, wrote:boolean, error?:string}}
81
+ */
82
+ export function auditWrite(line, opts = {}) {
83
+ const keep = Math.max(1, Math.min(200000, opts.keep ?? 2000));
84
+ try {
85
+ const path = auditPath();
86
+ if (!existsSync(dirname(path))) mkdirSync(dirname(path), { recursive: true });
87
+ appendFileSync(path, line + '\n', 'utf8');
88
+ // Prune only when the file is plausibly over budget: a line count on every action would read the
89
+ // whole log each time, and an audit must never become the slow part of a click.
90
+ let lines = 0;
91
+ try {
92
+ const buf = readFileSync(path, 'utf8');
93
+ lines = buf.split('\n').filter((l) => l !== '').length;
94
+ } catch { lines = 0; }
95
+ if (lines > keep * 1.25 || lines > keep + 500) {
96
+ const tail = readFileSync(path, 'utf8').split('\n').filter((l) => l !== '').slice(-keep);
97
+ const tmp = path + '.new';
98
+ writeFileSync(tmp, tail.join('\n') + '\n', 'utf8');
99
+ try { renameSync(tmp, path); } catch { }
100
+ }
101
+ return { ok: true, wrote: true };
102
+ } catch (err) {
103
+ // `catch` binds `unknown` under checkJs+strict, so the message is reached through a type test rather
104
+ // than a cast: an audit failure that itself threw on the way out would be a worse bug than the one it
105
+ // is meant to make visible.
106
+ const message = err && typeof err === 'object' && 'message' in err ? String(/** @type {{message?: string}} */ (err).message) : String(err);
107
+ return { ok: false, wrote: false, error: message };
108
+ }
109
+ }
package/lib/config.js CHANGED
@@ -21,11 +21,13 @@
21
21
  // from the bundle patch. That limitation is stated in the README rather than papered over.
22
22
 
23
23
  /**
24
- * One declarable setting. `type` is a closed string union rather than a string so the three-way
24
+ * One declarable setting. `type` is a closed string union rather than a string so the four-way
25
25
  * branch in both validators is checked as exhaustive by the reader, not just by the shim at runtime.
26
+ * `string[]` exists for one reason: `appLaunchAllow` is a whitelist, and a whitelist that has to be
27
+ * spelled inside a string is a whitelist that will be parsed differently by two readers.
26
28
  * @typedef {object} ConfigField
27
29
  * @property {string} key
28
- * @property {'boolean'|'number'|'string'} type
30
+ * @property {'boolean'|'number'|'string'|'string[]'} type
29
31
  * @property {any} default
30
32
  * @property {number} [min]
31
33
  * @property {number} [max]
@@ -82,6 +84,35 @@ const FIELDS = [
82
84
  description: 'How many screenshot PNGs stay in %LOCALAPPDATA%\\wpm\\shots. Older files are deleted '
83
85
  + 'after each capture, so the directory cannot grow without bound; a shotId that was cleaned up '
84
86
  + 'is refused with stale_ref rather than reinterpreted.' },
87
+ // ---- 0.7.0 desktop actions. `launch` is the one action in this product that can run arbitrary code,
88
+ // so it gets its OWN gate rather than riding on takeoverAllowed, and it gets a whitelist rather than a
89
+ // denylist: a denylist is wrong the first time someone adds a program (spec 0.7.0-A). Both default to
90
+ // "nothing may launch", which means an upgrade cannot start spawning processes on its own, and the
91
+ // whitelist is matched EXACTLY (case-insensitive, no wildcards, no prefixes) because `notepad` matching
92
+ // `notepad-helper.exe` by prefix is the shape of a whitelist that authorises more than it says.
93
+ { key: 'appLaunchAllowed', type: 'boolean', default: false, volatile: true,
94
+ description: 'Allow action=launch at all. Off by default; when off, a launch is refused with '
95
+ + 'app_launch_denied before any worker request is made. This gate is independent of '
96
+ + 'takeoverAllowed: being allowed to move a cursor is not being allowed to start a program.' },
97
+ { key: 'appLaunchAllow', type: 'string[]', default: [], volatile: true,
98
+ description: 'The launch whitelist: exact program names or absolute exe paths, matched '
99
+ + 'case-insensitively and in full. An EMPTY list means nothing may launch even when '
100
+ + 'appLaunchAllowed is on -- the two switches are deliberately not one.' },
101
+ // ---- 0.7.0 authorization model. TWO AXES, deliberately not one enum per action: the action declares
102
+ // the minimum tier it can need (src/schema/tools.json#requiresTier), and this setting says how far the
103
+ // plugin may go. Eleven actions times one knob stays readable; eleven knobs would not.
104
+ { key: 'policy', type: 'string', default: 'balanced', volatile: true,
105
+ description: 'How far an action may go without asking again: readonly (reads only -- snapshot, '
106
+ + 'screenshot, preview, status, windows, clipboard read), quiet (adds click/type/focus through the '
107
+ + 'message door), balanced (default: adds the bounded-flash tier, clipboard writes and window ops), '
108
+ + 'full (adds takeover and launch). Anything above the level is refused with policy_denied, whose '
109
+ + 'next step is to raise this setting -- not to retry. An unrecognizable value falls back to '
110
+ + 'balanced, never to full.' },
111
+ { key: 'policyIdleMs', type: 'number', default: 3000, min: 0, max: 60000, volatile: true,
112
+ description: 'Idle sensing: how recently a PHYSICAL input must have happened for the owner to count '
113
+ + 'as "present". An action that needs the takeover tier while the owner is present is refused with '
114
+ + 'user_active and NO dialog -- a popup that interrupts someone who is typing is not consent, it is '
115
+ + 'a second disturbance. 0 disables the check. Measured input age already travels with status.' },
85
116
  ];
86
117
 
87
118
  /** Defaults, for documentation and for tests that must not depend on a resolver. */
@@ -116,6 +147,27 @@ function validateWithShim(raw) {
116
147
  } else {
117
148
  value[field.key] = given;
118
149
  }
150
+ } else if (field.type === 'string[]') {
151
+ // An array is validated element-wise, and a non-array is an ISSUE rather than a coercion: the
152
+ // bundle patch is YAML, and `appLaunchAllow: notepad` (a bare string) is the single most likely
153
+ // way someone will write a one-entry whitelist. Accepting it silently would make the setting work
154
+ // today and break the moment a second entry is added as a list.
155
+ if (!Array.isArray(given)) {
156
+ issues.push({ message: 'expected an array of strings', path: [field.key] });
157
+ } else if (given.some((x) => typeof x !== 'string')) {
158
+ issues.push({ message: 'expected every entry to be a string', path: [field.key] });
159
+ } else {
160
+ value[field.key] = given.map((x) => x.trim()).filter((x) => x !== '');
161
+ }
162
+ } else if (field.key === 'policy') {
163
+ // A closed set, checked where the settings are parsed rather than at the decision site: a policy
164
+ // that silently reads as an unknown level is the same class of bug as a level the table does not
165
+ // know how to compare.
166
+ if (!['readonly', 'quiet', 'balanced', 'full'].includes(given)) {
167
+ issues.push({ message: 'expected readonly|quiet|balanced|full', path: [field.key] });
168
+ } else {
169
+ value[field.key] = given;
170
+ }
119
171
  } else if (typeof given !== 'string') {
120
172
  issues.push({ message: `expected a string`, path: [field.key] });
121
173
  } else {
@@ -161,6 +213,7 @@ export async function createConfigSchema() {
161
213
  let s;
162
214
  if (field.type === 'boolean') s = z.boolean();
163
215
  else if (field.type === 'number') s = z.number();
216
+ else if (field.type === 'string[]') s = z.array(z.string());
164
217
  else s = z.string();
165
218
  if (field.min !== undefined || field.max !== undefined) {
166
219
  if (typeof s.min === 'function' && field.min !== undefined) s = s.min(field.min);
package/lib/host-tools.js CHANGED
@@ -18,8 +18,9 @@
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 eight actions, in the order the contract lists them. */
22
- export const ACTIONS = ['windows', 'click', 'type', 'focus', 'status', 'snapshot', 'screenshot', 'preview'];
21
+ /** The eleven actions, in the order the contract lists them. */
22
+ export const ACTIONS = ['windows', 'click', 'type', 'focus', 'status', 'snapshot', 'screenshot', 'preview',
23
+ 'launch', 'clipboard', 'window'];
23
24
 
24
25
  /**
25
26
  * One field of the simplified parameter spec -- the shape the host's `defineTool` consumes and the
@@ -57,7 +58,12 @@ export const PARAMETERS = {
57
58
  + 'focus: move keyboard focus to a named control inside the target. '
58
59
  + 'snapshot: read the accessibility tree as a numbered element table (labels you can act on). '
59
60
  + '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.',
61
+ + 'preview: draw the marker at a point and report the element under it, without clicking. '
62
+ + 'launch: start a program by name or path (needs appLaunchAllowed AND an exact whitelist entry; '
63
+ + 'refused with app_launch_denied before any worker call otherwise). '
64
+ + 'clipboard: read or write the system clipboard (read reports lengths, never contents). '
65
+ + 'window: minimize/restore/move/resize/topmost ONE window named by hwnd, verified by reading its '
66
+ + 'real state back.',
61
67
  },
62
68
  hwnd: {
63
69
  type: 'string',
@@ -169,6 +175,58 @@ export const PARAMETERS = {
169
175
  type: 'number',
170
176
  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.',
171
177
  },
178
+ // ---- 0.7.0 desktop actions -----------------------------------------------------------------
179
+ // Every description states the gate it falls under, because these three are the first actions whose
180
+ // refusal is about a SETTING rather than about the target, and a caller that cannot see which gate
181
+ // blocked it will retry forever.
182
+ target: {
183
+ type: 'string',
184
+ description:
185
+ 'launch only: the program to start -- an exact name on the appLaunchAllow whitelist ("notepad") or an '
186
+ + 'absolute exe path that appears in the list verbatim. Matched case-insensitively and IN FULL: '
187
+ + '"notepad" does not authorise "notepad-helper.exe", and no wildcard exists. Refused with '
188
+ + 'app_launch_denied when appLaunchAllowed is off or the name is not listed, before any worker request.',
189
+ },
190
+ args: {
191
+ type: 'string',
192
+ description:
193
+ 'launch only: one command line for the program, passed through as given. It is NOT parsed by the '
194
+ + 'whitelist -- listing a program does not vouch for its arguments, which is why every launch is '
195
+ + 'written to the audit log with its arguments attached.',
196
+ },
197
+ waitMs: {
198
+ type: 'number',
199
+ description: 'launch only: how long to wait for the started process to publish a top-level window (0-30000, default 3000). A window that has not appeared answers ok:true with hwnd="" and detail=window-not-yet -- the program DID start, and pretending otherwise would be a different lie.',
200
+ },
201
+ op: {
202
+ type: 'string',
203
+ enum: ['read', 'write', 'minimize', 'restore', 'move', 'resize', 'topmost'],
204
+ description:
205
+ 'clipboard: "read" or "write". window: "minimize", "restore", "move", "resize", "topmost". Each op is ' +
206
+ 'verified by reading the window back (IsIconic / the rect / the ex-style), not by the call\'s return ' +
207
+ 'value, so a syscall that said yes while the window said no is reported as verified=false.',
208
+ },
209
+ format: {
210
+ type: 'string',
211
+ enum: ['text', 'image'],
212
+ description: 'clipboard only (default text). "image" read returns a PNG under %LOCALAPPDATA%\\wpm\\clipboard and reports its size; "image" write takes a shotId from action=screenshot. Text reads are capped at 64 KB and a longer payload says truncated.',
213
+ },
214
+ width: { type: 'number', description: 'window only: the width to resize to (resize). The result reports what the window actually became, which may be a clamp.' },
215
+ height: { type: 'number', description: 'window only: the height to resize to (resize).' },
216
+ // ---- 0.7.0 the escape hatch on the idle check ------------------------------------------------
217
+ // It exists because an unattended run is the case that MUST still work, and because a caller that is
218
+ // blocked with no way forward will simply look for a way around the plugin. Making the override an
219
+ // explicit argument rather than a hidden retry keeps it visible: it is written to the audit log with
220
+ // forced=true, so a run that typed over someone's keyboard is attributable afterwards.
221
+ forceUserActive: {
222
+ type: 'boolean',
223
+ description:
224
+ 'Override the idle check (user_active) for THIS call: "start it even though the owner is at the keyboard". '
225
+ + 'Has an effect only on actions that need the takeover tier (takeover:true, keyInput:"inject", launch). '
226
+ + 'It does NOT bypass policy, takeoverAllowed, keyInjectAllowed or the launch whitelist, and the audit '
227
+ + 'line records forced:true, so an interruption you caused on purpose stays distinguishable from one '
228
+ + 'the plugin caused by accident.',
229
+ },
172
230
  };
173
231
 
174
232
  /**