config

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package config provides configuration types and serialization for Gas Town.

Package config provides configuration types and serialization for Gas Town.

Index

Constants

View Source
const (
	OnConflictAssignBack = "assign_back"
	OnConflictAutoRebase = "auto_rebase"
)

OnConflict strategy constants.

View Source
const CurrentAccountsVersion = 1

CurrentAccountsVersion is the current schema version for AccountsConfig.

View Source
const CurrentAgentRegistryVersion = 1

CurrentAgentRegistryVersion is the current schema version.

View Source
const CurrentDaemonPatrolConfigVersion = 1

CurrentDaemonPatrolConfigVersion is the current schema version for DaemonPatrolConfig.

View Source
const CurrentMayorConfigVersion = 1

CurrentMayorConfigVersion is the current schema version for MayorConfig.

View Source
const CurrentMessagingVersion = 1

CurrentMessagingVersion is the current schema version for MessagingConfig.

View Source
const CurrentOverseerVersion = 1

CurrentOverseerVersion is the current schema version for OverseerConfig.

View Source
const CurrentRigConfigVersion = 1

CurrentRigConfigVersion is the current schema version for RigConfig.

View Source
const CurrentRigSettingsVersion = 1

CurrentRigSettingsVersion is the current schema version for RigSettings.

View Source
const CurrentRigsVersion = 1

CurrentRigsVersion is the current schema version for RigsConfig.

View Source
const CurrentTownSettingsVersion = 1

CurrentTownSettingsVersion is the current schema version for TownSettings.

View Source
const CurrentTownVersion = 2

CurrentTownVersion is the current schema version for TownConfig. Version 2: Added Owner and PublicName fields for federation identity.

View Source
const DaemonPatrolConfigFileName = "daemon.json"

DaemonPatrolConfigFileName is the filename for daemon patrol configuration.

View Source
const DefaultCrewName = "max"

DefaultCrewName is the default name for crew workspaces when not overridden.

Variables

View Source
var (
	// ErrNotFound indicates the config file does not exist.
	ErrNotFound = errors.New("config file not found")

	// ErrInvalidVersion indicates an unsupported schema version.
	ErrInvalidVersion = errors.New("unsupported config version")

	// ErrInvalidType indicates an unexpected config type.
	ErrInvalidType = errors.New("invalid config type")

	// ErrMissingField indicates a required field is missing.
	ErrMissingField = errors.New("missing required field")
)
View Source
var ErrInvalidOnConflict = errors.New("invalid on_conflict strategy")

ErrInvalidOnConflict indicates an invalid on_conflict strategy.

Functions

func BuildAgentStartupCommand

func BuildAgentStartupCommand(role, bdActor, rigPath, prompt string) string

BuildAgentStartupCommand is a convenience function for starting agent sessions. It sets standard environment variables (GT_ROLE, BD_ACTOR, GIT_AUTHOR_NAME) and builds the full startup command.

func BuildAgentStartupCommandWithAgentOverride

func BuildAgentStartupCommandWithAgentOverride(role, bdActor, rigPath, prompt, agentOverride string) (string, error)

BuildAgentStartupCommandWithAgentOverride is like BuildAgentStartupCommand, but uses agentOverride if non-empty.

func BuildCrewStartupCommand

func BuildCrewStartupCommand(rigName, crewName, rigPath, prompt string) string

BuildCrewStartupCommand builds the startup command for a crew member. Sets GT_ROLE, GT_RIG, GT_CREW, BD_ACTOR, and GIT_AUTHOR_NAME.

func BuildCrewStartupCommandWithAgentOverride

func BuildCrewStartupCommandWithAgentOverride(rigName, crewName, rigPath, prompt, agentOverride string) (string, error)

BuildCrewStartupCommandWithAgentOverride is like BuildCrewStartupCommand, but uses agentOverride if non-empty.

func BuildPolecatStartupCommand

func BuildPolecatStartupCommand(rigName, polecatName, rigPath, prompt string) string

BuildPolecatStartupCommand builds the startup command for a polecat. Sets GT_ROLE, GT_RIG, GT_POLECAT, BD_ACTOR, and GIT_AUTHOR_NAME.

func BuildPolecatStartupCommandWithAgentOverride

func BuildPolecatStartupCommandWithAgentOverride(rigName, polecatName, rigPath, prompt, agentOverride string) (string, error)

BuildPolecatStartupCommandWithAgentOverride is like BuildPolecatStartupCommand, but uses agentOverride if non-empty.

func BuildResumeCommand

func BuildResumeCommand(agentName, sessionID string) string

