@copylee/dsh-computer-use 0.14.0 → 0.14.2

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/helper/Capture.cs CHANGED
@@ -111,17 +111,27 @@ namespace DshComputerUse
111
111
  * Wait until the screen stops changing: at least minMs, then until two
112
112
  * consecutive samples (quietMs apart in total) differ in under 0.2% of
113
113
  * the sampled pixels, or maxMs passes (videos, spinners).
114
+ * When waitForChange is true (explicit multi-second waits for async replies),
115
+ * never exit early until the screen actually updates relative to t=0, then
116
+ * settle cleanly as soon as the burst finishes (or user skips wait).
114
117
  */
115
118
  public static Dictionary<string, object> Settle(Dictionary<string, object> r)
116
119
  {
117
120
  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);
118
121
  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);
122
+ bool waitForChange = Args.Bool(r, "waitForChange", false);
123
+ int checkpointMs = Args.Int(r, "checkpointMs", 0);
124
+ int noChangeMaxMs = Args.Int(r, "noChangeMaxMs", 0);
119
125
  if (w <= 0 || h <= 0) throw new Exception("invalid settle rect");
120
126
  var watch = System.Diagnostics.Stopwatch.StartNew();
121
- byte[] prev = Sample(x, y, w, h);
127
+ byte[] initial = Sample(x, y, w, h);
128
+ byte[] prev = initial;
122
129
  long quietSince = -1;
130
+ long firstChangeAt = -1;
123
131
  bool stable = false;
124
132
  bool skipped = false;
133
+ bool sawChange = false;
134
+ bool checkpoint = false;
125
135
  while (true)
126
136
  {
127
137
  if (Overlay.SkipWaitRequested) { skipped = true; break; }
@@ -129,15 +139,36 @@ namespace DshComputerUse
129
139
  if (Overlay.SkipWaitRequested) { skipped = true; break; }
130
140
  byte[] cur = Sample(x, y, w, h);
131
141
  long now = watch.ElapsedMilliseconds;
132
- if (Changed(prev, cur) < 0.002) { if (quietSince < 0) quietSince = now - interval; }
142
+ bool stepDiff = Changed(prev, cur) >= 0.002;
143
+ if (stepDiff || (!sawChange && Changed(initial, cur) >= 0.002))
144
+ {
145
+ if (!sawChange) { sawChange = true; firstChangeAt = now; }
146
+ }
147
+ if (!stepDiff) { if (quietSince < 0) quietSince = now - interval; }
133
148
  else quietSince = -1;
134
149
  prev = cur;
135
- if (now >= minMs && quietSince >= 0 && now - quietSince >= quietMs) { stable = true; break; }
150
+ if (now >= minMs && quietSince >= 0 && now - quietSince >= quietMs && (!waitForChange || sawChange))
151
+ {
152
+ stable = true;
153
+ break;
154
+ }
155
+ if (sawChange && checkpointMs > 0 && firstChangeAt >= 0 && now - firstChangeAt >= checkpointMs)
156
+ {
157
+ checkpoint = true;
158
+ break;
159
+ }
160
+ if (waitForChange && !sawChange && noChangeMaxMs > 0 && now >= noChangeMaxMs)
161
+ {
162
+ checkpoint = true;
163
+ break;
164
+ }
136
165
  if (now >= maxMs) break;
137
166
  }
138
167
  var d = new Dictionary<string, object>();
139
168
  d["ms"] = (int)watch.ElapsedMilliseconds;
140
169
  d["stable"] = stable;
170
+ d["changed"] = sawChange;
171
+ if (checkpoint) d["checkpoint"] = true;
141
172
  if (skipped) d["skipped"] = true;
142
173
  return d;
143
174
  }
package/helper/Native.cs CHANGED
@@ -42,6 +42,16 @@ namespace DshComputerUse
42
42
  [DllImport("user32.dll")] public static extern bool SetCursorPos(int x, int y);
43
43
  [DllImport("user32.dll")] public static extern bool GetCursorPos(out POINT p);
44
44
  [DllImport("user32.dll")] public static extern uint MapVirtualKey(uint code, uint mapType);
45
+ [StructLayout(LayoutKind.Sequential)]
46
+ public struct ICONINFO { public bool fIcon; public int xHotspot; public int yHotspot; public IntPtr hbmMask; public IntPtr hbmColor; }
47
+ [DllImport("user32.dll", SetLastError = true)] public static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO piconinfo);
48
+ [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr CreateIconIndirect(ref ICONINFO piconinfo);
49
+ [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr CopyIcon(IntPtr hIcon);
50
+ [DllImport("user32.dll", SetLastError = true)] public static extern bool DestroyIcon(IntPtr hIcon);
51
+ [DllImport("user32.dll", SetLastError = true)] public static extern bool SetSystemCursor(IntPtr hcur, uint id);
52
+ [DllImport("user32.dll", SetLastError = true)] public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, IntPtr pvParam, uint fWinIni);
53
+ public const uint SPI_SETCURSORS = 0x0057;
54
+ public const uint OCR_NORMAL = 32512, OCR_IBEAM = 32513, OCR_WAIT = 32514, OCR_HAND = 32649, OCR_APPSTARTING = 32650;
45
55
 
46
56
  public delegate bool MonitorEnumProc(IntPtr hMonitor, IntPtr hdc, ref RECT rect, IntPtr data);
47
57
  [DllImport("user32.dll")] public static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr clip, MonitorEnumProc proc, IntPtr data);
@@ -57,6 +67,7 @@ namespace DshComputerUse
57
67
  [DllImport("gdi32.dll")] public static extern bool DeleteDC(IntPtr hdc);
58
68
  [DllImport("gdi32.dll")] public static extern IntPtr SelectObject(IntPtr hdc, IntPtr obj);
59
69
  [DllImport("gdi32.dll")] public static extern bool DeleteObject(IntPtr obj);
70
+ [DllImport("gdi32.dll")] public static extern IntPtr CreateBitmap(int nWidth, int nHeight, uint cPlanes, uint cBitsPerPel, IntPtr lpvBits);
60
71
 
61
72
  public delegate bool EnumWindowsProc(IntPtr hwnd, IntPtr data);
62
73
  [DllImport("user32.dll")] public static extern bool EnumWindows(EnumWindowsProc proc, IntPtr data);
