dsh-codex-style-computer-use 2.3.2 → 2.3.4
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/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 +529 -18
- package/lib/tools.js +59 -21
- 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 +7 -1
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.4 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.4 · 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
|
|
|
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
|
@@ -4517,7 +4517,7 @@ namespace DshComputerUse.Worker
|
|
|
4517
4517
|
if (GetB(a, "clamp", true))
|
|
4518
4518
|
{
|
|
4519
4519
|
int x2 = Math.Max(x, vx), y2 = Math.Max(y, vy);
|
|
4520
|
-
int x3 = Math.Min(x + w, vx + vw), y3 = Math.Min(y + h, vy + vh);
|
|
4520
|
+
int x3 = (int)Math.Min((long)x + w, (long)vx + vw), y3 = (int)Math.Min((long)y + h, (long)vy + vh);
|
|
4521
4521
|
if (x3 <= x2 || y3 <= y2) throw new Exception("region outside virtual desktop");
|
|
4522
4522
|
x = x2; y = y2; w = x3 - x2; h = y3 - y2;
|
|
4523
4523
|
}
|
|
@@ -4549,7 +4549,7 @@ namespace DshComputerUse.Worker
|
|
|
4549
4549
|
if (mem != IntPtr.Zero) Native.DeleteDC(mem);
|
|
4550
4550
|
if (screen != IntPtr.Zero) Native.ReleaseDC(IntPtr.Zero, screen);
|
|
4551
4551
|
}
|
|
4552
|
-
return RecognizePixels(bgra, x, y, w, h);
|
|
4552
|
+
return RecognizePixels(bgra, x, y, w, h, GetI(a, "scale", 0));
|
|
4553
4553
|
}
|
|
4554
4554
|
|
|
4555
4555
|
static Dictionary<string, object> WindowOcr(Dictionary<string, object> args, IntPtr window)
|
|
@@ -4561,8 +4561,13 @@ namespace DshComputerUse.Worker
|
|
|
4561
4561
|
RECT r = frames.Bounds;
|
|
4562
4562
|
int x = GetI(args, "x", r.Left), y = GetI(args, "y", r.Top);
|
|
4563
4563
|
int w = GetI(args, "width", r.Right - r.Left), h = GetI(args, "height", r.Bottom - r.Top);
|
|
4564
|
-
|
|
4565
|
-
|
|
4564
|
+
int[] requested = { x, y, w, h };
|
|
4565
|
+
int left = Math.Max(x, r.Left), top = Math.Max(y, r.Top);
|
|
4566
|
+
long right = Math.Min((long)x + w, r.Right), bottom = Math.Min((long)y + h, r.Bottom);
|
|
4567
|
+
if (w <= 0 || h <= 0 || right <= left || bottom <= top)
|
|
4568
|
+
throw new Exception("OCR region outside window surface " + String.Join(",", new int[] { r.Left, r.Top, r.Right-r.Left, r.Bottom-r.Top }));
|
|
4569
|
+
x = left; y = top; w = (int)(right-left); h = (int)(bottom-top);
|
|
4570
|
+
if ((long)w*h > 16L*1024*1024) throw new Exception("OCR region exceeds 16M pixels; crop tighter");
|
|
4566
4571
|
frames.Sample();
|
|
4567
4572
|
byte[] pixels = frames.Pixels;
|
|
4568
4573
|
if (x != r.Left || y != r.Top || w != r.Right-r.Left || h != r.Bottom-r.Top) {
|
|
@@ -4570,19 +4575,48 @@ namespace DshComputerUse.Worker
|
|
|
4570
4575
|
for (int i = 0; i < h; i++) Buffer.BlockCopy(frames.Pixels,
|
|
4571
4576
|
((y-r.Top+i)*(r.Right-r.Left)+x-r.Left)*4, pixels, i*w*4, w*4);
|
|
4572
4577
|
}
|
|
4573
|
-
var result = RecognizePixels(pixels, x, y, w, h);
|
|
4578
|
+
var result = RecognizePixels(pixels, x, y, w, h, GetI(args, "scale", 0));
|
|
4574
4579
|
ValidateCaptureTarget(args, window);
|
|
4575
4580
|
if (ScreenshotGeometry(window, out bounds) != geometry) throw new Exception("OCR_TARGET_CHANGED: observe this window again");
|
|
4581
|
+
if (requested[0] != x || requested[1] != y || requested[2] != w || requested[3] != h)
|
|
4582
|
+
result["requestedRegion"] = requested;
|
|
4576
4583
|
result["hwnd"] = window.ToInt64(); result["captureBackend"] = "windows-graphics-capture";
|
|
4577
4584
|
return result;
|
|
4578
4585
|
}
|
|
4579
4586
|
}
|
|
4580
4587
|
|
|
4581
|
-
static
|
|
4588
|
+
static byte[] EnlargeOcrPixels(byte[] pixels, int width, int height)
|
|
4582
4589
|
{
|
|
4590
|
+
// Preserve GDI screen captures whose unused alpha byte may be zero.
|
|
4591
|
+
var pin = GCHandle.Alloc(pixels, GCHandleType.Pinned);
|
|
4592
|
+
try {
|
|
4593
|
+
using (var source = new Bitmap(width, height, width*4, PixelFormat.Format32bppRgb, pin.AddrOfPinnedObject()))
|
|
4594
|
+
using (var target = new Bitmap(width*2, height*2, PixelFormat.Format32bppArgb)) {
|
|
4595
|
+
using (var g = Graphics.FromImage(target)) {
|
|
4596
|
+
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
4597
|
+
g.PixelOffsetMode = PixelOffsetMode.Half;
|
|
4598
|
+
g.DrawImage(source, new Rectangle(0, 0, target.Width, target.Height));
|
|
4599
|
+
}
|
|
4600
|
+
var bits = target.LockBits(new Rectangle(0, 0, target.Width, target.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
|
4601
|
+
try {
|
|
4602
|
+
byte[] data = new byte[target.Width*target.Height*4];
|
|
4603
|
+
Marshal.Copy(bits.Scan0, data, 0, data.Length);
|
|
4604
|
+
return data;
|
|
4605
|
+
} finally { target.UnlockBits(bits); }
|
|
4606
|
+
}
|
|
4607
|
+
} finally { pin.Free(); }
|
|
4608
|
+
}
|
|
4609
|
+
|
|
4610
|
+
static Dictionary<string, object> RecognizePixels(byte[] bgra, int x, int y, int w, int h, int requestedScale)
|
|
4611
|
+
{
|
|
4612
|
+
bool fits = (long)w*h <= 1024*1024 && Math.Max(w,h)*2L <= OcrEngine.MaxImageDimension;
|
|
4613
|
+
if (requestedScale < 0 || requestedScale > 2 || (requestedScale == 2 && !fits))
|
|
4614
|
+
throw new Exception("OCR scale 2 requires a crop within 1M pixels and the Windows OCR dimension limit");
|
|
4615
|
+
int scale = requestedScale == 0 ? (fits ? 2 : 1) : requestedScale;
|
|
4616
|
+
if (scale == 2) bgra = EnlargeOcrPixels(bgra, w, h);
|
|
4583
4617
|
OcrResult result;
|
|
4584
4618
|
using (SoftwareBitmap bitmap = SoftwareBitmap.CreateCopyFromBuffer(
|
|
4585
|
-
WindowsRuntimeBufferExtensions.AsBuffer(bgra), BitmapPixelFormat.Bgra8, w, h))
|
|
4619
|
+
WindowsRuntimeBufferExtensions.AsBuffer(bgra), BitmapPixelFormat.Bgra8, w*scale, h*scale))
|
|
4586
4620
|
result = _ocrEngine.RecognizeAsync(bitmap).AsTask().GetAwaiter().GetResult();
|
|
4587
4621
|
List<object> lines = new List<object>();
|
|
4588
4622
|
StringBuilder joined = new StringBuilder();
|
|
@@ -4591,15 +4625,17 @@ namespace DshComputerUse.Worker
|
|
|
4591
4625
|
List<object> words = new List<object>();
|
|
4592
4626
|
foreach (OcrWord word in line.Words)
|
|
4593
4627
|
{
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4628
|
+
var box = word.BoundingRect;
|
|
4629
|
+
int left = (int)(box.X/scale), top = (int)(box.Y/scale);
|
|
4630
|
+
words.Add(Dict("text", word.Text, "x", x+left, "y", y+top,
|
|
4631
|
+
"w", (int)Math.Ceiling((box.X+box.Width)/scale)-left,
|
|
4632
|
+
"h", (int)Math.Ceiling((box.Y+box.Height)/scale)-top));
|
|
4597
4633
|
}
|
|
4598
4634
|
lines.Add(Dict("text", line.Text, "words", words));
|
|
4599
4635
|
if (joined.Length > 0) joined.Append('\n');
|
|
4600
4636
|
joined.Append(line.Text);
|
|
4601
4637
|
}
|
|
4602
|
-
return Dict("lines", lines, "text", joined.ToString(), "language", _ocrLanguage,
|
|
4638
|
+
return Dict("lines", lines, "text", joined.ToString(), "language", _ocrLanguage, "scale", scale,
|
|
4603
4639
|
"region", new int[] { x, y, w, h });
|
|
4604
4640
|
}
|
|
4605
4641
|
|
|
@@ -4839,7 +4875,7 @@ namespace DshComputerUse.Worker
|
|
|
4839
4875
|
if (shotWindow == IntPtr.Zero && GetB(a, "clamp", true))
|
|
4840
4876
|
{
|
|
4841
4877
|
int x2 = Math.Max(x, vx), y2 = Math.Max(y, vy);
|
|
4842
|
-
int x3 = Math.Min(x + w, vx + vw), y3 = Math.Min(y + h, vy + vh);
|
|
4878
|
+
int x3 = (int)Math.Min((long)x + w, (long)vx + vw), y3 = (int)Math.Min((long)y + h, (long)vy + vh);
|
|
4843
4879
|
if (x3 <= x2 || y3 <= y2) throw new Exception("region outside virtual desktop");
|
|
4844
4880
|
x = x2; y = y2; w = x3 - x2; h = y3 - y2;
|
|
4845
4881
|
}
|
|
@@ -8264,6 +8300,293 @@ namespace DshComputerUse.Worker
|
|
|
8264
8300
|
return d;
|
|
8265
8301
|
}
|
|
8266
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
|
+
|
|
8267
8590
|
// >>>UIA-QUERY-BUDGET<<<
|
|
8268
8591
|
// Cooperative limits between provider calls. A synchronous UIA/COM call
|
|
8269
8592
|
// already in progress is NOT interruptible by this traversal budget.
|
|
@@ -8479,11 +8802,20 @@ namespace DshComputerUse.Worker
|
|
|
8479
8802
|
catch (UiBudgetStop) { evidenceRoot = null; }
|
|
8480
8803
|
}
|
|
8481
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);
|
|
8482
8808
|
CacheRequest selectorCache = UiSelectorCache();
|
|
8483
8809
|
UiWalkBounded(rootEl, maxDepth, maxNodes, Math.Max(1, Math.Min(80, GetI(a, "limit", 80))), budget,
|
|
8484
8810
|
delegate(AutomationElement match) {
|
|
8485
8811
|
if (!ElementMatchesBudgeted(match, nameFilter, idFilter, roleFilter, budget)) return false;
|
|
8486
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
|
+
}
|
|
8487
8819
|
if (witness != null) {
|
|
8488
8820
|
try {
|
|
8489
8821
|
if (evidenceRoot == null) throw new UiBudgetStop();
|
|
@@ -8696,6 +9028,43 @@ namespace DshComputerUse.Worker
|
|
|
8696
9028
|
return matches;
|
|
8697
9029
|
}
|
|
8698
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>
|
|
8699
9068
|
static TextPatternRange SelectExactText(TextPattern pattern, string value, string prefix, string suffix)
|
|
8700
9069
|
{
|
|
8701
9070
|
if (String.IsNullOrEmpty(value)) throw new Exception("selectText requires nonempty text in value");
|
|
@@ -8715,8 +9084,6 @@ namespace DshComputerUse.Worker
|
|
|
8715
9084
|
if (suffix.Length > 0)
|
|
8716
9085
|
match.MoveEndpointByRange(TextPatternRangeEndpoint.End, match.FindText(suffix, true, false), TextPatternRangeEndpoint.Start);
|
|
8717
9086
|
if (match.GetText(value.Length + 1) != value) throw new Exception("TEXT_CHANGED: query the passage again");
|
|
8718
|
-
MarkMutation();
|
|
8719
|
-
match.Select();
|
|
8720
9087
|
return match;
|
|
8721
9088
|
}
|
|
8722
9089
|
|
|
@@ -8779,6 +9146,9 @@ namespace DshComputerUse.Worker
|
|
|
8779
9146
|
object pat = null;
|
|
8780
9147
|
string via = null;
|
|
8781
9148
|
TextPatternRange selectedRange = null;
|
|
9149
|
+
string selectedType = "select";
|
|
9150
|
+
bool beforeHorizontalEnabled = false, beforeVerticalEnabled = false;
|
|
9151
|
+
object beforeViewId = null;
|
|
8782
9152
|
double beforeScrollPercent = 0;
|
|
8783
9153
|
switch (action)
|
|
8784
9154
|
{
|
|
@@ -8800,7 +9170,23 @@ namespace DshComputerUse.Worker
|
|
|
8800
9170
|
case "selectText":
|
|
8801
9171
|
if (found.Current.IsPassword) throw new Exception("selectText is unavailable on password controls");
|
|
8802
9172
|
if (found.TryGetCurrentPattern(TextPattern.Pattern, out pat)) {
|
|
8803
|
-
|
|
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;
|
|
8804
9190
|
via = "TextPattern.Select";
|
|
8805
9191
|
}
|
|
8806
9192
|
break;
|
|
@@ -8828,6 +9214,72 @@ namespace DshComputerUse.Worker
|
|
|
8828
9214
|
}
|
|
8829
9215
|
break;
|
|
8830
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
|
+
}
|
|
8831
9283
|
case "focus":
|
|
8832
9284
|
MarkMutation(); found.SetFocus(); via = "SetFocus"; break;
|
|
8833
9285
|
case "scrollIntoView":
|
|
@@ -8848,23 +9300,82 @@ namespace DshComputerUse.Worker
|
|
|
8848
9300
|
}
|
|
8849
9301
|
break;
|
|
8850
9302
|
default:
|
|
8851
|
-
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");
|
|
8852
9304
|
}
|
|
8853
9305
|
EndActuationForReadback();
|
|
8854
9306
|
if (via == null)
|
|
8855
9307
|
throw new Exception("element does not support '" + action + "': " + ElemDict(found)["name"]);
|
|
8856
9308
|
|
|
8857
9309
|
Thread.Sleep(GetI(a, "settleMs", 120));
|
|
8858
|
-
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
|
+
}
|
|
8859
9322
|
try {
|
|
8860
9323
|
if (via == "ScrollPattern") {
|
|
8861
9324
|
var scroll = ((ScrollPattern)pat).Current;
|
|
8862
9325
|
string direction = GetS(a, "value", "");
|
|
8863
9326
|
res["beforePercent"] = beforeScrollPercent;
|
|
8864
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).
|
|
8865
9348
|
} else if (selectedRange != null) {
|
|
8866
9349
|
var selected = ((TextPattern)pat).GetSelection();
|
|
8867
|
-
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;
|
|
8868
9379
|
} else if (via == "RangeValuePattern") res["rangeValue"] = ((RangeValuePattern)pat).Current.Value;
|
|
8869
9380
|
else if (action == "addToSelection" || action == "removeFromSelection")
|
|
8870
9381
|
res["isSelected"] = ((SelectionItemPattern)pat).Current.IsSelected;
|
package/lib/tools.js
CHANGED
|
@@ -70,6 +70,43 @@ const rect = (v) => {
|
|
|
70
70
|
return null
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
// Keep the recognizer's own text within each fragment (including RTL and CJK).
|
|
74
|
+
// Render separately located fragments together when they share a visual baseline.
|
|
75
|
+
function renderOcr(value) {
|
|
76
|
+
if (!value?.lines) return 'no text'
|
|
77
|
+
const head = `ocr ${value.language}${value.hwnd ? ' hwnd=' + value.hwnd : ''} region=${value.region || ''}${value.requestedRegion ? ' clippedFrom=' + value.requestedRegion : ''} scale=${value.scale || 1} @center(x,y)`
|
|
78
|
+
const parts = [], unplaced = []
|
|
79
|
+
for (const line of value.lines) {
|
|
80
|
+
const words = line.words || []
|
|
81
|
+
if (!words.length) { unplaced.push(line.text); continue }
|
|
82
|
+
let group = []
|
|
83
|
+
function flush() {
|
|
84
|
+
const left = Math.min(...group.map(w => w.x)), right = Math.max(...group.map(w => w.x + w.w))
|
|
85
|
+
const top = Math.min(...group.map(w => w.y)), bottom = Math.max(...group.map(w => w.y + w.h))
|
|
86
|
+
parts.push({ x: Math.floor((left+right)/2), y: Math.floor((top+bottom)/2), h: bottom-top,
|
|
87
|
+
text: group.length === words.length ? line.text : group.map(w => w.text).join(' ') })
|
|
88
|
+
group = []
|
|
89
|
+
}
|
|
90
|
+
for (const w of words) {
|
|
91
|
+
const prev = group.at(-1)
|
|
92
|
+
if (prev && Math.max(w.x-prev.x-prev.w, prev.x-w.x-w.w) > 2*Math.max(w.h,prev.h)) flush()
|
|
93
|
+
group.push(w)
|
|
94
|
+
}
|
|
95
|
+
flush()
|
|
96
|
+
}
|
|
97
|
+
const rows = []
|
|
98
|
+
for (const p of parts.sort((a,b) => a.y-b.y || a.x-b.x)) {
|
|
99
|
+
let row = rows.at(-1)
|
|
100
|
+
if (!row || p.y-row.y > Math.max(2, Math.min(row.h,p.h)*0.45)) {
|
|
101
|
+
row = { y:p.y, h:p.h, parts:[] }
|
|
102
|
+
rows.push(row)
|
|
103
|
+
}
|
|
104
|
+
row.parts.push(p)
|
|
105
|
+
}
|
|
106
|
+
const body = rows.map(row => row.parts.sort((a,b) => a.x-b.x).map(p => `@${p.x},${p.y} ${p.text}`).join(' | '))
|
|
107
|
+
return [head, ...body, ...unplaced].join('\n')
|
|
108
|
+
}
|
|
109
|
+
|
|
73
110
|
export function registerTools ({ ctx, cu, config, dataDir, log, snapshotPath, defineTool, hooks, ensureCycle, register }) {
|
|
74
111
|
const observations = new ObservationStore({ archiveDir: typeof dataDir?.root === 'string' ? join(dataDir.root, 'observation-cache') : undefined })
|
|
75
112
|
let observationEpoch
|
|
@@ -208,9 +245,9 @@ export function registerTools ({ ctx, cu, config, dataDir, log, snapshotPath, de
|
|
|
208
245
|
const targets = !!args.hwnd && (args.targets ?? !!(args.id || args.name))
|
|
209
246
|
const res = await cu.call('uia', { hwnd: args.hwnd, depth: args.depth ?? 6, maxNodes: args.maxNodes ?? 120,
|
|
210
247
|
budgetMs: args.budgetMs ?? 1200, anchor: args.anchor,
|
|
211
|
-
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 })
|
|
212
249
|
syncObservationEpoch()
|
|
213
|
-
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],
|
|
214
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)
|
|
215
252
|
}
|
|
216
253
|
const receiver = args => args.hwnd === undefined ? {} : { expectHwnd: checkedWindow(args.hwnd), strictHwnd: true }
|
|
@@ -226,8 +263,10 @@ export function registerTools ({ ctx, cu, config, dataDir, log, snapshotPath, de
|
|
|
226
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' })
|
|
227
264
|
}
|
|
228
265
|
return cu.uiaAct({ hwnd: args.hwnd, nameContains: args.name, automationId: args.id, target: args.target, allowRebind: args.rebind === true,
|
|
229
|
-
role: args.role, action: args.action, value: args.value, prefix: args.prefix, suffix: args.suffix,
|
|
230
|
-
|
|
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 })
|
|
231
270
|
}
|
|
232
271
|
const readMarks = async (args) => {
|
|
233
272
|
const res = await cu.landmarks({ hwnd: args.hwnd, refresh: args.refresh, uiaOnly: args.uiaOnly })
|
|
@@ -263,9 +302,11 @@ export function registerTools ({ ctx, cu, config, dataDir, log, snapshotPath, de
|
|
|
263
302
|
const readOcr = async args => {
|
|
264
303
|
const hwnd = checkedWindow(args.hwnd)
|
|
265
304
|
if (args.region !== undefined && String(args.region).trim().split(/[,\s]+/).length !== 4) throw Error('region must be "x,y,w,h"')
|
|
266
|
-
const region = args.region === undefined ? undefined : rect(args.region)
|
|
305
|
+
const region = args.region === undefined ? undefined : rect(String(args.region).trim())
|
|
267
306
|
if (args.region !== undefined && (!region || region.width <= 0 || region.height <= 0)) throw Error('region must be "x,y,w,h"')
|
|
268
|
-
|
|
307
|
+
if (region && Object.values(region).some(n => !Number.isInteger(n) || n < -2147483648 || n > 2147483647)) throw Error('OCR region requires 32-bit integer screen coordinates and sizes')
|
|
308
|
+
if (args.scale !== undefined && ![1, 2].includes(args.scale)) throw Error('OCR scale must be 1 or 2')
|
|
309
|
+
return cu.ocr({ ...region, ...(hwnd ? { hwnd } : {}), ...(args.scale ? { scale: args.scale } : {}) })
|
|
269
310
|
}
|
|
270
311
|
const observeState = async (args, exec) => {
|
|
271
312
|
if (args.appQuery !== undefined) {
|
|
@@ -559,20 +600,13 @@ export function registerTools ({ ctx, cu, config, dataDir, log, snapshotPath, de
|
|
|
559
600
|
|
|
560
601
|
reg({
|
|
561
602
|
name: 'computer_ocr',
|
|
562
|
-
description: "Read
|
|
603
|
+
description: "Read text as spatial rows with absolute screen centers. Start with hwnd alone; use a targeted crop only for ambiguous text. Partially overlapping window crops are clipped to its captured surface. No images.",
|
|
563
604
|
parameters: {
|
|
564
605
|
hwnd: windowParam,
|
|
565
|
-
region: P('string', '
|
|
606
|
+
region: P('string', 'absolute x,y,w,h (default: target window or desktop)'),
|
|
607
|
+
scale: P('number', 'optional OCR magnification: 1 or 2; default doubles small regions'),
|
|
566
608
|
},
|
|
567
|
-
output: out((
|
|
568
|
-
if (!v || !v.lines) return [{ type: 'text', text: 'no text' }]
|
|
569
|
-
const head = `ocr ${v.language}${v.hwnd ? ' hwnd=' + v.hwnd : ''} region=${v.region ? v.region.join(',') : ''} lines=${v.lines.length}`
|
|
570
|
-
const body = v.lines.map(l => {
|
|
571
|
-
const w0 = l.words[0]
|
|
572
|
-
return `${w0 ? `@${w0.x},${w0.y} ` : ''}${l.text}`
|
|
573
|
-
}).join('\n')
|
|
574
|
-
return [{ type: 'text', text: head + '\n' + body }]
|
|
575
|
-
}),
|
|
609
|
+
output: out((_args, value) => [{ type: 'text', text: renderOcr(value) }]),
|
|
576
610
|
isConcurrencySafe: () => false,
|
|
577
611
|
timeoutMs: 30_000,
|
|
578
612
|
execute: readOcr,
|
|
@@ -618,7 +652,7 @@ export function registerTools ({ ctx, cu, config, dataDir, log, snapshotPath, de
|
|
|
618
652
|
|
|
619
653
|
reg({
|
|
620
654
|
name: 'computer_uia',
|
|
621
|
-
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).",
|
|
622
656
|
parameters: {
|
|
623
657
|
focused: P('boolean', 'with hwnd only: read the focused field and selection'),
|
|
624
658
|
at: P('string', 'hit test at "x,y"'),
|
|
@@ -627,6 +661,7 @@ export function registerTools ({ ctx, cu, config, dataDir, log, snapshotPath, de
|
|
|
627
661
|
name: P('string', 'name substring'),
|
|
628
662
|
id: P('string', 'exact AutomationId from UIA'),
|
|
629
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)'),
|
|
630
665
|
limit: P('number', 'maximum matches, 1–80 (default 80)'),
|
|
631
666
|
depth: P('number', 'tree depth, default 6; broader traversal needs anchor'),
|
|
632
667
|
anchor: P('string', 'observed "x,y" inside hwnd; search only this element subtree'),
|
|
@@ -644,16 +679,19 @@ export function registerTools ({ ctx, cu, config, dataDir, log, snapshotPath, de
|
|
|
644
679
|
|
|
645
680
|
reg({
|
|
646
681
|
name: 'computer_uia_act',
|
|
647
|
-
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.",
|
|
648
683
|
parameters: {
|
|
649
684
|
hwnd: P('number', 'required window scope unless using an observed target'),
|
|
650
685
|
name: P('string', 'element name substring'),
|
|
651
686
|
id: P('string', 'exact AutomationId from UIA; scope with hwnd'),
|
|
652
687
|
role: P('string', 'TabItem | Button | ListItem | ComboBox | Edit | MenuItem'),
|
|
653
|
-
action: P('string', 'invoke | select | addToSelection | removeFromSelection | selectText | expand | collapse | toggle | setValue | focus | scrollIntoView | scroll (value: up/down/left/right)'),
|
|
654
|
-
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'),
|
|
655
690
|
prefix: P('string', 'selectText: immediately preceding context for repeated text'),
|
|
656
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'),
|
|
657
695
|
depth: P('number', 'tree depth, default 6; broader traversal needs anchor'),
|
|
658
696
|
anchor: P('string', 'observed "x,y" inside hwnd; narrow selector search'),
|
|
659
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.4",
|
|
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()
|
|
@@ -42,7 +42,7 @@ The plugin also has a deterministic backstop: after a non-desktop top-level tool
|
|
|
42
42
|
|
|
43
43
|
On a multi-display desktop, keep the task in its existing work window. Inspect `computer_state {hwnd}` for the work area, owned popups and nine sampled pixel receivers. If a required popup opens on another screen, identify its owner and use `computer_window {op:"move", hwnd:popup, workHwnd:parent}`. Check `contained:true`, then activate the popup and observe it again. The same call leaves an already contained window in place. For a covered window, query its controls by hwnd. Pixel samples describe only the sampled positions.
|
|
44
44
|
|
|
45
|
-
For a screenshot-bound click, the worker rechecks a known accessible control or the local pixels before pressing. On STALE_SCREENSHOT, observe again and select the current target. Window OCR accepts `hwnd`
|
|
45
|
+
For a screenshot-bound click, the worker rechecks a known accessible control or the local pixels before pressing. On STALE_SCREENSHOT, observe again and select the current target. Window OCR accepts `hwnd` alone or an absolute screen crop. A partially overlapping crop returns the intersection and identifies the requested region. Read the spatial rows and their absolute centers first. For ambiguous text, crop the relevant area or change `scale` between 1 and 2. Window-scoped pixel waits and OCR read the same surface as the screenshot, including behind other windows. For a targeted action, automatic feedback follows its window and active owned popup. Inspect the returned title and controls before choosing the next action.
|
|
46
46
|
|
|
47
47
|
On Windows, `computer_shot {hwnd}` reads the selected window surface even under an opaque window. A background capture can be inspected. For input, bring the intended window forward and take a fresh shot with a screenshotId. Minimized or unavailable surfaces can return a capture error. Default screenshots wait for the observed area to go quiet. Repeated static views return sooner. If `settled:false` is returned, observe again before acting.
|
|
48
48
|
|
|
@@ -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
|