package oracle import ( "path/filepath" "strings" ) // WalkWeights converts oracle directives into file weight modifiers for // walk.BuildWeighted. Files whose paths match the oracle's focus keywords // get higher weights, causing them to appear earlier in the walk order. // // The returned map is keyed by relative file path and valued by weight // multiplier (default = 1.0, boosted = 2.0-4.0). func WalkWeights(r *Reading, files []string) map[string]float64 { if r == nil || len(files) == 0 { return nil } weights := make(map[string]float64, len(files)) // Collect all keywords from the domain and changing line focuses. domain := TrigramToDomain(r.OuterTrigram()) keywords := DomainKeywords(domain) // Build a set of focus terms from directives. var focusTerms []string for _, kw := range keywords { focusTerms = append(focusTerms, strings.ToLower(kw)) } // Add changing line dimension focuses. for _, lineIdx := range r.ChangingLines() { bit := lineIdx % 3 isInner := lineIdx < 3 focus := ChangingBitFocus(bit, isInner) for word := range strings.FieldsSeq(strings.ToLower(focus)) { if len(word) > 3 { // skip short words focusTerms = append(focusTerms, word) } } } // Score each file by keyword matches in its path. for _, f := range files { lowerPath := strings.ToLower(f) base := strings.ToLower(filepath.Base(f)) w := 1.0 for _, term := range focusTerms { if strings.Contains(lowerPath, term) || strings.Contains(base, term) { w += 1.0 } } // Style modulation: targeted and reference styles boost test files; // broad style boosts non-test files. style := ADSRToStyle(0) if len(r.Directives) > 0 { style = r.Directives[0].Style } isTest := strings.HasSuffix(base, "_test.go") || strings.Contains(base, "test") switch style { case StyleTargeted, StyleReference: if isTest { w += 0.5 } case StyleBroad: if !isTest { w += 0.5 } case StyleSynthesis: // Synthesis boosts files that connect packages (main, cmd, etc.). if strings.Contains(lowerPath, "cmd/") || base == "main.go" { w += 1.0 } } if w > 1.0 { weights[f] = w } } return weights } // DominantADSRPhase returns the ADSR phase with the highest count. // Used to determine the organism's current lifecycle position for oracle casting. func DominantADSRPhase(counts [4]uint32) uint8 { maxIdx := uint8(0) maxVal := counts[0] for i := uint8(1); i < 4; i++ { if counts[i] > maxVal { maxVal = counts[i] maxIdx = i } } return maxIdx }