Passer au contenu principal
S

dsh-prompt-optimizer

stijnus/dsh-prompt-optimizer

Adds an Optimize prompt control next to the composer send button that rewrites the draft into a structured prompt (plain, sections, or role-task-goal) streamed from the session model, with Use, Undo, Copy and Close.

Installer

dsh plugin --profile web add github:stijnus/dsh-prompt-optimizer

README

dsh-prompt-rewrite

npm npm provenance test license

English · 中文

A DeepSeek Harness plugin that optimizes the prompt you are about to send.

It adds a ✨ Optimize prompt control next to the composer send button. Clicking it rewrites the current draft into a structured prompt and streams the result into a panel above the composer, with Use, Undo, Copy, and Close. Nothing is sent to the agent; the draft is only replaced when you click Use.

It runs on the model the session is already routed to (the same route the next turn would use), and it never writes to the Session log.

Prompt style

The rewritten prompt can take three shapes, chosen in Settings → General → Prompt style:

StyleOutput
plain (default)One continuous, heading-free prompt.
sections## Role / ## Task / ## Context / ## Format headings.
role-task-goalRole: / Task: / Goal: labeled lines.

The row stores a per-browser override. A profile can set the default for everyone through the plugin's Config:

- id: prompt-optimizer
  name: 'dsh-prompt-rewrite'
  config:
    outputStyle: sections

Until the row is changed, it shows that profile default; an override in the row wins for requests from that browser. The result panel names the style that produced it.

Package name: install dsh-prompt-rewrite. The GitHub repository is named dsh-prompt-optimizer, but that is not this plugin’s npm package name. The rewrite engine is oss-prompt-optimizer.

Install · Local walkthrough · Prompt styles · Implementation

Try a rewrite

After installation, enter a draft such as “Build a task list for my team” and click Optimize prompt. Review the completed result, choose Use to replace the draft, or Copy to keep it separately. Undo restores the draft captured when you clicked Use.

This is a suggested local walkthrough, not a recorded demo. Output depends on your session’s model and selected prompt style. Rewriting calls the model and may incur provider charges; it does not send the rewritten draft as a conversation turn.

Quick start

dsh plugin --profile web add dsh-prompt-rewrite

Restart the Harness (or refresh the Web UI). A ✨ Optimize prompt control appears next to the composer send button.

More from this suite: Moodboard · Composer Predictions · Move to Workspace · Workspace Status · Prompt Rewrite

⭐ If this saves you a step, a star helps the next DSH user find it.

Install

dsh plugin --profile web add dsh-prompt-rewrite

Then restart the Harness (or refresh the page for the Client half). The plugin appears in Settings → Plugins as Prompt Optimizer.

Compatibility: DSH >=0.2.1-rc.3 <0.3.0-0, Node >=20.

Market

The plugin is listed in the Stijnus market index that the desktop profile already reads, so it appears in Settings → Plugin Market next to Composer Predictions:

  • https://raw.githubusercontent.com/Stijnus/dsh-composer-predictions/main/market-index.json

This repository also publishes its own format-1 index, for anyone who wants a focused source:

  • https://raw.githubusercontent.com/Stijnus/dsh-prompt-optimizer/main/market-index.json

Market sources are cached for 10 minutes per URL by the Host, so a newly published version can take that long to show up in an open market panel.

Where the rewrite logic lives

This plugin does not re-implement prompt rewriting. It imports the engine from the published Prompt Optimizer implementation, oss-prompt-optimizer.

LayerModuleSymbol
Meta-prompt buildeross-prompt-optimizer/lib/meta.jsbuildOptimizePrompt(input, language, extraInstructions, examples, outputStyle, metaLanguage, diagnosis, templates, context, taskType, maxOutputTokens, profile, level, builtinExamples, compact, sceneRefEnabled)
Template dataoss-prompt-optimizer/lib/templates.jsMETA_PROMPT, META_PROMPT_EN, DEFAULT_TEMPLATES
System-prompt wrappeross-prompt-optimizer/lib/prompt.jsbuildOptimizeSystem(ctx, input, outputLanguage, diagnosis, profile)
Rewrite executor (full service)oss-prompt-optimizer/lib/optimizer.jsclass PromptOptimizerService, optimize(rawInput, options)
Output validationoss-prompt-optimizer/lib/validate.jsREQUIRED_SECTIONS, hasValidSections, truncateInput, …

Those files sit behind the package's exports map, which only exposes the root, ./client, ./cordis.patch.yml, and ./package.json. The root re-exports the functions this plugin needs, so the supported import is:

import { buildOptimizePrompt, detectLanguage } from 'oss-prompt-optimizer'

index.js builds the meta-prompt with buildOptimizePrompt(draft, 'auto', …, 'plain', metaLanguage), sends the short user turn "只输出优化后的提示词。" / "Output only the optimized prompt.", and streams the answer back over SSE. That mirrors the upstream PromptOptimizerService.optimize() call shape — but the upstream service itself is not mounted, so this plugin owns its own route, timeout, and SSE framing, and no second ✨ control or settings panel appears.

Those defaults match upstream: outputLanguage: 'auto' (no forced-language line, the rewrite follows the draft) and outputStyle: 'plain' (a heading-free prompt body, which is what the composer holds).

Deep imports such as oss-prompt-optimizer/lib/meta.js are blocked by the package exports map (ERR_PACKAGE_PATH_NOT_EXPORTED). If a future release removes the root re-exports, add an exports entry upstream or vendor lib/meta.js + lib/templates.js into this package.

Files

FileRole
index.jsHost half: POST /prompt-optimizer/optimize (SSE), owner guard, route resolution, timeout, disconnect handling.
client.jsBrowser half: conversation.input.right control and conversation.input.dock panel.
cordis.patch.ymlInserts the prompt-optimizer Host row.
locale/en.json, locale/zh.jsonPlugin Manager / Settings display metadata.
icon.svgOriginal artwork.

UI layout notes

conversation.input.dock renders entries with no width wrapper, so a dock entry that does not constrain itself becomes full-bleed. The panel adopts the host's own dock geometry:

  • max-width: var(--dsh-chat-content-width, 920px) — the inherited transcript / composer column (clamp(680px, column * .64, 920px), user-draggable).
  • margin: 0 auto calc(0px - var(--dsh-composer-stack-gap, 6px) - 3px) and top-only border-radius with no bottom border, so the panel merges into the composer card instead of floating above it.

After a draft is replaced, Undo becomes the primary action and the applied note is an aria-live status region.

Development

npm install
npm test

npm test runs the Client render tests (module format, slot registrations, dock geometry, state transitions) and a Host integration test that streams a stubbed model call through the real route handler.

Local profile install

plugin_manager { action: "install_bundle", target: "<checkout>" }

install_bundle links a local directory (link:), so the profile's pnpm install does not install this package's dependencies — Node resolves imports from the plugin's real path. Run npm install in the checkout first, which creates the local node_modules/oss-prompt-optimizer the Host half imports. Harness packages used inside oss-prompt-optimizer (such as @deepseek-ai/cordis) resolve from the DSH installation at runtime.

Release

Releases are tag-driven: pushing vX.Y.Z runs .github/workflows/release.yml, which checks the tag against package.json, runs the tests, and publishes to npm with a provenance attestation. See RELEASING.md for the one-time trusted-publishing setup.

License

MIT. The imported rewrite engine is MIT-licensed by its author (seven282/oss-prompt-optimizer).

Interrupted or failed rewrites cannot be applied. The original draft remains editable; only a completed result enables Use. Undo restores the draft captured when Use was clicked.

Plugins associés