diff --git a/backend/src/modules/timers/routes.ts b/backend/src/modules/timers/routes.ts index 37fbb48..80085dc 100644 --- a/backend/src/modules/timers/routes.ts +++ b/backend/src/modules/timers/routes.ts @@ -136,6 +136,34 @@ export async function timerRoutes(app: FastifyInstance) { return { success: true }; }); + // Sync status — returns timer + routine counts and latest sync timestamp. + // MCP tool: chronomind.syncStatus(userId) — instant ops visibility without querying raw data. + app.get('/timers/sync-status', async req => { + const auth = await extractAuth(req); + const { items: timers } = await repo.listTimers(auth.sub, PRODUCT_ID, { + limit: 1000, + offset: 0, + sortBy: 'createdAt', + sortOrder: 'desc', + }); + + const active = timers.filter(t => t.state === 'active' || t.state === 'warning').length; + const pending = timers.filter(t => t.state === 'paused').length; + const lastSyncedAt = timers[0]?.lastSyncedAt ?? null; + const conflictCount = timers.filter(t => t.syncVersion === 0).length; + + return { + userId: auth.sub, + productId: PRODUCT_ID, + totalTimers: timers.length, + active, + pending, + conflictCount, + lastSyncedAt, + generatedAt: new Date().toISOString(), + }; + }); + // Batch upsert (initial sync / offline queue flush) app.post('/timers/batch', async req => { const auth = await extractAuth(req);