DeepSeek Harness Plugin

ruiyukirin/dsh-prompt-optimization-master

Stars ★ 2 Downloads (30d) 1,335 Category UI Enhancements Added 2026-10-17 npm dsh-prompt-optimization-master

Adds a button to the composer that rewrites the unsent draft into a clearer, more specific prompt, with one-click restore, a settings page and an optional per-request model override.

Install

# from npm (prebuilt)

dsh plugin --profile web add dsh-prompt-optimization-master

# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)

dsh plugin --profile web add github:ruiyukirin/dsh-prompt-optimization-master

Any plugin you install runs third-party code with your own permissions — it can read your files, use your credentials, and reach the network, and tool approvals don’t sandbox it. GitHub-sourced plugins also run build scripts at install time — pnpm blocks those until you allow them, so an install can stop with ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED or ERR_PNPM_IGNORED_BUILDS; dsh prints the exact key to add under allowBuilds in your profile’s pnpm-workspace.yaml, and the install works on the next run. Allowing a build is a trust decision: only install sources you trust, and pin a commit (github:owner/repo#sha).

README

Author: Kirin (ruiyukirin)

A prompt optimization button for the DeepSeek Harness composer: one click rewrites the unsent draft into a clearer, more specific prompt; click again to restore the original.

The mechanism follows Tencent WorkBuddy's EnhancePrompt feature.

中文说明 →


Demo video

Click to watch the 30-second film: what you give the AI is usually an idea, not an instruction

That is a short looping clip. Click it to play all 30 seconds (1080p, with voice-over and captions).

GitHub's README only plays video inline from its own attachment host; an mp4 living in the repository gets stripped by the Markdown sanitizer, so this is a preview that opens the file.


Install

From npm:

dsh plugin --profile web add dsh-prompt-optimization-master

Or straight from GitHub:

dsh plugin --profile web add github:ruiyukirin/dsh-prompt-optimization-master

Compatibility range: engines.dsh declares >=0.2.0-rc.2 <0.4.0. DSH enforces that range at install time and at profile startup and refuses anything outside it (an explicit dsh plugin ... allow-version exemption exists, but it is risky). Verified on DSH 0.2.1-rc.3.

Upgrading: 0.3.1 fixed "spins forever and produces nothing on a thinking model" (see CHANGELOG). 0.3.2 only corrected the compatibility declaration. 0.3.3 adds no features — it is polish: a model dropdown instead of a typed id, an adjustable timeout, the failure reason shown where people can see it, the debug leftover removed, plus CI and a manifest test. Behaviourally equivalent to 0.3.2.

About the name: dsh-prompt-enhance and dsh-prompt-optimizer were both already taken on npm and GitHub by plugins with the same product intent, so this one uses dsh-prompt-optimization-master. The name was checked against npm and GitHub before release and was free in both places.


What it does

A ✨ button appears in the composer toolbar, between the model selector and the send button:

State Icon What a click does
Draft present, idle ✨ Sends the draft to the model; the rewrite replaces the composer content
Enhancing ⏳ Cancels, aborts the request and restores the original
Enhanced ↩️ Restores the original
  • Appears only once you type. An empty draft hides the button, exactly like WorkBuddy. Invisible placeholders (zero-width space, U+200B) do not count as content.
  • Hidden while the composer is busy. During submitting / adjudicating the button hides so a click cannot fire a pointless request — but a result that is still revertible stays reachable, so a pending restore is never locked away.
  • Editing retires the backup. If you change the draft after an enhancement, "restore original" steps aside instead of swallowing your edit.
  • Per-session state. Switching sessions drops the previous session's backup and error banner.
  • No conversation context is consumed. The enhancement is an independent model call: it creates no Session, writes nothing to the session log, and does not read conversation history — it sees only the fixed prompt plus the current draft. WorkBuddy behaves the same way.

In action

The same draft, before and after one click on ✨:

Before After
Before: the draft with the ✨ button After: the rewrite with the ↩ restore button

The draft「已经重启了,现在你检查一下任务的进度」became a task statement that names every item to check; the ✨ turned into a ↶ (restore original) at the same time.


Settings

Settings → Prompt optimization — its own entry in the settings sidebar, next to the other sections:

Setting Effect
Enable the ✨ button Switched off, the button disappears from the composer. Come back here any time to turn it on again
Minimum characters The button hides while the draft is shorter than this. Empty = follow the host default
Use a specific model Follows the current session model by default. When enabled, pick from a dropdown: the plugin asks the host for its model catalog and groups every registered model by provider ("name (id)", with the session's own model marked). A provider the host cannot enumerate is named instead of being silently dropped. The last entry, "Enter the provider and model id manually", stays as a fallback — so this auxiliary call can be pinned to a cheaper model without changing what your conversation uses
Timeout (seconds) Give up on one enhancement after this long and say so. Empty = follow the host default (60s here). The allowed range comes from the host (5–300s here); out-of-range values are clamped instead of rejected

Settings page: "Prompt optimization" in the settings sidebar

Settings live in browser local storage, so reinstalling the plugin does not lose them.

Language

Button text follows the harness UI language (Settings → Language). Simplified Chinese and English are built in, served through the harness locale service rather than hard-coded strings.


How it works

[composer draft]
    ↓ useInput(s => s.draft)
[✨ button]  (slot: conversation.input.right)
    ↓ POST /dsh-prompt-enhance/enhance
[host half]  ctx.llm.stream({ system, messages })   ← independent call, no Session
    ↓ accumulate text-delta chunks
[write back]  inputActions.setDraft(text)
    + the original is kept as a backup, restorable in one click

The bridge is the plugin's own HTTP route rather than the harness Remote (typert) channel. The desktop UI is served over the custom dsh-app:// scheme; Electron forwards every non-asset path to the host HTTP server, but that forwarding function requires the request header Origin: dsh-app://app. A host-side check must accept that origin explicitly, otherwise every desktop request is answered with 403.

Prompt design

Two layers, following WorkBuddy:

  1. system — the role: a prompt engineering expert serving a general-purpose coding/operations agent. It lists what not to do (no how-to guides, no code snippets the user never asked for, no technologies the user never mentioned, do not answer the question — rewrite it more precisely), plus the ~800 character ceiling and two English few-shot examples.
  2. user — the task template with a language lock as the highest priority, a bad-output/good-output pair that suppresses meta commentary about language, and three mixed-language few-shot examples.

The result is cleaned before use: Markdown fences and leading/trailing quote characters are stripped.


Layout

Path Role
dsh/index.js Host half: routes, prompts, model call, cancellation, error codes
client/client.js Client half: the three-state button, settings popover, i18n
cordis.patch.yml The single insert that mounts this package
test/smoke.mjs Host half offline smoke test (45 checks)
test/client.test.mjs Client half state-machine test (57 checks, real code in a sandbox)
docs/ Research reports: WorkBuddy internals, naming, mechanism diff, go-to-market

Development constraints (measured, not guessed)

  • Client half changes → refresh the page. HMR pushes a module only the first time it joins the client module graph; later edits are not pushed.
  • Host half changes → restart DSH. The Loader caches the imported plugin module for the process lifetime. All of these were tried and none re-imports the module: disabling/re-enabling the plugin, re-applying the bundle, and rewriting the profile's cordis.patch.yml.

Offline tests

npm test        # four suites, 204 checks, no DSH required
  • Manifest (test/manifest.mjs): guards "is the declared field actually read by anyone". Asserts engines.dsh exists and is a non-empty range, that the inert dsh.compatibility block stays deleted, that files never ships test, and that CHANGELOG documents the current version.
  • Host half (test/smoke.mjs): a fake Cordis context plus a real HTTP server. Covers route registration, the request guard (including the dsh-app://app origin), prompt assembly, chunk accumulation, result cleaning, every error code, cancellation, model overrides, the model-catalog route, backoff retry on network failures, and a missing llm service.
  • Client half (test/client.test.mjs): loads the real client/client.js through node:vm with a minimal React and a stubbed fetch, then drives the button through every transition — hidden on empty draft, enhance, revert, cancel, failure restore, settings effects, model override, i18n, the settings page's model dropdown and timeout clamping, and the failure chip.
  • CI: .github/workflows/test.yml runs npm test on Node 20 and 22 for every push to main and every pull request.

Findings worth keeping

Finding Detail
ctx.llm cannot be read directly Cordis throws cannot get property "llm" without inject. Use ctx.get('llm') or declare inject. The smoke test now reproduces that guard so a regression cannot slip through.
Reasoning can eat the whole output budget Measured on deepseek-flash: one short rewrite emitted 132 characters of visible text after 2632 characters of reasoning. A 512-token budget was consumed entirely by reasoning and produced no visible output, so the cap is 4096 and a budget hit is reported as truncated — a cut-off prompt is worse than no rewrite.
Business errors are not HTTP errors The host answers {ok:false, code} with HTTP 200. The client once cleared its in-flight request id before validating, so the catch treated the error as a superseded request and the button span forever. Fixed and locked with a test.
setDraft replaces the whole draft Per the harness source: it replaces the entire draft, splits newlines into paragraphs, and leaves the caret at the end.
Zero-width space counts as content The editor inserts U+200B as an invisible placeholder and trim() does not remove it, so a draft that looks empty could still fire a request. Now stripped before measuring.
Desktop origin is dsh-app://app Electron forwards non-asset paths to the host HTTP server but requires that exact origin; a strict same-origin check answers 403 for every desktop request.

⚠️ Do not rewrite a UTF-8 file with shell Get-Content / WriteAllText on Windows: PowerShell decodes BOM-less UTF-8 as ANSI, turning comments into mojibake and eating newlines. Use an editor that guarantees UTF-8.

License

MIT

Content from the project README on GitHub ↗

Links

More in this category

View the whole category →

Community comments

Comments are public GitHub Discussions. Loading them connects to GitHub and Giscus; a GitHub account is required to post.