# moon-wrecker/tau architecture

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

- Interactive diagram: https://gitdiagram.com/moon-wrecker/tau
- Repository: https://github.com/moon-wrecker/tau

## Overview

#### Purpose and Entry Points
Tau is a Python 3.12+ terminal coding agent and reusable agent harness. The installed `tau` command is implemented by the coding application CLI, supporting interactive Textual TUI and one-shot print mode. Package boundaries are intentional: `tau_coding` application layer → `tau_agent` portable orchestration core → `tau_ai` provider adapters.
- `src/tau_coding/cli.py`
- `src/tau_coding/tui/app.py`
- `pyproject.toml`

#### Application Composition
`tau_coding` constructs the coding-specific environment around the generic harness: working directory, system prompt, coding tools, discovered instructions/skills, provider selection, sessions, and frontend choice. `CodingSession`-oriented modules bridge CLI/TUI commands to the core without making `tau_agent` depend on filesystem layout or UI.
- `src/tau_coding/session.py`
- `src/tau_coding/system_prompt.py`
- `src/tau_coding/tools.py`

#### Portable Agent Core
`tau_agent` defines typed messages, events, tools, provider contracts, and the asynchronous agent loop. `AgentHarness` accepts a provider, model, system prompt, and typed tools; on each user prompt it streams provider output, executes requested tools, feeds results back into the loop, and emits neutral events to consumers.
- `src/tau_agent/harness.py`
- `src/tau_agent/loop.py`
- `src/tau_agent/events.py`

#### Provider and Streaming Boundary
`tau_ai` normalizes Anthropic, Google, Mistral, OpenAI/Codex, and OpenAI-compatible APIs into Tau’s provider-neutral streaming interface. HTTP/retry/error handling and model limits live below the agent boundary, so application code selects providers rather than speaking vendor protocols.
- `src/tau_ai/provider.py`
- `src/tau_ai/stream.py`
- `src/tau_ai/openai_compatible.py`

Provider catalog/config/runtime code resolves configured models and credentials into these adapters. OAuth implementations cover interactive authentication flows, including Anthropic and GitHub Copilot.
- `src/tau_coding/provider_catalog.py`
- `src/tau_coding/provider_runtime.py`
- `src/tau_coding/oauth_registry.py`

#### Event Consumers and Frontends
Events are the primary integration contract. Print mode renders events as plain text, JSON, or transcript output; the Textual TUI adapts the same stream into state and widgets. This permits custom frontends without modifying the harness.
- `src/tau_coding/rendering/base.py`
- `src/tau_coding/tui/adapter.py`
- `src/tau_coding/tui/state.py`

Material UI runtime dependencies are Textual and Rich; CLI rendering remains outside `tau_agent`.

#### Durable Context and Sessions
Session history is append-only JSONL with an in-memory active view and tree/branch semantics. The coding layer manages session discovery, resume, export, statistics, context-window accounting, and compaction, preserving durable history while reducing active model context.
- `src/tau_agent/session/jsonl.py`
- `src/tau_agent/session/tree.py`
- `src/tau_coding/session_manager.py`

#### Extensibility and Project Context
At startup and during session assembly, Tau discovers project instructions/resources, skills, prompts, configuration, and extensions. Built-in provider/model definitions are data-driven and user overrides can extend the catalog; extensions can register custom behavior such as tools.
- `src/tau_coding/resources.py`
- `src/tau_coding/skills.py`
- `src/tau_coding/extensions/runtime.py`
- `src/tau_coding/data/catalog.toml`

