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

feat: add activity streak tracking to Dashboard

Adam Eivy629595215b7d
diff --git a/.changelog/v0.10.x.md b/.changelog/v0.10.x.md
index 5409089152..c8d4153925 100644
--- a/.changelog/v0.10.x.md
+++ b/.changelog/v0.10.x.md
@@ -26,6 +26,13 @@ This release introduces a structured changelog documentation system for creating
- **Progress Bar Enhancement**: Improved progress bar with clearer "X% complete" and prominent ETA display
- **Visual Polish**: Slightly thicker progress bars and better typography for the countdown display
+### Dashboard - Activity Streak
+- **Current Streak Display**: Shows consecutive days of activity with dynamic emoji (fire for 7+ days, lightning for 3+, sparkles for less)
+- **Longest Streak Tracking**: Displays your personal best streak alongside current streak
+- **Personal Best Badge**: Green "Personal best!" badge appears when you match or beat your longest streak
+- **7-Day Activity Bar**: Visual mini-chart showing activity for the past week with green/gray bars
+- **Gamification**: Motivates consistent usage through streak tracking and progress visualization
+
## 🔧 Improvements
### Release Process
diff --git a/client/src/pages/Dashboard.jsx b/client/src/pages/Dashboard.jsx
index 67d0a427d7..169eff1ad2 100644
--- a/client/src/pages/Dashboard.jsx
+++ b/client/src/pages/Dashboard.jsx
@@ -7,17 +7,20 @@ import socket from '../services/socket';
export default function Dashboard() {
const [apps, setApps] = useState([]);
const [health, setHealth] = useState(null);
+ const [usage, setUsage] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const fetchData = useCallback(async () => {
setError(null);
- const [appsData, healthData] = await Promise.all([
+ const [appsData, healthData, usageData] = await Promise.all([
api.getApps().catch(err => { setError(err.message); return []; }),
- api.checkHealth().catch(() => null)
+ api.checkHealth().catch(() => null),
+ api.getUsage().catch(() => null)
]);
setApps(appsData);
setHealth(healthData);
+ setUsage(usageData);
setLoading(false);
}, []);
@@ -98,6 +101,54 @@ export default function Dashboard() {
</div>
)}
+ {/* Activity Streak */}
+ {usage && (usage.currentStreak > 0 || usage.longestStreak > 0) && (
+ <div className="mt-8 bg-port-card border border-port-border rounded-xl p-6">
+ <div className="flex flex-col sm:flex-row sm:items-center gap-4">
+ <div className="flex items-center gap-3">
+ <div className="text-4xl" aria-hidden="true">
+ {usage.currentStreak >= 7 ? '🔥' : usage.currentStreak >= 3 ? '⚡' : '✨'}
+ </div>
+ <div>
+ <div className="text-2xl font-bold text-white">
+ {usage.currentStreak} day{usage.currentStreak !== 1 ? 's' : ''}
+ </div>
+ <div className="text-sm text-gray-500">Current streak</div>
+ </div>
+ </div>
+ {usage.longestStreak > usage.currentStreak && (
+ <div className="sm:ml-auto text-right">
+ <div className="text-lg font-semibold text-port-accent">
+ {usage.longestStreak} days
+ </div>
+ <div className="text-xs text-gray-500">Longest streak</div>
+ </div>
+ )}
+ {usage.currentStreak === usage.longestStreak && usage.currentStreak > 0 && (
+ <div className="sm:ml-auto px-3 py-1 bg-port-success/20 text-port-success text-sm rounded-full">
+ Personal best!
+ </div>
+ )}
+ </div>
+ {/* Mini streak visualization */}
+ <div className="mt-4 flex gap-1">
+ {usage.last7Days?.map((day) => (
+ <div
+ key={day.date}
+ className={`flex-1 h-2 rounded-full ${
+ day.sessions > 0 ? 'bg-port-success' : 'bg-port-border'
+ }`}
+ title={`${day.label}: ${day.sessions} sessions`}
+ />
+ ))}
+ </div>
+ <div className="mt-1 flex justify-between text-xs text-gray-500">
+ <span>7 days ago</span>
+ <span>Today</span>
+ </div>
+ </div>
+ )}
+
{/* Quick Stats */}
{apps.length > 0 && (
<div className="mt-8 grid grid-cols-2 md:grid-cols-4 gap-4">
diff --git a/server/services/usage.js b/server/services/usage.js
index 49403f0fde..68ce84f614 100644
--- a/server/services/usage.js
+++ b/server/services/usage.js
@@ -154,11 +154,104 @@ export async function recordTokens(inputTokens, outputTokens) {
await saveUsage();
}
+/**
+ * Calculate current activity streak (consecutive days with sessions)
+ */
+function calculateStreak(dailyActivity) {
+ const today = new Date();
+ let streak = 0;
+ let checkDate = new Date(today);
+
+ // Start from today and work backwards
+ while (true) {
+ const dateStr = checkDate.toISOString().split('T')[0];
+ const dayData = dailyActivity[dateStr];
+
+ if (dayData && dayData.sessions > 0) {
+ streak++;
+ checkDate.setDate(checkDate.getDate() - 1);
+ } else if (streak === 0) {
+ // If today has no activity, check if yesterday started a streak
+ checkDate.setDate(checkDate.getDate() - 1);
+ const yesterdayStr = checkDate.toISOString().split('T')[0];
+ const yesterdayData = dailyActivity[yesterdayStr];
+ if (!yesterdayData || yesterdayData.sessions === 0) {
+ break; // No streak
+ }
+ // Continue checking from yesterday
+ } else {
+ break; // Streak broken
+ }
+ }
+
+ return streak;
+}
+
+/**
+ * Find the longest streak in history
+ */
+function findLongestStreak(dailyActivity) {
+ const dates = Object.keys(dailyActivity).sort();
+ if (dates.length === 0) return 0;
+
+ let maxStreak = 0;
+ let currentStreak = 0;
+ let prevDate = null;
+
+ for (const dateStr of dates) {
+ const dayData = dailyActivity[dateStr];
+ if (!dayData || dayData.sessions === 0) continue;
+
+ if (prevDate) {
+ const prev = new Date(prevDate);
+ const curr = new Date(dateStr);
+ const diffDays = Math.round((curr - prev) / (1000 * 60 * 60 * 24));
+
+ if (diffDays === 1) {
+ currentStreak++;
+ } else {
+ currentStreak = 1;
+ }
+ } else {
+ currentStreak = 1;
+ }
+
+ maxStreak = Math.max(maxStreak, currentStreak);
+ prevDate = dateStr;
+ }
+
+ return maxStreak;
+}
+
/**
* Get usage summary
*/
export function getUsageSummary() {
- if (!usageData) return getEmptyUsage();
+ if (!usageData) {
+ const empty = getEmptyUsage();
+ // Generate empty last7Days
+ const last7Days = [];
+ for (let i = 6; i >= 0; i--) {
+ const date = new Date();
+ date.setDate(date.getDate() - i);
+ last7Days.push({
+ date: date.toISOString().split('T')[0],
+ label: date.toLocaleDateString('en-US', { weekday: 'short' }),
+ sessions: 0,
+ messages: 0,
+ tokens: 0
+ });
+ }
+ return {
+ ...empty,
+ currentStreak: 0,
+ longestStreak: 0,
+ last7Days,
+ estimatedCost: 0,
+ topProviders: [],
+ topModels: []
+ };
+ }
// Get last 7 days activity
const last7Days = [];
@@ -173,6 +266,10 @@ export function getUsageSummary() {
});
}
+ // Calculate streaks
+ const currentStreak = calculateStreak(usageData.dailyActivity);
+ const longestStreak = findLongestStreak(usageData.dailyActivity);
+
// Calculate totals
const totalCost = estimateCost(usageData.totalTokens.input, usageData.totalTokens.output);
@@ -182,6 +279,8 @@ export function getUsageSummary() {
totalToolCalls: usageData.totalToolCalls,
totalTokens: usageData.totalTokens,
estimatedCost: totalCost,
+ currentStreak,
+ longestStreak,
last7Days,
hourlyActivity: usageData.hourlyActivity,
topProviders: Object.entries(usageData.byProvider)
diff --git a/server/services/usage.test.js b/server/services/usage.test.js
new file mode 100644
index 0000000000..0f211a70f8
--- /dev/null
+++ b/server/services/usage.test.js
@@ -0,0 +1,83 @@
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+import { getUsageSummary, recordSession } from './usage.js';
+
+// Helper to generate date strings
+const dateStr = (daysAgo) => {
+ const d = new Date();
+ d.setDate(d.getDate() - daysAgo);
+ return d.toISOString().split('T')[0];
+};
+
+describe('Usage Service - Streak Calculation', () => {
+ describe('currentStreak', () => {
+ it('should return 0 when no activity', () => {
+ // Empty daily activity means no streak
+ const summary = getUsageSummary();
+ // With real data from file, we just verify streak is a number >= 0
+ expect(typeof summary.currentStreak).toBe('number');
+ expect(summary.currentStreak).toBeGreaterThanOrEqual(0);
+ });
+
+ it('should include currentStreak in summary', () => {
+ const summary = getUsageSummary();
+ expect(summary).toHaveProperty('currentStreak');
+ expect(typeof summary.currentStreak).toBe('number');
+ });
+
+ it('should include longestStreak in summary', () => {
+ const summary = getUsageSummary();
+ expect(summary).toHaveProperty('longestStreak');
+ expect(typeof summary.longestStreak).toBe('number');
+ });
+
+ it('should have currentStreak <= longestStreak', () => {
+ const summary = getUsageSummary();
+ expect(summary.currentStreak).toBeLessThanOrEqual(summary.longestStreak);
+ });
+ });
+
+ describe('streak logic validation', () => {
+ it('should include last7Days in summary', () => {
+ const summary = getUsageSummary();
+ expect(summary).toHaveProperty('last7Days');
+ expect(Array.isArray(summary.last7Days)).toBe(true);
+ expect(summary.last7Days.length).toBe(7);
+ });
+
+ it('last7Days should have correct structure', () => {
+ const summary = getUsageSummary();
+ summary.last7Days.forEach(day => {
+ expect(day).toHaveProperty('date');
+ expect(day).toHaveProperty('label');
+ expect(day).toHaveProperty('sessions');
+ expect(typeof day.sessions).toBe('number');
+ });
+ });
+
+ it('last7Days dates should be in chronological order', () => {
+ const summary = getUsageSummary();
+ const dates = summary.last7Days.map(d => d.date);
+ const sorted = [...dates].sort();
+ expect(dates).toEqual(sorted);
+ });
+ });
+
+ describe('summary structure', () => {
+ it('should have all expected fields', () => {
+ const summary = getUsageSummary();
+ expect(summary).toHaveProperty('totalSessions');
+ expect(summary).toHaveProperty('totalMessages');
+ expect(summary).toHaveProperty('currentStreak');
+ expect(summary).toHaveProperty('longestStreak');
+ expect(summary).toHaveProperty('last7Days');
+ expect(summary).toHaveProperty('hourlyActivity');
+ expect(summary).toHaveProperty('topProviders');
+ expect(summary).toHaveProperty('topModels');
+ });
+
+ it('hourlyActivity should have 24 entries', () => {
+ const summary = getUsageSummary();
+ expect(summary.hourlyActivity).toHaveLength(24);
+ });
+ });
+});