Introduction¶
When writing prompts, a quick draft is often vague in intent and unclear in boundaries. Dispatching it directly to the main brain or a sub-agent tends to go off track. The DeepSeek Harness (DSH) community already has plenty of prompt optimization ideas, but most focus on “wording polish” and lack structured packaging for the “dispatch scenario.” The dsh-mainbrain-prompt-optimizer plugin by Haibo0223 builds on existing optimization capabilities by adding a “dispatch mode” and an “intent fidelity check,” rewriting drafts into ready-to-dispatch task briefs. It streams a preview first and only writes back upon confirmation, preventing accidental auto-send.
Plugin Overview¶
dsh-mainbrain-prompt-optimizer is a model-inference plugin for DeepSeek Harness, maintained by Haibo0223. It adds a ✦ Optimize button to the right side of the DSH input box, rewriting a rough draft into a prompt that preserves intent, clarifies boundaries, and is ready to be dispatched to the main brain or a sub-agent. The generated result is previewed via streaming; only when you click “Replace Draft” is it written into the input box. It never auto-sends.
The plugin is built on the MIT-licensed open-source upstream by infcel/dsh-prompt-optimizer. On top of that, it adds a main-brain dispatch mode, lightweight auto-selection, an intent fidelity check, and isolation from the upstream package to avoid install conflicts.
Core Features¶
6 Optimization Modes¶
The top of the panel offers mode switching. The default is “Auto,” which selects a mode via text heuristics, or you can manually specify one:
- Auto: Suggests a default mode based on rules.
- Dispatch: Rewrites the task into a structured brief containing objectives, context, execution scope, constraints, deliverables, acceptance criteria, execution & reporting, and items to confirm. Sections with no source content are omitted entirely—no empty headings or placeholders.
- Structured: Generates a long-reusable role prompt, outputting
# Role+## Use Cases / ## Capabilities / ## Work Constraints / ## Execution Flow / ## Opening. - Analytical: For complex tasks lacking background and output format, outputs
# Task Objective+## Assumptions & Inputs / ## Analysis Dimensions / ## Decision Criteria / ## Execution Order / ## Output Format / ## Pre-delivery Check. - Refine: Compresses a vague one-liner into a natural-language paragraph with no headings or lists; length capped at 3× the original.
- Iterative: Preserves the existing structure and weaves “what to change this time” into the original text. Ideal for a finished draft that only needs one tweak.
Intent Fidelity Check¶
After generation, the Host side compares the original and the result using deterministic rules, returning structured warnings in the done event. The panel displays warnings beyond variable status:
variable:{{variable}}losttoken: Backtick content lostconstraint: Numeric constraint lost (supports thousands separators and “ms”)identity: Identity sentence removed or weakenedbloat: Abnormal bloat of a short draft (Refine mode only: original ≤ 160 chars and result exceedsmax(600, original × 4))
When the output language is manually set to something different from the source, constraint, identity, and bloat checks are skipped—translation inevitably changes units and identity phrasing. variable and token are still strictly checked. Warnings do not block adoption, nor do they trigger another paid request.
Draft Safety & Interaction¶
- Preview only: Clicking the button only generates a preview; without clicking “Replace Draft,” nothing is written into the input box and no message is sent.
- No selection = full replacement: When the host has no selection, the plugin uses a
[0, draft-length]full span viainsertText, so the result replaces the entire draft—no “original + new result” duplication. - Selection = same span in and out: A chip-free selection only sends the selected portion, and the write-back uses the same span + draftRev; the send range matches the write-back range.
@reference + selection = safe full replace: Chip detect coordinates and clipboard text come from different sources, so the full text is sent and written back viasetDraft. The panel shows a notice: “Replacing will convert references to plain text.”- Draft conflict protection: If the draft is modified during generation, it is intercepted with a prompt. In the selection-optimization scenario, the first click only enters a confirmation state; the second click writes and warns that content outside the selection and new content generated during the process will be lost.
- Session isolation: The panel records the opaque token of the owning session. Switching sessions closes the panel, aborts the request, and clears drafts/results/classification. Old SSE/classify/meta responses do not pollute the new session.
- Quick close/reopen: The model request is fired 200 ms after the panel opens; a quick close cancels any request not yet sent. If the request was sent and then cancelled, reopening within 1.5 s enters a “Last optimization was cancelled” paused state, requiring an explicit “Re-optimize” click.
Auto-Selection Rules¶
Auto-classification is based on lexical heuristic rules in lib/heuristic.js on the Host side. The client first calls POST /classify to display “Detected,” and /optimize with mode: "auto" re-computes with the same rules to avoid a mismatch between the UI and the actual request. Once the user manually selects a mode, the client no longer overwrites it with auto-classification.
Rules include: explicitly naming DeepSeek/sub-agent → Dispatch; 400+ chars with a skeleton ({{variable}}, # heading, Role:, or “You are…”) → Structured; explicit “long-term / reusable / role prompt” with existing role structure → Structured; short web/plugin/project implementation, modification, refactoring, or fix → Dispatch; two or more verifiable deliverables, multi-step implementation/validation, or post-implementation testing requirements → Dispatch; 600+ chars with analysis/process signals → Analytical; ≤ 400 chars with no # heading → Refine; long text without analysis/process signals → Refine (not mechanically escalated to Analytical); everything else → Analytical.
Installation & Activation¶
This repository is not published on npm; installation requires a git clone. Requirements: DSH >=0.2.2-rc.3 <0.2.3-0 (covers the 0.2.2 series; rc.3 and rc.5 tested), Node ^22.19.0 || >=24.0.0.
- Clone the repository:
git clone https://github.com/Haibo0223/dsh-mainbrain-prompt-optimizer.git
- Pass the absolute path of the cloned directory to
plugin_manager:
plugin_manager(action: "install_bundle", target: "<ABSOLUTE_PATH_TO_THIS_REPO>")
-
Restart Harness (bundle/patch is a startup snapshot).
-
Verify two things:
- ✦ Optimize appears to the right of the input box;
- The plugin management page shows “Main Brain Prompt Optimizer” with row idmainbrain-prompt-optimizerand status active.
Typical Usage¶
Open the panel, type a draft sentence in the input box, and click ✦ Optimize. You can select a mode at the top of the panel; the default is auto-detection:
- A simple “Write a blurb for a landing page” goes into Refine mode, outputting a natural-language paragraph with no headings or lists.
- A clear task type like “Build a web page/plugin/project” or “Implement/Modify/Refactor/Fix” goes into Dispatch mode, outputting a structured brief with objectives, context, execution scope, constraints, deliverables, acceptance criteria, execution & reporting, and items to confirm.
- When you want a long-reusable role prompt, manually select Structured mode, outputting a template with role, use cases, capabilities, work constraints, execution flow, and opening.
- For a finished draft that only needs one tweak, select Iterative mode, which preserves the existing structure and weaves “what to change this time” into the original text.
During generation, the right panel displays the streaming result in real time. Once you’re satisfied, press Ctrl/⌘+Enter or click “Replace Draft” to write the result into the input box—only then does it truly enter the editor.
Use Cases & Caveats¶
Suited for scenarios where you need to rewrite a draft into a clear task brief ready for dispatch to the main brain or a sub-agent. The plugin runs with the current DSH process’s permissions; review the source code and license before installing.
The plugin only rewrites the prompt itself—it does not execute the prompt or do the work for you. It uses the current session’s default model with no extra API key configuration. Selecting a portion only modifies that portion; no selection means the entire draft is modified. No history is saved; no favorites or template library. {{variable}}s, backtick content, numeric constraints, and identity sentences undergo deterministic checks, but semantic-level “fidelity” is not guaranteed.
Summary¶
dsh-mainbrain-prompt-optimizer adds structured packaging for “dispatch scenarios” and an intent fidelity check on top of prompt optimization. Combined with streaming preview and draft safety mechanisms, it is ideal for developers who need to turn rough drafts into clear task briefs. The plugin is currently at version 0.2.0, MIT-licensed, and based on the open-source upstream infcel/dsh-prompt-optimizer.
Ecosystem Context¶
DeepSeek Harness embraces the philosophy of “everything is a plugin.” The community directory is an independent site with no official affiliation with DeepSeek or High-Flyer. This plugin can be viewed on the SkillHub directory page, and the source code is available in the GitHub repository.