@copylee/dsh-computer-use 0.1.2 → 0.1.3

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@copylee/dsh-computer-use)](https://www.npmjs.com/package/@copylee/dsh-computer-use)
4
4
 
5
- 让 DeepSeek Harness 直接操控你的 Windows 电脑:看屏幕、点鼠标、敲键盘,打开应用、切换窗口、读写剪贴板。控制期间屏幕四周会泛起**橙色光晕**,顶部出现“**DeepSeek 正在使用你的电脑**”提示条,按 **Esc** 或点“停止”立即中断。
5
+ 让 DeepSeek Harness 直接操控你的 Windows 电脑:看屏幕、点鼠标、敲键盘,打开应用、切换窗口、读写剪贴板。控制期间屏幕四周会泛起**橙色光晕**,顶部出现“**DeepSeek Harness 正在操控你的电脑**”提示条,DeepSeek Harness 自己缩成右下角的置顶悬浮卡片,让你同时看到操作过程和 AI 的输出。按 **Esc** 暂停 / 继续,点“停止”结束本轮。
6
6
 
7
7
  | 功能 | 说明 |
8
8
  |---|---|
@@ -11,9 +11,12 @@
11
11
  | 批量动作 | `computer_batch` 一次执行“点输入框 → 输入 → 回车”等多步,最后只截一张图 |
12
12
  | 按应用授权 | 先 `request_access` 列出要操控的应用,经 DSH 原生审批后才能操作;也可改为“全部允许” |
13
13
  | 不会操作自己 | 永远拒绝向 DeepSeek Harness 自身窗口输入;常见密码管理器默认禁止,可再自定义禁用列表 |
14
- | 正在控制的提示 | 橙色光晕 + 胶囊提示条(显示当前动作),**不会出现在截图里**;真实按下的 Esc 才算停止,插件自己发的 Esc 不会误触发 |
14
+ | 正在控制的提示 | 橙色光晕 + 胶囊提示条(显示当前动作),**不会出现在截图里** |
15
+ | 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 / 最小化状态(也可选最小化或不动) |
16
+ | 暂停与停止 | 你亲手按 **Esc** 暂停(AI 停在下一步之前),再按 Esc 或点“继续”恢复,对话不会被中断;点“停止”才结束本轮。插件自己发出的 Esc 不会误触发 |
15
17
  | 你随时可以插手 | 你用键盘打字时 AI 自动暂停,停手 1.5 秒后继续;你切换或打开了别的窗口,AI 下一步不会盲目执行,而是先看新截图再决定。鼠标移动不会触发,避免误触 |
16
- | 中文输入 | Unicode 直接输入,不受输入法状态影响;长文本走剪贴板并自动恢复原剪贴板 |
18
+ | 中文输入 | Unicode 直接输入,不受输入法状态影响;长文本走剪贴板并自动恢复原剪贴板;剪贴板文本统一为 CRLF,粘贴到 Obsidian 等应用不丢换行 |
19
+ | 打开应用 | `open_application` 同时搜索开始菜单和桌面快捷方式(含公共桌面),便携软件也能按名字打开 |
17
20
  | 看不见图的模型 | `ui_elements` 用 Windows UI Automation 列出可点击元素和坐标,纯文本模型也能用 |
18
21
  | 零原生依赖 | 首次使用时用 Windows 自带的 .NET Framework `csc.exe` 编译一个小 helper(约 1 秒,之后缓存),不需要 node-gyp、不受 Electron ABI 影响 |
19
22
 
@@ -41,7 +44,7 @@ dsh plugin --profile web add @copylee/dsh-computer-use@latest
41
44
 
42
45
  按应用授权模式下,模型会先请求操控对应应用,你在 DSH 里批准即可。会话权限为“完全权限”或“自动审查”(不弹审批)时,请求会被自动批准,但 DeepSeek Harness 自身和禁用列表里的应用仍然不可操作。
43
46
 
44
- **随时按 Esc 停止**,或点提示条上的“停止”。想临时帮一把也可以直接上手:打字时 AI 会等你,切到别的窗口后 AI 会先重新看屏幕。
47
+ **随时按 Esc 暂停**,再按一次继续;点提示条上的“停止”结束本轮。想临时帮一把也可以直接上手:打字时提示条显示“你正在操作,已暂停”,AI 会等你停手;切到别的窗口后 AI 会先重新看屏幕。
45
48
 
46
49
  ## Agent 工具
47
50
 
@@ -64,8 +67,8 @@ dsh plugin --profile web add @copylee/dsh-computer-use@latest
64
67
  |---|---|---|
65
68
  | 授权方式 | 按应用授权 | 或“全部允许” |
66
69
  | 光晕与提示条 | 开 | 控制时显示橙色边框和提示条 |
67
- | 提示条名称 | DeepSeek | 显示为“<名称> 正在使用你的电脑” |
68
- | 控制期间最小化 DSH | 关 | 开启后控制时最小化 DSH 窗口,结束后恢复 |
70
+ | 提示条名称 | DeepSeek Harness | 显示为“<名称> 正在操控你的电脑” |
71
+ | 操控期间 DSH 窗口 | 悬浮卡片 | 悬浮卡片 / 最小化 / 保持不变,结束后自动恢复 |
69
72
  | 操作后自动截图 | 开 | 关闭可省 token,但模型需要自己截图 |
70
73
  | 等待稳定 | 400 ms | 动作后多久再截图 |
71
74
  | 截图最长边 / 总像素 / JPEG 质量 | 1366 / 1.15MP / 80 | 越大越清晰、越费 token |
@@ -92,6 +92,10 @@ namespace DshComputerUse
92
92
  [DllImport("user32.dll")] public static extern IntPtr GetAncestor(IntPtr hwnd, uint flags);
93
93
  [DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr hwnd, IntPtr after, int x, int y, int w, int h, uint flags);
94
94
  [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hwnd, out RECT r);
95
+ [StructLayout(LayoutKind.Sequential)]
96
+ public struct WINDOWPLACEMENT { public int length; public int flags; public int showCmd; public POINT ptMinPosition; public POINT ptMaxPosition; public RECT rcNormalPosition; }
97
+ [DllImport("user32.dll")] public static extern bool GetWindowPlacement(IntPtr hwnd, ref WINDOWPLACEMENT wp);
98
+ [DllImport("user32.dll")] public static extern bool SetWindowPlacement(IntPtr hwnd, ref WINDOWPLACEMENT wp);
95
99
  [DllImport("dwmapi.dll")] public static extern int DwmGetWindowAttribute(IntPtr hwnd, int attr, out RECT value, int size);
96
100
  [DllImport("dwmapi.dll")] public static extern int DwmGetWindowAttribute(IntPtr hwnd, int attr, out int value, int size);
97
101
 
@@ -266,7 +270,10 @@ namespace DshComputerUse
266
270
  case "clipboard_get": { var d = new Dictionary<string, object>(); d["text"] = Clip.Get(); return d; }
267
271
  case "clipboard_set": Clip.Set(Args.Str(r, "text", "")); return null;
268
272
  case "ui": return Uia.Elements(r);
269
- case "overlay_show": Overlay.ExcludeFromCapture = Args.Bool(r, "excludeFromCapture", true); Overlay.Show(Args.Str(r, "label", ""), Args.Str(r, "status", ""), Args.Bool(r, "glow", true)); return null;
273
+ case "overlay_show": Overlay.ExcludeFromCapture = Args.Bool(r, "excludeFromCapture", true); Overlay.Show(r); return null;
274
+ case "overlay_pause": Overlay.SetPaused(Args.Bool(r, "paused", false)); return null;
275
+ case "window_card": return Windows.Card(new IntPtr(Convert.ToInt64(r["hwnd"])), Args.Int(r, "x", 0), Args.Int(r, "y", 0), Args.Int(r, "width", 0), Args.Int(r, "height", 0));
276
+ case "window_uncard": return Windows.Uncard(new IntPtr(Convert.ToInt64(r["hwnd"])));
270
277
  case "overlay_status": Overlay.Status(Args.Str(r, "status", "")); return null;
271
278
  case "overlay_hide": Overlay.Hide(); return null;
272
279
  default: throw new Exception("unknown command: " + cmd);
@@ -566,6 +573,7 @@ namespace DshComputerUse
566
573
 
567
574
  public static void Set(string text)
568
575
  {
576
+ if (!string.IsNullOrEmpty(text)) text = text.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n");
569
577
  for (int i = 0; i < 5; i++)
570
578
  {
571
579
  try
@@ -716,6 +724,51 @@ namespace DshComputerUse
716
724
  return d;
717
725
  }
718
726
 
727
+ static readonly Dictionary<long, Native.WINDOWPLACEMENT> cards = new Dictionary<long, Native.WINDOWPLACEMENT>();
728
+
729
+ /// Shrink a window into an always-on-top card; Uncard restores it exactly.
730
+ public static object Card(IntPtr hwnd, int x, int y, int w, int h)
731
+ {
732
+ if (!Native.IsWindow(hwnd)) throw new Exception("window no longer exists");
733
+ if (!cards.ContainsKey(hwnd.ToInt64()))
734
+ {
735
+ var wp = new Native.WINDOWPLACEMENT();
736
+ wp.length = Marshal.SizeOf(typeof(Native.WINDOWPLACEMENT));
737
+ Native.GetWindowPlacement(hwnd, ref wp);
738
+ cards[hwnd.ToInt64()] = wp;
739
+ }
740
+ // A minimized window restores to its previous state, which may be maximized: restore until normal.
741
+ for (int i = 0; i < 2 && (Native.IsIconic(hwnd) || Native.IsZoomed(hwnd)); i++) { Native.ShowWindow(hwnd, 9); Thread.Sleep(150); }
742
+ Native.SetWindowPos(hwnd, new IntPtr(-1), x, y, w, h, 0x0010 | 0x0040); // TOPMOST, NOACTIVATE | SHOWWINDOW
743
+ // Apps enforce a minimum size (Electron does): keep the card anchored bottom-right.
744
+ Native.RECT rc;
745
+ if (Native.GetWindowRect(hwnd, out rc) && (rc.Right - rc.Left != w || rc.Bottom - rc.Top != h))
746
+ {
747
+ int nx = x + w - (rc.Right - rc.Left), ny = y + h - (rc.Bottom - rc.Top);
748
+ Native.SetWindowPos(hwnd, new IntPtr(-1), nx, ny, 0, 0, 0x0001 | 0x0010); // NOSIZE | NOACTIVATE
749
+ }
750
+ return Describe(hwnd);
751
+ }
752
+
753
+ public static object Uncard(IntPtr hwnd)
754
+ {
755
+ Native.WINDOWPLACEMENT wp;
756
+ bool known = cards.TryGetValue(hwnd.ToInt64(), out wp);
757
+ cards.Remove(hwnd.ToInt64());
758
+ if (!Native.IsWindow(hwnd)) return null;
759
+ Native.SetWindowPos(hwnd, new IntPtr(-2), 0, 0, 0, 0, 0x0001 | 0x0002 | 0x0010); // NOTOPMOST
760
+ if (known)
761
+ {
762
+ // Restore the normal rectangle first, then the original show state (maximized etc.).
763
+ int show = wp.showCmd;
764
+ wp.showCmd = 1; // SW_SHOWNORMAL
765
+ Native.SetWindowPlacement(hwnd, ref wp);
766
+ if (show == 3) Native.ShowWindow(hwnd, 3);
767
+ else if (show == 2) Native.ShowWindow(hwnd, 6);
768
+ }
769
+ return Describe(hwnd);
770
+ }
771
+
719
772
  public static object Command(IntPtr hwnd, string op)
720
773
  {
721
774
  if (!Native.IsWindow(hwnd)) throw new Exception("window no longer exists");
@@ -753,6 +806,17 @@ namespace DshComputerUse
753
806
  }
754
807
  }
755
808
  finally { Marshal.FinalReleaseComObject(shell); }
809
+ // Desktop shortcuts too: portable apps often only live there.
810
+ foreach (var folder in new[] { Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory) })
811
+ {
812
+ try
813
+ {
814
+ if (folder.Length == 0 || !Directory.Exists(folder)) continue;
815
+ foreach (var f in Directory.GetFiles(folder, "*.lnk"))
816
+ list.Add(new KeyValuePair<string, string>(Path.GetFileNameWithoutExtension(f), "lnk:" + f));
817
+ }
818
+ catch (Exception) { }
819
+ }
756
820
  cache = list; cachedAt = DateTime.UtcNow;
757
821
  return list;
758
822
  }
@@ -785,7 +849,8 @@ namespace DshComputerUse
785
849
  string target = Args.Str(r, "target", "");
786
850
  string args = Args.Str(r, "args", "");
787
851
  ProcessStartInfo psi;
788
- if (appId.Length > 0) psi = new ProcessStartInfo("explorer.exe", "shell:AppsFolder\\" + appId);
852
+ if (appId.StartsWith("lnk:")) psi = new ProcessStartInfo(appId.Substring(4));
853
+ else if (appId.Length > 0) psi = new ProcessStartInfo("explorer.exe", "shell:AppsFolder\\" + appId);
789
854
  else { psi = new ProcessStartInfo(target); if (args.Length > 0) psi.Arguments = args; }
790
855
  psi.UseShellExecute = true;
791
856
  using (var p = Process.Start(psi)) { }
@@ -958,15 +1023,21 @@ namespace DshComputerUse
958
1023
  static Control invoker;
959
1024
  static readonly List<LayeredForm> glows = new List<LayeredForm>();
960
1025
  static LayeredForm pill;
961
- static Rectangle pillRect, stopRect, pillDisplay;
1026
+ static Rectangle pillRect;
1027
+ static readonly List<KeyValuePair<Rectangle, string>> buttons = new List<KeyValuePair<Rectangle, string>>();
962
1028
  static bool pillAtBottom;
963
- static string label = "", status = "";
964
- static float pillScale = 1f;
1029
+ static string label = "", status = "", rendered = "";
1030
+ static Image icon;
1031
+ static string iconPath = "";
1032
+ static int idleMs = 1500;
965
1033
  static System.Windows.Forms.Timer timer;
966
1034
  static DateTime shownAt;
967
1035
  static IntPtr hook = IntPtr.Zero;
968
1036
  static Native.LowLevelKeyboardProc hookProc;
969
1037
  static volatile bool visible;
1038
+ static volatile bool paused;
1039
+ static int lastTyping = int.MinValue / 2;
1040
+ static int lastEmit;
970
1041
  static readonly object RectLock = new object();
971
1042
 
972
1043
  static void Ensure()
@@ -991,17 +1062,32 @@ namespace DshComputerUse
991
1062
 
992
1063
  static void Ui(MethodInvoker action) { invoker.Invoke(action); }
993
1064
 
