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
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func runRoot(_ *cobra.Command, args []string) error {
return nil
},
}
cfg.Explain = explainFlag
return interactiveRun(Version, cmds, cfg, client, shellInfo)
}

Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions internal/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Expand Down