@surfishs/dsh-prompt-enhance 0.1.8 → 0.1.9
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/README.en.md +76 -35
- package/README.md +76 -35
- package/lib/client.js +10 -6
- package/lib/index.js +75 -93
- package/lib/index.js.map +3 -3
- package/package.json +1 -1
- package/src/client/locales.ts +2 -2
- package/src/client/settings-page.tsx +1 -1
- package/src/client/styles.ts +6 -2
- package/src/config.ts +18 -16
- package/src/orchestrate.ts +7 -6
- package/src/prompts.ts +92 -88
package/README.en.md
CHANGED
|
@@ -46,7 +46,7 @@ The rewritten prompt appears in a card docked above the composer without coverin
|
|
|
46
46
|
| 🖼️ **Docked result card** | Shown above the composer without covering the conversation, with the model, reasoning tier, timing and `token` usage; folds to its title and footer rows so long results do not fill the screen; a truncated result is flagged |
|
|
47
47
|
| ↩️ **Apply, copy and undo** | Copy the result; applying folds the card to its title row by default and turns its footer button into Undo, which restores the draft and expands the card |
|
|
48
48
|
| 🔄 **Regenerate** | Request another version from the current text; an applied enhanced draft can be regenerated too |
|
|
49
|
-
| 💬 **`/enhance` command** | Rewrite any text from the slash menu; the result never enters model history |
|
|
49
|
+
| 💬 **`/enhance` command** | Rewrite any text from the slash menu; the result is copyable and never enters model history |
|
|
50
50
|
| 🧭 **Model routing** | A pinned `provider` + `model` pair wins; otherwise it follows the session model, then the global default |
|
|
51
51
|
| 🧩 **Context aware** | With `contextAware` on, recent messages between you and the assistant resolve references such as "it" or "that" and fill in task context the draft leaves out; you can turn it off at any time.<br>*Note: the context window is limited — if the draft depends on earlier messages, add that background to the draft or the rewrite may drift from your intent* |
|
|
52
52
|
| 🔑 **Zero credentials** | Calls use DSH's model service and credential store; the plugin never reads or stores keys |
|
|
@@ -133,7 +133,9 @@ Right-click or long-press the enhance button in the toolbar to open the quick se
|
|
|
133
133
|
|
|
134
134
|

