@copylee/dsh-computer-use 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  | 功能 | 说明 |
8
8
  |---|---|
9
9
  | 截图即坐标系 | 模型只用最近一张截图的像素坐标,DPI、缩放、多显示器偏移全部由插件换算,高分屏(200% 缩放)也点得准 |
10
- | 动作后自动回传截图 | 点击 / 输入 / 按键 / 滚动后,**等画面不再变化**(页面加载、动画结束,最多约 2.5 秒)再截图;`wait` 也直接带回截图,“等一下再看”只需一步 |
10
+ | 动作后自动回传截图 | 点击 / 输入 / 按键 / 滚动后,**等画面不再变化**(页面加载、动画结束,最多约 2.5 秒)再截图;`wait` 也直接带回截图,“等一下再看”只需一步;画面与上一张截图完全相同时不再发图,只告诉模型“没有可见变化”,省 token |
11
11
  | 批量动作 | `computer_batch` 一次执行“点输入框 → 输入 → 回车”等多步,最后只截一张图 |
12
12
  | 按应用授权 | 先 `request_access` 列出要操控的应用,经 DSH 原生审批后才能操作;也可改为“全部允许” |
13
13
  | 不会操作自己 | 永远拒绝向 DeepSeek Harness 自身窗口输入;常见密码管理器默认禁止,可再自定义禁用列表 |
@@ -15,7 +15,8 @@
15
15
  | 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 / 最小化状态(也可选最小化或不动)。AI 要点击 / 滚动 / 查看卡片下面的内容时,卡片自动躲到另一侧角落 |
16
16
  | 暂停与停止 | 你亲手按 **Esc** 暂停(AI 停在下一步之前),再按 Esc 或点“继续”恢复,对话不会被中断;点“停止”才结束本轮。插件自己发出的 Esc 不会误触发 |
17
17
  | 你随时可以插手 | 你用键盘打字时 AI 自动暂停,停手 1.5 秒后继续(单按 Shift / Ctrl 等修饰键不算);你切换或打开了别的窗口,AI 下一步不会盲目执行,而是先看新截图再决定。你只是点进 DSH 卡片看对话时不算切换,AI 的按键会自动回到它正在操作的窗口。鼠标移动不会触发,避免误触 |
18
- | 中文输入 | Unicode 直接输入,不受输入法状态影响;长文本走剪贴板并自动恢复原剪贴板;剪贴板文本统一为 CRLF,粘贴到 Obsidian 等应用不丢换行 |
18
+ | 中文输入 | Unicode 直接输入,不受输入法状态影响;长文本走剪贴板粘贴,剪贴板文本统一为 CRLF,粘贴到 Obsidian 等应用不丢换行 |
19
+ | 不弄乱剪贴板 | 插件写入剪贴板的内容不进 Windows 剪贴板历史(Win+V)和云剪贴板;粘贴后按原样恢复你的剪贴板(图片、文件也保留);AI 用 `clipboard` 工具写过剪贴板的,本轮结束后自动还原(期间你自己复制了新内容则不动) |
19
20
  | 打开应用 | `open_application` 同时搜索开始菜单和桌面快捷方式(含公共桌面),便携软件也能按名字打开 |
20
21
  | 看不见图的模型 | `ui_elements` 用 Windows UI Automation 列出可点击元素和坐标,纯文本模型也能用 |
21
22
  | 零原生依赖 | 首次使用时用 Windows 自带的 .NET Framework `csc.exe` 编译一个小 helper(约 1 秒,之后缓存),不需要 node-gyp、不受 Electron ABI 影响 |
@@ -251,6 +251,8 @@ namespace DshComputerUse
251
251
  case "displays": return Screen2.Displays();
252
252
  case "screenshot": return Screen2.Capture(r);
253
253
  case "settle": return Screen2.Settle(r);
254
+ case "shot_mark": Screen2.Mark(r); return null;
255
+ case "shot_diff": return Screen2.Diff(r);
254
256
  case "cursor": { Native.POINT p; Native.GetCursorPos(out p); return Pt(p.X, p.Y); }
255
257
  case "move": 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;
256
258
  case "click": return Input.Click(r);
@@ -269,7 +271,8 @@ namespace DshComputerUse
269
271
  case "apps": return Apps.Search(Args.Str(r, "query", ""), Args.Int(r, "limit", 8));
270
272
  case "launch": return Apps.Launch(r);
271
273
  case "clipboard_get": { var d = new Dictionary<string, object>(); d["text"] = Clip.Get(); return d; }
