config

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config handles loading and validating nightshift configuration. Supports YAML config files and environment variable overrides.

Index

Constants

View Source
const (
	DefaultBudgetMode        = "daily"
	DefaultMaxPercent        = 75
	DefaultReservePercent    = 5
	DefaultWeeklyTokens      = 700000
	DefaultBillingMode       = "subscription"
	DefaultSnapshotInterval  = "30m"
	DefaultSnapshotRetention = 90
	DefaultWeekStartDay      = "monday"
	DefaultLogLevel          = "info"
	DefaultLogFormat         = "json"
	DefaultClaudeDataPath    = "~/.claude"
	DefaultCodexDataPath     = "~/.codex"
	DefaultCopilotDataPath   = "~/.copilot"
)

Default values for configuration.

View Source
const ProjectConfigName = "nightshift.yaml"

ProjectConfigName is the per-project config filename.

Variables

View Source
var (
	ErrCronAndInterval          = errors.New("cron and interval are mutually exclusive")
	ErrInvalidBudgetMode        = errors.New("budget mode must be 'daily' or 'weekly'")
	ErrInvalidBillingMode       = errors.New("billing mode must be 'subscription' or 'api'")
	ErrInvalidWeekStartDay      = errors.New("week_start_day must be 'monday' or 'sunday'")
	ErrInvalidMaxPercent        = errors.New("max_percent must be between 1 and 100")
	ErrInvalidReservePercent    = errors.New("reserve_percent must be between 0 and 100")
	ErrInvalidSnapshotRetention = errors.New("snapshot_retention_days must be >= 0")
	ErrInvalidLogLevel          = errors.New("log level must be debug, info, warn, or error")
	ErrInvalidLogFormat         = errors.New("log format must be json or text")
	ErrNoSchedule               = errors.New("either cron or interval must be specified")

	ErrCustomTaskMissingType        = errors.New("custom task: type is required")
	ErrCustomTaskMissingName        = errors.New("custom task: name is required")
	ErrCustomTaskMissingDescription = errors.New("custom task: description is required")
	ErrCustomTaskInvalidType        = errors.New("custom task: type must match [a-z0-9-]+")
	ErrCustomTaskInvalidCategory    = errors.New("custom task: invalid category")
	ErrCustomTaskInvalidCostTier    = errors.New("custom task: invalid cost_tier")
	ErrCustomTaskInvalidRiskLevel   = errors.New("custom task: invalid risk_level")
	ErrCustomTaskDuplicateType      = errors.New("custom task: duplicate type")
)

Validation errors

Functions

func DefaultDBPath

func DefaultDBPath() string

DefaultDBPath returns the default database path.

func DefaultLogPath

func DefaultLogPath() string

DefaultLogPath returns the default log path.

func GlobalConfigPath

func GlobalConfigPath() string

GlobalConfigPath returns the global config path.

func Validate

func Validate(cfg *Config) error

Validate checks configuration for errors.

Types

type BudgetConfig

type BudgetConfig struct {
	Mode                  string         `mapstructure:"mode"`                    // daily | weekly
	MaxPercent            int            `mapstructure:"max_percent"`             // Max % of budget per run
	AggressiveEndOfWeek   bool           `mapstructure:"aggressive_end_of_week"`  // Ramp up in last 2 days
	ReservePercent        int            `mapstructure:"reserve_percent"`         // Always keep in reserve
	WeeklyTokens          int            `mapstructure:"weekly_tokens"`           // Fallback weekly budget
	PerProvider           map[string]int `mapstructure:"per_provider"`            // Per-provider overrides
	BillingMode           string         `mapstructure:"billing_mode"`            // subscription | api
	CalibrateEnabled      bool           `mapstructure:"calibrate_enabled"`       // Enable budget calibration
	SnapshotInterval      string         `mapstructure:"snapshot_interval"`       // Interval for snapshots
	SnapshotRetentionDays int            `mapstructure:"snapshot_retention_days"` // Snapshot retention in days
	WeekStartDay          string         `mapstructure:"week_start_day"`          // monday | sunday
	DBPath                string         `mapstructure:"db_path"`                 // Override DB path
}

