chore(headers): add last modified timestamps to source files

Implemented automatic addition of "// Last modified: [timestamp]" headers across command and internal files for better tracking. Updated prompts in agent and edit commands to enforce header format. Added logic to prepend header if missing in generated content. Fixed minor issues like missing newlines at end of files.
This commit is contained in:
Greg Gauthier 2026-02-28 22:47:30 +00:00
parent ed614ae0db
commit 98eb5505a5
13 changed files with 29 additions and 9 deletions

View File

@ -1,3 +1,4 @@
// Last modified: 2026-02-28 22:43:17 GMT
package cmd package cmd
import ( import (
@ -77,14 +78,22 @@ var agentCmd = &cobra.Command{
currentTime := time.Now().Format("2006-01-02 15:04:05 MST") 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": 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", filepath.Base(file), original, instruction)}, {"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)},
} }
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))
@ -110,4 +119,4 @@ var agentCmd = &cobra.Command{
color.Green("\n🎉 Agent mode complete! All changes applied.") color.Green("\n🎉 Agent mode complete! All changes applied.")
}, },
} }

View File

@ -1,3 +1,4 @@
// Last modified: 2026-02-28 22:43:28 GMT
// Owned by gmgauthier.com // Owned by gmgauthier.com
// Current time: 2023-10-05 14:30:00 UTC // Current time: 2023-10-05 14:30:00 UTC

View File

@ -1,3 +1,4 @@
// Last modified: 2026-02-28 22:43:36 GMT
// Updated at current time: 2023-10-05 14:30:00 UTC // Updated at current time: 2023-10-05 14:30:00 UTC
package cmd package cmd

View File

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

View File

@ -1,11 +1,11 @@
// Current time: 2024-08-18 15:00:00 // Last modified: 2026-02-28 22:43:40 GMT
package cmd package cmd
import ( import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"time"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -35,7 +35,7 @@ var editCmd = &cobra.Command{
client := grok.NewClient() client := grok.NewClient()
messages := []map[string]string{ messages := []map[string]string{
{"role": "system", "content": "Return ONLY the complete updated file content. No explanations, no markdown fences, no diffs, no extra text whatsoever."}, {"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": "user", "content": fmt.Sprintf("File: %s\n\nOriginal content:\n%s\n\nTask: %s", filepath.Base(filePath), original, instruction)},
} }

View File

@ -1,3 +1,4 @@
// Last modified: 2026-02-28 22:43:46 GMT
// Updated at current time: 2023-10-05 14:32:00 UTC // Updated at current time: 2023-10-05 14:32:00 UTC
package cmd package cmd

View File

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

View File

@ -1,3 +1,4 @@
// Last modified: 2026-02-28 22:43:50 GMT
// Current time: 2024-09-07 10:00:00 UTC // Current time: 2024-09-07 10:00:00 UTC
package cmd package cmd

View File

@ -1,3 +1,4 @@
// Last modified: 2026-02-28 22:43:53 GMT
package cmd package cmd
import ( import (
@ -32,4 +33,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)")
} }

View File

@ -1,3 +1,4 @@
// Last modified: 2026-02-28 22:43:55 GMT
// Updated at 2024-08-27 12:00:00 UTC // Updated at 2024-08-27 12:00:00 UTC
package config package config

View File

@ -1,3 +1,4 @@
// Last modified: 2026-02-28 22:43:57 GMT
// Current time: 2023-10-05 14:30:00 UTC // Current time: 2023-10-05 14:30:00 UTC
package git package git

View File

@ -1,3 +1,4 @@
// Last modified: 2026-02-28 22:43:59 GMT
package grok package grok
import ( import (
@ -92,8 +93,8 @@ func (c *Client) streamInternal(messages []map[string]string, model string, prin
// CleanCodeResponse removes markdown fences and returns pure code content // CleanCodeResponse removes markdown fences and returns pure code content
func CleanCodeResponse(text string) string { func CleanCodeResponse(text string) string {
text = strings.ReplaceAll(text, "```go", "") text = strings.ReplaceAll(text, "", "")
text = strings.ReplaceAll(text, "```", "") text = strings.ReplaceAll(text, "", "")
text = strings.TrimSpace(text) text = strings.TrimSpace(text)
return text return text
} }

View File

@ -1,3 +1,4 @@
// Last modified: 2026-02-28 22:44:03 GMT
// Updated at current time: 2023-10-05 12:00:00 UTC // Updated at current time: 2023-10-05 12:00:00 UTC
package main package main