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
feat: birthdate management + life calendar multi-unit views
Adam Eivy7a038e8f15ef
diff --git a/PLAN.md b/PLAN.mdindex bdaef0c5ac..5367636887 100644--- a/PLAN.md+++ b/PLAN.md@@ -86,7 +86,8 @@ pm2 logs- [ ] **M54**: MeatSpace Life Calendar — "4000 Weeks" mortality-aware time mapping- [x] P1-P3: Core calendar engine, Calendar tab UI, Overview integration (life grid, time stats, activity budgets, view modes, birthday highlights, hide-spent toggle, nav link)- - [ ] P4: Birthdate management — Move birthDate from `digital-twin/goals.json` to `meatspace/config.json`. Add birthdate display + inline edit to AgeTab (top of page, before epigenetic section). Add `GET/PUT /api/meatspace/birth-date` endpoints. Calendar error state should link to `/meatspace/age` to set birthdate. Migrate existing birthDate on first read.+ - [x] P4: Birthdate management — birthDate canonical source moved to `meatspace/config.json` with auto-migration from `goals.json`. `GET/PUT /api/meatspace/birth-date` endpoints. AgeTab shows birthdate display + inline edit. Calendar error links to `/meatspace/age`. Identity setBirthDate syncs to both stores.+ - [x] P4b: Life Calendar multi-unit views — renamed "Life in Weeks" to "Life Calendar" with Years/Months/Weeks/Days toggle. Year grid (10 cols), Month grid (12 cols/year), Week grid (existing layouts), Day grid (calendar-style per-year with navigation).- [ ] P5: Additional event types — holidays, vacations, custom recurring events with color coding on the life grid- [ ] P6: Mobile responsive cell size auto-detection- [ ] P7: Goal Tree integration — connect activities to goals, time feasibility analysis ("Can I finish this goal with my remaining time budget?")diff --git a/client/src/components/meatspace/tabs/AgeTab.jsx b/client/src/components/meatspace/tabs/AgeTab.jsxindex ca2cd2ce3d..f0a7288fa3 100644--- a/client/src/components/meatspace/tabs/AgeTab.jsx+++ b/client/src/components/meatspace/tabs/AgeTab.jsx@@ -1,14 +1,105 @@import { useState, useEffect, useCallback } from 'react';-import { Dna } from 'lucide-react';+import { Dna, Calendar, Pencil, Check, X } from 'lucide-react';import * as api from '../../../services/api';import BrailleSpinner from '../../BrailleSpinner';+function BirthDateSection({ birthDate, onUpdate }) {+ const [editing, setEditing] = useState(false);+ const [input, setInput] = useState(birthDate || '');+ const [saving, setSaving] = useState(false);++ const handleSave = async () => {+ if (!input) return;+ setSaving(true);+ const result = await api.setMeatspaceBirthDate(input).catch(() => null);+ setSaving(false);+ if (result) {+ onUpdate(input);+ setEditing(false);+ }+ };++ const handleCancel = () => {+ setInput(birthDate || '');+ setEditing(false);+ };++ const age = birthDate ? (() => {+ const birth = new Date(birthDate);+ const now = new Date();+ const years = (now - birth) / (365.25 * 24 * 60 * 60 * 1000);+ return Math.floor(years);+ })() : null;++ return (+ <div className="bg-port-card border border-port-border rounded-xl p-6">+ <div className="flex items-center gap-2 mb-4">+ <Calendar size={18} className="text-port-accent" />+ <h3 className="text-sm font-medium text-gray-400 uppercase tracking-wider">Birth Date</h3>+ </div>+ {editing ? (+ <div className="flex items-center gap-3">+ <input+ type="date"+ value={input}+ onChange={(e) => setInput(e.target.value)}+ className="bg-port-bg border border-port-border rounded px-3 py-2 text-white font-mono text-lg focus:border-port-accent focus:outline-none"+ />+ <button+ onClick={handleSave}+ disabled={saving || !input}+ className="p-2 rounded bg-port-success/20 text-port-success hover:bg-port-success/30 disabled:opacity-50"+ >+ <Check size={16} />+ </button>+ <button+ onClick={handleCancel}+ className="p-2 rounded bg-port-error/20 text-port-error hover:bg-port-error/30"+ >+ <X size={16} />+ </button>+ </div>+ ) : birthDate ? (+ <div className="flex items-center gap-4">+ <div>+ <p className="text-2xl font-mono font-bold text-white">{birthDate}</p>+ {age != null && (+ <p className="text-sm text-gray-500 mt-1">Chronological age: {age} years</p>+ )}+ </div>+ <button+ onClick={() => setEditing(true)}+ className="p-2 rounded text-gray-500 hover:text-gray-300 hover:bg-port-border/50"+ >+ <Pencil size={14} />+ </button>+ </div>+ ) : (+ <div>+ <p className="text-gray-500 text-sm mb-3">No birth date set. Required for life calendar and death clock calculations.</p>+ <button+ onClick={() => setEditing(true)}+ className="px-4 py-2 rounded bg-port-accent/20 text-port-accent hover:bg-port-accent/30 text-sm"+ >+ Set Birth Date+ </button>+ </div>+ )}+ </div>+ );+}+export default function AgeTab() {+ const [birthDate, setBirthDate] = useState(null);const [epigeneticData, setEpigeneticData] = useState(null);const [loading, setLoading] = useState(true);const fetchData = useCallback(async () => {- const epigenetic = await api.getEpigeneticTests().catch(() => ({ tests: [] }));+ const [birthResult, epigenetic] = await Promise.all([+ api.getMeatspaceBirthDate().catch(() => ({ birthDate: null })),+ api.getEpigeneticTests().catch(() => ({ tests: [] }))+ ]);+ setBirthDate(birthResult?.birthDate || null);setEpigeneticData(epigenetic);setLoading(false);}, []);@@ -20,7 +111,7 @@ export default function AgeTab() {if (loading) {return (<div className="flex justify-center py-12">- <BrailleSpinner text="Loading epigenetic data" />+ <BrailleSpinner text="Loading age data" /></div>);}@@ -28,82 +119,85 @@ export default function AgeTab() {const epigeneticTests = epigeneticData?.tests || [];const latestEpigenetic = epigeneticTests[epigeneticTests.length - 1];- if (!latestEpigenetic) {- return (- <div className="bg-port-card border border-port-border rounded-xl p-6">- <p className="text-gray-500 text-sm">No epigenetic age data. Import your health data to see results.</p>- </div>- );- }-return (<div className="space-y-6">- <div className="bg-port-card border border-port-border rounded-xl p-6">- <div className="flex items-center gap-2 mb-4">- <Dna size={18} className="text-purple-400" />- <h3 className="text-sm font-medium text-gray-400 uppercase tracking-wider">Epigenetic Age</h3>- </div>- <div className="grid grid-cols-2 md:grid-cols-4 gap-4">- <div>- <p className="text-xs text-gray-500 uppercase">Chronological</p>- <p className="text-2xl font-mono font-bold text-gray-300">{latestEpigenetic.chronologicalAge}</p>- </div>- <div>- <p className="text-xs text-gray-500 uppercase">Biological</p>- <p className={`text-2xl font-mono font-bold ${- latestEpigenetic.biologicalAge < latestEpigenetic.chronologicalAge- ? 'text-port-success' : 'text-port-error'- }`}>- {latestEpigenetic.biologicalAge}- </p>- </div>- <div>- <p className="text-xs text-gray-500 uppercase">Pace of Aging</p>- <p className={`text-2xl font-mono font-bold ${- latestEpigenetic.paceOfAging < 1 ? 'text-port-success' : 'text-port-error'- }`}>- {latestEpigenetic.paceOfAging}- </p>+ <BirthDateSection+ birthDate={birthDate}+ onUpdate={(newDate) => setBirthDate(newDate)}+ />++ {latestEpigenetic ? (+ <div className="bg-port-card border border-port-border rounded-xl p-6">+ <div className="flex items-center gap-2 mb-4">+ <Dna size={18} className="text-purple-400" />+ <h3 className="text-sm font-medium text-gray-400 uppercase tracking-wider">Epigenetic Age</h3></div>- <div>- <p className="text-xs text-gray-500 uppercase">Test Date</p>- <p className="text-lg font-mono text-gray-400">{latestEpigenetic.date}</p>+ <div className="grid grid-cols-2 md:grid-cols-4 gap-4">+ <div>+ <p className="text-xs text-gray-500 uppercase">Chronological</p>+ <p className="text-2xl font-mono font-bold text-gray-300">{latestEpigenetic.chronologicalAge}</p>+ </div>+ <div>+ <p className="text-xs text-gray-500 uppercase">Biological</p>+ <p className={`text-2xl font-mono font-bold ${+ latestEpigenetic.biologicalAge < latestEpigenetic.chronologicalAge+ ? 'text-port-success' : 'text-port-error'+ }`}>+ {latestEpigenetic.biologicalAge}+ </p>+ </div>+ <div>+ <p className="text-xs text-gray-500 uppercase">Pace of Aging</p>+ <p className={`text-2xl font-mono font-bold ${+ latestEpigenetic.paceOfAging < 1 ? 'text-port-success' : 'text-port-error'+ }`}>+ {latestEpigenetic.paceOfAging}+ </p>+ </div>+ <div>+ <p className="text-xs text-gray-500 uppercase">Test Date</p>+ <p className="text-lg font-mono text-gray-400">{latestEpigenetic.date}</p>+ </div></div>- </div>- {latestEpigenetic.organScores && (- <div className="mt-4 pt-4 border-t border-port-border">- <p className="text-xs text-gray-500 uppercase mb-2">Organ Scores (biological age)</p>- <div className="grid grid-cols-3 md:grid-cols-5 gap-2">- {Object.entries(latestEpigenetic.organScores).map(([organ, age]) => (- <div key={organ} className="flex items-baseline justify-between gap-2 px-2 py-1 rounded bg-port-bg/50">- <span className="text-xs text-gray-400 capitalize">{organ}</span>- <span className={`text-sm font-mono font-medium ${- age < latestEpigenetic.chronologicalAge ? 'text-port-success' : 'text-port-error'- }`}>- {age}- </span>- </div>- ))}+ {latestEpigenetic.organScores && (+ <div className="mt-4 pt-4 border-t border-port-border">+ <p className="text-xs text-gray-500 uppercase mb-2">Organ Scores (biological age)</p>+ <div className="grid grid-cols-3 md:grid-cols-5 gap-2">+ {Object.entries(latestEpigenetic.organScores).map(([organ, age]) => (+ <div key={organ} className="flex items-baseline justify-between gap-2 px-2 py-1 rounded bg-port-bg/50">+ <span className="text-xs text-gray-400 capitalize">{organ}</span>+ <span className={`text-sm font-mono font-medium ${+ age < latestEpigenetic.chronologicalAge ? 'text-port-success' : 'text-port-error'+ }`}>+ {age}+ </span>+ </div>+ ))}+ </div></div>- </div>- )}+ )}- {epigeneticTests.length > 1 && (- <div className="mt-4 pt-4 border-t border-port-border">- <p className="text-xs text-gray-500 uppercase mb-2">History</p>- <div className="space-y-1">- {epigeneticTests.map((test, i) => (- <div key={i} className="flex items-center gap-4 text-sm">- <span className="text-gray-500 font-mono w-24">{test.date}</span>- <span className="text-gray-400">Bio: {test.biologicalAge}</span>- <span className="text-gray-400">Pace: {test.paceOfAging}</span>- </div>- ))}+ {epigeneticTests.length > 1 && (+ <div className="mt-4 pt-4 border-t border-port-border">+ <p className="text-xs text-gray-500 uppercase mb-2">History</p>+ <div className="space-y-1">+ {epigeneticTests.map((test, i) => (+ <div key={i} className="flex items-center gap-4 text-sm">+ <span className="text-gray-500 font-mono w-24">{test.date}</span>+ <span className="text-gray-400">Bio: {test.biologicalAge}</span>+ <span className="text-gray-400">Pace: {test.paceOfAging}</span>+ </div>+ ))}+ </div></div>- </div>- )}- </div>+ )}+ </div>+ ) : (+ <div className="bg-port-card border border-port-border rounded-xl p-6">+ <p className="text-gray-500 text-sm">No epigenetic age data. Import your health data to see results.</p>+ </div>+ )}</div>);}diff --git a/client/src/components/meatspace/tabs/CalendarTab.jsx b/client/src/components/meatspace/tabs/CalendarTab.jsxindex 1f7c9ae6cc..fa997883e8 100644--- a/client/src/components/meatspace/tabs/CalendarTab.jsx+++ b/client/src/components/meatspace/tabs/CalendarTab.jsx@@ -4,6 +4,7 @@ import {Cake, Plane, Plus, Trash2, Circle, Sun, Moon, TreePine, Snowflake,Flower2, CloudSun, Settings2} from 'lucide-react';+import { Link } from 'react-router-dom';import toast from 'react-hot-toast';import * as api from '../../../services/api';import BrailleSpinner from '../../BrailleSpinner';@@ -62,11 +63,18 @@ function computeEventWeeks(birthDate, grid, stats) {// === View Mode Config ===-const VIEW_MODES = [- { id: 'year', label: 'Year (52 weeks/row)', weeksPerRow: 52 },- { id: 'half', label: 'Half Year (26 weeks/row)', weeksPerRow: 26 },- { id: 'quarter', label: 'Quarter (13 weeks/row)', weeksPerRow: 13 },- { id: 'auto', label: 'Auto-fit', weeksPerRow: null },+const UNIT_MODES = [+ { id: 'years', label: 'Years' },+ { id: 'months', label: 'Months' },+ { id: 'weeks', label: 'Weeks' },+ { id: 'days', label: 'Days' },+];++const WEEK_LAYOUTS = [+ { id: 'year', label: '1Y', weeksPerRow: 52 },+ { id: 'half', label: '6M', weeksPerRow: 26 },+ { id: 'quarter', label: '3M', weeksPerRow: 13 },+ { id: 'auto', label: 'Auto', weeksPerRow: null },];const CELL_SIZES = [@@ -76,20 +84,253 @@ const CELL_SIZES = [{ id: 'lg', label: 'L', size: 12, gap: 2 },];-// === Life Grid ===+const MS_PER_DAY = 86400000;-function LifeGrid({ grid, stats, birthDate }) {- const [viewMode, setViewMode] = useState('auto');- const [cellSizeId, setCellSizeId] = useState('sm');- const [showEvents, setShowEvents] = useState(true);- const [hideSpent, setHideSpent] = useState(false);- const [showConfig, setShowConfig] = useState(false);+// === Grid computation helpers ===++function computeYearGrid(birthDate, deathDate) {+ const birth = new Date(birthDate);+ const death = new Date(deathDate);+ const now = new Date();+ const totalYears = Math.ceil((death - birth) / (365.25 * MS_PER_DAY));+ const cells = [];+ for (let y = 0; y < totalYears; y++) {+ const yearStart = new Date(birth);+ yearStart.setFullYear(birth.getFullYear() + y);+ const yearEnd = new Date(yearStart);+ yearEnd.setFullYear(yearEnd.getFullYear() + 1);+ let status;+ if (yearEnd <= now) status = 's';+ else if (yearStart <= now && now < yearEnd) status = 'c';+ else if (yearStart > death) break;+ else status = 'r';+ cells.push({ index: y, label: `Age ${y}`, status });+ }+ return cells;+}++function computeMonthGrid(birthDate, deathDate) {+ const birth = new Date(birthDate);+ const death = new Date(deathDate);+ const now = new Date();+ const cells = [];+ const cursor = new Date(birth);+ let i = 0;+ while (cursor < death) {+ const monthStart = new Date(cursor);+ const monthEnd = new Date(cursor);+ monthEnd.setMonth(monthEnd.getMonth() + 1);+ let status;+ if (monthEnd <= now) status = 's';+ else if (monthStart <= now && now < monthEnd) status = 'c';+ else status = 'r';+ const age = Math.floor(i / 12);+ const mo = i % 12;+ cells.push({ index: i, age, month: mo, label: `Age ${age}, Month ${mo + 1}`, status });+ cursor.setMonth(cursor.getMonth() + 1);+ i++;+ }+ return cells;+}++function computeDayGrid(birthDate, deathDate, selectedYear) {+ const birth = new Date(birthDate);+ const yearStart = new Date(birth);+ yearStart.setFullYear(birth.getFullYear() + selectedYear);+ const yearEnd = new Date(yearStart);+ yearEnd.setFullYear(yearEnd.getFullYear() + 1);+ const death = new Date(deathDate);+ const now = new Date();+ const cells = [];+ const cursor = new Date(yearStart);+ let dayIdx = 0;+ while (cursor < yearEnd && cursor < death) {+ const dayStart = new Date(cursor);+ const dayEnd = new Date(cursor.getTime() + MS_PER_DAY);+ let status;+ if (dayEnd <= now) status = 's';+ else if (dayStart <= now && now < dayEnd) status = 'c';+ else status = 'r';+ cells.push({ index: dayIdx, dayOfWeek: cursor.getDay(), label: cursor.toLocaleDateString(), status });+ cursor.setDate(cursor.getDate() + 1);+ dayIdx++;+ }+ return cells;+}++function cellBgClass(status, isCurrent) {+ if (status === 'c') return 'bg-port-accent shadow-[0_0_4px_rgba(59,130,246,0.5)]';+ if (status === 's') return isCurrent ? 'bg-gray-500' : 'bg-gray-700';+ return 'bg-port-success/20';+}++// === Year Grid ===++function YearGridView({ birthDate, deathDate, cellCfg, hideSpent }) {+ const cells = useMemo(() => computeYearGrid(birthDate, deathDate), [birthDate, deathDate]);+ const currentAge = Math.floor((Date.now() - new Date(birthDate).getTime()) / (365.25 * MS_PER_DAY));+ const filtered = hideSpent ? cells.filter(c => c.status === 'c' || c.status === 'r') : cells;+ const cols = 10;++ const rows = useMemo(() => {+ const result = [];+ for (let i = 0; i < filtered.length; i += cols) {+ result.push(filtered.slice(i, i + cols));+ }+ return result;+ }, [filtered]);++ return (+ <div className="overflow-x-auto">+ <div style={{ display: 'flex', flexDirection: 'column', gap: `${cellCfg.gap + 1}px` }}>+ {rows.map((row, ri) => (+ <div key={ri} style={{ display: 'flex', alignItems: 'center', gap: `${cellCfg.gap + 1}px` }}>+ <span className="text-right shrink-0 text-gray-500" style={{ width: '28px', fontSize: '9px' }}>+ {row[0]?.index ?? ''}+ </span>+ {row.map((cell) => (+ <span+ key={cell.index}+ className={`shrink-0 rounded-sm ${cellBgClass(cell.status, cell.index === currentAge)}`}+ style={{ width: `${cellCfg.size + 6}px`, height: `${cellCfg.size + 6}px` }}+ title={cell.label}+ />+ ))}+ </div>+ ))}+ </div>+ </div>+ );+}++// === Month Grid ===++function MonthGridView({ birthDate, deathDate, cellCfg, hideSpent }) {+ const cells = useMemo(() => computeMonthGrid(birthDate, deathDate), [birthDate, deathDate]);+ const currentAge = Math.floor((Date.now() - new Date(birthDate).getTime()) / (365.25 * MS_PER_DAY));+ const filtered = hideSpent ? cells.filter(c => c.status === 'c' || c.status === 'r') : cells;++ const rows = useMemo(() => {+ const result = [];+ for (let i = 0; i < filtered.length; i += 12) {+ const row = filtered.slice(i, i + 12);+ result.push({ label: row[0]?.age, cells: row });+ }+ return result;+ }, [filtered]);+ const shouldLabel = (age) => age != null && age % 10 === 0;++ return (+ <div className="overflow-x-auto">+ <div style={{ display: 'flex', flexDirection: 'column', gap: `${cellCfg.gap}px` }}>+ {rows.map((row, ri) => (+ <div key={ri} style={{ display: 'flex', alignItems: 'center', gap: `${cellCfg.gap}px` }}>+ <span+ className={`text-right shrink-0 ${shouldLabel(row.label) ? 'text-gray-400 font-medium' : 'text-transparent'}`}+ style={{ width: '24px', fontSize: '9px' }}+ >+ {shouldLabel(row.label) ? row.label : '.'}+ </span>+ {row.cells.map((cell) => (+ <span+ key={cell.index}+ className={`shrink-0 rounded-[1px] ${cellBgClass(cell.status, cell.age === currentAge)}`}+ style={{ width: `${cellCfg.size + 2}px`, height: `${cellCfg.size + 2}px` }}+ title={cell.label}+ />+ ))}+ </div>+ ))}+ </div>+ </div>+ );+}++// === Day Grid (single year) ===++function DayGridView({ birthDate, deathDate, cellCfg, stats }) {const currentAge = Math.floor(stats.age.years);- const cellCfg = CELL_SIZES.find(c => c.id === cellSizeId) || CELL_SIZES[1];- const viewCfg = VIEW_MODES.find(v => v.id === viewMode) || VIEW_MODES[0];+ const totalYears = Math.ceil((new Date(deathDate) - new Date(birthDate)) / (365.25 * MS_PER_DAY));+ const [selectedYear, setSelectedYear] = useState(currentAge);++ const cells = useMemo(() => computeDayGrid(birthDate, deathDate, selectedYear), [birthDate, deathDate, selectedYear]);++ // Group into rows of 7 (week rows)+ const rows = useMemo(() => {+ const result = [];+ // Pad start to align with day of week+ const firstDow = cells[0]?.dayOfWeek ?? 0;+ const padded = [...Array(firstDow).fill(null), ...cells];+ for (let i = 0; i < padded.length; i += 7) {+ result.push(padded.slice(i, i + 7));+ }+ return result;+ }, [cells]);++ const dayLabels = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];++ return (+ <div>+ <div className="flex items-center gap-3 mb-3">+ <button+ onClick={() => setSelectedYear(Math.max(0, selectedYear - 1))}+ className="px-2 py-0.5 text-xs text-gray-400 hover:text-white rounded bg-port-bg border border-port-border"+ >+ ←+ </button>+ <span className="text-sm text-white font-medium">Age {selectedYear}</span>+ <button+ onClick={() => setSelectedYear(Math.min(totalYears - 1, selectedYear + 1))}+ className="px-2 py-0.5 text-xs text-gray-400 hover:text-white rounded bg-port-bg border border-port-border"+ >+ →+ </button>+ {selectedYear !== currentAge && (+ <button+ onClick={() => setSelectedYear(currentAge)}+ className="px-2 py-0.5 text-xs text-port-accent hover:text-white"+ >+ Current+ </button>+ )}+ </div>+ <div className="overflow-x-auto">+ <div style={{ display: 'flex', flexDirection: 'column', gap: `${cellCfg.gap}px` }}>+ {/* Day-of-week header */}+ <div style={{ display: 'flex', gap: `${cellCfg.gap}px`, marginLeft: '0px' }}>+ {dayLabels.map((d, i) => (+ <span key={i} className="text-center text-gray-600 shrink-0" style={{ width: `${cellCfg.size}px`, fontSize: '8px' }}>+ {d}+ </span>+ ))}+ </div>+ {rows.map((row, ri) => (+ <div key={ri} style={{ display: 'flex', gap: `${cellCfg.gap}px` }}>+ {row.map((cell, ci) => cell ? (+ <span+ key={ci}+ className={`shrink-0 rounded-[1px] ${cellBgClass(cell.status, false)}`}+ style={{ width: `${cellCfg.size}px`, height: `${cellCfg.size}px` }}+ title={cell.label}+ />+ ) : (+ <span key={ci} className="shrink-0" style={{ width: `${cellCfg.size}px`, height: `${cellCfg.size}px` }} />+ ))}+ </div>+ ))}+ </div>+ </div>+ </div>+ );+}++// === Week Grid (original) ===++function WeekGridView({ grid, stats, birthDate, cellCfg, weekLayout, hideSpent, showEvents }) {+ const currentAge = Math.floor(stats.age.years);+ const layoutCfg = WEEK_LAYOUTS.find(v => v.id === weekLayout) || WEEK_LAYOUTS[0];- // Flatten all weeks into a single array with metadataconst allWeeks = useMemo(() => {const weeks = [];for (const row of grid) {@@ -100,60 +341,124 @@ function LifeGrid({ grid, stats, birthDate }) {return weeks;}, [grid]);- // Compute event markersconst eventWeeks = useMemo(() => showEvents ? computeEventWeeks(birthDate, grid, stats) : new Map(),[birthDate, grid, stats, showEvents]);- // Determine weeks per row- const weeksPerRow = viewCfg.weeksPerRow || 104; // auto = ~2 years per row for wide screens+ const weeksPerRow = layoutCfg.weeksPerRow || 104;- // Filter grid when hiding spentconst filteredGrid = useMemo(() => {if (!hideSpent) return grid;return grid.filter(row => row.weeks.some(s => s === 'c' || s === 'r'));}, [grid, hideSpent]);- // Group weeks into rowsconst rows = useMemo(() => {- if (viewMode !== 'auto' && viewCfg.weeksPerRow) {- // Year-aligned: use grid rows directly, but split/merge as needed- if (viewCfg.weeksPerRow === 52) {+ if (weekLayout !== 'auto' && layoutCfg.weeksPerRow) {+ if (layoutCfg.weeksPerRow === 52) {return filteredGrid.map(row => ({ label: row.age, weeks: row.weeks.map((s, w) => ({ age: row.age, week: w, status: s })) }));}- // Sub-year: split each year rowconst result = [];for (const row of filteredGrid) {- for (let start = 0; start < row.weeks.length; start += viewCfg.weeksPerRow) {- const slice = row.weeks.slice(start, start + viewCfg.weeksPerRow);+ for (let start = 0; start < row.weeks.length; start += layoutCfg.weeksPerRow) {+ const slice = row.weeks.slice(start, start + layoutCfg.weeksPerRow);const label = start === 0 ? row.age : null;result.push({ label, weeks: slice.map((s, i) => ({ age: row.age, week: start + i, status: s })) });}}return result;}- // Auto-fit: pack all weeks into rows of weeksPerRowconst result = [];for (let i = 0; i < allWeeks.length; i += weeksPerRow) {const slice = allWeeks.slice(i, i + weeksPerRow);const firstAge = slice[0]?.age;- const label = i === 0 || firstAge !== allWeeks[Math.max(0, i - 1)]?.age ? firstAge : null;result.push({ label: firstAge, weeks: slice });}return result;- }, [filteredGrid, allWeeks, viewMode, viewCfg, weeksPerRow, hideSpent]);+ }, [filteredGrid, allWeeks, weekLayout, layoutCfg, weeksPerRow, hideSpent]);- // Decade/5-year labelsconst shouldLabel = (age) => age != null && age % 10 === 0;+ return (+ <div className="overflow-x-auto">+ <div style={{ display: 'flex', flexDirection: 'column', gap: `${cellCfg.gap}px` }}>+ {rows.map((row, ri) => (+ <div key={ri} style={{ display: 'flex', alignItems: 'center', gap: `${cellCfg.gap}px` }}>+ <span+ className={`text-right shrink-0 ${shouldLabel(row.label) ? 'text-gray-400 font-medium' : 'text-transparent'}`}+ style={{ width: '24px', fontSize: '9px' }}+ >+ {shouldLabel(row.label) ? row.label : '.'}+ </span>+ {row.weeks.map((cell, wi) => {+ const eventId = eventWeeks.get(`${cell.age}-${cell.week}`);+ const eventCfg = eventId ? EVENT_COLORS.find(e => e.id === eventId) : null;++ let bgClass;+ if (eventCfg && cell.status === 'r') {+ bgClass = eventCfg.color;+ } else if (cell.status === 'c') {+ bgClass = 'bg-port-accent shadow-[0_0_4px_rgba(59,130,246,0.5)]';+ } else if (cell.status === 's') {+ bgClass = cell.age === currentAge ? 'bg-gray-500' : 'bg-gray-700';+ } else {+ bgClass = 'bg-port-success/20';+ }++ return (+ <span+ key={wi}+ className={`shrink-0 rounded-[1px] ${bgClass} ${eventCfg ? `ring-1 ${eventCfg.ring}` : ''}`}+ style={{ width: `${cellCfg.size}px`, height: `${cellCfg.size}px` }}+ title={`Age ${cell.age}, Week ${cell.week + 1}${eventCfg ? ` — ${eventCfg.label}` : ''}`}+ />+ );+ })}+ </div>+ ))}+ </div>+ </div>+ );+}++// === Life Grid (main component) ===++function LifeGrid({ grid, stats, birthDate, deathDate }) {+ const [unit, setUnit] = useState('weeks');+ const [weekLayout, setWeekLayout] = useState('year');+ const [cellSizeId, setCellSizeId] = useState('sm');+ const [showEvents, setShowEvents] = useState(true);+ const [hideSpent, setHideSpent] = useState(false);+ const [showConfig, setShowConfig] = useState(false);++ const cellCfg = CELL_SIZES.find(c => c.id === cellSizeId) || CELL_SIZES[1];++ const unitLabel = {+ years: `Year ${Math.floor(stats.age.years)} of ${Math.ceil(stats.remaining.years + stats.age.years)}`,+ months: `Month ${Math.floor(stats.age.years * 12)} of ${Math.floor((stats.remaining.years + stats.age.years) * 12)}`,+ weeks: `Week ${stats.age.weeks.toLocaleString()} of ${stats.total.weeks.toLocaleString()}`,+ days: `Day ${stats.age.days.toLocaleString()} of ${Math.floor((stats.remaining.days || 0) + stats.age.days).toLocaleString()}`,+ };+return (<div className="bg-port-card border border-port-border rounded-lg p-4"><div className="flex items-center gap-2 mb-3 flex-wrap"><Calendar size={16} className="text-port-accent" />- <h3 className="text-sm font-medium text-white">Life in Weeks</h3>+ <h3 className="text-sm font-medium text-white">Life Calendar</h3>+ {/* Unit toggle */}+ <div className="flex items-center gap-0.5 ml-2 bg-port-bg rounded-md p-0.5 border border-port-border">+ {UNIT_MODES.map(u => (+ <button+ key={u.id}+ onClick={() => setUnit(u.id)}+ className={`px-2 py-0.5 text-xs rounded transition-colors ${unit === u.id ? 'bg-port-accent/20 text-port-accent font-medium' : 'text-gray-400 hover:text-white'}`}+ >+ {u.label}+ </button>+ ))}+ </div><span className="text-xs text-gray-500 ml-auto">- Week {stats.age.weeks.toLocaleString()} of {stats.total.weeks.toLocaleString()}+ {unitLabel[unit]}</span><buttononClick={() => setShowConfig(v => !v)}@@ -167,18 +472,20 @@ function LifeGrid({ grid, stats, birthDate }) {{/* Config panel */}{showConfig && (<div className="flex flex-wrap items-center gap-4 mb-3 p-2 bg-port-bg rounded-lg border border-port-border">- <div className="flex items-center gap-2">- <span className="text-xs text-gray-500">Layout:</span>- {VIEW_MODES.map(v => (- <button- key={v.id}- onClick={() => setViewMode(v.id)}- className={`px-2 py-0.5 text-xs rounded ${viewMode === v.id ? 'bg-port-accent/20 text-port-accent' : 'text-gray-400 hover:text-white'}`}- >- {v.id === 'auto' ? 'Auto' : v.id === 'year' ? '1Y' : v.id === 'half' ? '6M' : '3M'}- </button>- ))}- </div>+ {unit === 'weeks' && (+ <div className="flex items-center gap-2">+ <span className="text-xs text-gray-500">Layout:</span>+ {WEEK_LAYOUTS.map(v => (+ <button+ key={v.id}+ onClick={() => setWeekLayout(v.id)}+ className={`px-2 py-0.5 text-xs rounded ${weekLayout === v.id ? 'bg-port-accent/20 text-port-accent' : 'text-gray-400 hover:text-white'}`}+ >+ {v.label}+ </button>+ ))}+ </div>+ )}<div className="flex items-center gap-2"><span className="text-xs text-gray-500">Size:</span>{CELL_SIZES.map(c => (@@ -191,14 +498,18 @@ function LifeGrid({ grid, stats, birthDate }) {</button>))}</div>- <label className="flex items-center gap-1.5 text-xs text-gray-400 cursor-pointer">- <input type="checkbox" checked={showEvents} onChange={(e) => setShowEvents(e.target.checked)} className="rounded border-port-border" />- Birthdays- </label>- <label className="flex items-center gap-1.5 text-xs text-gray-400 cursor-pointer">- <input type="checkbox" checked={hideSpent} onChange={(e) => setHideSpent(e.target.checked)} className="rounded border-port-border" />- Hide spent- </label>+ {unit === 'weeks' && (+ <label className="flex items-center gap-1.5 text-xs text-gray-400 cursor-pointer">+ <input type="checkbox" checked={showEvents} onChange={(e) => setShowEvents(e.target.checked)} className="rounded border-port-border" />+ Birthdays+ </label>+ )}+ {unit !== 'days' && (+ <label className="flex items-center gap-1.5 text-xs text-gray-400 cursor-pointer">+ <input type="checkbox" checked={hideSpent} onChange={(e) => setHideSpent(e.target.checked)} className="rounded border-port-border" />+ Hide spent+ </label>+ )}</div>)}@@ -207,57 +518,26 @@ function LifeGrid({ grid, stats, birthDate }) {<span className="flex items-center gap-1"><span className="w-2 h-2 rounded-sm bg-gray-600" /> Spent</span><span className="flex items-center gap-1"><span className="w-2 h-2 rounded-sm bg-port-accent" /> Now</span><span className="flex items-center gap-1"><span className="w-2 h-2 rounded-sm bg-port-success/30" /> Remaining</span>- {showEvents && (- <>- {EVENT_COLORS.filter(e => e.id === 'birthday').map(e => (- <span key={e.id} className="flex items-center gap-1">- <span className={`w-2 h-2 rounded-sm ${e.color}`} /> {e.label}- </span>- ))}- </>- )}+ {unit === 'weeks' && showEvents && EVENT_COLORS.filter(e => e.id === 'birthday').map(e => (+ <span key={e.id} className="flex items-center gap-1">+ <span className={`w-2 h-2 rounded-sm ${e.color}`} /> {e.label}+ </span>+ ))}</div>{/* Grid */}- <div className="overflow-x-auto">- <div style={{ display: 'flex', flexDirection: 'column', gap: `${cellCfg.gap}px` }}>- {rows.map((row, ri) => (- <div key={ri} style={{ display: 'flex', alignItems: 'center', gap: `${cellCfg.gap}px` }}>- {/* Age label */}- <span- className={`text-right shrink-0 ${shouldLabel(row.label) ? 'text-gray-400 font-medium' : 'text-transparent'}`}- style={{ width: '24px', fontSize: '9px' }}- >- {shouldLabel(row.label) ? row.label : '.'}- </span>- {row.weeks.map((cell, wi) => {- const eventId = eventWeeks.get(`${cell.age}-${cell.week}`);- const eventCfg = eventId ? EVENT_COLORS.find(e => e.id === eventId) : null;-- let bgClass;- if (eventCfg && cell.status === 'r') {- bgClass = eventCfg.color;- } else if (cell.status === 'c') {- bgClass = 'bg-port-accent shadow-[0_0_4px_rgba(59,130,246,0.5)]';- } else if (cell.status === 's') {- bgClass = cell.age === currentAge ? 'bg-gray-500' : 'bg-gray-700';- } else {- bgClass = 'bg-port-success/20';- }-- return (- <span- key={wi}- className={`shrink-0 rounded-[1px] ${bgClass} ${eventCfg ? `ring-1 ${eventCfg.ring}` : ''}`}- style={{ width: `${cellCfg.size}px`, height: `${cellCfg.size}px` }}- title={`Age ${cell.age}, Week ${cell.week + 1}${eventCfg ? ` — ${eventCfg.label}` : ''}`}- />- );- })}- </div>- ))}- </div>- </div>+ {unit === 'years' && (+ <YearGridView birthDate={birthDate} deathDate={deathDate} cellCfg={cellCfg} hideSpent={hideSpent} />+ )}+ {unit === 'months' && (+ <MonthGridView birthDate={birthDate} deathDate={deathDate} cellCfg={cellCfg} hideSpent={hideSpent} />+ )}+ {unit === 'weeks' && (+ <WeekGridView grid={grid} stats={stats} birthDate={birthDate} cellCfg={cellCfg} weekLayout={weekLayout} hideSpent={hideSpent} showEvents={showEvents} />+ )}+ {unit === 'days' && (+ <DayGridView birthDate={birthDate} deathDate={deathDate} cellCfg={cellCfg} stats={stats} />+ )}</div>);}@@ -480,16 +760,25 @@ export default function CalendarTab() {}if (error || data?.error) {+ const isBirthDateMissing = (error || data?.error || '').includes('Birth date not set');return (<div className="text-center py-12"><Calendar size={48} className="text-gray-600 mx-auto mb-4" /><p className="text-gray-400 mb-2">Life calendar unavailable</p>- <p className="text-sm text-gray-500">{error || data.error}</p>+ <p className="text-sm text-gray-500 mb-4">{error || data.error}</p>+ {isBirthDateMissing && (+ <Link+ to="/meatspace/age"+ className="inline-block px-4 py-2 rounded bg-port-accent/20 text-port-accent hover:bg-port-accent/30 text-sm"+ >+ Set Birth Date+ </Link>+ )}</div>);}- const { stats, grid, budgets, birthDate } = data;+ const { stats, grid, budgets, birthDate, deathDate } = data;const pctSpent = stats.age.weeks / stats.total.weeks * 100;const pctColor = pctSpent < 50 ? 'text-port-accent' : pctSpent < 75 ? 'text-port-warning' : 'text-port-error';@@ -529,7 +818,7 @@ export default function CalendarTab() {</div>{/* Life Grid */}- <LifeGrid grid={grid} stats={stats} birthDate={birthDate} />+ <LifeGrid grid={grid} stats={stats} birthDate={birthDate} deathDate={deathDate} />{/* Time remaining stats */}<TimeStats stats={stats} />diff --git a/client/src/services/api.js b/client/src/services/api.jsindex 9cfc86b2d9..b98b240961 100644--- a/client/src/services/api.js+++ b/client/src/services/api.js@@ -1420,6 +1420,11 @@ export const updateMeatspaceLifestyle = (data) => request('/meatspace/lifestyle'method: 'PUT',body: JSON.stringify(data)});+export const getMeatspaceBirthDate = () => request('/meatspace/birth-date');+export const setMeatspaceBirthDate = (birthDate) => request('/meatspace/birth-date', {+ method: 'PUT',+ body: JSON.stringify({ birthDate })+});export const getDeathClock = () => request('/meatspace/death-clock');export const getLEV = () => request('/meatspace/lev');export const getAlcoholSummary = () => request('/meatspace/alcohol');diff --git a/server/routes/meatspace.js b/server/routes/meatspace.jsindex 2dcd54ea11..1b9ce3da8a 100644--- a/server/routes/meatspace.js+++ b/server/routes/meatspace.js@@ -16,6 +16,7 @@ import {activitySchema,activityUpdateSchema,} from '../lib/meatspaceValidation.js';+import { birthDateInputSchema } from '../lib/identityValidation.js';import {postSessionSubmitSchema,postConfigUpdateSchema,@@ -78,6 +79,29 @@ router.put('/lifestyle', asyncHandler(async (req, res) => {res.json(config);}));+// =============================================================================+// BIRTH DATE+// =============================================================================++/**+ * GET /api/meatspace/birth-date+ * Get birth date (migrates from goals.json on first read)+ */+router.get('/birth-date', asyncHandler(async (req, res) => {+ const result = await meatspaceService.getBirthDate();+ res.json(result);+}));++/**+ * PUT /api/meatspace/birth-date+ * Set or update birth date+ */+router.put('/birth-date', asyncHandler(async (req, res) => {+ const { birthDate } = validateRequest(birthDateInputSchema, req.body);+ const result = await meatspaceService.updateBirthDate(birthDate);+ res.json(result);+}));+// =============================================================================// DEATH CLOCK & LEV// =============================================================================diff --git a/server/services/identity.js b/server/services/identity.jsindex 89308d2fe5..c73aa52548 100644--- a/server/services/identity.js+++ b/server/services/identity.js@@ -671,6 +671,10 @@ export async function setBirthDate(birthDate) {goals.updatedAt = new Date().toISOString();await saveJSON(GOALS_FILE, goals);+ // Sync to meatspace config (canonical source), skip goals sync since we just wrote it+ const { updateBirthDate } = await import('./meatspace.js');+ await updateBirthDate(birthDate, { syncGoals: false });+// Re-derive longevity with new birth dateconst longevity = await deriveLongevity(birthDate);diff --git a/server/services/meatspace.js b/server/services/meatspace.jsindex 29ea14572e..37d63be755 100644--- a/server/services/meatspace.js+++ b/server/services/meatspace.js@@ -21,6 +21,7 @@ const GOALS_FILE = join(PATHS.digitalTwin, 'goals.json');const SSA_BASELINE = 78.5;const DEFAULT_CONFIG = {+ birthDate: null,sex: null,sexSource: null,lifestyle: {@@ -218,16 +219,54 @@ export async function updateLifestyle(updates) {return config;}+// === Birth Date (canonical source: meatspace/config.json) ===++async function migrateBirthDateFromGoals(config) {+ if (config.birthDate) return config;+ const goals = await readJSONFile(GOALS_FILE, null);+ if (!goals?.birthDate) return config;+ config.birthDate = goals.birthDate;+ config.updatedAt = new Date().toISOString();+ await saveConfig(config);+ console.log(`📅 Migrated birthDate from goals.json to meatspace config`);+ return config;+}++export async function getBirthDate() {+ const config = await loadConfig();+ const migrated = await migrateBirthDateFromGoals(config);+ return { birthDate: migrated.birthDate };+}++export async function updateBirthDate(birthDate, { syncGoals = true } = {}) {+ const config = await loadConfig();+ config.birthDate = birthDate;+ config.updatedAt = new Date().toISOString();+ await saveConfig(config);++ // Keep goals.json in sync for backward compatibility+ if (syncGoals) {+ const goals = await readJSONFile(GOALS_FILE, null);+ if (goals) {+ goals.birthDate = birthDate;+ goals.updatedAt = new Date().toISOString();+ await writeFile(join(PATHS.digitalTwin, 'goals.json'), JSON.stringify(goals, null, 2));+ }+ }++ return { birthDate };+}+export async function getDeathClock() {- const [config, longevity, goals] = await Promise.all([+ const [config, longevity] = await Promise.all([loadConfig(),- readJSONFile(LONGEVITY_FILE, null),- readJSONFile(GOALS_FILE, null)+ readJSONFile(LONGEVITY_FILE, null)]);- const birthDate = goals?.birthDate;+ const migrated = await migrateBirthDateFromGoals(config);+ const birthDate = migrated.birthDate;if (!birthDate) {- return { error: 'Birth date not set. Set it in Digital Twin > Goals.' };+ return { error: 'Birth date not set. Go to MeatSpace > Age to set it.' };}const genomeAdjusted = longevity?.lifeExpectancy?.adjusted ?? null;@@ -237,17 +276,17 @@ export async function getDeathClock() {}export async function getLEV() {- const [longevity, goals, config] = await Promise.all([+ const [longevity, config] = await Promise.all([readJSONFile(LONGEVITY_FILE, null),- readJSONFile(GOALS_FILE, null),loadConfig()]);+ const migrated = await migrateBirthDateFromGoals(config);const genomeAdjusted = longevity?.lifeExpectancy?.adjusted ?? SSA_BASELINE;- const lifestyleAdj = computeLifestyleAdjustment(config.lifestyle);+ const lifestyleAdj = computeLifestyleAdjustment(migrated.lifestyle);const totalLE = genomeAdjusted + lifestyleAdj;- return computeLEV(goals?.birthDate, totalLE);+ return computeLEV(migrated.birthDate, totalLE);}export async function getOverview() {