# geffzhang/deepseek-harness-dotnet architecture

> Architecture diagram of the GitHub repository geffzhang/deepseek-harness-dotnet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/geffzhang/deepseek-harness-dotnet
- Repository: https://github.com/geffzhang/deepseek-harness-dotnet

## Overview

DeepSeek Harness .NET is a C#/.NET reimplementation of the deepseek-harness agent runtime, aiming for behavioral equivalence. A user enters through a host or SDK; the agent loop prepares and runs session turns, uses model adapters for assistant output, and dispatches tools, while session events and projections preserve state. Cordis supplies the plugin, service, event, fiber, and effect layer beneath these capabilities. The README documents further product areas, including approval, sandbox policy, goals, and terminal control. Some links reflect README descriptions; unsampled implementations are not assumed to have been inspected.

Main entry points: [`src/Dsh.AgentLoop/AgentLoop.cs`](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.AgentLoop/AgentLoop.cs) (Agent loop), [`src/Dsh.Llm/LlmRuntime.cs`](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Llm/LlmRuntime.cs) (LLM runtime), [`src/Dsh.Session/Session.cs`](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Session/Session.cs) (Session log), [`src/Dsh.Cordis/Context.cs`](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Cordis/Context.cs) (Service context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Hosts and SDK"]
  node_cli["CLI host<br/>[Program.cs]"]
  node_desktop["Desktop host<br/>[Program.cs]"]
  node_sdk["SDK handler"]
end

subgraph group_runtime["Agent runtime"]
  node_agentloop["Agent loop<br/>[AgentLoop.cs]"]
  node_agentmaf["Agent Framework host<br/>[DshAgentHost.cs]"]
end

subgraph group_ai["Models and messages"]
  node_messages["Messages<br/>[Messages.cs]"]
  node_llmruntime["LLM runtime<br/>[LlmRuntime.cs]"]
  node_chatclient["Chat client<br/>[DshChatClient.cs]"]
  node_deepseek["DeepSeek adapter<br/>[DeepSeekAdapter.cs]"]
end

subgraph group_session["Session state"]
  node_session[("Session log<br/>[Session.cs]")]
  node_sessionstore[("Session store<br/>[SessionStore.cs]")]
  node_projection["Session projections"]
  node_storage["Persistence contract<br/>[StorageContract.cs]"]
  node_jsonl[("JSONL persistence")]
  node_format["Session format<br/>[SessionJsonText.cs]"]
end

subgraph group_services["Tools and services"]
  node_systemprompt["System prompt<br/>[SystemPrompt.cs]"]
  node_tools["Tool runtime<br/>[ToolRuntime.cs]"]
  node_terminal["Terminal control"]
  node_approval["Approval service<br/>[ApprovalService.cs]"]
  node_sandbox["Sandbox policy"]
  node_goals["Goal service<br/>[GoalService.cs]"]
end

subgraph group_platform["Cordis platform"]
  node_cordiscontext["Service context<br/>[Context.cs]"]
  node_fiber["Fiber lifecycle<br/>[Fiber.cs]"]
  node_effects["Effect cleanup<br/>[Effect.cs]"]
  node_plugins["Plugin declarations<br/>[Plugin.cs]"]
  node_eventservice["Event service<br/>[EventService.cs]"]
end

node_user(("User"))

node_user -->|"uses"| node_cli
node_user -->|"uses"| node_desktop
node_user -->|"calls"| node_sdk
node_cli -.->|"starts turns"| node_agentloop
node_desktop -.->|"hosts sessions"| node_agentloop
node_sdk -->|"routes requests"| node_agentloop
node_agentmaf -.->|"adapts agent"| node_agentloop
node_agentloop -->|"prepares sessions"| node_session
node_agentloop -->|"runs model calls"| node_llmruntime
node_llmruntime -->|"projects messages"| node_messages
node_llmruntime -.->|"uses client"| node_chatclient
node_llmruntime -.->|"selects adapter"| node_deepseek
node_session -.->|"managed by"| node_sessionstore
node_session -.->|"projects events"| node_projection
node_sessionstore -.->|"validates persistence"| node_storage
node_storage -->|"shared contract"| node_jsonl
node_jsonl -->|"reads and writes"| node_format
node_agentloop -.->|"assembles prompts"| node_systemprompt
node_agentloop -.->|"dispatches tools"| node_tools
node_tools -->|"routes terminal calls"| node_terminal
node_agentloop -->|"requests approval"| node_approval
node_agentloop -.->|"applies policy"| node_sandbox
node_agentloop -->|"supports goal work"| node_goals
node_agentloop -->|"uses context"| node_cordiscontext
node_cordiscontext -->|"loads plugins"| node_plugins
node_plugins -->|"creates fibers"| node_fiber
node_fiber -->|"owns cleanup"| node_effects
node_cordiscontext -->|"dispatches events"| node_eventservice

click node_cli "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Cli/Program.cs"
click node_desktop "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Desktop/Program.cs"
click node_sdk "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Sdk/SdkInitializeHandler.cs"
click node_agentloop "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.AgentLoop/AgentLoop.cs"
click node_agentmaf "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Agent.Maf/DshAgentHost.cs"
click node_messages "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Ai/Messages.cs"
click node_llmruntime "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Llm/LlmRuntime.cs"
click node_chatclient "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Ai.ChatClient/DshChatClient.cs"
click node_deepseek "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Ai.DeepSeek/DeepSeekAdapter.cs"
click node_session "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Session/Session.cs"
click node_sessionstore "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Session/SessionStore.cs"
click node_projection "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Session.Projection/SessionProjectionRegistry.cs"
click node_storage "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Session.Persistence/StorageContract.cs"
click node_jsonl "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Session.Persistence.Jsonl/JsonlSessionService.cs"
click node_format "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Session.Format/SessionJsonText.cs"
click node_systemprompt "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.SystemPrompt/SystemPrompt.cs"
click node_tools "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Tools/ToolRuntime.cs"
click node_terminal "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Tools/TerminalController.cs"
click node_approval "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Approval/ApprovalService.cs"
click node_sandbox "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Sandbox.Policy/SandboxPolicyService.cs"
click node_goals "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Goal.Service/GoalService.cs"
click node_cordiscontext "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Cordis/Context.cs"
click node_fiber "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Cordis/Fiber.cs"
click node_effects "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Cordis/Effect.cs"
click node_plugins "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Cordis/Plugin.cs"
click node_eventservice "https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Cordis/EventService.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_desktop,node_sdk,node_user toneBlue
class node_agentloop,node_agentmaf toneAmber
class node_messages,node_llmruntime,node_chatclient,node_deepseek toneMint
class node_session,node_sessionstore,node_projection,node_storage,node_jsonl,node_format toneRose
class node_systemprompt,node_tools,node_terminal,node_approval,node_sandbox,node_goals toneIndigo
class node_cordiscontext,node_fiber,node_effects,node_plugins,node_eventservice toneTeal
```

## Components

### Hosts and SDK

- [CLI host](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Cli/Program.cs): `src/Dsh.Cli/Program.cs`
- [Desktop host](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Desktop/Program.cs): `src/Dsh.Desktop/Program.cs`
- [SDK handler](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Sdk/SdkInitializeHandler.cs): `src/Dsh.Sdk/SdkInitializeHandler.cs`

### Agent runtime

- [Agent loop](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.AgentLoop/AgentLoop.cs): `src/Dsh.AgentLoop/AgentLoop.cs`
- [Agent Framework host](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Agent.Maf/DshAgentHost.cs): `src/Dsh.Agent.Maf/DshAgentHost.cs`

### Models and messages

- [Messages](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Ai/Messages.cs): `src/Dsh.Ai/Messages.cs`
- [LLM runtime](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Llm/LlmRuntime.cs): `src/Dsh.Llm/LlmRuntime.cs`
- [Chat client](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Ai.ChatClient/DshChatClient.cs): `src/Dsh.Ai.ChatClient/DshChatClient.cs`
- [DeepSeek adapter](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Ai.DeepSeek/DeepSeekAdapter.cs): `src/Dsh.Ai.DeepSeek/DeepSeekAdapter.cs`

### Session state

- [Session log](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Session/Session.cs): `src/Dsh.Session/Session.cs`
- [Session store](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Session/SessionStore.cs): `src/Dsh.Session/SessionStore.cs`
- [Session projections](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Session.Projection/SessionProjectionRegistry.cs): `src/Dsh.Session.Projection/SessionProjectionRegistry.cs`
- [Persistence contract](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Session.Persistence/StorageContract.cs): `src/Dsh.Session.Persistence/StorageContract.cs`
- [JSONL persistence](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Session.Persistence.Jsonl/JsonlSessionService.cs): `src/Dsh.Session.Persistence.Jsonl/JsonlSessionService.cs`
- [Session format](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Session.Format/SessionJsonText.cs): `src/Dsh.Session.Format/SessionJsonText.cs`

### Tools and services

- [System prompt](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.SystemPrompt/SystemPrompt.cs): `src/Dsh.SystemPrompt/SystemPrompt.cs`
- [Tool runtime](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Tools/ToolRuntime.cs): `src/Dsh.Tools/ToolRuntime.cs`
- [Terminal control](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Tools/TerminalController.cs): `src/Dsh.Tools/TerminalController.cs`
- [Approval service](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Approval/ApprovalService.cs): `src/Dsh.Approval/ApprovalService.cs`
- [Sandbox policy](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Sandbox.Policy/SandboxPolicyService.cs): `src/Dsh.Sandbox.Policy/SandboxPolicyService.cs`
- [Goal service](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Goal.Service/GoalService.cs): `src/Dsh.Goal.Service/GoalService.cs`

### Cordis platform

- [Service context](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Cordis/Context.cs): `src/Dsh.Cordis/Context.cs`
- [Fiber lifecycle](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Cordis/Fiber.cs): `src/Dsh.Cordis/Fiber.cs`
- [Effect cleanup](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Cordis/Effect.cs): `src/Dsh.Cordis/Effect.cs`
- [Plugin declarations](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Cordis/Plugin.cs): `src/Dsh.Cordis/Plugin.cs`
- [Event service](https://github.com/geffzhang/deepseek-harness-dotnet/blob/main/src/Dsh.Cordis/EventService.cs): `src/Dsh.Cordis/EventService.cs`

### Other components

- **User**

## Connections

- User → CLI host: uses (evidence: `src/Dsh.Cli/Program.cs`)
- User → Desktop host: uses (evidence: `src/Dsh.Desktop/Program.cs`)
- User → SDK handler: calls (evidence: `src/Dsh.Sdk/SdkInitializeHandler.cs`)
- CLI host → Agent loop: starts turns
- Desktop host → Agent loop: hosts sessions
- SDK handler → Agent loop: routes requests (evidence: `src/Dsh.Sdk/SdkInitializeHandler.cs`)
- Agent Framework host → Agent loop: adapts agent
- Agent loop → Session log: prepares sessions (evidence: `src/Dsh.AgentLoop/AgentLoop.cs`)
- Agent loop → LLM runtime: runs model calls (evidence: `src/Dsh.AgentLoop/LlmRemoteServiceAdapter.cs`)
- LLM runtime → Messages: projects messages (evidence: `src/Dsh.Llm/LlmRuntime.cs`)
- LLM runtime → Chat client: uses client
- LLM runtime → DeepSeek adapter: selects adapter
- Session log → Session store: managed by
- Session log → Session projections: projects events (evidence: `src/Dsh.Session.Projection/SessionProjectionRegistry.cs`)
- Session store → Persistence contract: validates persistence
- Persistence contract → JSONL persistence: shared contract (evidence: `src/Dsh.Session.Persistence.Jsonl/JsonlSessionService.cs`)
- JSONL persistence → Session format: reads and writes (evidence: `src/Dsh.Session.Persistence.Jsonl/JsonlSessionService.cs`)
- Agent loop → System prompt: assembles prompts (evidence: `src/Dsh.AgentLoop/AgentLoop.cs`)
- Agent loop → Tool runtime: dispatches tools (evidence: `src/Dsh.AgentLoop/AgentLoop.cs`)
- Tool runtime → Terminal control: routes terminal calls (evidence: `src/Dsh.Tools/TerminalController.cs`)
- Agent loop → Approval service: requests approval (evidence: `src/Dsh.Approval/ApprovalService.cs`)
- Agent loop → Sandbox policy: applies policy
- Agent loop → Goal service: supports goal work (evidence: `src/Dsh.Goal.Service/GoalService.cs`)
- Agent loop → Service context: uses context (evidence: `src/Dsh.AgentLoop/AgentLoop.cs`)
- Service context → Plugin declarations: loads plugins (evidence: `src/Dsh.Cordis/Context.cs`)
- Plugin declarations → Fiber lifecycle: creates fibers (evidence: `src/Dsh.Cordis/Plugin.cs`)
- Fiber lifecycle → Effect cleanup: owns cleanup (evidence: `src/Dsh.Cordis/Fiber.cs`)
- Service context → Event service: dispatches events (evidence: `src/Dsh.Cordis/Context.cs`)