Main entry points: [`src/tau_coding/session.py`](https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/session.py) (Coding Session), [`src/tau_agent/loop.py`](https://github.com/moon-wrecker/tau/blob/main/src/tau_agent/loop.py) (Async Agent Loop), [`src/tau_coding/provider_runtime.py`](https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/provider_runtime.py) (Provider Runtime), [`src/tau_ai/provider.py`](https://github.com/moon-wrecker/tau/blob/main/src/tau_ai/provider.py) (Provider Interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_coding["Coding Application"]
  node_cli["tau CLI<br/>CLI entry point<br/>[cli.py]"]
  node_tui_app["Textual TUI<br/>interactive frontend<br/>[app.py]"]
  node_coding_session["Coding Session<br/>application composition<br/>[session.py]"]
  node_coding_environment["Prompt &amp; Coding Tools<br/>environment assembly<br/>[tools.py]"]
  node_provider_runtime["Provider Runtime<br/>provider selection"]
  node_provider_catalog["Provider Catalog<br/>catalog configuration"]
  node_oauth["OAuth Registry<br/>authentication<br/>[oauth_registry.py]"]
  node_project_context["Project Context<br/>discovery<br/>[resources.py]"]
  node_extensions["Extension Runtime<br/>plugin runtime<br/>[runtime.py]"]
  node_rendering["Print Renderers<br/>event consumer<br/>[base.py]"]
  node_tui_adapter["TUI Event Adapter<br/>event consumer<br/>[adapter.py]"]
end

subgraph group_agent["Portable Agent Core"]
  node_harness["Agent Harness<br/>orchestration API<br/>[harness.py]"]
  node_agent_loop["Async Agent Loop<br/>tool-execution loop<br/>[loop.py]"]
  node_events["Neutral Events<br/>integration contract<br/>[events.py]"]
  node_session_history[("JSONL Session History<br/>durable storage<br/>[jsonl.py]")]
  node_session_tree["Session Tree<br/>context model<br/>[tree.py]"]
end

subgraph group_ai["Provider Adapters"]
  node_provider_contract["Provider Interface<br/>provider contract<br/>[provider.py]"]
  node_provider_stream["Streaming Layer<br/>stream normalization<br/>[stream.py]"]
  node_openai_compatible["OpenAI-Compatible Adapter<br/>vendor adapter"]
end

node_cli -->|"interactive mode"| node_tui_app
node_cli -->|"print mode"| node_rendering
node_cli -->|"creates"| node_coding_session
node_coding_session -->|"assembles"| node_coding_environment
node_coding_session -->|"discovers"| node_project_context
node_project_context -->|"loads"| node_extensions
node_extensions -.->|"registers tools"| node_coding_environment
node_coding_session -->|"selects model"| node_provider_runtime
node_provider_catalog -->|"definitions"| node_provider_runtime
node_oauth -->|"credentials"| node_provider_runtime
node_provider_runtime -->|"constructs adapter"| node_provider_contract
node_coding_session -->|"configures"| node_harness
node_coding_environment -->|"prompt and tools"| node_harness
node_harness -->|"runs"| node_agent_loop
node_agent_loop -->|"streams requests"| node_provider_contract
node_provider_contract -->|"normalizes"| node_provider_stream
node_openai_compatible -->|"implements"| node_provider_contract
node_provider_stream -->|"model output"| node_agent_loop
node_agent_loop -->|"emits"| node_events
node_events -->|"renders"| node_rendering
node_events -->|"adapts"| node_tui_adapter
node_tui_adapter -->|"updates"| node_tui_app
node_coding_session -->|"manages active context"| node_session_tree
node_session_tree -->|"persists branches"| node_session_history

click node_cli "https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/cli.py"
click node_tui_app "https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/tui/app.py"
click node_coding_session "https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/session.py"
click node_coding_environment "https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/tools.py"
click node_provider_runtime "https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/provider_runtime.py"
click node_provider_catalog "https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/provider_catalog.py"
click node_oauth "https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/oauth_registry.py"
click node_project_context "https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/resources.py"
click node_extensions "https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/extensions/runtime.py"
click node_rendering "https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/rendering/base.py"
click node_tui_adapter "https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/tui/adapter.py"
click node_harness "https://github.com/moon-wrecker/tau/blob/main/src/tau_agent/harness.py"
click node_agent_loop "https://github.com/moon-wrecker/tau/blob/main/src/tau_agent/loop.py"
click node_events "https://github.com/moon-wrecker/tau/blob/main/src/tau_agent/events.py"
click node_session_history "https://github.com/moon-wrecker/tau/blob/main/src/tau_agent/session/jsonl.py"
click node_session_tree "https://github.com/moon-wrecker/tau/blob/main/src/tau_agent/session/tree.py"
click node_provider_contract "https://github.com/moon-wrecker/tau/blob/main/src/tau_ai/provider.py"
click node_provider_stream "https://github.com/moon-wrecker/tau/blob/main/src/tau_ai/stream.py"
click node_openai_compatible "https://github.com/moon-wrecker/tau/blob/main/src/tau_ai/openai_compatible.py"

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_tui_app,node_coding_session,node_coding_environment,node_provider_runtime,node_provider_catalog,node_oauth,node_project_context,node_extensions,node_rendering,node_tui_adapter toneBlue
class node_harness,node_agent_loop,node_events,node_session_history,node_session_tree toneAmber
class node_provider_contract,node_provider_stream,node_openai_compatible toneMint
```

## Components

### Coding Application

CLI, sessions, project context, and frontends.

- [tau CLI](https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/cli.py): CLI entry point · Selects interactive TUI or one-shot rendering. · `src/tau_coding/cli.py`
- [Textual TUI](https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/tui/app.py): interactive frontend · `src/tau_coding/tui/app.py`
- [Coding Session](https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/session.py): application composition · Bridges coding commands and environment into the portable core. · `src/tau_coding/session.py`
- [Prompt & Coding Tools](https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/tools.py): environment assembly · Builds the system prompt and coding-specific tool set. · `src/tau_coding/tools.py`
- [Provider Runtime](https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/provider_runtime.py): provider selection · Resolves configured models and credentials into adapters. · `src/tau_coding/provider_runtime.py`
- [Provider Catalog](https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/provider_catalog.py): catalog configuration · Combines data-driven definitions with user overrides. · `src/tau_coding/provider_catalog.py`
- [OAuth Registry](https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/oauth_registry.py): authentication · Registers interactive provider authentication flows. · `src/tau_coding/oauth_registry.py`
- [Project Context](https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/resources.py): discovery · Discovers instructions, resources, skills, and extensions. · `src/tau_coding/resources.py`
- [Extension Runtime](https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/extensions/runtime.py): plugin runtime · Loads extensions that can register custom behavior and tools. · `src/tau_coding/extensions/runtime.py`
- [Print Renderers](https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/rendering/base.py): event consumer · Renders plain text, JSON, or transcript output. · `src/tau_coding/rendering/base.py`
- [TUI Event Adapter](https://github.com/moon-wrecker/tau/blob/main/src/tau_coding/tui/adapter.py): event consumer · Adapts neutral events into TUI state and widgets. · `src/tau_coding/tui/adapter.py`

### Portable Agent Core

Provider-neutral orchestration and durable context.

- [Agent Harness](https://github.com/moon-wrecker/tau/blob/main/src/tau_agent/harness.py): orchestration API · Accepts model, prompt, provider, and typed tools. · `src/tau_agent/harness.py`
- [Async Agent Loop](https://github.com/moon-wrecker/tau/blob/main/src/tau_agent/loop.py): tool-execution loop · Streams model output, executes tool calls, and returns results to the model. · `src/tau_agent/loop.py`
- [Neutral Events](https://github.com/moon-wrecker/tau/blob/main/src/tau_agent/events.py): integration contract · Provider- and UI-independent stream emitted to consumers. · `src/tau_agent/events.py`
- [JSONL Session History](https://github.com/moon-wrecker/tau/blob/main/src/tau_agent/session/jsonl.py): durable storage · Append-only persisted session history. · `src/tau_agent/session/jsonl.py`
- [Session Tree](https://github.com/moon-wrecker/tau/blob/main/src/tau_agent/session/tree.py): context model · Maintains active views and branch semantics. · `src/tau_agent/session/tree.py`

### Provider Adapters

Vendor API normalization and streaming.

- [Provider Interface](https://github.com/moon-wrecker/tau/blob/main/src/tau_ai/provider.py): provider contract · Normalizes provider-neutral model streaming. · `src/tau_ai/provider.py`
- [Streaming Layer](https://github.com/moon-wrecker/tau/blob/main/src/tau_ai/stream.py): stream normalization · Carries normalized provider stream events. · `src/tau_ai/stream.py`
- [OpenAI-Compatible Adapter](https://github.com/moon-wrecker/tau/blob/main/src/tau_ai/openai_compatible.py): vendor adapter · One adapter family alongside Anthropic, Google, Mistral, and Codex. · `src/tau_ai/openai_compatible.py`

## Connections

- tau CLI → Textual TUI: interactive mode
- tau CLI → Print Renderers: print mode
- tau CLI → Coding Session: creates
- Coding Session → Prompt & Coding Tools: assembles
- Coding Session → Project Context: discovers
- Project Context → Extension Runtime: loads
- Extension Runtime → Prompt & Coding Tools: registers tools
- Coding Session → Provider Runtime: selects model
- Provider Catalog → Provider Runtime: definitions
- OAuth Registry → Provider Runtime: credentials
- Provider Runtime → Provider Interface: constructs adapter
- Coding Session → Agent Harness: configures
- Prompt & Coding Tools → Agent Harness: prompt and tools
- Agent Harness → Async Agent Loop: runs
- Async Agent Loop → Provider Interface: streams requests
- Provider Interface → Streaming Layer: normalizes
- OpenAI-Compatible Adapter → Provider Interface: implements
- Streaming Layer → Async Agent Loop: model output
- Async Agent Loop → Neutral Events: emits
- Neutral Events → Print Renderers: renders
- Neutral Events → TUI Event Adapter: adapts
- TUI Event Adapter → Textual TUI: updates
- Coding Session → Session Tree: manages active context
- Session Tree → JSONL Session History: persists branches