BuildResumeCommand builds a command to resume an agent session. Returns the full command string including any YOLO/autonomous flags. If sessionID is empty or the agent doesn't support resume, returns empty string.

func BuildStartupCommand

func BuildStartupCommand(envVars map[string]string, rigPath, prompt string) string

BuildStartupCommand builds a full startup command with environment exports. envVars is a map of environment variable names to values. rigPath is optional - if empty, tries to detect town root from cwd. prompt is optional - if provided, appended as the initial prompt.

func BuildStartupCommandWithAgentOverride

func BuildStartupCommandWithAgentOverride(envVars map[string]string, rigPath, prompt, agentOverride string) (string, error)

BuildStartupCommandWithAgentOverride builds a startup command like BuildStartupCommand, but uses agentOverride if non-empty.

func BuiltinRoleThemes

func BuiltinRoleThemes() map[string]string

BuiltinRoleThemes returns the default themes for each role. These are used when no explicit configuration is provided.

func DaemonPatrolConfigPath

func DaemonPatrolConfigPath(townRoot string) string

DaemonPatrolConfigPath returns the path to the daemon patrol config file.

func DefaultAccountsConfigDir

func DefaultAccountsConfigDir() string

DefaultAccountsConfigDir returns the default base directory for account configs.

func DefaultAgentRegistryPath

func DefaultAgentRegistryPath(townRoot string) string

DefaultAgentRegistryPath returns the default path for agent registry. Located alongside other town settings.

func EnsureDaemonPatrolConfig

func EnsureDaemonPatrolConfig(townRoot string) error

EnsureDaemonPatrolConfig creates the daemon patrol config if it doesn't exist.

func ExpectedPaneCommands

func ExpectedPaneCommands(rc *RuntimeConfig) []string

ExpectedPaneCommands returns tmux pane command names that indicate the runtime is running. For example, cursor-agent runs as "node", while most other runtimes report their executable name.

func GetProcessNames

func GetProcessNames(agentName string) []string

GetProcessNames returns the process names used to detect if an agent is running. Used by tmux.IsAgentRunning to check pane_current_command. Returns ["node"] (default) if agent is not found or has no ProcessNames.

func GetRigPrefix

func GetRigPrefix(townRoot, rigName string) string

GetRigPrefix returns the beads prefix for a rig from rigs.json. Falls back to "gt" if the rig isn't found or has no prefix configured. townRoot is the path to the town directory (e.g., ~/gt).

func GetRuntimeCommand

func GetRuntimeCommand(rigPath string) string

GetRuntimeCommand is a convenience function that returns the full command string for starting an LLM session. It resolves the agent config and builds the command.

func GetRuntimeCommandWithAgentOverride

func GetRuntimeCommandWithAgentOverride(rigPath, agentOverride string) (string, error)

GetRuntimeCommandWithAgentOverride returns the full command for starting an LLM session, using agentOverride if non-empty.

func GetRuntimeCommandWithPrompt

func GetRuntimeCommandWithPrompt(rigPath, prompt string) string

GetRuntimeCommandWithPrompt returns the full command with an initial prompt.

func GetRuntimeCommandWithPromptAndAgentOverride

func GetRuntimeCommandWithPromptAndAgentOverride(rigPath, prompt, agentOverride string) (string, error)

GetRuntimeCommandWithPromptAndAgentOverride returns the full command with an initial prompt, using agentOverride if non-empty.

func GetSessionIDEnvVar

func GetSessionIDEnvVar(agentName string) string

GetSessionIDEnvVar returns the environment variable name for storing session IDs for a given agent. Returns empty string if the agent doesn't use env vars for this.

func IsKnownPreset

func IsKnownPreset(name string) bool

IsKnownPreset checks if a string is a known agent preset name.

func ListAgentPresets

func ListAgentPresets() []string

ListAgentPresets returns all known agent preset names.

func LoadAgentRegistry

func LoadAgentRegistry(path string) error

LoadAgentRegistry loads agent definitions from a JSON file and merges with built-ins. User-defined agents override built-in presets with the same name. This function caches loaded paths to avoid redundant file reads.

func MessagingConfigPath

func MessagingConfigPath(townRoot string) string

MessagingConfigPath returns the standard path for messaging config in a town.

func OverseerConfigPath

func OverseerConfigPath(townRoot string) string

OverseerConfigPath returns the standard path for overseer config in a town.

func ResetRegistryForTesting

func ResetRegistryForTesting()

ResetRegistryForTesting clears all registry state. This is intended for use in tests only to ensure test isolation.

func ResolveAccountConfigDir

