适配 DSH 0.1.7 配置与会话接口

This commit is contained in:
yexi committed 2026-09-22 19:12:55 +08:00
1 parent fa575632e5
commit 9ca994201a
33 files changed
+228 -221

No files matched your search

+1 -1
View File
@@ -75,7 +75,7 @@ export function UnrestrictedCard(props: UnrestrictedCardProps) {
}
return (
<details className="dsh-unrestricted-card">
<details open className="dsh-unrestricted-card">
<summary className="dsh-unrestricted-summary">
<span className="dsh-unrestricted-summaryText">
<span className="dsh-unrestricted-title" role="heading" aria-level={3}>{t('title')}</span>
+4 -4
View File
@@ -9,7 +9,7 @@ import type { Context } from '@deepseek-ai/cordis'
import type { ConnectionHandle } from '@deepseek-ai/dsh-client-connection/client'
// Type-only: the ctx.remote Context merge and the forwarded-event key face.
import type {} from '@deepseek-ai/dsh-api-remotes/client'
// Type-only: the ctx.settingsScope Context merge.
// Type-only: the ctx.configForms Context merge.
import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
/** The toggle section stored in the `unrestricted` settings namespace. */
@@ -104,12 +104,12 @@ function messageOf(error: unknown): string {
/**
* Create the card controller bound to the calling plugin's context.
* @param ctx - the browser plugin context (connection + remote + settingsScope injected).
* @param ctx - the browser plugin context (connection + remote + configForms injected).
* @returns the controller whose face() feeds the slot inject share.
*/
export function createUnrestrictedController(ctx: Context) {
const connection = ctx.get('connection') as ConnectionHandle
const settings = ctx.settingsScope.bind<UnrestrictedSettings>({ namespace: SETTINGS_NS })
const settings = ctx.configForms.get<UnrestrictedSettings>(SETTINGS_NS)
let snapshot: UnrestrictedViewSnapshot = {
enabled: false,
@@ -208,7 +208,7 @@ export function createUnrestrictedController(ctx: Context) {
() => settings.subscribe(publish),
'dsh-unrestricted: settings mirror',
)
// External settings.yaml edits commit through the settings service, which
// External profile configuration edits commit through the settings service, which
// forwards one document event per commit regardless of namespace.
ctx.effect(
() => ctx.remote.$on('settings/document-updated', (namespace?: string) => {
+1 -1
View File
@@ -19,7 +19,7 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
}
/** Services required by the registration and the controller. */
export const inject = ['slots', 'locale', 'connection', 'remote', 'settingsScope']
export const inject = ['slots', 'locale', 'connection', 'remote', 'configForms']
/** 注册本插件的配置页面。 */
export function apply(ctx: Context): void {
+24 -17
View File
@@ -22,13 +22,14 @@
* settings card.
*
* The toggle lives in the `unrestricted` settings namespace (persisted to
* $DSH_HOME/settings.yaml). Switching affects the NEXT assembly of any live
* $DSH_HOME/profiles/web/cordis.patch.yml). Switching affects the NEXT assembly of any live
* or future agent — never an in-flight request or a logged session event.
*/
import z from '@deepseek-ai/schemastery'
import { renderPrompt } from '@deepseek-ai/dsh-system-prompt'
import { createScope } from '@deepseek-ai/dsh-scope'
import {
ANCHORS, PRESETS, PRESET_RULES, contractFingerprint, fuseSections, fusedMinimalPrompt, renderPreview,
PRESETS, PRESET_RULES, contractFingerprint, fuseSections, fusedMinimalPrompt, renderPreview,
} from './rules.js'
/** Cordis plugin name used by Loader diagnostics. */
@@ -39,9 +40,9 @@ export const inject = ['settings', 'systemPrompt', 'agentPresets']
const RPC_CHANNEL = '/dsh-unrestricted'
const Section = z.object({
export const Config = z.object({
enabled: z.boolean().default(false),
})
}).default({ enabled: false }).volatile()
/** Human-readable error text for status and RPC error branches. */
function messageOf(error) {
@@ -57,11 +58,11 @@ function ok(value) {
* @param ctx - plugin context carrying settings, systemPrompt, agentPresets,
* connection, and the cordis Loader.
*/
export function apply(ctx) {
const scope = ctx.settings.register('unrestricted', Section)
export function apply(ctx, config) {
ctx.effect(() => ctx.settings.configure({ auto: false }, ctx.fiber))
const state = {
enabled: scope.get().enabled,
enabled: config.get().enabled,
/** presetId -> issue strings; a preset with an empty list is verified. */
startup: new Map(),
/** presetId -> in-flight startup check. */
@@ -81,6 +82,18 @@ export function apply(ctx) {
return [...state.startup.get(presetId) ?? [], ...state.runtime.get(presetId) ?? []]
}
/** 用公开预设挂载接口读取当前配置;临时作用域在组装后释放。 */
async function presetAssembly(presetId) {
const key = {}
const scope = createScope(ctx, key)
try {
await ctx.agentPresets.mount(scope.ctx, presetId)
return await ctx.systemPrompt.assemble({ scope: key })
} finally {
await scope.dispose()
}
}
/**
* Run the standing-scope anchor check for ONE preset (lazy per-preset, so a
* minimal toggle never waits on the other three mounts). Idempotent per
@@ -92,14 +105,9 @@ export function apply(ctx) {
pending = (async () => {
const issues = []
try {
const key = await ctx.agentPresets.standingKeyFor(presetId)
const assembly = await ctx.systemPrompt.assemble({ scope: key })
const assembly = await presetAssembly(presetId)
const fused = fuseSections(assembly.sections, presetId)
if (fused.issues !== undefined) issues.push(...fused.issues)
if (PRESET_RULES[presetId].plan) {
const source = await ctx.agentPresets.read(presetId)
if (!source.includes(ANCHORS.planPrefix)) issues.push('plan-mode section changed')
}
} catch (error) {
issues.push(`preset probe failed: ${messageOf(error)}`)
}
@@ -243,8 +251,7 @@ export function apply(ctx) {
return { presetId, contract, available: true, source: 'live', ...summarize(cached) }
}
try {
const key = await ctx.agentPresets.standingKeyFor(presetId)
const assembly = await ctx.systemPrompt.assemble({ scope: key })
const assembly = await presetAssembly(presetId)
const fused = presetId === 'minimal'
? { sections: [{ name: 'deployment:persona-prefix', text: fusedMinimalPrompt() }] }
: fuseSections(assembly.sections, presetId)
@@ -334,8 +341,8 @@ export function apply(ctx) {
})
ctx.effect(() => {
const unwatch = scope.watch((next) => {
const enabled = next.enabled
const unwatch = ctx.on('loader/volatile-update', () => {
const enabled = config.get().enabled
if (enabled === state.enabled) return
state.enabled = enabled
if (enabled) onEnable()
+1 -2
View File
@@ -15,7 +15,6 @@ import { createHash } from 'node:crypto'
export const ANCHORS = {
identity: 'You are an AI agent powered by DeepSeek Harness.',
personaStandard: 'You are a coding agent powered by the {{model}} model.',
personaCordis: "You are a coding agent powered by the {{model}} model, running on the DeepSeek Harness.\n\nYou can read and modify the harness you run on. Its composition is Cordis: every capability is a plugin row in a `cordis.yml`, and an agent preset is one such file mounted for a single session.\n\nTwo planes decide where an edit belongs. The HOST composition holds the registries and anything shared across sessions — persistence, the sandbox and approval stack, the model route, the subagent registry and its backends. An AGENT PRESET holds what one session contributes to those registries: its tools, its persona, its prompt sections. A row that publishes a service belongs in the host composition, or inside an `isolate` realm if the preset genuinely owns that service and nothing outside one agent reads it.\n\nPresets you author live one directory per preset under `${DSH_HOME:-$HOME/.dsh}/.agent-presets/<id>/`. Load `editing-cordis-compositions` for file discovery and copying instructions. NEVER edit or delete the shipped preset install (the `agent-presets` directory beside the deployment's own config): it belongs to the deployment, an upgrade overwrites it, and corrupting the `cordis` preset would disable this very mode. To change what a shipped preset does, copy its composition into a new preset directory and edit the copy.\n\nLoad the `editing-cordis-compositions` skill before writing or changing a composition.\n\nUse plugin_manager for persistent bundle installation, removal and enablement in the current profile. Author plugin code and configuration as ordinary workspace bundle files. Changes affect every session in that profile. Read saved-state and activation outcomes separately; restart-required means the new capability is not available yet.\n\nIn Creator mode, requests to make a visual object, decoration, or widget mean creating an installed UI plugin that displays it in this Harness Web UI, unless the user specifies another destination. Choose reasonable visual details and proceed. Load cordis-plugin-development, inspect the Client slots, build the plugin in the workspace, and install it with plugin_manager. Install a minimal working version before visual refinement; use the connected page as its preview. Verify that the open page renders it; a standalone image or HTML file does not complete an in-app creation request.\n\nLoad the cordis-plugin-development skill before authoring an installed plugin. Use cordis_inspect_list to discover Host and Client providers, then cordis_inspect_query to read exact Service, Event, Tool, Theme or Slot APIs. These tools are read-only; queries do not invoke business methods.\n\nTo connect an MCP server, create a configuration-only bundle whose patch inserts @deepseek-ai/dsh-mcp-client, then install it with plugin_manager. Load cordis-plugin-development for the package and YAML examples. After successful activation, call one of the newly available mcp__<serverName>__<tool> tools to verify the connection.\n\nUse installed bundles for new plugin code. Package installation may require explicit user approval for build scripts. Preserve returned failures and pending states; only report success after observing the requested capability.",
personaMinimal: 'You are a helpful software engineer assistant.',
planPrefix: 'You are in plan mode. Stay in plan mode until exit_plan_mode succeeds or the user switches the session mode.',
ptcOnly: '`run_code` is the only tool you can call directly — a tool call naming any other tool fails. Reach every tool the SDK declares below from inside the program.',
@@ -29,7 +28,7 @@ export const PRESETS = ['standard', 'ptc', 'cordis', 'minimal']
export const PRESET_RULES = {
standard: { persona: 'personaStandard', plan: true, ptcOnly: false, identity: true },
ptc: { persona: 'personaStandard', plan: true, ptcOnly: true, identity: true },
cordis: { persona: 'personaCordis', plan: true, ptcOnly: false, identity: true },
cordis: { persona: 'personaStandard', plan: true, ptcOnly: false, identity: true },
// minimal's complete persona replaces the whole prompt, so no identity line exists.
minimal: { persona: 'personaMinimal', plan: false, ptcOnly: false, identity: false },
}