package/helper/Overlay.cs CHANGED
@@ -217,6 +217,7 @@ namespace DshComputerUse
217
217
  {
218
218
  readonly bool clickThrough;
219
219
  public Rectangle Physical;
220
+ int affinityState = -1;
220
221
 
221
222
  public LayeredForm(bool clickThrough)
222
223
  {
@@ -245,6 +246,7 @@ namespace DshComputerUse
245
246
  {
246
247
  base.OnHandleCreated(e);
247
248
  // Keep the overlay out of every screenshot, including our own.
249
+ affinityState = Overlay.ExcludeFromCapture ? 1 : 0;
248
250
  if (Overlay.ExcludeFromCapture) { try { Native.SetWindowDisplayAffinity(Handle, 0x11); } catch (Exception) { } }
249
251
  }
250
252
 
@@ -291,6 +293,9 @@ namespace DshComputerUse
291
293
 
292
294
  public void SetCapturable(bool capturable)
293
295
  {
296
+ int want = capturable ? 0 : 1;
297
+ if (affinityState == want) return;
298
+ affinityState = want;
294
299
  try { Native.SetWindowDisplayAffinity(Handle, capturable ? 0u : 0x11u); } catch (Exception) { }
295
300
  }
296
301
  }
@@ -377,9 +382,14 @@ namespace DshComputerUse
377
382
  static volatile bool visible;
378
383
  static volatile bool paused;
379
384
  static volatile bool petWaiting;
385
+ static DateTime petWaitingSince = DateTime.UtcNow;
386
+ static string petPhase = "";
387
+ static DateTime petPhaseSince = DateTime.UtcNow;
388
+ static int lastPhaseSec = -1;
380
389
  public static volatile bool SkipWaitRequested;
381
390
  static volatile bool clickTargetEnabled = true;
382
- static string cursorBadge = "DeepSeek";
391
+ static volatile bool customCursorActive;
392
+ static string cursorBadge = "DSH";
383
393
  static LayeredForm markForm;
384
394
  static DateTime markExpiresAt = DateTime.MinValue;
385
395
  static bool markActive;
@@ -392,6 +402,7 @@ namespace DshComputerUse
392
402
  static bool hasCachedMarkBitmap;
393
403
  static volatile int latestMouseX, latestMouseY;
394
404
  static int mouseMovePending;
405
+ static int lastMouseMoveTick = int.MinValue / 2;
395
406
  static int lastTyping = int.MinValue / 2;
396
407
  static int lastEmit;
397
408
  static readonly object RectLock = new object();
@@ -483,10 +494,14 @@ namespace DshComputerUse
483
494
  if (reqSize == "compact" || reqSize == "standard" || reqSize == "detailed") petSize = reqSize;
484
495
  clickTargetEnabled = Args.Bool(r, "glow", true);
485
496
  string badgeSrc = label.Replace("正在操控你的电脑", "").Replace("正在操控", "").Trim();
486
- if (badgeSrc.StartsWith("DeepSeek", StringComparison.OrdinalIgnoreCase)) cursorBadge = "DeepSeek";
487
- else if (badgeSrc.Length > 0) cursorBadge = badgeSrc.Length > 10 ? badgeSrc.Substring(0, 10) : badgeSrc;
488
- else cursorBadge = "AI";
489
- if (visible && !petFinished) { RenderPill(); return; }
497
+ if (badgeSrc.Length == 0 || badgeSrc.StartsWith("DeepSeek", StringComparison.OrdinalIgnoreCase) || string.Equals(badgeSrc, "DSH", StringComparison.OrdinalIgnoreCase)) cursorBadge = "DSH";
498
+ else cursorBadge = badgeSrc.Length > 10 ? badgeSrc.Substring(0, 10) : badgeSrc;
499
+ if (visible && !petFinished)
500
+ {
501
+ if (clickTargetEnabled && !paused) ApplyCustomCursor(); else RestoreSystemCursor(false);
502
+ RenderPill();
503
+ return;
504
+ }
490
505
  if (visible) HideCore(); // the previous run's "done" card is still up
491
506
  petMode = Args.Bool(r, "pet", false);
492
507
  hoveredBtn = "";
@@ -585,6 +600,7 @@ namespace DshComputerUse
585
600
  visible = true;
586
601
  if (clickTargetEnabled)
587
602
  {
603
+ ApplyCustomCursor();
588
604
  Native.POINT cp;
589
605
  if (Native.GetCursorPos(out cp)) ShowRestingMarkOnUi(cp.X, cp.Y);
590
606
  }
@@ -592,6 +608,104 @@ namespace DshComputerUse
592
608
  });
593
609
  }
594
610
 
611
+ /**
612
+ * Replace Windows' hardware pointer (Normal / IBeam / Hand) with our crisp,
613
+ * DPI-scaled stylized DSH cursor while controlling. Hardware-composited at
614
+ * full refresh rate with zero double-arrow overlap, and always restored via
615
+ * SystemParametersInfo(SPI_SETCURSORS) on pause, hide, exit, or crash recovery.
616
+ */
617
+ static void ApplyCustomCursor()
618
+ {
619
+ if (customCursorActive) return;
620
+ IntPtr hCursor = IntPtr.Zero;
621
+ try
622
+ {
623
+ float s = Math.Max(1f, Math.Min(3f, Scale()));
624
+ int size = Math.Max(32, Math.Min(96, (int)Math.Round(32f * s)));
625
+ int tipX = Math.Max(1, (int)Math.Round(2f * s));
626
+ int tipY = Math.Max(1, (int)Math.Round(2f * s));
627
+ using (var bmp = new Bitmap(size, size, PixelFormat.Format32bppArgb))
628
+ {
629
+ using (var g = Graphics.FromImage(bmp))
630
+ {
631
+ g.Clear(Color.Transparent);
632
+ g.SmoothingMode = SmoothingMode.AntiAlias;
633
+ var arrow = new PointF[]
634
+ {
635
+ new PointF(tipX, tipY),
636
+ new PointF(tipX, tipY + 19.2f * s),
637
+ new PointF(tipX + 5.0f * s, tipY + 14.8f * s),
638
+ new PointF(tipX + 8.6f * s, tipY + 22.4f * s),
639
+ new PointF(tipX + 11.8f * s, tipY + 20.9f * s),
640
+ new PointF(tipX + 8.2f * s, tipY + 13.5f * s),
641
+ new PointF(tipX + 14.5f * s, tipY + 13.1f * s),
642
+ };
643
+ var shadow = new PointF[arrow.Length];
644
+ for (int i = 0; i < arrow.Length; i++)
645
+ shadow[i] = new PointF(arrow[i].X + 1.0f * s, arrow[i].Y + 1.6f * s);
646
+ using (var sb = new SolidBrush(Color.FromArgb(88, 0, 0, 0)))
647
+ g.FillPolygon(sb, shadow);
648
+ using (var grad = new LinearGradientBrush(
649
+ new PointF(tipX, tipY),
650
+ new PointF(tipX + 15f * s, tipY + 23f * s),
651
+ AccentHi, Accent))
652
+ g.FillPolygon(grad, arrow);
653
+ using (var outline = new Pen(Color.FromArgb(250, 255, 255, 255), Math.Max(1.4f, 1.6f * s)))
654
+ {
655
+ outline.LineJoin = LineJoin.Round;
656
+ g.DrawPolygon(outline, arrow);
657
+ }
658
+ }
659
+ // Build a clean 32-bit ARGB cursor with an all-zero monochrome AND mask
660
+ // so Windows DWM composites it purely on the hardware cursor plane without flicker.
661
+ IntPtr hbmColor = bmp.GetHbitmap(Color.FromArgb(0));
662
+ IntPtr hbmMask = Native.CreateBitmap(size, size, 1, 1, IntPtr.Zero);
663
+ try
664
+ {
665
+ if (hbmColor != IntPtr.Zero && hbmMask != IntPtr.Zero)
666
+ {
667
+ var ii = new Native.ICONINFO();
668
+ ii.fIcon = false;
669
+ ii.xHotspot = tipX;
670
+ ii.yHotspot = tipY;
671
+ ii.hbmColor = hbmColor;
672
+ ii.hbmMask = hbmMask;
673
+ hCursor = Native.CreateIconIndirect(ref ii);
674
+ }
675
+ }
676
+ finally
677
+ {
678
+ if (hbmColor != IntPtr.Zero) Native.DeleteObject(hbmColor);
679
+ if (hbmMask != IntPtr.Zero) Native.DeleteObject(hbmMask);
680
+ }
681
+ }
682
+ if (hCursor == IntPtr.Zero) return;
683
+ uint[] ids = new uint[] { Native.OCR_NORMAL, Native.OCR_IBEAM, Native.OCR_HAND, Native.OCR_APPSTARTING, Native.OCR_WAIT };
684
+ bool anyApplied = false;
685
+ for (int i = 0; i < ids.Length; i++)
686
+ {
687
+ IntPtr dup = Native.CopyIcon(hCursor);
688
+ if (dup == IntPtr.Zero) continue;
689
+ if (Native.SetSystemCursor(dup, ids[i])) anyApplied = true;
690
+ else Native.DestroyIcon(dup);
691
+ }
692
+ if (anyApplied) customCursorActive = true;
693
+ }
694
+ catch (Exception) { }
695
+ finally
696
+ {
697
+ if (hCursor != IntPtr.Zero) Native.DestroyIcon(hCursor);
698
+ }
699
+ }
700
+
701
+ /** Reload the user's native Windows cursor scheme (idempotent & crash-safe). */
702
+ public static void RestoreSystemCursor(bool force)
703
+ {
704
+ if (!force && !customCursorActive) return;
705
+ try { Native.SystemParametersInfo(Native.SPI_SETCURSORS, 0, IntPtr.Zero, 0); } catch (Exception) { }
706
+ customCursorActive = false;
707
+ }
708
+
595
709
  public static void Status(string newStatus)
