# tdav/myharness architecture

> Architecture diagram of the GitHub repository tdav/myharness, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tdav/myharness
- Repository: https://github.com/tdav/myharness

## Overview

#### Purpose and solution shape
MyHarness is an autonomous ReAct coding/research agent backed by Ollama Cloud or compatible Ollama servers. Shared agent behavior lives in the `net10.0` library; WinForms and terminal applications are presentation shells over it. Solution entry points are `MyHarness/Program.cs` and `HarnessCli/Program.cs`; core assembly and orchestration begin at `Harness.Core/AgentHost.cs`.

#### Agent host and model boundary
`AgentHost` constructs the Microsoft Agent Framework/Harness agent, configures OllamaSharp with Bearer authentication, registers tools, and owns workspace-scoped runtime dependencies. Settings resolve from `secret.json` and environment variables, with model/context-window changes requiring host recreation while preserving sessions.
- `Harness.Core/AgentHost.cs`
- `Harness.Core/IAgentHost.cs`
- `Harness.Core/AppSettings.cs`

The external model boundary is Ollama’s API: model listing/context discovery and streaming completion traffic go to Ollama Cloud or a local compatible endpoint.

#### ReAct execution and workspace safety
The agent iterates reasoning, tool selection, execution, and observation. It operates against a selected working directory and exposes file access/search, PowerShell execution, Hyperlight-isolated Python CodeAct, todo/mode/memory capabilities, and optional web tools. UI supplies approval decisions; read-only file operations are auto-approved, while mutations and execution require policy approval.
- `Harness.Core/AgentHost.cs`
- `Harness.Core/Runtime/RunLoop.cs`
- `Harness.Core/Runtime/TaskQueue.cs`

Shell and filesystem execution are a critical trust boundary: workspace scoping, command deny-listing, timeouts, sandboxing, and approval policy protect the host.

#### Sessions, long-running work, and recovery
Runtime services model queued work, progress, health, notifications, automated recovery, and long-running agent runs. Session persistence preserves conversation state across UI session changes and application restarts; memory services compact/prune context and retain longer-lived information.
- `Harness.Core/Persistence/SessionStore.cs`
- `Harness.Core/Runtime/LongRunManager.cs`
- `Harness.Core/Runtime/AutoRecovery.cs`
- `Harness.Core/Memory/LongTermMemory.cs`
- `Harness.Core/Memory/ContextCompactor.cs`

#### Goal planning and self-improvement
For multi-step work, goals are decomposed into a tree and prioritized for scheduling. Post-run analysis can refine execution strategy and optimize prompts, forming a feedback loop around agent outcomes rather than UI behavior.
- `Harness.Core/Goals/GoalDecomposer.cs`
- `Harness.Core/Goals/GoalTree.cs`
- `Harness.Core/Goals/PriorityScheduler.cs`
- `Harness.Core/Evolution/RunAnalyzer.cs`
- `Harness.Core/Evolution/PromptOptimizer.cs`

#### Extensibility, packaged knowledge, and workflows
Runtime plugins are C# source files compiled with Roslyn and loaded as one-shot tools or resident services. Plugins may call back into the agent through persistent plugin sessions; examples include web search and Telegram. This feature depends on JIT and is unavailable under NativeAOT. Shipped skill/persona documents and .NET scripts are runtime-discovered/copied resources, not compiled agent logic.
- `Harness.Core/Plugins/PluginContracts.cs`
- `Harness.Core/Plugins/PluginManager.cs`
- `Harness.Core/Workflows/Magentic.cs`
- `Harness.Core/agents/`
- `Harness.Core/skills/`

#### UI adapters and observability
WinForms provides WebView2 Markdown rendering and interactive tool approval; SharpConsoleUI provides the equivalent terminal workflow. Both create and drive `AgentHost` instances, stream transcripts, manage sessions/models/modes, and surface plugin logs. OpenTelemetry spans—including HTTP instrumentation—are file-exported; Serilog application logging is configured by the app hosts.
- `MyHarness/UI/MainForm.cs`
- `MyHarness/UI/MarkdownViewer.cs`
- `HarnessCli/UI/MainWindow.cs`
- `Harness.Core/Tracing/HarnessTracing.cs`
- `Harness.Core/Tracing/FileSpanExporter.cs`

