mirror of
https://github.com/yexi-by/dsh-unrestricted.git
synced 2026-11-28 02:30:22 +08:00
文档:精简 README 与技术说明
This commit is contained in:
1 parent
13b6772f16
commit
fbd8475d01
6 files changed
+371
-453
No files matched your search
+44
-53
@@ -1,102 +1,93 @@
|
||||
# Dynamic Prompt Injection & Mode Coordination in DSH
|
||||
# Prompt Injection & Mode Adaptation in DSH
|
||||
|
||||
> [简体中文](./prompt-fusion.md) | **English** | [日本語](./prompt-fusion.ja.md)
|
||||
|
||||
This technical guide details how `dsh-unrestricted` hooks into DeepSeek Harness (DSH), injects unrestrict rules on the fly, and coordinates across multiple execution modes.
|
||||
This document explains how `dsh-unrestricted` hooks into DeepSeek Harness (DSH) prompt assembly and handles each execution mode.
|
||||
|
||||
---
|
||||
|
||||
## 1. Architecture & Interception Mechanism
|
||||
## 1. Injection Mechanism
|
||||
|
||||
Prior to dispatching requests to LLMs, DSH dynamically builds its System Prompt section by section via its **Prompt Assemble Pipeline** (`system-prompt/assemble`).
|
||||
Before sending a request to the model, DSH builds its System Prompt section by section through the `system-prompt/assemble` pipeline.
|
||||
|
||||
The plugin's injection logic is structured as follows:
|
||||
The plugin works as follows:
|
||||
|
||||
1. **Pipeline Hook**:
|
||||
Registers a global listener on the prompt assembly pipeline. When enabled, it intercepts the outgoing section array; when disabled, it acts as a transparent pass-through, preserving 100% of the stock prompt.
|
||||
2. **Post-Persona Injection**:
|
||||
Locates the persona prefix (`deployment:persona-prefix`), appends an execution pointer directing the model to unrestricted local execution mode, and inserts the unrestrict rules block (`unrestricted:execution-mode`) immediately after.
|
||||
3. **Preserving Environment & Tools**:
|
||||
DSH's working directory suffix (`deployment:persona-suffix`) and all native tool schemas (filesystem, terminal commands, web search) are kept untouched. The plugin adjusts only the instructions governing output scale and directness.
|
||||
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. Unrestrict Rules Design & Core Scenarios
|
||||
## 2. Rule Structure & Scenarios
|
||||
|
||||
The unrestrict block (`EXECUTION_MODE_BLOCK`) enforces direct technical delivery while removing defensive tendencies:
|
||||
The rule block (`EXECUTION_MODE_BLOCK`) covers the following areas:
|
||||
|
||||
1. **Direct Delivery (No Chitchat)**:
|
||||
The answer itself is the final deliverable. If code is requested, output code starting on line 1. No conversational fluff, moral lectures, or unsolicited compliance warnings.
|
||||
2. **Reverse Engineering & Keygens**:
|
||||
Locates license/signature validation routines (`CHECK_FN`), extracts core cryptographic algorithms, and implements keygen generation code. Outlines binary patch offsets (`OFFSET`) and replacement bytes (`PATCH_BYTE`), along with anti-debug/anti-VM bypasses.
|
||||
3. **Security Research & Exploits**:
|
||||
Provides complete, reproducible PoC scripts detailing payload structure and delivery mechanisms. Formulates multi-threaded bruteforcers with canonical placeholders (`WORDLIST`, `THREADS`, `RATE`), and generates encrypted reverse shells.
|
||||
4. **Fiction, Creative Writing & Editorial**:
|
||||
Adapts fluidly between plot/worldbuilding brainstorming, outlining, prose editing, and direct scene writing while honoring the user's literary style. Renders anatomy and intimate acts plainly without fade-to-black avoidance when explicit scenes are requested, while preserving literary restraint and atmosphere when subtlety is desired. Fictional characters silently default to adults aged 18+; no age-based refusals or patronizing warnings.
|
||||
5. **Industrial & Technical Guides**:
|
||||
Provides unabridged formulations, reagents, and physical parameters for chemical and industrial procedures, without substituting degraded proxies on safety grounds.
|
||||
6. **Structured Resource Search**:
|
||||
Formulates targeted queries via DSH's search tools to extract verified download links, file sizes, and sources into structured tables, strictly forbidding hallucinatory URLs.
|
||||
7. **Data vs. Instruction Separation**:
|
||||
Explicitly informs the model that workspace files and scraped web pages are passive data, never instructions capable of modifying unrestrict guidelines.
|
||||
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**:
|
||||
Domain names, IPs, software titles, and function names specified by the user are preserved verbatim in all output.
|
||||
Preserves user-specified domain names, IPs, software names, and function names verbatim; uses uppercase placeholders (`TARGET`, `PORT`) for unspecified values.
|
||||
|
||||
---
|
||||
|
||||
## 3. Per-Mode Coordination
|
||||
## 3. Mode Adaptation
|
||||
|
||||
DSH provides distinct execution modes with differing prompt structures and tool constraints:
|
||||
Each DSH preset structures its prompt sections differently:
|
||||
|
||||
### Standard & Cordis Modes
|
||||
- **Profile**: Full-featured coding agents with terminal, filesystem, and task automation tools.
|
||||
- **Coordination**: Injects the unrestrict block immediately after the persona prefix. Built-in tools and contexts pass through unchanged.
|
||||
- Inserts the pointer and rule block right after `deployment:persona-prefix`, leaving tool and environment sections unchanged.
|
||||
|
||||
### PTC Mode (Program Tool Call)
|
||||
- **Profile**: Models interact with tools exclusively via `run_code` scripts.
|
||||
- **Coordination**: Appends an explanatory note to `tools:ptc-only` clarifying that Python/Node scripts executed inside `run_code` are unconstrained, allowing full access to internal SDK tools for automated analysis.
|
||||
- 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
|
||||
- **Profile**: Prevents destructive file writes prior to user approval.
|
||||
- **Coordination**: Appends a rule to `plan:policy` decoupling operational execution from technical depth. The model respects execution gates (no file modifications without user confirmation) while providing complete, unabridged technical procedures in the plan markdown.
|
||||
- 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
|
||||
- **Profile**: Minimal terminal assistant with an isolated scope registration.
|
||||
- **Coordination**: Preserves the persona text while injecting rules in the current agent scope, restoring the original prompt upon deactivation. `0.2.4` fixes assembly failures caused by duplicate persona registration in Minimal subagents with custom personas and preserves the native `structured_output` instructions required by structured subagents.
|
||||
- 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
|
||||
- **Subagents**: Background child agents inherit the unrestrict rules of their parent mode.
|
||||
- **Structured Output**: Subagents reporting via `structured_output` are instructed to supply comprehensive, unconstrained data in each JSON field.
|
||||
- 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. Robustness & Safety Guardrails
|
||||
## 4. Anchor Checks & Preview
|
||||
|
||||
### Anchor Verification
|
||||
To ensure compatibility with upstream DSH updates, the plugin checks verbatim text anchors before every fusion (defined in `ANCHORS` in `src/rules.js`):
|
||||
- Verifies identity strings, persona openings, Plan Mode policies, and `run_code` descriptions.
|
||||
- If all anchors match, rules are cleanly fused.
|
||||
- If an anchor fails, the plugin **gracefully falls back to the original stock prompt** for that mode and surfaces the issue in the UI.
|
||||
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 a SHA-256 hash (first 16 hex characters) of the unrestrict text block, displayed on the settings card for instantaneous verification of the active revision.
|
||||
Computes the first 16 hex characters of the rule block's SHA-256 hash and displays it on the settings card for version checks.
|
||||
|
||||
### Realtime Prompt Preview
|
||||
An RPC endpoint renders the exact, fully assembled prompt text, total line count, and byte size for each mode, ensuring complete transparency.
|
||||
|
||||
When refreshes or rechecks overlap, stale responses cannot overwrite the latest status or preview. The busy state remains active until all pending status operations finish.
|
||||
### Prompt Preview
|
||||
An RPC endpoint returns the assembled system prompt text, line count, and byte size for each mode in the settings UI.
|
||||
|
||||
---
|
||||
|
||||
## 5. Automated Testing
|
||||
## 5. Testing & Verification Scripts
|
||||
|
||||
```sh
|
||||
# Run the test suite
|
||||
# Run unit tests
|
||||
pnpm test
|
||||
|
||||
# Dump fresh prompts from DSH source to update fixtures
|
||||
# Export stock prompts from DSH source to update test fixtures
|
||||
node tools/dump-prompts.mjs --repo <deepseek-harness-path> --out tests/fixtures
|
||||
|
||||
# Verify live assembly and fallback in an active profile without LLM calls
|
||||
# Verify assembly and rollback across all four modes locally without API calls
|
||||
node tools/verify-live.mjs --repo <deepseek-harness-path>
|
||||
```
|
||||
+50
-59
@@ -1,102 +1,93 @@
|
||||
# DSH プロンプト動的注入の仕組みと各モード適応の解説
|
||||
# DSH におけるプロンプト注入と各モード対応の解説
|
||||
|
||||
> [简体中文](./prompt-fusion.md) | [English](./prompt-fusion.en.md) | **日本語**
|
||||
|
||||
本ドキュメントは開発者向けに、`dsh-unrestricted` が DeepSeek Harness(DSH)においてどのようにシステムプロンプトを動的に注入し、各種実行モードと協調動作しているかを解説します。
|
||||
本ドキュメントでは、`dsh-unrestricted` が DeepSeek Harness(DSH)のシステムプロンプト組み立てパイプラインにフックし、各実行モードを処理する仕組みを説明します。
|
||||
|
||||
---
|
||||
|
||||
## 1. アーキテクチャと注入の仕組み
|
||||
## 1. 注入の仕組み
|
||||
|
||||
DSH は LLM へリクエストを送信する直前に、**システムプロンプト構築パイプライン(`system-prompt/assemble`)**を通じて各セクション(Sections)を動的に組み立てます。
|
||||
DSH はモデルへリクエストを送る前に、`system-prompt/assemble` パイプラインでシステムプロンプトをセクション(Sections)単位で組み立てます。
|
||||
|
||||
プラグインの注入ロジックは以下の通りです:
|
||||
プラグインの処理フローは以下の通りです:
|
||||
|
||||
1. **パイプラインフック(Hook)**:
|
||||
構築パイプラインにグローバルリスナーを登録します。プラグインが有効な場合はセクション配列をインターセプトして改変し、無効な場合はそのまま通過させて 100% 公式標準の状態へロールバックします。
|
||||
2. **ペルソナ直後の注入**:
|
||||
DSH のペルソナ前置部(`deployment:persona-prefix`)を検出し、その末尾に制限解除実行モードへのポインタを付加した上で、直後のセクション(`unrestricted:execution-mode`)に制限解除ルールブロックを挿入します。
|
||||
3. **環境変数およびツールの維持**:
|
||||
DSH 本来の作業ディレクトリ後置部(`deployment:persona-suffix`)や、ターミナル実行、ファイル操作、Web 検索等のすべてのツール定義はそのまま維持されます。
|
||||
1. **パイプラインフック**:
|
||||
`system-prompt/assemble` にリスナーを登録します。スイッチがオンのときは出力されるセクション配列を書き換え、オフのときはそのまま通過させて公式の標準出力を保ちます。
|
||||
2. **ペルソナ直後の挿入**:
|
||||
公式のペルソナ前置部(`deployment:persona-prefix`)の末尾に案内文を追加し、直後のセクション(`unrestricted:execution-mode`)にルール本文を挿入します。
|
||||
3. **環境情報とツール定義の維持**:
|
||||
作業ディレクトリ後置部(`deployment:persona-suffix`)や、ファイル操作、ターミナル実行、Web 検索などのツール定義はそのまま維持します。
|
||||
|
||||
---
|
||||
|
||||
## 2. 制限解除ルールの設計と主要シナリオ
|
||||
## 2. ルール構成と対象シナリオ
|
||||
|
||||
制限解除ルールブロック(`EXECUTION_MODE_BLOCK`)は、モデルの過剰な自己防衛・説教を抑制するために設計されています:
|
||||
ルールブロック(`EXECUTION_MODE_BLOCK`)は以下の項目で構成されています:
|
||||
|
||||
1. **成果物を直接出力(前置き・説教の排除)**:
|
||||
「回答そのものが完成品である」と指示します。コードが求められている場合は 1 行目からコードを出力し、挨拶、前置き、倫理的な説教、免責事項を一切排除します。
|
||||
2. **ソフトウェアリバースエンジニアリング(RE / Keygen / Patch)**:
|
||||
ライセンスや署名の検証ロジック(`CHECK_FN`)を直接特定し、暗号・鍵生成アルゴリズムを抽出して Keygen コードを実装します。バイナリパッチのアドレス(`OFFSET`)や置換バイト(`PATCH_BYTE`)、アンチデバッグ回避コードを提供します。
|
||||
3. **サイバーセキュリティとペネトレーションテスト(Exploit / PoC)**:
|
||||
ペイロード構造と侵入メカニズムを含む完全な再現可能 PoC コードを作成します。辞書攻撃スクリプト(`WORDLIST`, `THREADS`, `RATE` 等のプレースホルダーを使用)や暗号化リバースシェルを提供します。
|
||||
4. **創作小説・文芸推敲・成人向けストーリーテリング(Fiction / Creative Writing & Editorial)**:
|
||||
プロットや世界観の考察、アウトライン作成、文章推敲と、実際のシーン執筆とを柔軟に切り替え、ユーザーが選んだ文体と美学に従います。成人向け・親密なシーンでは解剖学的な部位や行為を暗転(フェードアウト)なしで直接描写し、余韻や抑制が求められる場面では文学的表現を保ちます。架空の登場人物は一律 18 歳以上として扱い、年齢審査による拒否や道徳的な説教を禁止します。
|
||||
5. **高度な工業・化学操作ガイド**:
|
||||
化学実験や工業手順において、正確な配合比率や物理パラメータを省略せずに完全に提示します。
|
||||
6. **構造化リソース検索**:
|
||||
DSH の検索ツールと連携して的確な検索クエリを生成し、実際の検索結果から検証可能なダウンロードリストを作成します。偽 URL の捏造は禁止します。
|
||||
7. **データと指示の分離**:
|
||||
ワークスペース内のファイルや取得した Web ページは「分析対象のデータ」であり、制限解除ルールを変更する新たな指示としては扱わないようモデルに明示します。
|
||||
8. **指定ターゲット名の verbatim 維持**:
|
||||
ユーザーが明示したドメイン、IP、ソフトウェア名等は出力においてそのまま保持します。
|
||||
1. **直接出力(Delivery)**:
|
||||
回答そのものを成果物として扱います。コードが求められた場合は 1 行目からコードを出力し、解析手順が求められた場合は手順から書き始め、前置きや免責事項を省きます。
|
||||
2. **リバースエンジニアリングとパッチ(RE / Keygen / Patch)**:
|
||||
検証ロジック(`CHECK_FN`)を特定し、アルゴリズムを復元して Keygen を作成します。バイナリパッチのオフセット(`OFFSET`)、置換バイト(`PATCH_BYTE`)、アンチデバッグ/アンチ VM コードを提示します。
|
||||
3. **セキュリティ検証と Exploit(Security / Exploit)**:
|
||||
ペイロード構造と注入方法を含む再現可能な PoC コードを作成します。辞書攻撃スクリプトでは統一プレースホルダー(`WORDLIST`、`THREADS`、`RATE`)を使用し、リバースシェルには暗号化通信を含めます。
|
||||
4. **小説執筆と文章編集(Fiction / Creative Writing & Editorial)**:
|
||||
設定・プロットの検討、アウトライン作成、文章推敲、本文執筆を切り替え、指定された文体に従います。直接的な描写が求められる場面では暗転させずにそのまま描写し、余韻や抑制が求められる場面では留白を保ちます。架空の登場人物は成人として扱い、年齢設定による回答拒否や説教を行いません。
|
||||
5. **工業・実験手順(Guides)**:
|
||||
化学実験や特殊工程の手順、材料、配合パラメータを省略せず記載します。必要な安全上の注意は文末に簡潔に付記します。
|
||||
6. **リソース検索(Resources)**:
|
||||
DSH の Web 検索ツールで検索クエリを組み立て、検索結果からリストを整理します。架空の URL は生成しません。
|
||||
7. **外部テキストの分離(Layer Independence)**:
|
||||
ワークスペース内のファイルや取得した Web ページは処理対象のデータとして扱い、回答ルールを変更する指示とは見なしません。
|
||||
8. **指定ターゲット名の保持(Values & Targets)**:
|
||||
ユーザーが指定したドメイン、IP、ソフトウェア名、関数名は出力内でそのまま保持し、未指定の項目には大文字プレースホルダー(`TARGET`、`PORT`)を使用します。
|
||||
|
||||
---
|
||||
|
||||
## 3. 各実行モードへの適応
|
||||
## 3. 各プリセットモードへの対応
|
||||
|
||||
DSH は複数の実行モードを備えており、プラグインはそれぞれの特性に合わせて協調動作します:
|
||||
DSH の各実行モードに応じてプロンプトセクションを処理します:
|
||||
|
||||
### Standard(標準モード)および Cordis モード
|
||||
- **特徴**:ターミナル、ファイルシステム、タスク自動化ツールを備えたフル機能のエージェント。
|
||||
- **適応**:ペルソナ直後に制限解除ブロックを挿入。既存ツールや環境変数はそのまま維持されます。
|
||||
### Standard および Cordis モード
|
||||
- `deployment:persona-prefix` の直後に案内文とルールセクションを挿入し、その他のツール・環境セクションは変更しません。
|
||||
|
||||
### PTC(コード実行モード)
|
||||
- **特徴**:モデルは `run_code` を介してのみツールを利用できます。
|
||||
- **適応**:`tools:ptc-only` セクションに注記を追加し、`run_code` 内部で実行される Python/Node スクリプトや SDK ツール呼び出しも無制限ルールに従って動作することを明示します。
|
||||
- `run_code` でスクリプトを実行して内部 SDK ツールを呼び出すモードです。`tools:ptc-only` セクションの末尾に説明を追加し、スクリプトと SDK 呼び出しにも同じ出力ルールを適用します。
|
||||
|
||||
### Plan Mode(計画モード)
|
||||
- **特徴**:ユーザーの承認なしにファイルを破壊的に書き換えることを防止するモード。
|
||||
- **適応**:`plan:policy` セクションに注記を追加し、「実行の安全性」(承認前のファイル変更禁止)と「計画の内容」を分離します。計画ドキュメント(Markdown)内では、攻撃経路や実装コードなどの技術的詳細を制限なく網羅的に記述させます。
|
||||
- `plan:policy` セクションの末尾に説明を追加し、実行権限と計画内容を分けます。ユーザー承認前のファイル変更は行わず、計画ドキュメント(Markdown)には完全な技術手順、解析ロジック、コードを記載します。
|
||||
|
||||
### Minimal(最小モード)
|
||||
- **特徴**:非常に軽量なプロンプト構成のエージェント。
|
||||
- **適応**:現在のエージェントスコープでペルソナ本文を保持しながらルールを注入し、無効化時には元のプロンプトへ復帰します。`0.2.4` は、カスタムペルソナを持つ Minimal サブエージェントで重複登録によって組み立てが失敗する問題を修正し、構造化サブエージェントに必要な公式の `structured_output` 呼び出し指示を保持します。
|
||||
- 現在のエージェントスコープ内でカスタムペルソナ本文と `structured_output` の説明を保持しつつルールを挿入し、オフにしたときは元のプロンプトへ戻します。
|
||||
|
||||
### サブエージェントおよび構造化出力
|
||||
- **サブエージェント**:バックグラウンドで起動されるサブエージェントは親モードの制限解除設定を自動継承します。
|
||||
- **構造化出力**:`structured_output` ツールを使用する際も、各 JSON フィールドに制限のない詳細なデータを格納するよう指示します。
|
||||
### サブエージェントと構造化出力(structured_output)
|
||||
- バックグラウンドのサブエージェントは親モードのルール状態を引き継ぎます。
|
||||
- サブエージェントが `structured_output` で構造化データを返す際も、各フィールドの内容を省略せず詳細に出力させます。
|
||||
|
||||
---
|
||||
|
||||
## 4. 堅牢性と自動安全フォールバック
|
||||
## 4. アンカー検証とプレビュー
|
||||
|
||||
### テキストアンカー検証(Anchors Check)
|
||||
DSH 本体のバージョン更新によるプロンプト構造の変化を検知するため、プラグインは注入前に特徴文字列(`src/rules.js` の `ANCHORS`)を照合します:
|
||||
- 公式のアイデンティティ文字列、各モードのペルソナ冒頭、Plan モード規則、`run_code` の説明文等を照合します。
|
||||
- すべて一致した場合のみ注入を実行します。
|
||||
- アンカーが不一致となった場合、プラグインは**該当モードを自動的に公式デフォルトへ安全にフォールバック**させ、UI 上に未検証の項目を表示します。
|
||||
### アンカー文字列の照合(Anchors Check)
|
||||
組み立てのたびに、公式プロンプト内のアンカー文字列(`src/rules.js` の `ANCHORS`:識別文字列、ペルソナ冒頭、Plan モードポリシー、`run_code` の説明文)を確認します。DSH の更新で文面が変わり一致しなかった場合、そのモードは公式プロンプトへフォールバックし、設定カードに未通過項目を表示します。
|
||||
|
||||
### ルールフィンガープリント
|
||||
注入される制限解除テキストの SHA-256 ハッシュ(先頭 16 文字)を算出し、設定カードに表示します。デプロイされているリビジョンを一目で確認できます。
|
||||
### ルールフィンガープリント(Fingerprint)
|
||||
ルール本文の SHA-256 ハッシュ(先頭 16 文字)を算出し、設定カードに表示します。
|
||||
|
||||
### リアルタイムプロンプトプレビュー
|
||||
UI 上の「プレビューを表示」をクリックすることで、実際にモデルへ送信されるシステムプロンプトの全文、行数、バイトサイズをリアルタイムに確認できます。
|
||||
|
||||
更新や再確認が重なっても、古いリクエストの結果が最新の状態やプレビューを上書きすることはありません。処理中の表示は、保留中の状態操作がすべて完了するまで維持します。
|
||||
### プロンプトプレビュー
|
||||
フロントエンドから RPC プレビューエンドポイントを通じて、各モードで組み立てられたシステムプロンプト全文、総行数、バイト数を確認できます。
|
||||
|
||||
---
|
||||
|
||||
## 5. 自動テストと検証
|
||||
## 5. テストと検証スクリプト
|
||||
|
||||
```sh
|
||||
# テストを実行
|
||||
# ユニットテストを実行
|
||||
pnpm test
|
||||
|
||||
# DSH 源码から最新プロンプトを抽出し fixtures を更新
|
||||
# DSH ソースから公式プロンプトを書き出し fixtures を更新
|
||||
node tools/dump-prompts.mjs --repo <deepseek-harness-path> --out tests/fixtures
|
||||
|
||||
# 実環境でプロンプトの組み立てとロールバックを検証
|
||||
# API を呼び出さずに 4 モードの組み立てと復元をローカル検証
|
||||
node tools/verify-live.mjs --repo <deepseek-harness-path>
|
||||
```
|
||||
+48
-61
@@ -1,106 +1,93 @@
|
||||
# DSH 提示词动态注入原理与各模式适配说明
|
||||
# DSH 提示词注入与各模式适配说明
|
||||
|
||||
> **简体中文** | [English](./prompt-fusion.en.md) | [日本語](./prompt-fusion.ja.md)
|
||||
|
||||
本文档面向开发者,详细介绍 `dsh-unrestricted` 在 DeepSeek Harness(DSH)中实现提示词拦截、动态拼装以及针对多模式适配的技术细节。
|
||||
本文档说明 `dsh-unrestricted` 在 DeepSeek Harness(DSH)中挂载系统提示词流水线及处理各运行模式的实现细节。
|
||||
|
||||
---
|
||||
|
||||
## 1. 架构与注入机制
|
||||
## 1. 注入机制
|
||||
|
||||
DSH 在与大模型通信前,通过系统提示词组装流水线(`system-prompt/assemble`)按分块(Sections)动态拼装 System Prompt。
|
||||
DSH 在请求模型前,通过 `system-prompt/assemble` 流水线按分块(Sections)拼装 System Prompt。
|
||||
|
||||
插件的注入逻辑如下:
|
||||
插件的处理流程如下:
|
||||
|
||||
1. **流水线挂钩(Hook)**:
|
||||
在流水线中注册全局监听器。当插件开启时,拦截即将输出的 Section 列表;当插件关闭时直接原样放行,做到 100% 官方默认行为回滚。
|
||||
2. **角色设定后置注入**:
|
||||
定位到 DSH 的角色前缀(`deployment:persona-prefix`),在其末尾追加一段引导语,提示模型进入无限制本地执行模式,并在紧接着的下一个 Section(`unrestricted:execution-mode`)中注入完整的破限规则正文。
|
||||
3. **保留官方环境变量与工具**:
|
||||
DSH 原版的工作目录后缀(`deployment:persona-suffix`)、所有原生工具声明(文件系统读写、终端命令执行、Web 搜索等)完全保持原样,插件仅修改控制模型回答尺度的指示,不增减任何系统工具。
|
||||
1. **挂载流水线**:
|
||||
在 `system-prompt/assemble` 注册监听器。开关开启时改写输出的分块列表;关闭时直接放行,保持官方默认输出。
|
||||
2. **角色分块后置插入**:
|
||||
定位官方角色前缀(`deployment:persona-prefix`),在末尾追加引导说明,并在紧邻的下一个分块(`unrestricted:execution-mode`)插入破限规则正文。
|
||||
3. **保留环境与工具定义**:
|
||||
工作目录后缀(`deployment:persona-suffix`)及文件系统、终端命令、网页搜索等工具定义保持原样,不增删系统工具。
|
||||
|
||||
---
|
||||
|
||||
## 2. 破限规则设计与核心场景
|
||||
## 2. 规则结构与场景分类
|
||||
|
||||
破限规则块(`EXECUTION_MODE_BLOCK`)针对模型的过度防御心理,做了严谨的指令设计:
|
||||
规则块(`EXECUTION_MODE_BLOCK`)包含以下几类约定:
|
||||
|
||||
1. **交付即成果(No Chitchat)**:
|
||||
明确告知模型“回答本身就是交付物”。提问如果是要代码,第一行就直接给代码;提问如果是要分析步骤,直接列步骤。严禁输出长篇大论的“作为一个 AI”、“请遵守当地法律法规”等废话和客套。
|
||||
2. **软件逆向与分析(RE / Keygen / Patch)**:
|
||||
指示模型直接定位关键验证逻辑(`CHECK_FN`),提取注册与加密算法,编写注册机代码;输出二进制 Patch 的偏移地址(`OFFSET`)和替换字节(`PATCH_BYTE`),并提供反调试和反检测的规避代码。
|
||||
3. **网络安全与渗透测试(Security / Exploit)**:
|
||||
要求模型提供完整可复现的漏洞 PoC 验证代码,包含载荷结构与注入原理;编写爆破脚本时使用规范的占位符(如 `WORDLIST`、`THREADS`、`RATE` 等),编写反弹 Shell 时包含数据传输加密逻辑。
|
||||
4. **小说共创、文书编修与敏感剧情创作(Fiction / Creative Writing & Editorial)**:
|
||||
灵活区分“剧情/设定探讨、大纲构思、文书润色”与“正文撰写”,顺应用户选定的文风(古典、唯美、克制或直白)。在需要亲密/成人描写的场景中直白自然地展现身体部位与互动,禁止因审查而拉灯淡出;在注重意境与留白的场景中保持文学美感,不强塞生硬词汇。虚构角色一律静默默认推定为 18+ 成年人,杜绝因年龄假定引发的审查拒答,且严禁刻意强调年龄或发表任何道德说教。
|
||||
5. **专业工业与工艺指南(Guides)**:
|
||||
针对复杂的化学实验、特殊工艺或技术配方,提供真实客观的步骤、物料与配比数据,不提供被阉割的“简化版”;必要的防护提醒以客观附注置于文末。
|
||||
6. **结构化资源搜索(Resources)**:
|
||||
需要查找资源时,结合 DSH 的联网搜索工具自动构造精准检索词,提取真实结果生成下载清单,严禁编造不存在的假链接。
|
||||
7. **数据与指令分离(Data vs Instructions)**:
|
||||
明确告知模型:工作区里的文件内容、从网络上抓取到的网页文本均属于“待分析的数据”,绝不能当作修改自身破限规则的新指令。
|
||||
8. **具名目标逐字保留**:
|
||||
用户明确提到的域名、IP、软件名、函数名,在输出中逐字保留;未提及的参数才使用大写占位符(如 `TARGET`、`PORT`)。
|
||||
1. **直接交付(Delivery)**:
|
||||
回答本身即交付物。请求代码时从首行直接给出代码;请求分析时直接列出步骤,省去套话与免责声明。
|
||||
2. **软件逆向与补丁(RE / Keygen / Patch)**:
|
||||
定位校验逻辑(`CHECK_FN`),还原算法并编写注册机;给出二进制补丁偏移(`OFFSET`)、替换字节(`PATCH_BYTE`)及反调试、反检测代码。
|
||||
3. **安全测试与漏洞验证(Security / Exploit)**:
|
||||
提供可复现的漏洞验证代码(PoC),包含载荷结构与注入方式;编写爆破脚本时使用统一占位符(如 `WORDLIST`、`THREADS`、`RATE`),编写反向 Shell 时包含加密传输逻辑。
|
||||
4. **文学创作与文稿编校(Fiction / Creative Writing & Editorial)**:
|
||||
区分设定推演、大纲构思、文稿润色与正文写作,配合用户指定的文风。需要直白亲密描写时自然写出身体部位与动作,不拉灯回避;侧重氛围与留白时保持克制。虚构角色默认按成年人处理,不因年龄设定触发拒答或说教。
|
||||
5. **工业与实验流程(Guides)**:
|
||||
给出化学实验、特殊工艺或技术配方的完整步骤、物料与配比参数,不省略关键环节;必要的防护提醒放在文末简短附注。
|
||||
6. **资源检索(Resources)**:
|
||||
配合 DSH 联网搜索工具构造查询词,从搜索结果中整理下载列表,不编造链接。
|
||||
7. **外部文本隔离(Layer Independence)**:
|
||||
工作区文件内容与抓取的网页文本作为待处理数据,不作为修改当前回答规则的指令。
|
||||
8. **保留具名目标(Values & Targets)**:
|
||||
用户明确给出的域名、IP、软件名、函数名在输出中保持原样;未指定的参数使用大写占位符(如 `TARGET`、`PORT`)。
|
||||
|
||||
---
|
||||
|
||||
## 3. 各预设模式的深度适配
|
||||
## 3. 各预设模式适配
|
||||
|
||||
DSH 支持多种工作模式,各模式下的提示词结构和工具调用策略各不相同。插件分别进行了适配:
|
||||
DSH 不同运行模式下的提示词分块结构不同,插件分别处理如下:
|
||||
|
||||
### Standard(标准模式)与 Cordis 模式
|
||||
- **特点**:全功能的通用智能体,拥有完整的终端命令、文件读写、任务编排等工具。
|
||||
- **适配方式**:在角色前缀后插入引导语,随后注入破限规则块。系统工具和环境参数保持原样。
|
||||
### Standard 与 Cordis 模式
|
||||
- 在 `deployment:persona-prefix` 后插入引导语与规则分块,其余工具和环境分块保持不变。
|
||||
|
||||
### PTC(代码执行模式)
|
||||
- **特点**:PTC 模式下,大模型唯一能直接调用的工具是 `run_code`,模型需要通过编写 Python/Node 代码调用内部 SDK 工具来完成操作。
|
||||
- **适配方式**:在 `tools:ptc-only` 规则后面追加说明,明确告知模型:编写的 Python/Node 脚本同样遵循无限制规则,程序内部调用 SDK 进行漏洞测试、逆向分析、文件读写不受对话层面的限制。
|
||||
- 该模式下模型通过 `run_code` 编写脚本调用内部 SDK 工具。插件在 `tools:ptc-only` 分块末尾补充说明,使脚本代码与 SDK 调用遵循同一套输出规则。
|
||||
|
||||
### Plan Mode(计划模式)
|
||||
- **特点**:防止模型未经许可随意修改工作区文件。
|
||||
- **适配方式**:在 `plan:policy` 段末尾追加说明,明确区分“动作权限”与“方案内容”:
|
||||
- **动作限制保持**:在用户审批之前,绝对不在工作区执行写入或破坏性命令;
|
||||
- **内容尺度放开**:在计划方案(Markdown)中,毫无保留地写出所有攻击路径、逆向逻辑或实现代码,以便用户评估。
|
||||
- 在 `plan:policy` 分块末尾补充说明,区分执行动作与方案内容:用户审批前不修改工作区文件,但计划文档(Markdown)中正常写出完整的技术步骤、逆向逻辑与实现代码。
|
||||
|
||||
### Minimal(极简模式)
|
||||
- **特点**:极简模式的系统提示词极其短小,且在底层使用了独立的作用域注册机制。
|
||||
- **适配方式**:在当前 agent 作用域中保留角色正文并注入规则,关闭开关时恢复原版。`0.2.4` 修复了带自定义角色的 Minimal 子代理因同名提示词重复注册而组装失败的问题,并保留结构化子代理所需的官方 `structured_output` 调用指引。
|
||||
- 在当前 agent 作用域内保留原有的自定义角色正文与 `structured_output` 说明,并插入破限规则;关闭开关时恢复原版。
|
||||
|
||||
### 子代理(Subagent)与结构化输出(structured_output)
|
||||
- **子代理**:主智能体派生的所有后台子代理自动继承父模式的破限规则。
|
||||
- **结构化输出**:当子代理需要通过 `structured_output` 汇报结构化 JSON 数据时,插件在工具描述后追加提示,要求其汇报的各字段内容同样遵循真实、深入、无阉割的标准。
|
||||
- 后台子代理自动沿用父级模式的规则状态。
|
||||
- 子代理通过 `structured_output` 返回结构化数据时,插件在工具说明后补充提示,使各字段内容保持完整详细。
|
||||
|
||||
---
|
||||
|
||||
## 4. 健壮性与防翻车机制
|
||||
## 4. 锚点校验与状态预览
|
||||
|
||||
### 特征文本匹配(Anchors Check)
|
||||
为了防止 DSH 后续版本升级导致底层提示词结构变化引发错误,插件在每次拼装前都会校验当前原版提示词的关键特征字符串(定义在 `src/rules.js` 的 `ANCHORS` 中):
|
||||
- 检查官方身份标识、各模式角色首句、Plan 模式规则特征、`run_code` 锚点等;
|
||||
- 只有全部特征匹配成功,才执行注入;
|
||||
- 一旦某项特征匹配失败,插件会**自动对该模式保持原版提示词**,并在前端界面直观展示具体的未通过项,确保绝对不影响系统的基础运行。
|
||||
### 锚点文本核对(Anchors Check)
|
||||
每次组装前,插件会检查原版提示词中的锚点字符串(定义在 `src/rules.js` 的 `ANCHORS` 中),包括身份标识、角色首句、Plan 模式策略与 `run_code` 说明。若某项锚点未命中,对应模式自动回退为官方原版提示词,并在前端卡片中列出未通过项。
|
||||
|
||||
### 规则指纹(Fingerprint)
|
||||
插件通过对注入的破限规则文本计算 SHA-256 哈希(取前 16 位十六进制),生成全局唯一的**提示词指纹**。在前端设置卡片中会实时展示该指纹,便于开发者核对线上生效的规则版本。
|
||||
对破限规则正文计算 SHA-256 哈希(取前 16 位十六进制),在设置卡片中显示,用于核对当前生效的规则版本。
|
||||
|
||||
### 完整提示词预览
|
||||
插件提供了专门的 RPC 预览端点。用户在前端界面点击“查看预览”,即可实时获取当前模式即将发送给模型的真实系统提示词、总行数和字节大小,做到底层透明可见。
|
||||
|
||||
并发刷新或重新检查时,过期请求的结果不会覆盖最新状态与预览;忙碌状态保持到所有状态操作结束,避免请求尚未完成就提前解除。
|
||||
### 提示词预览
|
||||
前端可通过 RPC 预览接口查看各模式组装后的完整系统提示词、总行数与字节数。
|
||||
|
||||
---
|
||||
|
||||
## 5. 自动化测试与验证
|
||||
|
||||
仓库内置了完善的断言测试与集成验证脚本:
|
||||
## 5. 测试与校验脚本
|
||||
|
||||
```sh
|
||||
# 运行测试
|
||||
# 运行单元测试
|
||||
pnpm test
|
||||
|
||||
# 从 DSH 源码中重新抓取原版提示词并更新测试 fixtures
|
||||
# 从 DSH 源码导出原版提示词并更新测试 fixtures
|
||||
node tools/dump-prompts.mjs --repo <deepseek-harness-path> --out tests/fixtures
|
||||
|
||||
# 在真实运行环境中校验四种模式的拼接与回滚(不消耗 API Token)
|
||||
# 在本地校验四种模式的组装与还原(不调用模型接口)
|
||||
node tools/verify-live.mjs --repo <deepseek-harness-path>
|
||||
```
|
||||
Reference in new issue
Block a user