前言¶
DSH 的擴展方式是「一切皆插件」。當模型需要操作真實界面時,Android 和 Web 往往要分別處理目標、定位和運行環境。ciky20171114/dsh-plugin-midscene 爲 DeepSeek Harness(DSH)提供基於 Midscene 的 AI-driven UI automation:模型看到屏幕,按自然語言描述定位元素,並作用於真實 Android 設備或真實 Chrome 頁面。
它通過一個 ctx.midscene 能力接縫提供 android_ui 和 web_ui 兩個工具。
這是什麼¶
dsh-plugin-midscene 是一個 DSH 插件,由 ciky20171114 維護,許可證爲 MIT。
它的能力結構可以概括爲:
- 單一接縫:
ctx.midscene - 兩個 provider:Android 和 Web
- 兩個工具:
android_ui和web_ui
核心功能¶
- Android provider 面向一個 ADB-connected device。
- Web provider 面向已運行 Chrome 的 active page;provider 只連接,不啓動 Chrome。
android_ui和web_ui使用單一action參數,支持tap、act、input、query、assert、boolean、back。- 視覺模型通過環境變量配置爲 Midscene 兼容模型;資料說明這不是通過 DSH 的
ctx.llm配置。
安裝與啓用¶
先準備環境:
- DSH CLI 和一個 profile。
- Android 場景:
adb devices能看到設備。 - Web 場景:Chrome 以
--remote-debugging-port=9222 --user-data-dir=<dir>啓動;插件只連接,不啓動 Chrome。
安裝:
dsh plugin --profile mysetup add dsh-plugin-midscene
安裝後,在 profile 的 cordis.patch.yml 中添加 exactly one provider row。示例路徑:
~/.dsh/profiles/mysetup/cordis.patch.yml
同一 context 中,兩個 provider 不能同時擁有 ctx.midscene,所以只能配置一行 provider。
Android 示例:
- insert:
- id: midscene-android
name: dsh-plugin-midscene/android
config:
deviceId: ''
aiActionContext: ''
deviceId 爲空表示取 getConnectedDevices() 的第一個設備;aiActionContext 是自由上下文。
Web 示例:
- insert:
- id: midscene-web
name: dsh-plugin-midscene/web
config:
browserWSEndpoint: 'ws://127.0.0.1:9222/devtools/browser/<id>'
aiActionContext: ''
browserWSEndpoint 可以從:
http://127.0.0.1:9222/json/version
的 webSocketDebuggerUrl 獲取。Chrome 重啓後 id 變化,需要更新 provider row 並 restart dsh。
啓動:
dsh --profile mysetup
如果 3080 被佔用,可添加:
dsh --profile mysetup --port 3081
本地開發時可以使用:
dsh plugin --profile dev add /path/to/dsh-plugin-midscene
模型配置¶
通過環境變量配置 Midscene 兼容視覺模型:
export MIDSCENE_MODEL_NAME=glm-4.6v
export MIDSCENE_MODEL_BASE_URL=https://open.bigmodel.cn/api/paas/v4/
export MIDSCENE_MODEL_API_KEY=<your key>
export MIDSCENE_MODEL_FAMILY=glm-v
工具與錯誤語義¶
android_ui 和 web_ui 共用單一 action 參數,模型選擇動作後由工具處理。已覈實的動作包括:
tap
act
input
query
assert
boolean
back
失敗的 assert 是成功結果,表現爲 pass: false;基礎設施失敗才走 error path。
設計邊界與限制¶
這個插件的設計邊界是 no policy, no recovery:
- 沒有 retry
- 沒有 precondition checks
- 沒有 automatic recovery
其他限制:
- 每個 provider instance 只支持一個 target。
- 無 reconnect;中途斷連表現爲 rejected call。
@midscene/android與@midscene/web固定在 exactly1.11.0。- Web 的
puppeteer是 peer dependency;Chrome 由部署方提供,不由插件下載。 - Web provider 在 teardown 時 disconnect 而不 close,Chrome 進程由部署方保留。
安裝排障¶
pnpm ≥ 10 可能因 sharp / @ffmpeg-installer/linux-x64 的 transitive install scripts 報 ERR_PNPM_IGNORED_BUILDS。需要按 profile 做一次 allowBuilds 修復:打開:
~/.dsh/profiles/<name>/pnpm-workspace.yaml
按 pnpm 輸出的 allowBuilds 提示調整相關項,然後重新執行 add 命令。
適用場景與注意¶
適合已經使用 DSH,並需要讓模型操作真實 Android 設備或 Chrome 頁面的場景。
使用前建議:
- 插件以當前
dsh進程權限運行,安裝前應檢查源碼和許可證。 - 它不負責啓動 Chrome,也不會自動恢復異常 UI 狀態。
- Web 場景需要部署方提供 Chrome,並由環境解析
puppeteer。 - 視覺模型需要通過環境變量指向可訪問的服務。
鏈接¶
- 插件目錄頁:https://www.skillhub.cn/plugins/ciky20171114/dsh-plugin-midscene
- GitHub 倉庫:https://github.com/ciky20171114/dsh-plugin-midscene