From fbd8475d01c7a705da34b7671b8ae9644770eedc Mon Sep 17 00:00:00 2001 From: yexi Date: Wed, 28 Oct 2026 16:26:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E6=A1=A3=EF=BC=9A=E7=B2=BE=E7=AE=80?= =?UTF-8?q?=20README=20=E4=B8=8E=E6=8A=80=E6=9C=AF=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 178 +++++++++++++++++--------------------- README.ja.md | 179 ++++++++++++++++++--------------------- README.md | 152 ++++++++++++++------------------- docs/prompt-fusion.en.md | 97 ++++++++++----------- docs/prompt-fusion.ja.md | 109 +++++++++++------------- docs/prompt-fusion.md | 109 +++++++++++------------- 6 files changed, 371 insertions(+), 453 deletions(-) diff --git a/README.en.md b/README.en.md index 80e5c5d..554f5f8 100644 --- a/README.en.md +++ b/README.en.md @@ -2,170 +2,150 @@ [简体中文](./README.md) | **English** | [日本語](./README.ja.md) -`dsh-unrestricted` is a system prompt unrestrict (jailbreak) plugin for **DeepSeek Harness (DSH)**. It injects purpose-built unrestrict rules directly into DSH's system prompts, removing refusal boundaries across reverse engineering, penetration testing, creative writing, and specialized technical operations, enabling models to directly output complete, actionable implementations and code. +`dsh-unrestricted` is a system prompt unrestrict plugin for **DeepSeek Harness (DSH)**. It injects unrestrict rules during system prompt assembly, lifting refusal boundaries across reverse engineering, security testing, creative writing, and technical workflows so the model returns complete code and implementations directly. -The plugin stays lightweight: the existing switches enable or disable the rules as a whole, preserving DSH's interface layout, tool-calling protocols, Plan Mode, code execution (PTC), and subagent mechanics. - -`0.2.5` fixes prompt registration conflicts in Minimal subagents with custom personas, missing native structured-output instructions, and overlapping settings requests that could overwrite a newer preview or clear the busy state too early. The prompt rules and existing switches remain unchanged. It supports DSH `0.2.2-alpha.2` (`f3803c9697`) with `engines.dsh` set to `>=0.2.2-alpha.2 <0.2.3-0`. Only the current DSH version is supported; legacy compatibility is removed. - -The native model reasoning settings and plugin index do not replace this plugin's per-mode prompt assembly. Reasoning levels remain managed by the native model settings. +A single toggle enables or disables the rules without altering DSH's UI layout, tool protocols, Plan Mode, code execution (PTC), or subagent workflow. --- ## Table of Contents -- [Core Capabilities](#core-capabilities) -- [Technical Architecture](#technical-architecture) - - [Dynamic System Prompt Interception & Injection](#dynamic-system-prompt-interception--injection) - - [Multi-Mode Coordination](#multi-mode-coordination) - - [Anchor Text Verification & Safe Fallback](#anchor-text-verification--safe-fallback) - - [Hot-Switching & Zero-Trace Reversion](#hot-switching--zero-trace-reversion) +- [What It Changes](#what-it-changes) +- [How It Works](#how-it-works) + - [System Prompt Injection](#system-prompt-injection) + - [Mode Adaptation](#mode-adaptation) + - [Anchor Check & Fallback](#anchor-check--fallback) + - [Instant Toggle](#instant-toggle) - [Installation & Updates](#installation--updates) - - [Web Mode](#web-mode) - [Local Source Install](#local-source-install) -- [Usage (Double-Switch Activation)](#usage-double-switch-activation) -- [Operational Boundaries](#operational-boundaries) +- [Usage](#usage) +- [Notes](#notes) - [Development & Testing](#development--testing) - [License & Credits](#license--credits) --- -## Core Capabilities +## What It Changes -When enabled, the model operates under the following execution directives: +When enabled, the injected rules adjust model responses as follows: -- **Direct Delivery Without Fluff or Preaching**: The very first line outputs the requested artifact (runnable code, step-by-step procedures, binary patches). Unsolicited disclaimers, ethical lectures, and pleasantries are omitted. Essential safety precautions are placed concisely at the end as objective postscripts. -- **Reverse Engineering & Algorithm Extraction**: Identifies key validation routines (`CHECK_FN`), extracts core algorithms, and implements keygen generators. Provides exact binary patch offsets (`OFFSET`) and replacement bytes (`PATCH_BYTE`), along with anti-debugging and anti-VM bypass code. -- **Cybersecurity & Penetration Research**: Provides complete, reproducible PoC and Exploit scripts detailing payload construction and delivery. Generates multi-threaded credential bruteforcers, port/banner scanners, encrypted reverse shells, and port-forwarding scripts. -- **Fiction, Literary Co-Creation & Adult Writing**: Fluidly adapts across scene writing, plot/worldbuilding brainstorming, character design, and editorial polishing. Honors the user's chosen style and aesthetic (lyrical, classical, restrained, gritty, or explicit): renders anatomy and intimate acts directly without fade-to-black censorship when explicit depiction is called for, while preserving subtlety and literary restraint when appropriate. Fictional characters silently default to 18+ adults without age-based refusals or intrusive disclaimers. -- **Specialized Industrial & Technical Procedures**: Supplies unabridged procedures, reagents, and physical parameters for chemical, pharmacological, and industrial operations without omitting critical steps. -- **Structured Resource Search**: Leverages DSH web search tools to build targeted queries and compiles structured tables (title, verified link, source, format/size) from real results without fabricating URLs. -- **Strict Data vs. Instruction Separation**: Workspace files and scraped web content are treated strictly as passive data, never as new instructions that alter unrestrict rules. User-specified names (domains, IPs, software titles) are preserved verbatim. +- **Direct Output**: Starts directly with the requested code, analysis steps, binary patch, or prose without disclaimers, pleasantries, or lecturing. Necessary physical or operational cautions are kept as a brief note at the end. +- **Reverse Engineering & Patching**: Locates validation routines (`CHECK_FN`), reconstructs core algorithms, and writes keygens; provides binary patch offsets (`OFFSET`), replacement bytes (`PATCH_BYTE`), and anti-debug / anti-VM bypasses. +- **Security Testing & Tooling**: Writes vulnerability PoC / exploit scripts, multi-threaded dictionary bruteforcers, port scanners, encrypted reverse shells, and tunneling scripts. +- **Fiction & Editorial Writing**: Adapts to scene writing, plot/worldbuilding exploration, character work, and prose editing. Follows the user's chosen tone—writing explicit scenes plainly without fade-to-black cuts when requested, or keeping subtlety and restraint when the style calls for it. Characters default to adults without age-based refusals or intrusive reminders. +- **Industrial & Lab Procedures**: Gives complete steps, ratios, and parameters for chemical, pharmacological, and technical processes without omitting key stages. +- **Resource Lookup**: Uses web search tools to query and organize results into a clear list (title, link, source, format/size) without inventing URLs. +- **External Text Isolation**: Treats workspace files and web pages strictly as input data rather than new instructions; preserves user-supplied domains, hosts, and software names verbatim. --- -## Technical Architecture +## How It Works -### Dynamic System Prompt Interception & Injection +### System Prompt Injection -In agentic architectures, DSH wraps all model interactions in a high-priority System Prompt that supersedes regular user messages. Injecting jailbreak phrases into user chat messages is often overridden by the system prompt or corrupts structured tool calling. +DSH assembles a global System Prompt before sending requests. Putting unrestrict instructions inside regular chat messages is easily overridden by the system prompt or can disrupt tool calling. -This plugin interfaces directly with DSH's system prompt assembly pipeline (`system-prompt/assemble`): +The plugin hooks into the `system-prompt/assemble` pipeline: -1. **Pipeline Hook**: Registers a global listener on the prompt assembly pipeline. -2. **Post-Persona Injection**: Locates the official persona prefix (`deployment:persona-prefix`), appends an execution pointer, and inserts the unrestrict rules block (`unrestricted:execution-mode`) in the immediately following section. -3. **Preserving Core Agent Protocols**: Working directory suffixes (`deployment:persona-suffix`), native tool definitions, and environment variables remain untouched; only directives governing response scope and directness are modified. +1. Appends a pointer at the end of the official persona prefix (`deployment:persona-prefix`) and inserts a dedicated rule section (`unrestricted:execution-mode`) right after it. +2. Leaves working directory info (`deployment:persona-suffix`), tool schemas, and environment context untouched. ```text -[DSH Agent Request] - │ - ▼ +[DSH Request] + │ + ▼ [Prompt Assemble Pipeline] - │ - ├─> Official Persona Prefix - │ │ - │ ▼ 【dsh-unrestricted Hook】 - │ ├─ Enabled: Injects unrestrict block & coordinates mode constraints - │ └─ Disabled: Transparent pass-through (100% stock prompt) - │ - ├─> Tool Catalog & Protocols (Bash/Pwsh, FS, Web Search...) - ├─> Plan Mode Policy - └─> Environment Info (CWD, Model...) - │ - ▼ -[Dispatched to LLM API] + │ + ├─> Official Persona Prefix + │ │ + │ ▼ [dsh-unrestricted] + │ ├─ Enabled: Inserts rule section & coordinates mode rules + │ └─ Disabled: Pass-through (stock prompt) + │ + ├─> Tool Catalog & Protocols (Bash/Pwsh, FS, Web Search...) + ├─> Plan Mode Policy + └─> Environment Info (CWD, Model...) + │ + ▼ +[Sent to Model API] ``` -### Multi-Mode Coordination +### Mode Adaptation -The plugin coordinates rules across all DSH execution presets: +The plugin handles each DSH execution preset according to its prompt structure: -- **Standard & Cordis Modes**: Injects the unrestrict block directly after the persona prefix, keeping all built-in tools (terminal, filesystem, web search) functional. -- **PTC Mode (Code-Only Execution)**: Since PTC agents interact only via `run_code`, an additional guideline is injected into `tools:ptc-only`, clarifying that Python/Node scripts executed inside `run_code` are unconstrained and free to use internal SDK tools for automated analysis. -- **Plan Mode**: Decouples operational constraints from planning depth. The plugin explicitly reinforces that **operational constraints apply only to mutations** (no file edits prior to approval), but **the plan markdown must contain unabridged technical procedures, exploit mechanisms, or reverse engineering steps**. -- **Minimal Mode**: Injects rules in the current agent scope while preserving custom subagent personas and native structured-output instructions, avoiding duplicate persona registration. Disabling the plugin restores the original prompt. -- **Subagents & Structured Output**: Background child agents and structured reporting (`structured_output`) automatically inherit the unrestrict rules. +- **Standard / Cordis Modes**: Inserts the rule block after the persona prefix while keeping all built-in tools intact. +- **PTC Mode**: Models in PTC mode run scripts via `run_code`. The plugin adds a note to `tools:ptc-only` so Python/Node code and SDK calls inside `run_code` follow the same output rules. +- **Plan Mode**: Separates execution permissions from plan content—no file edits happen before approval, while the plan markdown itself includes full technical steps and code. +- **Minimal Mode**: Injects rules within the active agent scope while preserving custom subagent personas and `structured_output` instructions. +- **Subagents**: Background subagents and structured output tasks inherit the current toggle state. -### Anchor Text Verification & Safe Fallback +### Anchor Check & Fallback -To prevent malformed prompts when DSH updates upstream, the plugin checks verbatim text anchors before every fusion (defined in `ANCHORS` in `src/rules.js`): +Before each assembly, the plugin checks expected anchor strings in the stock prompt (see `ANCHORS` in `src/rules.js`), including persona openings, Plan Mode policies, and `run_code` descriptions. If an upstream DSH update changes those strings and a check fails, that mode falls back to the stock prompt and reports the failed anchor in the settings panel. -- Verifies persona openings, Plan Mode policies, and `run_code` descriptions. -- Edits are applied only if all anchors match. -- If an anchor fails, the plugin **safely falls back to the stock DSH prompt** for that mode and flags the issue in the settings card. +### Instant Toggle -### Hot-Switching & Zero-Trace Reversion - -- **Instant Switching**: Toggling the switch persists the setting to `cordis.patch.yml`. Changes take effect on the very next request without requiring a service restart. -- **Zero Artifacts**: Deactivating the switch restores the stock prompts immediately, leaving no persistent markers in conversation history or databases. +The toggle state is saved in the profile's `cordis.patch.yml` and takes effect on the next request without restarting the service. Turning it off restores the stock prompt immediately without leaving markers in session history. --- ## Installation & Updates -### Web Mode - -For CLI and server setups running `dsh web`. - -#### Install ```sh -# Install specific tag +# Install a specific release dsh plugin --profile web add github:yexi-by/dsh-unrestricted#v0.2.5 # Or track master dsh plugin --profile web add github:yexi-by/dsh-unrestricted ``` -Restart `dsh web`, then follow the [Usage section](#usage-double-switch-activation) to enable both the plugin and the unrestrict toggle. + +Restart `dsh web` after installing, then follow [Usage](#usage) to enable it. #### Update + ```sh dsh plugin --profile web remove dsh-unrestricted -dsh plugin --profile web add github:yexi-by/dsh-unrestricted# +dsh plugin --profile web add github:yexi-by/dsh-unrestricted# ``` + Restart `dsh web`. #### Uninstall + ```sh dsh plugin --profile web remove dsh-unrestricted ``` ---- - ### Local Source Install -For developers linking a local workspace: +For local development: ```sh -# Web profile dsh plugin --profile web add file:D:/work/dsh/plugin/unrestricted - ``` --- -## Usage (Double-Switch Activation) +## Usage -> **Important: Both switches must be turned on for unrestrict rules to take effect!** -> -> 1. **Step 1 (Plugin Activation Switch)**: Navigate to **Plugins** in the sidebar. In the installed plugins list, find `dsh-unrestricted` (Unrestricted mode) and **toggle the plugin ON**. If the plugin is not enabled here, DSH will not load the plugin runtime at all. -> 2. **Step 2 (Feature Toggle Switch)**: Click `dsh-unrestricted` in the **Plugins** page to open its configuration card, and turn on the **"Enable unrestricted mode"** switch at the top. -> -> Both switches must be active for rules to be injected into the system prompt assembly pipeline. +Make sure both switches are turned on after installation: -### Settings Panel Features +1. **Enable Plugin**: Open **Plugins** in the left sidebar, find `dsh-unrestricted`, and turn on the plugin switch. +2. **Enable Rules**: Click `dsh-unrestricted` to open its settings card and turn on **"Enable unrestricted mode"**. -- **Enable Switch**: Toggles unrestrict mode globally for future requests. -- **Per-Mode Status**: Shows real-time injection status across Standard, PTC, Cordis, and Minimal modes (`Active` indicates successful anchor verification and injection; if inactive, check whether the plugin is toggled on in the Plugins manager). -- **Rule Fingerprint**: Displays the SHA-256 hash (first 16 hex characters) of the deployed unrestrict rule block. -- **Prompt Preview**: Click **"Show preview"** under any mode to inspect the exact system prompt text, line count, and byte size. +The settings card also provides: + +- **Mode Status**: Shows anchor check and injection status for Standard, PTC, Cordis, and Minimal modes. +- **Rule Fingerprint**: First 16 hex characters of the rule text's SHA-256 hash. +- **Prompt Preview**: Expands the full assembled system prompt, line count, and byte size for each mode. --- -## Operational Boundaries +## Notes -- **Cloud Platform Moderation Filters**: Commercial AI providers often enforce external content filters at the network layer. If a request triggers server-side keyword blocks, the connection is terminated by the API host (HTTP 400 or policy reset). Such external network-level filters cannot be bypassed by prompt engineering alone; pairing with relaxed API endpoints or local models (Ollama / vLLM) is advised. -- **Host Security Enforcement**: The plugin modifies only the model's instruction following and reasoning depth. DSH's read-only file sandbox, terminal command approval prompts, and Plan Mode write restrictions remain fully enforced. -- **Compliance**: Intended for authorized security research, reverse engineering, software development, and creative fiction. +- **API Gateway Filtering**: System prompts adjust the model's own refusal behavior. If an upstream API gateway enforces external keyword blocking, requests may still be dropped or return HTTP 400 at the network layer. +- **Host Permissions**: The plugin does not alter DSH's file sandbox, command approval prompts, or Plan Mode write protection. --- @@ -175,19 +155,21 @@ dsh plugin --profile web add file:D:/work/dsh/plugin/unrestricted git clone https://github.com/yexi-by/dsh-unrestricted.git cd dsh-unrestricted pnpm install + pnpm typecheck pnpm build pnpm test ``` -Repository maintenance tools: -- `node tools/dump-prompts.mjs --repo --out tests/fixtures`: Dumps stock prompts from DSH source to update test fixtures. -- `node tools/verify-live.mjs --repo `: Verifies live assembly and rollback without calling the LLM. +Helper scripts: + +- `node tools/dump-prompts.mjs --repo --out tests/fixtures`: Exports stock prompts from a DSH source checkout to update test fixtures. +- `node tools/verify-live.mjs --repo `: Verifies assembly and rollback across all four modes locally without calling model APIs. --- ## License & Credits -- Initial prompt rules adapted and refined from [Jia-Ethan/codex-keysmith](https://github.com/Jia-Ethan/codex-keysmith)'s `gpt-unrestricted.md` (MIT License). See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). -- This project has no affiliation with codex-keysmith or its author. -- Licensed under the [MIT License](LICENSE). +- Initial prompt rule structure adapted from [Jia-Ethan/codex-keysmith](https://github.com/Jia-Ethan/codex-keysmith) (MIT License). See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). +- Not affiliated with codex-keysmith or its author. +- Released under the [MIT License](LICENSE). diff --git a/README.ja.md b/README.ja.md index 25be3d7..c111206 100644 --- a/README.ja.md +++ b/README.ja.md @@ -2,110 +2,96 @@ [简体中文](./README.md) | [English](./README.en.md) | **日本語** -`dsh-unrestricted` は、**DeepSeek Harness (DSH)** 向けのプロンプト制限解除(アンレストリクト)プラグインです。システムプロンプト(System Prompt)に専用の制限解除ルールを注入することで、リバースエンジニアリング、ペネトレーションテスト、創作執筆、特殊技術手順における回答拒否や説教を解除し、完全で実行可能なコードと技術ソリューションを直接出力させます。 +`dsh-unrestricted` は、**DeepSeek Harness (DSH)** 向けのシステムプロンプト制限解除プラグインです。システムプロンプト(System Prompt)の組み立て段階でルールを注入し、リバースエンジニアリング、セキュリティ検証、創作執筆、技術手順における回答拒否を解除して、実行可能なコードと手順を直接出力させます。 -プラグインは軽量な構成を維持し、既存のスイッチでルール全体を有効・無効にします。DSH 本来の画面レイアウト、ツール呼び出しプロトコル、計画モード(Plan Mode)、コード実行(PTC)、サブエージェントの実行ロジックを維持します。 - -`0.2.5` は、カスタムペルソナを持つ Minimal サブエージェントのプロンプト登録競合、公式の構造化出力指示の欠落、設定画面の並行リクエストによる古いプレビューの上書きや処理中状態の早期解除を修正します。既存のプロンプトルールとスイッチは変更しません。DSH `0.2.2-alpha.2`(`f3803c9697`)に対応し、`engines.dsh` は `>=0.2.2-alpha.2 <0.2.3-0` です。旧バージョン向けの互換処理は削除しました。 - -公式の推論レベル設定とプラグイン索引は、本プラグインのモード別プロンプト組み立てを代替しません。推論レベルは公式のモデル設定で管理します。 +単一のスイッチでルール全体を有効・無効にでき、DSH 本来の画面レイアウト、ツール呼び出しプロトコル、計画モード(Plan Mode)、コード実行(PTC)、サブエージェントの仕組みは変更しません。 --- ## 目次 -- [主要機能](#主要機能) -- [技術アーキテクチャ](#技術アーキテクチャ) - - [動的インターセプトと注入](#動的インターセプトと注入) - - [各モードとの高度な協調](#各モードとの高度な協調) - - [アンカー検証と自動安全フォールバック](#アンカー検証と自動安全フォールバック) - - [即時適用と痕跡ゼロのロールバック](#即時適用と痕跡ゼロのロールバック) -- [インストール・更新](#インストール更新) - - [Web 版](#web-版) +- [ルールの効果](#ルールの効果) +- [仕組み](#仕組み) + - [システムプロンプト注入](#システムプロンプト注入) + - [各実行モードへの対応](#各実行モードへの対応) + - [アンカー検証とフォールバック](#アンカー検証とフォールバック) + - [即時切り替え](#即時切り替え) +- [インストールと更新](#インストールと更新) - [ローカルソースインストール](#ローカルソースインストール) -- [使用方法(二重スイッチの確認)](#使用方法二重スイッチの確認) -- [動作境界と注意事項](#動作境界と注意事項) +- [使い方](#使い方) +- [注意事項](#注意事項) - [開発とテスト](#開発とテスト) - [ライセンスと謝辞](#ライセンスと謝辞) --- -## 主要機能 +## ルールの効果 -プラグイン有効時、モデルは以下の実行指示に従います: +有効化すると、モデルの応答動作を以下のように調整します: -- **成果物の直接提示(前置き・説教の排除)**:1 行目から完成した成果物(実行可能なコード、分析手順、バイナリパッチ等)を出力し、挨拶、免責事項、倫理的な説教を排除します。必須の物理的安全注意事項のみ、文末に客観的な付記として記載します。 -- **リバースエンジニアリングとアルゴリズム解析**:ライセンス検証関数(`CHECK_FN`)を特定し、暗号・鍵導出アルゴリズムを抽出して Keygen コードを実装します。バイナリパッチのアドレス(`OFFSET`)や置換バイト(`PATCH_BYTE`)、アンチデバッグ・アンチ VM 回避コードを提供します。 -- **サイバーセキュリティとペネトレーションテスト**:ペイロード構造と侵入メカニズムを含む完全な再現可能 PoC / Exploit コードを作成します。辞書攻撃スクリプト、ポート・フィンガープリントスキャナー、暗号化リバースシェル、ポートフォワーディング等のコードを提供します。 -- **創作小説・設定考察・成人向けストーリーテリング**:シーン執筆、プロット・世界観の考察、キャラクター造形、文章推敲に柔軟に対応します。ユーザーの文体・美学(叙情的、古典的、抑制的、ハード、または直接的)を尊重し、成人向け描写が求められる場面では婉曲表現や暗転(フェードアウト)なしで直接描写する一方、余韻や抑制が求められる場面では文学的表現を維持します。架空の登場人物は一律 18 歳以上の成人として静かに扱い、年齢審査による拒否や不自然な強調を禁止します。 -- **高度な工業・化学操作ガイド**:化学実験や工業手順において、正確な配合比率や物理パラメータを省略せずに完全に提示します。 -- **構造化リソース検索**:DSH の検索ツールと連携して的確な検索クエリを生成し、実際の検索結果から検証可能なダウンロードリストを作成します。偽 URL の捏造は禁止します。 -- **データと指示の厳密な分離**:ワークスペース内のファイルや取得した Web ページは「分析対象のデータ」であり、制限解除ルールを変更する新たな指示としては扱いません。ユーザーが明示したターゲット名はそのまま保持します。 +- **成果物の直接出力**:1 行目からコード、解析手順、パッチ、本文を出力し、免責事項や前置き、説教を省きます。物理的・操作上の注意点が必要な場合は文末に簡潔に付記します。 +- **リバースエンジニアリングとパッチ**:検証関数(`CHECK_FN`)の特定、アルゴリズムの復元と Keygen の作成、バイナリパッチのオフセット(`OFFSET`)と置換バイト(`PATCH_BYTE`)、アンチデバッグ/アンチ VM 回避策を提示します。 +- **セキュリティ検証とスクリプト実装**:脆弱性検証コード(PoC / Exploit)、マルチスレッド辞書攻撃、ポートスキャン、暗号化リバースシェル、転送スクリプトを作成します。 +- **小説執筆と文章編集**:本文執筆、プロット・設定の検討、キャラクター造形、推敲に対応します。指定された文体に従い、直接的な描写が求められる場面では暗転させずにそのまま描写し、余韻や抑制が求められる場面では留白を保ちます。登場人物は成人として扱い、年齢を理由にした拒否や不自然な強調を行いません。 +- **工業・実験手順**:化学、薬理、特殊加工などの工程、配合比、パラメータを省略せず記載します。 +- **リソース検索**:Web 検索ツールを用いて検索し、結果(名称、リンク、出典、形式・サイズ)を整理して返します。架空の URL は生成しません。 +- **外部テキスト指示の分離**:ワークスペース内のファイルや取得した Web ページは入力データとして扱い、現在の回答ルールを上書きする指示とは見なしません。ユーザーが指定したドメイン、ホスト、ソフトウェア名はそのまま保持します。 --- -## 技術アーキテクチャ +## 仕組み -### 動的インターセプトと注入 +### システムプロンプト注入 -自律型エージェント環境では、DSH は毎回の推論時に高権限なシステムプロンプト(System Prompt)を最外層に付与します。通常のチャットメッセージに脱獄文を送信しても、システムプロンプトに上書きされるか、ツールの呼び出し形式が破損する原因となります。 +DSH はリクエスト送信前に全体のシステムプロンプトを組み立てます。通常のチャットメッセージ内に制限解除の指示を入れても、システムプロンプトに抑え込まれるか、ツール呼び出し形式に影響しやすくなります。 -本プラグインは DSH のシステムプロンプト構築パイプライン(`system-prompt/assemble`)に直接フックします: +本プラグインは `system-prompt/assemble` パイプラインに直接フックします: -1. **パイプラインフック**:構築パイプラインにグローバルリスナーを登録します。 -2. **ペルソナ直後の注入**:公式のペルソナ前置部(`deployment:persona-prefix`)を検出し、その末尾に制限解除実行モードへのポインタを付加した上で、直後のセクション(`unrestricted:execution-mode`)に制限解除ルールブロックを挿入します。 -3. **ネイティブ能力の維持**:作業ディレクトリ(`deployment:persona-suffix`)、ツール定義、環境変数はそのまま維持されます。 +1. 公式のペルソナ前置部(`deployment:persona-prefix`)の末尾に案内文を追加し、直後に専用セクション(`unrestricted:execution-mode`)を挿入します。 +2. 作業ディレクトリ情報(`deployment:persona-suffix`)、ツール定義、環境変数はそのまま維持します。 ```text -[DSH 発起リクエスト] - │ - ▼ -[システムプロンプト構築パイプライン] - │ - ├─> 公式ペルソナ (Persona) - │ │ - │ ▼ 【dsh-unrestricted フック】 - │ ├─ 有効: 制限解除ルールを注入しモード制約を協調 - │ └─ 無効: そのまま通過(100% 公式標準プロンプト) - │ - ├─> ツールおよびプロトコル定義 (Bash/Pwsh, FS, Web Search...) - ├─> 計画モードポリシー (Plan Policy) - └─> 実行環境情報 (CWD, Model...) - │ - ▼ -[LLM API へ送信] +[DSH リクエスト] + │ + ▼ +[システムプロンプト組み立てパイプライン] + │ + ├─> 公式ペルソナ (Persona) + │ │ + │ ▼ [dsh-unrestricted] + │ ├─ 有効: ルールセクションを挿入し各モード制約を調整 + │ └─ 無効: そのまま通過(公式標準プロンプト) + │ + ├─> ツール・プロトコル定義 (Bash/Pwsh, FS, Web Search...) + ├─> 計画モードポリシー (Plan Policy) + └─> 実行環境情報 (CWD, Model...) + │ + ▼ +[モデル API へ送信] ``` -### 各モードとの高度な協調 +### 各実行モードへの対応 -- **Standard / Cordis モード**:全ツール定義を維持しつつ、ペルソナ直後に制限解除ブロックを挿入します。 -- **PTC モード(コード実行専用)**:PTC では `run_code` のみが使用可能です。プラグインは `tools:ptc-only` に注記を追加し、Python/Node 内部で実行されるスクリプトや SDK ツール呼び出しにも制限解除を適用します。 -- **Plan Mode(計画モード)**:安全上の制約は「実行のタイミング」(承認前のファイル変更禁止)にのみ適用され、計画ドキュメント(Markdown)内では技術的な手順やコードを制限なくすべて展開するよう指示します。 -- **Minimal モード**:現在のエージェントスコープでルールを注入し、サブエージェントのカスタムペルソナと公式の構造化出力指示を保持します。ペルソナの重複登録を避け、無効化時には元のプロンプトへ復帰します。 -- **サブエージェント**:派生したバックグラウンドタスクや構造化出力(`structured_output`)も自動的に制限解除設定を継承します。 +DSH の各実行モードに合わせてプロンプトセクションを処理します: -### アンカー検証と自動安全フォールバック +- **Standard / Cordis モード**:ペルソナ直後にルールを挿入し、すべての標準ツール定義を維持します。 +- **PTC モード**:`run_code` でスクリプトを実行するモードです。`tools:ptc-only` セクションに説明を追加し、`run_code` 内の Python/Node スクリプトおよび SDK 呼び出しにも同じ出力ルールを適用します。 +- **Plan モード**:実行権限と計画内容を分け、承認前のファイル変更や書き込み操作は行わず、計画ドキュメント(Markdown)には完全な技術手順とコードを記載します。 +- **Minimal モード**:現在のエージェントスコープ内でルールを注入し、サブエージェントのカスタムペルソナと構造化出力(`structured_output`)の指示を保持します。 +- **サブエージェント**:バックグラウンドのサブエージェントと構造化出力タスクも現在のスイッチ状態を引き継ぎます。 -DSH 本体のバージョン更新によるプロンプト構造の変化を検知するため、プラグインは注入前に特徴文字列(`src/rules.js` の `ANCHORS`)を照合します: +### アンカー検証とフォールバック -- ペルソナ冒頭、Plan モード規則、`run_code` の説明文等を照合します。 -- すべて一致した場合のみ注入を実行します。 -- アンカーが不一致となった場合、プラグインは**該当モードを自動的に公式デフォルトへ安全にフォールバック**させ、UI 上に未検証の項目を表示します。 +組み立てのたびに、公式プロンプト内のアンカー文字列(`src/rules.js` の `ANCHORS`:ペルソナ冒頭、Plan モードポリシー、`run_code` の説明文)を照合します。DSH の更新で文面が変わり一致しなかった場合、そのモードは公式プロンプトへフォールバックし、設定画面に未通過項目を表示します。 -### 即時適用と痕跡ゼロのロールバック +### 即時切り替え -- 設定の変更は即座に反映され、サービスの再起動なしで次回の会話から新しいプロンプトが使用されます。 -- プラグインをオフにすると即座に公式デフォルトに戻り、会話ログや DB に痕跡を残しません。 +スイッチの状態は現在のプロファイルの `cordis.patch.yml` に保存され、サービスを再起動せずに次のリクエストから反映されます。オフにすると公式プロンプトへ戻り、会話履歴にマーカーを残しません。 --- -## インストール・更新 +## インストールと更新 -### Web 版 - -CLI またはサーバー環境で `dsh web` を実行している場合。 - -#### インストール ```sh # 指定バージョンのインストール dsh plugin --profile web add github:yexi-by/dsh-unrestricted#v0.2.5 @@ -113,57 +99,53 @@ dsh plugin --profile web add github:yexi-by/dsh-unrestricted#v0.2.5 # または master 最新コードのインストール dsh plugin --profile web add github:yexi-by/dsh-unrestricted ``` -インストール後に `dsh web` を再起動し、下記の使用方法に従ってプラグインと機能スイッチの両方をオンにします。 -#### アップデート +インストール後に `dsh web` を再起動し、下記の[使い方](#使い方)に従って有効化します。 + +#### 更新 + ```sh dsh plugin --profile web remove dsh-unrestricted -dsh plugin --profile web add github:yexi-by/dsh-unrestricted#新バージョン +dsh plugin --profile web add github:yexi-by/dsh-unrestricted#バージョン番号 ``` + 更新後に `dsh web` を再起動します。 #### アンインストール + ```sh dsh plugin --profile web remove dsh-unrestricted ``` ---- - ### ローカルソースインストール -開発・デバッグ用: +ローカル環境での開発・デバッグ時: ```sh -# Web 版 dsh plugin --profile web add file:D:/work/dsh/plugin/unrestricted - ``` --- -## 使用方法(二重スイッチの確認) +## 使い方 -> **重要:両方のスイッチがオンになって初めて、制限解除が実際に有効化されます!** -> -> 1. **ステップ 1(プラグイン読み込みスイッチ)**:サイドバーの **「プラグイン」** 管理画面を開き、インストール済み一覧から `dsh-unrestricted`(破限モード)を探して、**プラグイン自体を有効化(オン)**にします。ここがオフの場合、DSH はプラグインのコード自体をロードしません。 -> 2. **ステップ 2(機能トグルスイッチ)**:**「プラグイン」** 管理画面で `dsh-unrestricted` をクリックして詳細設定カードを開き、上部の **「破限を有効化」** スイッチをオンにします。 -> -> 上記の 2 つが両方オンになって初めて、システムプロンプト構築時に制限解除ルールが注入されます。 +インストール後、以下の 2 つのスイッチが両方オンになっていることを確認してください: -### 設定画面の機能 +1. **プラグインの有効化**:左サイドバーの **「プラグイン」** 画面で `dsh-unrestricted` を探し、プラグインのスイッチをオンにします。 +2. **破限の有効化**:`dsh-unrestricted` の詳細画面を開き、**「破限モード」** カード内の **「破限を有効化」** をオンにします。 -- **有効化スイッチ**:ワンクリックで制限解除を切り替えます。 -- **各モードの状態表示**:Standard、PTC、Cordis、Minimal の注入状態を表示します。「有効」であれば正常にアンカーが一致し、適用されています(未ロードの場合はプラグイン管理画面でプラグインがオンになっているか確認してください)。 -- **ルールフィンガープリント**:適用されている制限解除テキストの SHA-256 ハッシュ(先頭 16 文字)を表示します。 -- **プロンプトプレビュー**:「プレビューを表示」をクリックすると、モデルに送信される**実際のシステムプロンプト全文・行数・バイト数**を確認できます。 +設定カードでは以下の項目も確認できます: + +- **モード状態**:Standard、PTC、Cordis、Minimal の 4 モードにおけるアンカー照合と注入結果を表示します。 +- **ルールフィンガープリント**:ルールテキストの SHA-256 先頭 16 文字を表示します。 +- **プロンプトプレビュー**:各モードで生成されたシステムプロンプト全文、行数、バイト数を展開表示します。 --- -## 動作境界と注意事項 +## 注意事項 -- **外部ネットワークフィルター**:商用 AI サービスがネットワーク層で設けているキーワード遮断システム(API Gateway)に引っかかった場合、通信が強制切断されます。この外部ネットワーク遮断はプロンプトで回避することはできません。フィルターの緩いプロバイダーや、ローカル(Ollama / vLLM)で動作するオープンモデルのご利用を推奨します。 -- **ホストセキュリティ機構の維持**:本プラグインはモデルの思考・出力内容の制限を解除するものであり、DSH のファイル読み書きサンドボックスやコマンド実行前のユーザー承認プロンプトは引き続き安全に動作します。 -- **コンプライアンス**:正当なセキュリティ研究、リバースエンジニアリング、ソフトウェア開発、創作活動を目的としています。 +- **API ゲートウェイのフィルタリング**:システムプロンプトはモデル自身の応答傾向を調整します。上流の API ゲートウェイ側で別途キーワード遮断が行われている場合、通信層で切断や HTTP 400 エラーが発生することがあります。 +- **ホスト権限機構**:DSH のファイルサンドボックス、コマンド承認ダイアログ、Plan モードの書き込み保護は変更しません。 --- @@ -173,14 +155,21 @@ dsh plugin --profile web add file:D:/work/dsh/plugin/unrestricted git clone https://github.com/yexi-by/dsh-unrestricted.git cd dsh-unrestricted pnpm install + pnpm typecheck pnpm build pnpm test ``` +補助スクリプト: + +- `node tools/dump-prompts.mjs --repo --out tests/fixtures`:指定した DSH ソースディレクトリから公式プロンプトを書き出し、テスト用 fixtures を更新します。 +- `node tools/verify-live.mjs --repo `:モデル API を呼び出さずに、4 モードの組み立てと復元をローカル検証します。 + --- ## ライセンスと謝辞 -- 本プロジェクトの初期プロンプトは [Jia-Ethan/codex-keysmith](https://github.com/Jia-Ethan/codex-keysmith) の `gpt-unrestricted.md`(MIT License)を基に二次創作・改良されたものです。詳細は [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) をご覧ください。 -- 本プロジェクトは [MIT License](LICENSE) の下で公開されています。 +- プロンプトルールの構成は [Jia-Ethan/codex-keysmith](https://github.com/Jia-Ethan/codex-keysmith)(MIT License)を参考に改編しています。詳細は [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) を参照してください。 +- 本プロジェクトは codex-keysmith およびその作者とは関係ありません。 +- [MIT License](LICENSE) の下で公開されています。 diff --git a/README.md b/README.md index 2b00fd5..3045ff2 100644 --- a/README.md +++ b/README.md @@ -2,59 +2,53 @@ **简体中文** | [English](./README.en.md) | [日本語](./README.ja.md) -`dsh-unrestricted` 是 DeepSeek Harness(DSH)的提示词破限插件。插件通过尝试向系统提示词(System Prompt)注入专门设计的破限规则,解除模型在代码逆向、网络安全、敏感内容创作等场景下的回答限制,让模型直接输出完整、可用的技术实现与代码方案。 +`dsh-unrestricted` 是 DeepSeek Harness(DSH)的提示词破限插件。它在系统提示词(System Prompt)组装阶段注入破限规则,放开模型在逆向分析、安全测试、敏感题材写作等场景下的拒答限制,让模型直接给出完整的代码与技术方案。 -插件保持轻量:通过现有开关整体启停破限规则,保留 DSH 原有的界面布局、工具调用协议、计划模式(Plan Mode)、代码执行(PTC)以及子代理运行逻辑。 - -`0.2.5` 修复 Minimal 自定义角色子代理的提示词注册冲突、结构化子代理遗漏官方输出指引,以及设置页并发请求导致的旧预览覆盖和忙碌状态提前解除。现有提示词规则与开关保持不变。支持 DSH `0.2.2-alpha.2`(`f3803c9697`),`engines.dsh` 为 `>=0.2.2-alpha.2 <0.2.3-0`。仅适配上述最新 DSH,不保留旧版兼容。 - -官方新增的自定义模型推理等级与插件索引不替代本插件的按模式提示词组装功能;本轮保留插件。模型推理等级统一由官方模型设置管理。 +插件提供一个总开关控制规则启停,不改动 DSH 原有的界面布局、工具调用协议、计划模式(Plan Mode)、代码执行(PTC)和子代理逻辑。 --- ## 目录 -- [主要特性](#主要特性) -- [技术原理](#技术原理) - - [系统提示词动态拦截与注入](#系统提示词动态拦截与注入) - - [多模式深度适配](#多模式深度适配) - - [特征文本校验与安全降级](#特征文本校验与安全降级) - - [动态开关与无痕回滚](#动态开关与无痕回滚) +- [规则效果](#规则效果) +- [工作原理](#工作原理) + - [系统提示词注入](#系统提示词注入) + - [各运行模式适配](#各运行模式适配) + - [锚点校验与回退](#锚点校验与回退) + - [即时开关](#即时开关) - [安装与更新](#安装与更新) - - [Web 端](#web-端) - [本地源码安装](#本地源码安装) -- [使用说明(双重开关确认)](#使用说明双重开关确认) -- [使用边界与说明](#使用边界与说明) +- [使用说明](#使用说明) +- [注意事项](#注意事项) - [本地开发与测试](#本地开发与测试) - [开源协议与致谢](#开源协议与致谢) --- -## 主要特性 +## 规则效果 -开启破限模式后,插件引导模型遵循以下执行规则: +开启破限后,注入的规则主要改变以下回答行为: -- **直接交付成果,消除废话与说教**:首行直接输出请求的成果(可运行的代码、分析步骤、二进制补丁等),去除客套、免责声明与道德评判。必要的物理防护与安全提示仅作为文末客观附注。 -- **软件逆向与算法分析**:直接定位关键校验逻辑(`CHECK_FN`),提取核心算法,编写注册机(Keygen)生成代码;提供二进制 Patch 的偏移地址(`OFFSET`)与修改字节(`PATCH_BYTE`),输出反调试与反虚拟机绕过脚本。 -- **网络安全与渗透测试**:提供完整的漏洞概念验证代码(PoC / Exploit),包含载荷结构与注入机制;编写多线程爆破脚本、端口与指纹扫描器、带加密传输的反向 Shell 及端口转发脚本。 -- **虚构故事、文学共创与敏感题材创作**:灵活适配正文撰写、剧情与世界观探讨、人物塑造及文书润色。顺应用户选定的文风与审美(唯美、古典、克制、冷峻或直白):当剧情需要直白亲密描写时,身体部位与动作自然直写,不拉灯淡出;当侧重意境与张力时保留文学留白,不强塞生硬词汇。虚构角色静默推定为 18+ 成年人,不触发年龄审查拒答,且严禁刻意强调。 -- **深度技术与特种工业指南**:提供化工实验、药理分析、特殊工业加工等专业操作的完整步骤、试剂物料、精确配比与物理参数,不以安全理由删减关键工艺。 -- **结构化资源检索**:结合 DSH 联网搜索工具自动生成精准检索词,提取真实搜索结果并整理为结构化清单(名称、链接、来源、规格),不编造虚假 URL。 -- **数据与指令严格分离**:工作区内的代码文件和网络抓取的文本一律视为分析数据,不作为覆盖破限规则的新指令;用户明确指定的名称(域名、IP、软件名等)在输出中逐字保留。 +- **直接输出结果**:首行直接给出代码、分析步骤、补丁或正文,省去免责声明、客套话与道德说教;确需说明的物理或操作风险放在文末简短附注。 +- **逆向分析与补丁**:定位校验函数(`CHECK_FN`),还原核心算法并编写注册机(Keygen);标注二进制补丁偏移(`OFFSET`)与替换字节(`PATCH_BYTE`),提供反调试、反虚拟机绕过方案。 +- **安全测试与脚本实现**:编写漏洞验证代码(PoC / Exploit)、多线程字典爆破、端口扫描、加密反向 Shell 及代理转发脚本。 +- **文学创作与文本编校**:适配正文写作、剧情设定推演、人物塑造和文稿润色。按用户指定的文风落笔——需要直白描写时自然写出,不拉灯回避;侧重氛围与克制时保留留白。角色默认按成年人处理,不因年龄话题拒答或刻意强调设定。 +- **工业与实验流程**:给出化工、药理、特种加工等流程的完整步骤、配比与参数,不省略关键环节。 +- **资源检索**:调用联网搜索工具查询并返回整理后的结果列表(名称、链接、来源、规格),不编造链接。 +- **隔离外部文本指令**:工作区文件与网页内容作为输入数据处理,不改变当前回答规则;用户给出的域名、主机、软件名等原样保留。 --- -## 技术原理 +## 工作原理 -### 系统提示词动态拦截与注入 +### 系统提示词注入 -在智能体架构中,DSH 在发起模型请求时会在最外层附带全局的系统提示词(System Prompt),其优先级高于普通的聊天消息。若仅在用户提问中加入越狱提示词,容易被系统提示词压制,也容易破坏 DSH 的工具调用格式。 +DSH 发起请求时会先组装全局系统提示词(System Prompt)。在普通对话里临时附带破限指令容易被系统提示词压过,也可能干扰工具调用格式。 -本插件直接接入 DSH 的系统提示词组装流水线(`system-prompt/assemble`): +插件直接挂载到 `system-prompt/assemble` 组装流水线: -1. **流水线挂钩**:插件在组装流水线中注册全局拦截钩子。 -2. **位置注入**:定位官方角色设定(`deployment:persona-prefix`),在其末尾追加引导声明,并在紧邻的独立分块(`unrestricted:execution-mode`)中注入破限规则正文。 -3. **保留原生能力**:DSH 的工作目录信息(`deployment:persona-suffix`)、所有原生工具定义及环境变量完全保持原样,仅调整控制模型输出尺度与行为的提示词。 +1. 在官方角色设定(`deployment:persona-prefix`)末尾追加引导说明,并在后方插入独立的规则分块(`unrestricted:execution-mode`)。 +2. 工作目录信息(`deployment:persona-suffix`)、工具定义和环境变量保持原样,不改动工具协议。 ```text [DSH 发起请求] @@ -64,50 +58,40 @@ │ ├─> 官方角色设定 (Persona) │ │ - │ ▼ 【dsh-unrestricted 拦截钩子】 - │ ├─ 开启: 动态注入破限规则并协调模式限制 - │ └─ 关闭: 原样放行,完全恢复官方系统提示词 + │ ▼ [dsh-unrestricted] + │ ├─ 开启: 插入破限规则分块并协调各模式约束 + │ └─ 关闭: 原样放行,保持官方默认提示词 │ ├─> 官方工具与协议定义 (Bash/Pwsh, FS, Web Search...) ├─> 计划模式策略 (Plan Policy) └─> 运行环境信息 (CWD, Model...) │ ▼ -[发送给大语言模型 API] +[发送给模型接口] ``` -### 多模式深度适配 +### 各运行模式适配 -针对 DSH 内置的不同运行模式,插件进行了专门的规则协调,确保破限不破坏智能体执行逻辑: +插件按 DSH 的不同运行模式分别处理提示词分块: -- **标准模式(Standard)与 Cordis 模式**:保留所有原生工具定义,在角色设定后注入破限规则,使模型在编写代码、执行系统命令和搜索网络时解除限制。 -- **代码执行模式(PTC)**:PTC 模式下模型仅能调用 `run_code`。插件在 `tools:ptc-only` 中补充规则,指示模型在编写 Python/Node 脚本时同样遵循无限制规则,脚本内部调用 SDK 工具进行安全扫描或逆向分析不受对话限制。 -- **计划模式(Plan Mode)**:将“操作安全”与“方案内容”解耦。插件明确指引:**安全限制仅约束执行时机**(在用户审批前不得修改文件),但在计划草案(Markdown)中,模型必须**毫无保留地展开完整的技术细节、攻击路径与实现代码**。 -- **极简模式(Minimal)**:在当前智能体作用域中注入规则,保留子代理的自定义角色正文与官方结构化输出指引,避免重复注册角色提示词;关闭开关时恢复原版。 -- **子代理与工作流**:派生出的后台子代理及带有结构化输出(`structured_output`)的子任务,均自动继承父级模式的破限规则。 +- **Standard / Cordis 模式**:在角色设定后插入破限规则,保留全部原生工具定义。 +- **PTC 模式**:该模式通过 `run_code` 执行脚本。插件在 `tools:ptc-only` 分块中补充说明,使 `run_code` 内编写的脚本和 SDK 调用遵循同一套输出规则。 +- **Plan 模式**:区分执行权限与方案内容——审批前不修改文件或执行写操作,但计划文档内正常写出完整的技术步骤与代码。 +- **Minimal 模式**:在当前智能体作用域内注入规则,保留子代理原有的自定义角色和结构化输出(`structured_output`)说明。 +- **子代理**:后台子代理与结构化输出任务自动沿用当前开关状态。 -### 特征文本校验与安全降级 +### 锚点校验与回退 -为了防止 DSH 上游版本更新导致底层提示词结构变化引发异常,插件在每次拼装前均校验特征文本(定义在 `src/rules.js` 的 `ANCHORS` 中): +每次组装前,插件会核对官方提示词中的锚点文本(见 `src/rules.js` 的 `ANCHORS`),包括角色设定开头、Plan 模式策略和 `run_code` 说明。如果 DSH 升级后某处文本变动导致匹配失败,对应模式会回退为官方原版提示词,并在设置页标出未通过项,避免拼出损坏的提示词。 -- 校验官方角色开头、Plan 模式规则特征、`run_code` 说明等关键文本; -- 只有全部特征匹配成功时才执行注入; -- 若特征不匹配,插件**自动安全降级**,对该模式保持 DSH 官方原版提示词,并在前端面板显示未通过状态,防止生成畸形提示词。 +### 即时开关 -### 动态开关与无痕回滚 - -- **实时热切换**:开关状态保存在当前 profile 的 `cordis.patch.yml` 中。修改开关后,下次对话或新派生子代理立即生效,无需重启服务。 -- **无痕回滚**:关闭开关后,提示词组装流水线直接输出官方原版内容,会话历史和持久化数据中不留任何插件标记。 +开关状态保存在当前 profile 的 `cordis.patch.yml` 中,切换后从下一次请求开始生效,无需重启服务。关闭开关即恢复官方原版提示词,不会在会话记录中残留标记。 --- ## 安装与更新 -### Web 端 - -适用于通过命令行运行 `dsh web` 的环境。 - -#### 安装 ```sh # 安装指定版本 dsh plugin --profile web add github:yexi-by/dsh-unrestricted#v0.2.5 @@ -115,57 +99,53 @@ dsh plugin --profile web add github:yexi-by/dsh-unrestricted#v0.2.5 # 或安装 master 最新代码 dsh plugin --profile web add github:yexi-by/dsh-unrestricted ``` -安装后重启 `dsh web`,在浏览器打开界面进行启用(详见下方[使用说明](#使用说明双重开关确认))。 + +安装后重启 `dsh web`,按下方[使用说明](#使用说明)启用。 #### 更新 + ```sh dsh plugin --profile web remove dsh-unrestricted dsh plugin --profile web add github:yexi-by/dsh-unrestricted#目标版本号 ``` + 更新后重启 `dsh web`。 #### 卸载 + ```sh dsh plugin --profile web remove dsh-unrestricted ``` ---- - ### 本地源码安装 -面向二次开发调试,使用 `file:` 协议安装本地源码目录: +调试本地源码目录时使用 `file:` 协议安装: ```sh -# Web 端 dsh plugin --profile web add file:D:/work/dsh/plugin/unrestricted - ``` --- -## 使用说明(双重开关确认) +## 使用说明 -> **特别注意:必须同时确保两处开关均已打开,插件才会真正生效!** -> -> 1. **第一步(插件加载开关)**:进入左侧侧边栏的 **「插件」** 管理页面,在已安装插件列表中找到 `dsh-unrestricted`(破限模式),**点击打开/启用该插件**。如果未在插件列表开启,DSH 运行时根本不会加载该插件代码。 -> 2. **第二步(破限功能开关)**:在 **「插件」** 管理页面点开 `dsh-unrestricted` 进入详情配置页,在 **「破限模式」** 设置卡片中将顶部的 **「启用破限」** 开关打开。 -> -> 只有上述两个开关同时开启,破限规则才会实际注入到系统提示词流水线中。 +安装后需确认以下两处开关均已开启: -### 「破限模式」设置面板功能 +1. **启用插件**:在左侧 **「插件」** 页面找到 `dsh-unrestricted`,打开插件开关。 +2. **启用破限**:点开 `dsh-unrestricted` 详情页,在 **「破限模式」** 卡片中打开 **「启用破限」**。 -- **启用破限开关**:一键切换破限功能状态,开启后下一次对话即刻生效。 -- **各模式状态**:实时查看 Standard、PTC、Cordis、Minimal 四个模式的注入状态。显示 `已生效` 即表示特征校验通过并成功注入;若显示异常,请首先检查「插件」管理页面中插件是否已被打开。 -- **提示词指纹**:展示当前注入规则的 SHA-256 哈希值(前 16 位),便于核对部署版本。 -- **查看提示词预览**:点击各模式下的「查看预览」,可实时查看即将发送给模型的**完整系统提示词正文、总行数与字节数**。 +设置卡片中同时提供: + +- **模式状态**:显示 Standard、PTC、Cordis、Minimal 四种模式的锚点校验与注入结果。 +- **规则指纹**:当前规则文本的 SHA-256 前 16 位,用于核对版本。 +- **提示词预览**:展开查看各模式最终生成的完整系统提示词、行数与字节数。 --- -## 使用边界与说明 +## 注意事项 -- **平台网络层审查过滤**:大模型的安全防御通常包含“模型内置对齐”与“云平台网络层审核过滤器(API Gateway)”。本插件通过系统提示词解决模型自身的拒绝倾向。如果使用的商业模型提供商在网络传输层部署了硬性关键词中断审查,触发违规词时连接会被直接切断(报错 400 或违规中断),该情况无法通过提示词绕过。建议搭配审查较宽松的接口或本地开源模型(如 Ollama / vLLM)使用。 -- **宿主安全机制保持生效**:插件仅调整模型的输出尺度与思考深度,不篡改 DSH 本身的系统权限保护机制。DSH 的只读文件沙箱、危险命令审批弹窗以及 Plan 模式未获审批前不修改文件的限制均继续正常生效。 -- **合规声明**:本插件供合法的安全测试、逆向研究、软件开发与文学创作使用。 +- **接口层内容过滤**:系统提示词只能改变模型自身的回答倾向。如果上游 API 网关设有额外的关键词拦截,触发时会直接断开或返回 400 错误,这类网关层拦截无法靠提示词绕过。 +- **宿主权限机制**:插件不改变 DSH 的文件沙箱、命令审批弹窗及 Plan 模式写保护。 --- @@ -176,22 +156,20 @@ git clone https://github.com/yexi-by/dsh-unrestricted.git cd dsh-unrestricted pnpm install -# 检查类型并构建 pnpm typecheck pnpm build - -# 运行规则测试 pnpm test ``` -仓库工具说明: -- `node tools/dump-prompts.mjs --repo --out tests/fixtures`:从指定 DSH 源码目录拉取原版提示词更新测试 fixtures。 -- `node tools/verify-live.mjs --repo `:在真实环境下验证四种模式的组装与回滚(不调用模型接口)。 +辅助脚本: + +- `node tools/dump-prompts.mjs --repo --out tests/fixtures`:从指定 DSH 源码目录导出原版提示词,更新测试 fixtures。 +- `node tools/verify-live.mjs --repo `:在本地验证四种模式的组装与还原结果(不调用模型接口)。 --- ## 开源协议与致谢 -- 提示词规则基础结构与部分任务路由思想参考并二次创作自 [Jia-Ethan/codex-keysmith](https://github.com/Jia-Ethan/codex-keysmith) 项目(MIT License)。版权声明详见 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。 -- 本项目与 codex-keysmith 及其作者无官方隶属关系。 -- 本项目采用 [MIT License](LICENSE) 开源。 +- 提示词规则结构与部分任务路由思路参考并改编自 [Jia-Ethan/codex-keysmith](https://github.com/Jia-Ethan/codex-keysmith)(MIT License),详见 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。 +- 本项目与 codex-keysmith 及其作者无隶属关系。 +- 采用 [MIT License](LICENSE) 开源。 diff --git a/docs/prompt-fusion.en.md b/docs/prompt-fusion.en.md index 270c13b..1dc61fc 100644 --- a/docs/prompt-fusion.en.md +++ b/docs/prompt-fusion.en.md @@ -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 --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 ``` diff --git a/docs/prompt-fusion.ja.md b/docs/prompt-fusion.ja.md index c46a16d..4868855 100644 --- a/docs/prompt-fusion.ja.md +++ b/docs/prompt-fusion.ja.md @@ -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 --out tests/fixtures -# 実環境でプロンプトの組み立てとロールバックを検証 +# API を呼び出さずに 4 モードの組み立てと復元をローカル検証 node tools/verify-live.mjs --repo ``` diff --git a/docs/prompt-fusion.md b/docs/prompt-fusion.md index 59aae2d..faba0f2 100644 --- a/docs/prompt-fusion.md +++ b/docs/prompt-fusion.md @@ -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 --out tests/fixtures -# 在真实运行环境中校验四种模式的拼接与回滚(不消耗 API Token) +# 在本地校验四种模式的组装与还原(不调用模型接口) node tools/verify-live.mjs --repo ```