@copylee/dsh-computer-use 0.8.0 → 0.8.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/README.md +2 -1
- package/helper/CuHelper.cs +108 -5
- package/lib/index.js +3 -0
- package/lib/types/target.d.ts +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# dsh-computer-use
|
|
2
2
|
|
|
3
|
+
[](https://awesome-dsh-plugin.com)
|
|
3
4
|
[](https://www.npmjs.com/package/@copylee/dsh-computer-use)
|
|
4
5
|
|
|
5
6
|
让 DeepSeek Harness 直接操控你的 Windows 电脑:看屏幕、点鼠标、敲键盘,打开应用、切换窗口、读写剪贴板。控制期间屏幕四周会泛起**橙色光晕**,顶部出现“**DeepSeek Harness 正在操控你的电脑**”提示条,DeepSeek Harness 自己最小化,右下角换成一张**迷你进度卡片**,两行滚动显示 AI 的回复正文和思考 / 工具调用,让你同时看清操作过程和 AI 在想什么。按 **Esc** 暂停 / 继续,点“停止”结束本轮。
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
| 不弄乱剪贴板 | 插件写入剪贴板的内容不进 Windows 剪贴板历史(Win+V)和云剪贴板;粘贴后按原样恢复你的剪贴板(图片、文件也保留);AI 用 `clipboard` 工具写过剪贴板的,本轮结束后自动还原(期间你自己复制了新内容则不动) |
|
|
36
37
|
| 应用技能 | AI 对各个应用的操作笔记,每个应用一份 Markdown(`~/.dsh/computer-use-skills/`)。AI 摸索清楚一个不熟悉的应用后用 `app_skill` 自己记下来(只记操作规律,不记任务内容),以后 `open_application` 打开该应用时自动附带,不占系统提示。自带 Word、PowerPoint、Excel、Chrome、文件资源管理器、Obsidian、Typora、微信、QQ、记事本十份内置技能(含各应用的快捷键清单,PowerPoint 含原生公式和动画的做法);AI 在内置技能上追加的笔记单独保存,内置部分随插件更新;设置页“应用技能”里可以查看、修改、删除、新建,内置技能可覆盖和恢复 |
|
|
37
38
|
| 打开应用 | `open_application` 同时搜索开始菜单和桌面快捷方式(含公共桌面),便携软件也能按名字打开。已经关到系统托盘的应用(QQ、微信等)会像人一样点托盘图标把窗口叫回来(必要时先展开“显示隐藏的图标”),不会再启动第二个实例、也不会重复登录;你明确要多开时(如微信双开)AI 会用 `new_instance` 另开一个。任务结束时 AI 会收拾现场:关掉自己打开、你不再需要的窗口,`windows tidy` 把原本最小化或在托盘里的应用重新最小化 |
|
|
38
|
-
| 看不见图的模型 | `ui_elements` 用 Windows UI Automation
|
|
39
|
+
| 看不见图的模型 | `ui_elements` 用 Windows UI Automation 列出可点击元素和坐标,纯文本模型也能用。Chromium / Electron 会先唤醒无障碍树,同时保留浏览器标签栏、地址栏等控件;支持识别常见网页编辑器,并返回应用提供的 AutomationId、焦点能力和编辑器标记 |
|
|
39
40
|
| 零原生依赖 | 截图、窗口查询和输入直接调用 DeepSeek Harness 自带的 koffi,不需要额外安装;浮层、UI Automation、剪贴板等由一个小 helper 负责,首次使用时用 Windows 自带的 .NET Framework `csc.exe` 编译(约 1 秒,之后缓存)。不需要 node-gyp,也不受 Electron ABI 影响。开启了智能应用控制(Smart App Control)时,helper 改为在系统自带的 PowerShell 里运行 |
|
|
40
41
|
|
|
41
42
|
## 安装
|
package/helper/CuHelper.cs
CHANGED
|
@@ -77,6 +77,8 @@ namespace DshComputerUse
|
|
|
77
77
|
[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern int GetWindowText(IntPtr hwnd, StringBuilder sb, int max);
|
|
78
78
|
[DllImport("user32.dll")] public static extern int GetWindowTextLength(IntPtr hwnd);
|
|
79
79
|
[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern int GetClassName(IntPtr hwnd, StringBuilder sb, int max);
|
|
80
|
+
[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr after, string cls, string title);
|
|
81
|
+
[DllImport("user32.dll")] public static extern IntPtr SendMessageTimeout(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam, uint flags, uint timeout, out IntPtr result);
|
|
80
82
|
[DllImport("user32.dll")] public static extern IntPtr GetWindow(IntPtr hwnd, uint cmd);
|
|
81
83
|
[DllImport("user32.dll")] public static extern int GetWindowLong(IntPtr hwnd, int index);
|
|
82
84
|
[DllImport("user32.dll")] public static extern int SetWindowLong(IntPtr hwnd, int index, int value);
|
|
@@ -1693,7 +1695,98 @@ namespace DshComputerUse
|
|
|
1693
1695
|
ControlType.Button, ControlType.Edit, ControlType.Hyperlink, ControlType.MenuItem, ControlType.ListItem,
|
|
1694
1696
|
ControlType.TabItem, ControlType.CheckBox, ControlType.RadioButton, ControlType.ComboBox, ControlType.TreeItem,
|
|
1695
1697
|
ControlType.DataItem, ControlType.SplitButton, ControlType.Slider, ControlType.Spinner, ControlType.Document,
|
|
1696
|
-
ControlType.MenuBar, ControlType.Menu, ControlType.ScrollBar };
|
|
1698
|
+
ControlType.MenuBar, ControlType.Menu, ControlType.ScrollBar, ControlType.Group };
|
|
1699
|
+
|
|
1700
|
+
// Wake the renderer, but keep collecting the window too: browser tabs,
|
|
1701
|
+
// toolbars and the address bar are outside the renderer's subtree.
|
|
1702
|
+
static IntPtr ChromiumRoot(IntPtr hwnd)
|
|
1703
|
+
{
|
|
1704
|
+
try
|
|
1705
|
+
{
|
|
1706
|
+
var cls = new StringBuilder(256);
|
|
1707
|
+
Native.GetClassName(hwnd, cls, cls.Capacity);
|
|
1708
|
+
if (!cls.ToString().StartsWith("Chrome_WidgetWin", StringComparison.Ordinal)) return hwnd;
|
|
1709
|
+
IntPtr render = IntPtr.Zero;
|
|
1710
|
+
while ((render = Native.FindWindowEx(hwnd, render, "Chrome_RenderWidgetHostHWND", null)) != IntPtr.Zero)
|
|
1711
|
+
if (Native.IsWindowVisible(render)) return render;
|
|
1712
|
+
return hwnd;
|
|
1713
|
+
}
|
|
1714
|
+
catch { return hwnd; }
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
static bool IsEditorClass(string cls)
|
|
1718
|
+
{
|
|
1719
|
+
if (string.IsNullOrEmpty(cls)) return false;
|
|
1720
|
+
string[] marks = { "ProseMirror", "tiptap", "CodeMirror", "monaco-editor", "ql-editor" };
|
|
1721
|
+
foreach (var mark in marks)
|
|
1722
|
+
if (cls.IndexOf(mark, StringComparison.OrdinalIgnoreCase) >= 0) return true;
|
|
1723
|
+
return false;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
// Chromium builds its accessibility tree lazily. A standard AT request
|
|
1727
|
+
// (WM_GETOBJECT/OBJID_CLIENT) wakes it; without this, apps such as
|
|
1728
|
+
// VS Code expose only a few nodes even though the render host exists.
|
|
1729
|
+
static void WakeAccessibility(IntPtr hwnd)
|
|
1730
|
+
{
|
|
1731
|
+
try
|
|
1732
|
+
{
|
|
1733
|
+
IntPtr result;
|
|
1734
|
+
Native.SendMessageTimeout(hwnd, 0x003D /* WM_GETOBJECT */, IntPtr.Zero,
|
|
1735
|
+
new IntPtr(-4) /* OBJID_CLIENT */, 0x0002 /* SMTO_ABORTIFHUNG */, 1000, out result);
|
|
1736
|
+
}
|
|
1737
|
+
catch { }
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
// A broken provider may never return. Bound background queries rather
|
|
1741
|
+
// than creating an unbounded number of stuck threads on repeated reads.
|
|
1742
|
+
static readonly SemaphoreSlim WindowCollectors = new SemaphoreSlim(4, 4);
|
|
1743
|
+
|
|
1744
|
+
static List<object> CollectWindow(IntPtr hwnd, int max, bool includeText)
|
|
1745
|
+
{
|
|
1746
|
+
IntPtr render = ChromiumRoot(hwnd);
|
|
1747
|
+
if (render == hwnd) return Collect(hwnd, max, includeText);
|
|
1748
|
+
WakeAccessibility(render);
|
|
1749
|
+
List<object> window = null;
|
|
1750
|
+
Exception windowError = null;
|
|
1751
|
+
Thread windowWorker = null;
|
|
1752
|
+
if (WindowCollectors.Wait(0))
|
|
1753
|
+
{
|
|
1754
|
+
windowWorker = new Thread(delegate ()
|
|
1755
|
+
{
|
|
1756
|
+
try { window = Collect(hwnd, max, includeText); }
|
|
1757
|
+
catch (Exception ex) { windowError = ex; }
|
|
1758
|
+
finally { WindowCollectors.Release(); }
|
|
1759
|
+
});
|
|
1760
|
+
windowWorker.IsBackground = true;
|
|
1761
|
+
windowWorker.SetApartmentState(ApartmentState.MTA);
|
|
1762
|
+
windowWorker.Start();
|
|
1763
|
+
}
|
|
1764
|
+
// Electron can take >16s at the top level while its renderer takes
|
|
1765
|
+
// <1s. Read independently; a slow/failed window must not lose DOM controls.
|
|
1766
|
+
List<object> content = null;
|
|
1767
|
+
Exception contentError = null;
|
|
1768
|
+
try { content = Collect(render, max, includeText); }
|
|
1769
|
+
catch (Exception ex) { contentError = ex; }
|
|
1770
|
+
bool windowReady = windowWorker != null && windowWorker.Join(1000);
|
|
1771
|
+
var result = windowReady && window != null ? window : new List<object>();
|
|
1772
|
+
if (content == null && result.Count == 0 && contentError != null)
|
|
1773
|
+
throw windowReady && windowError != null ? windowError : contentError;
|
|
1774
|
+
if (content != null && result.Count < max)
|
|
1775
|
+
{
|
|
1776
|
+
foreach (Dictionary<string, object> extra in content)
|
|
1777
|
+
{
|
|
1778
|
+
bool duplicate = false;
|
|
1779
|
+
foreach (Dictionary<string, object> item in result)
|
|
1780
|
+
if (Equals(item["role"], extra["role"]) && Equals(item["name"], extra["name"])
|
|
1781
|
+
&& Equals(item["x"], extra["x"]) && Equals(item["y"], extra["y"])
|
|
1782
|
+
&& Equals(item["width"], extra["width"]) && Equals(item["height"], extra["height"]))
|
|
1783
|
+
{ duplicate = true; break; }
|
|
1784
|
+
if (!duplicate) result.Add(extra);
|
|
1785
|
+
if (result.Count >= max) break;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
return result;
|
|
1789
|
+
}
|
|
1697
1790
|
|
|
1698
1791
|
public static object Elements(Dictionary<string, object> r)
|
|
1699
1792
|
{
|
|
@@ -1710,14 +1803,14 @@ namespace DshComputerUse
|
|
|
1710
1803
|
if (popupsOnly) result = new List<object>();
|
|
1711
1804
|
else
|
|
1712
1805
|
{
|
|
1713
|
-
result =
|
|
1714
|
-
if (result.Count < 4) { Thread.Sleep(400); result =
|
|
1806
|
+
result = CollectWindow(hwnd, max, all);
|
|
1807
|
+
if (result.Count < 4) { Thread.Sleep(400); result = CollectWindow(hwnd, max, all); } // Chromium builds its tree lazily
|
|
1715
1808
|
}
|
|
1716
1809
|
// An open menu or flyout is a window of its own, not a descendant of the one it belongs to.
|
|
1717
1810
|
if (popups || popupsOnly) foreach (var extra in Popups(hwnd))
|
|
1718
1811
|
{
|
|
1719
1812
|
if (result.Count >= max) break;
|
|
1720
|
-
try { result.AddRange(
|
|
1813
|
+
try { result.AddRange(CollectWindow(extra, max - result.Count, all)); } catch (Exception) { }
|
|
1721
1814
|
}
|
|
1722
1815
|
}
|
|
1723
1816
|
catch (Exception ex) { error = ex; }
|
|
@@ -1856,6 +1949,8 @@ namespace DshComputerUse
|
|
|
1856
1949
|
cache.Add(AutomationElement.BoundingRectangleProperty);
|
|
1857
1950
|
cache.Add(AutomationElement.IsEnabledProperty);
|
|
1858
1951
|
cache.Add(AutomationElement.AutomationIdProperty);
|
|
1952
|
+
cache.Add(AutomationElement.ClassNameProperty);
|
|
1953
|
+
cache.Add(AutomationElement.IsKeyboardFocusableProperty);
|
|
1859
1954
|
cache.Add(ValuePattern.ValueProperty);
|
|
1860
1955
|
cache.Add(TogglePattern.ToggleStateProperty);
|
|
1861
1956
|
cache.AutomationElementMode = AutomationElementMode.None;
|
|
@@ -1870,9 +1965,17 @@ namespace DshComputerUse
|
|
|
1870
1965
|
if (rect.IsEmpty || rect.Width < 2 || rect.Height < 2) continue;
|
|
1871
1966
|
var type = (ControlType)el.GetCachedPropertyValue(AutomationElement.ControlTypeProperty);
|
|
1872
1967
|
string name = (el.GetCachedPropertyValue(AutomationElement.NameProperty) as string) ?? "";
|
|
1968
|
+
string cls = (el.GetCachedPropertyValue(AutomationElement.ClassNameProperty) as string) ?? "";
|
|
1969
|
+
// Web 编辑器的 contenteditable 常是 Group(ProseMirror/tiptap 等),
|
|
1970
|
+
// 不是 Edit;保留这类 Group,其余 Group 跳过,避免淹没按钮。
|
|
1971
|
+
if (type == ControlType.Group && !IsEditorClass(cls)) continue;
|
|
1873
1972
|
var d = new Dictionary<string, object>();
|
|
1874
|
-
d["role"] = type.ProgrammaticName.Replace("ControlType.", "");
|
|
1973
|
+
d["role"] = type == ControlType.Group ? "Edit" : type.ProgrammaticName.Replace("ControlType.", "");
|
|
1974
|
+
if (type == ControlType.Group) d["editable"] = true;
|
|
1875
1975
|
d["name"] = name.Length > 120 ? name.Substring(0, 120) + "…" : name;
|
|
1976
|
+
string aid = (el.GetCachedPropertyValue(AutomationElement.AutomationIdProperty) as string) ?? "";
|
|
1977
|
+
if (aid.Length > 0) d["automationId"] = aid.Length > 120 ? aid.Substring(0, 120) + "…" : aid;
|
|
1978
|
+
d["focusable"] = (bool)el.GetCachedPropertyValue(AutomationElement.IsKeyboardFocusableProperty);
|
|
1876
1979
|
object value = el.GetCachedPropertyValue(ValuePattern.ValueProperty, true);
|
|
1877
1980
|
if (value is string && ((string)value).Length > 0) { var v = (string)value; d["value"] = v.Length > 120 ? v.Substring(0, 120) + "…" : v; }
|
|
1878
1981
|
object toggle = el.GetCachedPropertyValue(TogglePattern.ToggleStateProperty, true);
|
package/lib/index.js
CHANGED
|
@@ -8996,6 +8996,9 @@ function createTools(host) {
|
|
|
8996
8996
|
el.value !== void 0 ? `value="${el.value}"` : "",
|
|
8997
8997
|
el.checked !== void 0 ? el.checked ? "checked" : "unchecked" : "",
|
|
8998
8998
|
el.disabled ? "disabled" : "",
|
|
8999
|
+
el.automationId ? `automationId=${JSON.stringify(el.automationId)}` : "",
|
|
9000
|
+
el.focusable !== void 0 ? `focusable=${el.focusable}` : "",
|
|
9001
|
+
el.editable ? "editable" : "",
|
|
8999
9002
|
center.offscreen ? "other display" : ""
|
|
9000
9003
|
].filter(Boolean).join(" ");
|
|
9001
9004
|
lines.push(`[${index}] ${el.role} "${el.name}" @ (${center.x}, ${center.y})${flags ? ` ${flags}` : ""}`);
|
package/lib/types/target.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ export interface UiElement {
|
|
|
11
11
|
value?: string;
|
|
12
12
|
checked?: boolean;
|
|
13
13
|
disabled?: boolean;
|
|
14
|
+
/** UIA AutomationId when the app exposes one; more stable than Name. */
|
|
15
|
+
automationId?: string;
|
|
16
|
+
/** Whether the element can take keyboard focus. */
|
|
17
|
+
focusable?: boolean;
|
|
18
|
+
/** True for web contenteditable composers (ProseMirror/tiptap/CodeMirror...). */
|
|
19
|
+
editable?: boolean;
|
|
14
20
|
x: number;
|
|
15
21
|
y: number;
|
|
16
22
|
width: number;
|
package/package.json
CHANGED