BudgetConfig controls token budget allocation.

type Config

type Config struct {
	Schedule     ScheduleConfig     `mapstructure:"schedule"`
	Budget       BudgetConfig       `mapstructure:"budget"`
	Providers    ProvidersConfig    `mapstructure:"providers"`
	Projects     []ProjectConfig    `mapstructure:"projects"`
	Tasks        TasksConfig        `mapstructure:"tasks"`
	Integrations IntegrationsConfig `mapstructure:"integrations"`
	Logging      LoggingConfig      `mapstructure:"logging"`
	Reporting    ReportingConfig    `mapstructure:"reporting"`
}

Config holds all nightshift configuration.

func Load

func Load() (*Config, error)

Load reads configuration from file and environment. Order: global config -> project config -> environment overrides

func LoadFromPaths

func LoadFromPaths(projectPath, globalPath string) (*Config, error)

LoadFromPaths reads configuration from specific paths. If projectPath is empty, looks in current directory. If globalPath is empty, uses default global path.

func (*Config) ExpandedDBPath

func (c *Config) ExpandedDBPath() string

ExpandedDBPath returns the database path with ~ expanded.

func (*Config) ExpandedLogPath

func (c *Config) ExpandedLogPath() string

ExpandedLogPath returns the log path with ~ expanded.

func (*Config) ExpandedProviderPath

func (c *Config) ExpandedProviderPath(provider string) string

ExpandedProviderPath returns the provider data path with ~ expanded.

func (*Config) GetProviderBudget

func (c *Config) GetProviderBudget(provider string) int

GetProviderBudget returns the weekly token budget for a provider.

func (*Config) GetTaskInterval

func (c *Config) GetTaskInterval(taskType string) time.Duration

GetTaskInterval returns the configured interval override for a task type. Returns 0 if no override is set (caller should fall back to TaskDefinition.DefaultInterval).

func (*Config) GetTaskPriority

func (c *Config) GetTaskPriority(task string) int

GetTaskPriority returns the priority for a task (higher = more important).

func (*Config) IsTaskEnabled

func (c *Config) IsTaskEnabled(task string) bool

IsTaskEnabled checks if a task type is enabled.

func (*Config) IsTaskExplicitlyEnabled

func (c *Config) IsTaskExplicitlyEnabled(task string) bool

IsTaskExplicitlyEnabled returns true if the task is in the explicit Enabled list.

type CustomTaskConfig

type CustomTaskConfig struct {
	Type        string `mapstructure:"type"`        // Task type slug, e.g. "my-review"
	Name        string `mapstructure:"name"`        // Human-readable name
	Description string `mapstructure:"description"` // Agent prompt text
	Category    string `mapstructure:"category"`    // One of: pr, analysis, options, safe, map, emergency
	CostTier    string `mapstructure:"cost_tier"`   // One of: low, medium, high, very-high
	RiskLevel   string `mapstructure:"risk_level"`  // One of: low, medium, high
	Interval    string `mapstructure:"interval"`    // Duration string, e.g. "48h"
}

CustomTaskConfig defines a user-defined custom task.

type IntegrationsConfig

type IntegrationsConfig struct {
	ClaudeMD    bool              `mapstructure:"claude_md"`    // Read claude.md
	AgentsMD    bool              `mapstructure:"agents_md"`    // Read agents.md
	TaskSources []TaskSourceEntry `mapstructure:"task_sources"` // Task sources
}

IntegrationsConfig defines external integrations.

type LoggingConfig

type LoggingConfig struct {
	Level  string `mapstructure:"level"`  // debug | info | warn | error
	Path   string `mapstructure:"path"`   // Log directory
	Format string `mapstructure:"format"` // json | text
}

LoggingConfig defines logging settings.

