@copylee/dsh-computer-use 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/helper/CuHelper.cs +57 -51
- package/lib/index.js +13 -19
- package/lib/types/computer.d.ts +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
| 按应用授权 | 先 `request_access` 列出要操控的应用,经 DSH 原生审批后才能操作;也可改为“全部允许” |
|
|
13
13
|
| 不会操作自己 | 永远拒绝向 DeepSeek Harness 自身窗口输入;常见密码管理器默认禁止,可再自定义禁用列表 |
|
|
14
14
|
| 正在控制的提示 | 橙色光晕 + 胶囊提示条(显示当前动作),**不会出现在截图里** |
|
|
15
|
-
| 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 / 最小化状态(也可选最小化或不动)。卡片只给你看:AI
|
|
15
|
+
| 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 / 最小化状态(也可选最小化或不动)。卡片只给你看:AI 的截图里看到的是卡片下面的内容(每次截图时卡片会透明约 20 毫秒,每个动作只截一次),点击和滚动也直接穿透卡片,卡片不会挪位置 |
|
|
16
16
|
| 暂停与停止 | 你亲手按 **Esc** 暂停(AI 停在下一步之前),再按 Esc 或点“继续”恢复,对话不会被中断;点“停止”才结束本轮。插件自己发出的 Esc 不会误触发 |
|
|
17
17
|
| 你随时可以插手 | 你用键盘打字时 AI 自动暂停,停手 1.5 秒后继续(单按 Shift / Ctrl 等修饰键不算);你切换或打开了别的窗口,AI 下一步不会盲目执行,而是先看新截图再决定。你只是点进 DSH 卡片看对话时不算切换,AI 的按键会自动回到它正在操作的窗口。鼠标移动不会触发,避免误触 |
|
|
18
18
|
| 中文输入 | Unicode 直接输入,不受输入法状态影响;长文本走剪贴板粘贴,剪贴板文本统一为 CRLF,粘贴到 Obsidian 等应用不丢换行 |
|
package/helper/CuHelper.cs
CHANGED
|
@@ -136,6 +136,11 @@ namespace DshComputerUse
|
|
|
136
136
|
object v; if (!d.TryGetValue(k, out v) || v == null) return def;
|
|
137
137
|
return (int)Math.Round(Convert.ToDouble(v));
|
|
138
138
|
}
|
|
139
|
+
public static double Double(Dictionary<string, object> d, string k, double def)
|
|
140
|
+
{
|
|
141
|
+
object v;
|
|
142
|
+
return d.TryGetValue(k, out v) && v != null ? Convert.ToDouble(v, System.Globalization.CultureInfo.InvariantCulture) : def;
|
|
143
|
+
}
|
|
139
144
|
public static string Str(Dictionary<string, object> d, string k, string def)
|
|
140
145
|
{
|
|
141
146
|
object v; if (!d.TryGetValue(k, out v) || v == null) return def;
|
|
@@ -253,8 +258,6 @@ namespace DshComputerUse
|
|
|
253
258
|
case "displays": return Screen2.Displays();
|
|
254
259
|
case "screenshot": return Screen2.Capture(r);
|
|
255
260
|
case "settle": return Screen2.Settle(r);
|
|
256
|
-
case "shot_mark": Screen2.Mark(r); return null;
|
|
257
|
-
case "shot_diff": return Screen2.Diff(r);
|
|
258
261
|
case "cursor": { Native.POINT p; Native.GetCursorPos(out p); return Pt(p.X, p.Y); }
|
|
259
262
|
case "move": using (new PassThrough()) { Overlay.Dodge(Args.Int(r, "x", 0), Args.Int(r, "y", 0)); Input.Move(Args.Int(r, "x", 0), Args.Int(r, "y", 0)); } return null;
|
|
260
263
|
case "click": using (new PassThrough()) return Input.Click(r);
|
|
@@ -318,12 +321,8 @@ namespace DshComputerUse
|
|
|
318
321
|
}
|
|
319
322
|
|
|
320
323
|
/** Sample every 8th pixel of a screen rectangle (BGR bytes). */
|
|
321
|
-
/**
|
|
322
|
-
|
|
323
|
-
* per action). Otherwise the card area is blanked so its own updates
|
|
324
|
-
* (streaming text, timers) never look like screen activity.
|
|
325
|
-
*/
|
|
326
|
-
static byte[] Sample(int x, int y, int w, int h, bool composite)
|
|
324
|
+
/** Sample the screen for settle detection; the card area is blanked (no flicker). */
|
|
325
|
+
static byte[] Sample(int x, int y, int w, int h)
|
|
327
326
|
{
|
|
328
327
|
using (var bmp = new Bitmap(w, h, PixelFormat.Format24bppRgb))
|
|
329
328
|
{
|
|
@@ -331,53 +330,41 @@ namespace DshComputerUse
|
|
|
331
330
|
{
|
|
332
331
|
IntPtr dst = g.GetHdc();
|
|
333
332
|
IntPtr src = Native.GetDC(IntPtr.Zero);
|
|
334
|
-
|
|
335
|
-
{
|
|
336
|
-
|
|
337
|
-
finally { Native.ReleaseDC(IntPtr.Zero, src); g.ReleaseHdc(dst); }
|
|
338
|
-
}
|
|
339
|
-
if (!composite) CardLayer.Blank(g, x, y);
|
|
333
|
+
try { Native.BitBlt(dst, 0, 0, w, h, src, x, y, 0x00CC0020 | 0x40000000); }
|
|
334
|
+
finally { Native.ReleaseDC(IntPtr.Zero, src); g.ReleaseHdc(dst); }
|
|
335
|
+
CardLayer.Blank(g, x, y);
|
|
340
336
|
}
|
|
341
|
-
|
|
342
|
-
|
|
337
|
+
return SampleBitmap(bmp);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** Every 8th pixel of a 24-bit bitmap (BGR bytes). */
|
|
342
|
+
static byte[] SampleBitmap(Bitmap bmp)
|
|
343
|
+
{
|
|
344
|
+
int w = bmp.Width, h = bmp.Height;
|
|
345
|
+
var data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
|
|
346
|
+
try
|
|
347
|
+
{
|
|
348
|
+
int sx = (w + 7) / 8, sy = (h + 7) / 8;
|
|
349
|
+
var row = new byte[data.Stride];
|
|
350
|
+
var outp = new byte[sx * sy * 3];
|
|
351
|
+
int k = 0;
|
|
352
|
+
for (int j = 0; j < sy; j++)
|
|
343
353
|
{
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
var outp = new byte[sx * sy * 3];
|
|
347
|
-
int k = 0;
|
|
348
|
-
for (int j = 0; j < sy; j++)
|
|
349
|
-
{
|
|
350
|
-
Marshal.Copy(new IntPtr(data.Scan0.ToInt64() + (long)j * 8 * data.Stride), row, 0, data.Stride);
|
|
351
|
-
for (int i = 0; i < sx; i++) { int o = i * 8 * 3; outp[k++] = row[o]; outp[k++] = row[o + 1]; outp[k++] = row[o + 2]; }
|
|
352
|
-
}
|
|
353
|
-
return outp;
|
|
354
|
+
Marshal.Copy(new IntPtr(data.Scan0.ToInt64() + (long)j * 8 * data.Stride), row, 0, data.Stride);
|
|
355
|
+
for (int i = 0; i < sx; i++) { int o = i * 8 * 3; outp[k++] = row[o]; outp[k++] = row[o + 1]; outp[k++] = row[o + 2]; }
|
|
354
356
|
}
|
|
355
|
-
|
|
357
|
+
return outp;
|
|
356
358
|
}
|
|
359
|
+
finally { bmp.UnlockBits(data); }
|
|
357
360
|
}
|
|
358
361
|
|
|
362
|
+
/** What the screen looked like in the last screenshot the model was shown. */
|
|
359
363
|
static byte[] marked;
|
|
360
364
|
static string markedRect;
|
|
361
365
|
|
|
362
366
|
static string RectKey(int x, int y, int w, int h) { return x + "," + y + "," + w + "," + h; }
|
|
363
367
|
|
|
364
|
-
/** Remember what the screen looked like when the model was last shown it. */
|
|
365
|
-
public static void Mark(Dictionary<string, object> r)
|
|
366
|
-
{
|
|
367
|
-
int x = Args.Int(r, "x", 0), y = Args.Int(r, "y", 0), w = Args.Int(r, "width", 0), h = Args.Int(r, "height", 0);
|
|
368
|
-
marked = Sample(x, y, w, h, true);
|
|
369
|
-
markedRect = RectKey(x, y, w, h);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/** Fraction of sampled pixels changed since Mark (-1 when there is nothing comparable). */
|
|
373
|
-
public static Dictionary<string, object> Diff(Dictionary<string, object> r)
|
|
374
|
-
{
|
|
375
|
-
int x = Args.Int(r, "x", 0), y = Args.Int(r, "y", 0), w = Args.Int(r, "width", 0), h = Args.Int(r, "height", 0);
|
|
376
|
-
var d = new Dictionary<string, object>();
|
|
377
|
-
d["diff"] = marked == null || markedRect != RectKey(x, y, w, h) ? -1.0 : Changed(marked, Sample(x, y, w, h, true));
|
|
378
|
-
return d;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
368
|
static double Changed(byte[] a, byte[] b)
|
|
382
369
|
{
|
|
383
370
|
int n = a.Length / 3, diff = 0;
|
|
@@ -397,13 +384,13 @@ namespace DshComputerUse
|
|
|
397
384
|
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);
|
|
398
385
|
if (w <= 0 || h <= 0) throw new Exception("invalid settle rect");
|
|
399
386
|
var watch = System.Diagnostics.Stopwatch.StartNew();
|
|
400
|
-
byte[] prev = Sample(x, y, w, h
|
|
387
|
+
byte[] prev = Sample(x, y, w, h);
|
|
401
388
|
long quietSince = -1;
|
|
402
389
|
bool stable = false;
|
|
403
390
|
while (true)
|
|
404
391
|
{
|
|
405
392
|
Thread.Sleep(interval);
|
|
406
|
-
byte[] cur = Sample(x, y, w, h
|
|
393
|
+
byte[] cur = Sample(x, y, w, h);
|
|
407
394
|
long now = watch.ElapsedMilliseconds;
|
|
408
395
|
if (Changed(prev, cur) < 0.002) { if (quietSince < 0) quietSince = now - interval; }
|
|
409
396
|
else quietSince = -1;
|
|
@@ -431,13 +418,29 @@ namespace DshComputerUse
|
|
|
431
418
|
{
|
|
432
419
|
IntPtr dst = g.GetHdc();
|
|
433
420
|
IntPtr src = Native.GetDC(IntPtr.Zero);
|
|
434
|
-
// The DSH card is for the user only: capture what is under it
|
|
435
|
-
|
|
421
|
+
// The DSH card is for the user only: capture what is under it
|
|
422
|
+
// (it blinks out for the duration of this one BitBlt).
|
|
423
|
+
using (CardLayer.Hide(new Rectangle(x, y, w, h)))
|
|
436
424
|
{
|
|
437
425
|
try { Native.BitBlt(dst, 0, 0, w, h, src, x, y, 0x00CC0020 | 0x40000000); }
|
|
438
426
|
finally { Native.ReleaseDC(IntPtr.Zero, src); g.ReleaseHdc(dst); }
|
|
439
427
|
}
|
|
440
428
|
}
|
|
429
|
+
// compare: report "unchanged" instead of an identical image; mark: remember for next time.
|
|
430
|
+
bool compare = Args.Bool(r, "compare", false), mark = Args.Bool(r, "mark", false) || compare;
|
|
431
|
+
if (mark)
|
|
432
|
+
{
|
|
433
|
+
string key = RectKey(x, y, w, h);
|
|
434
|
+
byte[] sample = SampleBitmap(bmp);
|
|
435
|
+
if (compare && marked != null && markedRect == key && Changed(marked, sample) < Args.Double(r, "threshold", 0.0005))
|
|
436
|
+
{
|
|
437
|
+
var same = new Dictionary<string, object>();
|
|
438
|
+
same["unchanged"] = true;
|
|
439
|
+
return same;
|
|
440
|
+
}
|
|
441
|
+
marked = sample;
|
|
442
|
+
markedRect = key;
|
|
443
|
+
}
|
|
441
444
|
Bitmap output = bmp;
|
|
442
445
|
Bitmap scaled = null;
|
|
443
446
|
try
|
|
@@ -842,10 +845,13 @@ namespace DshComputerUse
|
|
|
842
845
|
g.FillRectangle(Brushes.Black, r.X - ox, r.Y - oy, r.Width, r.Height);
|
|
843
846
|
}
|
|
844
847
|
|
|
845
|
-
/** Make the card invisible while a capture runs (dispose to show it again). */
|
|
846
|
-
public static IDisposable Hide()
|
|
848
|
+
/** Make the card invisible while a capture of `area` runs (dispose to show it again). */
|
|
849
|
+
public static IDisposable Hide(Rectangle area)
|
|
847
850
|
{
|
|
848
|
-
|
|
851
|
+
if (!Live()) return new Hidden(IntPtr.Zero);
|
|
852
|
+
var r = Frame(Hwnd);
|
|
853
|
+
r.Inflate(32, 32);
|
|
854
|
+
return new Hidden(r.IntersectsWith(area) ? Hwnd : IntPtr.Zero);
|
|
849
855
|
}
|
|
850
856
|
|
|
851
857
|
sealed class Hidden : IDisposable
|
package/lib/index.js
CHANGED
|
@@ -559,32 +559,24 @@ var Computer = class Computer {
|
|
|
559
559
|
await this.refreshDisplays();
|
|
560
560
|
const display = await this.display();
|
|
561
561
|
const size = this.shotSize(display);
|
|
562
|
-
const shot = await this.capture(display, size);
|
|
563
|
-
await this.helper.call("shot_mark", this.rect(display)).catch(() => {});
|
|
562
|
+
const shot = await this.capture(display, size, { mark: true });
|
|
564
563
|
await this.remember();
|
|
565
564
|
return shot;
|
|
566
565
|
}
|
|
567
|
-
rect(display) {
|
|
568
|
-
return {
|
|
569
|
-
x: display.x,
|
|
570
|
-
y: display.y,
|
|
571
|
-
width: display.width,
|
|
572
|
-
height: display.height
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
566
|
/**
|
|
576
567
|
* A fresh screenshot, or 'unchanged' when the screen looks the same as in
|
|
577
568
|
* the last one the model saw (saves an image and tells it the action had no
|
|
578
569
|
* visible effect).
|
|
579
570
|
*/
|
|
580
571
|
async freshShot() {
|
|
572
|
+
await this.refreshDisplays();
|
|
581
573
|
const display = await this.display();
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
return
|
|
574
|
+
const shot = await this.capture(display, this.shotSize(display), {
|
|
575
|
+
compare: true,
|
|
576
|
+
threshold: UNCHANGED_DIFF
|
|
577
|
+
});
|
|
578
|
+
await this.remember();
|
|
579
|
+
return shot ?? "unchanged";
|
|
588
580
|
}
|
|
589
581
|
/** The foreground window as of the model's latest look at the screen. */
|
|
590
582
|
seen;
|
|
@@ -607,7 +599,7 @@ var Computer = class Computer {
|
|
|
607
599
|
const now = await this.foreground().catch(() => void 0);
|
|
608
600
|
return now && now.hwnd !== seen.hwnd ? now : void 0;
|
|
609
601
|
}
|
|
610
|
-
async capture(rect, out) {
|
|
602
|
+
async capture(rect, out, options = {}) {
|
|
611
603
|
const result = await this.helper.call("screenshot", {
|
|
612
604
|
x: rect.x,
|
|
613
605
|
y: rect.y,
|
|
@@ -615,8 +607,10 @@ var Computer = class Computer {
|
|
|
615
607
|
height: rect.height,
|
|
616
608
|
outWidth: out.width,
|
|
617
609
|
outHeight: out.height,
|
|
618
|
-
quality: this.settings().jpegQuality
|
|
610
|
+
quality: this.settings().jpegQuality,
|
|
611
|
+
...options
|
|
619
612
|
}, 3e4);
|
|
613
|
+
if (result.unchanged || result.data === void 0) return void 0;
|
|
620
614
|
return {
|
|
621
615
|
data: Buffer.from(result.data, "base64"),
|
|
622
616
|
width: result.width,
|
|
@@ -632,7 +626,7 @@ var Computer = class Computer {
|
|
|
632
626
|
maxLongEdge: s.maxLongEdge,
|
|
633
627
|
maxPixels: s.maxPixels
|
|
634
628
|
});
|
|
635
|
-
return this.capture(rect, out);
|
|
629
|
+
return await this.capture(rect, out);
|
|
636
630
|
}
|
|
637
631
|
async foreground() {
|
|
638
632
|
const win = await this.helper.call("foreground");
|
package/lib/types/computer.d.ts
CHANGED
|
@@ -89,7 +89,6 @@ export declare class Computer {
|
|
|
89
89
|
offscreen: boolean;
|
|
90
90
|
}>;
|
|
91
91
|
screenshot(): Promise<Shot>;
|
|
92
|
-
private rect;
|
|
93
92
|
/**
|
|
94
93
|
* A fresh screenshot, or 'unchanged' when the screen looks the same as in
|
|
95
94
|
* the last one the model saw (saves an image and tells it the action had no
|
package/package.json
CHANGED