272
- case "clipboard_set": Clip.Set(Args.Str(r, "text", "")); return null;
274
+ case "clipboard_set": if (Args.Bool(r, "agent", false)) Clip.AgentSet(Args.Str(r, "text", "")); else Clip.Set(Args.Str(r, "text", ""), false); return null;
275
+ case "clipboard_restore": { var d = new Dictionary<string, object>(); d["restored"] = Clip.RestoreAgent(); return d; }
273
276
  case "ui": return Uia.Elements(r);
274
277
  case "overlay_show": Overlay.ExcludeFromCapture = Args.Bool(r, "excludeFromCapture", true); Overlay.Show(r); return null;
275
278
  case "overlay_pause": Overlay.SetPaused(Args.Bool(r, "paused", false)); return null;
@@ -342,6 +345,28 @@ namespace DshComputerUse
342
345
  }
343
346
  }
344
347
 
348
+ static byte[] marked;
349
+ static string markedRect;
350
+
351
+ static string RectKey(int x, int y, int w, int h) { return x + "," + y + "," + w + "," + h; }
352
+
353
+ /** Remember what the screen looked like when the model was last shown it. */
354
+ public static void Mark(Dictionary<string, object> r)
355
+ {
356
+ 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);
357
+ marked = Sample(x, y, w, h);
358
+ markedRect = RectKey(x, y, w, h);
359
+ }
360
+
361
+ /** Fraction of sampled pixels changed since Mark (-1 when there is nothing comparable). */
362
+ public static Dictionary<string, object> Diff(Dictionary<string, object> r)
363
+ {
364
+ 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);
365
+ var d = new Dictionary<string, object>();
366
+ d["diff"] = marked == null || markedRect != RectKey(x, y, w, h) ? -1.0 : Changed(marked, Sample(x, y, w, h));
367
+ return d;
368
+ }
369
+
345
370
  static double Changed(byte[] a, byte[] b)
346
371
  {
347
372
  int n = a.Length / 3, diff = 0;
@@ -616,15 +641,16 @@ namespace DshComputerUse
616
641
 
617
642
  public static object Paste(string text, bool restore)
618
643
  {
619
- string previous = null;
620
- if (restore) { try { previous = Clip.Get(); } catch (Exception) { } }
621
- Clip.Set(text);
644
+ // Keep every format the user had (images, files, rich text), not just text.
645
+ DataObject previous = null;
646
+ if (restore) { try { previous = Clip.Snapshot(); } catch (Exception) { } }
647
+ Clip.Set(text, true);
622
648
  Thread.Sleep(40);
623
649
  Send(new List<Native.INPUT> { Key(0x11, false), Key(0x56, false) });
624
650
  Thread.Sleep(30);
625
651
  Send(new List<Native.INPUT> { Key(0x56, true), Key(0x11, true) });
626
652
  Thread.Sleep(250);
627
- if (restore && previous != null) { try { Clip.Set(previous); } catch (Exception) { } }
653
+ if (restore) { try { Clip.Put(previous); } catch (Exception) { } }
628
654
  return null;
629
655
  }
630
656
  }
@@ -641,20 +667,107 @@ namespace DshComputerUse
641
667
  throw new Exception("clipboard is busy");
642
668
  }
643
669
 