func ResolveAccountConfigDir(accountsPath, accountFlag string) (configDir, handle string, err error)

ResolveAccountConfigDir resolves the CURSOR_CONFIG_DIR for account selection. Priority order:

  1. GT_ACCOUNT environment variable
  2. accountFlag (from --account command flag)
  3. Default account from config

Returns empty string if no account configured or resolved. Returns the handle that was resolved as second value.

func RigSettingsPath

func RigSettingsPath(rigPath string) string

RigSettingsPath returns the path to rig settings file.

func SaveAccountsConfig

func SaveAccountsConfig(path string, config *AccountsConfig) error

SaveAccountsConfig saves an accounts configuration to a file.

func SaveAgentRegistry

func SaveAgentRegistry(path string, registry *AgentRegistry) error

SaveAgentRegistry writes the agent registry to a file.

func SaveDaemonPatrolConfig

func SaveDaemonPatrolConfig(path string, config *DaemonPatrolConfig) error

SaveDaemonPatrolConfig saves a daemon patrol config to a file.

func SaveMayorConfig

func SaveMayorConfig(path string, config *MayorConfig) error

SaveMayorConfig saves a mayor config to a file.

func SaveMessagingConfig

func SaveMessagingConfig(path string, config *MessagingConfig) error

SaveMessagingConfig saves a messaging configuration to a file.

func SaveOverseerConfig

func SaveOverseerConfig(path string, config *OverseerConfig) error

SaveOverseerConfig saves an overseer configuration to a file.

func SaveRigConfig

func SaveRigConfig(path string, config *RigConfig) error

SaveRigConfig saves a rig configuration to a file.

func SaveRigSettings

func SaveRigSettings(path string, settings *RigSettings) error

SaveRigSettings saves rig settings to a file.

func SaveRigsConfig

func SaveRigsConfig(path string, config *RigsConfig) error

SaveRigsConfig saves a rigs registry to a file.

func SaveTownConfig

func SaveTownConfig(path string, config *TownConfig) error

SaveTownConfig saves a town configuration to a file.

func SaveTownSettings

func SaveTownSettings(path string, settings *TownSettings) error

SaveTownSettings saves town settings to a file.

func SupportsSessionResume

func SupportsSessionResume(agentName string) bool

SupportsSessionResume checks if an agent supports session resumption.

func TownSettingsPath

func TownSettingsPath(townRoot string) string

TownSettingsPath returns the path to town settings file.

Types

type Account

type Account struct {
	Email       string `json:"email"`                 // account email
	Description string `json:"description,omitempty"` // human description
	ConfigDir   string `json:"config_dir"`            // path to CURSOR_CONFIG_DIR
}

Account represents a single Cursor account.

type AccountsConfig

type AccountsConfig struct {
	Version  int                `json:"version"`  // schema version
	Accounts map[string]Account `json:"accounts"` // handle -> account details
	Default  string             `json:"default"`  // default account handle
}

AccountsConfig represents Cursor account configuration (mayor/accounts.json). This enables Gas Town to manage multiple Cursor accounts with easy switching.

func LoadAccountsConfig

func LoadAccountsConfig(path string) (*AccountsConfig, error)

LoadAccountsConfig loads and validates an accounts configuration file.

func NewAccountsConfig

func NewAccountsConfig() *AccountsConfig

NewAccountsConfig creates a new AccountsConfig with defaults.

func (*AccountsConfig) GetAccount

func (c *AccountsConfig) GetAccount(handle string) *Account

GetAccount returns an account by handle, or nil if not found.

func (*AccountsConfig) GetDefaultAccount

func (c *AccountsConfig) GetDefaultAccount() *Account

GetDefaultAccount returns the default account, or nil if not set.

type AgentPreset

type AgentPreset string

AgentPreset identifies a supported LLM agent runtime. These presets provide sensible defaults that can be overridden in config.

const (
	// AgentGemini is Gemini CLI.
	AgentGemini AgentPreset = "gemini"
	// AgentCodex is OpenAI Codex.
	AgentCodex AgentPreset = "codex"
	// AgentCursor is Cursor Agent.
	AgentCursor AgentPreset = "cursor"
	// AgentAuggie is Auggie CLI.
	AgentAuggie AgentPreset = "auggie"
	// AgentAmp is Sourcegraph AMP.
	AgentAmp AgentPreset = "amp"
)

Supported agent presets (built-in, E2E tested).

func DefaultAgentPreset

func DefaultAgentPreset() AgentPreset

DefaultAgentPreset returns the default agent preset (Cursor).

type AgentPresetInfo

