DeepSeek Harness
DeepSeek Harness 源码分析:架构与执行流程
结合架构文档和包目录,从 Profile 组合追踪到一次模型 Step。

你将学会
- Read apps, packages, docs, and examples as separate architectural layers.
- Profile layers compose into a Cordis entry tree before the app activates services.
- Steps, turns, and event domains provide the vocabulary for tracing execution.
开始前需要
- Basic HTTP and API knowledge
Leave with a concrete implementation checklist and a testable starting point.
先看结论
- 把 apps、packages、docs、examples 当成不同架构层。
- Profile 层组合成 Cordis Entry Tree 后才激活服务。
- Step、Turn 和 Event 域提供了追踪执行的共同词汇。
按层阅读仓库
先看 `apps` 中的可运行入口、`packages` 中的可复用服务、`docs` 中的契约和 `examples` 中的组合。包目录分别列出 Core API、LLM 适配器、工具、Session、Host、Client、Bundle 和 SDK。
这种目录地图比随机打开文件更有效:它能告诉你哪个包拥有能力,哪个包只是消费服务定义。追踪 import 时应同时打开官方架构文档。
启动与组合流程
启动时,Profile 依次贡献 Bundle,随后应用 Profile 和 Home 补丁,最后叠加命令行 overlay。app-boot 在空 entry list 上组合这些层,挂载 Cordis include tree,并检查启用的 Entry 是否加载和激活。
`dsh --profile web --dump-config` 是很好的观察点,因为它能展示机器实际启动的树。按 id 匹配的补丁会替换整行 config,因此要重新写出仍需保留的字段。
Turn、Step 与扩展点
架构文档区分 Step 和 Turn:Step 是一次模型请求加上它调用的工具;Turn 从领取输入开始,直到没有待处理工作。Session Event 是持久事实,Agent Event 描述实时工作,Capability Event 则连接策略和适配器。
做源码练习时,先沿一个 Event 从 Producer 追到 Consumer,再定位服务定义、Provider 和面向模型的 Consumer。这样得到的是可测试的扩展路径,而不是泛泛地说系统模块化。
如何选择
| 比较维度 | 方案 A | 方案 B |
|---|---|---|
| Trace this first | A service definition and its provider/consumer | A random implementation file without its composition |
| Use events when | The fact is durable or needs an extension point | A local helper has no lifecycle or observer contract |
实施步骤
- 1
从 docs/architecture.md 和 packages/README.md 开始。
- 2
选择 tools 或 sessions 等能力并定位服务 key。
- 3
检查 Profile Bundle 顺序并 dump 配置。
- 4
沿一个 Event 追踪 Producer 与 Consumer,并写一个聚焦测试或图。
可复制示例
# Inspect the composed tree before changing a package
dsh --profile web --dump-config
# Source build checkpoints
pnpm run typecheck
pnpm run build常见问题
应该从哪里开始源码分析?
先读 docs/architecture.md,再读 packages/README.md 和目标子系统 README。
资料来源
- DeepSeek Harness architecture来源核查 2026-08-27
- DeepSeek Harness packages map来源核查 2026-08-27
- DeepSeek Harness app-boot package来源核查 2026-08-27