From ccc61fac4c422b9b1c9aba3d4b22dd842ecc19b3 Mon Sep 17 00:00:00 2001 From: yexi-by <181818451+yexi-by@users.noreply.github.com> Date: Sat, 28 Nov 2026 04:47:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=87=AA=E7=94=B1?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E7=A0=B4=E9=99=90=E6=8F=90=E7=A4=BA=E8=AF=8D?= =?UTF-8?q?=E4=B8=8E=E4=B8=80=E9=94=AE=E6=81=A2=E5=A4=8D=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=EF=BC=88v0.2.17=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 1 + README.ja.md | 1 + README.md | 1 + lib/client.js | 760 +++++++++++++++++++++++--------- lib/client.js.map | 2 +- locale/en.json | 2 +- locale/zh.json | 2 +- package.json | 2 +- src/client/UnrestrictedCard.tsx | 191 +++++++- src/client/controller.ts | 88 +++- src/client/locales.ts | 36 ++ src/client/styles.ts | 61 +++ src/node.js | 44 +- src/rules.js | 32 +- tests/controller.spec.mjs | 68 ++- tests/rules.spec.mjs | 32 +- tools/verify-live.mjs | 45 +- 17 files changed, 1122 insertions(+), 246 deletions(-) diff --git a/README.en.md b/README.en.md index e1537a8..4766d66 100644 --- a/README.en.md +++ b/README.en.md @@ -34,6 +34,7 @@ dsh plugin --profile web remove dsh-unrestricted Restart `dsh web` or DSH Desktop after installing, then enable both the plugin switch under **Plugins** and **"Enable unrestricted mode"** inside its settings card. Additional card features: - **Strip Host Brand Identity**: Independently removes `DeepSeek Harness` / `DSH` identity sections and Web GUI checkout context to avoid HTTP `429` client-fingerprinting blocks on third-party proxy routes. +- **Custom Execution Prompt Editor**: Edit the injected `unrestricted:execution-mode` prompt directly inside the settings card (e.g., tweak sensitive keywords or substitute custom rules) with instant hot-apply on the next request and one-click reset to default. - **Mode Coverage & Prompt Preview**: Inspect and copy the full assembled system prompt across Standard, PTC, Cordis, and Minimal modes. ## Development & Testing diff --git a/README.ja.md b/README.ja.md index c7e280e..476fbea 100644 --- a/README.ja.md +++ b/README.ja.md @@ -34,6 +34,7 @@ dsh plugin --profile web remove dsh-unrestricted インストール後に `dsh web` または DSH Desktop を再起動し、左サイドバーの **「プラグイン → dsh-unrestricted」** でプラグインスイッチとカード内の **「破限を有効化」** をオンにします。設定カードの追加機能: - **ホストブランド識別子の非表示**:破限スイッチとは独立して動作し、`DeepSeek Harness` / `DSH` の識別セクションや Web GUI パスを除去してサードパーティ経路でのクライアント指紋検知(HTTP `429`)を回避します。 +- **破限プロンプトの自由編集**:設定カード内から `unrestricted:execution-mode` プロンプト本文を自由に編集でき(敏感なキーワードの調整や独自ルールへの差し替えなど)、保存後すぐ次のリクエストから反映されます。ワンクリックで内蔵デフォルトへ復元可能です。 - **モード状態とプロンプトプレビュー**:Standard、PTC、Cordis、Minimal の組み立て済みシステムプロンプトを展開確認・コピーできます。 ## 開発とテスト diff --git a/README.md b/README.md index 862592f..ec65161 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ dsh plugin --profile web remove dsh-unrestricted 安装或更新后重启 `dsh web` 或 DSH 桌面端,在侧栏 **「插件 → dsh-unrestricted」** 打开插件开关与卡片内的 **「启用破限」**。卡片同时提供: - **隐藏宿主品牌标识**:独立于破限主开关生效,移除系统提示词与运行时上下文中的 `DeepSeek Harness` / `DSH` 身份段落与 Web GUI 路径,避免第三方反代路由因客户端特征检测返回 `429`。 +- **破限提示词自由编辑**:支持在卡片内直接编辑 `unrestricted:execution-mode` 破限提示词本体(如删改敏感关键词或替换为自定义规则),保存后从下一次请求即时生效,并支持一键恢复内置默认。 - **模式覆盖与提示词预览**:查看并一键复制 Standard、PTC、Cordis、Minimal 四种模式组装后的完整系统提示词。 ## 开发与验证 diff --git a/lib/client.js b/lib/client.js index a474d23..6f77e97 100644 --- a/lib/client.js +++ b/lib/client.js @@ -11,6 +11,10 @@ window.__ModuleLoader__.load({ const RPC_CHANNEL = "/api"; const RPC_NAMESPACE = "dsh-unrestricted"; const SETTINGS_NS = "unrestricted"; + /** Normalize line endings so YAML/browser values compare identically across OSes. */ + function normalizePromptText(value) { + return typeof value === "string" ? value.replace(/\r\n?/g, "\n") : ""; + } /** Human-readable error text for the banner. */ function messageOf(error) { return error instanceof Error ? error.message : String(error); @@ -26,6 +30,9 @@ window.__ModuleLoader__.load({ let snapshot = { enabled: false, stripHostIdentity: false, + customPrompt: "", + defaultPrompt: "", + isCustomPrompt: false, writable: false, settingsStatus: "loading", status: null, @@ -47,10 +54,16 @@ window.__ModuleLoader__.load({ const settingsSnapshot = settings.getSnapshot(); const enabled = settingsSnapshot.value?.enabled === true; const stripHostIdentity = settingsSnapshot.value?.stripHostIdentity === true; - if (enabled !== snapshot.enabled || stripHostIdentity !== snapshot.stripHostIdentity) invalidatePreviews(); + const customPrompt = normalizePromptText(settingsSnapshot.value?.customPrompt); + const defaultPrompt = normalizePromptText(snapshot.status?.defaultPrompt); + const isCustomPrompt = customPrompt.trim() !== "" && (defaultPrompt === "" || customPrompt !== defaultPrompt); + if (enabled !== snapshot.enabled || stripHostIdentity !== snapshot.stripHostIdentity || customPrompt !== snapshot.customPrompt) invalidatePreviews(); snapshot = { enabled, stripHostIdentity, + customPrompt, + defaultPrompt, + isCustomPrompt, writable: settingsSnapshot.writable, settingsStatus: settingsSnapshot.status, status: snapshot.status, @@ -106,24 +119,52 @@ window.__ModuleLoader__.load({ function refresh(clearPreviews = false) { return readStatus("status", clearPreviews); } - function updateSetting(field, value) { - return whileBusy(async () => { + async function updateSetting(field, value) { + let accepted = false; + await whileBusy(async () => { try { - await settings.set(field, value); + accepted = await settings.set(field, value) !== false; await refresh(true); } catch (error) { snapshot = { ...snapshot, message: messageOf(error) }; + accepted = false; } }); + return accepted; } - function setEnabled(enabled) { - return updateSetting("enabled", enabled); + async function clearCustomPrompt() { + let accepted = false; + await whileBusy(async () => { + try { + accepted = (typeof settings.unset === "function" ? await settings.unset("customPrompt") : await settings.set("customPrompt", "")) !== false; + await refresh(true); + } catch (error) { + snapshot = { + ...snapshot, + message: messageOf(error) + }; + accepted = false; + } + }); + return accepted; } - function setStripHostIdentity(strip) { - return updateSetting("stripHostIdentity", strip); + async function setEnabled(enabled) { + await updateSetting("enabled", enabled); + } + async function setStripHostIdentity(strip) { + await updateSetting("stripHostIdentity", strip); + } + function setCustomPrompt(prompt) { + const normalized = normalizePromptText(prompt); + const defaultPrompt = normalizePromptText(snapshot.status?.defaultPrompt); + if (normalized.trim() === "" || defaultPrompt !== "" && normalized === defaultPrompt) return clearCustomPrompt(); + return updateSetting("customPrompt", normalized); + } + function resetCustomPrompt() { + return clearCustomPrompt(); } function recheck() { return readStatus("recheck", true); @@ -182,6 +223,8 @@ window.__ModuleLoader__.load({ hooks: { view }, setEnabled, setStripHostIdentity, + setCustomPrompt, + resetCustomPrompt, recheck, refresh: () => refresh(true), loadPreview @@ -201,9 +244,27 @@ window.__ModuleLoader__.load({ description: "开启后,各运行模式与委派子代理的系统提示词将自动融合无限制本地执行契约;关闭即恢复 DSH 原版提示词。切换从下一次请求生效,不改动正在执行的请求、工具定义、权限配置与会话历史。", toggle: "启用破限模式", stripHostBadge: "已隐去宿主标识", + customPromptBadge: "已自定义提示词", stripHostTitle: "隐藏宿主品牌标识", stripHostDesc: "移除系统提示词与运行时上下文中的 DeepSeek Harness / DSH 身份段落及开发界面路径,避免第三方路由(适用于 Google Antigravity 反重力反代、Google AI Studio PG 渠道等)因检测到客户端特征而返回 429 拦截(可独立于破限开关生效)。", scopeNote: "仅作用于由 DSH 组装的系统提示词;模型平台或外部网关的远端策略不在本插件覆盖范围内。", + promptEditorTitle: "破限提示词", + promptEditorDesc: "默认内置英文破限契约;支持自由删改敏感关键词或替换为自定义规则,保存后从下一次请求生效。", + promptStateDefault: "内置默认", + promptStateCustom: "已自定义", + promptStateUnsaved: "未保存", + openPromptEditor: "编辑提示词", + closePromptEditor: "收起编辑", + promptEditorLoading: "正在加载内置提示词内容…", + promptEditorPlaceholder: "输入要注入到 unrestricted:execution-mode 段落的提示词内容…", + promptEditorChars: "字符", + promptEditorShortcutHint: "Ctrl/Cmd + Enter 保存", + promptEditorEmptyHint: "提示词不能为空;如需使用内置内容,请点击「恢复默认」。", + promptEditorSaved: "已保存,下一次请求生效", + promptEditorResetDone: "已恢复内置默认提示词", + promptEditorSave: "保存更改", + promptEditorDiscard: "放弃更改", + promptEditorReset: "恢复默认", statusTitle: "模式覆盖与提示词预览", statusSubtitle: "覆盖全部 4 种预设及委派子代理,可随时展开核对或复制融合后的完整提示词。", modeStandard: "Standard 标准模式", @@ -252,9 +313,27 @@ window.__ModuleLoader__.load({ description: "When enabled, system prompts across all modes and delegated subagents are fused with the unrestricted local execution contract; disabling restores the stock DSH prompt immediately. Takes effect from the next request without altering in-flight turns, tool schemas, permissions, or session history.", toggle: "Enable unrestricted mode", stripHostBadge: "Host identity stripped", + customPromptBadge: "Custom prompt", stripHostTitle: "Strip host brand identity", stripHostDesc: "Remove DeepSeek Harness / DSH identity sections and Web GUI checkout context from assembled prompts to prevent HTTP 429 client-fingerprinting blocks on third-party routes such as Google Antigravity proxies and Google AI Studio PG channels (works independently of the main toggle).", scopeNote: "Applies only to system prompts assembled by DSH; upstream model provider policies outside the prompt are out of scope.", + promptEditorTitle: "Execution Prompt", + promptEditorDesc: "Built-in English contract tuned for reliability. Freely edit keywords or replace with custom rules; saved changes apply on the next request.", + promptStateDefault: "Default", + promptStateCustom: "Customized", + promptStateUnsaved: "Unsaved", + openPromptEditor: "Edit prompt", + closePromptEditor: "Hide editor", + promptEditorLoading: "Loading built-in prompt…", + promptEditorPlaceholder: "Enter the prompt text injected into the unrestricted:execution-mode section…", + promptEditorChars: "chars", + promptEditorShortcutHint: "Ctrl/Cmd + Enter to save", + promptEditorEmptyHint: "Prompt cannot be empty. Click \"Reset to default\" to restore the built-in prompt.", + promptEditorSaved: "Saved — applies on next request", + promptEditorResetDone: "Restored built-in default prompt", + promptEditorSave: "Save changes", + promptEditorDiscard: "Discard", + promptEditorReset: "Reset to default", statusTitle: "Mode Coverage & Prompt Preview", statusSubtitle: "Covers all 4 built-in presets and delegated subagents. Expand any mode to inspect or copy the full fused prompt.", modeStandard: "Standard", @@ -543,6 +622,67 @@ window.__ModuleLoader__.load({ overflow-wrap: anywhere; } +.dsh-unrestricted-editor { + display: flex; + flex-direction: column; + gap: 8px; + padding-top: 10px; + border-top: 1px solid var(--dsw-alias-border-l3, var(--dsw-alias-border-l2)); +} + +.dsh-unrestricted-editorInput { + width: 100%; + min-height: 240px; + max-height: 520px; + box-sizing: border-box; + margin: 0; + border: 1px solid var(--dsw-alias-border-l2); + border-radius: var(--dsw-radius-md, 8px); + padding: 10px 12px; + background: var(--dsw-alias-bg-layer-1, var(--dsw-alias-bg-layer-2)); + color: var(--dsw-alias-label-primary); + font-family: var(--ds-font-family-code, ui-monospace, SFMono-Regular, Menlo, monospace); + font-size: 12px; + line-height: 18px; + resize: vertical; + outline: none; + transition: border-color 120ms ease; +} + +.dsh-unrestricted-editorInput:focus { + border-color: var(--dsw-alias-state-business-primary, var(--dsw-alias-border-l1)); +} + +.dsh-unrestricted-editorInput:disabled { + opacity: 0.65; + cursor: not-allowed; +} + +.dsh-unrestricted-editorFooter { + display: flex; + align-items: center; + justify-content: space-between; + flex-wrap: wrap; + gap: 8px 12px; +} + +.dsh-unrestricted-editorStatus { + flex: 1; + min-width: 160px; + margin: 0; + font-size: 12px; + line-height: 18px; + color: var(--dsw-alias-label-tertiary); +} + +.dsh-unrestricted-editorStatus[data-tone='success'] { + color: var(--dsw-alias-state-success-primary); +} + +.dsh-unrestricted-editorStatus[data-tone='warning'] { + color: var(--dsw-alias-state-warning-primary, var(--dsw-alias-state-error-primary)); +} + @media (max-width: 640px) { .dsh-unrestricted-card { padding: 14px; @@ -575,6 +715,7 @@ window.__ModuleLoader__.load({ /** * The unrestricted settings view: * - Master toggle card with native Switch, status Tag, and scope boundary notes + * - Editable execution-mode prompt card with save, discard, and reset-to-default * - Per-preset coverage list with StateDot, Tag, preview drawer, and one-click copy */ /** Mode rows in display order, with their locale label and description keys. */ @@ -648,6 +789,10 @@ window.__ModuleLoader__.load({ const detail = entry.preview?.reason ?? entry.message; return detail !== void 0 && detail.trim() !== "" ? `${t("previewUnavailable")}${detail}` : t("errorPreviewFailed"); } + /** UTF-8 byte length of a string in browser environments. */ + function utf8ByteLength(text) { + return new TextEncoder().encode(text).length; + } /** * Render the unrestricted configuration cards. */ @@ -657,7 +802,26 @@ window.__ModuleLoader__.load({ const status = view.status; const [openPreview, setOpenPreview] = (0, react.useState)(null); const [copiedPreset, setCopiedPreset] = (0, react.useState)(null); + const [editorOpen, setEditorOpen] = (0, react.useState)(false); + const [draft, setDraft] = (0, react.useState)(""); + const [hasLocalEdit, setHasLocalEdit] = (0, react.useState)(false); + const [promptFeedback, setPromptFeedback] = (0, react.useState)(null); + const feedbackTimerRef = (0, react.useRef)(null); const openEntry = openPreview === null ? void 0 : view.previews[openPreview]; + const effectivePrompt = view.customPrompt.trim() !== "" ? view.customPrompt : view.defaultPrompt; + const normalizedDraft = draft.replace(/\r\n?/g, "\n"); + const isDirty = hasLocalEdit && normalizedDraft !== effectivePrompt; + const isDraftEmpty = normalizedDraft.trim() === ""; + const editorReady = effectivePrompt !== "" || view.status !== null; + const controlsEditable = view.writable && view.settingsStatus === "ready" && !view.busy; + const canSave = controlsEditable && isDirty && !isDraftEmpty; + const canReset = controlsEditable && (view.isCustomPrompt || view.defaultPrompt !== "" && normalizedDraft !== view.defaultPrompt); + (0, react.useEffect)(() => { + if (!hasLocalEdit) setDraft(effectivePrompt); + }, [effectivePrompt, hasLocalEdit]); + (0, react.useEffect)(() => () => { + if (feedbackTimerRef.current !== null) clearTimeout(feedbackTimerRef.current); + }, []); (0, react.useEffect)(() => { if (openPreview !== null && openEntry === void 0) loadPreview(openPreview); }, [ @@ -665,6 +829,35 @@ window.__ModuleLoader__.load({ openEntry, loadPreview ]); + function showPromptFeedback(kind) { + setPromptFeedback(kind); + if (feedbackTimerRef.current !== null) clearTimeout(feedbackTimerRef.current); + feedbackTimerRef.current = setTimeout(() => { + setPromptFeedback(null); + feedbackTimerRef.current = null; + }, 2600); + } + async function handleSavePrompt() { + if (!canSave) return; + if (!await props.setCustomPrompt(draft)) return; + const matchedDefault = view.defaultPrompt !== "" && normalizedDraft === view.defaultPrompt; + setHasLocalEdit(false); + showPromptFeedback(matchedDefault ? "reset" : "saved"); + } + function handleDiscardPrompt() { + setDraft(effectivePrompt); + setHasLocalEdit(false); + setPromptFeedback(null); + } + async function handleResetPrompt() { + if (!canReset) return; + if (view.isCustomPrompt) { + if (!await props.resetCustomPrompt()) return; + } + setDraft(view.defaultPrompt); + setHasLocalEdit(false); + showPromptFeedback("reset"); + } const hasFailedMode = status !== null && Object.values(status.modes).some((mode) => mode.state === "failed"); const summaryKey = view.settingsStatus === "loading" ? "summaryLoading" : view.settingsStatus === "unavailable" ? "summaryUnavailable" : hasFailedMode ? "summaryValidationFailed" : view.enabled ? "summaryEnabled" : "summaryDisabled"; const summaryTone = view.settingsStatus !== "ready" ? "neutral" : hasFailedMode ? "warning" : view.enabled ? "success" : "neutral"; @@ -697,219 +890,356 @@ window.__ModuleLoader__.load({ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { className: "dsh-unrestricted-root", "aria-busy": view.busy, - children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", { - className: "dsh-unrestricted-card", - "aria-labelledby": "dsh-unrestricted-main-title", - children: [ - /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { - className: "dsh-unrestricted-header", - children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { - className: "dsh-unrestricted-headerTitle", - children: [ - /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { - id: "dsh-unrestricted-main-title", - className: "dsh-unrestricted-title", - children: t("title") - }), - /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, { - tone: summaryTone, - children: t(summaryKey) - }), - view.settingsStatus === "ready" && view.stripHostIdentity && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, { - tone: "outline", - children: t("stripHostBadge") - }) - ] - }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { - className: "dsh-unrestricted-headerControls", - children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { - className: "dsh-unrestricted-switchLabel", - children: t("toggle") - }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, { - checked: view.enabled, - disabled: !view.writable || view.settingsStatus !== "ready" || view.busy, - label: t("toggle"), - onChange: (checked) => { - props.setEnabled(checked); - } - })] - })] - }), - /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { - className: "dsh-unrestricted-description", - children: t("description") - }), - /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { - className: "dsh-unrestricted-note", - children: t("scopeNote") - }), - /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { - className: "dsh-unrestricted-optionRow", - children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { - className: "dsh-unrestricted-optionCopy", - children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { - className: "dsh-unrestricted-modeName", - children: t("stripHostTitle") - }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { - className: "dsh-unrestricted-note", - children: t("stripHostDesc") - })] - }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, { - checked: view.stripHostIdentity, - disabled: !view.writable || view.settingsStatus !== "ready" || view.busy, - label: t("stripHostTitle"), - onChange: (checked) => { - props.setStripHostIdentity(checked); - } - })] - }), - view.settingsStatus === "loading" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { - className: "dsh-unrestricted-note", - role: "status", - children: t("settingsLoading") - }), - view.settingsStatus === "unavailable" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { - className: "dsh-unrestricted-banner", - "data-tone": "info", - role: "status", - children: t("settingsUnavailable") - }), - view.message !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { - className: "dsh-unrestricted-banner", - "data-tone": "error", - role: "alert", - children: localizeBannerError(view.message, t) - }) - ] - }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", { - className: "dsh-unrestricted-card", - "aria-labelledby": "dsh-unrestricted-modes-title", - children: [ - /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { - className: "dsh-unrestricted-header", - children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { - className: "dsh-unrestricted-headerTitle", - children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", { - id: "dsh-unrestricted-modes-title", - className: "dsh-unrestricted-subtitle", - children: t("statusTitle") - }) - }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { - className: "dsh-unrestricted-headerControls", - children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, { - variant: "outline", - size: "sm", - disabled: view.busy, - onClick: () => { - props.refresh(); - }, - children: t("refresh") - }) - })] - }), - /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { - className: "dsh-unrestricted-note", - children: t("statusSubtitle") - }), - /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", { - className: "dsh-unrestricted-modes", - children: MODE_ROWS.map((row) => { - const mode = status?.modes[row.id]; - const entry = view.previews[row.id]; - const isOpen = openPreview === row.id; - const previewText = entry?.preview?.text; - return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", { - className: "dsh-unrestricted-mode", + children: [ + /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", { + className: "dsh-unrestricted-card", + "aria-labelledby": "dsh-unrestricted-main-title", + children: [ + /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-header", + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-headerTitle", children: [ - /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { - className: "dsh-unrestricted-modeMain", - children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { - className: "dsh-unrestricted-modeInfo", - children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { - className: "dsh-unrestricted-modeHeading", - children: [ - /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.StateDot, { state: dotStateOf(mode) }), - /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { - className: "dsh-unrestricted-modeName", - children: t(row.labelKey) - }), - /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, { - tone: "outline", - children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { - className: "dsh-unrestricted-mono", - children: t(row.presetKey) - }) - }), - /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, { - tone: modeTagTone(mode), - children: t(stateKey(mode)) - }) - ] - }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { - className: "dsh-unrestricted-modeDesc", - children: t(row.descKey) - })] - }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { - className: "dsh-unrestricted-headerControls", - children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, { - variant: isOpen ? "toolbar" : "outline", - size: "sm", - onClick: () => { - togglePreview(row.id); - }, - children: t(isOpen ? "hidePreview" : "showPreview") - }) - })] + /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { + id: "dsh-unrestricted-main-title", + className: "dsh-unrestricted-title", + children: t("title") }), - mode !== void 0 && mode.issues.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { - className: "dsh-unrestricted-issues", - children: formatIssues(mode.issues) + /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, { + tone: summaryTone, + children: t(summaryKey) }), - isOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { - className: "dsh-unrestricted-preview", - children: entry === void 0 || entry.status === "loading" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { - className: "dsh-unrestricted-note", - role: "status", - children: t("previewLoading") - }) : entry.status === "failed" || entry.preview?.available === false ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { - className: "dsh-unrestricted-banner", - "data-tone": "error", - role: "alert", - children: localizePreviewError(entry, t) - }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { - className: "dsh-unrestricted-previewHeader", - children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", { - className: "dsh-unrestricted-previewMeta", - children: [ - entry.preview?.lines, - " ", - t("previewSize"), - entry.preview?.bytes !== void 0 && ` · ${(0, _deepseek_ai_dsh_client_ui_primitives.fileSizeText)(entry.preview.bytes)}`, - entry.preview?.source !== void 0 && ` · ${t(entry.preview.source === "live" ? "previewSourceLive" : "previewSourceStanding")}` - ] - }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, { - variant: "ghost", - size: "sm", - onClick: () => { - handleCopyPreview(row.id, previewText); - }, - children: t(copiedPreset === row.id ? "copiedPreview" : "copyPreview") - })] - }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", { - className: "dsh-unrestricted-previewText", - children: previewText - })] }) + view.settingsStatus === "ready" && view.stripHostIdentity && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, { + tone: "outline", + children: t("stripHostBadge") + }), + view.settingsStatus === "ready" && view.isCustomPrompt && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, { + tone: "info", + children: t("customPromptBadge") }) ] - }, row.id); + }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-headerControls", + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { + className: "dsh-unrestricted-switchLabel", + children: t("toggle") + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, { + checked: view.enabled, + disabled: !view.writable || view.settingsStatus !== "ready" || view.busy, + label: t("toggle"), + onChange: (checked) => { + props.setEnabled(checked); + } + })] + })] + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-description", + children: t("description") + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-note", + children: t("scopeNote") + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-optionRow", + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-optionCopy", + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { + className: "dsh-unrestricted-modeName", + children: t("stripHostTitle") + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-note", + children: t("stripHostDesc") + })] + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, { + checked: view.stripHostIdentity, + disabled: !view.writable || view.settingsStatus !== "ready" || view.busy, + label: t("stripHostTitle"), + onChange: (checked) => { + props.setStripHostIdentity(checked); + } + })] + }), + view.settingsStatus === "loading" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-note", + role: "status", + children: t("settingsLoading") + }), + view.settingsStatus === "unavailable" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-banner", + "data-tone": "info", + role: "status", + children: t("settingsUnavailable") + }), + view.message !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-banner", + "data-tone": "error", + role: "alert", + children: localizeBannerError(view.message, t) }) - }), - /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { - className: "dsh-unrestricted-note", - children: t("subagentNote") - }) - ] - })] + ] + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", { + className: "dsh-unrestricted-card", + "aria-labelledby": "dsh-unrestricted-prompt-title", + children: [ + /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-header", + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-headerTitle", + children: [ + /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", { + id: "dsh-unrestricted-prompt-title", + className: "dsh-unrestricted-subtitle", + children: t("promptEditorTitle") + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, { + tone: view.isCustomPrompt ? "info" : "neutral", + children: t(view.isCustomPrompt ? "promptStateCustom" : "promptStateDefault") + }), + isDirty && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, { + tone: "warning", + children: t("promptStateUnsaved") + }) + ] + }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-headerControls", + children: [view.isCustomPrompt && !editorOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, { + variant: "ghost", + size: "sm", + disabled: !controlsEditable, + onClick: () => { + handleResetPrompt(); + }, + children: t("promptEditorReset") + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, { + variant: editorOpen ? "toolbar" : "outline", + size: "sm", + onClick: () => { + setEditorOpen((open) => !open); + }, + children: t(editorOpen ? "closePromptEditor" : "openPromptEditor") + })] + })] + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-note", + children: t("promptEditorDesc") + }), + editorOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { + className: "dsh-unrestricted-editor", + children: !editorReady ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-note", + role: "status", + children: t("promptEditorLoading") + }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [ + /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-previewHeader", + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", { + className: "dsh-unrestricted-previewMeta", + children: [ + draft === "" ? 0 : draft.split("\n").length, + " ", + t("previewSize"), + ` · ${draft.length} ${t("promptEditorChars")} · ${(0, _deepseek_ai_dsh_client_ui_primitives.fileSizeText)(utf8ByteLength(draft))}` + ] + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { + className: "dsh-unrestricted-previewMeta", + children: t("promptEditorShortcutHint") + })] + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", { + className: "dsh-unrestricted-editorInput", + "aria-label": t("promptEditorTitle"), + placeholder: t("promptEditorPlaceholder"), + spellCheck: false, + value: draft, + disabled: !controlsEditable, + onChange: (event) => { + setDraft(event.target.value); + setHasLocalEdit(true); + setPromptFeedback(null); + }, + onKeyDown: (event) => { + if ((event.ctrlKey || event.metaKey) && event.key === "Enter" && canSave) { + event.preventDefault(); + handleSavePrompt(); + } + } + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-editorFooter", + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-editorStatus", + "data-tone": isDraftEmpty ? "warning" : promptFeedback !== null ? "success" : void 0, + role: "status", + children: isDraftEmpty ? t("promptEditorEmptyHint") : promptFeedback === "saved" ? t("promptEditorSaved") : promptFeedback === "reset" ? t("promptEditorResetDone") : "" + }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-headerControls", + children: [ + isDirty && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, { + variant: "ghost", + size: "sm", + disabled: view.busy, + onClick: handleDiscardPrompt, + children: t("promptEditorDiscard") + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, { + variant: "outline", + size: "sm", + disabled: !canReset, + onClick: () => { + handleResetPrompt(); + }, + children: t("promptEditorReset") + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, { + variant: "primary", + size: "sm", + disabled: !canSave, + onClick: () => { + handleSavePrompt(); + }, + children: t("promptEditorSave") + }) + ] + })] + }) + ] }) + }) + ] + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", { + className: "dsh-unrestricted-card", + "aria-labelledby": "dsh-unrestricted-modes-title", + children: [ + /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-header", + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { + className: "dsh-unrestricted-headerTitle", + children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", { + id: "dsh-unrestricted-modes-title", + className: "dsh-unrestricted-subtitle", + children: t("statusTitle") + }) + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { + className: "dsh-unrestricted-headerControls", + children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, { + variant: "outline", + size: "sm", + disabled: view.busy, + onClick: () => { + props.refresh(); + }, + children: t("refresh") + }) + })] + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-note", + children: t("statusSubtitle") + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", { + className: "dsh-unrestricted-modes", + children: MODE_ROWS.map((row) => { + const mode = status?.modes[row.id]; + const entry = view.previews[row.id]; + const isOpen = openPreview === row.id; + const previewText = entry?.preview?.text; + return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", { + className: "dsh-unrestricted-mode", + children: [ + /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-modeMain", + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-modeInfo", + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-modeHeading", + children: [ + /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.StateDot, { state: dotStateOf(mode) }), + /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { + className: "dsh-unrestricted-modeName", + children: t(row.labelKey) + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, { + tone: "outline", + children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { + className: "dsh-unrestricted-mono", + children: t(row.presetKey) + }) + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, { + tone: modeTagTone(mode), + children: t(stateKey(mode)) + }) + ] + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-modeDesc", + children: t(row.descKey) + })] + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { + className: "dsh-unrestricted-headerControls", + children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, { + variant: isOpen ? "toolbar" : "outline", + size: "sm", + onClick: () => { + togglePreview(row.id); + }, + children: t(isOpen ? "hidePreview" : "showPreview") + }) + })] + }), + mode !== void 0 && mode.issues.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-issues", + children: formatIssues(mode.issues) + }), + isOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { + className: "dsh-unrestricted-preview", + children: entry === void 0 || entry.status === "loading" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-note", + role: "status", + children: t("previewLoading") + }) : entry.status === "failed" || entry.preview?.available === false ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-banner", + "data-tone": "error", + role: "alert", + children: localizePreviewError(entry, t) + }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: "dsh-unrestricted-previewHeader", + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", { + className: "dsh-unrestricted-previewMeta", + children: [ + entry.preview?.lines, + " ", + t("previewSize"), + entry.preview?.bytes !== void 0 && ` · ${(0, _deepseek_ai_dsh_client_ui_primitives.fileSizeText)(entry.preview.bytes)}`, + entry.preview?.source !== void 0 && ` · ${t(entry.preview.source === "live" ? "previewSourceLive" : "previewSourceStanding")}` + ] + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, { + variant: "ghost", + size: "sm", + onClick: () => { + handleCopyPreview(row.id, previewText); + }, + children: t(copiedPreset === row.id ? "copiedPreview" : "copyPreview") + })] + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", { + className: "dsh-unrestricted-previewText", + children: previewText + })] }) + }) + ] + }, row.id); + }) + }), + /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: "dsh-unrestricted-note", + children: t("subagentNote") + }) + ] + }) + ] }); } //#endregion diff --git a/lib/client.js.map b/lib/client.js.map index 0fcdfb3..2144b79 100644 --- a/lib/client.js.map +++ b/lib/client.js.map @@ -1 +1 @@ -{"version":3,"file":"client.js","names":["useState","writeClipboard","Tag","Switch","Button","StateDot","fileSizeText"],"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 reads per-preset state and previews.\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 stripHostIdentity?: boolean\n}\n\n/** Per-preset fusion state reported by the host half. */\nexport interface UnrestrictedModeState {\n state: 'off' | 'active' | 'failed'\n issues: string[]\n}\n\n/** Host status endpoint payload. */\nexport interface UnrestrictedStatus {\n enabled: boolean\n stripHostIdentity?: boolean\n /** Current plugin version reported by the host half. */\n version?: 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 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 /** Structured error code when unavailable. */\n errorCode?: string\n /** Diagnostic reason 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 errorCode?: string\n message?: string\n}\n\n/** Full view snapshot the card subscribes to. */\nexport interface UnrestrictedViewSnapshot {\n /** Persisted toggle; false until the settings scope first syncs. */\n enabled: boolean\n /** Persisted host-brand stripping toggle; false until synced. */\n stripHostIdentity: 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 settings write or status refresh is 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 /** Persist whether host identity branding is stripped from prompts. */\n setStripHostIdentity: (strip: boolean) => Promise\n /** Re-validate runtime state 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 = '/api'\nconst RPC_NAMESPACE = '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 stripHostIdentity: false,\n writable: false,\n settingsStatus: 'loading',\n status: null,\n previews: {},\n busy: false,\n }\n const listeners = new Set<() => void>()\n const previewRequests = new Map()\n let statusGeneration = 0\n let pendingOperations = 0\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 const enabled = settingsSnapshot.value?.enabled === true\n const stripHostIdentity = settingsSnapshot.value?.stripHostIdentity === true\n if (enabled !== snapshot.enabled || stripHostIdentity !== snapshot.stripHostIdentity) {\n invalidatePreviews()\n }\n snapshot = {\n enabled,\n stripHostIdentity,\n writable: settingsSnapshot.writable,\n settingsStatus: settingsSnapshot.status,\n status: snapshot.status,\n previews: snapshot.previews,\n busy: pendingOperations > 0,\n message: snapshot.message,\n }\n for (const listener of listeners) listener()\n }\n\n function invalidatePreviews(): void {\n previewRequests.clear()\n snapshot = { ...snapshot, previews: {} }\n }\n\n async function call(endpoint: string, payload: unknown): Promise {\n const result = await connection.rpc.call(\n RPC_CHANNEL,\n `${RPC_NAMESPACE}/${endpoint}`,\n payload,\n ) as RpcResult\n if (!result.ok) throw new Error(result.error.message)\n return result.value\n }\n\n async function whileBusy(action: () => Promise): Promise {\n pendingOperations++\n publish()\n try {\n await action()\n } finally {\n pendingOperations--\n publish()\n }\n }\n\n function readStatus(endpoint: 'status' | 'recheck', clearPreviews: boolean): Promise {\n const generation = ++statusGeneration\n return whileBusy(async () => {\n try {\n const status = await call(endpoint, {})\n if (generation !== statusGeneration) return\n if (clearPreviews) invalidatePreviews()\n snapshot = {\n ...snapshot,\n status,\n message: undefined,\n }\n } catch (error) {\n if (generation !== statusGeneration) return\n snapshot = { ...snapshot, message: messageOf(error) }\n }\n })\n }\n\n function refresh(clearPreviews = false): Promise {\n return readStatus('status', clearPreviews)\n }\n\n function updateSetting(\n field: K,\n value: NonNullable,\n ): Promise {\n return whileBusy(async () => {\n try {\n await settings.set(field, value)\n await refresh(true)\n } catch (error) {\n snapshot = { ...snapshot, message: messageOf(error) }\n }\n })\n }\n\n function setEnabled(enabled: boolean): Promise {\n return updateSetting('enabled', enabled)\n }\n\n function setStripHostIdentity(strip: boolean): Promise {\n return updateSetting('stripHostIdentity', strip)\n }\n\n function recheck(): Promise {\n return readStatus('recheck', true)\n }\n\n /**\n * Fetch one preset's deploy preview.\n * @param presetId - preset id from the card's row.\n */\n async function loadPreview(presetId: string): Promise {\n const request = Symbol(presetId)\n previewRequests.set(presetId, request)\n snapshot = {\n ...snapshot,\n previews: { ...snapshot.previews, [presetId]: { status: 'loading' } },\n }\n publish()\n try {\n const preview = await call('preview', { presetId })\n if (previewRequests.get(presetId) !== request) return\n snapshot = {\n ...snapshot,\n previews: { ...snapshot.previews, [presetId]: { status: 'ready', preview } },\n }\n } catch (error) {\n if (previewRequests.get(presetId) !== request) return\n snapshot = {\n ...snapshot,\n previews: {\n ...snapshot.previews,\n [presetId]: {\n status: 'failed',\n errorCode: 'preview-failed',\n message: messageOf(error),\n },\n },\n }\n }\n publish()\n }\n\n ctx.effect(\n () => settings.subscribe(publish),\n 'dsh-unrestricted: settings mirror',\n )\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 setStripHostIdentity,\n recheck,\n refresh: () => refresh(true),\n loadPreview,\n }),\n }\n}\n","/** Copy dictionaries for the unrestricted settings card and detail badge. */\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 stripHostBadge: '已隐去宿主标识',\n stripHostTitle: '隐藏宿主品牌标识',\n stripHostDesc: '移除系统提示词与运行时上下文中的 DeepSeek Harness / DSH 身份段落及开发界面路径,避免第三方路由(适用于 Google Antigravity 反重力反代、Google AI Studio PG 渠道等)因检测到客户端特征而返回 429 拦截(可独立于破限开关生效)。',\n scopeNote: '仅作用于由 DSH 组装的系统提示词;模型平台或外部网关的远端策略不在本插件覆盖范围内。',\n statusTitle: '模式覆盖与提示词预览',\n statusSubtitle: '覆盖全部 4 种预设及委派子代理,可随时展开核对或复制融合后的完整提示词。',\n modeStandard: 'Standard 标准模式',\n modeStandardDesc: '日常编码、逆向分析、脚本编写与综合问答',\n modePtc: 'PTC 编程模式',\n modePtcDesc: '基于 run_code 工具链的程序化任务执行',\n modeCordis: 'Cordis 创造模式',\n modeCordisDesc: 'DSH 与 Cordis 插件生态开发调试',\n modeMinimal: 'Minimal 极简模式',\n modeMinimalDesc: '零内置先验的纯净系统提示词与子代理基座',\n subagentNote: '子代理(含结构化输出子代理)随所属会话模式一并生效。',\n stateActive: '已生效',\n stateOff: '待命',\n stateValidationFailed: '已跳过(缺少角色段落)',\n refresh: '刷新状态',\n presetStandard: 'standard',\n presetPtc: 'ptc',\n presetCordis: 'cordis',\n presetMinimal: 'minimal',\n showPreview: '查看提示词',\n hidePreview: '收起预览',\n copyPreview: '复制全文',\n copiedPreview: '已复制',\n previewLoading: '正在生成当前模式的提示词预览…',\n previewUnavailable: '暂无法生成预览:',\n previewSize: '行',\n previewSourceLive: '当前会话实时组装',\n previewSourceStanding: '预设基准组装',\n settingsUnavailable: '当前连接处于只读模式,无法修改设置。',\n settingsLoading: '正在读取配置…',\n operationFailed: '操作失败:',\n issuePersona: '未检测到预设角色前缀段落,已自动保留原版提示词',\n errorRpcDisconnected: '无法连接宿主服务,请确认 DSH 正在运行后刷新重试。',\n errorUnsupportedPreset: '不支持该预设模式的提示词预览。',\n errorMissingPersona: '当前预设未包含角色前缀段落,已自动保留原版提示词。',\n errorPreviewFailed: '生成提示词预览失败,请稍后刷新重试。',\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: 'Read-only',\n summaryValidationFailed: 'Partial mode coverage',\n description: 'When enabled, system prompts across all modes and delegated subagents are fused with the unrestricted local execution contract; disabling restores the stock DSH prompt immediately. Takes effect from the next request without altering in-flight turns, tool schemas, permissions, or session history.',\n toggle: 'Enable unrestricted mode',\n stripHostBadge: 'Host identity stripped',\n stripHostTitle: 'Strip host brand identity',\n stripHostDesc: 'Remove DeepSeek Harness / DSH identity sections and Web GUI checkout context from assembled prompts to prevent HTTP 429 client-fingerprinting blocks on third-party routes such as Google Antigravity proxies and Google AI Studio PG channels (works independently of the main toggle).',\n scopeNote: 'Applies only to system prompts assembled by DSH; upstream model provider policies outside the prompt are out of scope.',\n statusTitle: 'Mode Coverage & Prompt Preview',\n statusSubtitle: 'Covers all 4 built-in presets and delegated subagents. Expand any mode to inspect or copy the full fused prompt.',\n modeStandard: 'Standard',\n modeStandardDesc: 'General coding, reverse engineering, scripting, and technical Q&A',\n modePtc: 'PTC Mode',\n modePtcDesc: 'Programmatic tool calling via the run_code execution environment',\n modeCordis: 'Cordis Mode',\n modeCordisDesc: 'DSH and Cordis plugin development and framework debugging',\n modeMinimal: 'Minimal Mode',\n modeMinimalDesc: 'Zero-prior minimal system prompt and subagent foundation',\n subagentNote: 'Subagents (including structured-output subagents) automatically follow their parent mode.',\n stateActive: 'Active',\n stateOff: 'Standby',\n stateValidationFailed: 'Skipped (missing persona section)',\n refresh: 'Refresh',\n presetStandard: 'standard',\n presetPtc: 'ptc',\n presetCordis: 'cordis',\n presetMinimal: 'minimal',\n showPreview: 'Preview prompt',\n hidePreview: 'Hide preview',\n copyPreview: 'Copy prompt',\n copiedPreview: 'Copied',\n previewLoading: 'Assembling prompt preview…',\n previewUnavailable: 'Preview unavailable: ',\n previewSize: 'lines',\n previewSourceLive: 'Live session assembly',\n previewSourceStanding: 'Preset baseline assembly',\n settingsUnavailable: 'This connection is read-only and cannot modify settings.',\n settingsLoading: 'Loading configuration…',\n operationFailed: 'Operation failed: ',\n issuePersona: 'Preset persona section not found — stock prompt kept',\n errorRpcDisconnected: 'Cannot reach the host service. Please verify DSH is running and refresh.',\n errorUnsupportedPreset: 'Prompt preview is not supported for this preset.',\n errorMissingPersona: 'The preset is missing a persona prefix section; the stock prompt is kept.',\n errorPreviewFailed: 'Could not assemble the prompt preview. Please try refreshing.',\n} satisfies Record\n\n/** Dictionary namespace owned by this plugin. */\nexport const NS = 'settings.unrestricted'\n","/**\n * Stylesheet for the unrestricted settings card. Injected once as a single\n *