Bundle
dsh-inject
Advanced model-context injection and request-only rewriting for DeepSeek Harness with native Keysmith rules compatibility. dsh-inject:为 DeepSeek Harness 提供高级上下文注入与请求侧消息重写,原生兼容 Keysmith 规则集。
- Source
- john-walks-slow
- License
- MIT
- Updated
- Updated 4 days ago
Readme
# dsh-inject
`dsh-inject` 是一个用于管理模型上下文的 DSH 插件:在模型请求前对指定角色的消息做关键词/正则替换,并按会话启用多个上下文预设;还可以在会话当前位置插入构造回合。

## 安装
```bash
npm install dsh-inject
```
把 `dsh-inject` 加入 profile 的 `dsh.profile.bundles`。
## 核心语义
- **只改请求,不改会话**:自动替换发生在发给模型的请求副本上;会话记录和界面显示的原始消息保持不变。
- **默认关闭**:任何会话一开始都没有启用预设。
- **会话级**:`/inject` 的启用状态只作用于当前会话。
- **零副作用**:启用状态是进程内状态,不写入会话日志;关掉预设等于从未启用。
- 会话级状态在进程重启后重置为默认关闭。
## 配置(设置页 → Inject)
设置页可以建立**任意多个预设**,每个预设包含两部分:
1. **自动替换**:多条规则,每条可选「关键词」或「正则」,填写替换文本,并勾选生效角色:用户 / 助手 / 工具返回。
2. **开头构造回合**:放进请求最前面的消息,角色可选 系统 / 助手 / 用户 / 工具。
另外可维护**构造回合模板**,供现场 dialog 与 `/inject-turn` 复用。
## 命令
```text
/inject 查看当前会话启用了哪些预设
/inject on <预设名...> 启用(可一次多个)
/inject off <预设名...> 关闭
/inject clear 关闭本会话全部预设
/inject-turn 打开「插入构造回合」窗口
/inject-turn <模板名> 把模板内容排进下一次请求
/inject-turn <JSON 数组> 现场构造,如 [{"role":"user","text":"..."}]
```
## 现场注入 dialog
在输入框输入 `/inject-turn` 回车即可打开(不需要点任何按钮):
- 现场增删消息与角色;
- 「载入模板…」载入已保存的模板;
- 填模板名后「保存为模板」写回配置;
- 「插入到当前位置」把内容排进**下一次模型请求**,不写入会话记录;
- `Esc` 关闭。
这是通过客户端命令装饰实现的:`/inject-turn` 的**裸调用**在客户端打开窗口,带参数时仍由宿主命令处理。
## Keysmith 兼容与默认包含项
`dsh-inject` 原生兼容并默认预置 **Keysmith**(Keysmith Switch / codex-keysmith)规则体系:
- **默认预设**:内置 `Keysmith: Unrestricted` 预设,包含其标志性的本地执行模式系统规约(`Local execution mode active`)及常用敏感词/边界词中性化替换规则;在未配置时作为默认包含项。
- **格式直接适配**:规则对象直接兼容 Keysmith 格式(`{ "from": "...", "to": "..." }`),自动映射为 `pattern`、`replacement` 并绑定至用户输入(`targets: ["user"]`)。
- **一键导入**:设置页提供「导入 Keysmith 规则」入口,支持一键批量解析粘贴的 Keysmith 规则包或规则数组。
- **安全保护机制**:对以 `/` 开头的斜杠命令以及 `<system-reminder>`、`<command-name>` 等系统注入标签自动跳过改写,避免误伤系统指令或命令参数。
## 已知限制
- 未在界面上标记被替换的片段(原文照旧显示)。
- `tool` 角色的构造消息会转成带「工具返回」标记的用户上下文,避免出现没有对应工具调用的悬空 tool result。
- 现场 dialog 依赖 `webServer` 与 `connection` 服务;缺失时命令的参数形式仍可用,但窗口内插入会失败。
- 会话级启用状态是进程内的:重启后回到默认关闭。
Install
dsh plugin --profile web add github:john-walks-slow/dsh-inject
Profile: web
With the hub plugin installed, ask your agent to install it by name — it resolves the same plan shown here.
dsh plugin --profile web add github:stvlynn/dsh.fish#path:packages/dsh-plugin-hub
install dsh-inject from the hub
- This package builds from source on install. pnpm will ask you to allow its build script — that is permission to run the package’s code on your machine, outside the agent sandbox. Only allow sources you trust.
- This source has no pinned commit, so a later push upstream changes what installs. Prefer pinning a commit.