DeepSeek Harness: 发布插件
最后更新:2026-08-31
写好的插件如果只在自己电脑上跑,价值有限。发布到 npm 和 GitHub,让其他 DSH 用户安装使用,你的插件才能真正融入生态。本课覆盖从代码到发布的全流程。
💡 提示:发布前最重要的步骤不是
npm publish,而是写好 README 和兼容性声明——用户能不能用你的插件,取决于文档是否清晰。
📋 前置知识:已完成 15-define-tool.md,能编写完整工具插件
1. 你将学到
- npm 发布流程
- package.json 的 dsh 字段
- dsh-plugin GitHub topic
- 版本管理与 semver
- 兼容性声明
- 插件文档编写
2. npm 发布流程
(1) 发布前检查清单
| 检查项 | 命令/方法 |
|---|---|
| 代码编译通过 | pnpm build |
| 测试通过 | pnpm test |
| package.json 正确 | 检查 name/version/main |
| README 存在 | 文件存在且内容完整 |
| .npmignore 配置 | 排除 src/ 等开发文件 |
| npm 登录 | npm whoami |
(2) ▶ 示例 2
BASH
# 编译 TypeScript
pnpm build
# 确认产物
ls dist/
# index.js index.d.ts ...
(3) ▶ 示例 3
BASH
# 首次发布
npm publish --access public
# 更新版本后发布
npm version patch # 1.0.0 → 1.0.1
npm publish
(4) ▶ 示例 4
TEXT
📖 仅展示
# .npmignore
src/
tests/
tsconfig.json
*.tsbuildinfo
.git/
.vscode/
只发布编译产物,不发布源码。
(5) 发布后验证
BASH
# 在另一个项目中安装
pnpm add @dsh-plugin/my-tool
# 验证导入
node -e "console.log(require('@dsh-plugin/my-tool'))"
3. package.json 的 dsh 字段
(1) dsh 字段结构
JSON
{
"name": "@dsh-plugin/my-tool",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dsh": {
"name": "my-tool",
"description": "A custom tool for DSH",
"services": ["tools"],
"inject": ["tools"],
"capabilities": [],
"compatibility": {
"dsh": ">=0.5.0",
"cordis": ">=1.0.0"
},
"permissions": [
"fs.read",
"network.outbound"
],
"config": {
"apiKey": {
"type": "string",
"required": true,
"description": "API key for the service"
}
}
}
}
(2) 各字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
name |
string | 插件标识(与 export const name 一致) |
description |
string | 插件描述 |
services |
string[] | 提供的服务列表 |
inject |
string[] | 依赖的服务列表 |
capabilities |
string[] | 实现的能力列表 |
compatibility |
object | 兼容性要求 |
permissions |
string[] | 所需权限 |
config |
object | 配置项描述 |
(3) dsh 字段的作用
- 安装时:DSH 读取 permissions 展示权限请求
- 加载时:DSH 读取 compatibility 检查版本兼容
- 发现时:npm 搜索可以过滤 dsh 字段
4. dsh-plugin GitHub topic
(1) 添加 topic
在 GitHub 仓库设置中添加 dsh-plugin topic:
TEXT
📖 仅展示
Repository Settings → Topics → Add topic: dsh-plugin
(2) topic 的作用
其他用户通过 topic 搜索插件:
BASH
# GitHub CLI 搜索
gh search repos --topic dsh-plugin --sort stars
# GitHub 网页搜索
https://github.com/topics/dsh-plugin
(3) 推荐的 topic 组合
TEXT
📖 仅展示
dsh-plugin ← 必须
deepseek-harness ← 可选,增加发现率
工具类型 ← 如 database, search, devops
(4) 命名规范
| 位置 | 命名 | 示例 |
|---|---|---|
| npm 包名 | @dsh-plugin/xxx |
@dsh-plugin/database |
| GitHub 仓库名 | dsh-plugin-xxx |
dsh-plugin-database |
| 插件 name | xxx |
database |
5. 版本管理与 semver
(1) semver 规则
版本号格式:MAJOR.MINOR.PATCH
| 变更类型 | 版本变化 | 说明 |
|---|---|---|
| PATCH | 1.0.0 → 1.0.1 | Bug 修复,向后兼容 |
| MINOR | 1.0.0 → 1.1.0 | 新功能,向后兼容 |
| MAJOR | 1.0.0 → 2.0.0 | 破坏性变更 |
(2) 版本变更指南
TEXT
📖 仅展示
什么情况下升 PATCH:
- 修复工具的 bug
- 修复配置校验问题
- 文档更新
什么情况下升 MINOR:
- 新增工具
- 新增配置项(有默认值)
- 新增能力实现
- 新增可选依赖
什么情况下升 MAJOR:
- 移除工具
- 修改工具参数格式
- 移除配置项
- 修改 inject 列表
- 修改 Capability 接口
(3) npm version 命令
BASH
# 升 PATCH
npm version patch -m "fix: resolve timeout issue"
# 升 MINOR
npm version minor -m "feat: add batch query tool"
# 升 MAJOR
npm version major -m "breaking: change tool parameter format"
(4) 预发布版本
BASH
# Alpha 版本
npm version prealpha --preid alpha
# 1.0.0 → 1.1.0-alpha.0
# Beta 版本
npm version prebeta --preid beta
# 1.0.0 → 1.1.0-beta.0
# RC 版本
npm version prerelease --preid rc
# 1.1.0-beta.0 → 1.1.0-rc.0
6. 兼容性声明
(1) package.json 中的声明
JSON
{
"dsh": {
"compatibility": {
"dsh": ">=0.5.0",
"cordis": ">=1.0.0",
"node": ">=18.0.0"
}
},
"peerDependencies": {
"@deepseek-ai/dsh": ">=0.5.0",
"@deepseek-ai/cordis": ">=1.0.0"
}
}
(2) 版本范围语法
| 语法 | 含义 | 匹配版本 |
|---|---|---|
>=0.5.0 |
大于等于 | 0.5.0, 0.6.0, 1.0.0 |
^0.5.0 |
兼容 0.5.x | 0.5.0 ~ 0.5.9 |
~0.5.0 |
兼容 0.5.0.x | 0.5.0 ~ 0.5.0.9 |
0.5.x |
0.5 任意 patch | 0.5.0 ~ 0.5.99 |
(3) 兼容性检查
BASH
# DSH 内置检查
dsh plugin check @dsh-plugin/my-tool
# 输出
✅ Compatible with dsh@0.5.0
✅ Compatible with cordis@1.0.0
⚠️ Requires Node.js >= 18.0.0 (current: 16.20.0)
(4) 破坏性变更的处理
发布 MAJOR 版本时:
- 在 CHANGELOG.md 中详细记录变更
- 提供迁移指南
- 保留旧版本至少 6 个月
- 在 README 中标注"Breaking Changes"
7. 插件文档编写
(1) README 模板
MARKDOWN
# @dsh-plugin/my-tool
> DSH plugin for [功能描述]
## 安装
\```bash
dsh plugin add @dsh-plugin/my-tool
\```
## 配置
\```yaml
plugins:
'@dsh-plugin/my-tool':
config:
apiKey: sk-xxx
maxRetries: 3
\```
## 提供的工具
| 工具 | 描述 |
|:-----|:-----|
| `my_tool` | Does something useful |
## 依赖
- DSH >= 0.5.0
- Cordis >= 1.0.0
## 权限
- fs.read
- network.outbound
### ▶ 示例
\```text
👤 Alice: 用 my_tool 分析项目
🤖 Agent:
🔧 Using tool: my_tool
→ Result: ...
\```
## 许可证
MIT
(2) 文档要素
| 要素 | 必需 | 说明 |
|---|---|---|
| 安装说明 | ✅ | 一行命令安装 |
| 配置说明 | ✅ | YAML 配置示例 |
| 工具列表 | ✅ | 提供的所有工具 |
| 依赖声明 | ✅ | DSH/Cordis 版本要求 |
| 权限声明 | ✅ | 所需权限及原因 |
| 使用示例 | ✅ | 至少一个完整示例 |
| API 文档 | ⚠️ | 如果提供 Service |
| 迁移指南 | ❌ | 仅 MAJOR 版本需要 |
(3) CHANGELOG 维护
MARKDOWN
# Changelog
## 1.1.0 (2026-08-20)
### Added
- batch_query tool for querying multiple paths
- Config option `maxDepth` for recursive analysis
### Fixed
- Timeout handling for large directories
## 1.0.0 (2026-08-01)
### Breaking
- Changed parameter format from `dir_path` to `path`
### Added
- Initial release with file_info tool
❓ 常见问题
Q 必须用
@dsh-plugin/ 前缀吗?A 推荐但不强制。
@dsh-plugin/ 前缀方便搜索和识别。私人插件可以用自己的 scope。Q 可以只发布到 GitHub 不发布 npm 吗?
A 可以。用户通过
github:user/repo 方式安装。但 npm 安装更快更稳定。Q 如何撤回已发布的版本?
A
bash npm unpublish @dsh-plugin/my-tool@1.0.0 只能在发布 24 小时内撤回,且不能撤回已有多人依赖的版本。Q 插件的 TypeScript 源码要发布吗?
A 推荐发布。在 package.json 中设置
"types": "dist/index.d.ts" 并包含 .d.ts 文件。源码通过 .npmignore 排除。Q 如何测试发布前的插件?
A
bash # 本地链接测试 cd dsh-plugin-my-tool npm link cd ../my-dsh-project npm link @dsh-plugin/my-tool # 验证 dsh plugin list Q 发布后发现 bug 怎么办?
A 修 bug → 升 patch 版本 → 发布。不要直接修改已发布版本。 ---
📖 小节
- npm 发布流程:build → 检查 →
npm publish - package.json 的
dsh字段描述插件元数据:服务、依赖、权限、兼容性 dsh-pluginGitHub topic 让其他用户通过 topic 搜索发现插件- semver 版本管理:PATCH(bug 修复)、MINOR(新功能)、MAJOR(破坏性变更)
- 兼容性声明在
dsh.compatibility和peerDependencies中双声明 - README 必须包含:安装、配置、工具列表、依赖、权限、示例
📝 作业
1. ⭐ 基础题:为之前编写的 file_count 工具插件补充完整的 package.json(包含 dsh 字段)和 README.md。使用 npm link 本地测试。
2. ⭐⭐ 进阶题:按照 semver 规范,为插件添加一个新功能(新工具),升 MINOR 版本。然后修复一个 bug,升 PATCH 版本。记录每次 npm version 命令的输出。
3. ⭐⭐⭐ 挑战题:将你的插件发布到 npm(可以是 --access public 的公开包或本地 registry)。发布后从另一个项目安装,验证所有功能正常。写一份 CHANGELOG.md 记录版本历史。