dsh-wsl-first:讓 DSH 在 Windows 上優先走 WSL 執行命令

前言

在 Windows 上使用 DeepSeek Harness(DSH)時,模型默認拿到的命令執行工具往往是 pwsh。若本機已經裝了 WSL,這個默認順序會帶來額外成本:模型更習慣寫 bash 與 POSIX 管道,被迫切到 PowerShell 時,引號、路徑和管道語義容易來回翻譯,失敗一次就多一輪重試,消耗 token。輸出形態也不一致——Linux 命令多爲緊湊純文本,PowerShell 默認常帶表格與對象屬性,同樣信息佔用的上下文更長。

下面介紹社區插件 dsh-wsl-first(維護者 yishuiliufang),分類爲工作流。它不新增工具、也不禁用任何工具,只在系統提示裏插入一段可配置的「Shell 路由」說明,引導模型優先調用 wsl,需要 Windows 原生能力時再退到 pwsh。DSH 生態是「一切皆插件」;插件目錄站點 SkillHub 爲社區獨立維護,與 DeepSeek / 幻方無官方從屬關係。

這是什麼

dsh-wsl-first 是一個基於 systemPrompt 服務的可配置路由器:在系統提示中追加「優先用 wsl 執行命令」的段落,改變默認選擇順序,而不是替換或隱藏 pwsh。路由文案只會列出當前 profile 裏已註冊的執行器;未安裝的工具不會出現在提示裏,避免模型被指示調用不存在的工具。

插件自身不註冊任何 tool,路由目標由其他插件提供。沒有 dsh-wsl-tool 時,就沒有 wsl 可優先,對應段落會渲染爲空。

核心功能

  1. 優先 WSL:默認 preferred 爲 wsl,discouraged 含 pwsh,模型被引導先走 Linux 側 bash。
  2. 保留 Windows 出口:pwsh 仍在工具列表中,僅作爲「確實需要 Windows 原生能力」時的最後手段。
  3. 可配置順序:可把首選改爲 bash,或只宣傳 wsl、清空備選與 discouraged 列表。
  4. 動態工具表:段落內的任務—工具表隨當前已註冊工具生成;例如 profile 未註冊 bash 時,渲染結果裏不會出現 bash 行。
  5. 進程級 patch:包內自帶 cordis.patch.yml,通過 profile 的 bundle 掛載後,各 agent preset 無需單獨聲明即可帶上該段提示。

環境與依賴

項 要求
DSH >=0.1.7-rc.2(package.json 中 engines.dsh)
服務 systemPrompt(標準 profile 自帶)
依賴插件 dsh-wsl-tool(提供 wsl / wsl-path / wsl-env / wsl-doctor)
WSL WSL2,至少一個已註冊發行版,wsl.exe 在 PATH 上
平臺 路由邏輯與平臺無關;主要動機場景是 Windows

安裝與啓用

先用 npm 安裝包(與 README 一致,勿自行拼接其他安裝命令):

npm install dsh-wsl-first

在 profile 的 package.json 裏把 bundle 加入 dsh.profile.bundles:

{
  "dsh": {
    "profile": {
      "bundles": ["...", "dsh-wsl-first"]
    }
  }
}

bundle 會加載自帶的 cordis.patch.yml,在進程範圍內插入路由行。修改 bundle 後需要重啓 DSH(或重啓 profile),loader 在啓動時讀取組合關係。

若尚未安裝 wsl 工具,先安裝依賴插件:

npm install dsh-wsl-tool

版本兼容說明:本插件未聲明 @deepseek-ai/* peer dependency。DSH 啓動時會對 bundle 做兼容性檢查;若某 peer 範圍不匹配運行版本,整個 bundle 可能被跳過,表現爲「裝了但沒效果」。升級 DSH 大版本後若失效,可在 stderr 中查找 skipping profile bundle,並確認 engines.dsh 仍覆蓋當前版本。

插件以當前 DSH 進程權限運行;安裝前建議閱讀 GitHub 倉庫 源碼與 MIT 許可證(package.json 當前版本 0.1.0)。

配置

字段均可寫在 profile patch(- id: wsl-first-routing / config:)或環境變量中。優先級:行內 config > 環境變量 > 內置默認。

字段 默認值 環境變量 含義
preferred wsl DSH_WSL_FIRST_PREFERRED 首選執行器
alternatives ['bash'] DSH_WSL_FIRST_ALTERNATIVES 首選之後嘗試(逗號分隔)
discouraged ['pwsh'] DSH_WSL_FIRST_DISCOURAGED 推到最後(逗號分隔)
promptPolicy true — 是否發佈該段
sectionOrder 3260 — 段落排序
sectionName dsh-wsl-first:shell-routing — 段落穩定名稱
extraGuidance '' — 追加到段落的額外說明
labels 內置 — 工具與任務描述表
requirePreferred false — 僅當 preferred 可見時才發佈

僅 WSL、不寫備選(未裝 wsl 的環境整段不出現):

- id: wsl-first-routing
  config:
    preferred: wsl
    alternatives: []
    discouraged: []

改首選爲 bash(插件本質是通用執行器路由器,wsl 只是默認):

- id: wsl-first-routing
  config:
    preferred: bash
    alternatives: []
    discouraged: []

配置約束:同一工具不能既在首選/備選又在 discouraged,否則會拋錯;preferred 重複出現在 alternatives 中會被去重。

系統提示中的效果

啓用後,系統提示中會插入類似下面的段落(實際內容隨已註冊工具變化;下列示例來自 README 中 live session 讀回,該 profile 未註冊 bash,故無 bash 行):

# Shell routing: wsl first

**For every command execution, call `wsl` as the first and default tool.**

| Task | Tool |
| --- | --- |
| Any command, build, git, pipeline, script, file listing, search | `wsl` |
| Windows-native only: registry, services, COM, cmdlets with no Linux equivalent | `pwsh` (last resort) |

## Rules

- `wsl` is the primary command executor. Reach for it first, every time.
- Use `pwsh` **only** when the task genuinely requires functionality no other available tool provides — and say why in the same reply.
- Never use `pwsh` merely because it appears first in a tool list, and never as a fallback when a `wsl` command fails: fix the command and retry there.
- Do not mix shell syntaxes. A `wsl` call contains the syntax of the shell that tool runs; each executor has its own quoting and path rules.
- `wsl` paths are Linux paths (`/mnt/c/...`). Windows paths in `command`/`workdir` are translated automatically; pass `translatePaths: false` to hand a native path to a Windows program.

dsh-wsl-tool 會在 wsl 側處理 C:\... 到 /mnt/c/... 的路徑轉換,模型在多數場景下無需手動換算。

適用場景與注意

適合:Windows 上已裝 WSL2 與 dsh-wsl-tool,希望 agent 默認在 Linux 環境跑 git、構建、管道與常見 CLI,減少 PowerShell 語法摩擦與重試。

不適合或需額外準備:無 WSL、或未裝 dsh-wsl-tool 的環境——路由段爲空或無法指向 wsl。

已知問題(不影響運行邏輯):在插件管理器中開關本插件時,可能出現「停用失敗: dsh: profile reload requires the root Include entry」或「啓用失敗: dsh: warning: 1 entry did not activate」。路由段仍會生效;重啓 DSH 後開關狀態與提示會按啓動加載恢復正常。運行中直接改 profile 的 cordis.patch.yml 可能從 live session 剝離工具,改完後應重啓而非依賴熱重載。

若希望硬性去掉 pwsh(而非僅路由),需在 profile patch 中自行禁用對應 sandbox 行(例如 - id: pwsh-sandbox / disabled: true,以 loader 樹中真實 id 爲準)——這與本插件「只改默認順序、不隱藏工具」的設計是不同層級的選擇。

結尾

dsh-wsl-first 用一段動態生成的系統提示,把命令執行默認順序從 pwsh 調到 wsl,在不剝奪 Windows 原生能力的前提下,讓模型按更自然的 bash 習慣工作。目錄與詳情見 SkillHub 插件頁,源碼與完整說明見 GitHub:yishuiliufang/dsh-wsl-first。

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

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

小夜