994
- public static void Show(string newLabel, string newStatus, bool glow)
1065
+ public static void Show(Dictionary<string, object> r)
995
1066
  {
996
1067
  Ensure();
997
1068
  Ui(delegate
998
1069
  {
999
- label = newLabel; status = newStatus;
1070
+ label = Args.Str(r, "label", "");
1071
+ status = Args.Str(r, "status", "");
1072
+ idleMs = Args.Int(r, "idleMs", 1500);
1073
+ string path = Args.Str(r, "icon", "");
1074
+ if (path != iconPath)
1075
+ {
1076
+ iconPath = path;
1077
+ if (icon != null) { icon.Dispose(); icon = null; }
1078
+ try
1079
+ {
1080
+ if (path.Length > 0 && File.Exists(path))
1081
+ using (var raw = Image.FromFile(path)) icon = new Bitmap(raw);
1082
+ }
1083
+ catch (Exception) { icon = null; }
1084
+ }
1000
1085
  if (visible) { RenderPill(); return; }
1001
1086
  pillAtBottom = false;
1087
+ paused = false;
1002
1088
  foreach (var g in glows) g.Close();
1003
1089
  glows.Clear();
1004
- if (glow)
1090
+ if (Args.Bool(r, "glow", true))
1005
1091
  {
1006
1092
  foreach (Dictionary<string, object> d in Screen2.Displays())
1007
1093
  {
@@ -1017,7 +1103,8 @@ namespace DshComputerUse
1017
1103
  pill = new LayeredForm(false);
1018
1104
  pill.MouseUp += delegate (object s, MouseEventArgs e)
1019
1105
  {
1020
- if (stopRect.Contains(e.Location)) { Program.EmitEvent("stop", "button"); }
1106
+ foreach (var b in buttons)
1107
+ if (b.Key.Contains(e.Location)) { Press(b.Value); break; }
1021
1108
  };
1022
1109
  pill.Show();
1023
1110
  }
@@ -1035,16 +1122,24 @@ namespace DshComputerUse
1035
1122
  Ui(delegate { status = newStatus; RenderPill(); });
1036
1123
  }
1037
1124
 
1125
+ public static void SetPaused(bool value)
1126
+ {
1127
+ if (thread == null) return;
1128
+ Ui(delegate { paused = value; RenderPill(); });
1129
+ }
1130
+
1038
1131
  public static void Hide()
1039
1132
  {
1040
1133
  if (thread == null) return;
1041
1134
  Ui(delegate
1042
1135
  {
1043
1136
  visible = false;
1137
+ paused = false;
1044
1138
  timer.Stop();
1045
1139
  foreach (var g in glows) g.Close();
1046
1140
  glows.Clear();
1047
1141
  if (pill != null) { pill.Close(); pill = null; }
1142
+ rendered = "";
1048
1143
  lock (RectLock) pillRect = Rectangle.Empty;
1049
1144
  RemoveHook();
1050
1145
  });
@@ -1069,14 +1164,26 @@ namespace DshComputerUse
1069
1164
  Thread.Sleep(30);
1070
1165
  }
1071
1166
 
1167
+ // pause / resume / stop, from Esc or the pill buttons.
1168
+ static void Press(string action)
1169
+ {
1170
+ if (action == "stop") { paused = false; Program.EmitEvent("stop", "button"); }
1171
+ else if (action == "pause") { paused = true; Program.EmitEvent("pause", "user"); }
1172
+ else if (action == "resume") { paused = false; Program.EmitEvent("resume", "user"); }
1173
+ RenderPill();
1174
+ }
1175
+
1176
+ static bool Typing() { return unchecked(Environment.TickCount - lastTyping) < idleMs; }
1177
+
1072
1178
  static void Tick()
1073
1179
  {
1074
1180
  if (!visible) return;
1075
1181
  double t = (DateTime.UtcNow - shownAt).TotalSeconds;
1076
1182
  double fadeIn = Math.Min(1.0, t / 0.35);
1077
- double breathe = 0.72 + 0.28 * (0.5 + 0.5 * Math.Sin(t * Math.PI * 2 / 2.6));
1183
+ double breathe = paused ? 0.55 : 0.72 + 0.28 * (0.5 + 0.5 * Math.Sin(t * Math.PI * 2 / 2.6));
1078
1184
  byte alpha = (byte)Math.Max(0, Math.Min(255, 255 * fadeIn * breathe));
1079
1185
  foreach (var g in glows) g.SetAlpha(alpha);
1186
+ if (Key() != rendered) RenderPill(); // typing started or stopped
1080
1187
  if ((int)(t * 25) % 50 == 0)
1081
1188
  {
1082
1189
  foreach (var g in glows) g.KeepOnTop();
@@ -1121,31 +1228,25 @@ namespace DshComputerUse
1121
1228
  return p;
1122
1229
  }
1123
1230
 
1124
- static readonly Color Whale = Color.FromArgb(77, 107, 254); // DeepSeek blue #4D6BFE
1125
-
1126
- /// A whale facing left, drawn in a 24x24 design box scaled to `size`.
1127
- static void DrawWhale(Graphics g, float x, float y, float size, Color eye)
1231
+ // What the pill should say right now; it is re-rendered whenever this changes.
1232
+ static void Content(out string main, out string sub, out string[] actions, out string[] captions)
1128
1233
  {
1129
- float k = size / 24f;
1130
- Func<float, float, PointF> P = delegate (float px, float py) { return new PointF(x + px * k, y + py * k); };
1131
- using (var path = new GraphicsPath())
1234
+ if (paused)
1132
1235
  {
1133
- path.AddBezier(P(1f, 14f), P(1f, 9f), P(5.5f, 6.5f), P(10f, 7.2f));
1134
- path.AddBezier(P(10f, 7.2f), P(14f, 7.8f), P(16.5f, 10f), P(18f, 10.5f));
1135
- path.AddBezier(P(18f, 10.5f), P(19.5f, 9f), P(20f, 6f), P(19.2f, 3.5f));
1136
- path.AddBezier(P(19.2f, 3.5f), P(21.5f, 4.5f), P(23f, 3.8f), P(23.5f, 2.5f));
1137
- path.AddBezier(P(23.5f, 2.5f), P(23.8f, 6f), P(22.5f, 9.5f), P(19.5f, 13f));
1138
- path.AddBezier(P(19.5f, 13f), P(17.5f, 17.5f), P(13f, 19.5f), P(8.5f, 19.3f));
1139
- path.AddBezier(P(8.5f, 19.3f), P(4f, 19f), P(1f, 17.5f), P(1f, 14f));
1140
- path.CloseFigure();
1141
- using (var brush = new SolidBrush(Whale)) g.FillPath(brush, path);
1236
+ main = "已暂停"; sub = "按 Esc 继续";
1237
+ actions = new[] { "resume", "stop" }; captions = new[] { "继续", "停止" };
1238
+ return;
1142
1239
  }
1143
- using (var pen = new Pen(Color.FromArgb(150, eye), Math.Max(1f, 1.1f * k)))
1144
- {
1145
- pen.StartCap = LineCap.Round; pen.EndCap = LineCap.Round;
1146
- g.DrawBezier(pen, P(2.6f, 15.4f), P(6f, 17.2f), P(10.5f, 17.2f), P(14f, 15.6f)); // belly line
1147
- }
1148
- using (var brush = new SolidBrush(eye)) g.FillEllipse(brush, x + 4.6f * k, y + 11f * k, 2.2f * k, 2.2f * k);
1240
+ main = label;
1241
+ sub = Typing() ? "你正在操作,已暂停" : status.Length > 0 ? status : "Esc 暂停";
1242
+ actions = new[] { "stop" }; captions = new[] { "停止" };
1243
+ }
1244
+
1245
+ static string Key()
1246
+ {
1247
+ string main, sub; string[] actions, captions;
1248
+ Content(out main, out sub, out actions, out captions);
1249
+ return main + "|" + sub + "|" + string.Join(",", actions) + "|" + pillAtBottom;
1149
1250
  }
1150
1251
 
1151
1252
  static void RenderPill()
@@ -1161,10 +1262,11 @@ namespace DshComputerUse
1161
1262
  scale = (int)d["dpi"] / 96f;
1162
1263
  }
1163
1264
  }
1164
- pillDisplay = work; pillScale = scale;
1265
+ string main, sub; string[] actions, captions;
1266
+ Content(out main, out sub, out actions, out captions);
1267
+ rendered = Key();
1268
+ if (sub.Length > 48) sub = sub.Substring(0, 47) + "…";
1165
1269
 
1166
- string main = label;
1167
- string hint = "Esc 停止";
1168
1270
  float px = 1.333f * scale; // points -> physical pixels
1169
1271
  using (var fMain = new Font("Microsoft YaHei UI", 10f * px, FontStyle.Bold, GraphicsUnit.Pixel))
1170
1272
  using (var fSub = new Font("Microsoft YaHei UI", 9f * px, FontStyle.Regular, GraphicsUnit.Pixel))
@@ -1175,15 +1277,18 @@ namespace DshComputerUse
1175
1277
  mg.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
1176
1278
  var fmt = StringFormat.GenericTypographic;
1177
1279
  fmt.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
1178
- string sub = status.Length > 0 ? status : hint;
1179
- if (sub.Length > 48) sub = sub.Substring(0, 47) + "…";
1180
1280
  SizeF mainSize = mg.MeasureString(main, fMain, 10000, fmt);
1181
1281
  SizeF subSize = mg.MeasureString(sub, fSub, 10000, fmt);
1182
- SizeF btnSize = mg.MeasureString("停止", fBtn, 10000, fmt);
1183
- float pad = 16 * scale, gap = 11 * scale, icon = 20 * scale;
1184
- float height = 40 * scale;
1185
- float btnW = btnSize.Width + 22 * scale, btnH = 26 * scale;
1186
- float width = pad + icon + gap + mainSize.Width + gap + 1 * scale + gap + subSize.Width + gap + btnW + (pad - 7 * scale);
1282
+ float pad = 14 * scale, gap = 11 * scale, iconSize = 24 * scale;
1283
+ float height = 40 * scale, btnH = 26 * scale, btnGap = 6 * scale;
1284
+ var btnSizes = new SizeF[captions.Length];
1285
+ float btnsW = 0;
1286
+ for (int i = 0; i < captions.Length; i++)
1287
+ {
1288
+ btnSizes[i] = mg.MeasureString(captions[i], fBtn, 10000, fmt);
1289
+ btnsW += btnSizes[i].Width + 22 * scale + (i > 0 ? btnGap : 0);
1290
+ }
1291
+ float width = pad + iconSize + gap + mainSize.Width + gap + 1 * scale + gap + subSize.Width + gap + btnsW + (pad - 7 * scale);
1187
1292
  int W = (int)Math.Ceiling(width), H = (int)Math.Ceiling(height);
1188
1293
  int x = work.X + (work.Width - W) / 2;
1189
1294
  int y = pillAtBottom ? work.Bottom - H - (int)(18 * scale) : work.Y + (int)(14 * scale);
@@ -1193,6 +1298,7 @@ namespace DshComputerUse
1193
1298
  {
1194
1299
  g.Clear(Color.Transparent);
1195
1300
  g.SmoothingMode = SmoothingMode.AntiAlias;
1301
+ g.InterpolationMode = InterpolationMode.HighQualityBicubic;
1196
1302
  g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
1197
1303
  var body = new RectangleF(0.5f, 0.5f, W - 1, H - 1);
1198
1304
  using (var path = Rounded(body, (H - 1) / 2f))
@@ -1200,19 +1306,28 @@ namespace DshComputerUse
1200
1306
  using (var brush = new SolidBrush(Color.FromArgb(242, 31, 30, 29))) g.FillPath(brush, path);
1201
1307
  using (var pen = new Pen(Color.FromArgb(200, Accent), Math.Max(1f, 1.2f * scale))) g.DrawPath(pen, path);
1202
1308
  }
1203
- DrawWhale(g, pad - 5 * scale, (H - icon - 10 * scale) / 2f, icon + 10 * scale, Color.FromArgb(31, 30, 29));
1204
- float tx = pad + icon + gap;
1309
+ var iconRect = new RectangleF(pad, (H - iconSize) / 2f, iconSize, iconSize);
1310
+ if (icon != null) g.DrawImage(icon, iconRect);
1311
+ else using (var brush = new SolidBrush(Accent)) g.FillEllipse(brush, RectangleF.Inflate(iconRect, -5 * scale, -5 * scale));
1312
+ float tx = pad + iconSize + gap;
1205
1313
  using (var b = new SolidBrush(Color.FromArgb(250, 250, 249))) g.DrawString(main, fMain, b, tx, (H - mainSize.Height) / 2f, fmt);
1206
1314
  tx += mainSize.Width + gap;
1207
1315
  using (var pen = new Pen(Color.FromArgb(90, 255, 255, 255), Math.Max(1f, scale))) g.DrawLine(pen, tx, H * 0.3f, tx, H * 0.7f);
1208
1316
  tx += 1 * scale + gap;
1209
1317
  using (var b = new SolidBrush(Color.FromArgb(175, 172, 168))) g.DrawString(sub, fSub, b, tx, (H - subSize.Height) / 2f, fmt);
1210
1318
  tx += subSize.Width + gap;
1211
- var btn = new RectangleF(tx, (H - btnH) / 2f, btnW, btnH);
1212
- using (var path = Rounded(btn, btnH / 2f))
1213
- using (var brush = new SolidBrush(Accent)) g.FillPath(brush, path);
1214
- using (var b = new SolidBrush(Color.White)) g.DrawString("停止", fBtn, b, btn.X + (btnW - btnSize.Width) / 2f, btn.Y + (btnH - btnSize.Height) / 2f, fmt);
1215
- stopRect = Rectangle.Round(btn);
1319
+ buttons.Clear();
1320
+ for (int i = 0; i < captions.Length; i++)
1321
+ {
1322
+ float bw = btnSizes[i].Width + 22 * scale;
1323
+ var btn = new RectangleF(tx, (H - btnH) / 2f, bw, btnH);
1324
+ bool primary = i == 0;
1325
+ using (var path = Rounded(btn, btnH / 2f))
1326
+ using (var brush = new SolidBrush(primary ? Accent : Color.FromArgb(70, 68, 66))) g.FillPath(brush, path);
1327
+ using (var b = new SolidBrush(Color.White)) g.DrawString(captions[i], fBtn, b, btn.X + (bw - btnSizes[i].Width) / 2f, btn.Y + (btnH - btnSizes[i].Height) / 2f, fmt);
1328
+ buttons.Add(new KeyValuePair<Rectangle, string>(Rectangle.Round(btn), actions[i]));
1329
+ tx += bw + btnGap;
1330
+ }
1216
1331
  pill.SetBitmap(bmp, new Rectangle(x, y, W, H), 255);
1217
1332
  }
1218
1333
  lock (RectLock) pillRect = new Rectangle(x, y, W, H);
@@ -1234,23 +1349,30 @@ namespace DshComputerUse
1234
1349
  hook = IntPtr.Zero;
1235
1350
  }
