Preface¶
In the plugin-based architecture of DSH, specific capabilities within an agent’s workflow can be implemented as independent plugins. For prompt generation, a common issue is that raw instructions are often brief, such as “write steps to troubleshoot 502 errors,” which when directly fed to a model can yield generic outputs. oss-prompt-optimizer handles this stage: it rewrites concise instructions into professional, ready-to-use prompts, outputting structured expressions oriented toward Role / Task / Context / Format. Optimization is performed via the harness’s LLM service, without direct API calls or credential handling.
What This Is¶
oss-prompt-optimizer is a DSH plugin bundle, with the npm package name oss-prompt-optimizer under the MIT license. The repository is at https://github.com/seven282/oss-prompt-optimizer. It addresses prompt quality and reusability: it provides callable tools for agents, programming interfaces for other plugins, and allows direct optimization of current drafts within the composer input field.
Core Features¶
Optimization Tools for Agents¶
The plugin provides the prompt_optimize tool. Agents can pass instruction to obtain optimized results, or pass lastOptimized and iterateInstruction to iteratively revise existing optimized outputs.
Service Interfaces for Other Plugins¶
The plugin exposes a service ctx.promptOptimizer, supporting optimize and iterate. Other plugins can call:
ctx.promptOptimizer.optimize(rawInput, { signal })
or:
ctx.promptOptimizer.iterate(lastOptimized, instruction, { signal })
On the browser side, remote interface calls can be made:
ctx.remote.promptOptimizer.optimize(sessionId, text)
Composer Input Field Optimization¶
The composer input field features a persistent optimization icon. Clicking it optimizes the current draft and writes it back to the input field; optimization can be canceled during processing, and undone after success.
Auto-Optimization¶
Auto-optimization hooks can optimize messages prefixed with /optimize before they enter the model. Runtime commands:
/optimize --auto on
/optimize --auto off
/optimize --auto toggle
/optimize --auto status
control the toggle. Auto-optimization is enabled by default but only applies to messages with the autoOptimizePrefix (/optimize); messages without the prefix enter the model as-is. At most one message is optimized per step; if the prefix is not matched, the content after the prefix is empty, or optimization fails, the original message proceeds unchanged.
Context, Situation Awareness, and Role Definitions¶
Context awareness is enabled by default, injecting recent conversation as background reference into meta-prompts; it can be disabled via configuration:
contextAware: false
Situation awareness parses instructions and context into roles, tasks, and objective profiles, injecting them into meta-prompts. It supports objective alignment retries and session-level objective persistence.
Role definitions are written based on three elements: identity, capability, and behavior, with writing suggestions tailored to task types such as code, copywriting, analysis, and operations.
The role document language can automatically switch between Chinese and English based on input content, and can be fixed or restored to auto via /optimize --language.
Output, Validation, Caching, and Duration Control¶
Output remains a complete, executable prompt. Empty input triggers an error; excessively long input has truncation safeguards; UI-level cancellation is supported.
Post-validation can automatically retry when output is missing sections, too thin, or too short, returning machine-readable error codes.
For optimization duration control, early termination of streaming is disabled by default; a speed profile can be used:
optimizationProfile: fast
Result caching uses LRU + TTL, allowing identical requests to avoid model calls; caching is enabled by default as in-memory cache, cleared on restart.
Self-Iteration and Settings Panel¶
The self-iteration system is enabled by default, encompassing session learning, smart defaults, and user overrides; it becomes effective after accumulating 10 optimization data points. Learning data is persisted by default to:
~/.dsh/oss-prompt-optimizer/state.json
Persistence only saves behavioral metadata, not original instructions.
The plugin registers a prompt-optimizer namespace in the DeepSeek Harness settings panel, allowing configuration viewing and adjustment. When the host lacks a settings service, the settings panel is skipped automatically, and configuration still follows cordis.patch.yml.
Runtime Commands and Templates¶
Runtime commands can temporarily override profile, local, temperature, and allow viewing insights, status, and clearing overrides:
/optimize --set-profile fast|balanced
/optimize --set-local on|off|hybrid
/optimize --set-temperature <0-2>
/optimize --clear
/optimize --insights
/optimize --status
The /template command provides scene templates, returning a fillable four-segment template or a locally rendered pre-filled version without invoking the model. For example:
/template Weekly Report
/template Weekly Report Summarize this week's progress
Event Subscriptions¶
The plugin publishes the following events via an event bus for other plugins to subscribe:
optimize:start
optimize:success
optimize:failure
Installation and Enabling¶
Installing via npm¶
Install the npm package in the target profile:
dsh plugin --profile web add oss-prompt-optimizer
Installing via GitHub¶
Build and install from GitHub source:
dsh plugin --profile web add github:seven282/oss-prompt-optimizer
GitHub installation requires prepare authorization. In pnpm ≥10 scenarios, builds may need to be allowed:
allowBuilds:
oss-prompt-optimizer: true
It is recommended to lock the commit, e.g.:
github:seven282/oss-prompt-optimizer#<sha>
Uninstalling¶
dsh plugin --profile web remove oss-prompt-optimizer
Restarting the Harness¶
After installation or uninstallation, restart the harness to apply the bundle layer:
dsh web
Configuring Auto-Optimization¶
Configuration can be set in cordis.patch.yml:
autoOptimize: true
autoOptimizePrefix: '/optimize '
After configuration, messages starting with the /optimize prefix enter the auto-optimization flow; messages without the prefix remain unchanged.
Typical Usage¶
Invocation in Agent Workflows¶
When an agent receives a raw instruction that needs to be optimized into a prompt, it can call prompt_optimize with instruction. If an optimized version already exists and further modification is desired, pass lastOptimized and iterateInstruction for iteration.
Invocation in Other Plugins¶
Other DSH plugins can use the unified entry point via ctx.promptOptimizer, avoiding separate implementations of prompt rewriting logic.
const result = await ctx.promptOptimizer.optimize(rawInput, { signal })
To continue adjusting from the previous result:
const next = await ctx.promptOptimizer.iterate(lastOptimized, instruction, { signal })
On the browser side:
ctx.remote.promptOptimizer.optimize(sessionId, text)
Temporarily Adjusting Parameters in a Session¶
/optimize --set-profile fast|balanced
/optimize --set-local on|off|hybrid
/optimize --set-temperature <0-2>
/optimize --clear
/optimize --insights
/optimize --status
These commands are suitable for experimenting with different parameters within a single session without changing global configuration.
Quick Drafting with Templates¶
When only a fillable skeleton is needed without model invocation, use:
/template Weekly Report
For a locally pre-filled version:
/template Weekly Report Summarize this week's progress
Applicable Scenarios and Notes¶
Suitable for the following scenarios:
- Agent workflows need to transform short instructions into more complete, executable prompts.
- Other DSH plugins require unified invocation of prompt optimization capabilities.
- The composer input field needs quick optimization of current drafts.
- Only a scene template skeleton is needed, avoiding model calls each time.
- Need to experiment with
profile,local,temperature, and other parameters within a session.
Notes before use:
- The plugin runs with the permissions of the current
dshprocess; check source code, license, and dependencies before installation. - The license is MIT, allowing free use, modification, and distribution, including for commercial purposes.
- Optimization is performed via the harness’s LLM service, without direct API calls or credential handling.
- Auto-optimization by default only applies to messages with the
/optimizeprefix, leaving regular conversations unchanged. - Result caching is in-memory, cleared on restart; self-iteration is enabled by default, becoming effective after accumulating 10 optimization data points, with persistence saving only behavioral metadata.
package.jsonpeerDependenciesrequire@deepseek-ai/cordis ^4.0.1and multipledsh-*rc packages; the list in the provided information is truncated, with the complete list available in the repository’spackage.json.- Empty input triggers an error; excessively long input has truncation safeguards; if auto-optimization fails, the original message proceeds unchanged into the model.
Conclusion¶
oss-prompt-optimizer integrates prompt optimization as an independent capability within the DSH plugin ecosystem: it provides tools for agents, services for other plugins, and allows draft optimization in the input field. If preparing to adopt it, first confirm profile dependencies and the MIT license, then install and restart the harness.
GitHub: https://github.com/seven282/oss-prompt-optimizer
Plugin Directory Page: No directory page URL was provided in the verified information; it can be found in the DSH plugin directory by npm package name oss-prompt-optimizer.