maintain method
Phase 2: runs maintainMemoryLevels() + consolidate() on both
scopes sequentially (smol-role cost class). Guarded: a second call
while one runs is a no-op returning false. Consolidation needs an
LLM provider — without one only level maintenance runs.
Implementation
Future<bool> maintain() async {
await _refreshConfig();
if (_maintaining) return false;
_maintaining = true;
try {
for (final store in [await projectStore, await userStore]) {
if (store == null) continue;
await store.maintainMemoryLevels();
if (_llmProvider != null) {
try {
await store.consolidate();
} on Object {
// Consolidation is best-effort: stale summary, LLM hiccup, or
// a concurrent write all skip this cycle (phase 2 spec).
}
}
}
await _writeMaintenanceStamp();
return true;
} finally {
_maintaining = false;
}
}