dsh-computer-use-windows:用 Win32 原語讓 Harness 控制 Windows 桌面

前言

在 DeepSeek Harness(DSH)裏做工作流時,模型往往需要「看見屏幕、點鼠標、敲鍵盤、切窗口」——而不是隻在終端裏跑命令。常見做法會依賴 UI Automation、SendKeys 或各應用的腳本接口,穩定性和覆蓋範圍因場景而異。下面介紹社區插件 dsh-computer-use-windows(維護者 pdong15dth):通過 12 個 computer_* 工具,把操作落到 Win32 調用上,由本機編譯或緩存的原生 helper 進程執行,README 明確說明不使用 UI Automation、也不使用 SendKeys。

這是什麼

dsh-computer-use-windows 是 DSH 的 Host 插件包(package.json 版本 1.0.0,許可證 MIT),分類爲工作流。它給模型提供對當前 Windows 桌面的真實控制能力:鼠標、鍵盤、截圖、窗口枚舉與操控、剪貼板、啓動應用/打開路徑或 URL。動作層與 README 中的機制對應關係如下。

能力 Win32 機制
鼠標 SendInput(絕對座標、按鍵、滾輪)
鍵盤 SendInput(Unicode、ctrl+shift+t 等組合鍵)
屏幕 GDI+ CopyFromScreen,按物理像素分辨率
窗口 EnumWindows、SetForegroundWindow、ShowWindow、PostMessage(WM_CLOSE) 等
剪貼板 真實 Win32 剪貼板(STA 工作線程)
啓動 Process.Start + UseShellExecute(與 Win+R / 開始菜單同類路徑)

插件以當前 DSH 進程所屬用戶權限運行 helper,不會自行提權;安裝前應在 GitHub 閱讀源碼與 LICENSE,再決定是否啓用。

核心功能:12 個工具

README 列出的工具及用途如下(名稱保持原文)。

工具 作用
computer_info 虛擬屏幕、顯示器、光標、DPI 感知狀態、是否提升權限
computer_screenshot 整桌、單顯示器或指定區域截圖
computer_mouse_move 絕對座標移動指針
computer_click 左/右/中鍵,單擊或雙擊,可先移動
computer_drag 按下、插值移動、釋放
computer_scroll 在指針處垂直/水平滾輪
computer_type Unicode 輸入(\n 爲 Enter,\t 爲 Tab)
computer_key 快捷鍵與命名鍵,如 ctrl+shift+t 或 ["ctrl+a", "delete"]
computer_clipboard 讀、寫或清空剪貼板
computer_windows 列出頂層窗口(句柄、標題、pid、矩形、狀態)
computer_window_control 聚焦、最小化、最大化、還原或關閉窗口
computer_launch 啓動應用、打開路徑/文檔或 URL

截圖結果會附帶座標映射(originX、originY、scale):圖像像素 (ix, iy) 對應屏幕點 (originX + ix*scale, originY + iy*scale)。所有工具座標均使用 computer_info 返回的虛擬屏幕空間中的物理像素。

原生 helper 如何就緒

首次調用工具時,Host 插件會用 Windows 自帶的 .NET Framework 編譯器編譯 helper/ComputerHelper.cs,輸出緩存到:

%LOCALAPPDATA%\dsh-computer-use\dsh-computer-helper.exe

編譯命令在 README 中寫爲使用 %WINDIR%\Microsoft.NET\Framework64\v4.0.30319\csc.exe;源碼變更時按 SHA-256 戳記重建。若 csc.exe 不可用,會回退到 helper/serve.ps1(Add-Type + 相同 JSON 行協議),啓動較慢。可通過環境變量覆蓋:

變量 效果
DSH_COMPUTER_USE_HELPER 使用指定已編譯 helper .exe
DSH_COMPUTER_USE_CSC 使用指定的 csc.exe 編譯

