前言¶
在 DeepSeek Harness(DSH)裏跑智能體時,項目約定通常寫在 AGENTS.md 或 CLAUDE.md 裏,DSH 會加載這些文件。但很多倉庫裏還有另一套規則:有人加了 .cursor/rules/testing.mdc,有人維護 .github/copilot-instructions.md,某段時間試過 Windsurf 時留下了 .windsurfrules。這些文件對各自工具有意義,DSH 默認不會讀,於是模型可能不知道「我們用 Vitest 不用 Jest」或「不要改舊 migration」,儘管規則已經寫在倉庫裏。
下面介紹社區插件 dsh-load-agent-rules(維護者 acus9345):它掃描這些常見 AI 工具的規則文件,按各工具原本的語義交給模型,無需你手工轉換或複製。
這是什麼¶
dsh-load-agent-rules 是 DeepSeek Harness 插件,分類上屬於模型推理相關能力:在會話中把 Cursor、GitHub Copilot、Windsurf、Cline、Kiro、Roo Code、Gemini CLI、JetBrains Junie 等工具使用的規則文件發現並注入上下文。插件在 SkillHub 目錄 與 GitHub 分發,許可證爲 MIT,當前包版本爲 0.2.3(以倉庫 package.json 爲準)。
會讀取哪些文件¶
插件按工具約定掃描路徑,嵌套目錄也會處理。下表來自官方 README。
| 工具 | 規則文件 |
|---|---|
| Cursor | .cursor/rules/**/*.mdc、.cursorrules |
| GitHub Copilot | .github/copilot-instructions.md、.github/instructions/*.instructions.md |
| Windsurf | .windsurf/rules/*.md、.windsurfrules |
| Cline | .clinerules(文件或目錄) |
| Kiro | .kiro/steering/*.md |
| Roo Code | .roo/rules/*、.roorules |
| Gemini CLI | GEMINI.md |
| JetBrains Junie | .junie/guidelines.md |
同一內容常以不同文件名或 symlink 重複出現;插件會去重,並與 DSH 已加載的 AGENTS.md、CLAUDE.md 比對,去掉完全相同的內容。
規則如何進入模型上下文¶
各工具對「何時生效」的定義不同,插件儘量保留原意,而不是把所有規則一次性塞進 prompt。
始終生效的規則 在會話開始時寫入上下文一次。包括 Cursor 的 alwaysApply: true、Copilot 主說明文件、Windsurf 的 always_on、Kiro 的 inclusion: always,以及 .cursorrules 這類純文本文件。會話中若規則文件變更,或上下文壓縮導致規則丟失,會再次發送。
按文件匹配的規則 在智能體首次讀或改匹配路徑的文件時附加,只附加一次,不會在每次觸碰文件時重複注入。例如 Cursor 的 globs: "*.tsx"、Copilot 的 applyTo: "src/db/**"、Kiro 的 fileMatch、Windsurf 的 glob。位於 packages/web/.cursor/rules/ 下的規則僅在該子樹內生效。
僅帶描述、需模型自行判斷的規則(如 Cursor 的 agent requested、Windsurf 的 model_decision)會以名稱和描述列出;模型可通過 project_rule 工具在認爲相關時打開。僅手動觸發的規則也會出現在該列表中。
首次請求中,上下文大致會包含已加載的 always-on 規則片段,並提示還有更多文件級規則與可按需讀取的條目,例如:
These are the project rules written for this repository. Follow them like the rest of your instructions.
<rule name=".cursor/rules/style.mdc">
Use tabs for indentation. Prefer named exports.
</rule>
More project rules are available. File-scoped rules are added automatically the first time you read or edit a matching file.
Read any of them with the `project_rule` tool when it is relevant to your task:
- .cursor/rules/react.mdc (applies to *.tsx): React conventions
- .github/instructions/db.instructions.md: Database migration conventions
安裝與啓用¶
DSH 按 profile 維護插件列表;你用的每種運行方式都要單獨安裝。官方安裝命令如下(web 對應 dsh web 的瀏覽器界面):
dsh plugin --profile web add dsh-load-agent-rules
若用腳本或 CI 跑 DSH,將 web 換成 headless;若通過編輯器集成使用,換成 acp。安裝後在下一次會話生效。移除命令:
dsh plugin --profile web remove dsh-load-agent-rules
本地調試插件時,README 說明可先構建 tarball 再安裝(示例包名爲 dsh-load-agent-rules-0.2.0.tgz,版本以你 npm pack 產出爲準):
git clone https://github.com/acus9345/dsh-load-agent-rules
cd dsh-load-agent-rules
npm install
npm pack
dsh plugin --profile web add ./dsh-load-agent-rules-0.2.0.tgz
配置¶
可在 DSH 側欄 Plugins 中點開 dsh-load-agent-rules,修改後 Save;除 toolName 外多數項在下一次 tool call 生效,toolName 變更需重啓。
也可在 ~/.dsh/profiles/<profile>/cordis.patch.yml,或全局 ~/.dsh/cordis.patch.yml 中增加片段;未寫的鍵保持默認:
- id: load-agent-rules
config:
sources: [cursor, copilot, windsurf, cline, kiro, roo, gemini, junie] # drop any you don't want
maxBaselineBytes: 48000 # budget for always-on rules; the rest are listed instead
maxAttachBytes: 24000 # budget for rules attached on one file touch
maxFileBytes: 200000 # skip rule files bigger than this
toolName: project_rule # '' to not register the tool
touchTools: [read, write, edit, str_replace_editor]
maxBaselineBytes 控制 always-on 規則的字節預算;超出部分不會靜默丟棄,而是以列表形式提示,由模型通過工具讀取。單文件超過 maxFileBytes 的規則會被跳過。
適用場景與注意¶
適合已經在倉庫裏爲 Cursor、Copilot、Windsurf 等維護規則、又希望在 DSH 裏複用同一套約定的團隊。插件不替代 AGENTS.md / CLAUDE.md,而是補齊 DSH 默認不掃描的路徑。
DSH 生態強調「一切皆插件」;SkillHub 爲社區目錄,與 DeepSeek / 幻方無官方從屬關係。插件以當前 DSH 進程權限讀取倉庫與配置,安裝前建議查看 源碼與 MIT 許可證,自行評估是否納入工作流。問題與建議可在 GitHub Issues 反饋。
結尾¶
經過上面的步驟,DSH 可以直接沿用倉庫裏爲其他 AI 編碼工具寫好的規則,並按 glob、always-on 等語義注入上下文。dsh-load-agent-rules 減少重複維護多套說明的成本。目錄頁:https://www.skillhub.cn/plugins/acus9345/dsh-load-agent-rules;倉庫:https://github.com/acus9345/dsh-load-agent-rules。