@surfishs/dsh-prompt-enhance 0.1.7 → 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 CHANGED
@@ -21,17 +21,21 @@ The draft is the source of truth: intent unchanged, no invented requirements, a
21
21
 
22
22
  ## Why you need it
23
23
 
24
- Users tend to open with a pleading "So… could you help me out?" — and that alone often sends the model off-course: it drifts from what you meant and fills in the gaps itself. That is not the user's fault: what is hard is rarely the thinking, it is turning what you have thought through into a form the model can follow.
24
+ Users tend to open with a plea: "So… could you help me out?" — like a patient who says only "I don't feel well" and expects a prescription. The model gets nothing but that plea, so it has to guess; the guesses look plausible, but they are often not what you meant.
25
25
 
26
- A good prompt spells out six things: who the model acts as and what it delivers, the context and constraints it works under, which steps it takes, in what format, what counts as correct, and where the boundaries are.
26
+ ![A photo captioned “So… could you help me out?”, with the plugin icon in the top-right corner](./docs/images/promo-enhance-en.png)
27
27
 
28
- The plugin adds a Prompt enhancement button to the composer toolbar: one click sends the draft to DSH's model service, which rewrites it around those six things as a structured prompt.
28
+ *“So… could you help me out?” — a pleading request like this is exactly what this plugin rewrites*
29
29
 
30
- The result appears in a card docked above the composer without covering the conversation; your draft is never replaced — apply it, copy it, regenerate it, or undo, and the original text can always be restored.
30
+ A good prompt spells out six things — who the model acts as and what it delivers, the context and constraints it works under, which steps it takes, in what format, what counts as correct, and where the boundaries are.
31
31
 
32
- With context awareness on, the plugin passes the most recent messages between you and the assistant to the model, helping it resolve references such as "it" or "that" and fill in task context the draft leaves out, so the rewrite stays closer to what you meant.
32
+ That is what the plugin fills in for you.
33
33
 
34
- > **Note**: the context window is limited. If the draft depends on earlier messages, add the necessary background to the draft; otherwise the rewrite may drift from your intent.
34
+ ## Button and result card
35
+
36
+ The plugin adds a Prompt enhancement button to the composer toolbar. One click sends your draft to DSH's model service, which rewrites it into a structured prompt.
37
+
38
+ The rewritten prompt appears in a card docked above the composer without covering the conversation. Your draft is never replaced: you can apply it, copy it, regenerate it, or undo — the draft you started from can always be restored.
35
39
 
36
40
  ## Feature overview
37
41
 
@@ -42,9 +46,9 @@ With context awareness on, the plugin passes the most recent messages between yo
42
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 |
43
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 |
44
48
  | 🔄 **Regenerate** | Request another version from the current text; an applied enhanced draft can be regenerated too |
45
- | 💬 **`/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 |
46
50
  | 🧭 **Model routing** | A pinned `provider` + `model` pair wins; otherwise it follows the session model, then the global default |
47
- | 🧩 **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 |
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* |
48
52
  | 🔑 **Zero credentials** | Calls use DSH's model service and credential store; the plugin never reads or stores keys |
49
53
  | 🛡️ **Draft safety** | Empty, attachment-only, over-length and command-or-reference drafts are blocked locally; upstream failures get a readable message and never touch the draft |
50
54
  | ⚙️ **Live settings** | Fields save automatically, common rows first and the rest under Advanced; changes apply on the next call |
@@ -129,9 +133,11 @@ Right-click or long-press the enhance button in the toolbar to open the quick se
129
133
 
130
134
  ![Quick settings card opened by right-click or long press](./docs/images/quick-settings-en.png)
131
135
 
132
- `/enhance <text>`: rewrite any text from the slash menu; the result is copyable and never enters model history.
136
+ ### `/enhance` command
137
+
138
+ Rewrite any text from the slash menu; the result is copyable and never enters model history.
133
139
 
134
- 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.
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.
135
141
 
136
142
  ## Configuration
137
143
 
@@ -144,7 +150,6 @@ Edit in **Settings → Prompt enhance** (or Plugins → `dsh-prompt-enhance` →
144
150
  | `enabled` | `true` | Master switch; off hides the composer button and disables the command and shortcut |
145
151
  | `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 (no pinned route). With only one filled, the save falls back to follow-session; switching the provider clears the chosen model so a stale pair cannot remain |
146
152
  | `reasoningEffort` | `off` | Tiers come from what the configured provider/model declares (DeepSeek: `off` / `low` / `high` / `max`). "Model default" sends no field, so the provider applies its default; switching to a model that does not declare the stored tier rewrites it to "Model default" |
147
- | `temperature` | `0.3` | Sampling temperature `0~1` (step 0.05); lower stays closer to the original |
148
153
  | `contextAware` | `true` | Read recent messages to resolve references; turn it off for sensitive sessions |
149
154
  | `streaming` | `true` | Show the result as it is written; display only, the final result is unchanged |
150
155
  | `systemPrompt` | empty | Custom system prompt; empty uses the built-in strategy |
