dsh-windows-parallel-mcp 0.8.2 → 0.9.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.de.md +444 -419
  2. package/CHANGELOG.es.md +444 -419
  3. package/CHANGELOG.fr.md +444 -419
  4. package/CHANGELOG.it.md +444 -419
  5. package/CHANGELOG.ja.md +444 -419
  6. package/CHANGELOG.ko.md +444 -419
  7. package/CHANGELOG.md +965 -940
  8. package/CHANGELOG.pt.md +444 -419
  9. package/CHANGELOG.ru.md +444 -419
  10. package/CHANGELOG.zh.md +444 -419
  11. package/INSTALL.de.md +126 -126
  12. package/INSTALL.es.md +126 -126
  13. package/INSTALL.fr.md +126 -126
  14. package/INSTALL.it.md +126 -126
  15. package/INSTALL.ja.md +126 -126
  16. package/INSTALL.ko.md +126 -126
  17. package/INSTALL.md +122 -122
  18. package/INSTALL.pt.md +126 -126
  19. package/INSTALL.ru.md +126 -126
  20. package/INSTALL.zh.md +126 -126
  21. package/README.de.md +684 -684
  22. package/README.es.md +684 -684
  23. package/README.fr.md +684 -684
  24. package/README.it.md +684 -684
  25. package/README.ja.md +684 -684
  26. package/README.ko.md +684 -684
  27. package/README.md +680 -680
  28. package/README.pt.md +684 -684
  29. package/README.ru.md +684 -684
  30. package/README.zh.md +684 -684
  31. package/cordis.patch.yml +15 -15
  32. package/docs/refusals.md +90 -90
  33. package/docs/takeover.md +128 -128
  34. package/dsh.plugin.json +18 -18
  35. package/lib/config.js +275 -275
  36. package/lib/engine.js +252 -252
  37. package/lib/host-tools.js +365 -338
  38. package/lib/index.js +1275 -1249
  39. package/lib/peers-schemastery.js +23 -23
  40. package/lib/peers-tools.js +15 -15
  41. package/lib/proof-window.mjs +427 -427
  42. package/package.json +122 -122
  43. package/server.json +110 -110
  44. package/src/engine/decide.ps1 +356 -356
  45. package/src/engine/engine.ps1 +1208 -1208
  46. package/src/engine/hud.ps1 +411 -411
  47. package/src/engine/input-inject.ps1 +176 -176
  48. package/src/engine/overlay.ps1 +389 -389
  49. package/src/engine/takeover.ps1 +144 -144
  50. package/src/engine/win.ps1 +1881 -1881
  51. package/src/engine/worker.ps1 +310 -310
  52. package/src/schema/tools.json +533 -533
  53. package/types/index.d.ts +190 -187
