tenseleyflow/parrot / 849bc22

Browse files

fixes

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
849bc221f953ae4cf8b25d80761221617216b3b9
Parents
ae1b808
Tree
53578c1

3 changed files

StatusFile+-
M internal/config/config.go 2 2
M internal/llm/fallback_database.go 10 1
M internal/llm/smart_fallback.go 20 2
internal/config/config.gomodified
@@ -57,10 +57,10 @@ func DefaultConfig() *Config {
5757
 		},
5858
 		Local: LocalConfig{
5959
 			Enabled:  true,
60
-			Provider: "ollama", 
60
+			Provider: "ollama",
6161
 			Endpoint: "http://127.0.0.1:11434",
6262
 			Model:    "llama3.2:3b",
63
-			Timeout:  8,  // Adequate time for local LLM processing
63
+			Timeout:  15,  // Adequate time for local LLM processing (increased for slower systems)
6464
 		},
6565
 		General: GeneralConfig{
6666
 			Personality:  "savage",
internal/llm/fallback_database.gomodified
@@ -1,5 +1,7 @@
11
 package llm
22
 
3
+import "time"
4
+
35
 // ExpandedFallbackDatabase contains hundreds of brutal, wry insults organized by command type
46
 // This database is used when LLM backends are unavailable to provide instant feedback
57
 var ExpandedFallbackDatabase = map[string][]string{
@@ -2916,12 +2918,19 @@ func GetExpandedFallback(commandType string, command string) string {
29162918
 		responses = ExpandedFallbackDatabase["generic"]
29172919
 	}
29182920
 
2919
-	// Improved pseudo-random selection using command text for variation
2921
+	// Improved pseudo-random selection using command text + time for variation
2922
+	// Add time-based entropy to provide variety over time while maintaining
2923
+	// some determinism within short timeframes (10-second buckets)
2924
+	timeBucket := time.Now().Unix() / 10 // 10-second buckets
2925
+
29202926
 	hash := 0
29212927
 	fullText := commandType + command
29222928
 	for _, char := range fullText {
29232929
 		hash = hash*31 + int(char)
29242930
 	}
2931
+	// Mix in time-based entropy
2932
+	hash = hash*31 + int(timeBucket)
2933
+
29252934
 	if hash < 0 {
29262935
 		hash = -hash
29272936
 	}
internal/llm/smart_fallback.gomodified
@@ -6,6 +6,7 @@ import (
66
 	"regexp"
77
 	"strconv"
88
 	"strings"
9
+	"sync"
910
 	"time"
1011
 )
1112
 
@@ -1279,16 +1280,26 @@ func getProjectTypeInsult(ctx SmartFallbackContext) string {
12791280
 	return ""
12801281
 }
12811282
 
1282
-// selectInsult picks an insult using pseudo-random selection
1283
+// selectInsult picks an insult using pseudo-random selection with time-based entropy
1284
+// This adds variety over time while maintaining some determinism within short timeframes
12831285
 func selectInsult(insults []string, seed string) string {
12841286
 	if len(insults) == 0 {
12851287
 		return ""
12861288
 	}
12871289
 
1290
+	// Add time-based entropy: same command gets different insults over time
1291
+	// Using 10-second buckets means same command within ~10 seconds gets same insult,
1292
+	// but after that, the insult changes. This provides both consistency and variety.
1293
+	timeBucket := time.Now().Unix() / 10 // 10-second buckets
1294
+
12881295
 	hash := 0
1296
+	// Hash the seed (command)
12891297
 	for _, char := range seed {
12901298
 		hash = hash*31 + int(char)
12911299
 	}
1300
+	// Mix in time-based entropy
1301
+	hash = hash*31 + int(timeBucket)
1302
+
12921303
 	if hash < 0 {
12931304
 		hash = -hash
12941305
 	}
@@ -1401,7 +1412,10 @@ func detectErrorPattern(exitCode int, command string) string {
14011412
 }
14021413
 
14031414
 // failureTracker stores recent command failures (simple in-process tracking)
1404
-var failureTracker = make(map[string]int)
1415
+var (
1416
+	failureTracker      = make(map[string]int)
1417
+	failureTrackerMutex sync.Mutex
1418
+)
14051419
 
14061420
 // trackFailure tracks command failures and detects repeats
14071421
 func trackFailure(command string) bool {
@@ -1412,6 +1426,10 @@ func trackFailure(command string) bool {
14121426
 	}
14131427
 	cmdHash := strconv.Itoa(hash)
14141428
 
1429
+	// Thread-safe map access
1430
+	failureTrackerMutex.Lock()
1431
+	defer failureTrackerMutex.Unlock()
1432
+
14151433
 	// Increment failure count
14161434
 	failureTracker[cmdHash]++
14171435