From c7afd4e03d162cf9545f47168f29a5ec225c0bd0 Mon Sep 17 00:00:00 2001 From: yexi Date: Sun, 15 Nov 2026 10:33:19 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=90=8C=E6=AD=A5=20DSH=200.2.2-rc.3?= =?UTF-8?q?=20=E5=8E=9F=E7=89=88=E6=8F=90=E7=A4=BA=E8=AF=8D=E5=BF=AB?= =?UTF-8?q?=E7=85=A7=E3=80=81=E8=A1=A5=E5=85=85=E6=A0=B7=E5=BC=8F=E6=B8=85?= =?UTF-8?q?=E7=90=86=E5=B9=B6=E5=8D=87=E7=BA=A7=E8=87=B3=20v0.2.9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cordis.patch.yml | 7 -- lib/client.js | 15 ++- lib/client.js.map | 2 +- package.json | 2 +- src/client/index.tsx | 2 +- src/client/styles.ts | 13 +- src/node.js | 2 +- tests/fixtures/meta.json | 32 ++--- tests/fixtures/original-cordis-plan.md | 4 +- tests/fixtures/original-cordis.md | 4 +- tests/fixtures/original-ptc-plan.md | 111 ++++++++++++----- tests/fixtures/original-ptc.md | 111 ++++++++++++----- tests/fixtures/original-standard-plan.md | 2 +- tests/fixtures/original-standard.md | 2 +- tests/fixtures/original-subagent-standard.md | 2 +- tests/fixtures/sections-cordis-plan.json | 4 +- tests/fixtures/sections-cordis.json | 4 +- tests/fixtures/sections-ptc-plan.json | 4 +- tests/fixtures/sections-ptc.json | 4 +- tests/fixtures/sections-standard-plan.json | 2 +- tests/fixtures/sections-standard.json | 2 +- .../fixtures/sections-subagent-standard.json | 2 +- tests/fixtures/tools-cordis-plan.json | 16 --- tests/fixtures/tools-cordis.json | 16 --- tests/fixtures/tools-ptc-plan.json | 2 +- tests/fixtures/tools-ptc.json | 2 +- tests/fixtures/tools-standard-plan.json | 112 +++++++++++++++--- tests/fixtures/tools-standard.json | 112 +++++++++++++++--- tests/fixtures/tools-subagent-standard.json | 112 +++++++++++++++--- 29 files changed, 518 insertions(+), 187 deletions(-) diff --git a/cordis.patch.yml b/cordis.patch.yml index 09a9316..d4e2b02 100644 --- a/cordis.patch.yml +++ b/cordis.patch.yml @@ -1,10 +1,3 @@ -# 私有 RPC 需要 Connection 持有 webServer;启动参数由官方 webStartup 提供。 -- id: connection - name: '@deepseek-ai/dsh-client-connection' - inject: [webStartup, webServer] - config: - trustedHosts: !!js ctx.webStartup.trustedHosts - # dsh-unrestricted bundle layer: one row mounts the plugin's node half; the # browser half is discovered through the package's dsh.client manifest and # served by the client-module registry. Prompt fusion happens in the node diff --git a/lib/client.js b/lib/client.js index 2dad577..419e812 100644 --- a/lib/client.js +++ b/lib/client.js @@ -520,14 +520,21 @@ window.__ModuleLoader__.load({ } } `; - /** Inject the stylesheet once; the tag id doubles as the re-evaluation guard. */ + /** Inject the stylesheet once and clean it up when this effect disposes. */ function ensureStyles() { - if (typeof document === "undefined") return; - if (document.querySelector("style[data-plugin=\"dsh-unrestricted\"]") !== null) return; + if (typeof document === "undefined") return () => {}; + const existing = document.querySelector("style[data-plugin=\"dsh-unrestricted\"]"); + if (existing !== null) { + existing.textContent = CSS; + return () => {}; + } const tag = document.createElement("style"); tag.dataset.plugin = "dsh-unrestricted"; tag.textContent = CSS; document.head.appendChild(tag); + return () => { + tag.remove(); + }; } //#endregion //#region src/client/UnrestrictedCard.tsx @@ -856,7 +863,7 @@ window.__ModuleLoader__.load({ ]; /** 注册本插件的配置卡片。 */ function apply(ctx) { - ensureStyles(); + ctx.effect(() => ensureStyles(), "dsh-unrestricted: stylesheet"); ctx.effect(() => ctx.locale.register(NS, { zh, en diff --git a/lib/client.js.map b/lib/client.js.map index d6943d3..2e8d8db 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}\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 /** 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 /** 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 /** 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 = '/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 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 if (enabled !== snapshot.enabled) invalidatePreviews()\n snapshot = {\n enabled,\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(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 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 setEnabled(enabled: boolean): Promise {\n return whileBusy(async () => {\n try {\n await settings.set('enabled', enabled)\n await refresh(true)\n } catch (error) {\n snapshot = { ...snapshot, message: messageOf(error) }\n }\n })\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 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 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 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 *