dsh-native-uia 0.4.0 → 0.6.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/README.md +81 -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 +1 -1
- package/scripts/load-tools.mjs +1 -1
- package/scripts/measure-parse.mjs +2 -2
- package/scripts/regression-tools.mjs +69 -24
- package/scripts/verify.mjs +117 -7
- 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 +4 -4
- 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/scripts/regression-halt-latch.mjs +0 -100
- 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.0",
|
|
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');
|
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 });
|
|
@@ -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)`);
|
package/scripts/verify.mjs
CHANGED
|
@@ -179,6 +179,14 @@ gate('guard denies every category the user asked to block (MUST FIRE)', () => {
|
|
|
179
179
|
{ action: 'toggle', descriptor: { name: 'Delete all history', controlType: 'Button' } },
|
|
180
180
|
{ action: 'close_window', descriptor: { name: 'Settings', ownedByPlugin: false } },
|
|
181
181
|
{ action: 'launch', descriptor: {}, extra: 'shutdown.exe' },
|
|
182
|
+
// The interpreter family: refusing the six shutdown tools means nothing while `launch` will
|
|
183
|
+
// start a shell, because one typed line there runs anything the name table above refuses.
|
|
184
|
+
{ action: 'launch', descriptor: {}, extra: 'cmd.exe' },
|
|
185
|
+
{ action: 'launch', descriptor: {}, extra: 'C:\\Windows\\System32\\powershell.exe' },
|
|
186
|
+
{ action: 'launch', descriptor: {}, extra: 'CMD.EXE' },
|
|
187
|
+
{ action: 'launch', descriptor: {}, extra: 'wscript.exe' },
|
|
188
|
+
{ action: 'launch', descriptor: {}, extra: 'mshta.exe' },
|
|
189
|
+
{ action: 'launch', descriptor: {}, extra: 'taskmgr.exe' },
|
|
182
190
|
// The window-close affordance: invoking it ends the application exactly like Alt+F4, and it
|
|
183
191
|
// used to be allowed because the pattern only knew the words "退出程序"/"关闭程序".
|
|
184
192
|
{ action: 'invoke', descriptor: { name: '关闭', controlType: 'Button' } },
|
|
@@ -1050,9 +1058,9 @@ gate('the first delivery asks permission through the host question card, and ref
|
|
|
1050
1058
|
// Fail-closed: only the literal allow option arms the session.
|
|
1051
1059
|
assert(/armed = picked === '允许'/.test(index), 'the gate arms on something other than the explicit allow answer');
|
|
1052
1060
|
assert(/store\.armed = picked === '允许'/.test(index), 'the decision never reaches the store');
|
|
1053
|
-
const actSrc = readFileSync(join(ROOT, 'src', 'tools', 'defs', 'act.js'), 'utf8');
|
|
1054
|
-
assert(/ensureArmed\(exec\?\.agent, exec\.signal\)/.test(actSrc), 'the delivery tools do not consult the gate with their exec.agent + exec.signal');
|
|
1055
|
-
const pointerSrc = readFileSync(join(ROOT, 'src', 'tools', 'defs', 'pointer.js'), 'utf8');
|
|
1061
|
+
const actSrc = readFileSync(join(ROOT, 'src', 'tools', 'defs', 'act.js'), 'utf8');
|
|
1062
|
+
assert(/ensureArmed\(exec\?\.agent, exec\.signal\)/.test(actSrc), 'the delivery tools do not consult the gate with their exec.agent + exec.signal');
|
|
1063
|
+
const pointerSrc = readFileSync(join(ROOT, 'src', 'tools', 'defs', 'pointer.js'), 'utf8');
|
|
1056
1064
|
assert(/ensureArmed\(exec\?\.agent, exec\?\.signal\)/.test(pointerSrc), 'the pointer domain gate drops the abort signal');
|
|
1057
1065
|
// Un-armed refuses delivery at the choke point, before the spawn, without consuming the latch.
|
|
1058
1066
|
assert(/disarmed/.test(client), 'the worker client has no activation gate');
|
|
@@ -1316,7 +1324,7 @@ gate('the ambient palette is switchable from the plugin page and survives restar
|
|
|
1316
1324
|
assert(/id: 'orb'/.test(stylesBlock), 'the orb is no longer offered');
|
|
1317
1325
|
// The worker rejects an unknown style, so the two sides can never drift silently.
|
|
1318
1326
|
assert(/@\('orb','wave','mark','inverse'\) -notcontains \$st/.test(workerSrc), 'the worker stopped validating the style it is handed');
|
|
1319
|
-
return '2 ambient palettes,
|
|
1327
|
+
return '2 ambient palettes, four capsule shapes, switched on the plugin page, applied live and persisted';
|
|
1320
1328
|
});
|
|
1321
1329
|
|
|
1322
1330
|
gate('the capsule is built like an island, not a badge', () => {
|
|
@@ -1513,6 +1521,107 @@ gate('computer_snapshot exposes depth and passes it through as maxDepth', () =>
|
|
|
1513
1521
|
return 'depth parameter declared and forwarded as worker maxDepth';
|
|
1514
1522
|
});
|
|
1515
1523
|
|
|
1524
|
+
gate('a snapshot node publishes its state, cached first with one budgeted live read', () => {
|
|
1525
|
+
// The tree used to answer "does this node support Toggle" and never "is it ON". A checked and an
|
|
1526
|
+
// unchecked checkbox rendered identically, a selected row looked like any other row, and the
|
|
1527
|
+
// model had to act blind or take a second observation after every click. State is now part of the
|
|
1528
|
+
// node, read from the cache the snapshot already materialised; providers that hand back an empty
|
|
1529
|
+
// cached struct (Explorer's shell items) get ONE live read, capped per snapshot.
|
|
1530
|
+
const tools = toolsSource();
|
|
1531
|
+
const ps = workerSource();
|
|
1532
|
+
const snap = tools.match(/name: 'computer_snapshot'([\s\S]*?)\n \}\)\)\);/)?.[1] ?? '';
|
|
1533
|
+
assert(snap !== '', 'computer_snapshot is missing');
|
|
1534
|
+
assert(/state \(toggle\/selected\/expanded\/range\/scroll\)/.test(snap), 'the snapshot description stopped promising node state');
|
|
1535
|
+
assert(/function State-Of\(/.test(ps), 'State-Of is gone: nodes cannot report toggle/selected/expanded/range/scroll');
|
|
1536
|
+
assert(/function State-Missing\(/.test(ps), 'State-Missing is gone: the live fallback can no longer tell a missing field from a missing state');
|
|
1537
|
+
assert(/GetCachedPattern/.test(ps) && /GetCurrentPattern/.test(ps), 'state reads no longer have both a cached and a live path');
|
|
1538
|
+
const cache = ps.match(/\$script:snapPatterns = @\(([\s\S]*?)\)/)?.[1] ?? '';
|
|
1539
|
+
assert(/SelectionItemPattern/.test(cache) && /ScrollPattern/.test(cache), 'the cache request no longer materialises SelectionItem/Scroll, so selected/scroll state silently disappears');
|
|
1540
|
+
assert(/State-Of \$el \$patterns \$true/.test(ps), 'Build-SnapshotNode no longer tries the cached state read');
|
|
1541
|
+
assert(/stateLiveBudget/.test(ps) && /State-Missing \$patterns \$st/.test(ps), 'the live state fallback lost its budget or its trigger');
|
|
1542
|
+
assert(/\$node\['state'\] = \$st/.test(ps), 'the node no longer carries the state it read');
|
|
1543
|
+
// The renderer must actually show it, or the worker pays for fields nobody reads.
|
|
1544
|
+
assert(/function stateText\(/.test(tools), 'the renderer lost stateText: state is collected and never printed');
|
|
1545
|
+
assert(/stateText\(n\.state\)/.test(tools), 'renderTree no longer prints node state');
|
|
1546
|
+
return 'toggle/selected/expanded/range/scroll on the node, cached first, live reads budgeted, rendered';
|
|
1547
|
+
});
|
|
1548
|
+
|
|
1549
|
+
gate('the tree can be walked in the raw/content views and drilled from a ref subtree', () => {
|
|
1550
|
+
// Coverage is a VIEW question, not a depth question: ControlView is the curated tree providers
|
|
1551
|
+
// publish, and "this Pane has nothing inside" is usually a ControlView answer. Raw exposes the
|
|
1552
|
+
// plumbing panes; a subtree root turns one located container into a cheap deep pass.
|
|
1553
|
+
const tools = toolsSource();
|
|
1554
|
+
const ps = workerSource();
|
|
1555
|
+
assert(/RawViewWalker/.test(ps) && /ContentViewWalker/.test(ps), 'the raw/content walkers are gone: only the curated tree is reachable');
|
|
1556
|
+
assert(/Get-SnapshotWalker \$view/.test(ps), 'Build-Snapshot walks a fixed view again');
|
|
1557
|
+
assert(/StrArg \$A 'view'/.test(ps), 'Build-Snapshot no longer reads the view argument');
|
|
1558
|
+
assert(/\$subReq = if \(\$view -eq 'control'\)/.test(ps), 'a non-control view can reach the one-shot cache path, which cannot honour it');
|
|
1559
|
+
assert(/StrArg \$A 'root'/.test(ps) && /Resolve-Ref \$rootRef/.test(ps), 'the subtree root argument is gone: digging into one container means re-snapshotting the window');
|
|
1560
|
+
assert(/if \(\$null -eq \$rootEl\) \{ \$entry\.revision \+= 1 \}/.test(ps), 'a subtree pass bumps the revision again, which invalidates the skeleton the caller just read');
|
|
1561
|
+
assert(/\$result\['subtree'\] = \$true/.test(ps), 'the reply no longer says it was a subtree pass');
|
|
1562
|
+
const snap = tools.match(/name: 'computer_snapshot'([\s\S]*?)\n \}\)\)\);/)?.[1] ?? '';
|
|
1563
|
+
assert(/enum: \['control', 'raw', 'content'\]/.test(snap), 'computer_snapshot has no view parameter');
|
|
1564
|
+
assert(/view: args\.view/.test(snap) && /root: args\.root/.test(snap), 'view/root are declared but not forwarded to the worker');
|
|
1565
|
+
assert(/\[cut\]/.test(tools), 'the per-node cut marker is gone: the reply stops saying where the walk stopped');
|
|
1566
|
+
return 'control/raw/content views, subtree root that keeps the revision, per-node cut markers';
|
|
1567
|
+
});
|
|
1568
|
+
|
|
1569
|
+
gate('find_text can be scoped to one container instead of scanning the window', () => {
|
|
1570
|
+
// The documented rhythm was "find_text into the container you located" with no way to name the
|
|
1571
|
+
// container, so every search paid the whole window (1-3 ms per element). within=<ref> makes the
|
|
1572
|
+
// promise real, and the reply says which scope produced the hits.
|
|
1573
|
+
const tools = toolsSource();
|
|
1574
|
+
const ps = workerSource();
|
|
1575
|
+
assert(/StrArg \$A 'within'/.test(ps) && /Resolve-Ref \$within/.test(ps), 'Cmd-FindText no longer scopes its scan by ref');
|
|
1576
|
+
assert(/\$r\['within'\] = \$within/.test(ps), 'the find_text reply no longer reports its within scope');
|
|
1577
|
+
const ft = tools.match(/name: 'computer_find_text'([\s\S]*?)\n \}\)\)\);/)?.[1] ?? '';
|
|
1578
|
+
assert(ft !== '', 'computer_find_text is missing');
|
|
1579
|
+
assert(/within: \{ \.\.\.STR/.test(ft), 'computer_find_text has no within parameter');
|
|
1580
|
+
assert(/within: args\.within/.test(ft), 'within is declared but not forwarded to the worker');
|
|
1581
|
+
assert(/scopeText/.test(ft), 'a scoped search no longer says it was scoped, so a zero-hit reply reads as "the text does not exist"');
|
|
1582
|
+
return 'within=<ref> reaches the worker and every reply names its scope';
|
|
1583
|
+
});
|
|
1584
|
+
|
|
1585
|
+
gate('the action surface covers range/selection/scroll-item, not only the original patterns', () => {
|
|
1586
|
+
// Four verbs that existed only as "you could drag it and hope": set_range (sliders/spinners),
|
|
1587
|
+
// scroll_to (bring one item into view via the provider), deselect / add_to_selection (multi-select
|
|
1588
|
+
// lists where `select` alone resets the selection).
|
|
1589
|
+
const tools = toolsSource();
|
|
1590
|
+
const ps = workerSource();
|
|
1591
|
+
for (const verb of ['deselect', 'add_to_selection', 'scroll_to', 'set_range']) {
|
|
1592
|
+
assert(new RegExp(`'${verb}' \\{`).test(ps), `the worker has no ${verb} branch`);
|
|
1593
|
+
}
|
|
1594
|
+
assert(/RemoveFromSelection\(\)/.test(ps) && /AddToSelection\(\)/.test(ps), 'deselect/add_to_selection lost their UIA calls');
|
|
1595
|
+
assert(/ScrollIntoView\(\)/.test(ps), 'scroll_to lost ScrollIntoView');
|
|
1596
|
+
assert(/SetValue\(\$num\)/.test(ps), 'set_range never calls RangeValue.SetValue');
|
|
1597
|
+
assert(/ScrollItem\s*=\s*\[System\.Windows\.Automation\.ScrollItemPattern\]/.test(ps), 'ScrollItem is not in the pattern table, so scroll_to can never obtain an object');
|
|
1598
|
+
const act = tools.match(/name: 'computer_act'([\s\S]*?)\n \}\)\)\);/)?.[1] ?? '';
|
|
1599
|
+
for (const verb of ["'deselect'", "'add_to_selection'", "'scroll_to'", "'set_range'"]) {
|
|
1600
|
+
assert(act.includes(verb), `computer_act does not declare ${verb}`);
|
|
1601
|
+
}
|
|
1602
|
+
assert(/ACT_VERBS = new Set\(\[[^\]]*'RangeValue'/.test(tools), 'RangeValue is not advertised as actionable even though set_range exists');
|
|
1603
|
+
assert(/ACT_VERBS = new Set\(\[[^\]]*'ScrollItem'/.test(tools), 'ScrollItem is not advertised, so scroll_to targets never look actionable');
|
|
1604
|
+
return 'deselect/add_to_selection/scroll_to/set_range wired end to end, ScrollItem obtainable';
|
|
1605
|
+
});
|
|
1606
|
+
|
|
1607
|
+
gate('pointer tools take a ref, and a mixed batch runs one step at a time', () => {
|
|
1608
|
+
// Physical actions were coordinate-only, so any model that had a ref still had to do rect
|
|
1609
|
+
// arithmetic (and could click where the element USED to be). And a batch could only carry UIA
|
|
1610
|
+
// verbs, so "click the field, type, press enter" was three calls with no shared stop rule.
|
|
1611
|
+
const tools = toolsSource();
|
|
1612
|
+
const block = (name) => tools.match(new RegExp(`name: '${name}'([\\s\\S]*?)\\n \\}\\)\\)\\);`))?.[1] ?? '';
|
|
1613
|
+
for (const tool of ['computer_click', 'computer_drag', 'computer_scroll', 'computer_mouse']) {
|
|
1614
|
+
const b = block(tool);
|
|
1615
|
+
assert(b !== '', `${tool} is missing`);
|
|
1616
|
+
assert(/ref: \{ \.\.\.STR/.test(b), `${tool} has no ref parameter`);
|
|
1617
|
+
}
|
|
1618
|
+
assert(/resolvePoint/.test(tools) && /worker\.call\('describe'/.test(tools), 'the pointer path no longer derives a centre from describe');
|
|
1619
|
+
assert(/POINTER_STEPS/.test(tools) && /runPointerStep/.test(tools), 'the lazy batch has no pointer step path');
|
|
1620
|
+
assert(/lazy: true/.test(tools), 'a mixed batch no longer tells the caller how to run it');
|
|
1621
|
+
assert(/含指针步骤的批次不存配方/.test(tools), 'mixed batches may still be saved as recipes (coordinates drift)');
|
|
1622
|
+
return 'ref targets on click/drag/scroll/mouse; click/type/key/scroll/drag/wait run inside a lazy batch';
|
|
1623
|
+
});
|
|
1624
|
+
|
|
1516
1625
|
gate('find_text ranks actionable hits first and labels containers', () => {
|
|
1517
1626
|
// Searching a window title ("插件") matches the window's own Pane and Document first — both huge,
|
|
1518
1627
|
// both clickable only in the "focus the window" sense. A model reading top-down picks #1 and
|
|
@@ -2031,7 +2140,7 @@ gate('the confirm layer stays removed, and the policy has no interactive verdict
|
|
|
2031
2140
|
assert(!/verdict: 'confirm'/.test(guard), 'classify() can return a confirm verdict again');
|
|
2032
2141
|
assert(!/confirmable/.test(guard), 'POLICY grew a confirmable flag again');
|
|
2033
2142
|
assert(!/ctrl\+alt\+y/.test(guard), 'the allow chord is back in the policy wording');
|
|
2034
|
-
assert(/deniedCategories: \['shutdown', '
|
|
2143
|
+
assert(/deniedCategories: \['shutdown', 'exit', 'delete', 'loop', 'shell'\]/.test(guard), 'the hard-refuse list changed');
|
|
2035
2144
|
assert(/approvable: false/.test(guard), 'POLICY made refusals approvable again');
|
|
2036
2145
|
// No caller, no handler, no import of the deleted module.
|
|
2037
2146
|
assert(!/askConfirm/.test(act), 'act.js asks the confirm gate again');
|
|
@@ -2067,8 +2176,8 @@ gate('notes persist across runs, and the clipboard read stays gated on the run o
|
|
|
2067
2176
|
assert(!/Set-Clipboard -Value ''/.test(ps), "Set-Clipboard -Value '' throws on Windows PowerShell 5.1; use [string[]]@()");
|
|
2068
2177
|
assert((ps.match(/\[string\[\]\]@\(\)/g) ?? []).length >= 2, 'clear and empty write no longer both use the empty-array form');
|
|
2069
2178
|
const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
|
|
2070
|
-
assert(pkg.version === '0.
|
|
2071
|
-
return 'notes capped/deduped/sanitised and read back by observations; clipboard read gated on ctrl+c; version 0.
|
|
2179
|
+
assert(pkg.version === '0.6.0', `package.json version is ${pkg.version}, not the 0.6.0 this work is released as`);
|
|
2180
|
+
return 'notes capped/deduped/sanitised and read back by observations; clipboard read gated on ctrl+c; version 0.6.0';
|
|
2072
2181
|
});
|
|
2073
2182
|
|
|
2074
2183
|
gate('the worker body lives in lib, and the entry dot-sources the same list the gates read', () => {
|
|
@@ -2101,6 +2210,7 @@ gate('the split tool modules actually resolve and register as a graph', () => {
|
|
|
2101
2210
|
assert(existsSync(join(ROOT, rel)), `${rel} is missing from the split`);
|
|
2102
2211
|
}
|
|
2103
2212
|
assert(!existsSync(join(ROOT, 'src', 'tools.js')), 'src/tools.js came back: one tool source or the other, not both');
|
|
2213
|
+
assert(!existsSync(join(ROOT, 'src', 'native-uia-remote.js')), 'native-uia-remote.js came back: the panel polls the loopback service, there is no host remote channel');
|
|
2104
2214
|
assert(/TOOLS_FILES/.test(readFileSync(join(ROOT, 'scripts', 'lib', 'sources.mjs'), 'utf8')), 'sources.mjs no longer declares the concatenation order');
|
|
2105
2215
|
return `graph loads: ${out.trim().split('\n').pop()}`;
|
|
2106
2216
|
});
|
package/src/guard.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* `commit_batch`, so one guard covers interactive calls and replayed recipes.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const RISKY_ACTIONS = new Set(['invoke', 'toggle', 'select'
|
|
7
|
+
const RISKY_ACTIONS = new Set(['invoke', 'toggle', 'select']);
|
|
8
8
|
|
|
9
9
|
const SHUTDOWN = /(?:\b(?:shut\s*down|shutdown|power\s*off|restart|reboot|sign\s*out|log\s*off|logoff|log\s*out|hibernate)\b|关机|注销|重启|休眠|退出登录)/i;
|
|
10
10
|
// A window's close affordance is called 关闭 / Close / ✕ in real UIA trees, not "关闭程序". Without
|
|
@@ -15,7 +15,16 @@ const SHUTDOWN = /(?:\b(?:shut\s*down|shutdown|power\s*off|restart|reboot|sign\s
|
|
|
15
15
|
const EXIT = /(?:^(?:exit|quit|close\s*(?:app|application|program))\b|^(?:close|关闭|✕|✖|×)$|退出(?:程序|应用)|关闭(?:程序|应用|窗口))/i;
|
|
16
16
|
const DELETE = /(?:\b(?:delete|remove|discard|erase|empty\s+recycle\s+bin|shred)\b|删除|彻底删除|清空回收站|丢弃)/i;
|
|
17
17
|
|
|
18
|
+
// The interpreter family. Refusing the six shutdown tools by name is worth nothing if `launch` will
|
|
19
|
+
// happily start cmd.exe, because one typed line there runs anything the name table below refuses —
|
|
20
|
+
// including the shutdown the person just denied. These are the shells and script hosts Windows
|
|
21
|
+
// ships, plus the process/task managers that can end an application without going through EXIT.
|
|
18
22
|
const DENY_EXECUTABLES = /^(?:shutdown|logoff|taskkill|psshutdown|restart|poweroff)\.exe$/i;
|
|
23
|
+
const DENY_SHELLS = new Set([
|
|
24
|
+
'cmd.exe', 'powershell.exe', 'pwsh.exe', 'wscript.exe', 'cscript.exe', 'mshta.exe',
|
|
25
|
+
'rundll32.exe', 'regsvr32.exe', 'reg.exe', 'wsl.exe', 'bash.exe', 'wt.exe', 'conhost.exe',
|
|
26
|
+
'taskmgr.exe', 'msconfig.exe', 'mmc.exe',
|
|
27
|
+
]);
|
|
19
28
|
|
|
20
29
|
const CATEGORIES = {
|
|
21
30
|
shutdown: {
|
|
@@ -34,6 +43,10 @@ const CATEGORIES = {
|
|
|
34
43
|
refusal: '同批内连续重复同一滚动动作且没有任何结果校验(疑似无效滚动循环)',
|
|
35
44
|
advice: '先重新 snapshot/find_text 观察列表是否真的滚动了;或给滚动步加 verify:{type:"scroll_percent_changed"},滚动无效果时批次会停下来。',
|
|
36
45
|
},
|
|
46
|
+
shell: {
|
|
47
|
+
refusal: '启动命令行或脚本宿主',
|
|
48
|
+
advice: '这类程序能把上面每一条拒收改写成一行命令,所以整族不开放;需要命令行的步骤请让用户自己开终端执行,应用请用它的正常入口启动。',
|
|
49
|
+
},
|
|
37
50
|
};
|
|
38
51
|
|
|
39
52
|
function text(descriptor) {
|
|
@@ -42,11 +55,10 @@ function text(descriptor) {
|
|
|
42
55
|
.join(' ');
|
|
43
56
|
}
|
|
44
57
|
|
|
45
|
-
function categoryOf(descriptor
|
|
58
|
+
function categoryOf(descriptor) {
|
|
46
59
|
const hay = `${text(descriptor)} ${descriptor?.command ?? ''}`.trim();
|
|
47
60
|
if (hay === '') return null;
|
|
48
61
|
if (SHUTDOWN.test(hay)) return 'shutdown';
|
|
49
|
-
if (action === 'close_window') return null;
|
|
50
62
|
if (EXIT.test(hay)) return 'exit';
|
|
51
63
|
if (DELETE.test(hay)) return 'delete';
|
|
52
64
|
return null;
|
|
@@ -81,7 +93,7 @@ export function classifyKeys(combo) {
|
|
|
81
93
|
if (hay === '') return { verdict: 'allow' };
|
|
82
94
|
if (KEY_LOCK.test(hay)) return denied('shutdown'); // win+l locks the session
|
|
83
95
|
if (KEY_EXIT.test(hay)) return denied('exit'); // alt+f4 closes the focused app
|
|
84
|
-
const category = categoryOf({ name: hay, command: hay }
|
|
96
|
+
const category = categoryOf({ name: hay, command: hay });
|
|
85
97
|
if (category === null) return { verdict: 'allow' };
|
|
86
98
|
return denied(category);
|
|
87
99
|
}
|
|
@@ -96,7 +108,7 @@ export function classify(request) {
|
|
|
96
108
|
// one policy gate must normalise before matching or a case variant sails past the text refusal.
|
|
97
109
|
const action = String(request.action ?? '').toLowerCase();
|
|
98
110
|
if (!RISKY_ACTIONS.has(action)) return { verdict: 'allow' };
|
|
99
|
-
const category = categoryOf(request.descriptor
|
|
111
|
+
const category = categoryOf(request.descriptor);
|
|
100
112
|
if (category === null) return { verdict: 'allow' };
|
|
101
113
|
return verdictFor(category);
|
|
102
114
|
}
|
|
@@ -177,14 +189,21 @@ export function classifyClose(descriptor) {
|
|
|
177
189
|
export function classifyLaunch(app) {
|
|
178
190
|
const leaf = String(app ?? '').trim().split(/[\\/]/).pop() ?? '';
|
|
179
191
|
if (DENY_EXECUTABLES.test(leaf)) {
|
|
180
|
-
return
|
|
192
|
+
return denied('shutdown');
|
|
193
|
+
}
|
|
194
|
+
// Case-insensitive because Windows is: `CMD.EXE` is the same program.
|
|
195
|
+
if (DENY_SHELLS.has(leaf.toLowerCase())) {
|
|
196
|
+
return denied('shell');
|
|
181
197
|
}
|
|
182
198
|
return { verdict: 'allow' };
|
|
183
199
|
}
|
|
184
200
|
|
|
185
201
|
export const POLICY = {
|
|
186
202
|
mode: 'dev',
|
|
187
|
-
|
|
203
|
+
// Every key that can appear in a verdict, and nothing else: this list is read by the panel and by
|
|
204
|
+
// the model-facing note, so a name here that no CATEGORIES entry defines is a claim about a rule
|
|
205
|
+
// that does not exist.
|
|
206
|
+
deniedCategories: ['shutdown', 'exit', 'delete', 'loop', 'shell'],
|
|
188
207
|
// Every refusal is final: nothing here can be turned into a button, and there is no interactive
|
|
189
208
|
// verdict at all. The former "hold for a person at the keyboard" family is gone -- it drew a
|
|
190
209
|
// permission prompt on the capsule, which is not a channel this plugin owns.
|
package/src/index.js
CHANGED
|
@@ -19,7 +19,7 @@ export const inject = ['tools', 'systemPrompt'];
|
|
|
19
19
|
const INDICATOR_SCRIPT = fileURLToPath(new URL('../worker/indicator-server.ps1', import.meta.url));
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* How long a
|
|
22
|
+
* How long a stop (Esc / the panel's stop) keeps refusing input.
|
|
23
23
|
*
|
|
24
24
|
* The latch exists to stop the command that was ALREADY in flight when the person hit stop —
|
|
25
25
|
* killing the worker is what surfaces that pending commit as WorkerDeadError. It must not
|
|
@@ -57,7 +57,7 @@ export function apply(ctx, config = {}) {
|
|
|
57
57
|
// plugin page all have to report the same number that is actually in force.
|
|
58
58
|
const leaseMs = Number(config.leaseMs ?? process.env.DSH_NATIVE_UIA_LEASE_MS ?? 300000) || 300000;
|
|
59
59
|
// The chosen action-delivery mode must survive an app restart; without this the store resets to
|
|
60
|
-
// its hardcoded default ('background') every launch, so the
|
|
60
|
+
// its hardcoded default ('background') every launch, so the panel's toggle looked like it
|
|
61
61
|
// forgot the user's pick.
|
|
62
62
|
const settingsPath = join(dataDir, 'settings.json');
|
|
63
63
|
const saveSettings = () => {
|
|
@@ -101,7 +101,7 @@ export function apply(ctx, config = {}) {
|
|
|
101
101
|
// The overlay process dying used to be nearly silent (a WPF composition-thread COM crash was
|
|
102
102
|
// observed in the wild: WER event 1001, DUCE.Channel.SyncFlush, Node only saw "exit 2"). The
|
|
103
103
|
// exit handler logs one info line; this warn-level event makes the crash readable from the
|
|
104
|
-
//
|
|
104
|
+
// panel log. Recovery needs no new code: the lazy start in CuaWorker.call respawns the
|
|
105
105
|
// process on the next indicator command, and Cmd-Beat/Cmd-Show re-light an invisible window.
|
|
106
106
|
onEvent: (kind, payload) => {
|
|
107
107
|
if (kind === 'worker' && payload?.started === false) {
|
|
@@ -244,7 +244,7 @@ export function apply(ctx, config = {}) {
|
|
|
244
244
|
logger('已从插件面板终止:worker 停止,在飞动作中断', 'error');
|
|
245
245
|
return { ok: true };
|
|
246
246
|
}
|
|
247
|
-
return { ok: false, error: `未知操作 "${kind}"(mode|kill)` };
|
|
247
|
+
return { ok: false, error: `未知操作 "${kind}"(mode|theme|style|mist|kill)` };
|
|
248
248
|
},
|
|
249
249
|
};
|
|
250
250
|
|
|
@@ -255,8 +255,8 @@ export function apply(ctx, config = {}) {
|
|
|
255
255
|
policy: POLICY,
|
|
256
256
|
commands,
|
|
257
257
|
// What the plugin page reports but cannot change from there: the bind address, the read-only
|
|
258
|
-
// switch (activation env), and the two timeouts.
|
|
259
|
-
//
|
|
258
|
+
// switch (activation env), and the two timeouts. pointerMode/theme/style/mist are the four
|
|
259
|
+
// writable settings, and they go through the same action the panel uses.
|
|
260
260
|
config: () => ({
|
|
261
261
|
host, port, readOnly: store.readOnly === true, leaseMs, idleMs: idleTimeoutMs(),
|
|
262
262
|
// Catalogs, not free text: the panel renders exactly what the worker can build, and a name
|
|
@@ -264,40 +264,6 @@ export function apply(ctx, config = {}) {
|
|
|
264
264
|
themes: THEMES, styles: STYLES, defaultTheme: DEFAULT_THEME, defaultStyle: DEFAULT_STYLE,
|
|
265
265
|
}),
|
|
266
266
|
});
|
|
267
|
-
// The native client channel: the panel component calls ctx.remote.nativeUia.*
|
|
268
|
-
// instead of fetching a loopback port, so it inherits host theme tokens and locale.
|
|
269
|
-
// Imported lazily and guarded: a resolution or decorator failure must not take
|
|
270
|
-
// the plugin down, and the reason has to be readable from the panel's own log.
|
|
271
|
-
store.remoteChannel = 'pending';
|
|
272
|
-
const mountRemoteChannel = async () => {
|
|
273
|
-
try {
|
|
274
|
-
const { NativeUiaRemote } = await import('./native-uia-remote.js');
|
|
275
|
-
// The instance self-registers inside the base constructor (TypertRemoteService mounts it on
|
|
276
|
-
// ctx.remote); nothing reads the handle afterwards — the mount-state carrier is
|
|
277
|
-
// store.remoteChannel, so a bare `new` keeps the guard shape without a dead variable.
|
|
278
|
-
new NativeUiaRemote(ctx, { store, commands, policy: POLICY });
|
|
279
|
-
store.remoteChannel = 'mounted';
|
|
280
|
-
logger('宿主通道已挂载:ctx.remote.nativeUia');
|
|
281
|
-
} catch (error) {
|
|
282
|
-
store.remoteChannel = { failed: true, reason: String(error?.message ?? error) };
|
|
283
|
-
logger(`宿主通道挂载失败,面板回退回环接口:${store.remoteChannel.reason}`, 'error');
|
|
284
|
-
// Control experiment: both specifiers sit at the same level of the app's own
|
|
285
|
-
// node_modules. If one resolves and the other does not, the host resolver is
|
|
286
|
-
// composition-scoped, not Node-scoped, and a plugin cannot import a library
|
|
287
|
-
// that no bundle depends on.
|
|
288
|
-
const probed = [];
|
|
289
|
-
for (const spec of ['@deepseek-ai/dsh-tools', '@deepseek-ai/dsh-typert-protocol', '@deepseek-ai/cordis']) {
|
|
290
|
-
try {
|
|
291
|
-
await import(spec);
|
|
292
|
-
probed.push(`${spec}=ok`);
|
|
293
|
-
} catch (probeError) {
|
|
294
|
-
probed.push(`${spec}=${String(probeError?.code ?? probeError?.message ?? 'fail')}`);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
logger(`解析对照:${probed.join(' ')}`, 'warn');
|
|
298
|
-
}
|
|
299
|
-
store.emit('state', { reason: 'remote' });
|
|
300
|
-
};
|
|
301
267
|
// ---- the permission question: asked at FIRST DELIVERY, not at activation ----
|
|
302
268
|
// Measured: asking at activation always fails with NO_PROVIDER — the answerer for
|
|
303
269
|
// user-questions/request is the session UI, and at activation there is no live agent/session to
|
|
@@ -412,9 +378,6 @@ export function apply(ctx, config = {}) {
|
|
|
412
378
|
logger('契约:心跳只喂渲染不续租,静默 run 在租约内自动收尾;Esc 主通道=指示层进程;find_text 已暴露为工具');
|
|
413
379
|
|
|
414
380
|
// ---- permission question: asked at FIRST DELIVERY (see ensureArmed above) ----
|
|
415
|
-
// The service is resolved here; the ask itself lives in ensureArmed, which the delivery tools
|
|
416
|
-
// call with the exec.agent of their first mutating command.
|
|
417
|
-
void mountRemoteChannel();
|
|
418
381
|
const reservation = optional('computerUse');
|
|
419
382
|
if (reservation !== undefined && reservation !== null) {
|
|
420
383
|
try {
|
|
@@ -424,8 +387,6 @@ export function apply(ctx, config = {}) {
|
|
|
424
387
|
logger(`computer-use 槽位已被其它 provider 占用:${error?.message ?? error}`, 'error');
|
|
425
388
|
}
|
|
426
389
|
}
|
|
427
|
-
store.visionRoute = optional('attachments') !== undefined;
|
|
428
|
-
|
|
429
390
|
const unregisterPrompt = ctx.systemPrompt.section({
|
|
430
391
|
name: 'computer-use:native-uia',
|
|
431
392
|
order: 3000,
|
|
@@ -449,8 +410,9 @@ export function apply(ctx, config = {}) {
|
|
|
449
410
|
logger(`屏幕指示层不可用,桌面动作照常执行:${error?.message ?? error}`, 'warn');
|
|
450
411
|
}
|
|
451
412
|
|
|
452
|
-
// Global Esc-to-stop: the
|
|
453
|
-
// the overlay is up the host
|
|
413
|
+
// Global Esc-to-stop: the indicator overlay cannot take keyboard focus (it is a click-through
|
|
414
|
+
// window), so while the overlay is up the host polls for a physically-held VK_ESCAPE and ends
|
|
415
|
+
// the run.
|
|
454
416
|
// The INDICATOR process is the primary channel: it is idle by design and answers in ms, while
|
|
455
417
|
// the worker may sit inside a 40 s OCR or a long batch, where a queued probe cannot even run —
|
|
456
418
|
// a tapped Esc is released long before that queue drains. The worker stays as fallback for
|
|
@@ -458,7 +420,7 @@ export function apply(ctx, config = {}) {
|
|
|
458
420
|
// own per-step Esc check: that one reads "held right now" only at step boundaries, so a tap
|
|
459
421
|
// released mid-step is invisible to it and the batch would run to completion, come back
|
|
460
422
|
// "all passed" and save a recipe for a run the user just stopped. That is why the handler
|
|
461
|
-
// below shuts the worker down exactly like the
|
|
423
|
+
// below shuts the worker down exactly like the panel's stop — the pending commit comes
|
|
462
424
|
// back as WorkerDeadError, which computer_run reports as "user stopped, nothing rolled back".
|
|
463
425
|
let escBusy = false;
|
|
464
426
|
const escTimer = setInterval(() => {
|
|
@@ -489,7 +451,7 @@ export function apply(ctx, config = {}) {
|
|
|
489
451
|
if (r && r.pressed === true) {
|
|
490
452
|
store.setKilled(true);
|
|
491
453
|
void activity.end({ reason: '用户按下 Esc' });
|
|
492
|
-
// Same closing sequence as the
|
|
454
|
+
// Same closing sequence as the panel's stop above: a batch already mid-flight
|
|
493
455
|
// cannot see a tap (its per-step check needs the key held across a boundary), so
|
|
494
456
|
// without the shutdown it runs to completion and saves a recipe. Killing the worker
|
|
495
457
|
// surfaces the pending commit as WorkerDeadError. The latch is armed WITH a timestamp
|