config

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config manages the configuration for the contextvibes CLI application.

It defines the structure of the configuration, provides functions to load configuration from a YAML file (defaulting to '.contextvibes.yaml' in the project root), and offers a way to get default configuration values.

The primary components are:

  • Config: The main struct holding all configuration settings, including Git behavior, logging preferences, and validation rules for branch names and commit messages.
  • GitSettings, LoggingSettings, ValidationRule: Sub-structs organizing related configuration items.
  • GetDefaultConfig(): Returns a pointer to a Config struct populated with sensible default values.
  • LoadConfig(filePath string): Attempts to load configuration from the specified YAML file. Returns nil if the file doesn't exist, allowing graceful fallback to defaults.
  • FindRepoRootConfigPath(execClient *exec.ExecutorClient): Locates the configuration file by searching upwards from the current directory to the Git repository root.
  • MergeWithDefaults(loadedCfg *Config, defaultConfig *Config): Merges a loaded user configuration with the default configuration, giving precedence to user-defined values.

Constants are also defined for default filenames (e.g., DefaultConfigFileName, DefaultCodemodFilename, DefaultDescribeOutputFile, UltimateDefaultAILogFilename) and default patterns for validation. These constants are intended to be used by CLI commands to ensure consistent default behavior.

The typical flow involves: 1. Attempting to find and load a user-defined '.contextvibes.yaml' file. 2. If found and valid, merging it with the application's default configuration. 3. If not found or invalid, using the application's default configuration directly. The resulting configuration is then used throughout the application, particularly by the cmd package to influence command behavior.

Index

Constants

View Source
const (
	// DefaultConfigFileName is the name of the configuration file.
	DefaultConfigFileName = ".contextvibes.yaml"
	// DefaultCodemodFilename is the default name for codemod scripts.
	DefaultCodemodFilename = "codemod.json"
	// DefaultDescribeOutputFile is the default output for the describe command.
	DefaultDescribeOutputFile = "contextvibes.md"
	// StrategicKickoffFilename is the path to the generated kickoff protocol.
	StrategicKickoffFilename = "docs/strategic_kickoff_protocol.md"
	// DefaultBranchNamePattern is the default regex for branch validation.
	DefaultBranchNamePattern = `^((feature|fix|docs|format)/.+)$`
	// DefaultCommitMessagePattern is the default regex for commit message validation.
	//nolint:lll // Regex pattern is long by necessity.
	DefaultCommitMessagePattern = `^(BREAKING|feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-zA-Z0-9\-_/]+\))?:\s.+`
	// DefaultGitRemote is the default git remote name.
	DefaultGitRemote = "origin"
	// DefaultGitMainBranch is the default main branch name.
	DefaultGitMainBranch = "main"
	// UltimateDefaultAILogFilename is the fallback log file name.
	UltimateDefaultAILogFilename = "contextvibes_ai_trace.log"
)

Variables

View Source
var (
	// ErrEmptyConfig is returned when the configuration file is empty.
	ErrEmptyConfig = errors.New("config file is empty")
	// ErrNoExecutor is returned when the executor client is nil.
	ErrNoExecutor = errors.New("executor client is nil, cannot find repo root")
	// ErrNotGitRepo is returned when the current directory is not a git repository.
	ErrNotGitRepo = errors.New("git rev-parse --show-toplevel returned an empty or invalid path, not in a git repository")
	// ErrNilConfigSave is returned when attempting to save a nil config.
	ErrNilConfigSave = errors.New("cannot save a nil config to file")
)

Functions

func FindRepoRootConfigPath

func FindRepoRootConfigPath(execClient *exec.ExecutorClient) (string, error)

FindRepoRootConfigPath attempts to locate the config file in the git repo root.

func UpdateAndSaveConfig added in v0.1.1

func UpdateAndSaveConfig(cfgToSave *Config, filePath string) error

UpdateAndSaveConfig writes the configuration to the specified file path.

Types

type AICollaborationPreferences added in v0.1.1

type AICollaborationPreferences struct {
	CodeProvisioningStyle string `yaml:"codeProvisioningStyle,omitempty"`
	MarkdownDocsStyle     string `yaml:"markdownDocsStyle,omitempty"`
	DetailedTaskMode      string `yaml:"detailedTaskMode,omitempty"`
	ProactiveDetailLevel  string `yaml:"proactiveDetailLevel,omitempty"`
	AIProactivity         string `yaml:"aiProactivity,omitempty"`
}

AICollaborationPreferences defines how the AI should interact with the user.

type AISettings added in v0.1.1

type AISettings struct {
	CollaborationPreferences AICollaborationPreferences `yaml:"collaborationPreferences,omitempty"`
}

AISettings groups AI-related settings.

type BehaviorSettings added in v0.2.1