1236
1351
 
1237
- static long lastTyping;
1238
-
1239
1352
  static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
1240
1353
  {
1241
- if (nCode >= 0 && visible && (wParam.ToInt32() == 0x100 || wParam.ToInt32() == 0x104))
1354
+ if (nCode >= 0 && visible)
1242
1355
  {
1356
+ int msg = wParam.ToInt32();
1243
1357
  var kb = (Native.KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Native.KBDLLHOOKSTRUCT));
1244
1358
  // Only physical keys count: our own SendInput sets LLKHF_INJECTED (0x10).
1245
1359
  if ((kb.flags & 0x10) == 0)
1246
1360
  {
1247
- if (kb.vkCode == 0x1B) Program.EmitEvent("stop", "esc");
1248
- else
1361
+ bool down = msg == 0x100 || msg == 0x104;
1362
+ if (kb.vkCode == 0x1B)
1363
+ {
1364
+ // Esc toggles pause and is swallowed, so the focused app
1365
+ // (DeepSeek Harness included) never turns it into "stop".
1366
+ if (down) invoker.BeginInvoke((MethodInvoker)delegate { Press(paused ? "resume" : "pause"); });
1367
+ return new IntPtr(1);
1368
+ }
1369
+ if (down)
1249
1370
  {
1250
- // The user is typing: let the host pause. Throttled; mouse
1251
- // movement is deliberately ignored (too easy to nudge).
1252
- long now = Environment.TickCount;
1253
- if (now - lastTyping > 250) { lastTyping = now; Program.EmitEvent("user_input", "keyboard"); }
1371
+ // The user is typing: the host waits. Mouse movement is
1372
+ // deliberately ignored (too easy to nudge).
1373
+ int now = Environment.TickCount;
1374
+ lastTyping = now;
1375
+ if (unchecked(now - lastEmit) > 250) { lastEmit = now; Program.EmitEvent("user_input", "keyboard"); }
1254
1376
  }
1255
1377
  }
1256
1378
  }
