@copylee/dsh-computer-use 0.1.9 → 0.1.10

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 CHANGED
@@ -12,7 +12,7 @@
12
12
  | 按应用授权 | 先 `request_access` 列出要操控的应用,经 DSH 原生审批后才能操作;也可改为“全部允许” |
13
13
  | 不会操作自己 | 永远拒绝向 DeepSeek Harness 自身窗口输入;常见密码管理器默认禁止,可再自定义禁用列表 |
14
14
  | 正在控制的提示 | 橙色光晕 + 胶囊提示条(显示当前动作),**不会出现在截图里** |
15
- | 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 / 最小化状态(也可选最小化或不动)。卡片只给你看:AI 的截图里看到的是卡片下面的内容(每次截图时卡片会透明约 20 毫秒,每个动作只截一次),点击和滚动也直接穿透卡片,卡片不会挪位置 |
15
+ | 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 / 最小化状态(也可选最小化或不动)。卡片只给你看:AI 的截图里看到的是卡片下面的内容(通过 Windows 放大镜接口截图时把卡片排除在外,不闪烁;该接口不可用时退回为截图瞬间让卡片透明约 20 毫秒),点击和滚动也直接穿透卡片,卡片不会挪位置 |
16
16
  | 暂停与停止 | 你亲手按 **Esc** 暂停(AI 停在下一步之前),再按 Esc 或点“继续”恢复,对话不会被中断;点“停止”才结束本轮。插件自己发出的 Esc 不会误触发 |
17
17
  | 你随时可以插手 | 你用键盘打字时 AI 自动暂停,停手 1.5 秒后继续(单按 Shift / Ctrl 等修饰键不算);你切换或打开了别的窗口,AI 下一步不会盲目执行,而是先看新截图再决定。你只是点进 DSH 卡片看对话时不算切换,AI 的按键会自动回到它正在操作的窗口。鼠标移动不会触发,避免误触 |
18
18
  | 中文输入 | Unicode 直接输入,不受输入法状态影响;长文本走剪贴板粘贴,剪贴板文本统一为 CRLF,粘贴到 Obsidian 等应用不丢换行 |
@@ -412,19 +412,38 @@ namespace DshComputerUse
412
412
  int ow = Args.Int(r, "outWidth", w), oh = Args.Int(r, "outHeight", h);
413
413
  int quality = Args.Int(r, "quality", 80);
414
414
  if (w <= 0 || h <= 0 || ow <= 0 || oh <= 0) throw new Exception("invalid capture size");
415
+ string via = "blt";
415
416
  using (var bmp = new Bitmap(w, h, PixelFormat.Format24bppRgb))
416
417
  {
417
418
  using (var g = Graphics.FromImage(bmp))
418
419
  {
419
420
  IntPtr dst = g.GetHdc();
420
421
  IntPtr src = Native.GetDC(IntPtr.Zero);
421
- // The DSH card is for the user only: capture what is under it
422
- // (it blinks out for the duration of this one BitBlt).
423
- using (CardLayer.Hide(new Rectangle(x, y, w, h)))
422
+ // The DSH card is for the user only: capture what is under it.
423
+ // Preferred: the Magnification API renders the screen without
424
+ // the card (no flicker). Fallback: hide the card for one BitBlt.
425
+ bool done = false;
426
+ var area = new Rectangle(x, y, w, h);
427
+ via = "blt";
428
+ if (CardLayer.Covers(area))
424
429
  {
425
- try { Native.BitBlt(dst, 0, 0, w, h, src, x, y, 0x00CC0020 | 0x40000000); }
426
- finally { Native.ReleaseDC(IntPtr.Zero, src); g.ReleaseHdc(dst); }
430
+ g.ReleaseHdc(dst);
431
+ dst = IntPtr.Zero;
432
+ using (var mag = MagCapture.Capture(area, CardLayer.Hwnd))
433
+ {
434
+ if (mag != null) { g.DrawImageUnscaled(mag, 0, 0); done = true; via = "mag"; }
435
+ }
436
+ if (!done) dst = g.GetHdc();
437
+ }
438
+ if (!done)
439
+ {
440
+ using (CardLayer.Hide(area))
441
+ {
442
+ try { Native.BitBlt(dst, 0, 0, w, h, src, x, y, 0x00CC0020 | 0x40000000); }
443
+ finally { g.ReleaseHdc(dst); }
444
+ }
427
445
  }
446
+ Native.ReleaseDC(IntPtr.Zero, src);
428
447
  }
429
448
  // compare: report "unchanged" instead of an identical image; mark: remember for next time.
430
449
  bool compare = Args.Bool(r, "compare", false), mark = Args.Bool(r, "mark", false) || compare;
@@ -468,6 +487,7 @@ namespace DshComputerUse
468
487
  output.Save(ms, jpegCodec, ep);
469
488
  var d = new Dictionary<string, object>();
470
489
  d["data"] = Convert.ToBase64String(ms.ToArray());
490
+ d["via"] = via == "blt" && MagCapture.Why.Length > 0 ? "blt (" + MagCapture.Why + ")" : via;
471
491
  d["width"] = ow; d["height"] = oh;
472
492
  return d;
473
493
  }
