# thetaplex/thetaterm architecture

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

- Interactive diagram: https://gitdiagram.com/thetaplex/thetaterm
- Repository: https://github.com/thetaplex/thetaterm

## Overview

ThetaTerm turns a natural-language request into a command tailored to the local OS and installed tools, then shows it for confirmation before execution. Its CLI also supports direct user-entered commands and an auto-confirm option, while outside-directory patterns always require confirmation. A separate MCP server exposes system information, documentation, command checks, and suggestions to other agents without running commands. The README documents the local tool/man-page context and OpenAI-compatible model support; the sampled source excerpts do not expose every internal call involved in gathering that context.

Main entry points: [`thetaterm/agent.py`](https://github.com/thetaplex/thetaterm/blob/main/thetaterm/agent.py) (Command agent), [`thetaterm/mcp.py`](https://github.com/thetaplex/thetaterm/blob/main/thetaterm/mcp.py) (MCP tools), [`thetaterm/cli.py`](https://github.com/thetaplex/thetaterm/blob/main/thetaterm/cli.py) (Query handling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Terminal workflow"]
  node_cli["CLI interface<br/>[cli.py]"]
  node_query_flow["Query handling<br/>[cli.py]"]
  node_approval["Review and approval<br/>[cli.py]"]
  node_shell_run["Shell execution<br/>[cli.py]"]
end

subgraph group_generation["Command generation"]
  node_agent["Command agent<br/>[agent.py]"]
  node_model_api["Model API client<br/>[agent.py]"]
  node_command_checks["Command checks<br/>[agent.py]"]
end

subgraph group_mcp["Agent integration"]
  node_mcp_server["MCP server<br/>[mcp.py]"]
  node_mcp_tools["MCP tools<br/>[mcp.py]"]
end

subgraph group_environment["Local system"]
  node_local_context["System and tool context<br/>[agent.py]"]
  node_local_shell["User shell"]
end

node_user(("Terminal user"))
node_model_service["Model server"]
node_agent_client(("Calling agent"))

node_user -->|"requests command"| node_cli
node_cli -->|"handles input"| node_query_flow
node_query_flow -->|"requests generation"| node_agent
node_query_flow -->|"presents command"| node_approval
node_approval -->|"checks outside paths"| node_command_checks
node_approval -->|"approves execution"| node_shell_run
node_shell_run -->|"runs command"| node_local_shell
node_agent -->|"requests completion"| node_model_api
node_model_api -->|"sends API request"| node_model_service
node_agent -->|"validates output"| node_command_checks
node_agent -.->|"uses system references"| node_local_context
node_agent_client -->|"connects over MCP"| node_mcp_server
node_mcp_server -->|"registers tools"| node_mcp_tools
node_mcp_tools -->|"suggests commands"| node_agent
node_mcp_tools -->|"returns system docs"| node_local_context
node_mcp_tools -->|"checks commands"| node_command_checks

click node_cli "https://github.com/thetaplex/thetaterm/blob/main/thetaterm/cli.py"
click node_query_flow "https://github.com/thetaplex/thetaterm/blob/main/thetaterm/cli.py"
click node_approval "https://github.com/thetaplex/thetaterm/blob/main/thetaterm/cli.py"
click node_shell_run "https://github.com/thetaplex/thetaterm/blob/main/thetaterm/cli.py"
click node_agent "https://github.com/thetaplex/thetaterm/blob/main/thetaterm/agent.py"
click node_model_api "https://github.com/thetaplex/thetaterm/blob/main/thetaterm/agent.py"
click node_local_context "https://github.com/thetaplex/thetaterm/blob/main/thetaterm/agent.py"
click node_command_checks "https://github.com/thetaplex/thetaterm/blob/main/thetaterm/agent.py"
click node_mcp_server "https://github.com/thetaplex/thetaterm/blob/main/thetaterm/mcp.py"
click node_mcp_tools "https://github.com/thetaplex/thetaterm/blob/main/thetaterm/mcp.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_query_flow,node_approval,node_shell_run,node_user toneBlue
class node_agent,node_model_api,node_command_checks toneAmber
class node_mcp_server,node_mcp_tools,node_model_service toneMint
class node_local_context,node_local_shell toneRose
class node_agent_client toneIndigo
```

## Components

### Terminal workflow

- [CLI interface](https://github.com/thetaplex/thetaterm/blob/main/thetaterm/cli.py): `thetaterm/cli.py`
- [Query handling](https://github.com/thetaplex/thetaterm/blob/main/thetaterm/cli.py): `thetaterm/cli.py`
- [Review and approval](https://github.com/thetaplex/thetaterm/blob/main/thetaterm/cli.py): `thetaterm/cli.py`
- [Shell execution](https://github.com/thetaplex/thetaterm/blob/main/thetaterm/cli.py): `thetaterm/cli.py`

### Command generation

- [Command agent](https://github.com/thetaplex/thetaterm/blob/main/thetaterm/agent.py): `thetaterm/agent.py`
- [Model API client](https://github.com/thetaplex/thetaterm/blob/main/thetaterm/agent.py): `thetaterm/agent.py`
- [Command checks](https://github.com/thetaplex/thetaterm/blob/main/thetaterm/agent.py): `thetaterm/agent.py`

### Agent integration

- [MCP server](https://github.com/thetaplex/thetaterm/blob/main/thetaterm/mcp.py): `thetaterm/mcp.py`
- [MCP tools](https://github.com/thetaplex/thetaterm/blob/main/thetaterm/mcp.py): `thetaterm/mcp.py`

### Local system

- [System and tool context](https://github.com/thetaplex/thetaterm/blob/main/thetaterm/agent.py): `thetaterm/agent.py`
- **User shell**

### Other components

- **Terminal user**
- **Model server**
- **Calling agent**

## Connections

- Terminal user → CLI interface: requests command (evidence: `README.md`)
- CLI interface → Query handling: handles input (evidence: `thetaterm/cli.py`)
- Query handling → Command agent: requests generation (evidence: `thetaterm/cli.py`)
- Query handling → Review and approval: presents command (evidence: `thetaterm/cli.py`)
- Review and approval → Command checks: checks outside paths (evidence: `thetaterm/cli.py`)
- Review and approval → Shell execution: approves execution (evidence: `thetaterm/cli.py`)
- Shell execution → User shell: runs command (evidence: `thetaterm/cli.py`)
- Command agent → Model API client: requests completion (evidence: `thetaterm/agent.py`)
- Model API client → Model server: sends API request (evidence: `thetaterm/agent.py`)
- Command agent → Command checks: validates output (evidence: `thetaterm/agent.py`)
- Command agent → System and tool context: uses system references (evidence: `thetaterm/agent.py`)
- Calling agent → MCP server: connects over MCP (evidence: `README.md`)
- MCP server → MCP tools: registers tools (evidence: `thetaterm/mcp.py`)
- MCP tools → Command agent: suggests commands (evidence: `thetaterm/mcp.py`)
- MCP tools → System and tool context: returns system docs (evidence: `thetaterm/mcp.py`)
- MCP tools → Command checks: checks commands (evidence: `thetaterm/mcp.py`)
