@surfishs/dsh-prompt-enhance 0.0.0-stage → 0.0.2

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.
Files changed (64) hide show
  1. package/LICENSE +201 -0
  2. package/README.en.md +114 -0
  3. package/README.md +113 -2
  4. package/cordis.patch.yml +15 -0
  5. package/docs/code-review-2026-09.md +211 -0
  6. package/docs/handoff-settings-page.md +195 -0
  7. package/docs/release-0.2.3.md +47 -0
  8. package/docs/release-0.2.4.md +20 -0
  9. package/docs/release-0.2.5.md +28 -0
  10. package/docs/release-0.2.6.md +33 -0
  11. package/docs/release-0.2.7.md +22 -0
  12. package/docs/release-0.3.0.md +36 -0
  13. package/docs/release-0.3.1.md +50 -0
  14. package/docs/release-0.3.2.md +41 -0
  15. package/docs/release-0.3.3.md +53 -0
  16. package/docs/release-0.3.4.md +43 -0
  17. package/lib/client.js +2591 -0
  18. package/lib/index.js +1634 -0
  19. package/lib/index.js.map +7 -0
  20. package/locale/en.json +6 -0
  21. package/locale/zh.json +6 -0
  22. package/package.json +112 -4
  23. package/src/catalog-route.ts +63 -0
  24. package/src/client/EnhanceButton.tsx +214 -0
  25. package/src/client/ResultPanel.tsx +324 -0
  26. package/src/client/UndoBar.tsx +58 -0
  27. package/src/client/enhance-client.ts +289 -0
  28. package/src/client/globals.d.ts +13 -0
  29. package/src/client/index.tsx +178 -0
  30. package/src/client/llm-catalog.ts +191 -0
  31. package/src/client/locales.ts +287 -0
  32. package/src/client/primitives.d.ts +73 -0
  33. package/src/client/reasoning-options.ts +76 -0
  34. package/src/client/session-key.ts +69 -0
  35. package/src/client/settings-page.tsx +1339 -0
  36. package/src/client/settings-source.ts +269 -0
  37. package/src/client/settings.ts +79 -0
  38. package/src/client/shortcut.ts +95 -0
  39. package/src/client/styles.ts +216 -0
  40. package/src/client/ui-state.ts +273 -0
  41. package/src/client/undo-stack.ts +81 -0
  42. package/src/config.ts +260 -0
  43. package/src/context.ts +192 -0
  44. package/src/enhance-command.ts +68 -0
  45. package/src/enhance-routes.ts +388 -0
  46. package/src/enhancer.ts +479 -0
  47. package/src/http.ts +62 -0
  48. package/src/index.ts +88 -0
  49. package/src/loopback.ts +102 -0
  50. package/src/orchestrate.ts +318 -0
  51. package/src/prompts.ts +105 -0
  52. package/src/provider-catalog.ts +127 -0
  53. package/src/reasoning-cache.ts +153 -0
  54. package/src/reasoning-efforts.ts +124 -0
  55. package/src/reasoning-route.ts +56 -0
  56. package/src/settings-source.ts +221 -0
  57. package/src/shared/catalog.ts +54 -0
  58. package/src/shared/defaults.ts +34 -0
  59. package/src/shared/normalize.ts +32 -0
  60. package/src/shared/protocol.ts +148 -0
  61. package/src/shared/reasoning.ts +75 -0
  62. package/src/shared/stream-text.ts +115 -0
  63. package/src/shared/validate.ts +102 -0
  64. package/src/sse.ts +90 -0
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.en.md ADDED
@@ -0,0 +1,114 @@
1
+ # dsh-prompt-enhance
2
+
3
+ [![CI](https://github.com/surfishs/dsh-prompt-enhance/actions/workflows/ci.yml/badge.svg)](https://github.com/surfishs/dsh-prompt-enhance/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/@surfishs/dsh-prompt-enhance.svg)](https://www.npmjs.com/package/@surfishs/dsh-prompt-enhance)
5
+ [![license](https://img.shields.io/badge/license-Apache--2.0-blue)](./LICENSE)
6
+
7
+ **Prompt enhancement for the DeepSeek Harness web GUI** — turn a composer draft into a structured prompt (role and goal, executable steps, output format, acceptance criteria, edge cases) in one click. The original draft is preserved, and a failure never touches it.
8
+
9
+ [简体中文](./README.md) | English
10
+
11
+ ---
12
+
13
+ ## Features
14
+
15
+ - **One-click enhance**: the ✨ button beside send; the shortcut is off by default and can be set in the settings.
16
+ - **Side-by-side preview**: original and result together, with model and timing; apply, copy, or cancel.
17
+ - **One-click undo**: an undo bar appears under the composer after applying.
18
+ - **`/enhance <text>`**: rewrite any text from the slash menu; the result never enters model history.
19
+ - **Model routing**: pinned settings pair → current session model → harness default, in that order.
20
+ - **Context aware**: uses recent conversation to resolve references; can be turned off.
21
+ - **Live settings**: changes apply to the next call, no restart.
22
+
23
+ ## Requirements
24
+
25
+ | | |
26
+ |---|---|
27
+ | dsh | `>= 0.1.1-rc.2 < 0.3.0` |
28
+ | Node (source builds only) | `^22.19.0 \|\| >=24.0.0` |
29
+ | Plugin | `0.0.x` |
30
+
31
+ ## Install
32
+
33
+ From npm:
34
+
35
+ ```bash
36
+ dsh plugin --profile <profile> add @surfishs/dsh-prompt-enhance
37
+ # restart dsh
38
+ ```
39
+
40
+ From GitHub (the built `lib/` is committed, so no local build happens):
41
+
42
+ ```bash
43
+ dsh plugin --profile <profile> add github:surfishs/dsh-prompt-enhance
44
+ ```
45
+
46
+ Replace `<profile>` with your profile name: usually `desktop` for the desktop app and `web` for the web build.
47
+
48
+ From a local checkout (development):
49
+
50
+ ```bash
51
+ git clone https://github.com/surfishs/dsh-prompt-enhance.git
52
+ cd dsh-prompt-enhance && npm install && npm run build
53
+ dsh plugin --profile <profile> add link:C:\path\to\dsh-prompt-enhance
54
+ ```
55
+
56
+ Uninstall:
57
+
58
+ ```bash
59
+ dsh plugin --profile <profile> remove @surfishs/dsh-prompt-enhance
60
+ ```
61
+
62
+ ## Usage
63
+
64
+ Leave a draft in the composer, then click ✨ (or your configured shortcut). Empty, over-length, images-only, and command/reference drafts are rejected locally (over-length is never truncated). A valid draft opens the preview; Apply writes it back and raises the undo bar, Copy puts it on the clipboard, `Esc` cancels, and a poor result can be retried.
65
+
66
+ `/enhance <text>` rewrites any text from the slash menu; the result is copyable and never enters model history.
67
+
68
+ ## Configuration
69
+
70
+ Edit in **Settings → dsh-prompt-enhance** (or Plugins → `dsh-prompt-enhance` → **Configure**). All fields:
71
+
72
+ | Field | Default | Notes |
73
+ |---|---|---|
74
+ | `enabled` | `true` | Master switch; off hides the composer button and disables the command and shortcut |
75
+ | `provider` + `model` | empty | Pick from the DSH-registered LLM providers and their models; the model can switch to “Custom…” to type an id; unconfigured providers are greyed out until set up in DSH model services; empty follows the session model (none). With only one filled, the save falls back to follow-session |
76
+ | `temperature` | `0.3` | Sampling temperature `0~1` (step 0.05); lower stays closer to the original |
77
+ | `reasoningEffort` | `off` | Tiers come from what the configured provider/model declares (DeepSeek: `off` / `low` / `high` / `max`). A route that declares no tiers omits the field (follows the provider default); `inherit` means the field is not sent |
78
+ | `maxOutputTokens` | `8192` | Output token cap per call |
79
+ | `maxInputChars` | `12000` | Input character cap; over-limit is rejected, never truncated |
80
+ | `timeoutMs` | `60000` | End-to-end timeout per call (ms) |
81
+ | `systemPrompt` | empty | Custom system prompt; empty uses the built-in strategy |
82
+ | `strategyMode` | `replace-default` | `replace-default` replaces the built-in strategy (the minimal output contract still applies); `extend-default` appends the custom strategy after the built-in one |
83
+ | `shortcut` | empty (disabled) | Trigger shortcut; e.g. `ctrl+alt+shift+e`. Needs at least one of ctrl/alt/meta; shift is optional |
84
+ | `streaming` | `true` | Show the result as it is written; display only, the final result is unchanged |
85
+ | `contextAware` | `true` | Read recent conversation to resolve references; turn it off for sensitive sessions |
86
+ | `contextMaxMessages` | `8` | Number of recent messages considered; `0` disables |
87
+ | `contextMaxChars` | `4000` | Character budget of the history snippet; `0` disables |
88
+ | `maxConcurrent` | `2` | Concurrent enhancement limit; a new request past the limit is told to retry later |
89
+ | `rateLimitPerMinute` | `10` | Successful enhancements per minute (sliding window); past the limit the request is told to retry later |
90
+
91
+ ## Security
92
+
93
+ The enhance route is served by your own local dsh host and accepts loopback addresses with a local `Host` / `Origin` only. With `contextAware` on, recent conversation history is sent with the draft to the configured model provider — do not send context from sensitive sessions.
94
+
95
+ ## Troubleshooting
96
+
97
+ - No button: make sure `enabled` is `true` and `dsh web` was restarted after installing.
98
+ - "No model resolved for the enhancement": set `provider` / `model` as a pair, or send a message in the current session first.
99
+ - Authentication failed: check the provider's API key in the harness.
100
+
101
+ ## Development
102
+
103
+ ```bash
104
+ npm install
105
+ npm run typecheck
106
+ npm test
107
+ npm run build
108
+ ```
109
+
110
+ See [CONTRIBUTING.md](./CONTRIBUTING.md).
111
+
112
+ ## License
113
+
114
+ Apache-2.0 (see [LICENSE](./LICENSE)). The code and design build on [rongxingda/dsh-prompt-enhance](https://github.com/rongxingda/dsh-prompt-enhance) (Apache-2.0).
package/README.md CHANGED
@@ -1,3 +1,114 @@
1
- # Temporary Holding Version
1
+ # dsh-prompt-enhance
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/surfishs/dsh-prompt-enhance/actions/workflows/ci.yml/badge.svg)](https://github.com/surfishs/dsh-prompt-enhance/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/@surfishs/dsh-prompt-enhance.svg)](https://www.npmjs.com/package/@surfishs/dsh-prompt-enhance)
5
+ [![license](https://img.shields.io/badge/license-Apache--2.0-blue)](./LICENSE)
6
+
7
+ **DeepSeek Harness Web GUI 的「提示词增强」插件** —— 一键把输入框草稿改写为结构化提示词(角色与目标、可执行步骤、输出格式、验收标准、边界条件)。原文保留,失败不改草稿。
8
+
9
+ 简体中文 | [English](./README.en.md)
10
+
11
+ ---
12
+
13
+ ## 功能
14
+
15
+ - **一键增强**:发送键旁的 ✨ 按钮;快捷键默认关闭,可在设置中自行指定。
16
+ - **对比预览**:原文与结果并排,附模型与耗时;可回填、复制或取消。
17
+ - **一键撤销**:回填后输入框上方出现撤销条。
18
+ - **`/enhance <文本>`**:从斜杠面板改写任意文本,结果不进入模型历史。
19
+ - **模型路由**:设置成对覆盖 → 当前会话模型 → 全局默认模型,逐级回退。
20
+ - **上下文感知**:参考当前会话近况消解指代;可关闭。
21
+ - **配置热生效**:改完即用于下一次调用,无需重启。
22
+
23
+ ## 环境要求
24
+
25
+ | | |
26
+ |---|---|
27
+ | dsh | `>= 0.1.1-rc.2 < 0.3.0` |
28
+ | Node(仅源码构建) | `^22.19.0 \|\| >=24.0.0` |
29
+ | 插件 | `0.0.x` |
30
+
31
+ ## 安装
32
+
33
+ 从 npm 安装:
34
+
35
+ ```bash
36
+ dsh plugin --profile <profile> add @surfishs/dsh-prompt-enhance
37
+ # 重启 dsh
38
+ ```
39
+
40
+ 从 GitHub 安装(`lib/` 已随仓库提交,无需本地构建):
41
+
42
+ ```bash
43
+ dsh plugin --profile <profile> add github:surfishs/dsh-prompt-enhance
44
+ ```
45
+
46
+ `<profile>` 换成你的 profile 名:桌面版通常是 `desktop`,Web 版通常是 `web`。
47
+
48
+ 从本地检出(开发用):
49
+
50
+ ```bash
51
+ git clone https://github.com/surfishs/dsh-prompt-enhance.git
52
+ cd dsh-prompt-enhance && npm install && npm run build
53
+ dsh plugin --profile <profile> add link:C:\path\to\dsh-prompt-enhance
54
+ ```
55
+
56
+ 卸载:
57
+
58
+ ```bash
59
+ dsh plugin --profile <profile> remove @surfishs/dsh-prompt-enhance
60
+ ```
61
+
62
+ ## 使用
63
+
64
+ 在输入框留下草稿,点 ✨(或你设置的快捷键)。空草稿、超长草稿、仅图片、含命令或引用块的草稿会被本地拒绝(超长不截断);通过后打开预览,回填写回输入框并升起撤销条,复制进剪贴板,`Esc` 取消。结果不满意可重试。
65
+
66
+ `/enhance <文本>` 从斜杠面板改写任意文本,结果可复制,不进入模型历史。
67
+
68
+ ## 配置
69
+
70
+ 在 **设置 → 提示词增强**(或 插件面板 → `dsh-prompt-enhance` → **配置**)编辑。全部字段:
71
+
72
+ | 字段 | 默认 | 说明 |
73
+ |---|---|---|
74
+ | `enabled` | `true` | 总开关;关闭后隐藏输入框按钮,并停用命令与快捷键 |
75
+ | `provider` + `model` | 空 | 从 DSH 已注册的 LLM provider 及模型中选择;模型可选「自定义…」手填 ID;未配置的 provider 置灰、需先在 DSH 模型服务中配置;留空表示跟随当前会话模型(不指定)。只填一个时保存后按跟随会话处理 |
76
+ | `temperature` | `0.3` | 采样温度 `0~1`(步进 0.05),越低越忠实原文 |
77
+ | `reasoningEffort` | `off` | 档位由当前 provider/model 的声明决定;DeepSeek 为 `off` / `low` / `high` / `max`。未声明档位的路由会自动省略该字段(即跟随提供方默认);`inherit` 表示不传该字段 |
78
+ | `maxOutputTokens` | `8192` | 单次调用的输出 token 上限 |
79
+ | `maxInputChars` | `12000` | 输入字符上限;超限拒绝,不截断 |
80
+ | `timeoutMs` | `60000` | 单次调用端到端超时(毫秒) |
81
+ | `systemPrompt` | 空 | 自定义系统提示词;留空使用内置增强策略 |
82
+ | `strategyMode` | `replace-default` | `replace-default` 整体替换内置策略(仍保留最小输出契约);`extend-default` 把自定义策略追加在内置策略之后 |
83
+ | `shortcut` | 空(禁用) | 触发快捷键;例 `ctrl+alt+shift+e`。须包含 ctrl/alt/meta 中至少一个修饰键,shift 可选 |
84
+ | `streaming` | `true` | 边写边显示;仅影响显示节奏,最终结果不变 |
85
+ | `contextAware` | `true` | 读取最近对话以消解指代;含敏感内容的会话建议关闭 |
86
+ | `contextMaxMessages` | `8` | 参考的最近消息条数;`0` 表示不参考 |
87
+ | `contextMaxChars` | `4000` | 历史片段的字符预算;`0` 表示不参考 |
88
+ | `maxConcurrent` | `2` | 同时进行的增强上限;达到上限时新请求会提示稍后再试 |
89
+ | `rateLimitPerMinute` | `10` | 每分钟增强次数上限(滑动窗口);超限时提示稍后再试 |
90
+
91
+ ## 安全
92
+
93
+ 增强路由只由本机 dsh 宿主提供,仅接受回环地址与本地 `Host` / `Origin`。`contextAware` 开启时,会话历史会随草稿发给当前配置的模型服务商——不要把敏感会话的上下文外发。
94
+
95
+ ## 故障排查
96
+
97
+ - 按钮不出现:确认 `enabled` 为 `true`,且安装后重启了 `dsh web`。
98
+ - 「尚未确定增强用的模型」:成对填写 `provider` / `model`,或先在当前会话发一条消息。
99
+ - 鉴权失败:检查对应 provider 在 harness 中的 API Key。
100
+
101
+ ## 开发
102
+
103
+ ```bash
104
+ npm install
105
+ npm run typecheck
106
+ npm test
107
+ npm run build
108
+ ```
109
+
110
+ 详见 [CONTRIBUTING.md](./CONTRIBUTING.md)。
111
+
112
+ ## 许可证
113
+
114
+ Apache-2.0(见 [LICENSE](./LICENSE))。代码与设计建立在 [rongxingda/dsh-prompt-enhance](https://github.com/rongxingda/dsh-prompt-enhance)(Apache-2.0)之上。
@@ -0,0 +1,15 @@
1
+ # dsh-prompt-enhance bundle patch: inserts the dsh-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:<path-to-checkout>`.
5
+ #
6
+ # One package, both halves: the node half (exports ".") runs in the host
7
+ # process and registers the POST /dsh-prompt-enhance/enhance route and the
8
+ # /enhance slash command, and declares the "dsh-prompt-enhance" settings schema
9
+ # this entry's config page renders (read live, per request); the
10
+ # browser half (declared by `dsh.client`, served from lib/client.js) adds
11
+ # the composer enhance button (conversation.input.right), the preview
12
+ # panel, and the undo bar (conversation.input.dock).
13
+ - insert:
14
+ - id: dsh-prompt-enhance
15
+ name: "@surfishs/dsh-prompt-enhance"
@@ -0,0 +1,211 @@
1
+ # dsh-prompt-enhance 代码审阅报告
2
+
3
+ 审阅对象:`dsh-prompt-enhance@0.2.2`(单包双半的 DSH Web GUI 提示词增强插件)
4
+ 审阅方式:全量静态阅读 + 依赖契约逐项比对 + 真实 `tsc`/`vitest`/`esbuild` 验证 + **GUI 实机冒烟**
5
+ 最终状态:typecheck 通过、**20 文件 / 207 用例全绿**、`lib/` 产物与 `src/` 一致、**插件在真实 `dsh web` 中加载并可用**
6
+
7
+ ---
8
+
9
+ ## 一、功能定位
10
+
11
+ 在 dsh Web GUI 的作曲区提供一个「增强」入口:把草稿经 harness 自带 LLM 服务低温重写为结构化提示词,预览原文/结果后回填、复制或撤销。
12
+
13
+ **硬约束(修复过程中一律未改动)**
14
+
15
+ - 原文永不被动修改:只有显式「回填」才会改动作曲区,且可一键撤销。
16
+ - 结果永远是规范化正文(去代码围栏、trim),超长输入**拒绝而非截断**。
17
+ - 流式仅为显示:最终应用内容始终来自 `normalizeOutput` 的完整结果。
18
+ - 上下文感知失败即 fail-open 回退到单条增强,绝不因读不到历史而失败。
19
+
20
+ **模型路由优先级**:设置里的 provider/model 对 → 会话请求头路由 → harness 默认模型。
21
+
22
+ ---
23
+
24
+ ## 二、目录结构与入口
25
+
26
+ ```
27
+ src/
28
+ index.ts 宿主入口:name/inject、跨代设置分区装配、装配 route+command
29
+ config.ts schemastery schema、DEFAULT_CONFIG、resolveConfig
30
+ enhance-routes.ts 两个 POST 端点:准入闸门、限流/并发、SSE 与 JSON
31
+ enhance-command.ts /enhance 斜杠命令
32
+ orchestrate.ts 两条入口共用的路由解析 + 上下文装配
33
+ enhancer.ts 一次 LLM 调用:超时竞速、BlockAssembler、finish 校验、错误映射
34
+ context.ts 会话历史 → 有界、去框架化的 <conversation_context> 片段
35
+ prompts.ts 内置增强策略 + 上下文规则 + <raw_prompt> 框架化
36
+ loopback.ts socket + Host + Origin 三重信任围栏(防 DNS rebinding)
37
+ http.ts readBoundedJson / writeJson
38
+ sse.ts 带背压的 SSE 帧写入器(本次新增)
39
+ shared/ protocol / validate / normalize / stream-text(两端共用)
40
+ client/
41
+ index.tsx 词典注册、设置镜像、两个 slot 注册、快捷键
42
+ EnhanceButton.tsx 守卫链 + fetch + 面板 + 回填/undo
43
+ ResultPanel.tsx 预览面板(loading/stream/result/error、焦点陷阱、复制兜底)
44
+ UndoBar.tsx 撤销条
45
+ enhance-client.ts 同源 fetch + SSE 读取 + 类型化错误
46
+ settings.ts 客户端设置镜像(不 import host config)
47
+ shortcut.ts 快捷键解析/匹配(event.code 优先,布局无关)
48
+ ui-state.ts 面板/undo/session 注册表 + 微任务合并 delta
49
+ session-key.ts sessionId 兼容 shim(0.1.1-rc ↔ 0.1.2-rc)
50
+ undo-stack.ts 按会话的深度受限 undo 栈
51
+ locales.ts 中英文字典
52
+ styles.ts 自注入样式
53
+ ```
54
+
55
+ - **宿主半**:`exports["."]` → `lib/index.js`(ESM,包引用保持 external)
56
+ - **浏览器半**:`dsh.client` → `lib/client.js`(CJS,包进 `window.__ModuleLoader__.load`)
57
+ - **bundle patch**:`cordis.patch.yml` 把插件行插入 web profile 名单
58
+
59
+ ---
60
+
61
+ ## 三、发现的问题与处置
62
+
63
+ ### P0-1 `error.upstream.<reason>` 键名错配(8 个原因中 5 个失效)
64
+
65
+ 线上 `reason` 是 kebab-case,字典键是 camelCase,用 `` `error.upstream.${reason}` `` 拼键导致 `invalid-credential`/`rate-limit`/`context-window`/`tool-call`/`max-tokens` 全部落空,永远退化成通用文案——而对应词条其实早已写好。
66
+
67
+ **处置**:改为显式映射表 `UPSTREAM_ERROR_KEYS`(`PromptEnhanceKey` 字面量校验),并补两层回归测试(键集一致性 + 真实面板逐 reason 渲染 + 负例)。
68
+
69
+ ### P0-2 `npm run typecheck` 在 CI 第一步即断
70
+
71
+ `tests/client-components.test.tsx` 导入了未公开的 `InputState`(该类型刻意不从包根与 `./client` 转出),导致 `tsc` 报错;CI 顺序为 typecheck → test → build,因此后续从未执行。
72
+
73
+ **处置**:测试改为本地字面量类型。过程中曾尝试用 `Parameters<>` 从 slot props 反推,核实后发现 `SnapshotSelectorHook<T>` 在 selector 上对 `T` 泛型、会擦除状态类型,该写法不可编译,故弃用并在注释中说明原因。
74
+
75
+ ### P0-3 运行时依赖声明不完整
76
+
77
+ - `lib/client.js` 实际 `require("react")`/`require("react-dom")`/`require("react/jsx-runtime")`,但只声明了 `react`。
78
+ - `lib/index.js` 静态 `import "@deepseek-ai/dsh-llm"`,却只写在 devDependencies。
79
+
80
+ **处置**:`peerDependencies` 补 `react-dom`、`@deepseek-ai/dsh-llm`;`dsh.client.inject` 补 `react-dom`。
81
+
82
+ ### P1-1 SSE 响应从不结束(隐藏最深的真缺陷)
83
+
84
+ 流式路由写完 `done` 帧后从不调用 `res.end()`,chunked 响应永远缺 `0\r\n\r\n`:
85
+
86
+ - 浏览器里"看起来正常"——客户端在 `done` 帧上 `return` 并 `reader.cancel()`,掩盖了它;
87
+ - 但**每次流式增强都泄漏一个未收尾的响应**,keep-alive 无法复用连接;
88
+ - 任何整 body 读取者(`response.text()`、curl、反向代理、访问日志中间件)**永久挂起**。
89
+
90
+ **处置**:路由在 `done` 帧后调用 `res.end()`(带 `writableEnded`/`destroyed` 守卫与 try/catch,避免客户端中途断开时抛出覆盖真实结果)。既有测试从未覆盖 SSE 端点,是它长期潜伏的原因;本次补了 SSE 端到端用例,并用裸 socket 字节打印取得铁证(修复前末尾无 `0\r\n\r\n`,修复后有,且 `response.text()` 从永久挂起变为 `200 / 236 bytes`)。
91
+
92
+ ### P1-2 SSE 帧写入无背压
93
+
94
+ 忽略 `res.write()` 返回的 `false`,慢客户端可让 socket 缓冲无界增长。
95
+
96
+ **处置**:新增 `src/sse.ts`——帧在缓冲区满时停靠至 `drain`,`close` 释放停靠,`dispose()` 释放监听;配 10 条单测。
97
+
98
+ ### P0-4 浏览器半硬声明可选服务,导致整个 Web 启动失败(本次审阅引入的回归)
99
+
100
+ 我把 `settingsScope` 写进了客户端半的 `inject`。cordis 的契约是"`inject` 里列了谁,就等于没有它就不加载"(`Plugin.Base.inject`:*Services the plugin requires; it only loads while all are available*),而该服务由可选的设置面板包 `@deepseek-ai/dsh-client-ui-settings` 提供——目标 profile 的 bundles 名单里没有它。结果插件永久 `pending`,shell 把"有 entry 没激活"当作致命错误,**整个 GUI 白屏**,报错为 `web boot: 1 entry did not activate`。
101
+
102
+ **处置**:改为**不硬依赖任何服务**——`slots`/`locale`/`settingsScope` 全部走可选的 `ctx.inject`,`apply` 本体不直接触碰任何服务;缺服务时降级(无设置面板则用内置默认值,无 locale 则渲染字典键)。配 `tests/client-apply.test.ts`(4 条)锁定"裸环境也必须能启动"。
103
+
104
+ ### P0-5 渲染期脆性读取使插槽条目被错误边界卸载(既有缺陷)
105
+
106
+ `EnhanceButton` 直接读 `state.imageIds.length` / `state.occurrences.length`。这两个字段在插件编写时所依据的 dsh 版本里属于输入快照,但 slot 宿主不保证提供;字段缺失时 `.length` 在**渲染期**抛错,React 错误边界据此卸载整个 `conversation.input.right` 条目——表现为按钮消失 + 控制台狂刷同一条堆栈(实测 `slot entry crashed in 'conversation.input.right'`),功能彻底不可用。
107
+
108
+ **处置**:新增 `countOf` / `stringOf` 防御式读取:字段缺失或类型畸形一律降级为"无此计数 / 空串",代价仅是两条**提示性**守卫(仅图片、含命令块)不触发,增强本身照常。同时给 `UndoBar` 的 `draft` 读取加同样防护(避免把 `undefined` 误判为"用户继续输入"而静默丢弃撤销记录)。配一条回归用例:宿主只提供 `{ draft, phase }` 时按钮必须照常渲染。
109
+
110
+ ### P1-3 其他
111
+
112
+ - `context.ts` 用 UTF-16 单元而非码点计上下文预算(中文/emoji 场景预算偏差约 2 倍),截断还可能劈开代理对 → 改用共享 `countText` 并按码点截断。
113
+ - `resolveConfig` 可原样返回 `provider: ''`,让下游把空串读成"存在覆盖" → 归一为 `undefined`。
114
+ - 跨会话 busy 用 `disabled` 静默禁用按钮,键盘/读屏用户连原因都读不到 → 改 `aria-disabled` + 可读原因文案。
115
+ - `abort()` 回调抛错会阻断面板状态迁移 → 统一用 `abortOf()` 包裹。
116
+ - `ResultPanel` 焦点还原挂在第二个 mount-only effect 上,StrictMode 下会立刻把焦点吐回按钮、使焦点陷阱与 Esc 失效 → 合并进同一 effect 并加"不抢用户已移动的焦点"守卫。
117
+ - `openError` 冗余同时传 `message` 与 `localized` → 只留 `localized`。
118
+ - CI `node-version: 22` 不满足 `engines: ^22.19.0` → 改为 `'22.19'`。
119
+ - `files` 未包含 README 引用的 `docs/` 截图 → 补入;加 `prepublishOnly` 与 `publishConfig.access`。
120
+
121
+ ---
122
+
123
+ ## 四、验证证据
124
+
125
+ | 检查 | 结果 |
126
+ |---|---|
127
+ | `npm run typecheck` | 通过,无错误 |
128
+ | `npm test` | **20 文件 / 207 用例全绿** |
129
+ | `npm run build` | 通过;`lib/index.js` 与 `lib/client.js` 均含最新逻辑 |
130
+ | `git status`(build 后) | 无产物漂移,符合 CI 的 lib 一致性校验 |
131
+ | SSE 协议 | 裸 socket 确认 `0\r\n\r\n` 终止符存在;`response.text()` 正常返回 |
132
+ | 安装形态 | `dsh plugin --profile web add link:C:\prompt-enhance-fresh`,插件行显示为 `link:` |
133
+ | **GUI 实机** | **插件在真实 `dsh web` 中加载成功、按钮渲染、增强流程可用** |
134
+
135
+ **审阅过程中被证伪的两处自身判断(记录以示校准)**
136
+
137
+ 1. 我曾判定「`README.md`/`README.zh-CN.md` 不存在、需补写」——错,两份都存在(305/304 行),是目录列举被输出截断误导;最终未改写,只补了 `docs/` 并同步架构树。
138
+ 2. 我曾推测 `tests/client-components.test.tsx` 导出的 `sessionId` 是类型错误——错,`dsh-client-runtime` 通过声明合并提供了它(`SessionIdentity` 非可选);真正的类型错误只有 `InputState` 一处。
139
+
140
+ **另一条被实践证的教训**:207 个自动化用例全绿,而插件在真实宿主里一加载就崩(P0-5)。差别在于"宿主不提供某些字段"这种**跨版本形状差异**,只有真正装进宿主才暴露得出来——因此新增的两组用例(`tests/client-apply.test.ts` 的裸环境启动、`tests/client-components.test.tsx` 的缺字段渲染)都把"宿主比预期更贫瘠"当作一等公民来锁定。
141
+
142
+ ---
143
+
144
+ ## 五、GUI 冒烟结果
145
+
146
+ 已在真实 `dsh web` 中完成基础冒烟:插件加载、作曲区按钮渲染、增强流程可用。
147
+
148
+ 仍建议按需逐条确认的细项(均已有自动化覆盖,此处仅列人工回归点):
149
+
150
+ 1. Settings → 插件配置出现 `prompt-enhance` 分区(目标 profile 未打包设置面板时,此项**预期不出现**,功能自动使用内置默认值)。
151
+ 2. ✨ 按钮与 `Ctrl+Alt+E` 走同一流程;空输入/超长/含引用块各自给出可读拒绝文案。
152
+ 3. 预览面板:回填 → 撤销条出现 → 撤销恢复原文;复制可用(含非安全上下文回退)。
153
+ 4. 流式增强:文字边写边显示,结束后面板**平滑切到规范化结果**(`display.finish()` 冲刷确保末尾字符不丢)。
154
+ 5. `/enhance <文本>` 在命令面板可复制、不进入模型历史。
155
+ 6. 多会话布局:另一会话增强中时,本会话按钮给出"另一个会话正在增强中"提示而非静默变灰。
156
+ 7. 上游错误(如错误 API Key)能否显示**具体**修复提示(对应 P0-1 的修复面)。
157
+
158
+ ---
159
+
160
+ ## 六、安装形态提醒
161
+
162
+ 当前 profile 通过 `link:` 指向本仓库,**宿主半改动必须重启 `dsh web`**;且 profile 的 `package.json` 里若残留 `^0.2.x` 语义版本声明,任何一次 `npm install` 都可能把 `link:` 覆盖回 npm 上的版本,从而静默丢掉本地修复。
163
+
164
+ ---
165
+
166
+ ## 七、发布记录(本次交付闭环)
167
+
168
+ 审阅修复经多轮提交交付,并已发布到 npm 与 GitHub。
169
+
170
+ ### 版本演进
171
+
172
+ | 版本 | 内容 | 状态 |
173
+ |---|---|---|
174
+ | `0.2.1` / `0.2.2` | 审阅前已发布(**不含本次任何修复**) | 已被 0.2.4 取代 |
175
+ | `0.2.3` | 四个缺陷修复(locale 映射、SSE 未结束、启动崩溃、渲染崩溃)+ 打包面补全 | 已发布,GitHub **Latest** |
176
+ | `0.2.4` | 仅打包修正:`@deepseek-ai/dsh-llm` 改为可满足范围的 optional peer | 已发布,npm **latest** / GitHub **Pre-release** |
177
+
178
+ ### commit 批次
179
+
180
+ | 顺序 | 主题 |
181
+ |---|---|
182
+ | 1 | `fix: locale reason mapping, package peer surface, SSE backpressure` |
183
+ | 2 | `fix: end the SSE response so the streamed route terminates` |
184
+ | 3 | `fix(client): never hard-require optional services so boot cannot fail` |
185
+ | 4 | `fix(client): tolerate host input states without imageIds/occurrences` |
186
+ | 5 | `docs: finalize code review report` |
187
+ | 6 | `docs: add 0.2.3 changelog entry`,随后 `npm version patch` 产出 0.2.3 的版本提交与 `v0.2.3` 标签 |
188
+ | 7 | `fix: make the dsh-llm peer optional and satisfiable`,随后 `npm version patch` 产出 0.2.4 的版本提交与 `v0.2.4` 标签 |
189
+ | 8 | `docs: add release notes for 0.2.3 and 0.2.4` |
190
+
191
+ 精确 hash 以 `git log --oneline` 为准;此处刻意不写 hash,避免记录随 rebase/amend 失真。
192
+
193
+ ### 发布验证
194
+
195
+ | 检查 | 结果 |
196
+ |---|---|
197
+ | `npm view dsh-prompt-enhance dist-tags --json` | `latest` = **`0.2.4`** |
198
+ | `gh release list` | `v0.2.3` = **Latest**;`v0.2.4` = **Pre-release** |
199
+ | GitHub 远端 | `main` 已推送(以 `git log origin/main -1` 为准) |
200
+ | `npm pack` | 37 个文件(0.2.3/0.2.4 发布时),含 `lib/`、`cordis.patch.yml`、两份 README、`docs/`、`src/` |
201
+ | `prepublishOnly` 闸门 | `npm run build && npm test` 各执行一次,207 用例通过后才上传 |
202
+
203
+ ### 过程中的两个教训
204
+
205
+ 1. **npm 版本号不可覆盖。** 首次 `npm publish` 因「已发布 0.2.2」被拒——这不是权限问题(`npm whoami` 全程为 `rongxingda`),而是 npm 的版本号一次性语义。正确反应是升版本号(`npm version patch`),而非排查权限。任何"改完直接重发同号"的期望都不成立。
206
+ 2. **`npm view` 的即时读数是旧快照。** 发布成功后立刻查 `dist-tags` 仍返回 0.2.2,属于 registry 复制延迟;判断发布是否成功应以 `npm publish` 自身的 `+ <pkg>@<version>` 输出为准,稍后再查 dist-tags 复核。
207
+
208
+ ### 已知遗留(未处理,供后续决策)
209
+
210
+ - `v0.2.0`–`v0.2.2` **有标签但无 GitHub Release 页**;CHANGELOG 的口径已相应限定为「自 0.2.3 起」,因此文档与实际一致,无需补建。
211
+ - `files` 含 `"docs"`,因此 Release 正文等文档会随后续版本进入 npm 包(每个约几 KB,不影响功能)。