-
Notifications
You must be signed in to change notification settings - Fork 1.2k
complexity router : add complexity analyzer config DB and API changes #3712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
akshaydeo
merged 1 commit into
dev
from
05-24-complexity_router_add_complexity_analyzer_config_db_and_api_changes
Jun 10, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| package configstore | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "sort" | ||
| "strings" | ||
| ) | ||
|
|
||
| // ComplexityTierBoundaries defines score thresholds for complexity tier classification. | ||
| type ComplexityTierBoundaries struct { | ||
| SimpleMedium float64 `json:"simple_medium"` | ||
| MediumComplex float64 `json:"medium_complex"` | ||
| ComplexReasoning float64 `json:"complex_reasoning"` | ||
| } | ||
|
|
||
| // Validate checks that tier boundaries are ordered and inside the analyzer score range. | ||
| func (b *ComplexityTierBoundaries) Validate() error { | ||
| if b == nil { | ||
| return nil | ||
| } | ||
| if !(0 < b.SimpleMedium && | ||
| b.SimpleMedium < b.MediumComplex && | ||
| b.MediumComplex < b.ComplexReasoning && | ||
| b.ComplexReasoning < 1) { | ||
| return fmt.Errorf( | ||
| "tier boundaries must satisfy 0 < simple_medium (%.4f) < medium_complex (%.4f) < complex_reasoning (%.4f) < 1", | ||
| b.SimpleMedium, b.MediumComplex, b.ComplexReasoning, | ||
| ) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // ComplexityEditableKeywordConfig contains the user-editable keyword lists. | ||
| type ComplexityEditableKeywordConfig struct { | ||
| CodeKeywords []string `json:"code_keywords"` | ||
| ReasoningKeywords []string `json:"reasoning_keywords"` | ||
| TechnicalKeywords []string `json:"technical_keywords"` | ||
| SimpleKeywords []string `json:"simple_keywords"` | ||
| } | ||
|
|
||
| // ComplexityAnalyzerConfig is the persisted runtime configuration for the complexity analyzer. | ||
| type ComplexityAnalyzerConfig struct { | ||
| TierBoundaries ComplexityTierBoundaries `json:"tier_boundaries"` | ||
| Keywords ComplexityEditableKeywordConfig `json:"keywords"` | ||
| } | ||
|
|
||
| // Validate checks that the config is internally consistent. | ||
| func (c *ComplexityAnalyzerConfig) Validate() error { | ||
| if c == nil { | ||
| return nil | ||
| } | ||
| if err := c.TierBoundaries.Validate(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| var missing []string | ||
| if len(c.Keywords.CodeKeywords) == 0 { | ||
| missing = append(missing, "code_keywords") | ||
| } | ||
| if len(c.Keywords.ReasoningKeywords) == 0 { | ||
| missing = append(missing, "reasoning_keywords") | ||
| } | ||
| if len(c.Keywords.TechnicalKeywords) == 0 { | ||
| missing = append(missing, "technical_keywords") | ||
| } | ||
| if len(c.Keywords.SimpleKeywords) == 0 { | ||
| missing = append(missing, "simple_keywords") | ||
| } | ||
| if len(missing) > 0 { | ||
| return fmt.Errorf("keyword lists must be non-empty: %s", strings.Join(missing, ", ")) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Normalized returns a canonical copy suitable for persistence and runtime use. | ||
| func (c *ComplexityAnalyzerConfig) Normalized() ComplexityAnalyzerConfig { | ||
| if c == nil { | ||
| return ComplexityAnalyzerConfig{} | ||
| } | ||
| return ComplexityAnalyzerConfig{ | ||
| TierBoundaries: c.TierBoundaries, | ||
| Keywords: ComplexityEditableKeywordConfig{ | ||
| CodeKeywords: normalizeComplexityKeywordList(c.Keywords.CodeKeywords), | ||
| ReasoningKeywords: normalizeComplexityKeywordList(c.Keywords.ReasoningKeywords), | ||
| TechnicalKeywords: normalizeComplexityKeywordList(c.Keywords.TechnicalKeywords), | ||
| SimpleKeywords: normalizeComplexityKeywordList(c.Keywords.SimpleKeywords), | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // DecodeComplexityAnalyzerConfig decodes raw JSON into a normalized, validated config. | ||
| func DecodeComplexityAnalyzerConfig(data []byte) (*ComplexityAnalyzerConfig, error) { | ||
| if len(data) == 0 { | ||
| return nil, nil | ||
| } | ||
|
|
||
| var cfg ComplexityAnalyzerConfig | ||
| if err := json.Unmarshal(data, &cfg); err != nil { | ||
| return nil, fmt.Errorf("failed to unmarshal complexity analyzer config: %w", err) | ||
| } | ||
|
|
||
| normalized := cfg.Normalized() | ||
| if err := normalized.Validate(); err != nil { | ||
| return nil, fmt.Errorf("invalid complexity analyzer config: %w", err) | ||
| } | ||
| return &normalized, nil | ||
| } | ||
|
|
||
| func normalizeComplexityKeywordList(values []string) []string { | ||
| if len(values) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| seen := make(map[string]struct{}, len(values)) | ||
| out := make([]string, 0, len(values)) | ||
| for _, value := range values { | ||
| normalized := strings.ToLower(strings.TrimSpace(value)) | ||
| if normalized == "" { | ||
| continue | ||
| } | ||
| if _, ok := seen[normalized]; ok { | ||
| continue | ||
| } | ||
| seen[normalized] = struct{}{} | ||
| out = append(out, normalized) | ||
| } | ||
| sort.Strings(out) | ||
| return out | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.