# andreashappe/cochise architecture

> Architecture diagram of the GitHub repository andreashappe/cochise, 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/andreashappe/cochise
- Repository: https://github.com/andreashappe/cochise

## Overview

Cochise is an autonomous Active Directory penetration-testing agent: a persistent Planner selects attack tasks, short-lived Executors run commands on an attacker VM and return findings, and shared Knowledge carries discoveries between tasks. It also records structured run logs and provides replay, tabular analysis, and graph-based analysis for benchmarking. Runtime relationships are supported by the README and sampled source; some analysis modules were not sampled, so their internal behavior is represented only where the source index or README supports it.

Main entry points: [`src/cochise/cli/cochise.py`](https://github.com/andreashappe/cochise/blob/main/src/cochise/cli/cochise.py) (Runtime CLI), [`src/cochise/analysis/common_analysis.py`](https://github.com/andreashappe/cochise/blob/main/src/cochise/analysis/common_analysis.py) (Run Log Parser), [`src/cochise/cli/analyze_json_logs.py`](https://github.com/andreashappe/cochise/blob/main/src/cochise/cli/analyze_json_logs.py) (Log Analysis CLI), [`src/cochise/planner.py`](https://github.com/andreashappe/cochise/blob/main/src/cochise/planner.py) (Planner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Planning"]
  node_runtime_cli["Runtime CLI<br/>[cochise.py]"]
  node_scenario["Attack Scenario<br/>[scenario.md]"]
  node_planner["Planner<br/>[planner.py]"]
  node_llm_client["LLM Interface<br/>[common.py]"]
end

subgraph group_execution["Task Execution"]
  node_executor_factory["Executor Factory<br/>[executor.py]"]
  node_executor["Task Executor<br/>[executor.py]"]
  node_ssh["SSH Connection<br/>[ssh_connection.py]"]
end

subgraph group_state["Shared State"]
  node_knowledge[("Knowledge Base<br/>[knowledge.py]")]
end

subgraph group_observability["Run Records"]
  node_logger["Run Logger<br/>[logger.py]"]
  node_run_logs["JSON Run Logs"]
end

subgraph group_analysis["Run Analysis"]
  node_replay_cli["Replay CLI<br/>[cochise_replay.py]"]
  node_log_analysis_cli["Log Analysis CLI"]
  node_graph_analysis_cli["Graph Analysis CLI"]
  node_log_parser["Run Log Parser<br/>[common_analysis.py]"]
  node_round_analysis["Round Analysis<br/>[index_rounds.py]"]
  node_round_token_analysis["Round Token Analysis"]
  node_account_analysis["Account Analysis"]
  node_token_analysis["Token Analysis<br/>[show_tokens.py]"]
end

node_operator(("Operator"))
node_llm_provider(("LLM Provider"))
node_attacker_vm(("Attacker VM"))

node_operator -->|"starts run"| node_runtime_cli
node_runtime_cli -->|"loads scenario"| node_scenario
node_runtime_cli -->|"configures SSH"| node_ssh
node_runtime_cli -->|"creates factory"| node_executor_factory
node_runtime_cli -->|"starts planning"| node_planner
node_planner -->|"requests plans"| node_llm_client
node_executor -->|"requests task calls"| node_llm_client
node_llm_client -->|"sends LLM requests"| node_llm_provider
node_planner -->|"delegates tasks"| node_executor_factory
node_executor_factory -->|"builds executor"| node_executor
node_executor -->|"invokes configured tools"| node_ssh
node_ssh -->|"executes commands"| node_attacker_vm
node_planner -->|"aggregates findings"| node_knowledge
node_executor -->|"returns findings"| node_knowledge
node_runtime_cli -->|"configures logging"| node_logger
node_logger -->|"writes events"| node_run_logs
node_operator -->|"replays run"| node_replay_cli
node_replay_cli -->|"reads run"| node_run_logs
node_operator -->|"analyzes runs"| node_log_analysis_cli
node_log_analysis_cli -->|"dispatches analysis"| node_round_analysis
node_log_analysis_cli -->|"dispatches analysis"| node_round_token_analysis
node_log_analysis_cli -->|"dispatches analysis"| node_account_analysis
node_log_analysis_cli -->|"dispatches analysis"| node_token_analysis
node_round_analysis -->|"parses run data"| node_log_parser
node_round_token_analysis -->|"parses run data"| node_log_parser
node_account_analysis -->|"parses run data"| node_log_parser
node_token_analysis -->|"parses run data"| node_log_parser
node_operator -->|"graphs run metrics"| node_graph_analysis_cli
node_graph_analysis_cli -->|"traverses run data"| node_log_parser
node_log_parser -->|"reads events"| node_run_logs

click node_runtime_cli "https://github.com/andreashappe/cochise/blob/main/src/cochise/cli/cochise.py"
click node_scenario "https://github.com/andreashappe/cochise/blob/main/src/cochise/templates/scenario.md"
click node_planner "https://github.com/andreashappe/cochise/blob/main/src/cochise/planner.py"
click node_llm_client "https://github.com/andreashappe/cochise/blob/main/src/cochise/common.py"
click node_executor_factory "https://github.com/andreashappe/cochise/blob/main/src/cochise/executor.py"
click node_executor "https://github.com/andreashappe/cochise/blob/main/src/cochise/executor.py"
click node_ssh "https://github.com/andreashappe/cochise/blob/main/src/cochise/ssh_connection.py"
click node_knowledge "https://github.com/andreashappe/cochise/blob/main/src/cochise/knowledge.py"
click node_logger "https://github.com/andreashappe/cochise/blob/main/src/cochise/logger.py"
click node_run_logs "https://github.com/andreashappe/cochise/tree/main/logs"
click node_replay_cli "https://github.com/andreashappe/cochise/blob/main/src/cochise/cli/cochise_replay.py"
click node_log_analysis_cli "https://github.com/andreashappe/cochise/blob/main/src/cochise/cli/analyze_json_logs.py"
click node_graph_analysis_cli "https://github.com/andreashappe/cochise/blob/main/src/cochise/cli/analyze_json_graphs.py"
click node_log_parser "https://github.com/andreashappe/cochise/blob/main/src/cochise/analysis/common_analysis.py"
click node_round_analysis "https://github.com/andreashappe/cochise/blob/main/src/cochise/analysis/index_rounds.py"
click node_round_token_analysis "https://github.com/andreashappe/cochise/blob/main/src/cochise/analysis/index_rounds_and_tokens.py"
click node_account_analysis "https://github.com/andreashappe/cochise/blob/main/src/cochise/analysis/index_tokens_and_accounts.py"
click node_token_analysis "https://github.com/andreashappe/cochise/blob/main/src/cochise/analysis/show_tokens.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_runtime_cli,node_scenario,node_planner,node_llm_client toneBlue
class node_executor_factory,node_executor,node_ssh toneAmber
class node_knowledge toneMint
class node_logger,node_run_logs toneRose
class node_replay_cli,node_log_analysis_cli,node_graph_analysis_cli,node_log_parser,node_round_analysis,node_round_token_analysis,node_account_analysis,node_token_analysis,node_operator,node_llm_provider,node_attacker_vm toneIndigo
```

## Components

### Planning

- [Runtime CLI](https://github.com/andreashappe/cochise/blob/main/src/cochise/cli/cochise.py): `src/cochise/cli/cochise.py`
- [Attack Scenario](https://github.com/andreashappe/cochise/blob/main/src/cochise/templates/scenario.md): `src/cochise/templates/scenario.md`
- [Planner](https://github.com/andreashappe/cochise/blob/main/src/cochise/planner.py): `src/cochise/planner.py`
- [LLM Interface](https://github.com/andreashappe/cochise/blob/main/src/cochise/common.py): `src/cochise/common.py`

### Task Execution

- [Executor Factory](https://github.com/andreashappe/cochise/blob/main/src/cochise/executor.py): `src/cochise/executor.py`
- [Task Executor](https://github.com/andreashappe/cochise/blob/main/src/cochise/executor.py): `src/cochise/executor.py`
- [SSH Connection](https://github.com/andreashappe/cochise/blob/main/src/cochise/ssh_connection.py): `src/cochise/ssh_connection.py`

### Shared State

- [Knowledge Base](https://github.com/andreashappe/cochise/blob/main/src/cochise/knowledge.py): `src/cochise/knowledge.py`

### Run Records

- [Run Logger](https://github.com/andreashappe/cochise/blob/main/src/cochise/logger.py): `src/cochise/logger.py`
- [JSON Run Logs](https://github.com/andreashappe/cochise/tree/main/logs): `logs`

### Run Analysis

- [Replay CLI](https://github.com/andreashappe/cochise/blob/main/src/cochise/cli/cochise_replay.py): `src/cochise/cli/cochise_replay.py`
- [Log Analysis CLI](https://github.com/andreashappe/cochise/blob/main/src/cochise/cli/analyze_json_logs.py): `src/cochise/cli/analyze_json_logs.py`
- [Graph Analysis CLI](https://github.com/andreashappe/cochise/blob/main/src/cochise/cli/analyze_json_graphs.py): `src/cochise/cli/analyze_json_graphs.py`
- [Run Log Parser](https://github.com/andreashappe/cochise/blob/main/src/cochise/analysis/common_analysis.py): `src/cochise/analysis/common_analysis.py`
- [Round Analysis](https://github.com/andreashappe/cochise/blob/main/src/cochise/analysis/index_rounds.py): `src/cochise/analysis/index_rounds.py`
- [Round Token Analysis](https://github.com/andreashappe/cochise/blob/main/src/cochise/analysis/index_rounds_and_tokens.py): `src/cochise/analysis/index_rounds_and_tokens.py`
- [Account Analysis](https://github.com/andreashappe/cochise/blob/main/src/cochise/analysis/index_tokens_and_accounts.py): `src/cochise/analysis/index_tokens_and_accounts.py`
- [Token Analysis](https://github.com/andreashappe/cochise/blob/main/src/cochise/analysis/show_tokens.py): `src/cochise/analysis/show_tokens.py`

### Other components

- **Operator**
- **LLM Provider**
- **Attacker VM**

## Connections

- Operator → Runtime CLI: starts run (evidence: `README.md`)
- Runtime CLI → Attack Scenario: loads scenario (evidence: `src/cochise/cli/cochise.py`)
- Runtime CLI → SSH Connection: configures SSH (evidence: `src/cochise/cli/cochise.py`)
- Runtime CLI → Executor Factory: creates factory (evidence: `src/cochise/cli/cochise.py`)
- Runtime CLI → Planner: starts planning (evidence: `src/cochise/cli/cochise.py`)
- Planner → LLM Interface: requests plans (evidence: `README.md`)
- Task Executor → LLM Interface: requests task calls (evidence: `src/cochise/executor.py`)
- LLM Interface → LLM Provider: sends LLM requests (evidence: `src/cochise/common.py`)
- Planner → Executor Factory: delegates tasks (evidence: `README.md`)
- Executor Factory → Task Executor: builds executor (evidence: `src/cochise/executor.py`)
- Task Executor → SSH Connection: invokes configured tools (evidence: `README.md`)
- SSH Connection → Attacker VM: executes commands (evidence: `README.md`)
- Planner → Knowledge Base: aggregates findings (evidence: `src/cochise/planner.py`)
- Task Executor → Knowledge Base: returns findings (evidence: `src/cochise/executor.py`)
- Runtime CLI → Run Logger: configures logging (evidence: `src/cochise/cli/cochise.py`)
- Run Logger → JSON Run Logs: writes events (evidence: `src/cochise/logger.py`)
- Operator → Replay CLI: replays run (evidence: `README.md`)
- Replay CLI → JSON Run Logs: reads run (evidence: `README.md`)
- Operator → Log Analysis CLI: analyzes runs (evidence: `README.md`)
- Log Analysis CLI → Round Analysis: dispatches analysis (evidence: `src/cochise/cli/analyze_json_logs.py`)
- Log Analysis CLI → Round Token Analysis: dispatches analysis (evidence: `src/cochise/cli/analyze_json_logs.py`)
- Log Analysis CLI → Account Analysis: dispatches analysis (evidence: `src/cochise/cli/analyze_json_logs.py`)
- Log Analysis CLI → Token Analysis: dispatches analysis (evidence: `src/cochise/cli/analyze_json_logs.py`)
- Round Analysis → Run Log Parser: parses run data (evidence: `src/cochise/analysis/index_rounds.py`)
- Round Token Analysis → Run Log Parser: parses run data (evidence: `src/cochise/analysis/index_rounds_and_tokens.py`)
- Account Analysis → Run Log Parser: parses run data (evidence: `src/cochise/analysis/index_tokens_and_accounts.py`)
- Token Analysis → Run Log Parser: parses run data (evidence: `src/cochise/analysis/show_tokens.py`)
- Operator → Graph Analysis CLI: graphs run metrics (evidence: `README.md`)
- Graph Analysis CLI → Run Log Parser: traverses run data (evidence: `src/cochise/cli/analyze_json_graphs.py`)
- Run Log Parser → JSON Run Logs: reads events (evidence: `src/cochise/analysis/common_analysis.py`)
