Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ Examples:
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
defer cancel()
projectContext := project.EnsureProject(ctx, cmd)

// Check for prompts evals feature flag
if CheckFeatureFlag(cmd, FeaturePromptsEvals, "enable-prompts-evals") {
projectContext.Logger.Info("Prompts evaluations feature is enabled")
}

production, _ := cmd.Flags().GetBool("production")
install, _ := cmd.Flags().GetBool("install")
deploy, _ := cmd.Flags().GetBool("deploy")
Expand Down
67 changes: 67 additions & 0 deletions cmd/feature_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package cmd

import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// Feature flag constants
const (
FeaturePromptsEvals = "enable_prompts_evals"
)

// SetupFeatureFlags initializes feature flag configuration and command line flags
func SetupFeatureFlags(rootCmd *cobra.Command) {
// Add command line flags (no defaults set - only write to config when explicitly enabled)
rootCmd.PersistentFlags().Bool("enable-prompts-evals", false, "Enable prompts evals")
rootCmd.PersistentFlags().MarkHidden("enable-prompts-evals")
// Don't bind to viper - we'll handle this manually to prevent false values in config
}

// Feature flag helper functions

// IsFeatureEnabled checks if a feature flag is enabled
func IsFeatureEnabled(feature string) bool {
key := "features." + feature
if viper.IsSet(key) {
return viper.GetBool(key)
}
return false
}

// CheckFeatureFlag checks if a feature flag is enabled via command line or config
// and only writes to config if explicitly enabled
func CheckFeatureFlag(cmd *cobra.Command, feature string, cmdFlagName string) bool {
// Check if flag was set via command line
if cmd.Flags().Changed(cmdFlagName) {
enabled, _ := cmd.Flags().GetBool(cmdFlagName)
// Only write to config if explicitly enabled
if enabled {
viper.Set("features."+feature, true)
}
return enabled
}

// Check config file
return IsFeatureEnabled(feature)
}

// IsExperimentalEnabled checks if experimental features are enabled
func IsPromptsEvalsEnabled() bool {
return IsFeatureEnabled(FeaturePromptsEvals)
}

// GetEnabledFeatures returns a list of all currently enabled feature flags
func GetEnabledFeatures() []string {
var enabled []string

if IsPromptsEvalsEnabled() {
enabled = append(enabled, FeaturePromptsEvals)
}
return enabled
}

// IsAnyFeatureEnabled checks if any feature flags are enabled
func IsAnyFeatureEnabled() bool {
return IsPromptsEvalsEnabled()
}
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ func init() {
viper.SetDefault("overrides.api_url", "https://api.agentuity.com")
viper.SetDefault("overrides.transport_url", "https://agentuity.ai")

// Setup feature flags
SetupFeatureFlags(rootCmd)

cobra.OnInitialize(initConfig)
}

Expand Down
5 changes: 5 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Examples:
fmt.Println("Version: " + Version)
fmt.Println("Commit: " + Commit)
fmt.Println("Date: " + Date)

// Example of using feature flags
if IsPromptsEvalsEnabled() {
fmt.Println("Prompts Evals: Enabled")
}
} else {
fmt.Println(Version)
}
Expand Down
Loading