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
address review (codex): seed daily-post into existing Health layouts via migration
[._.]/ Adam Eivy6b2639d54321
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex b3bb7a2e12..008184609e 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,7 +2,7 @@## Dashboard-- **A new "Daily POST" dashboard widget surfaces your cognitive self-test streak and whether you've trained today.** POST (the daily 5-minute math/wordplay/memory/verbal/imagination self-test) had no dashboard presence — you had to navigate to `/post` to even remember it existed, which is exactly the wrong friction for a habit you want to do *daily*. The new widget shows today's status (✓ Done · score%, or a "Start →" nudge), your current practice streak with a fire/zap/sparkle glyph, and your personal-best run — one click into `/post/launcher`. To back it, `getPostStats` now also returns `completedToday`, `currentStreak`, `longestStreak`, `lastDate`, and `todayScore`, computed by a new pure `computePostStreaks(sessions, today)` helper that mirrors the activity-streak grace-window semantics (a not-yet-done today doesn't break the streak if yesterday is logged) using UTC day math so month/DST boundaries don't cause off-by-ones. The widget ships in the built-in **Health** layout and is addable to any layout. (`server/services/meatspacePost.js`, `client/src/components/DailyPostWidget.jsx`, `client/src/components/dashboard/widgetRegistry.jsx`, `server/services/dashboardLayouts.js`)+- **A new "Daily POST" dashboard widget surfaces your cognitive self-test streak and whether you've trained today.** POST (the daily 5-minute math/wordplay/memory/verbal/imagination self-test) had no dashboard presence — you had to navigate to `/post` to even remember it existed, which is exactly the wrong friction for a habit you want to do *daily*. The new widget shows today's status (✓ Done · score%, or a "Start →" nudge), your current practice streak with a fire/zap/sparkle glyph, and your personal-best run — one click into `/post/launcher`. To back it, `getPostStats` now also returns `completedToday`, `currentStreak`, `longestStreak`, `lastDate`, and `todayScore`, computed by a new pure `computePostStreaks(sessions, today)` helper that mirrors the activity-streak grace-window semantics (a not-yet-done today doesn't break the streak if yesterday is logged) using UTC day math so month/DST boundaries don't cause off-by-ones. The widget ships in the built-in **Health** layout — a migration (`145-seed-daily-post-widget.js`) seeds it into existing installs' persisted Health layout, so current users get it too, not just fresh installs — and is addable to any layout. (`server/services/meatspacePost.js`, `client/src/components/DailyPostWidget.jsx`, `client/src/components/dashboard/widgetRegistry.jsx`, `server/services/dashboardLayouts.js`, `scripts/migrations/145-seed-daily-post-widget.js`)## Catalogdiff --git a/scripts/migrations/145-seed-daily-post-widget.js b/scripts/migrations/145-seed-daily-post-widget.jsnew file mode 100644index 0000000000..6aa7b8e9a8--- /dev/null+++ b/scripts/migrations/145-seed-daily-post-widget.js@@ -0,0 +1,105 @@+/**+ * Seed the new `daily-post` dashboard widget ("Daily POST") into the built-in+ * `health` layout for installs that already have a persisted+ * `data/dashboard-layouts.json`.+ *+ * Background:+ * `server/services/dashboardLayouts.js#DEFAULT_LAYOUTS` only seeds when the+ * file is missing. Adding a widget to the Health layout in code alone won't+ * reach existing users — this migration walks the file, finds the built-in+ * `health` layout, and inserts `daily-post` into its `widgets` list + `grid`+ * if missing. User-renamed copies and other layouts are not touched. Re-runs+ * detect the widget is already present and skip. Mirrors migration 070.+ */++import { readLayoutsDoc, writeLayoutsDoc } from './_lib.js';++const WIDGET_ID = 'daily-post';+const WIDGET_W = 3;+const WIDGET_H = 2;++// Mirror of the geometry in `server/services/dashboardLayouts.js`+// DEFAULT_LAYOUTS `health` layout — edits here must match that file or fresh+// installs + migrated installs diverge.+const PREFERRED_SLOTS = {+ health: { x: 9, y: 3, w: WIDGET_W, h: WIDGET_H },+};+const TARGET_LAYOUT_IDS = Object.keys(PREFERRED_SLOTS);++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) {+ for (const item of grid) {+ if (rectsOverlap(item, candidate)) return true;+ }+ return false;+}++function pickGridEntry(grid, layoutId) {+ const preferred = PREFERRED_SLOTS[layoutId];+ if (preferred) {+ const candidate = { id: WIDGET_ID, x: preferred.x, y: preferred.y, w: preferred.w, h: preferred.h };+ 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: WIDGET_ID,+ x: 0,+ y: bottom,+ w: preferred?.w ?? WIDGET_W,+ h: preferred?.h ?? WIDGET_H,+ };+}++function applyToLayout(layout) {+ 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(WIDGET_ID)) {+ layout.widgets = [...layout.widgets, WIDGET_ID];+ changed = true;+ }+ // 2) Heal the grid entry independently — the widget 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 [] (the shape the+ // client's `synthesizeGrid` would auto-create at render time).+ const existingGrid = Array.isArray(layout.grid) ? layout.grid : [];+ const hasGridEntry = existingGrid.some((it) => it?.id === WIDGET_ID);+ if (!hasGridEntry) {+ layout.grid = [...existingGrid, pickGridEntry(existingGrid, layout.id)];+ 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 145' });+ if (!result.ok) return { updated: 0, reason: result.reason };+ const { doc, path } = result;++ let touched = 0;+ for (const layout of doc.layouts) {+ if (!layout || !TARGET_LAYOUT_IDS.includes(layout.id)) continue;+ if (applyToLayout(layout)) touched += 1;+ }++ if (touched === 0) {+ console.log(`📦 migration 145: daily-post already present in target layouts.`);+ return { updated: 0, reason: 'already-applied' };+ }++ await writeLayoutsDoc(path, doc);+ console.log(`📦 migration 145: seeded daily-post widget into ${touched} built-in layout(s).`);+ return { updated: touched };+ },+};diff --git a/scripts/migrations/145-seed-daily-post-widget.test.js b/scripts/migrations/145-seed-daily-post-widget.test.jsnew file mode 100644index 0000000000..2d114dcf71--- /dev/null+++ b/scripts/migrations/145-seed-daily-post-widget.test.js@@ -0,0 +1,136 @@+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 './145-seed-daily-post-widget.js';++const writeJson = (path, value) => writeFileSync(path, JSON.stringify(value, null, 2) + '\n');+const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));++describe('migration 145 — seed daily-post widget into the health layout', () => {+ let rootDir;+ let layoutsPath;++ beforeEach(() => {+ rootDir = mkdtempSync(join(tmpdir(), 'migration-145-'));+ 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 daily-post into the health layout at its preferred slot', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'default',+ layouts: [+ {+ id: 'health',+ name: 'Health',+ builtIn: true,+ widgets: ['death-clock', 'activity-streak'],+ grid: [+ { id: 'death-clock', x: 0, y: 0, w: 4, h: 3 },+ { id: 'activity-streak', x: 9, y: 0, w: 3, h: 3 },+ ],+ },+ ],+ });+ const result = await migration.up({ rootDir });+ expect(result.updated).toBe(1);+ const after = readJson(layoutsPath);++ const health = after.layouts.find((l) => l.id === 'health');+ expect(health.widgets).toContain('daily-post');+ expect(health.grid.find((g) => g.id === 'daily-post')).toEqual({ id: 'daily-post', x: 9, y: 3, w: 3, h: 2 });+ });++ it('is idempotent — second run is a no-op', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'default',+ layouts: [+ { id: 'health', name: 'Health', builtIn: true, widgets: ['daily-post'], grid: [{ id: 'daily-post', x: 9, y: 3, w: 3, h: 2 }] },+ ],+ });+ const result = await migration.up({ rootDir });+ expect(result.updated).toBe(0);+ expect(result.reason).toBe('already-applied');+ });++ it('only touches the health id, not other or renamed layouts', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'focus',+ layouts: [+ { id: 'focus', name: 'Focus', builtIn: true, widgets: ['cos'], grid: [] },+ { id: 'my-health', name: 'My Health', builtIn: false, widgets: ['cos'], grid: [] },+ { id: 'health', name: 'Health', 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-health').widgets).toEqual(['cos']);+ expect(after.layouts.find((l) => l.id === 'health').widgets).toContain('daily-post');+ });++ 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 widget id is in widgets[] but missing from grid[]', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'default',+ layouts: [+ {+ id: 'health',+ name: 'Health',+ builtIn: true,+ widgets: ['death-clock', 'daily-post'],+ 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 === 'daily-post');+ expect(entry).toBeDefined();+ expect(after.layouts[0].widgets.filter((w) => w === 'daily-post')).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'],+ // Something already sits in the preferred slot (x:9,y:3).+ grid: [{ id: 'hourly-activity', x: 9, y: 3, w: 3, 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 === 'daily-post');+ expect(newEntry).toBeDefined();+ expect(newEntry.x).toBe(0);+ expect(newEntry.y).toBeGreaterThanOrEqual(7);+ });+});