dsh-native-uia 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +663 -2
- package/client/client.js +269 -0
- package/cordis.patch.yml +10 -0
- package/icon.svg +11 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +75 -4
- package/scripts/bench-live.mjs +157 -0
- package/scripts/check-lease.mjs +308 -0
- package/scripts/install.mjs +154 -0
- package/scripts/lib/dsh-tools-stub.mjs +14 -0
- package/scripts/lib/load-tools-source.mjs +25 -0
- package/scripts/lib/sources.mjs +62 -0
- package/scripts/load-tools.mjs +74 -0
- package/scripts/measure-parse.mjs +77 -0
- package/scripts/regression-halt-latch.mjs +100 -0
- package/scripts/regression-quality.mjs +207 -0
- package/scripts/regression-tools.mjs +192 -0
- package/scripts/regression-worker.ps1 +1071 -0
- package/scripts/smoke.mjs +158 -0
- package/scripts/verify-capture-scale.mjs +37 -0
- package/scripts/verify-live-clipboard.mjs +108 -0
- package/scripts/verify-live-style.mjs +46 -0
- package/scripts/verify-live.mjs +104 -0
- package/scripts/verify-locator.mjs +52 -0
- package/scripts/verify.mjs +2110 -0
- package/src/activity-window.js +276 -0
- package/src/dashboard.js +103 -0
- package/src/guard.js +201 -0
- package/src/index.js +525 -0
- package/src/native-uia-remote.js +80 -0
- package/src/notes.js +83 -0
- package/src/state.js +267 -0
- package/src/themes.js +74 -0
- package/src/tools/defs/act.js +533 -0
- package/src/tools/defs/lifecycle.js +205 -0
- package/src/tools/defs/observe.js +309 -0
- package/src/tools/defs/pointer.js +298 -0
- package/src/tools/format.js +301 -0
- package/src/tools/index.js +128 -0
- package/src/tools/ocr.js +91 -0
- package/src/tools/recipes.js +44 -0
- package/src/tools/runtime.js +42 -0
- package/src/worker-client.js +268 -0
- package/worker/assets/dsh-whale.path +1 -0
- package/worker/bin/build-ocr.ps1 +41 -0
- package/worker/bin/ocr.cs +69 -0
- package/worker/bin/ocr.exe +0 -0
- package/worker/indicator-server.ps1 +2963 -0
- package/worker/lib/01-core.ps1 +64 -0
- package/worker/lib/02-uia.ps1 +221 -0
- package/worker/lib/03-window.ps1 +194 -0
- package/worker/lib/04-match.ps1 +435 -0
- package/worker/lib/05-value.ps1 +149 -0
- package/worker/lib/06-snapshot.ps1 +345 -0
- package/worker/lib/07-action.ps1 +291 -0
- package/worker/lib/08-command.ps1 +1485 -0
- package/worker/lib/09-pointer.ps1 +840 -0
- package/worker/lib/10-dispatch.ps1 +134 -0
- package/worker/ps-stdio.ps1 +173 -0
- package/worker/uia-worker.ps1 +599 -0
package/client/client.js
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-native-uia',
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
const module = { exports: {} };
|
|
5
|
+
const exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
7
|
+
/* Only platform seed words may be required here. `require("zod")` is present in
|
|
8
|
+
generated host artifacts but NOT in the plugin client module table, and a
|
|
9
|
+
missing module at import time aborts the whole web boot. */
|
|
10
|
+
const react = require('react');
|
|
11
|
+
|
|
12
|
+
const PKG = 'dsh-native-uia';
|
|
13
|
+
const SERVICE = 'http://127.0.0.1:3099';
|
|
14
|
+
/** Writes must carry this; the server refuses anything else. It is a CSRF marker, not a secret. */
|
|
15
|
+
const API_HEADER = 'x-dsh-cua';
|
|
16
|
+
const POLL_MS = 1500;
|
|
17
|
+
|
|
18
|
+
const css = '.dsh-uia-row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}'
|
|
19
|
+
+ '.dsh-uia-name{font-weight:600;margin-right:4px}'
|
|
20
|
+
+ '.dsh-uia-label{color:var(--dsw-alias-label-tertiary);font-size:12px}'
|
|
21
|
+
// Transitions on the control itself: a border and a colour change with no transition read as
|
|
22
|
+
// a jump, and a jump on every click is what "not smooth" meant. 120 ms is under the threshold
|
|
23
|
+
// where a control feels laggy but long enough to be perceived as movement.
|
|
24
|
+
+ '.dsh-uia-btn{font:inherit;font-size:12px;line-height:18px;padding:2px 10px;border-radius:6px;border:1px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer;transition:border-color 120ms ease,color 120ms ease,background-color 120ms ease}'
|
|
25
|
+
+ '.dsh-uia-btn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}'
|
|
26
|
+
+ '.dsh-uia-btn[data-on=true]{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary)}'
|
|
27
|
+
// The pressed state is shown the moment the click lands, before the server answers: without
|
|
28
|
+
// it the control is inert for a whole poll interval and reads as "the click did nothing".
|
|
29
|
+
+ '.dsh-uia-btn[data-pending=true]{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary);opacity:.65;cursor:progress}'
|
|
30
|
+
+ '.dsh-uia-btn:disabled{opacity:.5;cursor:default}'
|
|
31
|
+
+ '.dsh-uia-sw{width:22px;height:22px;padding:0;border-radius:50%;border:1px solid var(--dsw-alias-border-l2);cursor:pointer;box-shadow:inset 0 0 0 1px #ffffff2e;transition:box-shadow 120ms ease,opacity 120ms ease}'
|
|
32
|
+
+ '.dsh-uia-sw[data-on=true]{box-shadow:inset 0 0 0 1px #ffffff2e,0 0 0 2px var(--dsw-alias-bg-layer-1),0 0 0 3px var(--dsw-alias-label-primary)}'
|
|
33
|
+
+ '.dsh-uia-sw[data-pending=true]{opacity:.65;cursor:progress}'
|
|
34
|
+
+ '.dsh-uia-warn{color:var(--dsw-alias-state-warn-primary);font-size:12px}'
|
|
35
|
+
+ '.dsh-uia-cfg{display:flex;flex-direction:column;gap:8px;font-size:13px;line-height:20px;color:var(--dsw-alias-label-primary)}'
|
|
36
|
+
+ '.dsh-uia-kv{display:grid;grid-template-columns:auto 1fr;gap:2px 14px;font-size:12px;line-height:18px}'
|
|
37
|
+
+ '.dsh-uia-k{color:var(--dsw-alias-label-tertiary)}'
|
|
38
|
+
+ '.dsh-uia-v{color:var(--dsw-alias-label-secondary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}'
|
|
39
|
+
+ '.dsh-uia-atmo{height:3px;border-radius:2px;margin-top:2px;opacity:.85;transition:background 160ms ease}';
|
|
40
|
+
const tagId = 'dsh-native-uia-ui/detail.css';
|
|
41
|
+
if (typeof document !== 'undefined' && document.querySelector(`style[data-plugin-css=${JSON.stringify(tagId)}]`) === null) {
|
|
42
|
+
const tag = document.createElement('style');
|
|
43
|
+
tag.dataset.plugin = 'dsh-native-uia-ui';
|
|
44
|
+
tag.dataset.pluginCss = tagId;
|
|
45
|
+
tag.textContent = css;
|
|
46
|
+
document.head.appendChild(tag);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const h = react.createElement;
|
|
50
|
+
|
|
51
|
+
const MODES = [
|
|
52
|
+
{ id: 'background', label: '后台', hint: '不动鼠标、不抢焦点' },
|
|
53
|
+
{ id: 'auto', label: '自动', hint: '按目标控件择路' },
|
|
54
|
+
{ id: 'foreground', label: '前台', hint: '移动真实鼠标' },
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Poll the loopback service while the panel is on screen. The service answers a 400-byte
|
|
59
|
+
* summary; there is no stream because the panel does not need one, and an EventSource would
|
|
60
|
+
* keep a socket open for a page nobody is looking at once they leave it.
|
|
61
|
+
*
|
|
62
|
+
* `apply` writes one field into the local summary immediately. The panel needs it because the
|
|
63
|
+
* poll is 1.5 s: a click that only took effect on the next poll left the control unchanged for
|
|
64
|
+
* a whole interval, which reads as a dead button. The write is optimistic -- the caller rolls it
|
|
65
|
+
* back if the action fails, and the next poll replaces the whole object anyway.
|
|
66
|
+
*/
|
|
67
|
+
function useSummary(enabled) {
|
|
68
|
+
const [summary, setSummary] = react.useState(null);
|
|
69
|
+
const [error, setError] = react.useState('');
|
|
70
|
+
const pullRef = react.useRef(null);
|
|
71
|
+
react.useEffect(() => {
|
|
72
|
+
if (enabled !== true) return undefined;
|
|
73
|
+
let alive = true;
|
|
74
|
+
let timer = null;
|
|
75
|
+
const pull = async () => {
|
|
76
|
+
try {
|
|
77
|
+
const res = await fetch(`${SERVICE}/api/summary`, { cache: 'no-store' });
|
|
78
|
+
if (res.ok !== true) throw new Error(`HTTP ${res.status}`);
|
|
79
|
+
const data = await res.json();
|
|
80
|
+
if (alive) {
|
|
81
|
+
setSummary(data);
|
|
82
|
+
setError('');
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
if (alive) setError('本机状态接口未响应:插件未激活,或 127.0.0.1:3099 被占用');
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
pullRef.current = pull;
|
|
89
|
+
const tick = () => {
|
|
90
|
+
if (alive === false) return;
|
|
91
|
+
void pull();
|
|
92
|
+
timer = setTimeout(tick, document.visibilityState === 'hidden' ? POLL_MS * 4 : POLL_MS);
|
|
93
|
+
};
|
|
94
|
+
tick();
|
|
95
|
+
const onVisible = () => { if (document.visibilityState === 'visible') void pull(); };
|
|
96
|
+
document.addEventListener('visibilitychange', onVisible);
|
|
97
|
+
return () => {
|
|
98
|
+
alive = false;
|
|
99
|
+
pullRef.current = null;
|
|
100
|
+
if (timer !== null) clearTimeout(timer);
|
|
101
|
+
document.removeEventListener('visibilitychange', onVisible);
|
|
102
|
+
};
|
|
103
|
+
}, [enabled]);
|
|
104
|
+
const apply = (patch) => {
|
|
105
|
+
setSummary((prev) => (prev === null ? prev : { ...prev, ...patch }));
|
|
106
|
+
};
|
|
107
|
+
/** Ask for a fresh summary now instead of waiting for the next tick. */
|
|
108
|
+
const refresh = () => {
|
|
109
|
+
const pull = pullRef.current;
|
|
110
|
+
if (pull !== null) void pull();
|
|
111
|
+
};
|
|
112
|
+
return { summary, error, apply, refresh };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function send(body) {
|
|
116
|
+
const res = await fetch(`${SERVICE}/api/action`, {
|
|
117
|
+
method: 'POST',
|
|
118
|
+
headers: { 'content-type': 'application/json', [API_HEADER]: '1' },
|
|
119
|
+
body: JSON.stringify(body),
|
|
120
|
+
});
|
|
121
|
+
return res.json();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Milliseconds as the person reads them: 20 s, 5 分钟. */
|
|
125
|
+
function humanMs(ms) {
|
|
126
|
+
if (typeof ms !== 'number' || Number.isFinite(ms) !== true) return '—';
|
|
127
|
+
if (ms < 60000) return `${Math.round(ms / 1000)} 秒`;
|
|
128
|
+
return `${Math.round(ms / 60000)} 分钟`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The bundle's config block. Rendered by the plugin page itself (keyed by package name), so it
|
|
133
|
+
* is the one place on the page that writes: pointerMode, the ambient palette and the capsule
|
|
134
|
+
* shape are the settings that can change at runtime, and all three persist to settings.json.
|
|
135
|
+
* Everything else here is a fact read back from the process -- printing it as a disabled control
|
|
136
|
+
* would suggest it can be edited from here. Deliberately no prose: the labels carry the meaning,
|
|
137
|
+
* and a hint paragraph under every row turns a settings block into documentation.
|
|
138
|
+
*/
|
|
139
|
+
function ConfigPanel() {
|
|
140
|
+
const { summary, error, apply, refresh } = useSummary(true);
|
|
141
|
+
const mode = summary?.pointerMode ?? 'background';
|
|
142
|
+
const cfg = summary?.config ?? null;
|
|
143
|
+
const themeId = summary?.theme ?? cfg?.defaultTheme ?? 'brand';
|
|
144
|
+
const themes = cfg?.themes ?? [];
|
|
145
|
+
const styles = cfg?.styles ?? [];
|
|
146
|
+
const styleId = summary?.style ?? cfg?.defaultStyle ?? 'orb';
|
|
147
|
+
const activeTheme = themes.find((t) => t.id === themeId) ?? null;
|
|
148
|
+
// No stop control here: stopping belongs to Esc, which is watched by the always-idle overlay
|
|
149
|
+
// on a 40 ms poll with an edge latch, so it lands even while a long OCR or batch is running.
|
|
150
|
+
// A button that can only work between commands is the weaker of the two, and it was the last
|
|
151
|
+
// piece of run-watching on a page that exists to change settings.
|
|
152
|
+
/**
|
|
153
|
+
* One write path for all three settings.
|
|
154
|
+
*
|
|
155
|
+
* The panel used to fire and forget, so the control only moved on the next poll -- up to 1.5 s
|
|
156
|
+
* later, with no feedback in between. That is the "not smooth" complaint: the click landed,
|
|
157
|
+
* nothing changed, and a moment later the highlight jumped. Now the field is written locally
|
|
158
|
+
* first (the control moves on the click), the in-flight control shows a pending state, and a
|
|
159
|
+
* failure puts the old value back with the reason attached. `busy` is the field being written,
|
|
160
|
+
* so two rows cannot both look pending from one click.
|
|
161
|
+
*/
|
|
162
|
+
const [pending, setPending] = react.useState(null);
|
|
163
|
+
const [failed, setFailed] = react.useState('');
|
|
164
|
+
const commit = async (field, value, body) => {
|
|
165
|
+
const before = summary?.[field];
|
|
166
|
+
if (value === before) return;
|
|
167
|
+
setFailed('');
|
|
168
|
+
setPending(field);
|
|
169
|
+
apply({ [field]: value });
|
|
170
|
+
try {
|
|
171
|
+
const outcome = await send(body);
|
|
172
|
+
if (outcome?.ok === false) throw new Error(outcome.error ?? '操作被拒绝');
|
|
173
|
+
// Pull once now: the optimistic value is already right, and this makes the rest of the
|
|
174
|
+
// summary (config facts, killed/running) agree without waiting for the next tick.
|
|
175
|
+
refresh();
|
|
176
|
+
} catch (cause) {
|
|
177
|
+
apply({ [field]: before });
|
|
178
|
+
setFailed(String(cause?.message ?? cause));
|
|
179
|
+
} finally {
|
|
180
|
+
setPending(null);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const onMode = (next) => void commit('pointerMode', next, { kind: 'mode', mode: next });
|
|
184
|
+
const onTheme = (next) => void commit('theme', next, { kind: 'theme', theme: next });
|
|
185
|
+
const onStyle = (next) => void commit('style', next, { kind: 'style', style: next });
|
|
186
|
+
// The smoke is decoration, so it gets a plain on/off rather than joining the shape row: it is
|
|
187
|
+
// an independent axis (any shape can have it), and mixing it into the shape buttons would read
|
|
188
|
+
// as a fifth shape.
|
|
189
|
+
const mistOn = summary?.mist !== false;
|
|
190
|
+
const onMist = (next) => void commit('mist', next, { kind: 'mist', mist: next });
|
|
191
|
+
return h('section', { className: 'dsh-uia-cfg' },
|
|
192
|
+
// The panel's own name leads the first row: the settings block is the whole page now, so it
|
|
193
|
+
// has to say whose settings these are. Same string the plugin card and locale carry.
|
|
194
|
+
themes.length === 0 ? null : h('div', { className: 'dsh-uia-row' },
|
|
195
|
+
h('span', { className: 'dsh-uia-name' }, '御屏'),
|
|
196
|
+
h('span', { className: 'dsh-uia-label' }, '氛围光'),
|
|
197
|
+
themes.map((t) => h('button', {
|
|
198
|
+
key: t.id,
|
|
199
|
+
type: 'button',
|
|
200
|
+
className: 'dsh-uia-sw',
|
|
201
|
+
'data-on': themeId === t.id ? 'true' : undefined,
|
|
202
|
+
'data-pending': pending === 'theme' && themeId === t.id ? 'true' : undefined,
|
|
203
|
+
title: t.name,
|
|
204
|
+
style: { background: `linear-gradient(135deg, ${t.ringFrom}, ${t.ringTo})` },
|
|
205
|
+
onClick: () => onTheme(t.id),
|
|
206
|
+
}))),
|
|
207
|
+
activeTheme === null ? null : h('div', {
|
|
208
|
+
className: 'dsh-uia-atmo',
|
|
209
|
+
title: activeTheme.name,
|
|
210
|
+
style: { background: `linear-gradient(90deg, transparent, ${activeTheme.ringFrom}, ${activeTheme.ringTo}, transparent)` },
|
|
211
|
+
}),
|
|
212
|
+
styles.length === 0 ? null : h('div', { className: 'dsh-uia-row' },
|
|
213
|
+
h('span', { className: 'dsh-uia-label' }, '胶囊'),
|
|
214
|
+
styles.map((s) => h('button', {
|
|
215
|
+
key: s.id,
|
|
216
|
+
type: 'button',
|
|
217
|
+
className: 'dsh-uia-btn',
|
|
218
|
+
'data-on': styleId === s.id ? 'true' : undefined,
|
|
219
|
+
'data-pending': pending === 'style' && styleId === s.id ? 'true' : undefined,
|
|
220
|
+
title: s.hint,
|
|
221
|
+
onClick: () => onStyle(s.id),
|
|
222
|
+
}, s.name))),
|
|
223
|
+
h('div', { className: 'dsh-uia-row' },
|
|
224
|
+
h('span', { className: 'dsh-uia-label' }, '投递'),
|
|
225
|
+
MODES.map((m) => h('button', {
|
|
226
|
+
key: m.id,
|
|
227
|
+
type: 'button',
|
|
228
|
+
className: 'dsh-uia-btn',
|
|
229
|
+
'data-on': mode === m.id ? 'true' : undefined,
|
|
230
|
+
'data-pending': pending === 'pointerMode' && mode === m.id ? 'true' : undefined,
|
|
231
|
+
title: m.hint,
|
|
232
|
+
onClick: () => onMode(m.id),
|
|
233
|
+
}, m.label))),
|
|
234
|
+
h('div', { className: 'dsh-uia-row' },
|
|
235
|
+
h('span', { className: 'dsh-uia-label' }, '薄云'),
|
|
236
|
+
h('button', {
|
|
237
|
+
type: 'button',
|
|
238
|
+
className: 'dsh-uia-btn',
|
|
239
|
+
'data-on': mistOn ? 'true' : undefined,
|
|
240
|
+
'data-pending': pending === 'mist' ? 'true' : undefined,
|
|
241
|
+
title: mistOn ? '底缘薄云正在显示,点击关闭' : '底缘薄云已关闭,点击开启',
|
|
242
|
+
onClick: () => onMist(!mistOn),
|
|
243
|
+
}, mistOn ? '开' : '关')),
|
|
244
|
+
cfg === null ? null : h('div', { className: 'dsh-uia-kv' },
|
|
245
|
+
h('span', { className: 'dsh-uia-k' }, '监听'), h('span', { className: 'dsh-uia-v' }, `${cfg.host}:${cfg.port}`),
|
|
246
|
+
h('span', { className: 'dsh-uia-k' }, '只读'), h('span', { className: 'dsh-uia-v' }, cfg.readOnly ? '开' : '关'),
|
|
247
|
+
h('span', { className: 'dsh-uia-k' }, '租约'), h('span', { className: 'dsh-uia-v' }, humanMs(cfg.leaseMs)),
|
|
248
|
+
h('span', { className: 'dsh-uia-k' }, '空转'), h('span', { className: 'dsh-uia-v' }, humanMs(cfg.idleMs))),
|
|
249
|
+
error === '' ? null : h('div', { className: 'dsh-uia-warn' }, error),
|
|
250
|
+
// A refused write has to say so: the control already snapped back, and without a reason the
|
|
251
|
+
// person would read that snap-back as another glitch.
|
|
252
|
+
failed === '' ? null : h('div', { className: 'dsh-uia-warn' }, `未生效:${failed}`));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const inject = ['slots'];
|
|
256
|
+
|
|
257
|
+
function apply(ctx) {
|
|
258
|
+
ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
|
|
259
|
+
name: 'plugins.bundle.config',
|
|
260
|
+
key: PKG,
|
|
261
|
+
order: 40,
|
|
262
|
+
}, ConfigPanel));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
exports.apply = apply;
|
|
266
|
+
exports.inject = inject;
|
|
267
|
+
return module.exports;
|
|
268
|
+
},
|
|
269
|
+
});
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# dsh-native-uia —— 一行组件。
|
|
2
|
+
#
|
|
3
|
+
# 这一行是本包自己的 Host 半侧:桌面操控工具、本机状态服务与屏幕指示层。挂上它,
|
|
4
|
+
# 本包才会被 client-module 扫描器发现(`dsh.client` 从 Loader 行挂载的那个包的
|
|
5
|
+
# 清单里读,且行必须是包名本身,不能是子路径),浏览器半侧的面板因此随它一起下发,
|
|
6
|
+
# 长在本包详情页的 `plugins.detail.section` 里,不再单独占一行。
|
|
7
|
+
|
|
8
|
+
- insert:
|
|
9
|
+
- id: native-uia
|
|
10
|
+
name: 'dsh-native-uia'
|
package/icon.svg
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36" width="36" height="36" fill="none" role="img" aria-label="御屏">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="yupingAccent" x1="17.5" y1="13" x2="25" y2="25" gradientUnits="userSpaceOnUse">
|
|
4
|
+
<stop stop-color="#54ECE7"/>
|
|
5
|
+
<stop offset="1" stop-color="#658EFF"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
|
|
9
|
+
<path d="M7 12.5C7 10 9.6 8 12.1 8H23.9C26.4 8 29 10 29 12.5V23.5C29 26 26.4 28 23.9 28H17.8" stroke="#679EFE" stroke-width="3.5" stroke-linecap="round"/>
|
|
10
|
+
<path d="M17.5 13.5L26 17.3L22.4 18.3L21.5 22.1L17.5 13.5Z" fill="url(#yupingAccent)"/>
|
|
11
|
+
</svg>
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
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, and destructive deletes. The panel on this plugin's detail page shows the current target, step count and the last few log lines, and can switch delivery mode or stop the run."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,77 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-native-uia",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"displayName": "御屏",
|
|
5
|
+
"description": "以 Windows UI Automation 控件树为主观测通道的桌面操控插件:纯文本模型即可操控桌面,后台投递动作(不动鼠标、不抢焦点),一次调用批量执行并逐步校验,成功批次自动存为可回放配方。",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"icon": "./icon.svg",
|
|
8
|
+
"main": "./src/index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/index.js",
|
|
11
|
+
"./client": "./client/client.js",
|
|
12
|
+
"./package.json": "./package.json",
|
|
13
|
+
"./locale/*.json": "./locale/*.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"worker",
|
|
18
|
+
"client",
|
|
19
|
+
"scripts",
|
|
20
|
+
"locale",
|
|
21
|
+
"icon.svg",
|
|
22
|
+
"cordis.patch.yml",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"check": "node scripts/verify.mjs",
|
|
28
|
+
"install-plugin": "node scripts/install.mjs install",
|
|
29
|
+
"uninstall-plugin": "node scripts/install.mjs remove",
|
|
30
|
+
"status": "node scripts/install.mjs status",
|
|
31
|
+
"worker:ping": "node scripts/smoke.mjs"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"deepseek-harness",
|
|
35
|
+
"dsh",
|
|
36
|
+
"dsh-bundle",
|
|
37
|
+
"cordis",
|
|
38
|
+
"plugin",
|
|
39
|
+
"computer-use",
|
|
40
|
+
"ui-automation",
|
|
41
|
+
"uia",
|
|
42
|
+
"windows"
|
|
43
|
+
],
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/xiaobaga281/dsh-native-uia.git"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/xiaobaga281/dsh-native-uia#readme",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/xiaobaga281/dsh-native-uia/issues"
|
|
52
|
+
},
|
|
53
|
+
"author": "xiaobaga281",
|
|
54
|
+
"dsh": {
|
|
55
|
+
"bundle": {
|
|
56
|
+
"patch": "./cordis.patch.yml"
|
|
57
|
+
},
|
|
58
|
+
"client": {
|
|
59
|
+
"platform": "web",
|
|
60
|
+
"inject": [
|
|
61
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager",
|
|
62
|
+
"@deepseek-ai/dsh-client-ui-slots"
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"@deepseek-ai/dsh-typert-protocol": "0.2.0-rc.2"
|
|
68
|
+
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"@deepseek-ai/cordis": "*",
|
|
71
|
+
"@deepseek-ai/dsh-tools": "*",
|
|
72
|
+
"@deepseek-ai/dsh-typert-protocol": "*"
|
|
73
|
+
},
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=18.0.0"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Read-only live benchmark. Drives the production CuaWorker client exactly like
|
|
4
|
+
* scripts/smoke.mjs does (spawn / JSON-lines framing / shutdown all live in
|
|
5
|
+
* src/worker-client.js) and sends NOTHING but observations:
|
|
6
|
+
* ping, list_windows, snapshot (default args) ×5, find_text ×3, shutdown.
|
|
7
|
+
* No act, no capture, no pointer/keyboard command, no mouse or touch of the desktop.
|
|
8
|
+
*
|
|
9
|
+
* stdout carries exactly ONE JSON line (the benchmark record); every diagnostic
|
|
10
|
+
* goes to stderr, so `node scripts/bench-live.mjs 2>/dev/null` yields the record alone.
|
|
11
|
+
*/
|
|
12
|
+
import { CuaWorker, WorkerCommandError } from '../src/worker-client.js';
|
|
13
|
+
|
|
14
|
+
// 宿主/终端侧进程不算被测窗口:本脚本自身(node)、worker(powershell)、宿主应用。
|
|
15
|
+
const HOST_APP = /powershell|pwsh|cmd|node|conhost|windowsterminal|openconsole|zcode|koishi/i;
|
|
16
|
+
const WATCHDOG_MS = 60000;
|
|
17
|
+
|
|
18
|
+
const worker = new CuaWorker({ logger: (m) => console.error(` . ${m}`) });
|
|
19
|
+
const t0 = Date.now();
|
|
20
|
+
const log = (m) => console.error(`[bench] ${m}`);
|
|
21
|
+
|
|
22
|
+
function percentile(sorted, p) {
|
|
23
|
+
// 线性插值(与常见分位数定义一致);调用前先升序排序。
|
|
24
|
+
if (sorted.length === 0) return 0;
|
|
25
|
+
const idx = (sorted.length - 1) * p;
|
|
26
|
+
const lo = Math.floor(idx);
|
|
27
|
+
const hi = Math.ceil(idx);
|
|
28
|
+
if (lo === hi) return sorted[lo];
|
|
29
|
+
return sorted[lo] + (sorted[hi] - sorted[lo]) * (idx - lo);
|
|
30
|
+
}
|
|
31
|
+
const median = (arr) => percentile([...arr].sort((a, b) => a - b), 0.5);
|
|
32
|
+
|
|
33
|
+
// 硬性总时长闸门:超过 60s 视为卡死,清进程后以失败退出,绝不硬造数字。
|
|
34
|
+
let done = false;
|
|
35
|
+
const watchdog = setTimeout(() => {
|
|
36
|
+
if (done) return;
|
|
37
|
+
log(`超过 ${WATCHDOG_MS} ms 未完成,强制退出`);
|
|
38
|
+
void worker.shutdown({ killMs: 2000 }).finally(() => process.exit(3));
|
|
39
|
+
}, WATCHDOG_MS);
|
|
40
|
+
|
|
41
|
+
async function main() {
|
|
42
|
+
// 预热 = spawn + 握手(worker 冷启动约 1s 就绪),不计入采样。
|
|
43
|
+
const ping = await worker.call('ping', {}, { timeoutMs: 30000 });
|
|
44
|
+
log(`worker 就绪 (${Date.now() - t0} ms) powershell ${ping?.psVersion ?? '?'}`);
|
|
45
|
+
|
|
46
|
+
const lw = await worker.call('list_windows', { onlyVisible: true }, { timeoutMs: 30000 });
|
|
47
|
+
const all = lw.windows ?? [];
|
|
48
|
+
log(`可见窗口 ${all.length} 个`);
|
|
49
|
+
|
|
50
|
+
// 选窗:排除宿主/终端侧进程;优先前台窗口;选不出就退回任意可见窗口。
|
|
51
|
+
const candidates = all.filter((w) => !HOST_APP.test(String(w.appName ?? '')));
|
|
52
|
+
const pool = candidates.length > 0 ? candidates : all;
|
|
53
|
+
if (pool.length === 0) throw new Error('list_windows 没有返回任何可见窗口,无法采样');
|
|
54
|
+
const picked =
|
|
55
|
+
pool.find((w) => w.isForeground === true && w.isMinimized !== true) ??
|
|
56
|
+
pool.find((w) => w.isForeground === true) ??
|
|
57
|
+
pool.find((w) => w.isMinimized !== true && (w.rect?.w ?? 0) > 0 && (w.rect?.h ?? 0) > 0) ??
|
|
58
|
+
pool[0];
|
|
59
|
+
log(`选中窗口 id=${picked.windowId} app=${picked.appName} fg=${picked.isForeground} title="${picked.title}"`);
|
|
60
|
+
const windowId = picked.windowId;
|
|
61
|
+
const windowLabel = String(picked.title ?? '').trim() !== ''
|
|
62
|
+
? String(picked.title).slice(0, 120)
|
|
63
|
+
: `${picked.appName ?? ''}:${windowId}`;
|
|
64
|
+
|
|
65
|
+
// 取针词:窗口标题里的一个常见字(有 CJK 取第一个汉字,否则取第一个字母/数字;
|
|
66
|
+
// find_text 是大小写不敏感的字面包含匹配,uia-worker.ps1:2723)。标题为空则从
|
|
67
|
+
// 第一次 snapshot 的节点名里取,再取不到就失败退出——不造数字。
|
|
68
|
+
let needle = '';
|
|
69
|
+
const title = String(picked.title ?? '');
|
|
70
|
+
const cjk = title.match(/[\u4e00-\u9fff]/);
|
|
71
|
+
const ascii = title.match(/[A-Za-z0-9]/);
|
|
72
|
+
if (cjk) needle = cjk[0];
|
|
73
|
+
else if (ascii) needle = ascii[0].toLowerCase();
|
|
74
|
+
|
|
75
|
+
const snaps = [];
|
|
76
|
+
for (let i = 0; i < 5; i++) {
|
|
77
|
+
const w0 = performance.now();
|
|
78
|
+
const r = await worker.call('snapshot', { windowId }, { timeoutMs: 30000 });
|
|
79
|
+
const wallMs = Math.round(performance.now() - w0);
|
|
80
|
+
const nodeCount = r?.nodeCount ?? (Array.isArray(r?.nodes) ? r.nodes.length : 0);
|
|
81
|
+
if (nodeCount === 0) throw new Error(`snapshot 第 ${i + 1} 次返回 0 节点,窗口树为空,无法采样`);
|
|
82
|
+
snaps.push({
|
|
83
|
+
msPerNode: Number(r.msPerNode),
|
|
84
|
+
ms: Number.isFinite(Number(r.ms)) ? Number(r.ms) : wallMs, // 返回值自带耗时;缺失才退回墙钟
|
|
85
|
+
nodeCount,
|
|
86
|
+
wallMs,
|
|
87
|
+
truncated: r.truncated === true,
|
|
88
|
+
visited: r.visited,
|
|
89
|
+
partialReason: r.partialReason ?? '',
|
|
90
|
+
});
|
|
91
|
+
log(`snapshot#${i + 1}: ${nodeCount} 节点, ms=${r.ms}, msPerNode=${r.msPerNode}, wall=${wallMs}ms, visited=${r.visited}${r.partialReason ? ', partial=' + r.partialReason : ''}`);
|
|
92
|
+
if (needle === '') {
|
|
93
|
+
const named = (r.nodes ?? []).find((n) => String(n.name ?? '').trim().length > 0);
|
|
94
|
+
if (named) {
|
|
95
|
+
const s = String(named.name).trim();
|
|
96
|
+
const c = s.match(/[\u4e00-\u9fff]/) ?? s.match(/[A-Za-z0-9]/);
|
|
97
|
+
if (c) needle = c[0].toLowerCase();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (needle === '') throw new Error('标题与节点名都取不出针词,find_text 无法采样');
|
|
102
|
+
|
|
103
|
+
// 一次性子树路径的节点数对照(评审⑤):快照的 visited(全树遍历数,无 maxNodes 截断时)
|
|
104
|
+
// 与 find_text 的 scanned(FindAll 全量数)应一致;FindAll(TrueCondition) 与 ControlViewWalker
|
|
105
|
+
// 的节点集合是 provider 特定行为,这里只对照记录,不做硬断言。
|
|
106
|
+
let nodesFull = 0;
|
|
107
|
+
try {
|
|
108
|
+
const full = await worker.call('snapshot', { windowId, maxNodes: 4000 }, { timeoutMs: 30000 });
|
|
109
|
+
nodesFull = Number(full?.nodeCount ?? 0);
|
|
110
|
+
log(`snapshot#full(maxNodes=4000): ${nodesFull} 节点, ms=${full?.ms}, msPerNode=${full?.msPerNode}, truncated=${full?.truncated}`);
|
|
111
|
+
} catch (e) {
|
|
112
|
+
log(`snapshot#full 失败(不影响主采样): ${e?.message ?? e}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const findMs = [];
|
|
116
|
+
let findMatches = 0;
|
|
117
|
+
let findScanned = 0;
|
|
118
|
+
for (let i = 0; i < 3; i++) {
|
|
119
|
+
const w0 = performance.now();
|
|
120
|
+
const r = await worker.call('find_text', { windowId, text: needle }, { timeoutMs: 30000 });
|
|
121
|
+
findMs.push(Math.round(performance.now() - w0));
|
|
122
|
+
findMatches = r?.count ?? 0;
|
|
123
|
+
findScanned = r?.scanned ?? 0;
|
|
124
|
+
log(`find_text#${i + 1} "${needle}": count=${r?.count} scanned=${r?.scanned} wall=${findMs[i]}ms`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const record = {
|
|
128
|
+
window: windowLabel,
|
|
129
|
+
nodes: Math.round(median(snaps.map((s) => s.nodeCount))),
|
|
130
|
+
msPerNodeP50: percentile(snaps.map((s) => s.msPerNode).sort((a, b) => a - b), 0.5),
|
|
131
|
+
msPerNodeP95: percentile(snaps.map((s) => s.msPerNode).sort((a, b) => a - b), 0.95),
|
|
132
|
+
snapshotMsP50: percentile(snaps.map((s) => s.ms).sort((a, b) => a - b), 0.5),
|
|
133
|
+
findTextMsP50: percentile(findMs.slice().sort((a, b) => a - b), 0.5),
|
|
134
|
+
// 一次性子树路径对照(见上方注释)
|
|
135
|
+
nodesFull,
|
|
136
|
+
visited: snaps[snaps.length - 1]?.visited,
|
|
137
|
+
findScanned,
|
|
138
|
+
partialReasons: [...new Set(snaps.map((s) => s.partialReason).filter((x) => x !== ''))],
|
|
139
|
+
ts: new Date().toISOString(),
|
|
140
|
+
};
|
|
141
|
+
log(`针词="${needle}" find命中=${findMatches} snapshot截断=${snaps.some((s) => s.truncated)} 总时长=${Date.now() - t0}ms`);
|
|
142
|
+
console.log(JSON.stringify(record)); // stdout 只有这一行
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
await main();
|
|
147
|
+
done = true;
|
|
148
|
+
process.exitCode = 0;
|
|
149
|
+
} catch (error) {
|
|
150
|
+
done = true;
|
|
151
|
+
const detail = error instanceof WorkerCommandError ? `${error.code}: ${error.message}` : String(error?.message ?? error);
|
|
152
|
+
console.error(`[bench] 失败: ${detail}`);
|
|
153
|
+
process.exitCode = 1;
|
|
154
|
+
} finally {
|
|
155
|
+
clearTimeout(watchdog);
|
|
156
|
+
try { await worker.shutdown({ killMs: 5000 }); } catch { /* exit handler 已覆盖 */ }
|
|
157
|
+
}
|