type AgentPresetInfo struct {
	// Name is the preset identifier (e.g., "gemini", "codex", "cursor", "auggie", "amp").
	Name AgentPreset `json:"name"`

	// Command is the CLI binary to invoke.
	Command string `json:"command"`

	// Args are the default command-line arguments for autonomous mode.
	Args []string `json:"args"`

	// ProcessNames are the process names to look for when detecting if the agent is running.
	// Used by tmux.IsAgentRunning to check pane_current_command.
	// E.g., ["cursor-agent"] for Cursor, ["codex"] for Codex.
	ProcessNames []string `json:"process_names,omitempty"`

	// SessionIDEnv is the environment variable for session ID.
	// Used for resuming sessions across restarts.
	SessionIDEnv string `json:"session_id_env,omitempty"`

	// ResumeFlag is the flag/subcommand for resuming sessions.
	// For gemini: "--resume"
	// For codex: "resume" (subcommand)
	ResumeFlag string `json:"resume_flag,omitempty"`

	// ResumeStyle indicates how to invoke resume:
	// "flag" - pass as --resume <id> argument
	// "subcommand" - pass as 'codex resume <id>'
	ResumeStyle string `json:"resume_style,omitempty"`

	// SupportsHooks indicates if the agent supports hooks system.
	SupportsHooks bool `json:"supports_hooks,omitempty"`

	// SupportsForkSession indicates if --fork-session is available.
	SupportsForkSession bool `json:"supports_fork_session,omitempty"`

	// NonInteractive contains settings for non-interactive mode.
	NonInteractive *NonInteractiveConfig `json:"non_interactive,omitempty"`
}

AgentPresetInfo contains the configuration details for an agent preset. This extends the basic RuntimeConfig with agent-specific metadata.

func GetAgentPreset

func GetAgentPreset(name AgentPreset) *AgentPresetInfo

GetAgentPreset returns the preset info for a given agent name. Returns nil if the preset is not found.

func GetAgentPresetByName

func GetAgentPresetByName(name string) *AgentPresetInfo

GetAgentPresetByName returns the preset info by string name. Returns nil if not found, allowing caller to fall back to defaults.

type AgentRegistry

type AgentRegistry struct {
	// Version is the schema version for the registry.
	Version int `json:"version"`

	// Agents maps agent names to their configurations.
	Agents map[string]*AgentPresetInfo `json:"agents"`
}

AgentRegistry contains all known agent presets. Can be loaded from JSON config or use built-in defaults.

func NewExampleAgentRegistry

func NewExampleAgentRegistry() *AgentRegistry

NewExampleAgentRegistry creates an example registry with comments.

type AnnounceConfig

type AnnounceConfig struct {
	// Readers lists addresses eligible to read from this announce channel.
	// Supports @group syntax: "@town", "@rig/gastown", "@witnesses".
	Readers []string `json:"readers"`

	// RetainCount is the number of messages to retain (0 = unlimited).
	RetainCount int `json:"retain_count,omitempty"`
}

AnnounceConfig represents a bulletin board configuration.

type BeadsConfig

type BeadsConfig struct {
	Repo   string `json:"repo"`   // "local" | path | git-url
	Prefix string `json:"prefix"` // issue prefix
}

BeadsConfig represents beads configuration for a rig.

type CrewConfig

type CrewConfig struct {
	// Startup is a natural language instruction for which crew to start on boot.
	// Interpreted by AI during startup. Examples:
	//   "max"                    - start only max
	//   "joe and max"            - start joe and max
	//   "all"                    - start all crew members
	//   "pick one"               - start any one crew member
	//   "none"                   - don't auto-start any crew
	//   "max, but not emma"      - start max, skip emma
	// If empty, defaults to starting no crew automatically.
	Startup string `json:"startup,omitempty"`
}

CrewConfig represents crew workspace settings for a rig.

type CustomTheme

type CustomTheme struct {
	BG string `json:"bg"` // Background color (hex or tmux color name)
	FG string `json:"fg"` // Foreground color (hex or tmux color name)
}

CustomTheme allows specifying exact colors for the status bar.

type DaemonConfig

type DaemonConfig struct {
	HeartbeatInterval string `json:"heartbeat_interval,omitempty"` // e.g., "30s"
	PollInterval      string `json:"poll_interval,omitempty"`      // e.g., "10s"
}

DaemonConfig represents daemon process settings.

type DaemonPatrolConfig

type DaemonPatrolConfig struct {
	Type      string                  `json:"type"`                // "daemon-patrol-config"
	Version   int                     `json:"version"`             // schema version
	Heartbeat *HeartbeatConfig        `json:"heartbeat,omitempty"` // heartbeat settings
	Patrols   map[string]PatrolConfig `json:"patrols,omitempty"`   // named patrol configurations
}

