Skip to content

DSH Profile 架构:Cordis → Bundle → Patch → Profile ​

你前面已经接触过 Cordis → Bundle → Patch → Profile,现在把这几个东西串起来,DSH 的 Profile 架构其实就很好理解了。

官方架构把 DSH 描述成:启动时按照多个有序 layer 组合出来的一棵 Cordis plugin tree。Profile 本质上就是这棵树的“组装说明书”。

1. 先记住一句话 ​

Profile = 一个“可运行的 DSH 产品形态”的配置组合。

例如:

text
web profile
    │
    ├── dsh-base
    │
    ├── dsh-web-app
    │
    ├── profile/cordis.patch.yml
    │
    ├── $DSH_HOME/cordis.patch.yml
    │
    └── --patch xxx.yml

最终这些东西会被组合成:

text
             DSH
              │
       ┌──────┴──────┐
       │ Cordis Tree │
       └──────┬──────┘
              │
       ┌──────┴───────┐
       │              │
   core plugins    web plugins
       │              │
   agent/llm/...   web/api/...

所以 Profile 自己并不是 Agent,也不是 Plugin。

它更像:

“我要启动什么样的一棵 Plugin Tree?”

2. Profile 到底是什么? ​

官方定义是:

Profile 是 $DSH_HOME/profiles/<name> 下的一个 named composition。

也就是:

text
$DSH_HOME/
└── profiles/
    └── web/
        ├── package.json
        ├── cordis.patch.yml
        └── pnpm-workspace.yaml

例如:

bash
dsh --profile web

DSH 首先找到:

text
$DSH_HOME/profiles/web/

然后读取它的 ../../package.json。

其中会有类似:

json
{
  "name": "dsh-profile-web",
  "dsh": {
    "profile": {
      "bundles": [
        "@deepseek-ai/dsh-base",
        "@deepseek-ai/dsh-web-app"
      ]
    }
  }
}

这里最重要的是:

text
bundles

它告诉 DSH:

这个 Profile 由哪些 Bundle 组成,以及按照什么顺序组成。

官方源码文档也明确说明,dsh.profile.bundles 就是 Profile 的 bundle 列表。

3. Profile 和 Bundle 的关系 ​

这是 DSH 最容易混淆的地方。

可以把它类比成:

text
Profile
   ↓
“我要组装什么?”

Bundle
   ↓
“我提供什么?”

Patch
   ↓
“具体怎么配置?”

Plugin
   ↓
“真正执行什么代码?”

例如:

text
web Profile
     │
     ├── dsh-base Bundle
     │       ├── llm
     │       ├── session
     │       ├── agent
     │       ├── tools
     │       ├── sandbox
     │       └── ...
     │
     └── dsh-web-app Bundle
             ├── web-server
             ├── api
             ├── workspace
             └── browser UI

所以:

Profile 不是 Bundle 的上级代码模块。

更准确地说:

text
Profile
   │
   │ references
   ▼
Bundle
   │
   │ provides
   ▼
Cordis patch entries
   │
   │ mounts
   ▼
Plugins

4. 为什么需要 Profile? ​

这是 DSH 架构非常漂亮的一点。

假设 DSH 有一个共同的 Agent 核心:

text
LLM
Session
Agent
Agent Loop
Tools
Persistence
Sandbox
Credentials
...

但是不同场景需要不同“外壳”。

例如:

Web ​

text
Agent Core
    +
Web UI
    +
HTTP/API

Headless ​

text
Agent Core
    +
CLI Runner

SDK ​

text
Agent Core
    +
JSON-RPC Server

ACP ​

text
Agent Core
    +
ACP Server

那么没必要复制四套 DSH。

而是:

text
                 dsh-base
                    │
       ┌────────────┼─────────────┐
       │            │             │
      web        headless        sdk
       │            │             │
 web-app        runner        sdk-app

所以:

Profile 把“产品形态差异”从代码差异变成了配置组合差异。

官方目前的架构中,web、headless、sdk、acp 都采用这种方式;sdk-minimal 是一个特殊的独立 bundle。

5. Bundle 又是什么? ​

Bundle 是一个可以被 Profile 装进去的配置层。

例如:

text
@deepseek-ai/dsh-base

它本身有:

text
package.json
cordis.patch.yml
代码模块

