config

package
v0.0.0-...-f0049f5 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

README

Configuration Package

This package provides comprehensive configuration management for the Flow application, supporting JSON configuration files and environment variable overrides.

Features

  • Centralized Configuration: All application settings in one place
  • Environment Variable Support: Override any setting via environment variables
  • Validation: Built-in validation for required configuration fields
  • Defaults: Sensible defaults for all configuration options
  • Type Safety: Strongly typed configuration structs

Configuration Sections

SlackBot Configuration
  • Purpose: Slack bot integration settings
  • Environment Variables: SLACK_APP_TOKEN, SLACK_BOT_TOKEN, SLACK_BOT_DEBUG, etc.
  • Auto-Enable: Bot automatically enables when tokens are provided
Claude Configuration
  • Purpose: Claude CLI integration settings
  • Environment Variables: CLAUDE_DEBUG, CLAUDE_DEBUG_DIR, CLAUDE_TOOLS
  • Default Tools: Read, Write, Bash
Worklet Configuration
  • Purpose: Worklet system settings
  • Environment Variables: WORKLET_BASE_DIR, WORKLET_CLEANUP_MAX_AGE, WORKLET_MAX_CONCURRENT
  • Default Cleanup: 24 hours
Git Configuration
  • Purpose: Git and GitHub integration
  • Environment Variables: GITHUB_TOKEN, GIT_BASE_DIR
  • Used For: Repository cloning, PR creation

Usage

Loading Configuration
// Load from file with environment overrides
config := config.LoadConfig()

// Load from specific file
config := config.NewFromFile("/path/to/config.json")

// Use default configuration
config := config.New()
Accessing Configuration
// Check if SlackBot is enabled and valid
if config.IsSlackBotEnabled() {
    slackConfig := config.GetSlackBotConfig()
    // Use slack configuration
}

// Get other configuration sections
claudeConfig := config.GetClaudeConfig()
workletConfig := config.GetWorkletConfig()  
gitConfig := config.GetGitConfig()
Environment Variable Examples
# SlackBot configuration
export SLACK_APP_TOKEN="xapp-1-..."
export SLACK_BOT_TOKEN="xoxb-..."
export SLACK_BOT_DEBUG="true"
export SLACK_BOT_SESSION_TIMEOUT="45m"
export SLACK_BOT_MAX_SESSIONS="15"

# Claude configuration  
export CLAUDE_DEBUG="true"
export CLAUDE_DEBUG_DIR="/var/log/claude"
export CLAUDE_TOOLS="Read,Write,Bash,Edit"

# Worklet configuration
export WORKLET_BASE_DIR="/data/worklets"
export WORKLET_CLEANUP_MAX_AGE="48h"
export WORKLET_MAX_CONCURRENT="10"

# Git configuration
export GITHUB_TOKEN="ghp_..."
export GIT_BASE_DIR="/data/repos"

Configuration File Format

See data/config.example.json for a complete example configuration file.

JSON Structure
{
  "slack_bot": {
    "enabled": true,
    "slack_app_token": "xapp-1-...",
    "slack_bot_token": "xoxb-...",
    "session_timeout": "30m",
    "max_sessions": 10,
    "working_directory": "/tmp/slackbot",
    "debug": false
  },
  "claude": {
    "debug": false,
    "debug_dir": "/tmp/claude",
    "tools": ["Read", "Write", "Bash"]
  },
  "worklet": {
    "base_dir": "/tmp/worklet-repos",
    "cleanup_max_age": "24h",
    "max_concurrent": 5
  },
  "git": {
    "github_token": "ghp_...",
    "base_dir": "/tmp/git-repos"
  }
}

Validation

SlackBot Validation
slackConfig := config.GetSlackBotConfig()
if slackConfig.IsValid() {
    // Both app token and bot token are present
}
Built-in Checks
  • SlackBot automatically enables when both tokens are provided
  • All duration strings are parsed (e.g., "30m", "24h")
  • Numeric values are validated from environment variables

Migration from Old Config

The new configuration system is backward compatible with the existing AppConfig structure. New configuration sections are added alongside existing fields, so existing code continues to work.

Testing

Run the configuration tests:

go test ./config/...