DaemonPatrolConfig represents the daemon patrol configuration (mayor/daemon.json). This configures how patrols are triggered and managed.

func LoadDaemonPatrolConfig

func LoadDaemonPatrolConfig(path string) (*DaemonPatrolConfig, error)

LoadDaemonPatrolConfig loads and validates a daemon patrol config file.

func NewDaemonPatrolConfig

func NewDaemonPatrolConfig() *DaemonPatrolConfig

NewDaemonPatrolConfig creates a new DaemonPatrolConfig with sensible defaults.

type DeaconConfig

type DeaconConfig struct {
	PatrolInterval string `json:"patrol_interval,omitempty"` // e.g., "5m"
}

DeaconConfig represents deacon process settings.

type HeartbeatConfig

type HeartbeatConfig struct {
	Enabled  bool   `json:"enabled"`            // whether heartbeat is enabled
	Interval string `json:"interval,omitempty"` // e.g., "3m"
}

HeartbeatConfig represents heartbeat settings for daemon.

type MayorConfig

type MayorConfig struct {
	Type            string           `json:"type"`                        // "mayor-config"
	Version         int              `json:"version"`                     // schema version
	Theme           *TownThemeConfig `json:"theme,omitempty"`             // global theme settings
	Daemon          *DaemonConfig    `json:"daemon,omitempty"`            // daemon settings
	Deacon          *DeaconConfig    `json:"deacon,omitempty"`            // deacon settings
	DefaultCrewName string           `json:"default_crew_name,omitempty"` // default crew name for new rigs
}

MayorConfig represents town-level behavioral configuration (mayor/config.json). This is separate from TownConfig (identity) to keep configuration concerns distinct.

func LoadMayorConfig

func LoadMayorConfig(path string) (*MayorConfig, error)

LoadMayorConfig loads and validates a mayor config file.

func NewMayorConfig

func NewMayorConfig() *MayorConfig

NewMayorConfig creates a new MayorConfig with defaults.

type MergeQueueConfig

type MergeQueueConfig struct {
	// Enabled controls whether the merge queue is active.
	Enabled bool `json:"enabled"`

	// TargetBranch is the default branch to merge into (usually "main").
	TargetBranch string `json:"target_branch"`

	// IntegrationBranches enables integration branch workflow for epics.
	IntegrationBranches bool `json:"integration_branches"`

	// OnConflict specifies conflict resolution strategy: "assign_back" or "auto_rebase".
	OnConflict string `json:"on_conflict"`

	// RunTests controls whether to run tests before merging.
	RunTests bool `json:"run_tests"`

	// TestCommand is the command to run for tests.
	TestCommand string `json:"test_command,omitempty"`

	// DeleteMergedBranches controls whether to delete branches after merging.
	DeleteMergedBranches bool `json:"delete_merged_branches"`

	// RetryFlakyTests is the number of times to retry flaky tests.
	RetryFlakyTests int `json:"retry_flaky_tests"`

	// PollInterval is how often to poll for new merge requests (e.g., "30s").
	PollInterval string `json:"poll_interval"`

	// MaxConcurrent is the maximum number of concurrent merges.
	MaxConcurrent int `json:"max_concurrent"`
}

MergeQueueConfig represents merge queue settings for a rig.

func DefaultMergeQueueConfig

func DefaultMergeQueueConfig() *MergeQueueConfig

DefaultMergeQueueConfig returns a MergeQueueConfig with sensible defaults.

type MessagingConfig

type MessagingConfig struct {
	Type    string `json:"type"`    // "messaging"
	Version int    `json:"version"` // schema version

	// Lists are static mailing lists. Messages are fanned out to all recipients.
	// Each recipient gets their own copy of the message.
	// Example: {"oncall": ["mayor/", "gastown/witness"]}
	Lists map[string][]string `json:"lists,omitempty"`

	// Queues are shared work queues. Only one copy exists; workers claim messages.
	// Messages sit in the queue until explicitly claimed by a worker.
	// Example: {"work/gastown": ["gastown/polecats/*"]}
	Queues map[string]QueueConfig `json:"queues,omitempty"`

	// Announces are bulletin boards. One copy exists; anyone can read, no claiming.
	// Used for broadcast announcements that don't need acknowledgment.
	// Example: {"alerts": {"readers": ["@town"]}}
	Announces map[string]AnnounceConfig `json:"announces,omitempty"`

	// NudgeChannels are named groups for real-time nudge fan-out.
	// Like mailing lists but for tmux send-keys instead of durable mail.
	// Example: {"workers": ["gastown/polecats/*", "gastown/crew/*"], "witnesses": ["*/witness"]}
	NudgeChannels map[string][]string `json:"nudge_channels,omitempty"`
}

