DeepSeek Harness 源码教程
DEEPSEEK HARNESS · OFFLINE TUTORIAL

学习总览

从顶层框架到源码细节的完整路线

目标:最终能够解释 DSH 的顶层设计、沿一次 Turn 追到源码、判断一个新功能应该落在哪个 seam,并能自己写出 mini-DSH。

学习顺序

阶段 A · 世界观

顶层架构 → Cordis → Profile/Bundle/Boot。先搞清楚“系统是什么”。

阶段 B · 核心执行链

Session → Prompt/LLM → Tools → Agent → Agent Loop。Agent Loop 必须最后看。

阶段 C · 真实运行时

Persistence、Compaction、Sandbox、Subagent、Jobs、UI。

阶段 D · 重新推导

从零实现 mini-DSH,再用 Tests / Invariants 验证理解。

最终心智模型

                      DSH
                       │
              ┌────────▼────────┐
              │      Cordis      │
              │ Plugin / Context │
              │ Service / Event  │
              └────────┬────────┘
                       │
           Profile + Bundle + Patch
                       │
     ┌─────────────────┼─────────────────┐
     │                 │                 │
    LLM              Tools             Session
 ctx.llm           ctx.tools         ctx.sessions
     │                 │                 │
adapters          capabilities       Event Log
     │                 │                 │
     └────────────┬────┴─────────────────┘
                  │
            Agent Interface
             ctx.agents
                  │
            Agent Loop
           ctx.agentLoop
                  │
         turn → step → step...

推荐源码路线

README.md
↓
docs/cordis-primer.md
↓
docs/architecture.zh.md
↓
Cordis
↓
Boot / Bundle / Profile / dump-config
↓
core/session
↓
core/system-prompt
↓
llm/llm + provider adapter
↓
core/tools
↓
fs family
↓
core/agent + core/scope
↓
core/agent-loop/agent.ts
↓
core/agent-loop/tool-calls.ts
↓
session persistence
↓
compaction
↓
sandbox / subprocess / shell / terminal
↓
subagent / jobs / workflow
↓
API / host / client / web
↓
tests + invariants
↓
自己写 mini-DSH