fixes
Authored by
mfwolffe <wolffemf@dukes.jmu.edu>
- SHA
849bc221f953ae4cf8b25d80761221617216b3b9- Parents
-
ae1b808 - Tree
53578c1
849bc22
849bc221f953ae4cf8b25d80761221617216b3b9ae1b808
53578c1| Status | File | + | - |
|---|---|---|---|
| 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 { | ||
| 57 | 57 | }, |
| 58 | 58 | Local: LocalConfig{ |
| 59 | 59 | Enabled: true, |
| 60 | - Provider: "ollama", | |
| 60 | + Provider: "ollama", | |
| 61 | 61 | Endpoint: "http://127.0.0.1:11434", |
| 62 | 62 | 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) | |
| 64 | 64 | }, |
| 65 | 65 | General: GeneralConfig{ |
| 66 | 66 | Personality: "savage", |
internal/llm/fallback_database.gomodified@@ -1,5 +1,7 @@ | ||
| 1 | 1 | package llm |
| 2 | 2 | |
| 3 | +import "time" | |
| 4 | + | |
| 3 | 5 | // ExpandedFallbackDatabase contains hundreds of brutal, wry insults organized by command type |
| 4 | 6 | // This database is used when LLM backends are unavailable to provide instant feedback |
| 5 | 7 | var ExpandedFallbackDatabase = map[string][]string{ |
@@ -2916,12 +2918,19 @@ func GetExpandedFallback(commandType string, command string) string { | ||
| 2916 | 2918 | responses = ExpandedFallbackDatabase["generic"] |
| 2917 | 2919 | } |
| 2918 | 2920 | |
| 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 | + | |
| 2920 | 2926 | hash := 0 |
| 2921 | 2927 | fullText := commandType + command |
| 2922 | 2928 | for _, char := range fullText { |
| 2923 | 2929 | hash = hash*31 + int(char) |
| 2924 | 2930 | } |
| 2931 | + // Mix in time-based entropy | |
| 2932 | + hash = hash*31 + int(timeBucket) | |
| 2933 | + | |
| 2925 | 2934 | if hash < 0 { |
| 2926 | 2935 | hash = -hash |
| 2927 | 2936 | } |
internal/llm/smart_fallback.gomodified@@ -6,6 +6,7 @@ import ( | ||
| 6 | 6 | "regexp" |
| 7 | 7 | "strconv" |
| 8 | 8 | "strings" |
| 9 | + "sync" | |
| 9 | 10 | "time" |
| 10 | 11 | ) |
| 11 | 12 | |
@@ -1279,16 +1280,26 @@ func getProjectTypeInsult(ctx SmartFallbackContext) string { | ||
| 1279 | 1280 | return "" |
| 1280 | 1281 | } |
| 1281 | 1282 | |
| 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 | |
| 1283 | 1285 | func selectInsult(insults []string, seed string) string { |
| 1284 | 1286 | if len(insults) == 0 { |
| 1285 | 1287 | return "" |
| 1286 | 1288 | } |
| 1287 | 1289 | |
| 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 | + | |
| 1288 | 1295 | hash := 0 |
| 1296 | + // Hash the seed (command) | |
| 1289 | 1297 | for _, char := range seed { |
| 1290 | 1298 | hash = hash*31 + int(char) |
| 1291 | 1299 | } |
| 1300 | + // Mix in time-based entropy | |
| 1301 | + hash = hash*31 + int(timeBucket) | |
| 1302 | + | |
| 1292 | 1303 | if hash < 0 { |
| 1293 | 1304 | hash = -hash |
| 1294 | 1305 | } |
@@ -1401,7 +1412,10 @@ func detectErrorPattern(exitCode int, command string) string { | ||
| 1401 | 1412 | } |
| 1402 | 1413 | |
| 1403 | 1414 | // 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 | +) | |
| 1405 | 1419 | |
| 1406 | 1420 | // trackFailure tracks command failures and detects repeats |
| 1407 | 1421 | func trackFailure(command string) bool { |
@@ -1412,6 +1426,10 @@ func trackFailure(command string) bool { | ||
| 1412 | 1426 | } |
| 1413 | 1427 | cmdHash := strconv.Itoa(hash) |
| 1414 | 1428 | |
| 1429 | + // Thread-safe map access | |
| 1430 | + failureTrackerMutex.Lock() | |
| 1431 | + defer failureTrackerMutex.Unlock() | |
| 1432 | + | |
| 1415 | 1433 | // Increment failure count |
| 1416 | 1434 | failureTracker[cmdHash]++ |
| 1417 | 1435 | |