From 3d7177dcb91353a4fb994dd87d0c1934f0366128 Mon Sep 17 00:00:00 2001 From: yexi Date: Wed, 25 Nov 2026 19:32:08 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=20DSH=200.2.3-alpha.2?= =?UTF-8?q?=EF=BC=9A=E8=A1=A5=E9=BD=90=E6=8F=90=E7=A4=BA=E8=AF=8D=E6=AE=B5?= =?UTF-8?q?=20order=E3=80=81=E4=BF=AE=E5=A4=8D=20minimal=20=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=AD=90=E4=BB=A3=E7=90=86=E9=98=B4=E5=BD=B1?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E5=B9=B6=E6=9B=B4=E6=96=B0=E5=AE=9E=E6=99=AF?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +- src/node.js | 85 +++++++++++++++++++++++++++++++++-------- src/rules.js | 4 +- tests/manifest.spec.mjs | 2 +- tools/verify-live.mjs | 22 +++++++---- 5 files changed, 90 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index ca9c641..a4a2968 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "dsh-unrestricted", - "version": "0.2.15", + "version": "0.2.16", "engines": { - "dsh": ">=0.2.0-rc.2 <0.2.3-0" + "dsh": ">=0.2.0-rc.2 <0.2.4-0" }, "private": true, "description": "Toggleable unrestricted mode for DeepSeek Harness: fuses execution rules into the active standard, ptc, cordis, minimal, and subagent prompts", diff --git a/src/node.js b/src/node.js index b758bea..2d2c3c0 100644 --- a/src/node.js +++ b/src/node.js @@ -39,7 +39,7 @@ import { registerRpcRoutes } from './rpc.js' export const name = 'dsh-unrestricted' /** Current plugin package version. */ -export const PLUGIN_VERSION = '0.2.15' +export const PLUGIN_VERSION = '0.2.16' /** Services required by this plugin (all base-backed profiles provide these). */ export const inject = ['settings', 'systemPrompt', 'loader'] @@ -69,6 +69,7 @@ export function apply(ctx, config) { const initialConfig = config.get() const state = { + active: true, enabled: Boolean(initialConfig.enabled), stripHostIdentity: Boolean(initialConfig.stripHostIdentity), extraPresets: new Set(initialConfig.extraPresets ?? []), @@ -78,6 +79,10 @@ export function apply(ctx, config) { shadows: new Map(), /** Minimal agents whose persona was already registered at agent scope by caller. */ customMinimal: new WeakSet(), + /** Minimal agents currently being probed for complete-section ownership. */ + probingMinimal: new WeakSet(), + /** Agents already disposed, guarding async shadow probes against late writes. */ + disposed: new WeakSet(), /** Precomputed fused minimal prompt. */ fusedMinimal: fusedMinimalPrompt(), } @@ -158,20 +163,27 @@ export function apply(ctx, config) { } /** - * Synchronize a minimal agent's complete persona shadow with its current - * preset and toggle state. If the agent is no longer on `minimal`, any stale - * shadow from an earlier blank-session preset selection is disposed. + * Determine whether a post-assembly section list belongs to a stock + * complete-persona minimal agent rather than a custom-persona child override. + * On DSH >= 0.2.3, `AssembledSection` exposes `order` and `complete`; on + * DSH <= 0.2.2, a complete assembly restores a single `deployment:persona-prefix` + * section without `order`. */ - function syncMinimalShadow(agent) { - if (!state.enabled) { - unshadowMinimal(agent) - return - } - const presetId = resolveAgentPreset(agent) - if (presetId !== 'minimal') { - unshadowMinimal(agent) - return - } + function isCompleteMinimalAssembly(sections) { + const persona = sections.find(section => section.name === 'deployment:persona-prefix') + if (persona === undefined) return false + if (typeof persona.order === 'number') return persona.complete === true + return sections.length === 1 + } + + /** + * Register the fused complete persona shadow directly on a stock minimal + * agent. Still handles the duplicate-section error thrown by DSH <= 0.2.2 if + * a caller registered a persona in the same scope before probing completed. + */ + function installMinimalShadow(agent) { + if (!state.active || !state.enabled || state.disposed.has(agent)) return + if (resolveAgentPreset(agent) !== 'minimal') return if (state.shadows.has(agent) || state.customMinimal.has(agent)) return let dispose try { @@ -196,6 +208,39 @@ export function apply(ctx, config) { state.shadows.set(agent, dispose) } + /** + * Synchronize a minimal agent's complete persona shadow with its current + * preset and toggle state. Probes the scope read-only (no `agent`/`session`) + * before installing a shadow so DSH >= 0.2.3's latest-registration-wins rule + * never overwrites a child subagent's custom non-complete persona. + */ + function syncMinimalShadow(agent) { + if (!state.active || !state.enabled || state.disposed.has(agent)) { + unshadowMinimal(agent) + return + } + const presetId = resolveAgentPreset(agent) + if (presetId !== 'minimal') { + unshadowMinimal(agent) + return + } + if (state.shadows.has(agent) || state.customMinimal.has(agent) || state.probingMinimal.has(agent)) return + state.probingMinimal.add(agent) + void ctx.systemPrompt.assemble({ scope: agent }).then((assembly) => { + if (!state.active || !state.enabled || state.disposed.has(agent)) return + if (resolveAgentPreset(agent) !== 'minimal') return + if (isCompleteMinimalAssembly(assembly.sections)) { + installMinimalShadow(agent) + } else { + state.customMinimal.add(agent) + } + }).catch(() => { + // Agent or scope disposed while probing; ignore transient error. + }).finally(() => { + state.probingMinimal.delete(agent) + }) + } + /** Synchronize minimal persona shadows across all live agents. */ function sweepAgents() { const agents = ctx.get('agents') @@ -365,7 +410,15 @@ export function apply(ctx, config) { if (presetId === 'minimal') { if (state.enabled) { - if (!state.shadows.has(agent)) syncMinimalShadow(agent) + if (!state.shadows.has(agent) && !state.customMinimal.has(agent)) { + const persona = current.sections.find(section => section.name === 'deployment:persona-prefix') + if (persona !== undefined && typeof persona.order === 'number') { + if (persona.complete === true) installMinimalShadow(agent) + else state.customMinimal.add(agent) + } else { + installMinimalShadow(agent) + } + } if (state.customMinimal.has(agent)) { const fused = fuseSections(current.sections, 'minimal', { isSubagent: true }) if (fused.issues !== undefined) { @@ -419,6 +472,7 @@ export function apply(ctx, config) { }) ctx.on('agent/disposed', ({ agent }) => { + state.disposed.add(agent) state.customMinimal.delete(agent) unshadowMinimal(agent) }) @@ -436,6 +490,7 @@ export function apply(ctx, config) { }) if (state.enabled) onEnable() return () => { + state.active = false state.enabled = false unwatch() clearShadows() diff --git a/src/rules.js b/src/rules.js index 0725ae6..16ed92f 100644 --- a/src/rules.js +++ b/src/rules.js @@ -252,6 +252,8 @@ export function fuseSections(sections, presetId, { isSubagent = false, allowDyna const personaIndex = fused.findIndex(section => section.name === 'deployment:persona-prefix') const identityIndex = fused.findIndex(section => section.name === 'harness:identity') const insertAt = personaIndex >= 0 ? personaIndex + 1 : (identityIndex >= 0 ? identityIndex + 1 : 0) - fused.splice(insertAt, 0, { name: BLOCK_SECTION, text: EXECUTION_MODE_BLOCK }) + const anchor = personaIndex >= 0 ? fused[personaIndex] : (identityIndex >= 0 ? fused[identityIndex] : undefined) + const blockOrder = typeof anchor?.order === 'number' && Number.isFinite(anchor.order) ? anchor.order + 1 : 101 + fused.splice(insertAt, 0, { name: BLOCK_SECTION, order: blockOrder, text: EXECUTION_MODE_BLOCK }) return { sections: fused } } diff --git a/tests/manifest.spec.mjs b/tests/manifest.spec.mjs index eab22b1..edc3abb 100644 --- a/tests/manifest.spec.mjs +++ b/tests/manifest.spec.mjs @@ -15,5 +15,5 @@ test('declares the current client renderer, settings dependencies, and Web + Des ]) assert.equal(manifest.dsh.client.platform, 'web') assert.equal(manifest.dsh.bundle.patch, './cordis.patch.yml') - assert.equal(manifest.engines.dsh, '>=0.2.0-rc.2 <0.2.3-0') + assert.equal(manifest.engines.dsh, '>=0.2.0-rc.2 <0.2.4-0') }) diff --git a/tools/verify-live.mjs b/tools/verify-live.mjs index 0f108b0..502bd85 100644 --- a/tools/verify-live.mjs +++ b/tools/verify-live.mjs @@ -18,7 +18,8 @@ * * Read-only against the repo. Requires the repo's `lib/` build outputs. */ -import { mkdtemp, mkdir, cp, writeFile } from 'node:fs/promises' +import { realpathSync } from 'node:fs' +import { mkdtemp, mkdir, cp, readFile, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import { dirname, join, resolve } from 'node:path' import { pathToFileURL, fileURLToPath } from 'node:url' @@ -29,8 +30,9 @@ function arg(name) { return process.argv[index + 1] } -const repo = resolve(arg('repo')) -const pluginDir = resolve(fileURLToPath(new URL('..', import.meta.url))) +const repo = realpathSync.native(resolve(arg('repo'))) +const pluginDir = realpathSync.native(resolve(fileURLToPath(new URL('..', import.meta.url)))) +const pluginVersion = JSON.parse(await readFile(join(pluginDir, 'package.json'), 'utf8')).version const bootEnabled = process.argv.includes('--boot-enabled') async function importPackage(relativeDir) { @@ -39,8 +41,6 @@ async function importPackage(relativeDir) { return import(pathToFileURL(join(repo, relativeDir, entry)).href) } -import { readFile } from 'node:fs/promises' - const appBoot = await importPackage('packages/boot/app-boot') const cmdline = await importPackage('packages/boot/cmdline') const { SessionId } = await importPackage('packages/core/session') @@ -88,6 +88,8 @@ const overrides = [ }, ] if (bootEnabled) overrides.push({ id: 'unrestricted', config: { enabled: true } }) +const overridesPath = join(home, 'verify-overrides.yml') +await writeFile(overridesPath, `${JSON.stringify(overrides, null, 2)}\n`) const installAnchor = join(repo, 'apps/cli/package.json') const profile = { @@ -110,7 +112,7 @@ const ctx = await appBoot.boot('dsh-test', rootConfig, [...bundlePatches, ...ove name: 'spec', dir: profileDir, patchPath: profile.patchPath, installAnchor, home, cwd: home, startedBundles: ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app', 'dsh-unrestricted'], - overlays: overrides, telemetryDisabledEnv: '1', + overlayPaths: [overridesPath], telemetryDisabledEnv: '1', }) await bootCtx.plugin(appBoot.PluginPackages, { resolution }) cmdline.provideCmdline(bootCtx, { args: [], exit: () => {} }) @@ -306,7 +308,7 @@ try { check('shared /api status RPC returns 200 ok with current version', rpcStatus.status === 200 && rpcStatus.body?.result?.ok === true - && rpcStatus.body.result.value?.version === '0.2.14' + && rpcStatus.body.result.value?.version === pluginVersion && rpcStatus.body.result.value?.enabled === true) const rpcPreview = await callSharedRpc('preview', { presetId: 'standard' }) check('shared /api preview RPC returns 200 ok with fused prompt', @@ -330,7 +332,11 @@ try { check('plan on: plan keeps the contract scope', planOn.text.includes('this contract decides the content')) planAgent.session.append('plan/mode', { active: false }) const planOff = await assemblePrompt(planAgent) - check('plan off: plan section gone', !planOff.text.includes('You are in plan mode.')) + const hasPlanStatus = planOff.sections.includes('plan:status') + check('plan off: plan mode marked inactive', hasPlanStatus + ? (planOff.text.includes('Plan mode is inactive. The plan-mode instructions no longer apply.') + && !planOff.text.includes('Plan mode is active.')) + : !planOff.text.includes('You are in plan mode.')) check('plan off: still fused', planOff.text.includes(rules.EXECUTION_MODE_BLOCK)) // PTC mode keeps its run_code protocol.