dsh-windows-parallel-mcp 0.2.0 → 0.4.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 +378 -0
- package/CHANGELOG.es.md +378 -0
- package/CHANGELOG.fr.md +378 -0
- package/CHANGELOG.it.md +378 -0
- package/CHANGELOG.ja.md +378 -0
- package/CHANGELOG.ko.md +378 -0
- package/CHANGELOG.md +70 -3
- package/CHANGELOG.pt.md +378 -0
- package/CHANGELOG.ru.md +378 -0
- package/CHANGELOG.zh.md +378 -0
- package/INSTALL.de.md +126 -0
- package/INSTALL.es.md +126 -0
- package/INSTALL.fr.md +126 -0
- package/INSTALL.it.md +126 -0
- package/INSTALL.ja.md +126 -0
- package/INSTALL.ko.md +126 -0
- package/INSTALL.md +49 -11
- package/INSTALL.pt.md +126 -0
- package/INSTALL.ru.md +126 -0
- package/INSTALL.zh.md +126 -0
- package/README.de.md +275 -0
- package/README.es.md +275 -0
- package/README.fr.md +275 -0
- package/README.it.md +275 -0
- package/README.ja.md +275 -0
- package/README.ko.md +275 -0
- package/README.md +1 -0
- package/README.pt.md +275 -0
- package/README.ru.md +275 -0
- package/README.zh.md +275 -0
- package/lib/config.js +29 -1
- package/lib/engine.js +31 -4
- package/lib/host-tools.js +41 -2
- package/lib/index.js +137 -9
- package/lib/peers-schemastery.js +6 -0
- package/lib/peers-tools.js +9 -0
- package/lib/proof-window.mjs +122 -8
- package/package.json +34 -4
- package/types/index.d.ts +68 -0
package/lib/engine.js
CHANGED
|
@@ -41,6 +41,9 @@ export function workerScript(from = HERE) {
|
|
|
41
41
|
* UIAutomationClient, and it needs no installation — which is the project's only citable difference
|
|
42
42
|
* against competitors that require uv/Python or an MSVC runtime (findings.md TS-1). pwsh is accepted
|
|
43
43
|
* when the operator points at it, because it is a superset for these calls.
|
|
44
|
+
* @param {string} [explicitPath]
|
|
45
|
+
* @param {Record<string, string|undefined>} [env]
|
|
46
|
+
* @returns {string}
|
|
44
47
|
*/
|
|
45
48
|
export function resolvePowerShell(explicitPath, env = process.env) {
|
|
46
49
|
if (explicitPath && existsSync(explicitPath)) return explicitPath;
|
|
@@ -80,6 +83,7 @@ export class WorkerClient {
|
|
|
80
83
|
this.started = false;
|
|
81
84
|
this.restarts = 0;
|
|
82
85
|
/** Last stderr lines, kept because a worker that dies usually explains itself there. */
|
|
86
|
+
/** @type {string[]} */
|
|
83
87
|
this.stderrTail = [];
|
|
84
88
|
this.buffer = '';
|
|
85
89
|
}
|
|
@@ -138,11 +142,17 @@ export class WorkerClient {
|
|
|
138
142
|
return this;
|
|
139
143
|
}
|
|
140
144
|
|
|
145
|
+
/**
|
|
146
|
+
* @param {number|null} code
|
|
147
|
+
* @param {string|null} signal
|
|
148
|
+
* @returns {string}
|
|
149
|
+
*/
|
|
141
150
|
#exitMessage(code, signal) {
|
|
142
151
|
const tail = this.stderrTail.length ? ` :: ${this.stderrTail.slice(-3).join(' | ')}` : '';
|
|
143
152
|
return `engine worker exited (code=${code ?? 'null'} signal=${signal ?? 'null'})${tail}`;
|
|
144
153
|
}
|
|
145
154
|
|
|
155
|
+
/** @param {string} chunk */
|
|
146
156
|
#onStdout(chunk) {
|
|
147
157
|
this.buffer += chunk;
|
|
148
158
|
let idx;
|
|
@@ -172,6 +182,7 @@ export class WorkerClient {
|
|
|
172
182
|
}
|
|
173
183
|
}
|
|
174
184
|
|
|
185
|
+
/** @param {string} reason */
|
|
175
186
|
#failAll(reason) {
|
|
176
187
|
for (const [id, entry] of this.pending) {
|
|
177
188
|
clearTimeout(entry.timer);
|
|
@@ -183,12 +194,18 @@ export class WorkerClient {
|
|
|
183
194
|
/**
|
|
184
195
|
* Send one request and await its response object. Resolves with the whole envelope, so the caller
|
|
185
196
|
* decides what a refusal means; this layer never turns a refusal into an exception.
|
|
197
|
+
* @param {any} payload
|
|
198
|
+
* @returns {Promise<any>}
|
|
186
199
|
*/
|
|
187
200
|
request(payload) {
|
|
188
201
|
this.start();
|
|
189
202
|
const id = String(++this.seq);
|
|
190
203
|
const line = JSON.stringify({ id, ...payload }) + '\n';
|
|
191
|
-
|
|
204
|
+
// `start()` above either established a live child or threw, so this cast states a fact the
|
|
205
|
+
// method just enforced rather than suppressing an unknown. The same holds for `stdin`: this
|
|
206
|
+
// class spawns with stdio 'pipe', and narrowing it here keeps the runtime path byte-identical
|
|
207
|
+
// (a defensive `if (!stdin) throw` would add a branch that can never run).
|
|
208
|
+
const child = /** @type {import('node:child_process').ChildProcess} */ (this.child);
|
|
192
209
|
return new Promise((resolvePromise, rejectPromise) => {
|
|
193
210
|
const timer = setTimeout(() => {
|
|
194
211
|
this.pending.delete(id);
|
|
@@ -201,7 +218,11 @@ export class WorkerClient {
|
|
|
201
218
|
try { child.kill(); } catch { /* already gone */ }
|
|
202
219
|
}, this.requestTimeoutMs);
|
|
203
220
|
this.pending.set(id, { resolve: resolvePromise, reject: rejectPromise, timer });
|
|
204
|
-
|
|
221
|
+
// The cast sits at the call site rather than in a `const stdin = ...` line so the emitted
|
|
222
|
+
// JavaScript keeps exactly the statements it had: this file's shape is reviewed as a document,
|
|
223
|
+
// and a typing exercise is not allowed to restructure it. `stdin` is `Writable | null` upstream
|
|
224
|
+
// but this class always spawns with stdio 'pipe'.
|
|
225
|
+
/** @type {import('node:stream').Writable} */ (child.stdin).write(line, 'utf8', (err) => {
|
|
205
226
|
if (!err) return;
|
|
206
227
|
this.pending.delete(id);
|
|
207
228
|
clearTimeout(timer);
|
|
@@ -216,8 +237,14 @@ export class WorkerClient {
|
|
|
216
237
|
this.child = null;
|
|
217
238
|
this.#failAll('engine worker disposed');
|
|
218
239
|
if (!child) return;
|
|
219
|
-
|
|
220
|
-
|
|
240
|
+
// Cast at the call site, not into a `const`: same reason as in request() -- the statements here
|
|
241
|
+
// must stay exactly what they are. `stdin` is `Writable | null` upstream; this class always
|
|
242
|
+
// spawns with stdio 'pipe', so the cast states the invariant instead of adding a dead branch.
|
|
243
|
+
try { /** @type {import('node:stream').Writable} */ (child.stdin).end(); } catch { }
|
|
244
|
+
// The `@param` hint is what TS2810 asks for under checkJs: it wants "this resolve may be called
|
|
245
|
+
// with no argument" stated, because the promise never carries a value. Documentation only -- the
|
|
246
|
+
// emitted JavaScript is byte-identical to the unhinted form.
|
|
247
|
+
await new Promise(/** @param {(value?: void) => void} done */ (done) => {
|
|
221
248
|
const t = setTimeout(() => { try { child.kill(); } catch { } done(); }, 1500);
|
|
222
249
|
child.once('exit', () => { clearTimeout(t); done(); });
|
|
223
250
|
});
|
package/lib/host-tools.js
CHANGED
|
@@ -21,7 +21,30 @@ export const TOOL_NAME = 'wpm';
|
|
|
21
21
|
/** The five actions, in the order the contract lists them. */
|
|
22
22
|
export const ACTIONS = ['windows', 'click', 'type', 'focus', 'status'];
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* One field of the simplified parameter spec -- the shape the host's `defineTool` consumes and the
|
|
26
|
+
* shape `parametersToJsonSchema` translates. `required` is optional HERE and mandatory in the
|
|
27
|
+
* registered JSON Schema, which is the whole reason `parametersToJsonSchema` destructures it out:
|
|
28
|
+
* spelling that with a per-field object literal instead would make `field.required` a property that
|
|
29
|
+
* does not exist on most members (TS2339), i.e. the checker saying what the data already says.
|
|
30
|
+
* @typedef {object} ParamSpec
|
|
31
|
+
* @property {'string'|'number'|'boolean'} type
|
|
32
|
+
* @property {string} [description]
|
|
33
|
+
* @property {string[]} [enum]
|
|
34
|
+
* @property {boolean} [required]
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The JSON Schema this plugin registers, as `parametersToJsonSchema` builds it.
|
|
39
|
+
* @typedef {object} SimplifiedSchema
|
|
40
|
+
* @property {string} [type]
|
|
41
|
+
* @property {Record<string, ParamSpec>} [properties]
|
|
42
|
+
* @property {string[]} [required]
|
|
43
|
+
* @property {boolean} [additionalProperties]
|
|
44
|
+
*/
|
|
45
|
+
|
|
24
46
|
/** Simplified parameter spec — the same shape the host's `defineTool` consumes. */
|
|
47
|
+
/** @type {Record<string, ParamSpec>} */
|
|
25
48
|
export const PARAMETERS = {
|
|
26
49
|
action: {
|
|
27
50
|
type: 'string',
|
|
@@ -81,9 +104,13 @@ export const PARAMETERS = {
|
|
|
81
104
|
* Kept separate and exported so test/schema-test.mjs can compare the shape this plugin registers
|
|
82
105
|
* against src/schema/tools.json: the contract file is the source of truth, and a divergence between
|
|
83
106
|
* "what the model is told" and "what the registry accepts" is invisible until a call is rejected.
|
|
107
|
+
* @param {Record<string, ParamSpec>} [spec]
|
|
108
|
+
* @returns {SimplifiedSchema}
|
|
84
109
|
*/
|
|
85
110
|
export function parametersToJsonSchema(spec = PARAMETERS) {
|
|
111
|
+
/** @type {Record<string, any>} */
|
|
86
112
|
const properties = {};
|
|
113
|
+
/** @type {string[]} */
|
|
87
114
|
const required = [];
|
|
88
115
|
for (const [name, field] of Object.entries(spec)) {
|
|
89
116
|
const { required: isRequired, ...rest } = field;
|
|
@@ -93,8 +120,14 @@ export function parametersToJsonSchema(spec = PARAMETERS) {
|
|
|
93
120
|
return { type: 'object', properties, required, additionalProperties: false };
|
|
94
121
|
}
|
|
95
122
|
|
|
96
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* Minimal argument validation. Returns a list of human-readable violations, empty when valid.
|
|
125
|
+
* @param {SimplifiedSchema} schema
|
|
126
|
+
* @param {any} args
|
|
127
|
+
* @returns {string[]}
|
|
128
|
+
*/
|
|
97
129
|
export function validateArguments(schema, args) {
|
|
130
|
+
/** @type {string[]} */
|
|
98
131
|
const problems = [];
|
|
99
132
|
if (args === null || typeof args !== 'object' || Array.isArray(args)) return ['arguments must be an object'];
|
|
100
133
|
for (const name of schema.required ?? []) {
|
|
@@ -117,7 +150,12 @@ export function validateArguments(schema, args) {
|
|
|
117
150
|
return problems;
|
|
118
151
|
}
|
|
119
152
|
|
|
120
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* The local shim: same input, same registry-ready output shape.
|
|
155
|
+
* @param {{name: string, description: string, parameters: Record<string, ParamSpec>,
|
|
156
|
+
* output: {schema: any, render: any}, execute: (args: any, exec: any) => any}} options
|
|
157
|
+
* @returns {any}
|
|
158
|
+
*/
|
|
121
159
|
export function localDefineTool(options) {
|
|
122
160
|
const parameters = parametersToJsonSchema(options.parameters);
|
|
123
161
|
const userExecute = options.execute;
|
|
@@ -134,6 +172,7 @@ export function localDefineTool(options) {
|
|
|
134
172
|
// `args` makes that code path unreachable -- the abort arrives, nothing is listening, and the call
|
|
135
173
|
// runs to completion. Measured: the first version of this shim did exactly that, and test/signal-test.mjs
|
|
136
174
|
// caught it as "the cancellation was not reported" while everything else looked green.
|
|
175
|
+
/** @param {any} args @param {any} exec @returns {Promise<any>} */
|
|
137
176
|
async execute(args, exec) {
|
|
138
177
|
const problems = validateArguments(parameters, args);
|
|
139
178
|
if (problems.length) {
|
package/lib/index.js
CHANGED
|
@@ -30,6 +30,70 @@ import { WorkerClient, workerScript } from './engine.js';
|
|
|
30
30
|
import { ACTIONS, PARAMETERS, TOOL_NAME, resolveDefineTool } from './host-tools.js';
|
|
31
31
|
import { evaluateProof } from './proof-window.mjs';
|
|
32
32
|
|
|
33
|
+
// ---- THE PUBLIC CONTRACT IS THE SOURCE OF TRUTH, AND THIS FILE IS CHECKED AGAINST IT ----------
|
|
34
|
+
//
|
|
35
|
+
// types/index.d.ts is what a consumer imports and what `scripts/check-types.mjs` proves a strict
|
|
36
|
+
// client accepts. The typedef block below IMPORTS that same file, so the annotations in this
|
|
37
|
+
// implementation are checked against the shipped promise rather than against a private copy of it:
|
|
38
|
+
// rename a field in types/index.d.ts and `scripts/check-jsdoc.mjs` turns this file red. That
|
|
39
|
+
// direction is the whole point -- a generated .d.ts (what a TypeScript rewrite would emit here) has
|
|
40
|
+
// no `WpmAction`/`RefusalCode`/`WpmArgs` at all, so it could not do this.
|
|
41
|
+
//
|
|
42
|
+
// (The first version of this block used `// @typedef` lines. Those are comments, not JSDoc: nothing
|
|
43
|
+
// was declared, and the checker answered "Cannot find name 'WpmArgs'". A JSDoc block is required.)
|
|
44
|
+
/**
|
|
45
|
+
* @typedef {import('../types/index.d.ts').WpmAction} WpmAction
|
|
46
|
+
* @typedef {import('../types/index.d.ts').WpmArgs} WpmArgs
|
|
47
|
+
* @typedef {import('../types/index.d.ts').RefusalCode} RefusalCode
|
|
48
|
+
* @typedef {import('../types/index.d.ts').WpmResult} WpmResult
|
|
49
|
+
* @typedef {import('../types/index.d.ts').WpmExec} WpmExec
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The settings object `apply` derives from the Cordis config. Spelled out because the config VALUE is
|
|
54
|
+
* `{}` at the type level -- config.js validates it at runtime, and a validator's output is not a
|
|
55
|
+
* static fact -- so without this every one of the ten reads under `apply` reports "does not exist on
|
|
56
|
+
* type '{}'". The property list here must match `FIELDS` in config.js; both are checked by
|
|
57
|
+
* test/plugin-test.mjs.
|
|
58
|
+
* @typedef {object} WpmSettings
|
|
59
|
+
* @property {boolean} enabled
|
|
60
|
+
* @property {number} settleMs
|
|
61
|
+
* @property {number} requestTimeoutMs
|
|
62
|
+
* @property {string} powershellPath
|
|
63
|
+
* @property {boolean} overlay
|
|
64
|
+
* @property {boolean} logWorkerStderr
|
|
65
|
+
* @property {boolean} takeoverAllowed
|
|
66
|
+
* @property {boolean} keyInjectAllowed
|
|
67
|
+
* @property {number} takeoverMaxMs
|
|
68
|
+
* @property {number} takeoverArmMs
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A refusal thrown before the worker is reached. The two extra fields are the whole point: the caller
|
|
73
|
+
* path reads `err.refusal` for the code and `err.reason` for the sentence, so typing this as a plain
|
|
74
|
+
* `Error` would lose the vocabulary that makes a refusal actionable.
|
|
75
|
+
* @typedef {Error & {refusal?: RefusalCode, reason?: string}} WpmError
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* One worker envelope, as engine.js documents it. `result` is deliberately `any`: its shape is the
|
|
80
|
+
* PowerShell engine's JSON-lines protocol, and pretending to type it from this side would be the
|
|
81
|
+
* "type safety over half the system" mistake in miniature.
|
|
82
|
+
* @typedef {object} Envelope
|
|
83
|
+
* @property {boolean} [ok]
|
|
84
|
+
* @property {string} [error]
|
|
85
|
+
* @property {any} [result]
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The Cordis context surface this plugin touches, and nothing more. `logger` is optional everywhere it
|
|
90
|
+
* is used (`logger.warn?.(...)`) because a host that supplies no logger must still work.
|
|
91
|
+
* @typedef {object} CordisContext
|
|
92
|
+
* @property {{register: (tool: any) => void}} tools
|
|
93
|
+
* @property {{info?: (m: string) => void, warn?: (m: string) => void}} [logger]
|
|
94
|
+
* @property {(event: string, fn: () => void) => void} [on]
|
|
95
|
+
*/
|
|
96
|
+
|
|
33
97
|
/** Stable Cordis plugin name (this is what a profile entry points at). */
|
|
34
98
|
export const name = 'windows-parallel';
|
|
35
99
|
|
|
@@ -60,8 +124,12 @@ export const toolHelperSource = resolvedTools.source;
|
|
|
60
124
|
* Register the tool. `apply` is the whole host half; there is no client half yet, which is
|
|
61
125
|
* deliberate: the overlay / pill / hotkey layer is task_54 and gets its own commit. A plugin with a
|
|
62
126
|
* working tool and no UI is usable; a plugin with UI and no working tool is a demo.
|
|
127
|
+
* @param {CordisContext} ctx
|
|
128
|
+
* @param {Record<string, any>} [config]
|
|
129
|
+
* @returns {void}
|
|
63
130
|
*/
|
|
64
131
|
export function apply(ctx, config = {}) {
|
|
132
|
+
/** @type {WpmSettings} */
|
|
65
133
|
const settings = {
|
|
66
134
|
enabled: resolveSetting(config.enabled, true),
|
|
67
135
|
settleMs: resolveSetting(config.settleMs, 350),
|
|
@@ -89,6 +157,7 @@ export function apply(ctx, config = {}) {
|
|
|
89
157
|
// make the README's "AI cursor is a click-through overlay" claim silently untrue.
|
|
90
158
|
// Cost measured over the real worker protocol (.tmp/worker-overlay.mjs): start ~875ms once,
|
|
91
159
|
// marker 19ms, status 15ms, stop ~660ms.
|
|
160
|
+
/** @type {Promise<any>|null} */
|
|
92
161
|
let overlayReady = null;
|
|
93
162
|
let overlayWarned = false;
|
|
94
163
|
const ensureOverlay = () => {
|
|
@@ -122,6 +191,7 @@ export function apply(ctx, config = {}) {
|
|
|
122
191
|
* retried. A promise with a race window is a promise that loses the race sometimes. The deadline
|
|
123
192
|
* is BOUNDED and a confirmed-dead start (a reason with starting=false) stops the loop immediately
|
|
124
193
|
* and warns -- endless patience would just hide a broken surface.
|
|
194
|
+
* @param {number} x @param {number} y @returns {void}
|
|
125
195
|
*/
|
|
126
196
|
const markPoint = (x, y) => {
|
|
127
197
|
if (!settings.overlay || !Number.isFinite(x) || !Number.isFinite(y)) return;
|
|
@@ -178,6 +248,7 @@ export function apply(ctx, config = {}) {
|
|
|
178
248
|
* Two channels because one of them is a local file write that cannot be lost to a wedged loop.
|
|
179
249
|
*/
|
|
180
250
|
const activeLatches = new Set();
|
|
251
|
+
/** @param {WpmExec|undefined} exec @returns {() => void} */
|
|
181
252
|
const armAbort = (exec) => {
|
|
182
253
|
const signal = exec?.signal;
|
|
183
254
|
if (!signal || typeof signal.addEventListener !== 'function') return () => {};
|
|
@@ -200,6 +271,7 @@ export function apply(ctx, config = {}) {
|
|
|
200
271
|
const { defineTool } = resolvedTools;
|
|
201
272
|
|
|
202
273
|
/** Build the worker request for one action. Throws for arguments the action cannot use. */
|
|
274
|
+
/** @param {WpmArgs} args @returns {any} */
|
|
203
275
|
function toRequest(args) {
|
|
204
276
|
const settleMs = clampSettle(args.settleMs ?? settings.settleMs);
|
|
205
277
|
// The takeover fields are attached ONLY when the caller asked for them AND the gate is open. When a
|
|
@@ -228,7 +300,12 @@ export function apply(ctx, config = {}) {
|
|
|
228
300
|
requireArg(args, 'hwnd', 'click');
|
|
229
301
|
requireArg(args, 'x', 'click');
|
|
230
302
|
requireArg(args, 'y', 'click');
|
|
231
|
-
|
|
303
|
+
// The two casts state what `requireArg` just enforced: `WpmArgs.x/y` are optional in the
|
|
304
|
+
// public contract (click requires them, windows does not), and the guard above is the only
|
|
305
|
+
// thing that narrows them. A checker cannot see through a separate function's throw, so this
|
|
306
|
+
// is where the guarantee is recorded -- not a suppression, since requireArg throws for both
|
|
307
|
+
// undefined and null before this line is reached.
|
|
308
|
+
return { action: 'click', hwnd: args.hwnd, x: Math.round(/** @type {number} */ (args.x)), y: Math.round(/** @type {number} */ (args.y)), settleMs, ...takeoverFields };
|
|
232
309
|
case 'type':
|
|
233
310
|
requireArg(args, 'hwnd', 'type');
|
|
234
311
|
if (typeof args.text !== 'string' || args.text.length === 0) {
|
|
@@ -278,8 +355,14 @@ export function apply(ctx, config = {}) {
|
|
|
278
355
|
text: { type: 'string', required: true },
|
|
279
356
|
},
|
|
280
357
|
},
|
|
281
|
-
|
|
358
|
+
// `WpmResult.text` is optional in the public contract (a consumer may hold a partial object),
|
|
359
|
+
// but every value that reaches this render is built by `result()` below, which always sets it.
|
|
360
|
+
// The cast records that invariant instead of substituting '' -- an empty string would be a
|
|
361
|
+
// rendered blank, and the text IS the product here.
|
|
362
|
+
/** @param {WpmArgs} _args @param {WpmResult} value @returns {Array<{type: string, text: string}>} */
|
|
363
|
+
render: (_args, value) => [{ type: 'text', text: /** @type {string} */ (value.text) }],
|
|
282
364
|
},
|
|
365
|
+
/** @param {WpmArgs} args @param {WpmExec|undefined} exec @returns {Promise<Record<string, any>>} */
|
|
283
366
|
async execute(args, exec) {
|
|
284
367
|
// Server-side gates first: a paused or disabled engine must refuse before it spends a worker
|
|
285
368
|
// call, and the refusal must name the gate rather than describe a symptom.
|
|
@@ -308,8 +391,14 @@ export function apply(ctx, config = {}) {
|
|
|
308
391
|
try {
|
|
309
392
|
request = toRequest(args);
|
|
310
393
|
} catch (err) {
|
|
311
|
-
|
|
312
|
-
|
|
394
|
+
// `catch` binds `unknown` under strict, which is correct: anything can be thrown. The casts
|
|
395
|
+
// are the narrowing step, kept INLINE so the statements and local names below are exactly what
|
|
396
|
+
// they were -- `scripts`-level AST comparison against the previous revision is a gate here, and
|
|
397
|
+
// a rename would make a comment-only change look like a behaviour change. Safe on this path
|
|
398
|
+
// because the only thrower is `refusal()` above; the `??` fallbacks still keep the vocabulary
|
|
399
|
+
// intact when it is not.
|
|
400
|
+
const code = /** @type {WpmError} */ (err)?.refusal ?? 'action_failed';
|
|
401
|
+
return result(args.action, false, code, /** @type {WpmError} */ (err)?.reason ?? String(/** @type {WpmError} */ (err)?.message ?? err));
|
|
313
402
|
}
|
|
314
403
|
let envelope;
|
|
315
404
|
const disarm = request.takeover ? armAbort(exec) : () => {};
|
|
@@ -318,7 +407,11 @@ export function apply(ctx, config = {}) {
|
|
|
318
407
|
} catch (err) {
|
|
319
408
|
// The worker layer failed (crash, timeout, missing engine). This is not a refusal code: the
|
|
320
409
|
// engine never got to decide. Say exactly that instead of borrowing a code it does not own.
|
|
321
|
-
|
|
410
|
+
// Cast inline for the same reason as above. No `String(...)` wrapper and no `?.` are added:
|
|
411
|
+
// the original read `err.message` directly, and a non-Error thrown here still renders the
|
|
412
|
+
// same way it always did -- widening the expression would be a behaviour change dressed as
|
|
413
|
+
// type safety, which is exactly what this file refuses to do.
|
|
414
|
+
return result(args.action, false, 'action_failed', `engine worker unavailable: ${/** @type {Error} */ (err).message}`);
|
|
322
415
|
} finally {
|
|
323
416
|
disarm();
|
|
324
417
|
}
|
|
@@ -354,6 +447,7 @@ export function apply(ctx, config = {}) {
|
|
|
354
447
|
// ---- small helpers ---------------------------------------------------------------------------
|
|
355
448
|
|
|
356
449
|
/** A Cordis settings value may be a live ref (0.1.7+) or a plain value (older lines). */
|
|
450
|
+
/** @param {any} value @param {any} fallback @returns {any} */
|
|
357
451
|
function resolveSetting(value, fallback) {
|
|
358
452
|
if (value === undefined || value === null) return fallback;
|
|
359
453
|
const v = typeof value.get === 'function' ? value.get() : value;
|
|
@@ -361,26 +455,49 @@ function resolveSetting(value, fallback) {
|
|
|
361
455
|
return v;
|
|
362
456
|
}
|
|
363
457
|
|
|
458
|
+
/** @param {any} value @returns {number} */
|
|
364
459
|
function clampSettle(value) {
|
|
365
460
|
const n = Number(value);
|
|
366
461
|
if (!Number.isFinite(n)) return 350;
|
|
367
462
|
return Math.max(0, Math.min(2000, Math.round(n)));
|
|
368
463
|
}
|
|
369
464
|
|
|
465
|
+
/**
|
|
466
|
+
* @param {Record<string, any>} args
|
|
467
|
+
* @param {'hwnd'|'x'|'y'|'text'|'elementName'} key
|
|
468
|
+
* @param {string} action
|
|
469
|
+
* @returns {void}
|
|
470
|
+
*/
|
|
370
471
|
function requireArg(args, key, action) {
|
|
371
472
|
if (args[key] === undefined || args[key] === null || args[key] === '') {
|
|
372
473
|
throw refusal('no_hwnd', `action=${action} requires '${key}'`);
|
|
373
474
|
}
|
|
374
475
|
}
|
|
375
476
|
|
|
376
|
-
/**
|
|
477
|
+
/**
|
|
478
|
+
* A refusal thrown before the worker is reached; caught by the caller path that renders results.
|
|
479
|
+
* @param {RefusalCode} code
|
|
480
|
+
* @param {string} reason
|
|
481
|
+
* @returns {WpmError}
|
|
482
|
+
*/
|
|
377
483
|
function refusal(code, reason) {
|
|
378
|
-
|
|
484
|
+
// The cast is the definition of this function's payload: a plain Error plus the two fields the
|
|
485
|
+
// caller path reads. Writing it after construction (rather than using a subclass) keeps `instanceof
|
|
486
|
+
// Error` true for the host, which is what the catch sites rely on.
|
|
487
|
+
const err = /** @type {WpmError} */ (new Error(`${code}: ${reason}`));
|
|
379
488
|
err.refusal = code;
|
|
380
489
|
err.reason = reason;
|
|
381
490
|
return err;
|
|
382
491
|
}
|
|
383
492
|
|
|
493
|
+
/**
|
|
494
|
+
* @param {string} action
|
|
495
|
+
* @param {boolean} ok
|
|
496
|
+
* @param {RefusalCode|''} refusalCode
|
|
497
|
+
* @param {string} text
|
|
498
|
+
* @param {Record<string, any>} [extra]
|
|
499
|
+
* @returns {Record<string, any>}
|
|
500
|
+
*/
|
|
384
501
|
function result(action, ok, refusalCode, text, extra) {
|
|
385
502
|
return { action, ok, refusal: refusalCode, text: refusalCode ? `${refusalCode}: ${text}` : text, ...(extra || {}) };
|
|
386
503
|
}
|
|
@@ -391,6 +508,9 @@ function result(action, ok, refusalCode, text, extra) {
|
|
|
391
508
|
* The text is the product. A caller that gets `ok:false` with a code and a reason can act; a caller
|
|
392
509
|
* that gets "the action failed" cannot. Every number reported here is measured by the engine, not
|
|
393
510
|
* inferred by this file.
|
|
511
|
+
* @param {string} action
|
|
512
|
+
* @param {any} r
|
|
513
|
+
* @returns {Record<string, any>}
|
|
394
514
|
*/
|
|
395
515
|
function format(action, r) {
|
|
396
516
|
if (!r) return result(action, false, 'action_failed', 'engine returned no result');
|
|
@@ -400,7 +520,7 @@ function format(action, r) {
|
|
|
400
520
|
if (list.length === 0) {
|
|
401
521
|
return result(action, true, '', 'no drivable windows are visible right now (minimised and untitled windows are excluded by design)');
|
|
402
522
|
}
|
|
403
|
-
const lines = list.map((w) => `${w.hwnd} ${truncate(String(w.title), 60)} [${w.cls}] pid=${w.pid} rect=${w.rect}`);
|
|
523
|
+
const lines = list.map(/** @param {any} w @returns {string} */ (w) => `${w.hwnd} ${truncate(String(w.title), 60)} [${w.cls}] pid=${w.pid} rect=${w.rect}`);
|
|
404
524
|
return result(action, true, '', `${list.length} drivable window(s):\n${lines.join('\n')}`);
|
|
405
525
|
}
|
|
406
526
|
|
|
@@ -433,7 +553,11 @@ function format(action, r) {
|
|
|
433
553
|
}
|
|
434
554
|
|
|
435
555
|
// Action results. `refusal` is the engine's own code: an empty string means the action ran.
|
|
436
|
-
|
|
556
|
+
// The cast leans on `scripts/check-refusals.mjs`, which pins the engine's emitted codes to the
|
|
557
|
+
// closed set in src/schema/tools.json: the wire format is a string, but the vocabulary is a
|
|
558
|
+
// contract that another gate already enforces. Typing this as plain `string` would push the check
|
|
559
|
+
// to every call site; typing it as `RefusalCode` names where the guarantee actually comes from.
|
|
560
|
+
const code = r.refusal ? /** @type {RefusalCode} */ (String(r.refusal)) : '';
|
|
437
561
|
if (code) {
|
|
438
562
|
const reason = r.reason ? ` (${r.reason})` : '';
|
|
439
563
|
// A takeover refusal still carries the takeover accounting: "aborted after 12 characters, cursor
|
|
@@ -520,11 +644,13 @@ function format(action, r) {
|
|
|
520
644
|
});
|
|
521
645
|
}
|
|
522
646
|
|
|
647
|
+
/** @param {string} s @param {number} n @returns {string} */
|
|
523
648
|
function truncate(s, n) {
|
|
524
649
|
return s.length <= n ? s : `${s.slice(0, n - 1)}…`;
|
|
525
650
|
}
|
|
526
651
|
|
|
527
652
|
/** Clamp a possibly-undefined number into [min,max], falling back to `fallback` for non-numbers. */
|
|
653
|
+
/** @param {any} value @param {number} min @param {number} max @param {number} fallback @returns {number} */
|
|
528
654
|
function clampNumber(value, min, max, fallback) {
|
|
529
655
|
const n = Number(value);
|
|
530
656
|
if (!Number.isFinite(n)) return fallback;
|
|
@@ -532,12 +658,14 @@ function clampNumber(value, min, max, fallback) {
|
|
|
532
658
|
}
|
|
533
659
|
|
|
534
660
|
/** The same latch path the engine computes: %LOCALAPPDATA%\wpm\takeover-abort.<worker pid>. */
|
|
661
|
+
/** @param {number|string} pid @returns {string} */
|
|
535
662
|
function abortLatchPath(pid) {
|
|
536
663
|
const base = process.env.LOCALAPPDATA || tmpdir();
|
|
537
664
|
return join(base, 'wpm', `takeover-abort.${pid}`);
|
|
538
665
|
}
|
|
539
666
|
|
|
540
667
|
/** A one-line target hint for a pre-worker refusal: the caller can retry without the field. */
|
|
668
|
+
/** @param {WpmArgs} args @returns {string} */
|
|
541
669
|
function hwndHint(args) {
|
|
542
670
|
return args.hwnd ? ` (target hwnd=${args.hwnd})` : '';
|
|
543
671
|
}
|
package/lib/peers-schemastery.js
CHANGED
|
@@ -12,6 +12,12 @@
|
|
|
12
12
|
// combined bridge module would mean the missing dsh-tools throws during evaluation and takes
|
|
13
13
|
// schemastery down with it -- the plugin would fail to LOAD, which is worse than the shim path it
|
|
14
14
|
// was meant to fix. Two files, two independent failure domains.
|
|
15
|
+
// @ts-nocheck -- DELIBERATE, same reasoning as peers-tools.js: `@deepseek-ai/schemastery` is a
|
|
16
|
+
// cordis dependency the HOST supplies, and whatever type surface a checker resolves for it here is a
|
|
17
|
+
// property of THIS machine's checkout, not of the package. `z` below is deliberately the shape-agnostic
|
|
18
|
+
// handoff into config.js; pinning it to one installed version's `.default` export would turn a
|
|
19
|
+
// host-version difference into a false red. The barrier is the point.
|
|
20
|
+
// @ts-nocheck
|
|
15
21
|
import schemasteryNs from '@deepseek-ai/schemastery';
|
|
16
22
|
|
|
17
23
|
export const z = schemasteryNs?.default ?? schemasteryNs;
|
package/lib/peers-tools.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
// peers-tools.js -- the host's defineTool, reached through a STATIC import. See peers-schemastery.js
|
|
2
2
|
// for why the bridge is split in two and why a dynamic bare specifier does not resolve for a
|
|
3
3
|
// `link:`-installed package.
|
|
4
|
+
//
|
|
5
|
+
// @ts-nocheck -- DELIBERATE, and the only honest option. `@deepseek-ai/dsh-tools` is a peer the HOST
|
|
6
|
+
// provides; it is not installed in this checkout, so a type checker can only see an unresolved module
|
|
7
|
+
// here. The alternatives are both lies: a `declare module` stub would assert a shape nobody verified
|
|
8
|
+
// against the real package (and this file exists precisely because peer resolution is unpredictable),
|
|
9
|
+
// while dropping the file from the check config makes its IMPORTER fail with TS2307 -- a gate
|
|
10
|
+
// inventing a problem of its own. The barrier is the point: everything downstream of this import is
|
|
11
|
+
// untyped on purpose, and this line says so where a reader will see it.
|
|
12
|
+
// @ts-nocheck
|
|
4
13
|
import * as toolsNs from '@deepseek-ai/dsh-tools';
|
|
5
14
|
|
|
6
15
|
export const defineTool = toolsNs.defineTool;
|