From 548ff04bd806b4ee59ed63f48dd0cce45a8ad607 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Thu, 1 Oct 2026 12:32:36 +0800 Subject: [PATCH] feat(dsh): ship in-package bili preset as the roster default (#1772) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Discussion draft — approach proven end-to-end against dsh 0.2.0-rc.2 on a live probe instance; NOT for merge until the open decisions below are settled. The #1786 recipe (copy standard into the user root by hand) works but is three steps across two worlds, and user copies drift on preset upgrades. Interception is worse: compaction-basic exposes no service or veto API (pure event listeners), vetoing agent/pre-step starves 16 sibling listeners, wrapping ctx.llm fights the core. The remaining sanctioned lever is the `agent-presets` row itself — a boot-tree row the web-app inserts, so the LAST bundle layer (bili) can replace its config wholesale: - dsh-presets/standard-bili-auto-off/: byte-copy of the shipped `standard` preset with exactly one delta — compaction-basic `config: { auto: false }` (it only registers automatic compaction when this.config.auto). Manual /compact (command-compact) and the tool-result pruner stay. Ships in the npm package, so every bili upgrade refreshes it — no snapshot drift. - dsh.bundle.patch.yml: replace the never-applied compaction-basic corpse row (preset-internal rows are below the patch engine's reach — that was the #1772 dead end) with an `agent-presets` config override: extra roster root pointing at the package's dsh-presets/ (path resolved from the loader ctx baseUrl at activation, win32 leading-slash handled), trust: system, default switched to the bili preset. Shipped + user roots stay enabled; every native preset remains selectable; an explicit settings/UI choice still wins over the row-config default. - package.json: publish dsh-presets. - tests/e2e/e2e-native-dsh.test.ts: wireProfile copies dsh-presets/ like a registry install would. - tests/dsh-bundle-preset.test.ts: guards — exactly one agent-presets patch row with default + package-relative root + win32 handling; preset keeps auto:false while command-compact and tool-result-pruner rows survive; package files and the e2e mirror stay in sync. Open decisions: (a) default override on/off (on = zero-action fix for existing installs; off = picker-only); (b) preset display name (标准模式(bili 托管压缩)) — both flagged in the #1772 discussion comment. --- .../standard-bili-auto-off/agent.cordis.yml | 258 ++++++++++++++++++ dsh-presets/standard-bili-auto-off/preset.yml | 3 + dsh.bundle.patch.yml | 21 +- package.json | 1 + tests/dsh-bundle-preset.test.ts | 51 ++++ tests/e2e/e2e-native-dsh.test.ts | 7 + 6 files changed, 339 insertions(+), 2 deletions(-) create mode 100644 dsh-presets/standard-bili-auto-off/agent.cordis.yml create mode 100644 dsh-presets/standard-bili-auto-off/preset.yml create mode 100644 tests/dsh-bundle-preset.test.ts diff --git a/dsh-presets/standard-bili-auto-off/agent.cordis.yml b/dsh-presets/standard-bili-auto-off/agent.cordis.yml new file mode 100644 index 0000000000..5db2e80dee --- /dev/null +++ b/dsh-presets/standard-bili-auto-off/agent.cordis.yml @@ -0,0 +1,258 @@ +# The `standard` agent preset: the full coding agent, mounted once per process. +# +# This file is an AGENT-PLANE composition. The roster mounts it ONCE under a +# standing scope; every session naming it joins by scope parentage, so the +# tools and prompt sections registered here cover each joined agent while a +# session's own state stays keyed per Session/Agent inside the plugins. The +# host composition (`base.cordis.yml` + `web.cordis.yml`) keeps everything a +# preset must not own: the registries themselves, the sandbox and approval +# stack, persistence, and the model route. +# +# A service row here MUST sit inside a group carrying an `isolate` realm. +# Without one it publishes into the root realm, where it is process-global — +# another preset publishing the same name collides, and a host reader would +# resolve one preset's instance for every session; `dsh-agent-presets` rejects +# that at mount. `true` means an entry-local realm: this standing mount's own +# private instance, apart from every other preset's. (A shared label does NOT +# pool instances — `provide()` throws on the second registration under the +# same realm symbol; labels join REALMS, and are not what this file needs.) + +# ── identity ──────────────────────────────────────────────────────────────── + +# The preset's own persona, shadowing the deployment default for this agent. +# `{{model}}` and `{{cwd}}` resolve from the agent's own route and workspace. +- id: persona + name: '@deepseek-ai/dsh-persona' + config: + suffix: Your working directory is {{cwd}}. + prefix: >- + You are a coding agent powered by the {{model}} model. + +- id: agent-instructions + name: '@deepseek-ai/dsh-agent-instructions' + config: + maxBytes: 65536 + +# ── shell ─────────────────────────────────────────────────────────────────── + +# `shell-env` stays in the HOST composition: `apps/cli/src/web.ts` injects it to +# publish `DSH_WEB_URL`/`DSH_WEB_MODE`, and a host row that injects a service is +# the criterion for host-plane ownership — injection resolves before any session +# exists, so there is no agent to key by. Behind a preset realm those variables +# never reached the model's shell at all. Both shell tools consume the host +# registry from here; their executors (`bash-sandbox`/`pwsh-sandbox`) are +# host-plane too. +- id: tool-bash + name: '@deepseek-ai/dsh-tool-bash' + disabled: !!js process.platform === 'win32' + +- id: tool-pwsh + name: '@deepseek-ai/dsh-tool-pwsh' + disabled: !!js process.platform !== 'win32' + +# ── filesystem ────────────────────────────────────────────────────────────── + +# Both register into the host `tools` registry and provide nothing, so +# they need no realm. The `fs` service and its policy stay in the host. +- id: tool-fs + name: '@deepseek-ai/dsh-tool-fs' + +- id: tool-fs-search + name: '@deepseek-ai/dsh-tool-fs-search' + config: + sampleOverCapGlobResults: false + +# ── background jobs ──────────────────────────────────────────────────────── + +# Only the model-facing controls. The task REGISTRY stays on the host plane: +# its producers sit outside any realm this file could put it in — `tool-bash` +# above resolves it with `ctx.get`, and an entry-local realm here is invisible +# to every sibling row, so `run_in_background` would answer "background jobs +# unavailable" while these controls sat in the catalog. The registry is keyed by +# owning agent anyway, so one host instance serves every session. What a preset +# chooses is whether its agent can collect and stop background work at all. +- id: tool-jobs + name: '@deepseek-ai/dsh-tool-jobs' + +# ── skills ────────────────────────────────────────────────────────────────── + +# The skill REGISTRY lives in the host composition and is layered per scope: +# these rows register into THIS preset's layer of it, so they need no realm. +# `skill-filesystem` contributes local-root discovery for agents on this preset, and +# `tool-skill` gives them the catalog and loader; the merged catalog also +# carries whatever the deployment registered globally (repository plugins). +- id: skill-filesystem + name: '@deepseek-ai/dsh-skill-filesystem' + +- id: tool-skill + name: '@deepseek-ai/dsh-tool-skill' + +# ── goals ─────────────────────────────────────────────────────────────────── + +# The goal service and session driver stay on the host plane, where the Gateway +# can resolve them. The human command and model-facing tool register into this +# preset's scoped layers. +- id: command-goal + name: '@deepseek-ai/dsh-command-goal' + +- id: tool-goal + name: '@deepseek-ai/dsh-tool-goal' + +# ── plan mode ─────────────────────────────────────────────────────────────── + +# Plan state is per-agent by nature, so an entry-local realm is not a +# workaround here — it is the correct lifetime. +- id: planning + name: cordis:group + group: true + isolate: + planMode: true + config: + - id: plan-mode + name: '@deepseek-ai/dsh-plan-mode' + config: + section: | + You are in plan mode. Stay in plan mode until exit_plan_mode succeeds or the user switches the session mode. Imperative language to implement changes means plan the implementation, not execute it. A user's conversational agreement — including an answer confirming something you asked — approves nothing and does not end plan mode; fold the confirmed decision into the plan and submit it through exit_plan_mode. + + Explore first. Use non-mutating reads, searches, static analysis, and checks to ground the plan in the actual repository. Do not edit or write files, change configuration, run formatters or code generation that rewrites tracked files, commit, or otherwise carry out the plan. Prefer existing functions and patterns over new machinery. + + The tool catalog stays the same across modes for request-cache stability. These plan-mode rules override any later tool description or guidance that suggests using mutation tools; those tools remain listed to keep the tool catalog unchanged. Do not use todo_write to track this planning phase: it tracks implementation after an approved plan, while the plan itself belongs in exit_plan_mode. + + Resolve discoverable facts by inspection. Use ask_user_question only for user-owned choices or material ambiguity that inspection cannot answer. Do not ask the user where code lives or how current behavior works when you can find out. + + Make the plan decision-complete: state the goal and success criteria; group implementation changes by subsystem; identify public API, schema, and data-flow changes; cover edge cases, failure modes, tests, acceptance criteria, and explicit assumptions. Keep it concise enough to review but detailed enough that another engineer can implement it without making design decisions. + + When ready, call exit_plan_mode with the complete plan markdown, starting with a # title. Make exit_plan_mode the only and final tool call in that assistant response: it presents the plan for approval, and implementation begins only in a later step after approval. Do not paste the final plan as a plain reply or ask "should I proceed?" through prose or ask_user_question. If review rejects it, incorporate the feedback and present again. If the review channel is unavailable or aborted, stay in plan mode and ask the user to switch modes manually; do not proceed with implementation. + +# ── compaction ────────────────────────────────────────────────────────────── + +# `compaction-basic` reads `toolResultPrune` through `ctx.get`, so the pruner must +# share this realm rather than sit outside it. +# +# `tokenMeter` is deliberately NOT in this realm: the meter stays on the HOST +# plane, and the rows here resolve that one instance. It takes no configuration, +# keys every fold by Session, and owns the context-meter projection units the +# browser reads for every session — behind a realm those units would come and go +# with whichever presets happen to be mounted. What a preset chooses is whether +# its agent compacts at all, which is `compaction-basic` below. +- id: compaction + name: cordis:group + group: true + isolate: + compaction: true + toolResultPruner: true + config: + - id: compaction-basic + name: '@deepseek-ai/dsh-compaction-basic' + # bili (#1772): ACP 压缩接管 — 关闭 dsh 原生自动压缩,保留手动 /compact 与 tool-result-pruner + config: + auto: false + + - id: command-compact + name: '@deepseek-ai/dsh-command-compact' + + - id: tool-result-pruner + name: '@deepseek-ai/dsh-compaction-tool-result-pruner' + config: + thresholdChars: 8192 + headChars: 4096 + tailChars: 1024 + +# ── delegation and workflows ──────────────────────────────────────────────── + +# The `subagents` registry and its spawn/fork backends live in the HOST +# composition: the registry is a process singleton whose cross-session queries +# the api-proxy serves to the browser, and a provider name may only be +# registered once. This preset contributes the delegation TOOLS, which resolve +# that host registry. +# +# `workflows` is different — nothing outside an agent reads it — so every row +# that reaches it shares one entry-local realm here, and a consumer left +# outside would resolve a host registry this preset does not populate. +- id: delegation + name: cordis:group + group: true + isolate: + workflowEngine: true + config: + - id: tool-subagent-control + name: '@deepseek-ai/dsh-tool-subagent-control' + + - id: tool-subagent-list-agents + name: '@deepseek-ai/dsh-tool-subagent-control/list-agents' + + - id: tool-subagent + name: '@deepseek-ai/dsh-tool-subagent' + config: + provider: spawn + toolName: subagent + modelSelectionSettings: true + backgroundMode: continuable + + # Fork omits model selection so provider/model stay equal to the parent and + # the inherited history remains eligible for KV Cache reuse. This preset + # keeps fork continuable; parent and child inherit the same messaging tool, + # while the parent id and return guidance follow the inherited history. + - id: tool-subagent-fork + name: '@deepseek-ai/dsh-tool-subagent' + config: + provider: fork + toolName: subagent_fork + backgroundMode: continuable + + # Production dsh does not install these optional providers. Install the + # matching Bundle in this Profile and restart the Host, then copy this + # preset and remove `disabled` from the matching tool row. Host availability + # alone grants no tool. + - id: tool-subagent-codex + name: '@deepseek-ai/dsh-tool-subagent' + disabled: true + config: + provider: codex + toolName: subagent_codex + backgroundMode: one-shot + maxDepth: provider-managed + + - id: tool-subagent-claude-code + name: '@deepseek-ai/dsh-tool-subagent' + disabled: true + config: + provider: claude-code + toolName: subagent_claude_code + backgroundMode: one-shot + maxDepth: provider-managed + + - id: workflow-worker-thread + name: '@deepseek-ai/dsh-workflow-worker-thread' + config: + provider: spawn + + - id: tool-workflow + name: '@deepseek-ai/dsh-tool-workflow' + + - id: tool-ralph + name: '@deepseek-ai/dsh-tool-ralph' + config: + subagentProvider: spawn + maxRounds: 64 + +# ── remaining model-facing rows ───────────────────────────────────────────── + +- id: tool-ask-user + name: '@deepseek-ai/dsh-tool-ask-user' + +- id: tool-todo + name: '@deepseek-ai/dsh-tool-todo' + config: + allowParallelInProgress: true + +# The `web` service and its search provider stay in the host composition; only +# the model-facing tool is per-session. +- id: tool-web + name: '@deepseek-ai/dsh-tool-web' + config: + fetch: true + searchTimeoutMs: 60000 + +- id: present + name: '@deepseek-ai/dsh-tool-present' diff --git a/dsh-presets/standard-bili-auto-off/preset.yml b/dsh-presets/standard-bili-auto-off/preset.yml new file mode 100644 index 0000000000..c82e35d5ba --- /dev/null +++ b/dsh-presets/standard-bili-auto-off/preset.yml @@ -0,0 +1,3 @@ +name: 标准模式(bili 托管压缩) +description: 与「标准模式」完全一致的编码 Agent;仅关闭 dsh 原生自动压缩,由 bili 的上下文压缩接管,避免双重压缩。手动 /compact 与工具结果修剪保留。 +order: 1 diff --git a/dsh.bundle.patch.yml b/dsh.bundle.patch.yml index e689a147f1..b0ee2cf754 100644 --- a/dsh.bundle.patch.yml +++ b/dsh.bundle.patch.yml @@ -5,6 +5,23 @@ - insert: - id: bili-native name: billion-context -- id: compaction-basic +# #1772: the shipped `standard` preset mounts `dsh-compaction-basic` with +# auto-compaction ON, which double-compresses alongside bili's own pipeline. +# The compaction row lives inside the preset's agent.cordis.yml — below the +# patch engine's reach (patch rows only match boot-tree rows). The lever we +# CAN turn from a bundle layer is the `agent-presets` row itself (inserted at +# boot-tree top level by dsh-web-app): its config is replaced wholesale here +# to (a) register the in-package `dsh-presets/` directory as an extra roster +# root — trust: system, path resolved from the loader ctx `baseUrl` (profile +# dir), win32 strips the leading slash — and (b) make `standard-bili-auto-off` +# (a byte-copy of `standard` with compaction-basic `auto: false`) the default. +# Shipped + user roots stay enabled (Config schema defaults), every native +# preset remains selectable, and an explicit settings/UI choice still wins +# over this row-config default. Drift is release-managed: the preset ships in +# this package, so every bili upgrade refreshes it. +- id: agent-presets config: - auto: false + default: standard-bili-auto-off + roots: + - path: !!js "(u => process.platform === 'win32' ? u.pathname.slice(1) : u.pathname)(new URL('node_modules/billion-context/dsh-presets/', baseUrl))" + trust: system diff --git a/package.json b/package.json index 6e98f6fb64..dd9217fba1 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "README.md", "dist", "dsh.bundle.patch.yml", + "dsh-presets", "hermes-plugin" ], "pi": { diff --git a/tests/dsh-bundle-preset.test.ts b/tests/dsh-bundle-preset.test.ts new file mode 100644 index 0000000000..40244a6cdd --- /dev/null +++ b/tests/dsh-bundle-preset.test.ts @@ -0,0 +1,51 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); + +// #1772: bili ships a byte-copy of dsh's `standard` preset with +// compaction-basic auto-compaction off, and the bundle layer's +// `agent-presets` config override (a) adds the in-package preset root and +// (b) makes it the default. These guards keep the shipped pieces from +// silently drifting apart. + +const patchPath = path.join(ROOT, "dsh.bundle.patch.yml"); +const presetDir = path.join(ROOT, "dsh-presets", "standard-bili-auto-off"); + +test("dsh bundle patch registers the bili preset root as default", () => { + const yaml = fs.readFileSync(patchPath, "utf8"); + const row = yaml.split(/^-\s+id:\s*agent-presets\s*$/m); + assert.equal(row.length, 2, "exactly one `agent-presets` row"); + const block = row[1]!.split(/^-\s+id:\s*\S+\s*$/m)[0]!; + assert.match(block, /default:\s*standard-bili-auto-off\b/); + // Root path must be resolved from the loader ctx `baseUrl` (profile dir), + // not a baked-in absolute path, and must cover the win32 leading-slash fix. + assert.match(block, /!!js/); + assert.match(block, /node_modules\/billion-context\/dsh-presets\//); + assert.match(block, /win32/); + assert.match(block, /trust:\s*system/); +}); + +test("shipped preset disables compaction-basic auto, keeps manual /compact and pruner", () => { + const preset = fs.readFileSync(path.join(presetDir, "preset.yml"), "utf8"); + assert.match(preset, /^name:\s*标准模式\(bili 托管压缩\)\s*$/m); + + const cordis = fs.readFileSync(path.join(presetDir, "agent.cordis.yml"), "utf8"); + const compactionBasic = cordis.split(/^ {4}- id:\s*compaction-basic\s*$/m); + assert.equal(compactionBasic.length, 2, "compaction-basic row present"); + const block = compactionBasic[1]!.split(/^ {4}- id:\s*\S+\s*$/m)[0]!; + assert.match(block, /auto:\s*false/, "auto compaction off"); + assert.match(cordis, /^ {4}- id:\s*command-compact\b/m, "manual /compact stays"); + assert.match(cordis, /^ {4}- id:\s*tool-result-pruner\b/m, "tool-result pruner stays"); +}); + +test("npm package ships dsh-presets and the e2e profile mirrors published files", () => { + const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, "package.json"), "utf8")); + assert.ok((pkg.files as string[]).includes("dsh-presets")); + + const e2e = fs.readFileSync(path.join(ROOT, "tests", "e2e", "e2e-native-dsh.test.ts"), "utf8"); + assert.match(e2e, /"dsh-presets"/, "wireProfile copies dsh-presets like a registry install"); +}); diff --git a/tests/e2e/e2e-native-dsh.test.ts b/tests/e2e/e2e-native-dsh.test.ts index 52e57711d6..1f8559b7d5 100644 --- a/tests/e2e/e2e-native-dsh.test.ts +++ b/tests/e2e/e2e-native-dsh.test.ts @@ -287,6 +287,13 @@ function wireProfile(ctx: Ctx): void { path.join(REPO_ROOT, "dsh.bundle.patch.yml"), path.join(pkgDir, "dsh.bundle.patch.yml"), ); + // Published shape (#1772): the bundle patch registers the in-package preset + // root, so the profile copy must carry `dsh-presets/` like a registry install. + fs.cpSync( + path.join(REPO_ROOT, "dsh-presets"), + path.join(pkgDir, "dsh-presets"), + { recursive: true }, + ); const biliVersion = JSON.parse( fs.readFileSync(path.join(REPO_ROOT, "package.json"), "utf8"),