# Prompt Injection & Mode Adaptation in DSH > [简体中文](./prompt-fusion.md) | **English** | [日本語](./prompt-fusion.ja.md) This document explains how `dsh-unrestricted` hooks into DeepSeek Harness (DSH) prompt assembly and handles each execution mode. --- ## 1. Injection Mechanism Before sending a request to the model, DSH builds its System Prompt section by section through the `system-prompt/assemble` pipeline. The plugin works as follows: 1. **Pipeline Hook**: Registers a listener on `system-prompt/assemble`. When enabled, it rewrites the outgoing section list; when disabled, it passes sections through unchanged. 2. **Post-Persona Insertion**: Finds the official persona prefix (`deployment:persona-prefix`), appends a pointer at the end, and inserts the rule block (`unrestricted:execution-mode`) as the next section. 3. **Preserving Context & Tools**: Keeps the working directory suffix (`deployment:persona-suffix`) and tool definitions (filesystem, terminal commands, web search) intact. --- ## 2. Rule Structure & Scenarios The rule block (`EXECUTION_MODE_BLOCK`) covers the following areas: 1. **Direct Delivery**: The response is the deliverable itself. Code requests start with code on line 1; analysis requests start directly with the steps, omitting disclaimers and pleasantries. 2. **Reverse Engineering & Patching**: Locates validation routines (`CHECK_FN`), reconstructs algorithms, and writes keygens; provides binary patch offsets (`OFFSET`), replacement bytes (`PATCH_BYTE`), and anti-debug / anti-VM code. 3. **Security Testing & Exploits**: Provides reproducible PoC scripts with payload structure and delivery details; uses standard placeholders (`WORDLIST`, `THREADS`, `RATE`) in bruteforcers and includes encryption in reverse shells. 4. **Fiction & Editorial Writing**: Adapts across worldbuilding/plot discussion, outlining, prose editing, and scene writing according to the user's chosen style. Writes explicit scenes plainly without fade-to-black cuts when called for, while keeping restraint when subtlety is preferred. Fictional characters default to adults without age-based refusals or lecturing. 5. **Industrial & Lab Procedures**: Gives full steps, materials, and ratios for chemical or industrial processes without omitting key stages; keeps necessary safety precautions as a brief note at the end. 6. **Resource Lookup**: Uses DSH's web search tools to query and organize download lists from real results without inventing URLs. 7. **External Text Isolation**: Treats workspace files and fetched web pages as input data rather than new instructions that alter active response rules. 8. **Verbatim Named Targets**: Preserves user-specified domain names, IPs, software names, and function names verbatim; uses uppercase placeholders (`TARGET`, `PORT`) for unspecified values. --- ## 3. Mode Adaptation Each DSH preset structures its prompt sections differently: ### Standard & Cordis Modes - Inserts the pointer and rule block right after `deployment:persona-prefix`, leaving tool and environment sections unchanged. ### PTC Mode (Program Tool Call) - Models in PTC mode call tools by running Python/Node scripts via `run_code`. The plugin appends a note to `tools:ptc-only` so scripts and internal SDK calls follow the same output rules. ### Plan Mode - Appends a rule to `plan:policy` separating execution permissions from plan content: no workspace files are modified before user approval, while the plan markdown itself contains full technical steps, reverse engineering logic, and code. ### Minimal Mode - Preserves custom persona text and `structured_output` instructions within the active agent scope while inserting the rule block; restores the original prompt when turned off. ### Subagents & Structured Output - Background subagents inherit the current rule state from their parent mode. - When a subagent reports via `structured_output`, a note is appended to keep each JSON field complete and detailed. --- ## 4. Anchor Checks & Preview ### Anchor Verification Before each assembly, the plugin checks expected anchor strings in the stock prompt (`ANCHORS` in `src/rules.js`), including identity strings, persona openings, Plan Mode policies, and `run_code` descriptions. If any anchor fails to match after an upstream DSH update, that mode falls back to the stock prompt and lists the failed item in the UI. ### Rule Fingerprint Computes the first 16 hex characters of the rule block's SHA-256 hash and displays it on the settings card for version checks. ### Prompt Preview An RPC endpoint returns the assembled system prompt text, line count, and byte size for each mode in the settings UI. --- ## 5. Testing & Verification Scripts ```sh # Run unit tests pnpm test # Export stock prompts from DSH source to update test fixtures node tools/dump-prompts.mjs --repo --out tests/fixtures # Verify assembly and rollback across all four modes locally without API calls node tools/verify-live.mjs --repo ```