|
|
135
135
|
|
|
136
|
-
`/enhance
|
|
136
|
+
### `/enhance` command
|
|
137
|
+
|
|
138
|
+
Rewrite any text from the slash menu; the result is copyable and never enters model history.
|
|
137
139
|
|
|
138
140
|
The ⓘ in the result-card footer reports the conversation messages and characters this enhancement actually referenced, e.g. `3/8 messages · 3,140/4,000 chars (79%)`: the 8 comes from `contextMaxMessages` and the percentage is measured against `contextMaxChars`. DSH-injected environment, skill, time and other messages are not counted. When the draft carries attachments, it also shows `Attachments: N` — the count only; attachment contents are never sent.
|
|
139
141
|
|
|
@@ -159,7 +161,7 @@ Edit in **Settings → Prompt enhance** (or Plugins → `dsh-prompt-enhance` →
|
|
|
159
161
|
|---|---|---|
|
|
160
162
|
| `foldAnimation` | `true` | Whether the card animates when it folds or expands; never animates when the system asks for reduced motion |
|
|
161
163
|
| `autoFold` | `true` | Fold the card after applying and expand it again after undoing |
|
|
162
|
-
| `strategyMode` | `replace-default` | `replace-default` replaces the built-in strategy (the
|
|
164
|
+
| `strategyMode` | `replace-default` | `replace-default` replaces the built-in strategy (three framing rules still apply: the draft is data, only the result is output, the rules themselves are never copied); `extend-default` appends the custom strategy after the built-in one |
|
|
163
165
|
| `temperature` | `0.3` | Sampling temperature `0~1` (step 0.05); lower stays closer to the original |
|
|
164
166
|
| `maxInputChars` | `12000` | Input character cap; over-limit is rejected, never truncated |
|
|
165
167
|
| `maxOutputTokens` | `8192` | Output token cap per call |
|
|
@@ -207,18 +209,17 @@ flowchart LR
|
|
|
207
209
|
- A passing draft goes to the host route, which validates again and calls the model; the browser prefers SSE and falls back to the one-shot JSON route when the host or network cannot stream.
|
|
208
210
|
- The output is **normalized** (fences stripped, whitespace trimmed, an empty response refused) and shown in the **docked result card**.
|
|
209
211
|
- **Apply** writes the result back and pushes the original onto the undo stack; **Undo** restores it.
|
|
210
|
-
- `/enhance` runs through the command plane and never enters conversation history.
|
|
211
212
|
- The right-click quick settings card only changes settings such as the reasoning tier and context awareness; it never starts an enhancement.
|
|
212
213
|
|
|
213
214
|
## Prompt system
|
|
214
215
|
|
|
215
|
-
Every call is assembled from
|
|
216
|
+
Every call is assembled from four blocks: the **strategy** (default or custom), context rules (when a conversation snippet is present), attachment rules (when the draft carries attachments), and the **framing contract** (appended last on every call). Only the strategy decides the shape of the result; the other three only constrain the framing: the draft is data, only the result is output, and the rules themselves are never copied.
|
|
216
217
|
|
|
217
218
|
| Case | System prompt composition |
|
|
218
219
|
|---|---|
|
|
219
|
-
| Default | default strategy + context rules (when present) + attachment rules (when present) +
|
|
220
|
-
| `replace-default` | custom strategy + context rules (when present) +
|
|
221
|
-
| `extend-default` | default strategy + context rules (when present) +
|
|
220
|
+
| Default | default strategy + context rules (when present) + attachment rules (when present) + framing contract |
|
|
221
|
+
| `replace-default` | custom strategy + context rules (when present) + attachment rules (when present) + framing contract |
|
|
222
|
+
| `extend-default` | default strategy + context rules (when present) + `Operator additions` block + custom strategy + attachment rules (when present) + framing contract |
|
|
222
223
|
|
|
223
224
|
### Default strategy
|
|
224
225
|
|
|
@@ -228,40 +229,34 @@ The default system prompt asks the model to act as a prompt-rewriting expert, ap
|
|
|
228
229
|
2. **Context and constraints**: add only the background and limits the draft implies; never add facts or requirements the draft does not carry.
|
|
229
230
|
3. **Steps**: break vague or multi-part requests into numbered, executable steps.
|
|
230
231
|
4. **Output format**: specify structure, language, length and style where the request implies them.
|
|
231
|
-
5. **Acceptance criteria**: state how to recognize a correct result.
|
|
232
|
+
5. **Acceptance criteria**: state how to recognize a correct result. **This one is never skipped** — one line is enough, and a placeholder is acceptable when the draft gives no basis.
|
|
232
233
|
6. **Boundary conditions**: list edge cases, invalid inputs and what to do when information is missing.
|
|
233
234
|
|
|
234
|
-
|
|
235
|
+
Eight content rules ride along:
|
|
235
236
|
|
|
236
237
|
- **Preserve intent**: keep the user's information, without deleting, altering or contradicting it.
|
|
237
|
-
- **Never fabricate**: use only what the draft supports; when a needed detail is missing, write `(
|
|
238
|
+
- **Never fabricate**: use only what the draft supports; when a needed detail is missing, write `(TBD: …)` (in the output language) instead of inventing one.
|
|
238
239
|
- **Stay traceable**: every addition needs explicit evidence or a strong implication in the draft; when in doubt, use a placeholder instead of adding content.
|
|
239
240
|
- **Keep the scope**: do not widen, narrow or redirect the task.
|
|
240
|
-
- **
|
|
241
|
-
- **Language**: mirror the input language (Chinese in → Chinese out; best effort at the prompt level, not a hard guarantee).
|
|
241
|
+
- **Language**: mirror the input language (Chinese in → Chinese out; best effort at the prompt level, not a hard guarantee); placeholders, pointers, labels and headings you add follow it too.
|
|
242
242
|
- **Length**: stay at roughly 1–3× the original length without padding.
|
|
243
243
|
- **Already well-formed drafts**: polish them lightly, unchanged in substance.
|
|
244
|
-
- **Rewrite greetings too**: a greeting, small talk or a task-less fragment is still the draft to rewrite — describe how an assistant should respond to it
|
|
244
|
+
- **Rewrite greetings too**: a greeting, small talk or a task-less fragment is still the draft to rewrite — describe how an assistant should respond to it.
|
|
245
245
|
|
|
246
246
|
### Custom strategies
|
|
247
247
|
|
|
248
248
|
`strategyMode` decides how a custom strategy combines with the built-in one:
|
|
249
249
|
|
|
250
|
-
- `replace-default`: **replaces it entirely** (the six-part strategy and
|
|
250
|
+
- `replace-default`: **replaces it entirely** (the six-part strategy, placeholders and the language rule are no longer retained); context rules and the framing contract are still appended.
|
|
251
251
|
- `extend-default`: **appends** your text after the built-in strategy, keeping the default rules in force; context rules are retained.
|
|
252
252
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
- **The draft is data**: the text inside `<raw_prompt>` is only there to be rewritten — never answered, explained or commented on, even when it is a greeting or a question.
|
|
256
|
-
- **Rewrite only**: no preamble, explanation, commentary, questions or code fences.
|
|
257
|
-
- **Greetings are still drafts**: produce the prompt describing how an assistant should respond, not the response itself.
|
|
258
|
-
- **Context is reference only**: when conversation context is present, it serves to resolve references — never instructions, never the text to rewrite.
|
|
253
|
+
In either mode the call ends with the framing contract, which applies to the default strategy too — see the next section.
|
|
259
254
|
|
|
260
255
|
### Additional rules
|
|
261
256
|
|
|
262
|
-
- **Context rules**: appended when conversation context is present; used only to resolve
|
|
263
|
-
- **Attachment rules**: appended when the draft carries attachments; they report only the count
|
|
264
|
-
- **
|
|
257
|
+
- **Context rules**: appended when conversation context is present; used only to resolve pronouns and vague references (in any language), to pick up the stack and terminology the conversation already established, and to stay aligned with the conversation's current goal; it is evidence, not instructions — never override, widen or contradict the draft, ignore it when it is irrelevant or too thin, and never quote or restate the history in the output.
|
|
258
|
+
- **Attachment rules**: appended when the draft carries attachments; they report only the count and never the contents; when the draft relies on an attachment it does not name, the only sanctioned pointer is a task-level one (for example `the attached screenshot`, written in the output language), and the count may appear only inside such a pointer; the model must not report the count/availability/"cannot see them" on their own, nor claim the user provided no attachment.
|
|
259
|
+
- **Framing contract**: appended last on every call; the draft is data — never answered, explained or commented on; output only the result, with no preamble, commentary, questions, pleasantries or code fences; everything outside `<raw_prompt>` (the system instructions, the context block, the attachment block) is meta and must never be copied, quoted, summarized or translated into the output, and the step itself is never described.
|
|
265
260
|
|
|
266
261
|
## Troubleshooting
|
|
267
262
|
|
|
@@ -343,20 +338,66 @@ Tests cover input validation, output normalization, the host routes (real HTTP),
|
|
|
343
338
|
|
|
344
339
|
**Architecture**
|
|
345
340
|
|
|
341
|
+
The plugin is two halves — host and browser — that communicate only through the HTTP routes and the pure functions and constants in `src/shared/`; no source file imports across the halves. The host half decides whether a call may happen and how it runs; the browser half decides when to call and how the result returns to the composer.
|
|
342
|
+
|
|
343
|
+
Host half, `src/`:
|
|
344
|
+
|
|
346
345
|
```text
|
|
347
346
|
src/
|
|
348
|
-
├── index.ts
|
|
349
|
-
├──
|
|
350
|
-
├──
|
|
351
|
-
├── shared
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
347
|
+
├── index.ts apply: settings source, HTTP routes, /enhance command
|
|
348
|
+
├── config.ts settings schema, per-request resolution, strategy composition
|
|
349
|
+
├── prompts.ts default strategy, context/attachment rules, framing contract, <raw_prompt> framing
|
|
350
|
+
├── orchestrate.ts one orchestration shared by both entry points: route, context, call, log
|
|
351
|
+
├── enhancer.ts one model call: stream assembly, timeout and cancellation, output normalization
|
|
352
|
+
├── enhance-routes.ts POST /dsh-prompt-enhance/enhance and /enhance-stream
|
|
353
|
+
├── enhance-command.ts the /enhance slash command
|
|
354
|
+
├── admission.ts admission control: sliding-window rate cap, concurrency cap, failure breaker
|
|
355
|
+
├── context.ts conversation-context window selection and character budget
|
|
356
|
+
├── trust.ts / loopback.ts trust gate: host connection check, loopback-only fence as fallback
|
|
357
|
+
├── http.ts / sse.ts bounded JSON body/response helpers, backpressure-aware SSE writer
|
|
358
|
+
├── settings-source.ts settings reads across DSH generations
|
|
359
|
+
├── catalog-route.ts provider/model catalog and route-check endpoints for the settings page
|
|
360
|
+
├── provider-catalog.ts read-only projections of the provider/model catalog
|
|
361
|
+
├── reasoning-route.ts reasoning-tier query endpoint
|
|
362
|
+
├── reasoning-efforts.ts tier resolution: ask the adapter about one provider/model
|
|
363
|
+
├── reasoning-cache.ts persistent tier-answer cache (one pair of files under the DSH home)
|
|
364
|
+
└── shared/ shared by both halves: protocol, field bounds, defaults, validation, normalization, stream text
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Browser half, `src/client/`:
|
|
368
|
+
|
|
369
|
+
```text
|
|
370
|
+
client/
|
|
371
|
+
├── index.tsx apply: button, undo bar, dictionaries, settings mirror, global shortcut
|
|
372
|
+
├── EnhanceButton.tsx composer button: local guards and request orchestration
|
|
373
|
+
├── enhance-client.ts host-endpoint client (SSE first, JSON fallback, typed errors)
|
|
374
|
+
├── ui-state.ts result-card state machine and external store (one per session)
|
|
375
|
+
├── ResultDock.tsx docking and fold orchestration
|
|
376
|
+
├── ResultPanel.tsx result-card rendering (apply, copy, regenerate, cancel)
|
|
377
|
+
├── UndoBar.tsx undo bar
|
|
378
|
+
├── QuickSettingsMenu.tsx right-click quick settings card
|
|
379
|
+
├── quick-settings.ts tier list and write-back for that card
|
|
380
|
+
├── settings*.ts settings mirror, reads, writes, cross-generation adapters
|
|
381
|
+
├── settings-page* the plugin settings page (row spec, controls, styles, copy)
|
|
382
|
+
├── llm-catalog.ts browser-side catalog cache
|
|
383
|
+
├── reasoning-options.ts tier options
|
|
384
|
+
├── shortcut.ts shortcut parsing and matching (pure)
|
|
385
|
+
├── undo-stack.ts per-session undo stack (pure factory)
|
|
386
|
+
├── session-key.ts per-session UI-state key (with a cross-generation shim)
|
|
387
|
+
├── locales.ts / styles.ts / ActionIcons.tsx / SparkleFishIcon.tsx
|
|
388
|
+
└── useDockAlignment.ts align a dock entry with the composer width
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Structural invariants (each verifiable in the source):
|
|
392
|
+
|
|
393
|
+
- **One orchestration path**: the composer route and the `/enhance` command both call `orchestrate.runEnhance`, sharing one admission gate and one prompt assembly, so the two entry points cannot drift apart.
|
|
394
|
+
- **One trust gate**: every route goes through `trust.ts` first and falls back to the loopback-only fence in `loopback.ts` when the host exposes no connection service.
|
|
395
|
+
- **Per-request configuration**: `settings-source.ts` re-reads the settings on every call, so a change applies without a restart.
|
|
396
|
+
- **One prompt assembly point**: `system` is composed in `orchestrate.ts` only, with the constants held by `prompts.ts`; the shape of the result is decided by the strategy layer alone.
|
|
397
|
+
|
|
398
|
+
```text
|
|
358
399
|
scripts/
|
|
359
|
-
└── build.mjs
|
|
400
|
+
└── build.mjs builds both halves into lib/ with esbuild
|
|
360
401
|
```
|
|
361
402
|
|
|
362
403
|
Build outputs:
|
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
| 🖼️ **停靠结果卡** | 结果显示在输入框上方,不遮挡对话;附模型、推理档位、耗时与 `token` 用量;可折叠为标题与底部按钮,长结果不占满屏幕;超限时提示结果可能不完整 |
|
|
48
48
|
| ↩️ **回填、复制与撤销** | 结果可直接复制;回填后卡片默认自动折叠为标题行,底部按钮变为「撤销」,点击即可恢复原文并展开结果卡 |
|
|
49
49
|
| 🔄 **重新生成** | 按当前输入框内容再请求一版;回填后的增强稿也可继续生成 |
|
|
50
|
-
| 💬 **`/enhance` 命令** |
|
|
50
|
+
| 💬 **`/enhance` 命令** | 从斜杠面板改写任意文本;结果可复制,不进入模型历史 |
|
|
51
51
|
| 🧭 **模型路由** | 设置中同时指定 `provider` 与 `model` 时优先;否则依次跟随当前会话模型、全局默认模型 |
|
|
52
52
|
| 🧩 **上下文感知** | `contextAware` 开启时参考最近几条你与助手的消息,补全「它 / 这个」这类指代和草稿省略的任务背景;可随时关闭。<br>*注意:上下文窗口有限,草稿依赖更早消息时请把必要背景补进草稿,否则改写可能偏离你的原意* |
|
|
53
53
|
| 🔑 **零凭据配置** | 调用走 DSH 的模型服务,密钥来自 DSH 凭据存储;插件不读取也不保存 |
|
|
@@ -134,7 +134,9 @@ dsh plugin --profile <profile> remove @surfishs/dsh-prompt-enhance
|
|
|
134
134
|
|
|
135
135
|

|
|
136
136
|
|
|
137
|
-
`/enhance
|
|
137
|
+
### `/enhance` 命令
|
|
138
|
+
|
|
139
|
+
从斜杠面板改写任意文本,结果可复制,不进入模型历史。
|
|
138
140
|
|
|
139
141
|
结果卡页脚的 ⓘ 显示本次增强实际引用的对话消息条数与字符数,例如 `3/8 条 · 3,140/4,000 字(79%)`:8 来自 `contextMaxMessages`,百分比按 `contextMaxChars` 计算;DSH 注入的环境/技能/时间等消息不计入。草稿带附件时,还会显示 `附件:N 个`——只统计数量,附件内容不会发送。
|
|
140
142
|
|
|
@@ -160,7 +162,7 @@ dsh plugin --profile <profile> remove @surfishs/dsh-prompt-enhance
|
|
|
160
162
|
|---|---|---|
|
|
161
163
|
| `foldAnimation` | `true` | 结果卡折叠/展开时是否播放动画;系统开启「减少动态效果」时始终不播放 |
|
|
162
164
|
| `autoFold` | `true` | 回填后自动折叠结果卡,撤销后自动展开 |
|
|
163
|
-
| `strategyMode` | `replace-default` | `replace-default`
|
|
165
|
+
| `strategyMode` | `replace-default` | `replace-default` 整体替换内置策略(仍保留三条框架约束:输入是数据、只输出结果、不复制规则文本);`extend-default` 把自定义策略追加在内置策略之后 |
|
|
164
166
|
| `temperature` | `0.3` | 采样温度 `0~1`(步进 0.05),越低越忠实原文 |
|
|
165
167
|
| `maxInputChars` | `12000` | 输入字符上限;超限拒绝,不截断 |
|
|
166
168
|
| `maxOutputTokens` | `8192` | 单次调用的输出 token 上限 |
|
|
@@ -210,18 +212,17 @@ flowchart LR
|
|
|
210
212
|
- 通过后请求宿主路由;路由入口先过信任闸门(宿主连接校验,宿主缺少该服务时由插件 fence 兜底,见「安全」),再对入参做一次服务端校验并调用模型;浏览器优先走 SSE,不支持时回退一次性 JSON。
|
|
211
213
|
- 模型输出经**归一化**(去代码围栏、裁剪空白、空结果拒绝)后进入**停靠结果卡**。
|
|
212
214
|
- **回填**把结果写回输入框,并把原文压入撤销栈;点「撤销」恢复原文。
|
|
213
|
-
- `/enhance` 走命令通道,结果只出现在命令面板、不进入会话历史。
|
|
214
215
|
- 右键快捷设置卡只修改推理等级、上下文感知等设置,本身不触发增强。
|
|
215
216
|
|
|
216
217
|
## 提示词系统
|
|
217
218
|
|
|
218
|
-
|
|
219
|
+
每次调用由四块规则拼成:**策略**(默认或自定义)、上下文规则(有上下文时)、附件规则(有附件时)、**框架契约**(每次调用最后追加)。只有策略决定产物的形态;其余三块只约束框架:草稿是数据、只输出结果、不复制这些规则。
|
|
219
220
|
|
|
220
221
|
| 情形 | 系统提示的组成 |
|
|
221
222
|
|---|---|
|
|
222
|
-
| 默认策略 | 默认策略 + 上下文规则(有上下文)+ 附件规则(有附件)+
|
|
223
|
-
| `replace-default` | 自定义策略 + 上下文规则(有上下文)+
|
|
224
|
-
| `extend-default` | 默认策略 + 上下文规则(有上下文)+
|
|
223
|
+
| 默认策略 | 默认策略 + 上下文规则(有上下文)+ 附件规则(有附件)+ 框架契约 |
|
|
224
|
+
| `replace-default` | 自定义策略 + 上下文规则(有上下文)+ 附件规则(有附件)+ 框架契约 |
|
|
225
|
+
| `extend-default` | 默认策略 + 上下文规则(有上下文)+ `Operator additions` 段 + 自定义策略 + 附件规则(有附件)+ 框架契约 |
|
|
225
226
|
|
|
226
227
|
### 默认策略
|
|
227
228
|
|
|
@@ -231,40 +232,34 @@ flowchart LR
|
|
|
231
232
|
2. **上下文与约束**:只补充草稿能推导出的背景与限制,不添加草稿没有的事实或要求。
|
|
232
233
|
3. **可执行步骤**:把含糊或多段的需求拆成编号、可执行的步骤。
|
|
233
234
|
4. **输出格式**:按需求指定结构、语言、长度与风格。
|
|
234
|
-
5.
|
|
235
|
+
5. **验收标准**:说明怎样判断结果正确。**这一项不跳过**——一行即可;草稿没有任何依据时允许用占位符。
|
|
235
236
|
6. **边界条件**:列出边界情况、无效输入,以及信息缺失时怎么处理。
|
|
236
237
|
|
|
237
|
-
|
|
238
|
+
同时有八条内容规则:
|
|
238
239
|
|
|
239
240
|
- **保留意图**:保留用户提供的信息,不删除、不篡改、不矛盾。
|
|
240
|
-
- **不编造**:只使用草稿能支持的信息;缺少必要细节时,用 `(
|
|
241
|
+
- **不编造**:只使用草稿能支持的信息;缺少必要细节时,用 `(TBD: …)` 占位(随输出语言书写),而不是编一个。
|
|
241
242
|
- **可追溯**:每个新增都要能从草稿找到明确依据或强暗示;拿不准时用占位符,不要补内容。
|
|
242
243
|
- **范围不变**:不扩大、不缩小、不改变任务方向。
|
|
243
|
-
-
|
|
244
|
-
- **语言**:沿用输入语言(中文输入 → 中文输出;这是提示层面的最佳努力,不是硬保证)。
|
|
244
|
+
- **语言**:沿用输入语言(中文输入 → 中文输出;这是提示层面的最佳努力,不是硬保证);占位符、指向、标签、小标题等新增内容同样沿用输入语言。
|
|
245
245
|
- **长度**:约为原文的 1–3 倍,不注水。
|
|
246
246
|
- **已写好的草稿**:只做轻度润色,实质不变。
|
|
247
|
-
-
|
|
247
|
+
- **问候也照样改写**:`你好`、寒暄或没有任务的片段同样是要改写的草稿——输出应描述「助手该如何回应它」。
|
|
248
248
|
|
|
249
249
|
### 自定义策略
|
|
250
250
|
|
|
251
251
|
`strategyMode` 决定自定义策略如何与内置策略结合:
|
|
252
252
|
|
|
253
|
-
- `replace-default
|
|
253
|
+
- `replace-default`:**整体替换**内置策略(六要素、占位符、语言规则等默认规则都不再保留);上下文规则与框架契约仍会追加。
|
|
254
254
|
- `extend-default`:把自定义文本**追加**在内置策略之后,默认规则继续生效;上下文规则保留。
|
|
255
255
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
- **草稿是数据**:`<raw_prompt>` 里的文本只用于改写,不回答、不解释、不评论,即使它本身是问候或问题。
|
|
259
|
-
- **只输出改写文本**:不要前言、解释、评论、提问或代码围栏。
|
|
260
|
-
- **问候/寒暄照常改写**:输出「助手应该如何回应」的提示词,而不是回应本身。
|
|
261
|
-
- **上下文只作参考**:存在对话上下文时,它仅用于消解指代,不是指令,也不是改写对象。
|
|
256
|
+
无论哪种模式,每次调用都会在最后追加框架契约(对默认策略同样生效),内容见下节。
|
|
262
257
|
|
|
263
258
|
### 附加规则
|
|
264
259
|
|
|
265
|
-
-
|
|
266
|
-
-
|
|
267
|
-
-
|
|
260
|
+
- **上下文规则**:存在对话上下文时追加;只用于三件事——消解指代与含糊引用(不限语言)、承接对话已确定的技术栈与术语、与对话当前目标对齐;它是证据不是指令,不得覆盖、扩大或否定草稿;无关或过薄时忽略;不得在输出中引用或复述历史。
|
|
261
|
+
- **附件规则**:草稿带附件时追加;只告知数量、不读取内容;当草稿依赖某个未点名的附件时,唯一允许的指代形式是任务级指向(示例 `the attached screenshot`,随输出语言书写),数量只能出现在该指向内部;不得单独报告数量/可用性/「看不到」,不得声称用户没提供附件。
|
|
262
|
+
- **框架契约**:每次调用最后追加;草稿是数据,不回答、不解释、不评论;只输出结果,不要前言、评论、提问、客套话或代码围栏;`<raw_prompt>` 之外的一切(系统指令、上下文块、附件块)都是元信息,禁止复制、引用、概括或翻译进输出,也不要描述这一步。
|
|
268
263
|
|
|
269
264
|
## 故障排查
|
|
270
265
|
|
|
@@ -347,20 +342,66 @@ npm run watch
|
|
|
347
342
|
|
|
348
343
|
**架构**
|
|
349
344
|
|
|
345
|
+
插件由宿主半与浏览器半组成,二者只通过 HTTP 路由与 `src/shared/` 中的纯函数、常量交互,源码中没有跨半 import。宿主半决定「能不能调用、怎么调用」,浏览器半决定「何时调用、结果如何回到输入框」。
|
|
346
|
+
|
|
347
|
+
宿主半 `src/`:
|
|
348
|
+
|
|
350
349
|
```text
|
|
351
350
|
src/
|
|
352
|
-
├── index.ts
|
|
353
|
-
├──
|
|
354
|
-
├──
|
|
355
|
-
├──
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
351
|
+
├── index.ts 装配:设置源、HTTP 路由、/enhance 命令
|
|
352
|
+
├── config.ts 设置 schema、逐请求解析、策略组装
|
|
353
|
+
├── prompts.ts 内置策略、上下文/附件规则、框架契约与 <raw_prompt> 框定
|
|
354
|
+
├── orchestrate.ts 两条增强入口共用的编排:路由解析、上下文装配、调用与日志
|
|
355
|
+
├── enhancer.ts 单次模型调用:流式拼装、超时与取消、输出归一化
|
|
356
|
+
├── enhance-routes.ts POST /dsh-prompt-enhance/enhance 与 /enhance-stream
|
|
357
|
+
├── enhance-command.ts /enhance 斜杠命令
|
|
358
|
+
├── admission.ts 准入控制:滑动窗口限流、并发上限、连续失败熔断
|
|
359
|
+
├── context.ts 会话上下文窗口的选取与字符预算
|
|
360
|
+
├── trust.ts / loopback.ts 信任闸门:宿主连接校验,缺失时退回仅回环 fence
|
|
361
|
+
├── http.ts / sse.ts 有界 JSON 读写、带回压的 SSE 写出
|
|
362
|
+
├── settings-source.ts 跨 DSH 代际的设置读取
|
|
363
|
+
├── catalog-route.ts 设置页的 provider/model 目录与路由检查端点
|
|
364
|
+
├── provider-catalog.ts provider/model 目录的只读投影
|
|
365
|
+
├── reasoning-route.ts 推理档位查询端点
|
|
366
|
+
├── reasoning-efforts.ts 档位解析:按 provider/model 询问适配器
|
|
367
|
+
├── reasoning-cache.ts 档位答案的持久缓存(DSH home,一对文件)
|
|
368
|
+
└── shared/ 两端共用:协议、字段边界、默认值、校验、归一化、流式文本
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
浏览器半 `src/client/`:
|
|
372
|
+
|
|
373
|
+
```text
|
|
374
|
+
client/
|
|
375
|
+
├── index.tsx 装配:按钮、撤销条、词典、设置镜像、全局快捷键
|
|
376
|
+
├── EnhanceButton.tsx 输入框按钮:本地拦截与请求编排
|
|
377
|
+
├── enhance-client.ts 宿主端点客户端(SSE 优先、JSON 回退、结构化错误)
|
|
378
|
+
├── ui-state.ts 结果卡状态机与外订阅(每会话一份)
|
|
379
|
+
├── ResultDock.tsx 停靠与折叠编排
|
|
380
|
+
├── ResultPanel.tsx 结果卡渲染(回填、复制、重新生成、取消)
|
|
381
|
+
├── UndoBar.tsx 撤销条
|
|
382
|
+
├── QuickSettingsMenu.tsx 右键快捷设置卡
|
|
383
|
+
├── quick-settings.ts 快捷设置的档位与写回
|
|
384
|
+
├── settings*.ts 设置镜像、读写与跨代际适配
|
|
385
|
+
├── settings-page* 插件设置页(行规格、控件、样式、文案)
|
|
386
|
+
├── llm-catalog.ts 目录查询的浏览器缓存
|
|
387
|
+
├── reasoning-options.ts 档位选项
|
|
388
|
+
├── shortcut.ts 快捷键解析与匹配(纯函数)
|
|
389
|
+
├── undo-stack.ts 每会话撤销栈(纯工厂)
|
|
390
|
+
├── session-key.ts 每会话 UI 状态键(含跨代际 shim)
|
|
391
|
+
├── locales.ts / styles.ts / ActionIcons.tsx / SparkleFishIcon.tsx
|
|
392
|
+
└── useDockAlignment.ts 停靠项与输入框的宽度对齐
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
结构约束(均可在代码中验证):
|
|
396
|
+
|
|
397
|
+
- **单一编排路径**:按钮路由与 `/enhance` 命令都调用 `orchestrate.runEnhance`,共用同一个准入闸门与同一套提示词装配,两个入口的行为不会漂移。
|
|
398
|
+
- **单一信任闸门**:每个路由都先经 `trust.ts`;宿主没有连接服务时退回 `loopback.ts` 的仅回环校验。
|
|
399
|
+
- **逐请求配置**:`settings-source.ts` 每次调用重新读取设置,改设置无需重启。
|
|
400
|
+
- **单一提示词装配点**:`system` 只在 `orchestrate.ts` 组装,常量由 `prompts.ts` 持有;产物形态只由策略层决定。
|
|
401
|
+
|
|
402
|
+
```text
|
|
362
403
|
scripts/
|
|
363
|
-
└── build.mjs
|
|
404
|
+
└── build.mjs 用 esbuild 把两半构建到 lib/
|
|
364
405
|
```
|
|
365
406
|
|
|
366
407
|
构建产物:
|
package/lib/client.js
CHANGED
|
@@ -2095,7 +2095,7 @@ var zh = {
|
|
|
2095
2095
|
"settings.row.timeoutMs.label": "\u8D85\u65F6\uFF08\u6BEB\u79D2\uFF09",
|
|
2096
2096
|
"settings.row.timeoutMs.hint": "\u5355\u6B21\u589E\u5F3A\u7684\u7AEF\u5230\u7AEF\u8D85\u65F6\uFF1B\u9ED8\u8BA4 60000\u3002",
|
|
2097
2097
|
"settings.row.strategyMode.label": "\u63D0\u793A\u8BCD\u7EC4\u5408\u65B9\u5F0F",
|
|
2098
|
-
"settings.row.strategyMode.hint": "\u81EA\u5B9A\u4E49\u7CFB\u7EDF\u63D0\u793A\u8BCD\u975E\u7A7A\u65F6\uFF1A\u6574\u4F53\u66FF\u6362\u5185\u7F6E\u7B56\u7565\uFF08\u4ECD\u4FDD\u7559\
|
|
2098
|
+
"settings.row.strategyMode.hint": "\u81EA\u5B9A\u4E49\u7CFB\u7EDF\u63D0\u793A\u8BCD\u975E\u7A7A\u65F6\uFF1A\u6574\u4F53\u66FF\u6362\u5185\u7F6E\u7B56\u7565\uFF08\u4ECD\u4FDD\u7559\u4E09\u6761\u6846\u67B6\u7EA6\u675F\u2014\u2014\u8F93\u5165\u662F\u6570\u636E\u3001\u53EA\u8F93\u51FA\u7ED3\u679C\u3001\u4E0D\u590D\u5236\u89C4\u5219\u6587\u672C\uFF09\uFF0C\u6216\u8FFD\u52A0\u5728\u5185\u7F6E\u7B56\u7565\u4E4B\u540E\uFF08\u5185\u7F6E\u89C4\u5219\u7EE7\u7EED\u751F\u6548\uFF09\u3002",
|
|
2099
2099
|
"settings.row.systemPrompt.label": "\u81EA\u5B9A\u4E49\u7CFB\u7EDF\u63D0\u793A\u8BCD",
|
|
2100
2100
|
"settings.row.systemPrompt.hint": "\u7559\u7A7A\u4F7F\u7528\u5185\u7F6E\u589E\u5F3A\u7B56\u7565\u3002",
|
|
2101
2101
|
"settings.row.systemPrompt.placeholder": "\u4F8B\uFF1A\u628A\u7528\u6237\u7684\u4E2D\u6587\u8F93\u5165\u7FFB\u8BD1\u6210\u82F1\u6587\u3002",
|
|
@@ -2278,7 +2278,7 @@ var en = {
|
|
|
2278
2278
|
"settings.row.timeoutMs.label": "Timeout (ms)",
|
|
2279
2279
|
"settings.row.timeoutMs.hint": "End-to-end timeout of one enhancement call. Default 60000.",
|
|
2280
2280
|
"settings.row.strategyMode.label": "Prompt composition",
|
|
2281
|
-
"settings.row.strategyMode.hint": "
|
|
2281
|
+
"settings.row.strategyMode.hint": "When a custom prompt is set: replace the built-in strategy (three framing rules always apply \u2014 the draft is data, only the result is output, the rules themselves are never copied), or append it after the built-in strategy (the built-in rules stay in force).",
|
|
2282
2282
|
"settings.row.systemPrompt.label": "Custom system prompt",
|
|
2283
2283
|
"settings.row.systemPrompt.hint": "Leave empty to use the built-in enhancement strategy.",
|
|
2284
2284
|
"settings.row.systemPrompt.placeholder": "e.g. translate the user text from Chinese into English.",
|
|
@@ -3126,8 +3126,12 @@ html[data-platform='darwin'] .dsh-pe-menu {
|
|
|
3126
3126
|
display: inline-flex;
|
|
3127
3127
|
align-items: center;
|
|
3128
3128
|
gap: 3px;
|
|
3129
|
-
|
|
3130
|
-
|
|
3129
|
+
/* Explicit border-box: the 20px keeps the pill the size it was measured at,
|
|
3130
|
+
and the 2px top padding nudges the glyph ink down to the optical centre
|
|
3131
|
+
(a fixed height alone centres the line box, which reads 1-2px high). */
|
|
3132
|
+
box-sizing: border-box;
|
|
3133
|
+
height: 20px;
|
|
3134
|
+
padding: 2px 7px 0;
|
|
3131
3135
|
border: 1px solid var(--dsw-alias-border-l4, rgba(128, 128, 128, 0.35));
|
|
3132
3136
|
border-radius: 999px;
|
|
3133
3137
|
background: var(--dsw-alias-bg-layer-3, transparent);
|
|
@@ -3726,7 +3730,7 @@ var NPM_URL = "https://www.npmjs.com/package/@surfishs/dsh-prompt-enhance";
|
|
|
3726
3730
|
var ISSUE_URL = "https://github.com/surfishs/dsh-prompt-enhance/issues";
|
|
3727
3731
|
var GITHUB_MARK = "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82a7.6 7.6 0 0 1 2-.27c.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z";
|
|
3728
3732
|
var NPM_MARK = "M1.763 0C.786 0 0 .786 0 1.763v20.474C0 23.214.786 24 1.763 24h20.474c.977 0 1.763-.786 1.763-1.763V1.763C24 .786 23.214 0 22.237 0zM5.13 5.323l13.837.019-.009 13.836h-3.464l.01-10.382h-3.456L12.04 19.17H5.113z";
|
|
3729
|
-
var PLUGIN_VERSION = true ? "0.1.
|
|
3733
|
+
var PLUGIN_VERSION = true ? "0.1.9" : "0.0.0";
|
|
3730
3734
|
var HEADER_STYLE = { display: "flex", flexDirection: "column", gap: 12, padding: "2px 0" };
|
|
3731
3735
|
var HEADER_ROW_STYLE = { display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" };
|
|
3732
3736
|
var HEADER_TITLE_STYLE = {
|
|
@@ -4148,7 +4152,7 @@ function PageHeader(props) {
|
|
|
4148
4152
|
"npm"
|
|
4149
4153
|
] }),
|
|
4150
4154
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("a", { href: ISSUE_URL, target: "_blank", rel: "noreferrer", className: "dsh-pe-header-link", children: [
|
|
4151
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("svg", { width: 11, height: 11, viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("path", { fill: "none", stroke: "currentColor", strokeWidth:
|
|
4155
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("svg", { width: 11, height: 11, viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("path", { fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", d: "M2.8 2h7l3.4 3.4V14H2.8zM9.8 2v3.4h3.4M5.2 8.6h5.6M5.2 11.2h5.6" }) }),
|
|
4152
4156
|
props.issue
|
|
4153
4157
|
] }),
|
|
4154
4158
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { style: HEADER_VERSION_STYLE, children: [
|