Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([capabilities-cheap-memory-count]): count via active memory backend

[._.]/ Adam Eivye27d9c9217e5
diff --git a/server/routes/capabilities.js b/server/routes/capabilities.js
index 94d2268f64..33d03548f6 100644
--- a/server/routes/capabilities.js
+++ b/server/routes/capabilities.js
@@ -5,7 +5,7 @@ import { getAllProviders, getProviderById } from '../services/providers.js';
import { getAllProviderStatuses } from '../services/providerStatus.js';
import { listAccounts as listCalendarAccounts } from '../services/calendarAccounts.js';
import { listAccounts as listMessageAccounts } from '../services/messageAccounts.js';
-import { countMemories } from '../services/memory.js';
+import { countMemories } from '../services/memoryBackend.js';
import { getConfig as getCosConfig } from '../services/cos.js';
import { getVoiceConfig } from '../services/voice/config.js';
import { getNetworkExposureStatus } from '../lib/networkExposure.js';
diff --git a/server/routes/capabilities.test.js b/server/routes/capabilities.test.js
index 16204733c8..7192ef50e7 100644
--- a/server/routes/capabilities.test.js
+++ b/server/routes/capabilities.test.js
@@ -18,7 +18,7 @@ vi.mock('../services/calendarAccounts.js', () => ({
vi.mock('../services/messageAccounts.js', () => ({
listAccounts: vi.fn(async () => [{ enabled: true, lastSyncStatus: 'success' }]),
}));
-vi.mock('../services/memory.js', () => ({
+vi.mock('../services/memoryBackend.js', () => ({
countMemories: vi.fn(async () => 7),
}));
vi.mock('../services/cos.js', () => ({
@@ -46,7 +46,7 @@ vi.mock('../services/apps.js', () => ({
getAppStatusSummary: vi.fn(async () => ({ total: 2, online: 2, stopped: 0, notStarted: 0, unmanaged: 0 })),
}));
-const { countMemories } = await import('../services/memory.js');
+const { countMemories } = await import('../services/memoryBackend.js');
const { getGenomeSummary } = await import('../services/genome.js');
const { default: capabilitiesRoutes } = await import('./capabilities.js');
diff --git a/server/services/memoryBackend.js b/server/services/memoryBackend.js
index 3e1a5da391..9e9e0aaa51 100644
--- a/server/services/memoryBackend.js
+++ b/server/services/memoryBackend.js
@@ -96,6 +96,11 @@ export async function getMemories(options) {
return b.getMemories(options);
}
+export async function countMemories(options) {
+ const b = await getBackend();
+ return b.countMemories(options);
+}
+
export async function updateMemory(id, updates) {
const b = await getBackend();
return b.updateMemory(id, updates);
@@ -199,4 +204,3 @@ export async function flushBM25Index() {
const b = await getBackend();
return b.flushBM25Index();
}
-
diff --git a/server/services/memoryDB.js b/server/services/memoryDB.js
index fbda43e872..c7f12ce8db 100644
--- a/server/services/memoryDB.js
+++ b/server/services/memoryDB.js
@@ -153,9 +153,9 @@ export async function getMemory(id) {
}
/**
- * Get memories with filters
+ * Build shared filters for memory list/count queries.
*/
-export async function getMemories(options = {}) {
+function buildMemoryFilterWhere(options = {}) {
const conditions = [];
const params = [];
let paramIdx = 1;
@@ -192,6 +192,21 @@ export async function getMemories(options = {}) {
}
const where = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
+ return { where, params };
+}
+
+export async function countMemories(options = {}) {
+ const { where, params } = buildMemoryFilterWhere(options);
+ const countResult = await query(`SELECT COUNT(*) as total FROM memories ${where}`, params);
+ return parseInt(countResult.rows[0].total, 10);
+}
+
+/**
+ * Get memories with filters
+ */
+export async function getMemories(options = {}) {
+ const { where, params } = buildMemoryFilterWhere(options);
+ let paramIdx = params.length + 1;
// Count total
const countResult = await query(`SELECT COUNT(*) as total FROM memories ${where}`, params);