DeepSeek Harness Prompt Optimization Plugin (dsh-prompt-optimization-master)

Introduction

The plugin ecosystem of DeepSeek Harness (DSH) allows users to extend the functionality of the input box. The Prompt Optimization plugin draws on Tencent WorkBuddy’s EnhancePrompt mechanism and aims to solve the problem of unclear drafts. By making an independent model call, the plugin rewrites the unsent draft in the input box into a more specific prompt and provides a one-click restore function.

Installation

Install it through DSH’s plugin command-line tool. It supports the Web and desktop clients (note the Origin check).

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

Core Features

The plugin adds a Prompt Optimization button to the right side of the DSH input box toolbar. Its behavior is determined jointly by the draft state and the input box state.

  1. Button state flow

    • Draft present and idle: Displays the ✨ button. Clicking it sends the draft to the model for rewriting, and the result directly replaces the content in the input box.
    • Optimizing: Displays the ⏳ button. Clicking it cancels the request and restores the original text.
    • Optimized: Displays the ↩️ button. Clicking it restores the original text from before optimization.
  2. Smart show/hide

    • Hidden when the draft is empty: When the draft is empty (including the zero-width space U+200B), the button hides automatically.
    • Hidden in busy state: When the input box is in submitting or adjudicating state, the button is hidden to prevent accidental operations.
  3. Conversation and context management

    • Independent call: The optimization request uses an independent model call; it does not create a conversation, does not write to conversation history, and does not read historical context.
    • Automatic reset: After switching conversations, the previous conversation’s backup and error messages are cleared automatically to prevent leftover state.

Configuration

In the DSH settings panel, locate the independent “Prompt Optimization” entry and configure it there.

  • Enable the ✨ button: Toggles the visibility of the button.
  • Minimum character count: Sets the minimum draft length required to trigger optimization. If left empty, it follows the host default.
  • Specify model: By default, it follows the current conversation model. Once checked, it can pin the provider and model ID, routing optimization requests to a cheaper model.

Working Principles and Limitations

The plugin uses a dedicated HTTP route (POST /dsh-prompt-enhance/enhance) for model interactions instead of Remote.

  1. Prompt design
    It uses a two-layer structure: the System layer defines the role (prompt engineering expert), and the User layer provides a task template and few-shot examples, with emphasis on locking the output language and suppressing meta-language.

  2. Desktop Origin check
    The desktop UI runs on the dsh-app:// protocol. Electron forwards non-static resource requests, but enforces the request header Origin: dsh-app://app. The host side must explicitly accept this Origin check; otherwise, the desktop client returns 403.

  3. Reasoning model budget issue
    Testing found that reasoning models (such as hy4-preview) can consume the entire output budget, leaving zero visible output. The plugin has fixed this issue:

    • It dynamically allocates the output budget: reasoning models are allocated 32768, while regular models are allocated 4096.
    • It uses ctx.llm.resolveModelInfo() to determine whether the model has thinking enabled and caps the budget with the model’s own defaultMaxTokens.
    • It adds a hard timeout of 60 seconds and provides an automatic retry mechanism for truncation errors.

Development and Debugging

Client-half and host-half changes have different effects on hot updates.

  1. Modification rules

    • Client-half changes: After modifying files such as client/client.js, refreshing the page makes the changes take effect. HMR pushes only once when the module is first added.
    • Host-half changes: After modifying files such as dsh/index.js, you must restart DSH. The Loader caches modules within the process.
  2. Offline testing
    The plugin includes a complete test suite that can be run without relying on DSH.

npm test        # 运行宿主半、客户端半与推理预算测试
  • Host-half test (test/smoke.mjs): Covers 45 checks, including route registration, request guards, and prompt assembly.
  • Client-half test (test/client.test.mjs): Covers state machines and state transitions, with 57 checks total.
  • Reasoning budget test (test/reasoning-budget.mjs): Covers thinking detection, limit capping, and truncation retry, with 29 checks total.
羽毛球分组比赛记分
小程序二维码

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

Xiaoye