# specular-org/specular architecture

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

- Interactive diagram: https://gitdiagram.com/specular-org/specular
- Repository: https://github.com/specular-org/specular

## Overview

Specular uses coding agents to analyze a target, generate TLA+ specifications and harnesses, validate them with TLC, and confirm and reproduce violations. Its CLI supports automated phased and single-session orchestration, resumable runs, and incremental continuous verification; agents can also use separately exposed MCP tools for trace debugging, invariant inspection, and specification analysis. The graph preserves these documented capabilities. Some subsystem links are documented only at workflow level because the sampled source excerpts omit their runtime wiring.

Main entry points: [`src/specular/pipelinelib.py`](https://github.com/specular-org/specular/blob/main/src/specular/pipelinelib.py) (Phased pipeline), [`src/specular/phaselib.py`](https://github.com/specular-org/specular/blob/main/src/specular/phaselib.py) (Phase execution), [`src/specular/cli.py`](https://github.com/specular-org/specular/blob/main/src/specular/cli.py) (CLI), [`src/specular/single_session.py`](https://github.com/specular-org/specular/blob/main/src/specular/single_session.py) (Single session)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Run orchestration"]
  node_cli["CLI<br/>[cli.py]"]
  node_pipeline["Phased pipeline<br/>[pipelinelib.py]"]
  node_single_session["Single session<br/>[single_session.py]"]
  node_resume["Run resume<br/>[resumelib.py]"]
  node_ci_workflow["Continuous verification<br/>[ci_workflow.py]"]
end

subgraph group_agent_work["Agent workflow"]
  node_phase_engine["Phase execution<br/>[phaselib.py]"]
  node_agent_adapters["Agent adapters<br/>[claude_code.py]"]
  node_policy["Adapter policy<br/>[policy.py]"]
  node_transient["Transient handling<br/>[transient.py]"]
  node_output_contract["Output contract<br/>[output_contract.py]"]
  node_context_control["Context control<br/>[context_control.py]"]
  node_notes["Agent notes<br/>[notes.py]"]
  node_rules["Workflow rules<br/>[rules.py]"]
end

subgraph group_verification["Model verification"]
  node_confirmation["Bug confirmation<br/>[confirmlib.py]"]
  node_tlc_tasks["TLC tasks<br/>[tlc_tasks.py]"]
  node_resource_summary["Resource summaries"]
end

subgraph group_analysis_tools["Analysis tools"]
  node_trace_debugger["Trace debugger MCP<br/>[mcp_server.py]"]
  node_debug_session["Debug sessions<br/>[session.py]"]
  node_dap_client["DAP client<br/>[dap_client.py]"]
  node_invariant_reader["TLC output MCP<br/>[server.py]"]
  node_tlc_output["TLC output reader"]
  node_spec_analyzer["Spec analyzer MCP<br/>[vav_handler.py]"]
  node_cfa["CFA analyzer"]
end

subgraph group_agent_integrations["Agent integrations"]
  node_coding_agent(("Coding agent"))
  node_tlc["TLC model checker"]
end

node_user(("Engineer"))

node_user -->|"runs"| node_cli
node_cli -.->|"starts"| node_pipeline
node_pipeline -->|"runs phases"| node_phase_engine
node_phase_engine -.->|"uses agents"| node_agent_adapters
node_phase_engine -->|"consults"| node_policy
node_phase_engine -->|"handles transient errors"| node_transient
node_pipeline -->|"selects orchestration"| node_single_session
node_pipeline -->|"restores runs"| node_resume
node_pipeline -->|"checks outputs"| node_output_contract
node_single_session -->|"handles handoffs"| node_context_control
node_phase_engine -->|"adds prompt notes"| node_notes
node_phase_engine -->|"loads rules"| node_rules
node_pipeline -->|"confirms findings"| node_confirmation
node_pipeline -.->|"supports incremental runs"| node_ci_workflow
node_pipeline -->|"completes summaries"| node_resource_summary
node_phase_engine -->|"uses TLC tasks"| node_tlc_tasks
node_tlc_tasks -.->|"launches checks"| node_tlc
node_coding_agent -->|"uses MCP tools"| node_trace_debugger
node_trace_debugger -->|"dispatches"| node_debug_session
node_debug_session -->|"sends requests"| node_dap_client
node_coding_agent -->|"uses MCP tools"| node_invariant_reader
node_invariant_reader -.->|"reads output"| node_tlc_output
node_coding_agent -->|"uses MCP tools"| node_spec_analyzer
node_spec_analyzer -->|"runs analysis"| node_cfa

click node_cli "https://github.com/specular-org/specular/blob/main/src/specular/cli.py"
click node_pipeline "https://github.com/specular-org/specular/blob/main/src/specular/pipelinelib.py"
click node_single_session "https://github.com/specular-org/specular/blob/main/src/specular/single_session.py"
click node_resume "https://github.com/specular-org/specular/blob/main/src/specular/resumelib.py"
click node_ci_workflow "https://github.com/specular-org/specular/blob/main/src/specular/ci_workflow.py"
click node_phase_engine "https://github.com/specular-org/specular/blob/main/src/specular/phaselib.py"
click node_agent_adapters "https://github.com/specular-org/specular/blob/main/src/specular/adapters/claude_code.py"
click node_policy "https://github.com/specular-org/specular/blob/main/src/specular/adapters/utils/policy.py"
click node_transient "https://github.com/specular-org/specular/blob/main/src/specular/adapters/utils/transient.py"
click node_output_contract "https://github.com/specular-org/specular/blob/main/src/specular/output_contract.py"
click node_context_control "https://github.com/specular-org/specular/blob/main/src/specular/context_control.py"
click node_notes "https://github.com/specular-org/specular/blob/main/src/specular/notes.py"
click node_rules "https://github.com/specular-org/specular/blob/main/src/specular/rules.py"
click node_confirmation "https://github.com/specular-org/specular/blob/main/src/specular/confirmlib.py"
click node_tlc_tasks "https://github.com/specular-org/specular/blob/main/src/specular/tlc_tasks.py"
click node_resource_summary "https://github.com/specular-org/specular/blob/main/src/specular/resource_summary.py"
click node_trace_debugger "https://github.com/specular-org/specular/blob/main/tools/trace_debugger/src/tla_mcp/mcp_server.py"
click node_debug_session "https://github.com/specular-org/specular/blob/main/tools/trace_debugger/src/debugger/session.py"
click node_dap_client "https://github.com/specular-org/specular/blob/main/tools/trace_debugger/src/client/dap_client.py"
click node_invariant_reader "https://github.com/specular-org/specular/blob/main/tools/inv_checking_tool/src/mcp/server.py"
click node_tlc_output "https://github.com/specular-org/specular/blob/main/tools/inv_checking_tool/src/tlc_output_reader.py"
click node_spec_analyzer "https://github.com/specular-org/specular/blob/main/tools/spec_analyzer/src/spec_mcp/handlers/vav_handler.py"
click node_cfa "https://github.com/specular-org/specular/blob/main/tools/cfa/src/main/java/CFG/SANYCFGBuilder.java"

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_pipeline,node_single_session,node_resume,node_ci_workflow toneBlue
class node_phase_engine,node_agent_adapters,node_policy,node_transient,node_output_contract,node_context_control,node_notes,node_rules toneAmber
class node_confirmation,node_tlc_tasks,node_resource_summary toneMint
class node_trace_debugger,node_debug_session,node_dap_client,node_invariant_reader,node_tlc_output,node_spec_analyzer,node_cfa toneRose
class node_coding_agent,node_tlc,node_user toneIndigo
```

## Components

### Run orchestration

- [CLI](https://github.com/specular-org/specular/blob/main/src/specular/cli.py): `src/specular/cli.py`
- [Phased pipeline](https://github.com/specular-org/specular/blob/main/src/specular/pipelinelib.py): `src/specular/pipelinelib.py`
- [Single session](https://github.com/specular-org/specular/blob/main/src/specular/single_session.py): `src/specular/single_session.py`
- [Run resume](https://github.com/specular-org/specular/blob/main/src/specular/resumelib.py): `src/specular/resumelib.py`
- [Continuous verification](https://github.com/specular-org/specular/blob/main/src/specular/ci_workflow.py): `src/specular/ci_workflow.py`

### Agent workflow

- [Phase execution](https://github.com/specular-org/specular/blob/main/src/specular/phaselib.py): `src/specular/phaselib.py`
- [Agent adapters](https://github.com/specular-org/specular/blob/main/src/specular/adapters/claude_code.py): `src/specular/adapters/claude_code.py`
- [Adapter policy](https://github.com/specular-org/specular/blob/main/src/specular/adapters/utils/policy.py): `src/specular/adapters/utils/policy.py`
- [Transient handling](https://github.com/specular-org/specular/blob/main/src/specular/adapters/utils/transient.py): `src/specular/adapters/utils/transient.py`
- [Output contract](https://github.com/specular-org/specular/blob/main/src/specular/output_contract.py): `src/specular/output_contract.py`
- [Context control](https://github.com/specular-org/specular/blob/main/src/specular/context_control.py): `src/specular/context_control.py`
- [Agent notes](https://github.com/specular-org/specular/blob/main/src/specular/notes.py): `src/specular/notes.py`
- [Workflow rules](https://github.com/specular-org/specular/blob/main/src/specular/rules.py): `src/specular/rules.py`

### Model verification

- [Bug confirmation](https://github.com/specular-org/specular/blob/main/src/specular/confirmlib.py): `src/specular/confirmlib.py`
- [TLC tasks](https://github.com/specular-org/specular/blob/main/src/specular/tlc_tasks.py): `src/specular/tlc_tasks.py`
- [Resource summaries](https://github.com/specular-org/specular/blob/main/src/specular/resource_summary.py): `src/specular/resource_summary.py`

### Analysis tools

- [Trace debugger MCP](https://github.com/specular-org/specular/blob/main/tools/trace_debugger/src/tla_mcp/mcp_server.py): `tools/trace_debugger/src/tla_mcp/mcp_server.py`
- [Debug sessions](https://github.com/specular-org/specular/blob/main/tools/trace_debugger/src/debugger/session.py): `tools/trace_debugger/src/debugger/session.py`
- [DAP client](https://github.com/specular-org/specular/blob/main/tools/trace_debugger/src/client/dap_client.py): `tools/trace_debugger/src/client/dap_client.py`
- [TLC output MCP](https://github.com/specular-org/specular/blob/main/tools/inv_checking_tool/src/mcp/server.py): `tools/inv_checking_tool/src/mcp/server.py`
- [TLC output reader](https://github.com/specular-org/specular/blob/main/tools/inv_checking_tool/src/tlc_output_reader.py): `tools/inv_checking_tool/src/tlc_output_reader.py`
- [Spec analyzer MCP](https://github.com/specular-org/specular/blob/main/tools/spec_analyzer/src/spec_mcp/handlers/vav_handler.py): `tools/spec_analyzer/src/spec_mcp/handlers/vav_handler.py`
- [CFA analyzer](https://github.com/specular-org/specular/blob/main/tools/cfa/src/main/java/CFG/SANYCFGBuilder.java): `tools/cfa/src/main/java/CFG/SANYCFGBuilder.java`

### Agent integrations

- **Coding agent**
- **TLC model checker**

### Other components

- **Engineer**

## Connections

- Engineer → CLI: runs (evidence: `README.md`)
- CLI → Phased pipeline: starts
- Phased pipeline → Phase execution: runs phases (evidence: `src/specular/pipelinelib.py`)
- Phase execution → Agent adapters: uses agents
- Phase execution → Adapter policy: consults (evidence: `src/specular/phaselib.py`)
- Phase execution → Transient handling: handles transient errors (evidence: `src/specular/phaselib.py`)
- Phased pipeline → Single session: selects orchestration (evidence: `src/specular/pipelinelib.py`)
- Phased pipeline → Run resume: restores runs (evidence: `src/specular/pipelinelib.py`)
- Phased pipeline → Output contract: checks outputs (evidence: `src/specular/pipelinelib.py`)
- Single session → Context control: handles handoffs (evidence: `src/specular/single_session.py`)
- Phase execution → Agent notes: adds prompt notes (evidence: `src/specular/phaselib.py`)
- Phase execution → Workflow rules: loads rules (evidence: `src/specular/phaselib.py`)
- Phased pipeline → Bug confirmation: confirms findings (evidence: `src/specular/pipelinelib.py`)
- Phased pipeline → Continuous verification: supports incremental runs (evidence: `src/specular/pipelinelib.py`)
- Phased pipeline → Resource summaries: completes summaries (evidence: `src/specular/pipelinelib.py`)
- Phase execution → TLC tasks: uses TLC tasks (evidence: `src/specular/phaselib.py`)
- TLC tasks → TLC model checker: launches checks
- Coding agent → Trace debugger MCP: uses MCP tools (evidence: `README.md`)
- Trace debugger MCP → Debug sessions: dispatches (evidence: `tools/trace_debugger/src/tla_mcp/mcp_server.py`)
- Debug sessions → DAP client: sends requests (evidence: `tools/trace_debugger/src/debugger/session.py`)
- Coding agent → TLC output MCP: uses MCP tools (evidence: `README.md`)
- TLC output MCP → TLC output reader: reads output
- Coding agent → Spec analyzer MCP: uses MCP tools (evidence: `README.md`)
- Spec analyzer MCP → CFA analyzer: runs analysis (evidence: `tools/spec_analyzer/src/spec_mcp/handlers/vav_handler.py`)