type ProjectConfig

type ProjectConfig struct {
	Path     string   `mapstructure:"path"`
	Priority int      `mapstructure:"priority"`
	Tasks    []string `mapstructure:"tasks"`   // Task overrides for this project
	Config   string   `mapstructure:"config"`  // Per-project config file
	Pattern  string   `mapstructure:"pattern"` // Glob pattern for discovery
	Exclude  []string `mapstructure:"exclude"` // Paths to exclude
}

ProjectConfig defines a project to manage.

type ProviderConfig

type ProviderConfig struct {
	Enabled  bool   `mapstructure:"enabled"`
	DataPath string `mapstructure:"data_path"` // Path to provider data directory
	// DangerouslySkipPermissions tells the CLI to skip interactive permission prompts.
	DangerouslySkipPermissions bool `mapstructure:"dangerously_skip_permissions"`
	// DangerouslyBypassApprovalsAndSandbox tells the CLI to bypass approvals and sandboxing.
	DangerouslyBypassApprovalsAndSandbox bool `mapstructure:"dangerously_bypass_approvals_and_sandbox"`
}

ProviderConfig defines settings for a single AI provider.

type ProvidersConfig

type ProvidersConfig struct {
	Claude  ProviderConfig `mapstructure:"claude"`
	Codex   ProviderConfig `mapstructure:"codex"`
	Copilot ProviderConfig `mapstructure:"copilot"`
	// Preference sets provider order (e.g., ["claude", "codex", "copilot"]).
	Preference []string `mapstructure:"preference"`
}

ProvidersConfig defines AI provider settings.

type ReportingConfig

type ReportingConfig struct {
	MorningSummary bool    `mapstructure:"morning_summary"`
	Email          *string `mapstructure:"email"`         // Optional email notification
	SlackWebhook   *string `mapstructure:"slack_webhook"` // Optional Slack webhook
}

ReportingConfig defines reporting settings.

type ScheduleConfig

type ScheduleConfig struct {
	Cron        string        `mapstructure:"cron"`         // Cron expression (e.g., "0 2 * * *")
	Interval    string        `mapstructure:"interval"`     // Alternative: duration (e.g., "1h")
	Window      *WindowConfig `mapstructure:"window"`       // Optional time window constraint
	MaxProjects int           `mapstructure:"max_projects"` // Default max projects per run (0 = unlimited)
	MaxTasks    int           `mapstructure:"max_tasks"`    // Default max tasks per project (0 = 1)
}

ScheduleConfig defines when nightshift runs.

type TDConfig

type TDConfig struct {
	Enabled    bool `mapstructure:"enabled"`
	TeachAgent bool `mapstructure:"teach_agent"` // Include td usage in prompts
}

TDConfig defines td task management integration.

type TaskSourceEntry

type TaskSourceEntry struct {
	TD           *TDConfig `mapstructure:"td"`
	GithubIssues bool      `mapstructure:"github_issues"`
	File         string    `mapstructure:"file"`
}

TaskSourceEntry represents a task source configuration.

type TasksConfig

type TasksConfig struct {
	Enabled    []string           `mapstructure:"enabled"`    // Enabled task types
	Priorities map[string]int     `mapstructure:"priorities"` // Priority per task type
	Disabled   []string           `mapstructure:"disabled"`   // Explicitly disabled tasks
	Intervals  map[string]string  `mapstructure:"intervals"`  // Per-task interval overrides (duration strings)
	Custom     []CustomTaskConfig `mapstructure:"custom"`     // User-defined custom tasks
}

TasksConfig defines task selection settings.

type WindowConfig

type WindowConfig struct {
	Start    string `mapstructure:"start"`    // Start time (e.g., "22:00")
	End      string `mapstructure:"end"`      // End time (e.g., "06:00")
	Timezone string `mapstructure:"timezone"` // Timezone (e.g., "America/Denver")
}

WindowConfig defines a time window for execution.

Jump to

Keyboard shortcuts

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