dsh-prompt-snippets 1.3.1 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,86 @@
1
+ # Changelog
2
+
3
+ 本文件记录 `dsh-prompt-snippets` 每个发布版本的用户可见变更。格式遵循 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/)。
4
+
5
+ ## [1.4.1] - 2026-11-10
6
+
7
+ ### 修复
8
+
9
+ - 修复历史记录路径穿越:迁移会重建不安全 ID,读取与写入都会校验路径边界,历史文件采用原子写入。
10
+ - 限制面板导入和文件管理器打开仅访问 exports 目录,并拒绝通过符号链接逃逸;命令行导入仍支持用户指定路径。
11
+ - 限制普通与流式 AI 优化的输入长度;修正文件管理器启动失败时的成功状态。
12
+ - 拒绝 Windows 保留设备名作为导出文件名。
13
+ - 加入 host/client 占位符解析一致性回归测试,并让 ESLint 实际检查测试文件。
14
+ - 占位符表单会预选有效默认值;必填下拉框没有默认值时自动选择首项,且允许用户清空可选默认值。
15
+ - exports 目录内不存在的导入文件会返回文件读取错误,避免误报为路径越界。
16
+ - AI 流式优化检查 HTTP 状态;流式路由返回 404/405 时回退到 RPC 优化接口,其他 HTTP 错误显示明确状态。
17
+ - 补齐客户端提示的中英文 locale 文案。
18
+ - 修正中英文 README 的快捷键说明,并删除重复的操作说明。
19
+
20
+ ### 工程化
21
+
22
+ - 增加枚举默认值、流式回退及 HTTP 错误的回归测试;清理 ESLint 重复配置并同步 lockfile 版本。
23
+
24
+ ## [1.4.0] - 2026-11-06
25
+
26
+ ### 新增
27
+
28
+ - **AI 优化流式透传**:点击 ✨ 优化后,对比视图会实时显示模型逐段生成的内容,不再全程静止、最后一次性蹦出。底层从一次性的 RPC 调用改为走 `/api/prompt-snippets/optimize-stream` 流式接口(NDJSON),生成进度即时可见。
29
+ - **AI 优化提速(maxTokens 自适应)**:优化请求的 `maxTokens` 从固定 2000 改为按输入长度自适应(短输入 600 / 中等 900 / 长输入 1200 封顶),减少模型扩写冗长输出的倾向,明显加快生成。
30
+
31
+ ### 修复
32
+
33
+ - **片段库按钮位置**:按钮从输入框卡片下方的独立一行(`conversation.composer.dock`)改挂到输入框工具条(`conversation.input.right`,与权限控件、模型选择器同排),修复 Claude 样式等主题下按钮消失或孤行的问题(#5、#6)。
34
+ - **窄窗口按钮撑高**:工具条按钮加 `flex: none` + 文字不折行,窄窗口下不再被压缩折行撑高。
35
+ - **收藏置顶复选框字号**:显式声明字号,不再继承会话字体放大一号(#2)。
36
+
37
+ ### 工程化
38
+
39
+ - **i18n 接入平台 locale 服务**:client 端全部硬编码文案接入 DSH 官方 locale(`ctx.locale.register/bind/subscribe`),随平台语言切换。
40
+ - **ESLint 门禁**:新增 ESLint 8 配置与 `npm run lint`,并在 CI 中强制执行。
41
+ - **CI Windows 矩阵**:GitHub Actions 增加 `windows-latest` runner,覆盖目标用户主平台。
42
+ - **README 徽章与措辞**:补充 npm version / downloads / License 徽章,同步按钮位置描述。
43
+
44
+ ## [1.3.1] - 2026-11-04
45
+
46
+ ### 修复
47
+
48
+ - Gemini review 8 处问题修复。
49
+ - 命令面板快捷键、滚动跟随、插入并发送等细节修正。
50
+
51
+ ## [1.3.0] - 2026-11-03
52
+
53
+ ### 新增
54
+
55
+ - 标签 / 收藏 / 最近使用。
56
+ - 版本历史(每片段保留最近 20 版)。
57
+ - 命令面板(Ctrl+Shift+K)。
58
+ - 动态变量(date / time / datetime)。
59
+ - 内置模板包冷启动。
60
+ - README 功能示意图。
61
+
62
+ ## [1.2.0] - 2026-11-03
63
+
64
+ ### 新增
65
+
66
+ - AI 优化闭环(三态对比视图:原文 / 优化后 / 覆盖或插入)。
67
+ - 搜索增强。
68
+ - 导入导出。
69
+ - 数据可靠性补丁。
70
+ - 窗口缩放。
71
+
72
+ ## [1.1.0] - 2026-11-02
73
+
74
+ ### 新增
75
+
76
+ - 数据可靠性(原子写 / .bak 轮换 / 损坏自愈 / 旧版本迁移)。
77
+ - 面板内编辑。
78
+ - 占位符表单(必填 / 默认值 / 枚举下拉)。
79
+ - 主题适配(浅色 / 深色)。
80
+
81
+ ## [1.0.0] - 2026-10-27
82
+
83
+ ### 新增
84
+
85
+ - `/snippet` 命令(保存 / 列出 / 查看 / 删除 / 恢复 / 改名)。
86
+ - 侧栏一键插入。
package/README.md CHANGED
@@ -1,226 +1,118 @@
1
- # 提示词片段库(Prompt Snippets)
1
+ # Prompt Snippets for DSH
2
+
3
+ [简体中文](README.zh-CN.md)
2
4
 
3
- [![CI](https://github.com/dadazhangn/dsh-prompt-snippets/actions/workflows/ci.yml/badge.svg)](https://github.com/dadazhangn/dsh-prompt-snippets/actions/workflows/ci.yml)
5
+ [![CI](https://github.com/dadazhangn/dsh-prompt-snippets/actions/workflows/ci.yml/badge.svg)](https://github.com/dadazhangn/dsh-prompt-snippets/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/dsh-prompt-snippets)](https://www.npmjs.com/package/dsh-prompt-snippets) [![npm downloads](https://img.shields.io/npm/dm/dsh-prompt-snippets)](https://www.npmjs.com/package/dsh-prompt-snippets) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
6
 
5
- <p align="center">
6
- <img src="docs/feature-map.svg" alt="Prompt Snippets 占位符三态填充流程" width="800">
7
- </p>
7
+ **Stop retyping the prompts you use every day.** Save them once, fill in the changing details, and insert them into the DSH composer in a click. If it saves you time, [star the repository](https://github.com/dadazhangn/dsh-prompt-snippets) or share it with another DSH user.
8
8
 
9
- 保存并一键插入可复用的提示词片段,支持分类与 `{{占位符}}`。
9
+ Prompt Snippets is a local-first prompt library for [DeepSeek Harness (DSH)](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin). Organize reusable prompts with categories, tags, and favorites; use `{{placeholders}}` for project-specific details; and find the right snippet from a searchable panel or keyboard shortcut.
10
10
 
11
- 一个让「常用提示词」随手可得、不重复造轮子的 DSH 插件。片段数据保存在本机
12
- `<DSH_HOME>/data/prompt-snippets/snippets.json`。默认只存本机、不上传任何内容;
13
- **仅当你主动点击 ✨ AI 优化时,才会把当前那一条片段文本发送给你配置的模型服务**
14
- (用于生成优化建议),除此之外不与网络通信。
11
+ > **Your prompts stay on your device.** Snippets are stored in your local DSH data directory. Nothing is sent to a server unless you choose **AI Optimize**, which sends the selected snippet to the model service configured in DSH.
15
12
 
16
- ## 安装
13
+ ## See how it works
14
+
15
+ 1. Save a prompt such as `Review this code for {{language}} bugs: {{code}}`.
16
+ 2. Search your library and click the snippet you need.
17
+ 3. Fill in its variables; the completed prompt goes straight into the composer.
18
+
19
+ The panel supports browsing, editing, and organizing your snippets without leaving the conversation. For a quick lookup, press **Ctrl+Shift+K** and search from anywhere.
20
+
21
+ Use **↑/↓** to choose a snippet and **Enter** to open its placeholder form. In the form, **Tab / Shift+Tab** moves between fields, **Ctrl+Enter** inserts and sends, and **Esc** closes it. If a required field is empty, **Ctrl+Enter** focuses the first missing field instead.
22
+
23
+ ## Install
24
+
25
+ ### From the DSH plugin store
26
+
27
+ Find **Prompt Snippets** in the [awesome-dsh-plugin catalog](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin). The catalog entry points to this GitHub repository, so it installs the repository version.
28
+
29
+ ### With DSH
30
+
31
+ Install the published npm package:
17
32
 
18
33
  ```bash
19
34
  dsh plugin --profile web add dsh-prompt-snippets
20
35
  ```
21
36
 
22
- `web` 换成你实际使用的 profile 名即可(本机 profile 在 `~/.dsh/profiles/<名字>`)。
23
- 装完重启 DSH,刷新页面,输入框下方会出现「📋 片段库」按钮。
37
+ Replace `web` with the profile you use. After installation, restart DSH and reload the page. The **📋 Snippets** button appears in the composer toolbar.
24
38
 
25
- 也可以从 GitHub 装(版本由仓库 HEAD 决定,不跟随 npm 发布):
39
+ ### From GitHub
40
+
41
+ To install the latest repository code directly:
26
42
 
27
43
  ```bash
28
44
  dsh plugin --profile web add github:dadazhangn/dsh-prompt-snippets
29
45
  ```
30
46
 
31
- 本地源码调试用路径安装:
47
+ GitHub installs follow the repository; npm installs follow the published package version. For local development, install a checkout with `dsh plugin --profile web add link:C:/path/to/dsh-prompt-snippets`.
32
48
 
33
- ```bash
34
- dsh plugin --profile web add link:C:/path/to/dsh-prompt-snippets
35
- ```
49
+ **Requirements:** DSH `>=0.2.1-rc.3`.
36
50
 
37
- ### Install (English)
51
+ ## Try it
38
52
 
39
- ```bash
40
- dsh plugin --profile web add dsh-prompt-snippets
53
+ Create a reusable code-review prompt. `/snippet add` uses the first word as the name, so use a hyphen between words:
54
+
55
+ ```text
56
+ /snippet add Review-code Review this {{language}} code for bugs and security issues: {{code}} --cat=Development
41
57
  ```
42
58
 
43
- Or install straight from GitHub (`github:dadazhangn/dsh-prompt-snippets`), which
44
- tracks the repository HEAD instead of the published npm version. Then restart DSH
45
- and reload the page.
46
-
47
- ## 功能
48
-
49
- - **保存片段**:`/snippet add <名称> <内容>` 保存一段提示词(同名即更新)。
50
- - **分类**:用 `--cat=<分类>`(或 `-c=<分类>`)指定分类,例如
51
- `/snippet add 代码审查 请审查以下代码:{{代码}} --cat=开发`;面板按分类分组展示。
52
- **分类参数只认行尾**:正文中间的 `--cat` 会按字面保留,不会被当成参数吃掉。
53
- 想在正文结尾真的写 `--cat`,用 `--` 结束选项:`/snippet add 说明 结尾是 -- --cat`。
54
- 更新内容时不带 `--cat` 会保留原分类,不会被清空。
55
- - **列出 / 查看 / 删除 / 恢复 / 改名**:`/snippet list`、`/snippet show <名称>`、
56
- `/snippet rm <名称>`、`/snippet undo <名称>`、`/snippet mv <旧名> <新名>`。
57
- 重名时不会瞎删,会列出候选让你用 `#id前缀` 精确指定。
58
- - **一键插入**:输入框下方「📋 片段库」按钮展开面板,按分类浏览,点击片段即插入当前
59
- 草稿。插入失败(草稿在面板打开期间被改动、或输入框正在提交)会在面板内说明原因。
60
- - **面板内编辑 / 新建**:点 ✏️ 在原行下方展开编辑器,改名称、分类、正文,并直接维护
61
- 变量(必填勾选 + 默认值);面板底部「+ 新建」同样在面板内完成创建,全程不用敲命令。
62
- 保存走乐观锁:两个标签同时改同一条时,后保存者看到冲突横幅,可选「覆盖」或
63
- 「重新载入」服务器版本。草稿没保存时点面板外部不会关闭面板,取消也要二次确认。
64
- - **搜索**:按名称、分类、正文实时筛选,打开面板自动聚焦。命中词在名称里高亮标记,
65
- 右侧实时显示 `当前/总数` 命中计数;键盘 `↑` `↓` 移动选中、`Enter` 插入选中项、`Esc` 逐层退出。
66
- 无命中时给出「+ 新建『搜索词』」按钮,点一下把搜索词预填为新片段名。
67
- - **删除可撤销**:点 🗑 删除后底部出现撤销条,记住最近 5 条,可逐条恢复或一键全部撤销。
68
- - **AI 优化(对比后决定)**:点 ✨ 用当前默认模型改写片段,结果进「原文 / 优化后」双栏对比,
69
- 不直接插入、也不自动落盘。**优化后那一栏可直接编辑**——微调后再决定怎么用。对比视图里给出
70
- 字节数变化与占位符保全标记(丢了哪个 `{{x}}` 会点名,字节数随编辑实时重算),
71
- 按钮为「插入优化版」「替换片段正文」「再试」「保留原文插入」「✕」:
72
- - 「插入优化版」只进输入框,不动库里的片段;插入的是你编辑后的文本;
73
- - 「替换片段正文」是**唯一会落盘**的动作,带 `expectedRevision` 乐观锁;冲突时只提供
74
- 「用优化版覆盖(force)」与「放弃」,不做自动合并;
75
- - 优化结果超长或丢了占位符时「替换片段正文」禁用,`title` 写明原因;把超长部分删短后自动解除;
76
- - 「再试」最多 3 次,之后置灰;「取消」走 `AbortController`,host 回 `aborted` 时静默收起;
77
- - 当前未配置默认模型时 ✨ 直接置灰,`title` 说明原因,不会等到点击才报错。
78
- - **`{{占位符}}` 智能填充**:正文里写 `{{主题}}` 之类占位符,点击片段时:
79
- - 无占位符 → 直接插入;
80
- - 占位符全部非必填且都有默认值 → 按默认值直接插入,并提示「可在 ✏️ 里改」;
81
- - 有必填占位符(或旧数据缺变量元数据)→ 弹表单逐项填写,必填为空时「插入」禁用,
82
- 也可选「保留占位符插入」原样插入。
83
-
84
- `\{{字面量}}` 转义后插入的是字面 `{{字面量}}`;同名占位符只问一次,全实例填同一个值。
85
- - **动态变量**:`{{date}}` / `{{time}}` / `{{datetime}}` 是内置宏变量,插入时用本地时间实时
86
- 替换(`date` = `YYYY-MM-DD`、`time` = `HH:mm`、`datetime` = `YYYY-MM-DD HH:mm:ss`),
87
- 不弹表单、也不进变量元数据;正文里只有动态变量的片段点一下即可直插。
88
- - **内置模板包**:首次运行(数据文件尚不存在)自动预置一组高频片段(代码审查、Git 提交信息、
89
- Bug 排查、周报、日报、翻译润色、会议纪要、学习计划),给你一个冷启动起点。删掉后不重灌,
90
- 已有数据文件(哪怕清空成 0 条)也不会再注入。
91
- - **导入 / 导出**:`/snippet export [文件名]` 把全部片段导出成 JSON,落在
92
- `<DSH_HOME>/data/prompt-snippets/exports/` 下;`/snippet import <文件路径>` 导回来,
93
- `--replace` 用文件内容替换现有库(未出现在文件里的片段软删除,仍可 `/snippet undo`),
94
- `--dry` 只预演不写入。面板底部同样有「⬇ 导出」「⬆ 导入」两个按钮,导入填路径即可
95
- (面板拿不到宿主文件系统,路径由 host 侧读取;省略目录与 `.json` 后缀时回落到 `exports/`)。
96
- - **深浅色主题跟随**:面板全部使用 DSH 主题 token,浅色 / 深色自动适配,无白底刺眼。
97
- - **窄屏可用**:面板宽度取 `min(340px, 100vw - 16px)`,窗口缩到 320px 也不溢出,
98
- 并会在视口变化后自动拉回可视区。
99
- - **可拖动可记忆**:拖标题栏移动面板,位置记在浏览器本地,下次打开还在原处。
100
- - **可缩放可记忆**:面板四条边和四个角都能拖(像 Windows 窗口),拖边缘调宽高(最小 200×160),
101
- 松手后尺寸记在浏览器本地,下次打开沿用上次大小;缩到超出视口会自动收窄拉回。
102
- - **标签**:`/snippet tag <名称> <标签1、标签2…>` 给片段打标签(逗号/顿号/空格分隔,最多 32 个、
103
- 每个最长 24 字);`add`/`save` 也能用 `--tag=` 带上。面板里标签以圆角 chip 显示在名称后。
104
- - **收藏置顶**:`/snippet pin <名称>` 收藏、`/snippet unpin <名称>` 取消(`add` 也可 `--pin`)。
105
- 面板顶部有「全部 / ★ 收藏 / 最近使用」三个视图切换按钮,收藏视图只看置顶项,
106
- 最近使用按 `lastUsedAt` 降序、最多 20 条。
107
- - **版本历史**:每次保存前的旧内容自动留档(每片段最多 20 版、单片段历史体积超限丢最旧)。
108
- 面板里点 🕘 展开该片段的历史,可回看历次正文;`/snippet show` 也会显示 revision 号。
109
- - **命令面板(全局快捷唤起)**:任意时刻按 `Ctrl+Shift+K`(或 `Ctrl+Shift+P`)弹出片段搜索
110
- 浮层,输入关键字即时过滤(名称/分类/标签/正文),`↑` `↓` 选择、`Enter` 插入、`Esc` 关闭;
111
- 收藏片段自动置顶,无需先点开 dock 面板。选中后按 `Ctrl+Enter`(Mac `Cmd+Enter`)则是
112
- **插入并立即发送**;带必填占位符的片段仍需先填表单,无法直接发送。`↑` `↓` 切换选中项时
113
- 列表自动滚动跟随,始终把选中项保持在可视区内。
114
-
115
- ## 使用
59
+ Then click **📋 Snippets** beside the composer, choose **Review-code**, fill in `language` and `code`, and insert the finished prompt. You can also create and edit snippets directly in the panel, where names may contain spaces.
116
60
 
117
- ```
118
- /snippet add 代码审查 请审查以下代码并指出问题:{{代码}}
119
- /snippet add 周报 总结本周工作:{{要点}} --cat=写作
120
- /snippet list
121
- /snippet show 周报
122
- /snippet rm 代码审查
123
- /snippet undo 代码审查
124
- /snippet mv 周报 日报
125
- /snippet pin 周报
126
- /snippet tag 周报 工作、总结
127
- /snippet optimize 周报
128
- /snippet export 我的片段
129
- /snippet import 我的片段.json --dry
130
- /snippet import 我的片段.json
131
- ```
61
+ Useful commands:
132
62
 
133
- 然后在任意会话里,点击输入框下方的「📋 片段库」→ 点击片段名 → 内容插入草稿。
134
- 要改内容或改分类,不必再敲命令:面板里点 ✏️ 直接改,改完点「保存」。
135
-
136
- ## 数据
137
-
138
- - 文件:`<DSH_HOME>/data/prompt-snippets/snippets.json`(DSH_HOME 未设置时为 `~/.dsh`)。
139
- - 结构(`version: 4`):
140
- ```json
141
- {
142
- "version": 4,
143
- "snippets": [
144
- {
145
- "id": "uuid",
146
- "name": "名称",
147
- "category": "分类或 null",
148
- "content": "正文",
149
- "variables": { "变量名": { "label": "…", "default": "…", "options": ["…"], "required": false } },
150
- "tags": ["标签"],
151
- "pinned": false,
152
- "pinnedAt": null,
153
- "createdAt": 0,
154
- "updatedAt": 0,
155
- "deletedAt": null,
156
- "revision": 1,
157
- "useCount": 0,
158
- "lastUsedAt": null
159
- }
160
- ]
161
- }
162
- ```
163
- - **写入是原子的**:先写同目录临时文件 → `fsync` → 轮换 `.bak` → `rename` 覆盖。
164
- 进程中断不会留下半个 JSON,最坏情况是文件停在上一份完整内容。
165
- - **写入是串行的**:并发保存/删除排队执行,不会互相覆盖。
166
- - **每次都留 `.bak`**:`snippets.json.bak` 永远是上一次成功写入的完整 JSON,
167
- 手滑改坏也能逐字节恢复。
168
- - **备份轮换**:`.bak` 写新值前先逐级后移成 `.bak.1` / `.bak.2` … 最多保留 7 份,
169
- `.bak` 始终是最新一份,更早的历史可回查。
170
- - **损坏自愈**:文件不是合法 JSON 或结构不可识别时,会备份成
171
- `snippets.corrupt-<时间戳>.json`(最多保留 5 份),插件以空库继续运行并在面板顶部
172
- 提示,不会卡死;第二次读取不会再重复备份。
173
- - **旧版本自动迁移**:`version: 1` / `version: 2` / `version: 3` 的文件在首次读取时补齐
174
- `id` / `revision` / `variables` / `useCount` / `tags` / `pinned` 等字段并升级到 `version: 4`,
175
- 迁移写入前先把**原始字节**存成 `snippets.json.pre-v4.bak`(一次性,已存在则保留
176
- 更早的那份、不覆盖),原有片段与时间戳保持不变。迁移是幂等的:第二次读取不再写盘。
177
- - **保守处理异常数据**:无法识别的条目会被丢弃并给出 `warning` 计数;重复 `id`
178
- 会被修复;`revision` 非法值归一到 1。
179
- - **不认识的更新版本只读**:文件 `version` 大于插件支持的版本时只读跳过加载,
180
- 原文件一字不改,避免旧插件写坏新数据。
181
- - **删除是软删除**:`deletedAt` 非空即视为已删除,记录仍留在文件里,所以
182
- `/snippet undo` 能立刻恢复;确实不想要了可以直接编辑该文件清掉。
183
-
184
- ## 结构
185
-
186
- bundle 结构:host 半(`index.js`,命令 + RPC + JSON 存储)、client 半(`client.js`,
187
- 输入框 dock 面板 UI)。
63
+ | Command | What it does |
64
+ |---|---|
65
+ | `/snippet list` | List saved snippets |
66
+ | `/snippet add <name> <content>` | Create or update a snippet |
67
+ | `/snippet show <name>` | View a snippet and its revision |
68
+ | `/snippet pin <name-or-id>` | Pin a favorite to the top |
69
+ | `/snippet tag <name-or-id> <tags>` | Add searchable tags |
70
+ | `/snippet optimize <name>` | Open an AI-assisted rewrite for review |
71
+ | `/snippet export [file]` | Export snippets to JSON |
72
+ | `/snippet import <file>` | Import snippets from JSON |
188
73
 
189
- ```
190
- index.js host 半:/snippet 命令 + /prompt-snippets RPC + JSON 持久化
191
- client.js client 半:conversation.composer.dock 面板
192
- package.json bundle 声明(dsh.bundle.patch + dsh.client + engines.dsh)
193
- cordis.patch.yml 插入 host 半的 loader patch
194
- locale/{en,zh}.json 市场显示名与描述
195
- icon.svg 图标
196
- LICENSE MIT
197
- test/ 测试套件(随仓库分发,不进 npm 包)
198
- .github/workflows GitHub Actions 自动验证
199
- ```
74
+ Commands that treat the remaining input as a name accept spaces. `/snippet add` and `/snippet tag` use the first word as the name; use a hyphen or underscore for multiword names in those commands, or create them in the panel. If a name collides, commands report candidates so you can select the intended snippet.
200
75
 
201
- ## 兼容性
76
+ ## Why use it?
202
77
 
203
- 要求 DSH `>=0.2.1-rc.3`(`package.json` 的 `engines.dsh`)。市场在安装前会按这条
204
- 检查宿主版本,不满足时禁用「安装」按钮并说明原因。
78
+ - **Get to the prompt quickly.** Search by name, category, tag, or content. Use the floating library or the global keyboard palette; favorites appear first.
79
+ - **Reuse a template without editing it every time.** Add `{{variables}}` and fill them in when inserting. Optional defaults, required fields, dropdown choices, and `{{date}}`, `{{time}}`, and `{{datetime}}` are supported.
80
+ - **Keep useful prompts organized.** Add categories and tags, pin favorites, sort by recent use, and revisit earlier versions.
81
+ - **Stay in control of AI rewrites.** Compare the original with the generated draft, edit the draft, then choose whether to insert it or replace the saved snippet. Rewrites never overwrite a snippet automatically.
82
+ - **Keep your library portable.** Import and export JSON backups. Data is stored locally, with atomic writes and recoverable backups.
205
83
 
84
+ ## AI Optimize
206
85
 
207
- ## 测试
86
+ AI Optimize is optional and uses the default model configured in DSH. It streams a proposed rewrite into a comparison view; the original stays intact until you choose an action.
208
87
 
209
- 仓库 `test/` 目录里有一组自测脚本(随仓库分发,不进 npm 包),当前覆盖 **466 条断言**:
88
+ - **Insert optimized** puts the reviewed draft into the composer and leaves the library unchanged.
89
+ - **Replace snippet content** saves the reviewed draft. The action is disabled if the result is incomplete, over the size limit, or missing an original placeholder.
90
+ - **Retry** requests a fresh rewrite. You can edit the generated draft before using it.
210
91
 
211
- | 套件 | 覆盖 |
212
- |---|---|
213
- | `v110-host-test.mjs` | 迁移矩阵与迁移前备份、存储可靠性、双轨匹配、占位符扫描、`--cat` 收口、能力握手、只读保护、标签/收藏/版本历史、首次预置模板包(177) |
214
- | `optimize-test.mjs` | 优化流的分支与降级(14) |
215
- | `io-test.mjs` | 导入/导出命令:落盘、文件名安全、后缀回退、merge/replace/dry、往返一致、同名去重、大小限制、一键打开(78) |
216
- | `client-test.mjs` | 渲染、搜索高亮、命中计数、键盘导航、插入、占位符表单、行内编辑、冲突处理、多条撤销、优化三态对比(含优化后编辑)、导入导出按钮、使用统计 touch、主题 token、窄屏、窗口缩放、标签/收藏/视图切换/版本历史、命令面板、动态变量(191) |
217
- | `client-error-test.mjs` | 插入失败的报错链路(6) |
92
+ The selected snippet is sent to your configured model service only when you start this action. Other library operations do not send snippet content to an external service.
93
+
94
+ ## Data and recovery
95
+
96
+ The library is stored at `<DSH_HOME>/data/prompt-snippets/snippets.json`. If `DSH_HOME` is unset, DSH uses `~/.dsh`.
218
97
 
219
- 测试通过 `isolate-home.mjs` 把 `DSH_HOME` 顶到系统临时目录,**绝不读写真实片段库**。
98
+ Writes use a temporary file and atomic replacement. Previous data is retained in rotating `.bak` files; malformed data is preserved as a recovery copy. Deletion is reversible, and each snippet keeps up to 20 prior versions. Import supports merge, replace, and dry-run modes.
220
99
 
221
- 每次 push、发 tag(`v*`)、提 PR 时,GitHub Actions 会自动跑「语法检查 + 这 5 个套件」(见
222
- `.github/workflows/ci.yml`),任何一步失败都会在 PR 上打红叉阻止合并。本地运行:
100
+ ## Contributing
101
+
102
+ Bug reports, feature ideas, and pull requests are welcome. Please include your DSH version and steps to reproduce when reporting a problem.
103
+
104
+ Run the checks locally:
223
105
 
224
106
  ```bash
107
+ npm ci
225
108
  npm test
109
+ npm run lint
226
110
  ```
111
+
112
+ The test suite uses a temporary `DSH_HOME`; it does not read or modify your real snippet library.
113
+
114
+ If Prompt Snippets saves you time, [star the repository](https://github.com/dadazhangn/dsh-prompt-snippets) or share it with another DSH user.
115
+
116
+ ## License
117
+
118
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,116 @@
1
+ # DSH 提示词片段库
2
+
3
+ [English](README.md)
4
+
5
+ **别再反复重写常用提示词。** 保存一次,填写每次不同的信息,然后一键插入 DSH 输入框。
6
+
7
+ Prompt Snippets 是为 [DeepSeek Harness(DSH)](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin) 提供的本地提示词库。你可以用分类、标签和收藏整理提示词,用 `{{占位符}}` 填入项目相关内容,也可以从可搜索面板或快捷键快速找到片段。
8
+
9
+ > **提示词保存在本机。** 片段存放在 DSH 本地数据目录。只有你主动使用「AI 优化」时,所选片段才会发送给 DSH 配置的模型服务。
10
+
11
+ ## 三步开始
12
+
13
+ 1. 保存提示词,例如:`审查这段 {{语言}} 代码中的错误:{{代码}}`。
14
+ 2. 搜索并点击需要的片段。
15
+ 3. 填写变量,完整提示词就会插入输入框。
16
+
17
+ 面板可以直接浏览、编辑和整理片段,不用离开当前对话。也可以随时按 **Ctrl+Shift+K** 打开快捷搜索。
18
+
19
+ 按 **↑/↓** 选择片段,按 **Enter** 打开占位符表单;在表单中按 **Tab / Shift+Tab** 切换字段,按 **Ctrl+Enter** 插入并发送,按 **Esc** 关闭。必填项未填写时,按 **Ctrl+Enter** 会聚焦到第一个待填写项。
20
+
21
+ ## 安装
22
+
23
+ ### 从 DSH 插件商店安装
24
+
25
+ 在 [awesome-dsh-plugin 插件目录](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin) 搜索 **Prompt Snippets**。商店条目指向 GitHub 仓库,安装的是仓库版本。
26
+
27
+ ### 使用 DSH 安装
28
+
29
+ 从 npm 安装已发布版本:
30
+
31
+ ```bash
32
+ dsh plugin --profile web add dsh-prompt-snippets
33
+ ```
34
+
35
+ 将 `web` 换成你使用的 profile。安装后重启 DSH 并刷新页面,输入框工具栏中会出现 **📋 片段库** 按钮。
36
+
37
+ ### 从 GitHub 安装
38
+
39
+ 直接安装仓库中的最新代码:
40
+
41
+ ```bash
42
+ dsh plugin --profile web add github:dadazhangn/dsh-prompt-snippets
43
+ ```
44
+
45
+ GitHub 安装跟随仓库版本;npm 安装跟随已发布的 npm 版本。本地开发时可以用 `dsh plugin --profile web add link:C:/path/to/dsh-prompt-snippets` 安装本地检出目录。
46
+
47
+ **环境要求:** DSH `>=0.2.1-rc.3`。
48
+
49
+ ## 快速试用
50
+
51
+ 创建一个代码审查提示词。`/snippet add` 会把第一个词作为名称,多词名称请用连字符连接:
52
+
53
+ ```text
54
+ /snippet add 代码审查-安全 审查这段 {{语言}} 代码中的错误和安全问题:{{代码}} --cat=开发
55
+ ```
56
+
57
+ 然后点击输入框旁边的 **📋 片段库**,选择「代码审查-安全」,填写 `语言` 和 `代码`,完整内容就会插入输入框。也可以直接在面板中新建或编辑片段;面板创建支持带空格的名称。
58
+
59
+ 常用命令:
60
+
61
+ | 命令 | 用途 |
62
+ |---|---|
63
+ | `/snippet list` | 列出已保存的片段 |
64
+ | `/snippet add <名称> <内容>` | 新建或更新片段 |
65
+ | `/snippet show <名称>` | 查看片段和版本号 |
66
+ | `/snippet pin <名称或 ID>` | 收藏并置顶 |
67
+ | `/snippet tag <名称或 ID> <标签>` | 添加可搜索标签 |
68
+ | `/snippet optimize <名称>` | 生成可检查的 AI 改写稿 |
69
+ | `/snippet export [文件名]` | 导出为 JSON |
70
+ | `/snippet import <文件>` | 从 JSON 导入 |
71
+
72
+ 将剩余输入作为名称的命令支持带空格名称。`/snippet add` 和 `/snippet tag` 会把第一个词作为名称;命令行操作时请用单词、连字符或下划线。也可以在面板里创建带空格的名称。名称冲突时命令会列出候选项供你选择。
73
+
74
+ ## 它能帮你做什么
75
+
76
+ - **更快找到提示词。** 按名称、分类、标签或正文搜索;使用片段库面板或全局快捷面板;收藏项优先显示。
77
+ - **用模板填入变化内容。** 使用 `{{变量}}`,插入时填写内容;支持默认值、必填项、下拉选项,以及 `{{date}}`、`{{time}}`、`{{datetime}}`。
78
+ - **整理并复用好用的提示词。** 添加分类和标签、收藏置顶、按最近使用排序,并查看旧版本。
79
+ - **由你决定是否采用 AI 改写。** 查看原文和改写稿、编辑结果,再选择插入或替换保存内容;不会自动覆盖原文。
80
+ - **备份和迁移自己的片段库。** 支持 JSON 导入导出;数据在本机保存,并带原子写入与备份恢复。
81
+
82
+ ## AI 优化
83
+
84
+ 「AI 优化」是可选功能,使用 DSH 中配置的默认模型。模型逐步生成的改写内容会显示在对比视图中;在你选择操作前,原片段保持不变。
85
+
86
+ - **插入优化版**:将检查后的文本插入输入框,不修改片段库。
87
+ - **替换片段正文**:保存检查后的文本。如果结果不完整、超过长度限制或丢失原有占位符,此操作会被禁用。
88
+ - **再试**:重新生成一份改写稿;生成后仍可编辑再决定如何使用。
89
+
90
+ 只有你主动开始优化时,所选片段才会发送到配置的模型服务。其他片段库操作不会把正文发送到外部服务。
91
+
92
+ ## 数据与恢复
93
+
94
+ 片段库存放在 `<DSH_HOME>/data/prompt-snippets/snippets.json`。未设置 `DSH_HOME` 时使用 `~/.dsh`。
95
+
96
+ 写入通过临时文件和原子替换完成,并轮换保留 `.bak` 备份;损坏的数据会另存恢复副本。删除可以撤销,每条片段最多保留 20 个旧版本。导入支持合并、替换和预演模式。
97
+
98
+ ## 参与项目
99
+
100
+ 欢迎提交问题反馈、功能建议和 Pull Request。反馈问题时请附上 DSH 版本和复现步骤。
101
+
102
+ 本地运行检查:
103
+
104
+ ```bash
105
+ npm ci
106
+ npm test
107
+ npm run lint
108
+ ```
109
+
110
+ 测试使用临时 `DSH_HOME`,不会读取或修改你的真实片段库。
111
+
112
+ 如果 Prompt Snippets 帮你节省了时间,欢迎[给仓库点个 Star](https://github.com/dadazhangn/dsh-prompt-snippets),或推荐给其他 DSH 用户。
113
+
114
+ ## 许可
115
+
116
+ MIT,详见 [LICENSE](LICENSE)。