feat(cmd): add query command for one-shot technical questions

- Implement new `query` command in cmd/query.go for non-interactive Grok queries focused on programming
- Add wordy flag for detailed responses
- Update root.go to include queryCmd
- Set default model for query in config.go
- Add .grok/settings.json with fast model configuration
This commit is contained in:
Gregory Gauthier 2026-03-04 15:39:41 +00:00
parent 5bf6b0c91c
commit cc6a2f642f
4 changed files with 58 additions and 0 deletions

3
.grok/settings.json Normal file
View File

@ -0,0 +1,3 @@
{
"model": "grok-code-fast-1"
}

53
cmd/query.go Normal file
View File

@ -0,0 +1,53 @@
package cmd
import (
"github.com/fatih/color"
"github.com/spf13/cobra"
"gmgauthier.com/grokkit/config"
"gmgauthier.com/grokkit/internal/grok"
)
var queryCmd = &cobra.Command{
Use: "query [question]",
Short: "One-shot non-interactive query to Grok (programming focused)",
Long: `Ask Grok a single technical question and get a concise, actionable answer.
Default mode is factual and brief. Use --wordy for longer, more explanatory answers.`,
Args: cobra.MinimumNArgs(1),
Run: runQuery,
}
func init() {
queryCmd.Flags().Bool("wordy", false, "Give a longer, more detailed answer")
rootCmd.AddCommand(queryCmd)
}
func runQuery(cmd *cobra.Command, args []string) {
wordy, _ := cmd.Flags().GetBool("wordy")
question := args[0]
// Use fast model by default for quick queries
model := config.GetModel("query", "")
client := grok.NewClient()
systemPrompt := `You are Grok, a helpful and truthful AI built by xAI.
Focus on programming, software engineering, and technical questions.
Be concise, factual, and actionable. Include code snippets when helpful.
Do not add unnecessary fluff.`
if wordy {
systemPrompt = `You are Grok, a helpful and truthful AI built by xAI.
Give thorough, detailed, textbook-style answers to technical questions.
Explain concepts clearly, include examples, and allow light humour where appropriate.
Be comprehensive but still clear and well-structured.`
}
messages := []map[string]string{
{"role": "system", "content": systemPrompt},
{"role": "user", "content": question},
}
color.Yellow("Asking Grok...")
client.Stream(messages, model)
}

View File

@ -60,6 +60,7 @@ func init() {
rootCmd.AddCommand(docsCmd) rootCmd.AddCommand(docsCmd)
rootCmd.AddCommand(testgenCmd) rootCmd.AddCommand(testgenCmd)
rootCmd.AddCommand(scaffoldCmd) rootCmd.AddCommand(scaffoldCmd)
rootCmd.AddCommand(queryCmd)
// Add model flag to all commands // Add model flag to all commands
rootCmd.PersistentFlags().StringP("model", "m", "", "Grok model to use (overrides config)") rootCmd.PersistentFlags().StringP("model", "m", "", "Grok model to use (overrides config)")

View File

@ -36,6 +36,7 @@ func Load() {
viper.SetDefault("commands.prdescribe.model", "grok-4") viper.SetDefault("commands.prdescribe.model", "grok-4")
viper.SetDefault("commands.review.model", "grok-4") viper.SetDefault("commands.review.model", "grok-4")
viper.SetDefault("commands.docs.model", "grok-4") viper.SetDefault("commands.docs.model", "grok-4")
viper.SetDefault("commands.query.model", "grok-4-1-fast-non-reasoning")
// Config file is optional, so we ignore read errors // Config file is optional, so we ignore read errors
_ = viper.ReadInConfig() _ = viper.ReadInConfig()