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(identity): cross-insights engine connecting genome, chronotype, longevity, and goals
Adam Eivy68baf5089f87
diff --git a/client/src/components/digital-twin/tabs/IdentityTab.jsx b/client/src/components/digital-twin/tabs/IdentityTab.jsxindex 8135da353c..66582bc6ee 100644--- a/client/src/components/digital-twin/tabs/IdentityTab.jsx+++ b/client/src/components/digital-twin/tabs/IdentityTab.jsx@@ -3,7 +3,8 @@ import { useNavigate } from 'react-router-dom';import {Fingerprint, Dna, Clock, Activity, Palette, Target,ChevronRight, RefreshCw, Sun, Moon, Coffee, Zap,- Heart, DollarSign, Lightbulb, Users, Flame+ Heart, DollarSign, Lightbulb, Users, Flame, Link2,+ AlertTriangle, CheckCircle, Info} from 'lucide-react';import * as api from '../../../services/api';@@ -44,6 +45,19 @@ function urgencyLabel(urgency) {return 'Low';}+const SEVERITY_CONFIG = {+ success: { icon: CheckCircle, color: 'text-green-400', border: 'border-green-500/30', bg: 'bg-green-500/10' },+ warning: { icon: AlertTriangle, color: 'text-yellow-400', border: 'border-yellow-500/30', bg: 'bg-yellow-500/10' },+ info: { icon: Info, color: 'text-blue-400', border: 'border-blue-500/30', bg: 'bg-blue-500/10' }+};++const CATEGORY_LABELS = {+ health: 'Health',+ lifestyle: 'Lifestyle',+ productivity: 'Productivity',+ goals: 'Goals'+};+export default function IdentityTab({ onRefresh }) {const navigate = useNavigate();const [loading, setLoading] = useState(true);@@ -52,22 +66,25 @@ export default function IdentityTab({ onRefresh }) {const [longevity, setLongevity] = useState(null);const [taste, setTaste] = useState(null);const [goals, setGoals] = useState(null);+ const [crossInsights, setCrossInsights] = useState(null);const [derivingChronotype, setDerivingChronotype] = useState(false);const [derivingLongevity, setDerivingLongevity] = useState(false);const loadData = useCallback(async () => {- const [identityData, chronoData, longData, tasteData, goalsData] = await Promise.all([+ const [identityData, chronoData, longData, tasteData, goalsData, insightsData] = await Promise.all([api.getIdentityStatus().catch(() => null),api.getChronotype().catch(() => null),api.getLongevity().catch(() => null),api.getTasteProfile().catch(() => null),- api.getGoals().catch(() => null)+ api.getGoals().catch(() => null),+ api.getCrossInsights().catch(() => null)]);setIdentity(identityData);setChronotype(chronoData);setLongevity(longData);setTaste(tasteData);setGoals(goalsData);+ setCrossInsights(insightsData);setLoading(false);}, []);@@ -484,6 +501,60 @@ export default function IdentityTab({ onRefresh }) {</button></div></div>++ {/* Cross-Insights Section */}+ {crossInsights?.insights?.length > 0 && (+ <div className="bg-port-card border border-port-border rounded-lg p-4">+ <div className="flex items-center gap-2 mb-4">+ <Link2 className="w-5 h-5 text-port-accent" />+ <h3 className="font-medium text-white">Cross-Domain Insights</h3>+ <span className="text-xs text-gray-500 ml-auto">+ {crossInsights.insights.length} insight{crossInsights.insights.length !== 1 ? 's' : ''}+ </span>+ </div>++ <div className="space-y-3">+ {crossInsights.insights.map(insight => {+ const config = SEVERITY_CONFIG[insight.severity] || SEVERITY_CONFIG.info;+ const SeverityIcon = config.icon;+ return (+ <div+ key={insight.id}+ className={`flex gap-3 p-3 rounded-lg border ${config.border} ${config.bg}`}+ >+ <SeverityIcon className={`w-4 h-4 shrink-0 mt-0.5 ${config.color}`} />+ <div className="min-w-0">+ <div className="flex items-center gap-2 mb-1">+ <span className="text-sm font-medium text-white">{insight.title}</span>+ <span className="text-[10px] text-gray-500 bg-port-bg px-1.5 py-0.5 rounded">+ {CATEGORY_LABELS[insight.category] || insight.category}+ </span>+ </div>+ <p className="text-xs text-gray-400 leading-relaxed">{insight.text}</p>+ {insight.sources?.length > 0 && (+ <div className="flex gap-1 mt-2">+ {insight.sources.map(src => (+ <span key={src} className="text-[10px] text-gray-600 bg-port-bg px-1.5 py-0.5 rounded">+ {src}+ </span>+ ))}+ </div>+ )}+ </div>+ </div>+ );+ })}+ </div>++ <button+ onClick={() => navigate('/insights/cross-domain')}+ className="flex items-center gap-1 mt-4 text-sm text-port-accent hover:text-white transition-colors"+ >+ View Full Insights+ <ChevronRight className="w-4 h-4" />+ </button>+ </div>+ )}</div>);}diff --git a/client/src/services/api.js b/client/src/services/api.jsindex 097d507841..5d2046206b 100644--- a/client/src/services/api.js+++ b/client/src/services/api.js@@ -1345,6 +1345,7 @@ export const deleteEpigeneticIntervention = (id) => request(`/meatspace/genome/e// Digital Twin - Identityexport const getIdentityStatus = () => request('/digital-twin/identity');+export const getCrossInsights = () => request('/digital-twin/identity/cross-insights');export const getChronotype = () => request('/digital-twin/identity/chronotype');export const deriveChronotype = () => request('/digital-twin/identity/chronotype/derive', { method: 'POST' });export const updateChronotypeBehavioral = (data) => request('/digital-twin/identity/chronotype', {diff --git a/server/routes/identity.js b/server/routes/identity.jsindex 9aa3989b28..121ead968e 100644--- a/server/routes/identity.js+++ b/server/routes/identity.js@@ -54,6 +54,16 @@ router.put('/chronotype', asyncHandler(async (req, res) => {res.json(chronotype);}));+// =============================================================================+// CROSS-INSIGHTS+// =============================================================================++// GET /api/digital-twin/identity/cross-insights — Rule-based cross-domain insights+router.get('/cross-insights', asyncHandler(async (req, res) => {+ const result = await identityService.getCrossInsights();+ res.json(result);+}));+// =============================================================================// LONGEVITY// =============================================================================diff --git a/server/services/identity.js b/server/services/identity.jsindex cf5bc0d9a1..7b00f28720 100644--- a/server/services/identity.js+++ b/server/services/identity.js@@ -1351,3 +1351,224 @@ export async function deleteTodo(goalId, todoId) {await saveJSON(GOALS_FILE, goals);return { deleted: true };}++// =============================================================================+// CROSS-INSIGHTS ENGINE (P5)+// =============================================================================++const INSIGHT_RULES = [+ {+ id: 'caffeine-chronotype',+ category: 'lifestyle',+ evaluate({ chronotype }) {+ if (!chronotype?.caffeineMarkers || !chronotype?.recommendations?.caffeineCutoff) return null;+ const { cyp1a2, ada } = chronotype.caffeineMarkers;+ if (!cyp1a2 && !ada) return null;++ const markers = [cyp1a2?.rsid, ada?.rsid].filter(Boolean);+ const sources = ['genome', 'chronotype'];+ const isSlowMetabolizer = cyp1a2?.status === 'concern' || ada?.status === 'concern';+ const cutoff = chronotype.recommendations.caffeineCutoff;+ const type = chronotype.type || 'intermediate';++ if (isSlowMetabolizer) {+ return {+ severity: 'warning', title: 'Caffeine Sensitivity', markers, sources,+ text: `Your caffeine metabolism markers suggest slower processing. Combined with your ${type} chronotype, cut caffeine by ${cutoff} to protect sleep quality.`+ };+ }++ return {+ severity: 'info', title: 'Caffeine Timing', markers, sources,+ text: `Your caffeine metabolism is typical. With your ${type} chronotype, a ${cutoff} cutoff keeps caffeine from interfering with your sleep window.`+ };+ }+ },++ {+ id: 'mtnr1b-meal-timing',+ category: 'lifestyle',+ evaluate({ chronotype }) {+ const mtnr1b = chronotype?.geneticMarkers?.mtnr1b;+ if (!mtnr1b || mtnr1b.status === 'not_found') return null;++ const cutoff = chronotype?.recommendations?.lastMealCutoff;+ if (!cutoff || mtnr1b.status !== 'concern') return null;++ return {+ severity: 'warning', title: 'Late Eating Risk',+ text: `Your MTNR1B variant (${mtnr1b.genotype}) impairs nighttime glucose handling. Finish eating by ${cutoff} to avoid metabolic disruption during sleep.`,+ markers: [mtnr1b.rsid], sources: ['genome', 'chronotype']+ };+ }+ },++ {+ id: 'chronotype-deep-work',+ category: 'productivity',+ evaluate({ chronotype }) {+ if (!chronotype?.recommendations?.peakFocusStart) return null;+ const { peakFocusStart, peakFocusEnd } = chronotype.recommendations;+ const type = chronotype.type || 'intermediate';+ const confidence = chronotype.confidence ?? 0;+ if (confidence < 0.3) return null;++ return {+ severity: 'info', title: 'Peak Focus Window',+ text: `Your ${type} chronotype (${Math.round(confidence * 100)}% confidence) suggests peak focus between ${peakFocusStart}–${peakFocusEnd}. Schedule demanding cognitive work in this window.`,+ markers: [], sources: ['chronotype']+ };+ }+ },++ {+ id: 'longevity-overview',+ category: 'health',+ evaluate({ longevity }) {+ if (!longevity?.derivedAt) return null;+ const { lifeExpectancy, confidence } = longevity;+ if (confidence < 0.5) return null;++ const adjustment = (lifeExpectancy?.longevityAdjustment ?? 0) + (lifeExpectancy?.cardiovascularAdjustment ?? 0);+ const direction = adjustment >= 0 ? 'favorable' : 'unfavorable';++ return {+ severity: adjustment >= 0 ? 'success' : 'warning', title: 'Genetic Life Expectancy',+ text: `Your genome markers shift life expectancy by ${adjustment >= 0 ? '+' : ''}${Math.round(adjustment * 10) / 10} years from the ${lifeExpectancy?.baseline ?? 78.5}-year baseline (${direction} overall). Adjusted estimate: ${lifeExpectancy?.adjusted ?? '—'} years.`,+ markers: [], sources: ['genome', 'longevity']+ };+ }+ },++ {+ id: 'inflammation-health-goals',+ category: 'health',+ evaluate({ longevity, goals }) {+ const il6 = longevity?.cardiovascularMarkers?.il6;+ const tnfa = longevity?.cardiovascularMarkers?.tnfa;+ if (!il6 && !tnfa) return null;+ if (il6?.status !== 'concern' && tnfa?.status !== 'concern') return null;++ const healthGoals = (goals?.goals || []).filter(g => g.category === 'health' && g.status === 'active');+ const concernMarkers = [+ il6?.status === 'concern' ? `IL-6 (${il6.genotype})` : null,+ tnfa?.status === 'concern' ? `TNF-alpha (${tnfa.genotype})` : null+ ].filter(Boolean);++ const goalNote = healthGoals.length > 0+ ? `Your ${healthGoals.length} active health goal${healthGoals.length > 1 ? 's' : ''} align${healthGoals.length === 1 ? 's' : ''} with managing this risk.`+ : 'Consider adding health goals focused on anti-inflammatory lifestyle changes.';++ return {+ severity: 'warning', title: 'Inflammation Risk',+ text: `Elevated inflammation markers: ${concernMarkers.join(', ')}. These increase cardiovascular risk over time. ${goalNote}`,+ markers: [il6?.rsid, tnfa?.rsid].filter(Boolean), sources: ['genome', 'longevity', 'goals']+ };+ }+ },++ {+ id: 'longevity-goal-urgency',+ category: 'goals',+ evaluate({ longevity, goals }) {+ if (!longevity?.timeHorizons?.yearsRemaining) return null;+ const activeGoals = (goals?.goals || []).filter(g => g.status === 'active');+ if (!activeGoals.length) return null;++ const { yearsRemaining, percentLifeComplete } = longevity.timeHorizons;+ const horizonYears = { '1-year': 1, '3-year': 3, '5-year': 5, '10-year': 10, 'lifetime': yearsRemaining };+ const atRiskGoals = activeGoals.filter(g => (horizonYears[g.horizon] ?? 999) > yearsRemaining * 0.8);++ if (!atRiskGoals.length) {+ return {+ severity: 'info', title: 'Goal Timeline',+ text: `At ${Math.round(percentLifeComplete)}% life complete with ~${Math.round(yearsRemaining)} years remaining, all ${activeGoals.length} active goals fit within your projected timeline.`,+ markers: [], sources: ['longevity', 'goals']+ };+ }++ return {+ severity: 'warning', title: 'Goal Timeline Pressure',+ text: `At ${Math.round(percentLifeComplete)}% life complete, ${atRiskGoals.length} goal${atRiskGoals.length > 1 ? 's' : ''} may need reprioritization: ${atRiskGoals.map(g => g.title).join(', ')}. ~${Math.round(yearsRemaining)} estimated years remaining.`,+ markers: [], sources: ['longevity', 'goals']+ };+ }+ },++ {+ id: 'foxo3a-longevity',+ category: 'health',+ evaluate({ longevity }) {+ const foxo3a = longevity?.longevityMarkers?.foxo3a;+ if (!foxo3a || foxo3a.status !== 'concern') return null;++ return {+ severity: 'warning', title: 'FOXO3A Longevity Variant',+ text: `Your FOXO3A variant (${foxo3a.genotype}) is associated with reduced longevity. FOXO3A regulates stress resistance and cellular repair. Caloric moderation, exercise, and stress management can help activate compensatory pathways.`,+ markers: [foxo3a.rsid], sources: ['genome', 'longevity']+ };+ }+ },++ {+ id: 'terc-telomere',+ category: 'health',+ evaluate({ longevity }) {+ const terc = longevity?.longevityMarkers?.terc;+ if (!terc || terc.status !== 'concern') return null;++ return {+ severity: 'warning', title: 'Telomere Length',+ text: `Your TERC variant (${terc.genotype}) is linked to shorter telomere length, a marker of cellular aging. Regular aerobic exercise and stress reduction are associated with slower telomere attrition.`,+ markers: [terc.rsid], sources: ['genome', 'longevity']+ };+ }+ },++ {+ id: 'cardiovascular-protection',+ category: 'health',+ evaluate({ longevity }) {+ if (!longevity?.cardiovascularMarkers) return null;+ const markers = Object.values(longevity.cardiovascularMarkers);+ const beneficial = markers.filter(m => m.status === 'beneficial');+ if (beneficial.length < 2) return null;++ return {+ severity: 'success', title: 'Cardiovascular Protection',+ text: `${beneficial.length} of ${markers.length} cardiovascular markers show protective variants: ${beneficial.map(m => m.gene).join(', ')}. This provides a favorable baseline for heart health.`,+ markers: beneficial.map(m => m.rsid), sources: ['genome', 'longevity']+ };+ }+ }+];++export async function getCrossInsights() {+ const [chronotype, longevity, goalsData] = await Promise.all([+ loadJSON(CHRONOTYPE_FILE, DEFAULT_CHRONOTYPE),+ loadJSON(LONGEVITY_FILE, DEFAULT_LONGEVITY),+ loadJSON(GOALS_FILE, DEFAULT_GOALS)+ ]);++ const context = { chronotype, longevity, goals: goalsData };++ // Rules return partial objects; engine injects id/category from rule definition+ const insights = INSIGHT_RULES+ .map(rule => {+ const result = rule.evaluate(context);+ return result ? { id: rule.id, category: rule.category, ...result } : null;+ })+ .filter(Boolean);++ console.log(`🔮 Cross-insights generated: ${insights.length} insights from ${INSIGHT_RULES.length} rules`);++ return {+ insights,+ generatedAt: new Date().toISOString(),+ dataSources: {+ chronotype: !!chronotype?.derivedAt,+ longevity: !!longevity?.derivedAt,+ goals: (goalsData?.goals || []).length > 0+ }+ };+}