DeepSeek Harness 源码教程
DEEPSEEK HARNESS · OFFLINE TUTORIAL

12 · 源码精读法

调用链、Tests、Invariants、边界案例

1. 调用链追踪法

不要从文件第 1 行读到第 1000 行。每次选一个问题,沿 Service、Event 和关键函数追到底。

追一条用户消息

send / input
↓
inbox
↓
claim
↓
agent/pre-step
↓
user/message
↓
deriveMessages
↓
assemble request
↓
llm.stream

追一次 Tool Call

model output
↓
assembler
↓
ToolCall
↓
tool scheduler
↓
tool/call
↓
pre-execute
↓
guards
↓
execute
↓
post
↓
tool/result
↓
session
↓
next step

追 Persistence

Session.append()
↓
session/event
↓
persistence coordinator
↓
buffer / checkpoint
↓
flush
↓
backend

2. 看到这些源码信号要立刻问

信号问题
extends Service它声明什么能力?ctx key 是什么?
inject它消费谁?
ctx.effect安装了什么可逆资源?
ctx.on挂在哪个 extension point?
waterfall谁 wrap 谁?谁可 short-circuit?
module augmentation如何扩展 ctx/event 的类型世界?

3. 第一轮先追 Runtime

谁创建对象
谁注册
谁调用
谁 dispatch
谁 append
谁 dispose

复杂泛型、conditional types、module augmentation 第二轮再看。

4. Tests / Invariants

README 告诉你作者希望系统怎样工作;Tests 与 Invariant 往往告诉你作者最怕系统怎样坏。

5. 必看边界案例