yale-demo-plugin
DeepSeek Harness(DSH)示例插件 —— 在 Web 设置页左侧新增一项 demo-plugin,点进去右侧显示 hello dsh plugin.。
仓库名是 dsh-demo-plugin,npm 包名是 yale-demo-plugin。两者不一致是有意的:仓库用来归类,包名跟着发布者走。
用来演示两件事:
- 一个树外(不在 DSH 仓库里)插件包,如何被
dsh plugin add 安装进 profile;
- 一组 Host 半侧 + 浏览器半侧,如何通过
settings.section slot 往设置页塞一个页面。
安装
dsh plugin --profile web add yale-demo-plugin
在 deepseek-harness 源码目录里则用 pnpm dsh plugin --profile web add yale-demo-plugin(pnpm dsh 就是「用 pnpm 跑 dsh CLI」)。
装完重启 dsh --profile web,打开设置,左栏就是 demo-plugin。
移除:
dsh plugin --profile web remove yale-demo-plugin
开发
npm install
npm run build # tsc 出 Host 半侧到 lib/,tsdown 出浏览器半侧到 client/client.js
npm run check # 校验产物齐全、且浏览器 bundle 带正确的模块表握手前缀
npm run typecheck # 两个 project:Host(tsconfig.json)与浏览器(tsconfig.client.json)
pnpm 同样可用(.npmrc 已经设好 node-linker=hoisted,原因见文末)。
本地联调不必发布,直接装这个目录:
dsh plugin --profile web add ./yale-demo-plugin
发布
npm publish
prepare 会在打包前先跑 build,所以 npm 上拿到的是预构建产物,用户安装时不需要任何构建授权(对比 git 安装:那种方式拉源码、要用户显式允许 prepare 执行)。
推到 GitHub
仓库 yiou362/dsh-demo-plugin(私有)。一条命令搞定建仓 + 推送:
bash scripts/publish-to-github.sh
首次运行会走 GitHub 的设备登录(浏览器里粘一次一次性码),然后自动建私有仓库、推 main。重复运行是安全的 —— 已有仓库和远端会被复用。
脚本优先用 PATH 上的 gh,找不到就用捆绑副本 ~/.workbuddy/binaries/gh/extracted/bin/gh。若都没有,就手动来:
# 先在网页上建好私有仓库(不要勾 README/.gitignore/license)
git remote add origin https://github.com/yiou362/dsh-demo-plugin.git
git push -u origin main
本机环境注意(pnpm 的布局选择)
结论:pnpm 能用,不需要开发者模式。 坑在布局(layout)上,dsh plugin add 不受影响。
这台机器确实建不出目录 symlink(fs.symlinkSync(t, l, 'dir') 和 'file' 都报 ENOENT,Windows 要开发者模式或管理员权限)。但 junction 和硬链接都正常 —— 于是关键在于 pnpm 用哪种布局:
| 布局 | 顶层包怎么挂 | 本机 |
|---|
isolated(pnpm 默认) | 目录 symlink | ❌ 建不出来。而且不报错:包全在 .pnpm/,顶层空着,.bin 不生成,prepare 里 tsc 报「不是内部或外部命令」 |
hoisted | junction + 硬链接 | ✅ 正常 |
DSH 的 profile 初始化时就写死了 hoisted,见 ~/.dsh/profiles/<name>/pnpm-workspace.yaml:
packages:
- .
nodeLinker: hoisted
autoInstallPeers: false
而 dsh plugin 只是个 pnpm 转发器(源码 apps/cli/src/plugin.ts),所以 dsh plugin --profile web add <包名> 开箱可用,装第三方插件不受 symlink 权限影响。
本项目自己也走 hoisted,配置在 .npmrc:
node-linker=hoisted
有了它 pnpm install 和 npm install 都通(npm 忽略这个键)。已验证:pnpm install → prepare → .bin 齐全 → lib/ + client/client.js 产出 → preflight ok。
顺带一个 dsh 的提示含义:warning: <pkg> declares no dsh.bundle 这条既表示「包没有声明 dsh.bundle」,也表示「包解析不到」(exportsPatch() 解析失败时按普通依赖处理)。看到它先确认包真的装上了,再怀疑声明。
目录
yale-demo-plugin/ # 仓库名 dsh-demo-plugin
├── package.json # dsh.bundle(贡献哪一层)+ dsh.client(浏览器半侧声明)
├── cordis.patch.yml # 本包贡献的 patch 层
├── .npmrc # node-linker=hoisted(见文末「本机环境注意」)
├── tsdown.config.ts # 浏览器 bundle:__ModuleLoader__ 闭包工厂产物
├── src/
│ ├── index.ts # Host 半侧(空操作)
│ └── client/
│ ├── index.ts # 注册 settings.section
│ ├── DemoSection.tsx
│ ├── DemoSection.module.css
│ └── locales.ts
└── scripts/preflight.mjs
lib/ 与 client/ 是构建产物(已被 .gitignore 忽略)。发布时由 prepare 现场生成。
三个要点
包名即入口名。 cordis.patch.yml 里的 name: 'yale-demo-plugin' 是包名而非相对路径,Node 的模块解析才能找到已安装的代码。
浏览器半侧靠声明被发现。 package.json 里的 dsh.client + exports["./client"] 一起,让 client 模块系统扫描已启用的 Loader entry 时能找到并加载这个 bundle —— 不用改 Web 应用、不用重新构建。
bundle 必须自己注册。 产物是一个 CJS 闭包工厂脚本,开头是 window.__ModuleLoader__.load({ id, factory }),require() 只认 loader 模块表里的条目(react 等由宿主提供,其余全部内联)。preflight.mjs 就是在守这条:丢了 banner 的 bundle 照样构建成功、照样 200,只在浏览器里运行时炸。
改点什么
换文案:改 src/client/locales.ts 的 zh / en 即可,demo-plugin 这个名字来自 nav 键。
加设置项控件:如果这一页要读写配置,Host 半侧需要用 ctx.settings.installSection() 注册一个命名空间,浏览器半侧改用 settings.plugin.item 卡片并绑定 ctx.settingsScope。参考 DSH 仓库 docs/cookbook/adding-a-settings-card.zh.md。
换位置:想放进已有的「插件」设置项里当标签页,把 slot 从 settings.section 换成 settings.plugins.tab。
License
MIT