Main entry points: [`Harness.Core/AgentHost.cs`](https://github.com/tdav/myharness/blob/master/Harness.Core/AgentHost.cs) (Agent host), [`Harness.Core/Runtime/RunLoop.cs`](https://github.com/tdav/myharness/blob/master/Harness.Core/Runtime/RunLoop.cs) (ReAct run loop), [`MyHarness/UI/MainForm.cs`](https://github.com/tdav/myharness/blob/master/MyHarness/UI/MainForm.cs) (WinForms app), [`HarnessCli/UI/MainWindow.cs`](https://github.com/tdav/myharness/blob/master/HarnessCli/UI/MainWindow.cs) (Terminal app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Presentation shells"]
  node_winforms["WinForms app<br/>desktop shell<br/>[MainForm.cs]"]
  node_markdown["Markdown viewer<br/>WebView2 renderer<br/>[MarkdownViewer.cs]"]
  node_terminal["Terminal app<br/>console shell<br/>[MainWindow.cs]"]
end

subgraph group_core["Agent runtime"]
  node_host{{"Agent host<br/>agent composition root<br/>[AgentHost.cs]"}}
  node_host_contract["Agent host contract<br/>interface<br/>[IAgentHost.cs]"]
  node_settings["Settings<br/>configuration resolver<br/>[AppSettings.cs]"]
  node_run_loop{{"ReAct run loop<br/>execution orchestrator<br/>[RunLoop.cs]"}}
  node_task_queue["Task queue<br/>work scheduler<br/>[TaskQueue.cs]"]
  node_tool_boundary{{"Workspace tool boundary<br/>approval and sandbox policy<br/>[AgentHost.cs]"}}
  node_long_runs["Long-run manager<br/>runtime service<br/>[LongRunManager.cs]"]
  node_recovery["Auto recovery<br/>runtime service<br/>[AutoRecovery.cs]"]
  node_sessions[("Session store<br/>persistence<br/>[SessionStore.cs]")]
  node_memory["Memory services<br/>context lifecycle<br/>[LongTermMemory.cs]"]
  node_goals["Goal planning<br/>decomposition and scheduling<br/>[GoalDecomposer.cs]"]
  node_evolution["Run evolution<br/>feedback optimizer<br/>[RunAnalyzer.cs]"]
  node_tracing["Tracing export<br/>OpenTelemetry file exporter"]
end

subgraph group_extension["Extensibility"]
  node_plugins{{"Plugin manager<br/>Roslyn runtime plugins<br/>[PluginManager.cs]"}}
  node_workflows["Magentic workflows<br/>multi-agent workflow<br/>[Magentic.cs]"]
  node_knowledge["Skills and personas<br/>runtime resources"]
end

node_ollama(("Ollama API<br/>external model service"))

node_winforms -->|"creates and drives"| node_host
node_terminal -->|"creates and drives"| node_host
node_winforms -->|"renders transcripts"| node_markdown
node_host -->|"implements"| node_host_contract
node_host -->|"loads"| node_settings
node_host -->|"streams completions"| node_ollama
node_host -->|"runs"| node_run_loop
node_run_loop -->|"selects tools through"| node_tool_boundary
node_winforms -->|"supplies approvals"| node_tool_boundary
node_terminal -->|"supplies approvals"| node_tool_boundary
node_run_loop -->|"queues work"| node_task_queue
node_task_queue -->|"tracks execution"| node_long_runs
node_long_runs -.->|"triggers recovery"| node_recovery
node_host -->|"preserves sessions"| node_sessions
node_run_loop -->|"compacts and recalls context"| node_memory
node_run_loop -->|"plans multi-step work"| node_goals
node_run_loop -.->|"sends outcomes"| node_evolution
node_evolution -.->|"refines prompts and strategy"| node_run_loop
node_host -->|"registers runtime tools"| node_plugins
node_plugins -->|"adds tools and services"| node_run_loop
node_host -->|"hosts"| node_workflows
node_host -->|"discovers resources"| node_knowledge
node_host -->|"emits spans"| node_tracing

click node_winforms "https://github.com/tdav/myharness/blob/master/MyHarness/UI/MainForm.cs"
click node_markdown "https://github.com/tdav/myharness/blob/master/MyHarness/UI/MarkdownViewer.cs"
click node_terminal "https://github.com/tdav/myharness/blob/master/HarnessCli/UI/MainWindow.cs"
click node_host "https://github.com/tdav/myharness/blob/master/Harness.Core/AgentHost.cs"
click node_host_contract "https://github.com/tdav/myharness/blob/master/Harness.Core/IAgentHost.cs"
click node_settings "https://github.com/tdav/myharness/blob/master/Harness.Core/AppSettings.cs"
click node_run_loop "https://github.com/tdav/myharness/blob/master/Harness.Core/Runtime/RunLoop.cs"
click node_task_queue "https://github.com/tdav/myharness/blob/master/Harness.Core/Runtime/TaskQueue.cs"
click node_tool_boundary "https://github.com/tdav/myharness/blob/master/Harness.Core/AgentHost.cs"
click node_long_runs "https://github.com/tdav/myharness/blob/master/Harness.Core/Runtime/LongRunManager.cs"
click node_recovery "https://github.com/tdav/myharness/blob/master/Harness.Core/Runtime/AutoRecovery.cs"
click node_sessions "https://github.com/tdav/myharness/blob/master/Harness.Core/Persistence/SessionStore.cs"
click node_memory "https://github.com/tdav/myharness/blob/master/Harness.Core/Memory/LongTermMemory.cs"
click node_goals "https://github.com/tdav/myharness/blob/master/Harness.Core/Goals/GoalDecomposer.cs"
click node_evolution "https://github.com/tdav/myharness/blob/master/Harness.Core/Evolution/RunAnalyzer.cs"
click node_plugins "https://github.com/tdav/myharness/blob/master/Harness.Core/Plugins/PluginManager.cs"
click node_workflows "https://github.com/tdav/myharness/blob/master/Harness.Core/Workflows/Magentic.cs"
click node_tracing "https://github.com/tdav/myharness/blob/master/Harness.Core/Tracing/FileSpanExporter.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_winforms,node_markdown,node_terminal toneBlue
class node_host,node_host_contract,node_settings,node_run_loop,node_task_queue,node_tool_boundary,node_long_runs,node_recovery,node_sessions,node_memory,node_goals,node_evolution,node_tracing toneAmber
class node_plugins,node_workflows,node_knowledge toneMint
class node_ollama toneNeutral
```

## Components

### Presentation shells

Interactive WinForms and terminal adapters.

- [WinForms app](https://github.com/tdav/myharness/blob/master/MyHarness/UI/MainForm.cs): desktop shell · Drives agent sessions and tool approvals. · `MyHarness/UI/MainForm.cs`
- [Markdown viewer](https://github.com/tdav/myharness/blob/master/MyHarness/UI/MarkdownViewer.cs): WebView2 renderer · `MyHarness/UI/MarkdownViewer.cs`
- [Terminal app](https://github.com/tdav/myharness/blob/master/HarnessCli/UI/MainWindow.cs): console shell · Terminal equivalent of the interactive workflow. · `HarnessCli/UI/MainWindow.cs`

### Agent runtime

Shared net10.0 agent orchestration and state.

- [Agent host](https://github.com/tdav/myharness/blob/master/Harness.Core/AgentHost.cs): agent composition root · Builds the framework agent and workspace-scoped dependencies. · `Harness.Core/AgentHost.cs`
- [Agent host contract](https://github.com/tdav/myharness/blob/master/Harness.Core/IAgentHost.cs): interface · `Harness.Core/IAgentHost.cs`
- [Settings](https://github.com/tdav/myharness/blob/master/Harness.Core/AppSettings.cs): configuration resolver · Resolves secret.json and environment settings. · `Harness.Core/AppSettings.cs`
- [ReAct run loop](https://github.com/tdav/myharness/blob/master/Harness.Core/Runtime/RunLoop.cs): execution orchestrator · Coordinates reasoning, tool execution, and observations. · `Harness.Core/Runtime/RunLoop.cs`
- [Task queue](https://github.com/tdav/myharness/blob/master/Harness.Core/Runtime/TaskQueue.cs): work scheduler · `Harness.Core/Runtime/TaskQueue.cs`
- [Workspace tool boundary](https://github.com/tdav/myharness/blob/master/Harness.Core/AgentHost.cs): approval and sandbox policy · Scopes filesystem and shell access; mutations and execution require approval. · `Harness.Core/AgentHost.cs`
- [Long-run manager](https://github.com/tdav/myharness/blob/master/Harness.Core/Runtime/LongRunManager.cs): runtime service · Tracks progress, health, notifications, and long-running work. · `Harness.Core/Runtime/LongRunManager.cs`
- [Auto recovery](https://github.com/tdav/myharness/blob/master/Harness.Core/Runtime/AutoRecovery.cs): runtime service · `Harness.Core/Runtime/AutoRecovery.cs`
- [Session store](https://github.com/tdav/myharness/blob/master/Harness.Core/Persistence/SessionStore.cs): persistence · Persists conversation state across UI changes and restarts. · `Harness.Core/Persistence/SessionStore.cs`
- [Memory services](https://github.com/tdav/myharness/blob/master/Harness.Core/Memory/LongTermMemory.cs): context lifecycle · Compacts context and retains long-lived information. · `Harness.Core/Memory/LongTermMemory.cs`
- [Goal planning](https://github.com/tdav/myharness/blob/master/Harness.Core/Goals/GoalDecomposer.cs): decomposition and scheduling · Builds goal trees and prioritizes multi-step work. · `Harness.Core/Goals/GoalDecomposer.cs`
- [Run evolution](https://github.com/tdav/myharness/blob/master/Harness.Core/Evolution/RunAnalyzer.cs): feedback optimizer · Analyzes outcomes to refine strategy and prompts. · `Harness.Core/Evolution/RunAnalyzer.cs`
- [Tracing export](https://github.com/tdav/myharness/blob/master/Harness.Core/Tracing/FileSpanExporter.cs): OpenTelemetry file exporter · Exports spans, including HTTP instrumentation, to files. · `Harness.Core/Tracing/FileSpanExporter.cs`

### Extensibility

Runtime-loaded capabilities and packaged resources.

- [Plugin manager](https://github.com/tdav/myharness/blob/master/Harness.Core/Plugins/PluginManager.cs): Roslyn runtime plugins · Compiles C# plugins into one-shot tools or resident services; requires JIT. · `Harness.Core/Plugins/PluginManager.cs`
- [Magentic workflows](https://github.com/tdav/myharness/blob/master/Harness.Core/Workflows/Magentic.cs): multi-agent workflow · `Harness.Core/Workflows/Magentic.cs`
- **Skills and personas**: runtime resources · Discovered packaged documents and scripts, not compiled agent logic.

### Other components

- **Ollama API**: external model service · Cloud or compatible local endpoint for discovery and streaming completions.

## Connections

- WinForms app → Agent host: creates and drives
- Terminal app → Agent host: creates and drives
- WinForms app → Markdown viewer: renders transcripts
- Agent host → Agent host contract: implements
- Agent host → Settings: loads
- Agent host → Ollama API: streams completions
- Agent host → ReAct run loop: runs
- ReAct run loop → Workspace tool boundary: selects tools through
- WinForms app → Workspace tool boundary: supplies approvals
- Terminal app → Workspace tool boundary: supplies approvals
- ReAct run loop → Task queue: queues work
- Task queue → Long-run manager: tracks execution
- Long-run manager → Auto recovery: triggers recovery
- Agent host → Session store: preserves sessions
- ReAct run loop → Memory services: compacts and recalls context
- ReAct run loop → Goal planning: plans multi-step work
- ReAct run loop → Run evolution: sends outcomes
- Run evolution → ReAct run loop: refines prompts and strategy
- Agent host → Plugin manager: registers runtime tools
- Plugin manager → ReAct run loop: adds tools and services
- Agent host → Magentic workflows: hosts
- Agent host → Skills and personas: discovers resources
- Agent host → Tracing export: emits spans