helper 爲 /target:winexe,Host 以 windowsHide: true 啓動,避免控制台閃窗。

安裝與啓用

插件是純 Host 包:無構建步驟、無 npm 依賴;ESM 與原生 helper 在首次使用時編譯。

從本地目錄安裝

在 Harness 會話中執行(路徑改爲你 clone 或解壓後的絕對路徑;資料要求通過 bundle 安裝,勿自行拼接未在文檔出現的 CLI 命令):

plugin_manager { action: "install_bundle", target: "<absolute path to this directory>" }

安裝會把該目錄鏈入 profile,並插入 cordis.patch.yml 中的 computer-use-windows 行。

從插件市場索引發現

倉庫發佈 format-1 市場索引,可在 Harness Plugins → Discover 中發現並安裝。索引 URL:

https://raw.githubusercontent.com/pdong15dth/dsh-computer-use-windows/main/market/index.json

將其加入 @deepseek-ai/dsh-plugin-market 的 indexes 列表(例如在 profile 的 cordis.patch.yml 中),Discover 頁會列出 dsh-computer-use-windows。代理側 plugin_market 的 list_indexes / list_plugins / list_versions 給出的安裝目標爲 commit 固定形式,例如:

git+https://github.com/pdong15dth/dsh-computer-use-windows.git#<40-hex-commit>

社區目錄頁:https://www.skillhub.cn/plugins/pdong15dth/dsh-computer-use-windows(獨立站點,與 DeepSeek / 幻方無官方從屬關係)。

典型用法思路

README 的 Verification 節記錄了在 Windows 11 build 26100、雙 1920×1080、per-monitor-v2 上的實測流程,可作爲復現順序參考:

  1. 安裝 bundle 後確認 plugin_manager 報告 application: applied。
  2. 調用 computer_info 確認顯示器與 DPI 狀態。
  3. 用 computer_screenshot 獲取帶 origin/scale 的圖像塊。
  4. 用 computer_windows 與 computer_window_control 聚焦、最小化、還原或關閉目標窗口。
  5. 用 computer_launch 啓動 Notepad 等應用。
  6. 在確認前臺窗口正確(computer_windows 中目標窗口帶 [focused])後,使用 computer_type / computer_key 輸入;README 強調焦點是全局狀態,人機共用桌面時兩次調用之間焦點可能變化。
  7. 讀寫剪貼板用 computer_clipboard;ctrl+c 成功會覆蓋用戶剪貼板。

座標類操作(computer_click、computer_drag、computer_scroll)在 helper 層有測試覆蓋;插件層驗證時若桌面仍被人使用,可能爲避免誤點而跳過,使用前宜保證桌面相對空閒。

適用場景與注意

適合:需要在 DSH 工作流裏做真實桌面自動化——例如打開應用、填表、截圖取證、窗口管理——且接受 Win32 輸入注入語義的場景。

務必知曉的限制(來自 README Safety / Known limits):

  • 輸入注入到當前焦點窗口;模型可點擊、輸入、關閉窗口,啓用前應審查會話權限並保存無關工作。
  • 非提升權限的 helper 無法向提升權限窗口注入輸入;無法觸及 UAC 安全桌面。
  • 部分全屏遊戲與反作弊窗口可能忽略合成輸入。
  • DRM 保護內容截圖可能爲黑屏。
  • 成功 ctrl+c 會覆蓋用戶剪貼板。

DSH 生態理念是「一切皆插件」;本插件 GitHub 星標數爲 1(以目錄線索爲準),適合自行審閱 helper/ComputerHelper.cs 與 PROTOCOL.md 後再用於生產環境。

結尾

dsh-computer-use-windows 把桌面控制收斂到 12 個 computer_* 工具與 Win32 helper,避免 UI Automation 與 SendKeys 路徑,並給出截圖座標映射與市場索引安裝方式。進一步瞭解實現與驗證細節見倉庫 README 與 helper 報告。

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