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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ ShellTime CLI configuration is stored in `$HOME/.shelltime/config.toml`. The con
| `ai.agent.view` | boolean | `false` | Allow AI to auto-execute read-only commands |
| `ai.agent.edit` | boolean | `false` | Allow AI to auto-execute file editing commands |
| `ai.agent.delete` | boolean | `false` | Allow AI to auto-execute deletion commands |
| `ai.showTips` | boolean | `true` | Show AI-related tips and suggestions |

#### Analytics Settings

Expand Down Expand Up @@ -99,6 +100,9 @@ exclude = [

# AI configuration (optional)
# Controls which command types the AI assistant can automatically execute
[ai]
showTips = true # Show AI-related tips and suggestions (default: true)

[ai.agent]
view = false # Allow AI to execute read-only commands (ls, cat, less, head, tail, etc.)
edit = false # Allow AI to execute file editing commands (vim, nano, code, sed, etc.)
Expand Down
22 changes: 16 additions & 6 deletions commands/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,21 @@ func commandQuery(c *cli.Context) error {
} else {
// Display command with info about why it's not auto-running
displayCommand(newCommand)
if actionType != model.ActionOther {
if shouldShowTips(cfg) && actionType != model.ActionOther {
color.Yellow.Printf("\n💡 Tip: This is a %s command. Enable 'ai.agent.%s' in your config to auto-run it.\n",
actionType, actionType)
}
}
} else {
// No auto-run configured, display the command and tip
displayCommand(newCommand)
color.Yellow.Printf("\n💡 Tip: You can enable AI auto-run in your config file:\n")
color.Yellow.Printf(" [ai.agent]\n")
color.Yellow.Printf(" view = true # Auto-run view commands\n")
color.Yellow.Printf(" edit = true # Auto-run edit commands\n")
color.Yellow.Printf(" delete = true # Auto-run delete commands\n")
if shouldShowTips(cfg) {
color.Yellow.Printf("\n💡 Tip: You can enable AI auto-run in your config file:\n")
color.Yellow.Printf(" [ai.agent]\n")
color.Yellow.Printf(" view = true # Auto-run view commands\n")
color.Yellow.Printf(" edit = true # Auto-run edit commands\n")
color.Yellow.Printf(" delete = true # Auto-run delete commands\n")
Comment on lines +135 to +139
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved readability and to consolidate multiple function calls into one, you can combine these Printf statements into a single call.

Suggested change
color.Yellow.Printf("\n💡 Tip: You can enable AI auto-run in your config file:\n")
color.Yellow.Printf(" [ai.agent]\n")
color.Yellow.Printf(" view = true # Auto-run view commands\n")
color.Yellow.Printf(" edit = true # Auto-run edit commands\n")
color.Yellow.Printf(" delete = true # Auto-run delete commands\n")
color.Yellow.Printf("\n💡 Tip: You can enable AI auto-run in your config file:\n [ai.agent]\n view = true # Auto-run view commands\n edit = true # Auto-run edit commands\n delete = true # Auto-run delete commands\n")

}
}

return nil
Expand All @@ -146,6 +148,14 @@ func displayCommand(command string) {
color.Cyan.Printf("%s\n", command)
}

func shouldShowTips(cfg model.ShellTimeConfig) bool {
// If ShowTips is not set (nil), default to true
if cfg.AI == nil || cfg.AI.ShowTips == nil {
return true
}
return *cfg.AI.ShowTips
}

func executeCommand(ctx context.Context, command string) error {
// Get the shell to use
shell := os.Getenv("SHELL")
Expand Down
4 changes: 3 additions & 1 deletion model/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type AIAgentConfig struct {
}

type AIConfig struct {
Agent AIAgentConfig `toml:"agent"`
Agent AIAgentConfig `toml:"agent"`
ShowTips *bool `toml:"showTips"`
}

type CCUsage struct {
Expand Down Expand Up @@ -62,6 +63,7 @@ var DefaultAIConfig = &AIConfig{
Edit: false,
Delete: false,
},
ShowTips: nil, // defaults to true if nil
}

var DefaultConfig = ShellTimeConfig{
Expand Down
Loading