saveFeatures static method
Save features. Completed/done entries are automatically moved to the archive section so they don't inflate active-context loads.
Implementation
static void saveFeatures(List<Feature> features) {
ensureDataFilesExist();
final active = features.where((f) => !_isArchived(f)).toList();
final promoted = features.where(_isArchived).toList();
// Rebuild archive: existing entries + newly promoted, deduplicated.
// If an ID reappears as active (reactivated), it leaves the archive.
final activeIds = active.map((f) => f.id).toSet();
final promotedIds = promoted.map((f) => f.id).toSet();
final existingArchive = _loadArchivedFeatures();
final archive = [
...existingArchive.where(
(f) => !activeIds.contains(f.id) && !promotedIds.contains(f.id)),
...promoted,
];
final buffer = StringBuffer();
buffer.writeln('features:');
if (active.isEmpty) {
buffer.writeln(' []');
} else {
for (final f in active) {
_writeFeatureEntry(buffer, f);
}
}
buffer.writeln('archive:');
if (archive.isEmpty) {
buffer.writeln(' []');
} else {
for (final f in archive) {
_writeFeatureEntry(buffer, f);
}
}
FileService.writeFile('$dataDir/features.yaml', buffer.toString());
}