dsh-native-uia 0.2.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 -398
- package/client/client.js +236 -48
- package/cordis.patch.yml +7 -8
- package/locale/en.json +2 -2
- package/locale/zh.json +2 -2
- package/package.json +8 -17
- package/scripts/check-lease.mjs +1 -1
- package/scripts/lib/dsh-tools-stub.mjs +14 -0
- package/scripts/lib/load-tools-source.mjs +17 -16
- package/scripts/lib/sources.mjs +62 -0
- package/scripts/load-tools.mjs +74 -0
- package/scripts/measure-parse.mjs +2 -2
- package/scripts/regression-tools.mjs +155 -6
- package/scripts/regression-worker.ps1 +29 -0
- package/scripts/verify-live-style.mjs +46 -0
- package/scripts/verify-live.mjs +12 -18
- package/scripts/verify.mjs +953 -192
- package/src/activity-window.js +71 -7
- package/src/dashboard.js +27 -69
- package/src/guard.js +39 -10
- package/src/index.js +187 -77
- package/src/notes.js +83 -0
- package/src/state.js +97 -10
- package/src/themes.js +66 -0
- package/src/tools/defs/act.js +671 -0
- package/src/tools/defs/lifecycle.js +205 -0
- package/src/tools/defs/observe.js +325 -0
- package/src/tools/defs/pointer.js +328 -0
- package/src/tools/format.js +338 -0
- package/src/tools/index.js +125 -0
- package/src/tools/ocr.js +91 -0
- package/src/tools/recipes.js +49 -0
- package/src/tools/runtime.js +42 -0
- package/src/worker-client.js +32 -10
- package/worker/assets/dsh-whale.path +1 -0
- package/worker/indicator-server.ps1 +1107 -72
- package/worker/lib/01-core.ps1 +64 -0
- package/worker/lib/02-uia.ps1 +224 -0
- package/worker/lib/03-window.ps1 +194 -0
- package/worker/lib/04-match.ps1 +435 -0
- package/worker/lib/05-value.ps1 +254 -0
- package/worker/lib/06-snapshot.ps1 +412 -0
- package/worker/lib/07-action.ps1 +329 -0
- package/worker/lib/08-command.ps1 +1495 -0
- package/worker/lib/09-pointer.ps1 +840 -0
- package/worker/lib/10-dispatch.ps1 +132 -0
- package/worker/ps-stdio.ps1 +7 -2
- package/worker/uia-worker.ps1 +599 -4220
- package/locale/desktop/en.json +0 -6
- package/locale/desktop/zh.json +0 -6
- package/scripts/regression-halt-latch.mjs +0 -100
- package/src/native-uia-remote.js +0 -80
- package/src/panel-face.js +0 -14
- package/src/tools.js +0 -1482
- package/web/control.html +0 -1413
package/client/client.js
CHANGED
|
@@ -8,13 +8,36 @@ window.__ModuleLoader__.load({
|
|
|
8
8
|
generated host artifacts but NOT in the plugin client module table, and a
|
|
9
9
|
missing module at import time aborts the whole web boot. */
|
|
10
10
|
const react = require('react');
|
|
11
|
-
const jsx = require('react/jsx-runtime');
|
|
12
11
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
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';
|
|
18
41
|
if (typeof document !== 'undefined' && document.querySelector(`style[data-plugin-css=${JSON.stringify(tagId)}]`) === null) {
|
|
19
42
|
const tag = document.createElement('style');
|
|
20
43
|
tag.dataset.plugin = 'dsh-native-uia-ui';
|
|
@@ -23,55 +46,220 @@ window.__ModuleLoader__.load({
|
|
|
23
46
|
document.head.appendChild(tag);
|
|
24
47
|
}
|
|
25
48
|
|
|
26
|
-
const
|
|
27
|
-
const RETRY_MS = 3000;
|
|
49
|
+
const h = react.createElement;
|
|
28
50
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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),
|
|
62
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}`));
|
|
63
253
|
}
|
|
64
254
|
|
|
65
255
|
const inject = ['slots'];
|
|
66
256
|
|
|
67
257
|
function apply(ctx) {
|
|
68
|
-
ctx.slots.inject('
|
|
69
|
-
name: '
|
|
70
|
-
|
|
71
|
-
order:
|
|
72
|
-
|
|
73
|
-
registrant: 'dsh-native-uia',
|
|
74
|
-
}, ComputerControlView));
|
|
258
|
+
ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
|
|
259
|
+
name: 'plugins.bundle.config',
|
|
260
|
+
key: PKG,
|
|
261
|
+
order: 40,
|
|
262
|
+
}, ConfigPanel));
|
|
75
263
|
}
|
|
76
264
|
|
|
77
265
|
exports.apply = apply;
|
package/cordis.patch.yml
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
1
|
+
# dsh-native-uia —— 一行组件。
|
|
2
|
+
#
|
|
3
|
+
# 这一行是本包自己的 Host 半侧:桌面操控工具、本机状态服务与屏幕指示层。挂上它,
|
|
4
|
+
# 本包才会被 client-module 扫描器发现(`dsh.client` 从 Loader 行挂载的那个包的
|
|
5
|
+
# 清单里读,且行必须是包名本身,不能是子路径),浏览器半侧因此随它一起下发,
|
|
6
|
+
# 面板作为 `plugins.bundle.config` 配置块渲染在本包自己的详情页上,不单独占一行。
|
|
7
|
+
|
|
6
8
|
- insert:
|
|
7
9
|
- id: native-uia
|
|
8
|
-
name: 'dsh-native-uia/desktop'
|
|
9
|
-
|
|
10
|
-
- id: native-uia-panel
|
|
11
10
|
name: 'dsh-native-uia'
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
|
-
"title": "Yuping
|
|
4
|
-
"description": "
|
|
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, 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
|
-
"title": "御屏
|
|
4
|
-
"description": "
|
|
3
|
+
"title": "御屏",
|
|
4
|
+
"description": "用 Windows UI Automation 控件树观察并操作桌面:主观测通道是元素树而不是截图,纯文本模型也能操控;动作默认在后台投递,不动鼠标、不抢焦点;一次调用批量执行并逐步校验,成功的批次自动存成可回放配方。策略硬拒系统关机/注销、退出程序、破坏性删除,以及命令行与脚本宿主的启动。插件详情页可切换投递方式、氛围光、胶囊样式与底缘薄云,改完立即生效并持久化;停止本轮按 Esc。"
|
|
5
5
|
}
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-native-uia",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"displayName": "御屏
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"displayName": "御屏",
|
|
5
5
|
"description": "以 Windows UI Automation 控件树为主观测通道的桌面操控插件:纯文本模型即可操控桌面,后台投递动作(不动鼠标、不抢焦点),一次调用批量执行并逐步校验,成功批次自动存为可回放配方。",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"icon": "./icon.svg",
|
|
8
|
-
"main": "./src/
|
|
8
|
+
"main": "./src/index.js",
|
|
9
9
|
"exports": {
|
|
10
|
-
".": "./src/
|
|
11
|
-
"./desktop": "./src/index.js",
|
|
10
|
+
".": "./src/index.js",
|
|
12
11
|
"./client": "./client/client.js",
|
|
13
12
|
"./package.json": "./package.json",
|
|
14
|
-
"./locale/*.json": "./locale/*.json"
|
|
15
|
-
"./desktop/locale/*.json": "./locale/desktop/*.json"
|
|
13
|
+
"./locale/*.json": "./locale/*.json"
|
|
16
14
|
},
|
|
17
15
|
"files": [
|
|
18
16
|
"src",
|
|
19
17
|
"worker",
|
|
20
|
-
"web",
|
|
21
18
|
"client",
|
|
22
19
|
"scripts",
|
|
23
20
|
"locale",
|
|
@@ -61,20 +58,14 @@
|
|
|
61
58
|
"client": {
|
|
62
59
|
"platform": "web",
|
|
63
60
|
"inject": [
|
|
64
|
-
"@deepseek-ai/dsh-
|
|
65
|
-
"@deepseek-ai/dsh-client-ui-
|
|
66
|
-
"@deepseek-ai/dsh-client-ui-slots",
|
|
67
|
-
"@deepseek-ai/dsh-client-ui-conversation"
|
|
61
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager",
|
|
62
|
+
"@deepseek-ai/dsh-client-ui-slots"
|
|
68
63
|
]
|
|
69
64
|
}
|
|
70
65
|
},
|
|
71
|
-
"dependencies": {
|
|
72
|
-
"@deepseek-ai/dsh-typert-protocol": "0.2.0-rc.2"
|
|
73
|
-
},
|
|
74
66
|
"peerDependencies": {
|
|
75
67
|
"@deepseek-ai/cordis": "*",
|
|
76
|
-
"@deepseek-ai/dsh-tools": "*"
|
|
77
|
-
"@deepseek-ai/dsh-typert-protocol": "*"
|
|
68
|
+
"@deepseek-ai/dsh-tools": "*"
|
|
78
69
|
},
|
|
79
70
|
"engines": {
|
|
80
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');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// ESM resolve/load hook used by scripts/load-tools.mjs. The host package
|
|
2
|
+
// `@deepseek-ai/dsh-tools` is provided by DSH itself and is not installed here, so the load test
|
|
3
|
+
// substitutes a one-line defineTool: the point is to prove the tool modules RESOLVE and every
|
|
4
|
+
// handler builds against its bindings, not to re-test the host SDK.
|
|
5
|
+
const STUB = 'data:text/javascript,' + encodeURIComponent(
|
|
6
|
+
'export const defineTool = (definition) => ({ ...definition, __stub: true });\n',
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export async function resolve(specifier, context, next) {
|
|
10
|
+
if (specifier === '@deepseek-ai/dsh-tools') {
|
|
11
|
+
return { url: STUB, shortCircuit: true };
|
|
12
|
+
}
|
|
13
|
+
return next(specifier, context);
|
|
14
|
+
}
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
|
-
import {
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { join } from 'node:path';
|
|
4
3
|
import { classify, classifyBatch, classifyClose, classifyLaunch, classifyKeys, POLICY } from '../../src/guard.js';
|
|
4
|
+
import { saveNote, noteHint } from '../../src/notes.js';
|
|
5
|
+
import { toolsSource } from './sources.mjs';
|
|
5
6
|
|
|
6
|
-
// Shared loader for the regression scripts: reads the PRODUCTION
|
|
7
|
-
// wrapper (imports / named exports) and
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// SAME set the tool uses instead
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
// Shared loader for the regression scripts: reads the PRODUCTION tool sources (concatenated in the
|
|
8
|
+
// order scripts/lib/sources.mjs declares), strips their ESM wrapper (imports / named exports) and
|
|
9
|
+
// evaluates the result as a plain function body with injected deps, so the scripts exercise the
|
|
10
|
+
// real source without a copy. `returnExpr` is the expression of the `return` statement inside the
|
|
11
|
+
// new Function body — each script picks the names it needs. Exported consts (PASS_THROUGH /
|
|
12
|
+
// OCR_COVER) are stripped to plain consts so scripts can pull the SAME set the tool uses instead
|
|
13
|
+
// of keeping a second copy around.
|
|
14
14
|
export async function loadToolsSource(returnExpr) {
|
|
15
|
-
const source =
|
|
15
|
+
const source = toolsSource();
|
|
16
16
|
const body = source
|
|
17
17
|
.replace(/^import .*;\r?\n/gm, '')
|
|
18
|
-
.replace(
|
|
19
|
-
.replace(
|
|
20
|
-
.replace(
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
.replace(/^export async function /gm, 'async function ')
|
|
19
|
+
.replace(/^export function /gm, 'function ')
|
|
20
|
+
.replace(/^export const (\w+) =/gm, 'const $1 =')
|
|
21
|
+
.replace(/^export \{ [^}]+ \};?\r?\n/gm, '');
|
|
22
|
+
return new Function('deps', `const {writeFile,readdir,readFile,mkdir,unlink,join,defineTool,classify,classifyBatch,classifyClose,classifyLaunch,classifyKeys,saveNote,noteHint,POLICY}=deps;\n${body}\nreturn ${returnExpr};`)({
|
|
23
|
+
...fs, join, defineTool: (x) => x, classify, classifyBatch, classifyClose, classifyLaunch, classifyKeys, saveNote, noteHint, POLICY,
|
|
23
24
|
});
|
|
24
25
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const root = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The browser half, the Host half and the gates all have to agree on ONE list order: the tool
|
|
9
|
+
* sources are concatenated in this order for the harness (which strips imports and evaluates the
|
|
10
|
+
* body), and the gates read the same concatenation so a rule can never be checked against a file
|
|
11
|
+
* the runtime no longer loads.
|
|
12
|
+
*/
|
|
13
|
+
export const TOOLS_FILES = [
|
|
14
|
+
'src/tools/runtime.js',
|
|
15
|
+
'src/tools/format.js',
|
|
16
|
+
'src/tools/ocr.js',
|
|
17
|
+
'src/tools/recipes.js',
|
|
18
|
+
'src/tools/defs/observe.js',
|
|
19
|
+
'src/tools/defs/act.js',
|
|
20
|
+
'src/tools/defs/pointer.js',
|
|
21
|
+
'src/tools/defs/lifecycle.js',
|
|
22
|
+
'src/tools/index.js',
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export function toolsSource() {
|
|
26
|
+
return TOOLS_FILES.map((rel) => `// ---- ${rel} ----\n${readFileSync(join(root, rel), 'utf8')}`).join('\n');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function toolsFileList() {
|
|
30
|
+
return TOOLS_FILES.slice();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The PowerShell worker, split the same way: the entry keeps process setup and the stdio loop, the
|
|
35
|
+
* body lives in worker/lib in this order. The entry dot-sources the very list below at run time,
|
|
36
|
+
* and the gates read the concatenation, so "the file the gate parsed" and "the file the worker ran"
|
|
37
|
+
* are the same text.
|
|
38
|
+
*/
|
|
39
|
+
export const WORKER_ENTRY = 'worker/uia-worker.ps1';
|
|
40
|
+
|
|
41
|
+
export const WORKER_FILES = [
|
|
42
|
+
'worker/lib/01-core.ps1',
|
|
43
|
+
'worker/lib/02-uia.ps1',
|
|
44
|
+
'worker/lib/03-window.ps1',
|
|
45
|
+
'worker/lib/04-match.ps1',
|
|
46
|
+
'worker/lib/05-value.ps1',
|
|
47
|
+
'worker/lib/06-snapshot.ps1',
|
|
48
|
+
'worker/lib/07-action.ps1',
|
|
49
|
+
'worker/lib/08-command.ps1',
|
|
50
|
+
'worker/lib/09-pointer.ps1',
|
|
51
|
+
'worker/lib/10-dispatch.ps1',
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
export function workerSource() {
|
|
55
|
+
return [WORKER_ENTRY, ...WORKER_FILES]
|
|
56
|
+
.map((rel) => `# ---- ${rel} ----\n${readFileSync(join(root, rel), 'utf8')}`)
|
|
57
|
+
.join('\n');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function workerFileList() {
|
|
61
|
+
return [WORKER_ENTRY, ...WORKER_FILES];
|
|
62
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { register } from 'node:module';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
|
|
7
|
+
// The module graph is the one thing a text-level gate cannot check: the split into
|
|
8
|
+
// src/tools/{runtime,format,ocr,recipes,defs/*} means a missing or mis-levelled import only shows
|
|
9
|
+
// up when the host applies the plugin — and then the whole plugin is dead (no tools, no service).
|
|
10
|
+
// This loads the real modules through a stub for the host SDK and asserts the full tool list
|
|
11
|
+
// registers, so the split stays honest without a desktop.
|
|
12
|
+
register(pathToFileURL(join(dirname(fileURLToPath(import.meta.url)), 'lib', 'dsh-tools-stub.mjs')));
|
|
13
|
+
|
|
14
|
+
const root = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
15
|
+
// The package entry is imported too: it is what the host actually loads, and a tool module that
|
|
16
|
+
// stops re-exporting something index.js imports (idleTimeoutMs) kills the plugin the same way.
|
|
17
|
+
const entry = await import(pathToFileURL(join(root, 'src', 'index.js')).href);
|
|
18
|
+
if (typeof entry.apply !== 'function' || entry.name !== 'dsh-native-uia') {
|
|
19
|
+
console.error('entry module does not expose apply()/name for the host');
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
const { registerTools } = await import(pathToFileURL(join(root, 'src', 'tools', 'index.js')).href);
|
|
23
|
+
|
|
24
|
+
const EXPECTED = [
|
|
25
|
+
'computer_windows', 'computer_snapshot', 'computer_find_text', 'computer_parse', 'computer_capture',
|
|
26
|
+
'computer_act', 'computer_run', 'computer_wait', 'computer_resolve_window', 'computer_replay',
|
|
27
|
+
'computer_click', 'computer_drag', 'computer_scroll', 'computer_type', 'computer_key', 'computer_mouse',
|
|
28
|
+
'computer_launch', 'computer_close', 'computer_window', 'computer_done', 'computer_clipboard',
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const registered = [];
|
|
32
|
+
const store = {
|
|
33
|
+
windows: [], steps: [], counters: { refused: 0 }, running: false, busy: false, blocked: [], heldButtons: new Set(), attempts: new Map(),
|
|
34
|
+
line() {}, block() { return { id: 1 }; }, step() {}, actionDone() {}, holdButton(b) { this.heldButtons.add(b); }, releaseButton(b) { return this.heldButtons.delete(b); },
|
|
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
|
+
};
|
|
37
|
+
let disposed = false;
|
|
38
|
+
const dispose = registerTools(
|
|
39
|
+
{ tools: { register: (d) => { registered.push(d); return () => {}; } }, systemPrompt: { add: () => () => {} } },
|
|
40
|
+
{
|
|
41
|
+
worker: { call: async () => ({}) },
|
|
42
|
+
store,
|
|
43
|
+
dataDir: join(process.env.TEMP ?? '.', 'dsh-native-uia-loadtest'),
|
|
44
|
+
owned: { windows: new Set() },
|
|
45
|
+
finishRun: async () => {},
|
|
46
|
+
activity: { withoutIndicator: async (f) => f(), beat() {}, show() {}, hide() {} },
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const names = registered.map((d) => d.name);
|
|
51
|
+
const missing = EXPECTED.filter((n) => !names.includes(n));
|
|
52
|
+
const extra = names.filter((n) => !EXPECTED.includes(n));
|
|
53
|
+
if (missing.length) { console.error(`missing tools: ${missing.join(', ')}`); process.exit(1); }
|
|
54
|
+
if (extra.length) { console.error(`unexpected tools: ${extra.join(', ')}`); process.exit(1); }
|
|
55
|
+
if (typeof dispose === 'function') { dispose(); disposed = true; }
|
|
56
|
+
|
|
57
|
+
// Registration only proves the module graph links. A helper that ended up in the wrong domain
|
|
58
|
+
// module (classifyPoint lived in act.js while the pointer tools called it) still registers fine and
|
|
59
|
+
// only dies when a tool runs, so every handler is invoked once with empty args: argument guards
|
|
60
|
+
// answer with a string, and a missing binding throws ReferenceError, which fails this test.
|
|
61
|
+
const broken = [];
|
|
62
|
+
for (const definition of registered) {
|
|
63
|
+
if (typeof definition.execute !== 'function') continue;
|
|
64
|
+
try {
|
|
65
|
+
await definition.execute({}, { signal: undefined });
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (error instanceof ReferenceError) broken.push(`${definition.name}: ${error.message}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (broken.length) {
|
|
71
|
+
console.error(`handlers reference names their module does not define:\n${broken.join('\n')}`);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
console.log(`${names.length}/${EXPECTED.length} tools registered, module graph loads, dispose=${disposed}`);
|
|
@@ -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 });
|