From 7beb2d2546599723f3b2958705d1da3b0bbd5e70 Mon Sep 17 00:00:00 2001 From: yexi Date: Sun, 18 Oct 2026 20:27:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Minimal=20=E5=AD=90?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E4=B8=8E=E9=A2=84=E8=A7=88=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E5=B8=83=200.2.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 10 +-- README.ja.md | 10 +-- README.md | 10 +-- docs/prompt-fusion.en.md | 6 +- docs/prompt-fusion.ja.md | 6 +- docs/prompt-fusion.md | 6 +- lib/client.js | 124 +++++++++++++++++------------------ lib/client.js.map | 2 +- package.json | 2 +- src/client/controller.ts | 94 ++++++++++++++------------ src/node.js | 51 ++++++++++----- tests/controller.spec.mjs | 134 ++++++++++++++++++++++++++++++++++++++ tools/verify-live.mjs | 62 ++++++++++++++++++ 13 files changed, 375 insertions(+), 142 deletions(-) create mode 100644 tests/controller.spec.mjs diff --git a/README.en.md b/README.en.md index 2614bfa..c4957dc 100644 --- a/README.en.md +++ b/README.en.md @@ -4,9 +4,9 @@ `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. -The plugin is deeply integrated into DSH's prompt assembly pipeline. While injecting unrestrict rules, it strictly preserves DSH's tool-calling protocols, Plan Mode, code execution (PTC), and subagent mechanics. +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.3` passes type checking, builds, 33 tests, and real-host integration checks against DSH `0.2.1-rc.2` (`687f282e86`), including four-mode toggle restoration, blank-session preset switching, and startup-enabled behavior. The assembly and preset APIs used here are unchanged from `0.2.1-alpha.4`; code, build artifacts, and package version remain unchanged. The declared `engines.dsh` range is `>=0.2.0-rc.2 <0.2.2-0`, retaining installation support for the local `0.2.0-rc.2` desktop runtime; no desktop UI check was performed in this update. +`0.2.4` 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.1-rc.2` (`687f282e86`) with `engines.dsh` set to `>=0.2.0-rc.2 <0.2.2-0`, retaining installation support for desktop `0.2.0-rc.2`. For desktop, this update synchronizes the installed plugin only; the desktop UI is not operated or tested. 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. @@ -84,7 +84,7 @@ The plugin coordinates rules across all DSH execution presets: - **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**: Uses an agent-scoped shadow override to supply the fused minimal persona, cleanly releasing it upon deactivation. +- **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. ### Anchor Text Verification & Safe Fallback @@ -111,7 +111,7 @@ For CLI and server setups running `dsh web`. #### Install ```sh # Install specific tag -dsh plugin --profile web add github:yexi-by/dsh-unrestricted#v0.2.3 +dsh plugin --profile web add github:yexi-by/dsh-unrestricted#v0.2.4 # Or track master dsh plugin --profile web add github:yexi-by/dsh-unrestricted @@ -148,7 +148,7 @@ On Windows, the default path is: 1. Completely exit the desktop app. 2. Run in PowerShell or CMD: ```powershell - & "$env:LOCALAPPDATA\Programs\DeepSeek Harness\resources\runtime\cli\bin\dsh.cmd" plugin --profile desktop add github:yexi-by/dsh-unrestricted#v0.2.3 + & "$env:LOCALAPPDATA\Programs\DeepSeek Harness\resources\runtime\cli\bin\dsh.cmd" plugin --profile desktop add github:yexi-by/dsh-unrestricted#v0.2.4 ``` 3. Launch the desktop app and follow the activation steps below. diff --git a/README.ja.md b/README.ja.md index ee85039..f2571c0 100644 --- a/README.ja.md +++ b/README.ja.md @@ -4,9 +4,9 @@ `dsh-unrestricted` は、**DeepSeek Harness (DSH)** 向けのプロンプト制限解除(アンレストリクト)プラグインです。システムプロンプト(System Prompt)に専用の制限解除ルールを注入することで、リバースエンジニアリング、ペネトレーションテスト、創作執筆、特殊技術手順における回答拒否や説教を解除し、完全で実行可能なコードと技術ソリューションを直接出力させます。 -プラグインは DSH のプロンプト構築メカニズムに深く適合しており、制限解除ルールを動的に注入しつつ、DSH のツール呼び出しプロトコル、計画モード(Plan Mode)、コード実行(PTC)、サブエージェントの実行ロジックを完全に維持します。 +プラグインは軽量な構成を維持し、既存のスイッチでルール全体を有効・無効にします。DSH 本来の画面レイアウト、ツール呼び出しプロトコル、計画モード(Plan Mode)、コード実行(PTC)、サブエージェントの実行ロジックを維持します。 -`0.2.3` は DSH `0.2.1-rc.2`(`687f282e86`)で型チェック、ビルド、33 件のテスト、実ホスト統合検証を完了しています。4 モードの有効化・復元、新規セッションのプリセット切り替え、起動時の有効化を確認しました。使用する組み立て・プリセット API は `0.2.1-alpha.4` から変更されておらず、コード・ビルド成果物・バージョンは維持しています。`engines.dsh` は `>=0.2.0-rc.2 <0.2.2-0` で、ローカルのデスクトップ版 `0.2.0-rc.2` へのインストールを引き続きサポートします。今回デスクトップ UI は操作していません。 +`0.2.4` は、カスタムペルソナを持つ Minimal サブエージェントのプロンプト登録競合、公式の構造化出力指示の欠落、設定画面の並行リクエストによる古いプレビューの上書きや処理中状態の早期解除を修正します。既存のプロンプトルールとスイッチは変更しません。DSH `0.2.1-rc.2`(`687f282e86`)に対応し、`engines.dsh` は `>=0.2.0-rc.2 <0.2.2-0` です。デスクトップ版 `0.2.0-rc.2` へのインストールも引き続きサポートします。今回はローカルのデスクトップ用インストールのみ同期し、デスクトップ UI の操作・検証は行いません。 公式の推論レベル設定とプラグイン索引は、本プラグインのモード別プロンプト組み立てを代替しません。推論レベルは公式のモデル設定で管理します。 @@ -82,7 +82,7 @@ - **Standard / Cordis モード**:全ツール定義を維持しつつ、ペルソナ直後に制限解除ブロックを挿入します。 - **PTC モード(コード実行専用)**:PTC では `run_code` のみが使用可能です。プラグインは `tools:ptc-only` に注記を追加し、Python/Node 内部で実行されるスクリプトや SDK ツール呼び出しにも制限解除を適用します。 - **Plan Mode(計画モード)**:安全上の制約は「実行のタイミング」(承認前のファイル変更禁止)にのみ適用され、計画ドキュメント(Markdown)内では技術的な手順やコードを制限なくすべて展開するよう指示します。 -- **Minimal モード**:エージェントスコープでペルソナを適切に置換し、制限解除ルールを注入します。無効化時には自動的に元の最小ペルソナへ復帰します。 +- **Minimal モード**:現在のエージェントスコープでルールを注入し、サブエージェントのカスタムペルソナと公式の構造化出力指示を保持します。ペルソナの重複登録を避け、無効化時には元のプロンプトへ復帰します。 - **サブエージェント**:派生したバックグラウンドタスクや構造化出力(`structured_output`)も自動的に制限解除設定を継承します。 ### アンカー検証と自動安全フォールバック @@ -109,7 +109,7 @@ CLI またはサーバー環境で `dsh web` を実行している場合。 #### インストール ```sh # 指定バージョンのインストール -dsh plugin --profile web add github:yexi-by/dsh-unrestricted#v0.2.3 +dsh plugin --profile web add github:yexi-by/dsh-unrestricted#v0.2.4 # または master 最新コードのインストール dsh plugin --profile web add github:yexi-by/dsh-unrestricted @@ -146,7 +146,7 @@ Windows の標準パス: 1. デスクトップアプリを完全に終了します。 2. PowerShell 等で以下を実行します: ```powershell - & "$env:LOCALAPPDATA\Programs\DeepSeek Harness\resources\runtime\cli\bin\dsh.cmd" plugin --profile desktop add github:yexi-by/dsh-unrestricted#v0.2.3 + & "$env:LOCALAPPDATA\Programs\DeepSeek Harness\resources\runtime\cli\bin\dsh.cmd" plugin --profile desktop add github:yexi-by/dsh-unrestricted#v0.2.4 ``` 3. デスクトップアプリを起動し、下記の使用方法に従って設定を完了します。 diff --git a/README.md b/README.md index 1d8e8b7..4e8bb11 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ `dsh-unrestricted` 是 DeepSeek Harness(DSH)的提示词破限插件。插件通过尝试向系统提示词(System Prompt)注入专门设计的破限规则,解除模型在代码逆向、网络安全、敏感内容创作等场景下的回答限制,让模型直接输出完整、可用的技术实现与代码方案。 -插件针对 DSH 的提示词组装机制进行了深度适配,在动态注入破限提示词的同时,完整保留 DSH 的工具调用协议、计划模式(Plan Mode)、代码执行(PTC)以及子代理运行逻辑。 +插件保持轻量:通过现有开关整体启停破限规则,保留 DSH 原有的界面布局、工具调用协议、计划模式(Plan Mode)、代码执行(PTC)以及子代理运行逻辑。 -`0.2.3` 已在 DSH `0.2.1-rc.2`(`687f282e86`)复核类型检查、构建、33 项测试与真实宿主集成,四种模式启停恢复、空白会话预设切换和启动时启用均通过。相对 `0.2.1-alpha.4`,使用的组装与预设接口未变,代码、构建产物及版本保持不变。`engines.dsh` 声明为 `>=0.2.0-rc.2 <0.2.2-0`,保留本机桌面版 `0.2.0-rc.2` 的安装支持;本轮不操作桌面界面。 +`0.2.4` 修复 Minimal 自定义角色子代理的提示词注册冲突、结构化子代理遗漏官方输出指引,以及设置页并发请求导致的旧预览覆盖和忙碌状态提前解除。现有提示词规则与开关保持不变。支持 DSH `0.2.1-rc.2`(`687f282e86`),`engines.dsh` 为 `>=0.2.0-rc.2 <0.2.2-0`;保留桌面版 `0.2.0-rc.2` 的安装支持,本轮桌面端仅同步安装副本,不操作或验证桌面界面。 官方新增的自定义模型推理等级与插件索引不替代本插件的按模式提示词组装功能;本轮保留插件。模型推理等级统一由官方模型设置管理。 @@ -84,7 +84,7 @@ - **标准模式(Standard)与 Cordis 模式**:保留所有原生工具定义,在角色设定后注入破限规则,使模型在编写代码、执行系统命令和搜索网络时解除限制。 - **代码执行模式(PTC)**:PTC 模式下模型仅能调用 `run_code`。插件在 `tools:ptc-only` 中补充规则,指示模型在编写 Python/Node 脚本时同样遵循无限制规则,脚本内部调用 SDK 工具进行安全扫描或逆向分析不受对话限制。 - **计划模式(Plan Mode)**:将“操作安全”与“方案内容”解耦。插件明确指引:**安全限制仅约束执行时机**(在用户审批前不得修改文件),但在计划草案(Markdown)中,模型必须**毫无保留地展开完整的技术细节、攻击路径与实现代码**。 -- **极简模式(Minimal)**:极简模式在底层使用独立的作用域注册机制。插件通过代理替换完整的角色设定实现注入,关闭开关时自动释放代理并恢复原版。 +- **极简模式(Minimal)**:在当前智能体作用域中注入规则,保留子代理的自定义角色正文与官方结构化输出指引,避免重复注册角色提示词;关闭开关时恢复原版。 - **子代理与工作流**:派生出的后台子代理及带有结构化输出(`structured_output`)的子任务,均自动继承父级模式的破限规则。 ### 特征文本校验与安全降级 @@ -111,7 +111,7 @@ #### 安装 ```sh # 安装指定版本 -dsh plugin --profile web add github:yexi-by/dsh-unrestricted#v0.2.3 +dsh plugin --profile web add github:yexi-by/dsh-unrestricted#v0.2.4 # 或安装 master 最新代码 dsh plugin --profile web add github:yexi-by/dsh-unrestricted @@ -148,7 +148,7 @@ dsh plugin --profile web remove dsh-unrestricted 1. 完全退出正在运行的桌面客户端。 2. 打开 PowerShell 或 CMD,执行安装命令: ```powershell - & "$env:LOCALAPPDATA\Programs\DeepSeek Harness\resources\runtime\cli\bin\dsh.cmd" plugin --profile desktop add github:yexi-by/dsh-unrestricted#v0.2.3 + & "$env:LOCALAPPDATA\Programs\DeepSeek Harness\resources\runtime\cli\bin\dsh.cmd" plugin --profile desktop add github:yexi-by/dsh-unrestricted#v0.2.4 ``` 3. 启动桌面客户端,按下方说明启用插件与功能开关。 diff --git a/docs/prompt-fusion.en.md b/docs/prompt-fusion.en.md index b5468ce..270c13b 100644 --- a/docs/prompt-fusion.en.md +++ b/docs/prompt-fusion.en.md @@ -62,7 +62,7 @@ DSH provides distinct execution modes with differing prompt structures and tool ### Minimal Mode - **Profile**: Minimal terminal assistant with an isolated scope registration. -- **Coordination**: Uses an agent-scoped shadow override to supply the fused minimal persona, seamlessly releasing it upon deactivation. +- **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. ### Subagents & Structured Output - **Subagents**: Background child agents inherit the unrestrict rules of their parent mode. @@ -84,12 +84,14 @@ Computes a SHA-256 hash (first 16 hex characters) of the unrestrict text block, ### 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. + --- ## 5. Automated Testing ```sh -# Run the 33-assertion test suite +# Run the test suite pnpm test # Dump fresh prompts from DSH source to update fixtures diff --git a/docs/prompt-fusion.ja.md b/docs/prompt-fusion.ja.md index 2866cb3..c46a16d 100644 --- a/docs/prompt-fusion.ja.md +++ b/docs/prompt-fusion.ja.md @@ -62,7 +62,7 @@ DSH は複数の実行モードを備えており、プラグインはそれぞ ### Minimal(最小モード) - **特徴**:非常に軽量なプロンプト構成のエージェント。 -- **適応**:エージェントスコープでペルソナを適切に置換し、制限解除ルールを注入します。無効化時には自動的に元の最小ペルソナへ復帰します。 +- **適応**:現在のエージェントスコープでペルソナ本文を保持しながらルールを注入し、無効化時には元のプロンプトへ復帰します。`0.2.4` は、カスタムペルソナを持つ Minimal サブエージェントで重複登録によって組み立てが失敗する問題を修正し、構造化サブエージェントに必要な公式の `structured_output` 呼び出し指示を保持します。 ### サブエージェントおよび構造化出力 - **サブエージェント**:バックグラウンドで起動されるサブエージェントは親モードの制限解除設定を自動継承します。 @@ -84,12 +84,14 @@ DSH 本体のバージョン更新によるプロンプト構造の変化を検 ### リアルタイムプロンプトプレビュー UI 上の「プレビューを表示」をクリックすることで、実際にモデルへ送信されるシステムプロンプトの全文、行数、バイトサイズをリアルタイムに確認できます。 +更新や再確認が重なっても、古いリクエストの結果が最新の状態やプレビューを上書きすることはありません。処理中の表示は、保留中の状態操作がすべて完了するまで維持します。 + --- ## 5. 自動テストと検証 ```sh -# 33 項目のテストを実行 +# テストを実行 pnpm test # DSH 源码から最新プロンプトを抽出し fixtures を更新 diff --git a/docs/prompt-fusion.md b/docs/prompt-fusion.md index 11d5d9f..59aae2d 100644 --- a/docs/prompt-fusion.md +++ b/docs/prompt-fusion.md @@ -64,7 +64,7 @@ DSH 支持多种工作模式,各模式下的提示词结构和工具调用策 ### Minimal(极简模式) - **特点**:极简模式的系统提示词极其短小,且在底层使用了独立的作用域注册机制。 -- **适配方式**:在 agent 作用域上使用动态代理替换完整的角色设定,将破限规则精炼注入;关闭开关时自动释放代理,恢复极简原貌。 +- **适配方式**:在当前 agent 作用域中保留角色正文并注入规则,关闭开关时恢复原版。`0.2.4` 修复了带自定义角色的 Minimal 子代理因同名提示词重复注册而组装失败的问题,并保留结构化子代理所需的官方 `structured_output` 调用指引。 ### 子代理(Subagent)与结构化输出(structured_output) - **子代理**:主智能体派生的所有后台子代理自动继承父模式的破限规则。 @@ -86,6 +86,8 @@ DSH 支持多种工作模式,各模式下的提示词结构和工具调用策 ### 完整提示词预览 插件提供了专门的 RPC 预览端点。用户在前端界面点击“查看预览”,即可实时获取当前模式即将发送给模型的真实系统提示词、总行数和字节大小,做到底层透明可见。 +并发刷新或重新检查时,过期请求的结果不会覆盖最新状态与预览;忙碌状态保持到所有状态操作结束,避免请求尚未完成就提前解除。 + --- ## 5. 自动化测试与验证 @@ -93,7 +95,7 @@ DSH 支持多种工作模式,各模式下的提示词结构和工具调用策 仓库内置了完善的断言测试与集成验证脚本: ```sh -# 运行全部规则断言测试(33 项测试) +# 运行测试 pnpm test # 从 DSH 源码中重新抓取原版提示词并更新测试 fixtures diff --git a/lib/client.js b/lib/client.js index c825c9a..07db0af 100644 --- a/lib/client.js +++ b/lib/client.js @@ -30,6 +30,9 @@ window.__ModuleLoader__.load({ busy: false }; const listeners = /* @__PURE__ */ new Set(); + const previewRequests = /* @__PURE__ */ new Map(); + let statusGeneration = 0; + let pendingOperations = 0; const view = { getSnapshot: () => snapshot, subscribe: (listener) => { @@ -39,89 +42,80 @@ window.__ModuleLoader__.load({ }; function publish() { const settingsSnapshot = settings.getSnapshot(); + const enabled = settingsSnapshot.value?.enabled === true; + if (enabled !== snapshot.enabled) invalidatePreviews(); snapshot = { - enabled: settingsSnapshot.value?.enabled === true, + enabled, writable: settingsSnapshot.writable, settingsStatus: settingsSnapshot.status, status: snapshot.status, previews: snapshot.previews, - busy: snapshot.busy, + busy: pendingOperations > 0, message: snapshot.message }; for (const listener of listeners) listener(); } + function invalidatePreviews() { + previewRequests.clear(); + snapshot = { + ...snapshot, + previews: {} + }; + } async function call(endpoint, payload) { const result = await connection.rpc.call(RPC_CHANNEL, endpoint, payload); if (!result.ok) throw new Error(result.error.message); return result.value; } - async function refresh(invalidatePreviews = false) { - snapshot = { - ...snapshot, - busy: true - }; + async function whileBusy(action) { + pendingOperations++; publish(); try { - const status = await call("status", {}); - snapshot = { - ...snapshot, - status, - previews: invalidatePreviews ? {} : snapshot.previews, - busy: false, - message: void 0 - }; - publish(); - } catch (error) { - snapshot = { - ...snapshot, - busy: false, - message: messageOf(error) - }; + await action(); + } finally { + pendingOperations--; publish(); } } - async function setEnabled(enabled) { - snapshot = { - ...snapshot, - busy: true - }; - publish(); - try { - await settings.set("enabled", enabled); - await refresh(true); - } catch (error) { - snapshot = { - ...snapshot, - busy: false, - message: messageOf(error) - }; - publish(); - } + function readStatus(endpoint, clearPreviews) { + const generation = ++statusGeneration; + return whileBusy(async () => { + try { + const status = await call(endpoint, {}); + if (generation !== statusGeneration) return; + if (clearPreviews) invalidatePreviews(); + snapshot = { + ...snapshot, + status, + message: void 0 + }; + } catch (error) { + if (generation !== statusGeneration) return; + snapshot = { + ...snapshot, + message: messageOf(error) + }; + } + }); } - async function recheck() { - snapshot = { - ...snapshot, - busy: true - }; - publish(); - try { - const status = await call("recheck", {}); - snapshot = { - ...snapshot, - status, - previews: {}, - busy: false, - message: void 0 - }; - publish(); - } catch (error) { - snapshot = { - ...snapshot, - busy: false, - message: messageOf(error) - }; - publish(); - } + function refresh(clearPreviews = false) { + return readStatus("status", clearPreviews); + } + function setEnabled(enabled) { + return whileBusy(async () => { + try { + await settings.set("enabled", enabled); + await refresh(true); + } catch (error) { + snapshot = { + ...snapshot, + message: messageOf(error) + }; + } + }); + } + function recheck() { + return readStatus("recheck", true); } /** * Fetch one preset's deploy preview. The card renders the raw fused prompt, @@ -129,6 +123,8 @@ window.__ModuleLoader__.load({ * @param presetId - preset id from the card's row. */ async function loadPreview(presetId) { + const request = Symbol(presetId); + previewRequests.set(presetId, request); snapshot = { ...snapshot, previews: { @@ -139,6 +135,7 @@ window.__ModuleLoader__.load({ publish(); try { const preview = await call("preview", { presetId }); + if (previewRequests.get(presetId) !== request) return; snapshot = { ...snapshot, previews: { @@ -150,6 +147,7 @@ window.__ModuleLoader__.load({ } }; } catch (error) { + if (previewRequests.get(presetId) !== request) return; snapshot = { ...snapshot, previews: { diff --git a/lib/client.js.map b/lib/client.js.map index eb3a663..15b20ab 100644 --- a/lib/client.js.map +++ b/lib/client.js.map @@ -1 +1 @@ -{"version":3,"file":"client.js","names":["useState"],"sources":["../src/client/controller.ts","../src/client/locales.ts","../src/client/styles.ts","../src/client/UnrestrictedCard.tsx","../src/client/index.tsx"],"sourcesContent":["/**\n * Browser-half controller for the unrestricted card: binds the `unrestricted`\n * settings namespace (the toggle) and polls the host half's private RPC for\n * per-preset fusion state. Mirrors the card-controller pattern: the apply\n * closure owns the controller, the slot inject face hands hooks and callbacks\n * to the component.\n */\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { ConnectionHandle } from '@deepseek-ai/dsh-client-connection/client'\n// Type-only: the ctx.remote Context merge and the forwarded-event key face.\nimport type {} from '@deepseek-ai/dsh-api-remotes/client'\n// Type-only: the ctx.configForms Context merge.\nimport type {} from '@deepseek-ai/dsh-client-ui-settings/client'\n\n/** The toggle section stored in the `unrestricted` settings namespace. */\nexport interface UnrestrictedSettings {\n enabled?: boolean\n}\n\n/** Per-preset fusion state reported by the host half. */\nexport interface UnrestrictedModeState {\n state: 'off' | 'checking' | 'active' | 'failed'\n issues: string[]\n}\n\n/** Host status endpoint payload. */\nexport interface UnrestrictedStatus {\n enabled: boolean\n /** Fingerprint of the contract bytes the host half deploys. */\n contract: string\n modes: Record\n}\n\n/** Deploy preview for one preset: what switching on would actually assemble. */\nexport interface UnrestrictedPreview {\n presetId: string\n contract: string\n available: boolean\n /** `live` = bytes a live agent received; `standing` = preset scope, no agent bound. */\n source?: 'live' | 'standing'\n /** Fused prompt text; present when available. */\n text?: string\n bytes?: number\n lines?: number\n /** Why no preview could be built; present when unavailable. */\n reason?: string\n}\n\n/** One fetched preview, keyed by preset, plus its in-flight/error state. */\nexport interface UnrestrictedPreviewEntry {\n status: 'loading' | 'ready' | 'failed'\n preview?: UnrestrictedPreview\n message?: string\n}\n\n/** Full view snapshot the card subscribes to. */\nexport interface UnrestrictedViewSnapshot {\n /** Persisted toggle; undefined until the settings scope first syncs. */\n enabled: boolean\n /** Whether the Host document accepts writes. */\n writable: boolean\n /** Settings scope sync state. */\n settingsStatus: 'loading' | 'ready' | 'unavailable'\n /** Live host status; null until the first RPC answer. */\n status: UnrestrictedStatus | null\n /** presetId -> fetched deploy preview. */\n previews: Record\n /** Whether a status refresh or recheck RPC is currently in flight. */\n busy: boolean\n /** Last transport/business failure, if any. */\n message?: string\n}\n\n/** Minimal RPC wire shape (structural copy of the host RpcResult). */\ntype RpcResult = { ok: true; value: T } | { ok: false; error: { code: string; message: string } }\n\n/** Minimal observable contract consumed by the slot renderer's hook binding. */\nexport interface UnrestrictedViewSource {\n getSnapshot(): UnrestrictedViewSnapshot\n subscribe(listener: () => void): () => void\n}\n\n/** Inject face handed to the card at registration. */\nexport interface UnrestrictedCardInjected {\n hooks: {\n /** Reactive card view. */\n view: UnrestrictedViewSource\n }\n /** Persist the toggle. */\n setEnabled: (enabled: boolean) => Promise\n /** Re-run the host-side anchor checks and refresh. */\n recheck: () => Promise\n /** Re-read host status and invalidate cached previews. */\n refresh: () => Promise\n /** Fetch the exact fused prompt this preset would deploy. */\n loadPreview: (presetId: string) => Promise\n}\n\nconst RPC_CHANNEL = '/dsh-unrestricted'\nconst SETTINGS_NS = 'unrestricted'\n\n/** Human-readable error text for the banner. */\nfunction messageOf(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n\n/**\n * Create the card controller bound to the calling plugin's context.\n * @param ctx - the browser plugin context (connection + remote + configForms injected).\n * @returns the controller whose face() feeds the slot inject share.\n */\nexport function createUnrestrictedController(ctx: Context) {\n const connection = ctx.get('connection') as ConnectionHandle\n const settings = ctx.configForms.get(SETTINGS_NS)\n\n let snapshot: UnrestrictedViewSnapshot = {\n enabled: false,\n writable: false,\n settingsStatus: 'loading',\n status: null,\n previews: {},\n busy: false,\n }\n const listeners = new Set<() => void>()\n\n const view: UnrestrictedViewSource = {\n getSnapshot: () => snapshot,\n subscribe: (listener) => {\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n }\n\n function publish(): void {\n const settingsSnapshot = settings.getSnapshot()\n snapshot = {\n enabled: settingsSnapshot.value?.enabled === true,\n writable: settingsSnapshot.writable,\n settingsStatus: settingsSnapshot.status,\n status: snapshot.status,\n previews: snapshot.previews,\n busy: snapshot.busy,\n message: snapshot.message,\n }\n for (const listener of listeners) listener()\n }\n\n async function call(endpoint: string, payload: unknown): Promise {\n const result = await connection.rpc.call(RPC_CHANNEL, endpoint, payload) as RpcResult\n if (!result.ok) throw new Error(result.error.message)\n return result.value\n }\n\n async function refresh(invalidatePreviews = false): Promise {\n snapshot = { ...snapshot, busy: true }\n publish()\n try {\n const status = await call('status', {})\n snapshot = {\n ...snapshot,\n status,\n previews: invalidatePreviews ? {} : snapshot.previews,\n busy: false,\n message: undefined,\n }\n publish()\n } catch (error) {\n snapshot = { ...snapshot, busy: false, message: messageOf(error) }\n publish()\n }\n }\n\n async function setEnabled(enabled: boolean): Promise {\n snapshot = { ...snapshot, busy: true }\n publish()\n try {\n await settings.set('enabled', enabled)\n await refresh(true)\n } catch (error) {\n snapshot = { ...snapshot, busy: false, message: messageOf(error) }\n publish()\n }\n }\n\n async function recheck(): Promise {\n snapshot = { ...snapshot, busy: true }\n publish()\n try {\n const status = await call('recheck', {})\n // The recheck invalidates every cached preview: the deployed bytes may\n // have changed under a new master.\n snapshot = { ...snapshot, status, previews: {}, busy: false, message: undefined }\n publish()\n } catch (error) {\n snapshot = { ...snapshot, busy: false, message: messageOf(error) }\n publish()\n }\n }\n\n /**\n * Fetch one preset's deploy preview. The card renders the raw fused prompt,\n * so the user reads the exact bytes before switching the mode on.\n * @param presetId - preset id from the card's row.\n */\n async function loadPreview(presetId: string): Promise {\n snapshot = {\n ...snapshot,\n previews: { ...snapshot.previews, [presetId]: { status: 'loading' } },\n }\n publish()\n try {\n const preview = await call('preview', { presetId })\n snapshot = {\n ...snapshot,\n previews: { ...snapshot.previews, [presetId]: { status: 'ready', preview } },\n }\n } catch (error) {\n snapshot = {\n ...snapshot,\n previews: { ...snapshot.previews, [presetId]: { status: 'failed', message: messageOf(error) } },\n }\n }\n publish()\n }\n\n ctx.effect(\n () => settings.subscribe(publish),\n 'dsh-unrestricted: settings mirror',\n )\n // External profile configuration edits commit through the settings service, which\n // forwards one document event per commit regardless of namespace.\n ctx.effect(\n () => ctx.remote.$on('settings/document-updated', (namespace?: string) => {\n if (namespace === undefined || namespace === SETTINGS_NS) void refresh(true)\n }),\n 'dsh-unrestricted: settings invalidations',\n )\n\n publish()\n void refresh()\n return {\n face: (): UnrestrictedCardInjected => ({\n hooks: { view },\n setEnabled,\n recheck,\n refresh: () => refresh(true),\n loadPreview,\n }),\n }\n}\n","/** Copy dictionaries for the unrestricted settings card. */\n\n/** Simplified Chinese dictionary and key source of truth. */\nexport const zh = {\n title: '破限模式',\n summaryEnabled: '已开启',\n summaryDisabled: '已关闭',\n summaryLoading: '读取中',\n summaryUnavailable: '设置不可用',\n summaryValidationFailed: '部分模式校验未通过',\n description: '开启后,各模式的系统提示词整体替换为以当前原版为底稿、融合破限规则的完整版本;关闭即恢复 DSH 原版提示词。从下一次请求和新建子代理开始生效,不改动正在执行的请求、工具定义、权限配置与会话历史。',\n toggle: '启用破限',\n scopeNote: '提示词仅由 DSH 生成时才受本插件控制;模型平台或宿主环境中更高优先级的规则不在覆盖范围内。',\n statusTitle: '各模式状态',\n modeStandard: 'Standard 标准模式',\n modePtc: 'PTC 模式',\n modeCordis: 'Cordis 创造模式',\n modeMinimal: 'Minimal 极简模式',\n subagentNote: '子代理随所属模式一并生效。',\n stateActive: '已生效',\n stateOff: '已关闭',\n stateChecking: '校验中',\n stateValidationFailed: '校验未通过,已保持原版',\n recheck: '重新校验',\n refresh: '刷新',\n preflightTitle: '本次即将写入的内容',\n fingerprint: '契约指纹',\n fingerprintNote: '与当前提示词一一对应。各模式实际部署的就是下面这段文本。',\n preset: '预设',\n presetStandard: 'standard',\n presetPtc: 'ptc',\n presetCordis: 'cordis',\n presetMinimal: 'minimal',\n showPreview: '查看预览',\n hidePreview: '收起预览',\n previewLoading: '正在组装当前提示词…',\n previewUnavailable: '暂不可预览:',\n previewSize: '行',\n previewSourceLive: '实时会话',\n previewSourceStanding: '静态预设',\n settingsUnavailable: '当前连接不可写设置(远程浏览器只读)。',\n settingsLoading: '正在读取设置…',\n operationFailed: '操作失败:',\n issueIdentity: 'DSH 身份开场白已变更',\n issuePersona: '预设角色前缀已变更',\n issuePlan: '计划模式段落已变更',\n issuePtcOnly: 'PTC 模式 run_code 规则已变更',\n issueStructuredOutput: '结构化输出指令已变更',\n} satisfies Record\n\n/** Unrestricted card locale key union. */\nexport type UnrestrictedLocaleKey = keyof typeof zh\n\n/** English dictionary checked against the Chinese key set. */\nexport const en = {\n title: 'Unrestricted mode',\n summaryEnabled: 'Enabled',\n summaryDisabled: 'Disabled',\n summaryLoading: 'Loading',\n summaryUnavailable: 'Settings unavailable',\n summaryValidationFailed: 'Some mode checks failed',\n description: 'When enabled, each mode\\'s system prompt is replaced wholesale by a fused prompt built on its current original; disabling restores the stock DSH prompt. Applies from the next request and new subagents; in-flight requests, tool definitions, permissions, and session history are never touched.',\n toggle: 'Enable unrestricted mode',\n scopeNote: 'This plugin can only rewrite prompts DSH generates itself; higher-priority rules from the model platform or host environment are out of scope.',\n statusTitle: 'Per-mode status',\n modeStandard: 'Standard',\n modePtc: 'PTC',\n modeCordis: 'Cordis',\n modeMinimal: 'Minimal',\n subagentNote: 'Subagents follow their parent\\'s mode.',\n stateActive: 'Active',\n stateOff: 'Off',\n stateChecking: 'Checking',\n stateValidationFailed: 'Check failed — stock prompt kept',\n recheck: 'Re-check',\n refresh: 'Refresh',\n preflightTitle: 'What this deployment would write',\n fingerprint: 'Contract fingerprint',\n fingerprintNote: 'One-to-one with the current prompt: the text below is exactly what each mode deploys.',\n preset: 'Preset',\n presetStandard: 'standard',\n presetPtc: 'ptc',\n presetCordis: 'cordis',\n presetMinimal: 'minimal',\n showPreview: 'Show preview',\n hidePreview: 'Hide preview',\n previewLoading: 'Assembling the current prompt…',\n previewUnavailable: 'No preview available: ',\n previewSize: 'lines',\n previewSourceLive: 'live session',\n previewSourceStanding: 'standing preset',\n settingsUnavailable: 'This connection cannot write settings (remote browser is read-only).',\n settingsLoading: 'Reading settings…',\n operationFailed: 'Operation failed: ',\n issueIdentity: 'harness identity opening changed',\n issuePersona: 'preset persona changed',\n issuePlan: 'plan-mode section changed',\n issuePtcOnly: 'ptc-mode run_code rule changed',\n issueStructuredOutput: 'structured-output instruction changed',\n} satisfies Record\n\n/** Dictionary namespace owned by this plugin. */\nexport const NS = 'settings.unrestricted'\n","/**\n * Stylesheet for the unrestricted settings card. One hand-written stylesheet\n * injected as a single