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(meatspace): editable biological sex on lifestyle tab, round-tripped to MortalLoom iCloud
Adam Eivy6e60b55ec847
diff --git a/client/src/components/meatspace/tabs/LifestyleTab.jsx b/client/src/components/meatspace/tabs/LifestyleTab.jsxindex 7b76ad7767..13c5c29c79 100644--- a/client/src/components/meatspace/tabs/LifestyleTab.jsx+++ b/client/src/components/meatspace/tabs/LifestyleTab.jsx@@ -10,6 +10,12 @@ const SMOKING_OPTIONS = [{ value: 'current', label: 'Current' }];+const SEX_OPTIONS = [+ { value: 'male', label: 'Male' },+ { value: 'female', label: 'Female' },+ { value: null, label: 'Unknown' }+];+const DIET_OPTIONS = [{ value: 'excellent', label: 'Excellent' },{ value: 'good', label: 'Good' },@@ -26,12 +32,14 @@ const STRESS_OPTIONS = [export default function LifestyleTab() {const [config, setConfig] = useState(null);const [lifestyle, setLifestyle] = useState(null);+ const [sex, setSex] = useState(null);const [saving, setSaving] = useState(false);const [loading, setLoading] = useState(true);const fetchData = useCallback(async () => {const data = await api.getMeatspaceConfig().catch(() => null);setConfig(data);+ setSex(data?.sex ?? null);setLifestyle(data?.lifestyle || {smokingStatus: 'never',exerciseMinutesPerWeek: 150,@@ -50,7 +58,14 @@ export default function LifestyleTab() {const handleSave = async () => {setSaving(true);- const result = await api.updateMeatspaceLifestyle(lifestyle).catch(() => null);+ // `sexSource = 'questionnaire'` whenever the user sets sex manually, so the+ // auto-detect-from-genome code path in getConfig() doesn't clobber it next load.+ const payload = {+ sex,+ sexSource: sex ? 'questionnaire' : null,+ lifestyle+ };+ const result = await api.updateMeatspaceConfig(payload).catch(() => null);setSaving(false);if (result) {setConfig(result);@@ -78,16 +93,33 @@ export default function LifestyleTab() {<ClipboardList size={18} className="text-port-accent" /><h3 className="text-sm font-medium text-gray-400 uppercase tracking-wider">Profile</h3></div>- <div className="grid grid-cols-2 gap-4">- <div>- <label className="block text-xs text-gray-500 uppercase mb-1">Biological Sex</label>- <p className="text-lg font-mono text-gray-300 capitalize">- {config?.sex || 'Unknown'}- {config?.sexSource && (- <span className="text-xs text-gray-600 ml-2">({config.sexSource})</span>- )}- </p>+ <div>+ <div className="flex items-center justify-between mb-2">+ <label className="block text-xs text-gray-500 uppercase">Biological Sex</label>+ {config?.sexSource && (+ <span className="text-[10px] text-gray-600 italic">+ {config.sexSource === 'genome' ? 'auto-detected from genome' : `source: ${config.sexSource}`}+ </span>+ )}+ </div>+ <div className="flex gap-2">+ {SEX_OPTIONS.map(opt => (+ <button+ key={opt.label}+ onClick={() => setSex(opt.value)}+ className={`px-3 py-1.5 text-sm rounded-lg border ${+ sex === opt.value+ ? 'border-port-accent bg-port-accent/20 text-port-accent'+ : 'border-port-border text-gray-400 hover:border-gray-500'+ }`}+ >+ {opt.label}+ </button>+ ))}</div>+ <p className="text-xs text-gray-600 mt-2">+ Used for SSA-baseline life expectancy, alcohol-risk thresholds, and sex-specific genome markers.+ </p></div></div>diff --git a/server/lib/meatspaceValidation.js b/server/lib/meatspaceValidation.jsindex 30bd764900..4867527e7b 100644--- a/server/lib/meatspaceValidation.js+++ b/server/lib/meatspaceValidation.js@@ -50,8 +50,8 @@ export const lifestyleSchema = z.object({});export const configSchema = z.object({- sex: z.enum(['male', 'female']).optional(),- sexSource: z.enum(['genome', 'questionnaire']).optional(),+ sex: z.enum(['male', 'female']).nullable().optional(),+ sexSource: z.enum(['genome', 'questionnaire']).nullable().optional(),lifestyle: lifestyleSchema.optional()});diff --git a/server/services/meatspace.js b/server/services/meatspace.jsindex 37d63be755..8eeddf4274 100644--- a/server/services/meatspace.js+++ b/server/services/meatspace.js@@ -9,6 +9,23 @@ import { readFile, writeFile } from 'fs/promises';import { join } from 'path';import { PATHS, ensureDir, readJSONFile } from '../lib/fileUtils.js';import { getSnpIndex } from './genome.js';+import { mlGetProfileIfEnabled, mlPatchProfileIfEnabled } from './mortalLoomStore.js';++// MortalLoom `LifestyleData` uses a subset of PortOS lifestyle fields.+// Only mirror these when writing back to avoid introducing PortOS-only keys.+const MORTALLOOM_LIFESTYLE_KEYS = [+ 'smokingStatus', 'exerciseMinutesPerWeek', 'sleepHoursPerNight',+ 'dietQuality', 'stressLevel', 'bmi'+];++function pickMortalLoomLifestyle(lifestyle) {+ if (!lifestyle || typeof lifestyle !== 'object') return null;+ const out = {};+ for (const k of MORTALLOOM_LIFESTYLE_KEYS) {+ if (lifestyle[k] !== undefined) out[k] = lifestyle[k];+ }+ return Object.keys(out).length ? out : null;+}const MEATSPACE_DIR = PATHS.meatspace;const CONFIG_FILE = join(MEATSPACE_DIR, 'config.json');@@ -196,6 +213,20 @@ export async function getConfig() {}}+ // MortalLoom iCloud: treat `store.profile` as authoritative when sync is enabled+ // so edits made in the iOS/macOS app show up here without a manual import.+ const mlProfile = await mlGetProfileIfEnabled();+ if (mlProfile) {+ if (mlProfile.biologicalSex) {+ config.sex = mlProfile.biologicalSex;+ config.sexSource = config.sexSource || 'questionnaire';+ }+ if (mlProfile.birthDate) config.birthDate = mlProfile.birthDate;+ if (mlProfile.lifestyle && typeof mlProfile.lifestyle === 'object') {+ config.lifestyle = { ...config.lifestyle, ...mlProfile.lifestyle };+ }+ }+return config;}@@ -208,6 +239,13 @@ export async function updateConfig(updates) {}config.updatedAt = new Date().toISOString();await saveConfig(config);++ const mlPatch = {};+ if (updates.sex !== undefined) mlPatch.biologicalSex = updates.sex || null;+ const mlLifestyle = pickMortalLoomLifestyle(updates.lifestyle);+ if (mlLifestyle) mlPatch.lifestyle = mlLifestyle;+ if (Object.keys(mlPatch).length) await mlPatchProfileIfEnabled(mlPatch);+return config;}@@ -216,6 +254,10 @@ export async function updateLifestyle(updates) {config.lifestyle = { ...config.lifestyle, ...updates };config.updatedAt = new Date().toISOString();await saveConfig(config);++ const mlLifestyle = pickMortalLoomLifestyle(updates);+ if (mlLifestyle) await mlPatchProfileIfEnabled({ lifestyle: mlLifestyle });+return config;}@@ -254,6 +296,8 @@ export async function updateBirthDate(birthDate, { syncGoals = true } = {}) {}}+ await mlPatchProfileIfEnabled({ birthDate });+return { birthDate };}diff --git a/server/services/mortalLoomStore.js b/server/services/mortalLoomStore.jsindex fdac24ea17..9f08400385 100644--- a/server/services/mortalLoomStore.js+++ b/server/services/mortalLoomStore.js@@ -97,6 +97,37 @@ export async function mlReplace(key, array) {await updateStore(store => { store[key] = array; });}+// === Profile (HealthProfile mirror: biologicalSex, birthDate, lifestyle, …) ===++/** Returns `store.profile` when MortalLoom sync is enabled, else null. */+export async function mlGetProfileIfEnabled() {+ if (!(await isMortalLoomEnabled())) return null;+ const store = await readStore();+ return (store && typeof store.profile === 'object') ? store.profile : null;+}++/**+ * Deep-merge `patch` onto `store.profile` when sync is enabled; no-op otherwise.+ * Nested objects (`lifestyle`, `locationProfile`, `socioeconomic`) are merged field-wise+ * so callers can patch a single field without clobbering the rest.+ */+export async function mlPatchProfileIfEnabled(patch) {+ if (!(await isMortalLoomEnabled())) return null;+ return updateStore(store => {+ const current = (store.profile && typeof store.profile === 'object') ? store.profile : {};+ const next = { ...current };+ for (const [k, v] of Object.entries(patch)) {+ if (v && typeof v === 'object' && !Array.isArray(v) && current[k] && typeof current[k] === 'object') {+ next[k] = { ...current[k], ...v };+ } else {+ next[k] = v;+ }+ }+ store.profile = next;+ return next;+ });+}+/*** Upsert a HealthMetricEntry by date — merges non-null fields into the* existing entry for that date, or appends a new one. Mirrors Swift's