MessagingConfig represents the messaging configuration (config/messaging.json). This defines mailing lists, work queues, and announcement channels.

func LoadMessagingConfig

func LoadMessagingConfig(path string) (*MessagingConfig, error)

LoadMessagingConfig loads and validates a messaging configuration file.

func LoadOrCreateMessagingConfig

func LoadOrCreateMessagingConfig(path string) (*MessagingConfig, error)

LoadOrCreateMessagingConfig loads the messaging config, creating a default if not found.

func NewMessagingConfig

func NewMessagingConfig() *MessagingConfig

NewMessagingConfig creates a new MessagingConfig with defaults.

type NamepoolConfig

type NamepoolConfig struct {
	// Style picks from a built-in theme (e.g., "mad-max", "minerals", "wasteland").
	// If empty, defaults to "mad-max".
	Style string `json:"style,omitempty"`

	// Names is a custom list of names to use instead of a built-in theme.
	// If provided, overrides the Style setting.
	Names []string `json:"names,omitempty"`

	// MaxBeforeNumbering is when to start appending numbers.
	// Default is 50. After this many polecats, names become name-01, name-02, etc.
	MaxBeforeNumbering int `json:"max_before_numbering,omitempty"`
}

NamepoolConfig represents namepool settings for themed polecat names.

func DefaultNamepoolConfig

func DefaultNamepoolConfig() *NamepoolConfig

DefaultNamepoolConfig returns a NamepoolConfig with sensible defaults.

type NonInteractiveConfig

type NonInteractiveConfig struct {
	// Subcommand is the subcommand for non-interactive execution (e.g., "exec" for codex).
	Subcommand string `json:"subcommand,omitempty"`

	// PromptFlag is the flag for passing prompts (e.g., "-p" for gemini).
	PromptFlag string `json:"prompt_flag,omitempty"`

	// OutputFlag is the flag for structured output (e.g., "--json", "--output-format json").
	OutputFlag string `json:"output_flag,omitempty"`
}

NonInteractiveConfig contains settings for running agents non-interactively.

type OverseerConfig

type OverseerConfig struct {
	Type     string `json:"type"`               // "overseer"
	Version  int    `json:"version"`            // schema version
	Name     string `json:"name"`               // display name
	Email    string `json:"email,omitempty"`    // email address
	Username string `json:"username,omitempty"` // username/handle
	Source   string `json:"source"`             // how identity was detected
}

OverseerConfig represents the human operator's identity (mayor/overseer.json). The overseer is the human who controls Gas Town, distinct from AI agents.

func DetectOverseer

func DetectOverseer(townRoot string) (*OverseerConfig, error)

DetectOverseer attempts to detect the overseer's identity from available sources. Priority order:

  1. Existing config file (if path provided and exists)
  2. Git config (user.name + user.email)
  3. GitHub CLI (gh api user)
  4. Environment ($USER or whoami)

func LoadOrDetectOverseer

func LoadOrDetectOverseer(townRoot string) (*OverseerConfig, error)

LoadOrDetectOverseer loads existing config or detects and saves a new one.

func LoadOverseerConfig

func LoadOverseerConfig(path string) (*OverseerConfig, error)

LoadOverseerConfig loads and validates an overseer configuration file.

func (*OverseerConfig) FormatOverseerIdentity

func (c *OverseerConfig) FormatOverseerIdentity() string

FormatOverseerIdentity returns a formatted string for display. Example: "Steve Yegge <stevey@example.com>"

type PatrolConfig

type PatrolConfig struct {
	Enabled  bool   `json:"enabled"`            // whether this patrol is enabled
	Interval string `json:"interval,omitempty"` // e.g., "5m"
	Agent    string `json:"agent,omitempty"`    // agent that runs this patrol
}

PatrolConfig represents a single patrol configuration.

type QueueConfig

type QueueConfig struct {
	// Workers lists addresses eligible to claim from this queue.
	// Supports wildcards: "gastown/polecats/*" matches all polecats in gastown.
	Workers []string `json:"workers"`

	// MaxClaims is the maximum number of concurrent claims (0 = unlimited).
	MaxClaims int `json:"max_claims,omitempty"`
}

QueueConfig represents a work queue configuration.

type RigConfig

