package engine import ( "fmt" "github.com/shopspring/decimal" ) // GlobalDefaultProfileVersion names the weight set every tenant scores on until the Adaptive // Intelligence Optimization Engine has produced a tenant profile. It is stamped into results and // audit rows so a served score always names the exact weights that produced it. const GlobalDefaultProfileVersion = "global.default" // Weights carries the six dimension weights the scorer applies. The engine stays pure and // deterministic: weights are an INPUT, injected by the caller, decimal end to end. The fixed // package constants (WeightClearance and friends) remain the frozen global default; a tenant // profile from the AIOE layer arrives here already validated and clamped. type Weights struct { Clearance decimal.Decimal Skills decimal.Decimal Certifications decimal.Decimal CustomerExperience decimal.Decimal Experience decimal.Decimal Location decimal.Decimal } // DefaultWeights returns the frozen global default weight set (CLAUDE.md fixed weights). Scoring // with DefaultWeights is byte identical to the historical ScoreCandidate behavior; the frozen // golden tests prove it. func DefaultWeights() Weights { return Weights{ Clearance: WeightClearance, Skills: WeightSkills, Certifications: WeightCerts, CustomerExperience: WeightCustomer, Experience: WeightExperience, Location: WeightLocation, } } // Sum returns the exact decimal sum of the six weights. func (w Weights) Sum() decimal.Decimal { return w.Clearance.Add(w.Skills).Add(w.Certifications). Add(w.CustomerExperience).Add(w.Experience).Add(w.Location) } // Validate rejects any weight set that is not a well formed probability style allocation: every // dimension strictly positive, none above one, and the total exactly 1 at four decimal places. // The scorer refuses an invalid set and falls back to the global default, so a corrupt profile // can degrade a tenant to defaults but can never distort a score. func (w Weights) Validate() error { one := decimal.NewFromInt(1) for name, v := range map[string]decimal.Decimal{ "clearance": w.Clearance, "skills": w.Skills, "certifications": w.Certifications, "customer_experience": w.CustomerExperience, "experience": w.Experience, "location": w.Location, } { if !v.IsPositive() || v.GreaterThan(one) { return fmt.Errorf("engine: weight %s out of range: %s", name, v.String()) } } if !w.Sum().Round(4).Equal(one) { return fmt.Errorf("engine: weights sum to %s, not 1", w.Sum().String()) } return nil }