@copylee/dsh-computer-use 0.1.7 → 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 +1 -1
- package/helper/CuHelper.cs +146 -16
- package/lib/client.js +10 -4
- package/lib/index.js +28 -48
- package/lib/types/access.d.ts +7 -0
- package/lib/types/overlay.d.ts +0 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
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
18
|
| 中文输入 | Unicode 直接输入,不受输入法状态影响;长文本走剪贴板粘贴,剪贴板文本统一为 CRLF,粘贴到 Obsidian 等应用不丢换行 |
|
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);
|
|
@@ -254,11 +256,11 @@ namespace DshComputerUse
|
|
|
254
256
|
case "shot_mark": Screen2.Mark(r); return null;
|
|
255
257
|
case "shot_diff": return Screen2.Diff(r);
|
|
256
258
|
case "cursor": { Native.POINT p; Native.GetCursorPos(out p); return Pt(p.X, p.Y); }
|
|
257
|
-
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;
|
|
258
|
-
case "click": return Input.Click(r);
|
|
259
|
-
case "button": return Input.Button(r);
|
|
260
|
-
case "drag": return Input.Drag(r);
|
|
261
|
-
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);
|
|
262
264
|
case "keys": return Input.Keys(r);
|
|
263
265
|
case "key_state": return Input.KeyState(r);
|
|
264
266
|
case "type": return Input.Type(Args.Str(r, "text", ""), Args.Int(r, "chunkDelay", 8));
|
|
@@ -316,7 +318,12 @@ namespace DshComputerUse
|
|
|
316
318
|
}
|
|
317
319
|
|
|
318
320
|
/** Sample every 8th pixel of a screen rectangle (BGR bytes). */
|
|
319
|
-
|
|
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)
|
|
320
327
|
{
|
|
321
328
|
using (var bmp = new Bitmap(w, h, PixelFormat.Format24bppRgb))
|
|
322
329
|
{
|
|
@@ -324,8 +331,12 @@ namespace DshComputerUse
|
|
|
324
331
|
{
|
|
325
332
|
IntPtr dst = g.GetHdc();
|
|
326
333
|
IntPtr src = Native.GetDC(IntPtr.Zero);
|
|
327
|
-
|
|
328
|
-
|
|
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);
|
|
329
340
|
}
|
|
330
341
|
var data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
|
|
331
342
|
try
|
|
@@ -354,7 +365,7 @@ namespace DshComputerUse
|
|
|
354
365
|
public static void Mark(Dictionary<string, object> r)
|
|
355
366
|
{
|
|
356
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);
|
|
357
|
-
marked = Sample(x, y, w, h);
|
|
368
|
+
marked = Sample(x, y, w, h, true);
|
|
358
369
|
markedRect = RectKey(x, y, w, h);
|
|
359
370
|
}
|
|
360
371
|
|
|
@@ -363,7 +374,7 @@ namespace DshComputerUse
|
|
|
363
374
|
{
|
|
364
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);
|
|
365
376
|
var d = new Dictionary<string, object>();
|
|
366
|
-
d["diff"] = marked == null || markedRect != RectKey(x, y, w, h) ? -1.0 : Changed(marked, Sample(x, y, w, h));
|
|
377
|
+
d["diff"] = marked == null || markedRect != RectKey(x, y, w, h) ? -1.0 : Changed(marked, Sample(x, y, w, h, true));
|
|
367
378
|
return d;
|
|
368
379
|
}
|
|
369
380
|
|
|
@@ -386,13 +397,13 @@ namespace DshComputerUse
|
|
|
386
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);
|
|
387
398
|
if (w <= 0 || h <= 0) throw new Exception("invalid settle rect");
|
|
388
399
|
var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
389
|
-
byte[] prev = Sample(x, y, w, h);
|
|
400
|
+
byte[] prev = Sample(x, y, w, h, false);
|
|
390
401
|
long quietSince = -1;
|
|
391
402
|
bool stable = false;
|
|
392
403
|
while (true)
|
|
393
404
|
{
|
|
394
405
|
Thread.Sleep(interval);
|
|
395
|
-
byte[] cur = Sample(x, y, w, h);
|
|
406
|
+
byte[] cur = Sample(x, y, w, h, false);
|
|
396
407
|
long now = watch.ElapsedMilliseconds;
|
|
397
408
|
if (Changed(prev, cur) < 0.002) { if (quietSince < 0) quietSince = now - interval; }
|
|
398
409
|
else quietSince = -1;
|
|
@@ -420,8 +431,12 @@ namespace DshComputerUse
|
|
|
420
431
|
{
|
|
421
432
|
IntPtr dst = g.GetHdc();
|
|
422
433
|
IntPtr src = Native.GetDC(IntPtr.Zero);
|
|
423
|
-
|
|
424
|
-
|
|
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
|
+
}
|
|
425
440
|
}
|
|
426
441
|
Bitmap output = bmp;
|
|
427
442
|
Bitmap scaled = null;
|
|
@@ -770,6 +785,108 @@ namespace DshComputerUse
|
|
|
770
785
|
}
|
|
771
786
|
}
|
|
772
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
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
773
890
|
internal static class Windows
|
|
774
891
|
{
|
|
775
892
|
public static string ExePath(uint pid)
|
|
@@ -838,7 +955,8 @@ namespace DshComputerUse
|
|
|
838
955
|
if (h != IntPtr.Zero) h = Native.GetAncestor(h, 2); // GA_ROOT
|
|
839
956
|
uint pid = 0;
|
|
840
957
|
if (h != IntPtr.Zero) Native.GetWindowThreadProcessId(h, out pid);
|
|
841
|
-
|
|
958
|
+
uint cardPid = CardLayer.Pid();
|
|
959
|
+
if (h == IntPtr.Zero || pid == (uint)Process.GetCurrentProcess().Id || (cardPid != 0 && pid == cardPid))
|
|
842
960
|
{
|
|
843
961
|
// Our own status pill is under the point (it dodges before the
|
|
844
962
|
// click): report the topmost foreign window there instead.
|
|
@@ -848,8 +966,9 @@ namespace DshComputerUse
|
|
|
848
966
|
{
|
|
849
967
|
if (!Native.IsWindowVisible(w)) return true;
|
|
850
968
|
uint p; Native.GetWindowThreadProcessId(w, out p);
|
|
851
|
-
if (p == self) return true;
|
|
969
|
+
if (p == self || (cardPid != 0 && p == cardPid)) return true; // our overlay, the DSH card
|
|
852
970
|
if ((Native.GetWindowLong(w, -20) & 0x20) != 0) return true; // WS_EX_TRANSPARENT
|
|
971
|
+
if (Native.IsIconic(w)) return true;
|
|
853
972
|
int cloaked;
|
|
854
973
|
if (Native.DwmGetWindowAttribute(w, 14, out cloaked, 4) == 0 && cloaked != 0) return true;
|
|
855
974
|
Native.RECT rc; Native.GetWindowRect(w, out rc);
|
|
@@ -901,6 +1020,15 @@ namespace DshComputerUse
|
|
|
901
1020
|
Native.SendInput(3, inputs, Marshal.SizeOf(typeof(Native.INPUT)));
|
|
902
1021
|
Thread.Sleep(120);
|
|
903
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
|
+
}
|
|
904
1032
|
}
|
|
905
1033
|
var d = Describe(hwnd);
|
|
906
1034
|
d["focused"] = Native.GetForegroundWindow() == hwnd;
|
|
@@ -913,6 +1041,7 @@ namespace DshComputerUse
|
|
|
913
1041
|
public static object Card(IntPtr hwnd, int x, int y, int w, int h)
|
|
914
1042
|
{
|
|
915
1043
|
if (!Native.IsWindow(hwnd)) throw new Exception("window no longer exists");
|
|
1044
|
+
CardLayer.Attach(hwnd);
|
|
916
1045
|
if (!cards.ContainsKey(hwnd.ToInt64()))
|
|
917
1046
|
{
|
|
918
1047
|
var wp = new Native.WINDOWPLACEMENT();
|
|
@@ -935,6 +1064,7 @@ namespace DshComputerUse
|
|
|
935
1064
|
|
|
936
1065
|
public static object Uncard(IntPtr hwnd)
|
|
937
1066
|
{
|
|
1067
|
+
if (CardLayer.Hwnd == hwnd) CardLayer.Detach();
|
|
938
1068
|
Native.WINDOWPLACEMENT wp;
|
|
939
1069
|
bool known = cards.TryGetValue(hwnd.ToInt64(), out wp);
|
|
940
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
|
}
|
|
@@ -534,12 +543,10 @@ var Computer = class Computer {
|
|
|
534
543
|
async point(coordinate, field = "coordinate") {
|
|
535
544
|
if (!Array.isArray(coordinate) || coordinate.length !== 2) throw new Error(`${field} must be [x, y] in screenshot pixels.`);
|
|
536
545
|
const display = await this.display();
|
|
537
|
-
|
|
546
|
+
return toPhysical({
|
|
538
547
|
x: coordinate[0],
|
|
539
548
|
y: coordinate[1]
|
|
540
549
|
}, display, this.shotSize(display));
|
|
541
|
-
await this.overlay.dodgeCard(p);
|
|
542
|
-
return p;
|
|
543
550
|
}
|
|
544
551
|
async toModel(point) {
|
|
545
552
|
const display = await this.display();
|
|
@@ -630,7 +637,7 @@ var Computer = class Computer {
|
|
|
630
637
|
async foreground() {
|
|
631
638
|
const win = await this.helper.call("foreground");
|
|
632
639
|
if (!win || typeof win.hwnd !== "number") return void 0;
|
|
633
|
-
if (!isHostWindow(win)) this.lastTarget = win;
|
|
640
|
+
if (!isHostWindow(win) && !isTransientShell(win)) this.lastTarget = win;
|
|
634
641
|
return win;
|
|
635
642
|
}
|
|
636
643
|
/**
|
|
@@ -641,7 +648,7 @@ var Computer = class Computer {
|
|
|
641
648
|
async refocusFromHost() {
|
|
642
649
|
const target = this.lastTarget;
|
|
643
650
|
const fg = await this.foreground().catch(() => void 0);
|
|
644
|
-
if (!fg || !isHostWindow(fg) || !target || target.hwnd === fg.hwnd) return;
|
|
651
|
+
if (!fg || !(isHostWindow(fg) || isTransientShell(fg)) || !target || target.hwnd === fg.hwnd) return;
|
|
645
652
|
if ((await this.focus(target).catch(() => void 0))?.focused) await setTimeout$1(80);
|
|
646
653
|
}
|
|
647
654
|
/** Wait until the screen stops changing (bounded), instead of a fixed delay. */
|
|
@@ -727,7 +734,7 @@ var Computer = class Computer {
|
|
|
727
734
|
}
|
|
728
735
|
if (s.pauseOnUserInput && INPUT.has(action)) {
|
|
729
736
|
const changed = await this.foregroundChanged();
|
|
730
|
-
if (changed && !isHostWindow(changed)) {
|
|
737
|
+
if (changed && !isHostWindow(changed) && !isTransientShell(changed)) {
|
|
731
738
|
await this.overlay.status("检测到窗口切换,重新查看屏幕");
|
|
732
739
|
const image = call.vision ? await this.screenshot() : void 0;
|
|
733
740
|
if (!image) this.seen = changed;
|
|
@@ -1148,8 +1155,6 @@ var OverlayController = class {
|
|
|
1148
1155
|
visible = false;
|
|
1149
1156
|
idleTimer;
|
|
1150
1157
|
hostWindows = [];
|
|
1151
|
-
/** The floating card and the display it lives on, while carded. */
|
|
1152
|
-
card;
|
|
1153
1158
|
stopping = false;
|
|
1154
1159
|
/** Paused by Esc or the pill; actions wait until resumed. */
|
|
1155
1160
|
paused = false;
|
|
@@ -1283,48 +1288,22 @@ var OverlayController = class {
|
|
|
1283
1288
|
hwnd: main.hwnd,
|
|
1284
1289
|
mode: "card"
|
|
1285
1290
|
}];
|
|
1286
|
-
this.card = {
|
|
1287
|
-
hwnd: main.hwnd,
|
|
1288
|
-
display
|
|
1289
|
-
};
|
|
1290
1291
|
} catch (error) {
|
|
1291
1292
|
this.log(`host window ${mode}: ${String(error)}`);
|
|
1292
1293
|
}
|
|
1293
1294
|
}
|
|
1294
|
-
/**
|
|
1295
|
-
* The agent is about to point at something under the card: move the card to
|
|
1296
|
-
* the opposite bottom corner so the target is visible and clickable.
|
|
1297
|
-
* Returns whether it moved.
|
|
1298
|
-
*/
|
|
1299
|
-
async dodgeCard(point) {
|
|
1300
|
-
const card = this.card;
|
|
1301
|
-
if (!card) return false;
|
|
1302
|
-
try {
|
|
1303
|
-
const win = await this.helper.call("window_at", { ...point });
|
|
1304
|
-
if (!win || win.hwnd !== card.hwnd) return false;
|
|
1305
|
-
const d = card.display;
|
|
1306
|
-
const margin = Math.round(16 * d.dpi / 96);
|
|
1307
|
-
const x = win.x + win.width / 2 > d.workX + d.workWidth / 2 ? d.workX + margin : d.workX + d.workWidth - win.width - margin;
|
|
1308
|
-
await this.helper.call("window_card", {
|
|
1309
|
-
hwnd: card.hwnd,
|
|
1310
|
-
x,
|
|
1311
|
-
y: win.y,
|
|
1312
|
-
width: win.width,
|
|
1313
|
-
height: win.height
|
|
1314
|
-
});
|
|
1315
|
-
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
1316
|
-
return true;
|
|
1317
|
-
} catch (error) {
|
|
1318
|
-
this.log(`card dodge: ${String(error)}`);
|
|
1319
|
-
return false;
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
1295
|
async restoreHost() {
|
|
1323
1296
|
const windows = this.hostWindows;
|
|
1324
1297
|
this.hostWindows = [];
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
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", {
|
|
1328
1307
|
hwnd: win.hwnd,
|
|
1329
1308
|
op: "restore"
|
|
1330
1309
|
}).catch(() => {});
|
|
@@ -1337,8 +1316,9 @@ function promptText(mode) {
|
|
|
1337
1316
|
You can see and operate the user's Windows computer with the computer, computer_batch, open_application, windows, ui_elements and clipboard tools.
|
|
1338
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.
|
|
1339
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.
|
|
1340
|
-
- The "DeepSeek Harness.exe" window is your own chat interface
|
|
1341
|
-
-
|
|
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).
|
|
1342
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.
|
|
1343
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.
|
|
1344
1324
|
- Office apps: F12 opens the classic Save As dialog, where you can type a full path in the file name box.
|
|
@@ -7320,7 +7300,7 @@ function createTools(host) {
|
|
|
7320
7300
|
for (let i = 0; i < 32; i++) {
|
|
7321
7301
|
await setTimeout$1(250, void 0, { signal: call.signal });
|
|
7322
7302
|
const now = await computer.foreground();
|
|
7323
|
-
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;
|
|
7324
7304
|
}
|
|
7325
7305
|
}
|
|
7326
7306
|
const fg = await computer.foreground();
|
|
@@ -7362,11 +7342,11 @@ function createTools(host) {
|
|
|
7362
7342
|
const { action, hwnd, name } = args;
|
|
7363
7343
|
const rows = await computer.windows();
|
|
7364
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." };
|
|
7365
|
-
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;
|
|
7366
7346
|
if (!target) throw new Error("Window not found; call windows with action \"list\".");
|
|
7367
7347
|
const settings = computer.settings();
|
|
7368
7348
|
const denial = computer.access.denial(call.session, target, settings.accessMode, settings.blockedApps, action);
|
|
7369
|
-
if (denial &&
|
|
7349
|
+
if (denial && action !== "minimize") throw new Error(denial);
|
|
7370
7350
|
await computer.overlay.begin(call.agent, `窗口 ${action}`);
|
|
7371
7351
|
await computer.overlay.yieldToUser(call.signal, false);
|
|
7372
7352
|
let text;
|
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/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