package.json 会声明:

json
{
  "dsh": {
    "bundle": {
      "patch": "./cordis.patch.yml"
    }
  }
}

意思就是:

“我是一个 DSH Bundle,我提供了一份 Cordis Patch。”

官方文档对 Bundle 的定义就是:

Cordis config rows + the code they mount 的 distribution format。

6. Profile 真正厉害的地方:Layer ​

现在来到最关键的部分。

DSH 不是:

text
读取一个配置文件
        ↓
启动

而是:

text
空配置
   ↓
Bundle 1
   ↓
Bundle 2
   ↓
Profile Patch
   ↓
Home Patch
   ↓
--patch
   ↓
最终配置
   ↓
启动 Cordis Tree

官方定义的顺序是:

text
1. Profile 中的 Bundles
2. Profile cordis.patch.yml
3. $DSH_HOME/cordis.patch.yml
4. --patch

后面的 layer 优先级更高。

7. 用你的 DSH 环境举例 ​

你之前的:

text
~/.dsh/profiles/web/

大概就是:

text
web/
├── package.json
├── cordis.patch.yml
└── pnpm-workspace.yaml

而 ../../package.json 里面类似:

text
dsh.profile
    │
    └── bundles
          │
          ├── @deepseek-ai/dsh-base
          └── @deepseek-ai/dsh-web-app

于是启动:

bash
dsh --profile web

实际上是在做:

text
                    dsh --profile web
                            │
                            ▼
                     找到 web profile
                            │
                            ▼
                  读取 dsh.profile
                            │
                            ▼
             ┌──────────────┴──────────────┐
             │                             │
        dsh-base                     dsh-web-app
             │                             │
             └──────────────┬──────────────┘
                            ▼
                  profile patch
                            │
                            ▼
                   home-level patch
                            │
                            ▼
                     --patch
                            │
                            ▼
                 最终 Cordis Tree
                            │
                            ▼
                         启动

8. 为什么你之前的 cordis.yml 是 []? ​

这个地方非常容易误解。

你之前的:

yaml
[]

并不意味着:

DSH 什么都没有。

它意味着:

Profile 本身没有直接声明 Cordis entry。

真正的东西来自:

text
dsh-base
dsh-web-app

这些 Bundle。

所以:

text
profile/cordis.yml = []

完全可以有:

text
几十个 / 上百个 plugin

因为它们来自 Bundle 的 patch。

这也是 DSH 设计的核心之一:

Profile 是 composition,不是 plugin implementation。

9. Profile Patch 又是什么? ​

假设:

text
dsh-base

里面有:

yaml
- id: llm
  plugin: ...
  config:
    provider: ...

然后你的:

text
profiles/web/cordis.patch.yml

可以针对:

text
id: llm

进行覆盖。

例如概念上:

yaml
- id: llm
  config:
    provider: xxx

那么:

text
dsh-base
    ↓
创建 llm
    ↓
profile patch
    ↓
覆盖 llm

因此最终使用的是 Profile 层的配置。

10. 一个非常重要的细节:不是 deep merge ​

这点以后你维护 DSH 会经常碰到。

如果原来:

yaml
- id: llm
  config:
    provider: openai
    model: xxx
    temperature: 0.7

你 patch:

yaml
- id: llm
  config:
    model: yyy

并不是简单地变成:

yaml
config:
  provider: openai
  model: yyy
  temperature: 0.7

而是 patch 对匹配的 row 的 config 进行整体替换。官方文档明确指出这里不是 deep merge。

所以理解成:

text
同一个 id
     ↓
后面的配置
     ↓
替换前面的配置

更准确。

11. Home Patch 为什么还要存在? ​

这里就体现出 DSH 的分层思想了。

有:

text
~/.dsh/profiles/web/cordis.patch.yml

也有:

text
~/.dsh/cordis.patch.yml

它们的意义不同。

Profile patch ​

text
“Web 这个 Profile 怎么配置”

只影响:

text
web

Home patch ​

text
“我这台机器上的 DSH 都怎么配置”

影响:

text
web
headless
sdk
...

因此:

