dsh-prompt-enhance 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # dsh-prompt-enhance
2
+
3
+ DeepSeek Harness(DSH)Web GUI 的「提示词增强」插件:把输入框里的草稿一键改写为结构化提示词——补全背景与约束、明确目标与角色、拆分可执行步骤、指定输出格式与验收标准、补充边界条件;**不改变原意、不凭空编造需求**。增强前后并排对比,一键回填 / 复制 / 撤销。
4
+
5
+ 仿照 WorkBuddy 的提示词增强体验,基于 DSH 的 Cordis 插件体系实现,单包双半区:
6
+
7
+ - **宿主半区**(`exports "."`):`prompt-enhance` 设置节(schemastery,自动渲染于 设置 → 插件配置)、`POST /prompt-enhance/enhance` 路由(经 `ctx.llm` 调模型,回环安全栅栏)、`/enhance <文本>` 斜杠命令。
8
+ - **浏览器半区**(`exports "./client"`):输入框工具栏增强按钮(`conversation.input.right`)、增强前后对比预览面板、撤销条(`conversation.input.dock`)、可配置全局快捷键。
9
+
10
+ ## 触发方式
11
+
12
+ | 入口 | 行为 |
13
+ |---|---|
14
+ | 输入框工具栏 ✨ 按钮(发送键左侧) | 读取草稿 → 调用宿主增强 → 弹出对比面板 |
15
+ | 快捷键(默认 `Ctrl+Alt+E`,可配置) | 作用于焦点所在的输入框;避免浏览器保留组合 |
16
+ | `/enhance <文本>` 斜杠命令 | 增强命令参数文本,结果在命令面板展示可复制,不进入对话历史 |
17
+
18
+ 面板内:**回填到输入框**(保留原文供撤销)/ **复制结果** / **取消**(Esc 或点击遮罩)。回填后输入框上方出现「✓ 已用增强结果替换原提示词 [撤销]」提示条,一键恢复原文;继续输入会自动撤销撤销条,不会用过期文本覆盖新编辑。原文始终保留,任何失败都不改动草稿。
19
+
20
+ ## 模型路由(按优先级)
21
+
22
+ 1. 插件设置中成对填写的 `provider` + `model`;
23
+ 2. 当前会话已记录的请求路由(跟随会话模型);
24
+ 3. 全局默认模型(`agent-default-model` 设置)。
25
+
26
+ 三者皆无时明确报错并指引导配置,不做静默兜底。凭据与传输完全复用 harness 的 LLM 服务,无需在插件内再配 API Key。
27
+
28
+ ## 配置(设置 → 插件配置 → prompt-enhance)
29
+
30
+ | 字段 | 默认 | 说明 |
31
+ |---|---|---|
32
+ | `enabled` | `true` | 总开关;关闭隐藏按钮并停用所有触发 |
33
+ | `provider` / `model` | 空 | 成对覆盖模型路由;留空跟随当前会话 |
34
+ | `temperature` | `0.3` | 低温改写更忠实原意 |
35
+ | `maxOutputTokens` | `2048` | 单次输出上限 |
36
+ | `maxInputChars` | `12000` | 输入字数上限;**超限拒绝而不截断**(避免改变原意) |
37
+ | `timeoutMs` | `60000` | 单次超时(毫秒) |
38
+ | `systemPrompt` | 内置策略 | 留空用内置增强策略;可整体替换 |
39
+ | `shortcut` | `ctrl+alt+e` | 快捷键(如 `ctrl+shift+p`);留空禁用 |
40
+
41
+ 配置热生效:每次增强调用前重读设置,改完保存即作用于下一次调用。
42
+
43
+ ## 异常与边界
44
+
45
+ - **空输入 / 仅空白 / 零宽字符**:本地拦截,提示「输入框为空」。
46
+ - **超长输入**:本地 + 宿主双重校验,拒绝并给出字数,不截断。
47
+ - **仅图片无文本**:提示仅支持文本。
48
+ - **含命令 / 文件引用 chip**(如 `/compact`、`@file`):回填会破坏 chip,拒绝并提示先移除。
49
+ - **提交中 / 请求在途**:防重入,提示稍候;面板加载中可取消(请求随之中止)。
50
+ - **上游失败**:按稳定错误码映射为可读中文(AUTH → 鉴权失败、RATE_LIMIT → 限流、QUOTA_EXCEEDED → 配额不足、CONTEXT_WINDOW_EXCEEDED → 超上下文等),附「原输入未改动」。
51
+ - **模型返回空 / 包裹代码围栏 / 请求工具调用**:规范化与校验兜底(剥围栏、拒绝空结果),错误可直接重试。
52
+ - **浏览器中途关闭 / 切换会话**:宿主路由侦测连接断开即中止模型调用;面板与撤销栈按会话隔离,随会话清理。
53
+ - 所有失败只出现在插件自己的面板中,输入框草稿永不被动丢失,可继续手动输入。
54
+
55
+ ## 安装
56
+
57
+ ```bash
58
+ cd dsh-prompt-enhance
59
+ npm install
60
+ npm run build # tsc 类型检查 + esbuild 产出 lib/index.js(ESM)与 lib/client.js(ModuleLoader 包裹)
61
+ dsh plugin --profile web add link:C:\path\to\dsh-prompt-enhance
62
+ # 重启 dsh web
63
+ ```
64
+
65
+ 从 GitHub 安装(lib 已随仓库提交,无需本地构建):
66
+
67
+ ```bash
68
+ dsh plugin --profile web add github:rongxingda/dsh-prompt-enhance
69
+ # 重启 dsh web
70
+ ```
71
+
72
+ 卸载:`dsh plugin --profile web remove dsh-prompt-enhance`(并检查 profile package.json 的 `dsh.profile.bundles` 数组是否残留该行,残留则手动删除)。
73
+
74
+ 要求:`dsh >= 0.1.1-rc.1`,Node `^22.19 || >=24`。
75
+
76
+ ## 发布新版本(维护者)
77
+
78
+ 1. `npm version <patch|minor|major>` 更新版本号并打 tag;
79
+ 2. `npm run build` 确保 `lib/` 与源码一致,与版本提交一起推送;
80
+ 3. 推送 tag(`git push --follow-tags`),在 GitHub Releases 上发布说明。
81
+
82
+ `lib/` 是刻意提交的:GitHub 直装(`dsh plugin add github:...`)不会执行构建,提交产物让安装零构建依赖。CI 会在 `lib/` 与源码不一致时拒绝合并。
83
+
84
+ ## 开发
85
+
86
+ ```bash
87
+ npm run typecheck # tsc --noEmit
88
+ npm test # vitest(48 个单测:校验/规范化/增强调用/撤销栈/快捷键/配置/客户端设置)
89
+ npm run watch # esbuild 监听构建双半区
90
+ ```
91
+
92
+ 结构:
93
+
94
+ ```
95
+ src/
96
+ ├── index.ts 宿主 apply:设置节 + 路由 + 命令
97
+ ├── config.ts schemastery 模式 + 解析校验(成对路由)
98
+ ├── prompts.ts 内置增强策略系统提示词 + <raw_prompt> 框架
99
+ ├── enhancer.ts ctx.llm 辅助调用(路由解析/超时竞速/finish 校验)
100
+ ├── enhance-routes.ts POST /prompt-enhance/enhance(回环栅栏/限长/错误码)
101
+ ├── enhance-command.ts /enhance 斜杠命令
102
+ ├── shared/ 两端共用:协议类型、输入校验、输出规范化
103
+ └── client/
104
+ ├── index.tsx 浏览器 apply:插槽注册 + 设置镜像 + 快捷键
105
+ ├── EnhanceButton input.right 按钮 + 守卫链 + 调用编排
106
+ ├── ResultPanel 对比预览面板(回填/复制/取消/重试)
107
+ ├── UndoBar input.dock 撤销条
108
+ ├── ui-state 跨组件面板/撤销/会话注册表(外部 store)
109
+ └── … fetch 客户端、undo-stack、shortcut、locales、styles
110
+ ```
111
+
112
+ ## 验收清单(实机 `dsh web`)
113
+
114
+ - [ ] 中文输入「帮我写个爬虫」→ 增强 → 面板对比,回填后草稿为结构化中文提示词,撤销恢复原文
115
+ - [ ] 英文输入返回英文(语言一致性)
116
+ - [ ] 空输入 / 超长输入 / 含 `/命令` chip / 提交中,均被拦截且草稿不变
117
+ - [ ] 面板加载中点取消:草稿不变,可继续输入
118
+ - [ ] 拔掉 API Key 或断网:错误消息可读,重试可用
119
+ - [ ] 设置改 `shortcut` / `maxInputChars` / `enabled` 后无需重启即生效
120
+ - [ ] `/enhance 帮我写周报` 结果在命令面板展示且未发送给会话模型
@@ -0,0 +1,14 @@
1
+ # dsh-prompt-enhance bundle patch: inserts the prompt-enhance plugin row
2
+ # into the web profile roster. Applied as a profile bundle layer (the
3
+ # `dsh.bundle.patch` manifest field); install with
4
+ # `dsh plugin --profile web add link:<repo>/dsh-prompt-enhance`.
5
+ #
6
+ # One package, both halves: the node half (exports ".") runs in the host
7
+ # process and registers the POST /prompt-enhance/enhance route, the
8
+ # /enhance slash command, and the "prompt-enhance" settings section; the
9
+ # browser half (declared by `dsh.client`, served from lib/client.js) adds
10
+ # the composer enhance button (conversation.input.right), the preview
11
+ # panel, and the undo bar (conversation.input.dock).
12
+ - insert:
13
+ - id: prompt-enhance
14
+ name: dsh-prompt-enhance