Skip to content

Appendix: Mapping to the Official Codebase

This table maps every concept you learned in mini-dsh back to the official repo — after this tutorial, you can already read most of deepseek-ai/deepseek-harness.

Concept Mapping

Official conceptOfficial locationmini-dshDifference
Cordis plugin frameworkvendor/ (vendored Cordis)src/context.tsSemantics aligned; waterfall simplified to single-value
Service repository ctx.<key>packages/core/*ctx.service()/get()Official uses declaration merging for type safety; mini uses generics
Session event logpackages/core/sessionsrc/session.tsSubset of event types; official has projection/fork/replay
System prompt assemblypackages/core/system-promptSystemPrompt (in agent.ts)Official also assembles tool schemas into the prompt
Tool registry & pipelinepackages/core/toolssrc/tools.tsSame event names (tools/pre-execute etc.)
Agent looppackages/core/agent-loopsrc/agent.tsSame turn/step semantics, event subset
LLM seampackages/llm/llm + llm-deepseeksrc/llm.tsBoth OpenAI-compatible chat/completions + SSE
Skillspackages/skillplugins/skills.tsOfficial has catalog/loader tools; mini simplifies to two tools
Shell capabilitypackages/shellplugins/shell.tsOfficial goes through subprocess/sandbox services
Filesystempackages/fsplugins/filesystem.tsOfficial supports fs/* policy events; mini inlines them
Profile/Bundlepackages/bundle/*boot.tsOfficial is YAML composition + patch overlays
Sandboxpackages/sandbox / e2bnot implementedDeliberately skipped in the teaching version; production requires it
Web UIapps/websrc/web.tsZero-dependency single page
CLIapps/clisrc/cli.tschat / run / web

Event Mapping

Official eventDispatch modemini-dshNotes
agent/requestwaterfall✅ samerewritable request
agent/pre-stepwaterfall⏭ mergedcovered by agent/request
agent/turn-stoppingserial⏭ simplifiedmaxSteps safety net
tools/pre-execute / post-executewaterfall✅ samepolicy interception points
tools/executeemit✅ sameaudit observation point
assistant/chunkemit✅ sameUI streaming
llm/streamgenerator✅ samesame vocabulary

Official Turn Flow (full) vs mini

text
official:
turn/start
  agent/pre-step (may reject/rewrite input)
  step/start
    agent/request -> llm/stream -> assistant/chunk* -> assistant/message
    tool/call* -> tools/pre-execute -> tools/execute -> tools/post-execute -> tool/result*
  step/end
  (tools owe another request, or new input arrived -> next step)
  agent/turn-stopping (serial, can stop)
turn/end

mini-dsh:
turn/start
  step/start
    system-prompt(waterfall) -> agent/request(waterfall)
    -> provider.stream -> assistant/chunk* -> assistant/message
    -> tools.execute(pre/execute/post) -> tool/result
  step/end
  (tool calls -> next step; maxSteps safety net)
turn/end

Reading Guide for the Official Repo

After this tutorial, read the official source in this order:

  1. docs/cordis-primer.md — you already know this; skim to confirm
  2. docs/architecture.md — the global map
  3. packages/core/agent-loop/src/agent.ts — find turn() / the step loop, compare with chapter 07
  4. packages/llm/llm-deepseek/src/adapter.ts — how the DeepSeek adapter handles streaming and tool calls
  5. packages/skill — the full skill system (catalog + loader tools)
  6. docs/subsystems/core.md — generated API reference

Further Reading

Known Simplifications (the honest list)

The official has, mini doesn'tNotes
Sandbox / permission systemProduction-critical; the teaching version executes tools directly
Subagentsthe official can spawn child task agents
Session fork / replay UIthe log supports it; no upper layer yet
Runtime tool-schema validationofficial uses zod; mini args are any
Context compactioncontext management strategy for long sessions
HMR hot reloadpart of the official dev experience
Typed events (declaration merging)an official engineering detail; mini uses string event names

These gaps are great practice problems — e.g. "add a sandbox plugin to mini-dsh that listens to tools/pre-execute and blocks dangerous commands". You now know exactly where to start.

After This Tutorial

  • For an architectural comparison of DeepSeek Harness with mainstream coding agents (Claude Code / Pi / Cursor...), see vs Mainstream Coding Agents.
  • To try the official dsh directly: npx @deepseek-ai/dsh web.

基于 MIT 许可的 deepseek-ai/deepseek-harness 设计理念 · 本教程为独立教学项目,与 DeepSeek 官方无隶属关系