Documentation
¶
Overview ¶
Package config loads and validates Ghost's TOML configuration.
Index ¶
- Constants
- Variables
- func RenderMessage(text string, d MessageData) (string, error)
- func RenderPrompt(text string, d PromptData) (string, error)
- func SaveViews(path string, views []View) error
- func ViewsPath(configPath string) string
- func WriteDefaults(configPath string) ([]string, error)
- type Agent
- type AutoApprove
- type Config
- type Duration
- type MessageData
- type PromptData
- type View
Constants ¶
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.
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 ¶
var DefaultConfigTOML string
var DefaultPrompt string
DefaultPrompt is used by agents that set neither prompt nor prompt_file.
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 ¶
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 WriteDefaults ¶
WriteDefaults writes a starter config and prompt beside configPath, skipping any file that already exists. It returns the files it created.
Types ¶
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"`
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 (*Config) AgentPrompt ¶
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
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
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Duration is a time.Duration that reads from TOML strings like "5m".
func (Duration) MarshalText ¶
func (*Duration) UnmarshalText ¶
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:"-"`
}