@copylee/dsh-computer-use 0.14.0 → 0.14.1
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 +34 -3
- package/helper/Native.cs +10 -0
- package/helper/Overlay.cs +160 -23
- package/helper/Program.cs +3 -2
- package/lib/index.js +45 -14
- package/lib/types/computer.d.ts +7 -3
- package/package.json +1 -1
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[]
|
|
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
|
-
|
|
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
|
|
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_HAND = 32649;
|
|
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);
|
package/helper/Overlay.cs
CHANGED
|
@@ -379,7 +379,8 @@ namespace DshComputerUse
|
|
|
379
379
|
static volatile bool petWaiting;
|
|
380
380
|
public static volatile bool SkipWaitRequested;
|
|
381
381
|
static volatile bool clickTargetEnabled = true;
|
|
382
|
-
static
|
|
382
|
+
static volatile bool customCursorActive;
|
|
383
|
+
static string cursorBadge = "DSH";
|
|
383
384
|
static LayeredForm markForm;
|
|
384
385
|
static DateTime markExpiresAt = DateTime.MinValue;
|
|
385
386
|
static bool markActive;
|
|
@@ -483,10 +484,14 @@ namespace DshComputerUse
|
|
|
483
484
|
if (reqSize == "compact" || reqSize == "standard" || reqSize == "detailed") petSize = reqSize;
|
|
484
485
|
clickTargetEnabled = Args.Bool(r, "glow", true);
|
|
485
486
|
string badgeSrc = label.Replace("正在操控你的电脑", "").Replace("正在操控", "").Trim();
|
|
486
|
-
if (badgeSrc.StartsWith("DeepSeek", StringComparison.OrdinalIgnoreCase)) cursorBadge = "
|
|
487
|
-
else
|
|
488
|
-
|
|
489
|
-
|
|
487
|
+
if (badgeSrc.Length == 0 || badgeSrc.StartsWith("DeepSeek", StringComparison.OrdinalIgnoreCase) || string.Equals(badgeSrc, "DSH", StringComparison.OrdinalIgnoreCase)) cursorBadge = "DSH";
|
|
488
|
+
else cursorBadge = badgeSrc.Length > 10 ? badgeSrc.Substring(0, 10) : badgeSrc;
|
|
489
|
+
if (visible && !petFinished)
|
|
490
|
+
{
|
|
491
|
+
if (clickTargetEnabled && !paused) ApplyCustomCursor(); else RestoreSystemCursor(false);
|
|
492
|
+
RenderPill();
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
490
495
|
if (visible) HideCore(); // the previous run's "done" card is still up
|
|
491
496
|
petMode = Args.Bool(r, "pet", false);
|
|
492
497
|
hoveredBtn = "";
|
|
@@ -585,6 +590,7 @@ namespace DshComputerUse
|
|
|
585
590
|
visible = true;
|
|
586
591
|
if (clickTargetEnabled)
|
|
587
592
|
{
|
|
593
|
+
ApplyCustomCursor();
|
|
588
594
|
Native.POINT cp;
|
|
589
595
|
if (Native.GetCursorPos(out cp)) ShowRestingMarkOnUi(cp.X, cp.Y);
|
|
590
596
|
}
|
|
@@ -592,6 +598,106 @@ namespace DshComputerUse
|
|
|
592
598
|
});
|
|
593
599
|
}
|
|
594
600
|
|
|
601
|
+
/**
|
|
602
|
+
* Replace Windows' hardware pointer (Normal / IBeam / Hand) with our crisp,
|
|
603
|
+
* DPI-scaled stylized DSH cursor while controlling. Hardware-composited at
|
|
604
|
+
* full refresh rate with zero double-arrow overlap, and always restored via
|
|
605
|
+
* SystemParametersInfo(SPI_SETCURSORS) on pause, hide, exit, or crash recovery.
|
|
606
|
+
*/
|
|
607
|
+
static void ApplyCustomCursor()
|
|
608
|
+
{
|
|
609
|
+
if (customCursorActive) return;
|
|
610
|
+
IntPtr hCursor = IntPtr.Zero;
|
|
611
|
+
try
|
|
612
|
+
{
|
|
613
|
+
float s = Math.Max(1f, Math.Min(3f, Scale()));
|
|
614
|
+
int size = Math.Max(32, Math.Min(96, (int)Math.Round(32f * s)));
|
|
615
|
+
int tipX = Math.Max(1, (int)Math.Round(2f * s));
|
|
616
|
+
int tipY = Math.Max(1, (int)Math.Round(2f * s));
|
|
617
|
+
using (var bmp = new Bitmap(size, size, PixelFormat.Format32bppArgb))
|
|
618
|
+
{
|
|
619
|
+
using (var g = Graphics.FromImage(bmp))
|
|
620
|
+
{
|
|
621
|
+
g.Clear(Color.Transparent);
|
|
622
|
+
g.SmoothingMode = SmoothingMode.AntiAlias;
|
|
623
|
+
var arrow = new PointF[]
|
|
624
|
+
{
|
|
625
|
+
new PointF(tipX, tipY),
|
|
626
|
+
new PointF(tipX, tipY + 19.2f * s),
|
|
627
|
+
new PointF(tipX + 5.0f * s, tipY + 14.8f * s),
|
|
628
|
+
new PointF(tipX + 8.6f * s, tipY + 22.4f * s),
|
|
629
|
+
new PointF(tipX + 11.8f * s, tipY + 20.9f * s),
|
|
630
|
+
new PointF(tipX + 8.2f * s, tipY + 13.5f * s),
|
|
631
|
+
new PointF(tipX + 14.5f * s, tipY + 13.1f * s),
|
|
632
|
+
};
|
|
633
|
+
var shadow = new PointF[arrow.Length];
|
|
634
|
+
for (int i = 0; i < arrow.Length; i++)
|
|
635
|
+
shadow[i] = new PointF(arrow[i].X + 1.0f * s, arrow[i].Y + 1.6f * s);
|
|
636
|
+
using (var sb = new SolidBrush(Color.FromArgb(88, 0, 0, 0)))
|
|
637
|
+
g.FillPolygon(sb, shadow);
|
|
638
|
+
using (var grad = new LinearGradientBrush(
|
|
639
|
+
new PointF(tipX, tipY),
|
|
640
|
+
new PointF(tipX + 15f * s, tipY + 23f * s),
|
|
641
|
+
AccentHi, Accent))
|
|
642
|
+
g.FillPolygon(grad, arrow);
|
|
643
|
+
using (var outline = new Pen(Color.FromArgb(250, 255, 255, 255), Math.Max(1.4f, 1.6f * s)))
|
|
644
|
+
{
|
|
645
|
+
outline.LineJoin = LineJoin.Round;
|
|
646
|
+
g.DrawPolygon(outline, arrow);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
IntPtr hIcon = bmp.GetHicon();
|
|
650
|
+
try
|
|
651
|
+
{
|
|
652
|
+
Native.ICONINFO ii;
|
|
653
|
+
if (Native.GetIconInfo(hIcon, out ii))
|
|
654
|
+
{
|
|
655
|
+
try
|
|
656
|
+
{
|
|
657
|
+
ii.fIcon = false;
|
|
658
|
+
ii.xHotspot = tipX;
|
|
659
|
+
ii.yHotspot = tipY;
|
|
660
|
+
hCursor = Native.CreateIconIndirect(ref ii);
|
|
661
|
+
}
|
|
662
|
+
finally
|
|
663
|
+
{
|
|
664
|
+
if (ii.hbmMask != IntPtr.Zero) Native.DeleteObject(ii.hbmMask);
|
|
665
|
+
if (ii.hbmColor != IntPtr.Zero) Native.DeleteObject(ii.hbmColor);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
finally
|
|
670
|
+
{
|
|
671
|
+
Native.DestroyIcon(hIcon);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
if (hCursor == IntPtr.Zero) return;
|
|
675
|
+
uint[] ids = new uint[] { Native.OCR_NORMAL, Native.OCR_IBEAM, Native.OCR_HAND };
|
|
676
|
+
bool anyApplied = false;
|
|
677
|
+
for (int i = 0; i < ids.Length; i++)
|
|
678
|
+
{
|
|
679
|
+
IntPtr dup = Native.CopyIcon(hCursor);
|
|
680
|
+
if (dup == IntPtr.Zero) continue;
|
|
681
|
+
if (Native.SetSystemCursor(dup, ids[i])) anyApplied = true;
|
|
682
|
+
else Native.DestroyIcon(dup);
|
|
683
|
+
}
|
|
684
|
+
if (anyApplied) customCursorActive = true;
|
|
685
|
+
}
|
|
686
|
+
catch (Exception) { }
|
|
687
|
+
finally
|
|
688
|
+
{
|
|
689
|
+
if (hCursor != IntPtr.Zero) Native.DestroyIcon(hCursor);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/** Reload the user's native Windows cursor scheme (idempotent & crash-safe). */
|
|
694
|
+
public static void RestoreSystemCursor(bool force)
|
|
695
|
+
{
|
|
696
|
+
if (!force && !customCursorActive) return;
|
|
697
|
+
try { Native.SystemParametersInfo(Native.SPI_SETCURSORS, 0, IntPtr.Zero, 0); } catch (Exception) { }
|
|
698
|
+
customCursorActive = false;
|
|
699
|
+
}
|
|
700
|
+
|
|
595
701
|
public static void Status(string newStatus)
|
|
596
702
|
{
|
|
597
703
|
if (thread == null || !visible) return;
|
|
@@ -620,6 +726,7 @@ namespace DshComputerUse
|
|
|
620
726
|
{
|
|
621
727
|
if (!visible || !petMode) { HideCore(); return; }
|
|
622
728
|
HideMark();
|
|
729
|
+
RestoreSystemCursor(false);
|
|
623
730
|
CloseInput(false);
|
|
624
731
|
foreach (var g in glows) g.Close();
|
|
625
732
|
glows.Clear();
|
|
@@ -635,7 +742,13 @@ namespace DshComputerUse
|
|
|
635
742
|
public static void SetPaused(bool value)
|
|
636
743
|
{
|
|
637
744
|
if (thread == null) return;
|
|
638
|
-
Ui(delegate
|
|
745
|
+
Ui(delegate
|
|
746
|
+
{
|
|
747
|
+
paused = value;
|
|
748
|
+
if (paused) { HideMark(); RestoreSystemCursor(false); }
|
|
749
|
+
else if (visible && clickTargetEnabled && !petFinished) { ApplyCustomCursor(); Native.POINT cp; if (Native.GetCursorPos(out cp)) ShowRestingMarkOnUi(cp.X, cp.Y); }
|
|
750
|
+
RenderPill();
|
|
751
|
+
});
|
|
639
752
|
}
|
|
640
753
|
|
|
641
754
|
public static void SetWaiting(bool value)
|
|
@@ -655,6 +768,7 @@ namespace DshComputerUse
|
|
|
655
768
|
{
|
|
656
769
|
{
|
|
657
770
|
HideMark();
|
|
771
|
+
RestoreSystemCursor(false);
|
|
658
772
|
CloseInput(false);
|
|
659
773
|
petFinished = false;
|
|
660
774
|
petWaiting = false;
|
|
@@ -676,8 +790,10 @@ namespace DshComputerUse
|
|
|
676
790
|
|
|
677
791
|
public static void Shutdown()
|
|
678
792
|
{
|
|
793
|
+
RestoreSystemCursor(false);
|
|
679
794
|
if (thread == null) return;
|
|
680
795
|
try { Hide(); Ui(delegate { Application.ExitThread(); }); } catch (Exception) { }
|
|
796
|
+
RestoreSystemCursor(false);
|
|
681
797
|
}
|
|
682
798
|
|
|
683
799
|
public static bool ShowClickTarget { get { return visible && clickTargetEnabled; } }
|
|
@@ -776,14 +892,20 @@ namespace DshComputerUse
|
|
|
776
892
|
}
|
|
777
893
|
}
|
|
778
894
|
|
|
779
|
-
// 2. Post-click delicate ripple ring
|
|
895
|
+
// 2. Post-click delicate ripple ring + crisp center dot so exact placement
|
|
896
|
+
// reads cleanly in screenshots without drawing a duplicate frozen arrow.
|
|
780
897
|
if (ripple)
|
|
781
898
|
{
|
|
782
899
|
float rr = 11.5f * s;
|
|
783
|
-
using (var ringHalo = new Pen(Color.FromArgb(
|
|
900
|
+
using (var ringHalo = new Pen(Color.FromArgb(145, 255, 255, 255), Math.Max(2.5f, 3.2f * s)))
|
|
784
901
|
g.DrawEllipse(ringHalo, cx - rr, cy - rr, rr * 2f, rr * 2f);
|
|
785
|
-
using (var ring = new Pen(Color.FromArgb(
|
|
902
|
+
using (var ring = new Pen(Color.FromArgb(235, color), Math.Max(1.6f, 2f * s)))
|
|
786
903
|
g.DrawEllipse(ring, cx - rr, cy - rr, rr * 2f, rr * 2f);
|
|
904
|
+
float dr = 3.2f * s;
|
|
905
|
+
using (var dotHalo = new SolidBrush(Color.FromArgb(245, 255, 255, 255)))
|
|
906
|
+
g.FillEllipse(dotHalo, cx - dr - 1.2f * s, cy - dr - 1.2f * s, (dr + 1.2f * s) * 2f, (dr + 1.2f * s) * 2f);
|
|
907
|
+
using (var dot = new SolidBrush(Color.FromArgb(255, color)))
|
|
908
|
+
g.FillEllipse(dot, cx - dr, cy - dr, dr * 2f, dr * 2f);
|
|
787
909
|
}
|
|
788
910
|
|
|
789
911
|
// 3. Attached collaborative name-tag pill.
|
|
@@ -865,7 +987,8 @@ namespace DshComputerUse
|
|
|
865
987
|
int estW = (int)((Math.Max(6, labelText.Length) * 11 + 36) * s);
|
|
866
988
|
bool flipX = !mon.IsEmpty && x + estW > mon.Right;
|
|
867
989
|
bool flipY = !mon.IsEmpty && y + (int)(52 * s) > mon.Bottom;
|
|
868
|
-
|
|
990
|
+
// The live hardware pointer itself is styled via SetSystemCursor (no duplicate frozen arrow).
|
|
991
|
+
bool drawArrow = false;
|
|
869
992
|
|
|
870
993
|
bool sameVisual = hasCachedMarkBitmap
|
|
871
994
|
&& Math.Abs(scale - cachedMarkScale) < 0.01f
|
|
@@ -906,7 +1029,7 @@ namespace DshComputerUse
|
|
|
906
1029
|
static void SyncRestingCursorOnUi()
|
|
907
1030
|
{
|
|
908
1031
|
Interlocked.Exchange(ref mouseMovePending, 0);
|
|
909
|
-
if (!visible || !clickTargetEnabled || petFinished || !markActive || !markIsResting) return;
|
|
1032
|
+
if (!visible || !clickTargetEnabled || petFinished || paused || !markActive || !markIsResting) return;
|
|
910
1033
|
PlaceMarkOnUi(latestMouseX, latestMouseY, cursorBadge, Accent, 0, false, false, true);
|
|
911
1034
|
}
|
|
912
1035
|
|
|
@@ -957,7 +1080,7 @@ namespace DshComputerUse
|
|
|
957
1080
|
else if (button == "right") { color = Color.FromArgb(16, 185, 129); verb = "已右键"; }
|
|
958
1081
|
else if (button == "middle") { color = Color.FromArgb(6, 182, 212); verb = "已中键"; }
|
|
959
1082
|
else { color = Color.FromArgb(59, 130, 246); verb = "已单击"; }
|
|
960
|
-
Mark(x, y, verb + " " + coordLabel, color,
|
|
1083
|
+
Mark(x, y, verb + " " + coordLabel, color, 900, true, true);
|
|
961
1084
|
}
|
|
962
1085
|
|
|
963
1086
|
static void HideMark()
|
|
@@ -990,10 +1113,15 @@ namespace DshComputerUse
|
|
|
990
1113
|
// pause / resume / stop, from Esc or the pill buttons.
|
|
991
1114
|
static void Press(string action)
|
|
992
1115
|
{
|
|
993
|
-
if (action == "stop") { paused = false; petWaiting = false; SkipWaitRequested = true; Program.EmitEvent("stop", "button"); }
|
|
1116
|
+
if (action == "stop") { paused = false; petWaiting = false; SkipWaitRequested = true; RestoreSystemCursor(false); Program.EmitEvent("stop", "button"); }
|
|
994
1117
|
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")
|
|
1118
|
+
else if (action == "pause") { paused = true; HideMark(); RestoreSystemCursor(false); Program.EmitEvent("pause", "user"); }
|
|
1119
|
+
else if (action == "resume")
|
|
1120
|
+
{
|
|
1121
|
+
paused = false; pausedByInput = false;
|
|
1122
|
+
if (visible && clickTargetEnabled && !petFinished) { ApplyCustomCursor(); Native.POINT cp; if (Native.GetCursorPos(out cp)) ShowRestingMarkOnUi(cp.X, cp.Y); }
|
|
1123
|
+
Program.EmitEvent("resume", "user");
|
|
1124
|
+
}
|
|
997
1125
|
else if (action == "expand") petExpanded = !petExpanded;
|
|
998
1126
|
else if (action == "input") { if (input == null) OpenInput(); else CloseInput(true); return; }
|
|
999
1127
|
else if (action == "send") { if (input != null) SubmitInput(input.Box.Text); return; }
|
|
@@ -1005,12 +1133,12 @@ namespace DshComputerUse
|
|
|
1005
1133
|
{
|
|
1006
1134
|
beforeInput = Native.GetForegroundWindow();
|
|
1007
1135
|
// 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"); }
|
|
1136
|
+
if (!paused) { paused = true; pausedByInput = true; HideMark(); RestoreSystemCursor(false); Program.EmitEvent("pause", "input"); }
|
|
1009
1137
|
bool dark = DarkTheme();
|
|
1010
1138
|
float px = 1.333f * Scale();
|
|
1011
1139
|
input = new InputBox(new Font("Microsoft YaHei UI", 10f * px, FontStyle.Regular, GraphicsUnit.Pixel),
|
|
1012
1140
|
dark ? Color.FromArgb(52, 51, 49) : Color.White, dark ? Color.FromArgb(244, 243, 241) : Color.FromArgb(31, 30, 29),
|
|
1013
|
-
"告诉
|
|
1141
|
+
"告诉 AI 接下来做什么(Enter 发送,Esc 取消)");
|
|
1014
1142
|
input.Submitted += SubmitInput;
|
|
1015
1143
|
input.Cancelled += delegate { CloseInput(true); };
|
|
1016
1144
|
inputBounds = Rectangle.Empty;
|
|
@@ -1041,7 +1169,12 @@ namespace DshComputerUse
|
|
|
1041
1169
|
InputHwnd = IntPtr.Zero;
|
|
1042
1170
|
inputBounds = Rectangle.Empty;
|
|
1043
1171
|
box.Close();
|
|
1044
|
-
if (pausedByInput)
|
|
1172
|
+
if (pausedByInput)
|
|
1173
|
+
{
|
|
1174
|
+
paused = false; pausedByInput = false;
|
|
1175
|
+
if (visible && clickTargetEnabled && !petFinished) { ApplyCustomCursor(); Native.POINT cp; if (Native.GetCursorPos(out cp)) ShowRestingMarkOnUi(cp.X, cp.Y); }
|
|
1176
|
+
Program.EmitEvent("resume", "input");
|
|
1177
|
+
}
|
|
1045
1178
|
var target = beforeInput;
|
|
1046
1179
|
beforeInput = IntPtr.Zero;
|
|
1047
1180
|
if (restoreFocus && target != IntPtr.Zero && Native.IsWindow(target))
|
|
@@ -1055,8 +1188,12 @@ namespace DshComputerUse
|
|
|
1055
1188
|
{
|
|
1056
1189
|
if (markActive && DateTime.UtcNow >= markExpiresAt)
|
|
1057
1190
|
{
|
|
1058
|
-
if (visible && clickTargetEnabled && !petFinished &&
|
|
1059
|
-
|
|
1191
|
+
if (visible && clickTargetEnabled && !petFinished && !paused)
|
|
1192
|
+
{
|
|
1193
|
+
Native.POINT cp;
|
|
1194
|
+
if (Native.GetCursorPos(out cp)) ShowRestingMarkOnUi(cp.X, cp.Y);
|
|
1195
|
+
else if (hasLastMark) ShowRestingMarkOnUi(lastMarkX, lastMarkY);
|
|
1196
|
+
}
|
|
1060
1197
|
else
|
|
1061
1198
|
HideMark();
|
|
1062
1199
|
}
|
|
@@ -1065,12 +1202,12 @@ namespace DshComputerUse
|
|
|
1065
1202
|
if (!markActive) timer.Stop();
|
|
1066
1203
|
return;
|
|
1067
1204
|
}
|
|
1068
|
-
if (visible && clickTargetEnabled && !petFinished && !markActive)
|
|
1205
|
+
if (visible && clickTargetEnabled && !petFinished && !paused && !markActive)
|
|
1069
1206
|
{
|
|
1070
1207
|
Native.POINT cp;
|
|
1071
1208
|
if (Native.GetCursorPos(out cp)) ShowRestingMarkOnUi(cp.X, cp.Y);
|
|
1072
1209
|
}
|
|
1073
|
-
else if (visible && clickTargetEnabled && !petFinished && markActive && markIsResting)
|
|
1210
|
+
else if (visible && clickTargetEnabled && !petFinished && !paused && markActive && markIsResting)
|
|
1074
1211
|
{
|
|
1075
1212
|
Native.POINT cp;
|
|
1076
1213
|
if (Native.GetCursorPos(out cp) && (Math.Abs(cp.X - lastMarkX) > 2 || Math.Abs(cp.Y - lastMarkY) > 2))
|
|
@@ -1262,7 +1399,7 @@ namespace DshComputerUse
|
|
|
1262
1399
|
bool isDetailed = petSize == "detailed";
|
|
1263
1400
|
string hoverTip = ButtonTip(hoveredBtn);
|
|
1264
1401
|
string title = hoverTip.Length > 0
|
|
1265
|
-
? (isCompact ? "" : "
|
|
1402
|
+
? (isCompact ? "" : "DSH")
|
|
1266
1403
|
: petFinished ? "已完成" : (isCompact && label.Length > 12 ? label.Substring(0, 11) + "…" : label);
|
|
1267
1404
|
string state = hoverTip.Length > 0 ? hoverTip
|
|
1268
1405
|
: petFinished ? "" : paused ? (input != null ? "输入指令中…" : "已暂停 · Esc 继续")
|
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;
|
package/lib/index.js
CHANGED
|
@@ -1785,7 +1785,7 @@ var Computer = class Computer {
|
|
|
1785
1785
|
heldButton = false;
|
|
1786
1786
|
/** Dimensions of the latest full-display screenshot shown to the model (keeps coordinate conversion exact across detail modes). */
|
|
1787
1787
|
lastShot;
|
|
1788
|
-
/** Recent click locations (
|
|
1788
|
+
/** Recent click locations (repeat counter + auto physical-click fallback if a UIA invoke had no effect). */
|
|
1789
1789
|
clickHistory = [];
|
|
1790
1790
|
/** The agent that last wrote the clipboard; when it goes idle the user's clipboard comes back. */
|
|
1791
1791
|
clipboardAgent;
|
|
@@ -2008,8 +2008,8 @@ var Computer = class Computer {
|
|
|
2008
2008
|
quality: budget.jpegQuality
|
|
2009
2009
|
}) ?? "unchanged";
|
|
2010
2010
|
}
|
|
2011
|
-
/** Record a
|
|
2012
|
-
noteClick(point, helperRepeat) {
|
|
2011
|
+
/** Record a click position and return how many times this spot (±24 px) was clicked in the last 2 minutes. */
|
|
2012
|
+
noteClick(point, helperRepeat, via = "physical") {
|
|
2013
2013
|
const now = Date.now();
|
|
2014
2014
|
while (this.clickHistory.length > 0 && now - this.clickHistory[0].at > REPEAT_WINDOW_MS) this.clickHistory.shift();
|
|
2015
2015
|
let local = 0;
|
|
@@ -2017,12 +2017,24 @@ var Computer = class Computer {
|
|
|
2017
2017
|
this.clickHistory.push({
|
|
2018
2018
|
x: point.x,
|
|
2019
2019
|
y: point.y,
|
|
2020
|
-
at: now
|
|
2020
|
+
at: now,
|
|
2021
|
+
via
|
|
2021
2022
|
});
|
|
2022
2023
|
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
2024
|
}
|
|
2024
2025
|
return typeof helperRepeat === "number" && Number.isFinite(helperRepeat) && helperRepeat > 0 ? helperRepeat : local;
|
|
2025
2026
|
}
|
|
2027
|
+
/** Whether this spot (±24 px) was already clicked via background UIA invoke recently (so a retry should use a real physical click). */
|
|
2028
|
+
hadRecentUiaClickAt(point, windowMs = 3e4) {
|
|
2029
|
+
if (!point) return false;
|
|
2030
|
+
const now = Date.now();
|
|
2031
|
+
for (let i = this.clickHistory.length - 1; i >= 0; i--) {
|
|
2032
|
+
const entry = this.clickHistory[i];
|
|
2033
|
+
if (now - entry.at > windowMs) break;
|
|
2034
|
+
if (Math.abs(entry.x - point.x) <= REPEAT_RADIUS_PX && Math.abs(entry.y - point.y) <= REPEAT_RADIUS_PX) return entry.via === "uia";
|
|
2035
|
+
}
|
|
2036
|
+
return false;
|
|
2037
|
+
}
|
|
2026
2038
|
async foreground() {
|
|
2027
2039
|
const win = await this.helper.call("foreground");
|
|
2028
2040
|
if (!win || typeof win.hwnd !== "number") return void 0;
|
|
@@ -2040,7 +2052,7 @@ var Computer = class Computer {
|
|
|
2040
2052
|
if (!fg || !(isHostWindow(fg) || isTransientShell(fg)) || !target || target.hwnd === fg.hwnd) return;
|
|
2041
2053
|
if ((await this.focus(target).catch(() => void 0))?.focused) await setTimeout$1(80);
|
|
2042
2054
|
}
|
|
2043
|
-
/** Wait at most `maxMs`, returning once the screen
|
|
2055
|
+
/** 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
2056
|
async waitForQuiet(maxMs, signal, wait) {
|
|
2045
2057
|
const started = Date.now();
|
|
2046
2058
|
const waitSignal = wait?.signal ?? signal;
|
|
@@ -2066,6 +2078,7 @@ var Computer = class Computer {
|
|
|
2066
2078
|
};
|
|
2067
2079
|
}
|
|
2068
2080
|
const display = await this.display();
|
|
2081
|
+
const waitForChange = maxMs >= 4e3;
|
|
2069
2082
|
const settlePromise = this.helper.call("settle", {
|
|
2070
2083
|
x: display.x,
|
|
2071
2084
|
y: display.y,
|
|
@@ -2073,7 +2086,12 @@ var Computer = class Computer {
|
|
|
2073
2086
|
height: display.height,
|
|
2074
2087
|
minMs: 300,
|
|
2075
2088
|
maxMs,
|
|
2076
|
-
quietMs: 800
|
|
2089
|
+
quietMs: waitForChange ? 1100 : 800,
|
|
2090
|
+
...waitForChange ? {
|
|
2091
|
+
waitForChange: true,
|
|
2092
|
+
checkpointMs: 5e3,
|
|
2093
|
+
noChangeMaxMs: Math.min(maxMs, 8e3)
|
|
2094
|
+
} : {}
|
|
2077
2095
|
}, maxMs + 1e4).catch(() => null);
|
|
2078
2096
|
const abortPromise = new Promise((resolve) => {
|
|
2079
2097
|
if (waitSignal.aborted) {
|
|
@@ -2101,9 +2119,13 @@ var Computer = class Computer {
|
|
|
2101
2119
|
}
|
|
2102
2120
|
const earlyEnd = checkAfter();
|
|
2103
2121
|
if (earlyEnd) return earlyEnd;
|
|
2122
|
+
const changed = raced !== "aborted" && raced !== null ? raced.changed : void 0;
|
|
2123
|
+
const checkpoint = raced !== "aborted" && raced !== null ? raced.checkpoint : void 0;
|
|
2104
2124
|
return {
|
|
2105
2125
|
ms: Date.now() - started,
|
|
2106
|
-
skipped: false
|
|
2126
|
+
skipped: false,
|
|
2127
|
+
...changed !== void 0 ? { changed } : {},
|
|
2128
|
+
...checkpoint !== void 0 ? { checkpoint } : {}
|
|
2107
2129
|
};
|
|
2108
2130
|
}
|
|
2109
2131
|
/** Wait until the screen stops changing (bounded), instead of a fixed delay. */
|
|
@@ -2702,6 +2724,10 @@ var Computer = class Computer {
|
|
|
2702
2724
|
const seconds = Math.min(30, Math.max(0, Number(input.duration ?? 1) || 0));
|
|
2703
2725
|
const res = await this.waitForQuiet(seconds * 1e3, call.signal, wait);
|
|
2704
2726
|
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.` };
|
|
2727
|
+
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).` };
|
|
2728
|
+
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).` };
|
|
2729
|
+
if (res.changed === true && res.ms < seconds * 1e3 - 200) return { text: `Waited ${(res.ms / 1e3).toFixed(1)}s (screen updated and settled).` };
|
|
2730
|
+
if (res.changed === false && seconds >= 4) return { text: `Waited ${seconds}s (no major visual change detected).` };
|
|
2705
2731
|
return { text: res.ms < seconds * 1e3 - 200 ? `Waited ${(res.ms / 1e3).toFixed(1)}s (the screen settled early).` : `Waited ${seconds}s.` };
|
|
2706
2732
|
} finally {
|
|
2707
2733
|
wait?.done();
|
|
@@ -2724,11 +2750,15 @@ var Computer = class Computer {
|
|
|
2724
2750
|
const button = action === "right_click" ? "right" : action === "middle_click" ? "middle" : "left";
|
|
2725
2751
|
const count = action === "double_click" ? 2 : action === "triple_click" ? 3 : 1;
|
|
2726
2752
|
const modifiers = parseModifiers(input.modifiers ?? input.text);
|
|
2727
|
-
|
|
2753
|
+
const retryAfterUia = action === "left_click" && modifiers.length === 0 && this.hadRecentUiaClickAt(p);
|
|
2754
|
+
if (action === "left_click" && named && modifiers.length === 0 && !retryAfterUia) {
|
|
2728
2755
|
const semantic = named.element.role === "Edit" || named.element.editable ? "focus" : "invoke";
|
|
2729
|
-
if (await this.semanticAction(call, named, semantic))
|
|
2756
|
+
if (await this.semanticAction(call, named, semantic)) {
|
|
2757
|
+
this.noteClick(p, void 0, "uia");
|
|
2758
|
+
return { text: `${semantic === "focus" ? "Focused" : "Invoked"}${label}.` };
|
|
2759
|
+
}
|
|
2730
2760
|
}
|
|
2731
|
-
if (action === "left_click" && !named && p && modifiers.length === 0 && s.elementFirstClick) {
|
|
2761
|
+
if (action === "left_click" && !named && p && modifiers.length === 0 && s.elementFirstClick && !retryAfterUia) {
|
|
2732
2762
|
let hit = null;
|
|
2733
2763
|
let uncertainReason;
|
|
2734
2764
|
try {
|
|
@@ -2742,7 +2772,7 @@ var Computer = class Computer {
|
|
|
2742
2772
|
}
|
|
2743
2773
|
if (hit?.ok === true) {
|
|
2744
2774
|
this.invalidateMarks();
|
|
2745
|
-
const repeat = this.noteClick(p);
|
|
2775
|
+
const repeat = this.noteClick(p, void 0, "uia");
|
|
2746
2776
|
const repeatHint = repeat >= 3 ? ` (same spot clicked ${repeat} times — screenshot before clicking again)` : "";
|
|
2747
2777
|
return { text: `Invoked ${hit.name ? `${hit.role || "control"} "${hit.name.slice(0, 40)}"` : hit.role || "control"}${label} in background (${hit.mechanism || "uia"}).${repeatHint}` };
|
|
2748
2778
|
}
|
|
@@ -2775,9 +2805,10 @@ var Computer = class Computer {
|
|
|
2775
2805
|
x: clickRes.x,
|
|
2776
2806
|
y: clickRes.y
|
|
2777
2807
|
} : void 0);
|
|
2778
|
-
const repeat = this.noteClick(clickedAt, clickRes?.repeat);
|
|
2808
|
+
const repeat = this.noteClick(clickedAt, clickRes?.repeat, "physical");
|
|
2779
2809
|
const repeatHint = repeat >= 3 ? ` (same spot clicked ${repeat} times — screenshot before clicking again)` : "";
|
|
2780
|
-
|
|
2810
|
+
const fallbackNote = retryAfterUia ? " (physical click after prior UIA invoke at same spot)" : "";
|
|
2811
|
+
return { text: `${action.replace("_", " ")}${label}${modifiers.length ? ` holding ${input.modifiers ?? input.text}` : ""}.${fallbackNote}${repeatHint}` };
|
|
2781
2812
|
}
|
|
2782
2813
|
case "left_click_drag": {
|
|
2783
2814
|
const from = await this.point(input.start_coordinate, "start_coordinate");
|
|
@@ -3265,7 +3296,7 @@ var HelperClient = class HelperClient {
|
|
|
3265
3296
|
timer,
|
|
3266
3297
|
child
|
|
3267
3298
|
});
|
|
3268
|
-
if (cmd === "window_card") this.cardChildren.add(child);
|
|
3299
|
+
if (cmd === "window_card" || cmd === "overlay_show") this.cardChildren.add(child);
|
|
3269
3300
|
child.stdin.write(`${JSON.stringify({
|
|
3270
3301
|
...args,
|
|
3271
3302
|
id,
|
package/lib/types/computer.d.ts
CHANGED
|
@@ -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 (
|
|
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
|
|
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
|
|
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>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copylee/dsh-computer-use",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
|
|
5
5
|
"icon": "assets/icon.svg",
|
|
6
6
|
"type": "module",
|