# gastownhall/gascity architecture

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

- Interactive diagram: https://gitdiagram.com/gastownhall/gascity
- Repository: https://github.com/gastownhall/gascity
- Video tour (about a minute): https://gitdiagram.com/gastownhall/gascity/video

## Overview

#### Purpose and Entry Points
Gas City is a Go-based orchestration toolkit for multi-agent coding workflows. The primary executable is `gc`, whose root command wires CLI commands, city discovery, configuration, storage, runtimes, and controller behavior. `gc init` scaffolds a city; `gc start` launches its control plane; operational commands manage rigs, work, sessions, formulas, orders, and services.
- `cmd/gc/main.go`
- `cmd/gc/cmd_commands.go`
- `cmd/gc/cmd_start.go`

#### City Configuration, Packs, and Scoping
A city is declaratively configured through `city.toml`; configuration composition resolves packs, imports, overlays, provider definitions, storage bindings, agents, named sessions, and rig-specific overrides. Packs are both a distribution boundary and an extensibility mechanism: the embedded core pack supplies default agents, formulas, orders, scripts, skills, and provider overlays.
- `internal/config/config.go`
- `internal/config/compose.go`
- `internal/bootstrap/packs/core/pack.toml`

#### Storage and Work Model
“Beads” are the durable work/coordination records underlying work tracking, mail, convoys, waits, and workflow graphs. The store abstraction supports multiple backends, notably the default external `bd`/Dolt path, native Dolt, SQLite, file, and memory implementations. Store binding resolves which backend serves each storage class and protects migrations/lifecycle transitions; this is a major boundary between orchestration logic and persistence.
- `internal/beads/beads.go`
- `internal/beads/factory.go`
- `internal/storebinding/storebinding.go`

#### Controller Reconciliation and Dispatch
The controller continuously reconciles configured and observed state into desired pools/sessions. It computes demand, creates or wakes capacity, routes ready work, tracks assignments, and repairs drift or failed ownership. Dispatch turns bead/workflow graph state into runnable work and supports retry, drain, fanout, and control-routing semantics. Conditional writes, residency, and store fences protect cross-process and cross-store ownership.
- `cmd/gc/controller.go`
- `cmd/gc/build_desired_state.go`
- `cmd/gc/session_reconciler.go`
- `internal/dispatch/runtime.go`

#### Sessions, Workers, and Runtime Providers
Sessions are the lifecycle unit for an agent invocation: identity, persisted state, waits, chat/submission, transcript metadata, and transitions are handled independently of a concrete runtime. Worker handles normalize agent operations and observation. The runtime interface permits the same orchestration layer to launch or control tmux, local subprocess/exec, ACP, Kubernetes, SSH, hybrid, T3 bridge, or herdr providers. tmux remains the default/fallback runtime.
- `internal/session/manager.go`
- `internal/worker/handle.go`
- `internal/runtime/runtime.go`
- `internal/runtime/tmux/tmux.go`
- `internal/runtime/k8s/provider.go`

#### Workflow Compilation and Scheduled Automation
Formulas define reusable multi-step workflows and compile into graph-shaped molecule/work records. The convergence subsystem runs bounded iterative refinement and gates over those workflows. Orders are separately parsed periodic or event-triggered automation definitions; their dispatcher evaluates triggers and launches actions through the same control/runtime boundaries.
- `internal/formula/compile.go`
- `internal/molecule/molecule.go`
- `internal/convergence/reconcile.go`
- `internal/orders/triggers.go`

#### Supervisor, API, Observability, and Integrations
A supervisor manages city-level service lifecycle, publishes status, and can host the HTTP control API and embedded dashboard. The API exposes typed resources for cities, sessions, agents, beads, runs, events, mail, rigs, and operational actions; SSE supports live streams. Events provide durable observability, while external-message and webhook modules connect outside systems. Optional infrastructure includes managed Dolt, Git/GitHub, MCP mail, Docker, and Kubernetes manifests.
- `internal/supervisor/registry.go`
- `internal/api/server.go`
- `internal/api/dashboardspa/embed.go`
- `internal/events/events.go`
- `internal/extmsg/services.go`

