@copylee/dsh-computer-use 0.1.6 → 0.1.8
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 +4 -3
- package/helper/CuHelper.cs +265 -22
- package/lib/client.js +10 -4
- package/lib/index.js +74 -53
- package/lib/types/access.d.ts +7 -0
- package/lib/types/computer.d.ts +12 -1
- package/lib/types/overlay.d.ts +0 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,15 +7,16 @@
|
|
|
7
7
|
| 功能 | 说明 |
|
|
8
8
|
|---|---|
|
|
9
9
|
| 截图即坐标系 | 模型只用最近一张截图的像素坐标,DPI、缩放、多显示器偏移全部由插件换算,高分屏(200% 缩放)也点得准 |
|
|
10
|
-
| 动作后自动回传截图 | 点击 / 输入 / 按键 / 滚动后,**等画面不再变化**(页面加载、动画结束,最多约 2.5 秒)再截图;`wait`
|
|
10
|
+
| 动作后自动回传截图 | 点击 / 输入 / 按键 / 滚动后,**等画面不再变化**(页面加载、动画结束,最多约 2.5 秒)再截图;`wait` 也直接带回截图,“等一下再看”只需一步;画面与上一张截图完全相同时不再发图,只告诉模型“没有可见变化”,省 token |
|
|
11
11
|
| 批量动作 | `computer_batch` 一次执行“点输入框 → 输入 → 回车”等多步,最后只截一张图 |
|
|
12
12
|
| 按应用授权 | 先 `request_access` 列出要操控的应用,经 DSH 原生审批后才能操作;也可改为“全部允许” |
|
|
13
13
|
| 不会操作自己 | 永远拒绝向 DeepSeek Harness 自身窗口输入;常见密码管理器默认禁止,可再自定义禁用列表 |
|
|
14
14
|
| 正在控制的提示 | 橙色光晕 + 胶囊提示条(显示当前动作),**不会出现在截图里** |
|
|
15
|
-
| 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 /
|
|
15
|
+
| 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 / 最小化状态(也可选最小化或不动)。卡片只给你看:AI 的截图里看到的是卡片下面的内容(截图那一瞬间卡片会透明几十毫秒),点击和滚动也直接穿透卡片,卡片不会挪位置 |
|
|
16
16
|
| 暂停与停止 | 你亲手按 **Esc** 暂停(AI 停在下一步之前),再按 Esc 或点“继续”恢复,对话不会被中断;点“停止”才结束本轮。插件自己发出的 Esc 不会误触发 |
|
|
17
17
|
| 你随时可以插手 | 你用键盘打字时 AI 自动暂停,停手 1.5 秒后继续(单按 Shift / Ctrl 等修饰键不算);你切换或打开了别的窗口,AI 下一步不会盲目执行,而是先看新截图再决定。你只是点进 DSH 卡片看对话时不算切换,AI 的按键会自动回到它正在操作的窗口。鼠标移动不会触发,避免误触 |
|
|
18
|
-
| 中文输入 | Unicode
|
|
18
|
+
| 中文输入 | Unicode 直接输入,不受输入法状态影响;长文本走剪贴板粘贴,剪贴板文本统一为 CRLF,粘贴到 Obsidian 等应用不丢换行 |
|
|
19
|
+
| 不弄乱剪贴板 | 插件写入剪贴板的内容不进 Windows 剪贴板历史(Win+V)和云剪贴板;粘贴后按原样恢复你的剪贴板(图片、文件也保留);AI 用 `clipboard` 工具写过剪贴板的,本轮结束后自动还原(期间你自己复制了新内容则不动) |
|
|
19
20
|
| 打开应用 | `open_application` 同时搜索开始菜单和桌面快捷方式(含公共桌面),便携软件也能按名字打开 |
|
|
20
21
|
| 看不见图的模型 | `ui_elements` 用 Windows UI Automation 列出可点击元素和坐标,纯文本模型也能用 |
|
|
21
22
|
| 零原生依赖 | 首次使用时用 Windows 自带的 .NET Framework `csc.exe` 编译一个小 helper(约 1 秒,之后缓存),不需要 node-gyp、不受 Electron ABI 影响 |
|
package/helper/CuHelper.cs
CHANGED
|
@@ -79,6 +79,8 @@ namespace DshComputerUse
|
|
|
79
79
|
[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern int GetClassName(IntPtr hwnd, StringBuilder sb, int max);
|
|
80
80
|
[DllImport("user32.dll")] public static extern IntPtr GetWindow(IntPtr hwnd, uint cmd);
|
|
81
81
|
[DllImport("user32.dll")] public static extern int GetWindowLong(IntPtr hwnd, int index);
|
|
82
|
+
[DllImport("user32.dll")] public static extern int SetWindowLong(IntPtr hwnd, int index, int value);
|
|
83
|
+
[DllImport("user32.dll")] public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint key, byte alpha, uint flags);
|
|
82
84
|
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint pid);
|
|
83
85
|
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
|
|
84
86
|
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hwnd);
|
|
@@ -251,12 +253,14 @@ namespace DshComputerUse
|
|
|
251
253
|
case "displays": return Screen2.Displays();
|
|
252
254
|
case "screenshot": return Screen2.Capture(r);
|
|
253
255
|
case "settle": return Screen2.Settle(r);
|
|
256
|
+
case "shot_mark": Screen2.Mark(r); return null;
|
|
257
|
+
case "shot_diff": return Screen2.Diff(r);
|
|
254
258
|
case "cursor": { Native.POINT p; Native.GetCursorPos(out p); return Pt(p.X, p.Y); }
|
|
255
|
-
case "move": Overlay.Dodge(Args.Int(r, "x", 0), Args.Int(r, "y", 0)); Input.Move(Args.Int(r, "x", 0), Args.Int(r, "y", 0)); return null;
|
|
256
|
-
case "click": return Input.Click(r);
|
|
257
|
-
case "button": return Input.Button(r);
|
|
258
|
-
case "drag": return Input.Drag(r);
|
|
259
|
-
case "scroll": return Input.Scroll(r);
|
|
259
|
+
case "move": using (new PassThrough()) { Overlay.Dodge(Args.Int(r, "x", 0), Args.Int(r, "y", 0)); Input.Move(Args.Int(r, "x", 0), Args.Int(r, "y", 0)); } return null;
|
|
260
|
+
case "click": using (new PassThrough()) return Input.Click(r);
|
|
261
|
+
case "button": using (new PassThrough()) return Input.Button(r);
|
|
262
|
+
case "drag": using (new PassThrough()) return Input.Drag(r);
|
|
263
|
+
case "scroll": using (new PassThrough()) return Input.Scroll(r);
|
|
260
264
|
case "keys": return Input.Keys(r);
|
|
261
265
|
case "key_state": return Input.KeyState(r);
|
|
262
266
|
case "type": return Input.Type(Args.Str(r, "text", ""), Args.Int(r, "chunkDelay", 8));
|
|
@@ -269,7 +273,8 @@ namespace DshComputerUse
|
|
|
269
273
|
case "apps": return Apps.Search(Args.Str(r, "query", ""), Args.Int(r, "limit", 8));
|
|
270
274
|
case "launch": return Apps.Launch(r);
|
|
271
275
|
case "clipboard_get": { var d = new Dictionary<string, object>(); d["text"] = Clip.Get(); return d; }
|
|
272
|
-
case "clipboard_set": Clip.Set(Args.Str(r, "text", "")); return null;
|
|
276
|
+
case "clipboard_set": if (Args.Bool(r, "agent", false)) Clip.AgentSet(Args.Str(r, "text", "")); else Clip.Set(Args.Str(r, "text", ""), false); return null;
|
|
277
|
+
case "clipboard_restore": { var d = new Dictionary<string, object>(); d["restored"] = Clip.RestoreAgent(); return d; }
|
|
273
278
|
case "ui": return Uia.Elements(r);
|
|
274
279
|
case "overlay_show": Overlay.ExcludeFromCapture = Args.Bool(r, "excludeFromCapture", true); Overlay.Show(r); return null;
|
|
275
280
|
case "overlay_pause": Overlay.SetPaused(Args.Bool(r, "paused", false)); return null;
|
|
@@ -313,7 +318,12 @@ namespace DshComputerUse
|
|
|
313
318
|
}
|
|
314
319
|
|
|
315
320
|
/** Sample every 8th pixel of a screen rectangle (BGR bytes). */
|
|
316
|
-
|
|
321
|
+
/**
|
|
322
|
+
* composite: paint what is under the DSH card (exact, slower: used once
|
|
323
|
+
* per action). Otherwise the card area is blanked so its own updates
|
|
324
|
+
* (streaming text, timers) never look like screen activity.
|
|
325
|
+
*/
|
|
326
|
+
static byte[] Sample(int x, int y, int w, int h, bool composite)
|
|
317
327
|
{
|
|
318
328
|
using (var bmp = new Bitmap(w, h, PixelFormat.Format24bppRgb))
|
|
319
329
|
{
|
|
@@ -321,8 +331,12 @@ namespace DshComputerUse
|
|
|
321
331
|
{
|
|
322
332
|
IntPtr dst = g.GetHdc();
|
|
323
333
|
IntPtr src = Native.GetDC(IntPtr.Zero);
|
|
324
|
-
|
|
325
|
-
|
|
334
|
+
using (composite ? CardLayer.Hide() : null)
|
|
335
|
+
{
|
|
336
|
+
try { Native.BitBlt(dst, 0, 0, w, h, src, x, y, 0x00CC0020 | 0x40000000); }
|
|
337
|
+
finally { Native.ReleaseDC(IntPtr.Zero, src); g.ReleaseHdc(dst); }
|
|
338
|
+
}
|
|
339
|
+
if (!composite) CardLayer.Blank(g, x, y);
|
|
326
340
|
}
|
|
327
341
|
var data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
|
|
328
342
|
try
|
|
@@ -342,6 +356,28 @@ namespace DshComputerUse
|
|
|
342
356
|
}
|
|
343
357
|
}
|
|
344
358
|
|
|
359
|
+
static byte[] marked;
|
|
360
|
+
static string markedRect;
|
|
361
|
+
|
|
362
|
+
static string RectKey(int x, int y, int w, int h) { return x + "," + y + "," + w + "," + h; }
|
|
363
|
+
|
|
364
|
+
/** Remember what the screen looked like when the model was last shown it. */
|
|
365
|
+
public static void Mark(Dictionary<string, object> r)
|
|
366
|
+
{
|
|
367
|
+
int x = Args.Int(r, "x", 0), y = Args.Int(r, "y", 0), w = Args.Int(r, "width", 0), h = Args.Int(r, "height", 0);
|
|
368
|
+
marked = Sample(x, y, w, h, true);
|
|
369
|
+
markedRect = RectKey(x, y, w, h);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** Fraction of sampled pixels changed since Mark (-1 when there is nothing comparable). */
|
|
373
|
+
public static Dictionary<string, object> Diff(Dictionary<string, object> r)
|
|
374
|
+
{
|
|
375
|
+
int x = Args.Int(r, "x", 0), y = Args.Int(r, "y", 0), w = Args.Int(r, "width", 0), h = Args.Int(r, "height", 0);
|
|
376
|
+
var d = new Dictionary<string, object>();
|
|
377
|
+
d["diff"] = marked == null || markedRect != RectKey(x, y, w, h) ? -1.0 : Changed(marked, Sample(x, y, w, h, true));
|
|
378
|
+
return d;
|
|
379
|
+
}
|
|
380
|
+
|
|
345
381
|
static double Changed(byte[] a, byte[] b)
|
|
346
382
|
{
|
|
347
383
|
int n = a.Length / 3, diff = 0;
|
|
@@ -361,13 +397,13 @@ namespace DshComputerUse
|
|
|
361
397
|
int minMs = Args.Int(r, "minMs", 300), maxMs = Args.Int(r, "maxMs", 2500), interval = Args.Int(r, "intervalMs", 120), quietMs = Args.Int(r, "quietMs", 240);
|
|
362
398
|
if (w <= 0 || h <= 0) throw new Exception("invalid settle rect");
|
|
363
399
|
var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
364
|
-
byte[] prev = Sample(x, y, w, h);
|
|
400
|
+
byte[] prev = Sample(x, y, w, h, false);
|
|
365
401
|
long quietSince = -1;
|
|
366
402
|
bool stable = false;
|
|
367
403
|
while (true)
|
|
368
404
|
{
|
|
369
405
|
Thread.Sleep(interval);
|
|
370
|
-
byte[] cur = Sample(x, y, w, h);
|
|
406
|
+
byte[] cur = Sample(x, y, w, h, false);
|
|
371
407
|
long now = watch.ElapsedMilliseconds;
|
|
372
408
|
if (Changed(prev, cur) < 0.002) { if (quietSince < 0) quietSince = now - interval; }
|
|
373
409
|
else quietSince = -1;
|
|
@@ -395,8 +431,12 @@ namespace DshComputerUse
|
|
|
395
431
|
{
|
|
396
432
|
IntPtr dst = g.GetHdc();
|
|
397
433
|
IntPtr src = Native.GetDC(IntPtr.Zero);
|
|
398
|
-
|
|
399
|
-
|
|
434
|
+
// The DSH card is for the user only: capture what is under it.
|
|
435
|
+
using (CardLayer.Hide())
|
|
436
|
+
{
|
|
437
|
+
try { Native.BitBlt(dst, 0, 0, w, h, src, x, y, 0x00CC0020 | 0x40000000); }
|
|
438
|
+
finally { Native.ReleaseDC(IntPtr.Zero, src); g.ReleaseHdc(dst); }
|
|
439
|
+
}
|
|
400
440
|
}
|
|
401
441
|
Bitmap output = bmp;
|
|
402
442
|
Bitmap scaled = null;
|
|
@@ -616,15 +656,16 @@ namespace DshComputerUse
|
|
|
616
656
|
|
|
617
657
|
public static object Paste(string text, bool restore)
|
|
618
658
|
{
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
Clip.
|
|
659
|
+
// Keep every format the user had (images, files, rich text), not just text.
|
|
660
|
+
DataObject previous = null;
|
|
661
|
+
if (restore) { try { previous = Clip.Snapshot(); } catch (Exception) { } }
|
|
662
|
+
Clip.Set(text, true);
|
|
622
663
|
Thread.Sleep(40);
|
|
623
664
|
Send(new List<Native.INPUT> { Key(0x11, false), Key(0x56, false) });
|
|
624
665
|
Thread.Sleep(30);
|
|
625
666
|
Send(new List<Native.INPUT> { Key(0x56, true), Key(0x11, true) });
|
|
626
667
|
Thread.Sleep(250);
|
|
627
|
-
if (restore
|
|
668
|
+
if (restore) { try { Clip.Put(previous); } catch (Exception) { } }
|
|
628
669
|
return null;
|
|
629
670
|
}
|
|
630
671
|
}
|
|
@@ -641,20 +682,209 @@ namespace DshComputerUse
|
|
|
641
682
|
throw new Exception("clipboard is busy");
|
|
642
683
|
}
|
|
643
684
|
|
|
644
|
-
|
|
685
|
+
/** The user's clipboard before the agent first wrote to it, restored when control ends. */
|
|
686
|
+
static DataObject saved;
|
|
687
|
+
static bool hasSaved;
|
|
688
|
+
/** What the agent last put there, to tell whether the user copied something since. */
|
|
689
|
+
static string agentText;
|
|
690
|
+
|
|
691
|
+
static string Normalize(string text)
|
|
692
|
+
{
|
|
693
|
+
return string.IsNullOrEmpty(text) ? "" : text.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n");
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/** Mark data as transient: clipboard history (Win+V), cloud clipboard and clipboard managers skip it. */
|
|
697
|
+
static void MarkPrivate(DataObject d)
|
|
698
|
+
{
|
|
699
|
+
d.SetData("ExcludeClipboardContentFromMonitorProcessing", false, new MemoryStream(new byte[] { 1, 0, 0, 0 }));
|
|
700
|
+
d.SetData("CanIncludeInClipboardHistory", false, new MemoryStream(BitConverter.GetBytes(0)));
|
|
701
|
+
d.SetData("CanUploadToCloudClipboard", false, new MemoryStream(BitConverter.GetBytes(0)));
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/** Copy every format currently on the clipboard (null when empty). */
|
|
705
|
+
public static DataObject Snapshot()
|
|
706
|
+
{
|
|
707
|
+
for (int i = 0; i < 5; i++)
|
|
708
|
+
{
|
|
709
|
+
try
|
|
710
|
+
{
|
|
711
|
+
var src = Clipboard.GetDataObject();
|
|
712
|
+
if (src == null) return null;
|
|
713
|
+
var formats = src.GetFormats(false);
|
|
714
|
+
if (formats.Length == 0) return null;
|
|
715
|
+
var dst = new DataObject();
|
|
716
|
+
foreach (var f in formats)
|
|
717
|
+
{
|
|
718
|
+
if (f == "CanIncludeInClipboardHistory" || f == "CanUploadToCloudClipboard" || f == "ExcludeClipboardContentFromMonitorProcessing") continue;
|
|
719
|
+
try { var v = src.GetData(f, false); if (v != null) dst.SetData(f, false, v); } catch (Exception) { }
|
|
720
|
+
}
|
|
721
|
+
return dst;
|
|
722
|
+
}
|
|
723
|
+
catch (ExternalException) { Thread.Sleep(50); }
|
|
724
|
+
}
|
|
725
|
+
throw new Exception("clipboard is busy");
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/** Put a snapshot back without adding a history entry (null clears). */
|
|
729
|
+
public static void Put(DataObject data)
|
|
730
|
+
{
|
|
731
|
+
for (int i = 0; i < 5; i++)
|
|
732
|
+
{
|
|
733
|
+
try
|
|
734
|
+
{
|
|
735
|
+
if (data == null) Clipboard.Clear();
|
|
736
|
+
else { MarkPrivate(data); Clipboard.SetDataObject(data, true); }
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
catch (ExternalException) { Thread.Sleep(50); }
|
|
740
|
+
}
|
|
741
|
+
throw new Exception("clipboard is busy");
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
public static void Set(string text, bool isPrivate)
|
|
645
745
|
{
|
|
646
|
-
|
|
746
|
+
text = Normalize(text);
|
|
647
747
|
for (int i = 0; i < 5; i++)
|
|
648
748
|
{
|
|
649
749
|
try
|
|
650
750
|
{
|
|
651
|
-
if (
|
|
751
|
+
if (text.Length == 0) Clipboard.Clear();
|
|
752
|
+
else
|
|
753
|
+
{
|
|
754
|
+
var d = new DataObject();
|
|
755
|
+
d.SetData(DataFormats.UnicodeText, false, text);
|
|
756
|
+
if (isPrivate) MarkPrivate(d);
|
|
757
|
+
Clipboard.SetDataObject(d, true);
|
|
758
|
+
}
|
|
652
759
|
return;
|
|
653
760
|
}
|
|
654
761
|
catch (ExternalException) { Thread.Sleep(50); }
|
|
655
762
|
}
|
|
656
763
|
throw new Exception("clipboard is busy");
|
|
657
764
|
}
|
|
765
|
+
|
|
766
|
+
/** The agent writes the clipboard: remember the user's content first (once per control session). */
|
|
767
|
+
public static void AgentSet(string text)
|
|
768
|
+
{
|
|
769
|
+
if (!hasSaved) { saved = Snapshot(); hasSaved = true; }
|
|
770
|
+
Set(text, true);
|
|
771
|
+
agentText = Normalize(text);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/** Control ended: put the user's clipboard back, unless they copied something since the agent's last write. */
|
|
775
|
+
public static bool RestoreAgent()
|
|
776
|
+
{
|
|
777
|
+
if (!hasSaved) return false;
|
|
778
|
+
bool ours = false;
|
|
779
|
+
try { ours = Get() == agentText; } catch (Exception) { }
|
|
780
|
+
var data = saved;
|
|
781
|
+
saved = null; hasSaved = false; agentText = null;
|
|
782
|
+
if (!ours) return false;
|
|
783
|
+
Put(data);
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* The DeepSeek Harness card floats on top for the user only. To the agent
|
|
790
|
+
* it is transparent: while a screenshot is taken the card is made fully
|
|
791
|
+
* transparent for a few milliseconds (another process's window cannot be
|
|
792
|
+
* excluded from capture), and its pointer input passes through.
|
|
793
|
+
*/
|
|
794
|
+
internal static class CardLayer
|
|
795
|
+
{
|
|
796
|
+
public static IntPtr Hwnd = IntPtr.Zero;
|
|
797
|
+
static int originalEx;
|
|
798
|
+
|
|
799
|
+
static bool Live()
|
|
800
|
+
{
|
|
801
|
+
return Hwnd != IntPtr.Zero && Native.IsWindow(Hwnd) && Native.IsWindowVisible(Hwnd) && !Native.IsIconic(Hwnd);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
public static uint Pid()
|
|
805
|
+
{
|
|
806
|
+
if (!Live()) return 0;
|
|
807
|
+
uint pid; Native.GetWindowThreadProcessId(Hwnd, out pid);
|
|
808
|
+
return pid;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/** The card becomes a (fully opaque) layered window so its alpha can be dropped instantly. */
|
|
812
|
+
public static void Attach(IntPtr hwnd)
|
|
813
|
+
{
|
|
814
|
+
if (Hwnd == hwnd) return;
|
|
815
|
+
Detach();
|
|
816
|
+
Hwnd = hwnd;
|
|
817
|
+
originalEx = Native.GetWindowLong(hwnd, -20);
|
|
818
|
+
Native.SetWindowLong(hwnd, -20, originalEx | 0x80000);
|
|
819
|
+
Native.SetLayeredWindowAttributes(hwnd, 0, 255, 2);
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
public static void Detach()
|
|
823
|
+
{
|
|
824
|
+
var hwnd = Hwnd;
|
|
825
|
+
Hwnd = IntPtr.Zero;
|
|
826
|
+
if (hwnd != IntPtr.Zero && Native.IsWindow(hwnd)) Native.SetWindowLong(hwnd, -20, originalEx);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
public static Rectangle Frame(IntPtr hwnd)
|
|
830
|
+
{
|
|
831
|
+
Native.RECT rc;
|
|
832
|
+
if (Native.DwmGetWindowAttribute(hwnd, 9, out rc, Marshal.SizeOf(typeof(Native.RECT))) != 0) Native.GetWindowRect(hwnd, out rc);
|
|
833
|
+
return new Rectangle(rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top);
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/** g draws a bitmap whose (0, 0) is screen (ox, oy): fill the card area with a constant. */
|
|
837
|
+
public static void Blank(Graphics g, int ox, int oy)
|
|
838
|
+
{
|
|
839
|
+
if (!Live()) return;
|
|
840
|
+
var r = Frame(Hwnd);
|
|
841
|
+
r.Inflate(32, 32); // its drop shadow too (wide at 200% scaling)
|
|
842
|
+
g.FillRectangle(Brushes.Black, r.X - ox, r.Y - oy, r.Width, r.Height);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/** Make the card invisible while a capture runs (dispose to show it again). */
|
|
846
|
+
public static IDisposable Hide()
|
|
847
|
+
{
|
|
848
|
+
return new Hidden(Live() ? Hwnd : IntPtr.Zero);
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
sealed class Hidden : IDisposable
|
|
852
|
+
{
|
|
853
|
+
readonly IntPtr hwnd;
|
|
854
|
+
public Hidden(IntPtr hwnd)
|
|
855
|
+
{
|
|
856
|
+
this.hwnd = hwnd;
|
|
857
|
+
if (hwnd != IntPtr.Zero) Native.SetLayeredWindowAttributes(hwnd, 0, 0, 2);
|
|
858
|
+
}
|
|
859
|
+
public void Dispose()
|
|
860
|
+
{
|
|
861
|
+
if (hwnd != IntPtr.Zero && Native.IsWindow(hwnd)) Native.SetLayeredWindowAttributes(hwnd, 0, 255, 2);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/** While the agent moves, clicks or scrolls, the card lets the mouse through. */
|
|
867
|
+
internal sealed class PassThrough : IDisposable
|
|
868
|
+
{
|
|
869
|
+
readonly IntPtr hwnd;
|
|
870
|
+
readonly int oldEx;
|
|
871
|
+
readonly bool active;
|
|
872
|
+
|
|
873
|
+
public PassThrough()
|
|
874
|
+
{
|
|
875
|
+
hwnd = CardLayer.Hwnd;
|
|
876
|
+
if (hwnd == IntPtr.Zero || !Native.IsWindow(hwnd)) return;
|
|
877
|
+
oldEx = Native.GetWindowLong(hwnd, -20);
|
|
878
|
+
Native.SetWindowLong(hwnd, -20, oldEx | 0x20 | 0x80000); // WS_EX_TRANSPARENT (layered already)
|
|
879
|
+
active = true;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
public void Dispose()
|
|
883
|
+
{
|
|
884
|
+
if (!active) return;
|
|
885
|
+
Thread.Sleep(60); // let the injected input reach its target first
|
|
886
|
+
if (Native.IsWindow(hwnd)) Native.SetWindowLong(hwnd, -20, oldEx);
|
|
887
|
+
}
|
|
658
888
|
}
|
|
659
889
|
|
|
660
890
|
internal static class Windows
|
|
@@ -725,7 +955,8 @@ namespace DshComputerUse
|
|
|
725
955
|
if (h != IntPtr.Zero) h = Native.GetAncestor(h, 2); // GA_ROOT
|
|
726
956
|
uint pid = 0;
|
|
727
957
|
if (h != IntPtr.Zero) Native.GetWindowThreadProcessId(h, out pid);
|
|
728
|
-
|
|
958
|
+
uint cardPid = CardLayer.Pid();
|
|
959
|
+
if (h == IntPtr.Zero || pid == (uint)Process.GetCurrentProcess().Id || (cardPid != 0 && pid == cardPid))
|
|
729
960
|
{
|
|
730
961
|
// Our own status pill is under the point (it dodges before the
|
|
731
962
|
// click): report the topmost foreign window there instead.
|
|
@@ -735,8 +966,9 @@ namespace DshComputerUse
|
|
|
735
966
|
{
|
|
736
967
|
if (!Native.IsWindowVisible(w)) return true;
|
|
737
968
|
uint p; Native.GetWindowThreadProcessId(w, out p);
|
|
738
|
-
if (p == self) return true;
|
|
969
|
+
if (p == self || (cardPid != 0 && p == cardPid)) return true; // our overlay, the DSH card
|
|
739
970
|
if ((Native.GetWindowLong(w, -20) & 0x20) != 0) return true; // WS_EX_TRANSPARENT
|
|
971
|
+
if (Native.IsIconic(w)) return true;
|
|
740
972
|
int cloaked;
|
|
741
973
|
if (Native.DwmGetWindowAttribute(w, 14, out cloaked, 4) == 0 && cloaked != 0) return true;
|
|
742
974
|
Native.RECT rc; Native.GetWindowRect(w, out rc);
|
|
@@ -788,6 +1020,15 @@ namespace DshComputerUse
|
|
|
788
1020
|
Native.SendInput(3, inputs, Marshal.SizeOf(typeof(Native.INPUT)));
|
|
789
1021
|
Thread.Sleep(120);
|
|
790
1022
|
}
|
|
1023
|
+
if (Native.GetForegroundWindow() != hwnd)
|
|
1024
|
+
{
|
|
1025
|
+
// Last resort: restoring a minimized window always activates it.
|
|
1026
|
+
bool zoomed = Native.IsZoomed(hwnd);
|
|
1027
|
+
Native.ShowWindow(hwnd, 6); // SW_MINIMIZE
|
|
1028
|
+
Thread.Sleep(150);
|
|
1029
|
+
Native.ShowWindow(hwnd, zoomed ? 3 : 9); // SW_MAXIMIZE / SW_RESTORE
|
|
1030
|
+
Thread.Sleep(200);
|
|
1031
|
+
}
|
|
791
1032
|
}
|
|
792
1033
|
var d = Describe(hwnd);
|
|
793
1034
|
d["focused"] = Native.GetForegroundWindow() == hwnd;
|
|
@@ -800,6 +1041,7 @@ namespace DshComputerUse
|
|
|
800
1041
|
public static object Card(IntPtr hwnd, int x, int y, int w, int h)
|
|
801
1042
|
{
|
|
802
1043
|
if (!Native.IsWindow(hwnd)) throw new Exception("window no longer exists");
|
|
1044
|
+
CardLayer.Attach(hwnd);
|
|
803
1045
|
if (!cards.ContainsKey(hwnd.ToInt64()))
|
|
804
1046
|
{
|
|
805
1047
|
var wp = new Native.WINDOWPLACEMENT();
|
|
@@ -822,6 +1064,7 @@ namespace DshComputerUse
|
|
|
822
1064
|
|
|
823
1065
|
public static object Uncard(IntPtr hwnd)
|
|
824
1066
|
{
|
|
1067
|
+
if (CardLayer.Hwnd == hwnd) CardLayer.Detach();
|
|
825
1068
|
Native.WINDOWPLACEMENT wp;
|
|
826
1069
|
bool known = cards.TryGetValue(hwnd.ToInt64(), out wp);
|
|
827
1070
|
cards.Remove(hwnd.ToInt64());
|
package/lib/client.js
CHANGED
|
@@ -101,23 +101,29 @@ window.__ModuleLoader__.load({
|
|
|
101
101
|
style.textContent = navIconCss;
|
|
102
102
|
document.head.appendChild(style);
|
|
103
103
|
let disposed = false;
|
|
104
|
+
let frame = 0;
|
|
104
105
|
const sync = () => {
|
|
106
|
+
frame = 0;
|
|
105
107
|
if (disposed) return;
|
|
106
|
-
|
|
108
|
+
const dialogs = document.querySelectorAll("[role=\"dialog\"]");
|
|
109
|
+
if (dialogs.length === 0) return;
|
|
110
|
+
for (const dialog of dialogs) for (const button of dialog.querySelectorAll("nav button")) {
|
|
107
111
|
const mine = button.textContent?.trim() === label;
|
|
108
112
|
if (mine && !button.hasAttribute(MARKER)) button.setAttribute(MARKER, "");
|
|
109
113
|
else if (!mine && button.hasAttribute(MARKER)) button.removeAttribute(MARKER);
|
|
110
114
|
}
|
|
111
115
|
};
|
|
112
116
|
sync();
|
|
113
|
-
const observer = new MutationObserver(
|
|
117
|
+
const observer = new MutationObserver(() => {
|
|
118
|
+
if (frame === 0) frame = requestAnimationFrame(sync);
|
|
119
|
+
});
|
|
114
120
|
observer.observe(document.body, {
|
|
115
121
|
childList: true,
|
|
116
|
-
subtree: true
|
|
117
|
-
characterData: true
|
|
122
|
+
subtree: true
|
|
118
123
|
});
|
|
119
124
|
return () => {
|
|
120
125
|
disposed = true;
|
|
126
|
+
if (frame !== 0) cancelAnimationFrame(frame);
|
|
121
127
|
observer.disconnect();
|
|
122
128
|
style.remove();
|
|
123
129
|
document.querySelectorAll(`[${MARKER}]`).forEach((element) => element.removeAttribute(MARKER));
|
package/lib/index.js
CHANGED
|
@@ -118,6 +118,15 @@ function sameApp(a, b) {
|
|
|
118
118
|
for (const exe of exeNames(b)) if (x.has(exe)) return true;
|
|
119
119
|
return false;
|
|
120
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Windows shell surfaces that grab the foreground without being a place to
|
|
123
|
+
* work: the touch-keyboard / IME host and Snap Assist.
|
|
124
|
+
*/
|
|
125
|
+
function isTransientShell(win) {
|
|
126
|
+
const exe = win.exe.toLowerCase();
|
|
127
|
+
if (exe === "textinputhost.exe") return true;
|
|
128
|
+
return exe === "explorer.exe" && (win.className === "XamlExplorerHostIslandWindow" || /贴靠助手|snap assist/i.test(win.title));
|
|
129
|
+
}
|
|
121
130
|
function isHostWindow(win) {
|
|
122
131
|
return HOST_EXES.includes(win.exe.toLowerCase());
|
|
123
132
|
}
|
|
@@ -484,6 +493,10 @@ const KEYBOARD = /* @__PURE__ */ new Set([
|
|
|
484
493
|
"key",
|
|
485
494
|
"hold_key"
|
|
486
495
|
]);
|
|
496
|
+
/** Below this fraction of changed sample pixels, the screen counts as unchanged. */
|
|
497
|
+
const UNCHANGED_DIFF = 5e-4;
|
|
498
|
+
/** Text returned instead of an identical screenshot. */
|
|
499
|
+
const UNCHANGED_TEXT = "The screen looks exactly as in your previous screenshot: the action had no visible effect.";
|
|
487
500
|
var Computer = class Computer {
|
|
488
501
|
helper;
|
|
489
502
|
access;
|
|
@@ -492,6 +505,8 @@ var Computer = class Computer {
|
|
|
492
505
|
displays = [];
|
|
493
506
|
displayIndex = -1;
|
|
494
507
|
heldButton = false;
|
|
508
|
+
/** The agent that last wrote the clipboard; when it goes idle the user's clipboard comes back. */
|
|
509
|
+
clipboardAgent;
|
|
495
510
|
constructor(helper, access, overlay, settings) {
|
|
496
511
|
this.helper = helper;
|
|
497
512
|
this.access = access;
|
|
@@ -528,12 +543,10 @@ var Computer = class Computer {
|
|
|
528
543
|
async point(coordinate, field = "coordinate") {
|
|
529
544
|
if (!Array.isArray(coordinate) || coordinate.length !== 2) throw new Error(`${field} must be [x, y] in screenshot pixels.`);
|
|
530
545
|
const display = await this.display();
|
|
531
|
-
|
|
546
|
+
return toPhysical({
|
|
532
547
|
x: coordinate[0],
|
|
533
548
|
y: coordinate[1]
|
|
534
549
|
}, display, this.shotSize(display));
|
|
535
|
-
await this.overlay.dodgeCard(p);
|
|
536
|
-
return p;
|
|
537
550
|
}
|
|
538
551
|
async toModel(point) {
|
|
539
552
|
const display = await this.display();
|
|
@@ -547,9 +560,32 @@ var Computer = class Computer {
|
|
|
547
560
|
const display = await this.display();
|
|
548
561
|
const size = this.shotSize(display);
|
|
549
562
|
const shot = await this.capture(display, size);
|
|
563
|
+
await this.helper.call("shot_mark", this.rect(display)).catch(() => {});
|
|
550
564
|
await this.remember();
|
|
551
565
|
return shot;
|
|
552
566
|
}
|
|
567
|
+
rect(display) {
|
|
568
|
+
return {
|
|
569
|
+
x: display.x,
|
|
570
|
+
y: display.y,
|
|
571
|
+
width: display.width,
|
|
572
|
+
height: display.height
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* A fresh screenshot, or 'unchanged' when the screen looks the same as in
|
|
577
|
+
* the last one the model saw (saves an image and tells it the action had no
|
|
578
|
+
* visible effect).
|
|
579
|
+
*/
|
|
580
|
+
async freshShot() {
|
|
581
|
+
const display = await this.display();
|
|
582
|
+
const result = await this.helper.call("shot_diff", this.rect(display)).catch(() => null);
|
|
583
|
+
if (result && result.diff >= 0 && result.diff < UNCHANGED_DIFF) {
|
|
584
|
+
await this.remember();
|
|
585
|
+
return "unchanged";
|
|
586
|
+
}
|
|
587
|
+
return this.screenshot();
|
|
588
|
+
}
|
|
553
589
|
/** The foreground window as of the model's latest look at the screen. */
|
|
554
590
|
seen;
|
|
555
591
|
/** The latest foreground window that was not DeepSeek Harness itself. */
|
|
@@ -601,7 +637,7 @@ var Computer = class Computer {
|
|
|
601
637
|
async foreground() {
|
|
602
638
|
const win = await this.helper.call("foreground");
|
|
603
639
|
if (!win || typeof win.hwnd !== "number") return void 0;
|
|
604
|
-
if (!isHostWindow(win)) this.lastTarget = win;
|
|
640
|
+
if (!isHostWindow(win) && !isTransientShell(win)) this.lastTarget = win;
|
|
605
641
|
return win;
|
|
606
642
|
}
|
|
607
643
|
/**
|
|
@@ -612,7 +648,7 @@ var Computer = class Computer {
|
|
|
612
648
|
async refocusFromHost() {
|
|
613
649
|
const target = this.lastTarget;
|
|
614
650
|
const fg = await this.foreground().catch(() => void 0);
|
|
615
|
-
if (!fg || !isHostWindow(fg) || !target || target.hwnd === fg.hwnd) return;
|
|
651
|
+
if (!fg || !(isHostWindow(fg) || isTransientShell(fg)) || !target || target.hwnd === fg.hwnd) return;
|
|
616
652
|
if ((await this.focus(target).catch(() => void 0))?.focused) await setTimeout$1(80);
|
|
617
653
|
}
|
|
618
654
|
/** Wait until the screen stops changing (bounded), instead of a fixed delay. */
|
|
@@ -698,7 +734,7 @@ var Computer = class Computer {
|
|
|
698
734
|
}
|
|
699
735
|
if (s.pauseOnUserInput && INPUT.has(action)) {
|
|
700
736
|
const changed = await this.foregroundChanged();
|
|
701
|
-
if (changed && !isHostWindow(changed)) {
|
|
737
|
+
if (changed && !isHostWindow(changed) && !isTransientShell(changed)) {
|
|
702
738
|
await this.overlay.status("检测到窗口切换,重新查看屏幕");
|
|
703
739
|
const image = call.vision ? await this.screenshot() : void 0;
|
|
704
740
|
if (!image) this.seen = changed;
|
|
@@ -846,7 +882,7 @@ var Computer = class Computer {
|
|
|
846
882
|
const mutating = inputs.some((input) => MUTATING.has(input.action));
|
|
847
883
|
if (!mutating && !inputs.some((input) => input.action === "wait")) return void 0;
|
|
848
884
|
if (mutating) await this.settle(call.signal);
|
|
849
|
-
return this.
|
|
885
|
+
return this.freshShot();
|
|
850
886
|
}
|
|
851
887
|
/** Bring a window forward and verify it is the foreground window. */
|
|
852
888
|
async focus(win) {
|
|
@@ -1119,8 +1155,6 @@ var OverlayController = class {
|
|
|
1119
1155
|
visible = false;
|
|
1120
1156
|
idleTimer;
|
|
1121
1157
|
hostWindows = [];
|
|
1122
|
-
/** The floating card and the display it lives on, while carded. */
|
|
1123
|
-
card;
|
|
1124
1158
|
stopping = false;
|
|
1125
1159
|
/** Paused by Esc or the pill; actions wait until resumed. */
|
|
1126
1160
|
paused = false;
|
|
@@ -1254,48 +1288,22 @@ var OverlayController = class {
|
|
|
1254
1288
|
hwnd: main.hwnd,
|
|
1255
1289
|
mode: "card"
|
|
1256
1290
|
}];
|
|
1257
|
-
this.card = {
|
|
1258
|
-
hwnd: main.hwnd,
|
|
1259
|
-
display
|
|
1260
|
-
};
|
|
1261
1291
|
} catch (error) {
|
|
1262
1292
|
this.log(`host window ${mode}: ${String(error)}`);
|
|
1263
1293
|
}
|
|
1264
1294
|
}
|
|
1265
|
-
/**
|
|
1266
|
-
* The agent is about to point at something under the card: move the card to
|
|
1267
|
-
* the opposite bottom corner so the target is visible and clickable.
|
|
1268
|
-
* Returns whether it moved.
|
|
1269
|
-
*/
|
|
1270
|
-
async dodgeCard(point) {
|
|
1271
|
-
const card = this.card;
|
|
1272
|
-
if (!card) return false;
|
|
1273
|
-
try {
|
|
1274
|
-
const win = await this.helper.call("window_at", { ...point });
|
|
1275
|
-
if (!win || win.hwnd !== card.hwnd) return false;
|
|
1276
|
-
const d = card.display;
|
|
1277
|
-
const margin = Math.round(16 * d.dpi / 96);
|
|
1278
|
-
const x = win.x + win.width / 2 > d.workX + d.workWidth / 2 ? d.workX + margin : d.workX + d.workWidth - win.width - margin;
|
|
1279
|
-
await this.helper.call("window_card", {
|
|
1280
|
-
hwnd: card.hwnd,
|
|
1281
|
-
x,
|
|
1282
|
-
y: win.y,
|
|
1283
|
-
width: win.width,
|
|
1284
|
-
height: win.height
|
|
1285
|
-
});
|
|
1286
|
-
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
1287
|
-
return true;
|
|
1288
|
-
} catch (error) {
|
|
1289
|
-
this.log(`card dodge: ${String(error)}`);
|
|
1290
|
-
return false;
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
1295
|
async restoreHost() {
|
|
1294
1296
|
const windows = this.hostWindows;
|
|
1295
1297
|
this.hostWindows = [];
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1298
|
+
for (const win of windows) if (win.mode === "card") {
|
|
1299
|
+
await this.helper.call("window_uncard", { hwnd: win.hwnd }).catch(() => {});
|
|
1300
|
+
setTimeout(() => {
|
|
1301
|
+
this.helper.call("windows").then((rows) => rows.some((row) => row.hwnd === win.hwnd) ? void 0 : this.helper.call("window_cmd", {
|
|
1302
|
+
hwnd: win.hwnd,
|
|
1303
|
+
op: "restore"
|
|
1304
|
+
})).catch(() => {});
|
|
1305
|
+
}, 1200).unref();
|
|
1306
|
+
} else await this.helper.call("window_cmd", {
|
|
1299
1307
|
hwnd: win.hwnd,
|
|
1300
1308
|
op: "restore"
|
|
1301
1309
|
}).catch(() => {});
|
|
@@ -1308,9 +1316,12 @@ function promptText(mode) {
|
|
|
1308
1316
|
You can see and operate the user's Windows computer with the computer, computer_batch, open_application, windows, ui_elements and clipboard tools.
|
|
1309
1317
|
${mode === "per-app" ? "- Before acting on an app, call request_access once with every app the task needs; the user approves it. Input to apps that are not granted is refused.\n" : ""}- Start with a screenshot (computer action "screenshot") unless you just received one. All coordinates are pixels of the latest screenshot; the plugin converts them for DPI and scaling.
|
|
1310
1318
|
- Open or switch apps with open_application (by name; it also finds desktop shortcuts) rather than hunting through the taskbar or Start menu or starting GUI apps from a shell. Use windows to see which windows exist; each line shows the process .exe.
|
|
1311
|
-
- The "DeepSeek Harness.exe" window is your own chat interface
|
|
1312
|
-
-
|
|
1319
|
+
- The "DeepSeek Harness.exe" window is your own chat interface. While you control the computer it floats as a card that only the user sees: your screenshots show what is underneath it and your clicks and scrolls pass through it, so simply ignore it. Never type into DeepSeek Harness; keys go to the window you were working in.
|
|
1320
|
+
- If the target window is small or partly covered by other windows, maximize it (windows maximize) or minimize what is in the way (windows minimize works for any window) instead of working around it.
|
|
1321
|
+
- Prefer reliable keyboard shortcuts (ctrl+l for a browser address bar, ctrl+s, alt+F4, ctrl+t). Click the center of targets. When text is too small to read, zoom once on a generous region that contains everything you need (zooming step by step wastes calls).
|
|
1313
1322
|
- Actions return a fresh screenshot taken once the screen stops changing (page loads included, up to a few seconds), so you rarely need wait. If something is still loading, use wait: it also returns a screenshot, so never follow it with a separate screenshot call.
|
|
1323
|
+
- Enter text with type, even long or multi-line text (over 200 characters it is pasted and the user's clipboard is restored). Do not put text on the clipboard with shell commands (Set-Clipboard, clip): that clutters the user's clipboard history.
|
|
1324
|
+
- Office apps: F12 opens the classic Save As dialog, where you can type a full path in the file name box.
|
|
1314
1325
|
- Be efficient: every tool call costs the user several seconds. Put predictable sequences (click a field, type, press Return; open a menu and pick an item you can already see) into one computer_batch. Avoid shell commands for things you can see on screen.
|
|
1315
1326
|
- To see more of a page or list, scroll (action "scroll" with coordinate over the area, scroll_direction, scroll_amount 5-10) instead of hunting with zoom; for long web pages Page Down / End keys also work.
|
|
1316
1327
|
- If a dedicated tool fits the whole task better (an API, or browser automation attached to the user's own browser), choose it at the start; do not switch tools halfway through a task that is going fine on screen.
|
|
@@ -7099,6 +7110,8 @@ function toJson(ref) {
|
|
|
7099
7110
|
}
|
|
7100
7111
|
async function withShot(host, text, shot, call) {
|
|
7101
7112
|
if (shot === void 0) return { text };
|
|
7113
|
+
if (shot === "unchanged") return { text: `${text}
|
|
7114
|
+
${UNCHANGED_TEXT}` };
|
|
7102
7115
|
if (!call.vision) return { text: `${text}\n(The current model cannot view images; use ui_elements to read the screen.)` };
|
|
7103
7116
|
const ref = await host.saveImage(shot, "screenshot.jpg");
|
|
7104
7117
|
return {
|
|
@@ -7242,7 +7255,7 @@ function createTools(host) {
|
|
|
7242
7255
|
}
|
|
7243
7256
|
}
|
|
7244
7257
|
const done = lines.join("\n");
|
|
7245
|
-
const shot = call.vision && computer.settings().autoScreenshot ? await computer.settle(call.signal).then(() => computer.
|
|
7258
|
+
const shot = call.vision && computer.settings().autoScreenshot ? await computer.settle(call.signal).then(() => computer.freshShot()) : void 0;
|
|
7246
7259
|
const summary = failure === void 0 ? `All ${actions.length} actions done.\n${done}` : `Stopped: ${failure}${done ? `\nCompleted before it:\n${done}` : ""}\nRemaining actions were skipped.`;
|
|
7247
7260
|
return withShot(host, shot === void 0 ? `${summary}\n${await computer.describeForeground()}` : summary, shot, call);
|
|
7248
7261
|
},
|
|
@@ -7287,7 +7300,7 @@ function createTools(host) {
|
|
|
7287
7300
|
for (let i = 0; i < 32; i++) {
|
|
7288
7301
|
await setTimeout$1(250, void 0, { signal: call.signal });
|
|
7289
7302
|
const now = await computer.foreground();
|
|
7290
|
-
if (now && now.hwnd !== before?.hwnd && !isHostWindow(now) && (now.exe.toLowerCase() !== "explorer.exe" || now.className === "CabinetWClass")) break;
|
|
7303
|
+
if (now && now.hwnd !== before?.hwnd && !isHostWindow(now) && !isTransientShell(now) && (now.exe.toLowerCase() !== "explorer.exe" || now.className === "CabinetWClass")) break;
|
|
7291
7304
|
}
|
|
7292
7305
|
}
|
|
7293
7306
|
const fg = await computer.foreground();
|
|
@@ -7329,11 +7342,11 @@ function createTools(host) {
|
|
|
7329
7342
|
const { action, hwnd, name } = args;
|
|
7330
7343
|
const rows = await computer.windows();
|
|
7331
7344
|
if (action === "list") return { text: (await Promise.all(rows.map(async (win) => `hwnd=${win.hwnd} | ${win.exe} | "${win.title.slice(0, 70)}"${win.foreground ? " | FOREGROUND" : ""}${win.minimized ? " | minimized" : ` | ${await computer.windowBox(win)}`}${isHostWindow(win) ? " | (your own DeepSeek Harness chat window)" : ""}`))).join("\n") || "No windows." };
|
|
7332
|
-
const target = hwnd !== void 0 ? rows.find((win) => win.hwnd === hwnd) : name ? rows.find((win) => appMatches(name, win)
|
|
7345
|
+
const target = hwnd !== void 0 ? rows.find((win) => win.hwnd === hwnd) : name ? rows.find((win) => !isHostWindow(win) && appMatches(name, win)) ?? rows.find((win) => !isHostWindow(win) && win.title.toLowerCase().includes(name.toLowerCase())) ?? rows.find((win) => appMatches(name, win)) : void 0;
|
|
7333
7346
|
if (!target) throw new Error("Window not found; call windows with action \"list\".");
|
|
7334
7347
|
const settings = computer.settings();
|
|
7335
7348
|
const denial = computer.access.denial(call.session, target, settings.accessMode, settings.blockedApps, action);
|
|
7336
|
-
if (denial &&
|
|
7349
|
+
if (denial && action !== "minimize") throw new Error(denial);
|
|
7337
7350
|
await computer.overlay.begin(call.agent, `窗口 ${action}`);
|
|
7338
7351
|
await computer.overlay.yieldToUser(call.signal, false);
|
|
7339
7352
|
let text;
|
|
@@ -7398,7 +7411,7 @@ function createTools(host) {
|
|
|
7398
7411
|
}));
|
|
7399
7412
|
tools.push(defineTool({
|
|
7400
7413
|
name: "clipboard",
|
|
7401
|
-
description: "Read or write the clipboard text.",
|
|
7414
|
+
description: "Read or write the clipboard text. Writes stay out of Windows clipboard history, and the user clipboard is restored when you finish. To enter long text, prefer computer type (it pastes for you); never set the clipboard from a shell.",
|
|
7402
7415
|
parameters: {
|
|
7403
7416
|
action: {
|
|
7404
7417
|
type: "string",
|
|
@@ -7411,10 +7424,14 @@ function createTools(host) {
|
|
|
7411
7424
|
}
|
|
7412
7425
|
},
|
|
7413
7426
|
output,
|
|
7414
|
-
async execute(args) {
|
|
7427
|
+
async execute(args, exec) {
|
|
7415
7428
|
const { action, text } = args;
|
|
7416
7429
|
if (action === "write") {
|
|
7417
|
-
|
|
7430
|
+
computer.clipboardAgent = (await host.context(exec)).agent;
|
|
7431
|
+
await computer.helper.call("clipboard_set", {
|
|
7432
|
+
text: text ?? "",
|
|
7433
|
+
agent: true
|
|
7434
|
+
});
|
|
7418
7435
|
return { text: `Clipboard set (${(text ?? "").length} characters).` };
|
|
7419
7436
|
}
|
|
7420
7437
|
const result = await computer.helper.call("clipboard_get");
|
|
@@ -7630,6 +7647,10 @@ function apply(ctx, config = {}) {
|
|
|
7630
7647
|
});
|
|
7631
7648
|
ctx.on("agent/status", ({ agent, status }) => {
|
|
7632
7649
|
if (status === "running") computer.resetLook();
|
|
7650
|
+
if (status === "idle" && computer.clipboardAgent === agent) {
|
|
7651
|
+
computer.clipboardAgent = void 0;
|
|
7652
|
+
helper.call("clipboard_restore").catch(() => {});
|
|
7653
|
+
}
|
|
7633
7654
|
if (status === "idle" && overlay.controller === agent) overlay.end(agent);
|
|
7634
7655
|
});
|
|
7635
7656
|
ctx.on("agent/disposed", ({ agent }) => {
|
package/lib/types/access.d.ts
CHANGED
|
@@ -14,6 +14,13 @@ export declare const HOST_EXES: string[];
|
|
|
14
14
|
export declare function normalizeApp(name: string): string;
|
|
15
15
|
/** Do two app names refer to the same program ("explorer" and "文件资源管理器")? */
|
|
16
16
|
export declare function sameApp(a: string, b: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Windows shell surfaces that grab the foreground without being a place to
|
|
19
|
+
* work: the touch-keyboard / IME host and Snap Assist.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isTransientShell(win: WindowLike & {
|
|
22
|
+
className?: string;
|
|
23
|
+
}): boolean;
|
|
17
24
|
export declare function isHostWindow(win: WindowLike): boolean;
|
|
18
25
|
/** Does a granted (or requested) app name refer to this window? */
|
|
19
26
|
export declare function appMatches(name: string, win: WindowLike): boolean;
|
package/lib/types/computer.d.ts
CHANGED
|
@@ -64,6 +64,8 @@ export interface ActionOutcome {
|
|
|
64
64
|
/** The action was not performed because the user took over the keyboard. */
|
|
65
65
|
skipped?: boolean;
|
|
66
66
|
}
|
|
67
|
+
/** Text returned instead of an identical screenshot. */
|
|
68
|
+
export declare const UNCHANGED_TEXT = "The screen looks exactly as in your previous screenshot: the action had no visible effect.";
|
|
67
69
|
/** Longest adaptive wait for the screen to settle after an action. */
|
|
68
70
|
export declare const MAX_SETTLE_MS = 2500;
|
|
69
71
|
export declare class Computer {
|
|
@@ -74,6 +76,8 @@ export declare class Computer {
|
|
|
74
76
|
private displays;
|
|
75
77
|
private displayIndex;
|
|
76
78
|
private heldButton;
|
|
79
|
+
/** The agent that last wrote the clipboard; when it goes idle the user's clipboard comes back. */
|
|
80
|
+
clipboardAgent: CancellableAgent | undefined;
|
|
77
81
|
constructor(helper: HelperLike, access: AccessControl, overlay: OverlayController, settings: () => Settings);
|
|
78
82
|
refreshDisplays(): Promise<Display[]>;
|
|
79
83
|
display(): Promise<Display>;
|
|
@@ -85,6 +89,13 @@ export declare class Computer {
|
|
|
85
89
|
offscreen: boolean;
|
|
86
90
|
}>;
|
|
87
91
|
screenshot(): Promise<Shot>;
|
|
92
|
+
private rect;
|
|
93
|
+
/**
|
|
94
|
+
* A fresh screenshot, or 'unchanged' when the screen looks the same as in
|
|
95
|
+
* the last one the model saw (saves an image and tells it the action had no
|
|
96
|
+
* visible effect).
|
|
97
|
+
*/
|
|
98
|
+
freshShot(): Promise<Shot | 'unchanged'>;
|
|
88
99
|
/** The foreground window as of the model's latest look at the screen. */
|
|
89
100
|
private seen;
|
|
90
101
|
/** The latest foreground window that was not DeepSeek Harness itself. */
|
|
@@ -127,7 +138,7 @@ export declare class Computer {
|
|
|
127
138
|
* (vision models only). A wait already waited, so it is captured at once:
|
|
128
139
|
* "wait, then look" should be one step, not two.
|
|
129
140
|
*/
|
|
130
|
-
after(inputs: readonly ActionInput[], call: CallContext): Promise<Shot | undefined>;
|
|
141
|
+
after(inputs: readonly ActionInput[], call: CallContext): Promise<Shot | 'unchanged' | undefined>;
|
|
131
142
|
/** Bring a window forward and verify it is the foreground window. */
|
|
132
143
|
focus(win: WindowInfo): Promise<WindowInfo & {
|
|
133
144
|
focused: boolean;
|
package/lib/types/overlay.d.ts
CHANGED
|
@@ -40,8 +40,6 @@ export declare class OverlayController {
|
|
|
40
40
|
private visible;
|
|
41
41
|
private idleTimer;
|
|
42
42
|
private hostWindows;
|
|
43
|
-
/** The floating card and the display it lives on, while carded. */
|
|
44
|
-
private card;
|
|
45
43
|
private stopping;
|
|
46
44
|
/** Paused by Esc or the pill; actions wait until resumed. */
|
|
47
45
|
paused: boolean;
|
|
@@ -70,15 +68,6 @@ export declare class OverlayController {
|
|
|
70
68
|
private armIdle;
|
|
71
69
|
/** Card: shrink the DSH window to an always-on-top corner card; minimize: get it out of the way. */
|
|
72
70
|
private shrinkHost;
|
|
73
|
-
/**
|
|
74
|
-
* The agent is about to point at something under the card: move the card to
|
|
75
|
-
* the opposite bottom corner so the target is visible and clickable.
|
|
76
|
-
* Returns whether it moved.
|
|
77
|
-
*/
|
|
78
|
-
dodgeCard(point: {
|
|
79
|
-
x: number;
|
|
80
|
-
y: number;
|
|
81
|
-
}): Promise<boolean>;
|
|
82
71
|
private restoreHost;
|
|
83
72
|
}
|
|
84
73
|
export {};
|
package/package.json
CHANGED