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
This commit is contained in:
Greg Gauthier 2026-02-28 22:59:16 +00:00
parent 98eb5505a5
commit f540f5fc24
13 changed files with 38 additions and 73 deletions

View File

@ -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))

View File

@ -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 {

View File

@ -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 (

View File

@ -1,6 +1,3 @@
// Last modified: 2026-02-28 22:43:38 GMT
// Current time: 2024-08-07 10:00:00
package cmd
import (

View File

@ -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): ")
@ -62,3 +61,17 @@ var editCmd = &cobra.Command{
color.Green("✅ Applied successfully! Backup: %s", backupPath)
},
}
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")
}

View File

@ -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 (

View File

@ -1,6 +1,3 @@
// Last modified: 2026-02-28 22:43:48 GMT
// Current time: 2023-10-05 14:30:00
package cmd
import (

View File

@ -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 (

View File

@ -1,4 +1,3 @@
// Last modified: 2026-02-28 22:43:53 GMT
package cmd
import (

View File

@ -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,18 +15,16 @@ 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
}

View File

@ -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"

View File

@ -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,7 +88,6 @@ 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, "", "")

View File

@ -1,6 +1,3 @@
// 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"