formatMemoryStatsLines function
List<String>
formatMemoryStatsLines(
- List<
MemoryEntry> entries, - DateTime? lastMaintenance,
- bool maintenanceDue
Formats the /memory stats block (pure, testable): counts per type,
last maintenance, and the due hint.
Implementation
List<String> formatMemoryStatsLines(
List<MemoryEntry> entries,
DateTime? lastMaintenance,
bool maintenanceDue,
) {
final byType = <String, int>{};
for (final entry in entries) {
byType[entry.type] = (byType[entry.type] ?? 0) + 1;
}
final lines = <String>['[Memory]', ' entries: ${entries.length}'];
for (final type in byType.keys.toList()..sort()) {
lines.add(' $type: ${byType[type]}');
}
lines.add(
lastMaintenance == null
? ' last maintenance: never (/memory maintain to run)'
: ' last maintenance: $lastMaintenance',
);
if (maintenanceDue) {
lines.add(' maintenance due — /memory maintain');
}
return lines;
}