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:
parent
98eb5505a5
commit
f540f5fc24
18
cmd/agent.go
18
cmd/agent.go
@ -1,4 +1,3 @@
|
|||||||
// Last modified: 2026-02-28 22:43:17 GMT
|
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -6,7 +5,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -76,24 +74,14 @@ var agentCmd = &cobra.Command{
|
|||||||
backupPath := file + ".bak"
|
backupPath := file + ".bak"
|
||||||
_ = os.WriteFile(backupPath, original, 0644)
|
_ = 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{
|
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": "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\n\nNOTE: Ensure the file starts with the required header comment followed by a blank line.", filepath.Base(file), original, instruction)},
|
{"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")
|
raw := client.StreamSilent(messages, "grok-4-1-fast-non-reasoning")
|
||||||
newContent := grok.CleanCodeResponse(raw)
|
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))
|
color.Cyan("Proposed changes for %s:", filepath.Base(file))
|
||||||
fmt.Println("--- a/" + filepath.Base(file))
|
fmt.Println("--- a/" + filepath.Base(file))
|
||||||
fmt.Println("+++ b/" + 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.")
|
color.Green("\n🎉 Agent mode complete! All changes applied.")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
11
cmd/chat.go
11
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
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -124,10 +120,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, tea.Batch(cmds...)
|
return m, tea.Batch(cmds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildHistoryView applies colors and ensures wrapping
|
|
||||||
func buildHistoryView(lines []string) string {
|
func buildHistoryView(lines []string) string {
|
||||||
userStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("33")) // blue
|
userStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("33"))
|
||||||
grokStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("10")) // green
|
grokStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("10"))
|
||||||
|
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
@ -180,4 +175,4 @@ func (m model) View() string {
|
|||||||
m.viewport.View(),
|
m.viewport.View(),
|
||||||
m.textarea.View(),
|
m.textarea.View(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -49,4 +46,4 @@ var commitCmd = &cobra.Command{
|
|||||||
color.Green("✅ Committed successfully!")
|
color.Green("✅ Committed successfully!")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,3 @@
|
|||||||
// Last modified: 2026-02-28 22:43:38 GMT
|
|
||||||
// Current time: 2024-08-07 10:00:00
|
|
||||||
|
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -33,4 +30,4 @@ var commitMsgCmd = &cobra.Command{
|
|||||||
color.Yellow("Generating commit message...")
|
color.Yellow("Generating commit message...")
|
||||||
client.Stream(messages, model)
|
client.Stream(messages, model)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
27
cmd/edit.go
27
cmd/edit.go
@ -1,11 +1,10 @@
|
|||||||
// Last modified: 2026-02-28 22:43:40 GMT
|
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -30,24 +29,24 @@ var editCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
original, _ := os.ReadFile(filePath)
|
original, _ := os.ReadFile(filePath)
|
||||||
|
cleanedOriginal := removeLastModifiedComments(string(original))
|
||||||
|
|
||||||
backupPath := filePath + ".bak"
|
backupPath := filePath + ".bak"
|
||||||
_ = os.WriteFile(backupPath, original, 0644)
|
_ = os.WriteFile(backupPath, original, 0644)
|
||||||
|
|
||||||
client := grok.NewClient()
|
client := grok.NewClient()
|
||||||
messages := []map[string]string{
|
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": "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), original, instruction)},
|
{"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)
|
color.Yellow("Asking Grok to %s...", instruction)
|
||||||
raw := client.Stream(messages, model)
|
raw := client.Stream(messages, model)
|
||||||
newContent := grok.CleanCodeResponse(raw)
|
newContent := grok.CleanCodeResponse(raw)
|
||||||
|
|
||||||
// Nice unified diff preview
|
|
||||||
color.Cyan("\nProposed changes:")
|
color.Cyan("\nProposed changes:")
|
||||||
fmt.Println("--- a/" + filepath.Base(filePath))
|
fmt.Println("--- a/" + filepath.Base(filePath))
|
||||||
fmt.Println("+++ b/" + filepath.Base(filePath))
|
fmt.Println("+++ b/" + filepath.Base(filePath))
|
||||||
// simple diff output (you can make it fancier later)
|
|
||||||
fmt.Print(newContent)
|
fmt.Print(newContent)
|
||||||
|
|
||||||
fmt.Print("\n\nApply these changes? (y/n): ")
|
fmt.Print("\n\nApply these changes? (y/n): ")
|
||||||
@ -61,4 +60,18 @@ var editCmd = &cobra.Command{
|
|||||||
_ = os.WriteFile(filePath, []byte(newContent), 0644)
|
_ = os.WriteFile(filePath, []byte(newContent), 0644)
|
||||||
color.Green("✅ Applied successfully! Backup: %s", backupPath)
|
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")
|
||||||
|
}
|
||||||
|
|||||||
@ -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
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -32,4 +29,4 @@ var historyCmd = &cobra.Command{
|
|||||||
color.Yellow("Summarizing recent commits...")
|
color.Yellow("Summarizing recent commits...")
|
||||||
client.Stream(messages, model)
|
client.Stream(messages, model)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,3 @@
|
|||||||
// Last modified: 2026-02-28 22:43:48 GMT
|
|
||||||
// Current time: 2023-10-05 14:30:00
|
|
||||||
|
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -36,4 +33,4 @@ var prDescribeCmd = &cobra.Command{
|
|||||||
color.Yellow("Writing PR description...")
|
color.Yellow("Writing PR description...")
|
||||||
client.Stream(messages, model)
|
client.Stream(messages, model)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,3 @@
|
|||||||
// Last modified: 2026-02-28 22:43:50 GMT
|
|
||||||
// Current time: 2024-09-07 10:00:00 UTC
|
|
||||||
|
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -31,4 +28,4 @@ var reviewCmd = &cobra.Command{
|
|||||||
color.Yellow("Grok is reviewing the repo...")
|
color.Yellow("Grok is reviewing the repo...")
|
||||||
client.Stream(messages, model)
|
client.Stream(messages, model)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
// Last modified: 2026-02-28 22:43:53 GMT
|
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -33,4 +32,4 @@ func init() {
|
|||||||
rootCmd.AddCommand(historyCmd)
|
rootCmd.AddCommand(historyCmd)
|
||||||
rootCmd.AddCommand(agentCmd)
|
rootCmd.AddCommand(agentCmd)
|
||||||
chatCmd.Flags().StringP("model", "m", "", "Grok model to use (overrides config)")
|
chatCmd.Flags().StringP("model", "m", "", "Grok model to use (overrides config)")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,3 @@
|
|||||||
// Last modified: 2026-02-28 22:43:55 GMT
|
|
||||||
// Updated at 2024-08-27 12:00:00 UTC
|
|
||||||
|
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -18,22 +15,20 @@ func Load() {
|
|||||||
viper.SetConfigType("toml")
|
viper.SetConfigType("toml")
|
||||||
viper.AddConfigPath(configPath)
|
viper.AddConfigPath(configPath)
|
||||||
viper.AddConfigPath(".")
|
viper.AddConfigPath(".")
|
||||||
viper.AutomaticEnv() // XAI_API_KEY etc.
|
viper.AutomaticEnv()
|
||||||
|
|
||||||
viper.SetDefault("default_model", "grok-4")
|
viper.SetDefault("default_model", "grok-4")
|
||||||
viper.SetDefault("temperature", 0.7)
|
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 {
|
func GetModel(flagModel string) string {
|
||||||
if flagModel != "" {
|
if flagModel != "" {
|
||||||
// Check alias first
|
|
||||||
if alias := viper.GetString("aliases." + flagModel); alias != "" {
|
if alias := viper.GetString("aliases." + flagModel); alias != "" {
|
||||||
return alias
|
return alias
|
||||||
}
|
}
|
||||||
return flagModel
|
return flagModel
|
||||||
}
|
}
|
||||||
return viper.GetString("default_model")
|
return viper.GetString("default_model")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,3 @@
|
|||||||
// Last modified: 2026-02-28 22:43:57 GMT
|
|
||||||
// Current time: 2023-10-05 14:30:00 UTC
|
|
||||||
|
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import "os/exec"
|
import "os/exec"
|
||||||
@ -13,4 +10,4 @@ func Run(args []string) string {
|
|||||||
func IsRepo() bool {
|
func IsRepo() bool {
|
||||||
_, err := exec.Command("git", "rev-parse", "--is-inside-work-tree").Output()
|
_, err := exec.Command("git", "rev-parse", "--is-inside-work-tree").Output()
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
// Last modified: 2026-02-28 22:43:59 GMT
|
|
||||||
package grok
|
package grok
|
||||||
|
|
||||||
import (
|
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 {
|
func (c *Client) Stream(messages []map[string]string, model string) string {
|
||||||
return c.streamInternal(messages, model, true)
|
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 {
|
func (c *Client) StreamSilent(messages []map[string]string, model string) string {
|
||||||
return c.streamInternal(messages, model, false)
|
return c.streamInternal(messages, model, false)
|
||||||
}
|
}
|
||||||
@ -91,10 +88,9 @@ func (c *Client) streamInternal(messages []map[string]string, model string, prin
|
|||||||
return fullReply.String()
|
return fullReply.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanCodeResponse removes markdown fences and returns pure code content
|
|
||||||
func CleanCodeResponse(text string) string {
|
func CleanCodeResponse(text string) string {
|
||||||
text = strings.ReplaceAll(text, "", "")
|
text = strings.ReplaceAll(text, "", "")
|
||||||
text = strings.ReplaceAll(text, "", "")
|
text = strings.ReplaceAll(text, "", "")
|
||||||
text = strings.TrimSpace(text)
|
text = strings.TrimSpace(text)
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user