getActiveContext static method
Get the current active context by analyzing recent file changes
Implementation
static ActiveContext getActiveContext({int hours = 24}) {
ensureDataFilesExist();
// Get recent files
final recentFiles = RecentChanges.getRecentFiles(hours: hours, limit: 10);
if (recentFiles.isEmpty) {
return ActiveContext();
}
// Load features
final features = loadFeatures();
if (features.isEmpty) {
return ActiveContext(recentChanges: recentFiles);
}
// Find feature with most matching files
int maxMatches = 0;
Feature? matchedFeature;
for (final feature in features) {
int matches = 0;
for (final featureFile in feature.files) {
for (final recentFile in recentFiles) {
// Check if recent file path starts with feature file path
if (recentFile.startsWith(featureFile) ||
recentFile.contains(featureFile)) {
matches++;
break;
}
}
}
if (matches > maxMatches) {
maxMatches = matches;
matchedFeature = feature;
}
}
if (matchedFeature == null) {
return ActiveContext(recentChanges: recentFiles);
}
// Return active context with matched feature
return ActiveContext(
featureTitle: matchedFeature.title,
featureDescription: matchedFeature.description,
featureStatus: matchedFeature.status,
relatedFiles: matchedFeature.files,
recentChanges: recentFiles,
);
}