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/CHANGELOG.de.md +13 -1
- package/CHANGELOG.es.md +13 -1
- package/CHANGELOG.fr.md +13 -1
- package/CHANGELOG.it.md +13 -1
- package/CHANGELOG.ja.md +13 -1
- package/CHANGELOG.ko.md +13 -1
- package/CHANGELOG.md +201 -1
- package/CHANGELOG.pt.md +13 -1
- package/CHANGELOG.ru.md +13 -1
- package/CHANGELOG.zh.md +13 -1
- package/README.de.md +231 -6
- package/README.es.md +231 -6
- package/README.fr.md +231 -6
- package/README.it.md +231 -6
- package/README.ja.md +231 -6
- package/README.ko.md +231 -6
- package/README.md +231 -6
- package/README.pt.md +231 -6
- package/README.ru.md +231 -6
- package/README.zh.md +231 -6
- package/docs/refusals.md +3 -0
- package/dsh.plugin.json +3 -3
- package/lib/audit.js +109 -0
- package/lib/config.js +55 -2
- package/lib/host-tools.js +61 -3
- package/lib/index.js +308 -12
- package/lib/mcp-server.mjs +350 -0
- package/lib/policy.js +127 -0
- package/package.json +9 -2
- package/server.json +109 -0
- package/src/engine/decide.ps1 +120 -3
- package/src/engine/engine.ps1 +249 -2
- package/src/engine/win.ps1 +266 -0
- package/src/engine/worker.ps1 +52 -0
- package/src/schema/tools.json +171 -13
- package/types/index.d.ts +35 -3
package/lib/index.js
CHANGED
|
@@ -25,12 +25,29 @@
|
|
|
25
25
|
// 3. `paused` and `enabled` are server-side gates. They are checked here, before any worker call,
|
|
26
26
|
// because a prompt-level hint is not a switch (R2.5).
|
|
27
27
|
import { createConfigSchema, CONFIG_DEFAULTS } from './config.js';
|
|
28
|
-
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
28
|
+
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
29
29
|
import { tmpdir } from 'node:os';
|
|
30
30
|
import { dirname, join } from 'node:path';
|
|
31
31
|
import { WorkerClient, workerScript } from './engine.js';
|
|
32
32
|
import { ACTIONS, PARAMETERS, TOOL_NAME, resolveDefineTool } from './host-tools.js';
|
|
33
33
|
import { evaluateProof } from './proof-window.mjs';
|
|
34
|
+
import { actionTier, policyDecision, tierTable } from './policy.js';
|
|
35
|
+
import { auditLine, auditWrite } from './audit.js';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The tier each action declares it needs, read ONCE from the contract file -- not copied into a table
|
|
39
|
+
* here. The reason is this repo's most repeated lesson: three hand-kept copies of one vocabulary drift
|
|
40
|
+
* (scripts/check-refusals.mjs exists because of it), and a policy table written in two places would be
|
|
41
|
+
* the same bug with permission semantics attached. If the file cannot be read the table is EMPTY, and an
|
|
42
|
+
* empty table makes `actionTier` answer `takeover` for everything -- fail closed, never fail open.
|
|
43
|
+
* @type {Record<string, {requiresTier: string, requiresTierFor: Record<string,string>}>}
|
|
44
|
+
*/
|
|
45
|
+
const REQUIRES_TIER = (() => {
|
|
46
|
+
try {
|
|
47
|
+
const doc = JSON.parse(readFileSync(new URL('../src/schema/tools.json', import.meta.url), 'utf8'));
|
|
48
|
+
return tierTable(doc.tools ?? []);
|
|
49
|
+
} catch { return {}; }
|
|
50
|
+
})();
|
|
34
51
|
|
|
35
52
|
// ---- THE PUBLIC CONTRACT IS THE SOURCE OF TRUTH, AND THIS FILE IS CHECKED AGAINST IT ----------
|
|
36
53
|
//
|
|
@@ -71,6 +88,11 @@ import { evaluateProof } from './proof-window.mjs';
|
|
|
71
88
|
* @property {number} snapshotMaxElements
|
|
72
89
|
* @property {number} screenshotMaxWidth
|
|
73
90
|
* @property {number} shotsKeep
|
|
91
|
+
* @property {boolean} appLaunchAllowed
|
|
92
|
+
* @property {string[]} appLaunchAllow
|
|
93
|
+
* @property {'readonly'|'quiet'|'balanced'|'full'} policy
|
|
94
|
+
* @property {number} policyIdleMs
|
|
95
|
+
* @property {number} auditKeep
|
|
74
96
|
*/
|
|
75
97
|
|
|
76
98
|
/**
|
|
@@ -155,6 +177,16 @@ export function apply(ctx, config = {}) {
|
|
|
155
177
|
snapshotMaxElements: clampNumber(resolveSetting(config.snapshotMaxElements, 300), 1, 5000, 300),
|
|
156
178
|
screenshotMaxWidth: clampNumber(resolveSetting(config.screenshotMaxWidth, 0), 0, 7680, 0),
|
|
157
179
|
shotsKeep: clampNumber(resolveSetting(config.shotsKeep, 10), 1, 200, 10),
|
|
180
|
+
// ---- 0.7.0 desktop gates. Read defensively because a whitelist is a list of AUTHORIZATIONS: a
|
|
181
|
+
// non-array, an empty entry, or a stray space must never turn into "everything is allowed".
|
|
182
|
+
appLaunchAllowed: resolveSetting(config.appLaunchAllowed, false) === true,
|
|
183
|
+
appLaunchAllow: normalizeAllowList(resolveSetting(config.appLaunchAllow, [])),
|
|
184
|
+
// ---- 0.7.0 authorization model. `policy` is the ONE knob that says how far this plugin may go
|
|
185
|
+
// without asking again; the per-action `requiresTier` in src/schema/tools.json is the other axis, so
|
|
186
|
+
// adding an action never means adding a setting.
|
|
187
|
+
policy: normalizePolicy(resolveSetting(config.policy, 'balanced')),
|
|
188
|
+
policyIdleMs: clampNumber(resolveSetting(config.policyIdleMs, 3000), 0, 60000, 3000),
|
|
189
|
+
auditKeep: clampNumber(resolveSetting(config.auditKeep, 2000), 100, 200000, 2000),
|
|
158
190
|
};
|
|
159
191
|
|
|
160
192
|
const logger = ctx.logger ?? console;
|
|
@@ -281,6 +313,40 @@ export function apply(ctx, config = {}) {
|
|
|
281
313
|
|
|
282
314
|
const { defineTool } = resolvedTools;
|
|
283
315
|
|
|
316
|
+
// Counted rather than logged-and-forgotten: an audit that silently fails to write would leave the
|
|
317
|
+
// operator with a log that LOOKS complete. The count is reported in the result text when non-zero.
|
|
318
|
+
let auditFailures = 0;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* The audit line for one call, built once so every exit path writes the same SHAPE. A refusal path
|
|
322
|
+
* that forgot to record would be the hole that makes an audit log useless, so this is called from a
|
|
323
|
+
* single place in `execute` rather than from each return.
|
|
324
|
+
* @param {WpmArgs} args @param {string} decision @param {string} code
|
|
325
|
+
* @param {Record<string, any>} [extra]
|
|
326
|
+
* @returns {{ok:boolean, wrote:boolean, error?:string}}
|
|
327
|
+
*/
|
|
328
|
+
const writeAudit = (args, decision, code, extra) => {
|
|
329
|
+
const r = auditLine({
|
|
330
|
+
action: String(args.action ?? ''), hwnd: String(args.hwnd ?? ''),
|
|
331
|
+
tier: String(extra?.tier ?? actionTier(REQUIRES_TIER, String(args.action ?? ''), args.op)),
|
|
332
|
+
policy: settings.policy, decision, code,
|
|
333
|
+
userActiveAgeMs: extra?.userActiveAgeMs, effect: String(extra?.effect ?? ''),
|
|
334
|
+
latencyMs: extra?.latencyMs, detail: extra?.detail,
|
|
335
|
+
forced: args.forceUserActive === true,
|
|
336
|
+
// The two content-free facts about a launch (R1: the whitelist cannot make arguments safe, so the
|
|
337
|
+
// record is what makes a bad one reviewable).
|
|
338
|
+
...(args.action === 'launch' ? { target: String(args.target ?? ''), args: String(args.args ?? '') } : {}),
|
|
339
|
+
// Clipboard and type: lengths only. A log that copied the clipboard or the typed text would be a
|
|
340
|
+
// second place a secret lives, and the second place is the one nobody protects.
|
|
341
|
+
...(args.action === 'clipboard' ? { op: String(args.op ?? ''), format: String(args.format ?? 'text') } : {}),
|
|
342
|
+
...(typeof args.text === 'string' ? { chars: args.text.length } : {}),
|
|
343
|
+
...(typeof extra?.chars === 'number' ? { resultChars: extra.chars } : {}),
|
|
344
|
+
});
|
|
345
|
+
const w = auditWrite(r, { keep: settings.auditKeep });
|
|
346
|
+
if (!w.ok) auditFailures += 1;
|
|
347
|
+
return w;
|
|
348
|
+
};
|
|
349
|
+
|
|
284
350
|
/** Build the worker request for one action. Throws for arguments the action cannot use. */
|
|
285
351
|
/** @param {WpmArgs} args @returns {any} */
|
|
286
352
|
function toRequest(args) {
|
|
@@ -302,6 +368,15 @@ export function apply(ctx, config = {}) {
|
|
|
302
368
|
...(keyInput === 'inject' ? { keyInput } : {}),
|
|
303
369
|
}
|
|
304
370
|
: {};
|
|
371
|
+
// ---- 0.7.0 authorization fields, forwarded to the engine for the door actions. The host has ALREADY
|
|
372
|
+
// refused anything above the ceiling (so a refusal here costs zero worker requests); these travel so
|
|
373
|
+
// the engine can apply the idle check, which needs a measurement only it can take.
|
|
374
|
+
const authFields = {
|
|
375
|
+
policy: settings.policy,
|
|
376
|
+
requiredTier: actionTier(REQUIRES_TIER, args.action, args.op),
|
|
377
|
+
policyIdleMs: settings.policyIdleMs,
|
|
378
|
+
...(args.forceUserActive === true ? { forceUserActive: true } : {}),
|
|
379
|
+
};
|
|
305
380
|
switch (args.action) {
|
|
306
381
|
case 'windows':
|
|
307
382
|
return { action: 'windows' };
|
|
@@ -362,6 +437,7 @@ export function apply(ctx, config = {}) {
|
|
|
362
437
|
}
|
|
363
438
|
return {
|
|
364
439
|
action: 'click', hwnd: args.hwnd, x: Math.round(/** @type {number} */ (args.x)), y: Math.round(/** @type {number} */ (args.y)), settleMs,
|
|
440
|
+
...authFields,
|
|
365
441
|
...(space === 'image' ? { space: 'image', shotId: args.shotId } : {}),
|
|
366
442
|
...(typeof args.label === 'number' && args.label > 0
|
|
367
443
|
? { label: Math.round(args.label), snapId: typeof args.snapId === 'string' ? args.snapId : '' }
|
|
@@ -378,6 +454,7 @@ export function apply(ctx, config = {}) {
|
|
|
378
454
|
return {
|
|
379
455
|
action: 'type', hwnd: args.hwnd, text: args.text,
|
|
380
456
|
elementName: args.elementName ?? '', replace: args.replace === true, settleMs,
|
|
457
|
+
...authFields,
|
|
381
458
|
// Forwarded only when it is one of the three values the engine declares; anything else is
|
|
382
459
|
// dropped to the default HERE rather than passed on, because the engine's ValidateSet would
|
|
383
460
|
// turn a model's typo into `action_failed` -- and a schema the host already validates against
|
|
@@ -395,11 +472,64 @@ export function apply(ctx, config = {}) {
|
|
|
395
472
|
if ((typeof args.label !== 'number' || args.label <= 0)) requireArg(args, 'elementName', 'focus');
|
|
396
473
|
return {
|
|
397
474
|
action: 'focus', hwnd: args.hwnd, elementName: args.elementName ?? '', settleMs,
|
|
475
|
+
...authFields,
|
|
398
476
|
...(typeof args.label === 'number' && args.label > 0
|
|
399
477
|
? { label: Math.round(args.label), snapId: typeof args.snapId === 'string' ? args.snapId : '' }
|
|
400
478
|
: {}),
|
|
401
479
|
...takeoverFields,
|
|
402
480
|
};
|
|
481
|
+
case 'launch': {
|
|
482
|
+
// The gates are applied in `execute` BEFORE this line is reached, so a refusal costs no worker
|
|
483
|
+
// request at all; this function only shapes an authorised call. `args` is passed through as one
|
|
484
|
+
// command line -- the whitelist vouches for the program, not for its arguments, which is exactly
|
|
485
|
+
// why the audit records both.
|
|
486
|
+
requireArg(args, 'target', 'launch');
|
|
487
|
+
return {
|
|
488
|
+
action: 'launch', target: args.target,
|
|
489
|
+
...(typeof args.args === 'string' && args.args ? { args: args.args } : {}),
|
|
490
|
+
waitMs: clampNumber(args.waitMs, 0, 30000, 3000),
|
|
491
|
+
policy: settings.policy, policyIdleMs: settings.policyIdleMs,
|
|
492
|
+
launchAllowed: settings.appLaunchAllowed,
|
|
493
|
+
allowList: settings.appLaunchAllow,
|
|
494
|
+
...(args.forceUserActive === true ? { forceUserActive: true } : {}),
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
case 'clipboard': {
|
|
498
|
+
if (args.op !== 'read' && args.op !== 'write') {
|
|
499
|
+
throw refusal('action_failed', "clipboard needs op:'read' or op:'write'; no worker request was made");
|
|
500
|
+
}
|
|
501
|
+
const format = args.format === 'image' ? 'image' : 'text';
|
|
502
|
+
if (args.op === 'write' && format === 'text' && (typeof args.text !== 'string' || args.text.length === 0)) {
|
|
503
|
+
// Same rule as `type`: an empty write cannot be told apart from a clipboard the owner already
|
|
504
|
+
// cleared, and "the write worked" would then be a claim about nothing.
|
|
505
|
+
throw refusal('action_failed', 'clipboard write needs text; an empty write is indistinguishable from an already-empty clipboard');
|
|
506
|
+
}
|
|
507
|
+
return {
|
|
508
|
+
action: 'clipboard', op: args.op, format,
|
|
509
|
+
...(format === 'text' && args.op === 'write' ? { text: args.text } : {}),
|
|
510
|
+
...(format === 'image' && typeof args.shotId === 'string' ? { shotId: args.shotId } : {}),
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
case 'window': {
|
|
514
|
+
// An action with no target window is not a convenience, it is the ability to move something
|
|
515
|
+
// nobody named -- so `hwnd` stays mandatory and "the front window" is not a selector here.
|
|
516
|
+
requireArg(args, 'hwnd', 'window');
|
|
517
|
+
const op = String(args.op ?? '');
|
|
518
|
+
if (!['minimize', 'restore', 'move', 'resize', 'topmost'].includes(op)) {
|
|
519
|
+
throw refusal('action_failed', `window needs op=minimize|restore|move|resize|topmost, not '${args.op ?? ''}'; no worker request was made`);
|
|
520
|
+
}
|
|
521
|
+
if (op === 'move' && (typeof args.x !== 'number' || typeof args.y !== 'number')) {
|
|
522
|
+
throw refusal('action_failed', 'window move needs x and y in physical screen pixels; guessing the current position would make the move unreviewable');
|
|
523
|
+
}
|
|
524
|
+
if (op === 'resize' && (typeof args.width !== 'number' || typeof args.height !== 'number')) {
|
|
525
|
+
throw refusal('action_failed', 'window resize needs width and height');
|
|
526
|
+
}
|
|
527
|
+
return {
|
|
528
|
+
action: 'window', hwnd: args.hwnd, op,
|
|
529
|
+
...(op === 'move' ? { x: Math.round(/** @type {number} */ (args.x)), y: Math.round(/** @type {number} */ (args.y)) } : {}),
|
|
530
|
+
...(op === 'resize' ? { width: Math.round(/** @type {number} */ (args.width)), height: Math.round(/** @type {number} */ (args.height)) } : {}),
|
|
531
|
+
};
|
|
532
|
+
}
|
|
403
533
|
default:
|
|
404
534
|
throw refusal('no_hwnd', `unknown action '${args.action}'`);
|
|
405
535
|
}
|
|
@@ -426,7 +556,14 @@ export function apply(ctx, config = {}) {
|
|
|
426
556
|
+ 'draws the marker at a point and reports, as TEXT, the element under it -- a reviewable click that '
|
|
427
557
|
+ 'needs no picture. Refusals carry a code (no_hwnd, '
|
|
428
558
|
+ 'paused, elevated_target, unreachable, uia_tree_empty, uia_probe_failed, terminal_no_door, needs_facts, action_failed, '
|
|
429
|
-
+ 'restore_failed, takeover_unavailable, keyinject_unavailable, takeover_aborted, stale_ref
|
|
559
|
+
+ 'restore_failed, takeover_unavailable, keyinject_unavailable, takeover_aborted, stale_ref, app_launch_denied, '
|
|
560
|
+
+ 'policy_denied, user_active) and a reason. '
|
|
561
|
+
+ 'THREE DESKTOP ACTIONS exist since 0.7.0 and are gated by settings rather than by the target: launch needs '
|
|
562
|
+
+ 'appLaunchAllowed AND an exact appLaunchAllow entry (an empty whitelist means nothing, and no wildcard exists); '
|
|
563
|
+
+ 'clipboard reads and writes the system clipboard, reporting lengths and never contents; window changes one '
|
|
564
|
+
+ 'named window (minimize/restore/move/resize/topmost) and verifies the change by reading the window state back. '
|
|
565
|
+
+ 'The single `policy` setting is the ceiling over all eleven actions: a call above it is refused with '
|
|
566
|
+
+ 'policy_denied, whose next step is to raise the setting and not to retry. '
|
|
430
567
|
+ 'Start with action=windows to get an hwnd, action=snapshot to read a frame, or action=status to see '
|
|
431
568
|
+ 'what currently holds the foreground.',
|
|
432
569
|
parameters: PARAMETERS,
|
|
@@ -450,24 +587,77 @@ export function apply(ctx, config = {}) {
|
|
|
450
587
|
},
|
|
451
588
|
/** @param {WpmArgs} args @param {WpmExec|undefined} exec @returns {Promise<Record<string, any>>} */
|
|
452
589
|
async execute(args, exec) {
|
|
590
|
+
// THE GATE ORDER IS THE SAFETY DESIGN, and each gate that can be answered from settings is answered
|
|
591
|
+
// before the worker is touched -- asserted that way with a request counter in test/plugin-test.mjs.
|
|
592
|
+
// 1 paused 2 policy 3 takeover / keyInject 4 launch gate + whitelist 5 (engine) idle 6 table
|
|
593
|
+
// Every exit below goes through `finish`, because an audit written on one path and forgotten on the
|
|
594
|
+
// next is an audit log that looks complete and is not.
|
|
595
|
+
/** True once the audit line for this call has been written -- any second call is ignored. A
|
|
596
|
+
* boolean, not an object: the field's whole job is "have we recorded this yet". */
|
|
597
|
+
let audited = false;
|
|
598
|
+
/** @param {Record<string, any>} res @returns {Record<string, any>} */
|
|
599
|
+
const finish = (res) => {
|
|
600
|
+
if (!audited) {
|
|
601
|
+
audited = true;
|
|
602
|
+
writeAudit(args, res.ok === true ? 'allow' : 'deny', String(res.refusal ?? ''), {
|
|
603
|
+
effect: res.effect, latencyMs: res.latencyMs, chars: res.chars,
|
|
604
|
+
tier: res.tier, detail: res.refusal ? String(res.text ?? '').slice(0, 200) : undefined,
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
if (auditFailures) res.text = `${res.text} auditNote=${auditFailures} write(s) failed`;
|
|
608
|
+
return res;
|
|
609
|
+
};
|
|
453
610
|
// Server-side gates first: a paused or disabled engine must refuse before it spends a worker
|
|
454
611
|
// call, and the refusal must name the gate rather than describe a symptom.
|
|
455
612
|
if (!settings.enabled) {
|
|
456
|
-
return result(args.action, false, 'paused', 'windows-parallel is switched off in settings; no action was attempted');
|
|
613
|
+
return finish(result(args.action, false, 'paused', 'windows-parallel is switched off in settings; no action was attempted'));
|
|
614
|
+
}
|
|
615
|
+
// ---- 0.7.0 policy ceiling. ONE setting against the tier the action declares, so a new action
|
|
616
|
+
// never needs a new switch -- and never can slip past one that was never added.
|
|
617
|
+
const pd = policyDecision({
|
|
618
|
+
policy: settings.policy, table: REQUIRES_TIER, action: String(args.action),
|
|
619
|
+
takeoverRequested: args.takeover === true, keyInjectRequested: args.keyInput === 'inject',
|
|
620
|
+
// clipboard is the one action whose two halves live on different rungs; the table refinement is
|
|
621
|
+
// consulted here so `policy:'readonly'` still permits a read while a write is refused.
|
|
622
|
+
op: args.action === 'clipboard' ? args.op : undefined,
|
|
623
|
+
});
|
|
624
|
+
if (pd.denied) {
|
|
625
|
+
return finish(result(args.action, false, 'policy_denied',
|
|
626
|
+
`policy='${settings.policy}' allows at most the '${pd.ceiling}' rung and this call needs '${pd.required}'. Nothing was sent to the worker and no window was touched. Next step is a settings change, not a retry: raise policy in the plugin settings${args.takeover === true ? ' or drop takeover:true' : ''}${args.action === 'clipboard' && args.op === 'write' ? ' (a clipboard READ is allowed at this level)' : ''}`));
|
|
457
627
|
}
|
|
458
628
|
// ---- R3 gates, BEFORE the worker. A refused takeover costs zero worker requests, which is
|
|
459
629
|
// asserted with a request counter in test/plugin-test.mjs: "the gate is checked" is otherwise
|
|
460
630
|
// indistinguishable from "the gate is checked after the expensive part".
|
|
461
631
|
if (args.takeover === true && !settings.takeoverAllowed) {
|
|
462
|
-
return result(args.action, false, 'takeover_unavailable',
|
|
632
|
+
return finish(result(args.action, false, 'takeover_unavailable',
|
|
463
633
|
'takeoverAllowed is off in settings; the action was refused rather than silently downgraded to the quiet tier. '
|
|
464
|
-
+ 'The quiet tier still works without takeover:true' + hwndHint(args));
|
|
634
|
+
+ 'The quiet tier still works without takeover:true' + hwndHint(args)));
|
|
465
635
|
}
|
|
466
636
|
if (args.keyInput === 'inject' && (!settings.keyInjectAllowed || args.takeover !== true)) {
|
|
467
|
-
return result(args.action, false, 'keyinject_unavailable',
|
|
637
|
+
return finish(result(args.action, false, 'keyinject_unavailable',
|
|
468
638
|
args.takeover !== true
|
|
469
639
|
? 'keyInput:"inject" is only available inside the takeover tier (takeover:true): synthetic keys go to the FOREGROUND window, so without the HUD and the cursor contract it would be typing into whatever is in front'
|
|
470
|
-
: 'keyInjectAllowed is off in settings; no keystroke was sent');
|
|
640
|
+
: 'keyInjectAllowed is off in settings; no keystroke was sent'));
|
|
641
|
+
}
|
|
642
|
+
// ---- 0.7.0 the launch gate, then its whitelist. TWO switches, and the reason they are two is that
|
|
643
|
+
// "the owner enabled the capability" and "this program is on the approved list" are different
|
|
644
|
+
// decisions made at different times; folding them into one would make enabling launch enable every
|
|
645
|
+
// program at once. An empty whitelist refuses even when the gate is on -- that is the point.
|
|
646
|
+
if (args.action === 'launch') {
|
|
647
|
+
if (!settings.appLaunchAllowed) {
|
|
648
|
+
return finish(result('launch', false, 'app_launch_denied',
|
|
649
|
+
'appLaunchAllowed is off in settings, so no program may be started and no worker request was made. The next step is the owner\'s: turn the gate on AND list the exact program in appLaunchAllow'));
|
|
650
|
+
}
|
|
651
|
+
const name = String(args.target ?? '').trim().toLowerCase();
|
|
652
|
+
if (!name) {
|
|
653
|
+
return finish(result('launch', false, 'app_launch_denied', 'launch needs a target program name or path; nothing was started'));
|
|
654
|
+
}
|
|
655
|
+
// EXACT, case-folded membership. No wildcard, no prefix, no path normalisation: `notepad` must not
|
|
656
|
+
// authorise `notepad-helper.exe`, and a rule that grows by prefix is a whitelist in name only.
|
|
657
|
+
if (!settings.appLaunchAllow.includes(name)) {
|
|
658
|
+
return finish(result('launch', false, 'app_launch_denied',
|
|
659
|
+
`'${args.target}' is not on the appLaunchAllow whitelist (which holds ${settings.appLaunchAllow.length} exact name(s)); no process was started. Add the exact name or absolute path -- there is no wildcard and no prefix match${name.includes('\\') ? ' (a path must appear verbatim)' : ''}`));
|
|
660
|
+
}
|
|
471
661
|
}
|
|
472
662
|
// A pre-worker refusal is still a refusal, not a thrown error. The first version of this file
|
|
473
663
|
// let `toRequest` throw for an empty write, and the caller saw a crashed tool call instead of
|
|
@@ -484,7 +674,7 @@ export function apply(ctx, config = {}) {
|
|
|
484
674
|
// because the only thrower is `refusal()` above; the `??` fallbacks still keep the vocabulary
|
|
485
675
|
// intact when it is not.
|
|
486
676
|
const code = /** @type {WpmError} */ (err)?.refusal ?? 'action_failed';
|
|
487
|
-
return result(args.action, false, code, /** @type {WpmError} */ (err)?.reason ?? String(/** @type {WpmError} */ (err)?.message ?? err));
|
|
677
|
+
return finish(result(args.action, false, code, /** @type {WpmError} */ (err)?.reason ?? String(/** @type {WpmError} */ (err)?.message ?? err)));
|
|
488
678
|
}
|
|
489
679
|
let envelope;
|
|
490
680
|
const disarm = request.takeover ? armAbort(exec) : () => {};
|
|
@@ -497,12 +687,12 @@ export function apply(ctx, config = {}) {
|
|
|
497
687
|
// the original read `err.message` directly, and a non-Error thrown here still renders the
|
|
498
688
|
// same way it always did -- widening the expression would be a behaviour change dressed as
|
|
499
689
|
// type safety, which is exactly what this file refuses to do.
|
|
500
|
-
return result(args.action, false, 'action_failed', `engine worker unavailable: ${/** @type {Error} */ (err).message}`);
|
|
690
|
+
return finish(result(args.action, false, 'action_failed', `engine worker unavailable: ${/** @type {Error} */ (err).message}`));
|
|
501
691
|
} finally {
|
|
502
692
|
disarm();
|
|
503
693
|
}
|
|
504
694
|
if (!envelope.ok) {
|
|
505
|
-
return result(args.action, false, 'action_failed', `worker error: ${envelope.error ?? 'unknown'}`);
|
|
695
|
+
return finish(result(args.action, false, 'action_failed', `worker error: ${envelope.error ?? 'unknown'}`));
|
|
506
696
|
}
|
|
507
697
|
// click coordinates are SCREEN pixels (the engine converts to client space itself), so the
|
|
508
698
|
// marker can be placed straight from the request -- no second coordinate system to get wrong.
|
|
@@ -517,7 +707,7 @@ export function apply(ctx, config = {}) {
|
|
|
517
707
|
const screen = request.space === 'image' ? parsePoint(r.screenPoint) : null;
|
|
518
708
|
markPoint(screen ? screen.x : request.x, screen ? screen.y : request.y);
|
|
519
709
|
}
|
|
520
|
-
return format(args.action, envelope.result);
|
|
710
|
+
return finish(format(args.action, envelope.result));
|
|
521
711
|
},
|
|
522
712
|
});
|
|
523
713
|
|
|
@@ -546,6 +736,29 @@ function resolveSetting(value, fallback) {
|
|
|
546
736
|
return v;
|
|
547
737
|
}
|
|
548
738
|
|
|
739
|
+
/**
|
|
740
|
+
* The launch whitelist, as the gate sees it: trimmed, empties dropped, LOWER-CASED for comparison.
|
|
741
|
+
* Case-folding is a deliberate decision and it is stated here rather than left to the reader: Windows
|
|
742
|
+
* treats program names and paths case-insensitively, so a whitelist that was case-sensitive would
|
|
743
|
+
* refuse `notepad.exe` when the owner wrote `NOTEPAD.EXE` -- and an operator who is refused for a
|
|
744
|
+
* spelling difference starts adding wildcards, which is the failure this list exists to prevent.
|
|
745
|
+
* @param {any} value @returns {string[]}
|
|
746
|
+
*/
|
|
747
|
+
function normalizeAllowList(value) {
|
|
748
|
+
if (!Array.isArray(value)) return [];
|
|
749
|
+
return value.filter((x) => typeof x === 'string' && x.trim() !== '').map((x) => x.trim().toLowerCase());
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* The policy level, defaulted rather than trusted. A typo in a bundle patch (`banlanced`) must not
|
|
754
|
+
* become "full" -- the safe direction for an unparseable authorization setting is the DOWNGRADE, and
|
|
755
|
+
* `balanced` is the documented default that the README and the settings form both describe.
|
|
756
|
+
* @param {any} value @returns {'readonly'|'quiet'|'balanced'|'full'}
|
|
757
|
+
*/
|
|
758
|
+
function normalizePolicy(value) {
|
|
759
|
+
return value === 'readonly' || value === 'quiet' || value === 'full' ? value : 'balanced';
|
|
760
|
+
}
|
|
761
|
+
|
|
549
762
|
/** @param {any} value @returns {number} */
|
|
550
763
|
function clampSettle(value) {
|
|
551
764
|
const n = Number(value);
|
|
@@ -555,7 +768,7 @@ function clampSettle(value) {
|
|
|
555
768
|
|
|
556
769
|
/**
|
|
557
770
|
* @param {Record<string, any>} args
|
|
558
|
-
* @param {'hwnd'|'x'|'y'|'text'|'elementName'} key
|
|
771
|
+
* @param {'hwnd'|'x'|'y'|'text'|'elementName'|'target'} key
|
|
559
772
|
* @param {string} action
|
|
560
773
|
* @returns {void}
|
|
561
774
|
*/
|
|
@@ -675,6 +888,14 @@ function format(action, r) {
|
|
|
675
888
|
if (action === 'snapshot') return formatSnapshot(r);
|
|
676
889
|
if (action === 'screenshot') return formatScreenshot(r);
|
|
677
890
|
if (action === 'preview') return formatPreview(r);
|
|
891
|
+
// ---- 0.7.0 DESKTOP RESULTS -----------------------------------------------------------------
|
|
892
|
+
// No channel, no tier, no proof window: these actions do not choose a door and there is no
|
|
893
|
+
// disturbance for a proof to attribute. What they DO carry is a read-back of the state they changed,
|
|
894
|
+
// rendered explicitly so a caller can see the difference between "the syscall answered" and "the
|
|
895
|
+
// window is like that now".
|
|
896
|
+
if (action === 'launch') return formatLaunch(r);
|
|
897
|
+
if (action === 'clipboard') return formatClipboard(r);
|
|
898
|
+
if (action === 'window') return formatWindow(r);
|
|
678
899
|
|
|
679
900
|
// WHO REPORTED THE SUCCESS. The engine sets `effect` when a channel call RETURNS without throwing;
|
|
680
901
|
// this file never upgrades it, and the four values are not degrees of confidence in the app -- they
|
|
@@ -917,6 +1138,81 @@ function formatPreview(r) {
|
|
|
917
1138
|
});
|
|
918
1139
|
}
|
|
919
1140
|
|
|
1141
|
+
/**
|
|
1142
|
+
* Render a launch. The two facts that matter are the pid (the process exists) and whether it has
|
|
1143
|
+
* published a window yet -- and the second is reported as `window-not-yet` rather than as a failure,
|
|
1144
|
+
* because Process.Start returning while MainWindowHandle is 0 is normal (measured 1348 ms cold).
|
|
1145
|
+
* An agent that is told "started, no window yet" can poll or pick a different target; an agent that is
|
|
1146
|
+
* told "failed" when the program is running will start it again.
|
|
1147
|
+
* @param {any} r @returns {Record<string, any>}
|
|
1148
|
+
*/
|
|
1149
|
+
function formatLaunch(r) {
|
|
1150
|
+
const lines = [
|
|
1151
|
+
`launch ok: pid=${r.pid ?? '?'} name=${r.processName ?? '?'}`,
|
|
1152
|
+
`detail=${r.detail || '(none)'}`,
|
|
1153
|
+
];
|
|
1154
|
+
if (r.hwnd) lines.push(`hwnd=${r.hwnd} -- the window is addressable now; use it with action=snapshot or click`);
|
|
1155
|
+
else lines.push('hwnd=(none yet) -- the process is running but has published no top-level window; this is NOT a failure, and retrying the launch would start a second copy');
|
|
1156
|
+
if (r.note) lines.push(`note: ${r.note}`);
|
|
1157
|
+
if (r.latencyMs !== undefined) lines.push(`latencyMs=${r.latencyMs} waitedMs=${r.waitedMs ?? 0}`);
|
|
1158
|
+
return result('launch', true, '', lines.join('\n'), {
|
|
1159
|
+
pid: r.pid, hwnd: r.hwnd || '', processName: r.processName, waitedMs: r.waitedMs,
|
|
1160
|
+
effect: r.effect || 'unverified',
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
/**
|
|
1165
|
+
* Render a clipboard result. THE VALUE IS DELIBERATELY ABSENT from a text read's summary line: it is
|
|
1166
|
+
* present in the structured field the caller asked for, and the text says what it is rather than
|
|
1167
|
+
* being it -- a log line or a screenshot of this result should not become a second copy of whatever was
|
|
1168
|
+
* on the clipboard.
|
|
1169
|
+
* @param {any} r @returns {Record<string, any>}
|
|
1170
|
+
*/
|
|
1171
|
+
function formatClipboard(r) {
|
|
1172
|
+
const lines = [];
|
|
1173
|
+
if (r.clipFormat === 'image') {
|
|
1174
|
+
lines.push(`clipboard ${r.op ?? ''} ok: image size=${r.readbackSize || r.imageSize || '?'}`);
|
|
1175
|
+
if (r.file) lines.push(`file=${r.file}`);
|
|
1176
|
+
if (r.clipId) lines.push(`clipId=${r.clipId}`);
|
|
1177
|
+
if (r.shotId) lines.push(`shotId=${r.shotId}`);
|
|
1178
|
+
} else {
|
|
1179
|
+
lines.push(`clipboard ${r.op ?? ''} ok: text chars=${r.chars ?? r.readbackChars ?? '?'}`);
|
|
1180
|
+
if (r.truncated) lines.push(`truncated: the clipboard held ${r.chars} characters and the 64 KB cap applies -- the value was cut, not lost`);
|
|
1181
|
+
}
|
|
1182
|
+
lines.push(`effect=${r.effect || 'unverified'}`);
|
|
1183
|
+
if (r.latencyMs !== undefined) lines.push(`latencyMs=${r.latencyMs}`);
|
|
1184
|
+
if (r.detail) lines.push(`detail=${r.detail}`);
|
|
1185
|
+
lines.push('privacy: a clipboard READ reports its length, never its content; the audit log records op/format/length only, because the clipboard may hold a token the owner copied seconds ago');
|
|
1186
|
+
return result('clipboard', true, '', lines.join('\n'), {
|
|
1187
|
+
clipFormat: r.clipFormat, chars: r.chars, truncated: r.truncated === true,
|
|
1188
|
+
file: r.file, clipId: r.clipId, imageSize: r.imageSize, readbackSize: r.readbackSize,
|
|
1189
|
+
effect: r.effect || 'unverified',
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
/**
|
|
1194
|
+
* Render a window op. `verified` is the word the whole action is built around: the op's own read-back
|
|
1195
|
+
* (IsIconic, the rect, the ex-style) said yes, not `ShowWindow` returning true.
|
|
1196
|
+
* @param {any} r @returns {Record<string, any>}
|
|
1197
|
+
*/
|
|
1198
|
+
function formatWindow(r) {
|
|
1199
|
+
const lines = [
|
|
1200
|
+
`window ok: ${r.detail || '(no detail)'}`,
|
|
1201
|
+
`effect=${r.effect || 'unverified'}`,
|
|
1202
|
+
];
|
|
1203
|
+
if (r.latencyMs !== undefined) lines.push(`latencyMs=${r.latencyMs}`);
|
|
1204
|
+
if (r.reason) lines.push(`reason: ${r.reason}`);
|
|
1205
|
+
lines.push('verified means the WINDOW reports the state (IsIconic / the rect / WS_EX_TOPMOST), not that the syscall answered; move/resize/topmost never activate the window');
|
|
1206
|
+
return result('window', true, '', lines.join('\n'), {
|
|
1207
|
+
effect: r.effect || 'unverified', detail: r.detail,
|
|
1208
|
+
// Forwarded, not re-derived: `foregroundTaken` is the engine's measurement of GetForegroundWindow on
|
|
1209
|
+
// both sides of the call. Dropping it here would leave the claim in the prose and out of the object,
|
|
1210
|
+
// which is how a caller that reads structure ends up less informed than one that reads text.
|
|
1211
|
+
foregroundTaken: r.foregroundTaken === true,
|
|
1212
|
+
verified: /verified=true/.test(String(r.detail ?? '')),
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
|
|
920
1216
|
/** Parse an engine-emitted "x,y" point. Returns null for anything else rather than guessing 0,0. */
|
|
921
1217
|
/** @param {any} s @returns {{x: number, y: number}|null} */
|
|
922
1218
|
function parsePoint(s) {
|