MCPcopy Create free account
hub / github.com/JordanCoin/codemap / classifyIntent

Function classifyIntent

cmd/intent.go:92–148  ·  view source on GitHub ↗

classifyIntent analyzes a user prompt against code intelligence to determine task intent.

(prompt string, files []string, info *hubInfo, cfg config.ProjectConfig)

Source from the content-addressed store, hash-verified

90
91// classifyIntent analyzes a user prompt against code intelligence to determine task intent.
92func classifyIntent(prompt string, files []string, info *hubInfo, cfg config.ProjectConfig) TaskIntent {
93 intent := TaskIntent{
94 Category: "feature", // default
95 Files: files,
96 RiskLevel: "low",
97 Scope: "single-file",
98 }
99
100 // Score each category using weighted signals
101 promptLower := strings.ToLower(prompt)
102 scores := make(map[string]int)
103 for _, cd := range categoryDefs {
104 for _, sig := range cd.Signals {
105 if strings.Contains(promptLower, sig.Phrase) {
106 scores[cd.Category] += sig.Weight
107 }
108 }
109 }
110
111 // Find highest scoring category (deterministic: on tie, use categoryDefs order)
112 bestScore := 0
113 totalScore := 0
114 for _, score := range scores {
115 totalScore += score
116 }
117 // Iterate in definition order for deterministic tie-breaking
118 for _, cd := range categoryDefs {
119 score := scores[cd.Category]
120 if score > bestScore {
121 bestScore = score
122 intent.Category = cd.Category
123 }
124 }
125
126 // Confidence: ratio of best score to total (1.0 if only one category matched)
127 if totalScore > 0 {
128 intent.Confidence = float64(bestScore) / float64(totalScore)
129 }
130
131 // Compute scope from file distribution
132 intent.Scope = computeScope(files)
133
134 // Match subsystems
135 if len(cfg.Routing.Subsystems) > 0 {
136 matches := matchSubsystemRoutes(prompt, cfg, cfg.RoutingTopKOrDefault())
137 for _, m := range matches {
138 intent.Subsystems = append(intent.Subsystems, m.ID)
139 }
140 }
141
142 // Compute risk level and generate suggestions from hub analysis
143 if info != nil {
144 intent.RiskLevel, intent.Suggestions = analyzeRisk(files, info, intent.Category)
145 }
146
147 return intent
148}
149

Calls 4

computeScopeFunction · 0.85
matchSubsystemRoutesFunction · 0.85
analyzeRiskFunction · 0.85
RoutingTopKOrDefaultMethod · 0.80