dsh-codex-style-computer-use 2.3.3 → 2.3.5
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 +2 -2
- package/README.zh.md +2 -2
- package/client.js +41 -20
- package/lib/core/bin/dsh-computer-use-worker.exe +0 -0
- package/lib/core/bin/dsh-computer-use-worker.exe.json +2 -2
- package/lib/core/worker.cs +481 -6
- package/lib/host-debug.js +3 -2
- package/lib/index.js +1 -1
- package/lib/tools.js +14 -8
- package/mcp/src/tools.js +2 -1
- package/package.json +2 -2
- package/scripts/check-behavior.mjs +5 -0
- package/skills/computer-use/SKILL.md +6 -0
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://dshopen.org/zh/plugins/dsh-codex-style-computer-use/)
|
|
4
4
|
|
|
5
|
-
**
|
|
5
|
+
**Windows Computer Use 2.3.5 for DeepSeek Harness**
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Discover available actions per control, scroll to an exact percentage, switch views, and place the caret before or after matching text. Includes OCR and batch actions.
|
|
8
8
|
|
|
9
9
|
English | [中文](README.zh.md) | [Français](README.fr.md) | [Deutsch](README.de.md) | [Español](README.es.md) | [Português](README.pt.md) | [العربية](README.ar.md) | [Русский](README.ru.md) | [فارسی](README.fa.md) · [Install](#install-and-update-in-dsh-market) · [Changelog](CHANGELOG.md) · [2.0.0 changes](docs/RELEASE-2.0.0.md)
|
|
10
10
|
|
package/README.zh.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://dshopen.org/zh/plugins/dsh-codex-style-computer-use/)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**Windows 桌面操控 2.3.5 · DeepSeek Harness 插件**
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
先看控件支持哪些操作,再按百分比精确滚动、切换视图或显示离屏条目。编辑时可把光标准确放在匹配文字前后。支持 OCR 和批量操作。
|
|
8
8
|
|
|
9
9
|
[English](README.md) | 中文 | [Français](README.fr.md) | [Deutsch](README.de.md) | [Español](README.es.md) | [Português](README.pt.md) | [العربية](README.ar.md) | [Русский](README.ru.md) | [فارسی](README.fa.md) · [安装](#在-dsh-market-安装和更新) · [版本记录](CHANGELOG.md) · [2.0.0 变更](docs/RELEASE-2.0.0.md)
|
|
10
10
|
|
package/client.js
CHANGED
|
@@ -22,7 +22,7 @@ window.__ModuleLoader__.load({
|
|
|
22
22
|
const module = { exports: {} }
|
|
23
23
|
const exports = module.exports
|
|
24
24
|
const React = require('react')
|
|
25
|
-
const { createElement: h, useState, useEffect, useCallback } = React
|
|
25
|
+
const { createElement: h, useState, useEffect, useCallback, useRef, useSyncExternalStore } = React
|
|
26
26
|
|
|
27
27
|
const API = '/api/computer-use/host-debug'
|
|
28
28
|
const TEXT = {
|
|
@@ -55,35 +55,56 @@ window.__ModuleLoader__.load({
|
|
|
55
55
|
h('b', { style: { color: ok ? 'inherit' : '#c0392b' } }, value))
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
const subscribeToNothing = () => () => {}
|
|
59
|
+
const selectedId = current => current?.getSnapshot().key ?? null
|
|
60
|
+
|
|
61
|
+
async function requestStatus (sessionId, options) {
|
|
62
|
+
const url = sessionId ? API + '?session=' + encodeURIComponent(sessionId) : API
|
|
63
|
+
const r = await fetch(url, options)
|
|
64
|
+
const status = await r.json()
|
|
65
|
+
if (!r.ok) throw new Error(status.error || ('HTTP ' + r.status))
|
|
66
|
+
return status
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function SettingsPage ({ current }) {
|
|
70
|
+
const sessionId = useSyncExternalStore(current?.subscribe ?? subscribeToNothing, () => selectedId(current))
|
|
59
71
|
const [state, setState] = useState(null)
|
|
60
72
|
const [error, setError] = useState(null)
|
|
61
73
|
const [busy, setBusy] = useState(false)
|
|
74
|
+
const lastRead = useRef(0)
|
|
62
75
|
|
|
63
76
|
const load = useCallback(async () => {
|
|
77
|
+
const read = ++lastRead.current
|
|
64
78
|
setError(null)
|
|
65
79
|
try {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
} catch (e) { setError(String(e?.message ?? e)) }
|
|
71
|
-
}, [])
|
|
80
|
+
const status = await requestStatus(selectedId(current), { cache: 'no-store' })
|
|
81
|
+
if (read === lastRead.current) setState(status)
|
|
82
|
+
} catch (e) { if (read === lastRead.current) setError(String(e?.message ?? e)) }
|
|
83
|
+
}, [current])
|
|
72
84
|
|
|
73
|
-
useEffect(() => {
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
load()
|
|
87
|
+
return () => { lastRead.current++ }
|
|
88
|
+
}, [load, sessionId])
|
|
74
89
|
|
|
75
|
-
|
|
90
|
+
async function save (enabled) {
|
|
76
91
|
setBusy(true)
|
|
92
|
+
setError(null)
|
|
77
93
|
try {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
94
|
+
const saved = await requestStatus(sessionId, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ enabled }) })
|
|
95
|
+
if (saved.session.id === selectedId(current)) {
|
|
96
|
+
lastRead.current++
|
|
97
|
+
setState(saved)
|
|
98
|
+
} else {
|
|
99
|
+
// The switch is shared. Refresh the conversation selected during the save.
|
|
100
|
+
await load()
|
|
101
|
+
}
|
|
82
102
|
} catch (e) { setError(String(e?.message ?? e)) } finally { setBusy(false) }
|
|
83
|
-
}
|
|
103
|
+
}
|
|
84
104
|
|
|
85
|
-
const
|
|
86
|
-
const
|
|
105
|
+
const permission = state?.session?.id === sessionId ? state.session : null
|
|
106
|
+
const sandbox = permission?.sandbox ?? null
|
|
107
|
+
const full = permission?.fullAccess === true
|
|
87
108
|
const enabled = state?.enabled === true
|
|
88
109
|
|
|
89
110
|
return h('div', { style: { padding: '18px 22px', lineHeight: 1.55, maxWidth: 760 } },
|
|
@@ -94,7 +115,7 @@ window.__ModuleLoader__.load({
|
|
|
94
115
|
row(TEXT.gate1, full ? TEXT.fullYes : (sandbox ? (TEXT.fullNo + ':' + sandbox) : TEXT.fullUnknown), full),
|
|
95
116
|
row(TEXT.gate2, enabled ? TEXT.on : TEXT.off, enabled),
|
|
96
117
|
h('p', { style: { margin: '10px 0 0', opacity: .75, fontSize: 13 } }, TEXT.gateHint),
|
|
97
|
-
!full ? h('p', { style: { margin: '6px 0 0', color: '#c0392b', fontSize: 13 } }, TEXT.warnGate1) : null,
|
|
118
|
+
sandbox && !full ? h('p', { style: { margin: '6px 0 0', color: '#c0392b', fontSize: 13 } }, TEXT.warnGate1) : null,
|
|
98
119
|
!enabled ? h('p', { style: { margin: '6px 0 0', opacity: .75, fontSize: 13 } }, TEXT.warnOff) : null,
|
|
99
120
|
state.lastBlockedAt ? h('p', { style: { margin: '6px 0 0', fontSize: 13 } }, TEXT.warnBlocked + '(' + TEXT.blockedAt + ':' + state.lastBlockedAt + ')') : null,
|
|
100
121
|
h('p', { style: { margin: '6px 0 0', fontSize: 13, opacity: .6 } },
|
|
@@ -102,7 +123,7 @@ window.__ModuleLoader__.load({
|
|
|
102
123
|
) : h('p', { style: { opacity: .7 } }, TEXT.loading),
|
|
103
124
|
h('div', { style: { display: 'flex', gap: 10, margin: '16px 0 14px' } },
|
|
104
125
|
h('button', {
|
|
105
|
-
disabled: busy,
|
|
126
|
+
disabled: busy || !state,
|
|
106
127
|
onClick: () => save(!enabled),
|
|
107
128
|
style: { padding: '7px 16px', borderRadius: 6, border: '1px solid rgba(127,127,127,.4)', cursor: 'pointer', fontWeight: 600, background: enabled ? 'transparent' : '#1f6feb', color: enabled ? 'inherit' : '#fff' },
|
|
108
129
|
}, busy ? '…' : (enabled ? '关闭调试模式' : '开启调试模式')),
|
|
@@ -119,7 +140,7 @@ window.__ModuleLoader__.load({
|
|
|
119
140
|
order: 52,
|
|
120
141
|
label: () => TEXT.nav,
|
|
121
142
|
locale: 'settings.computerUseDebug',
|
|
122
|
-
}, () => h(SettingsPage)))
|
|
143
|
+
}, () => h(SettingsPage, { current: ctx.get('uiSession')?.adapter?.current })))
|
|
123
144
|
}
|
|
124
145
|
|
|
125
146
|
exports.apply = apply
|
|
Binary file
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"format": 1,
|
|
3
3
|
"platform": "win32",
|
|
4
4
|
"architecture": "x64",
|
|
5
|
-
"sourceSha256": "
|
|
6
|
-
"binarySha256": "
|
|
5
|
+
"sourceSha256": "96928659d137ba3485d6fc838ae5b601e8696e9313946f8000439405dc7dc003",
|
|
6
|
+
"binarySha256": "6ceb7cdc437295198b9d6844fa69a979d8303b6b477b43c15510658fd2ff3892"
|
|
7
7
|
}
|
package/lib/core/worker.cs
CHANGED
|
@@ -8300,6 +8300,293 @@ namespace DshComputerUse.Worker
|
|
|
8300
8300
|
return d;
|
|
8301
8301
|
}
|
|
8302
8302
|
|
|
8303
|
+
// ---- action discovery (opt-in) -------------------------------------------------------
|
|
8304
|
+
// Derived ONLY from what the element actually reports: a pattern is listed when its own
|
|
8305
|
+
// "Is<Pattern>PatternAvailable" property is true, and an action is listed when the pattern
|
|
8306
|
+
// object is really obtainable. A control that does not support something is never told it
|
|
8307
|
+
// does, which is the difference between a capability list and a wish list.
|
|
8308
|
+
//
|
|
8309
|
+
// This is deliberately NOT part of the default response: a broad inventory would pay a
|
|
8310
|
+
// provider read per element for information almost no caller needs.
|
|
8311
|
+
internal static List<string> UiActionsFor(AutomationElement e, UiReadBudget budget)
|
|
8312
|
+
{
|
|
8313
|
+
var actions = new List<string>();
|
|
8314
|
+
if (e == null) return actions;
|
|
8315
|
+
// Every provider access is its OWN budget.Read, so the soft budget is checked between
|
|
8316
|
+
// synchronous COM calls (an individual call cannot be interrupted) and each read is
|
|
8317
|
+
// counted once — wrapping the whole group would check only before and after it.
|
|
8318
|
+
Action<string> add = name => { if (!actions.Contains(name)) actions.Add(name); };
|
|
8319
|
+
|
|
8320
|
+
bool enabled = BudgetBool(budget, delegate { return e.Current.IsEnabled; }, false);
|
|
8321
|
+
bool focusable = BudgetBool(budget, delegate { return e.Current.IsKeyboardFocusable; }, false);
|
|
8322
|
+
// Unknown password state is treated AS a password and unknown read-only state AS
|
|
8323
|
+
// read-only: a capability list must never advertise what it could not confirm.
|
|
8324
|
+
bool password = BudgetBool(budget, delegate { return e.Current.IsPassword; }, true);
|
|
8325
|
+
|
|
8326
|
+
if (BudgetPattern(budget, e, InvokePattern.Pattern) != null && enabled) add("invoke");
|
|
8327
|
+
if (BudgetPattern(budget, e, TogglePattern.Pattern) != null && enabled) add("toggle");
|
|
8328
|
+
|
|
8329
|
+
// ExpandCollapse: a leaf node can hold the pattern and still be unable to expand, so the
|
|
8330
|
+
// real ExpandCollapseState decides. Only a collapsed node can be expanded and only an
|
|
8331
|
+
// expanded one can be collapsed; a leaf or partially-expanded node advertises neither.
|
|
8332
|
+
object expandPattern = BudgetPattern(budget, e, ExpandCollapsePattern.Pattern);
|
|
8333
|
+
if (expandPattern != null && enabled) {
|
|
8334
|
+
var expand = (ExpandCollapsePattern)expandPattern;
|
|
8335
|
+
ExpandCollapseState state = ExpandCollapseState.LeafNode;
|
|
8336
|
+
try { state = budget.Read(delegate { return expand.Current.ExpandCollapseState; }); }
|
|
8337
|
+
catch (UiBudgetStop) { throw; }
|
|
8338
|
+
catch { }
|
|
8339
|
+
if (state == ExpandCollapseState.Collapsed) { add("expand"); }
|
|
8340
|
+
else if (state == ExpandCollapseState.Expanded) { add("collapse"); }
|
|
8341
|
+
// PartiallyExpanded: neither direction is guaranteed, so it advertises neither.
|
|
8342
|
+
}
|
|
8343
|
+
|
|
8344
|
+
if (BudgetPattern(budget, e, ScrollItemPattern.Pattern) != null) add("scrollIntoView");
|
|
8345
|
+
if (BudgetPattern(budget, e, VirtualizedItemPattern.Pattern) != null) add("realize");
|
|
8346
|
+
|
|
8347
|
+
// SelectionItem: add/remove only exist where the container really allows multi-select and
|
|
8348
|
+
// only where removing is allowed. A single-select list (or a required single selection)
|
|
8349
|
+
// can still `select`, but advertising add/remove there would promise something the
|
|
8350
|
+
// control refuses.
|
|
8351
|
+
object itemPattern = BudgetPattern(budget, e, SelectionItemPattern.Pattern);
|
|
8352
|
+
if (itemPattern != null && enabled) {
|
|
8353
|
+
var item = (SelectionItemPattern)itemPattern;
|
|
8354
|
+
add("select");
|
|
8355
|
+
object container = null;
|
|
8356
|
+
try { container = budget.Read(delegate { return item.Current.SelectionContainer; }); }
|
|
8357
|
+
catch (UiBudgetStop) { throw; }
|
|
8358
|
+
catch { }
|
|
8359
|
+
AutomationElement holder = container as AutomationElement;
|
|
8360
|
+
if (holder != null) {
|
|
8361
|
+
// Read the container through its SelectionPattern: the server-side
|
|
8362
|
+
// SelectionContainer element does not carry a cached property set, so a plain
|
|
8363
|
+
// GetCurrentPropertyValue returns NotSupported and would silently allow
|
|
8364
|
+
// add/remove that the container actually refuses.
|
|
8365
|
+
bool canSelectMultiple = false, selectionRequired = false;
|
|
8366
|
+
object selectionPattern = null;
|
|
8367
|
+
try { selectionPattern = budget.Read(delegate { object p; return holder.TryGetCurrentPattern(SelectionPattern.Pattern, out p) ? p : null; }); }
|
|
8368
|
+
catch (UiBudgetStop) { throw; }
|
|
8369
|
+
catch { }
|
|
8370
|
+
var selection = selectionPattern as SelectionPattern;
|
|
8371
|
+
if (selection != null) {
|
|
8372
|
+
try { canSelectMultiple = budget.Read(delegate { return selection.Current.CanSelectMultiple; }); }
|
|
8373
|
+
catch (UiBudgetStop) { throw; }
|
|
8374
|
+
catch { }
|
|
8375
|
+
try { selectionRequired = budget.Read(delegate { return selection.Current.IsSelectionRequired; }); }
|
|
8376
|
+
catch (UiBudgetStop) { throw; }
|
|
8377
|
+
catch { }
|
|
8378
|
+
} else {
|
|
8379
|
+
// No SelectionPattern means multi-select cannot be confirmed: stay
|
|
8380
|
+
// conservative and advertise only `select`.
|
|
8381
|
+
canSelectMultiple = false;
|
|
8382
|
+
}
|
|
8383
|
+
// Removing is legal in more places than "multi-select and not required":
|
|
8384
|
+
// * an UNSELECTED item cannot be removed at all;
|
|
8385
|
+
// * a SELECTED item can be removed when the selection is not required;
|
|
8386
|
+
// * with a REQUIRED selection, a selected item can still be removed as long as
|
|
8387
|
+
// it is not the only remaining one (so a single-select list whose selection
|
|
8388
|
+
// is clearable still allows remove).
|
|
8389
|
+
// Adding needs a container that really allows multiple selection AND an item that
|
|
8390
|
+
// is not selected yet.
|
|
8391
|
+
bool isSelected = false;
|
|
8392
|
+
try { isSelected = budget.Read(delegate { return item.Current.IsSelected; }); }
|
|
8393
|
+
catch (UiBudgetStop) { throw; }
|
|
8394
|
+
catch { }
|
|
8395
|
+
|
|
8396
|
+
if (canSelectMultiple && !isSelected) add("addToSelection");
|
|
8397
|
+
|
|
8398
|
+
if (isSelected) {
|
|
8399
|
+
bool canRemove;
|
|
8400
|
+
if (!selectionRequired) canRemove = true;
|
|
8401
|
+
else {
|
|
8402
|
+
// A required selection protects only the LAST selected item, so the
|
|
8403
|
+
// selected count decides — read it under the same budget.
|
|
8404
|
+
int selectedCount = -1;
|
|
8405
|
+
if (selection != null) {
|
|
8406
|
+
try { selectedCount = budget.Read(delegate { return selection.Current.GetSelection().Length; }); }
|
|
8407
|
+
catch (UiBudgetStop) { throw; }
|
|
8408
|
+
catch { selectedCount = -1; }
|
|
8409
|
+
}
|
|
8410
|
+
// Unknown count with a required selection: stay conservative and do not
|
|
8411
|
+
// advertise remove, because removing the last one would be refused.
|
|
8412
|
+
canRemove = selectedCount > 1;
|
|
8413
|
+
}
|
|
8414
|
+
if (canRemove) add("removeFromSelection");
|
|
8415
|
+
}
|
|
8416
|
+
}
|
|
8417
|
+
}
|
|
8418
|
+
|
|
8419
|
+
object pattern = BudgetPattern(budget, e, ValuePattern.Pattern);
|
|
8420
|
+
if (pattern != null && enabled) {
|
|
8421
|
+
bool readOnly = BudgetBool(budget, delegate { return ((ValuePattern)pattern).Current.IsReadOnly; }, true);
|
|
8422
|
+
if (!readOnly) add("setValue");
|
|
8423
|
+
} else {
|
|
8424
|
+
pattern = BudgetPattern(budget, e, RangeValuePattern.Pattern);
|
|
8425
|
+
if (pattern != null && enabled) {
|
|
8426
|
+
bool readOnly = BudgetBool(budget, delegate { return ((RangeValuePattern)pattern).Current.IsReadOnly; }, true);
|
|
8427
|
+
if (!readOnly) add("setValue");
|
|
8428
|
+
}
|
|
8429
|
+
}
|
|
8430
|
+
|
|
8431
|
+
pattern = BudgetPattern(budget, e, ScrollPattern.Pattern);
|
|
8432
|
+
if (pattern != null && enabled) {
|
|
8433
|
+
var scroll = (ScrollPattern)pattern;
|
|
8434
|
+
bool horizontal = BudgetBool(budget, delegate { return scroll.Current.HorizontallyScrollable; }, false);
|
|
8435
|
+
bool vertical = BudgetBool(budget, delegate { return scroll.Current.VerticallyScrollable; }, false);
|
|
8436
|
+
if (horizontal || vertical) { add("scroll"); add("setScrollPercent"); }
|
|
8437
|
+
}
|
|
8438
|
+
|
|
8439
|
+
if (BudgetPattern(budget, e, MultipleViewPattern.Pattern) != null && enabled) add("setCurrentView");
|
|
8440
|
+
|
|
8441
|
+
// Text: selectText needs a SELECTABLE, non-password control — having a TextPattern is
|
|
8442
|
+
// not the same thing (read-only viewers and password boxes both expose one).
|
|
8443
|
+
pattern = BudgetPattern(budget, e, TextPattern.Pattern);
|
|
8444
|
+
if (pattern != null && !password && enabled) {
|
|
8445
|
+
var text = (TextPattern)pattern;
|
|
8446
|
+
bool selectable = BudgetBool(budget, delegate { return text.SupportedTextSelection != SupportedTextSelection.None; }, false);
|
|
8447
|
+
if (selectable) add("selectText");
|
|
8448
|
+
}
|
|
8449
|
+
// focus follows IsKeyboardFocusable AND the enabled state: a disabled control reports
|
|
8450
|
+
// itself focusable on some providers yet cannot take focus, so it advertises neither.
|
|
8451
|
+
if (focusable && enabled) add("focus");
|
|
8452
|
+
return actions;
|
|
8453
|
+
}
|
|
8454
|
+
|
|
8455
|
+
/// <summary>
|
|
8456
|
+
/// A property read under the caller's budget. `fallbackWhenUnreadable` decides what an
|
|
8457
|
+
/// UNKNOWN answer means, and it matters both ways: for a RESTRICTIVE property (IsPassword,
|
|
8458
|
+
/// IsReadOnly) unknown must fall back to the restrictive value, never to the permissive one,
|
|
8459
|
+
/// so a provider error can never advertise an action the control might refuse.
|
|
8460
|
+
/// </summary>
|
|
8461
|
+
static bool BudgetBool(UiReadBudget budget, Func<bool> read, bool fallbackWhenUnreadable)
|
|
8462
|
+
{
|
|
8463
|
+
try { return budget.Read(delegate { return read(); }); }
|
|
8464
|
+
catch (UiBudgetStop) { throw; }
|
|
8465
|
+
catch { return fallbackWhenUnreadable; }
|
|
8466
|
+
}
|
|
8467
|
+
|
|
8468
|
+
/// <summary>
|
|
8469
|
+
/// Obtain one pattern under the caller's budget. UiBudgetStop is ALWAYS rethrown — a budget
|
|
8470
|
+
/// exhaustion must never be mistaken for "the control does not support this".
|
|
8471
|
+
/// </summary>
|
|
8472
|
+
static object BudgetPattern(UiReadBudget budget, AutomationElement e, AutomationPattern required)
|
|
8473
|
+
{
|
|
8474
|
+
try
|
|
8475
|
+
{
|
|
8476
|
+
return budget.Read(delegate
|
|
8477
|
+
{
|
|
8478
|
+
object pattern;
|
|
8479
|
+
return e.TryGetCurrentPattern(required, out pattern) ? pattern : null;
|
|
8480
|
+
});
|
|
8481
|
+
}
|
|
8482
|
+
catch (UiBudgetStop) { throw; }
|
|
8483
|
+
catch { return null; }
|
|
8484
|
+
}
|
|
8485
|
+
|
|
8486
|
+
/// <summary>
|
|
8487
|
+
/// The terse parameter summary an action really takes, plus the live capability ranges a
|
|
8488
|
+
/// caller needs to pick a legal value (scroll axes, view ids, value bounds). Only values the
|
|
8489
|
+
/// provider already exposes are reported.
|
|
8490
|
+
/// </summary>
|
|
8491
|
+
internal static Dictionary<string, object> UiActionSchema(AutomationElement e, List<string> actions, UiReadBudget budget)
|
|
8492
|
+
{
|
|
8493
|
+
var schema = new Dictionary<string, object>();
|
|
8494
|
+
if (e == null) return schema;
|
|
8495
|
+
foreach (string action in actions)
|
|
8496
|
+
{
|
|
8497
|
+
switch (action)
|
|
8498
|
+
{
|
|
8499
|
+
case "setScrollPercent":
|
|
8500
|
+
schema[action] = Dict("argument", "horizontalPercent/verticalPercent (0-100, or -1 to leave that axis unchanged)");
|
|
8501
|
+
break;
|
|
8502
|
+
case "scroll":
|
|
8503
|
+
schema[action] = Dict("argument", "value: up|down|left|right");
|
|
8504
|
+
break;
|
|
8505
|
+
case "setCurrentView":
|
|
8506
|
+
schema[action] = Dict("argument", "value: a viewId from views");
|
|
8507
|
+
break;
|
|
8508
|
+
case "setValue":
|
|
8509
|
+
schema[action] = Dict("argument", "value: text, or a finite number within range");
|
|
8510
|
+
break;
|
|
8511
|
+
case "selectText":
|
|
8512
|
+
schema[action] = Dict("argument", "value + optional prefix/suffix; optional selectionType select|cursor_before|cursor_after");
|
|
8513
|
+
break;
|
|
8514
|
+
default:
|
|
8515
|
+
schema[action] = Dict("argument", "none");
|
|
8516
|
+
break;
|
|
8517
|
+
}
|
|
8518
|
+
}
|
|
8519
|
+
// Live capability detail: only what this control reports right now. Each provider access
|
|
8520
|
+
// is its own budget.Read, and UiBudgetStop is rethrown rather than swallowed.
|
|
8521
|
+
try
|
|
8522
|
+
{
|
|
8523
|
+
if (actions.Contains("setScrollPercent"))
|
|
8524
|
+
{
|
|
8525
|
+
object pattern = BudgetPattern(budget, e, ScrollPattern.Pattern);
|
|
8526
|
+
if (pattern != null)
|
|
8527
|
+
{
|
|
8528
|
+
var scroll = (ScrollPattern)pattern;
|
|
8529
|
+
bool horizontal = BudgetBool(budget, delegate { return scroll.Current.HorizontallyScrollable; }, false);
|
|
8530
|
+
bool vertical = BudgetBool(budget, delegate { return scroll.Current.VerticallyScrollable; }, false);
|
|
8531
|
+
double? verticalPercent = null, horizontalPercent = null;
|
|
8532
|
+
try { verticalPercent = budget.Read(delegate { return scroll.Current.VerticalScrollPercent; }); } catch (UiBudgetStop) { throw; } catch { }
|
|
8533
|
+
try { horizontalPercent = budget.Read(delegate { return scroll.Current.HorizontalScrollPercent; }); } catch (UiBudgetStop) { throw; } catch { }
|
|
8534
|
+
schema["scrollAxes"] = Dict("horizontal", horizontal, "vertical", vertical,
|
|
8535
|
+
"verticalPercent", verticalPercent, "horizontalPercent", horizontalPercent);
|
|
8536
|
+
}
|
|
8537
|
+
}
|
|
8538
|
+
if (actions.Contains("setCurrentView"))
|
|
8539
|
+
{
|
|
8540
|
+
object pattern = BudgetPattern(budget, e, MultipleViewPattern.Pattern);
|
|
8541
|
+
if (pattern != null)
|
|
8542
|
+
{
|
|
8543
|
+
var views = (MultipleViewPattern)pattern;
|
|
8544
|
+
// A control may report many views; listing them is bounded so an absurd list
|
|
8545
|
+
// can neither blow the response nor the budget.
|
|
8546
|
+
const int maxViews = 32;
|
|
8547
|
+
int[] ids = null;
|
|
8548
|
+
try { ids = budget.Read(delegate { return views.Current.GetSupportedViews(); }) ?? new int[0]; }
|
|
8549
|
+
catch (UiBudgetStop) { throw; } catch { }
|
|
8550
|
+
if (ids != null)
|
|
8551
|
+
{
|
|
8552
|
+
var named = new List<object>();
|
|
8553
|
+
foreach (int id in ids.Take(maxViews))
|
|
8554
|
+
{
|
|
8555
|
+
int viewId = id;
|
|
8556
|
+
string name = null;
|
|
8557
|
+
// Each view name is one more provider read, counted on its own.
|
|
8558
|
+
try { name = budget.Read(delegate { return views.GetViewName(viewId); }); }
|
|
8559
|
+
catch (UiBudgetStop) { throw; } catch { }
|
|
8560
|
+
named.Add(Dict("id", viewId, "name", name));
|
|
8561
|
+
}
|
|
8562
|
+
schema["views"] = named;
|
|
8563
|
+
schema["viewsTruncated"] = ids.Length > maxViews;
|
|
8564
|
+
try { schema["currentView"] = budget.Read(delegate { return views.Current.CurrentView; }); }
|
|
8565
|
+
catch (UiBudgetStop) { throw; } catch { }
|
|
8566
|
+
}
|
|
8567
|
+
}
|
|
8568
|
+
}
|
|
8569
|
+
if (actions.Contains("setValue"))
|
|
8570
|
+
{
|
|
8571
|
+
object pattern = BudgetPattern(budget, e, RangeValuePattern.Pattern);
|
|
8572
|
+
if (pattern != null)
|
|
8573
|
+
{
|
|
8574
|
+
var range = (RangeValuePattern)pattern;
|
|
8575
|
+
double? minimum = null, maximum = null, value = null;
|
|
8576
|
+
bool readOnly = false;
|
|
8577
|
+
try { minimum = budget.Read(delegate { return range.Current.Minimum; }); } catch (UiBudgetStop) { throw; } catch { }
|
|
8578
|
+
try { maximum = budget.Read(delegate { return range.Current.Maximum; }); } catch (UiBudgetStop) { throw; } catch { }
|
|
8579
|
+
try { value = budget.Read(delegate { return range.Current.Value; }); } catch (UiBudgetStop) { throw; } catch { }
|
|
8580
|
+
readOnly = BudgetBool(budget, delegate { return range.Current.IsReadOnly; }, true);
|
|
8581
|
+
schema["range"] = Dict("minimum", minimum, "maximum", maximum, "value", value, "readOnly", readOnly);
|
|
8582
|
+
}
|
|
8583
|
+
}
|
|
8584
|
+
}
|
|
8585
|
+
catch (UiBudgetStop) { throw; }
|
|
8586
|
+
catch { }
|
|
8587
|
+
return schema;
|
|
8588
|
+
}
|
|
8589
|
+
|
|
8303
8590
|
// >>>UIA-QUERY-BUDGET<<<
|
|
8304
8591
|
// Cooperative limits between provider calls. A synchronous UIA/COM call
|
|
8305
8592
|
// already in progress is NOT interruptible by this traversal budget.
|
|
@@ -8515,11 +8802,20 @@ namespace DshComputerUse.Worker
|
|
|
8515
8802
|
catch (UiBudgetStop) { evidenceRoot = null; }
|
|
8516
8803
|
}
|
|
8517
8804
|
string nameFilter = GetS(a, "nameContains", null), idFilter = GetS(a, "automationId", null), roleFilter = GetS(a, "role", null);
|
|
8805
|
+
// Action discovery is OPT-IN: only a caller that asked for `actions` pays the extra
|
|
8806
|
+
// provider reads per element, and a broad inventory never carries them.
|
|
8807
|
+
bool wantActions = GetB(a, "actions", false);
|
|
8518
8808
|
CacheRequest selectorCache = UiSelectorCache();
|
|
8519
8809
|
UiWalkBounded(rootEl, maxDepth, maxNodes, Math.Max(1, Math.Min(80, GetI(a, "limit", 80))), budget,
|
|
8520
8810
|
delegate(AutomationElement match) {
|
|
8521
8811
|
if (!ElementMatchesBudgeted(match, nameFilter, idFilter, roleFilter, budget)) return false;
|
|
8522
8812
|
var item = ElemDictBudgeted(match, budget);
|
|
8813
|
+
if (wantActions) {
|
|
8814
|
+
// Discovery itself is one budgeted read; the schema is a second one.
|
|
8815
|
+
var discovered = budget.Read(delegate { return UiActionsFor(match, budget); });
|
|
8816
|
+
item["actions"] = discovered;
|
|
8817
|
+
item["actionSchema"] = budget.Read(delegate { return UiActionSchema(match, discovered, budget); });
|
|
8818
|
+
}
|
|
8523
8819
|
if (witness != null) {
|
|
8524
8820
|
try {
|
|
8525
8821
|
if (evidenceRoot == null) throw new UiBudgetStop();
|
|
@@ -8732,6 +9028,43 @@ namespace DshComputerUse.Worker
|
|
|
8732
9028
|
return matches;
|
|
8733
9029
|
}
|
|
8734
9030
|
|
|
9031
|
+
/// <summary>
|
|
9032
|
+
/// Describe an element only if it still answers. Used after an action that may invalidate
|
|
9033
|
+
/// it (Realize): a dead element must not turn a successful action into a failed one.
|
|
9034
|
+
/// </summary>
|
|
9035
|
+
static Dictionary<string, object> SafeElemDict(AutomationElement e, Dictionary<string, object> receipt)
|
|
9036
|
+
{
|
|
9037
|
+
try { return ElemDict(e); }
|
|
9038
|
+
catch (Exception error)
|
|
9039
|
+
{
|
|
9040
|
+
receipt["elementUnavailable"] = error.GetType().Name;
|
|
9041
|
+
return null;
|
|
9042
|
+
}
|
|
9043
|
+
}
|
|
9044
|
+
|
|
9045
|
+
/// <summary>
|
|
9046
|
+
/// One axis of a scroll percentage: absent or -1 means "leave this axis unchanged"
|
|
9047
|
+
/// (ScrollPattern.NoScroll), anything else must be a finite 0..100. A rejected value never
|
|
9048
|
+
/// reaches the provider.
|
|
9049
|
+
/// </summary>
|
|
9050
|
+
static bool TryScrollPercent(string text, out double value)
|
|
9051
|
+
{
|
|
9052
|
+
value = ScrollPattern.NoScroll;
|
|
9053
|
+
if (text == null) return true;
|
|
9054
|
+
string trimmed = text.Trim();
|
|
9055
|
+
if (trimmed.Length == 0) return true;
|
|
9056
|
+
if (!Double.TryParse(trimmed, System.Globalization.NumberStyles.Float,
|
|
9057
|
+
System.Globalization.CultureInfo.InvariantCulture, out value)) return false;
|
|
9058
|
+
if (Double.IsNaN(value) || Double.IsInfinity(value)) return false;
|
|
9059
|
+
if (value == ScrollPattern.NoScroll) return true;
|
|
9060
|
+
return value >= 0 && value <= 100;
|
|
9061
|
+
}
|
|
9062
|
+
|
|
9063
|
+
/// <summary>
|
|
9064
|
+
/// Locate the exact passage and return its range WITHOUT committing anything: no MarkMutation,
|
|
9065
|
+
/// no Select. The caller validates, folds if asked, and then commits with exactly ONE
|
|
9066
|
+
/// Select() — a request must produce one selection change, not two.
|
|
9067
|
+
/// </summary>
|
|
8735
9068
|
static TextPatternRange SelectExactText(TextPattern pattern, string value, string prefix, string suffix)
|
|
8736
9069
|
{
|
|
8737
9070
|
if (String.IsNullOrEmpty(value)) throw new Exception("selectText requires nonempty text in value");
|
|
@@ -8751,8 +9084,6 @@ namespace DshComputerUse.Worker
|
|
|
8751
9084
|
if (suffix.Length > 0)
|
|
8752
9085
|
match.MoveEndpointByRange(TextPatternRangeEndpoint.End, match.FindText(suffix, true, false), TextPatternRangeEndpoint.Start);
|
|
8753
9086
|
if (match.GetText(value.Length + 1) != value) throw new Exception("TEXT_CHANGED: query the passage again");
|
|
8754
|
-
MarkMutation();
|
|
8755
|
-
match.Select();
|
|
8756
9087
|
return match;
|
|
8757
9088
|
}
|
|
8758
9089
|
|
|
@@ -8815,6 +9146,9 @@ namespace DshComputerUse.Worker
|
|
|
8815
9146
|
object pat = null;
|
|
8816
9147
|
string via = null;
|
|
8817
9148
|
TextPatternRange selectedRange = null;
|
|
9149
|
+
string selectedType = "select";
|
|
9150
|
+
bool beforeHorizontalEnabled = false, beforeVerticalEnabled = false;
|
|
9151
|
+
object beforeViewId = null;
|
|
8818
9152
|
double beforeScrollPercent = 0;
|
|
8819
9153
|
switch (action)
|
|
8820
9154
|
{
|
|
@@ -8836,7 +9170,23 @@ namespace DshComputerUse.Worker
|
|
|
8836
9170
|
case "selectText":
|
|
8837
9171
|
if (found.Current.IsPassword) throw new Exception("selectText is unavailable on password controls");
|
|
8838
9172
|
if (found.TryGetCurrentPattern(TextPattern.Pattern, out pat)) {
|
|
8839
|
-
|
|
9173
|
+
string selectionType = GetS(a, "selectionType", "select");
|
|
9174
|
+
if (selectionType != "select" && selectionType != "cursor_before" && selectionType != "cursor_after")
|
|
9175
|
+
throw new Exception("INVALID_ARGUMENT: selectionType must be select, cursor_before or cursor_after; no action sent");
|
|
9176
|
+
var match = SelectExactText((TextPattern)pat, GetS(a, "value", ""), GetS(a, "prefix", "") ?? "", GetS(a, "suffix", "") ?? "");
|
|
9177
|
+
// Fold the SAME range: cursor_before collapses its end onto its start,
|
|
9178
|
+
// cursor_after collapses its start onto its end. Both are endpoint moves on
|
|
9179
|
+
// the one matched range, never a second search.
|
|
9180
|
+
if (selectionType == "cursor_before")
|
|
9181
|
+
match.MoveEndpointByRange(TextPatternRangeEndpoint.End, match, TextPatternRangeEndpoint.Start);
|
|
9182
|
+
else if (selectionType == "cursor_after")
|
|
9183
|
+
match.MoveEndpointByRange(TextPatternRangeEndpoint.Start, match, TextPatternRangeEndpoint.End);
|
|
9184
|
+
// EXACTLY ONE commit per request: the range is fully decided above, so this
|
|
9185
|
+
// is the only Select() a caller's SelectionChanged handler can observe.
|
|
9186
|
+
MarkMutation();
|
|
9187
|
+
match.Select();
|
|
9188
|
+
selectedRange = match;
|
|
9189
|
+
selectedType = selectionType;
|
|
8840
9190
|
via = "TextPattern.Select";
|
|
8841
9191
|
}
|
|
8842
9192
|
break;
|
|
@@ -8864,6 +9214,72 @@ namespace DshComputerUse.Worker
|
|
|
8864
9214
|
}
|
|
8865
9215
|
break;
|
|
8866
9216
|
}
|
|
9217
|
+
case "setCurrentView":
|
|
9218
|
+
{
|
|
9219
|
+
// Validate the view id against what the provider actually reports BEFORE
|
|
9220
|
+
// touching it: an unsupported id must not be attempted at all.
|
|
9221
|
+
string viewText = GetS(a, "value", "");
|
|
9222
|
+
int viewId;
|
|
9223
|
+
if (!Int32.TryParse(viewText, System.Globalization.NumberStyles.Integer,
|
|
9224
|
+
System.Globalization.CultureInfo.InvariantCulture, out viewId))
|
|
9225
|
+
throw new Exception("INVALID_ARGUMENT: setCurrentView needs a numeric viewId in value; no action sent");
|
|
9226
|
+
if (found.TryGetCurrentPattern(MultipleViewPattern.Pattern, out pat)) {
|
|
9227
|
+
var multiple = (MultipleViewPattern)pat;
|
|
9228
|
+
int[] supported = multiple.Current.GetSupportedViews() ?? new int[0];
|
|
9229
|
+
if (Array.IndexOf(supported, viewId) < 0)
|
|
9230
|
+
throw new Exception("VIEW_ID_UNSUPPORTED: this control supports " +
|
|
9231
|
+
String.Join(",", supported.Select(n => n.ToString())) + "; no action sent");
|
|
9232
|
+
beforeViewId = multiple.Current.CurrentView;
|
|
9233
|
+
MarkMutation();
|
|
9234
|
+
multiple.SetCurrentView(viewId);
|
|
9235
|
+
via = "MultipleViewPattern.SetCurrentView";
|
|
9236
|
+
}
|
|
9237
|
+
break;
|
|
9238
|
+
}
|
|
9239
|
+
case "setScrollPercent":
|
|
9240
|
+
{
|
|
9241
|
+
// Each axis is independent: missing or -1 means "leave this axis unchanged",
|
|
9242
|
+
// exactly like ScrollPattern.NoScroll. 0..100 is the only legal range.
|
|
9243
|
+
// The PUBLIC contract is the two axis parameters; there is no undocumented
|
|
9244
|
+
// fallback from `value` to the horizontal axis.
|
|
9245
|
+
object rawH, rawV;
|
|
9246
|
+
string horizontalText = a.TryGetValue("horizontalPercent", out rawH) ? Convert.ToString(rawH, System.Globalization.CultureInfo.InvariantCulture) : null;
|
|
9247
|
+
string verticalText = a.TryGetValue("verticalPercent", out rawV) ? Convert.ToString(rawV, System.Globalization.CultureInfo.InvariantCulture) : null;
|
|
9248
|
+
if (horizontalText == null && verticalText == null)
|
|
9249
|
+
throw new Exception("INVALID_ARGUMENT: setScrollPercent needs horizontalPercent and/or verticalPercent (0-100, or -1 to leave an axis unchanged); no action sent");
|
|
9250
|
+
double horizontal, vertical;
|
|
9251
|
+
if (!TryScrollPercent(horizontalText, out horizontal))
|
|
9252
|
+
throw new Exception("INVALID_ARGUMENT: horizontalPercent must be 0-100 or -1; no action sent");
|
|
9253
|
+
if (!TryScrollPercent(verticalText, out vertical))
|
|
9254
|
+
throw new Exception("INVALID_ARGUMENT: verticalPercent must be 0-100 or -1; no action sent");
|
|
9255
|
+
if (found.TryGetCurrentPattern(ScrollPattern.Pattern, out pat)) {
|
|
9256
|
+
var scroll = (ScrollPattern)pat;
|
|
9257
|
+
bool wantsHorizontal = horizontal != ScrollPattern.NoScroll;
|
|
9258
|
+
bool wantsVertical = vertical != ScrollPattern.NoScroll;
|
|
9259
|
+
if (wantsHorizontal && !scroll.Current.HorizontallyScrollable)
|
|
9260
|
+
throw new Exception("SCROLL_AXIS_UNAVAILABLE: this control cannot scroll horizontally; no action sent");
|
|
9261
|
+
if (wantsVertical && !scroll.Current.VerticallyScrollable)
|
|
9262
|
+
throw new Exception("SCROLL_AXIS_UNAVAILABLE: this control cannot scroll vertically; no action sent");
|
|
9263
|
+
beforeHorizontalEnabled = scroll.Current.HorizontallyScrollable;
|
|
9264
|
+
beforeVerticalEnabled = scroll.Current.VerticallyScrollable;
|
|
9265
|
+
beforeScrollPercent = scroll.Current.VerticalScrollPercent;
|
|
9266
|
+
MarkMutation();
|
|
9267
|
+
scroll.SetScrollPercent(horizontal, vertical);
|
|
9268
|
+
via = "ScrollPattern.SetScrollPercent";
|
|
9269
|
+
}
|
|
9270
|
+
break;
|
|
9271
|
+
}
|
|
9272
|
+
case "realize":
|
|
9273
|
+
{
|
|
9274
|
+
// VirtualizedItem.Realize can invalidate the element it was called on, so the
|
|
9275
|
+
// receipt says so and callers must re-observe instead of replaying.
|
|
9276
|
+
if (found.TryGetCurrentPattern(VirtualizedItemPattern.Pattern, out pat)) {
|
|
9277
|
+
MarkMutation();
|
|
9278
|
+
((VirtualizedItemPattern)pat).Realize();
|
|
9279
|
+
via = "VirtualizedItemPattern.Realize";
|
|
9280
|
+
}
|
|
9281
|
+
break;
|
|
9282
|
+
}
|
|
8867
9283
|
case "focus":
|
|
8868
9284
|
MarkMutation(); found.SetFocus(); via = "SetFocus"; break;
|
|
8869
9285
|
case "scrollIntoView":
|
|
@@ -8884,23 +9300,82 @@ namespace DshComputerUse.Worker
|
|
|
8884
9300
|
}
|
|
8885
9301
|
break;
|
|
8886
9302
|
default:
|
|
8887
|
-
throw new Exception("action must be invoke|select|addToSelection|removeFromSelection|selectText|expand|collapse|toggle|setValue|focus|scrollIntoView");
|
|
9303
|
+
throw new Exception("action must be invoke|select|addToSelection|removeFromSelection|selectText|expand|collapse|toggle|setValue|focus|scrollIntoView|scroll|setScrollPercent|realize|setCurrentView");
|
|
8888
9304
|
}
|
|
8889
9305
|
EndActuationForReadback();
|
|
8890
9306
|
if (via == null)
|
|
8891
9307
|
throw new Exception("element does not support '" + action + "': " + ElemDict(found)["name"]);
|
|
8892
9308
|
|
|
8893
9309
|
Thread.Sleep(GetI(a, "settleMs", 120));
|
|
8894
|
-
Dictionary<string, object> res = Dict("action", action, "via", via, "
|
|
9310
|
+
Dictionary<string, object> res = Dict("action", action, "via", via, "scanned", seen);
|
|
9311
|
+
// Realize is the one action that can invalidate the element it was called on, so the
|
|
9312
|
+
// element is described LAST and only if it still answers; a dead element is reported as
|
|
9313
|
+
// such instead of failing the whole (already successful) action.
|
|
9314
|
+
if (via == "VirtualizedItemPattern.Realize") {
|
|
9315
|
+
res["realized"] = true;
|
|
9316
|
+
res["reobserveRequired"] = true;
|
|
9317
|
+
res["element"] = SafeElemDict(found, res);
|
|
9318
|
+
res["note"] = "Realize can invalidate this element; query again before another action on it";
|
|
9319
|
+
} else {
|
|
9320
|
+
res["element"] = ElemDict(found);
|
|
9321
|
+
}
|
|
8895
9322
|
try {
|
|
8896
9323
|
if (via == "ScrollPattern") {
|
|
8897
9324
|
var scroll = ((ScrollPattern)pat).Current;
|
|
8898
9325
|
string direction = GetS(a, "value", "");
|
|
8899
9326
|
res["beforePercent"] = beforeScrollPercent;
|
|
8900
9327
|
res["afterPercent"] = direction == "left" || direction == "right" ? scroll.HorizontalScrollPercent : scroll.VerticalScrollPercent;
|
|
9328
|
+
} else if (via == "ScrollPattern.SetScrollPercent") {
|
|
9329
|
+
// Both axes are reported, and a "-1 / unchanged" axis is reported as exactly that
|
|
9330
|
+
// so a caller can prove the other axis was not disturbed.
|
|
9331
|
+
var scroll = ((ScrollPattern)pat).Current;
|
|
9332
|
+
res["horizontalPercent"] = scroll.HorizontalScrollPercent;
|
|
9333
|
+
res["verticalPercent"] = scroll.VerticalScrollPercent;
|
|
9334
|
+
res["horizontalScrollable"] = scroll.HorizontallyScrollable;
|
|
9335
|
+
res["verticalScrollable"] = scroll.VerticallyScrollable;
|
|
9336
|
+
res["beforePercent"] = beforeScrollPercent;
|
|
9337
|
+
res["afterPercent"] = scroll.VerticalScrollPercent;
|
|
9338
|
+
res["beforeHorizontalScrollable"] = beforeHorizontalEnabled;
|
|
9339
|
+
res["beforeVerticalScrollable"] = beforeVerticalEnabled;
|
|
9340
|
+
} else if (via == "MultipleViewPattern.SetCurrentView") {
|
|
9341
|
+
var multiple = (MultipleViewPattern)pat;
|
|
9342
|
+
res["currentView"] = multiple.Current.CurrentView;
|
|
9343
|
+
res["beforeView"] = beforeViewId;
|
|
9344
|
+
res["supportedViews"] = multiple.Current.GetSupportedViews();
|
|
9345
|
+
res["viewChanged"] = !Equals(beforeViewId, multiple.Current.CurrentView);
|
|
9346
|
+
} else if (via == "VirtualizedItemPattern.Realize") {
|
|
9347
|
+
// Already described above (realized / reobserveRequired / element-or-unavailable).
|
|
8901
9348
|
} else if (selectedRange != null) {
|
|
8902
9349
|
var selected = ((TextPattern)pat).GetSelection();
|
|
8903
|
-
res["
|
|
9350
|
+
res["selectionType"] = selectedType;
|
|
9351
|
+
// Endpoint proof WITHOUT trusting a bounded text length: ask the control's own
|
|
9352
|
+
// held range how it compares to the range we selected. That comparison is the
|
|
9353
|
+
// real UIA answer and needs no offsets at all.
|
|
9354
|
+
if (selected.Length == 1) {
|
|
9355
|
+
TextPatternRange held = selected[0];
|
|
9356
|
+
// Old-contract semantics: verified means the control HOLDS EXACTLY the range we
|
|
9357
|
+
// asked for. It starts false and only becomes true after the comparisons
|
|
9358
|
+
// really succeeded — a provider that accepts Select() but keeps a different
|
|
9359
|
+
// range must not read as verified.
|
|
9360
|
+
res["selectionVerified"] = false;
|
|
9361
|
+
bool startMatches = false, endMatches = false, collapsed = false;
|
|
9362
|
+
try {
|
|
9363
|
+
startMatches = held.CompareEndpoints(TextPatternRangeEndpoint.Start, selectedRange, TextPatternRangeEndpoint.Start) == 0;
|
|
9364
|
+
endMatches = held.CompareEndpoints(TextPatternRangeEndpoint.End, selectedRange, TextPatternRangeEndpoint.End) == 0;
|
|
9365
|
+
collapsed = held.CompareEndpoints(TextPatternRangeEndpoint.Start, held, TextPatternRangeEndpoint.End) == 0;
|
|
9366
|
+
res["startMatches"] = startMatches;
|
|
9367
|
+
res["endMatches"] = endMatches;
|
|
9368
|
+
res["collapsed"] = collapsed;
|
|
9369
|
+
bool foldRequested = selectedType == "cursor_before" || selectedType == "cursor_after";
|
|
9370
|
+
res["selectionVerified"] = startMatches && endMatches && (!foldRequested || collapsed);
|
|
9371
|
+
} catch (Exception comparisonError) {
|
|
9372
|
+
// Unverifiable is NOT verified: say so instead of claiming the old contract.
|
|
9373
|
+
res["selectionVerified"] = false;
|
|
9374
|
+
res["compareUnavailable"] = comparisonError.GetType().Name;
|
|
9375
|
+
}
|
|
9376
|
+
// No document-wide text read here: the absolute offsets are the fixture's own
|
|
9377
|
+
// business, and a 1 MiB prefix read has no place in a default action.
|
|
9378
|
+
} else res["selectionVerified"] = false;
|
|
8904
9379
|
} else if (via == "RangeValuePattern") res["rangeValue"] = ((RangeValuePattern)pat).Current.Value;
|
|
8905
9380
|
else if (action == "addToSelection" || action == "removeFromSelection")
|
|
8906
9381
|
res["isSelected"] = ((SelectionItemPattern)pat).Current.IsSelected;
|
package/lib/host-debug.js
CHANGED
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
// writes. Tools can read both; they cannot write either.
|
|
15
15
|
//
|
|
16
16
|
// SETTINGS PAGE CONTRACT (host side):
|
|
17
|
-
// GET /api/computer-use/host-debug
|
|
18
|
-
// POST /api/computer-use/host-debug
|
|
17
|
+
// GET /api/computer-use/host-debug?session=<id> returns { enabled, since, session, lastBlockedAt, ready }.
|
|
18
|
+
// POST /api/computer-use/host-debug?session=<id> accepts { enabled: boolean } and returns the same status.
|
|
19
|
+
// The query identifies the displayed conversation. A missing or unknown id reports fullAccess: false.
|
|
19
20
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
20
21
|
import path from 'node:path'
|
|
21
22
|
|
package/lib/index.js
CHANGED
|
@@ -450,7 +450,7 @@ function handleHostDebug (req, res, sctx) {
|
|
|
450
450
|
const rejection = connection && typeof connection.requestRejection === 'function' ? connection.requestRejection(req) : null
|
|
451
451
|
if (rejection) { send(403, { error: 'rejected by host', detail: String(rejection) }); return }
|
|
452
452
|
const url = new URL(req.url, 'http://127.0.0.1')
|
|
453
|
-
const sid = url.searchParams.get('session') ||
|
|
453
|
+
const sid = url.searchParams.get('session') || null
|
|
454
454
|
const status = () => {
|
|
455
455
|
const debug = readHostDebug()
|
|
456
456
|
const perm = sessionPermission(sid)
|
package/lib/tools.js
CHANGED
|
@@ -245,9 +245,9 @@ export function registerTools ({ ctx, cu, config, dataDir, log, snapshotPath, de
|
|
|
245
245
|
const targets = !!args.hwnd && (args.targets ?? !!(args.id || args.name))
|
|
246
246
|
const res = await cu.call('uia', { hwnd: args.hwnd, depth: args.depth ?? 6, maxNodes: args.maxNodes ?? 120,
|
|
247
247
|
budgetMs: args.budgetMs ?? 1200, anchor: args.anchor,
|
|
248
|
-
query: true, targets, role: args.role, nameContains: args.name, automationId: args.id, limit: args.limit ?? 80 })
|
|
248
|
+
query: true, targets, actions: args.actions === true, role: args.role, nameContains: args.name, automationId: args.id, limit: args.limit ?? 80 })
|
|
249
249
|
syncObservationEpoch()
|
|
250
|
-
return observations.publish(exec, 'uia', [args.hwnd ?? null, args.depth ?? 6, args.maxNodes ?? 120, args.budgetMs ?? 1200, args.anchor ?? null, args.role ?? null, args.name ?? null, args.id ?? null, args.limit ?? 80, targets],
|
|
250
|
+
return observations.publish(exec, 'uia', [args.hwnd ?? null, args.depth ?? 6, args.maxNodes ?? 120, args.budgetMs ?? 1200, args.anchor ?? null, args.role ?? null, args.name ?? null, args.id ?? null, args.limit ?? 80, targets, args.actions === true],
|
|
251
251
|
{ count: res.count, elements: res.flat || [], scanned: res.scanned, truncated: res.truncated, budget: res.budget, hwnd: res.hwnd ?? args.hwnd, pid: res.pid }, args.since)
|
|
252
252
|
}
|
|
253
253
|
const receiver = args => args.hwnd === undefined ? {} : { expectHwnd: checkedWindow(args.hwnd), strictHwnd: true }
|
|
@@ -263,8 +263,10 @@ export function registerTools ({ ctx, cu, config, dataDir, log, snapshotPath, de
|
|
|
263
263
|
throw Object.assign(new Error('TARGET_NOT_OBSERVED: obtain a fresh computer_uia target in this Agent before acting'), { code: 'TARGET_NOT_OBSERVED', outcome: 'not-dispatched' })
|
|
264
264
|
}
|
|
265
265
|
return cu.uiaAct({ hwnd: args.hwnd, nameContains: args.name, automationId: args.id, target: args.target, allowRebind: args.rebind === true,
|
|
266
|
-
role: args.role, action: args.action, value: args.value, prefix: args.prefix, suffix: args.suffix,
|
|
267
|
-
|
|
266
|
+
role: args.role, action: args.action, value: args.value, prefix: args.prefix, suffix: args.suffix,
|
|
267
|
+
selectionType: args.selectionType,
|
|
268
|
+
horizontalPercent: args.horizontalPercent, verticalPercent: args.verticalPercent,
|
|
269
|
+
requireUnique: true, depth: args.depth ?? 6, maxNodes: 300, anchor: args.anchor, budgetMs: args.budgetMs ?? 1200 })
|
|
268
270
|
}
|
|
269
271
|
const readMarks = async (args) => {
|
|
270
272
|
const res = await cu.landmarks({ hwnd: args.hwnd, refresh: args.refresh, uiaOnly: args.uiaOnly })
|
|
@@ -650,7 +652,7 @@ export function registerTools ({ ctx, cu, config, dataDir, log, snapshotPath, de
|
|
|
650
652
|
|
|
651
653
|
reg({
|
|
652
654
|
name: 'computer_uia',
|
|
653
|
-
description: "Query hwnd plus role/name/exact id; returns controls and patterns. Scoped name/id queries also return target handles. since gives fresh changes; omit for full. snapshot retrieves a retained full result. at hit-tests. truncated:true is partial evidence.",
|
|
655
|
+
description: "Query hwnd plus role/name/exact id; returns controls and patterns. Scoped name/id queries also return target handles. since gives fresh changes; omit for full. snapshot retrieves a retained full result. at hit-tests. truncated:true is partial evidence. actions:true adds, per control, the actions that control actually supports plus a one-line argument summary and live capability values (scroll axes, view ids, value range).",
|
|
654
656
|
parameters: {
|
|
655
657
|
focused: P('boolean', 'with hwnd only: read the focused field and selection'),
|
|
656
658
|
at: P('string', 'hit test at "x,y"'),
|
|
@@ -659,6 +661,7 @@ export function registerTools ({ ctx, cu, config, dataDir, log, snapshotPath, de
|
|
|
659
661
|
name: P('string', 'name substring'),
|
|
660
662
|
id: P('string', 'exact AutomationId from UIA'),
|
|
661
663
|
targets: P('boolean', 'recovery handles; default on for hwnd + name/id, off for broad queries'),
|
|
664
|
+
actions: P('boolean', 'per-control executable actions and their argument summary, derived from the patterns and states this control really reports (opt-in: costs several provider reads per element)'),
|
|
662
665
|
limit: P('number', 'maximum matches, 1–80 (default 80)'),
|
|
663
666
|
depth: P('number', 'tree depth, default 6; broader traversal needs anchor'),
|
|
664
667
|
anchor: P('string', 'observed "x,y" inside hwnd; search only this element subtree'),
|
|
@@ -676,16 +679,19 @@ export function registerTools ({ ctx, cu, config, dataDir, log, snapshotPath, de
|
|
|
676
679
|
|
|
677
680
|
reg({
|
|
678
681
|
name: 'computer_uia_act',
|
|
679
|
-
description: "Act through UIA. Prefer an observed target handle; rebind:true permits unique identity/semantic recovery inside the same window. Or use hwnd + exact id. Ambiguous, changed or incomplete evidence refuses; verify readback.",
|
|
682
|
+
description: "Act through UIA. Prefer an observed target handle; rebind:true permits unique identity/semantic recovery inside the same window. Or use hwnd + exact id. Ambiguous, changed or incomplete evidence refuses; verify readback. setScrollPercent takes horizontalPercent/verticalPercent (0-100, -1 keeps that axis); realize calls VirtualizedItemPattern and may invalidate the element; setCurrentView takes a viewId the control reports; selectText accepts selectionType select|cursor_before|cursor_after.",
|
|
680
683
|
parameters: {
|
|
681
684
|
hwnd: P('number', 'required window scope unless using an observed target'),
|
|
682
685
|
name: P('string', 'element name substring'),
|
|
683
686
|
id: P('string', 'exact AutomationId from UIA; scope with hwnd'),
|
|
684
687
|
role: P('string', 'TabItem | Button | ListItem | ComboBox | Edit | MenuItem'),
|
|
685
|
-
action: P('string', 'invoke | select | addToSelection | removeFromSelection | selectText | expand | collapse | toggle | setValue | focus | scrollIntoView | scroll (value: up/down/left/right)'),
|
|
686
|
-
value: P('string', 'setValue: text or slider number; selectText: exact text to select'),
|
|
688
|
+
action: P('string', 'invoke | select | addToSelection | removeFromSelection | selectText | expand | collapse | toggle | setValue | focus | scrollIntoView | scroll (value: up/down/left/right) | setScrollPercent | realize | setCurrentView'),
|
|
689
|
+
value: P('string', 'setValue: text or slider number; selectText: exact text to select; scroll: up/down/left/right; setCurrentView: viewId'),
|
|
687
690
|
prefix: P('string', 'selectText: immediately preceding context for repeated text'),
|
|
688
691
|
suffix: P('string', 'selectText: immediately following context for repeated text'),
|
|
692
|
+
selectionType: P('string', 'selectText only: select (default) | cursor_before | cursor_after — collapses the SAME range to its start or end'),
|
|
693
|
+
horizontalPercent: P('number', 'setScrollPercent: 0-100, or -1 to leave the horizontal axis unchanged'),
|
|
694
|
+
verticalPercent: P('number', 'setScrollPercent: 0-100, or -1 to leave the vertical axis unchanged'),
|
|
689
695
|
depth: P('number', 'tree depth, default 6; broader traversal needs anchor'),
|
|
690
696
|
anchor: P('string', 'observed "x,y" inside hwnd; narrow selector search'),
|
|
691
697
|
budgetMs: P('number', 'soft traversal budget 100–5000 ms (default 1200)'),
|
package/mcp/src/tools.js
CHANGED
|
@@ -51,7 +51,7 @@ const tools = [
|
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
53
|
name: 'cu_uia_query',
|
|
54
|
-
description: 'Bounded UIA query inside an explicit window. Default depth6/120 nodes/1200ms soft budget. Broad searches require an observed point anchor. Truncated results are partial evidence; a single provider call cannot be preempted.',
|
|
54
|
+
description: 'Bounded UIA query inside an explicit window. Default depth6/120 nodes/1200ms soft budget. Broad searches require an observed point anchor. Truncated results are partial evidence; a single provider call cannot be preempted. actions:true adds, per control, the actions that control actually supports with a one-line argument summary and live capability values (scroll axes, view ids, value range).',
|
|
55
55
|
inputSchema: {
|
|
56
56
|
type: 'object', additionalProperties: false,
|
|
57
57
|
properties: {
|
|
@@ -62,6 +62,7 @@ const tools = [
|
|
|
62
62
|
nameContains: { type: 'string' },
|
|
63
63
|
anchor: { type: 'string', description: 'Observed screen point "x,y" inside hwnd; query its subtree' },
|
|
64
64
|
budgetMs: { type: 'integer', minimum: 100, maximum: 5000 },
|
|
65
|
+
actions: { type: 'boolean', description: 'Per-control executable actions, derived from the patterns and states each control really reports; opt-in (costs several provider reads per element).' },
|
|
65
66
|
},
|
|
66
67
|
},
|
|
67
68
|
},
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-codex-style-computer-use",
|
|
3
|
-
"version": "2.3.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.3.5",
|
|
4
|
+
"description": "Windows desktop automation for DeepSeek Harness. Discover actions per control, scroll to an exact percentage, switch views, and place the caret before or after matching text. Includes OCR and a prebuilt Windows worker.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"bin": {
|
|
@@ -42,6 +42,11 @@ const reviewed = new Set([
|
|
|
42
42
|
'release-channel', 'renders', 'root-integration', 'session-identity', 'skill-gate', 'steer-message-shape',
|
|
43
43
|
'task-rules', 'terminal-cleanup', 'timeout-branch', 'turnend-agent', 'turnend-rootagent',
|
|
44
44
|
'ui-geometry', 'uia-budget', 'uia-read-timeout', 'uia-native', 'uia-targets-native', 'verification-region', 'window-management-key',
|
|
45
|
+
// UIA feature coverage (CUA-IMPL-1123). Each of these establishes its own isolation:
|
|
46
|
+
// uia-feature and uia-public-smoke call requirePrivateDesktop (private non-input desktop, verified
|
|
47
|
+
// child desktop, test-private STOP/EXITED/OWNER/AUDIT); uia-tool-contract drives only the
|
|
48
|
+
// registered tool bodies against a recording core and starts no worker or window.
|
|
49
|
+
'uia-feature', 'uia-public-smoke', 'uia-tool-contract',
|
|
45
50
|
'window-screenshot',
|
|
46
51
|
].map(name => `test-${name}.mjs`))
|
|
47
52
|
const files = fs.readdirSync(path.join(root, 'build')).filter(name => /^test-.+\.mjs$/.test(name)).sort()
|
|
@@ -70,6 +70,12 @@ Use `computer_window {hwnd, observe:true}` to activate a known window and read i
|
|
|
70
70
|
|
|
71
71
|
Use `computer_uia_act {target, action:"selectText", value}` to select an exact passage. Add immediately adjacent `prefix` or `suffix` if the passage occurs more than once. Check `selectionVerified`. On a slider, `setValue` accepts a numeric string and returns `rangeValue`. For list items, `addToSelection` and `removeFromSelection` preserve other selected items when supported.
|
|
72
72
|
|
|
73
|
+
Why a passage repeats: add `selectionType` to move the caret instead of selecting the whole match — `cursor_before` collapses the matched range to its start, `cursor_after` to its end. The default stays `select`. One request commits exactly one selection, and `selectionVerified` is only true when the control's own range matches the requested endpoints.
|
|
74
|
+
|
|
75
|
+
Discover what a control can actually do before acting: `computer_uia {hwnd, actions:true}` returns, per control, an `actions` list plus an `actionSchema` summary, both derived from the patterns AND the live state that control really reports — a password box never advertises `selectText`, a read-only field never advertises `setValue`, a disabled control advertises no mutation and no focus, a leaf node advertises neither `expand` nor `collapse`, `addToSelection` needs a multi-select container and an unselected item, `removeFromSelection` needs a selected item that is not the last one of a required selection, and a control with no scrollable axis never advertises `scroll`/`setScrollPercent`. It is opt-in because discovery costs several provider reads per element.
|
|
76
|
+
|
|
77
|
+
Position a scrollable control exactly: `computer_uia_act {target, action:"setScrollPercent", horizontalPercent, verticalPercent}` takes 0–100 per axis, and `-1` (or an omitted axis) leaves that axis untouched; an unavailable axis and an out-of-range value are refused by name before anything moves. `action:"setCurrentView", value:<viewId>` switches a MultipleView control using an id the control reports (see `actionSchema.views`), and `action:"realize"` materialises a virtualised item — after a successful Realize the element may be invalidated, so re-observe before acting on it again rather than replaying.
|
|
78
|
+
|
|
73
79
|
Use `computer_click {mark, ctrl:true}` for Ctrl-click. Click and key accept `durationMs` from 20 to 2000. `computer_key` accepts `Control_L`, `Shift_L`, `Alt_L` and numeric keypad digits such as `KP_9` and `Numpad_0`. Num Lock determines how an app interprets keypad digits.
|
|
74
80
|
|
|
75
81
|
## Screenshots and coordinates
|