dsh-prompt-optimizer: Optimize drafts in the DSH input box using the current model

Preface

When writing prompts in DeepSeek Harness (DSH), drafts are often in a state of “intent expressed but unrefined”: context is in the conversation, and the model is in the session selection. To polish the same text with the model, the common practice is to copy it to an external tool or start a new round of conversation. The DSH community plugin dsh-prompt-optimizer makes “Normal Input / Optimize Input” a permanent toggle on the top right of the chat input box. The optimization result is directly backfilled into the draft, which can still be edited.

The following introduces the plugin’s positioning, capabilities, and installation method under the web profile. Facts are subject to the GitHub Repository README.

What is this

dsh-prompt-optimizer is a registerable formal bundle plugin for DSH (not just a dynamic sandbox package alive only in process memory). The maintainer is EmotionG. It is categorized as “Model Inference” in the SkillHub directory, with a brief description of optimizing prompts.

The Host side registers the Connection RPC channel /prompt-optimizer; the Client side provides a “Normal Mode / ✨ Optimize Mode” toggle at conversation.input.right. In optimize mode, the plugin performs streaming optimization on the input draft based on the current conversation context and reuses the model selected for the current session, then writes back to the composer via setDraft.

Compared to the dynamic plugin version that only uses cordis_define: this package is installed via the profile’s dsh.profile.bundles and remains effective after process restarts; communication goes through Connection RPC, allowing the host handler to receive a real AbortSignal, and cancellation propagates to the underlying LLM adapter transport (the dynamic version mostly uses cooperative break).

Core Features

Input Box UI and Shortcuts

  • Slot: conversation.input.right, including states for mode switching, initiating optimization, loading, cancellation, error/truncation hints, and success fading.
  • Shortcut: Alt+O (implementation includes safeguards for IME, form controls, and defaultPrevented).

Optimization and Context

  • Uses modelSelection on the session projection: next ?? lastUsed; if only provider or model is passed, it is treated as not provided, falling back to the agent default model.
  • Context constraints (README behavior highlights): last 10 messages, max 800 characters per message, total limit of 6000 characters; drafts exceeding 8000 characters are truncated before optimization.

Cancellation and Robustness

  • User cancellation, unmounting due to session switch, plugin stop, and transport close all converge to the same AbortController, aborting the LLM request at the transport layer (including a fallback via the DeepSeek adapter idle watchdog).
  • Returns truncated with a prompt when max-tokens causes truncation; rejects duplicate tokens; uses a unique message ID for each request.
  • Mode selection is a module-level variable, retained across session switches; reset upon plugin reload.

Code Structure (for secondary development)

Path Responsibility
src/index.ts Host: optimize / cancel RPC, streaming generation via ctx.llm.stream
src/client/index.ts Client: UI and RPC calls, backfill via setDraft
scripts/build-client.mjs esbuild outputs lib/client.js (react externalized)
cordis.patch.yml Bundle patch, inserts into profile composition

Version 0.1.0, License MIT (see repo package.json). Peer dependencies include @deepseek-ai/cordis (>=4.0.2) and react (^18.2.0).

Installation and Activation

The plugin targets the web profile. Before installation, you need to complete the build in the package directory to produce lib/index.js and lib/client.js.

Method 1: Manually modify dependencies in the profile directory

In the profile directory (example path C:\Users\<user>\.dsh\profiles\web):

  1. Add this package to dependencies in package.json, changing the path to the actual directory after cloning or extracting on your machine, for example:
"dsh-prompt-optimizer": "file:D:/developRelevant/product/dshp/dsh-sen-message/dsh-prompt-optimizer"
  1. Add "dsh-prompt-optimizer" to dsh.profile.bundles.

  2. Execute in the profile directory:

pnpm install
  1. Execute in this package directory:
npm install
npm run build
  1. Restart dsh web (or manage via the dsh plugin command).

README Note: npm install is for devDependencies (esbuild, tsc, type packages); npm run build is equivalent to build:host (tsc) and build:client (esbuild).

Method 2: dsh plugin command

Similarly, you must first run npm install and npm run build in this package directory. Afterwards, you can use:

dsh plugin --profile web -- add "file:..."

Replace "file:..." with the file: path of this package on your local machine; this command forwards to pnpm for dependency management.

Typical Usage

  1. After installing and restarting DSH web, open any conversation and switch to “✨ Optimize Mode” at the top right of the chat input box.
  2. Write your draft in the input box (note the 8000 character limit and context count/length constraints).
  3. Trigger optimization (UI or Alt+O, subject to Client implementation). Wait for the streaming result to be backfilled into the draft.
  4. If generation is truncated by token limits, the interface will show a truncated related prompt; you can cancel at any time, and cancellation should abort the underlying LLM transport.
  5. After backfilling, you can continue editing and then switch back to “Normal Mode” to send as usual.

The mode selection remains retained when switching conversations until the plugin is reloaded.

Applicable Scenarios and Notes

Who it is for: Developers or agent users who frequently write long prompts in the DSH composer and want to polish drafts in-place using the same model as the current session; if you need a registerable bundle that remains effective after restarts, you should choose this repository over an in-memory dynamic plugin.

Permissions and Security: The plugin runs with the permissions of the current DSH process. Optimization requests go through ctx.llm.stream and read the conversation surface for context. Please review the GitHub Source Code and the MIT License yourself before installation, and ensure the file: path points to a trusted directory.

Ecosystem Note: DSH emphasizes “Everything is a plugin”; the SkillHub Directory Page is a community site, has no official affiliation with DeepSeek / High-Flyer, and is not an official app store.

Conclusion

dsh-prompt-optimizer embeds prompt optimization into the DSH input box: switch modes, optimize drafts using the session model and limited context, backfill with editability, and connect the cancellation chain to the transport layer via RPC and AbortSignal. For installation details and behavioral boundaries, refer to the repository README.

  • Directory Page: https://www.skillhub.cn/plugins/EmotionG/dsh-prompt-optimizer
  • GitHub: https://github.com/EmotionG/dsh-prompt-optimizer
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye