Back to home

zuoguyoupan2023

openharness-rule-for-dsh-plugin

DSH plugin that injects a system-prompt rule block for DeepSeek Harness plugin development (CAN/SHOULD/MUST NOT)

Stars
0
Language
TypeScript
Created
Aug 14, 2026
Updated
Aug 14, 2026

Introduction

openharness-rule-for-dsh-plugin

一个 DeepSeek Harness(dsh)插件:往系统提示词注入「DSH 插件开发规范」——四类规则: 能做什么(CAN)/ 应该做什么(SHOULD)/ 不能做什么(MUST NOT)/ 不应该做什么(SHOULD NOT)。 并在 dsh 设置页侧边栏显示「插件开发规范」一项。

  • 纯 dsh plugin(bundle),装在 web profile 即可生效;
  • host 半:ctx.systemPrompt.section({ name, order: 46, text }) 注入规范(真实逻辑);
  • client 半:注册 settings.section 槽,显示侧边栏项(与 openharness-reply-in-cn / adhdgofly-dsh-ext 完全同构)。

注入逻辑(host half,src/host/index.ts

export const inject = ['systemPrompt']              // 申报依赖,否则 boot 崩
export const name = 'openharness-rule-for-dsh-plugin'
export function apply(ctx, config) {
  if (config?.enabled === false) return             // 可通过 patch 关闭
  const disposer = ctx.systemPrompt.section({
    name: 'openharness:rule-for-dsh-plugin',
    order: 46,                                      // persona(0) 之后、工具引导(100+)之前
    text: (context) => (context.agent === undefined ? '' : <规范正文>),
  })
  return () => disposer?.()   // apply 返回 disposer,卸载时清理
}
  • order:46比「中文回复」的 45 略低(46 排在 45 之后),不影响对方。
  • 规则正文本体是一个字符串数组 ruleText,含 CAN / SHOULD / MUST NOT / SHOULD NOT 四段。
  • 只有真实 agent 装配(context.agent 存在)才渲染,不污染非 agent 的 assemble 调用。

遵循程度:这是软约束。注入一定发生(官方装配按 order 拼接、当前 profile 无 complete 段覆盖),但「模型是否严格遵守」无法 100% 保证——靠 order 靠前 + 措辞「最高优先级」尽量稳住。

验证注入是否生效:在对话框直接问「系统提示里有没有『DSH 插件开发规范:能做什么/不能做什么』这条」——模型能复述即注入成功。


侧边栏项(client half,src/client/index.ts

slots.inject('settings.section', () => slots.register(
  { name: 'settings.section', id: 'openharness-rule-for-dsh-plugin', order: 20, label: () => '插件开发规范' },
  Section,
))
  • settings.sectionlist 槽:多个插件同时注册不冲突、都会显示(与 中文回复/ADHDGoFly/OpenHarness Reader 并列)。
  • openharness-reply-in-cn 的 client 结构完全一致,只是 id/label 不同。

⚠️ 必读:为什么代码对了却不显示(缓存/进程坑,2026-08 真实教训)

这是调试中最隐蔽的坑之一(安装任何 DSH client 插件后漏看新项的最常见原因)。现象:两个 client bundle 结构完全一致、都进了 boot 图、rev 也更新了,但新加的侧边栏项就是看不到。

根因

  • Tauri 壳(OpenHarness)的「重启 DSH」按钮只杀后端 node 进程并重新 spawn,不会重建前端 webview、不让页面重新加载
  • dsh 的 client bundle 按 rev(内容哈希)缓存在 webview 内存里;后端重启、rev 变后,webview 仍用旧的,拿不到新插件/新 bundle。
  • 所以反复按「重启DSH」看不到新插件项——不是代码问题,是 webview 没刷新

正确做法

  1. 改 client / 加新 client 插件后,不要只按「重启DSH」。
  2. 彻底退出 OpenHarness(⌘Q)再重开,或手动刷新/重载 dsh 页面——让 webview 重新请求 client.js?rev=<新>
  3. 判断「代码问题 vs 缓存问题」:lib/client.js 结构是否与已验证的一致 + boot 图是否引用它 + rev 是否更新 → 三者都对却看不到 → 先彻底重启 webview 再看

安装

# 当前依赖目录(开发):
dsh plugin --profile web add ./openharness-rule-for-dsh-plugin
# 或发布后按名装:
dsh plugin --profile web add openharness-rule-for-dsh-plugin

装完彻底退出 app 重开(见上文缓存坑)。


依赖与构建

pnpm install   # 生成 node_modules(含 esbuild / typescript)
pnpm build     # 产出 lib/index.js(host)+ lib/client.js(client)

package.json

  • dsh.bundle.patch: ./cordis.patch.yml(插入插件行)
  • dsh.client.platform: "web"(声明 client 半)
  • exports["./client"] → lib/client.js(浏览器 bundle)
  • main → lib/index.js(host)

文件结构

openharness-rule-for-dsh-plugin/
├── src/host/index.ts      # 注入「插件开发规范」system-prompt section(order 46)
├── src/client/index.ts    # 注册 settings.section 侧边栏项「插件开发规范」
├── build.mjs              # esbuild 双半打包
├── package.json           # dsh bundle + client 声明 + exports
├── cordis.patch.yml       # 插入插件行
└── tsconfig.json

我开发的 DSH 插件

我(zuoguyoupan2023)开发维护的一系列 DeepSeek Harness(dsh)插件,均可按需通过 dsh plugin --profile web add <name> 安装:

插件作用GitHub 仓库安装
adhdgofly-dsh-extDSH Web 界面词性高亮(名绿/动红/形紫/其他灰)zuoguyoupan2023/adhdgofly-dsh-extdsh plugin --profile web add adhdgofly-dsh-ext
openharness-reader工作区文件浏览/编辑 + Markdown 预览zuoguyoupan2023/openharness-readerdsh plugin --profile web add openharness-reader
openharness-reply-in-cn强制模型用简体中文回复,侧边栏「中文回复」项zuoguyoupan2023/openharness-reply-in-cndsh plugin --profile web add openharness-reply-in-cn
openharness-rule-for-dsh-plugin注入 DSH 插件开发的 CAN/SHOULD/MUST NOT 规范,侧边栏「插件开发规范」项zuoguyoupan2023/openharness-rule-for-dsh-plugindsh plugin --profile web add openharness-rule-for-dsh-plugin