@y1x1n/dsh-prompt-optimizer 0.5.0 → 0.6.5
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 +31 -17
- package/README.md +31 -17
- package/lib/client.js +86 -41
- package/lib/controller.js +47 -9
- package/lib/index.js +29 -8
- package/lib/prompt.js +29 -8
- package/package.json +10 -7
package/README.en.md
CHANGED
|
@@ -110,28 +110,40 @@ dsh plugin --profile web remove @y1x1n/dsh-prompt-optimizer
|
|
|
110
110
|
|
|
111
111
|
## Compatibility
|
|
112
112
|
|
|
113
|
-
> **This version (v0.5
|
|
113
|
+
> **This version (v0.6.5) targets DeepSeek Harness**:
|
|
114
114
|
>
|
|
115
|
-
> | dsh version | Optimize route / model calls | Settings page (incl. GitHub link) | Composer button / result panel |
|
|
116
|
-
>
|
|
117
|
-
> | **0.2.
|
|
118
|
-
> | **0.
|
|
119
|
-
> | **0.1
|
|
120
|
-
> | **0.1
|
|
121
|
-
> | **0.
|
|
115
|
+
> | dsh version | Optimize route / model calls | Settings page (incl. GitHub link) | Composer button / result panel | Session context |
|
|
116
|
+
> |---|---|---|---|---|
|
|
117
|
+
> | **0.2.2-rc.3 (Web + official desktop runtime)** | ✅ verified live (successful rewrite produced) | ✅ verified live (tab + settings read/write) | ✅ verified live | ✅ contract-verified |
|
|
118
|
+
> | **0.2.2-rc.1 (Web + official desktop runtime)** | ✅ verified live (v0.6.4, successful rewrite produced) | ✅ verified live (tab + settings read/write) | ✅ verified live | ✅ contract-verified |
|
|
119
|
+
> | **0.2.1-rc.5 (Web + official desktop runtime)** | ✅ verified live (successful rewrite produced) | ✅ verified live (tab + settings card) | ✅ verified live | ✅ contract-verified |
|
|
120
|
+
> | **0.2.1-rc.3 (Web + official desktop runtime)** | ✅ verified live (route/SSE/error state) | ✅ verified live (tab + settings read/write) | ✅ verified live | ✅ contract-verified |
|
|
121
|
+
> | **0.2.1-rc.2 (Web + official desktop)** | ✅ artifact-verified | ✅ artifact-verified (incl. slot-registration fix) | ✅ artifact-verified | ✅ now available |
|
|
122
|
+
> | **0.2.0-rc.2 (Web + official desktop)** | ✅ verified | ✅ verified (volatile config + native-style settings card) | ✅ verified | ✅ |
|
|
123
|
+
> | **0.1.5-rc.2** | ✅ verified | ✅ verified | ✅ verified | degraded (no `ctx.sessions`) |
|
|
124
|
+
> | **0.1.5-rc.1** | ✅ verified | ✅ verified | ✅ verified | degraded (no `ctx.sessions`) |
|
|
125
|
+
> | **0.1.2-rc.1 / 0.1.2-alpha.5** | ✅ verified | ✅ verified | ✅ verified | degraded (no `ctx.sessions`) |
|
|
126
|
+
> | **0.1.1-rc.2 and below** (0.1.0-rc.7+) | ✅ verified | ✅ verified | ✅ verified | degraded (no `ctx.sessions`) |
|
|
122
127
|
>
|
|
123
|
-
> One build covers 0.1.0-rc.7 through 0.2.
|
|
128
|
+
> One build covers 0.1.0-rc.7 through 0.2.2; `package.json` now declares `engines.dsh: ">=0.1.0-rc.7 <0.3.0-0"`, enforced by the host at boot (prereleases included), explicitly excluding 0.3.x.
|
|
129
|
+
>
|
|
130
|
+
> **About "artifact-verified"**: v0.6.0's 0.2.1-rc.2 support was established by inspecting the **real runtime shipped in the app's own `app.asar`** item by item (slot declarations, `SlotCore` throw behavior, the `ctx.sessions` provider, `session/page` pagination semantics, the `ConfigFormSnapshot` shape, `engines.dsh` validation, the client baseline static-module table), backed by targeted regression tests; at that time the full UI flow was not clicked through in a live 0.2.1-rc.2 GUI (the local instance requires a launch token). **v0.6.2 upgrades 0.2.1-rc.3 support to a real end-to-end run**: a throwaway profile was booted with the official desktop app's bundled rc.3 runtime CLI and the released tgz installed; the composer "Optimize" button, the `settings.plugins.tab` tab and the settings card were confirmed in the live page, settings writes persisted into the profile patch, and an optimize request reached the Host route and returned the upstream error through SSE (the test account has zero balance, so the error state rather than a successful completion was verified). Item-by-item differences: [`docs/dsh-021-rc3-diff.md`](docs/dsh-021-rc3-diff.md). This annotation is maintained in every Release note from v0.3.15 onward, and earlier Release notes have been retroactively annotated.
|
|
124
131
|
|
|
125
132
|
- **v0.4.0 adapts dsh 0.2.0-rc.2** (2026-10-03, Windows, real-profile end-to-end): ① Settings migration — 0.2.0 removed the `settingsScope` service and the `settings.plugin.item` slot; settings are now auto-generated by the host from the plugin's Config schema. The plugin declares every Config field `.volatile()` (volatile fields update in place via reference cells — **editing settings no longer remounts the plugin**), the client reads/writes through `configForms`, and the settings card registers BOTH the 0.2.0 `settings.plugins.tab` and the 0.1.x `settings.plugin.item` slots — each host renders the one it knows. ② The settings card was redesigned to the 0.2.0 official design language (flat rows, native-style segmented controls and switches, `configure({auto:false})` hiding the host's duplicate auto form). ③ The `kind:'plugin'` message source crosses 0.2.0's narrowed union via a structural assertion (the runtime tolerates unknown sources, merge-extensible). ④ Verified on **0.2.0-rc.2 Web** (button, SSE panel, model-catalog RPC, settings read/write with profile-patch persistence and no plugin restart, undo) and the **official desktop app** (Electron `DeepSeek Harness 0.2.0-rc.2`, `desktop` profile installed via the app's own CLI, composer button and settings card verified through UIA).
|
|
126
133
|
- **Session id stamped on llm calls (v0.4.0, fixes opencode)**: opencode (`opencode-go`) requires the `x-opencode-session` per-conversation header, which the pi-ai adapter injects only when `GenerateOptions.sessionId` is present — the plugin's one-shot calls never set it, so the API rejected them over missing headers (opencode could not be probed or used to optimize). The client now sends the originating session id and the Host stamps it on the llm call (session-level metering attributes the call correctly); the connectivity probe stamps a fixed synthetic id. Other adapters treat sessionId as model-hidden transport metadata and never send it.
|
|
127
134
|
- **Session stamp always present (v0.5.0, hardens opencode)**: v0.4.0's stamp depended on the client sending a session id; on host forms that never deliver `sessionId` to slot components the request body lacked it and opencode still complained about the missing header. Since 0.5.0 the Host falls back to a synthetic id (`prompt-optimizer-one-shot`) whenever the client omits one (or sends whitespace), so every call path satisfies the header requirement; when the client does send the real id, metering attribution is unchanged. Note that profiles still running 0.3.x-or-older plugin builds do not include the fix — upgrade to 0.5.0+ and restart the host / refresh the page.
|
|
128
135
|
- **Official desktop installation**: after the desktop app initializes its `desktop` profile on first launch, fully quit the app, install with the app's own CLI and relaunch: `"E:\Deepseek-Harness\resources\runtime\cli\bin\dsh.cmd" plugin --profile desktop add @y1x1n/dsh-prompt-optimizer` (macOS/Linux paths per app install dir); do not manage the desktop's reserved profile with the npm CLI.
|
|
129
|
-
- Development baseline: `@deepseek-ai/*` **0.2.
|
|
136
|
+
- Development baseline: `@deepseek-ai/*` **0.2.2-rc.3** (pinned by `sync:types` across 20 packages — now including `dsh-error` — same version in devDeps, from v0.6.5; the `cordis` devDep stays at `^4.1.0` and the `schemastery` runtime dependency at `^3.19.0`, matching the unchanged upstream vendor line); previously 0.2.2-rc.1 (from v0.6.4), 0.2.1-rc.5 (from v0.6.3), 0.2.1-rc.3 (from v0.6.2), 0.2.1-rc.2 (from v0.6.0), 0.2.0-rc.2 (v0.4.0) and 0.1.5-rc.1 (v0.3.17), verified on **0.1.0-rc.8** (2026-08-20, Windows, real-profile install + Web routes / client bundle / session-history RPC / end-to-end LLM call), re-verified on **0.1.1-rc.2** (2026-08-27), and adapted + verified on **0.1.2-rc.1 / 0.1.2-alpha.5** (2026-09-05/06), on **0.1.5-rc.1** (2026-09-10, real-profile end-to-end smoke tests: composition layer, route SSE, client bundle, composer button and result panel, settings card), and on **0.1.5-rc.2** (2026-09-11, full-chain re-verification: composition-layer injection, Host load, route contract 405/400/200, end-to-end SSE with 155 delta frames, all four strategy paths, client bundle slots and settings-card API — all passing, 69 tests green). **0.2.1-rc.2** was adapted on 2026-10-18 (item-by-item inspection of the `app.asar` runtime; typecheck and four suites green; the full GUI flow was not clicked through). **0.2.1-rc.3** was adapted on 2026-10-26: all six upstream commits diffed (see [`docs/dsh-021-rc3-diff.md`](docs/dsh-021-rc3-diff.md)), the type baseline moved to rc.3, and a throwaway profile booted with the official desktop app's bundled rc.3 runtime was used for a **real Web end-to-end run** (composer button, result-panel error state, settings tab and settings-card read/write; a successful LLM completion was not verified because the test account has zero balance).
|
|
130
137
|
- Verified on **macOS** via automated tests (2026-09-02, macOS 26.5 (Darwin 25.5.0), Node.js v26.0.0; after `npm install --legacy-peer-deps`, `sync:types` / `typecheck` / `build` / `npm test` all pass — 62 tests green); CI now runs typecheck and the full suite on both ubuntu-latest and macos-latest (@ruijiaang-lab, #3).
|
|
131
138
|
- **dsh-settings API compatibility layer**: the 0.1.2 line rewrote the settings API (standalone `installSettingsSection` removed, replaced by the `installSection` method on the `ctx.settings` service instance). 0.3.16+ feature-detects at runtime: uses the new interface when present, otherwise an inline equivalent (register + watch + unload fallback); when the settings service is absent it falls back to the composition-layer config.
|
|
132
139
|
- **Client type surface migrated across 0.1.2/0.1.5** (adapted in v0.3.17): the `dsh-client-runtime` package is gone upstream, so `ClientContext` is simply cordis' `Context`; `SettingsScope` moved to `@deepseek-ai/dsh-client-ui-settings/client` (its `SettingsScopeBinder` now owns the `ctx.settingsScope` Context merge — re-declaring it would conflict); the `ctx.slots` merge is provided by `@deepseek-ai/dsh-client-ui-renderer/client`. `HistoryEntry` / `ModelProviderGroup` moved into the unpublished `dsh-api-session-controller`, so the plugin now ships its own minimal structural faces in `src/client/host-faces.ts` instead of chasing upstream types.
|
|
133
140
|
- **Session model & catalog (real since v0.3.17)**: the model catalog goes through the connection-level generic RPC `session/modelCatalog` (the `/api` channel; the payload envelope requires exactly one plain-object `args` field — `{ args: {} }` for a zero-parameter method); "follow the current session" reads the official per-session model directory service `ctx.modelDirectories` (provided by `dsh-client-ui-model-selection`, the same directory the /model popup uses, whose `current` is the model the session will actually use). That service is captured through a **separate optional inject** — folding it into the main inject would leave clients waiting forever on hosts without it; when absent the plugin falls back to Host route resolution.
|
|
134
|
-
- **Session history (context)
|
|
141
|
+
- **Session history (context) now works on 0.2.x (fixed in v0.6.0)**: the legacy `connection.api.sessions.history` face was never implemented upstream (absent across 0.1.0-rc.7 → 0.2.2), so "carry recent conversation" silently degraded through v0.5.0. Since 0.2.0/0.2.1 the plugin reads the **session event window** instead: `ctx.sessions.binding(sessionId).eventSource` already holds the host-seeded tail page (`maxMessages:500`, at least 2 turns / 50 messages; `loadOlder()` pages further back) as `{type:'event', event}` entries, from which it extracts the last 4 real user messages plus 4 assistant replies. Note that the `session/page` RPC was replaced by `session/events` in 0.2.2 (previously it required the `throughSeq` upper bound from a follow opening frame — a cold call with `-1` makes `paginate()` compute `end=0` and return an empty page), so the plugin never uses it; the `session/modelCatalog` RPC and the event window it does use both remain in 0.2.2-rc.1. The service is captured through its own **optional inject**, so 0.1.x hosts keep the old degradation ladder (event window → legacy query face → no context).
|
|
142
|
+
- **0.2.1-rc.5 adaptation notes (v0.6.3)**: rc.4/rc.5 are again purely additive — `src/` needs zero behavior changes. The four host surfaces the plugin relies on (both composer slots still `list`/`session`, the composer standard props, `settings.plugins.tab` in both types and runtime, and the still-absent legacy `settings.plugin.item`) are byte-identical to rc.3. The only real code changes land in `ui-chat` (thinking blocks gained `rawText`; the plugin occupies no `conversation.chat.*` slot and has zero type-graph references to it) and in the ui-conversation view-tab tooltips (the contract/facade/apply blobs are identical between the two versions). This release is declaration-only adaptation: the type baseline (the 19 `sync:types` packages plus devDeps) moved to 0.2.1-rc.5, `package-lock.json` was regenerated, and description/version/docs were updated; a real rc.5 Web run additionally produced a **successful rewrite** end to end (see below).
|
|
143
|
+
- **0.2.2-rc.3 adaptation notes (v0.6.5)**: rc.2/rc.3 are **fully contract-stable and purely additive** for this plugin — `src/` needs zero changes. The declaration blocks of all three slots, the `SessionStandardProps` block, and `setDraft` / `draft` / `phase:'sending'` are **byte-identical** to rc.1 (the block hashes also match the rc.5 era); the `modelCatalog` RPC and the event-window `entries` remain; the desktop `staticModules` baseline and the ModuleLoader wrapper shape are unchanged; the vendor line (cordis 4.1.0 / schemastery 3.19.0) did not move. The real upstream changes — a new `hoc` slot kind, document-level paste routing, quote summaries, failed-generation retry ("continue"), the LLM error-taxonomy split (`HarnessError` moved into the new `dsh-error` package and the `LlmError` constructor tightened — the plugin only reads failure codes and never constructs one, so it is unaffected), session batch-append and automatic history loading (internal), and the menu-positioning rework (the plugin's panel is an inline dock card, unaffected) — all bypass the surfaces the plugin uses. This release is declaration-only adaptation: the type baseline (20 `sync:types` packages, adding `dsh-error`, plus devDeps) moved to 0.2.2-rc.3, `package-lock.json` was regenerated, and description/version/docs were updated; a real rc.3 Web run produced **two successful rewrites** end to end (4.2s / 5.3s, incl. replace/undo, settings read/write + persistence, zero console errors). Item-by-item differences: [`docs/dsh-022-rc3-diff.md`](docs/dsh-022-rc3-diff.md).
|
|
144
|
+
- **0.2.2-rc.1 adaptation notes (v0.6.4)**: 0.2.2 is **contract-stable with richer composer semantics**. The declaration blocks of all three slots (`conversation.input.right` / `conversation.input.dock` / `settings.plugins.tab`), the `SessionStandardProps` block, `InputActions.setDraft` / `InputState.draft`, every `ui-slots` `.d.ts` plus `lib/index.js`, the `ui-renderer` client types, the public `dsh-llm` method surface, and the client `staticModules` baseline are **byte-identical** to rc.5. The one behavior change is the new send semantics: the host keeps the draft until it accepts the message, the editor is read-only while sending, and `InputState.phase` gains `'sending'`; the result panel now closes as soon as the user sends, and older hosts whose `phase` lacks `'sending'` keep the previous decision path. The type baseline (19 `sync:types` packages plus devDeps) moved to 0.2.2-rc.1, `cordis` / `schemastery` followed the upstream version line, `package-lock.json` was regenerated, and a real rc.1 Web run produced a **successful rewrite** end to end (replace/undo, settings read/write, zero console errors). Item-by-item differences: [`docs/dsh-022-rc1-diff.md`](docs/dsh-022-rc1-diff.md).
|
|
145
|
+
- **0.2.1-rc.3 adaptation notes (v0.6.2)**: rc.3 is purely additive for this plugin — `src/` needs zero behavior changes for a lossless upgrade. The surfaces the plugin relies on (`conversation.input.right` / `conversation.input.dock`, still `list` / `session`; `settings.plugins.tab`; the composer standard props `useInput` / `inputActions` / `sessionId`; `ui-slots` / `ConnectionHandle` / `dsh-llm` / `ConfigFormSnapshot` / `SessionSnapshot`; package-manifest validation; the client `staticModules` baseline) are byte-identical to rc.2; ui-conversation only added the More-menu slots and the `whenDraftExists` / `appendDraft` draft-initialization API, which the plugin does not go through. This release is declaration-only adaptation: the type baseline (`sync:types`' 19 packages plus the `dsh-client-ui-slots` / `dsh-llm` devDeps) moved to 0.2.1-rc.3, `package-lock.json` was regenerated, description/version/READMEs were updated, and `test/upstream-contract.test.mjs` now pins the baseline versions and the three slot contracts in CI. Upstream behavior notes: the official API-key route now follows the `/models` listing (the set can change with the account), the official models declare a 1M context window, and a pinned model that has disappeared from the catalog ends the call with a host error (visible in the panel's error state).
|
|
146
|
+
- **0.2.1-rc.2 adaptation notes (v0.6.0)**: ① The `settings.plugin.item` slot is gone from upstream (confirmed in both the runtime bundles and the npm package), and `SlotCore.register` **throws synchronously** for an undeclared slot while `slots.inject` re-throws callback failures through `queueMicrotask` as page-level uncaught errors — the old code registered `settings.plugins.tab` and `settings.plugin.item` inside one `slots.inject` callback, which on 0.2.1 registers the tab and then throws. Both slots are now registered under **separate injects**, so an undeclared one only skips itself (`test/slot-guard.test.mjs` pins this against the real `SlotCore`). ② `ConfigFormSnapshot` dropped `mode: 'host' | 'memory'` — in-memory mode no longer exists, so the settings card copy no longer mentions it and uses `settings.readOnly` instead. ③ `package.json` gained `dsh.manifestVersion: 1` and `engines.dsh`. ④ Type baseline pinned to `0.2.1-rc.2`.
|
|
135
147
|
- **Client slot props dual form**: since 0.1.2 the composer slots are session-scoped — components read session/draft state via standard hooks (`useInput`/`useSession`), and registration uses the official two-layer shape (register inside an inject callback on the derived context, with an `inject(sessionId)` hook). Components dispatch on the props shape (hooks on 0.1.2, direct snapshots on older hosts), so both hosts share one build.
|
|
136
148
|
- **Client bundle registration id**: the loader id in `lib/client.js` must equal the plugin npm package name (the host's client-modules validates registration against it); the client inject list no longer names `dsh-client-runtime`, which 0.1.2 merged away. From 0.1.5 the bundle is served through a combined `/plugins/??<id>/client.js,…&rev=<hash>` URL — bare per-plugin paths are no longer exposed (the boot manifest's combined URL is authoritative).
|
|
137
149
|
- Protocol contract: `/dsh-prompt-optimizer/optimize` returns 400/405/409/413 as plain JSON on pre-check failure and switches to an SSE stream on success (model errors arrive as `error` events); `/dsh-prompt-optimizer/test-model` **always returns HTTP 200** with an `ok` field in the body (a probe is application-level semantics, deliberately not mapped to transport status codes) — integrate against `ok`, not the status code.
|
|
@@ -152,16 +164,18 @@ dsh plugin --profile web remove @y1x1n/dsh-prompt-optimizer
|
|
|
152
164
|
|
|
153
165
|
## Verification status
|
|
154
166
|
|
|
155
|
-
Verified in a real environment (dsh 0.1.0-rc.8 tested + 0.1.1-rc.2 re-verified, Windows — see Compatibility); macOS automated verification passed (2026-09-02, macOS 26.5, all 62 tests green, and CI now permanently runs the full suite on macos-latest); **v0.3.16 completed end-to-end verification on the 0.1.2 line** (dsh 0.1.2-rc.1 / 0.1.2-alpha.5: composer button, result panel, settings card, optimize route and SSE); **v0.3.17 completed end-to-end verification on 0.1.5-rc.1** (2026-09-10, Windows, real profile + browser-driven: the composer「Optimize」button enables with input, the panel opens on click and passes the upstream error through SSE, and the settings card shows both the collapsed summary and the full controls), **and a full-chain re-verification on 0.1.5-rc.2** (2026-09-11: composition-layer injection, Host load, route contract, end-to-end SSE, all four strategy paths, client bundle slots and settings-card API — every item passing); v0.3.9–0.3.11 were additionally verified end-to-end on a **third-party free model** (openrouter `minimax/minimax-m3:free`, which emits no marker format): both strategies, element-by-element fidelity, `[TODO]` markers, memory chain, and cancel-keeps-content all behave as designed — and this live testing is what surfaced the fast-mode false-positive fixed in v0.3.10/11.
|
|
167
|
+
**v0.6.5 was verified end-to-end on a real 0.2.2-rc.3 Web UI** (2026-11-16, Windows, an independent profile booted with the official desktop app bundled rc.3 runtime CLI, driven by headless Chrome/CDP): the Host log shows `[dsh-prompt-optimizer] loaded`; the composer "Optimize" button starts disabled and becomes enabled once a draft is typed; clicking it streams the output and **produces a successful rewrite in 4.2s / 5.3s across two runs**, with the badge reading `magpie / trae-cn/deepseek-v4.1-flash-max · 4.2s` (the attached screenshot is the first run) and the panel offering "Replace input / Copy / Re-optimize / Close"; replace-then-undo works (the panel shows "Replaced ✓" after replace, and undo restores the original draft); the Settings → Built-in plugins → "Prompt optimizer" tab and the full settings card render, the model dropdown lists the whole host catalog, and switching the output language zh → en → zh persists into the profile's `cordis.patch.yml` each time; the browser console recorded zero errors and zero uncaught exceptions. **v0.6.4 was verified end-to-end on a real 0.2.2-rc.1 Web UI** (2026-11-11, Windows, an independent profile booted with the official desktop app bundled rc.1 runtime CLI, driven by headless Chrome/CDP): the Host log shows `[dsh-prompt-optimizer] loaded`; the composer "Optimize" button starts disabled and becomes enabled once a draft is typed; clicking it streams the output and **produces a successful rewrite in 13.4s / 5.7s across two runs**, with the badge reading `magpie / trae-cn/deepseek-v4.1-flash-max · 5.7s` and the panel offering "Replace input / Copy / Re-optimize / Close"; replace-then-undo works; the Settings → Built-in plugins → "Prompt optimizer" tab and the full settings card render, the model dropdown lists the whole host catalog, and switching the output language persists into the profile's `cordis.patch.yml`; the browser console recorded zero errors and zero uncaught exceptions. **v0.6.3 was verified end-to-end on a real 0.2.1-rc.5 Web UI** (2026-10-31, Windows, an independent profile booted with the official desktop app bundled rc.5 runtime CLI, driven by headless Chrome/CDP): the Host log shows `[dsh-prompt-optimizer] loaded`; the composer "Optimize" button starts disabled and becomes enabled once a draft is typed; clicking it streams the output and **produces a successful rewrite in ~6-7s**, with the panel offering "Replace input / Copy / Re-optimize / Close" and the badge reading `magpie / trae-cn/deepseek-v4.1-flash-max · 5.9s` (the other run took 7.0s); the Settings → Built-in plugins → "Prompt optimizer" tab and the full settings card render, with the model dropdown listing the whole host catalog; the browser console recorded zero errors. **v0.6.2 was verified end-to-end on a real 0.2.1-rc.3 Web UI** (2026-10-26, Windows, throwaway profile booted with the official desktop app's bundled rc.3 runtime CLI, browser-driven): after installing the released tgz, the Host log showed `[dsh-prompt-optimizer] loaded` and the routes were registered; the composer "Optimize" button appeared with input and carried this plugin's style class; clicking it opened the result panel and the request went through the Host route and SSE, returning the upstream error (`QUOTA: Insufficient Balance` — the test account has zero balance, so this verified the error state and the pass-through path); the "Built-in plugins → Prompt optimizer" tab and settings card rendered fully, and switching the output language persisted into the profile's `cordis.patch.yml`. Verified in a real environment (dsh 0.1.0-rc.8 tested + 0.1.1-rc.2 re-verified, Windows — see Compatibility); macOS automated verification passed (2026-09-02, macOS 26.5, all 62 tests green, and CI now permanently runs the full suite on macos-latest); **v0.3.16 completed end-to-end verification on the 0.1.2 line** (dsh 0.1.2-rc.1 / 0.1.2-alpha.5: composer button, result panel, settings card, optimize route and SSE); **v0.3.17 completed end-to-end verification on 0.1.5-rc.1** (2026-09-10, Windows, real profile + browser-driven: the composer「Optimize」button enables with input, the panel opens on click and passes the upstream error through SSE, and the settings card shows both the collapsed summary and the full controls), **and a full-chain re-verification on 0.1.5-rc.2** (2026-09-11: composition-layer injection, Host load, route contract, end-to-end SSE, all four strategy paths, client bundle slots and settings-card API — every item passing); v0.3.9–0.3.11 were additionally verified end-to-end on a **third-party free model** (openrouter `minimax/minimax-m3:free`, which emits no marker format): both strategies, element-by-element fidelity, `[TODO]` markers, memory chain, and cancel-keeps-content all behave as designed — and this live testing is what surfaced the fast-mode false-positive fixed in v0.3.10/11.
|
|
156
168
|
|
|
157
169
|
- Composition-layer load: `--dump-config` shows the `# == @y1x1n/dsh-prompt-optimizer` layer;
|
|
158
170
|
- Host: startup log `[dsh-prompt-optimizer] loaded`; both routes behave correctly across their 400/405/409/413 paths; SSE streaming verified live;
|
|
159
171
|
- Client: the bundle is picked up by client-modules and listed in the page boot manifest (from 0.1.5 served through the combined `/plugins/??<ids>&rev=<hash>` URL), with the plugin row present in the module list;
|
|
160
|
-
- End to end: a real `ctx.llm` call
|
|
161
|
-
- Automated tests (`npm test`,
|
|
172
|
+
- End to end: a real `ctx.llm` call completes "analysis + rewrite" with correct marker parsing (`wellFormed: true`). **The v0.6.5 rc.3 re-run produced a successful rewrite** (`provider: magpie`, `model: trae-cn/deepseek-v4.1-flash-max`, 4.2s / 5.3s across two runs); the v0.6.4 rc.1 re-run also produced one (13.4s / 5.7s across two runs); the v0.6.3 rc.5 re-run also produced one (`provider: magpie`, `wellFormed: true`, `truncated: false`); the v0.6.2 rc.3 re-run verified only the upstream error state and panel pass-through because the test account had zero balance.
|
|
173
|
+
- Automated tests (`npm test`, 100 cases):
|
|
162
174
|
- `test/smoke.mjs`: 35 Host smoke cases (real cordis Context + mocked services: route-resolution priority, empty/malformed config, 400/405/409/413, non-object JSON body rejection, SSE event flow, post-header errors not escaping the route, concurrency cap 429, carrier service mounted exactly once, max-tokens truncation, timeout, fast mode and the new default, reasoning clamp (by intensity rank, not display order), legacy-settings normalization, connectivity test, session-stamp fallback, fallback chain with fallback-reason passthrough, tool-calls guard, auto output cap, context injection and hard switch, strategy selection, memory-chain injection and truncation, origin fence);
|
|
163
|
-
- `test/prompt.test.mjs`:
|
|
164
|
-
- `test/controller.test.mjs`:
|
|
175
|
+
- `test/prompt.test.mjs`: 25 meta-prompt parsing cases (marker whitespace variants, degradation paths, empty OPTIMIZED segment not falling back to raw text, marker text never entering the result, unclosed think blocks not polluting parsing, partial-stream parsing, both output orders, stream-buffer compaction (single-segment and two-stage), CJK token-estimation coverage, context payload and budgeting, strategy fork, fidelity rules and examples, memory-chain payload);
|
|
176
|
+
- `test/controller.test.mjs`: 29 client pure-logic cases (SSE frame parsing with corrupt-frame skipping, frame coalescing, interrupted connections, session-query skipping, undo flow, retry preserving the slash prefix, close-abort, cancel keeping partial output plus its state gate, client timeout watchdog, history extraction filtering and degradation, slash-prefix splitting and bare-command rejection, memory-chain passing and gates, send-to-close decisions (incl. the 0.2.2 `sending` phase), duration recording, user-first context sampling, live preview and compaction fallback under the new output order);
|
|
177
|
+
- `test/slot-guard.test.mjs`: 5 slot-guard cases (`s1–s4` pin the "undeclared slot throws + separate inject guards" boundary against the real upstream `SlotCore`; `s5` loads the real `lib/client.js` and calls the real `apply()`);
|
|
178
|
+
- `test/upstream-contract.test.mjs`: 6 upstream-contract cases (new in v0.6.2, extended in v0.6.4 with `u3b`, version-pin check covers 20 packages from v0.6.5: baseline package versions match the pins, both composer slots stay list/session, the composer standard props are still declared, `setDraft` / `InputState.draft` / `phase:'sending'` remain, `settings.plugins.tab` stays declared in both types and runtime, and the legacy `settings.plugin.item` is still absent).
|
|
165
179
|
|
|
166
180
|
## How it works
|
|
167
181
|
|
|
@@ -192,7 +206,7 @@ npm install --legacy-peer-deps # install deps and trigger the build
|
|
|
192
206
|
npm run sync:types # sync the client type packages (see below)
|
|
193
207
|
npm run typecheck # tsc --noEmit
|
|
194
208
|
npm run build # produces lib/{index,client,prompt,controller}.js
|
|
195
|
-
npm test # smoke + prompt + controller suites
|
|
209
|
+
npm test # smoke + prompt + controller + slot-guard + upstream-contract suites
|
|
196
210
|
```
|
|
197
211
|
|
|
198
212
|
### About `sync:types`
|
package/README.md
CHANGED
|
@@ -110,29 +110,41 @@ dsh plugin --profile web remove @y1x1n/dsh-prompt-optimizer
|
|
|
110
110
|
|
|
111
111
|
## 兼容性
|
|
112
112
|
|
|
113
|
-
> **当前版本(v0.5
|
|
113
|
+
> **当前版本(v0.6.5)适配 DeepSeek Harness**:
|
|
114
114
|
>
|
|
115
|
-
> | dsh 版本 | 优化路由 / 模型调用 | 设置页(含 GitHub 入口) | 发送栏按钮 / 结果面板 |
|
|
116
|
-
>
|
|
117
|
-
> | **0.2.
|
|
118
|
-
> | **0.
|
|
119
|
-
> | **0.1
|
|
120
|
-
> | **0.1
|
|
121
|
-
> | **0.
|
|
115
|
+
> | dsh 版本 | 优化路由 / 模型调用 | 设置页(含 GitHub 入口) | 发送栏按钮 / 结果面板 | 携带会话上下文 |
|
|
116
|
+
> |---|---|---|---|---|
|
|
117
|
+
> | **0.2.2-rc.3(Web + 官方桌面端运行时)** | ✅ 实测(成功产出优化稿) | ✅ 实测(标签页 + 设置卡读写) | ✅ 实测 | ✅ 契约核对 |
|
|
118
|
+
> | **0.2.2-rc.1(Web + 官方桌面端运行时)** | ✅ 实测(v0.6.4,成功产出优化稿) | ✅ 实测(标签页 + 设置卡读写) | ✅ 实测 | ✅ 契约核对 |
|
|
119
|
+
> | **0.2.1-rc.5(Web + 官方桌面端运行时)** | ✅ 实测(成功产出优化稿) | ✅ 实测(标签页 + 设置卡渲染) | ✅ 实测 | ✅ 契约核对 |
|
|
120
|
+
> | **0.2.1-rc.3(Web + 官方桌面端运行时)** | ✅ 实测(路由/SSE/错误态) | ✅ 实测(标签页 + 设置卡读写) | ✅ 实测 | ✅ 契约核对 |
|
|
121
|
+
> | **0.2.1-rc.2(Web + 官方桌面端)** | ✅ 产物核对 | ✅ 产物核对(含槽位注册修复) | ✅ 产物核对 | ✅ 新增可用 |
|
|
122
|
+
> | **0.2.0-rc.2(Web + 官方桌面端)** | ✅ 实测 | ✅ 实测 | ✅ 实测 | ✅ |
|
|
123
|
+
> | **0.1.5-rc.2** | ✅ 实测 | ✅ 实测 | ✅ 实测 | 降级(无 `ctx.sessions`) |
|
|
124
|
+
> | **0.1.5-rc.1** | ✅ 实测 | ✅ 实测 | ✅ 实测 | 降级(无 `ctx.sessions`) |
|
|
125
|
+
> | **0.1.2-rc.1 / 0.1.2-alpha.5** | ✅ 实测 | ✅ 实测 | ✅ 实测 | 降级(无 `ctx.sessions`) |
|
|
126
|
+
> | **0.1.1-rc.2 及以下**(0.1.0-rc.7+) | ✅ 实测 | ✅ 实测 | ✅ 实测 | 降级(无 `ctx.sessions`) |
|
|
122
127
|
>
|
|
123
|
-
> 同一份构建覆盖 0.1.0-rc.7 至 0.2.
|
|
128
|
+
> 同一份构建覆盖 0.1.0-rc.7 至 0.2.2 全线;`package.json` 现声明 `engines.dsh: ">=0.1.0-rc.7 <0.3.0-0"`,由宿主在启动期校验(含 prerelease),把 0.3.x 显式排除在外。
|
|
129
|
+
>
|
|
130
|
+
> **关于「产物核对」**:v0.6.0 的 0.2.1-rc.2 支持是对**上游随包发布的真实运行时**逐项核对得到的(槽位声明、`SlotCore` 抛错行为、`ctx.sessions` 提供方、`session/page` 分页语义、`ConfigFormSnapshot` 形状、`engines.dsh` 校验、client baseline 静态模块表),并配有针对性回归测试;当时未在 0.2.1-rc.2 的真实 GUI 里点通全流程(本机实例需要 launch token)。**v0.6.2 的 0.2.1-rc.3 支持升级为真实端到端实测**:用官方桌面端自带的 rc.3 runtime CLI 引导临时 profile 并安装发布的 tgz,在页面上确认了发送栏「优化」按钮、`settings.plugins.tab` 标签页与设置卡渲染、设置写入落盘到 profile 补丁;优化请求确实到达 Host 路由并经 SSE 返回上游错误(测试账户余额为 0,因此验证的是错误态而非成功输出)。逐项差异核对见 [`docs/dsh-021-rc3-diff.md`](docs/dsh-021-rc3-diff.md)。此标注自 v0.3.15 起在每个 Release 说明中固定维护,更早 Release 的说明已回溯补注。
|
|
124
131
|
|
|
125
132
|
- **v0.4.0 适配 dsh 0.2.0-rc.2(2026-10-03,Windows,真实 profile 端到端)**:①设置迁移——0.2.0 移除 `settingsScope` 服务与 `settings.plugin.item` 槽位,设置改由宿主按插件 Config schema 自动生成表单;本插件 Config 全字段声明 `.volatile()`(volatile 字段经引用 cell 原位更新,**修改设置不重挂载插件**),客户端经 `configForms` 读写,设置卡同时注册 0.2.0 的 `settings.plugins.tab` 与 0.1.x 的 `settings.plugin.item` 双槽位,宿主各自渲染认识的那一个;②设置卡按 0.2.0 官方设计语言重做(平铺行布局、官方同款分段控件与开关、`configure({auto:false})` 关闭宿主原生表单避免重复);③消息源 `kind:'plugin'` 以结构断言跨过 0.2.0 收窄后的联合类型(运行时按 merge-extensible 容忍);④已在 **0.2.0-rc.2 Web**(按钮、SSE 面板、模型目录 RPC、设置卡读写与撤销、配置写入 profile 补丁且插件不重启)与**官方桌面端**(Electron `DeepSeek Harness 0.2.0-rc.2`,desktop profile 经应用自带 CLI 安装,发送栏按钮与设置卡 UIA 实测)通过验证。
|
|
126
133
|
- **llm 调用标注会话 id(v0.4.0 修复 opencode)**:opencode(`opencode-go`)要求请求携带 `x-opencode-session` 会话头,pi-ai 适配器仅在 `GenerateOptions.sessionId` 存在时注入——插件的一次性调用原本不带,被 API 以缺少请求头拒绝(表现为 opencode 无法测试连接/优化)。现客户端优化请求携带会话 id 由 Host 标注(费用等会话级计量随之正确归属),探活标注固定合成 id;其余适配器视其为模型不可见的传输元数据,不外发。
|
|
127
134
|
- **会话标注恒存在(v0.5.0 补强 opencode)**:v0.4.0 的标注依赖客户端携带会话 id,个别宿主形态不向槽位组件投递 `sessionId` 时请求体会缺失、opencode 依旧报「缺少请求头」。0.5.0 起 Host 侧兜底:客户端未携带(或为空白)时标注合成 id `prompt-optimizer-one-shot`,任何调用路径都满足会话头要求;客户端正常携带时仍用真实会话 id(计量归属不变)。注意旧 profile 里装的插件(0.3.x 及更早)不含修复,升级到 0.5.0+ 并重启宿主/刷新页面。
|
|
128
135
|
- **官方桌面端安装**:桌面应用首次启动初始化 `desktop` profile 后,完全退出应用,用应用自带 CLI 安装并重启:`"E:\Deepseek-Harness\resources\runtime\cli\bin\dsh.cmd" plugin --profile desktop add @y1x1n/dsh-prompt-optimizer`(macOS/Linux 路径见应用安装目录);不要用 npm 版 CLI 管理桌面保留 profile。
|
|
129
136
|
|
|
130
|
-
- 开发基线:`@deepseek-ai/*` **0.2.
|
|
137
|
+
- 开发基线:`@deepseek-ai/*` **0.2.2-rc.3**(v0.6.5 起,`sync:types` 20 包与 devDeps 钉同一版本,新增 `dsh-error`;`cordis` devDep `^4.1.0`、`schemastery` 运行时依赖 `^3.19.0` 随上游 vendor 保持不变);此前基线为 **0.2.2-rc.1**(v0.6.4 起)、**0.2.1-rc.5**(v0.6.3 起)、**0.2.1-rc.3**(v0.6.2 起)、**0.2.1-rc.2**(v0.6.0 起)、**0.2.0-rc.2**(v0.4.0 起)、**0.1.5-rc.1**(v0.3.17 起)。已实测通过 **0.1.0-rc.8**(2026-08-20,Windows,真实 profile 安装 + Web 路由/客户端 bundle/会话历史 RPC/端到端 LLM 调用)、复测通过 **0.1.1-rc.2**(2026-08-27)、适配并通过 **0.1.2-rc.1 与 0.1.2-alpha.5**(2026-09-05/06)、**0.1.5-rc.1**(2026-09-10,真实 profile 端到端冒烟:组合层注入、路由 SSE、client bundle、发送栏按钮与结果面板、设置卡片)、**0.1.5-rc.2**(2026-09-11,全链路复测:组合层注入、Host 加载、路由契约 405/400/200、SSE 端到端 155 帧 delta、四种策略路径、client bundle 槽位与设置卡 API 全部通过,69 项测试全绿)。**0.2.1-rc.2** 于 2026-10-18 完成适配(对上游 `app.asar` 运行时逐项核对,`typecheck` 与四套测试全绿;未在真实 GUI 点通全流程)。**0.2.1-rc.3** 于 2026-10-26 完成适配:上游 6 个 commit 逐项差异核对(见 [`docs/dsh-021-rc3-diff.md`](docs/dsh-021-rc3-diff.md))、类型基线升到 rc.3,并用官方桌面端自带的 rc.3 runtime 引导临时 profile 完成**真实 Web 端到端**(发送栏按钮、结果面板错误态、设置标签页与设置卡读写;LLM 成功输出受测试账户余额限制未验证)。
|
|
131
138
|
- 已在 **macOS** 端通过自动化实测(2026-09-02,macOS 26.5(Darwin 25.5.0),Node.js v26.0.0,`npm install --legacy-peer-deps` 后 `sync:types` / `typecheck` / `build` / `npm test` 全部通过,62 项测试全绿);CI 现同时在 ubuntu-latest 与 macos-latest 上跑 typecheck + 全量测试(@ruijiaang-lab,#3)。
|
|
132
139
|
- **dsh-settings API 兼容层**:0.1.2 线重写了设置 API(独立函数 `installSettingsSection` 移除,改为 `ctx.settings` 服务的 `installSection` 方法)。0.3.16+ 运行时按能力探测自动分派:新 API 存在则走新接口,否则内联等价实现(register+watch+卸载回落),settings 服务整体缺席时回落组合层配置。
|
|
133
140
|
- **客户端类型面随 0.1.2/0.1.5 迁移**(v0.3.17 适配):`dsh-client-runtime` 包已从上游移除,`ClientContext` 即 cordis 的 `Context`;`SettingsScope` 迁至 `@deepseek-ai/dsh-client-ui-settings/client`(其 `SettingsScopeBinder` 自带 `ctx.settingsScope` 的 Context 合并,插件不再重复声明,否则合并冲突);`ctx.slots` 的合并由 `@deepseek-ai/dsh-client-ui-renderer/client` 提供。`HistoryEntry` / `ModelProviderGroup` 迁入未发布的 `dsh-api-session-controller`,插件改在 `src/client/host-faces.ts` 自带最小结构面,不再追上游类型。
|
|
134
141
|
- **会话模型与目录(v0.3.17 起真实可用)**:模型目录走连接层通用 RPC `session/modelCatalog`(`/api` 通道,载荷信封要求恰好一个纯对象 `args` 字段,零参方法即 `{ args: {} }`);「跟随会话」读取官方会话模型目录服务 `ctx.modelDirectories`(`dsh-client-ui-model-selection` 提供,与 /model 弹窗共用同一份目录,其 `current` 即会话实际将使用的模型)。该服务经**独立的可选 inject** 捕获——不能并进主 inject,否则无此服务的宿主会让客户端永远等不到就绪;缺席时回落 Host 回退解析。
|
|
135
|
-
- **会话历史(上下文)
|
|
142
|
+
- **会话历史(上下文)在 0.2.x 上已可用(v0.6.0 修复)**:`connection.api.sessions.history` 这一旧查询面上游从未实现过(0.1.0-rc.7 → 0.2.2 全线都不提供),所以 v0.5.0 及更早的「携带会话近期对话」实际一直静默降级。0.2.0/0.2.1 起改走**会话事件窗口**:`ctx.sessions.binding(sessionId).eventSource` 里就是宿主已经灌好的尾部页(`maxMessages:500` / 至少 2 个 turn / 50 条消息,`loadOlder()` 再向前翻页),条目形如 `{type:'event', event}`,据此提炼最近 4 条真实用户输入 + 4 条助手回复。注意 `session/page` RPC 在 0.2.2 已被 `session/events` 取代(此前版本该 RPC 要求调用方先给出 follow 开场帧里的 `throughSeq`,冷调用传 `-1` 会被 `paginate()` 算成 `end=0` 返回空页),因此插件始终不采用它;实际使用的 `session/modelCatalog` 与事件窗口在 0.2.2-rc.1 均保持。该服务经**独立可选 inject** 捕获,0.1.x 宿主无此服务时保持旧降级路径(逐级回退:事件窗口 → legacy 查询面 → 无上下文)。
|
|
143
|
+
- **0.2.1-rc.5 适配要点(v0.6.3)**:rc.4/rc.5 对本插件仍是纯加法,`src/` 零行为改动即可无损升级。插件依赖的四个宿主面(`conversation.input.right` / `conversation.input.dock` 仍 `list`/`session`、composer 标准 props、`settings.plugins.tab` 类型 + 运行时、legacy `settings.plugin.item` 仍 0 命中)与 rc.3 逐字节相同;真实代码变化只落在 `ui-chat`(思考块新增 `rawText`,插件不占 `conversation.chat.*` 槽位、类型图 0 引用)与 `ui-conversation` 的 view-tab tooltip(契约/facade/apply 的 blob SHA 两版全同)。本版只做声明层适配:类型基线(`sync:types` 19 包 + devDeps)升到 0.2.1-rc.5、`package-lock.json` 重新生成、描述/版本/文档更新;并在真实 rc.5 Web 上完成一次**成功产出优化稿**的端到端验证(见下)。
|
|
144
|
+
- **0.2.2-rc.3 适配要点(v0.6.5)**:rc.2/rc.3 对插件是**平台契约完全不变 + 上游功能加法**,`src/` 零改动。三个槽位声明块、`SessionStandardProps` 块、`setDraft` / `draft` / `phase:'sending'` 与 rc.1 **逐字节相同**(块哈希亦与 rc.5 时代一致);`modelCatalog` RPC 与事件窗口 `entries` 仍在;桌面端 `staticModules` 基线与 ModuleLoader 包装形态不变;vendor(cordis 4.1.0 / schemastery 3.19.0)未升。上游真实变化:hoc 槽位 kind、文档级粘贴路由、引用摘要、失败重试「继续生成」、LLM 错误分类拆包(`HarnessError` 移入新包 `dsh-error`,`LlmError` 构造收紧——插件只读失败码不构造,不受影响)、会话批量追加与历史自动加载(内部)、菜单定位重构(插件面板为 dock 内联卡片,不受影响)。本版只做声明层适配:类型基线(`sync:types` 20 包,新增 `dsh-error` + devDeps)升到 0.2.2-rc.3、`package-lock.json` 重新生成、描述/版本/文档更新;并在真实 rc.3 Web 上完成两次**成功产出优化稿**的端到端验证(4.2s / 5.3s,含替换/撤回、设置卡读写与持久化、零控制台错误)。逐项差异见 [`docs/dsh-022-rc3-diff.md`](docs/dsh-022-rc3-diff.md)。
|
|
145
|
+
- **0.2.2-rc.1 适配要点(v0.6.4)**:0.2.2 对插件是**平台契约不变 + 交互语义增强**。三个槽位(`conversation.input.right` / `conversation.input.dock` / `settings.plugins.tab`)声明块、composer 标准 props(`SessionStandardProps` 块)、`InputActions.setDraft` / `InputState.draft` 与 rc.5 **逐字节相同**;`ui-slots` 全部 `.d.ts` + `lib/index.js`、`ui-renderer` 客户端类型、`dsh-llm` 公开方法面、client `staticModules` 基线均相同。本版唯一行为改动是接入 0.2.2 的发送语义:宿主确认接收前保留草稿、发送期间输入框只读,`InputState.phase` 新增 `'sending'`;结果面板据此在点击发送时立即关闭,旧宿主 phase 不含 `'sending'` 则保持原判定。类型基线(`sync:types` 19 包 + devDeps)升到 0.2.2-rc.1,`cordis`/`schemastery` 随上游版本线升级,`package-lock.json` 重新生成;并在真实 rc.1 Web 上完成一次**成功产出优化稿**的端到端验证(含替换/撤回、设置卡读写、零控制台错误)。逐项差异见 [`docs/dsh-022-rc1-diff.md`](docs/dsh-022-rc1-diff.md)。
|
|
146
|
+
- **0.2.1-rc.3 适配要点(v0.6.2)**:rc.3 对本插件是纯加法,`src/` 零行为改动即可无损升级——插件依赖的 `conversation.input.right` / `conversation.input.dock`(仍 `list` / `session`)、`settings.plugins.tab`、composer 标准 props(`useInput` / `inputActions` / `sessionId`)、`ui-slots` / `ConnectionHandle` / `dsh-llm` / `ConfigFormSnapshot` / `SessionSnapshot`、包清单校验与 client `staticModules` 基线均与 rc.2 逐字节相同;ui-conversation 仅新增「更多菜单」槽位与草稿初始化 `whenDraftExists` / `appendDraft`(插件不经过该 API)。本版只做声明层适配:类型基线(`sync:types` 19 包 + devDeps `dsh-client-ui-slots` / `dsh-llm`)升到 0.2.1-rc.3、`package-lock.json` 重新生成、描述/版本/README 更新,并新增 `test/upstream-contract.test.mjs` 把钉版版本与三个槽位契约锁进 CI。上游行为变化提示:官方 API-key 路由的模型列表改为跟随 `/models`(集合可能随账号变化),官方模型上下文窗口标注为 1M;若设置卡固定了已下线模型,调用会以宿主错误结束(面板 error 态可见)。
|
|
147
|
+
- **0.2.1-rc.2 适配要点(v0.6.0)**:①`settings.plugin.item` 槽位已被上游彻底移除(运行时 bundle 与 npm 包双向确认),而 `SlotCore.register` 对未声明槽位是**同步抛错**、`slots.inject` 的异常还会被 `queueMicrotask` 抛成页面级未捕获错误——旧实现把 `settings.plugins.tab` 与 `settings.plugin.item` 放在同一个 `slots.inject` 回调里,在 0.2.1 上会先注册成功再抛错;现改为**两个槽位各自独立 inject**,任一未声明都只跳过自己(`test/slot-guard.test.mjs` 用真实 `SlotCore` 固化该边界)。②`ConfigFormSnapshot` 删除了 `mode: 'host' | 'memory'`,内存模式不复存在,设置卡文案随之去掉「内存模式」措辞并改用 `settings.readOnly`。③`package.json` 补 `dsh.manifestVersion: 1` 与 `engines.dsh`。④类型基线(baseline)钉到 `0.2.1-rc.2`。
|
|
136
148
|
- **客户端槽位 props 双形态**:0.1.2 起 composer 槽位改为 session scope,组件经 standard hooks(`useInput`/`useSession`)读取会话与草稿状态,注册需采用「注入回调内 scope 化注册 + `inject(sessionId)` 钩子」的官方双层形态。组件按 props 形态自动分派(0.1.2 走 hooks,旧版读直传快照),两种宿主共用同一份构建。
|
|
137
149
|
- **client bundle 注册 id**:`lib/client.js` 的 loader id 必须等于插件 npm 包名(宿主 client-modules 按包名校验注册);client 注入列表已随 0.1.2 移除已合并的 `dsh-client-runtime`。0.1.5 起 bundle 以 `/plugins/??<id>/client.js,…&rev=<hash>` 组合 URL 提供,单插件裸路径不再单独暴露(以 boot manifest 里的组合 URL 为准)。
|
|
138
150
|
- HTTP 载体服务名在发布版间漂移过(npm 0.0.1-rc.x 类型包叫 `httpServer`,0.1.0-rc.x 运行时叫 `webServer`):本插件用 `ctx.inject` 同时等待两个名字,且不做静态硬依赖——即使服务名再次变化,也只会使本插件的路由不注册(10 秒后日志告警),不会拖垮整个 Harness 启动。
|
|
@@ -153,16 +165,18 @@ dsh plugin --profile web remove @y1x1n/dsh-prompt-optimizer
|
|
|
153
165
|
|
|
154
166
|
## 验证状态
|
|
155
167
|
|
|
156
|
-
|
|
168
|
+
**v0.6.5 在真实 0.2.2-rc.3 Web 端到端验证**(2026-11-16,Windows,官方桌面端自带的 rc.3 runtime CLI 引导独立 profile + 无头 Chrome/CDP 真实驱动):Host 日志 `[dsh-prompt-optimizer] loaded`;发送栏「优化」按钮随草稿输入由 disabled 变 enabled;点击后流式输出,两次实测分别 **4.2s / 5.3s 成功产出优化稿**,徽章 `magpie / trae-cn/deepseek-v4.1-flash-max · 用时 4.2s`(截图为首次运行),面板出现「替换输入框 / 复制 / 重新优化 / 关闭」;「替换输入框 → 撤回」路径正常(替换后面板显示「已替换 ✓」,撤回恢复原文);设置 → 内置插件 → 「提示词优化」标签页与设置卡完整渲染,模型下拉列出宿主全部目录,输出语言 zh → en → zh 切换均写入 profile 的 `cordis.patch.yml`;浏览器控制台零 error、零未捕获异常。**v0.6.4 在真实 0.2.2-rc.1 Web 端到端验证**(2026-11-11,Windows,官方桌面端自带的 rc.1 runtime CLI 引导独立 profile + 无头 Chrome/CDP 真实驱动):Host 日志 `[dsh-prompt-optimizer] loaded`;发送栏「优化」按钮随草稿输入由 disabled 变 enabled;点击后流式输出,两次实测分别 **13.4s / 5.7s 成功产出优化稿**,徽章 `magpie / trae-cn/deepseek-v4.1-flash-max · 用时 5.7s`,面板出现「替换输入框 / 复制 / 重新优化 / 关闭」;「替换输入框 → 撤回」路径正常;设置 → 内置插件 → 「提示词优化」标签页与设置卡完整渲染,模型下拉列出宿主全部目录,切换输出语言写入 profile 的 `cordis.patch.yml`;浏览器控制台零 error、零未捕获异常。**v0.6.3 在真实 0.2.1-rc.5 Web 端到端验证**(2026-10-31,Windows,官方桌面端自带的 rc.5 runtime CLI 引导独立 profile + 无头 Chrome/CDP 真实驱动):Host 日志 `[dsh-prompt-optimizer] loaded`;发送栏「优化」按钮随草稿输入由 disabled 变 enabled;点击后流式输出,约 6-7s **成功产出优化稿**,面板出现「替换输入框 / 复制 / 重新优化 / 关闭」,徽章 `magpie / trae-cn/deepseek-v4.1-flash-max · 用时 5.9s`(另一次实测 7.0s);设置 → 内置插件 → 「提示词优化」标签页与设置卡完整渲染,模型下拉列出宿主全部目录;浏览器控制台零错误。**v0.6.2 在真实 0.2.1-rc.3 Web 端到端验证**(2026-10-26,Windows,官方桌面端自带的 rc.3 runtime CLI 引导临时 profile + 浏览器驱动):安装发布的 tgz 后 Host 启动日志出现 `[dsh-prompt-optimizer] loaded`、路由已注册;页面发送栏「优化」按钮随输入出现并带本插件样式类;点击后结果面板打开,请求经 Host 路由与 SSE 返回上游错误(`QUOTA: Insufficient Balance`,测试账户余额为 0——错误态与透传链路由此验证);设置页「内置插件 → 提示词优化」标签页与设置卡完整渲染,切换输出语言后写入持久化到 profile 的 `cordis.patch.yml`。已在真实环境验证(dsh 0.1.0-rc.8 实测 + 0.1.1-rc.2 复测,Windows,详见「兼容性」);macOS 端自动化实测通过(2026-09-02,macOS 26.5,62 项测试全绿,CI 亦常驻 macos-latest 跑全量测试);**v0.3.16 起 0.1.2 线(dsh 0.1.2-rc.1 / 0.1.2-alpha.5)完成端到端实测**(发送栏按钮、结果面板、设置卡片、优化路由与 SSE);**v0.3.17 起 0.1.5-rc.1 完成端到端实测**(2026-09-10,Windows,真实 profile + 浏览器驱动:发送栏「优化」按钮随输入启停、点击后面板打开并按 SSE 透传上游错误、设置卡片折叠摘要与展开配置齐全),**并在 0.1.5-rc.2 上完成全链路复测**(2026-09-11:组合层注入、Host 加载、路由契约、SSE 端到端、四种策略路径、client bundle 槽位与设置卡 API 全项通过);v0.3.9–0.3.11 另在**第三方免费模型**(openrouter 的 `minimax/minimax-m3:free`,不输出标记格式)上完成端到端实测:模板/意图双策略、保真逐要素保留、待补充标记、记忆链与取消保留等行为均按设计工作,并据此修复了快速模式的格式误报。
|
|
157
169
|
|
|
158
170
|
- 组合层加载:`--dump-config` 出现 `# == @y1x1n/dsh-prompt-optimizer` 层;
|
|
159
171
|
- Host:启动日志 `[dsh-prompt-optimizer] loaded`,优化路由与测试路由的 400/405/409/413 各路径行为正确,SSE 流式输出实测正常;
|
|
160
172
|
- Client:bundle 被 client-modules 扫描收录并出现在页面 boot manifest(0.1.5 起以 `/plugins/??<ids>&rev=<hash>` 组合 URL 提供),插件行出现在模块清单中;
|
|
161
|
-
- 端到端:真实调用 `ctx.llm`
|
|
162
|
-
- 自动化测试(`npm test`,共
|
|
173
|
+
- 端到端:真实调用 `ctx.llm` 完成「分析 + 优化」,标记解析正确(`wellFormed: true`)。**v0.6.5 的 rc.3 复测已成功产出优化稿**(`provider: magpie`、`model: trae-cn/deepseek-v4.1-flash-max`、两次实测 4.2s / 5.3s);v0.6.4 的 rc.1 复测同样成功(两次实测 13.4s / 5.7s);v0.6.3 的 rc.5 复测同样成功(`provider: magpie`、`wellFormed: true`、`truncated: false`);v0.6.2 的 rc.3 复测因测试账户余额为 0,只验证到上游错误态与面板透传。
|
|
174
|
+
- 自动化测试(`npm test`,共 100 例):
|
|
163
175
|
- `test/smoke.mjs`:35 项 Host 冒烟用例(真实 cordis Context + mock 服务,覆盖路由解析优先级、空字符串/畸形配置、400/405/409/413、非对象 JSON 体拒绝、SSE 事件流、SSE 阶段错误不逃出路由、并发上限 429、载体服务只挂载一次、max-tokens 截断、超时、快速模式与默认模式、推理钳档(按强度序数而非展示顺序)、旧版设置文档归一化、连接测试、会话标注兜底、回退链与回退原因透传、tool-calls 防御、输出上限自适应、上下文注入与硬开关、策略选择、记忆链注入与截断、来源围栏);
|
|
164
|
-
- `test/prompt.test.mjs`:
|
|
165
|
-
- `test/controller.test.mjs`:
|
|
176
|
+
- `test/prompt.test.mjs`:25 项元提示词解析用例(标记空白变体、降级路径、空 OPTIMIZED 段不回退、标记字样不进入结果、未闭合思考块不污染解析、流式实况解析、新旧两种输出顺序、流式缓冲压缩(单段/两段式)、token 估算 CJK 覆盖、上下文载荷与预算收敛、策略分叉、保真纪律与示例、记忆链载荷);
|
|
177
|
+
- `test/controller.test.mjs`:29 项客户端纯逻辑用例(SSE 帧解析与损坏帧跳过、合帧节流、连接中断、跳过会话查询、撤回流转、retry 保留斜杠前缀、close 中止、cancel 取消保留已生成部分及其状态门槛、客户端超时看门狗、历史提取过滤与失败降级、斜杠前缀拆分与空命令拦截、记忆链传递与门槛、发送即关闭判定(含 0.2.2 `sending` 阶段)、耗时记录、上下文取样用户消息保底、新输出顺序的流式预览与压缩兜底);
|
|
178
|
+
- `test/slot-guard.test.mjs`:5 项槽位守卫(`s1–s4` 对真实上游 `SlotCore` 固化「未声明槽位同步抛错 + 独立 inject 守卫」边界,`s5` 加载真实 `lib/client.js` 并调用真实 `apply()`);
|
|
179
|
+
- `test/upstream-contract.test.mjs`:6 项上游契约守卫(v0.6.2 新增,v0.6.4 增补 `u3b`,v0.6.5 起钉版一致性按 20 包校验;钉版包安装版本一致性、composer 两槽位仍为 list/session、composer 标准 props 仍在、`setDraft` / `InputState.draft` / `phase:'sending'` 仍在、`settings.plugins.tab` 类型与运行时声明仍在、legacy `settings.plugin.item` 仍不存在)。
|
|
166
180
|
|
|
167
181
|
## 工作原理
|
|
168
182
|
|
|
@@ -193,7 +207,7 @@ npm install --legacy-peer-deps # 安装依赖并触发构建
|
|
|
193
207
|
npm run sync:types # 同步客户端类型包(见下)
|
|
194
208
|
npm run typecheck # tsc --noEmit
|
|
195
209
|
npm run build # 产出 lib/{index,client,prompt,controller}.js
|
|
196
|
-
npm test # smoke + prompt + controller
|
|
210
|
+
npm test # smoke + prompt + controller + slot-guard + upstream-contract 五套测试
|
|
197
211
|
```
|
|
198
212
|
|
|
199
213
|
### 关于 `sync:types`
|
package/lib/client.js
CHANGED
|
@@ -107,8 +107,11 @@ var dict = {
|
|
|
107
107
|
"panel.truncated": "\u8F93\u51FA\u8FBE\u5230 Token \u4E0A\u9650\u88AB\u622A\u65AD\u3002\u53EF\u5728\u8BBE\u7F6E\u7684\u63D2\u4EF6\u9875\u300C\u63D0\u793A\u8BCD\u4F18\u5316\u300D\u4E2D\u8C03\u9AD8\u300C\u6700\u5927\u8F93\u51FA Token\u300D\u3002",
|
|
108
108
|
"panel.notWellFormed": "\u6A21\u578B\u672A\u5B8C\u5168\u9075\u5B88\u8F93\u51FA\u683C\u5F0F,\u4EE5\u4E0A\u5185\u5BB9\u53EF\u80FD\u6DF7\u5165\u591A\u4F59\u6587\u5B57,\u66FF\u6362\u524D\u8BF7\u626B\u4E00\u773C\u3002",
|
|
109
109
|
"settings.loading": "\u8BBE\u7F6E\u52A0\u8F7D\u4E2D\u2026",
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
// 0.2.1-rc.2 删除了 ConfigFormSnapshot.mode('host' | 'memory'):设置只可能是
|
|
111
|
+
// 宿主持久化,不再有浏览器进程内内存模式。文案随之去掉「内存模式」措辞,
|
|
112
|
+
// 只保留「这份部署不对外提供该命名空间 / 当前只读」两种真实状态。
|
|
113
|
+
"settings.unavailable": "\u5F53\u524D\u5BBF\u4E3B\u672A\u5411\u6B64\u9875\u9762\u5F00\u653E\u672C\u63D2\u4EF6\u7684\u8BBE\u7F6E\u547D\u540D\u7A7A\u95F4;\u53EF\u7528\u7EC4\u5408\u5C42\u914D\u7F6E,\u6216\u5728 dsh \u8BBE\u7F6E\u4E2D\u68C0\u67E5\u63D2\u4EF6\u662F\u5426\u542F\u7528\u3002",
|
|
114
|
+
"settings.readOnly": "\u5F53\u524D\u8BBE\u7F6E\u53EA\u8BFB:\u5BBF\u4E3B\u62D2\u7EDD\u5199\u5165,\u6539\u52A8\u4E0D\u4F1A\u4FDD\u5B58\u3002",
|
|
112
115
|
"settings.undo": "\u64A4\u9500\u4E0A\u4E00\u6B21\u4FEE\u6539",
|
|
113
116
|
"settings.undoTitle": "\u6062\u590D\u8FD9\u6B21\u4FEE\u6539\u524D\u7684\u5168\u90E8\u8BBE\u7F6E(\u4EC5\u672C\u6B21\u9875\u9762\u4F1A\u8BDD\u5185\u53EF\u64A4\u9500)",
|
|
114
117
|
"settings.group.model": "\u6A21\u578B",
|
|
@@ -188,8 +191,10 @@ var dict = {
|
|
|
188
191
|
"panel.truncated": 'Output hit the token cap and was truncated. Raise "Max output tokens" in the "Prompt Optimizer" tab of the plugins settings page.',
|
|
189
192
|
"panel.notWellFormed": "The model did not fully follow the output format; the content above may contain extra text \u2014 review before replacing.",
|
|
190
193
|
"settings.loading": "Loading settings\u2026",
|
|
191
|
-
|
|
192
|
-
|
|
194
|
+
// 0.2.1-rc.2 removed ConfigFormSnapshot.mode ('host' | 'memory'): settings are
|
|
195
|
+
// always Host-persisted now, there is no process-local memory mode.
|
|
196
|
+
"settings.unavailable": "This Host does not expose the plugin settings namespace to this page; use composition config, or check that the plugin is enabled.",
|
|
197
|
+
"settings.readOnly": "Settings are read-only: the Host refuses writes, so changes will not be saved.",
|
|
193
198
|
"settings.undo": "Undo last change",
|
|
194
199
|
"settings.undoTitle": "Restore all settings to before this change (undo is session-only)",
|
|
195
200
|
"settings.group.model": "Model",
|
|
@@ -318,6 +323,11 @@ async function sessionCatalog(connection, signal) {
|
|
|
318
323
|
function legacyQueryFace(connection) {
|
|
319
324
|
return connection?.api;
|
|
320
325
|
}
|
|
326
|
+
function sessionEventEntries(sessions, sessionId) {
|
|
327
|
+
const binding = sessions?.binding?.(sessionId);
|
|
328
|
+
const window = binding?.eventSource?.getSnapshot();
|
|
329
|
+
return window?.entries;
|
|
330
|
+
}
|
|
321
331
|
|
|
322
332
|
// src/prompt.ts
|
|
323
333
|
var MARKERS = {
|
|
@@ -356,23 +366,44 @@ Do not output anything outside these markers.`;
|
|
|
356
366
|
var CONTEXT_MAX_TURNS = 8;
|
|
357
367
|
var CONTEXT_MAX_CHARS = 1600;
|
|
358
368
|
var CONTEXT_TURN_MAX_CHARS = 600;
|
|
369
|
+
var CONTEXT_MIN_USER_TURNS = 1;
|
|
370
|
+
var CONTEXT_USER_BUDGET = 800;
|
|
359
371
|
function capConversationContext(turns) {
|
|
360
372
|
const recent = turns.filter((t) => t.text.trim()).slice(-CONTEXT_MAX_TURNS).map((t) => ({
|
|
361
373
|
role: t.role,
|
|
362
374
|
text: t.text.trim().length > CONTEXT_TURN_MAX_CHARS ? `${t.text.trim().slice(0, CONTEXT_TURN_MAX_CHARS)}\u2026` : t.text.trim()
|
|
363
375
|
}));
|
|
376
|
+
if (recent.length === 0) return [];
|
|
377
|
+
const indexed = recent.map((turn, index) => ({ turn, index }));
|
|
378
|
+
const kept = /* @__PURE__ */ new Map();
|
|
364
379
|
let budget = CONTEXT_MAX_CHARS;
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
380
|
+
const users = indexed.filter((x) => x.turn.role === "user");
|
|
381
|
+
let userBudget = Math.min(CONTEXT_USER_BUDGET, budget);
|
|
382
|
+
for (let i = users.length - 1; i >= 0; i--) {
|
|
383
|
+
const { turn, index } = users[i];
|
|
384
|
+
const keptUsers = users.length - i;
|
|
385
|
+
const mustKeep = keptUsers <= CONTEXT_MIN_USER_TURNS && ![...kept.values()].some((t) => t.role === "user");
|
|
386
|
+
if (turn.text.length <= userBudget) {
|
|
387
|
+
kept.set(index, turn);
|
|
388
|
+
userBudget -= turn.text.length;
|
|
389
|
+
budget -= turn.text.length;
|
|
390
|
+
} else if (mustKeep) {
|
|
391
|
+
const slice = userBudget > 16 ? userBudget : Math.min(16, budget);
|
|
392
|
+
if (slice > 0) {
|
|
393
|
+
kept.set(index, { role: turn.role, text: `${turn.text.slice(0, slice)}\u2026` });
|
|
394
|
+
userBudget -= slice;
|
|
395
|
+
budget -= slice;
|
|
396
|
+
}
|
|
371
397
|
}
|
|
372
|
-
|
|
398
|
+
}
|
|
399
|
+
const assistants = indexed.filter((x) => x.turn.role === "assistant");
|
|
400
|
+
for (let i = assistants.length - 1; i >= 0; i--) {
|
|
401
|
+
const { turn, index } = assistants[i];
|
|
402
|
+
if (turn.text.length > budget) continue;
|
|
403
|
+
kept.set(index, turn);
|
|
373
404
|
budget -= turn.text.length;
|
|
374
405
|
}
|
|
375
|
-
return kept;
|
|
406
|
+
return [...kept.entries()].sort(([a], [b]) => a - b).map(([, turn]) => turn);
|
|
376
407
|
}
|
|
377
408
|
function findMarker(text, word, fromIndex = 0) {
|
|
378
409
|
const re = new RegExp(`<<<\\s*${word}\\s*>>>`, "g");
|
|
@@ -461,7 +492,7 @@ function joinLast(last) {
|
|
|
461
492
|
}
|
|
462
493
|
function shouldAutoClose(input) {
|
|
463
494
|
if (!input.open || input.status === "loading") return false;
|
|
464
|
-
return !input.draft.trim() || !input.prevRunning && input.running || input.queued > input.prevQueued;
|
|
495
|
+
return input.phase === "sending" || !input.draft.trim() || !input.prevRunning && input.running || input.queued > input.prevQueued;
|
|
465
496
|
}
|
|
466
497
|
function flattenText(content) {
|
|
467
498
|
if (!Array.isArray(content)) return "";
|
|
@@ -573,6 +604,18 @@ function createOptimizerController(ctx, opts = {}) {
|
|
|
573
604
|
})(),
|
|
574
605
|
(async () => {
|
|
575
606
|
if (!(opts.isContextEnabled?.() ?? true)) return void 0;
|
|
607
|
+
try {
|
|
608
|
+
const entries = sessionEventEntries(opts.getSessions?.(), sessionId);
|
|
609
|
+
if (entries?.length) {
|
|
610
|
+
const turns = extractContextTurns(entries);
|
|
611
|
+
if (turns.length) return turns;
|
|
612
|
+
console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u4E8B\u4EF6\u7A97\u53E3\u91CC\u6CA1\u6709\u53EF\u7528\u7684\u5BF9\u8BDD,\u5C1D\u8BD5\u65E7\u67E5\u8BE2\u9762");
|
|
613
|
+
} else {
|
|
614
|
+
console.warn("[dsh-prompt-optimizer] \u5F53\u524D\u4F1A\u8BDD\u6CA1\u6709\u53EF\u8BFB\u7684\u4E8B\u4EF6\u7A97\u53E3,\u5C1D\u8BD5\u65E7\u67E5\u8BE2\u9762");
|
|
615
|
+
}
|
|
616
|
+
} catch (cause) {
|
|
617
|
+
console.warn("[dsh-prompt-optimizer] \u8BFB\u53D6\u4F1A\u8BDD\u4E8B\u4EF6\u7A97\u53E3\u5931\u8D25,\u5C1D\u8BD5\u65E7\u67E5\u8BE2\u9762:", cause);
|
|
618
|
+
}
|
|
576
619
|
try {
|
|
577
620
|
const history = legacyQueryFace(ctx.connection)?.sessions?.history;
|
|
578
621
|
if (!history) {
|
|
@@ -897,6 +940,7 @@ function createResultDock(controller) {
|
|
|
897
940
|
}, [owns]);
|
|
898
941
|
const applied = state.applied;
|
|
899
942
|
const draft = input.draft ?? "";
|
|
943
|
+
const phase = input.phase;
|
|
900
944
|
const running = Boolean(session.running);
|
|
901
945
|
const queued = session.queue?.length ?? 0;
|
|
902
946
|
const prevRef = (0, import_react3.useRef)({ running, queued });
|
|
@@ -904,12 +948,12 @@ function createResultDock(controller) {
|
|
|
904
948
|
const prev = prevRef.current;
|
|
905
949
|
prevRef.current = { running, queued };
|
|
906
950
|
if (!owns) return;
|
|
907
|
-
if (shouldAutoClose({ open: true, status: state.status, draft, prevRunning: prev.running, running, prevQueued: prev.queued, queued })) {
|
|
951
|
+
if (shouldAutoClose({ open: true, status: state.status, draft, phase, prevRunning: prev.running, running, prevQueued: prev.queued, queued })) {
|
|
908
952
|
controller.close();
|
|
909
953
|
return;
|
|
910
954
|
}
|
|
911
955
|
if (applied && draft !== applied.text) controller.clearApplied();
|
|
912
|
-
}, [draft, applied, owns, state.status, running, queued]);
|
|
956
|
+
}, [draft, phase, applied, owns, state.status, running, queued]);
|
|
913
957
|
const [elapsed, setElapsed] = (0, import_react3.useState)(0);
|
|
914
958
|
(0, import_react3.useEffect)(() => {
|
|
915
959
|
if (state.status !== "loading") return;
|
|
@@ -1359,7 +1403,7 @@ function createSettingsCard(ctx, face2) {
|
|
|
1359
1403
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "dsh-po-sec", children: [
|
|
1360
1404
|
snap.status === "loading" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-hint", children: t("settings.loading") }),
|
|
1361
1405
|
snap.status === "unavailable" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-hint", children: t("settings.unavailable") }),
|
|
1362
|
-
!writable && snap.status === "ready" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-hint", children: t("settings.
|
|
1406
|
+
!writable && snap.status === "ready" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-hint", children: t("settings.readOnly") }),
|
|
1363
1407
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-group", children: t("settings.group.model") }),
|
|
1364
1408
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.model"), desc: t("settings.model.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1365
1409
|
ModelSelect,
|
|
@@ -1626,6 +1670,10 @@ function apply(ctx) {
|
|
|
1626
1670
|
ctx.inject(["modelDirectories"], (mctx) => {
|
|
1627
1671
|
modelDirectories = mctx.modelDirectories;
|
|
1628
1672
|
});
|
|
1673
|
+
let sessions;
|
|
1674
|
+
ctx.inject(["sessions"], (sctx) => {
|
|
1675
|
+
sessions = sctx.sessions;
|
|
1676
|
+
});
|
|
1629
1677
|
const settings = createSettingsFace();
|
|
1630
1678
|
ctx.inject(["configForms"], (cctx) => {
|
|
1631
1679
|
const forms = cctx.configForms;
|
|
@@ -1646,7 +1694,9 @@ function apply(ctx) {
|
|
|
1646
1694
|
// R21:看门狗 = 设置超时秒数 + 5s 余量(正常时 Host 的超时错误先到达,文案更友好)。
|
|
1647
1695
|
getWatchdogMs: () => ((scope.getSnapshot().value?.timeoutSeconds ?? 120) + 5) * 1e3,
|
|
1648
1696
|
// 「跟随会话」的模型来源(见上);点击时读取,服务缺席走 Host 回退。
|
|
1649
|
-
getSessionModelDirectories: () => modelDirectories
|
|
1697
|
+
getSessionModelDirectories: () => modelDirectories,
|
|
1698
|
+
// 「携带上下文」的会话事件窗口来源(见上);点击时读取。
|
|
1699
|
+
getSessions: () => sessions
|
|
1650
1700
|
});
|
|
1651
1701
|
ctx.inject(["slots", "connection", "remote"], (scopeCtx) => {
|
|
1652
1702
|
scopeCtx.slots.inject(
|
|
@@ -1674,33 +1724,28 @@ function apply(ctx) {
|
|
|
1674
1724
|
)
|
|
1675
1725
|
);
|
|
1676
1726
|
});
|
|
1677
|
-
|
|
1678
|
-
const
|
|
1679
|
-
const
|
|
1680
|
-
for (const dispose of settingsDisposers ?? []) dispose();
|
|
1681
|
-
settingsDisposers = null;
|
|
1682
|
-
};
|
|
1683
|
-
if (settingsDisposers) return unmount;
|
|
1727
|
+
const slotsAny = ctx.slots;
|
|
1728
|
+
const registerSettingsTab = (slotCtx) => {
|
|
1729
|
+
const slots = slotCtx.slots;
|
|
1684
1730
|
const card = createSettingsCard(slotCtx, settings.face);
|
|
1731
|
+
return slots.register(
|
|
1732
|
+
{
|
|
1733
|
+
name: "settings.plugins.tab",
|
|
1734
|
+
id: SETTINGS_ENTRY_ID,
|
|
1735
|
+
order: 30,
|
|
1736
|
+
label: () => translate("panel.title"),
|
|
1737
|
+
inject: () => ({})
|
|
1738
|
+
},
|
|
1739
|
+
card
|
|
1740
|
+
);
|
|
1741
|
+
};
|
|
1742
|
+
const registerSettingsItem = (slotCtx) => {
|
|
1685
1743
|
const slots = slotCtx.slots;
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
{
|
|
1689
|
-
name: "settings.plugins.tab",
|
|
1690
|
-
id: SETTINGS_ENTRY_ID,
|
|
1691
|
-
order: 30,
|
|
1692
|
-
label: () => translate("panel.title"),
|
|
1693
|
-
inject: () => ({})
|
|
1694
|
-
},
|
|
1695
|
-
card
|
|
1696
|
-
),
|
|
1697
|
-
slots.register({ name: "settings.plugin.item", key: SETTINGS_ENTRY_ID }, card)
|
|
1698
|
-
];
|
|
1699
|
-
return unmount;
|
|
1744
|
+
const card = createSettingsCard(slotCtx, settings.face);
|
|
1745
|
+
return slots.register({ name: "settings.plugin.item", key: SETTINGS_ENTRY_ID }, card);
|
|
1700
1746
|
};
|
|
1701
|
-
|
|
1702
|
-
slotsAny.inject("settings.plugin.item", () =>
|
|
1703
|
-
slotsAny.inject("settings.plugins.tab", () => mountSettingsCard(ctx));
|
|
1747
|
+
slotsAny.inject("settings.plugins.tab", () => registerSettingsTab(ctx));
|
|
1748
|
+
slotsAny.inject("settings.plugin.item", () => registerSettingsItem(ctx));
|
|
1704
1749
|
}
|
|
1705
1750
|
return module.exports;
|
|
1706
1751
|
}
|
package/lib/controller.js
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
function legacyQueryFace(connection) {
|
|
3
3
|
return connection?.api;
|
|
4
4
|
}
|
|
5
|
+
function sessionEventEntries(sessions, sessionId) {
|
|
6
|
+
const binding = sessions?.binding?.(sessionId);
|
|
7
|
+
const window = binding?.eventSource?.getSnapshot();
|
|
8
|
+
return window?.entries;
|
|
9
|
+
}
|
|
5
10
|
|
|
6
11
|
// src/prompt.ts
|
|
7
12
|
var MARKERS = {
|
|
@@ -40,23 +45,44 @@ Do not output anything outside these markers.`;
|
|
|
40
45
|
var CONTEXT_MAX_TURNS = 8;
|
|
41
46
|
var CONTEXT_MAX_CHARS = 1600;
|
|
42
47
|
var CONTEXT_TURN_MAX_CHARS = 600;
|
|
48
|
+
var CONTEXT_MIN_USER_TURNS = 1;
|
|
49
|
+
var CONTEXT_USER_BUDGET = 800;
|
|
43
50
|
function capConversationContext(turns) {
|
|
44
51
|
const recent = turns.filter((t) => t.text.trim()).slice(-CONTEXT_MAX_TURNS).map((t) => ({
|
|
45
52
|
role: t.role,
|
|
46
53
|
text: t.text.trim().length > CONTEXT_TURN_MAX_CHARS ? `${t.text.trim().slice(0, CONTEXT_TURN_MAX_CHARS)}\u2026` : t.text.trim()
|
|
47
54
|
}));
|
|
55
|
+
if (recent.length === 0) return [];
|
|
56
|
+
const indexed = recent.map((turn, index) => ({ turn, index }));
|
|
57
|
+
const kept = /* @__PURE__ */ new Map();
|
|
48
58
|
let budget = CONTEXT_MAX_CHARS;
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
const users = indexed.filter((x) => x.turn.role === "user");
|
|
60
|
+
let userBudget = Math.min(CONTEXT_USER_BUDGET, budget);
|
|
61
|
+
for (let i = users.length - 1; i >= 0; i--) {
|
|
62
|
+
const { turn, index } = users[i];
|
|
63
|
+
const keptUsers = users.length - i;
|
|
64
|
+
const mustKeep = keptUsers <= CONTEXT_MIN_USER_TURNS && ![...kept.values()].some((t) => t.role === "user");
|
|
65
|
+
if (turn.text.length <= userBudget) {
|
|
66
|
+
kept.set(index, turn);
|
|
67
|
+
userBudget -= turn.text.length;
|
|
68
|
+
budget -= turn.text.length;
|
|
69
|
+
} else if (mustKeep) {
|
|
70
|
+
const slice = userBudget > 16 ? userBudget : Math.min(16, budget);
|
|
71
|
+
if (slice > 0) {
|
|
72
|
+
kept.set(index, { role: turn.role, text: `${turn.text.slice(0, slice)}\u2026` });
|
|
73
|
+
userBudget -= slice;
|
|
74
|
+
budget -= slice;
|
|
75
|
+
}
|
|
55
76
|
}
|
|
56
|
-
|
|
77
|
+
}
|
|
78
|
+
const assistants = indexed.filter((x) => x.turn.role === "assistant");
|
|
79
|
+
for (let i = assistants.length - 1; i >= 0; i--) {
|
|
80
|
+
const { turn, index } = assistants[i];
|
|
81
|
+
if (turn.text.length > budget) continue;
|
|
82
|
+
kept.set(index, turn);
|
|
57
83
|
budget -= turn.text.length;
|
|
58
84
|
}
|
|
59
|
-
return kept;
|
|
85
|
+
return [...kept.entries()].sort(([a], [b]) => a - b).map(([, turn]) => turn);
|
|
60
86
|
}
|
|
61
87
|
function findMarker(text, word, fromIndex = 0) {
|
|
62
88
|
const re = new RegExp(`<<<\\s*${word}\\s*>>>`, "g");
|
|
@@ -145,7 +171,7 @@ function joinLast(last) {
|
|
|
145
171
|
}
|
|
146
172
|
function shouldAutoClose(input) {
|
|
147
173
|
if (!input.open || input.status === "loading") return false;
|
|
148
|
-
return !input.draft.trim() || !input.prevRunning && input.running || input.queued > input.prevQueued;
|
|
174
|
+
return input.phase === "sending" || !input.draft.trim() || !input.prevRunning && input.running || input.queued > input.prevQueued;
|
|
149
175
|
}
|
|
150
176
|
function flattenText(content) {
|
|
151
177
|
if (!Array.isArray(content)) return "";
|
|
@@ -257,6 +283,18 @@ function createOptimizerController(ctx, opts = {}) {
|
|
|
257
283
|
})(),
|
|
258
284
|
(async () => {
|
|
259
285
|
if (!(opts.isContextEnabled?.() ?? true)) return void 0;
|
|
286
|
+
try {
|
|
287
|
+
const entries = sessionEventEntries(opts.getSessions?.(), sessionId);
|
|
288
|
+
if (entries?.length) {
|
|
289
|
+
const turns = extractContextTurns(entries);
|
|
290
|
+
if (turns.length) return turns;
|
|
291
|
+
console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u4E8B\u4EF6\u7A97\u53E3\u91CC\u6CA1\u6709\u53EF\u7528\u7684\u5BF9\u8BDD,\u5C1D\u8BD5\u65E7\u67E5\u8BE2\u9762");
|
|
292
|
+
} else {
|
|
293
|
+
console.warn("[dsh-prompt-optimizer] \u5F53\u524D\u4F1A\u8BDD\u6CA1\u6709\u53EF\u8BFB\u7684\u4E8B\u4EF6\u7A97\u53E3,\u5C1D\u8BD5\u65E7\u67E5\u8BE2\u9762");
|
|
294
|
+
}
|
|
295
|
+
} catch (cause) {
|
|
296
|
+
console.warn("[dsh-prompt-optimizer] \u8BFB\u53D6\u4F1A\u8BDD\u4E8B\u4EF6\u7A97\u53E3\u5931\u8D25,\u5C1D\u8BD5\u65E7\u67E5\u8BE2\u9762:", cause);
|
|
297
|
+
}
|
|
260
298
|
try {
|
|
261
299
|
const history = legacyQueryFace(ctx.connection)?.sessions?.history;
|
|
262
300
|
if (!history) {
|
package/lib/index.js
CHANGED
|
@@ -118,23 +118,44 @@ function buildSystemPrompt(language, mode = "full", strategy = "template") {
|
|
|
118
118
|
var CONTEXT_MAX_TURNS = 8;
|
|
119
119
|
var CONTEXT_MAX_CHARS = 1600;
|
|
120
120
|
var CONTEXT_TURN_MAX_CHARS = 600;
|
|
121
|
+
var CONTEXT_MIN_USER_TURNS = 1;
|
|
122
|
+
var CONTEXT_USER_BUDGET = 800;
|
|
121
123
|
function capConversationContext(turns) {
|
|
122
124
|
const recent = turns.filter((t) => t.text.trim()).slice(-CONTEXT_MAX_TURNS).map((t) => ({
|
|
123
125
|
role: t.role,
|
|
124
126
|
text: t.text.trim().length > CONTEXT_TURN_MAX_CHARS ? `${t.text.trim().slice(0, CONTEXT_TURN_MAX_CHARS)}\u2026` : t.text.trim()
|
|
125
127
|
}));
|
|
128
|
+
if (recent.length === 0) return [];
|
|
129
|
+
const indexed = recent.map((turn, index) => ({ turn, index }));
|
|
130
|
+
const kept = /* @__PURE__ */ new Map();
|
|
126
131
|
let budget = CONTEXT_MAX_CHARS;
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
const users = indexed.filter((x) => x.turn.role === "user");
|
|
133
|
+
let userBudget = Math.min(CONTEXT_USER_BUDGET, budget);
|
|
134
|
+
for (let i = users.length - 1; i >= 0; i--) {
|
|
135
|
+
const { turn, index } = users[i];
|
|
136
|
+
const keptUsers = users.length - i;
|
|
137
|
+
const mustKeep = keptUsers <= CONTEXT_MIN_USER_TURNS && ![...kept.values()].some((t) => t.role === "user");
|
|
138
|
+
if (turn.text.length <= userBudget) {
|
|
139
|
+
kept.set(index, turn);
|
|
140
|
+
userBudget -= turn.text.length;
|
|
141
|
+
budget -= turn.text.length;
|
|
142
|
+
} else if (mustKeep) {
|
|
143
|
+
const slice = userBudget > 16 ? userBudget : Math.min(16, budget);
|
|
144
|
+
if (slice > 0) {
|
|
145
|
+
kept.set(index, { role: turn.role, text: `${turn.text.slice(0, slice)}\u2026` });
|
|
146
|
+
userBudget -= slice;
|
|
147
|
+
budget -= slice;
|
|
148
|
+
}
|
|
133
149
|
}
|
|
134
|
-
|
|
150
|
+
}
|
|
151
|
+
const assistants = indexed.filter((x) => x.turn.role === "assistant");
|
|
152
|
+
for (let i = assistants.length - 1; i >= 0; i--) {
|
|
153
|
+
const { turn, index } = assistants[i];
|
|
154
|
+
if (turn.text.length > budget) continue;
|
|
155
|
+
kept.set(index, turn);
|
|
135
156
|
budget -= turn.text.length;
|
|
136
157
|
}
|
|
137
|
-
return kept;
|
|
158
|
+
return [...kept.entries()].sort(([a], [b]) => a - b).map(([, turn]) => turn);
|
|
138
159
|
}
|
|
139
160
|
function buildUserPayload(draft, language, context, previous) {
|
|
140
161
|
const sections = [];
|
package/lib/prompt.js
CHANGED
|
@@ -115,23 +115,44 @@ function buildSystemPrompt(language, mode = "full", strategy = "template") {
|
|
|
115
115
|
var CONTEXT_MAX_TURNS = 8;
|
|
116
116
|
var CONTEXT_MAX_CHARS = 1600;
|
|
117
117
|
var CONTEXT_TURN_MAX_CHARS = 600;
|
|
118
|
+
var CONTEXT_MIN_USER_TURNS = 1;
|
|
119
|
+
var CONTEXT_USER_BUDGET = 800;
|
|
118
120
|
function capConversationContext(turns) {
|
|
119
121
|
const recent = turns.filter((t) => t.text.trim()).slice(-CONTEXT_MAX_TURNS).map((t) => ({
|
|
120
122
|
role: t.role,
|
|
121
123
|
text: t.text.trim().length > CONTEXT_TURN_MAX_CHARS ? `${t.text.trim().slice(0, CONTEXT_TURN_MAX_CHARS)}\u2026` : t.text.trim()
|
|
122
124
|
}));
|
|
125
|
+
if (recent.length === 0) return [];
|
|
126
|
+
const indexed = recent.map((turn, index) => ({ turn, index }));
|
|
127
|
+
const kept = /* @__PURE__ */ new Map();
|
|
123
128
|
let budget = CONTEXT_MAX_CHARS;
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
const users = indexed.filter((x) => x.turn.role === "user");
|
|
130
|
+
let userBudget = Math.min(CONTEXT_USER_BUDGET, budget);
|
|
131
|
+
for (let i = users.length - 1; i >= 0; i--) {
|
|
132
|
+
const { turn, index } = users[i];
|
|
133
|
+
const keptUsers = users.length - i;
|
|
134
|
+
const mustKeep = keptUsers <= CONTEXT_MIN_USER_TURNS && ![...kept.values()].some((t) => t.role === "user");
|
|
135
|
+
if (turn.text.length <= userBudget) {
|
|
136
|
+
kept.set(index, turn);
|
|
137
|
+
userBudget -= turn.text.length;
|
|
138
|
+
budget -= turn.text.length;
|
|
139
|
+
} else if (mustKeep) {
|
|
140
|
+
const slice = userBudget > 16 ? userBudget : Math.min(16, budget);
|
|
141
|
+
if (slice > 0) {
|
|
142
|
+
kept.set(index, { role: turn.role, text: `${turn.text.slice(0, slice)}\u2026` });
|
|
143
|
+
userBudget -= slice;
|
|
144
|
+
budget -= slice;
|
|
145
|
+
}
|
|
130
146
|
}
|
|
131
|
-
|
|
147
|
+
}
|
|
148
|
+
const assistants = indexed.filter((x) => x.turn.role === "assistant");
|
|
149
|
+
for (let i = assistants.length - 1; i >= 0; i--) {
|
|
150
|
+
const { turn, index } = assistants[i];
|
|
151
|
+
if (turn.text.length > budget) continue;
|
|
152
|
+
kept.set(index, turn);
|
|
132
153
|
budget -= turn.text.length;
|
|
133
154
|
}
|
|
134
|
-
return kept;
|
|
155
|
+
return [...kept.entries()].sort(([a], [b]) => a - b).map(([, turn]) => turn);
|
|
135
156
|
}
|
|
136
157
|
function buildUserPayload(draft, language, context, previous) {
|
|
137
158
|
const sections = [];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y1x1n/dsh-prompt-optimizer",
|
|
3
|
-
"version": "0.5
|
|
4
|
-
"description": "DeepSeek Harness 插件:在发送栏旁一键分析并优化提示词(复用当前会话模型)。适配 dsh 0.2.
|
|
3
|
+
"version": "0.6.5",
|
|
4
|
+
"description": "DeepSeek Harness 插件:在发送栏旁一键分析并优化提示词(复用当前会话模型)。适配 dsh 0.2.2-rc.3(含官方桌面端)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"cordis"
|
|
24
24
|
],
|
|
25
25
|
"engines": {
|
|
26
|
-
"node": ">=18"
|
|
26
|
+
"node": ">=18",
|
|
27
|
+
"dsh": ">=0.1.0-rc.7 <0.3.0-0"
|
|
27
28
|
},
|
|
28
29
|
"exports": {
|
|
29
30
|
".": "./lib/index.js",
|
|
@@ -40,9 +41,10 @@
|
|
|
40
41
|
"prepare": "node scripts/build.mjs",
|
|
41
42
|
"sync:types": "node scripts/sync-types.mjs",
|
|
42
43
|
"typecheck": "tsc --noEmit",
|
|
43
|
-
"test": "node test/smoke.mjs && node test/prompt.test.mjs && node test/controller.test.mjs"
|
|
44
|
+
"test": "node test/smoke.mjs && node test/prompt.test.mjs && node test/controller.test.mjs && node test/slot-guard.test.mjs && node test/upstream-contract.test.mjs"
|
|
44
45
|
},
|
|
45
46
|
"dsh": {
|
|
47
|
+
"manifestVersion": 1,
|
|
46
48
|
"bundle": {
|
|
47
49
|
"patch": "./cordis.patch.yml"
|
|
48
50
|
},
|
|
@@ -57,11 +59,12 @@
|
|
|
57
59
|
}
|
|
58
60
|
},
|
|
59
61
|
"dependencies": {
|
|
60
|
-
"@deepseek-ai/schemastery": "^3.
|
|
62
|
+
"@deepseek-ai/schemastery": "^3.19.0"
|
|
61
63
|
},
|
|
62
64
|
"devDependencies": {
|
|
63
|
-
"@deepseek-ai/cordis": "^4.0
|
|
64
|
-
"@deepseek-ai/dsh-
|
|
65
|
+
"@deepseek-ai/cordis": "^4.1.0",
|
|
66
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.3",
|
|
67
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.3",
|
|
65
68
|
"@types/node": "^20.0.0",
|
|
66
69
|
"@types/react": "^18.3.1",
|
|
67
70
|
"esbuild": "^0.24.0",
|