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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix([issue-2091]): genuinely unify the streak across all POST surfaces + guard stale progress fetch
Adam Eivy2dbb4b5e6dd6
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 19270dbce1..a4fd898a9d 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -25,7 +25,7 @@## POST Training-- **[issue-2091] A unified Progress dashboard shows whether you're actually improving.** POST has a new **Progress** page (in the POST sidebar section, ⌘K, and voice nav) that pulls scored sessions, Morse/memory practice, and mastery into one view. It charts your score, accuracy, and response-time trends over time — so "am I getting faster?" finally has an answer — with same-day sessions rolled into one point (no more overlapping dots), a per-domain focus selector, and time-in-training cards. A single practice streak now counts *any* active day (a scored session **or** a Morse/memory practice), so the launcher, the Morse trainer, and the dashboard widgets can no longer disagree about your streak. A mastery panel shows your multiplication ladder rung and each memory item's mastery and due status. The full session-history table lives on as a sub-view.+- **[issue-2091] A unified Progress dashboard shows whether you're actually improving.** POST has a new **Progress** page (in the POST sidebar section, ⌘K, and voice nav) that pulls scored sessions, Morse/memory practice, and mastery into one view. It charts your score, accuracy, and response-time trends over time — so "am I getting faster?" finally has an answer — with same-day sessions rolled into one point (no more overlapping dots), a per-domain focus selector, and time-in-training cards. Your practice streak is now a single number counting *any* active day — a scored session **or** a Morse/memory practice — so the launcher, the Morse trainer, the Progress page, and the dashboard widgets all show the same streak instead of three different ones. A mastery panel shows your multiplication ladder rung and each memory item's mastery and due status. The full session-history table lives on as a sub-view.- **[issue-2092] Morse progress now lives on the server, with WPM/accuracy trends and a per-character confusion matrix.** Your Koch level and every completed drill round are now saved server-side instead of only in the browser — so clearing browser data or switching devices (over Tailscale) no longer wipes your Morse mastery, and your level is identical everywhere. The first time you open the trainer it adopts your existing browser level once, then keeps both in sync. A new **Morse Progress** panel on `/post/morse` charts accuracy and effective-WPM trends per mode (Copy / Head Copy / Send), highlights your most-confused character pairs (E↔I and friends), and lists your weakest characters worst-first so you know exactly which to drill next. Send-mode rounds record per-character keying accuracy and timing too.## Roundsdiff --git a/client/src/components/meatspace/post/PostProgress.jsx b/client/src/components/meatspace/post/PostProgress.jsxindex d1e89ad80d..e4b7161ffa 100644--- a/client/src/components/meatspace/post/PostProgress.jsx+++ b/client/src/components/meatspace/post/PostProgress.jsx@@ -1,4 +1,4 @@-import { useState, useEffect, useCallback, useMemo } from 'react';+import { useState, useEffect, useCallback, useMemo, useRef } from 'react';import { ArrowLeft, Flame, Trophy, Clock, Gauge } from 'lucide-react';import {LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer, CartesianGrid@@ -69,13 +69,19 @@ export default function PostProgress({ subtab, onBack }) {const [range, setRange] = useState(90);const [domain, setDomain] = useState('all');const [loaded, setLoaded] = useState(false);+ // Guard against out-of-order responses: switching All (a full-history scan)+ // → 7d can let the slower All response land last and overwrite the 7d data+ // while the 7d range stays selected. Only the newest request may set state.+ const reqRef = useRef(0);const loadData = useCallback(async () => {// The Sessions sub-view renders PostHistory (its own fetch) — no need to// pull the progress payload for it.if (subtab === 'sessions') return;+ const reqId = ++reqRef.current;const p = await getPostProgress(range, { silent: true }).catch((err) => { console.warn('⚠️ Failed to load POST progress: ' + err.message); return null; });+ if (reqId !== reqRef.current) return; // a newer request superseded this onesetProgress(p);setLoaded(true);}, [range, subtab]);diff --git a/server/services/meatspacePost.js b/server/services/meatspacePost.jsindex 01c656b8b6..01cbf8f1ff 100644--- a/server/services/meatspacePost.js+++ b/server/services/meatspacePost.js@@ -336,10 +336,36 @@ export function deriveTaskAvgResponseMs(task) {return Math.round(timed.reduce((sum, q) => sum + q.responseMs, 0) / timed.length);}+/**+ * ONE unified activity streak across scored sessions AND the training log — the+ * single number every POST surface (launcher, Morse trainer, dashboard widgets)+ * should show, so they can't disagree (issue #2091). A day is active with EITHER+ * a scored session or a training-log entry (Morse / memory practice). Computed+ * over ALL history, independent of any stats window.+ */+export async function getUnifiedActivityStreak(todayStr = new Date().toISOString().split('T')[0]) {+ const [sessions, training] = await Promise.all([getPostSessions(), getAllTrainingEntries()]);+ return computeUnifiedStreak(sessions, training, todayStr);+}+export async function getPostStats(days = 30) {const sessions = await getPostSessions();- // Streaks are computed over ALL history, independent of the stats window.- const streaks = computePostStreaks(sessions, new Date().toISOString().split('T')[0]);+ const todayStr = new Date().toISOString().split('T')[0];+ // Streaks are computed over ALL history, independent of the stats window, and+ // over BOTH scored sessions and the training log so the launcher/dashboard+ // streak matches the Morse trainer and the Progress page (issue #2091).+ // `completedToday`/`todayScore` stay SCORED-session specific — they answer+ // "did you complete a scored POST today / what did you score", which a+ // practice-only day legitimately doesn't satisfy.+ const sessionStreaks = computePostStreaks(sessions, todayStr);+ const training = await getAllTrainingEntries();+ const unified = computeUnifiedStreak(sessions, training, todayStr);+ const streaks = {+ ...sessionStreaks,+ currentStreak: unified.current,+ longestStreak: unified.longest,+ lastDate: unified.lastActiveDate,+ };let recent = sessions;if (days > 0) {const cutoff = new Date();diff --git a/server/services/meatspacePostProgress.test.js b/server/services/meatspacePostProgress.test.jsindex 6b64c786fa..6b8756350f 100644--- a/server/services/meatspacePostProgress.test.js+++ b/server/services/meatspacePostProgress.test.js@@ -18,7 +18,8 @@ vi.mock('../lib/fileUtils.js', () => ({}),}));-import { getPostProgress } from './meatspacePost.js';+import { getPostProgress, getPostStats, getUnifiedActivityStreak } from './meatspacePost.js';+import { getTrainingStats } from './meatspacePostTraining.js';import { postProgressQuerySchema } from '../lib/postValidation.js';const mathTask = (score, questions) => ({ module: 'mental-math', type: 'multiplication', score, questions });@@ -113,6 +114,50 @@ describe('getPostProgress bucketing', () => {});});+describe('unified streak agrees across every POST surface', () => {+ it('getPostStats, getTrainingStats, and getPostProgress report the SAME streak', async () => {+ // Interleave scored sessions and practice on distinct days: neither source+ // alone is a full streak, but together they form a consecutive run ending+ // today — every surface must see the same unified number.+ state.sessions = [+ { date: daysAgo(2), durationMs: 60000, score: 80, tasks: [mathTask(80, [q(true)])] },+ { date: todayStr(), durationMs: 60000, score: 90, tasks: [mathTask(90, [q(true)])] },+ ];+ state.training = [+ { date: daysAgo(1), module: 'morse', drillType: 'morse-copy', questionCount: 5, correctCount: 5, totalMs: 1000 },+ ];++ const [stats, training, progress, unified] = await Promise.all([+ getPostStats(30),+ getTrainingStats(30),+ getPostProgress({ days: 30 }),+ getUnifiedActivityStreak(),+ ]);++ // 3 consecutive active days (session, practice, session) → streak 3.+ expect(unified.current).toBe(3);+ expect(stats.currentStreak).toBe(3);+ expect(training.currentStreak).toBe(3);+ expect(progress.streak.current).toBe(3);+ // Longest agrees too.+ expect(stats.longestStreak).toBe(training.longestStreak);+ expect(stats.longestStreak).toBe(progress.streak.longest);+ });++ it('a practice-only day still extends the launcher (getPostStats) streak', async () => {+ // No scored sessions at all — the launcher/dashboard streak (getPostStats)+ // must still count Morse practice, matching the Morse trainer.+ state.training = [+ { date: daysAgo(1), module: 'morse', drillType: 'morse-copy', questionCount: 5, correctCount: 5, totalMs: 1000 },+ { date: todayStr(), module: 'morse', drillType: 'morse-copy', questionCount: 5, correctCount: 5, totalMs: 1000 },+ ];+ const stats = await getPostStats(30);+ expect(stats.currentStreak).toBe(2);+ // But completedToday stays SCORED-session specific — no scored POST today.+ expect(stats.completedToday).toBe(false);+ });+});+describe('postProgressQuerySchema clamping', () => {it('defaults days to 90 when missing or NaN', () => {expect(postProgressQuerySchema.parse({}).days).toBe(90);diff --git a/server/services/meatspacePostTraining.js b/server/services/meatspacePostTraining.jsindex 6655149ef7..3f6e44725a 100644--- a/server/services/meatspacePostTraining.js+++ b/server/services/meatspacePostTraining.js@@ -8,7 +8,7 @@import { join } from 'path';import { randomUUID } from 'crypto';import { atomicWrite, PATHS, ensureDir, readJSONFile } from '../lib/fileUtils.js';-import { computePostStreaks } from '../lib/postStreak.js';+import { getUnifiedActivityStreak } from './meatspacePost.js';const MEATSPACE_DIR = PATHS.meatspace;const TRAINING_LOG_FILE = join(MEATSPACE_DIR, 'post-training-log.json');@@ -51,11 +51,11 @@ export async function submitTrainingEntry(entry) {/*** Get training stats: per-drill practice counts, streaks, recent activity.*- * Streaks come from the SHARED `computePostStreaks` (server/lib/postStreak.js) —- * the same DST-safe helper the scored-session streak uses — so the training- * streak can no longer disagree with the POST streak for identical activity- * (issue #2091). Like `getPostStats`, the streak is computed over ALL history,- * independent of the stats window; only the per-drill breakdown is windowed.+ * The streak comes from the SHARED unified streak (`getUnifiedActivityStreak` in+ * meatspacePost.js) — the exact same number the launcher, dashboard widgets, and+ * Progress page show — so the Morse trainer can no longer disagree with them+ * (issue #2091). It counts BOTH scored sessions and training-log entries over+ * ALL history; only the per-drill breakdown below is windowed.*/export async function getTrainingStats(days = 30) {const data = await loadTrainingLog();@@ -81,9 +81,8 @@ export async function getTrainingStats(days = 30) {byDrill[key].dates.add(String(e.date || '').split('T')[0]);}- // Unified streak semantics (shared helper, ALL history, grace window).- const todayStr = new Date().toISOString().split('T')[0];- const { currentStreak, longestStreak } = computePostStreaks(allEntries, todayStr);+ // ONE unified streak across sessions + training (shared helper, ALL history).+ const { current: currentStreak, longest: longestStreak } = await getUnifiedActivityStreak();const activeDays = new Set(entries.map(e => String(e.date || '').split('T')[0])).size;// Summarizediff --git a/server/services/meatspacePostTraining.test.js b/server/services/meatspacePostTraining.test.jsindex f4df7beeeb..1e0f098895 100644--- a/server/services/meatspacePostTraining.test.js+++ b/server/services/meatspacePostTraining.test.js@@ -3,7 +3,10 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';vi.mock('../lib/fileUtils.js', () => ({tryReadFile: vi.fn().mockResolvedValue(null),atomicWrite: vi.fn().mockResolvedValue(undefined),- PATHS: { meatspace: '/tmp/test-meatspace' },+ // `data` is required because getTrainingStats now imports meatspacePost.js+ // (for the shared unified streak), which transitively loads the drill cache —+ // its module-load `join(PATHS.data, …)` needs a string.+ PATHS: { data: '/tmp/test-data', meatspace: '/tmp/test-meatspace' },ensureDir: vi.fn().mockResolvedValue(undefined),readJSONFile: vi.fn().mockResolvedValue({ entries: [] }),}));