# rsi-gear/gear architecture

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

- Interactive diagram: https://gitdiagram.com/rsi-gear/gear
- Repository: https://github.com/rsi-gear/gear

## Overview

Gear is an agent-optimization framework: a user supplies a benchmark and target harness, then the Refine workflow evaluates the baseline, uses evaluation evidence to propose harness changes, and iterates toward an improved agent. The TypeScript refinement/search system is the principal workflow; Python gear_training and the TypeScript training modules provide a distinct model-training capability. The README supports the product-level flow, while source-index imports support only the cited internal links; several subsystem details are unsampled, so their relationships are intentionally limited.

Main entry points: [`src/refine/service.ts`](https://github.com/rsi-gear/gear/blob/main/src/refine/service.ts) (Refinement Service), [`src/search/engine.ts`](https://github.com/rsi-gear/gear/blob/main/src/search/engine.ts) (Evolution Search), [`python/gear_training/driver.py`](https://github.com/rsi-gear/gear/blob/main/python/gear_training/driver.py) (Training Runtime), [`src/state/store.ts`](https://github.com/rsi-gear/gear/blob/main/src/state/store.ts) (Refinement State)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_refine["Refinement Control"]
  node_skill["Refine Skill<br/>[SKILL.md]"]
  node_cli["Gear CLI<br/>[cli.ts]"]
  node_refine_service["Refinement Service<br/>[service.ts]"]
  node_meta["Meta-Agent Control<br/>[controller.ts]"]
  node_baseline["Baseline Sources<br/>[baseline-source.ts]"]
end

subgraph group_harness["Harness Evolution"]
  node_workspace["Candidate Workspace<br/>[workspace.ts]"]
  node_harness_builder["Harness Builder<br/>[builder.ts]"]
  node_components["Evolution Components<br/>[components.ts]"]
end

subgraph group_evaluation["Search and Evaluation"]
  node_search_engine["Evolution Search<br/>[engine.ts]"]
  node_search_contracts["Search Contracts<br/>[contracts.ts]"]
  node_evaluation_runner["Hitch Evaluator<br/>[hitch-cli.ts]"]
  node_objective["Objective Scoring<br/>[scoring.ts]"]
end

subgraph group_state["Durable State"]
  node_dataset["Benchmark Dataset<br/>[dataset.ts]"]
  node_state_store[("Refinement State<br/>[store.ts]")]
  node_storage["Storage Management<br/>[storage.ts]"]
end

subgraph group_training["Model Training"]
  node_python_training["Training Runtime<br/>[driver.py]"]
  node_training_preflight["Training Preflight<br/>[preflight.py]"]
  node_training_inference["Inference Process"]
  node_training_coordinator["Training Coordinator<br/>[coordinator.ts]"]
  node_training_control["Script Controller"]
end

node_user(("Benchmark Owner"))

node_user -->|"requests optimization"| node_skill
node_skill -->|"invokes Gear"| node_cli
node_cli -.->|"starts refinement"| node_refine_service
node_refine_service -->|"loads baseline"| node_baseline
node_refine_service -->|"coordinates proposals"| node_meta
node_refine_service -->|"manages candidates"| node_workspace
node_refine_service -->|"builds harness"| node_harness_builder
node_refine_service -->|"runs search"| node_search_engine
node_refine_service -->|"persists evolution"| node_state_store
node_search_engine -->|"registers strategies"| node_components
node_search_engine -->|"resolves sizing"| node_search_contracts
node_search_engine -.->|"evaluates candidates"| node_evaluation_runner
node_evaluation_runner -->|"reads benchmark"| node_dataset
node_search_engine -.->|"scores outcomes"| node_objective
node_state_store -->|"stores benchmark data"| node_dataset
node_storage -->|"audits stored state"| node_state_store
node_user -.->|"configures training"| node_python_training
node_python_training -.->|"checks readiness"| node_training_preflight
node_python_training -->|"starts inference"| node_training_inference
node_user -.->|"requests training"| node_training_coordinator
node_training_coordinator -.->|"controls script jobs"| node_training_control

click node_skill "https://github.com/rsi-gear/gear/blob/main/skills/refine/SKILL.md"
click node_cli "https://github.com/rsi-gear/gear/blob/main/src/cli.ts"
click node_refine_service "https://github.com/rsi-gear/gear/blob/main/src/refine/service.ts"
click node_meta "https://github.com/rsi-gear/gear/blob/main/src/meta/controller.ts"
click node_baseline "https://github.com/rsi-gear/gear/blob/main/src/refine/baseline-source.ts"
click node_workspace "https://github.com/rsi-gear/gear/blob/main/src/candidate/workspace.ts"
click node_harness_builder "https://github.com/rsi-gear/gear/blob/main/src/harness/builder.ts"
click node_components "https://github.com/rsi-gear/gear/blob/main/src/evolution/components.ts"
click node_search_engine "https://github.com/rsi-gear/gear/blob/main/src/search/engine.ts"
click node_search_contracts "https://github.com/rsi-gear/gear/blob/main/src/search/contracts.ts"
click node_evaluation_runner "https://github.com/rsi-gear/gear/blob/main/src/evaluator/hitch-cli.ts"
click node_objective "https://github.com/rsi-gear/gear/blob/main/src/objective/scoring.ts"
click node_dataset "https://github.com/rsi-gear/gear/blob/main/src/state/dataset.ts"
click node_state_store "https://github.com/rsi-gear/gear/blob/main/src/state/store.ts"
click node_storage "https://github.com/rsi-gear/gear/blob/main/src/state/storage.ts"
click node_python_training "https://github.com/rsi-gear/gear/blob/main/python/gear_training/driver.py"
click node_training_preflight "https://github.com/rsi-gear/gear/blob/main/python/gear_training/preflight.py"
click node_training_inference "https://github.com/rsi-gear/gear/blob/main/python/gear_training/inference_process.py"
click node_training_coordinator "https://github.com/rsi-gear/gear/blob/main/src/training/coordinator.ts"
click node_training_control "https://github.com/rsi-gear/gear/blob/main/src/training/script-controller.ts"

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_skill,node_cli,node_refine_service,node_meta,node_baseline toneBlue
class node_workspace,node_harness_builder,node_components toneAmber
class node_search_engine,node_search_contracts,node_evaluation_runner,node_objective toneMint
class node_dataset,node_state_store,node_storage toneRose
class node_python_training,node_training_preflight,node_training_inference,node_training_coordinator,node_training_control,node_user toneIndigo
```

## Components

### Refinement Control

- [Refine Skill](https://github.com/rsi-gear/gear/blob/main/skills/refine/SKILL.md): `skills/refine/SKILL.md`
- [Gear CLI](https://github.com/rsi-gear/gear/blob/main/src/cli.ts): `src/cli.ts`
- [Refinement Service](https://github.com/rsi-gear/gear/blob/main/src/refine/service.ts): `src/refine/service.ts`
- [Meta-Agent Control](https://github.com/rsi-gear/gear/blob/main/src/meta/controller.ts): `src/meta/controller.ts`
- [Baseline Sources](https://github.com/rsi-gear/gear/blob/main/src/refine/baseline-source.ts): `src/refine/baseline-source.ts`

### Harness Evolution

- [Candidate Workspace](https://github.com/rsi-gear/gear/blob/main/src/candidate/workspace.ts): `src/candidate/workspace.ts`
- [Harness Builder](https://github.com/rsi-gear/gear/blob/main/src/harness/builder.ts): `src/harness/builder.ts`
- [Evolution Components](https://github.com/rsi-gear/gear/blob/main/src/evolution/components.ts): `src/evolution/components.ts`

### Search and Evaluation

- [Evolution Search](https://github.com/rsi-gear/gear/blob/main/src/search/engine.ts): `src/search/engine.ts`
- [Search Contracts](https://github.com/rsi-gear/gear/blob/main/src/search/contracts.ts): `src/search/contracts.ts`
- [Hitch Evaluator](https://github.com/rsi-gear/gear/blob/main/src/evaluator/hitch-cli.ts): `src/evaluator/hitch-cli.ts`
- [Objective Scoring](https://github.com/rsi-gear/gear/blob/main/src/objective/scoring.ts): `src/objective/scoring.ts`

### Durable State

- [Benchmark Dataset](https://github.com/rsi-gear/gear/blob/main/src/state/dataset.ts): `src/state/dataset.ts`
- [Refinement State](https://github.com/rsi-gear/gear/blob/main/src/state/store.ts): `src/state/store.ts`
- [Storage Management](https://github.com/rsi-gear/gear/blob/main/src/state/storage.ts): `src/state/storage.ts`

### Model Training

- [Training Runtime](https://github.com/rsi-gear/gear/blob/main/python/gear_training/driver.py): `python/gear_training/driver.py`
- [Training Preflight](https://github.com/rsi-gear/gear/blob/main/python/gear_training/preflight.py): `python/gear_training/preflight.py`
- [Inference Process](https://github.com/rsi-gear/gear/blob/main/python/gear_training/inference_process.py): `python/gear_training/inference_process.py`
- [Training Coordinator](https://github.com/rsi-gear/gear/blob/main/src/training/coordinator.ts): `src/training/coordinator.ts`
- [Script Controller](https://github.com/rsi-gear/gear/blob/main/src/training/script-controller.ts): `src/training/script-controller.ts`

### Other components

- **Benchmark Owner**

## Connections

- Benchmark Owner → Refine Skill: requests optimization (evidence: `README.md`)
- Refine Skill → Gear CLI: invokes Gear (evidence: `README.md`)
- Gear CLI → Refinement Service: starts refinement
- Refinement Service → Baseline Sources: loads baseline (evidence: `src/refine/service.ts`)
- Refinement Service → Meta-Agent Control: coordinates proposals (evidence: `src/refine/service.ts`)
- Refinement Service → Candidate Workspace: manages candidates (evidence: `src/refine/service.ts`)
- Refinement Service → Harness Builder: builds harness (evidence: `src/refine/service.ts`)
- Refinement Service → Evolution Search: runs search (evidence: `src/refine/service.ts`)
- Refinement Service → Refinement State: persists evolution (evidence: `src/refine/service.ts`)
- Evolution Search → Evolution Components: registers strategies (evidence: `src/search/engine.ts`)
- Evolution Search → Search Contracts: resolves sizing (evidence: `src/search/engine.ts`)
- Evolution Search → Hitch Evaluator: evaluates candidates
- Hitch Evaluator → Benchmark Dataset: reads benchmark (evidence: `src/evaluator/hitch-cli.ts`)
- Evolution Search → Objective Scoring: scores outcomes (evidence: `src/search/engine.ts`)
- Refinement State → Benchmark Dataset: stores benchmark data (evidence: `src/state/storage.ts`)
- Storage Management → Refinement State: audits stored state (evidence: `src/state/storage.ts`)
- Benchmark Owner → Training Runtime: configures training
- Training Runtime → Training Preflight: checks readiness
- Training Runtime → Inference Process: starts inference (evidence: `python/gear_training/inference_process.py`)
- Benchmark Owner → Training Coordinator: requests training
- Training Coordinator → Script Controller: controls script jobs