Main entry points: [`cmd/gc/controller.go`](https://github.com/gastownhall/gascity/blob/main/cmd/gc/controller.go) (Controller reconciler), [`internal/config/compose.go`](https://github.com/gastownhall/gascity/blob/main/internal/config/compose.go) (City configuration), [`internal/beads/beads.go`](https://github.com/gastownhall/gascity/blob/main/internal/beads/beads.go) (Beads work records), [`cmd/gc/main.go`](https://github.com/gastownhall/gascity/blob/main/cmd/gc/main.go) (gc command)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI and bootstrap"]
  node_gc["gc command<br/>Go CLI<br/>[main.go]"]
  node_commands["Operational commands<br/>CLI commands<br/>[cmd_commands.go]"]
  node_start["gc start<br/>control-plane launch<br/>[cmd_start.go]"]
end

subgraph group_config["Configuration"]
  node_city_config["City configuration<br/>TOML model<br/>[compose.go]"]
  node_core_pack["Embedded core pack<br/>default pack<br/>[pack.toml]"]
end

subgraph group_control["Control plane"]
  node_store_binding[("Store binding<br/>persistence boundary<br/>[storebinding.go]")]
  node_beads[("Beads work records<br/>durable work model<br/>[beads.go]")]
  node_store_factory["Store backends<br/>backend factory<br/>[factory.go]"]
  node_controller{{"Controller reconciler<br/>desired-state control<br/>[controller.go]"}}
  node_dispatch["Work dispatch<br/>dispatch runtime<br/>[runtime.go]"]
end

subgraph group_execution["Execution"]
  node_sessions["Session manager<br/>session lifecycle<br/>[manager.go]"]
  node_worker_handle["Worker handles<br/>agent adapter<br/>[handle.go]"]
  node_runtime["Runtime providers<br/>runtime interface<br/>[runtime.go]"]
  node_tmux["tmux runtime<br/>default runtime<br/>[tmux.go]"]
end

subgraph group_operations["Automation and operations"]
  node_formulas["Formula compiler<br/>workflow compiler<br/>[compile.go]"]
  node_convergence["Convergence reconciler<br/>iterative workflow control<br/>[reconcile.go]"]
  node_orders["Orders dispatcher<br/>scheduled automation<br/>[triggers.go]"]
  node_supervisor{{"City supervisor<br/>service lifecycle<br/>[registry.go]"}}
  node_api["HTTP API and dashboard<br/>control API<br/>[server.go]"]
  node_events["Durable events<br/>observability<br/>[events.go]"]
  node_external_messages["External messaging<br/>integration services<br/>[services.go]"]
end

node_gc -->|"registers"| node_commands
node_gc -->|"launch command"| node_start
node_gc -->|"discovers city"| node_city_config
node_city_config -->|"resolves packs"| node_core_pack
node_start -->|"starts"| node_controller
node_city_config -->|"desired inputs"| node_controller
node_city_config -->|"storage bindings"| node_store_binding
node_store_binding -->|"selects backend"| node_store_factory
node_store_binding -->|"persists through"| node_beads
node_controller -->|"reconciles work"| node_beads
node_controller -->|"routes ready work"| node_dispatch
node_dispatch -->|"creates or wakes"| node_sessions
node_sessions -->|"manages"| node_worker_handle
node_worker_handle -->|"normalizes provider"| node_runtime
node_runtime -.->|"default/fallback"| node_tmux
node_formulas -->|"compiles workflows"| node_beads
node_convergence -->|"gates iterations"| node_formulas
node_orders -->|"launches actions"| node_dispatch
node_supervisor -->|"hosts"| node_api
node_supervisor -->|"manages service"| node_controller
node_controller -->|"emits lifecycle events"| node_events
node_api -->|"operates sessions"| node_sessions
node_external_messages -->|"integrates coordination"| node_beads

click node_gc "https://github.com/gastownhall/gascity/blob/main/cmd/gc/main.go"
click node_commands "https://github.com/gastownhall/gascity/blob/main/cmd/gc/cmd_commands.go"
click node_start "https://github.com/gastownhall/gascity/blob/main/cmd/gc/cmd_start.go"
click node_city_config "https://github.com/gastownhall/gascity/blob/main/internal/config/compose.go"
click node_core_pack "https://github.com/gastownhall/gascity/blob/main/internal/bootstrap/packs/core/pack.toml"
click node_store_binding "https://github.com/gastownhall/gascity/blob/main/internal/storebinding/storebinding.go"
click node_beads "https://github.com/gastownhall/gascity/blob/main/internal/beads/beads.go"
click node_store_factory "https://github.com/gastownhall/gascity/blob/main/internal/beads/factory.go"
click node_controller "https://github.com/gastownhall/gascity/blob/main/cmd/gc/controller.go"
click node_dispatch "https://github.com/gastownhall/gascity/blob/main/internal/dispatch/runtime.go"
click node_sessions "https://github.com/gastownhall/gascity/blob/main/internal/session/manager.go"
click node_worker_handle "https://github.com/gastownhall/gascity/blob/main/internal/worker/handle.go"
click node_runtime "https://github.com/gastownhall/gascity/blob/main/internal/runtime/runtime.go"
click node_tmux "https://github.com/gastownhall/gascity/blob/main/internal/runtime/tmux/tmux.go"
click node_formulas "https://github.com/gastownhall/gascity/blob/main/internal/formula/compile.go"
click node_convergence "https://github.com/gastownhall/gascity/blob/main/internal/convergence/reconcile.go"
click node_orders "https://github.com/gastownhall/gascity/blob/main/internal/orders/triggers.go"
click node_supervisor "https://github.com/gastownhall/gascity/blob/main/internal/supervisor/registry.go"
click node_api "https://github.com/gastownhall/gascity/blob/main/internal/api/server.go"
click node_events "https://github.com/gastownhall/gascity/blob/main/internal/events/events.go"
click node_external_messages "https://github.com/gastownhall/gascity/blob/main/internal/extmsg/services.go"

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_gc,node_commands,node_start toneBlue
class node_city_config,node_core_pack toneAmber
class node_store_binding,node_beads,node_store_factory,node_controller,node_dispatch toneMint
class node_sessions,node_worker_handle,node_runtime,node_tmux toneRose
class node_formulas,node_convergence,node_orders,node_supervisor,node_api,node_events,node_external_messages toneIndigo
```

## Components

### CLI and bootstrap

- [gc command](https://github.com/gastownhall/gascity/blob/main/cmd/gc/main.go): Go CLI · Root command and operational entry point. · `cmd/gc/main.go`
- [Operational commands](https://github.com/gastownhall/gascity/blob/main/cmd/gc/cmd_commands.go): CLI commands · `cmd/gc/cmd_commands.go`
- [gc start](https://github.com/gastownhall/gascity/blob/main/cmd/gc/cmd_start.go): control-plane launch · `cmd/gc/cmd_start.go`

### Configuration

- [City configuration](https://github.com/gastownhall/gascity/blob/main/internal/config/compose.go): TOML model · Composes imports, overlays, providers, storage, agents, and rigs. · `internal/config/compose.go`
- [Embedded core pack](https://github.com/gastownhall/gascity/blob/main/internal/bootstrap/packs/core/pack.toml): default pack · Supplies default agents, formulas, orders, scripts, and overlays. · `internal/bootstrap/packs/core/pack.toml`

### Control plane

- [Store binding](https://github.com/gastownhall/gascity/blob/main/internal/storebinding/storebinding.go): persistence boundary · Selects storage backends and protects lifecycle transitions. · `internal/storebinding/storebinding.go`
- [Beads work records](https://github.com/gastownhall/gascity/blob/main/internal/beads/beads.go): durable work model · Tracks work, coordination, mail, convoys, waits, and workflow graphs. · `internal/beads/beads.go`
- [Store backends](https://github.com/gastownhall/gascity/blob/main/internal/beads/factory.go): backend factory · Supports bd/Dolt, native Dolt, SQLite, file, and memory stores. · `internal/beads/factory.go`
- [Controller reconciler](https://github.com/gastownhall/gascity/blob/main/cmd/gc/controller.go): desired-state control · Reconciles capacity, assignments, routing, and ownership drift. · `cmd/gc/controller.go`
- [Work dispatch](https://github.com/gastownhall/gascity/blob/main/internal/dispatch/runtime.go): dispatch runtime · Turns ready work into runnable assignments with retry and drain semantics. · `internal/dispatch/runtime.go`

### Execution

- [Session manager](https://github.com/gastownhall/gascity/blob/main/internal/session/manager.go): session lifecycle · Persists invocation state, waits, chat, submissions, and transitions. · `internal/session/manager.go`
- [Worker handles](https://github.com/gastownhall/gascity/blob/main/internal/worker/handle.go): agent adapter · Normalizes agent operations and observation. · `internal/worker/handle.go`
- [Runtime providers](https://github.com/gastownhall/gascity/blob/main/internal/runtime/runtime.go): runtime interface · Launches or controls tmux, exec, ACP, Kubernetes, SSH, hybrid, T3, and herdr. · `internal/runtime/runtime.go`
- [tmux runtime](https://github.com/gastownhall/gascity/blob/main/internal/runtime/tmux/tmux.go): default runtime · `internal/runtime/tmux/tmux.go`

### Automation and operations

- [Formula compiler](https://github.com/gastownhall/gascity/blob/main/internal/formula/compile.go): workflow compiler · Compiles reusable formulas into graph-shaped work records. · `internal/formula/compile.go`
- [Convergence reconciler](https://github.com/gastownhall/gascity/blob/main/internal/convergence/reconcile.go): iterative workflow control · Runs bounded refinement and gates workflow progress. · `internal/convergence/reconcile.go`
- [Orders dispatcher](https://github.com/gastownhall/gascity/blob/main/internal/orders/triggers.go): scheduled automation · Evaluates periodic or event triggers and launches actions. · `internal/orders/triggers.go`
- [City supervisor](https://github.com/gastownhall/gascity/blob/main/internal/supervisor/registry.go): service lifecycle · Manages city services and publishes status. · `internal/supervisor/registry.go`
- [HTTP API and dashboard](https://github.com/gastownhall/gascity/blob/main/internal/api/server.go): control API · Provides typed resources, operational actions, SSE, and embedded dashboard. · `internal/api/server.go`
- [Durable events](https://github.com/gastownhall/gascity/blob/main/internal/events/events.go): observability · `internal/events/events.go`
- [External messaging](https://github.com/gastownhall/gascity/blob/main/internal/extmsg/services.go): integration services · Connects webhooks and outside message systems. · `internal/extmsg/services.go`

## Connections

- gc command → Operational commands: registers
- gc command → gc start: launch command
- gc command → City configuration: discovers city
- City configuration → Embedded core pack: resolves packs
- gc start → Controller reconciler: starts
- City configuration → Controller reconciler: desired inputs
- City configuration → Store binding: storage bindings
- Store binding → Store backends: selects backend
- Store binding → Beads work records: persists through
- Controller reconciler → Beads work records: reconciles work
- Controller reconciler → Work dispatch: routes ready work
- Work dispatch → Session manager: creates or wakes
- Session manager → Worker handles: manages
- Worker handles → Runtime providers: normalizes provider
- Runtime providers → tmux runtime: default/fallback
- Formula compiler → Beads work records: compiles workflows
- Convergence reconciler → Formula compiler: gates iterations
- Orders dispatcher → Work dispatch: launches actions
- City supervisor → HTTP API and dashboard: hosts
- City supervisor → Controller reconciler: manages service
- Controller reconciler → Durable events: emits lifecycle events
- HTTP API and dashboard → Session manager: operates sessions
- External messaging → Beads work records: integrates coordination
