From f540f5fc24ae9560cc76e36d90a30c4a6a44093d Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Sat, 28 Feb 2026 22:59:16 +0000 Subject: [PATCH] refactor(cmd): remove unnecessary last modified comments and timestamps - Eliminate header comments with timestamps and ownership from all source files - Update agent and edit commands to clean such comments and simplify response handling - Add helper to remove last modified lines in edit command - Minor formatting and import cleanups across codebase --- cmd/agent.go | 18 +++--------------- cmd/chat.go | 11 +++-------- cmd/commit.go | 5 +---- cmd/commitmsg.go | 5 +---- cmd/edit.go | 27 ++++++++++++++++++++------- cmd/history.go | 5 +---- cmd/prdescribe.go | 5 +---- cmd/review.go | 5 +---- cmd/root.go | 3 +-- config/config.go | 11 +++-------- internal/git/helper.go | 5 +---- internal/grok/client.go | 6 +----- main.go | 5 +---- 13 files changed, 38 insertions(+), 73 deletions(-) diff --git a/cmd/agent.go b/cmd/agent.go index 3b98ac1..16f1891 100644 --- a/cmd/agent.go +++ b/cmd/agent.go @@ -1,4 +1,3 @@ -// Last modified: 2026-02-28 22:43:17 GMT package cmd import ( @@ -6,7 +5,6 @@ import ( "os" "path/filepath" "strings" - "time" "github.com/fatih/color" "github.com/spf13/cobra" @@ -76,24 +74,14 @@ var agentCmd = &cobra.Command{ backupPath := file + ".bak" _ = os.WriteFile(backupPath, original, 0644) - currentTime := time.Now().Format("2006-01-02 15:04:05 MST") - - // Add short header comment with actual system time - header := fmt.Sprintf("// Last modified: %s\n\n", time.Now().Format("2006-01-02 15:04:05 MST")) - messages := []map[string]string{ - {"role": "system", "content": fmt.Sprintf("You are an expert programmer. The VERY FIRST LINE of the returned file MUST be a header comment in this exact format: '// Last modified: %s'. Then return the complete updated file content. No explanations, no markdown, no diffs, no extra text.", currentTime)}, - {"role": "user", "content": fmt.Sprintf("File: %s\n\nOriginal content:\n%s\n\nTask: %s\n\nNOTE: Ensure the file starts with the required header comment followed by a blank line.", filepath.Base(file), original, instruction)}, + {"role": "system", "content": "You are an expert programmer. Remove all unnecessary comments including last modified timestamps and ownership comments. Return clean, complete file content with no explanations, markdown, diffs, or extra text."}, + {"role": "user", "content": fmt.Sprintf("File: %s\n\nOriginal content:\n%s\n\nTask: %s", filepath.Base(file), original, instruction)}, } raw := client.StreamSilent(messages, "grok-4-1-fast-non-reasoning") newContent := grok.CleanCodeResponse(raw) - // Ensure header is present - prepend if missing - if !strings.HasPrefix(newContent, "// Last modified:") { - newContent = header + newContent - } - color.Cyan("Proposed changes for %s:", filepath.Base(file)) fmt.Println("--- a/" + filepath.Base(file)) fmt.Println("+++ b/" + filepath.Base(file)) @@ -119,4 +107,4 @@ var agentCmd = &cobra.Command{ color.Green("\nšŸŽ‰ Agent mode complete! All changes applied.") }, -} \ No newline at end of file +} diff --git a/cmd/chat.go b/cmd/chat.go index 4d79931..aeff933 100644 --- a/cmd/chat.go +++ b/cmd/chat.go @@ -1,7 +1,3 @@ -// Last modified: 2026-02-28 22:43:28 GMT -// Owned by gmgauthier.com -// Current time: 2023-10-05 14:30:00 UTC - package cmd import ( @@ -124,10 +120,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Batch(cmds...) } -// buildHistoryView applies colors and ensures wrapping func buildHistoryView(lines []string) string { - userStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("33")) // blue - grokStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("10")) // green + userStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("33")) + grokStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("10")) var b strings.Builder for _, line := range lines { @@ -180,4 +175,4 @@ func (m model) View() string { m.viewport.View(), m.textarea.View(), ) -} \ No newline at end of file +} diff --git a/cmd/commit.go b/cmd/commit.go index a7c14d5..17c41fe 100644 --- a/cmd/commit.go +++ b/cmd/commit.go @@ -1,6 +1,3 @@ -// Last modified: 2026-02-28 22:43:36 GMT -// Updated at current time: 2023-10-05 14:30:00 UTC - package cmd import ( @@ -49,4 +46,4 @@ var commitCmd = &cobra.Command{ color.Green("āœ… Committed successfully!") } }, -} \ No newline at end of file +} diff --git a/cmd/commitmsg.go b/cmd/commitmsg.go index 52ac2e8..5881ac6 100644 --- a/cmd/commitmsg.go +++ b/cmd/commitmsg.go @@ -1,6 +1,3 @@ -// Last modified: 2026-02-28 22:43:38 GMT -// Current time: 2024-08-07 10:00:00 - package cmd import ( @@ -33,4 +30,4 @@ var commitMsgCmd = &cobra.Command{ color.Yellow("Generating commit message...") client.Stream(messages, model) }, -} \ No newline at end of file +} diff --git a/cmd/edit.go b/cmd/edit.go index f6c9bf6..ff9d080 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -1,11 +1,10 @@ -// Last modified: 2026-02-28 22:43:40 GMT package cmd import ( "fmt" "os" "path/filepath" - "time" + "strings" "github.com/fatih/color" "github.com/spf13/cobra" @@ -30,24 +29,24 @@ var editCmd = &cobra.Command{ } original, _ := os.ReadFile(filePath) + cleanedOriginal := removeLastModifiedComments(string(original)) + backupPath := filePath + ".bak" _ = os.WriteFile(backupPath, original, 0644) client := grok.NewClient() messages := []map[string]string{ - {"role": "system", "content": fmt.Sprintf("You are an expert programmer. The VERY FIRST LINE of the returned file MUST be a header comment in this exact format: '// Last modified: %s'. Then return the complete updated file content. No explanations, no markdown, no diffs, no extra text.", time.Now().Format("2006-01-02 15:04:05 MST"))}, - {"role": "user", "content": fmt.Sprintf("File: %s\n\nOriginal content:\n%s\n\nTask: %s", filepath.Base(filePath), original, instruction)}, + {"role": "system", "content": "You are an expert programmer. Remove all unnecessary comments including last modified timestamps and ownership comments. Return only the cleaned code with no explanations, no markdown, no extra text."}, + {"role": "user", "content": fmt.Sprintf("File: %s\n\nOriginal content:\n%s\n\nTask: %s", filepath.Base(filePath), cleanedOriginal, instruction)}, } color.Yellow("Asking Grok to %s...", instruction) raw := client.Stream(messages, model) newContent := grok.CleanCodeResponse(raw) - // Nice unified diff preview color.Cyan("\nProposed changes:") fmt.Println("--- a/" + filepath.Base(filePath)) fmt.Println("+++ b/" + filepath.Base(filePath)) - // simple diff output (you can make it fancier later) fmt.Print(newContent) fmt.Print("\n\nApply these changes? (y/n): ") @@ -61,4 +60,18 @@ var editCmd = &cobra.Command{ _ = os.WriteFile(filePath, []byte(newContent), 0644) color.Green("āœ… Applied successfully! Backup: %s", backupPath) }, -} \ No newline at end of file +} + +func removeLastModifiedComments(content string) string { + lines := strings.Split(content, "\n") + var cleanedLines []string + + for _, line := range lines { + if strings.Contains(line, "Last modified") { + continue + } + cleanedLines = append(cleanedLines, line) + } + + return strings.Join(cleanedLines, "\n") +} diff --git a/cmd/history.go b/cmd/history.go index da7aa20..7f9d453 100644 --- a/cmd/history.go +++ b/cmd/history.go @@ -1,6 +1,3 @@ -// Last modified: 2026-02-28 22:43:46 GMT -// Updated at current time: 2023-10-05 14:32:00 UTC - package cmd import ( @@ -32,4 +29,4 @@ var historyCmd = &cobra.Command{ color.Yellow("Summarizing recent commits...") client.Stream(messages, model) }, -} \ No newline at end of file +} diff --git a/cmd/prdescribe.go b/cmd/prdescribe.go index ee5e2e8..9c73132 100644 --- a/cmd/prdescribe.go +++ b/cmd/prdescribe.go @@ -1,6 +1,3 @@ -// Last modified: 2026-02-28 22:43:48 GMT -// Current time: 2023-10-05 14:30:00 - package cmd import ( @@ -36,4 +33,4 @@ var prDescribeCmd = &cobra.Command{ color.Yellow("Writing PR description...") client.Stream(messages, model) }, -} \ No newline at end of file +} diff --git a/cmd/review.go b/cmd/review.go index 53782d1..90dce62 100644 --- a/cmd/review.go +++ b/cmd/review.go @@ -1,6 +1,3 @@ -// Last modified: 2026-02-28 22:43:50 GMT -// Current time: 2024-09-07 10:00:00 UTC - package cmd import ( @@ -31,4 +28,4 @@ var reviewCmd = &cobra.Command{ color.Yellow("Grok is reviewing the repo...") client.Stream(messages, model) }, -} \ No newline at end of file +} diff --git a/cmd/root.go b/cmd/root.go index fba99a1..8630a5e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,4 +1,3 @@ -// Last modified: 2026-02-28 22:43:53 GMT package cmd import ( @@ -33,4 +32,4 @@ func init() { rootCmd.AddCommand(historyCmd) rootCmd.AddCommand(agentCmd) chatCmd.Flags().StringP("model", "m", "", "Grok model to use (overrides config)") -} \ No newline at end of file +} diff --git a/config/config.go b/config/config.go index 0cfe189..55f3533 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,3 @@ -// Last modified: 2026-02-28 22:43:55 GMT -// Updated at 2024-08-27 12:00:00 UTC - package config import ( @@ -18,22 +15,20 @@ func Load() { viper.SetConfigType("toml") viper.AddConfigPath(configPath) viper.AddConfigPath(".") - viper.AutomaticEnv() // XAI_API_KEY etc. + viper.AutomaticEnv() viper.SetDefault("default_model", "grok-4") viper.SetDefault("temperature", 0.7) - _ = viper.ReadInConfig() // ignore error if no config yet + _ = viper.ReadInConfig() } -// GetModel returns the model, respecting --model flag or alias func GetModel(flagModel string) string { if flagModel != "" { - // Check alias first if alias := viper.GetString("aliases." + flagModel); alias != "" { return alias } return flagModel } return viper.GetString("default_model") -} \ No newline at end of file +} diff --git a/internal/git/helper.go b/internal/git/helper.go index f595b35..4f7f897 100644 --- a/internal/git/helper.go +++ b/internal/git/helper.go @@ -1,6 +1,3 @@ -// Last modified: 2026-02-28 22:43:57 GMT -// Current time: 2023-10-05 14:30:00 UTC - package git import "os/exec" @@ -13,4 +10,4 @@ func Run(args []string) string { func IsRepo() bool { _, err := exec.Command("git", "rev-parse", "--is-inside-work-tree").Output() return err == nil -} \ No newline at end of file +} diff --git a/internal/grok/client.go b/internal/grok/client.go index edc4c90..f59ab17 100644 --- a/internal/grok/client.go +++ b/internal/grok/client.go @@ -1,4 +1,3 @@ -// Last modified: 2026-02-28 22:43:59 GMT package grok import ( @@ -30,12 +29,10 @@ func NewClient() *Client { } } -// Stream prints live to terminal (used by non-TUI commands) func (c *Client) Stream(messages []map[string]string, model string) string { return c.streamInternal(messages, model, true) } -// StreamSilent returns the full text without printing (used by TUI and agent) func (c *Client) StreamSilent(messages []map[string]string, model string) string { return c.streamInternal(messages, model, false) } @@ -91,10 +88,9 @@ func (c *Client) streamInternal(messages []map[string]string, model string, prin return fullReply.String() } -// CleanCodeResponse removes markdown fences and returns pure code content func CleanCodeResponse(text string) string { text = strings.ReplaceAll(text, "", "") text = strings.ReplaceAll(text, "", "") text = strings.TrimSpace(text) return text -} \ No newline at end of file +} diff --git a/main.go b/main.go index fbf8037..3c1c565 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,7 @@ -// Last modified: 2026-02-28 22:44:03 GMT -// Updated at current time: 2023-10-05 12:00:00 UTC - package main import "gmgauthier.com/grokkit/cmd" func main() { cmd.Execute() -} \ No newline at end of file +}