dshplugin.devDeepSeek Harness Plugins
DSH Keyword Context plugin logo
DeepSeek Harness Plugin

DSH Keyword Context

0
Published by QQQW114

DeepSeek Harness (DSH) plugin - inject context when user input or model output hits configured keywords, with toggleable/configurable rules and model-editable memory.

Modelsdsh-plugin

Get this plugin

Review the source, then continue to the publisher.

Get this plugin
Share on X ↗

About this plugin

Source snapshot 8/17/2026

dsh-keyword-context

当用户输入或模型输出命中配置的关键词时,向模型注入上下文。可开关、可配置,并可选择允许模型读写记忆。

功能

  • 命中注入:监听用户输入(agent/inbox/inserted)与模型输出(session/eventassistant/message),命中任一触发词即激活对应规则,把配置的上下文注入到后续模型上下文。
  • 可开关:设置页「启用上下文注入」总开关,关闭后立即停止注入并清空命中状态。
  • 可配置:触发规则(关键词 ↔ 注入文本)、记忆条目(key/value)均可在设置页增删改,持久化到 config.json
  • 模型可读写记忆:开启「允许模型读写」后,注册 memory_get / memory_set 两个工具,并在注入上下文中附上工具用法说明。

安装

dsh plugin --profile web add dsh-keyword-context

然后确认 ~/.dsh/profiles/web/cordis.patch.yml 里挂载了 host 半区:

- insert:
    - id: keyword-context
      name: dsh-keyword-context

重启 dsh web,浏览器 Ctrl+F5 强刷。

结构

dsh-keyword-context/
├── package.json        # dsh.client.platform: "web" + exports ./client
├── config.json         # 持久化配置(enabled / allowModelWrite / triggers / memories)
└── lib/
    ├── index.js        # 宿主半区:注入上下文 + 检测 + memory_get/memory_set 工具 + HTTP 接口
    └── client.js       # 浏览器半区:设置页「上下文注入」

配置(config.json)

{
  "enabled": true,
  "allowModelWrite": false,
  "triggers": [
    { "id": "t1", "keywords": ["记忆", "memory"], "context": "用户提到了「记忆」相关话题,请结合上方【记忆】中的内容作答。" }
  ],
  "memories": [
    { "key": "用户偏好", "value": "使用简体中文回答" }
  ]
}

原理

  • host 半区通过 ctx.systemPrompt.context() 注册动态上下文(每次组装时求值),命中触发规则后返回注入文本,否则返回空串(不贡献内容)。
  • 记忆条目始终注入(开关开启时);模型读写开关打开后,注入文本追加工具用法说明,并动态注册 memory_get / memory_set 工具。
  • 配置读写走 webServer/keyword-context/* JSON 接口,客户端设置页用 fetch 读写。