mirror of
https://github.com/yexi-by/dsh-unrestricted.git
synced 2026-11-27 18:20:23 +08:00
适配 DSH 0.2.3-alpha.2:补齐提示词段 order、修复 minimal 自定义子代理阴影覆盖并更新实景校验
This commit is contained in:
1 parent
7b4b01339b
commit
3d7177dcb9
5 files changed
+90
-27
No files matched your search
+70
-15
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user