diff --git a/cmd/root.go b/cmd/root.go index d82a0b6..20c2ab0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -165,6 +165,7 @@ func runRoot(_ *cobra.Command, args []string) error { return nil }, } + cfg.Explain = explainFlag return interactiveRun(Version, cmds, cfg, client, shellInfo) } diff --git a/internal/config/config.go b/internal/config/config.go index 31613ee..619d4eb 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -22,6 +22,7 @@ type Config struct { Provider ProviderConfig `toml:"provider"` Safety SafetyConfig `toml:"safety"` Debug string `toml:"debug"` // "none", "screen", or "file" + Explain bool `toml:"-"` // runtime-only; set from CLI flag, not persisted } type ProviderConfig struct { diff --git a/internal/executor/executor.go b/internal/executor/executor.go index 514f026..a7722fb 100644 --- a/internal/executor/executor.go +++ b/internal/executor/executor.go @@ -44,7 +44,7 @@ func Run(commands []llm.Command, cfg *config.Config, shellInfo shell.Info, expla dimColor.Printf(" %d%% certainty\n", cmd.Certainty) if explain && cmd.Explanation != "" { - dimColor.Printf(" 💡 %s\n", cmd.Explanation) + dimColor.Fprintf(os.Stdout, " 💡 %s\n", cmd.Explanation) } if ShouldConfirm(cmd, cfg) { diff --git a/internal/executor/executor_test.go b/internal/executor/executor_test.go index adeba5c..ae8b60d 100644 --- a/internal/executor/executor_test.go +++ b/internal/executor/executor_test.go @@ -131,12 +131,13 @@ func TestRunExecutesSafeCommandWithoutConfirmation(t *testing.T) { func TestRunWithExplainTrue(t *testing.T) { cfg := defaultSafetyCfg() + const explanationText = "Unique explanation string that only appears in the explanation output." cmds := []llm.Command{{ - Command: "echo explain-test", + Command: "echo hello", Description: "echo with explanation", Risk: "safe", Certainty: 100, - Explanation: "Prints the text 'explain-test' to stdout.", + Explanation: explanationText, }} // Capture stdout to verify explanation is printed @@ -160,7 +161,7 @@ func TestRunWithExplainTrue(t *testing.T) { t.Fatalf("Run() error = %v, want nil", runErr) } output := buf.String() - if !strings.Contains(output, "explain-test") { + if !strings.Contains(output, explanationText) { t.Errorf("output missing explanation text:\n%s", output) } }