dsh-windows-parallel-mcp 0.3.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 +5 -1
- package/CHANGELOG.es.md +5 -1
- package/CHANGELOG.fr.md +5 -1
- package/CHANGELOG.it.md +5 -1
- package/CHANGELOG.ja.md +5 -1
- package/CHANGELOG.ko.md +5 -1
- package/CHANGELOG.md +43 -3
- package/CHANGELOG.pt.md +5 -1
- package/CHANGELOG.ru.md +5 -1
- package/CHANGELOG.zh.md +5 -1
- 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 +3 -2
package/CHANGELOG.de.md
CHANGED
|
@@ -8,7 +8,11 @@ Dates are the registry `time` values for each version, not git commit dates —
|
|
|
8
8
|
when someone typed, a publish time records when a version became installable, and only the second
|
|
9
9
|
one is a promise to anyone installing it.
|
|
10
10
|
|
|
11
|
-
## 0.
|
|
11
|
+
## 0.4.0 — 2026-11-23
|
|
12
|
+
|
|
13
|
+
> Keine Laufzeitänderung: die ganze Arbeit macht die Aussage „dieser Kommentar ist wahr" maschinell überprüfbar. `lib/` vollständig mit JSDoc versehen und unter checkJs geprüft (107 Fehler → 0), die handgeschriebene `types/index.d.ts` wird zur einzigen Wahrheitsquelle auf Implementierungsseite (eine Änderung dort macht rot), und die Unverändertheit des Codes ist Knoten für Knoten belegt (identische ASTs). Zwei echte Instabilitätsursachen im Testaufbau behoben (Wettlauf um das Pre-Layout-Orakel, verdecktes Ziel-Fenster). Keine neue Abhängigkeit. Siehe englischen Eintrag.
|
|
14
|
+
|
|
15
|
+
## 0.3.0 — 2026-11-23
|
|
12
16
|
|
|
13
17
|
> Zehn Sprachen und eine typisierte öffentliche Oberfläche. Die Dokumentation erscheint in den zehn DSH-Ökosystemsprachen, Deutsch als gleichrangiger Wechsel neben Englisch. Zwei Installationsfälle: desktop (nur integriertes pnpm, nie `dsh plugin add`) und nicht-desktop. `types/index.d.ts` hinzugefügt. Siehe englischen Eintrag.
|
|
14
18
|
|
package/CHANGELOG.es.md
CHANGED
|
@@ -8,7 +8,11 @@ Dates are the registry `time` values for each version, not git commit dates —
|
|
|
8
8
|
when someone typed, a publish time records when a version became installable, and only the second
|
|
9
9
|
one is a promise to anyone installing it.
|
|
10
10
|
|
|
11
|
-
## 0.
|
|
11
|
+
## 0.4.0 — 2026-11-23
|
|
12
|
+
|
|
13
|
+
> Sin cambios en tiempo de ejecución: todo el trabajo hace verificable por máquina la afirmación «este comentario es cierto». `lib/` totalmente anotado y comprobado con checkJs (107 errores → 0), el `types/index.d.ts` escrito a mano pasa a ser la única fuente de verdad en el lado de la implementación (cambiarlo lo pone en rojo), y la ausencia de cambios en el código se demuestra nodo a nodo (AST idénticos). Corregidas dos causas reales de inestabilidad del banco de pruebas (carrera del oráculo pre-layout, ventana objetivo tapada). Sin dependencias nuevas. Véase la entrada en inglés.
|
|
14
|
+
|
|
15
|
+
## 0.3.0 — 2026-11-23
|
|
12
16
|
|
|
13
17
|
> Diez idiomas y una superficie pública tipada. Los documentos se publican en los diez idiomas del ecosistema DSH, con el español como cambio de primer nivel junto al inglés. Dos casos de instalación: desktop (solo pnpm integrado, nunca `dsh plugin add`) y no-desktop. Añadido `types/index.d.ts`. Véase la entrada en inglés.
|
|
14
18
|
|
package/CHANGELOG.fr.md
CHANGED
|
@@ -8,7 +8,11 @@ Dates are the registry `time` values for each version, not git commit dates —
|
|
|
8
8
|
when someone typed, a publish time records when a version became installable, and only the second
|
|
9
9
|
one is a promise to anyone installing it.
|
|
10
10
|
|
|
11
|
-
## 0.
|
|
11
|
+
## 0.4.0 — 2026-11-23
|
|
12
|
+
|
|
13
|
+
> Aucun changement d'exécution : tout le travail sert à rendre vérifiable par la machine l'affirmation « ce commentaire est vrai ». `lib/` entièrement annoté et contrôlé sous checkJs (107 erreurs → 0), le `types/index.d.ts` écrit à la main devient la source unique de vérité côté implémentation (le modifier le passe au rouge), et l'absence de changement de code est prouvée nœud par nœud (AST identiques). Deux causes réelles d'instabilité du banc de test corrigées (course sur l'oracle pré-layout, fenêtre cible masquée). Aucune nouvelle dépendance. Voir l'entrée anglaise.
|
|
14
|
+
|
|
15
|
+
## 0.3.0 — 2026-11-23
|
|
12
16
|
|
|
13
17
|
> Dix langues et une surface publique typée. Les documents sont publiés dans les dix langues de l'écosystème DSH, avec le français en bascule de premier rang à côté de l'anglais. L'installation distingue exactement deux cas : desktop (pnpm intégré uniquement, jamais `dsh plugin add`) et non-desktop. `types/index.d.ts` ajouté. Voir l'entrée anglaise.
|
|
14
18
|
|
package/CHANGELOG.it.md
CHANGED
|
@@ -8,7 +8,11 @@ Dates are the registry `time` values for each version, not git commit dates —
|
|
|
8
8
|
when someone typed, a publish time records when a version became installable, and only the second
|
|
9
9
|
one is a promise to anyone installing it.
|
|
10
10
|
|
|
11
|
-
## 0.
|
|
11
|
+
## 0.4.0 — 2026-11-23
|
|
12
|
+
|
|
13
|
+
> Nessun cambiamento a runtime: tutto il lavoro rende verificabile dalla macchina l'affermazione «questo commento è vero». `lib/` interamente annotato e controllato con checkJs (107 errori → 0), il `types/index.d.ts` scritto a mano diventa l'unica fonte di verità lato implementazione (modificarlo lo fa diventare rosso), e l'assenza di modifiche al codice è dimostrata nodo per nodo (AST identici). Corrette due cause reali di instabilità del banco di prova (corsa sull'oracolo pre-layout, finestra bersaglio coperta). Nessuna nuova dipendenza. Vedi la voce inglese.
|
|
14
|
+
|
|
15
|
+
## 0.3.0 — 2026-11-23
|
|
12
16
|
|
|
13
17
|
> Dieci lingue e una superficie pubblica tipizzata. I documenti sono pubblicati nelle dieci lingue dell'ecosistema DSH, con l'italiano come opzione di primo livello accanto all'inglese. Due casi di installazione: desktop (solo pnpm integrato, mai `dsh plugin add`) e non-desktop. Aggiunto `types/index.d.ts`. Vedi la voce inglese.
|
|
14
18
|
|
package/CHANGELOG.ja.md
CHANGED
|
@@ -8,7 +8,11 @@ Dates are the registry `time` values for each version, not git commit dates —
|
|
|
8
8
|
when someone typed, a publish time records when a version became installable, and only the second
|
|
9
9
|
one is a promise to anyone installing it.
|
|
10
10
|
|
|
11
|
-
## 0.
|
|
11
|
+
## 0.4.0 — 2026-11-23
|
|
12
|
+
|
|
13
|
+
> 実行時の変更はゼロ。作業のすべては「このコメントは正しい」を機械で検証可能にすることに使われました。`lib/` 全体を JSDoc + checkJs で検査(107 エラー → 0)、手書きの `types/index.d.ts` が実装側の唯一の真実源になり(変更すれば赤くなる)、コード未変更は AST のノード単位比較で証明。テスト側の不安定要因2件(pre-layout oracle 競合、対象ウィンドウの遮蔽)も修正。新しい依存はゼロ。詳細は英語版参照。
|
|
14
|
+
|
|
15
|
+
## 0.3.0 — 2026-11-23
|
|
12
16
|
|
|
13
17
|
> 10言語と型付き公開インターフェース。ドキュメントは DSH エコシステムの10言語で提供され、日本語は英語と並ぶ一等スイッチです。インストールは desktop / 非desktop の2通り(desktop は内蔵 pnpm のみ手動、dsh plugin add 禁止)。types/index.d.ts を追加。詳細は英語版参照。
|
|
14
18
|
|
package/CHANGELOG.ko.md
CHANGED
|
@@ -8,7 +8,11 @@ Dates are the registry `time` values for each version, not git commit dates —
|
|
|
8
8
|
when someone typed, a publish time records when a version became installable, and only the second
|
|
9
9
|
one is a promise to anyone installing it.
|
|
10
10
|
|
|
11
|
-
## 0.
|
|
11
|
+
## 0.4.0 — 2026-11-23
|
|
12
|
+
|
|
13
|
+
> 런타임 변경은 없습니다. 모든 작업은 "이 주석은 사실이다"를 기계가 검증할 수 있게 만드는 데 쓰였습니다. `lib/` 전체를 JSDoc + checkJs로 검사(107 오류 → 0), 수기 `types/index.d.ts`가 구현 측 단일 진실 원천이 되고(바꾸면 빨개짐), 코드 미변경은 AST 노드 단위 비교로 증명. 테스트 불안정 원인 2건(pre-layout oracle 경합, 대상 창 가림)도 수정. 새 의존성 없음. 자세한 내용은 영문 항목 참조.
|
|
14
|
+
|
|
15
|
+
## 0.3.0 — 2026-11-23
|
|
12
16
|
|
|
13
17
|
> 10개 언어와 타입 공개 인터페이스. 문서는 DSH 생태계 10개 언어로 제공되며 한국어는 영어와 나란한 1등 전환입니다. 설치는 desktop / 비desktop 두 경우(desktop은 내장 pnpm으로만 수동, dsh plugin add 금지). types/index.d.ts 추가. 자세한 내용은 영문 항목 참조.
|
|
14
18
|
|
package/CHANGELOG.md
CHANGED
|
@@ -5,10 +5,50 @@ Dates are the registry `time` values for each version, not git commit dates —
|
|
|
5
5
|
when someone typed, a publish time records when a version became installable, and only the second
|
|
6
6
|
one is a promise to anyone installing it.
|
|
7
7
|
|
|
8
|
-
## 0.
|
|
8
|
+
## 0.4.0 — 2026-11-23
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
**Nothing about the plugin changed; everything about proving it did.** 0.4.0 has no runtime change at
|
|
11
|
+
all -- the seven files under `lib/` differ from 0.3.0 by comments and JSDoc only, and that is verified
|
|
12
|
+
node by node against the previous revision (identical abstract syntax trees, 6739 nodes in `index.js`,
|
|
13
|
+
2625 in `engine.js`, 3154 in `proof-window.mjs`), not asserted in a commit message. What it adds is the
|
|
14
|
+
machinery that turns "this comment is true" into a gate instead of a promise.
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- `tsconfig.checkjs.json` + `scripts/check-jsdoc.mjs`: the whole of `lib/` is checked under
|
|
18
|
+
`allowJs + checkJs + strict`. 107 errors before the annotations, 0 after. No new dependency: the
|
|
19
|
+
compiler is the workspace's own, and no `@types` path is written into a repo file -- it is derived
|
|
20
|
+
from where the compiler was found, so a machine without one gets a NAMED SKIP, never a red gate that
|
|
21
|
+
really means "this box lacks tsc".
|
|
22
|
+
- The hand-written `types/index.d.ts` is now the source of truth for the implementation as well: the
|
|
23
|
+
`lib/` annotations `import()` it, so renaming a field there turns `lib/index.js` red. Verified by
|
|
24
|
+
doing exactly that (2 errors) and reverting.
|
|
25
|
+
- `scripts/find-tsc.mjs`: the compiler search that `check-types.mjs` and `check-jsdoc.mjs` share, so the
|
|
26
|
+
two gates can never disagree about which compiler they tested against.
|
|
27
|
+
- `lib/peers-tools.js` and `lib/peers-schemastery.js` carry `// @ts-nocheck` with the reason written
|
|
28
|
+
down: they are the host-peer boundary, and a stub type there would assert a shape nobody verified.
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
- `test/uia-click-target.ps1` wrote an oracle BEFORE `ShowDialog()`, when `ActualWidth` is still 0 and
|
|
32
|
+
`PointToScreen` throws. The catch-all wrote `{-1,-1}` and the reader accepted the first parseable
|
|
33
|
+
snapshot, so on a loaded machine the arm reported four failures that looked like product defects.
|
|
34
|
+
The pre-show write is gone; the reader now only accepts a snapshot whose both centres are real.
|
|
35
|
+
- That same target came up with `Topmost="False"`, so it could sit BEHIND whatever held the foreground
|
|
36
|
+
and the engine's element probe correctly found a foreign window:
|
|
37
|
+
`unreachable ... the element under that point does not belong to the target window`. That refusal was
|
|
38
|
+
the product behaving properly -- a covered window SHOULD be refused -- and the harness was asserting
|
|
39
|
+
against a window it had never put on top. Fixed in the harness, not in the engine.
|
|
40
|
+
|
|
41
|
+
### Verification
|
|
42
|
+
- 16 gates, `GATE GREEN` on three consecutive runs.
|
|
43
|
+
- Desktop suites: hud 24/24, takeover 25/25, keyinject 11 with one named skip (host-managed terminal),
|
|
44
|
+
signal 6/6, overlay 16/16, marker 10/10.
|
|
45
|
+
- `uia-click-truth` 11 consecutive green runs after the two harness fixes; before them, 3 of 5 failed.
|
|
46
|
+
- Zero install dependencies unchanged: `dependencies` and `devDependencies` are still absent, and
|
|
47
|
+
`clone && install` still needs no toolchain.
|
|
48
|
+
|
|
49
|
+
## 0.3.0 — 2026-11-23
|
|
50
|
+
|
|
51
|
+
> Published 2026-11-23T09:21:29.737Z (registry `time` for 0.3.0, read from the packument, not from a commit date).
|
|
12
52
|
|
|
13
53
|
**Ten languages, and a typed public surface.** 0.2.0 was the capability release; 0.3.0 is the
|
|
14
54
|
reachability release. The documentation now ships in the ten DSH ecosystem languages
|
package/CHANGELOG.pt.md
CHANGED
|
@@ -8,7 +8,11 @@ Dates are the registry `time` values for each version, not git commit dates —
|
|
|
8
8
|
when someone typed, a publish time records when a version became installable, and only the second
|
|
9
9
|
one is a promise to anyone installing it.
|
|
10
10
|
|
|
11
|
-
## 0.
|
|
11
|
+
## 0.4.0 — 2026-11-23
|
|
12
|
+
|
|
13
|
+
> Sem mudanças em tempo de execução: todo o trabalho torna verificável por máquina a afirmação «este comentário é verdadeiro». `lib/` totalmente anotado e verificado com checkJs (107 erros → 0), o `types/index.d.ts` escrito à mão passa a ser a única fonte de verdade no lado da implementação (alterá-lo fica vermelho), e a ausência de mudanças no código é provada nó a nó (ASTs idênticos). Corrigidas duas causas reais de instabilidade do banco de testes (corrida do oráculo pré-layout, janela alvo coberta). Sem novas dependências. Veja a entrada em inglês.
|
|
14
|
+
|
|
15
|
+
## 0.3.0 — 2026-11-23
|
|
12
16
|
|
|
13
17
|
> Dez idiomas e uma superfície pública tipada. Os documentos são publicados nos dez idiomas do ecossistema DSH, com o português como opção de primeiro nível ao lado do inglês. Dois casos de instalação: desktop (apenas pnpm integrado, nunca `dsh plugin add`) e não-desktop. Adicionado `types/index.d.ts`. Veja a entrada em inglês.
|
|
14
18
|
|
package/CHANGELOG.ru.md
CHANGED
|
@@ -8,7 +8,11 @@ Dates are the registry `time` values for each version, not git commit dates —
|
|
|
8
8
|
when someone typed, a publish time records when a version became installable, and only the second
|
|
9
9
|
one is a promise to anyone installing it.
|
|
10
10
|
|
|
11
|
-
## 0.
|
|
11
|
+
## 0.4.0 — 2026-11-23
|
|
12
|
+
|
|
13
|
+
> Изменений в рантайме нет: вся работа делает утверждение «этот комментарий правдив» машинно проверяемым. Весь `lib/` размечен JSDoc и проверяется под checkJs (107 ошибок → 0), написанный вручную `types/index.d.ts` становится единственным источником истины на стороне реализации (правка в нём даёт красный), а неизменность кода доказана узел за узлом (идентичные AST). Исправлены две настоящие причины нестабильности тестового стенда (гонка вокруг pre-layout oracle, перекрытое целевое окно). Новых зависимостей нет. Подробнее — в английской записи.
|
|
14
|
+
|
|
15
|
+
## 0.3.0 — 2026-11-23
|
|
12
16
|
|
|
13
17
|
> Десять языков и типизированный публичный интерфейс. Документация выходит на десяти языках экосистемы DSH, русский — равноправный переключатель рядом с английским. Два варианта установки: desktop (только встроенный pnpm, никогда `dsh plugin add`) и не-desktop. Добавлен `types/index.d.ts`. Подробнее — в английской записи.
|
|
14
18
|
|
package/CHANGELOG.zh.md
CHANGED
|
@@ -8,7 +8,11 @@ Dates are the registry `time` values for each version, not git commit dates —
|
|
|
8
8
|
when someone typed, a publish time records when a version became installable, and only the second
|
|
9
9
|
one is a promise to anyone installing it.
|
|
10
10
|
|
|
11
|
-
## 0.
|
|
11
|
+
## 0.4.0 — 2026-11-23
|
|
12
|
+
|
|
13
|
+
> 没有运行时变更,全部工作用于让「注释是真的」可被机器验证。`lib/` 全量 JSDoc + checkJs(107 错 → 0),手写的 `types/index.d.ts` 成为实现侧唯一真源(改它就会红),并且代码未动是逐 AST 节点证明的而非声称的;另修掉测试夹具的两个不稳定真因(pre-layout oracle 竞态、目标窗口被遮挡)。未新增任何依赖。详情见英文权威条目。
|
|
14
|
+
|
|
15
|
+
## 0.3.0 — 2026-11-23
|
|
12
16
|
|
|
13
17
|
> 十种语言与类型化公开接口。文档现以 DSH 生态十语发布,中文为与英文并列的一等切换;安装明确为 desktop / 非desktop 两类(desktop 只能用内置 pnpm 手动补,禁 dsh plugin add);新增 types/index.d.ts 类型契约。详情见英文权威条目。
|
|
14
18
|
|
package/lib/config.js
CHANGED
|
@@ -19,6 +19,21 @@
|
|
|
19
19
|
// Cordis renders. It is NOT schemastery: the settings FORM is rendered from schemastery's field
|
|
20
20
|
// metadata, so a host that cannot resolve schemastery gives the user no form — the values still work
|
|
21
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 three-way
|
|
25
|
+
* branch in both validators is checked as exhaustive by the reader, not just by the shim at runtime.
|
|
26
|
+
* @typedef {object} ConfigField
|
|
27
|
+
* @property {string} key
|
|
28
|
+
* @property {'boolean'|'number'|'string'} type
|
|
29
|
+
* @property {any} default
|
|
30
|
+
* @property {number} [min]
|
|
31
|
+
* @property {number} [max]
|
|
32
|
+
* @property {boolean} [volatile]
|
|
33
|
+
* @property {string} [description]
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/** @type {ConfigField[]} */
|
|
22
37
|
const FIELDS = [
|
|
23
38
|
{ key: 'enabled', type: 'boolean', default: true, volatile: true,
|
|
24
39
|
description: 'Master switch. When off, every action refuses with `paused` before the engine is reached.' },
|
|
@@ -58,9 +73,19 @@ const FIELDS = [
|
|
|
58
73
|
/** Defaults, for documentation and for tests that must not depend on a resolver. */
|
|
59
74
|
export const CONFIG_DEFAULTS = Object.fromEntries(FIELDS.map((f) => [f.key, f.default]));
|
|
60
75
|
|
|
61
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Validate one raw config object against FIELDS. Returns `{ value, issues }` standard-schema style.
|
|
78
|
+
*
|
|
79
|
+
* `@returns {any}` on purpose: the two returns below have different shapes (`{issues}` alone vs
|
|
80
|
+
* `{value}` alone), which is exactly what the standard-schema contract allows and what Cordis
|
|
81
|
+
* branches on. A precise union here is a lie about the runtime and was measured to turn two errors
|
|
82
|
+
* into three (findings §7.5).
|
|
83
|
+
* @param {any} raw
|
|
84
|
+
* @returns {any}
|
|
85
|
+
*/
|
|
62
86
|
function validateWithShim(raw) {
|
|
63
87
|
const input = raw && typeof raw === 'object' ? raw : {};
|
|
88
|
+
/** @type {Record<string, any>} */
|
|
64
89
|
const value = {};
|
|
65
90
|
const issues = [];
|
|
66
91
|
for (const field of FIELDS) {
|
|
@@ -116,6 +141,7 @@ export async function createConfigSchema() {
|
|
|
116
141
|
const mod = await import('./peers-schemastery.js');
|
|
117
142
|
const z = mod?.z;
|
|
118
143
|
if (z && typeof z.object === 'function') {
|
|
144
|
+
/** @type {Record<string, any>} */
|
|
119
145
|
const shape = {};
|
|
120
146
|
for (const field of FIELDS) {
|
|
121
147
|
let s;
|
|
@@ -149,8 +175,10 @@ export async function createConfigSchema() {
|
|
|
149
175
|
const std = schema['~standard'];
|
|
150
176
|
let configValue = schema;
|
|
151
177
|
if (std && typeof std.validate === 'function') {
|
|
178
|
+
/** @type {Set<string>} */
|
|
152
179
|
const known = new Set(FIELDS.map((f) => f.key));
|
|
153
180
|
const wrapped = Object.assign(Object.create(null), std, {
|
|
181
|
+
/** @param {any} raw @returns {any} */
|
|
154
182
|
validate(raw) {
|
|
155
183
|
const input = raw && typeof raw === 'object' ? raw : {};
|
|
156
184
|
const unknown = Object.keys(input).filter((k) => !known.has(k));
|
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;
|
package/lib/proof-window.mjs
CHANGED
|
@@ -46,14 +46,97 @@
|
|
|
46
46
|
// reachability numbers and the per-action proof were measured by different instruments while
|
|
47
47
|
// carrying the same name -- the drift this repo already killed once (see sampler.mjs header).
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* One sampler reading. `inputAgeMs` is `undefined` when the instrument could not read it, which is
|
|
51
|
+
* NOT the same as 0 ("input just happened") -- the whole fail-closed rule below depends on that.
|
|
52
|
+
* @typedef {object} ProofSample
|
|
53
|
+
* @property {number} ts
|
|
54
|
+
* @property {number} [inputAgeMs]
|
|
55
|
+
* @property {number} cx
|
|
56
|
+
* @property {number} cy
|
|
57
|
+
* @property {number|string} [fg]
|
|
58
|
+
* @property {number|string} [focus]
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The software-attributable counts. Named rather than inferred because `{}` fragments this object at
|
|
63
|
+
* every consumer (`attribution.x`, `summary.attribution.y`), and a checker that cannot see the keys
|
|
64
|
+
* reports each read as an error against a type nobody wrote down.
|
|
65
|
+
* @typedef {object} Attribution
|
|
66
|
+
* @property {number} physicalInputEvents
|
|
67
|
+
* @property {number} humanActiveMs
|
|
68
|
+
* @property {number} quietMs
|
|
69
|
+
* @property {number} unexplainedCursorMotionGaps
|
|
70
|
+
* @property {number} unexplainedCursorMaxDeltaPx
|
|
71
|
+
* @property {number|null} unexplainedCursorMaxDeltaAt
|
|
72
|
+
* @property {number} unexplainedCursorPathPx
|
|
73
|
+
* @property {number} unexplainedForegroundSwitches
|
|
74
|
+
* @property {number} unexplainedFocusChanges
|
|
75
|
+
* @property {number} unreadableInputAgeGaps
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* One attempt's outcome, as the engine reported it.
|
|
80
|
+
* @typedef {object} ActionAttempt
|
|
81
|
+
* @property {boolean} [ok]
|
|
82
|
+
* @property {string} [effect]
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @typedef {object} ProofOpts
|
|
87
|
+
* @property {number} [minSamples]
|
|
88
|
+
* @property {number} [humanGapFactor]
|
|
89
|
+
* @property {ProofSample[]} [control]
|
|
90
|
+
* @property {boolean} [declaredFlash]
|
|
91
|
+
* @property {string} [effect]
|
|
92
|
+
* @property {ActionAttempt[]} [actions]
|
|
93
|
+
* @property {boolean} [declaredTakeover]
|
|
94
|
+
* @property {boolean} [cursorRestored]
|
|
95
|
+
* @property {number} [unreadableCap]
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @typedef {object} VerdictResult
|
|
100
|
+
* @property {'pass'|'fail'|'inconclusive'|'insufficient'} verdict
|
|
101
|
+
* @property {string} reason
|
|
102
|
+
* @property {Record<string,string>} [dimensions]
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @typedef {object} ProofResult
|
|
107
|
+
* @property {number} samples
|
|
108
|
+
* @property {number} windowMs
|
|
109
|
+
* @property {number|null} cursorMaxDeltaPx
|
|
110
|
+
* @property {number|null} cursorMaxDeltaAt
|
|
111
|
+
* @property {number|null} cursorTotalPathPx
|
|
112
|
+
* @property {number|null} foregroundSwitches
|
|
113
|
+
* @property {number|null} focusChanges
|
|
114
|
+
* @property {Attribution|null} attribution
|
|
115
|
+
* @property {Attribution|null} control
|
|
116
|
+
* @property {'pass'|'fail'|'inconclusive'|'insufficient'} verdict
|
|
117
|
+
* @property {string} reason
|
|
118
|
+
* @property {Record<string,string>} [dimensions]
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
/** @param {number} v @returns {number} */
|
|
49
122
|
const round = (v) => Math.round(v * 100) / 100;
|
|
50
123
|
|
|
51
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* Absolute timestamp of the last PHYSICAL input at sample x, or null if unreadable.
|
|
126
|
+
* @param {ProofSample} x
|
|
127
|
+
* @returns {number|null}
|
|
128
|
+
*/
|
|
52
129
|
export function physEventAt(x) {
|
|
53
130
|
return typeof x.inputAgeMs === 'number' && x.inputAgeMs >= 0 ? x.ts - x.inputAgeMs : null;
|
|
54
131
|
}
|
|
55
132
|
|
|
56
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* Was there physical input inside the gap between b and a? Unreadable age => NOT human (fail closed).
|
|
135
|
+
* @param {ProofSample} b
|
|
136
|
+
* @param {ProofSample} a
|
|
137
|
+
* @param {number} [humanGapFactor]
|
|
138
|
+
* @returns {boolean}
|
|
139
|
+
*/
|
|
57
140
|
export function isHumanGap(b, a, humanGapFactor = 0.6) {
|
|
58
141
|
const ea = physEventAt(b), eb = physEventAt(a);
|
|
59
142
|
if (ea === null || eb === null) return false;
|
|
@@ -62,9 +145,13 @@ export function isHumanGap(b, a, humanGapFactor = 0.6) {
|
|
|
62
145
|
|
|
63
146
|
/**
|
|
64
147
|
* Evaluate one proof window. Pure.
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
148
|
+
*
|
|
149
|
+
* The `@param` types below were written as a plain object literal before, which is legal JSDoc but
|
|
150
|
+
* was not applied where `Array` appeared bare: `{Array}` is not a usable type under checkJs (it
|
|
151
|
+
* demands a type argument), so the checker discarded the whole annotation and read `opts` as `{}`.
|
|
152
|
+
* Seven "property does not exist on type '{}'" errors were one symptom of that single mistake.
|
|
153
|
+
* @param {ProofSample[]} samples the ACTION window
|
|
154
|
+
* @param {ProofOpts} [opts]
|
|
68
155
|
* control = the pre-action window (sampled while nothing was done). It cannot excuse motion in the
|
|
69
156
|
* action window -- the structural rule already handles that -- but it decides whether the
|
|
70
157
|
* foreground/focus dimensions are evaluable at all.
|
|
@@ -73,14 +160,19 @@ export function isHumanGap(b, a, humanGapFactor = 0.6) {
|
|
|
73
160
|
* old behaviour byte for byte.
|
|
74
161
|
* actions = optional per-attempt results ({ ok, effect }); when EVERY attempt failed to take
|
|
75
162
|
* effect the verdict is fail regardless of how still the desktop stayed.
|
|
163
|
+
* @returns {ProofResult}
|
|
76
164
|
*/
|
|
77
165
|
export function evaluateProof(samples, opts = {}) {
|
|
78
166
|
const minSamples = opts.minSamples ?? 3;
|
|
79
167
|
const humanGap = opts.humanGapFactor ?? 0.6;
|
|
80
168
|
|
|
81
|
-
|
|
169
|
+
// The cast is the point of the filter: `filter(Boolean)` drops the nulls at runtime but is not a
|
|
170
|
+
// type predicate, so the array's declared element type has to be asserted once here rather than
|
|
171
|
+
// sprinkled through the loop as non-null assertions.
|
|
172
|
+
/** @type {ProofSample[]} */
|
|
173
|
+
const r = /** @type {ProofSample[]} */ ((Array.isArray(samples) ? samples : [])
|
|
82
174
|
.map((x) => (x && typeof x.ts === 'number' ? x : null))
|
|
83
|
-
.filter(Boolean);
|
|
175
|
+
.filter(Boolean));
|
|
84
176
|
|
|
85
177
|
if (r.length < minSamples) {
|
|
86
178
|
return {
|
|
@@ -200,9 +292,14 @@ export function evaluateProof(samples, opts = {}) {
|
|
|
200
292
|
* the case the pre-0.1.3 gate could read as a green light: 50 failed calls, zero
|
|
201
293
|
* displacement. Displacement proves we did not disturb; it never proves we accomplished.
|
|
202
294
|
* Overall = worst dimension: fail > inconclusive > pass.
|
|
295
|
+
* @param {string|null} [effect]
|
|
296
|
+
* @param {ActionAttempt[]} [actions]
|
|
297
|
+
* @returns {{dim: 'pass'|'fail'|'inconclusive', note: string}|null}
|
|
203
298
|
*/
|
|
204
299
|
function judgeEffect(effect, actions) {
|
|
300
|
+
/** @type {ActionAttempt[]} */
|
|
205
301
|
const list = Array.isArray(actions) ? actions.filter(Boolean) : [];
|
|
302
|
+
/** @param {ActionAttempt} a @returns {boolean} */
|
|
206
303
|
const reported = (a) => a.ok !== false
|
|
207
304
|
&& (a.effect === 'reported-by-send' || a.effect === 'reported-by-pattern');
|
|
208
305
|
|
|
@@ -231,9 +328,20 @@ function judgeEffect(effect, actions) {
|
|
|
231
328
|
};
|
|
232
329
|
}
|
|
233
330
|
|
|
331
|
+
/**
|
|
332
|
+
* @param {Attribution|null} attribution
|
|
333
|
+
* @param {Attribution|null} control
|
|
334
|
+
* @param {number} sampleCount
|
|
335
|
+
* @param {ProofOpts} [opts]
|
|
336
|
+
* @returns {VerdictResult}
|
|
337
|
+
*/
|
|
234
338
|
export function verdictFor(attribution, control, sampleCount, opts = {}) {
|
|
339
|
+
// `Partial` because both callers legitimately pass nothing (`null`) for a window they have no
|
|
340
|
+
// control for, and every read below already defends with `?? 0`.
|
|
341
|
+
/** @type {Partial<Attribution>} */
|
|
235
342
|
const a = attribution || {};
|
|
236
343
|
const unreadableCap = opts.unreadableCap ?? Math.max(1, Math.floor((sampleCount - 1) * 0.3));
|
|
344
|
+
/** @type {Record<string,string>} */
|
|
237
345
|
const dims = {};
|
|
238
346
|
|
|
239
347
|
if ((a.unreadableInputAgeGaps ?? 0) > unreadableCap) {
|
|
@@ -299,8 +407,14 @@ export function verdictFor(attribution, control, sampleCount, opts = {}) {
|
|
|
299
407
|
return { verdict, reason, dimensions: dims };
|
|
300
408
|
}
|
|
301
409
|
|
|
302
|
-
/**
|
|
410
|
+
/**
|
|
411
|
+
* The software-attributable quantities, flattened for callers that only want the numbers.
|
|
412
|
+
* @param {ProofResult|{attribution?: Attribution|null}} [summary]
|
|
413
|
+
* @returns {{motionGaps: number|null, maxPx: number|null, pathPx: number|null,
|
|
414
|
+
* foregroundSwitches: number|null, focusChanges: number|null, quietMs: number|null}}
|
|
415
|
+
*/
|
|
303
416
|
export function softwareCursorEvidence(summary) {
|
|
417
|
+
/** @type {Partial<Attribution>} */
|
|
304
418
|
const a = (summary && summary.attribution) || {};
|
|
305
419
|
return {
|
|
306
420
|
motionGaps: a.unexplainedCursorMotionGaps ?? null,
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-windows-parallel-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
|
-
"tag": "latest"
|
|
6
|
+
"tag": "latest",
|
|
7
|
+
"registry": "https://registry.npmjs.org/"
|
|
7
8
|
},
|
|
8
9
|
"description": "Drive a Windows window quietly by default and visibly on request: one tool, five actions, a channel decision table that prefers the quiet door, a bounded self-reversing focus flash when only UI Automation can reach the control, and an opt-in takeover tier (HUD mandatory, cursor always restored, keyboard injection only when asked and only for the foreground target). Windows PowerShell 5.1 sidecar, zero install dependencies, no mouse injection.",
|
|
9
10
|
"keywords": [
|