适配 DSH 0.2.3-alpha.2:补齐提示词段 order、修复 minimal 自定义子代理阴影覆盖并更新实景校验

This commit is contained in:
yexi committed 2026-11-25 19:32:08 +08:00
1 parent 7b4b01339b
commit 3d7177dcb9
5 files changed
+89 -26

No files matched your search

+2 -2
View File
@@ -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",
+69 -14
View File
@@ -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()
+3 -1
View File
@@ -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 }
}
+1 -1
View File
@@ -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')
})
+14 -8
View File
@@ -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.