type RigConfig struct {
	Type          string       `json:"type"`    // "rig"
	Version       int          `json:"version"` // schema version
	Name          string       `json:"name"`    // rig name
	GitURL        string       `json:"git_url"` // git repository URL
	LocalRepo     string       `json:"local_repo,omitempty"`
	DefaultBranch string       `json:"default_branch,omitempty"` // default branch (defaults to "main")
	CreatedAt     time.Time    `json:"created_at"`               // when the rig was created
	Beads         *BeadsConfig `json:"beads,omitempty"`
}

RigConfig represents per-rig identity (rig/config.json). This contains only identity - behavioral config is in settings/config.json.

func LoadRigConfig

func LoadRigConfig(path string) (*RigConfig, error)

LoadRigConfig loads and validates a rig configuration file.

func NewRigConfig

func NewRigConfig(name, gitURL string) *RigConfig

NewRigConfig creates a new RigConfig (identity only).

type RigEntry

type RigEntry struct {
	GitURL      string       `json:"git_url"`
	LocalRepo   string       `json:"local_repo,omitempty"`
	AddedAt     time.Time    `json:"added_at"`
	BeadsConfig *BeadsConfig `json:"beads,omitempty"`
}

RigEntry represents a single rig in the registry.

type RigSettings

type RigSettings struct {
	Type       string            `json:"type"`                  // "rig-settings"
	Version    int               `json:"version"`               // schema version
	MergeQueue *MergeQueueConfig `json:"merge_queue,omitempty"` // merge queue settings
	Theme      *ThemeConfig      `json:"theme,omitempty"`       // tmux theme settings
	Namepool   *NamepoolConfig   `json:"namepool,omitempty"`    // polecat name pool settings
	Crew       *CrewConfig       `json:"crew,omitempty"`        // crew startup settings
	Runtime    *RuntimeConfig    `json:"runtime,omitempty"`     // LLM runtime settings (deprecated: use Agent)

	// Agent selects which agent preset to use for this rig.
	// Can be a built-in preset ("cursor", "gemini", "codex", "auggie", "amp")
	// or a custom agent defined in settings/agents.json.
	// If empty, uses the town's default_agent setting (cursor).
	// Takes precedence over Runtime if both are set.
	Agent string `json:"agent,omitempty"`
}

RigSettings represents per-rig behavioral configuration (settings/config.json).

func LoadRigSettings

func LoadRigSettings(path string) (*RigSettings, error)

LoadRigSettings loads and validates a rig settings file.

func NewRigSettings

func NewRigSettings() *RigSettings

NewRigSettings creates a new RigSettings with defaults.

type RigsConfig

type RigsConfig struct {
	Version int                 `json:"version"`
	Rigs    map[string]RigEntry `json:"rigs"`
}

RigsConfig represents the rigs registry (mayor/rigs.json).

func LoadRigsConfig

func LoadRigsConfig(path string) (*RigsConfig, error)

LoadRigsConfig loads and validates a rigs registry file.

type RuntimeConfig

type RuntimeConfig struct {
	// Command is the CLI command to invoke (e.g., "cursor-agent", "gemini", "aider").
	// Default: "cursor-agent"
	Command string `json:"command,omitempty"`

	// Args are additional command-line arguments.
	// Default: ["-f"] (force/YOLO mode for cursor-agent)
	Args []string `json:"args,omitempty"`

	// InitialPrompt is an optional first message to send after startup.
	// For cursor-agent, this is passed with -p flag.
	// Empty by default (hooks handle context).
	InitialPrompt string `json:"initial_prompt,omitempty"`
}

RuntimeConfig represents LLM runtime configuration for agent sessions. This allows switching between different LLM backends (cursor, gemini, codex, etc.) without modifying startup code.

func DefaultRuntimeConfig

func DefaultRuntimeConfig() *RuntimeConfig

DefaultRuntimeConfig returns a RuntimeConfig with sensible defaults.

func LoadRuntimeConfig deprecated

func LoadRuntimeConfig(rigPath string) *RuntimeConfig

LoadRuntimeConfig loads the RuntimeConfig from a rig's settings. Falls back to defaults if settings don't exist or don't specify runtime config. rigPath should be the path to the rig directory (e.g., ~/gt/gastown).

Deprecated: Use ResolveAgentConfig for full agent resolution with town settings.

func ResolveAgentConfig

func ResolveAgentConfig(townRoot, rigPath string) *RuntimeConfig

ResolveAgentConfig resolves the agent configuration for a rig. It looks up the agent by name in town settings (custom agents) and built-in presets.

