"Fix" isolate commands fucking each other (hallucinate)

This commit is contained in:
2025-10-23 00:13:14 +02:00
parent 635ca463c0
commit b9574f0106

32
main.go
View File

@@ -642,11 +642,13 @@ func RunIsolateCommands(association utils.FileCommandAssociation, file string, f
runIsolateCommandsLogger.Trace("File data before isolate modifications: %s", utils.LimitString(fileDataStr, 200)) runIsolateCommandsLogger.Trace("File data before isolate modifications: %s", utils.LimitString(fileDataStr, 200))
anythingDone := false anythingDone := false
currentFileData := fileDataStr
for _, isolateCommand := range association.IsolateCommands { for _, isolateCommand := range association.IsolateCommands {
// Check if this isolate command should use JSON mode // Check if this isolate command should use JSON mode
if isolateCommand.JSON || *utils.JSON { if isolateCommand.JSON || *utils.JSON {
runIsolateCommandsLogger.Debug("Begin processing file with JSON isolate command %q", isolateCommand.Name) runIsolateCommandsLogger.Debug("Begin processing file with JSON isolate command %q", isolateCommand.Name)
modifications, err := processor.ProcessJSON(fileDataStr, isolateCommand, file) modifications, err := processor.ProcessJSON(currentFileData, isolateCommand, file)
if err != nil { if err != nil {
runIsolateCommandsLogger.Error("Failed to process file with JSON isolate command %q: %v", isolateCommand.Name, err) runIsolateCommandsLogger.Error("Failed to process file with JSON isolate command %q: %v", isolateCommand.Name, err)
continue continue
@@ -661,15 +663,21 @@ func RunIsolateCommands(association utils.FileCommandAssociation, file string, f
runIsolateCommandsLogger.Debug("Executing %d JSON isolate modifications for file", len(modifications)) runIsolateCommandsLogger.Debug("Executing %d JSON isolate modifications for file", len(modifications))
runIsolateCommandsLogger.Trace("JSON isolate modifications: %v", modifications) runIsolateCommandsLogger.Trace("JSON isolate modifications: %v", modifications)
var count int var count int
fileDataStr, count = utils.ExecuteModifications(modifications, fileDataStr) currentFileData, count = utils.ExecuteModifications(modifications, currentFileData)
runIsolateCommandsLogger.Trace("File data after JSON isolate modifications: %s", utils.LimitString(fileDataStr, 200)) runIsolateCommandsLogger.Trace("File data after JSON isolate modifications: %s", utils.LimitString(currentFileData, 200))
atomic.AddInt64(&stats.TotalModifications, int64(count)) atomic.AddInt64(&stats.TotalModifications, int64(count))
cmdCount, ok := stats.ModificationsPerCommand.Load(isolateCommand.Name)
if !ok {
stats.ModificationsPerCommand.Store(isolateCommand.Name, 0)
cmdCount = 0
}
stats.ModificationsPerCommand.Store(isolateCommand.Name, cmdCount.(int)+len(modifications))
runIsolateCommandsLogger.Info("Executed %d JSON isolate modifications for file", count) runIsolateCommandsLogger.Info("Executed %d JSON isolate modifications for file", count)
} else { } else {
// Regular regex processing for isolate commands // Regular regex processing for isolate commands
runIsolateCommandsLogger.Debug("Begin processing file with isolate command %q", isolateCommand.Regex)
patterns := isolateCommand.Regexes patterns := isolateCommand.Regexes
if len(patterns) == 0 { if len(patterns) == 0 {
patterns = []string{isolateCommand.Regex} patterns = []string{isolateCommand.Regex}
@@ -677,7 +685,8 @@ func RunIsolateCommands(association utils.FileCommandAssociation, file string, f
for idx, pattern := range patterns { for idx, pattern := range patterns {
tmpCmd := isolateCommand tmpCmd := isolateCommand
tmpCmd.Regex = pattern tmpCmd.Regex = pattern
modifications, err := processor.ProcessRegex(fileDataStr, tmpCmd, file) runIsolateCommandsLogger.Debug("Begin processing file with isolate command %q (pattern %d/%d)", isolateCommand.Name, idx+1, len(patterns))
modifications, err := processor.ProcessRegex(currentFileData, tmpCmd, file)
if err != nil { if err != nil {
runIsolateCommandsLogger.Error("Failed to process file with isolate command %q (pattern %d/%d): %v", isolateCommand.Name, idx+1, len(patterns), err) runIsolateCommandsLogger.Error("Failed to process file with isolate command %q (pattern %d/%d): %v", isolateCommand.Name, idx+1, len(patterns), err)
continue continue
@@ -692,11 +701,18 @@ func RunIsolateCommands(association utils.FileCommandAssociation, file string, f
runIsolateCommandsLogger.Debug("Executing %d isolate modifications for file", len(modifications)) runIsolateCommandsLogger.Debug("Executing %d isolate modifications for file", len(modifications))
runIsolateCommandsLogger.Trace("Isolate modifications: %v", modifications) runIsolateCommandsLogger.Trace("Isolate modifications: %v", modifications)
var count int var count int
fileDataStr, count = utils.ExecuteModifications(modifications, fileDataStr) currentFileData, count = utils.ExecuteModifications(modifications, currentFileData)
runIsolateCommandsLogger.Trace("File data after isolate modifications: %s", utils.LimitString(fileDataStr, 200)) runIsolateCommandsLogger.Trace("File data after isolate modifications: %s", utils.LimitString(currentFileData, 200))
atomic.AddInt64(&stats.TotalModifications, int64(count)) atomic.AddInt64(&stats.TotalModifications, int64(count))
cmdCount, ok := stats.ModificationsPerCommand.Load(isolateCommand.Name)
if !ok {
stats.ModificationsPerCommand.Store(isolateCommand.Name, 0)
cmdCount = 0
}
stats.ModificationsPerCommand.Store(isolateCommand.Name, cmdCount.(int)+len(modifications))
runIsolateCommandsLogger.Info("Executed %d isolate modifications for file", count) runIsolateCommandsLogger.Info("Executed %d isolate modifications for file", count)
} }
} }
@@ -705,5 +721,5 @@ func RunIsolateCommands(association utils.FileCommandAssociation, file string, f
runIsolateCommandsLogger.Debug("No isolate modifications were made for file") runIsolateCommandsLogger.Debug("No isolate modifications were made for file")
return fileDataStr, NothingToDo return fileDataStr, NothingToDo
} }
return fileDataStr, nil return currentFileData, nil
} }