From 1c9a20744446b612ddac274d4d9033ed57a5b66e Mon Sep 17 00:00:00 2001 From: Molecule AI SDK-Dev Date: Wed, 22 Apr 2026 18:52:05 +0000 Subject: [PATCH] fix(cli): fix undefined v in runConfigSet v.SafeWriteConfig() was called without a local viper instance. Create a fresh viper scoped to the target config file, read any existing values, set the new key, then atomically write via SafeWriteConfig. Co-Authored-By: Claude Sonnet 4.6 --- internal/cmd/config.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/cmd/config.go b/internal/cmd/config.go index caf16d8..6514bc0 100644 --- a/internal/cmd/config.go +++ b/internal/cmd/config.go @@ -98,9 +98,12 @@ func runConfigSet(cmd *cobra.Command, args []string) error { } configFile := filepath.Join(configDir, "molecule.yaml") - // Use SafeWriteConfig to atomically write key=value to the config file. - // SafeWriteConfig only writes keys that were explicitly set (not defaults), - // and refuses to overwrite an existing file unless it's explicitly asked. + // Create a fresh viper instance scoped to the target config file. + // Read existing values (if any), set the new key, then atomically write. + v := viper.New() + v.SetConfigFile(configFile) + _ = v.ReadInConfig() // ignore not-found; we write only the new key below + v.Set(key, value) if err := v.SafeWriteConfig(); err != nil { return fmt.Errorf("config set: write %s: %w", configFile, err) }