Resolution order:

  1. If rig has Runtime set directly, use it (backwards compatibility)
  2. If rig has Agent set, look it up in: a. Town's custom agents (from TownSettings.Agents) b. Built-in presets (cursor, gemini, codex)
  3. If rig has no Agent set, use town's default_agent
  4. Fall back to cursor defaults

townRoot is the path to the town directory (e.g., ~/gt). rigPath is the path to the rig directory (e.g., ~/gt/gastown).

func ResolveAgentConfigWithOverride

func ResolveAgentConfigWithOverride(townRoot, rigPath, agentOverride string) (*RuntimeConfig, string, error)

ResolveAgentConfigWithOverride resolves the agent configuration for a rig, with an optional override. If agentOverride is non-empty, it is used instead of rig/town defaults. Returns the resolved RuntimeConfig, the selected agent name, and an error if the override name does not exist in town custom agents or built-in presets.

func RuntimeConfigFromPreset

func RuntimeConfigFromPreset(preset AgentPreset) *RuntimeConfig

RuntimeConfigFromPreset creates a RuntimeConfig from an agent preset. This provides the basic Command/Args; additional fields from AgentPresetInfo can be accessed separately for extended functionality.

func (*RuntimeConfig) BuildCommand

func (rc *RuntimeConfig) BuildCommand() string

BuildCommand returns the full command line string. For use with tmux SendKeys.

func (*RuntimeConfig) BuildCommandWithPrompt

func (rc *RuntimeConfig) BuildCommandWithPrompt(prompt string) string

BuildCommandWithPrompt returns the full command line with an initial prompt. If the config has an InitialPrompt, it's appended as a quoted argument. If prompt is provided, it overrides the config's InitialPrompt.

func (*RuntimeConfig) MergeWithPreset

func (rc *RuntimeConfig) MergeWithPreset(preset AgentPreset) *RuntimeConfig

MergeWithPreset applies preset defaults to a RuntimeConfig. User-specified values take precedence over preset defaults. Returns a new RuntimeConfig without modifying the original.

type ThemeConfig

type ThemeConfig struct {
	// Name picks from the default palette (e.g., "ocean", "forest").
	// If empty, a theme is auto-assigned based on rig name.
	Name string `json:"name,omitempty"`

	// Custom overrides the palette with specific colors.
	Custom *CustomTheme `json:"custom,omitempty"`

	// RoleThemes overrides themes for specific roles in this rig.
	// Keys: "witness", "refinery", "crew", "polecat"
	RoleThemes map[string]string `json:"role_themes,omitempty"`
}

ThemeConfig represents tmux theme settings for a rig.

type TownConfig

type TownConfig struct {
	Type       string    `json:"type"`                  // "town"
	Version    int       `json:"version"`               // schema version
	Name       string    `json:"name"`                  // town identifier (internal)
	Owner      string    `json:"owner,omitempty"`       // owner email (entity identity)
	PublicName string    `json:"public_name,omitempty"` // public display name
	CreatedAt  time.Time `json:"created_at"`
}

TownConfig represents the main town identity (mayor/town.json).

func LoadTownConfig

func LoadTownConfig(path string) (*TownConfig, error)

LoadTownConfig loads and validates a town configuration file.

type TownSettings

type TownSettings struct {
	Type    string `json:"type"`    // "town-settings"
	Version int    `json:"version"` // schema version

	// DefaultAgent is the name of the agent preset to use by default.
	// Can be a built-in preset ("cursor", "gemini", "codex", "auggie", "amp")
	// or a custom agent name defined in settings/agents.json.
	// Default: "cursor"
	DefaultAgent string `json:"default_agent,omitempty"`

	// Agents defines custom agent configurations or overrides.
	// Keys are agent names that can be referenced by DefaultAgent or rig settings.
	// Values override or extend the built-in presets.
	// Example: {"gemini": {"command": "/custom/path/to/gemini"}}
	Agents map[string]*RuntimeConfig `json:"agents,omitempty"`
}

TownSettings represents town-level behavioral configuration (settings/config.json). This contains agent configuration that applies to all rigs unless overridden.

func LoadOrCreateTownSettings

func LoadOrCreateTownSettings(path string) (*TownSettings, error)

LoadOrCreateTownSettings loads town settings or creates defaults if missing.

func NewTownSettings

func NewTownSettings() *TownSettings

NewTownSettings creates a new TownSettings with defaults.

type TownThemeConfig

type TownThemeConfig struct {
	// RoleDefaults sets default themes for roles across all rigs.
	// Keys: "witness", "refinery", "crew", "polecat"
	RoleDefaults map[string]string `json:"role_defaults,omitempty"`
}

TownThemeConfig represents global theme settings (mayor/config.json).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL