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: seed widgets into built-in layouts + normalize health log date (#2034)
Adam Eivydfb5acd6c09e
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 2c326cf69a..24ccff3767 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -30,7 +30,7 @@## Dashboard-- **Two new dashboard widgets surface previously invisible data: a Feeds unread digest and a health-logging streak.** The Feeds Digest widget shows your total unread RSS/Atom count plus the top unread feeds by count and deep-links to Brain → Feeds — it consumes the existing `getFeedStats` wrapper (now the endpoint's first real caller) so unread counts aren't recomputed. The Health Logging Streak widget mirrors the Activity Streak / Daily POST pattern: current + best cross-domain logging streak, a 7-day sparkline, and this-week counts per domain (alcohol, nicotine, workouts, body, blood pressure) via a new `GET /api/meatspace/logging-stats` aggregate, deep-linking to MeatSpace. Both are gated hidden on fresh installs with no feeds/logs and render at mobile widths (#2034).+- **Two new dashboard widgets surface previously invisible data: a Feeds unread digest and a health-logging streak.** The Feeds Digest widget shows your total unread RSS/Atom count plus the top unread feeds by count and deep-links to Brain → Feeds — it consumes the existing `getFeedStats` wrapper (now the endpoint's first real caller) so unread counts aren't recomputed. The Health Logging Streak widget mirrors the Activity Streak / Daily POST pattern: current + best cross-domain logging streak, a 7-day sparkline, and this-week counts per domain (alcohol, nicotine, workouts, body, blood pressure) via a new `GET /api/meatspace/logging-stats` aggregate, deep-linking to MeatSpace. `feeds` seeds into the Everything layout and `meatspace-streak` into the Health layout (fresh installs via `DEFAULT_LAYOUTS`, existing installs via migration 156); both are gated hidden until there's data and render at mobile widths. Also normalized the workout/body/blood-pressure default log date to the local calendar day (matching alcohol/nicotine) so a same-day US-evening entry lands on today's streak/sparkline instead of tomorrow's UTC bucket (#2034).## Loading statesdiff --git a/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.js b/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.jsnew file mode 100644index 0000000000..37583f294f--- /dev/null+++ b/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.js@@ -0,0 +1,94 @@+/**+ * Seed the new `feeds` (Feeds Digest) and `meatspace-streak` (Health Logging+ * Streak) dashboard widgets into their built-in layouts for installs that+ * already have a persisted `data/dashboard-layouts.json`.+ *+ * Background:+ * `server/services/dashboardLayouts.js#DEFAULT_LAYOUTS` (+ INTENT_LAYOUTS)+ * only seed when the file is missing. Adding a widget to a built-in layout+ * in code alone won't reach existing users — this migration walks the file,+ * finds each target built-in layout, and inserts the widget into its+ * `widgets` list + `grid` if missing. User-renamed copies and other layouts+ * are untouched. Re-runs detect the widget is already present and skip.+ * Mirrors migrations 070 / 145.+ *+ * `feeds` → `default` ("Everything") layout; `meatspace-streak` → `health`.+ * Both widgets are gated client-side (hidden until feeds/logs exist), so a+ * fresh-but-persisted install seeing the id costs nothing until it has data.+ */++import { readLayoutsDoc, writeLayoutsDoc } from './_lib.js';++// Each widget → its target built-in layout id + preferred grid slot. Slots+// mirror the geometry in `server/services/dashboardLayouts.js` — edits here+// must match that file or fresh installs + migrated installs diverge.+const SEEDS = [+ { widgetId: 'feeds', layoutId: 'default', slot: { x: 8, y: 29, w: 3, h: 4 } },+ { widgetId: 'meatspace-streak', layoutId: 'health', slot: { x: 0, y: 9, w: 4, h: 4 } },+];++function rectsOverlap(a, b) {+ return a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;+}++function collidesWith(grid, candidate) {+ return grid.some((item) => rectsOverlap(item, candidate));+}++function pickGridEntry(grid, widgetId, slot) {+ const candidate = { id: widgetId, ...slot };+ if (!collidesWith(grid, candidate)) return candidate;+ // Fall back to a clean row below everything else if the preferred slot is+ // occupied (a user rearranged the layout but kept the built-in id).+ const bottom = grid.reduce((max, it) => Math.max(max, (it.y ?? 0) + (it.h ?? 0)), 0);+ return { id: widgetId, x: 0, y: bottom, w: slot.w, h: slot.h };+}++function applyToLayout(layout, widgetId, slot) {+ if (!layout || typeof layout !== 'object') return false;+ if (!Array.isArray(layout.widgets)) return false;++ let changed = false;+ // 1) Insert into widgets if absent.+ if (!layout.widgets.includes(widgetId)) {+ layout.widgets = [...layout.widgets, widgetId];+ changed = true;+ }+ // 2) Heal the grid entry independently — the id can be present in `widgets`+ // but missing from `grid` (e.g. a widgets-only edit landed without an+ // arrange-and-save pass). Treat a non-array grid as [].+ const existingGrid = Array.isArray(layout.grid) ? layout.grid : [];+ const hasGridEntry = existingGrid.some((it) => it?.id === widgetId);+ if (!hasGridEntry) {+ layout.grid = [...existingGrid, pickGridEntry(existingGrid, widgetId, slot)];+ changed = true;+ } else if (!Array.isArray(layout.grid)) {+ layout.grid = existingGrid;+ changed = true;+ }+ return changed;+}++export default {+ async up({ rootDir }) {+ const result = await readLayoutsDoc({ rootDir, label: 'migration 156' });+ if (!result.ok) return { updated: 0, reason: result.reason };+ const { doc, path } = result;++ let touched = 0;+ for (const { widgetId, layoutId, slot } of SEEDS) {+ const layout = doc.layouts.find((l) => l && l.id === layoutId);+ if (!layout) continue;+ if (applyToLayout(layout, widgetId, slot)) touched += 1;+ }++ if (touched === 0) {+ console.log(`📦 migration 156: feeds + meatspace-streak already present in target layouts.`);+ return { updated: 0, reason: 'already-applied' };+ }++ await writeLayoutsDoc(path, doc);+ console.log(`📦 migration 156: seeded feeds/meatspace-streak into ${touched} built-in layout(s).`);+ return { updated: touched };+ },+};diff --git a/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.test.js b/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.test.jsnew file mode 100644index 0000000000..043a3c972e--- /dev/null+++ b/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.test.js@@ -0,0 +1,120 @@+import { describe, it, expect, beforeEach, afterEach } from 'vitest';+import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync, existsSync } from 'fs';+import { tmpdir } from 'os';+import { join } from 'path';++import migration from './156-seed-feeds-and-meatspace-streak-widgets.js';++const writeJson = (path, value) => writeFileSync(path, JSON.stringify(value, null, 2) + '\n');+const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));++describe('migration 156 — seed feeds + meatspace-streak widgets', () => {+ let rootDir;+ let layoutsPath;++ beforeEach(() => {+ rootDir = mkdtempSync(join(tmpdir(), 'migration-156-'));+ mkdirSync(join(rootDir, 'data'), { recursive: true });+ layoutsPath = join(rootDir, 'data', 'dashboard-layouts.json');+ });++ afterEach(() => {+ rmSync(rootDir, { recursive: true, force: true });+ });++ it('no-ops cleanly when dashboard-layouts.json is missing (fresh install)', async () => {+ const result = await migration.up({ rootDir });+ expect(result.updated).toBe(0);+ expect(result.reason).toBe('no-state');+ expect(existsSync(layoutsPath)).toBe(false);+ });++ it('inserts each widget into its target layout at the preferred slot', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'default',+ layouts: [+ { id: 'default', name: 'Everything', builtIn: true, widgets: ['apps'], grid: [{ id: 'apps', x: 0, y: 0, w: 12, h: 8 }] },+ { id: 'health', name: 'Health', builtIn: true, widgets: ['death-clock'], grid: [{ id: 'death-clock', x: 0, y: 0, w: 4, h: 3 }] },+ ],+ });+ const result = await migration.up({ rootDir });+ expect(result.updated).toBe(2);+ const after = readJson(layoutsPath);++ const def = after.layouts.find((l) => l.id === 'default');+ expect(def.widgets).toContain('feeds');+ expect(def.grid.find((g) => g.id === 'feeds')).toEqual({ id: 'feeds', x: 8, y: 29, w: 3, h: 4 });++ const health = after.layouts.find((l) => l.id === 'health');+ expect(health.widgets).toContain('meatspace-streak');+ expect(health.grid.find((g) => g.id === 'meatspace-streak')).toEqual({ id: 'meatspace-streak', x: 0, y: 9, w: 4, h: 4 });+ });++ it('is idempotent — second run is a no-op', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'default',+ layouts: [+ { id: 'default', name: 'Everything', builtIn: true, widgets: ['feeds'], grid: [{ id: 'feeds', x: 8, y: 29, w: 3, h: 4 }] },+ { id: 'health', name: 'Health', builtIn: true, widgets: ['meatspace-streak'], grid: [{ id: 'meatspace-streak', x: 0, y: 9, w: 4, h: 4 }] },+ ],+ });+ const result = await migration.up({ rootDir });+ expect(result.updated).toBe(0);+ expect(result.reason).toBe('already-applied');+ });++ it('only touches the built-in ids, not renamed/other layouts', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'focus',+ layouts: [+ { id: 'focus', name: 'Focus', builtIn: true, widgets: ['cos'], grid: [] },+ { id: 'my-default', name: 'My Home', builtIn: false, widgets: ['cos'], grid: [] },+ { id: 'default', name: 'Everything', builtIn: true, widgets: ['cos'], grid: [] },+ ],+ });+ const result = await migration.up({ rootDir });+ expect(result.updated).toBe(1);+ const after = readJson(layoutsPath);+ expect(after.layouts.find((l) => l.id === 'focus').widgets).toEqual(['cos']);+ expect(after.layouts.find((l) => l.id === 'my-default').widgets).toEqual(['cos']);+ expect(after.layouts.find((l) => l.id === 'default').widgets).toContain('feeds');+ });++ it('survives an unreadable JSON file', async () => {+ writeFileSync(layoutsPath, 'not json');+ const result = await migration.up({ rootDir });+ expect(result.updated).toBe(0);+ expect(result.reason).toBe('unreadable');+ });++ it('heals legacy state where the id is in widgets[] but missing from grid[]', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'health',+ layouts: [+ { id: 'health', name: 'Health', builtIn: true, widgets: ['death-clock', 'meatspace-streak'], grid: [{ id: 'death-clock', x: 0, y: 0, w: 4, h: 3 }] },+ ],+ });+ const result = await migration.up({ rootDir });+ expect(result.updated).toBe(1);+ const after = readJson(layoutsPath);+ const entry = after.layouts[0].grid.find((g) => g.id === 'meatspace-streak');+ expect(entry).toBeDefined();+ expect(after.layouts[0].widgets.filter((w) => w === 'meatspace-streak')).toHaveLength(1);+ });++ it('appends below existing items when the preferred slot is occupied', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'default',+ layouts: [+ { id: 'health', name: 'Health', builtIn: true, widgets: ['hourly-activity'], grid: [{ id: 'hourly-activity', x: 0, y: 9, w: 12, h: 4 }] },+ ],+ });+ const result = await migration.up({ rootDir });+ expect(result.updated).toBe(1);+ const after = readJson(layoutsPath);+ const newEntry = after.layouts[0].grid.find((g) => g.id === 'meatspace-streak');+ expect(newEntry).toBeDefined();+ expect(newEntry.x).toBe(0);+ expect(newEntry.y).toBeGreaterThanOrEqual(13);+ });+});diff --git a/server/services/dashboardLayouts.js b/server/services/dashboardLayouts.jsindex 35e6d4fd40..ea6874b982 100644--- a/server/services/dashboardLayouts.js+++ b/server/services/dashboardLayouts.js@@ -51,14 +51,16 @@ export const INTENT_LAYOUTS = [{id: 'health',name: 'Health',- widgets: ['death-clock', 'goal-progress', 'activity-streak', 'daily-post', 'quick-brain', 'hourly-activity'],+ widgets: ['death-clock', 'goal-progress', 'activity-streak', 'daily-post', 'quick-brain', 'hourly-activity', 'meatspace-streak'],grid: [- { id: 'death-clock', x: 0, y: 0, w: 4, h: 3 },- { id: 'goal-progress', x: 4, y: 0, w: 5, h: 5 },- { id: 'activity-streak', x: 9, y: 0, w: 3, h: 3 },- { id: 'daily-post', x: 9, y: 3, w: 3, h: 2 },- { id: 'quick-brain', x: 0, y: 3, w: 4, h: 2 },- { id: 'hourly-activity', x: 0, y: 5, w: 12, h: 4 },+ { id: 'death-clock', x: 0, y: 0, w: 4, h: 3 },+ { id: 'goal-progress', x: 4, y: 0, w: 5, h: 5 },+ { id: 'activity-streak', x: 9, y: 0, w: 3, h: 3 },+ { id: 'daily-post', x: 9, y: 3, w: 3, h: 2 },+ { id: 'quick-brain', x: 0, y: 3, w: 4, h: 2 },+ { id: 'hourly-activity', x: 0, y: 5, w: 12, h: 4 },+ // Gated on any health log existing — hidden on installs with no logs.+ { id: 'meatspace-streak', x: 0, y: 9, w: 4, h: 4 },],},{@@ -86,7 +88,7 @@ const DEFAULT_LAYOUTS = ['apps','cos', 'goal-progress', 'upcoming-tasks','proactive-alerts', 'review-hub', 'while-away', 'system-health', 'network-exposure', 'backup', 'death-clock', 'quick-stats', 'decision-log',- 'activity-streak', 'hourly-activity', 'tribe-care',+ 'activity-streak', 'hourly-activity', 'tribe-care', 'feeds',],// Above-the-fold capture row stretches to h=5 so the Quick Task card// can show its expanded options (worktree/PR/simplify/etc.) without@@ -124,6 +126,8 @@ const DEFAULT_LAYOUTS = [{ id: 'quick-idea', x: 0, y: 29, w: 4, h: 4 },// Gated on the Tribe having people — hidden on installs that don't use it.{ id: 'tribe-care', x: 4, y: 29, w: 4, h: 4 },+ // Gated on having subscribed feeds — hidden on installs with none.+ { id: 'feeds', x: 8, y: 29, w: 3, h: 4 },],},{diff --git a/server/services/meatspaceHealth.js b/server/services/meatspaceHealth.jsindex 7cc9c9cd91..f647b274d7 100644--- a/server/services/meatspaceHealth.js+++ b/server/services/meatspaceHealth.js@@ -7,7 +7,7 @@*/import { join } from 'path';-import { atomicWrite, PATHS, ensureDir, readJSONFile } from '../lib/fileUtils.js';+import { atomicWrite, PATHS, ensureDir, readJSONFile, getDateString } from '../lib/fileUtils.js';import {isMortalLoomEnabled,mlArrayIfEnabled,@@ -78,7 +78,7 @@ export async function getBodyHistory() {}export async function addBodyEntry({ date, ...body }) {- const targetDate = date || new Date().toISOString().split('T')[0];+ const targetDate = date || getDateString(); // local calendar day (matches alcohol/nicotine + dashboard streak)if (await isMortalLoomEnabled()) {const stored = await mlPush('bodyEntries', { date: targetDate, ...body });@@ -191,7 +191,7 @@ export async function getWorkouts() {}export async function addWorkout({ date, type, durationMinutes, intensity, notes } = {}) {- const targetDate = date || new Date().toISOString().split('T')[0];+ const targetDate = date || getDateString(); // local calendar day (matches alcohol/nicotine + dashboard streak)const trimmedType = typeof type === 'string' ? type.trim() : '';if (!trimmedType) throw new Error('workout type is required');const entry = {@@ -229,7 +229,7 @@ export async function getBloodPressureHistory() {}export async function addBloodPressureReading({ date, systolic, diastolic }) {- const targetDate = date || new Date().toISOString().split('T')[0];+ const targetDate = date || getDateString(); // local calendar day (matches alcohol/nicotine + dashboard streak)const patch = { bloodPressureSystolic: systolic, bloodPressureDiastolic: diastolic };if (await isMortalLoomEnabled()) {