package/lib/config.js CHANGED
@@ -1,275 +1,275 @@
1
- // config.js — the settings surface, built on the host's schema library when it is reachable and on a
2
- // standard-schema shim when it is not.
3
- //
4
- // WHY THIS FILE EXISTS AT ALL. The first version exported `Config` as a factory function. Cordis
5
- // requires a *standard-schema value* — it calls `Config['~standard'].validate(config)` — so the
6
- // plugin failed to activate with `Cannot read properties of undefined (reading 'validate')`, and the
7
- // only reason it was found is that the profile was actually booted (`dsh --profile wpm-dev headless`)
8
- // instead of being assumed good from a passing unit test. A plugin that never activates is the worst
9
- // failure mode available: it registers no tool, prints one warning into a busy log, and looks
10
- // installed.
11
- //
12
- // WHY NOT A HARD DEPENDENCY. `@deepseek-ai/schemastery` is a host-provided peer. Declaring it as a
13
- // dependency would drag a second copy of the schema library into the profile, and declaring it as a
14
- // peer would make install fail wherever the host resolves peers differently than it does here. So the
15
- // import is attempted, and the shim is the documented fallback.
16
- //
17
- // WHAT THE SHIM IS. A standard-schema implementation over a flat, explicitly typed field list. It
18
- // applies defaults, rejects wrong types and out-of-range values, and reports issues in the shape
19
- // Cordis renders. It is NOT schemastery: the settings FORM is rendered from schemastery's field
20
- // metadata, so a host that cannot resolve schemastery gives the user no form — the values still work
21
- // from the bundle patch. That limitation is stated in the README rather than papered over.
22
-
23
- /**
24
- * One declarable setting. `type` is a closed string union rather than a string so the four-way
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.
28
- * @typedef {object} ConfigField
29
- * @property {string} key
30
- * @property {'boolean'|'number'|'string'|'string[]'} type
31
- * @property {any} default
32
- * @property {number} [min]
33
- * @property {number} [max]
34
- * @property {boolean} [volatile]
35
- * @property {string} [description]
36
- */
37
-
38
- /** @type {ConfigField[]} */
39
- const FIELDS = [
40
- { key: 'enabled', type: 'boolean', default: true, volatile: true,
41
- description: 'Master switch. When off, every action refuses with `paused` before the engine is reached.' },
42
- { key: 'settleMs', type: 'number', default: 350, min: 0, max: 2000, volatile: true,
43
- description: 'How long the target app gets to commit its state before the effect is judged.' },
44
- { key: 'requestTimeoutMs', type: 'number', default: 20000, min: 1000, max: 600000,
45
- description: 'A worker that stops answering is killed and restarted on the next call.' },
46
- { key: 'powershellPath', type: 'string', default: '',
47
- description: 'Override the PowerShell executable. Windows PowerShell 5.1 is the floor; pwsh is accepted.' },
48
- { key: 'overlay', type: 'boolean', default: true, volatile: true,
49
- description: 'Show the click-through AI marker at the point each action touched. It never takes '
50
- + 'the foreground and never intercepts a click (measured). The first action pays a one-time '
51
- + 'worker round-trip while the overlay starts; after that a placement costs ~19ms and does not '
52
- + 'gate the action result.' },
53
- { key: 'logWorkerStderr', type: 'boolean', default: false, volatile: true,
54
- description: 'Forward the sidecar’s stderr diagnostics to the host log.' },
55
- // ---- R3 gates. BOTH DEFAULT OFF, and that is a product decision, not timidity: with them off the
56
- // tool behaves exactly like 0.1.6 (zero physical input), so an upgrade cannot silently start moving
57
- // the owner's cursor. Turning takeover on is the owner's explicit act.
58
- { key: 'takeoverAllowed', type: 'boolean', default: false, volatile: true,
59
- description: 'Allow actions to request the takeover tier (takeover:true): the real cursor is moved '
60
- + 'to the action point and always restored, the focus is held for the duration, and a three-phase '
61
- + 'HUD is mandatory. Off by default; when off, a takeover request is refused with '
62
- + 'takeover_unavailable and the action is NOT silently downgraded.' },
63
- { key: 'keyInjectAllowed', type: 'boolean', default: false, volatile: true,
64
- description: 'Allow keyboard injection (keyInput:"inject") inside the takeover tier, for targets '
65
- + 'with no message door and no UIA pattern (terminals). Text is typed into the FOREGROUND window '
66
- + 'after asserting it is the target; never mouse injection. Off by default.' },
67
- { key: 'takeoverMaxMs', type: 'number', default: 10000, min: 500, max: 60000, volatile: true,
68
- description: 'How long a takeover action may hold the owner’s cursor/focus before it must end. '
69
- + 'Hard ceiling 60s; the HUD shows the elapsed/limit clock so a long action is visible.' },
70
- { key: 'takeoverArmMs', type: 'number', default: 800, min: 0, max: 5000, volatile: true,
71
- description: 'Length of the HUD’s arming phase: the window in which the owner can cancel before '
72
- + 'the cursor moves or a key is typed. 0 disables the wait (the HUD still shows).' },
73
- // ---- 0.5.0 read-path settings. Each one is a COST the owner can see, not a hidden default:
74
- // a snapshot cap, an explicit downscale, and a retention count. Nothing here changes the input
75
- // stance -- snapshot/screenshot/preview write no input and take no focus.
76
- { key: 'snapshotMaxElements', type: 'number', default: 300, min: 1, max: 5000, volatile: true,
77
- description: 'Cap on the number of elements one snapshot returns. Measured trees: 71 visible '
78
- + 'elements for an 816-node Electron window, so 300 is deliberately loose; a lower value trades '
79
- + 'completeness for a smaller frame when the deciding side is a clean subagent.' },
80
- { key: 'screenshotMaxWidth', type: 'number', default: 0, min: 0, max: 7680, volatile: true,
81
- description: 'Downscale screenshots to at most this width. 0 (default) means no scaling and '
82
- + 'scale=1: a resized image is a different coordinate system, so it is never chosen silently.' },
83
- { key: 'shotsKeep', type: 'number', default: 10, min: 1, max: 200, volatile: true,
84
- description: 'How many screenshot PNGs stay in %LOCALAPPDATA%\\wpm\\shots. Older files are deleted '
85
- + 'after each capture, so the directory cannot grow without bound; a shotId that was cleaned up '
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.' },
116
- ];
117
-
118
- /** Defaults, for documentation and for tests that must not depend on a resolver. */
119
- export const CONFIG_DEFAULTS = Object.fromEntries(FIELDS.map((f) => [f.key, f.default]));
120
-
121
- /**
122
- * Validate one raw config object against FIELDS. Returns `{ value, issues }` standard-schema style.
123
- *
124
- * `@returns {any}` on purpose: the two returns below have different shapes (`{issues}` alone vs
125
- * `{value}` alone), which is exactly what the standard-schema contract allows and what Cordis
126
- * branches on. A precise union here is a lie about the runtime and was measured to turn two errors
127
- * into three (findings §7.5).
128
- * @param {any} raw
129
- * @returns {any}
130
- */
131
- function validateWithShim(raw) {
132
- const input = raw && typeof raw === 'object' ? raw : {};
133
- /** @type {Record<string, any>} */
134
- const value = {};
135
- const issues = [];
136
- for (const field of FIELDS) {
137
- const given = input[field.key];
138
- if (given === undefined || given === null) { value[field.key] = field.default; continue; }
139
- if (field.type === 'boolean') {
140
- if (typeof given !== 'boolean') issues.push({ message: `expected a boolean`, path: [field.key] });
141
- else value[field.key] = given;
142
- } else if (field.type === 'number') {
143
- if (typeof given !== 'number' || !Number.isFinite(given)) {
144
- issues.push({ message: `expected a finite number`, path: [field.key] });
145
- } else if ((field.min !== undefined && given < field.min) || (field.max !== undefined && given > field.max)) {
146
- issues.push({ message: `expected ${field.min}..${field.max}`, path: [field.key] });
147
- } else {
148
- value[field.key] = given;
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
- }
171
- } else if (typeof given !== 'string') {
172
- issues.push({ message: `expected a string`, path: [field.key] });
173
- } else {
174
- value[field.key] = given;
175
- }
176
- }
177
- for (const key of Object.keys(input)) {
178
- if (!FIELDS.some((f) => f.key === key)) {
179
- // Unknown keys are an issue, not silence: a typo in the bundle patch would otherwise take the
180
- // default and leave the user wondering why their setting did nothing.
181
- issues.push({ message: `unknown setting`, path: [key] });
182
- }
183
- }
184
- return issues.length ? { issues } : { value };
185
- }
186
-
187
- const shimSchema = {
188
- '~standard': {
189
- version: 1,
190
- vendor: 'dsh-windows-parallel-mcp',
191
- validate: validateWithShim,
192
- },
193
- /** Marker parity with schemastery so `typeof field.volatile === 'function'` probes behave. */
194
- fields: FIELDS,
195
- };
196
-
197
- /**
198
- * Build the Config value. Tries the host's schema library first; falls back to the shim.
199
- * Returns `{ schema, source }` so the caller can log which one is active -- a silent fallback is how
200
- * "works on my machine" diverges from "works on the host".
201
- */
202
- export async function createConfigSchema() {
203
- try {
204
- // Static-import bridge (see lib/peers-schemastery.js): a dynamic bare specifier does not
205
- // resolve for a `link:`-installed package under the host, which is exactly why the desktop
206
- // profile fell to the shim and rendered no settings form.
207
- const mod = await import('./peers-schemastery.js');
208
- const z = mod?.z;
209
- if (z && typeof z.object === 'function') {
210
- /** @type {Record<string, any>} */
211
- const shape = {};
212
- for (const field of FIELDS) {
213
- let s;
214
- if (field.type === 'boolean') s = z.boolean();
215
- else if (field.type === 'number') s = z.number();
216
- else if (field.type === 'string[]') s = z.array(z.string());
217
- else s = z.string();
218
- if (field.min !== undefined || field.max !== undefined) {
219
- if (typeof s.min === 'function' && field.min !== undefined) s = s.min(field.min);
220
- if (typeof s.max === 'function' && field.max !== undefined) s = s.max(field.max);
221
- }
222
- if (field.description) s = s.description(field.description);
223
- s = s.default(field.default);
224
- // `.volatile()` marks a field as hot-reloadable on 0.1.7+. Guarded because older schema
225
- // lines in the same major do not have it.
226
- if (field.volatile && typeof s.volatile === 'function') s = s.volatile();
227
- shape[field.key] = s;
228
- }
229
- const schema = typeof z.object(shape).prefault === 'function' ? z.object(shape).prefault({}) : z.object(shape);
230
- // TWO PROPERTIES THE SHIM ALREADY HAD, restored on the Schemastery path so both paths behave the
231
- // same way for the caller:
232
- // * UNKNOWN KEYS ARE REJECTED, not silently carried through. Schemastery keeps them in the
233
- // validated value, which means a typo'd setting reads as accepted while doing nothing -- the
234
- // exact failure test/plugin-test.mjs pins, and the reason the shim has this rule;
235
- // * '~standard' stays the single validation entry point Cordis calls.
236
- // The Schemastery INSTANCE itself is kept: it is a callable object and it is what the host uses to
237
- // render the settings form. Wrapping it in a plain object would trade the form for the check.
238
- // Schemastery owns '~standard' as a non-writable accessor, so it cannot be replaced in place. The
239
- // wrapper below is a PROXY over the instance: still callable, still carrying the instance's own
240
- // fields and methods (which is what the settings form reads), but with one property -- the
241
- // validation entry point Cordis calls -- replaced by the strict one.
242
- const std = schema['~standard'];
243
- let configValue = schema;
244
- if (std && typeof std.validate === 'function') {
245
- /** @type {Set<string>} */
246
- const known = new Set(FIELDS.map((f) => f.key));
247
- const wrapped = Object.assign(Object.create(null), std, {
248
- /** @param {any} raw @returns {any} */
249
- validate(raw) {
250
- const input = raw && typeof raw === 'object' ? raw : {};
251
- const unknown = Object.keys(input).filter((k) => !known.has(k));
252
- if (unknown.length) {
253
- return { issues: unknown.map((k) => ({ message: 'unknown setting', path: [k] })) };
254
- }
255
- return std.validate(raw);
256
- },
257
- });
258
- try {
259
- configValue = new Proxy(schema, {
260
- get(target, prop, receiver) {
261
- if (prop === '~standard') return wrapped;
262
- const v = Reflect.get(target, prop, receiver);
263
- return typeof v === 'function' ? v.bind(target) : v;
264
- },
265
- apply(target, thisArg, args) { return Reflect.apply(target, thisArg, args); },
266
- });
267
- } catch { configValue = schema; }
268
- }
269
- return { schema: configValue, source: '@deepseek-ai/schemastery' };
270
- }
271
- } catch {
272
- // Documented fallback, reported through `source`.
273
- }
274
- return { schema: shimSchema, source: 'local-standard-schema-shim' };
275
- }
1
+ // config.js — the settings surface, built on the host's schema library when it is reachable and on a
2
+ // standard-schema shim when it is not.
3
+ //
4
+ // WHY THIS FILE EXISTS AT ALL. The first version exported `Config` as a factory function. Cordis
5
+ // requires a *standard-schema value* — it calls `Config['~standard'].validate(config)` — so the
6
+ // plugin failed to activate with `Cannot read properties of undefined (reading 'validate')`, and the
7
+ // only reason it was found is that the profile was actually booted (`dsh --profile wpm-dev headless`)
8
+ // instead of being assumed good from a passing unit test. A plugin that never activates is the worst
9
+ // failure mode available: it registers no tool, prints one warning into a busy log, and looks
10
+ // installed.
11
+ //
12
+ // WHY NOT A HARD DEPENDENCY. `@deepseek-ai/schemastery` is a host-provided peer. Declaring it as a
13
+ // dependency would drag a second copy of the schema library into the profile, and declaring it as a
14
+ // peer would make install fail wherever the host resolves peers differently than it does here. So the
15
+ // import is attempted, and the shim is the documented fallback.
16
+ //
17
+ // WHAT THE SHIM IS. A standard-schema implementation over a flat, explicitly typed field list. It
18
+ // applies defaults, rejects wrong types and out-of-range values, and reports issues in the shape
19
+ // Cordis renders. It is NOT schemastery: the settings FORM is rendered from schemastery's field
20
+ // metadata, so a host that cannot resolve schemastery gives the user no form — the values still work
21
+ // from the bundle patch. That limitation is stated in the README rather than papered over.
22
+
23
+ /**
24
+ * One declarable setting. `type` is a closed string union rather than a string so the four-way
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.
28
+ * @typedef {object} ConfigField
29
+ * @property {string} key
30
+ * @property {'boolean'|'number'|'string'|'string[]'} type
31
+ * @property {any} default
32
+ * @property {number} [min]
33
+ * @property {number} [max]
34
+ * @property {boolean} [volatile]
35
+ * @property {string} [description]
36
+ */
37
+
38
+ /** @type {ConfigField[]} */
39
+ const FIELDS = [
40
+ { key: 'enabled', type: 'boolean', default: true, volatile: true,
41
+ description: 'Master switch. When off, every action refuses with `paused` before the engine is reached.' },
42
+ { key: 'settleMs', type: 'number', default: 350, min: 0, max: 2000, volatile: true,
43
+ description: 'How long the target app gets to commit its state before the effect is judged.' },
44
+ { key: 'requestTimeoutMs', type: 'number', default: 20000, min: 1000, max: 600000,
45
+ description: 'A worker that stops answering is killed and restarted on the next call.' },
46
+ { key: 'powershellPath', type: 'string', default: '',
47
+ description: 'Override the PowerShell executable. Windows PowerShell 5.1 is the floor; pwsh is accepted.' },
48
+ { key: 'overlay', type: 'boolean', default: true, volatile: true,
49
+ description: 'Show the click-through AI marker at the point each action touched. It never takes '
50
+ + 'the foreground and never intercepts a click (measured). The first action pays a one-time '
51
+ + 'worker round-trip while the overlay starts; after that a placement costs ~19ms and does not '
52
+ + 'gate the action result.' },
53
+ { key: 'logWorkerStderr', type: 'boolean', default: false, volatile: true,
54
+ description: 'Forward the sidecar’s stderr diagnostics to the host log.' },
55
+ // ---- R3 gates. BOTH DEFAULT OFF, and that is a product decision, not timidity: with them off the
56
+ // tool behaves exactly like 0.1.6 (zero physical input), so an upgrade cannot silently start moving
57
+ // the owner's cursor. Turning takeover on is the owner's explicit act.
58
+ { key: 'takeoverAllowed', type: 'boolean', default: false, volatile: true,
59
+ description: 'Allow actions to request the takeover tier (takeover:true): the real cursor is moved '
60
+ + 'to the action point and always restored, the focus is held for the duration, and a three-phase '
61
+ + 'HUD is mandatory. Off by default; when off, a takeover request is refused with '
62
+ + 'takeover_unavailable and the action is NOT silently downgraded.' },
63
+ { key: 'keyInjectAllowed', type: 'boolean', default: false, volatile: true,
64
+ description: 'Allow keyboard injection (keyInput:"inject") inside the takeover tier, for targets '
65
+ + 'with no message door and no UIA pattern (terminals). Text is typed into the FOREGROUND window '
66
+ + 'after asserting it is the target; never mouse injection. Off by default.' },
67
+ { key: 'takeoverMaxMs', type: 'number', default: 10000, min: 500, max: 60000, volatile: true,
68
+ description: 'How long a takeover action may hold the owner’s cursor/focus before it must end. '
69
+ + 'Hard ceiling 60s; the HUD shows the elapsed/limit clock so a long action is visible.' },
70
+ { key: 'takeoverArmMs', type: 'number', default: 800, min: 0, max: 5000, volatile: true,
71
+ description: 'Length of the HUD’s arming phase: the window in which the owner can cancel before '
72
+ + 'the cursor moves or a key is typed. 0 disables the wait (the HUD still shows).' },
73
+ // ---- 0.5.0 read-path settings. Each one is a COST the owner can see, not a hidden default:
74
+ // a snapshot cap, an explicit downscale, and a retention count. Nothing here changes the input
75
+ // stance -- snapshot/screenshot/preview write no input and take no focus.
76
+ { key: 'snapshotMaxElements', type: 'number', default: 300, min: 1, max: 5000, volatile: true,
77
+ description: 'Cap on the number of elements one snapshot returns. Measured trees: 71 visible '
78
+ + 'elements for an 816-node Electron window, so 300 is deliberately loose; a lower value trades '
79
+ + 'completeness for a smaller frame when the deciding side is a clean subagent.' },
80
+ { key: 'screenshotMaxWidth', type: 'number', default: 0, min: 0, max: 7680, volatile: true,
81
+ description: 'Downscale screenshots to at most this width. 0 (default) means no scaling and '
82
+ + 'scale=1: a resized image is a different coordinate system, so it is never chosen silently.' },
83
+ { key: 'shotsKeep', type: 'number', default: 10, min: 1, max: 200, volatile: true,
84
+ description: 'How many screenshot PNGs stay in %LOCALAPPDATA%\\wpm\\shots. Older files are deleted '
85
+ + 'after each capture, so the directory cannot grow without bound; a shotId that was cleaned up '
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.' },
116
+ ];
117
+
118
+ /** Defaults, for documentation and for tests that must not depend on a resolver. */
119
+ export const CONFIG_DEFAULTS = Object.fromEntries(FIELDS.map((f) => [f.key, f.default]));
120
+
121
+ /**
122
+ * Validate one raw config object against FIELDS. Returns `{ value, issues }` standard-schema style.
123
+ *
124
+ * `@returns {any}` on purpose: the two returns below have different shapes (`{issues}` alone vs
125
+ * `{value}` alone), which is exactly what the standard-schema contract allows and what Cordis
126
+ * branches on. A precise union here is a lie about the runtime and was measured to turn two errors
127
+ * into three (findings §7.5).
128
+ * @param {any} raw
129
+ * @returns {any}
130
+ */
131
+ function validateWithShim(raw) {
132
+ const input = raw && typeof raw === 'object' ? raw : {};
133
+ /** @type {Record<string, any>} */
134
+ const value = {};
135
+ const issues = [];
136
+ for (const field of FIELDS) {
137
+ const given = input[field.key];
138
+ if (given === undefined || given === null) { value[field.key] = field.default; continue; }
139
+ if (field.type === 'boolean') {
140
+ if (typeof given !== 'boolean') issues.push({ message: `expected a boolean`, path: [field.key] });
141
+ else value[field.key] = given;
142
+ } else if (field.type === 'number') {
143
+ if (typeof given !== 'number' || !Number.isFinite(given)) {
144
+ issues.push({ message: `expected a finite number`, path: [field.key] });
145
+ } else if ((field.min !== undefined && given < field.min) || (field.max !== undefined && given > field.max)) {
146
+ issues.push({ message: `expected ${field.min}..${field.max}`, path: [field.key] });
147
+ } else {
148
+ value[field.key] = given;
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
+ }
171
+ } else if (typeof given !== 'string') {
172
+ issues.push({ message: `expected a string`, path: [field.key] });
173
+ } else {
174
+ value[field.key] = given;
175
+ }
176
+ }
177
+ for (const key of Object.keys(input)) {
178
+ if (!FIELDS.some((f) => f.key === key)) {
179
+ // Unknown keys are an issue, not silence: a typo in the bundle patch would otherwise take the
180
+ // default and leave the user wondering why their setting did nothing.
181
+ issues.push({ message: `unknown setting`, path: [key] });
182
+ }
183
+ }
184
+ return issues.length ? { issues } : { value };
185
+ }
186
+
187
+ const shimSchema = {
188
+ '~standard': {
189
+ version: 1,
190
+ vendor: 'dsh-windows-parallel-mcp',
191
+ validate: validateWithShim,
192
+ },
193
+ /** Marker parity with schemastery so `typeof field.volatile === 'function'` probes behave. */
194
+ fields: FIELDS,
195
+ };
196
+
197
+ /**
198
+ * Build the Config value. Tries the host's schema library first; falls back to the shim.
199
+ * Returns `{ schema, source }` so the caller can log which one is active -- a silent fallback is how
200
+ * "works on my machine" diverges from "works on the host".
201
+ */
202
+ export async function createConfigSchema() {
203
+ try {
204
+ // Static-import bridge (see lib/peers-schemastery.js): a dynamic bare specifier does not
205
+ // resolve for a `link:`-installed package under the host, which is exactly why the desktop
206
+ // profile fell to the shim and rendered no settings form.
207
+ const mod = await import('./peers-schemastery.js');
208
+ const z = mod?.z;
209
+ if (z && typeof z.object === 'function') {
210
+ /** @type {Record<string, any>} */
211
+ const shape = {};
212
+ for (const field of FIELDS) {
213
+ let s;
214
+ if (field.type === 'boolean') s = z.boolean();
215
+ else if (field.type === 'number') s = z.number();
216
+ else if (field.type === 'string[]') s = z.array(z.string());
217
+ else s = z.string();
218
+ if (field.min !== undefined || field.max !== undefined) {
219
+ if (typeof s.min === 'function' && field.min !== undefined) s = s.min(field.min);
220
+ if (typeof s.max === 'function' && field.max !== undefined) s = s.max(field.max);
221
+ }
222
+ if (field.description) s = s.description(field.description);
223
+ s = s.default(field.default);
224
+ // `.volatile()` marks a field as hot-reloadable on 0.1.7+. Guarded because older schema
225
+ // lines in the same major do not have it.
226
+ if (field.volatile && typeof s.volatile === 'function') s = s.volatile();
227
+ shape[field.key] = s;
228
+ }
229
+ const schema = typeof z.object(shape).prefault === 'function' ? z.object(shape).prefault({}) : z.object(shape);
230
+ // TWO PROPERTIES THE SHIM ALREADY HAD, restored on the Schemastery path so both paths behave the
231
+ // same way for the caller:
232
+ // * UNKNOWN KEYS ARE REJECTED, not silently carried through. Schemastery keeps them in the
233
+ // validated value, which means a typo'd setting reads as accepted while doing nothing -- the
234
+ // exact failure test/plugin-test.mjs pins, and the reason the shim has this rule;
235
+ // * '~standard' stays the single validation entry point Cordis calls.
236
+ // The Schemastery INSTANCE itself is kept: it is a callable object and it is what the host uses to
237
+ // render the settings form. Wrapping it in a plain object would trade the form for the check.
238
+ // Schemastery owns '~standard' as a non-writable accessor, so it cannot be replaced in place. The
239
+ // wrapper below is a PROXY over the instance: still callable, still carrying the instance's own
240
+ // fields and methods (which is what the settings form reads), but with one property -- the
241
+ // validation entry point Cordis calls -- replaced by the strict one.
242
+ const std = schema['~standard'];
243
+ let configValue = schema;
244
+ if (std && typeof std.validate === 'function') {
245
+ /** @type {Set<string>} */
246
+ const known = new Set(FIELDS.map((f) => f.key));
247
+ const wrapped = Object.assign(Object.create(null), std, {
248
+ /** @param {any} raw @returns {any} */
249
+ validate(raw) {
250
+ const input = raw && typeof raw === 'object' ? raw : {};
251
+ const unknown = Object.keys(input).filter((k) => !known.has(k));
252
+ if (unknown.length) {
253
+ return { issues: unknown.map((k) => ({ message: 'unknown setting', path: [k] })) };
254
+ }
255
+ return std.validate(raw);
256
+ },
257
+ });
258
+ try {
259
+ configValue = new Proxy(schema, {
260
+ get(target, prop, receiver) {
261
+ if (prop === '~standard') return wrapped;
262
+ const v = Reflect.get(target, prop, receiver);
263
+ return typeof v === 'function' ? v.bind(target) : v;
264
+ },
265
+ apply(target, thisArg, args) { return Reflect.apply(target, thisArg, args); },
266
+ });
267
+ } catch { configValue = schema; }
268
+ }
269
+ return { schema: configValue, source: '@deepseek-ai/schemastery' };
270
+ }
271
+ } catch {
272
+ // Documented fallback, reported through `source`.
273
+ }
274
+ return { schema: shimSchema, source: 'local-standard-schema-shim' };
275
+ }