644
- public static void Set(string text)
670
+ /** The user's clipboard before the agent first wrote to it, restored when control ends. */
671
+ static DataObject saved;
672
+ static bool hasSaved;
673
+ /** What the agent last put there, to tell whether the user copied something since. */
674
+ static string agentText;
675
+
676
+ static string Normalize(string text)
677
+ {
678
+ return string.IsNullOrEmpty(text) ? "" : text.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n");
679
+ }
680
+
681
+ /** Mark data as transient: clipboard history (Win+V), cloud clipboard and clipboard managers skip it. */
682
+ static void MarkPrivate(DataObject d)
683
+ {
684
+ d.SetData("ExcludeClipboardContentFromMonitorProcessing", false, new MemoryStream(new byte[] { 1, 0, 0, 0 }));
685
+ d.SetData("CanIncludeInClipboardHistory", false, new MemoryStream(BitConverter.GetBytes(0)));
686
+ d.SetData("CanUploadToCloudClipboard", false, new MemoryStream(BitConverter.GetBytes(0)));
687
+ }
688
+
689
+ /** Copy every format currently on the clipboard (null when empty). */
690
+ public static DataObject Snapshot()
691
+ {
692
+ for (int i = 0; i < 5; i++)
693
+ {
694
+ try
695
+ {
696
+ var src = Clipboard.GetDataObject();
697
+ if (src == null) return null;
698
+ var formats = src.GetFormats(false);
699
+ if (formats.Length == 0) return null;
700
+ var dst = new DataObject();
701
+ foreach (var f in formats)
702
+ {
703
+ if (f == "CanIncludeInClipboardHistory" || f == "CanUploadToCloudClipboard" || f == "ExcludeClipboardContentFromMonitorProcessing") continue;
704
+ try { var v = src.GetData(f, false); if (v != null) dst.SetData(f, false, v); } catch (Exception) { }
705
+ }
706
+ return dst;
707
+ }
708
+ catch (ExternalException) { Thread.Sleep(50); }
709
+ }
710
+ throw new Exception("clipboard is busy");
711
+ }
712
+
713
+ /** Put a snapshot back without adding a history entry (null clears). */
714
+ public static void Put(DataObject data)
715
+ {
716
+ for (int i = 0; i < 5; i++)
717
+ {
718
+ try
719
+ {
720
+ if (data == null) Clipboard.Clear();
721
+ else { MarkPrivate(data); Clipboard.SetDataObject(data, true); }
722
+ return;
723
+ }
724
+ catch (ExternalException) { Thread.Sleep(50); }
725
+ }
726
+ throw new Exception("clipboard is busy");
727
+ }
728
+
729
+ public static void Set(string text, bool isPrivate)
645
730
  {
646
- if (!string.IsNullOrEmpty(text)) text = text.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n");
731
+ text = Normalize(text);
647
732
  for (int i = 0; i < 5; i++)
648
733
  {
649
734
  try
650
735
  {
651
- if (string.IsNullOrEmpty(text)) Clipboard.Clear(); else Clipboard.SetText(text);
736
+ if (text.Length == 0) Clipboard.Clear();
737
+ else
738
+ {
739
+ var d = new DataObject();
740
+ d.SetData(DataFormats.UnicodeText, false, text);
741
+ if (isPrivate) MarkPrivate(d);
742
+ Clipboard.SetDataObject(d, true);
743
+ }
652
744
  return;
653
745
  }
654
746
  catch (ExternalException) { Thread.Sleep(50); }
655
747
  }
656
748
  throw new Exception("clipboard is busy");
657
749
  }
750
+
751
+ /** The agent writes the clipboard: remember the user's content first (once per control session). */
752
+ public static void AgentSet(string text)
753
+ {
754
+ if (!hasSaved) { saved = Snapshot(); hasSaved = true; }
755
+ Set(text, true);
756
+ agentText = Normalize(text);
757
+ }
758
+
759
+ /** Control ended: put the user's clipboard back, unless they copied something since the agent's last write. */
760
+ public static bool RestoreAgent()
761
+ {
762
+ if (!hasSaved) return false;
763
+ bool ours = false;
764
+ try { ours = Get() == agentText; } catch (Exception) { }
765
+ var data = saved;
766
+ saved = null; hasSaved = false; agentText = null;
767
+ if (!ours) return false;
768
+ Put(data);
769
+ return true;
770
+ }
658
771
  }
659
772
 
660
773
  internal static class Windows
package/lib/index.js CHANGED
@@ -484,6 +484,10 @@ const KEYBOARD = /* @__PURE__ */ new Set([
484
484
  "key",
485
485
  "hold_key"
486
486
  ]);
