dsh-plugin-git-bash:讓 DSH 在 Windows 上默認使用 Git Bash

前言

在 DSH 的插件化擴展中,Windows 上的 shell 環境會影響命令執行的細節。dsh-plugin-git-bash 解決的是一個問題:讓 DeepSeek Harness(DSH)在 Windows 上默認使用 Git for Windows Bash,同時保留 DSH 原有的 read-only、workspace-write 和 danger-full-access 權限語義。

這個插件由 inmny 維護,npm 包名爲 dsh-plugin-git-bash,GitHub 倉庫爲 dsh-git-bash,許可證爲 MIT。

這是什麼

dsh-plugin-git-bash 是一個安裝到 DSH profile 的 bundle layer,用來把 DSH 在 Windows 上的默認 shell 切到 Git for Windows Bash。

插件安裝到 profile 後,standard、code、cordis 和 minimal preset 會使用 Git Bash 代替 PowerShell。前臺命令、後臺命令和 Web Agent preset 共用同一個 executor。

它只作爲 bundle layer 安裝到目標 profile,不修改 DSH 安裝目錄。

核心功能

下面介紹插件已經明確支持的能力。

  • 在 Windows 上讓 DSH 默認使用 Git for Windows Bash。
  • 保留 DSH 的 read-only、workspace-write 和 danger-full-access 權限語義。
  • 安裝到 profile 後,standard、code、cordis 和 minimal preset 使用 Git Bash 代替 PowerShell。
  • 前臺命令、後臺命令和 Web Agent preset 共用同一個 executor。
  • 自動探測 Program Files、用戶安裝目錄和 Scoop 中的 Git Bash,並支持手動配置 bash.exe 路徑。
  • Web GUI 中可展開 Bash 工具行,查看 command、cwd、stdout/stderr 和 exit status。
  • npm 包包含 win32-x64 預編譯的 msys-token-guard.exe 和 msys-token-guard-hook.dll。

安裝與啓用

運行時要求:

  • Windows x64
  • Node.js 24 或更高版本
  • DSH 0.1.0-rc.7
  • Git for Windows x64

先安裝固定版本到 Web profile:

dsh plugin --profile web add dsh-plugin-git-bash@0.3.1

安裝完成後重啓 dsh web,讓 Host 和瀏覽器 client 同時加載新版本,然後新建會話。

安裝最新版時可以省略版本號:

dsh plugin --profile web add dsh-plugin-git-bash

開發本地版本時傳入 checkout 路徑:

dsh plugin --profile web add C:\path\to\dsh-git-bash

驗證 shell

新建會話後運行下面的命令,確認當前 shell 已經是 Git Bash 環境:

printf 'shell=%s\nversion=%s\nmsystem=%s\n' "$BASH" "$BASH_VERSION" "$MSYSTEM"

其中 MSYSTEM 應爲 MINGW64 或 MINGW32。

Web GUI 中也可以展開 Bash 工具行,查看該次命令的 command、cwd、stdout/stderr 和 exit status。

配置 bash.exe 路徑

插件會自動探測 Program Files、用戶安裝目錄和 Scoop 中的 Git Bash。

無 GUI 場景可以在啓動 DSH 前設置 DSH_GIT_BASH_PATH:

$env:DSH_GIT_BASH_PATH = 'D:\Apps\Git\bin\bash.exe'
dsh web

也可以在 profile 的 cordis.patch.yml 中爲 provider 配置 executable:

- id: git-bash-shell
  name: dsh-plugin-git-bash
  config:
    executable: D:\Apps\Git\bin\bash.exe

權限模式

read-only 和 workspace-write

受限模式下,DSH Windows ACL sandbox 會創建 WRITE_RESTRICTED token。插件在 sandbox 內先運行 native guard,再由 guard 啓動 Git Bash:

DSH ACL runner -> msys-token-guard.exe -> bash.exe -> child processes

具體語義是:

  • read-only 可以啓動 Git Bash,但不能寫 workspace。
  • workspace-write 只能寫 DSH 授權的 workspace 和 private temp。

danger-full-access

danger-full-access 不經過 native guard,直接運行 Git Bash,與插件 0.1.x 的執行方式一致。

平臺支持與限制

npm 包包含預編譯的 msys-token-guard.exe 和 msys-token-guard-hook.dll,普通安裝不需要 Visual Studio 或 CMake。

當前 native guard 僅支持 win32-x64。其他架構在受限模式下會返回 SANDBOX_UNAVAILABLE,不會降級到未隔離執行。

Microsoft Detours 4.0.1 源碼按 MIT 許可存放在 native/vendor/detours,許可文本隨 npm 包分發。由於 Detours 的 DLL path 參數使用 Windows ANSI API,插件安裝路徑必須能由當前系統代碼頁無損表示,並且不能超過 MAX_PATH;不滿足條件時 guard 會 fail closed。

適用場景與注意

這個插件適合以下場景:

  • 需要在 Windows 上把 DSH 的默認 shell 統一爲 Git Bash。
  • 需要保留 DSH 的 read-only、workspace-write 和 danger-full-access 權限語義。
  • 需要在 Web GUI 中查看 Bash 命令的執行詳情。

安裝前要注意:

  • 插件最終運行在 DSH 進程所獲得的系統權限範圍內,安裝前應檢查源碼、許可證和依賴。
  • 當前 native guard 僅支持 win32-x64。
  • 安裝路徑必須滿足 Windows ANSI API 的代碼頁要求和 MAX_PATH 限制。
  • danger-full-access 不經過 native guard,會直接運行 Git Bash,使用前應明確該權限範圍。

結尾

dsh-plugin-git-bash 的價值比較具體:它把 DSH 在 Windows 上的默認 shell 切到 Git for Windows Bash,同時保留 DSH 的權限語義,並在受限模式下通過 native guard 維持 sandbox 隔離路徑。

GitHub:https://github.com/inmny/dsh-git-bash

目錄頁鏈接未在已覈實資料中確認,本文不寫具體地址;如果社區目錄收錄,可搜索 dsh-plugin-git-bash。社區目錄是獨立站點,與 DeepSeek / 幻方無官方從屬關係。

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

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

小夜