dsh-pnpm-manager:爲 DSH 下的 pnpm 做代理與 registry 切換

前言

DeepSeek Harness(DSH)在安裝、更新插件時依賴 pnpm 拉取依賴。在 Windows 上,Node 與 pnpm 不會走系統代理,pnpm 往往直連 registry.npmjs.org 和 GitHub。防火牆後常見慢連或 ECONNRESET;把 pnpm 指到本機代理(例如 Clash 的 127.0.0.1:7897)能明顯加快解析,但代理一關,安裝又會失敗。手工改 ~/.npmrc 可以切換,卻容易和日常配置纏在一起。

dsh-pnpm-manager(維護者 easyzoom,GitHub 倉庫 easyzoom/dsh-pnpm-manager)面向上述場景:在 DSH 設置頁或獨立 CLI 裏,控制 DSH 所用 pnpm 是否走代理,並查看、切換 registry 與 store。README 將其描述爲「Proxy and registry switch for DeepSeek Harness (DSH) pnpm — host plugin + Settings tab + standalone CLI」。分類爲客戶端插件;當前 package 版本爲 0.1.0,許可證 MIT,要求 Node >= 18。

這是什麼

插件通過 package.json 的 dsh.bundle.patch 與 cordis.patch.yml 向宿主 bundle 插入一行配置;該行的 Config(schemastery)由 DSH 渲染成設置表單。可選的 lib/client.js 還會在插件頁與 Settings → Built-in plugins 下注冊 pnpm 代理 標籤頁(含保存確認與「測試連接」)。同一套邏輯也可脫離界面,用 bin/dsh-pnpm-manager.mjs 作爲 CLI 使用。

會改哪些文件

只讀寫用戶主目錄下的 ~/.npmrc 中與 proxy、https-proxy、registry 相關的行,其餘項保留不動。僅在內容確實變更時寫入帶時間戳的備份(*.bak-<timestamp>)。

核心功能

宿主設置項

字段 取值 含義
mode on / off / auto 強制開代理 / 強制直連 / 僅當代理端口可達時啓用
proxyUrl URL 代理地址,默認 http://127.0.0.1:7897
noProxy 逗號分隔主機名 走代理時的 bypass 列表(noproxy)
strictSsl true / false 嚴格 TLS;對 SSL 攔截型代理(如 Clash)可設爲 false → strict-ssl=false
registry keep / npmjs / npmmirror 不改 registry / 官方源 / 中國鏡像

在表單中修改後,會立即重寫 ~/.npmrc(loader 會重新應用該行)。README 註明:在隔離的 web profile 與 desktop 應用中,宿主路由返回實時數據;卡片出現在插件頁,並在 Settings → Built-in plugins 的 pnpm 代理 標籤中展示模式狀態及 開 / 關 / 自動 / 測試;宿主路由另有單元測試。

獨立 CLI

在插件目錄或全局安裝後,可執行:

node bin/dsh-pnpm-manager.mjs status [--json]
node bin/dsh-pnpm-manager.mjs doctor [--json]
node bin/dsh-pnpm-manager.mjs on | off | toggle | auto
node bin/dsh-pnpm-manager.mjs proxy http://127.0.0.1:7890   # 或: proxy reset
node bin/dsh-pnpm-manager.mjs registry npmjs | npmmirror
node bin/dsh-pnpm-manager.mjs store
node bin/dsh-pnpm-manager.mjs test

環境變量:PNPM_PROXY_URL、DSH_PROFILE_DIR、DSH_PNPM_CJS。

安裝與啓用

使用 DSH 自帶的 dsh CLI。將 <profile> 換成你的 profile 名(桌面應用爲 desktop,dsh web 爲 web,依此類推)。

# 1) git source (main channel)
dsh plugin --profile <profile> add "github:easyzoom/dsh-pnpm-manager#main"

# 2) npm (once published to npm)
dsh plugin --profile <profile> add dsh-pnpm-manager

# 3) local dev (a checkout of this repo)
dsh plugin --profile <profile> add /path/to/dsh-pnpm-manager

說明(摘自 README):

  • desktop profile 由正在運行的應用鎖定 — 用 CLI 安裝前請先關閉 DeepSeek Harness,或在應用的 Plugins 面板裏安裝。
  • git 源在已配置 git 憑證時可用於私有倉庫;公開倉庫無需鑑權。
  • npm 方式需包已發佈到 npm(npm publish)後方能使用。

典型用法

  1. 在防火牆或需本機代理的環境下,安裝插件後打開 Settings → Built-in plugins → pnpm 代理,將 mode 設爲 on 或 auto,確認 proxyUrl 與本地代理端口一致,保存並點 測試連接。
  2. 需要國內鏡像時,在表單或 CLI 中將 registry 設爲 npmmirror:node bin/dsh-pnpm-manager.mjs registry npmmirror。
  3. 臨時直連:node bin/dsh-pnpm-manager.mjs off;恢復代理:on 或 toggle。
  4. 排查當前生效配置:node bin/dsh-pnpm-manager.mjs status 或 doctor [--json]。

適用場景與注意

適合經常在 DSH 裏裝插件、且 pnpm 網絡行爲需要隨環境(代理開/關、鏡像切換)快速調整的用戶。插件以當前 DSH 進程的用戶權限讀寫 ~/.npmrc;安裝前請自行查看倉庫源碼與 MIT 許可證,確認改動範圍可接受。

DSH 生態強調「一切皆插件」;社區目錄(如 SkillHub 上的條目)爲獨立站點,與 DeepSeek / 幻方無官方從屬關係。

代碼佈局(便於對照倉庫)

lib/index.js            host plugin (name / Config / apply + web routes)
lib/npmrc.js            shared .npmrc read/write helpers
lib/client.js           optional client card (__ModuleLoader__ bundle)
bin/dsh-pnpm-manager.mjs   standalone CLI
cordis.patch.yml        bundle patch (inserts the host row)

更多細節與截圖見倉庫 README:github.com/easyzoom/dsh-pnpm-manager。

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

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

小夜