596
710
  {
597
711
  if (thread == null || !visible) return;
@@ -620,6 +734,7 @@ namespace DshComputerUse
620
734
  {
621
735
  if (!visible || !petMode) { HideCore(); return; }
622
736
  HideMark();
737
+ RestoreSystemCursor(false);
623
738
  CloseInput(false);
624
739
  foreach (var g in glows) g.Close();
625
740
  glows.Clear();
@@ -635,14 +750,41 @@ namespace DshComputerUse
635
750
  public static void SetPaused(bool value)
636
751
  {
637
752
  if (thread == null) return;
638
- Ui(delegate { paused = value; RenderPill(); });
753
+ Ui(delegate
754
+ {
755
+ paused = value;
756
+ if (paused) { HideMark(); RestoreSystemCursor(false); }
757
+ else if (visible && clickTargetEnabled && !petFinished) { ApplyCustomCursor(); Native.POINT cp; if (Native.GetCursorPos(out cp)) ShowRestingMarkOnUi(cp.X, cp.Y); }
758
+ RenderPill();
759
+ });
639
760
  }
640
761
 
641
762
  public static void SetWaiting(bool value)
642
763
  {
643
764
  if (thread == null) return;
644
765
  if (value) SkipWaitRequested = false;
645
- Ui(delegate { petWaiting = value; if (visible) RenderPill(); });
766
+ Ui(delegate
767
+ {
768
+ petWaiting = value;
769
+ if (value) { petWaitingSince = DateTime.UtcNow; lastPhaseSec = -1; }
770
+ if (visible) RenderPill();
771
+ });
772
+ }
773
+
774
+ public static void SetPhase(string phase)
775
+ {
776
+ if (thread == null) return;
777
+ Ui(delegate
778
+ {
779
+ string next = phase ?? "";
780
+ if (petPhase != next)
781
+ {
782
+ petPhase = next;
783
+ petPhaseSince = DateTime.UtcNow;
784
+ lastPhaseSec = -1;
785
+ }
786
+ if (visible && !petFinished) RenderPill();
787
+ });
646
788
  }
647
789
 
648
790
  public static void Hide()
@@ -655,9 +797,12 @@ namespace DshComputerUse
655
797
  {
656
798
  {
657
799
  HideMark();
800
+ RestoreSystemCursor(false);
658
801
  CloseInput(false);
659
802
  petFinished = false;
660
803
  petWaiting = false;
804
+ petPhase = "";
805
+ lastPhaseSec = -1;
661
806
  SkipWaitRequested = false;
662
807
  petReply = "";
663
808
  visible = false;
@@ -676,8 +821,10 @@ namespace DshComputerUse
676
821
 
677
822
  public static void Shutdown()
678
823
  {
824
+ RestoreSystemCursor(false);
679
825
  if (thread == null) return;
680
826
  try { Hide(); Ui(delegate { Application.ExitThread(); }); } catch (Exception) { }
827
+ RestoreSystemCursor(false);
681
828
  }
682
829
 
683
830
  public static bool ShowClickTarget { get { return visible && clickTargetEnabled; } }
@@ -741,15 +888,16 @@ namespace DshComputerUse
741
888
  float pillW = textSize.Width > 0 ? (float)Math.Ceiling(textSize.Width + 2f * pillPadX) : 0f;
742
889
  float pillH = textSize.Height > 0 ? Math.Max(19f * s, (float)Math.Ceiling(textSize.Height + 5f * s)) : 0f;
743
890
 
744
- // Offsets relative to the pointer tip at (0, 0). Clear the native Windows pointer
745
- // arrow cleanly when attaching to the live OS cursor (drawArrow == false).
746
- float tagX = flipX ? (-10f * s - pillW) : (drawArrow ? 13f * s : 14f * s);
747
- float tagY = flipY ? (-10f * s - pillH) : (drawArrow ? 15f * s : 18f * s);
891
+ // Offsets relative to the pointer tip at (0, 0). When not showing a click ripple,
892
+ // keep the layered pill strictly outside the hardware cursor's bounding box so
893
+ // Windows DWM never flickers the hardware cursor plane over WDA_EXCLUDEFROMCAPTURE.
894
+ float tagX = flipX ? (-10f * s - pillW) : (ripple ? 14f * s : 16f * s);
895
+ float tagY = flipY ? (-10f * s - pillH) : (ripple ? 16f * s : 21f * s);
748
896
 
749
- float minX = Math.Min(-glowR, pillW > 0 ? tagX : 0f) - pad;
750
- float maxX = Math.Max(glowR, Math.Max(14f * s, pillW > 0 ? tagX + pillW : 0f)) + pad;
751
- float minY = Math.Min(-glowR, pillH > 0 ? tagY : 0f) - pad;
752
- float maxY = Math.Max(glowR, Math.Max(22f * s, pillH > 0 ? tagY + pillH : 0f)) + pad;
897
+ float minX = ripple ? Math.Min(-glowR, pillW > 0 ? tagX : 0f) - pad : (pillW > 0 ? tagX - pad : 0f);
898
+ float maxX = ripple ? Math.Max(glowR, Math.Max(14f * s, pillW > 0 ? tagX + pillW : 0f)) + pad : (pillW > 0 ? tagX + pillW + pad : 1f);
899
+ float minY = ripple ? Math.Min(-glowR, pillH > 0 ? tagY : 0f) - pad : (pillH > 0 ? tagY - pad : 0f);
900
+ float maxY = ripple ? Math.Max(glowR, Math.Max(22f * s, pillH > 0 ? tagY + pillH : 0f)) + pad : (pillH > 0 ? tagY + pillH + pad + 2f * s : 1f);
753
901
 
754
902
  int W = Math.Max(1, (int)Math.Ceiling(maxX - minX));
755
903
  int H = Math.Max(1, (int)Math.Ceiling(maxY - minY));
@@ -763,27 +911,36 @@ namespace DshComputerUse
763
911
  g.SmoothingMode = SmoothingMode.AntiAlias;
764
912
  g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
765
913
 
766
- // 1. Soft radial spotlight centered right under the tip (cx, cy).
767
- using (var spot = new GraphicsPath())
914
+ // 1. Soft radial spotlight ONLY on post-click ripples (avoid overlapping the live hardware cursor).
915
+ if (ripple)
768
916
  {
769
- spot.AddEllipse(cx - glowR, cy - glowR, glowR * 2f, glowR * 2f);
770
- using (var glow = new PathGradientBrush(spot))
917
+ using (var spot = new GraphicsPath())
771
918
  {
772
- glow.CenterPoint = new PointF(cx, cy);
773
- glow.CenterColor = Color.FromArgb(ripple ? 135 : 115, color);
774
- glow.SurroundColors = new Color[] { Color.FromArgb(0, color) };
775
- g.FillPath(glow, spot);
919
+ spot.AddEllipse(cx - glowR, cy - glowR, glowR * 2f, glowR * 2f);
920
+ using (var glow = new PathGradientBrush(spot))
921
+ {
922
+ glow.CenterPoint = new PointF(cx, cy);
923
+ glow.CenterColor = Color.FromArgb(135, color);
924
+ glow.SurroundColors = new Color[] { Color.FromArgb(0, color) };
925
+ g.FillPath(glow, spot);
926
+ }
776
927
  }
777
928
  }
778
929
 
779
- // 2. Post-click delicate ripple ring so exact placement reads cleanly in screenshots.
930
+ // 2. Post-click delicate ripple ring + crisp center dot so exact placement
931
+ // reads cleanly in screenshots without drawing a duplicate frozen arrow.
780
932
  if (ripple)
781
933
  {
782
934
  float rr = 11.5f * s;
783
- using (var ringHalo = new Pen(Color.FromArgb(140, 255, 255, 255), Math.Max(2.5f, 3.2f * s)))
935
+ using (var ringHalo = new Pen(Color.FromArgb(145, 255, 255, 255), Math.Max(2.5f, 3.2f * s)))
784
936
  g.DrawEllipse(ringHalo, cx - rr, cy - rr, rr * 2f, rr * 2f);
785
- using (var ring = new Pen(Color.FromArgb(230, color), Math.Max(1.6f, 2f * s)))
937
+ using (var ring = new Pen(Color.FromArgb(235, color), Math.Max(1.6f, 2f * s)))
786
938
  g.DrawEllipse(ring, cx - rr, cy - rr, rr * 2f, rr * 2f);
939
+ float dr = 3.2f * s;
940
+ using (var dotHalo = new SolidBrush(Color.FromArgb(245, 255, 255, 255)))
941
+ g.FillEllipse(dotHalo, cx - dr - 1.2f * s, cy - dr - 1.2f * s, (dr + 1.2f * s) * 2f, (dr + 1.2f * s) * 2f);
942
+ using (var dot = new SolidBrush(Color.FromArgb(255, color)))
943
+ g.FillEllipse(dot, cx - dr, cy - dr, dr * 2f, dr * 2f);
787
944
  }
788
945
 
789
946
  // 3. Attached collaborative name-tag pill.
@@ -865,7 +1022,8 @@ namespace DshComputerUse
865
1022
  int estW = (int)((Math.Max(6, labelText.Length) * 11 + 36) * s);
866
1023
  bool flipX = !mon.IsEmpty && x + estW > mon.Right;
867
1024
  bool flipY = !mon.IsEmpty && y + (int)(52 * s) > mon.Bottom;
868
- bool drawArrow = capturable;
1025
+ // The live hardware pointer itself is styled via SetSystemCursor (no duplicate frozen arrow).
1026
+ bool drawArrow = false;
869
1027
 
870
1028
  bool sameVisual = hasCachedMarkBitmap
871
1029
  && Math.Abs(scale - cachedMarkScale) < 0.01f
@@ -906,7 +1064,7 @@ namespace DshComputerUse
906
1064
  static void SyncRestingCursorOnUi()
907
1065
  {
908
1066
  Interlocked.Exchange(ref mouseMovePending, 0);
909
- if (!visible || !clickTargetEnabled || petFinished || !markActive || !markIsResting) return;
1067
+ if (!visible || !clickTargetEnabled || petFinished || paused || !markActive || !markIsResting) return;
910
1068
  PlaceMarkOnUi(latestMouseX, latestMouseY, cursorBadge, Accent, 0, false, false, true);
911
1069
  }
912
1070
 
@@ -957,7 +1115,7 @@ namespace DshComputerUse
957
1115
  else if (button == "right") { color = Color.FromArgb(16, 185, 129); verb = "已右键"; }
958
1116
  else if (button == "middle") { color = Color.FromArgb(6, 182, 212); verb = "已中键"; }
959
1117
  else { color = Color.FromArgb(59, 130, 246); verb = "已单击"; }
960
- Mark(x, y, verb + " " + coordLabel, color, 4000, true, true);
1118
+ Mark(x, y, verb + " " + coordLabel, color, 900, true, true);
961
1119
  }
962
1120
 
963
1121
  static void HideMark()
@@ -990,10 +1148,15 @@ namespace DshComputerUse
990
1148
  // pause / resume / stop, from Esc or the pill buttons.
991
1149
  static void Press(string action)
992
1150
  {
993
- if (action == "stop") { paused = false; petWaiting = false; SkipWaitRequested = true; Program.EmitEvent("stop", "button"); }
1151
+ if (action == "stop") { paused = false; petWaiting = false; SkipWaitRequested = true; RestoreSystemCursor(false); Program.EmitEvent("stop", "button"); }
994
1152
  else if (action == "skip_wait") { petWaiting = false; SkipWaitRequested = true; Program.EmitEvent("skip_wait", "button"); }
995
- else if (action == "pause") { paused = true; Program.EmitEvent("pause", "user"); }
996
- else if (action == "resume") { paused = false; pausedByInput = false; Program.EmitEvent("resume", "user"); }
1153
+ else if (action == "pause") { paused = true; HideMark(); RestoreSystemCursor(false); Program.EmitEvent("pause", "user"); }
1154
+ else if (action == "resume")
1155
+ {
1156
+ paused = false; pausedByInput = false;
1157
+ if (visible && clickTargetEnabled && !petFinished) { ApplyCustomCursor(); Native.POINT cp; if (Native.GetCursorPos(out cp)) ShowRestingMarkOnUi(cp.X, cp.Y); }
1158
+ Program.EmitEvent("resume", "user");
1159
+ }
997
1160
  else if (action == "expand") petExpanded = !petExpanded;
998
1161
  else if (action == "input") { if (input == null) OpenInput(); else CloseInput(true); return; }
999
1162
  else if (action == "send") { if (input != null) SubmitInput(input.Box.Text); return; }
@@ -1005,12 +1168,12 @@ namespace DshComputerUse
1005
1168
  {
1006
1169
  beforeInput = Native.GetForegroundWindow();
1007
1170
  // Typing an instruction pauses the agent, so its keys cannot land in the box.
1008
- if (!paused) { paused = true; pausedByInput = true; Program.EmitEvent("pause", "input"); }
1171
+ if (!paused) { paused = true; pausedByInput = true; HideMark(); RestoreSystemCursor(false); Program.EmitEvent("pause", "input"); }
1009
1172
  bool dark = DarkTheme();
1010
1173
  float px = 1.333f * Scale();
1011
1174
  input = new InputBox(new Font("Microsoft YaHei UI", 10f * px, FontStyle.Regular, GraphicsUnit.Pixel),
1012
1175
  dark ? Color.FromArgb(52, 51, 49) : Color.White, dark ? Color.FromArgb(244, 243, 241) : Color.FromArgb(31, 30, 29),
1013
- "告诉 DeepSeek 接下来做什么(Enter 发送,Esc 取消)");
1176
+ "告诉 AI 接下来做什么(Enter 发送,Esc 取消)");
1014
1177
  input.Submitted += SubmitInput;
1015
1178
  input.Cancelled += delegate { CloseInput(true); };
1016
1179
  inputBounds = Rectangle.Empty;
@@ -1041,7 +1204,12 @@ namespace DshComputerUse
1041
1204
  InputHwnd = IntPtr.Zero;
1042
1205
  inputBounds = Rectangle.Empty;
1043
1206
  box.Close();
1044
- if (pausedByInput) { paused = false; pausedByInput = false; Program.EmitEvent("resume", "input"); }
1207
+ if (pausedByInput)
1208
+ {
1209
+ paused = false; pausedByInput = false;
1210
+ if (visible && clickTargetEnabled && !petFinished) { ApplyCustomCursor(); Native.POINT cp; if (Native.GetCursorPos(out cp)) ShowRestingMarkOnUi(cp.X, cp.Y); }
1211
+ Program.EmitEvent("resume", "input");
1212
+ }
1045
1213
  var target = beforeInput;
1046
1214
  beforeInput = IntPtr.Zero;
1047
1215
  if (restoreFocus && target != IntPtr.Zero && Native.IsWindow(target))
@@ -1055,8 +1223,12 @@ namespace DshComputerUse
1055
1223
  {
1056
1224
  if (markActive && DateTime.UtcNow >= markExpiresAt)
1057
1225
  {
1058
- if (visible && clickTargetEnabled && !petFinished && hasLastMark)
1059
- ShowRestingMarkOnUi(lastMarkX, lastMarkY);
1226
+ if (visible && clickTargetEnabled && !petFinished && !paused)
1227
+ {
1228
+ Native.POINT cp;
1229
+ if (Native.GetCursorPos(out cp)) ShowRestingMarkOnUi(cp.X, cp.Y);
1230
+ else if (hasLastMark) ShowRestingMarkOnUi(lastMarkX, lastMarkY);
1231
+ }
1060
1232
  else
1061
1233
  HideMark();
1062
1234
  }
@@ -1065,12 +1237,12 @@ namespace DshComputerUse
1065
1237
  if (!markActive) timer.Stop();
1066
1238
  return;
1067
1239
  }
1068
- if (visible && clickTargetEnabled && !petFinished && !markActive)
1240
+ if (visible && clickTargetEnabled && !petFinished && !paused && !markActive)
1069
1241
  {
1070
1242
  Native.POINT cp;
1071
1243
  if (Native.GetCursorPos(out cp)) ShowRestingMarkOnUi(cp.X, cp.Y);
1072
1244
  }
1073
- else if (visible && clickTargetEnabled && !petFinished && markActive && markIsResting)
1245
+ else if (visible && clickTargetEnabled && !petFinished && !paused && markActive && markIsResting)
1074
1246
  {
1075
1247
  Native.POINT cp;
1076
1248
  if (Native.GetCursorPos(out cp) && (Math.Abs(cp.X - lastMarkX) > 2 || Math.Abs(cp.Y - lastMarkY) > 2))
@@ -1090,12 +1262,16 @@ namespace DshComputerUse
1090
1262
  byte alpha = (byte)Math.Max(0, Math.Min(255, 255 * fadeIn * breathe));
1091
1263
  foreach (var g in glows) g.SetAlpha(alpha);
1092
1264
  if (Key() != rendered) RenderPill(); // typing started or stopped
1265
+ else if (!paused && (petWaiting || petPhase == "llm"))
1266
+ {
1267
+ int sec = (int)Math.Max(0, Math.Floor((DateTime.UtcNow - (petWaiting ? petWaitingSince : petPhaseSince)).TotalSeconds));
1268
+ if (sec != lastPhaseSec) { lastPhaseSec = sec; RenderPill(); }
1269
+ }
1093
1270
  if ((int)(t * 25) % 50 == 0)
1094
1271
  {
1095
1272
  foreach (var g in glows) g.KeepOnTop();
1096
1273
  if (pill != null) pill.KeepOnTop();
1097
1274
  if (pet != null) pet.KeepOnTop();
1098
- if (markForm != null) markForm.KeepOnTop();
1099
1275
  if (input != null) Native.SetWindowPos(input.Handle, new IntPtr(-1), 0, 0, 0, 0, 0x0001 | 0x0002 | 0x0010);
1100
1276
  }
1101
1277
  }
@@ -1260,13 +1436,20 @@ namespace DshComputerUse
1260
1436
 
1261
1437
  bool isCompact = petSize == "compact";
1262
1438
  bool isDetailed = petSize == "detailed";
1439
+ int waitSec = petWaiting ? (int)Math.Max(0, Math.Floor((DateTime.UtcNow - petWaitingSince).TotalSeconds)) : 0;
1440
+ int llmSec = petPhase == "llm" ? (int)Math.Max(0, Math.Floor((DateTime.UtcNow - petPhaseSince).TotalSeconds)) : 0;
1441
+ bool hasReply = !petFinished && petReply.Length > 0;
1442
+ bool showLlmWait = !petFinished && !paused && !petWaiting && petPhase == "llm" && !hasReply && petThinking.Length == 0;
1263
1443
  string hoverTip = ButtonTip(hoveredBtn);
1264
1444
  string title = hoverTip.Length > 0
1265
- ? (isCompact ? "" : "DeepSeek")
1445
+ ? (isCompact ? "" : "DSH")
1266
1446
  : petFinished ? "已完成" : (isCompact && label.Length > 12 ? label.Substring(0, 11) + "…" : label);
1267
1447
  string state = hoverTip.Length > 0 ? hoverTip
1268
1448
  : petFinished ? "" : paused ? (input != null ? "输入指令中…" : "已暂停 · Esc 继续")
1269
- : Typing() ? "你正在操作,已暂停" : (isCompact ? "" : "Esc 暂停");
1449
+ : Typing() ? "你正在操作,已暂停"
1450
+ : petWaiting ? (isCompact ? ("等待 " + waitSec + "s") : ("等待画面 " + waitSec + "s"))
1451
+ : showLlmWait ? (isCompact ? ("模型响应 " + llmSec + "s") : ("等待模型响应 " + llmSec + "s"))
1452
+ : (isCompact ? "" : "Esc 暂停");
1270
1453
  // Header buttons, right to left.
1271
1454
  var actions = new List<string>(); var glyphs = new List<string>();
1272
1455
  if (petFinished) { actions.Add("close"); glyphs.Add("\uE711"); }
@@ -1285,13 +1468,16 @@ namespace DshComputerUse
1285
1468
  float bodyW = (isCompact ? 320f : isDetailed ? 484f : 420f) * s;
1286
1469
  float pad = (isCompact ? 13f : 16f) * s;
1287
1470
  float headH = (isCompact ? 40f : 44f) * s;
1288
- bool showThinking = !isCompact || petExpanded || (!petFinished && petReply.Length > 0);
1471
+ bool showThinking = !isCompact || petExpanded || hasReply || petWaiting || showLlmWait;
1289
1472
  bool showTimeline = petExpanded || isDetailed;
1290
1473
  float replyH = showThinking ? (isDetailed && !petExpanded ? 42f * s : 26f * s) : 0f;
1291
- bool hasReply = !petFinished && petReply.Length > 0;
1292
1474
  string progressPrefix = hasReply ? "说明 · " : "思考 · ";
1293
1475
  string progressBody = hasReply ? petReply : petThinking;
1294
- string progress = petFinished ? "已交还电脑控制" : progressBody.Length > 0 ? progressPrefix + progressBody : "正在操作,等待下一步…";
1476
+ string progress = petFinished ? "已交还电脑控制"
1477
+ : petWaiting ? ("等待画面变化… " + waitSec + "s(点右上角 ⏭ 可提前继续)")
1478
+ : progressBody.Length > 0 ? progressPrefix + progressBody
1479
+ : showLlmWait ? ("等待模型响应中… " + llmSec + "s")
1480
+ : "正在操作,等待下一步…";
1295
1481
  if (showThinking && (petExpanded || isDetailed))
1296
1482
  {
1297
1483
  using (var probe = new Bitmap(1, 1))
@@ -1700,17 +1886,19 @@ namespace DshComputerUse
1700
1886
  if (nCode >= 0 && visible)
1701
1887
  {
1702
1888
  int msg = wParam.ToInt32();
1703
- // Hardware-rate cursor tracking on WM_MOUSEMOVE: never triggers takeover, only moves
1704
- // the cached resting badge via SetWindowPos for silky native-grade responsiveness.
1889
+ // Hardware-rate cursor tracking on WM_MOUSEMOVE (throttled to ~60Hz so 1000Hz mice
1890
+ // never flood the UI thread): never triggers takeover, only moves the cached badge.
1705
1891
  if (msg == 0x0200)
1706
1892
  {
1707
- if (clickTargetEnabled && !petFinished && markActive && markIsResting && invoker != null)
1893
+ if (clickTargetEnabled && !petFinished && !paused && markActive && markIsResting && invoker != null)
1708
1894
  {
1709
1895
  var mm = (Native.MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Native.MSLLHOOKSTRUCT));
1710
1896
  latestMouseX = mm.pt.X;
1711
1897
  latestMouseY = mm.pt.Y;
1712
- if (Interlocked.Exchange(ref mouseMovePending, 1) == 0)
1898
+ int tick = Environment.TickCount;
1899
+ if (unchecked(tick - lastMouseMoveTick) >= 16 && Interlocked.Exchange(ref mouseMovePending, 1) == 0)
1713
1900
  {
1901
+ lastMouseMoveTick = tick;
1714
1902
  try { invoker.BeginInvoke((MethodInvoker)SyncRestingCursorOnUi); }
1715
1903
  catch (Exception) { Interlocked.Exchange(ref mouseMovePending, 0); }
1716
1904
  }
package/helper/Program.cs CHANGED
@@ -94,6 +94,7 @@ namespace DshComputerUse
94
94
  parser.MaxJsonLength = int.MaxValue;
95
95
  Apps.Warm();
96
96
  Windows.RecoverCards(false);
97
+ AppDomain.CurrentDomain.ProcessExit += delegate { Overlay.RestoreSystemCursor(false); };
97
98
 
98
99
  var hello = new Dictionary<string, object>();
99
100
  hello["event"] = "ready"; hello["version"] = Version; hello["pid"] = Process.GetCurrentProcess().Id;
@@ -123,7 +124,7 @@ namespace DshComputerUse
123
124
  Emit(reply);
124
125
  }
125
126
  }
126
- finally { Windows.RecoverCards(true); Overlay.Shutdown(); }
127
+ finally { Windows.RecoverCards(true); Overlay.Shutdown(); Overlay.RestoreSystemCursor(false); }
127
128
  return 0;
128
129
  }
129
130
 
@@ -198,7 +199,7 @@ namespace DshComputerUse
198
199
  case "clipboard_release": Clip.Release(); return null;
199
200
  case "paste": return Input.Paste(Args.Str(r, "text", ""), Args.Bool(r, "restore", true), Args.Int(r, "waitMs", 250));
200
201
  case "windows": return Windows.List();
201
- case "window_recover": Windows.RecoverCards(false); return null;
202
+ case "window_recover": Windows.RecoverCards(false); Overlay.RestoreSystemCursor(true); return null;
202
203
  case "background": return Windows.Background(Args.Bool(r, "tray", true));
203
204
  case "tray_restore": return Tray.Restore(Args.Str(r, "exe", ""));
204
205
  case "card_opacity": CardLayer.SetOpacity(Args.Int(r, "opacity", 100)); return null;
@@ -230,6 +231,7 @@ namespace DshComputerUse
230
231
  case "overlay_show": Overlay.ExcludeFromCapture = Args.Bool(r, "excludeFromCapture", true); Overlay.Show(r); return null;
231
232
  case "overlay_pause": Overlay.SetPaused(Args.Bool(r, "paused", false)); return null;
232
233
  case "overlay_waiting": Overlay.SetWaiting(Args.Bool(r, "waiting", false)); return null;
234
+ case "overlay_phase": Overlay.SetPhase(Args.Str(r, "phase", "")); return null;
233
235
  case "window_card": CardLayer.SetOpacity(Args.Int(r, "opacity", 100)); 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));
234
236
  case "window_uncard": return Windows.Uncard(new IntPtr(Convert.ToInt64(r["hwnd"])));
235
237
  case "overlay_status": Overlay.Status(Args.Str(r, "status", "")); return null;
package/lib/index.js CHANGED
@@ -1270,9 +1270,10 @@ var OverlayController = class {
1270
1270
  if (controlSignal?.aborted) onControlAbort();
1271
1271
  else controlSignal?.addEventListener("abort", onControlAbort, { once: true });
1272
1272
  this.waitSkippers.add(skip);
1273
- this.helper.call("overlay_waiting", { waiting: true }).catch(() => {});
1273
+ const ready = this.helper.call("overlay_waiting", { waiting: true }, 2e3).then(() => {}, () => {});
1274
1274
  return {
1275
1275
  signal: ctrl.signal,
1276
+ ready,
1276
1277
  skipped: () => wasSkipped && !signal.aborted && !wasStopped,
1277
1278
  controlStopped: () => wasStopped,
1278
1279
  done: () => {
@@ -1285,6 +1286,14 @@ var OverlayController = class {
1285
1286
  }
1286
1287
  };
1287
1288
  }
1289
+ /** Mark that the computer-use tool finished and we are now waiting for the LLM API response. */
1290
+ awaitingModel(agent) {
1291
+ if (!this.visible || this.paused || this.stopping) return;
1292
+ if (agent !== void 0 && this.agent !== void 0 && agent !== this.agent) return;
1293
+ this.thinking = "";
1294
+ this.reply = "";
1295
+ this.helper.call("overlay_phase", { phase: "llm" }).catch(() => {});
1296
+ }
1288
1297
  recordUserAction(action) {
1289
1298
  const prev = this.userActions.at(-1);
1290
1299
  if (action.kind === "type" && prev?.kind === "type" && prev.exe === action.exe && prev.role === action.role && prev.name === action.name && action.at - prev.at < 8e3) {
@@ -1366,6 +1375,7 @@ var OverlayController = class {
1366
1375
  this.cardOpacity = settings.cardOpacity;
1367
1376
  await this.helper.call("card_opacity", { opacity: settings.cardOpacity }).catch(() => {});
1368
1377
  }
1378
+ this.helper.call("overlay_phase", { phase: "tool" }).catch(() => {});
1369
1379
  await this.status(status);
1370
1380
  }
1371
1381
  async start(agent, status, settings) {
@@ -1436,6 +1446,7 @@ var OverlayController = class {
1436
1446
  if (frame.type === "start") {
1437
1447
  this.thinking = "";
1438
1448
  this.reply = "";
1449
+ if (this.visible && agent === this.agent) this.helper.call("overlay_phase", { phase: "llm" }).catch(() => {});
1439
1450
  this.schedulePush();
1440
1451
  return;
1441
1452
  }
@@ -1444,6 +1455,7 @@ var OverlayController = class {
1444
1455
  if (!chunk) return;
1445
1456
  if (chunk.type === "text-delta" && chunk.text) {
1446
1457
  if (this.visible && this.agent && agent === this.agent && !this.paused && !this.stopping) {
1458
+ this.helper.call("overlay_phase", { phase: "" }).catch(() => {});
1447
1459
  if (this.settings().hostWindow === "pet") {
1448
1460
  this.reply = plainLine(this.reply + chunk.text).slice(-300);
1449
1461
  this.schedulePush();
@@ -1455,6 +1467,7 @@ var OverlayController = class {
1455
1467
  return;
1456
1468
  }
1457
1469
  if (chunk.type !== "reasoning-delta" || !chunk.text) return;
1470
+ if (this.thinking === "" && this.visible && agent === this.agent) this.helper.call("overlay_phase", { phase: "" }).catch(() => {});
1458
1471
  this.reply = "";
1459
1472
  this.thinking = plainLine(this.thinking + chunk.text).slice(-300);
1460
1473
  this.schedulePush();
@@ -1785,7 +1798,7 @@ var Computer = class Computer {
1785
1798
  heldButton = false;
1786
1799
  /** Dimensions of the latest full-display screenshot shown to the model (keeps coordinate conversion exact across detail modes). */
1787
1800
  lastShot;
1788
- /** Recent click locations (fallback repeat counter when helper does not report repeat). */
1801
+ /** Recent click locations (repeat counter + auto physical-click fallback if a UIA invoke had no effect). */
1789
1802
  clickHistory = [];
1790
1803
  /** The agent that last wrote the clipboard; when it goes idle the user's clipboard comes back. */
1791
1804
  clipboardAgent;
@@ -2008,8 +2021,8 @@ var Computer = class Computer {
2008
2021
  quality: budget.jpegQuality
2009
2022
  }) ?? "unchanged";
2010
2023
  }
2011
- /** Record a physical click position and return how many times this spot (±24 px) was clicked in the last 2 minutes. */
2012
- noteClick(point, helperRepeat) {
2024
+ /** Record a click position and return how many times this spot (±24 px) was clicked in the last 2 minutes. */
2025
+ noteClick(point, helperRepeat, via = "physical") {
2013
2026
  const now = Date.now();
2014
2027
  while (this.clickHistory.length > 0 && now - this.clickHistory[0].at > REPEAT_WINDOW_MS) this.clickHistory.shift();
2015
2028
  let local = 0;
@@ -2017,12 +2030,24 @@ var Computer = class Computer {
2017
2030
  this.clickHistory.push({
2018
2031
  x: point.x,
2019
2032
  y: point.y,
2020
- at: now
2033
+ at: now,
2034
+ via
2021
2035
  });
2022
2036
  for (const entry of this.clickHistory) if (Math.abs(entry.x - point.x) <= REPEAT_RADIUS_PX && Math.abs(entry.y - point.y) <= REPEAT_RADIUS_PX) local++;
2023
2037
  }
2024
2038
  return typeof helperRepeat === "number" && Number.isFinite(helperRepeat) && helperRepeat > 0 ? helperRepeat : local;
2025
2039
  }
2040
+ /** Whether this spot (±24 px) was already clicked via background UIA invoke recently (so a retry should use a real physical click). */
2041
+ hadRecentUiaClickAt(point, windowMs = 3e4) {
2042
+ if (!point) return false;
2043
+ const now = Date.now();
2044
+ for (let i = this.clickHistory.length - 1; i >= 0; i--) {
2045
+ const entry = this.clickHistory[i];
2046
+ if (now - entry.at > windowMs) break;
2047
+ if (Math.abs(entry.x - point.x) <= REPEAT_RADIUS_PX && Math.abs(entry.y - point.y) <= REPEAT_RADIUS_PX) return entry.via === "uia";
2048
+ }
2049
+ return false;
2050
+ }
2026
2051
  async foreground() {
2027
2052
  const win = await this.helper.call("foreground");
2028
2053
  if (!win || typeof win.hwnd !== "number") return void 0;
@@ -2040,7 +2065,7 @@ var Computer = class Computer {
2040
2065
  if (!fg || !(isHostWindow(fg) || isTransientShell(fg)) || !target || target.hwnd === fg.hwnd) return;
2041
2066
  if ((await this.focus(target).catch(() => void 0))?.focused) await setTimeout$1(80);
2042
2067
  }
2043
- /** Wait at most `maxMs`, returning once the screen has been still for ~0.8 s or the user clicks "跳过等待". */
2068
+ /** Wait at most `maxMs`, returning once the screen settles (for waits ≥ 4s, waits for a real visual update first and emits progress checkpoints if still changing so AI can act early or wait again). */
2044
2069
  async waitForQuiet(maxMs, signal, wait) {
2045
2070
  const started = Date.now();
2046
2071
  const waitSignal = wait?.signal ?? signal;
@@ -2066,6 +2091,7 @@ var Computer = class Computer {
2066
2091
  };
2067
2092
  }
2068
2093
  const display = await this.display();
2094
+ const waitForChange = maxMs >= 4e3;
2069
2095
  const settlePromise = this.helper.call("settle", {
2070
2096
  x: display.x,
2071
2097
  y: display.y,
@@ -2073,7 +2099,12 @@ var Computer = class Computer {
2073
2099
  height: display.height,
2074
2100
  minMs: 300,
2075
2101
  maxMs,
2076
- quietMs: 800
2102
+ quietMs: waitForChange ? 800 : 600,
2103
+ ...waitForChange ? {
2104
+ waitForChange: true,
2105
+ checkpointMs: 3500,
2106
+ noChangeMaxMs: Math.min(maxMs, 4e3)
2107
+ } : {}
2077
2108
  }, maxMs + 1e4).catch(() => null);
2078
2109
  const abortPromise = new Promise((resolve) => {
2079
2110
  if (waitSignal.aborted) {
@@ -2101,9 +2132,13 @@ var Computer = class Computer {
2101
2132
  }
2102
2133
  const earlyEnd = checkAfter();
2103
2134
  if (earlyEnd) return earlyEnd;
2135
+ const changed = raced !== "aborted" && raced !== null ? raced.changed : void 0;
2136
+ const checkpoint = raced !== "aborted" && raced !== null ? raced.checkpoint : void 0;
2104
2137
  return {
2105
2138
  ms: Date.now() - started,
2106
- skipped: false
2139
+ skipped: false,
2140
+ ...changed !== void 0 ? { changed } : {},
2141
+ ...checkpoint !== void 0 ? { checkpoint } : {}
2107
2142
  };
2108
2143
  }
2109
2144
  /** Wait until the screen stops changing (bounded), instead of a fixed delay. */
@@ -2698,10 +2733,15 @@ var Computer = class Computer {
2698
2733
  case "wait": {
2699
2734
  const wait = this.overlay.beginWait?.(call.signal);
2700
2735
  try {
2736
+ if (wait?.ready) await wait.ready;
2701
2737
  if (input.until) return { text: await this.waitUntil(input, call.signal, wait) };
2702
2738
  const seconds = Math.min(30, Math.max(0, Number(input.duration ?? 1) || 0));
2703
2739
  const res = await this.waitForQuiet(seconds * 1e3, call.signal, wait);
2704
2740
  if (res.skipped) return { text: `Wait skipped early by the user after ${(res.ms / 1e3).toFixed(1)}s — inspect the new screenshot and continue now.` };
2741
+ if (res.checkpoint === true && res.changed === true) return { text: `Waited ${(res.ms / 1e3).toFixed(1)}s (screen updated — progress checkpoint while still changing; act now if ready, or wait again if still loading).` };
2742
+ if (res.checkpoint === true && res.changed === false) return { text: `Waited ${(res.ms / 1e3).toFixed(1)}s (no major visual change yet — check the screenshot; act if already ready, or wait again).` };
2743
+ if (res.changed === true && res.ms < seconds * 1e3 - 200) return { text: `Waited ${(res.ms / 1e3).toFixed(1)}s (screen updated and settled).` };
2744
+ if (res.changed === false && seconds >= 4) return { text: `Waited ${seconds}s (no major visual change detected).` };
2705
2745
  return { text: res.ms < seconds * 1e3 - 200 ? `Waited ${(res.ms / 1e3).toFixed(1)}s (the screen settled early).` : `Waited ${seconds}s.` };
2706
2746
  } finally {
2707
2747
  wait?.done();
@@ -2724,11 +2764,15 @@ var Computer = class Computer {
2724
2764
  const button = action === "right_click" ? "right" : action === "middle_click" ? "middle" : "left";
2725
2765
  const count = action === "double_click" ? 2 : action === "triple_click" ? 3 : 1;
2726
2766
  const modifiers = parseModifiers(input.modifiers ?? input.text);
2727
- if (action === "left_click" && named && modifiers.length === 0) {
2767
+ const retryAfterUia = action === "left_click" && modifiers.length === 0 && this.hadRecentUiaClickAt(p);
2768
+ if (action === "left_click" && named && modifiers.length === 0 && !retryAfterUia) {
2728
2769
  const semantic = named.element.role === "Edit" || named.element.editable ? "focus" : "invoke";
2729
- if (await this.semanticAction(call, named, semantic)) return { text: `${semantic === "focus" ? "Focused" : "Invoked"}${label}.` };
2770
+ if (await this.semanticAction(call, named, semantic)) {
2771
+ this.noteClick(p, void 0, "uia");
2772
+ return { text: `${semantic === "focus" ? "Focused" : "Invoked"}${label}.` };
2773
+ }
2730
2774
  }
2731
- if (action === "left_click" && !named && p && modifiers.length === 0 && s.elementFirstClick) {
2775
+ if (action === "left_click" && !named && p && modifiers.length === 0 && s.elementFirstClick && !retryAfterUia) {
2732
2776
  let hit = null;
2733
2777
  let uncertainReason;
2734
2778
  try {
@@ -2742,7 +2786,7 @@ var Computer = class Computer {
2742
2786
  }
2743
2787
  if (hit?.ok === true) {
2744
2788
  this.invalidateMarks();
2745
- const repeat = this.noteClick(p);
2789
+ const repeat = this.noteClick(p, void 0, "uia");
2746
2790
  const repeatHint = repeat >= 3 ? ` (same spot clicked ${repeat} times — screenshot before clicking again)` : "";
2747
2791
  return { text: `Invoked ${hit.name ? `${hit.role || "control"} "${hit.name.slice(0, 40)}"` : hit.role || "control"}${label} in background (${hit.mechanism || "uia"}).${repeatHint}` };
2748
2792
  }
@@ -2775,9 +2819,10 @@ var Computer = class Computer {
2775
2819
  x: clickRes.x,
2776
2820
  y: clickRes.y
2777
2821
  } : void 0);
2778
- const repeat = this.noteClick(clickedAt, clickRes?.repeat);
2822
+ const repeat = this.noteClick(clickedAt, clickRes?.repeat, "physical");
2779
2823
  const repeatHint = repeat >= 3 ? ` (same spot clicked ${repeat} times — screenshot before clicking again)` : "";
2780
- return { text: `${action.replace("_", " ")}${label}${modifiers.length ? ` holding ${input.modifiers ?? input.text}` : ""}.${repeatHint}` };
2824
+ const fallbackNote = retryAfterUia ? " (physical click after prior UIA invoke at same spot)" : "";
2825
+ return { text: `${action.replace("_", " ")}${label}${modifiers.length ? ` holding ${input.modifiers ?? input.text}` : ""}.${fallbackNote}${repeatHint}` };
2781
2826
  }
2782
2827
  case "left_click_drag": {
2783
2828
  const from = await this.point(input.start_coordinate, "start_coordinate");
@@ -3237,6 +3282,7 @@ var HelperClient = class HelperClient {
3237
3282
  pending = /* @__PURE__ */ new Map();
3238
3283
  listeners = /* @__PURE__ */ new Set();
3239
3284
  cardChildren = /* @__PURE__ */ new WeakSet();
3285
+ overlayChildren = /* @__PURE__ */ new WeakSet();
3240
3286
  nextId = 0;
3241
3287
  disposed = false;
3242
3288
  constructor(log = () => {}) {
@@ -3266,6 +3312,8 @@ var HelperClient = class HelperClient {
3266
3312
  child
3267
3313
  });
3268
3314
  if (cmd === "window_card") this.cardChildren.add(child);
3315
+ else if (cmd === "overlay_show") this.overlayChildren.add(child);
3316
+ else if (cmd === "overlay_hide") this.overlayChildren.delete(child);
3269
3317
  child.stdin.write(`${JSON.stringify({
3270
3318
  ...args,
3271
3319
  id,
@@ -3361,7 +3409,7 @@ var HelperClient = class HelperClient {
3361
3409
  entry.reject(/* @__PURE__ */ new Error(`computer-use helper exited (code ${String(code)})`));
3362
3410
  this.pending.delete(id);
3363
3411
  }
3364
- if (this.cardChildren.has(child) && (!this.disposed || code !== 0)) {
3412
+ if ((this.cardChildren.has(child) || this.overlayChildren.has(child)) && (!this.disposed || code !== 0)) {
3365
3413
  const recovery = this.disposed ? new HelperClient(this.log) : this;
3366
3414
  recovery.call("window_recover").catch((error) => {
3367
3415
  if (!recovery.disposed) this.log(`recover host window: ${String(error)}`);
@@ -12122,7 +12170,7 @@ function apply(ctx, config = {}) {
12122
12170
  ctx.on("agent/assistant-stream", ({ agent, frame }) => {
12123
12171
  overlay.stream(agent, frame);
12124
12172
  });
12125
- ctx.on("tools/pre-execute", (exec, next) => {
12173
+ ctx.on("tools/pre-execute", async (exec, next) => {
12126
12174
  if (!OWN_TOOLS.has(exec.name)) {
12127
12175
  const args = exec.arguments ?? {};
12128
12176
  const detail = [
@@ -12133,8 +12181,13 @@ function apply(ctx, config = {}) {
12133
12181
  args.url
12134
12182
  ].find((value) => typeof value === "string");
12135
12183
  overlay.toolStarted(exec.agent, exec.name, (detail ?? "").split("\n")[0].slice(0, 120));
12184
+ return next();
12185
+ }
12186
+ try {
12187
+ return await next();
12188
+ } finally {
12189
+ overlay.awaitingModel(exec.agent);
12136
12190
  }
12137
- return next();
12138
12191
  });
12139
12192
  overlay.onMessage = (agent, text) => {
12140
12193
  const steer = agent.steer;
@@ -164,7 +164,7 @@ export declare class Computer {
164
164
  private heldButton;
165
165
  /** Dimensions of the latest full-display screenshot shown to the model (keeps coordinate conversion exact across detail modes). */
166
166
  private lastShot;
167
- /** Recent click locations (fallback repeat counter when helper does not report repeat). */
167
+ /** Recent click locations (repeat counter + auto physical-click fallback if a UIA invoke had no effect). */
168
168
  private readonly clickHistory;
169
169
  /** The agent that last wrote the clipboard; when it goes idle the user's clipboard comes back. */
170
170
  clipboardAgent: CancellableAgent | undefined;
@@ -225,8 +225,10 @@ export declare class Computer {
225
225
  force?: boolean;
226
226
  detail?: ScreenshotDetail;
227
227
  }): Promise<Shot | 'unchanged'>;
228
- /** Record a physical click position and return how many times this spot (±24 px) was clicked in the last 2 minutes. */
228
+ /** Record a click position and return how many times this spot (±24 px) was clicked in the last 2 minutes. */
229
229
  private noteClick;
230
+ /** Whether this spot (±24 px) was already clicked via background UIA invoke recently (so a retry should use a real physical click). */
231
+ private hadRecentUiaClickAt;
230
232
  foreground(): Promise<WindowInfo | undefined>;
231
233
  /**
232
234
  * The user clicked into the DeepSeek Harness card (to read or scroll the
@@ -234,10 +236,12 @@ export declare class Computer {
234
236
  * in front instead of refusing.
235
237
  */
236
238
  private refocusFromHost;
237
- /** Wait at most `maxMs`, returning once the screen has been still for ~0.8 s or the user clicks "跳过等待". */
239
+ /** Wait at most `maxMs`, returning once the screen settles (for waits ≥ 4s, waits for a real visual update first and emits progress checkpoints if still changing so AI can act early or wait again). */
238
240
  waitForQuiet(maxMs: number, signal: AbortSignal, wait?: WaitHandle): Promise<{
239
241
  ms: number;
240
242
  skipped: boolean;
243
+ changed?: boolean;
244
+ checkpoint?: boolean;
241
245
  }>;
242
246
  /** Wait until the screen stops changing (bounded), instead of a fixed delay. */
243
247
  settle(signal: AbortSignal): Promise<void>;
@@ -24,6 +24,7 @@ export declare class HelperClient implements HelperLike {
24
24
  private readonly pending;
25
25
  private readonly listeners;
26
26
  private readonly cardChildren;
27
+ private readonly overlayChildren;
27
28
  private nextId;
28
29
  private disposed;
29
30
  constructor(log?: (message: string) => void);
@@ -76,6 +76,7 @@ export declare function cardRect(display: DisplayRow): {
76
76
  export declare const CONTROL_STOPPED_MESSAGE = "The user stopped computer control and returned to DeepSeek Harness. Do not perform further desktop actions unless the user asks again; summarize your progress and reply in DeepSeek Harness.";
77
77
  export interface WaitHandle {
78
78
  readonly signal: AbortSignal;
79
+ readonly ready: Promise<void>;
79
80
  skipped(): boolean;
80
81
  controlStopped(): boolean;
81
82
  done(): void;
@@ -134,6 +135,8 @@ export declare class OverlayController {
134
135
  private skipActiveWaits;
135
136
  /** Register an active wait so the Pet card / pill exposes the "跳过等待" button. */
136
137
  beginWait(signal: AbortSignal): WaitHandle;
138
+ /** Mark that the computer-use tool finished and we are now waiting for the LLM API response. */
139
+ awaitingModel(agent: unknown): void;
137
140
  private recordUserAction;
138
141
  /** Whether the user has performed physical mouse/keyboard actions not yet reported to the model. */
139
142
  hasUserActions(): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "icon": "assets/icon.svg",
6
6
  "type": "module",