Binary file
package/lib/index.js CHANGED
@@ -635,10 +635,11 @@ var Computer = class Computer {
635
635
  await this.overlay.begin(call.agent, Computer.statusOf(input));
636
636
  const { action } = input;
637
637
  const s = this.settings();
638
- if (s.pauseOnUserInput && INPUT.has(action) && await this.overlay.waitForUserIdle(call.signal, s.userIdleMs)) {
638
+ const wasPaused = this.overlay.paused;
639
+ if (await this.overlay.yieldToUser(call.signal, s.pauseOnUserInput && INPUT.has(action)) && INPUT.has(action)) {
639
640
  await this.overlay.begin(call.agent, Computer.statusOf(input));
640
641
  return {
641
- text: `Not done: the user was typing on the keyboard, so you were paused until they stopped. ${action} was NOT performed. Look at the new screenshot and re-plan before acting.`,
642
+ text: `Not done: ${wasPaused ? "the user paused computer use (Esc) and has now resumed" : "the user was typing on the keyboard, so you were paused until they stopped"}. ${action} was NOT performed. Look at the new screenshot and re-plan before acting.`,
642
643
  ...call.vision ? { image: await this.screenshot() } : {},
643
644
  skipped: true
644
645
  };
@@ -646,6 +647,7 @@ var Computer = class Computer {
646
647
  if (s.pauseOnUserInput && INPUT.has(action)) {
647
648
  const changed = await this.foregroundChanged();
648
649
  if (changed) {
650
+ await this.overlay.status("检测到窗口切换,重新查看屏幕");
649
651
  const image = call.vision ? await this.screenshot() : void 0;
650
652
  if (!image) this.seen = changed;
651
653
  return {
@@ -824,11 +826,14 @@ const REFERENCES = [
824
826
  "UIAutomationTypes.dll",
825
827
  "WindowsBase.dll"
826
828
  ];
827
- /** The helper source at the package root: one level up from lib/ or src/, two from lib/types/. */
828
- function helperSourcePath() {
829
- const candidates = ["../helper/CuHelper.cs", "../../helper/CuHelper.cs"].map((rel) => fileURLToPath(new URL(rel, import.meta.url)));
829
+ /** A file in helper/ at the package root: one level up from lib/ or src/, two from lib/types/. */
830
+ function helperAssetPath(name) {
831
+ const candidates = [`../helper/${name}`, `../../helper/${name}`].map((rel) => fileURLToPath(new URL(rel, import.meta.url)));
830
832
  return candidates.find((path) => existsSync(path)) ?? candidates[0];
831
833
  }
834
+ function helperSourcePath() {
835
+ return helperAssetPath("CuHelper.cs");
836
+ }
832
837
  function frameworkDir() {
833
838
  const windir = process.env.SystemRoot ?? process.env.windir ?? "C:\\Windows";
834
839
  for (const arch of ["Framework64", "Framework"]) {
@@ -1024,57 +1029,80 @@ var HelperClient = class {
1024
1029
  //#endregion
1025
1030
  //#region lib/types/overlay.js
1026
1031
  /**
1027
- * The "AI is controlling your computer" indicator: an orange glow around
1028
- * every display plus a status pill with a stop button, both excluded from
1032
+ * The "AI is controlling your computer" indicator and the user's controls:
1033
+ * an orange glow around every display plus a status pill, both excluded from
1029
1034
  * screenshots. Shown on the first action of a run, hidden when that agent
1030
- * goes idle; a physical Esc or the stop button cancels the agent.
1035
+ * goes idle. A physical Esc pauses / resumes, the stop button cancels the
1036
+ * agent, and typing on the keyboard makes the agent wait. While controlling,
1037
+ * the DeepSeek Harness window can shrink into an always-on-top card.
1031
1038
  */
1032
1039
  /** Without a status change from the host, hide after this long without actions. */
1033
1040
  const IDLE_HIDE_MS = 9e4;
1041
+ /** A pause longer than this ends the tool call with a message for the model. */
1042
+ const MAX_PAUSE_MS = 15e5;
1043
+ /** Card rectangle in the bottom-right corner of a display's work area. */
1044
+ function cardRect(display) {
1045
+ const scale = display.dpi / 96;
1046
+ const margin = Math.round(16 * scale);
1047
+ const width = Math.round(Math.min(Math.max(display.workWidth * .28, 400 * scale), 560 * scale, display.workWidth - 2 * margin));
1048
+ const height = Math.round(Math.min(display.workHeight * .66, display.workHeight - 2 * margin));
1049
+ return {
1050
+ x: display.workX + display.workWidth - width - margin,
1051
+ y: display.workY + display.workHeight - height - margin,
1052
+ width,
1053
+ height
1054
+ };
1055
+ }
1034
1056
  var OverlayController = class {
1035
1057
  helper;
1036
1058
  settings;
1037
1059
  log;
1060
+ iconPath;
1038
1061
  agent;
1039
1062
  visible = false;
1040
1063
  idleTimer;
1041
- minimizedHost = [];
1064
+ hostWindows = [];
1042
1065
  stopping = false;
1043
- constructor(helper, settings, log) {
1066
+ /** Paused by Esc or the pill; actions wait until resumed. */
1067
+ paused = false;
1068
+ /** When the user last typed on the physical keyboard while the overlay was up (ms epoch). */
1069
+ lastUserInput = 0;
1070
+ constructor(helper, settings, log, iconPath = "") {
1044
1071
  this.helper = helper;
1045
1072
  this.settings = settings;
1046
1073
  this.log = log;
1074
+ this.iconPath = iconPath;
1047
1075
  helper.onEvent((event) => {
1048
1076
  if (event.event === "stop") this.stop(event.reason ?? "user");
1077
+ else if (event.event === "pause") this.paused = true;
1078
+ else if (event.event === "resume") this.paused = false;
1049
1079
  else if (event.event === "user_input") this.lastUserInput = Date.now();
1050
1080
  });
1051
1081
  }
1052
- /** When the user last typed on the physical keyboard while the overlay was up (ms epoch). */
1053
- lastUserInput = 0;
1082
+ /** The agent currently driving the computer, if any. */
1083
+ get controller() {
1084
+ return this.agent;
1085
+ }
1054
1086
  /** Did the user type after `since`? */
1055
1087
  userTypedSince(since) {
1056
1088
  return this.lastUserInput > since;
1057
1089
  }
1058
1090
  /**
1059
- * If the user is typing, pause until the keyboard has been quiet for
1060
- * `idleMs`. Throws after `maxMs` so the model can tell the user. Returns
1061
- * whether it had to wait.
1091
+ * Hold the next action while the user has paused (Esc) or is typing.
1092
+ * Returns whether it had to wait, so the caller can re-check the screen.
1062
1093
  */
1063
- async waitForUserIdle(signal, idleMs, maxMs = 12e4) {
1064
- if (Date.now() - this.lastUserInput >= idleMs) return false;
1094
+ async yieldToUser(signal, waitForTyping) {
1095
+ const idleMs = this.settings().userIdleMs;
1096
+ const typing = () => waitForTyping && Date.now() - this.lastUserInput < idleMs;
1097
+ if (!this.paused && !typing()) return false;
1065
1098
  const started = Date.now();
1066
- if (this.settings().overlay && this.visible) await this.helper.call("overlay_status", { status: "你正在操作,已暂停" }).catch(() => {});
1067
- while (Date.now() - this.lastUserInput < idleMs) {
1099
+ while (this.paused || typing()) {
1068
1100
  if (signal.aborted) throw new Error("Cancelled.");
1069
- if (Date.now() - started > maxMs) throw new Error("The user has been typing on the keyboard for a while, so computer use is paused. Ask the user whether to continue.");
1101
+ if (Date.now() - started > MAX_PAUSE_MS) throw new Error("Computer use has been paused by the user for a long time. Stop here and ask the user whether to continue.");
1070
1102
  await new Promise((resolve) => setTimeout(resolve, 200));
1071
1103
  }
1072
1104
  return true;
1073
1105
  }
1074
- /** The agent currently driving the computer, if any. */
1075
- get controller() {
1076
- return this.agent;
1077
- }
1078
1106
  /** Called before every action: shows the overlay once and updates its status line. */
1079
1107
  async begin(agent, status) {
1080
1108
  if (agent) this.agent = agent;
@@ -1082,14 +1110,20 @@ var OverlayController = class {
1082
1110
  const settings = this.settings();
1083
1111
  if (!this.visible) {
1084
1112
  this.visible = true;
1085
- if (settings.minimizeHostWindow) await this.minimizeHost();
1113
+ this.paused = false;
1114
+ await this.shrinkHost(settings.hostWindow);
1086
1115
  if (settings.overlay) await this.helper.call("overlay_show", {
1087
- label: `${settings.overlayLabel || "DeepSeek"} 正在使用你的电脑`,
1088
- status
1116
+ label: `${settings.overlayLabel || "DeepSeek Harness"} 正在操控你的电脑`,
1117
+ status,
1118
+ icon: this.iconPath,
1119
+ idleMs: settings.userIdleMs
1089
1120
  }).catch((error) => this.log(`overlay: ${String(error)}`));
1090
1121
  return;
1091
1122
  }
1092
- if (settings.overlay) await this.helper.call("overlay_status", { status }).catch(() => {});
1123
+ await this.status(status);
1124
+ }
1125
+ async status(status) {
1126
+ if (this.visible && this.settings().overlay) await this.helper.call("overlay_status", { status }).catch(() => {});
1093
1127
  }
1094
1128
  /** Agent finished (idle), was cancelled, or the plugin is stopping. */
1095
1129
  async end(agent) {
@@ -1097,6 +1131,7 @@ var OverlayController = class {
1097
1131
  if (this.idleTimer) clearTimeout(this.idleTimer);
1098
1132
  this.idleTimer = void 0;
1099
1133
  this.agent = void 0;
1134
+ this.paused = false;
1100
1135
  if (!this.visible) return;
1101
1136
  this.visible = false;
1102
1137
  await this.helper.call("overlay_hide").catch(() => {});
@@ -1123,23 +1158,47 @@ var OverlayController = class {
1123
1158
  }, IDLE_HIDE_MS);
1124
1159
  this.idleTimer.unref();
1125
1160
  }
1126
- async minimizeHost() {
1161
+ /** Card: shrink the DSH window to an always-on-top corner card; minimize: get it out of the way. */
1162
+ async shrinkHost(mode) {
1163
+ if (mode === "keep") return;
1127
1164
  try {
1128
- const host = (await this.helper.call("windows")).filter((row) => isHostWindow(row) && !row.minimized);
1129
- for (const row of host) await this.helper.call("window_cmd", {
1130
- hwnd: row.hwnd,
1131
- op: "minimize"
1165
+ const rows = (await this.helper.call("windows")).filter((row) => isHostWindow(row) && !row.minimized);
1166
+ if (rows.length === 0) return;
1167
+ if (mode === "minimize") {
1168
+ for (const row of rows) await this.helper.call("window_cmd", {
1169
+ hwnd: row.hwnd,
1170
+ op: "minimize"
1171
+ });
1172
+ this.hostWindows = rows.map((row) => ({
1173
+ hwnd: row.hwnd,
1174
+ mode: "minimize"
1175
+ }));
1176
+ return;
1177
+ }
1178
+ const main = rows.find((row) => row.foreground) ?? rows.reduce((a, b) => a.width * a.height >= b.width * b.height ? a : b);
1179
+ const displays = await this.helper.call("displays");
1180
+ const cx = main.x + main.width / 2;
1181
+ const cy = main.y + main.height / 2;
1182
+ const display = displays.find((d) => cx >= d.x && cx < d.x + d.width && cy >= d.y && cy < d.y + d.height) ?? displays.find((d) => d.primary) ?? displays[0];
1183
+ if (!display) return;
1184
+ await this.helper.call("window_card", {
1185
+ hwnd: main.hwnd,
1186
+ ...cardRect(display)
1132
1187
  });
1133
- this.minimizedHost = host.map((row) => row.hwnd);
1188
+ this.hostWindows = [{
1189
+ hwnd: main.hwnd,
1190
+ mode: "card"
1191
+ }];
1134
1192
  } catch (error) {
1135
- this.log(`minimize host window: ${String(error)}`);
1193
+ this.log(`host window ${mode}: ${String(error)}`);
1136
1194
  }
1137
1195
  }
1138
1196
  async restoreHost() {
1139
- const handles = this.minimizedHost;
1140
- this.minimizedHost = [];
1141
- for (const hwnd of handles) await this.helper.call("window_cmd", {
1142
- hwnd,
1197
+ const windows = this.hostWindows;
1198
+ this.hostWindows = [];
1199
+ for (const win of windows) if (win.mode === "card") await this.helper.call("window_uncard", { hwnd: win.hwnd }).catch(() => {});
1200
+ else await this.helper.call("window_cmd", {
1201
+ hwnd: win.hwnd,
1143
1202
  op: "restore"
1144
1203
  }).catch(() => {});
1145
1204
  }
@@ -1150,13 +1209,13 @@ function promptText(mode) {
1150
1209
  return `# Computer use (Windows desktop)
1151
1210
  You can see and operate the user's Windows computer with the computer, computer_batch, open_application, windows, ui_elements and clipboard tools.
1152
1211
  ${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.
1153
- - Open or switch apps with open_application (by name) rather than hunting through the taskbar or Start menu. Use windows to see which windows exist; each line shows the process .exe.
1154
- - The "DeepSeek Harness.exe" window is your own chat interface. Never click or type into it; bring the target window to the front first.
1212
+ - 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.
1213
+ - The "DeepSeek Harness.exe" window is your own chat interface; while you control the computer it may float as a small card in a corner. Never click or type into it; bring the target window to the front first, and work around the card.
1155
1214
  - Prefer reliable keyboard shortcuts (ctrl+l for a browser address bar, ctrl+s, alt+F4, ctrl+t). Click the center of targets; zoom in when text is small.
1156
1215
  - Actions return a fresh screenshot. Check it before continuing and verify the result instead of assuming success. Use computer_batch for several confident steps in a row.
1157
1216
  - If the user has a dedicated tool for a website or service (browser automation, an API tool), prefer it over driving the desktop.
1158
1217
  - Do not enter passwords, payment details or solve CAPTCHAs: stop and ask the user to do that step. Ask before irreversible actions (sending messages, deleting, purchasing) unless the user clearly asked for them.
1159
- - The user sees an orange border and can press Esc at any time to stop you. If they type on the keyboard you are paused; when an action reports it was not performed, re-check the screen instead of repeating it blindly.`;
1218
+ - The user sees an orange border and can press Esc to pause you at any time. If they pause, type on the keyboard or switch windows, you wait; when an action reports it was not performed, re-check the screen instead of repeating it blindly.`;
1160
1219
  }
1161
1220
  //#endregion
1162
1221
  //#region node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4_@deepseek-ai+dsh-invariants_0d6b19188928ab894325adc32e18b0b5/node_modules/@deepseek-ai/dsh-scope/lib/index.js
@@ -6897,7 +6956,7 @@ function createTools(host) {
6897
6956
  description: "Control the Windows desktop with the mouse and keyboard, like a person. Coordinates are pixels of the latest screenshot (the plugin handles DPI and scaling). Clicks, typing, keys and scrolls return a fresh screenshot automatically, so do not call screenshot again right after. Prefer keyboard shortcuts when they are reliable. zoom shows a region at full resolution for small text.",
6898
6957
  parameters: actionProperties,
6899
6958
  output,
6900
- timeoutMs: 12e4,
6959
+ timeoutMs: 18e5,
6901
6960
  async execute(args, exec) {
6902
6961
  const call = await host.context(exec);
6903
6962
  const input = args;
@@ -6933,7 +6992,7 @@ function createTools(host) {
6933
6992
  }
6934
6993
  } },
6935
6994
  output,
6936
- timeoutMs: 3e5,
6995
+ timeoutMs: 18e5,
6937
6996
  async execute(args, exec) {
6938
6997
  const call = await host.context(exec);
6939
6998
  const actions = args.actions;
@@ -6984,7 +7043,7 @@ function createTools(host) {
6984
7043
  description: "App name as shown in the Start menu, an executable path, or an http(s) URL."
6985
7044
  } },
6986
7045
  output,
6987
- timeoutMs: 6e4,
7046
+ timeoutMs: 18e5,
6988
7047
  async execute(args, exec) {
6989
7048
  const call = await host.context(exec);
6990
7049
  const name = String(args.name ?? "").trim();
@@ -6996,6 +7055,7 @@ function createTools(host) {
6996
7055
  if (!running || !computer.access.isGranted(call.session, running)) throw new Error(`"${name}" is not granted for this session. Call request_access with ["${name}"] first.`);
6997
7056
  }
6998
7057
  await computer.overlay.begin(call.agent, `打开 ${name}`);
7058
+ await computer.overlay.yieldToUser(call.signal, false);
6999
7059
  const before = await computer.foreground();
7000
7060
  let how;
7001
7061
  const running = isUrl ? void 0 : (await computer.windows()).find((win) => !isHostWindow(win) && appMatches(name, win));
@@ -7059,6 +7119,7 @@ function createTools(host) {
7059
7119
  const denial = computer.access.denial(call.session, target, settings.accessMode, settings.blockedApps, action);
7060
7120
  if (denial && !(action === "minimize" && isHostWindow(target))) throw new Error(denial);
7061
7121
  await computer.overlay.begin(call.agent, `窗口 ${action}`);
7122
+ await computer.overlay.yieldToUser(call.signal, false);
7062
7123
  let text;
7063
7124
  if (action === "focus") text = (await computer.focus(target)).focused ? `Focused ${target.exe} ("${target.title.slice(0, 60)}").` : `Windows refused to focus ${target.exe}; try clicking it.`;
7064
7125
  else {
@@ -7214,8 +7275,8 @@ const inject = ["tools", "attachments"];
7214
7275
  const DEFAULTS = {
7215
7276
  accessMode: "per-app",
7216
7277
  overlay: true,
7217
- overlayLabel: "DeepSeek",
7218
- minimizeHostWindow: false,
7278
+ overlayLabel: "DeepSeek Harness",
7279
+ hostWindow: "card",
7219
7280
  autoScreenshot: true,
7220
7281
  settleMs: 400,
7221
7282
  maxLongEdge: 1366,
@@ -7240,13 +7301,26 @@ const Config = z.object({
7240
7301
  "zh-CN": { $description: "控制时显示橙色光晕边框和顶部提示条(不会出现在截图里,按 Esc 可停止)" },
7241
7302
  "en-US": { $description: "Show the orange glow and status pill while controlling (hidden from screenshots; Esc stops)" }
7242
7303
  }),
7243
- overlayLabel: z.string().default("DeepSeek").volatile().i18n({
7244
- "zh-CN": { $description: "提示条名称:“<名称> 正在使用你的电脑”" },
7245
- "en-US": { $description: "Name in the pill: \"<name> 正在使用你的电脑\"" }
7304
+ overlayLabel: z.string().default("DeepSeek Harness").volatile().i18n({
7305
+ "zh-CN": { $description: "提示条名称:“<名称> 正在操控你的电脑”" },
7306
+ "en-US": { $description: "Name in the pill: \"<name> 正在操控你的电脑\"" }
7246
7307
  }),
7247
- minimizeHostWindow: z.boolean().default(false).volatile().i18n({
7248
- "zh-CN": { $description: "控制期间最小化 DeepSeek Harness 窗口,结束后恢复" },
7249
- "en-US": { $description: "Minimize the DeepSeek Harness window while controlling; restore afterwards" }
7308
+ hostWindow: z.union([
7309
+ z.const("card").i18n({
7310
+ "zh-CN": { $description: "缩成右下角置顶悬浮卡片" },
7311
+ "en-US": { $description: "Shrink to an always-on-top card" }
7312
+ }),
7313
+ z.const("minimize").i18n({
7314
+ "zh-CN": { $description: "最小化" },
7315
+ "en-US": { $description: "Minimize" }
7316
+ }),
7317
+ z.const("keep").i18n({
7318
+ "zh-CN": { $description: "保持不变" },
7319
+ "en-US": { $description: "Leave it as is" }
7320
+ })
7321
+ ]).default("card").volatile().i18n({
7322
+ "zh-CN": { $description: "操控期间 DeepSeek Harness 窗口怎么摆放(结束后自动恢复原尺寸和位置)" },
7323
+ "en-US": { $description: "What to do with the DeepSeek Harness window while controlling (restored afterwards)" }
7250
7324
  }),
7251
7325
  autoScreenshot: z.boolean().default(true).volatile().i18n({
7252
7326
  "zh-CN": { $description: "每次操作后自动回传截图(省去一轮调用)" },
@@ -7294,7 +7368,7 @@ function resolveConfig(raw) {
7294
7368
  accessMode: out.accessMode === "allow-all" || out.accessMode === "per-app" ? out.accessMode : DEFAULTS.accessMode,
7295
7369
  overlay: bool("overlay"),
7296
7370
  overlayLabel: typeof out.overlayLabel === "string" && out.overlayLabel.trim() !== "" ? out.overlayLabel.trim().slice(0, 40) : DEFAULTS.overlayLabel,
7297
- minimizeHostWindow: bool("minimizeHostWindow"),
7371
+ hostWindow: out.hostWindow === "card" || out.hostWindow === "minimize" || out.hostWindow === "keep" ? out.hostWindow : out.minimizeHostWindow === true ? "minimize" : DEFAULTS.hostWindow,
7298
7372
  autoScreenshot: bool("autoScreenshot"),
7299
7373
  settleMs: num("settleMs", 0, 5e3),
7300
7374
  maxLongEdge: num("maxLongEdge", 640, 3840),
@@ -7314,7 +7388,7 @@ function apply(ctx, config = {}) {
7314
7388
  const log = (message) => ctx.logger.info(message);
7315
7389
  const helper = new HelperClient((message) => ctx.logger.warn(message));
7316
7390
  const access = new AccessControl();
7317
- const overlay = new OverlayController(helper, settings, log);
7391
+ const overlay = new OverlayController(helper, settings, log, helperAssetPath("deepseek-white.png"));
7318
7392
  const computer = new Computer(helper, access, overlay, settings);
7319
7393
  ctx.effect(() => () => {
7320
7394
  overlay.end().finally(() => helper.dispose());
@@ -1,13 +1,13 @@
1
1
  import type { AccessControl, AccessMode, WindowLike } from './access.js';
2
2
  import { type Display, type Point, type Size } from './coords.js';
3
3
  import type { HelperLike } from './helper-client.js';
4
- import type { CancellableAgent, OverlayController } from './overlay.js';
4
+ import type { CancellableAgent, HostWindowMode, OverlayController } from './overlay.js';
5
5
  export interface Settings {
6
6
  accessMode: AccessMode;
7
7
  blockedApps: string[];
8
8
  overlay: boolean;
9
9
  overlayLabel: string;
10
- minimizeHostWindow: boolean;
10
+ hostWindow: HostWindowMode;
11
11
  maxLongEdge: number;
12
12
  maxPixels: number;
13
13
  jpegQuality: number;
@@ -7,7 +7,8 @@ export interface HelperLike {
7
7
  onEvent(listener: (event: HelperEvent) => void): () => void;
8
8
  dispose(): void;
9
9
  }
10
- /** The helper source at the package root: one level up from lib/ or src/, two from lib/types/. */
10
+ /** A file in helper/ at the package root: one level up from lib/ or src/, two from lib/types/. */
11
+ export declare function helperAssetPath(name: string): string;
11
12
  export declare function helperSourcePath(): string;
12
13
  /** Compile the helper if this source version has no cached exe yet; returns the exe path. */
13
14
  export declare function ensureHelperExe(source?: string): Promise<string>;
@@ -8,12 +8,15 @@ import type { Context } from '@deepseek-ai/cordis';
8
8
  import z from '@deepseek-ai/schemastery';
9
9
  import { type AccessMode } from './access.js';
10
10
  import { type Settings } from './computer.js';
11
+ import { type HostWindowMode } from './overlay.js';
11
12
  export declare const name = "@copylee/dsh-computer-use";
12
13
  export declare const inject: string[];
13
14
  export interface Config {
14
15
  accessMode?: AccessMode;
15
16
  overlay?: boolean;
16
17
  overlayLabel?: string;
18
+ hostWindow?: HostWindowMode;
19
+ /** @deprecated replaced by hostWindow: 'minimize' */
17
20
  minimizeHostWindow?: boolean;
18
21
  autoScreenshot?: boolean;
19
22
  settleMs?: number;
@@ -4,39 +4,68 @@ export interface CancellableAgent {
4
4
  kind: 'user';
5
5
  }): void;
6
6
  }
7
+ export type HostWindowMode = 'card' | 'minimize' | 'keep';
7
8
  export interface OverlaySettings {
8
9
  overlay: boolean;
9
10
  overlayLabel: string;
10
- minimizeHostWindow: boolean;
11
+ hostWindow: HostWindowMode;
12
+ userIdleMs: number;
11
13
  }
14
+ interface DisplayRow {
15
+ x: number;
16
+ y: number;
17
+ width: number;
18
+ height: number;
19
+ workX: number;
20
+ workY: number;
21
+ workWidth: number;
22
+ workHeight: number;
23
+ primary: boolean;
24
+ dpi: number;
25
+ }
26
+ /** Card rectangle in the bottom-right corner of a display's work area. */
27
+ export declare function cardRect(display: DisplayRow): {
28
+ x: number;
29
+ y: number;
30
+ width: number;
31
+ height: number;
32
+ };
12
33
  export declare class OverlayController {
13
34
  private readonly helper;
14
35
  private readonly settings;
15
36
  private readonly log;
37
+ /** Absolute path of the pill icon (PNG). */
38
+ private readonly iconPath;
16
39
  private agent;
17
40
  private visible;
18
41
  private idleTimer;
19
- private minimizedHost;
42
+ private hostWindows;
20
43
  private stopping;
21
- constructor(helper: HelperLike, settings: () => OverlaySettings, log: (message: string) => void);
44
+ /** Paused by Esc or the pill; actions wait until resumed. */
45
+ paused: boolean;
22
46
  /** When the user last typed on the physical keyboard while the overlay was up (ms epoch). */
23
47
  lastUserInput: number;
48
+ constructor(helper: HelperLike, settings: () => OverlaySettings, log: (message: string) => void,
49
+ /** Absolute path of the pill icon (PNG). */
50
+ iconPath?: string);
51
+ /** The agent currently driving the computer, if any. */
52
+ get controller(): CancellableAgent | undefined;
24
53
  /** Did the user type after `since`? */
25
54
  userTypedSince(since: number): boolean;
26
55
  /**
27
- * If the user is typing, pause until the keyboard has been quiet for
28
- * `idleMs`. Throws after `maxMs` so the model can tell the user. Returns
29
- * whether it had to wait.
56
+ * Hold the next action while the user has paused (Esc) or is typing.
57
+ * Returns whether it had to wait, so the caller can re-check the screen.
30
58
  */
31
- waitForUserIdle(signal: AbortSignal, idleMs: number, maxMs?: number): Promise<boolean>;
32
- /** The agent currently driving the computer, if any. */
33
- get controller(): CancellableAgent | undefined;
59
+ yieldToUser(signal: AbortSignal, waitForTyping: boolean): Promise<boolean>;
34
60
  /** Called before every action: shows the overlay once and updates its status line. */
35
61
  begin(agent: CancellableAgent | undefined, status: string): Promise<void>;
62
+ status(status: string): Promise<void>;
36
63
  /** Agent finished (idle), was cancelled, or the plugin is stopping. */
37
64
  end(agent?: CancellableAgent): Promise<void>;
38
65
  private stop;
39
66
  private armIdle;
40
- private minimizeHost;
67
+ /** Card: shrink the DSH window to an always-on-top corner card; minimize: get it out of the way. */
68
+ private shrinkHost;
41
69
  private restoreHost;
42
70
  }
71
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.1.2",
4
- "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek 正在使用你的电脑”,按 Esc 立即停止。",
3
+ "version": "0.1.3",
4
+ "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "type": "module",
6
6
  "author": "copylee",
7
7
  "repository": {
@@ -25,6 +25,7 @@
25
25
  "lib/index.js",
26
26
  "lib/types/**/*.d.ts",
27
27
  "helper/CuHelper.cs",
28
+ "helper/deepseek-white.png",
28
29
  "cordis.patch.yml",
29
30
  "README.md",
30
31
  "LICENSE"