From e1f90810ae6281a6cba6d774f6e244e07ff410e2 Mon Sep 17 00:00:00 2001 From: Bobby Christopher Date: Tue, 30 Sep 2025 12:58:00 -0400 Subject: [PATCH 1/2] added ff to config --- cmd/bundle.go | 6 ++++++ cmd/feature_flags.go | 48 ++++++++++++++++++++++++++++++++++++++++++++ cmd/root.go | 3 +++ cmd/version.go | 5 +++++ 4 files changed, 62 insertions(+) create mode 100644 cmd/feature_flags.go diff --git a/cmd/bundle.go b/cmd/bundle.go index b852cdd0..517ede0f 100644 --- a/cmd/bundle.go +++ b/cmd/bundle.go @@ -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 IsPromptsEvalsEnabled() { + projectContext.Logger.Info("Prompts evaluations feature is enabled") + } + production, _ := cmd.Flags().GetBool("production") install, _ := cmd.Flags().GetBool("install") deploy, _ := cmd.Flags().GetBool("deploy") diff --git a/cmd/feature_flags.go b/cmd/feature_flags.go new file mode 100644 index 00000000..260e58bf --- /dev/null +++ b/cmd/feature_flags.go @@ -0,0 +1,48 @@ +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) { + // Set default values + viper.SetDefault("features.enable_prompts_evals", false) + // Add command line flags + rootCmd.PersistentFlags().Bool("enable-prompts-evals", false, "Enable prompts evals") + rootCmd.PersistentFlags().MarkHidden("enable-prompts-evals") + viper.BindPFlag("features.enable_prompts_evals", rootCmd.PersistentFlags().Lookup("enable-prompts-evals")) +} + +// Feature flag helper functions + +// IsFeatureEnabled checks if a feature flag is enabled +func IsFeatureEnabled(feature string) bool { + return viper.GetBool("features." + 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() +} diff --git a/cmd/root.go b/cmd/root.go index 40fe2b3a..434ef00f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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) } diff --git a/cmd/version.go b/cmd/version.go index 7b9150a7..3744d05c 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -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) } From 2836c504ea006a1b63102d6d30d903953d761a59 Mon Sep 17 00:00:00 2001 From: Bobby Christopher Date: Tue, 30 Sep 2025 13:29:31 -0400 Subject: [PATCH 2/2] clean up --- cmd/bundle.go | 2 +- cmd/feature_flags.go | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cmd/bundle.go b/cmd/bundle.go index 517ede0f..0c067a59 100644 --- a/cmd/bundle.go +++ b/cmd/bundle.go @@ -40,7 +40,7 @@ Examples: projectContext := project.EnsureProject(ctx, cmd) // Check for prompts evals feature flag - if IsPromptsEvalsEnabled() { + if CheckFeatureFlag(cmd, FeaturePromptsEvals, "enable-prompts-evals") { projectContext.Logger.Info("Prompts evaluations feature is enabled") } diff --git a/cmd/feature_flags.go b/cmd/feature_flags.go index 260e58bf..d6785c92 100644 --- a/cmd/feature_flags.go +++ b/cmd/feature_flags.go @@ -12,19 +12,38 @@ const ( // SetupFeatureFlags initializes feature flag configuration and command line flags func SetupFeatureFlags(rootCmd *cobra.Command) { - // Set default values - viper.SetDefault("features.enable_prompts_evals", false) - // Add command line flags + // 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") - viper.BindPFlag("features.enable_prompts_evals", rootCmd.PersistentFlags().Lookup("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 { - return viper.GetBool("features." + feature) + 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