text
                    DSH_HOME
                       │
          ┌────────────┴────────────┐
          │                         │
      profiles/                 cordis.patch.yml
          │                         │
      ┌───┴───┐                     │
      │       │                     │
     web   headless                  │
      │       │                     │
      └───┬───┘                     │
          │                         │
          └──────────┬──────────────┘
                     ▼
              Home-level override

这也是为什么 Home Patch 的优先级高于 Profile Patch。

12. --patch 是什么? ​

最后还有:

bash
dsh --profile web --patch xxx.yml

它是:

临时最高优先级覆盖层。

所以:

text
Bundle
   ↓
Profile Patch
   ↓
Home Patch
   ↓
--patch     ← 最高

这非常适合实验。

例如你想测试:

text
换一个模型

没必要修改:

text
~/.dsh/profiles/web/cordis.patch.yml

可以:

bash
dsh --profile web --patch experiment.yml

实验结束直接删掉命令即可。

13. 你可以把整个架构理解成“CSS 层叠” ​

这个比喻其实非常准确。

假设:

text
dsh-base

定义:

text
llm = A

然后:

text
web bundle

定义:

text
llm = B

然后:

text
profile patch

定义:

text
llm = C

然后:

text
home patch

定义:

text
llm = D

最后:

text
--patch

定义:

text
llm = E

最终:

text
llm = E

也就是:

text
base
  ↓
web
  ↓
profile
  ↓
home
  ↓
command line
  ↓
最终值

越靠后,优先级越高。

14. Profile 最核心的结构图 ​

我建议你以后脑子里就记这一张:

text
                         DSH
                          │
                          ▼
                    ┌───────────┐
                    │  Profile  │
                    │   "web"   │
                    └─────┬─────┘
                          │
                    bundles[]
                          │
              ┌───────────┴───────────┐
              ▼                       ▼
        ┌───────────┐           ┌──────────────┐
        │ dsh-base  │           │ dsh-web-app  │
        └─────┬─────┘           └──────┬───────┘
              │                        │
              └───────────┬────────────┘
                          ▼
                 Cordis Patch Entries
                          │
                          ▼
              profile/cordis.patch.yml
                          │
                          ▼
                 $DSH_HOME/cordis.patch.yml
                          │
                          ▼
                       --patch
                          │
                          ▼
                 ┌──────────────────┐
                 │ Final Config Tree│
                 └────────┬─────────┘
                          │
                          ▼
                    Cordis Context
                          │
             ┌────────────┼────────────┐
             ▼            ▼            ▼
            LLM         Agent        Tools
             │            │            │
             └────────────┼────────────┘
                          ▼
                    Running DSH

15. 这和你之前研究的 @local/sople-badge 又有什么关系? ​

这个就很重要了。

你之前实际上是在做:

text
DSH Profile
     │
     ├── dsh-base
     ├── dsh-web-app
     │
     └── @local/sople-badge

也就是说,你不是在修改 DSH 的核心代码。

你是在:

向一个现有 Profile 增加自己的 Plugin / Bundle。

这正是 DSH 架构希望你做的事情。

官方架构甚至明确强调:DSH 没有一个必须修改的“特权核心”;功能通过 Plugin 挂载到共享 Cordis Context 中。

16. 最后把四个概念彻底区分 ​

概念你可以把它理解成
CordisPlugin 运行框架
Plugin一个实际能力
Bundle一组可分发、可组合的 Plugin 配置层
Profile“我要运行哪一套 Bundle”的产品组合
Patch修改某个 Plugin 配置的覆盖层
--patch临时最高优先级 Patch

最关键的一条关系:

text
                Profile
                   │
             chooses / orders
                   │
                   ▼
                Bundles
                   │
              provide layers
                   │
                   ▼
             Patch Entries
                   │
               mount code
                   │
                   ▼
                Plugins
                   │
                   ▼
              Cordis Context

所以如果你现在准备真正深入 DSH 源码,下一步最值得搞懂的不是继续研究 Profile 文件本身,而是:

Profile → Bundle → cordis.patch.yml → composeEntries → Cordis Plugin Tree → ctx 的启动过程。

一旦这条链理解了,你之前遇到的 HARNESS Failed to load plugins、@local/sople-badge、Profile patch、Bundle、HMR 基本都会串成一个完整的体系。官方也建议用 dsh --profile web --dump-config 直接观察机器实际启动出来的配置树。

参考 ​