@@ -845,6 +865,15 @@ namespace DshComputerUse
845
865
  g.FillRectangle(Brushes.Black, r.X - ox, r.Y - oy, r.Width, r.Height);
846
866
  }
847
867
 
868
+ /** Is the card visible over (any part of) this screen rectangle? */
869
+ public static bool Covers(Rectangle area)
870
+ {
871
+ if (!Live()) return false;
872
+ var r = Frame(Hwnd);
873
+ r.Inflate(32, 32);
874
+ return r.IntersectsWith(area);
875
+ }
876
+
848
877
  /** Make the card invisible while a capture of `area` runs (dispose to show it again). */
849
878
  public static IDisposable Hide(Rectangle area)
850
879
  {
@@ -869,6 +898,102 @@ namespace DshComputerUse
869
898
  }
870
899
  }
871
900
 
901
+ /**
902
+ * Screen capture through the Windows Magnification API, which can leave
903
+ * out windows of other processes (MagSetWindowFilterList). The magnifier
904
+ * control lives in a never-shown host window; MagSetWindowSource renders
905
+ * synchronously into the scaling callback. Any failure disables it for the
906
+ * rest of the run and callers fall back to BitBlt.
907
+ */
908
+ internal static class MagCapture
909
+ {
910
+ [StructLayout(LayoutKind.Sequential)]
911
+ public struct MAGIMAGEHEADER { public uint width; public uint height; public Guid format; public uint stride; public uint offset; public UIntPtr cbSize; }
912
+
913
+ delegate bool ScalingCallback(IntPtr hwnd, IntPtr srcdata, MAGIMAGEHEADER srcheader, IntPtr destdata, MAGIMAGEHEADER destheader, Native.RECT unclipped, Native.RECT clipped, IntPtr dirty);
914
+
915
+ [DllImport("Magnification.dll")] static extern bool MagInitialize();
916
+ [DllImport("Magnification.dll")] static extern bool MagSetWindowSource(IntPtr hwnd, Native.RECT rect);
917
+ [DllImport("Magnification.dll")] static extern bool MagSetWindowFilterList(IntPtr hwnd, int mode, int count, IntPtr[] list);
918
+ [DllImport("Magnification.dll")] static extern bool MagSetImageScalingCallback(IntPtr hwnd, ScalingCallback cb);
919
+ [DllImport("user32.dll", CharSet = CharSet.Unicode)]
920
+ static extern IntPtr CreateWindowEx(int ex, string cls, string name, int style, int x, int y, int w, int h, IntPtr parent, IntPtr menu, IntPtr inst, IntPtr param);
921
+
922
+ static bool broken;
923
+ public static string Why = "";
924
+ static Form host;
925
+ static IntPtr magnifier = IntPtr.Zero;
926
+ static ScalingCallback callback;
927
+ static Bitmap frame;
928
+
929
+ static bool Ready()
930
+ {
931
+ if (broken) return false;
932
+ if (magnifier != IntPtr.Zero) return true;
933
+ try
934
+ {
935
+ if (!MagInitialize()) { broken = true; Why = "init"; return false; }
936
+ host = new Form { FormBorderStyle = FormBorderStyle.None, ShowInTaskbar = false, StartPosition = FormStartPosition.Manual, Location = new Point(0, 0), Size = new Size(16, 16) };
937
+ IntPtr parent = host.Handle; // created, never shown
938
+ magnifier = CreateWindowEx(0, "Magnifier", "cu-magnifier", 0x40000000 | 0x10000000, 0, 0, 16, 16, parent, IntPtr.Zero, Native.GetModuleHandle(null), IntPtr.Zero);
939
+ callback = OnImage;
940
+ if (magnifier == IntPtr.Zero || !MagSetImageScalingCallback(magnifier, callback)) { broken = true; Why = "callback"; return false; }
941
+ return true;
942
+ }
943
+ catch (Exception e) { broken = true; Why = "ready: " + e.Message; return false; }
944
+ }
945
+
946
+ /** The screen rectangle without the `exclude` window, or null when unavailable. */
947
+ public static Bitmap Capture(Rectangle area, IntPtr exclude)
948
+ {
949
+ if (!Ready()) return null;
950
+ try
951
+ {
952
+ // The never-shown host must be as large as the capture, or the control is clipped.
953
+ Native.SetWindowPos(host.Handle, IntPtr.Zero, 0, 0, area.Width, area.Height, 0x0004 | 0x0010);
954
+ Native.SetWindowPos(magnifier, IntPtr.Zero, 0, 0, area.Width, area.Height, 0x0004 | 0x0010); // NOZORDER | NOACTIVATE
955
+ if (!MagSetWindowFilterList(magnifier, 0 /* MW_FILTERMODE_EXCLUDE */, 1, new[] { exclude })) { broken = true; Why = "filter"; return null; }
956
+ frame = null;
957
+ var rc = new Native.RECT { Left = area.Left, Top = area.Top, Right = area.Right, Bottom = area.Bottom };
958
+ if (!MagSetWindowSource(magnifier, rc)) { broken = true; Why = "source"; return null; }
959
+ var result = frame;
960
+ frame = null;
961
+ if (result == null || result.Width != area.Width || result.Height != area.Height)
962
+ {
963
+ Why = result == null ? "no frame" : "size " + result.Width + "x" + result.Height;
964
+ if (result != null) result.Dispose();
965
+ broken = true;
966
+ return null;
967
+ }
968
+ return result;
969
+ }
970
+ catch (Exception e) { broken = true; Why = "capture: " + e.Message; return null; }
971
+ }
972
+
973
+ static bool OnImage(IntPtr hwnd, IntPtr srcdata, MAGIMAGEHEADER h, IntPtr destdata, MAGIMAGEHEADER dh, Native.RECT unclipped, Native.RECT clipped, IntPtr dirty)
974
+ {
975
+ try
976
+ {
977
+ var bmp = new Bitmap((int)h.width, (int)h.height, PixelFormat.Format32bppRgb);
978
+ var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
979
+ try
980
+ {
981
+ int rowBytes = (int)h.width * 4;
982
+ var row = new byte[rowBytes];
983
+ for (int y = 0; y < h.height; y++)
984
+ {
985
+ Marshal.Copy(new IntPtr(srcdata.ToInt64() + h.offset + (long)y * h.stride), row, 0, rowBytes);
986
+ Marshal.Copy(row, 0, new IntPtr(data.Scan0.ToInt64() + (long)y * data.Stride), rowBytes);
987
+ }
988
+ }
989
+ finally { bmp.UnlockBits(data); }
990
+ frame = bmp;
991
+ }
992
+ catch (Exception) { frame = null; }
993
+ return true;
994
+ }
995
+ }
996
+
872
997
  /** While the agent moves, clicks or scrolls, the card lets the mouse through. */
873
998
  internal sealed class PassThrough : IDisposable
874
999
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "type": "module",
6
6
  "author": "copylee",