487
+ /** Below this fraction of changed sample pixels, the screen counts as unchanged. */
488
+ const UNCHANGED_DIFF = 5e-4;
489
+ /** Text returned instead of an identical screenshot. */
490
+ const UNCHANGED_TEXT = "The screen looks exactly as in your previous screenshot: the action had no visible effect.";
487
491
  var Computer = class Computer {
488
492
  helper;
489
493
  access;
@@ -492,6 +496,8 @@ var Computer = class Computer {
492
496
  displays = [];
493
497
  displayIndex = -1;
494
498
  heldButton = false;
499
+ /** The agent that last wrote the clipboard; when it goes idle the user's clipboard comes back. */
500
+ clipboardAgent;
495
501
  constructor(helper, access, overlay, settings) {
496
502
  this.helper = helper;
497
503
  this.access = access;
@@ -547,9 +553,32 @@ var Computer = class Computer {
547
553
  const display = await this.display();
548
554
  const size = this.shotSize(display);
549
555
  const shot = await this.capture(display, size);
556
+ await this.helper.call("shot_mark", this.rect(display)).catch(() => {});
550
557
  await this.remember();
551
558
  return shot;
552
559
  }
560
+ rect(display) {
561
+ return {
562
+ x: display.x,
563
+ y: display.y,
564
+ width: display.width,
565
+ height: display.height
566
+ };
567
+ }
568
+ /**
569
+ * A fresh screenshot, or 'unchanged' when the screen looks the same as in
570
+ * the last one the model saw (saves an image and tells it the action had no
571
+ * visible effect).
572
+ */
573
+ async freshShot() {
574
+ const display = await this.display();
575
+ const result = await this.helper.call("shot_diff", this.rect(display)).catch(() => null);
576
+ if (result && result.diff >= 0 && result.diff < UNCHANGED_DIFF) {
577
+ await this.remember();
578
+ return "unchanged";
579
+ }
580
+ return this.screenshot();
581
+ }
553
582
  /** The foreground window as of the model's latest look at the screen. */
554
583
  seen;
555
584
  /** The latest foreground window that was not DeepSeek Harness itself. */
@@ -846,7 +875,7 @@ var Computer = class Computer {
846
875
  const mutating = inputs.some((input) => MUTATING.has(input.action));
847
876
  if (!mutating && !inputs.some((input) => input.action === "wait")) return void 0;
848
877
  if (mutating) await this.settle(call.signal);
849
- return this.screenshot();
878
+ return this.freshShot();
850
879
  }
851
880
  /** Bring a window forward and verify it is the foreground window. */
852
881
  async focus(win) {
@@ -1311,6 +1340,8 @@ ${mode === "per-app" ? "- Before acting on an app, call request_access once with
1311
1340
  - The "DeepSeek Harness.exe" window is your own chat interface; while you control the computer it floats as a card in a bottom corner. Never type into it. If the card hides something you need, point at that spot (mouse_move, or just click/scroll there): the card jumps to the other corner. Keys go to the window you were working in even if the user clicked the card.
1312
1341
  - Prefer reliable keyboard shortcuts (ctrl+l for a browser address bar, ctrl+s, alt+F4, ctrl+t). Click the center of targets; zoom in when text is small.
1313
1342
  - Actions return a fresh screenshot taken once the screen stops changing (page loads included, up to a few seconds), so you rarely need wait. If something is still loading, use wait: it also returns a screenshot, so never follow it with a separate screenshot call.
1343
+ - Enter text with type, even long or multi-line text (over 200 characters it is pasted and the user's clipboard is restored). Do not put text on the clipboard with shell commands (Set-Clipboard, clip): that clutters the user's clipboard history.
1344
+ - Office apps: F12 opens the classic Save As dialog, where you can type a full path in the file name box.
1314
1345
  - Be efficient: every tool call costs the user several seconds. Put predictable sequences (click a field, type, press Return; open a menu and pick an item you can already see) into one computer_batch. Avoid shell commands for things you can see on screen.
1315
1346
  - To see more of a page or list, scroll (action "scroll" with coordinate over the area, scroll_direction, scroll_amount 5-10) instead of hunting with zoom; for long web pages Page Down / End keys also work.
1316
1347
  - If a dedicated tool fits the whole task better (an API, or browser automation attached to the user's own browser), choose it at the start; do not switch tools halfway through a task that is going fine on screen.
@@ -7099,6 +7130,8 @@ function toJson(ref) {
7099
7130
  }
7100
7131
  async function withShot(host, text, shot, call) {
7101
7132
  if (shot === void 0) return { text };
7133
+ if (shot === "unchanged") return { text: `${text}
7134
+ ${UNCHANGED_TEXT}` };
7102
7135
  if (!call.vision) return { text: `${text}\n(The current model cannot view images; use ui_elements to read the screen.)` };
7103
7136
  const ref = await host.saveImage(shot, "screenshot.jpg");
7104
7137
  return {
@@ -7242,7 +7275,7 @@ function createTools(host) {
7242
7275
  }
7243
7276
  }
7244
7277
  const done = lines.join("\n");
7245
- const shot = call.vision && computer.settings().autoScreenshot ? await computer.settle(call.signal).then(() => computer.screenshot()) : void 0;
7278
+ const shot = call.vision && computer.settings().autoScreenshot ? await computer.settle(call.signal).then(() => computer.freshShot()) : void 0;
7246
7279
  const summary = failure === void 0 ? `All ${actions.length} actions done.\n${done}` : `Stopped: ${failure}${done ? `\nCompleted before it:\n${done}` : ""}\nRemaining actions were skipped.`;
7247
7280
  return withShot(host, shot === void 0 ? `${summary}\n${await computer.describeForeground()}` : summary, shot, call);
7248
7281
  },
@@ -7398,7 +7431,7 @@ function createTools(host) {
7398
7431
  }));
7399
7432
  tools.push(defineTool({
7400
7433
  name: "clipboard",
7401
- description: "Read or write the clipboard text.",
7434
+ description: "Read or write the clipboard text. Writes stay out of Windows clipboard history, and the user clipboard is restored when you finish. To enter long text, prefer computer type (it pastes for you); never set the clipboard from a shell.",
7402
7435
  parameters: {
7403
7436
  action: {
7404
7437
  type: "string",
@@ -7411,10 +7444,14 @@ function createTools(host) {
7411
7444
  }
7412
7445
  },
7413
7446
  output,
7414
- async execute(args) {
7447
+ async execute(args, exec) {
7415
7448
  const { action, text } = args;
7416
7449
  if (action === "write") {
7417
- await computer.helper.call("clipboard_set", { text: text ?? "" });
7450
+ computer.clipboardAgent = (await host.context(exec)).agent;
7451
+ await computer.helper.call("clipboard_set", {
7452
+ text: text ?? "",
7453
+ agent: true
7454
+ });
7418
7455
  return { text: `Clipboard set (${(text ?? "").length} characters).` };
7419
7456
  }
7420
7457
  const result = await computer.helper.call("clipboard_get");
@@ -7630,6 +7667,10 @@ function apply(ctx, config = {}) {
7630
7667
  });
7631
7668
  ctx.on("agent/status", ({ agent, status }) => {
7632
7669
  if (status === "running") computer.resetLook();
7670
+ if (status === "idle" && computer.clipboardAgent === agent) {
7671
+ computer.clipboardAgent = void 0;
7672
+ helper.call("clipboard_restore").catch(() => {});
7673
+ }
7633
7674
  if (status === "idle" && overlay.controller === agent) overlay.end(agent);
7634
7675
  });
7635
7676
  ctx.on("agent/disposed", ({ agent }) => {
@@ -64,6 +64,8 @@ export interface ActionOutcome {
64
64
  /** The action was not performed because the user took over the keyboard. */
65
65
  skipped?: boolean;
66
66
  }
67
+ /** Text returned instead of an identical screenshot. */
68
+ export declare const UNCHANGED_TEXT = "The screen looks exactly as in your previous screenshot: the action had no visible effect.";
67
69
  /** Longest adaptive wait for the screen to settle after an action. */
68
70
  export declare const MAX_SETTLE_MS = 2500;
69
71
  export declare class Computer {
@@ -74,6 +76,8 @@ export declare class Computer {
74
76
  private displays;
75
77
  private displayIndex;
76
78
  private heldButton;
79
+ /** The agent that last wrote the clipboard; when it goes idle the user's clipboard comes back. */
80
+ clipboardAgent: CancellableAgent | undefined;
77
81
  constructor(helper: HelperLike, access: AccessControl, overlay: OverlayController, settings: () => Settings);
78
82
  refreshDisplays(): Promise<Display[]>;
79
83
  display(): Promise<Display>;
@@ -85,6 +89,13 @@ export declare class Computer {
85
89
  offscreen: boolean;
86
90
  }>;
87
91
  screenshot(): Promise<Shot>;
92
+ private rect;
93
+ /**
94
+ * A fresh screenshot, or 'unchanged' when the screen looks the same as in
95
+ * the last one the model saw (saves an image and tells it the action had no
96
+ * visible effect).
97
+ */
98
+ freshShot(): Promise<Shot | 'unchanged'>;
88
99
  /** The foreground window as of the model's latest look at the screen. */
89
100
  private seen;
90
101
  /** The latest foreground window that was not DeepSeek Harness itself. */
@@ -127,7 +138,7 @@ export declare class Computer {
127
138
  * (vision models only). A wait already waited, so it is captured at once:
128
139
  * "wait, then look" should be one step, not two.
129
140
  */
130
- after(inputs: readonly ActionInput[], call: CallContext): Promise<Shot | undefined>;
141
+ after(inputs: readonly ActionInput[], call: CallContext): Promise<Shot | 'unchanged' | undefined>;
131
142
  /** Bring a window forward and verify it is the foreground window. */
132
143
  focus(win: WindowInfo): Promise<WindowInfo & {
133
144
  focused: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "type": "module",
6
6
  "author": "copylee",