Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package config loads and validates Ghost's TOML configuration.

Index

Constants

View Source
const (
	DefaultMaxPRs = 50
	MaxPRsLimit   = 100
)

DefaultMaxPRs is how many PRs a view shows unless max_prs_per_view or the view's max_prs says otherwise. MaxPRsLimit is the most GitHub returns in one search request.

View Source
const ViewsFileName = "views.toml"

ViewsFileName holds the views Ghost manages from the TUI. It sits next to config.toml, which Ghost never writes (so its comments survive).

Variables

View Source
var DefaultConfigTOML string
View Source
var DefaultPrompt string

DefaultPrompt is used by agents that set neither prompt nor prompt_file.

View Source
var KnownAgentKinds = map[string]bool{"claude": true}

KnownAgentKinds lists the agent implementations Ghost can run.

Functions

func RenderMessage added in v0.2.0

func RenderMessage(text string, d MessageData) (string, error)

RenderMessage executes a review_footer or approval_message template. An empty template renders as "" (the message is off).

func RenderPrompt

func RenderPrompt(text string, d PromptData) (string, error)

RenderPrompt executes a review prompt template against d.

func SaveViews

func SaveViews(path string, views []View) error

SaveViews replaces views.toml with views, atomically and durably: it writes a synced temp file next to the real file and renames it over it. A symlinked views.toml (dotfile managers) stays a symlink, and an existing file keeps its permissions.

func ViewsPath

func ViewsPath(configPath string) string

func WriteDefaults

func WriteDefaults(configPath string) ([]string, error)

WriteDefaults writes a starter config and prompt beside configPath, skipping any file that already exists. It returns the files it created.

Types

type Agent

type Agent struct {
	Kind       string   `toml:"kind"`
	Model      string   `toml:"model"`
	ExtraArgs  []string `toml:"extra_args"`
	Prompt     string   `toml:"prompt"`
	PromptFile string   `toml:"prompt_file"`
}

type AutoApprove

type AutoApprove struct {
	Enabled            bool `toml:"enabled"`
	RequireConfirm     bool `toml:"require_confirm"`
	RequireCIGreen     bool `toml:"require_ci_green"`
	NoChecksIsGreen    bool `toml:"no_checks_is_green"`
	NoBlockingComments bool `toml:"no_blocking_comments"`
	NoChangesRequested bool `toml:"no_changes_requested"`
	MaxChangedLines    int  `toml:"max_changed_lines"`
}

type Config

type Config struct {
	PollInterval         Duration         `toml:"poll_interval"`
	MaxConcurrentReviews int              `toml:"max_concurrent_reviews"`
	MaxDailyCostUSD      float64          `toml:"max_daily_cost_usd"`
	MaxCostPerReviewUSD  float64          `toml:"max_cost_per_review_usd"`
	PostMode             string           `toml:"post_mode"`
	Theme                string           `toml:"theme"`
	ReviewFooter         string           `toml:"review_footer"`
	ApprovalMessage      string           `toml:"approval_message"`
	ReviewLabel          string           `toml:"review_label"`
	MaxPRsPerView        int              `toml:"max_prs_per_view"`
	DefaultAgent         string           `toml:"default_agent"`
	Agents               map[string]Agent `toml:"agents"`
	AutoApprove          AutoApprove      `toml:"auto_approve"`
	Views                []View           `toml:"view"`
	// contains filtered or unexported fields
}

func Default

func Default() Config

Default returns the configuration used for any key the file leaves unset.

func Load

func Load(path string) (Config, error)

Load reads and parses the config file at path.

func Parse

func Parse(data []byte) (Config, error)

Parse decodes TOML over Default(). Unknown keys are an error so typos surface.

func (*Config) AgentPrompt

func (c *Config) AgentPrompt(name string) (string, error)

AgentPrompt returns the raw prompt template text for the named agent: inline prompt, else the contents of prompt_file, else DefaultPrompt.

func (*Config) LabelFor added in v0.3.0

func (c *Config) LabelFor(v View) string

LabelFor returns the review label that applies to v: the view's own label if set ("" meaning none), otherwise review_label. "" means no label gate.

func (*Config) PRLimitFor added in v0.4.0

func (c *Config) PRLimitFor(v View) int

PRLimitFor returns how many PRs view v fetches: its own max_prs if set, otherwise max_prs_per_view (or the default when that is unset).

func (*Config) ThemesDir

func (c *Config) ThemesDir() string

ThemesDir is where user theme files live: <config dir>/themes. It is empty for a config that wasn't loaded from a file.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the config and reports every problem at once. When exactly one agent is defined and default_agent is unset, it becomes the default.

func (*Config) ValidateThemes

func (c *Config) ValidateThemes() error

ValidateThemes loads the theme files and checks that the configured theme exists. It is separate from Validate because only the TUI and --check use themes; a broken theme file shouldn't stop ghost review.

func (*Config) ValidateViews

func (c *Config) ValidateViews() error

ValidateViews checks only the views (names, queries, agent references), so saving a view isn't blocked by an unrelated file that broke after startup.

type Duration

type Duration struct{ time.Duration }

Duration is a time.Duration that reads from TOML strings like "5m".

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(b []byte) error

type MessageData added in v0.2.0

type MessageData struct {
	Agent   string
	Model   string
	Repo    string
	Number  int
	HeadSHA string // short (7 characters)
}

MessageData holds the variables available to review_footer and approval_message templates.

type PromptData

type PromptData struct {
	Repo         string
	Number       int
	Title        string
	Author       string
	Body         string
	BaseRef      string
	HeadRef      string
	HeadSHA      string
	URL          string
	ChangedFiles []string
}

PromptData holds the variables available to review prompt templates.

type View

type View struct {
	Name       string `toml:"name"`
	Query      string `toml:"query"`
	AutoReview bool   `toml:"auto_review"`
	Agent      string `toml:"agent,omitempty"`

	// Label overrides review_label for this view: nil = use review_label,
	// "" = no label, otherwise the label to require.
	Label *string `toml:"label,omitempty"`
	// MaxPRs overrides max_prs_per_view for this view; 0 = use it.
	MaxPRs int `toml:"max_prs,omitzero"`

	// Source is the file that defined the view: "config.toml" or
	// "views.toml". Only views.toml views are edited from the TUI.
	Source string `toml:"-"`
}

Jump to

Keyboard shortcuts

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