前言¶
在 DeepSeek Harness(DSH)裏讓智能體操作 GitHub,常見做法是外掛腳本或臨時拼 REST 調用:token 散落、寫操作難審計、瀏覽器端還要遷就 ESM 與 window.__ModuleLoader__ 的加載約束。valing1837 維護的 dsh-plugin-github 走另一條路——host-only:只註冊宿主側 agent 工具,不附帶客戶端 bundle,從結構上避開桌面版 web 啓動與模塊格式衝突;token 從 DSH 憑證域解析,寫 GitHub 狀態前可走審批門禁;另帶不依賴模型憑據的確定性 PR 審查與可複用的 composite action 思路。插件面向 DSH 0.2.0-rc.2,在 Node 22.19 或 24 上開發與測試(package 聲明 ^22.19.0 || >=24.0.0)。
這是什麼¶
dsh-plugin-github 是社區插件(分類:工作流),倉庫 valing1837/dsh-plugin-github,目錄頁 SkillHub。一句話:通過 GitHub REST API 與本地 git,把建庫、讀 diff、開/審/合併 PR、issue、搜索、checks、發版等能力暴露爲 DSH 工具;審查側用純函數規則掃 unified diff,刻意不做模型調用。許可證 MIT,當前 package 版本 0.1.0。
爲什麼是 host-only¶
插件沒有 dsh.client、沒有 lib/client.js。DSH 0.2.x 瀏覽器端要求客戶端以 window.__ModuleLoader__.load({...}) 自注冊且不含頂層 import;普通 ESM 放進去會導致 web 啓動失敗(README 實測:Cannot use import statement outside a module)。本插件只掛主機工具,不觸發該類故障。
核心功能¶
Agent 工具(29 個)¶
README 工具表覆蓋倉庫生命週期、PR/issue、內容與 CI 等,例如:
| 類別 | 代表工具 |
|---|---|
| 診斷 | github_status(配置與 token 來源,不發請求、不打印密鑰)、github_whoami |
| 倉庫 | github_create_repo、github_list_repos、github_delete_repo(需 confirm 精確等於 owner/repo)、github_clone、github_push |
| 內容與分支 | github_get_file、github_put_file、github_delete_file、github_list_branches、github_compare |
| Pull Request | github_list_pulls、github_get_pull(元數據 + 逐文件 patch + 全量 unified diff)、github_create_pull、github_update_pull、github_review_pull、github_merge_pull |
| Issue | github_list_issues、github_get_issue、github_create_issue、github_update_issue、github_comment |
| 搜索與 CI | github_search、github_get_checks、github_set_status |
| 發版 | github_list_releases、github_create_release |
| 審查(只讀) | github_analyze_pull:對 PR diff 跑確定性規則,返回發現 + 可發佈的 review body + 行內評論形狀 |
斜槓命令 /github¶
不經過模型輪次,直接查詢(實現上不硬注入 commands,而用 ctx.get('commands') 探測,避免缺組合命令運行時整包加載失敗):
/github status token 來源、apiBase、門禁狀態
/github whoami 當前賬號
/github repo <owner>/<name> 倉庫概要
/github pr <owner>/<name> <n> PR 概要
/github checks <owner>/<name> <ref> CI 狀態(列出不是綠色的 run)
/github review <owner>/<name> <n> 對 PR 跑確定性審查
/github search <query> 搜索 issue / PR
寫操作審批門禁¶
配置 approveWrites 默認 true 時,註冊 tools/pre-execute 監聽器,對 14 個會改變 GitHub 狀態的工具返回 { kind: 'ask', reason: '... will change state on GitHub: ...' }。運行時經 ctx.approval 派發,僅 allowed-once 繼續;無應答方則拒絕。被攔工具包括 create_repo、delete_repo、push、create_pull、update_pull、review_pull、merge_pull、create_issue、update_issue、comment、put_file、delete_file、create_release、set_status。github_clone 不在門禁內(只從 GitHub 讀,本地寫由文件沙箱管)。可設 approveWrites: false 關閉監聽器。
確定性審查(lib/review.js)¶
純函數:輸入 unified diff,輸出發現;無網絡、無時鐘、無隨機數。規則示例:secret-literal、known-token-prefix、conflict-marker、focused-test、sensitive-file 等爲 error;debug-leftover、dangerous-eval、destructive-shell 等爲 warning;todo-added、trailing-whitespace、lockfile-only、large-change(默認超過 largeChangeLines 800 行)等爲 note。輸出含發現列表、帶標記 <!-- dsh-plugin-github:review --> 的 review body,以及可錨定新增行的 GitHub 行內評論;文件級/PR 級進 unanchoredFindings。
安全相關設計(README 摘要)¶
- Token 不寫進插件源碼;
github_push/github_clone完成後儘量把origin設爲無憑證 URL。 - stdout/stderr 經
redact()再返回,避免 git 報錯泄露帶 token 的 URL。 - 提交身份優先用已有
git config user.email,爲空才用配置的authorName/authorEmail。
安裝與啓用¶
桌面版 profile 由 Electron 獨佔,CLI 的 dsh plugin add 會拒絕管理 desktop profile,因此官方步驟是 clone 後跑安裝腳本(冪等,改 package.json 前會備份):
git clone https://github.com/valing1837/dsh-plugin-github
cd dsh-plugin-github
powershell -ExecutionPolicy Bypass -File install.ps1
腳本將包複製到 <profile>\node_modules\dsh-plugin-github,並把 dsh-plugin-github 寫入 <profile>\package.json 的 dsh.profile.bundles。默認 profile 爲 %USERPROFILE%\.dsh\profiles\desktop,可用 -ProfileDir 覆蓋。裝完需重啓 DSH(宿主側改動不會被 HMR 重載)。
Token 與權限¶
解析順序:
- 配置項
token(字面值,不推薦) - DSH 憑證域
credentialRef(tokenRef),默認引用名GITHUB_TOKEN - 環境變量
GITHUB_TOKEN
推薦在 %USERPROFILE%\.dsh\.credentials.yaml 的 refs: 下配置:
refs:
GITHUB_TOKEN: ghp_xxxxxxxx
| 方式 | 需要什麼 |
|---|---|
| 經典 token | scope repo(含建庫、推送、PR/issue、刪除倉庫) |
| 細粒度 token | Contents / Pull requests / Issues 各 RW,Metadata R;建庫另需 Account → Administration RW |
用 github_status 看 token 是否解析、來源何處;github_whoami 驗證有效性。
配置項(節選)¶
可在 profile patch 中覆蓋,均有默認值:
| 鍵 | 默認 | 說明 |
|---|---|---|
tokenRef |
GITHUB_TOKEN |
憑證引用名 |
apiBase |
https://api.github.com |
REST 基址 |
gitHost |
github.com |
Enterprise 可改 |
approveWrites |
true |
寫操作審批 |
reviewMinSeverity |
warning |
行內評論最低嚴重度 |
reviewMaxComments |
20 |
行內評論上限(≤50) |
largeChangeLines |
800 |
大改動提示閾值 |
完整列表見倉庫 README「配置項」一節。
典型用法¶
- 安裝並重啓 DSH,在憑證文件或環境中配置
GITHUB_TOKEN。 - 在會話中讓 agent 調用
github_status/github_whoami確認連通。 - 讀 PR:
github_get_pull或斜槓/github pr owner/name n;只分析不發文:github_analyze_pull或/github review owner/name n。 - 需要改 GitHub 狀態時,在
approveWrites: true下於 UI 審批一次(allowed-once)後再執行github_push、github_create_pull、github_merge_pull等。
倉庫還提供 action.yml 與審查 CLI,供 CI 側複用同一套 diff 規則;README 註明 composite action 已在本地 Git Bash 對真實 PR 做過腳本驗證,尚未在 GitHub 託管 runner 上跑完 self-review 工作流(計劃在本倉庫下一 PR 完成)。
適用場景與注意¶
適合:已在 DSH 0.2.x 桌面 profile 上開發、希望 agent 穩定操作 GitHub(倉庫/PR/issue/審查/狀態),且希望寫操作有人工門禁、PR 審查不綁定模型 API 的團隊或個人。
注意:
- 插件以當前 DSH 進程權限運行,安裝前請自行審閱源碼與 MIT 許可證。
- 不要使用資料未給出的
dsh plugin add github:...安裝方式;以 README 的install.ps1爲準。 github_delete_repo不可逆,且需 confirm 護欄;經典 token 的reposcope 權限範圍大,應按最小需要選用 token 類型。- 社區目錄 SkillHub 與 DeepSeek / 幻方無官方從屬關係,本文僅介紹社區插件能力。
結尾¶
dsh-plugin-github 把 GitHub 工作流收進 DSH 主機側:29 個工具、寫審批、確定性 diff 審查與 /github 快捷查詢,token 走憑證域,審查方不必持有模型憑據。進一步瞭解請訪問 SkillHub 目錄頁 與 GitHub 倉庫。