@@ -156,7 +161,8 @@ Edit in **Settings → Prompt enhance** (or Plugins → `dsh-prompt-enhance` →
156
161
  |---|---|---|
157
162
  | `foldAnimation` | `true` | Whether the card animates when it folds or expands; never animates when the system asks for reduced motion |
158
163
  | `autoFold` | `true` | Fold the card after applying and expand it again after undoing |
159
- | `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 |
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 |
165
+ | `temperature` | `0.3` | Sampling temperature `0~1` (step 0.05); lower stays closer to the original |
160
166
  | `maxInputChars` | `12000` | Input character cap; over-limit is rejected, never truncated |
161
167
  | `maxOutputTokens` | `8192` | Output token cap per call |
162
168
  | `timeoutMs` | `60000` | End-to-end timeout per call (ms) |
@@ -165,7 +171,11 @@ Edit in **Settings → Prompt enhance** (or Plugins → `dsh-prompt-enhance` →
165
171
  | `maxConcurrent` | `2` | Concurrent enhancement limit; a new request past the limit is told to retry later |
166
172
  | `rateLimitPerMinute` | `10` | Successful enhancements per minute, counted over any rolling 60 seconds; past the limit the request is told to retry later |
167
173
 
168
- An empty or attachment-only draft dims the button and starts no request; raise `maxOutputTokens` when a result is truncated.
174
+ ### About the default reasoning effort
175
+
176
+ This plugin defaults to `off`, and that default is usually the right one to keep. Prompt enhancement is normally a short, well-specified task — restating a draft more clearly — so no chain of reasoning is needed: on a simple task a thinking tier buys little, while costing several times the output tokens and a longer wait. A thinking tier is not without value — when the draft leans on involved context, or the task itself calls for weighing trade-offs, raising the tier clearly improves the rewrite, and you can do it for that one call. When you need more capability, a stronger model usually pays off more than a higher effort tier. Both the settings page and the right-click quick card switch the tier, so you can compare on the same draft.
177
+
178
+ Do not pick a model that is too weak for the job: the output is a task description handed to the downstream model, and a noticeably weaker model tends to make it vaguer, drop key constraints, or drift from what you meant — **a lower-quality prompt can be worse than no rewrite at all**. Do not route prompt optimisation through a model weaker than the one running the current session.
169
179
 
170
180
  ## Security
171
181
 
@@ -199,18 +209,17 @@ flowchart LR
199
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.
200
210
  - The output is **normalized** (fences stripped, whitespace trimmed, an empty response refused) and shown in the **docked result card**.
201
211
  - **Apply** writes the result back and pushes the original onto the undo stack; **Undo** restores it.
202
- - `/enhance` runs through the command plane and never enters conversation history.
203
212
  - The right-click quick settings card only changes settings such as the reasoning tier and context awareness; it never starts an enhancement.
204
213
 
205
214
  ## Prompt system
206
215
 
207
- Every call is assembled from a few rule blocks: the default or custom strategy, context rules (when a conversation snippet is present), attachment rules (when the draft carries attachments), the invariant contract (custom strategies only), and meta rules (appended last on every call).
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.
208
217
 
209
218
  | Case | System prompt composition |
210
219
  |---|---|
211
- | Default | default strategy + context rules (when present) + attachment rules (when present) + meta |
212
- | `replace-default` | custom strategy + context rules (when present) + invariant contract + attachment rules (when present) + meta |
213
- | `extend-default` | default strategy + context rules (when present) + custom strategy + invariant contract + attachment rules (when present) + meta |
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 |
214
223
 
215
224
  ### Default strategy
216
225
 
@@ -220,40 +229,34 @@ The default system prompt asks the model to act as a prompt-rewriting expert, ap
220
229
  2. **Context and constraints**: add only the background and limits the draft implies; never add facts or requirements the draft does not carry.
221
230
  3. **Steps**: break vague or multi-part requests into numbered, executable steps.
222
231
  4. **Output format**: specify structure, language, length and style where the request implies them.
223
- 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.
224
233
  6. **Boundary conditions**: list edge cases, invalid inputs and what to do when information is missing.
225
234
 
226
- Nine hard rules ride along:
235
+ Eight content rules ride along:
227
236
 
228
237
  - **Preserve intent**: keep the user's information, without deleting, altering or contradicting it.
229
- - **Never fabricate**: use only what the draft supports; when a needed detail is missing, write `(待补充:…)` / `(TBD: …)` instead of inventing one.
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.
230
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.
231
240
  - **Keep the scope**: do not widen, narrow or redirect the task.
232
- - **Body only**: no explanations, preamble, comparison with the original, code fences or pleasantries.
233
- - **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.
234
242
  - **Length**: stay at roughly 1–3× the original length without padding.
235
243
  - **Already well-formed drafts**: polish them lightly, unchanged in substance.
236
- - **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, never answer it yourself.
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.
237
245
 
238
246
  ### Custom strategies
239
247
 
240
248
  `strategyMode` decides how a custom strategy combines with the built-in one:
241
249
 
242
- - `replace-default`: **replaces it entirely** (the six-part strategy and default rules such as placeholders are no longer retained); context rules are still appended.
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.
243
251
  - `extend-default`: **appends** your text after the built-in strategy, keeping the default rules in force; context rules are retained.
244
252
 
245
- With a custom strategy, the plugin appends an invariant contract, and it **applies in both custom-strategy modes**:
246
-
247
- - **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.
248
- - **Rewrite only**: no preamble, explanation, commentary, questions or code fences.
249
- - **Greetings are still drafts**: produce the prompt describing how an assistant should respond, not the response itself.
250
- - **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.
251
254
 
252
255
  ### Additional rules
253
256
 
254
- - **Context rules**: appended when conversation context is present; used only to resolve references and fill in omissions, with the draft taking precedence; never quote or restate the conversation history.
255
- - **Attachment rules**: appended when the draft carries attachments; they report only the count, never the contents; the model may add a task-level pointer ("see the attachment") and use the count inside the task description, but must not describe or guess the contents, report the count/availability/"cannot see them", or restate the rules.
256
- - **Meta rules**: appended last on every call; only `<raw_prompt>` is draft material — the system instructions, context block and attachment block are meta and must never be copied, summarized or translated into the output; the output must be a task prompt for the downstream assistant, never a note about this rewriting step.
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.
257
260
 
258
261
  ## Troubleshooting
259
262
 
@@ -275,6 +278,48 @@ The table is organized by what you see; parameter meanings and defaults are in C
275
278
  | Message says no model is configured for the enhancement (no model route) | No pinned `provider`/`model` pair and no session model route | Set both `provider` and `model` in settings, or send a message in the current session so the plugin can follow the session model |
276
279
  | `/enhance` shows only the first line and cannot be expanded | A rendering limit of the DSH chat UI, not this plugin | Put the same text in the composer and use the enhance button; its card wraps and scrolls |
277
280
 
281
+ ## Known issues
282
+
283
+ The items below are known issues, numbered. Anything marked (no support planned) is a capability we do not currently provide, not a defect awaiting a fix.
284
+
285
+ ### 1. Reference preservation (no support planned)
286
+
287
+ This plugin **does not preserve references**. It does not offer "chip-preserving fill-back" or any equivalent that writes `@file` references, links, or commands back into the composer intact. A draft containing such references is rejected locally, before any request is sent. The plugin enhances the text you typed — turning a rough draft into a fuller, clearer prompt — and does not carry or rebuild reference structures.
288
+
289
+ #### Why it is out of scope
290
+
291
+ A rewrite has to reorganise the text. Once reference markers are allowed into that text, they restrict how much can be rewritten and pull the model's attention onto the markers themselves, at the cost of the body's completeness and readability. **Reference markers damaging the body text is an error we are not willing to accept**, so the draft is refused instead.
292
+
293
+ #### Breakage observed in testing
294
+
295
+ Evaluating the "chip-preserving fill-back" approach used by a comparable plugin reproduced three failure modes:
296
+
297
+ - **References lost**: the chip disappears, or degrades into ordinary text that merely looks like a reference;
298
+ - **References misplaced**: the chip survives but its position or target no longer matches the text;
299
+ - **Body text absorbed into a reference**: wording that belongs to the body ends up inside the reference range.
300
+
301
+ All three are visible in the result: the formatting is already broken by the time you read the enhanced prompt — a reference is gone, has turned into plain text, or no longer lines up with the body.
302
+
303
+ #### What to do with such a draft
304
+
305
+ - Drafts containing `@file` references, links, or commands are blocked locally and no request is sent (see "How it works");
306
+ - When a draft carries attachments, the model is told only how many there are — contents are never read or sent, and no attachment markers are inserted into the result;
307
+ - To enhance such a draft, remove the references first, put the necessary details in plain text, then insert the references back manually.
308
+
309
+ ### 2. Reading images and attachment contents (no support planned)
310
+
311
+ This plugin **does not read images, and does not read attachment contents**. When a draft carries attachments, it knows only how many there are, and the model is told it cannot see them: it may write a pointer such as "see the attachment", but must not describe, guess, or transcribe what is inside. The originals travel with your message to the downstream model, which reads them itself.
312
+
313
+ #### Why it is out of scope
314
+
315
+ What the enhancement delivers is better **text**. Let the enhancement model read an image or a document, and what it read becomes a transcription inside that text: a transcription can be wrong, while the originals reach the downstream model too — and which one wins when they disagree is not guaranteed. Images are the worst case: small print and chart values are costly to get wrong, and they are exactly what the downstream model reads most reliably from the original and what the enhancement model is most likely to misread.
316
+
317
+ The cost does not add up either: the same content is read twice, once during enhancement and once during execution, and images make that most obvious in tokens. Binary attachments (PDF, DOCX, and so on) add a further limit: on the host side their contents are never handed to the model — only a file handle is — so reading them would mean parsing them in the plugin, which is a different scale of work.
318
+
319
+ #### What to do instead
320
+
321
+ Put the details you actually need into the draft: the exact error, the numbers, the field names, the steps. That is what the enhancement can genuinely improve; leave the rest of the attachment to the downstream model, which has the original.
322
+
278
323
  ## Development
279
324
 
280
325
  **Common commands**
@@ -293,20 +338,66 @@ Tests cover input validation, output normalization, the host routes (real HTTP),
293
338
 
294
339
  **Architecture**
295
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
+
296
345
  ```text
297
346
  src/
298
- ├── index.ts host apply: settings section, routes and the /enhance command
299
- ├── prompts.ts default strategy, context/attachment/META rules, invariant contract and <raw_prompt> framing
300
- ├── enhance-routes.ts POST /dsh-prompt-enhance/enhance and the SSE stream
301
- ├── shared/ shared by both halves: protocol, input checks, output normalization
302
- └── client/
303
- ├── EnhanceButton.tsx composer button, local guards and request orchestration
304
- ├── QuickSettingsMenu.tsx right-click card (model, tier, context)
305
- ├── ResultDock.tsx docking, apply/undo and fold orchestration
306
- ├── ResultPanel.tsx result-card rendering (apply, copy, regenerate, cancel)
307
- └── UndoBar.tsx undo bar that restores the original draft
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
308
399
  scripts/
309
- └── build.mjs builds both halves into lib/
400
+ └── build.mjs builds both halves into lib/ with esbuild
310
401
  ```
311
402
 
312
403
  Build outputs:
package/README.md CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  **DeepSeek Harness Web GUI 的「提示词增强」插件** —— 一键把输入框草稿改写为结构化提示词:角色与目标、上下文与约束、可执行步骤、输出格式、验收标准、边界条件。
16
16
 
17
- 以原文为准:不改变原意、不凭空编造需求;信息不足时留占位。改写不改动你的草稿(出错时也不会):结果先出现在停靠卡里,点「回填」才写回,回填后可一键撤销。
17
+ 以原文为准:不改变原意、不凭空编造需求;信息不足时留占位。改写不改动你的草稿(出错时也不会):结果先出现在结果卡里,点「回填」才写回,回填后可一键撤销。
18
18
 
19
19
  ![提示词增强:输入框上方的停靠结果卡](./docs/images/panel.png)
20
20
 
@@ -22,17 +22,21 @@
22
22
 
23
23
  ## 为什么需要它
24
24
 
25
- 用户往往带着祈求式的「那你能帮帮我吗?」发问。而这往往让模型偏离用户意愿、自行补充内容。问题不在用户身上:难点通常不在想,而在把想过的东西整理成模型能照着做的形式。
25
+ 用户往往带着祈求的语气发问「那你能帮帮我吗?」——像病人只说一句「我不舒服」,就等着大夫开药。可模型拿到的只有这句求助,它只能自己猜;猜出来的部分看着合理,却常常不是你的原意。
26
26
 
27
- 一段好的提示词会讲清六件事:让模型扮演谁和交付什么、在什么上下文和约束下做、分哪几步、以什么格式、怎样算合格、边界在哪。
27
+ ![配文「那你能帮帮我吗?」的照片,右上角是插件图标](./docs/images/promo-enhance.png)
28
28
 
29
- 插件在输入框工具栏加了一个「提示词增强」按钮:点一下,草稿就会交给 DSH 的模型服务,按上面那六件事改写成结构化提示词。
29
+ *「那你能帮帮我吗?」——这样一句祈求式提问,正是本插件要改写的对象*
30
30
 
31
- 结果出现在输入框上方的停靠卡里,不遮挡对话;草稿不会被直接替换——你可以回填、复制、重新生成或撤销,原文随时可恢复。
31
+ 一段好的提示词会讲清六件事——让模型扮演什么角色、交付什么结果,在什么上下文和约束下做,分哪几步,以什么格式输出,怎样算合格,边界在哪。
32
32
 
33
- 开启后,插件会参考最近几条你和助手的消息,帮模型理解「它」「这个」指什么,补全草稿省略的任务背景,让改写更贴近原意。
33
+ 插件做的,就是把这几件事替你补齐。
34
34
 
35
- > **注意**:上下文窗口有限;如果草稿依赖更早的消息,请把必要背景补进草稿,否则改写可能偏离你的原意。
35
+ ## 按钮与结果卡
36
+
37
+ 插件在输入框工具栏加了一个「提示词增强」按钮。点一下,插件就会把你的草稿交给 DSH 的模型服务,把它改写成结构化提示词。
38
+
39
+ 改写后的提示词会出现在输入框上方的结果卡里,不遮挡对话。草稿不会被直接替换:你可以回填、复制、重新生成或撤销,改写前的草稿随时可恢复。
36
40
 
37
41
  ## 功能一览
38
42
 
@@ -43,9 +47,9 @@
43
47
  | 🖼️ **停靠结果卡** | 结果显示在输入框上方,不遮挡对话;附模型、推理档位、耗时与 `token` 用量;可折叠为标题与底部按钮,长结果不占满屏幕;超限时提示结果可能不完整 |
44
48
  | ↩️ **回填、复制与撤销** | 结果可直接复制;回填后卡片默认自动折叠为标题行,底部按钮变为「撤销」,点击即可恢复原文并展开结果卡 |
45
49
  | 🔄 **重新生成** | 按当前输入框内容再请求一版;回填后的增强稿也可继续生成 |
46
- | 💬 **`/enhance` 命令** | 斜杠面板直接改写任意文本;结果不进入模型历史 |
50
+ | 💬 **`/enhance` 命令** | 从斜杠面板改写任意文本;结果可复制,不进入模型历史 |
47
51
  | 🧭 **模型路由** | 设置中同时指定 `provider` 与 `model` 时优先;否则依次跟随当前会话模型、全局默认模型 |
48
- | 🧩 **上下文感知** | `contextAware` 开启时参考最近几条你与助手的消息,补全「它 / 这个」这类指代和草稿省略的任务背景;可随时关闭 |
52
+ | 🧩 **上下文感知** | `contextAware` 开启时参考最近几条你与助手的消息,补全「它 / 这个」这类指代和草稿省略的任务背景;可随时关闭。<br>*注意:上下文窗口有限,草稿依赖更早消息时请把必要背景补进草稿,否则改写可能偏离你的原意* |
49
53
  | 🔑 **零凭据配置** | 调用走 DSH 的模型服务,密钥来自 DSH 凭据存储;插件不读取也不保存 |
50
54
  | 🛡️ **草稿安全** | 空输入、仅附件、超长、含命令或文件引用都在本地拦截;上游失败给出可读提示,且不改动草稿 |
51
55
  | ⚙️ **配置热生效** | 字段改完自动保存,常用项在前、其余收进「高级设置」;下一次调用立即生效 |
@@ -109,7 +113,7 @@ dsh plugin --profile <profile> remove @surfishs/dsh-prompt-enhance
109
113
  ## 使用
110
114
 
111
115
  1. **开始**:在输入框写下草稿,点工具栏的增强按钮(或你设置的快捷键)。
112
- 2. **查看结果**:结果出现在输入框上方的停靠卡里,可以:
116
+ 2. **查看结果**:结果出现在输入框上方的结果卡里,可以:
113
117
  - **回填**:写回输入框,卡片默认自动折叠为标题行,底部按钮变为「撤销」;
114
118
  - **复制**:复制结果;
115
119
  - **重新生成**:按当前输入再生成一版。
@@ -130,9 +134,11 @@ dsh plugin --profile <profile> remove @surfishs/dsh-prompt-enhance
130
134
 
131
135
  ![右键或长按按钮打开的快捷设置卡](./docs/images/quick-settings.png)
132
136
 
133
- `/enhance <文本>`:从斜杠面板改写任意文本,结果可复制,不进入模型历史。
137
+ ### `/enhance` 命令
138
+
139
+ 从斜杠面板改写任意文本,结果可复制,不进入模型历史。
134
140
 
135
- 结果卡页脚的 ⓘ 显示本次增强实际引用的对话消息条数与字符数,例如 `3/8 条 · 3,140/4,000 字(79%)`:8 来自 `contextMaxMessages`,百分比按 `contextMaxChars` 计算;DSH 注入的环境/技能/时间等消息不计入。
141
+ 结果卡页脚的 ⓘ 显示本次增强实际引用的对话消息条数与字符数,例如 `3/8 条 · 3,140/4,000 字(79%)`:8 来自 `contextMaxMessages`,百分比按 `contextMaxChars` 计算;DSH 注入的环境/技能/时间等消息不计入。草稿带附件时,还会显示 `附件:N 个`——只统计数量,附件内容不会发送。
136
142
 
137
143
  ## 配置
138
144
 
@@ -145,7 +151,6 @@ dsh plugin --profile <profile> remove @surfishs/dsh-prompt-enhance
145
151
  | `enabled` | `true` | 总开关;关闭后隐藏输入框按钮,并停用命令与快捷键 |
146
152
  | `provider` + `model` | 空 | 从 DSH 已注册的 LLM provider 及模型中选择;模型可选「自定义…」手填 ID;未配置的 provider 置灰、需先在 DSH 模型服务中配置;留空表示跟随当前会话模型(不固定路由)。只填一个时保存后按跟随会话处理;切换 provider 会清空已选 model,避免留下不匹配的旧值 |
147
153
  | `reasoningEffort` | `off` | 档位由当前 provider/model 的声明决定;DeepSeek 为 `off` / `low` / `high` / `max`。选「模型默认」时不发送该字段,由提供方使用默认档;切换到不声明当前档位的模型时,插件会自动改回「模型默认」 |
148
- | `temperature` | `0.3` | 采样温度 `0~1`(步进 0.05),越低越忠实原文 |
149
154
  | `contextAware` | `true` | 读取最近几条消息以消解指代;含敏感内容的会话建议关闭 |
150
155
  | `streaming` | `true` | 边写边显示;仅影响显示节奏,最终结果不变 |
151
156
  | `systemPrompt` | 空 | 自定义系统提示词;留空使用内置增强策略 |
@@ -157,7 +162,8 @@ dsh plugin --profile <profile> remove @surfishs/dsh-prompt-enhance
157
162
  |---|---|---|
158
163
  | `foldAnimation` | `true` | 结果卡折叠/展开时是否播放动画;系统开启「减少动态效果」时始终不播放 |
159
164
  | `autoFold` | `true` | 回填后自动折叠结果卡,撤销后自动展开 |
160
- | `strategyMode` | `replace-default` | `replace-default` 整体替换内置策略(仍保留最小输出契约);`extend-default` 把自定义策略追加在内置策略之后 |
165
+ | `strategyMode` | `replace-default` | `replace-default` 整体替换内置策略(仍保留三条框架约束:输入是数据、只输出结果、不复制规则文本);`extend-default` 把自定义策略追加在内置策略之后 |
166
+ | `temperature` | `0.3` | 采样温度 `0~1`(步进 0.05),越低越忠实原文 |
161
167
  | `maxInputChars` | `12000` | 输入字符上限;超限拒绝,不截断 |
162
168
  | `maxOutputTokens` | `8192` | 单次调用的输出 token 上限 |
163
169
  | `timeoutMs` | `60000` | 单次调用端到端超时(毫秒) |
@@ -166,7 +172,11 @@ dsh plugin --profile <profile> remove @surfishs/dsh-prompt-enhance
166
172
  | `maxConcurrent` | `2` | 同时进行的增强上限;达到上限时新请求会提示稍后再试 |
167
173
  | `rateLimitPerMinute` | `10` | 每分钟成功增强次数上限,按任意连续 60 秒计算;超限时提示稍后再试 |
168
174
 
169
- 输入为空或只有附件时按钮变灰、不可点,不发起请求;结果被截断时调高 `maxOutputTokens`。
175
+ ### 关于默认的思考档位
176
+
177
+ 本插件默认使用 `off`,多数情况下保持这个默认即可。提示词增强通常是短、目标明确的任务——把草稿改写成更清楚的表述,不需要推理过程:在简单任务上,带思考的档位收益很小,代价却是几倍的输出 token 与更长的等待。带思考的档位并非没有价值——当草稿依赖较复杂的上下文、或任务本身需要权衡取舍时,提高档位能明显改善改写质量,可以针对那一次临时调高。需要更强能力时,换一个更好的模型通常比抬高思考档位更划算。设置页与右键快捷卡都能切换档位,方便你用同一份草稿自行对比。
178
+
179
+ 选模型时不要用能力过弱的模型:增强的产物是交给下游执行的任务描述,用明显更弱的模型改写,容易把话说得含糊、丢掉关键约束,甚至与你的原意产生偏差——**一份质量更低的提示词,可能比不改写更糟**。因此不要用比当前会话模型能力更低的模型来负责提示词优化。
170
180
 
171
181
  ## 安全
172
182
 
@@ -202,18 +212,17 @@ flowchart LR
202
212
  - 通过后请求宿主路由;路由入口先过信任闸门(宿主连接校验,宿主缺少该服务时由插件 fence 兜底,见「安全」),再对入参做一次服务端校验并调用模型;浏览器优先走 SSE,不支持时回退一次性 JSON。
203
213
  - 模型输出经**归一化**(去代码围栏、裁剪空白、空结果拒绝)后进入**停靠结果卡**。
204
214
  - **回填**把结果写回输入框,并把原文压入撤销栈;点「撤销」恢复原文。
205
- - `/enhance` 走命令通道,结果只出现在命令面板、不进入会话历史。
206
215
  - 右键快捷设置卡只修改推理等级、上下文感知等设置,本身不触发增强。
207
216
 
208
217
  ## 提示词系统
209
218
 
210
- 每次调用由几块规则拼成:默认或自定义策略、上下文规则(有上下文时)、附件规则(有附件时)、不可变契约(仅自定义策略)以及 meta 规则(每次调用最后追加)。
219
+ 每次调用由四块规则拼成:**策略**(默认或自定义)、上下文规则(有上下文时)、附件规则(有附件时)、**框架契约**(每次调用最后追加)。只有策略决定产物的形态;其余三块只约束框架:草稿是数据、只输出结果、不复制这些规则。
211
220
 
212
221
  | 情形 | 系统提示的组成 |
213
222
  |---|---|
214
- | 默认策略 | 默认策略 + 上下文规则(有上下文)+ 附件规则(有附件)+ meta |
215
- | `replace-default` | 自定义策略 + 上下文规则(有上下文)+ 不可变契约 + 附件规则(有附件)+ meta |
216
- | `extend-default` | 默认策略 + 上下文规则(有上下文)+ 自定义策略 + 不可变契约 + 附件规则(有附件)+ meta |
223
+ | 默认策略 | 默认策略 + 上下文规则(有上下文)+ 附件规则(有附件)+ 框架契约 |
224
+ | `replace-default` | 自定义策略 + 上下文规则(有上下文)+ 附件规则(有附件)+ 框架契约 |
225
+ | `extend-default` | 默认策略 + 上下文规则(有上下文)+ `Operator additions` 段 + 自定义策略 + 附件规则(有附件)+ 框架契约 |
217
226
 
218
227
  ### 默认策略
219
228
 
@@ -223,40 +232,34 @@ flowchart LR
223
232
  2. **上下文与约束**:只补充草稿能推导出的背景与限制,不添加草稿没有的事实或要求。
224
233
  3. **可执行步骤**:把含糊或多段的需求拆成编号、可执行的步骤。
225
234
  4. **输出格式**:按需求指定结构、语言、长度与风格。
226
- 5. **验收标准**:说明怎样判断结果正确。
235
+ 5. **验收标准**:说明怎样判断结果正确。**这一项不跳过**——一行即可;草稿没有任何依据时允许用占位符。
227
236
  6. **边界条件**:列出边界情况、无效输入,以及信息缺失时怎么处理。
228
237
 
229
- 同时有九条硬规则:
238
+ 同时有八条内容规则:
230
239
 
231
240
  - **保留意图**:保留用户提供的信息,不删除、不篡改、不矛盾。
232
- - **不编造**:只使用草稿能支持的信息;缺少必要细节时,用 `(待补充:…)` / `(TBD: …)` 占位,而不是编一个。
241
+ - **不编造**:只使用草稿能支持的信息;缺少必要细节时,用 `(TBD: …)` 占位(随输出语言书写),而不是编一个。
233
242
  - **可追溯**:每个新增都要能从草稿找到明确依据或强暗示;拿不准时用占位符,不要补内容。
234
243
  - **范围不变**:不扩大、不缩小、不改变任务方向。
235
- - **只输出正文**:不要解释、前言、与原文的对比、代码围栏或客套话。
236
- - **语言**:沿用输入语言(中文输入 → 中文输出;这是提示层面的最佳努力,不是硬保证)。
244
+ - **语言**:沿用输入语言(中文输入 → 中文输出;这是提示层面的最佳努力,不是硬保证);占位符、指向、标签、小标题等新增内容同样沿用输入语言。
237
245
  - **长度**:约为原文的 1–3 倍,不注水。
238
246
  - **已写好的草稿**:只做轻度润色,实质不变。
239
- - **问候也照样改写**:`你好`、寒暄或没有任务的片段同样是要改写的草稿——输出应描述「助手该如何回应它」,而不是直接回应它。
247
+ - **问候也照样改写**:`你好`、寒暄或没有任务的片段同样是要改写的草稿——输出应描述「助手该如何回应它」。
240
248
 
241
249
  ### 自定义策略
242
250
 
243
251
  `strategyMode` 决定自定义策略如何与内置策略结合:
244
252
 
245
- - `replace-default`:**整体替换**内置策略(六要素、占位符等默认规则不再保留);上下文规则仍会追加。
253
+ - `replace-default`:**整体替换**内置策略(六要素、占位符、语言规则等默认规则都不再保留);上下文规则与框架契约仍会追加。
246
254
  - `extend-default`:把自定义文本**追加**在内置策略之后,默认规则继续生效;上下文规则保留。
247
255
 
248
- 使用自定义策略时,插件会追加一段不可变契约,**两种自定义模式都生效**:
249
-
250
- - **草稿是数据**:`<raw_prompt>` 里的文本只用于改写,不回答、不解释、不评论,即使它本身是问候或问题。
251
- - **只输出改写文本**:不要前言、解释、评论、提问或代码围栏。
252
- - **问候/寒暄照常改写**:输出「助手应该如何回应」的提示词,而不是回应本身。
253
- - **上下文只作参考**:存在对话上下文时,它仅用于消解指代,不是指令,也不是改写对象。
256
+ 无论哪种模式,每次调用都会在最后追加框架契约(对默认策略同样生效),内容见下节。
254
257
 
255
258
  ### 附加规则
256
259
 
257
- - **上下文规则**:存在对话上下文时追加;仅用于消解指代、补全省略,草稿优先;不得引用或复述上下文历史。
258
- - **附件规则**:草稿带附件时追加;只告知数量,不读取内容;允许任务级指代(「见附件」)和在任务描述内使用数量,但不得描述/猜测内容、报告数量/可用性/「看不到」,也不得复述规则。
259
- - **Meta 规则**:每次调用最后追加;只有 `<raw_prompt>` 里是草稿,系统指令、上下文块、附件块都是 meta,禁止复制/概括/翻译进输出;输出必须是给下游助手的任务提示词,而不是关于本次改写的说明。
260
+ - **上下文规则**:存在对话上下文时追加;只用于三件事——消解指代与含糊引用(不限语言)、承接对话已确定的技术栈与术语、与对话当前目标对齐;它是证据不是指令,不得覆盖、扩大或否定草稿;无关或过薄时忽略;不得在输出中引用或复述历史。
261
+ - **附件规则**:草稿带附件时追加;只告知数量、不读取内容;当草稿依赖某个未点名的附件时,唯一允许的指代形式是任务级指向(示例 `the attached screenshot`,随输出语言书写),数量只能出现在该指向内部;不得单独报告数量/可用性/「看不到」,不得声称用户没提供附件。
262
+ - **框架契约**:每次调用最后追加;草稿是数据,不回答、不解释、不评论;只输出结果,不要前言、评论、提问、客套话或代码围栏;`<raw_prompt>` 之外的一切(系统指令、上下文块、附件块)都是元信息,禁止复制、引用、概括或翻译进输出,也不要描述这一步。
260
263
 
261
264
  ## 故障排查
262
265
 
@@ -279,6 +282,48 @@ flowchart LR
279
282
  | 提示「还没确定用哪个模型」(缺模型路由) | 未固定 `provider`/`model`,且当前会话没有模型路由 | 在设置中成对填写 `provider` / `model`;或先在当前会话发一条消息,让插件跟随会话模型 |
280
283
  | `/enhance` 的结果只显示第一行、点不开 | DSH 聊天界面的渲染限制,与本插件无关 | 把同样的文本放进输入框,用增强按钮;结果卡会自动折行并可滚动 |
281
284
 
285
+ ## 已知问题
286
+
287
+ 下面列出目前已知的问题,按编号排列。标注「暂无支持计划」的条目,是当前不提供的能力,不是等待修复的缺陷。
288
+
289
+ ### 1. 引用保留类功能(暂无支持计划)
290
+
291
+ 本插件**不做引用保留**,也不提供「芯片保留式回填」这类把 `@文件` 引用、链接或命令原样写回输入框的能力。含这类引用的草稿会在本地被拒绝,不会发出请求。本插件只增强你敲下的文字:把草稿改写成更完整、更明确的提示词,不负责搬运或重建引用结构。
292
+
293
+ #### 为什么不做
294
+
295
+ 改写必然要重新组织正文。一旦允许引用标记参与这段正文,它们就会限制作改能动的范围,也会让模型把注意力分给标记本身,正文的完整性与可读性都要为此让步。**引用标记破坏正文,是我们不能接受的错误**,所以宁可拒绝,也不做这类保留。
296
+
297
+ #### 实测到的破坏类型
298
+
299
+ 参考同类插件的「芯片保留式回填」方案并实测,复现出三类问题:
300
+
301
+ - **引用失效**:引用芯片消失,或退化成一串看起来像引用的普通文字;
302
+ - **引用错误**:引用还在,但位置或指向变了,与正文对不上;
303
+ - **正文被并入引用**:本该属于正文的文字被吸附进了引用范围。
304
+
305
+ 这三类问题在结果里直接可见:拿到增强后的提示词时,就能看出格式已经被破坏——引用没了、变成了普通文字,或者位置与正文对不上。
306
+
307
+ #### 遇到这类草稿怎么办
308
+
309
+ - 含 `@文件` 引用、链接或命令的草稿会被本地拦截,不发请求(见「工作原理」);
310
+ - 草稿带附件时,只告诉模型附件的数量,不读取、不发送附件内容,也不在结果里插入附件标记;
311
+ - 需要增强这类草稿时,先把引用去掉、把必要信息写成纯文字,增强完成后再手动把引用插回去。
312
+
313
+ ### 2. 读取图片与附件内容(暂无支持计划)
314
+
315
+ 本插件**不读取图片,也不读取附件内容**。草稿带附件时,它只知道附件的数量,并被明确告知看不到附件:可以写「见附件」这类指代,但不能描述、猜测或转述附件里有什么。附件原件会随你的消息一起发送给下游模型,由下游自己查看。
316
+
317
+ #### 为什么不做
318
+
319
+ 增强要交付的是一段更好的**文字**。一旦让增强模型去读图或读附件,它读到的内容就会变成这段文字里的一段转写:转写可能出错,而原件同时也到达下游,两者对不上时以谁为准并没有保证。图片尤其如此——小字、图表数值这类细节误读代价高,而它们恰恰是下游对着原件看最可靠、增强模型最容易读错的部分。
320
+
321
+ 成本上也不划算:同一份内容会被读两次,一次在增强时、一次在执行时,图片在 token 上的体现尤其明显。二进制附件(PDF、DOCX 等)还有另一层限制:宿主侧不会把它的内容交给模型,只给出文件句柄,真要读正文得由插件自己解析,那是另一个量级的工作。
322
+
323
+ #### 替代做法
324
+
325
+ 把真正需要的信息直接写进草稿:确切的报错、数值、字段名、步骤。这些正是增强能改好的东西;附件里的其余部分,交给下游带着原件去看。
326
+
282
327
  ## 开发
283
328
 
284
329
  **常用命令**
@@ -297,20 +342,66 @@ npm run watch
297
342
 
298
343
  **架构**
299
344
 
345
+ 插件由宿主半与浏览器半组成,二者只通过 HTTP 路由与 `src/shared/` 中的纯函数、常量交互,源码中没有跨半 import。宿主半决定「能不能调用、怎么调用」,浏览器半决定「何时调用、结果如何回到输入框」。
346
+
347
+ 宿主半 `src/`:
348
+
300
349
  ```text
301
350
  src/
302
- ├── index.ts 宿主装配:设置节、路由与 /enhance 命令
303
- ├── prompts.ts 默认策略、上下文/附件/META 规则、不可变契约与 <raw_prompt> 框定
304
- ├── enhance-routes.ts POST /dsh-prompt-enhance/enhance 与 SSE 流
305
- ├── shared/ 两端共用:协议、输入校验、输出归一化
306
- └── client/
307
- ├── EnhanceButton.tsx 输入框按钮、本地拦截与请求编排
308
- ├── QuickSettingsMenu.tsx 右键快捷设置卡(模型、档位、上下文)
309
- ├── ResultDock.tsx 停靠、回填/撤销与折叠编排
310
- ├── ResultPanel.tsx 结果卡渲染(回填、复制、重新生成、取消)
311
- └── UndoBar.tsx 撤销条(恢复原文)
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
312
403
  scripts/
313
- └── build.mjs 构建两半到 lib/
404
+ └── build.mjs 用 esbuild 把两半构建到 lib/
314
405
  ```
315
406
 
316
407
  构建产物:
Binary file