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

Function analyzeRisk

cmd/intent.go:171–238  ·  view source on GitHub ↗

analyzeRisk evaluates hub involvement and generates context suggestions.

(files []string, info *hubInfo, category string)

Source from the content-addressed store, hash-verified

169
170// analyzeRisk evaluates hub involvement and generates context suggestions.
171func analyzeRisk(files []string, info *hubInfo, category string) (string, []ContextSuggestion) {
172 risk := "low"
173 var suggestions []ContextSuggestion
174
175 hubCount := 0
176 maxImporters := 0
177
178 for _, file := range files {
179 importers := info.Importers[file]
180 importerCount := len(importers)
181
182 if importerCount > maxImporters {
183 maxImporters = importerCount
184 }
185
186 if importerCount >= 3 {
187 hubCount++
188 suggestions = append(suggestions, ContextSuggestion{
189 Type: "review-hub",
190 Target: file,
191 Reason: formatImporterReason(file, importerCount),
192 })
193 // For refactors and features on hubs, suggest checking deps
194 if category == "refactor" || category == "feature" {
195 suggestions = append(suggestions, ContextSuggestion{
196 Type: "check-deps",
197 Target: file,
198 Reason: "verify dependents still compile after changes",
199 })
200 }
201 }
202 }
203
204 // Escalate risk based on hub involvement
205 if hubCount > 0 {
206 risk = "medium"
207 }
208 if hubCount >= 2 || maxImporters >= 8 {
209 risk = "high"
210 }
211
212 // Category-specific suggestions
213 switch category {
214 case "bugfix":
215 if len(files) > 0 {
216 suggestions = append(suggestions, ContextSuggestion{
217 Type: "run-tests",
218 Target: filepath.Dir(files[0]),
219 Reason: "verify fix with existing tests",
220 })
221 }
222 case "refactor":
223 if len(files) > 0 {
224 suggestions = append(suggestions, ContextSuggestion{
225 Type: "run-tests",
226 Target: ".",
227 Reason: "run full test suite after refactoring",
228 })

Calls 1

formatImporterReasonFunction · 0.85