type BehaviorSettings struct {
	DualOutput bool `yaml:"dualOutput,omitempty"`
}

BehaviorSettings configures general CLI behavior.

type Config

type Config struct {
	Git          GitSettings          `yaml:"git,omitempty"`
	Logging      LoggingSettings      `yaml:"logging,omitempty"`
	SystemPrompt SystemPromptSettings `yaml:"systemPrompt,omitempty"`
	Validation   struct {
		BranchName    ValidationRule `yaml:"branchName,omitempty"`
		CommitMessage ValidationRule `yaml:"commitMessage,omitempty"`
	} `yaml:"validation,omitempty"`
	ProjectState ProjectState     `yaml:"projectState,omitempty"`
	AI           AISettings       `yaml:"ai,omitempty"`
	Run          RunSettings      `yaml:"run,omitempty"`
	Export       ExportSettings   `yaml:"export,omitempty"`
	Describe     DescribeSettings `yaml:"describe,omitempty"`
	Project      ProjectSettings  `yaml:"project,omitempty"`
	Behavior     BehaviorSettings `yaml:"behavior,omitempty"`
	Feedback     FeedbackSettings `yaml:"feedback,omitempty"`
}

Config is the top-level configuration structure.

func GetDefaultConfig

func GetDefaultConfig() *Config

GetDefaultConfig returns a Config struct populated with default values.

func LoadConfig

func LoadConfig(filePath string) (*Config, error)

LoadConfig attempts to load configuration from the specified file path.

func MergeWithDefaults

func MergeWithDefaults(loadedCfg *Config, defaultConfig *Config) *Config

MergeWithDefaults merges a loaded config with the default config.

type DescribeSettings added in v0.4.0

type DescribeSettings struct {
	IncludePatterns []string `yaml:"includePatterns,omitempty"`
	ExcludePatterns []string `yaml:"excludePatterns,omitempty"`
}

DescribeSettings configures the 'describe' command.

type ExampleSettings added in v0.2.1

type ExampleSettings struct {
	Verify []VerificationCheck `yaml:"verify,omitempty"`
}

ExampleSettings configures settings for a specific example.

type ExportSettings added in v0.2.1

type ExportSettings struct {
	ExcludePatterns []string `yaml:"excludePatterns,omitempty"`
}

ExportSettings configures the 'export' command.

type FeedbackSettings added in v0.2.1

type FeedbackSettings struct {
	DefaultRepository string            `yaml:"defaultRepository,omitempty"`
	Repositories      map[string]string `yaml:"repositories,omitempty"`
}

FeedbackSettings configures the 'feedback' command.

type GitSettings

type GitSettings struct {
	DefaultRemote     string `yaml:"defaultRemote,omitempty"`
	DefaultMainBranch string `yaml:"defaultMainBranch,omitempty"`
}

GitSettings configures git behavior.

type LoggingSettings

type LoggingSettings struct {
	Enable *bool `yaml:"enable,omitempty"`
	//nolint:tagliatelle // Keep camelCase for backward compatibility.
	DefaultAILogFile string `yaml:"defaultAILogFile,omitempty"`
}

LoggingSettings configures application logging.

type ProjectSettings added in v0.2.1

type ProjectSettings struct {
	Provider        string   `yaml:"provider,omitempty"`
	UpstreamModules []string `yaml:"upstreamModules,omitempty"`
}

ProjectSettings configures project-wide settings.

type ProjectState added in v0.1.1

type ProjectState struct {
	StrategicKickoffCompleted *bool  `yaml:"strategicKickoffCompleted,omitempty"`
	LastStrategicKickoffDate  string `yaml:"lastStrategicKickoffDate,omitempty"`
}

ProjectState tracks the state of project workflows.

type RunSettings added in v0.2.1

type RunSettings struct {
	Examples map[string]ExampleSettings `yaml:"examples,omitempty"`
}

RunSettings configures the 'run' command.

type SystemPromptSettings added in v0.2.1

type SystemPromptSettings struct {
	DefaultOutputFiles map[string]string `yaml:"defaultOutputFiles,omitempty"`
}

SystemPromptSettings configures system prompt generation.

type ValidationRule

type ValidationRule struct {
	Enable  *bool  `yaml:"enable,omitempty"`
	Pattern string `yaml:"pattern,omitempty"`
}

ValidationRule defines a validation rule with an enable flag and a regex pattern.

type VerificationCheck added in v0.2.1

type VerificationCheck struct {
	Name        string   `yaml:"name"`
	Description string   `yaml:"description,omitempty"`
	Command     string   `yaml:"command"`
	Args        []string `yaml:"args,omitempty"`
}

VerificationCheck defines a command to run to verify an example.

Jump to

Keyboard shortcuts

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