* Load pattern intelligence for trend detection and warnings
()
| 222 | * Load pattern intelligence for trend detection and warnings |
| 223 | */ |
| 224 | private async loadPatternIntelligence(): Promise<void> { |
| 225 | try { |
| 226 | const intelligencePath = path.join( |
| 227 | this.rootPath, |
| 228 | CODEBASE_CONTEXT_DIRNAME, |
| 229 | INTELLIGENCE_FILENAME |
| 230 | ); |
| 231 | const content = await fs.readFile(intelligencePath, 'utf-8'); |
| 232 | const intelligence = JSON.parse(content) as IntelligenceData; |
| 233 | |
| 234 | const decliningPatterns = new Set<string>(); |
| 235 | const risingPatterns = new Set<string>(); |
| 236 | const patternWarnings = new Map<string, string>(); |
| 237 | |
| 238 | // Extract pattern indicators from intelligence data |
| 239 | if (intelligence.patterns) { |
| 240 | for (const [_category, patternData] of Object.entries(intelligence.patterns)) { |
| 241 | // Track primary pattern |
| 242 | if (patternData.primary?.trend === 'Rising') { |
| 243 | risingPatterns.add(patternData.primary.name.toLowerCase()); |
| 244 | } |
| 245 | |
| 246 | // Track declining alternatives |
| 247 | if (patternData.alsoDetected) { |
| 248 | for (const alt of patternData.alsoDetected) { |
| 249 | if (alt.trend === 'Declining') { |
| 250 | decliningPatterns.add(alt.name.toLowerCase()); |
| 251 | patternWarnings.set( |
| 252 | alt.name.toLowerCase(), |
| 253 | `WARNING: Uses declining pattern: ${alt.name} (${alt.guidance || 'consider modern alternatives'})` |
| 254 | ); |
| 255 | } else if (alt.trend === 'Rising') { |
| 256 | risingPatterns.add(alt.name.toLowerCase()); |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | this.patternIntelligence = { decliningPatterns, risingPatterns, patternWarnings }; |
| 264 | if (process.env.CODEBASE_CONTEXT_DEBUG) { |
| 265 | console.error( |
| 266 | `[search] Loaded pattern intelligence: ${decliningPatterns.size} declining, ${risingPatterns.size} rising patterns` |
| 267 | ); |
| 268 | } |
| 269 | |
| 270 | this.importCentrality = new Map<string, number>(); |
| 271 | if (intelligence.internalFileGraph && intelligence.internalFileGraph.imports) { |
| 272 | // Count how many files import each file (in-degree centrality) |
| 273 | const importCounts = new Map<string, number>(); |
| 274 | |
| 275 | for (const [_importingFile, importedFiles] of Object.entries( |
| 276 | intelligence.internalFileGraph.imports |
| 277 | )) { |
| 278 | const imports = importedFiles as string[]; |
| 279 | for (const imported of imports) { |
| 280 | importCounts.set(imported, (importCounts.get(imported) || 0) + 1); |
| 281 | } |
no test coverage detected