diff --git a/.hive-mind/hive.db b/.hive-mind/hive.db index a7cd9daa74..2e3d4aa797 100644 Binary files a/.hive-mind/hive.db and b/.hive-mind/hive.db differ diff --git a/src/cli/simple-commands/hive-mind/db-optimizer.js b/src/cli/simple-commands/hive-mind/db-optimizer.js index a46576f279..f629e8bc02 100644 --- a/src/cli/simple-commands/hive-mind/db-optimizer.js +++ b/src/cli/simple-commands/hive-mind/db-optimizer.js @@ -583,16 +583,30 @@ export async function performMaintenance(dbPath, options = {}) { // Clean up old memory entries if (options.cleanMemory) { - spinner.text = 'Cleaning old memory entries...'; - const cutoffDate = new Date(); - cutoffDate.setDate(cutoffDate.getDate() - (options.memoryRetentionDays || 30)); + // Check if collective_memory table exists + const hasMemoryTable = db.prepare(` + SELECT name FROM sqlite_master + WHERE type='table' AND name='collective_memory' + `).get(); - const result = db.prepare(` - DELETE FROM collective_memory - WHERE last_accessed < ? AND access_count < 5 - `).run(cutoffDate.toISOString()); - - console.log(chalk.green(`✓ Removed ${result.changes} old memory entries`)); + if (hasMemoryTable) { + spinner.text = 'Cleaning old memory entries...'; + const cutoffDate = new Date(); + cutoffDate.setDate(cutoffDate.getDate() - (options.memoryRetentionDays || 30)); + + try { + const result = db.prepare(` + DELETE FROM collective_memory + WHERE accessed_at < ? AND access_count < 5 + `).run(cutoffDate.toISOString()); + + console.log(chalk.green(`✓ Removed ${result.changes} old memory entries`)); + } catch (error) { + console.warn(chalk.yellow(`⚠ Could not clean memory entries: ${error.message}`)); + } + } else { + console.log(chalk.yellow('⚠ collective_memory table not found, skipping memory cleanup')); + } } // Archive completed tasks