dsh-native-uia 0.4.0 → 0.6.1
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/README.md +82 -630
- package/cordis.patch.yml +2 -2
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -6
- package/scripts/check-lease.mjs +2 -2
- package/scripts/install.mjs +1 -2
- package/scripts/lib/sources.mjs +0 -4
- package/scripts/load-tools.mjs +1 -1
- package/scripts/measure-parse.mjs +2 -2
- package/scripts/regression-halt-latch.mjs +100 -100
- package/scripts/regression-tools.mjs +69 -24
- package/scripts/verify.mjs +142 -13
- package/src/guard.js +26 -7
- package/src/index.js +11 -49
- package/src/state.js +0 -3
- package/src/themes.js +16 -24
- package/src/tools/defs/act.js +149 -11
- package/src/tools/defs/lifecycle.js +2 -2
- package/src/tools/defs/observe.js +22 -6
- package/src/tools/defs/pointer.js +65 -35
- package/src/tools/format.js +45 -8
- package/src/tools/index.js +3 -6
- package/src/tools/ocr.js +1 -1
- package/src/tools/recipes.js +9 -4
- package/src/worker-client.js +5 -5
- package/worker/indicator-server.ps1 +150 -196
- package/worker/lib/02-uia.ps1 +9 -6
- package/worker/lib/05-value.ps1 +111 -6
- package/worker/lib/06-snapshot.ps1 +79 -12
- package/worker/lib/07-action.ps1 +44 -6
- package/worker/lib/08-command.ps1 +11 -1
- package/worker/lib/10-dispatch.ps1 +0 -2
- package/src/native-uia-remote.js +0 -80
package/cordis.patch.yml
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
#
|
|
3
3
|
# 这一行是本包自己的 Host 半侧:桌面操控工具、本机状态服务与屏幕指示层。挂上它,
|
|
4
4
|
# 本包才会被 client-module 扫描器发现(`dsh.client` 从 Loader 行挂载的那个包的
|
|
5
|
-
#
|
|
6
|
-
#
|
|
5
|
+
# 清单里读,且行必须是包名本身,不能是子路径),浏览器半侧因此随它一起下发,
|
|
6
|
+
# 面板作为 `plugins.bundle.config` 配置块渲染在本包自己的详情页上,不单独占一行。
|
|
7
7
|
|
|
8
8
|
- insert:
|
|
9
9
|
- id: native-uia
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Yuping",
|
|
4
|
-
"description": "Observe and operate the Windows desktop through the UI Automation element tree: the tree is the primary channel rather than screenshots, so a text-only model can drive it; actions are delivered in the background without moving the cursor or stealing focus; a batch runs in one call with per-step verification, and successful batches are saved as replayable recipes. Policy hard-refuses OS shutdown or sign-out, application exit,
|
|
4
|
+
"description": "Observe and operate the Windows desktop through the UI Automation element tree: the tree is the primary channel rather than screenshots, so a text-only model can drive it; actions are delivered in the background without moving the cursor or stealing focus; a batch runs in one call with per-step verification, and successful batches are saved as replayable recipes. Policy hard-refuses OS shutdown or sign-out, application exit, destructive deletes, and launching any command shell or script host. The plugin page switches delivery mode, ambient theme, capsule shape and the bottom-edge smoke, applied live and persisted; Esc stops the run."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "御屏",
|
|
4
|
-
"description": "用 Windows UI Automation
|
|
4
|
+
"description": "用 Windows UI Automation 控件树观察并操作桌面:主观测通道是元素树而不是截图,纯文本模型也能操控;动作默认在后台投递,不动鼠标、不抢焦点;一次调用批量执行并逐步校验,成功的批次自动存成可回放配方。策略硬拒系统关机/注销、退出程序、破坏性删除,以及命令行与脚本宿主的启动。插件详情页可切换投递方式、氛围光、胶囊样式与底缘薄云,改完立即生效并持久化;停止本轮按 Esc。"
|
|
5
5
|
}
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-native-uia",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"displayName": "御屏",
|
|
5
5
|
"description": "以 Windows UI Automation 控件树为主观测通道的桌面操控插件:纯文本模型即可操控桌面,后台投递动作(不动鼠标、不抢焦点),一次调用批量执行并逐步校验,成功批次自动存为可回放配方。",
|
|
6
6
|
"type": "module",
|
|
@@ -63,13 +63,9 @@
|
|
|
63
63
|
]
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"dependencies": {
|
|
67
|
-
"@deepseek-ai/dsh-typert-protocol": "0.2.0-rc.2"
|
|
68
|
-
},
|
|
69
66
|
"peerDependencies": {
|
|
70
67
|
"@deepseek-ai/cordis": "*",
|
|
71
|
-
"@deepseek-ai/dsh-tools": "*"
|
|
72
|
-
"@deepseek-ai/dsh-typert-protocol": "*"
|
|
68
|
+
"@deepseek-ai/dsh-tools": "*"
|
|
73
69
|
},
|
|
74
70
|
"engines": {
|
|
75
71
|
"node": ">=18.0.0"
|
package/scripts/check-lease.mjs
CHANGED
|
@@ -82,7 +82,7 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
82
82
|
const indicator = fakeIndicator();
|
|
83
83
|
const activity = new ActivityWindow({ indicator, leaseMs: 300, beatMs: 60 });
|
|
84
84
|
activity.claim();
|
|
85
|
-
await activity.end({ reason: 'kill' }); //
|
|
85
|
+
await activity.end({ reason: 'kill' }); // 面板 / Esc 终止
|
|
86
86
|
assert.equal(activity.active, false, 'end() left the window active');
|
|
87
87
|
assert.equal(activity.phase, 'stopped', 'the window does not report stopped after a kill');
|
|
88
88
|
const stopped = indicator.calls.find((c) => c.cmd === 'phase' && c.args.phase === 'stopped');
|
|
@@ -148,7 +148,7 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
148
148
|
// --- 8: the choke point classifies commands, and internal probes stay silent ---------------------
|
|
149
149
|
// This is the flicker regression: the Esc watchdog polls `escape_pressed` every 40 ms. When the
|
|
150
150
|
// client inferred "observation = not an action", each poll renewed the lease and beat the overlay
|
|
151
|
-
// ~8×/s, which interleaved with the
|
|
151
|
+
// ~8×/s, which interleaved with the pulse tick and made the ring visibly flicker.
|
|
152
152
|
{
|
|
153
153
|
const { CuaWorker } = await import('../src/worker-client.js');
|
|
154
154
|
const fired = { action: [], observe: [] };
|
package/scripts/install.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* and `dependencies`. Both edits are derived from the file as it is on disk,
|
|
6
6
|
* never from a copied-out list, and every run leaves a timestamped backup.
|
|
7
7
|
*/
|
|
8
|
-
import { readFileSync, writeFileSync, copyFileSync, existsSync
|
|
8
|
+
import { readFileSync, writeFileSync, copyFileSync, existsSync } from 'node:fs';
|
|
9
9
|
import { dirname, join, resolve, isAbsolute } from 'node:path';
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
11
|
import { homedir } from 'node:os';
|
|
@@ -25,7 +25,6 @@ const PLUGIN_ROOT = process.env.DSH_PLUGIN_ROOT ?? join(homedir(), '.dsh', 'plug
|
|
|
25
25
|
* (`dsh.client` in the same manifest), so there are no component packages to
|
|
26
26
|
* link and no rows beyond the one bare-name row the patch inserts.
|
|
27
27
|
*/
|
|
28
|
-
import { readdirSync } from 'node:fs';
|
|
29
28
|
const ALL = [{ name: CORE_NAME, dir: CORE_DIR }];
|
|
30
29
|
// DSH_PROFILE is often a bare profile NAME ("desktop"), not a path — the host exports it that way.
|
|
31
30
|
// Joining it directly produced "desktop\package.json" relative to the cwd and status failed with
|
package/scripts/lib/sources.mjs
CHANGED
|
@@ -26,10 +26,6 @@ export function toolsSource() {
|
|
|
26
26
|
return TOOLS_FILES.map((rel) => `// ---- ${rel} ----\n${readFileSync(join(root, rel), 'utf8')}`).join('\n');
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export function toolsFileList() {
|
|
30
|
-
return TOOLS_FILES.slice();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
29
|
/**
|
|
34
30
|
* The PowerShell worker, split the same way: the entry keeps process setup and the stdio loop, the
|
|
35
31
|
* body lives in worker/lib in this order. The entry dot-sources the very list below at run time,
|
package/scripts/load-tools.mjs
CHANGED
|
@@ -30,7 +30,7 @@ const EXPECTED = [
|
|
|
30
30
|
|
|
31
31
|
const registered = [];
|
|
32
32
|
const store = {
|
|
33
|
-
windows: [], steps: [], counters: { refused: 0 }, running: false, busy: false, blocked: [], heldButtons: new Set(), attempts: new Map(),
|
|
33
|
+
windows: [], steps: [], counters: { refused: 0 }, running: false, busy: false, blocked: [], heldButtons: new Set(), attempts: new Map(),
|
|
34
34
|
line() {}, block() { return { id: 1 }; }, step() {}, actionDone() {}, holdButton(b) { this.heldButtons.add(b); }, releaseButton(b) { return this.heldButtons.delete(b); },
|
|
35
35
|
noteAttempt(sig, ok) { const cur = this.attempts.get(sig) ?? { total: 0, misses: 0 }; cur.total += 1; cur.misses = ok ? 0 : cur.misses + 1; this.attempts.set(sig, cur); return cur; }, clearAttempts() { this.attempts.clear(); },
|
|
36
36
|
};
|
|
@@ -10,8 +10,8 @@ import { loadToolsSource } from './lib/load-tools-source.mjs';
|
|
|
10
10
|
const root = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
11
11
|
const mod = await loadToolsSource('{ registerTools, groupOcrWords, ocrTargets, OCR_COVER }');
|
|
12
12
|
const { registerTools, groupOcrWords, ocrTargets, OCR_COVER: COVER } = mod;
|
|
13
|
-
// COVER is the production set
|
|
14
|
-
//
|
|
13
|
+
// COVER is the production set pulled out of the real tool sources, not a copy: a verbatim duplicate
|
|
14
|
+
// here is the divergence risk (the tool's list moves, the script's copy silently stays).
|
|
15
15
|
|
|
16
16
|
const dataDir = join(root, '.test-output', 'measure');
|
|
17
17
|
await fs.mkdir(dataDir, { recursive: true });
|
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* The kill latch must refuse only the command that was in flight at the stop instant.
|
|
4
|
-
*
|
|
5
|
-
* Measured bug (2026-11-21): Esc armed the latch, the next mutating call consumed it and was
|
|
6
|
-
* refused, and the model — reading "本轮已被终止" — never retried. `killed` stayed true, the run
|
|
7
|
-
* could not light again, and the person saw an unresponsive overlay. A second Esc re-armed it,
|
|
8
|
-
* so every stop kept poisoning one more action.
|
|
9
|
-
*
|
|
10
|
-
* This exercises the real halt callback from src/index.js against a fake store: no desktop input,
|
|
11
|
-
* no worker spawn.
|
|
12
|
-
*/
|
|
13
|
-
import assert from 'node:assert/strict';
|
|
14
|
-
import { readFileSync } from 'node:fs';
|
|
15
|
-
import { dirname, join } from 'node:path';
|
|
16
|
-
import { fileURLToPath } from 'node:url';
|
|
17
|
-
|
|
18
|
-
const root = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
19
|
-
const source = readFileSync(join(root, 'src/index.js'), 'utf8');
|
|
20
|
-
|
|
21
|
-
// Pull the production halt callback and its window constant out of index.js so the test cannot
|
|
22
|
-
// drift from the shipped logic.
|
|
23
|
-
const latchMs = Number(source.match(/const HALT_LATCH_MS = (\d+);/)?.[1]);
|
|
24
|
-
const haltBody = source.match(/halt: \(\) => \{([\s\S]*?)\n \},/)?.[1];
|
|
25
|
-
|
|
26
|
-
let passed = 0;
|
|
27
|
-
function test(name, fn) {
|
|
28
|
-
try { fn(); passed++; console.log(`PASS ${name}`); }
|
|
29
|
-
catch (error) { console.log(`FAIL ${name}: ${error.message}`); process.exitCode = 1; }
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
test('the latch window and the halt callback are present in the shipped source', () => {
|
|
33
|
-
assert.ok(Number.isFinite(latchMs) && latchMs > 0, 'HALT_LATCH_MS is missing or not a number');
|
|
34
|
-
assert.ok(typeof haltBody === 'string' && haltBody.length > 0, 'the halt callback was not found in index.js');
|
|
35
|
-
assert.match(haltBody, /killedAt/, 'the halt callback no longer considers when the latch was armed');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Build a store shaped like src/state.js and run the production halt body against it.
|
|
39
|
-
function makeHalt() {
|
|
40
|
-
const logged = [];
|
|
41
|
-
const store = { killed: false, killedAt: 0, setKilled(v) { this.killed = v; if (v) this.killedAt = Date.now(); } };
|
|
42
|
-
const logger = (m) => logged.push(m);
|
|
43
|
-
const halt = new Function('store', 'logger', 'HALT_LATCH_MS', `return () => {${haltBody}\n};`)(store, logger, latchMs);
|
|
44
|
-
return { store, halt, logged };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
test('a stopped command is refused inside the latch window', () => {
|
|
48
|
-
const { store, halt, logged } = makeHalt();
|
|
49
|
-
store.setKilled(true); // Esc fired
|
|
50
|
-
const message = halt(); // the in-flight command arrives immediately
|
|
51
|
-
assert.equal(typeof message, 'string', 'the command in flight at the stop was allowed through');
|
|
52
|
-
assert.match(message, /本轮已被终止/);
|
|
53
|
-
assert.equal(store.killed, false, 'the one-shot latch was not cleared after refusing');
|
|
54
|
-
assert.equal(logged.length, 1);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('the next instruction after the window is delivered, not refused', () => {
|
|
58
|
-
const { store, halt, logged } = makeHalt();
|
|
59
|
-
store.setKilled(true);
|
|
60
|
-
store.killedAt = Date.now() - (latchMs + 500); // the person asked for something new
|
|
61
|
-
const message = halt();
|
|
62
|
-
assert.equal(message, null, 'a fresh instruction was refused because of an old stop');
|
|
63
|
-
assert.equal(store.killed, false, 'the stale latch was left armed');
|
|
64
|
-
assert.equal(logged.length, 0, 'a stale latch logged a stop that did not apply to this action');
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('an unarmed latch never blocks anything', () => {
|
|
68
|
-
const { halt, logged } = makeHalt();
|
|
69
|
-
assert.equal(halt(), null);
|
|
70
|
-
assert.equal(logged.length, 0);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('a latch with no timestamp is treated as stale, not as fresh', () => {
|
|
74
|
-
// Defensive: a store restored from an older build has no killedAt. Reading it as age 0 would
|
|
75
|
-
// make the very first action after an upgrade look like the stopped command.
|
|
76
|
-
const { store, halt } = makeHalt();
|
|
77
|
-
store.killed = true;
|
|
78
|
-
store.killedAt = 0;
|
|
79
|
-
assert.equal(halt(), null, 'a timestamp-less latch blocked a new instruction');
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('Esc clears the latch even when no command ever consumes it', () => {
|
|
83
|
-
// The overlay is dismissed by Esc, so nothing else would ever clear a latch nobody read: the
|
|
84
|
-
// panel kept showing 已终止. index.js schedules a clear after the window.
|
|
85
|
-
assert.match(source, /clearAt/, 'index.js does not schedule a latch clear after Esc');
|
|
86
|
-
assert.match(source, /HALT_LATCH_MS \+ 250/, 'the scheduled clear does not wait for the latch window to pass');
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('Esc is sampled while the run is live, not only while the overlay is painted', () => {
|
|
90
|
-
// The overlay self-closes after DSH_NATIVE_UIA_IDLE_MS (20 s default) of tool silence, so a
|
|
91
|
-
// model thinking pause set activity.active=false. Gating the watchdog on that made Esc dead
|
|
92
|
-
// exactly when a person watches the agent work — the reported "运行中按 ESC 没反应".
|
|
93
|
-
const esc = source.match(/const escTimer = setInterval\(\(\) => \{([\s\S]*?)\n \}, (\d+)\)/)?.[1] ?? '';
|
|
94
|
-
assert.ok(esc !== '', 'the Esc watchdog block was not found');
|
|
95
|
-
assert.doesNotMatch(esc, /!activity\.active/, 'the watchdog still gates on the rendered overlay');
|
|
96
|
-
assert.match(esc, /store\.running !== true && store\.busy !== true/,
|
|
97
|
-
'the watchdog does not gate on the live run plus in-flight commands');
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
console.log(`\n${passed}/7 halt-latch regressions passed (no desktop input)`);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The kill latch must refuse only the command that was in flight at the stop instant.
|
|
4
|
+
*
|
|
5
|
+
* Measured bug (2026-11-21): Esc armed the latch, the next mutating call consumed it and was
|
|
6
|
+
* refused, and the model — reading "本轮已被终止" — never retried. `killed` stayed true, the run
|
|
7
|
+
* could not light again, and the person saw an unresponsive overlay. A second Esc re-armed it,
|
|
8
|
+
* so every stop kept poisoning one more action.
|
|
9
|
+
*
|
|
10
|
+
* This exercises the real halt callback from src/index.js against a fake store: no desktop input,
|
|
11
|
+
* no worker spawn.
|
|
12
|
+
*/
|
|
13
|
+
import assert from 'node:assert/strict';
|
|
14
|
+
import { readFileSync } from 'node:fs';
|
|
15
|
+
import { dirname, join } from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
|
|
18
|
+
const root = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
19
|
+
const source = readFileSync(join(root, 'src/index.js'), 'utf8');
|
|
20
|
+
|
|
21
|
+
// Pull the production halt callback and its window constant out of index.js so the test cannot
|
|
22
|
+
// drift from the shipped logic.
|
|
23
|
+
const latchMs = Number(source.match(/const HALT_LATCH_MS = (\d+);/)?.[1]);
|
|
24
|
+
const haltBody = source.match(/halt: \(\) => \{([\s\S]*?)\n \},/)?.[1];
|
|
25
|
+
|
|
26
|
+
let passed = 0;
|
|
27
|
+
function test(name, fn) {
|
|
28
|
+
try { fn(); passed++; console.log(`PASS ${name}`); }
|
|
29
|
+
catch (error) { console.log(`FAIL ${name}: ${error.message}`); process.exitCode = 1; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
test('the latch window and the halt callback are present in the shipped source', () => {
|
|
33
|
+
assert.ok(Number.isFinite(latchMs) && latchMs > 0, 'HALT_LATCH_MS is missing or not a number');
|
|
34
|
+
assert.ok(typeof haltBody === 'string' && haltBody.length > 0, 'the halt callback was not found in index.js');
|
|
35
|
+
assert.match(haltBody, /killedAt/, 'the halt callback no longer considers when the latch was armed');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Build a store shaped like src/state.js and run the production halt body against it.
|
|
39
|
+
function makeHalt() {
|
|
40
|
+
const logged = [];
|
|
41
|
+
const store = { killed: false, killedAt: 0, setKilled(v) { this.killed = v; if (v) this.killedAt = Date.now(); } };
|
|
42
|
+
const logger = (m) => logged.push(m);
|
|
43
|
+
const halt = new Function('store', 'logger', 'HALT_LATCH_MS', `return () => {${haltBody}\n};`)(store, logger, latchMs);
|
|
44
|
+
return { store, halt, logged };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
test('a stopped command is refused inside the latch window', () => {
|
|
48
|
+
const { store, halt, logged } = makeHalt();
|
|
49
|
+
store.setKilled(true); // Esc fired
|
|
50
|
+
const message = halt(); // the in-flight command arrives immediately
|
|
51
|
+
assert.equal(typeof message, 'string', 'the command in flight at the stop was allowed through');
|
|
52
|
+
assert.match(message, /本轮已被终止/);
|
|
53
|
+
assert.equal(store.killed, false, 'the one-shot latch was not cleared after refusing');
|
|
54
|
+
assert.equal(logged.length, 1);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('the next instruction after the window is delivered, not refused', () => {
|
|
58
|
+
const { store, halt, logged } = makeHalt();
|
|
59
|
+
store.setKilled(true);
|
|
60
|
+
store.killedAt = Date.now() - (latchMs + 500); // the person asked for something new
|
|
61
|
+
const message = halt();
|
|
62
|
+
assert.equal(message, null, 'a fresh instruction was refused because of an old stop');
|
|
63
|
+
assert.equal(store.killed, false, 'the stale latch was left armed');
|
|
64
|
+
assert.equal(logged.length, 0, 'a stale latch logged a stop that did not apply to this action');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('an unarmed latch never blocks anything', () => {
|
|
68
|
+
const { halt, logged } = makeHalt();
|
|
69
|
+
assert.equal(halt(), null);
|
|
70
|
+
assert.equal(logged.length, 0);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('a latch with no timestamp is treated as stale, not as fresh', () => {
|
|
74
|
+
// Defensive: a store restored from an older build has no killedAt. Reading it as age 0 would
|
|
75
|
+
// make the very first action after an upgrade look like the stopped command.
|
|
76
|
+
const { store, halt } = makeHalt();
|
|
77
|
+
store.killed = true;
|
|
78
|
+
store.killedAt = 0;
|
|
79
|
+
assert.equal(halt(), null, 'a timestamp-less latch blocked a new instruction');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('Esc clears the latch even when no command ever consumes it', () => {
|
|
83
|
+
// The overlay is dismissed by Esc, so nothing else would ever clear a latch nobody read: the
|
|
84
|
+
// panel kept showing 已终止. index.js schedules a clear after the window.
|
|
85
|
+
assert.match(source, /clearAt/, 'index.js does not schedule a latch clear after Esc');
|
|
86
|
+
assert.match(source, /HALT_LATCH_MS \+ 250/, 'the scheduled clear does not wait for the latch window to pass');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('Esc is sampled while the run is live, not only while the overlay is painted', () => {
|
|
90
|
+
// The overlay self-closes after DSH_NATIVE_UIA_IDLE_MS (20 s default) of tool silence, so a
|
|
91
|
+
// model thinking pause set activity.active=false. Gating the watchdog on that made Esc dead
|
|
92
|
+
// exactly when a person watches the agent work — the reported "运行中按 ESC 没反应".
|
|
93
|
+
const esc = source.match(/const escTimer = setInterval\(\(\) => \{([\s\S]*?)\n \}, (\d+)\)/)?.[1] ?? '';
|
|
94
|
+
assert.ok(esc !== '', 'the Esc watchdog block was not found');
|
|
95
|
+
assert.doesNotMatch(esc, /!activity\.active/, 'the watchdog still gates on the rendered overlay');
|
|
96
|
+
assert.match(esc, /store\.running !== true && store\.busy !== true/,
|
|
97
|
+
'the watchdog does not gate on the live run plus in-flight commands');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
console.log(`\n${passed}/7 halt-latch regressions passed (no desktop input)`);
|
|
@@ -9,10 +9,19 @@ const root = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
|
9
9
|
const registerTools = await loadToolsSource('registerTools');
|
|
10
10
|
const dataDir = join(root, '.test-output', 'tools');
|
|
11
11
|
await fs.mkdir(dataDir, { recursive: true });
|
|
12
|
-
function fixture(call, activity) {
|
|
12
|
+
function fixture(call, activity, { armed = true } = {}) {
|
|
13
13
|
const tools = new Map();
|
|
14
|
-
const store = { running: false, windows: [], pointerMode: 'background', counters: { refused: 0 }, heldButtons: new Set(), attempts: new Map(),
|
|
15
|
-
const dispose = registerTools({ tools: { register(def) { tools.set(def.name, def); return () => {}; } } }, {
|
|
14
|
+
const store = { running: false, windows: [], pointerMode: 'background', counters: { refused: 0 }, heldButtons: new Set(), attempts: new Map(), ctrlCAt: 0, block() { return { id: 1 }; }, line() {}, step() {}, actionDone() {}, setWindows(w) { this.windows = w; }, holdButton(b) { this.heldButtons.add(b); }, releaseButton(b) { return this.heldButtons.delete(b); }, noteAttempt(sig, ok) { const cur = this.attempts.get(sig) ?? { total: 0, misses: 0 }; cur.total += 1; cur.misses = ok ? 0 : cur.misses + 1; this.attempts.set(sig, cur); return cur; }, clearAttempts() { this.attempts.clear(); }, setTree(nodes, meta) { this.tree = { nodes, ...meta }; }, setTarget(target) { this.target = target; } };
|
|
15
|
+
const dispose = registerTools({ tools: { register(def) { tools.set(def.name, def); return () => {}; } } }, {
|
|
16
|
+
worker: { call, epoch: 1 },
|
|
17
|
+
store,
|
|
18
|
+
dataDir,
|
|
19
|
+
owned: new Map(),
|
|
20
|
+
// The session permission gate is a callback in production (ctx.userQuestions behind it); the
|
|
21
|
+
// fixtures default to an armed session so tool bodies stay the thing under test.
|
|
22
|
+
ensureArmed: async () => armed,
|
|
23
|
+
...(activity === undefined ? {} : { activity }),
|
|
24
|
+
});
|
|
16
25
|
return { tools, store, dispose, execute: (name, args) => tools.get(name).execute(args, { signal: new AbortController().signal }) };
|
|
17
26
|
}
|
|
18
27
|
let passed = 0;
|
|
@@ -120,31 +129,24 @@ await test('repeating the same failing action is called out instead of invited',
|
|
|
120
129
|
assert.equal(n, 4, 'the watchdog must not suppress the action itself');
|
|
121
130
|
} finally { f.dispose(); }
|
|
122
131
|
});
|
|
123
|
-
await test('a send
|
|
132
|
+
await test('a send action is delivered when armed, and refused before the worker when not', async () => {
|
|
124
133
|
let acted = 0;
|
|
125
134
|
const send = { name: '发送', controlType: 'Button', availablePatterns: ['Invoke'], rect: { x: 1, y: 1, w: 10, h: 10 } };
|
|
126
|
-
const
|
|
135
|
+
const armed = fixture(async (cmd) => { if (cmd === 'describe') return send; if (cmd === 'act') { acted += 1; return { applied: true, via: 'uia', ms: 2 }; } return {}; });
|
|
127
136
|
try {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
assert.match(result,
|
|
131
|
-
assert.
|
|
132
|
-
assert.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
const answered = fixture(async (cmd) => {
|
|
137
|
-
if (cmd === 'describe') return send;
|
|
138
|
-
if (cmd === 'confirm') return { decision: 'allow', source: 'key', waitedMs: 120 };
|
|
139
|
-
if (cmd === 'act') { acted += 1; return { applied: true, via: 'uia', ms: 2 }; }
|
|
140
|
-
return {};
|
|
141
|
-
}, { indicator: { call: async (cmd, body) => { beats.push(`${cmd}:${body?.subtext ?? ''}`); return {}; } }, pointerMode: 'background' });
|
|
137
|
+
// The confirm family is gone: sending is ordinary work now, delivered without asking anyone.
|
|
138
|
+
const result = await armed.execute('computer_act', { windowId: 'w1', ref: 'e1', action: 'invoke' });
|
|
139
|
+
assert.match(result, /已执行/);
|
|
140
|
+
assert.doesNotMatch(result, /已拦截|ctrl\+alt\+y/);
|
|
141
|
+
assert.equal(acted, 1, 'an armed session must deliver the action');
|
|
142
|
+
} finally { armed.dispose(); }
|
|
143
|
+
const calls = [];
|
|
144
|
+
const disarmed = fixture(async (cmd) => { calls.push(cmd); if (cmd === 'describe') return send; return {}; }, undefined, { armed: false });
|
|
142
145
|
try {
|
|
143
|
-
const result = await
|
|
144
|
-
assert.
|
|
145
|
-
assert.
|
|
146
|
-
|
|
147
|
-
} finally { answered.dispose(); }
|
|
146
|
+
const result = await disarmed.execute('computer_act', { windowId: 'w1', ref: 'e1', action: 'invoke' });
|
|
147
|
+
assert.match(result, /桌面控制未获准/);
|
|
148
|
+
assert.deepEqual(calls, [], 'a disarmed session must not reach the worker at all');
|
|
149
|
+
} finally { disarmed.dispose(); }
|
|
148
150
|
});
|
|
149
151
|
|
|
150
152
|
await test('clipboard read is gated on this run having copied something itself', async () => {
|
|
@@ -189,4 +191,47 @@ await test('a finished run can leave a note that the next observation brings bac
|
|
|
189
191
|
} finally { g.dispose(); }
|
|
190
192
|
});
|
|
191
193
|
|
|
194
|
+
await test('a click can name a ref instead of coordinates, and the centre comes from its rect now', async () => {
|
|
195
|
+
const calls = [];
|
|
196
|
+
const f = fixture(async (cmd, body) => {
|
|
197
|
+
calls.push({ cmd, body });
|
|
198
|
+
if (cmd === 'describe') return { ref: 'e3', windowId: 'w1', name: '保存', controlType: 'Button', availablePatterns: ['Invoke'], rect: { x: 100, y: 200, w: 40, h: 20 } };
|
|
199
|
+
if (cmd === 'pointer_target') return { under: { title: 'w1', class: 'Button' } };
|
|
200
|
+
if (cmd === 'pointer_click') return { ms: 3, via: 'physical', under: { title: 'w1' }, mods: [] };
|
|
201
|
+
return {};
|
|
202
|
+
});
|
|
203
|
+
try {
|
|
204
|
+
const result = await f.execute('computer_click', { windowId: 'w1', ref: 'e3' });
|
|
205
|
+
const click = calls.find((c) => c.cmd === 'pointer_click');
|
|
206
|
+
assert.ok(click, 'the click never reached the worker');
|
|
207
|
+
assert.equal(click.body.x, 120, 'x must be the rect centre, not 0');
|
|
208
|
+
assert.equal(click.body.y, 210, 'y must be the rect centre, not 0');
|
|
209
|
+
assert.match(result, /已点击 e3/);
|
|
210
|
+
} finally { f.dispose(); }
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
await test('a mixed batch runs pointer steps in lazy mode and refuses to pretend otherwise', async () => {
|
|
214
|
+
const calls = [];
|
|
215
|
+
const f = fixture(async (cmd, body) => {
|
|
216
|
+
calls.push({ cmd, body });
|
|
217
|
+
if (cmd === 'describe') return { ref: 'e3', windowId: 'w1', name: '搜索', controlType: 'Edit', availablePatterns: ['Value'], rect: { x: 10, y: 10, w: 100, h: 20 } };
|
|
218
|
+
if (cmd === 'pointer_target') return { under: { title: 'w1', class: 'Edit' } };
|
|
219
|
+
return {};
|
|
220
|
+
});
|
|
221
|
+
try {
|
|
222
|
+
// Non-lazy: the whole point of that mode is that every target resolves before anything runs.
|
|
223
|
+
const refused = await f.execute('computer_run', { windowId: 'w1', goal: '混动作', steps: [{ action: 'click', ref: 'e3' }] });
|
|
224
|
+
assert.match(refused, /lazy: true/);
|
|
225
|
+
assert.deepEqual(calls, [], 'a refused mixed batch must not touch the worker');
|
|
226
|
+
// Lazy: click → type → key, each delivered on its own, stopping only on failure.
|
|
227
|
+
const result = await f.execute('computer_run', {
|
|
228
|
+
windowId: 'w1', goal: '混动作', lazy: true, saveRecipe: true,
|
|
229
|
+
steps: [{ action: 'click', ref: 'e3' }, { action: 'type', text: 'hello' }, { action: 'key', keys: 'enter' }],
|
|
230
|
+
});
|
|
231
|
+
assert.deepEqual(calls.map((c) => c.cmd), ['describe', 'pointer_click', 'type_text', 'key']);
|
|
232
|
+
assert.match(result, /performedCount=3/);
|
|
233
|
+
assert.match(result, /含指针步骤的批次不存配方/);
|
|
234
|
+
} finally { f.dispose(); }
|
|
235
|
+
});
|
|
236
|
+
|
|
192
237
|
console.log(`${passed}/${passed} tool regressions passed (no desktop actions)`);
|