The tests verify:

  • Default value initialization
  • Environment variable parsing
  • Configuration validation
  • Helper method functionality

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	OpenAIKey          string        `json:"openai_key"`
	SMTP               SMTPConfig    `json:"smtp"`
	Spotify            SpotifyConfig `json:"spotify"`
	ExternalURL        string        `json:"external_url"`
	SessionSecret      string        `json:"session_secret"`
	GoogleClientID     string        `json:"google_client_id"`
	GoogleClientSecret string        `json:"google_client_secret"`
	Blog               BlogConfig    `json:"blog"`
	Stripe             Stripe        `json:"stripe"`
	Figma              string        `json:"figma"`
	Github             GithubConfig  `json:"github"`
	Proxy              ProxyConfig   `json:"proxy"`
	Admins             []string      `json:"admins"`
	DB                 string        `json:"db"`
	DSN                string        `json:"dsn"`
	ShareDir           string        `json:"share_dir"`
	JamsocketURL       string        `json:"jamsocket_url"`
	SupabaseURL        string        `json:"supabase_url"`
	ClaudeDebug        bool          `json:"claude_debug"`

	// New configuration sections
	SlackBot SlackBotConfig `json:"slack_bot"`
	Claude   ClaudeConfig   `json:"claude"`
	Worklet  WorkletConfig  `json:"worklet"`
	Git      GitConfig      `json:"git"`
}

func LoadConfig

func LoadConfig() AppConfig

func (*AppConfig) GetClaudeConfig

func (c *AppConfig) GetClaudeConfig() *ClaudeConfig

GetClaudeConfig returns the Claude configuration

func (*AppConfig) GetGitConfig

func (c *AppConfig) GetGitConfig() *GitConfig

GetGitConfig returns the Git configuration

func (*AppConfig) GetSlackBotConfig

func (c *AppConfig) GetSlackBotConfig() *SlackBotConfig

GetSlackBotConfig returns the Slack bot configuration

func (*AppConfig) GetWorkletConfig

func (c *AppConfig) GetWorkletConfig() *WorkletConfig

GetWorkletConfig returns the Worklet configuration

func (*AppConfig) IsSlackBotEnabled

func (c *AppConfig) IsSlackBotEnabled() bool

IsSlackBotEnabled returns true if the Slack bot is enabled and has valid configuration

type BlogConfig

type BlogConfig struct {
	BaseURL string `json:"base_url"`
	YJSURL  string `json:"yjs_url"`
}

type ClaudeConfig

type ClaudeConfig struct {
	Debug    bool     `json:"debug"`
	DebugDir string   `json:"debug_dir"`
	Tools    []string `json:"tools"`
}

type GitConfig

type GitConfig struct {
	Token   string `json:"github_token"`
	BaseDir string `json:"base_dir"`
}

type GithubConfig

type GithubConfig struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
}

type ProxyConfig

type ProxyConfig struct {
	URL      string `json:"url"`
	Username string `json:"username"`
	Password string `json:"password"`
	SocksURL string `json:"socks_url"`
}

type SMTPConfig

type SMTPConfig struct {
	Host     string `json:"host"`
	Port     string `json:"port"`
	Username string `json:"username"`
	Password string `json:"password"`
}

type SlackBotConfig

type SlackBotConfig struct {
	Enabled            bool          `json:"enabled"`
	SlackAppID         string        `json:"app_id"`
	SlackClientID      string        `json:"client_id"`
	SlackClientSecret  string        `json:"client_secret"`
	SlackSigningSecret string        `json:"signing_secret"`
	SlackToken         string        `json:"token"`
	BotToken           string        `json:"bot_token"`
	SessionTimeout     time.Duration `json:"session_timeout"`
	MaxSessions        int           `json:"max_sessions"`
	WorkingDirectory   string        `json:"working_directory"`
	Debug              bool          `json:"debug"`
	ChannelWhitelist   []string      `json:"channel_whitelist"`

	// Ideation settings
	IdeationEnabled     bool          `json:"ideation_enabled"`
	IdeationTimeout     time.Duration `json:"ideation_timeout"`
	MaxIdeationSessions int           `json:"max_ideation_sessions"`
	AutoExpandThreshold int           `json:"auto_expand_threshold"`
}

type SpotifyConfig

type SpotifyConfig struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
}

type Stripe

type Stripe struct {
	SecretKey string `json:"secret_key"`
}

type WorkletConfig

type WorkletConfig struct {
	BaseDir       string        `json:"base_dir"`
	CleanupMaxAge time.Duration `json:"cleanup_max_age"`
	MaxConcurrent int           `json:"max_concurrent"`
}

Jump to

Keyboard shortcuts

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