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([issue-710]): provenance chips on health/longevity insight views
[._.]/ Adam Eivy702e60b52e68
diff --git a/client/src/components/meatspace/tabs/AgeTab.jsx b/client/src/components/meatspace/tabs/AgeTab.jsxindex 51b169965c..852c2df645 100644--- a/client/src/components/meatspace/tabs/AgeTab.jsx+++ b/client/src/components/meatspace/tabs/AgeTab.jsx@@ -2,6 +2,7 @@ import { useState, useEffect, useCallback } from 'react';import { Dna, Calendar, Pencil, Check, X } from 'lucide-react';import * as api from '../../../services/api';import BrailleSpinner from '../../BrailleSpinner';+import ProvenanceChip from '../../ui/ProvenanceChip';function BirthDateSection({ birthDate, onUpdate }) {const [editing, setEditing] = useState(false);@@ -68,7 +69,14 @@ function BirthDateSection({ birthDate, onUpdate }) {<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>+ <p className="text-sm text-gray-500 mt-1 flex items-center gap-2">+ Chronological age: {age} years+ <ProvenanceChip+ level="data-backed"+ explainer="Counted directly from the birth date on record — a fact, not an estimate."+ whatWouldChange="Correcting the birth date above."+ />+ </p>)}</div><button@@ -135,6 +143,11 @@ export default function AgeTab() {<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>+ <ProvenanceChip+ level="experimental"+ explainer="From a DNA-methylation aging clock — a measured lab result, but one based on methods still maturing toward clinical standard."+ whatWouldChange="Re-testing over time, and the methylation-clock science continuing to validate."+ /></div><div className="grid grid-cols-2 md:grid-cols-4 gap-4"><div>diff --git a/client/src/components/meatspace/tabs/GenomeTab.jsx b/client/src/components/meatspace/tabs/GenomeTab.jsxindex d4cf1426cc..7b865eaff3 100644--- a/client/src/components/meatspace/tabs/GenomeTab.jsx+++ b/client/src/components/meatspace/tabs/GenomeTab.jsx@@ -57,6 +57,7 @@ async function parseZipText(arrayBuffer, ext = '.txt') {import * as api from '../../../services/api';import GenomeCategoryCard from '../GenomeCategoryCard';import EpigeneticTracker from '../EpigeneticTracker';+import ProvenanceChip from '../../ui/ProvenanceChip';const CATEGORY_META = {longevity: { emoji: '\u2728', label: 'Longevity', color: 'purple' },@@ -444,6 +445,16 @@ export default function GenomeTab() {return (<div className="space-y-6">+ {/* Provenance — genome markers are population associations, not diagnoses */}+ <div className="flex items-center gap-2 text-xs text-gray-500">+ <span>Marker insights</span>+ <ProvenanceChip+ level="inferred"+ explainer="Each marker links your variants to traits via published population studies — associations and tendencies, not a clinical diagnosis."+ whatWouldChange="Stronger research on a variant, or pairing it with your blood and lifestyle data, sharpens what it means for you."+ />+ </div>+{/* Summary Dashboard */}<div className="grid grid-cols-2 sm:grid-cols-4 gap-3"><StatCard label="SNPs Loaded" value={summary.snpCount?.toLocaleString()} />diff --git a/client/src/components/meatspace/tabs/OverviewTab.jsx b/client/src/components/meatspace/tabs/OverviewTab.jsxindex 9e21553f33..0d7d639e0a 100644--- a/client/src/components/meatspace/tabs/OverviewTab.jsx+++ b/client/src/components/meatspace/tabs/OverviewTab.jsx@@ -4,6 +4,7 @@ import { Beer, Scale, HeartPulse, Dna, Eye, Dumbbell, Database, Rocket, Calendarimport * as api from '../../../services/api';import BrailleSpinner from '../../BrailleSpinner';import DeathClockCountdown from '../../DeathClockCountdown';+import ProvenanceChip from '../../ui/ProvenanceChip';import { useAutoRefetch } from '../../../hooks/useAutoRefetch';function HealthTile({ icon: Icon, iconColor, label, metrics, onClick }) {@@ -39,6 +40,11 @@ function CompactCountdown({ deathDate, lifeExpectancy, percentComplete, lev }) {<div><div className="flex items-baseline gap-2 mb-2"><h3 className="text-xs font-medium text-gray-400 uppercase tracking-wider">Time Remaining</h3>+ <ProvenanceChip+ level="inferred"+ explainer="Estimated from an actuarial baseline, then adjusted by your genome and lifestyle data — a model, not a fixed date."+ whatWouldChange="New genome, lifestyle, or body-metric data shifts the projection; the actuarial baseline updates with your age."+ /><span className="text-xs text-gray-500">({new Date(deathDate).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' })}){lev?.onTrack && <span className="text-port-success font-medium"> +LEV</span>}@@ -88,6 +94,11 @@ function CompactLEV({ lev }) {<div className="flex items-center gap-2 mb-3"><Rocket size={14} className="text-port-accent" /><h3 className="text-xs font-medium text-gray-400 uppercase tracking-wider">LEV Tracker</h3>+ <ProvenanceChip+ level="speculative"+ explainer="Longevity Escape Velocity assumes medical progress outpaces aging by ~2045 — a forward-looking bet on the future, not a measurement."+ whatWouldChange="The pace of longevity research and your adjusted life expectancy moving the on-track/at-risk margin."+ /></div><div className="mb-3">diff --git a/client/src/components/ui/ProvenanceChip.jsx b/client/src/components/ui/ProvenanceChip.jsxnew file mode 100644index 0000000000..6b28769ba4--- /dev/null+++ b/client/src/components/ui/ProvenanceChip.jsx@@ -0,0 +1,102 @@+import { useEffect, useId, useRef, useState } from 'react';+import { BadgeCheck, FlaskConical, HelpCircle, Sigma, Telescope } from 'lucide-react';+import { getProvenanceLevel } from '../../lib/healthProvenance.js';++// Source-style provenance chip for health/longevity insights. Tap (or click) to+// reveal how the insight was derived plus a "what would change this?" explainer.+// Mirrors Ask's SourceChip affordance but for confidence/derivation rather than+// citations. Levels + default copy live in lib/healthProvenance.js; pass+// `explainer` / `whatWouldChange` to override the defaults for a specific insight.++// Full literal class strings so Tailwind's JIT keeps them — never interpolate tones.+const TONE_CHIP = {+ success: 'text-port-success bg-port-success/10 border-port-success/30 hover:border-port-success/60',+ accent: 'text-port-accent bg-port-accent/10 border-port-accent/30 hover:border-port-accent/60',+ warning: 'text-port-warning bg-port-warning/10 border-port-warning/30 hover:border-port-warning/60',+ muted: 'text-gray-400 bg-port-bg border-port-border hover:border-gray-500',+};++const TONE_ICON = {+ success: 'text-port-success',+ accent: 'text-port-accent',+ warning: 'text-port-warning',+ muted: 'text-gray-400',+};++const LEVEL_ICONS = {+ 'data-backed': BadgeCheck,+ inferred: Sigma,+ experimental: FlaskConical,+ speculative: Telescope,+};++export default function ProvenanceChip({+ level,+ label,+ explainer,+ whatWouldChange,+ className = '',+}) {+ const meta = getProvenanceLevel(level);+ const [open, setOpen] = useState(false);+ const wrapRef = useRef(null);+ const popId = useId();++ useEffect(() => {+ if (!open) return undefined;+ const onPointerDown = (e) => {+ if (wrapRef.current && !wrapRef.current.contains(e.target)) setOpen(false);+ };+ const onKey = (e) => {+ if (e.key === 'Escape') setOpen(false);+ };+ document.addEventListener('mousedown', onPointerDown);+ document.addEventListener('keydown', onKey);+ return () => {+ document.removeEventListener('mousedown', onPointerDown);+ document.removeEventListener('keydown', onKey);+ };+ }, [open]);++ const Icon = LEVEL_ICONS[meta.id] ?? Sigma;+ const chipTone = TONE_CHIP[meta.tone] ?? TONE_CHIP.muted;+ const iconTone = TONE_ICON[meta.tone] ?? TONE_ICON.muted;+ const description = explainer ?? meta.description;+ const change = whatWouldChange ?? meta.whatWouldChange;++ return (+ <span ref={wrapRef} className={`relative inline-flex align-middle ${className}`}>+ <button+ type="button"+ onClick={() => setOpen((v) => !v)}+ aria-expanded={open}+ aria-haspopup="dialog"+ aria-controls={open ? popId : undefined}+ title={`${meta.label} — tap for how this is derived`}+ className={`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide transition-colors ${chipTone}`}+ >+ <Icon size={10} aria-hidden="true" className="shrink-0" />+ <span>{label ?? meta.label}</span>+ <HelpCircle size={10} aria-hidden="true" className="shrink-0 opacity-60" />+ </button>+ {open && (+ <div+ id={popId}+ role="dialog"+ aria-label={`${meta.label} provenance`}+ className="absolute left-0 top-full z-30 mt-1.5 w-64 rounded-lg border border-port-border bg-port-card p-3 text-left shadow-xl"+ >+ <p className="mb-1 flex items-center gap-1.5 text-xs font-semibold text-gray-200 normal-case tracking-normal">+ <Icon size={12} aria-hidden="true" className={`shrink-0 ${iconTone}`} />+ {meta.label}+ </p>+ <p className="text-xs leading-relaxed text-gray-400">{description}</p>+ <p className="mt-2 text-[10px] font-semibold uppercase tracking-wide text-gray-500">+ What would change this?+ </p>+ <p className="text-xs leading-relaxed text-gray-400">{change}</p>+ </div>+ )}+ </span>+ );+}diff --git a/client/src/components/ui/ProvenanceChip.test.jsx b/client/src/components/ui/ProvenanceChip.test.jsxnew file mode 100644index 0000000000..6bc08dda2c--- /dev/null+++ b/client/src/components/ui/ProvenanceChip.test.jsx@@ -0,0 +1,63 @@+import { describe, it, expect } from 'vitest';+import { render, screen, fireEvent } from '@testing-library/react';++import ProvenanceChip from './ProvenanceChip';+import { PROVENANCE_LEVELS } from '../../lib/healthProvenance.js';++describe('ProvenanceChip', () => {+ it('renders the level label and the success tone for data-backed', () => {+ render(<ProvenanceChip level="data-backed" />);+ const btn = screen.getByRole('button', { name: /data-backed/i });+ expect(btn.className).toContain('text-port-success');+ expect(btn).toHaveAttribute('aria-expanded', 'false');+ });++ it('falls back to the inferred level for an unknown id', () => {+ render(<ProvenanceChip level="bogus" />);+ expect(screen.getByRole('button', { name: /inferred/i })).toBeTruthy();+ });++ it('reveals the default explainer and "what would change this?" on click', () => {+ render(<ProvenanceChip level="speculative" />);+ const btn = screen.getByRole('button');+ expect(screen.queryByRole('dialog')).toBeNull();++ fireEvent.click(btn);++ expect(btn).toHaveAttribute('aria-expanded', 'true');+ const dialog = screen.getByRole('dialog');+ expect(dialog.textContent).toContain(PROVENANCE_LEVELS.speculative.description);+ expect(dialog.textContent).toContain('What would change this?');+ expect(dialog.textContent).toContain(PROVENANCE_LEVELS.speculative.whatWouldChange);+ });++ it('prefers custom explainer / whatWouldChange copy over the level defaults', () => {+ render(+ <ProvenanceChip+ level="inferred"+ explainer="Custom how-derived copy."+ whatWouldChange="Custom change copy."+ />,+ );+ fireEvent.click(screen.getByRole('button'));+ const dialog = screen.getByRole('dialog');+ expect(dialog.textContent).toContain('Custom how-derived copy.');+ expect(dialog.textContent).toContain('Custom change copy.');+ expect(dialog.textContent).not.toContain(PROVENANCE_LEVELS.inferred.description);+ });++ it('overrides the chip label when label prop is set, keeping the resolved tone', () => {+ render(<ProvenanceChip level="experimental" label="Beta clock" />);+ const btn = screen.getByRole('button', { name: /beta clock/i });+ expect(btn.className).toContain('text-port-warning');+ });++ it('closes the popover on Escape', () => {+ render(<ProvenanceChip level="inferred" />);+ const btn = screen.getByRole('button');+ fireEvent.click(btn);+ expect(screen.getByRole('dialog')).toBeTruthy();+ fireEvent.keyDown(document, { key: 'Escape' });+ expect(screen.queryByRole('dialog')).toBeNull();+ });+});diff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex 8f6c9f42af..40d4ffd48c 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -65,6 +65,7 @@ grep -i "what you want to do" client/src/lib/README.md| `clipboard.js` | `copyToClipboard`, `writeClipboardSilently`, `readClipboard` — safe across insecure-origin contexts. Use these instead of `navigator.clipboard.writeText` inline. || `compareHelpers.js` | `equalByKeys(a, b, keys)` / `equalListByKeys(a, b, keys)` — typed key-based equality for `useAutoRefetch`'s `compare`. Keys are property names, dotted paths (`'context.running'`), or `(item) => value` accessors. The typed alternative to `sameJsonShape` when a monotonic timestamp or unrendered field would break stringify-equality dedup. || `genUtils.js` | Shared bits between Image Gen and Video Gen pages. |+| `healthProvenance.js` | `PROVENANCE_LEVELS` / `getProvenanceLevel(level)` — the `data-backed`/`inferred`/`experimental`/`speculative` trust taxonomy (label, tone, description, "what would change this?" copy) behind the `ProvenanceChip` source-style chips on MeatSpace / genome / death-clock / longevity views. Pure data; the chip component maps tone→color and id→icon. || `joinInfluenceList.js` | Mirror of `joinInfluenceList` in server universe builder. || `localLlmTargetKey.js` | `localLlmTargetKey({ backend, modelId })` — stable string key for a local-LLM compare target. Shared by the LocalLlmTab checkbox grid and the LocalLlmPlayground compare URL so a delimiter change can't desync the round-trip. || `loopbackHost.js` | `isLoopbackHost(host)` / `isLoopbackOrigin()` / `describeMicAvailability()` — Secure Context / loopback-origin heuristics. Use these in any new mic, clipboard, or `getUserMedia`-gated surface; matches the full `127.0.0.0/8` range, IPv6 `::1`, and the browser-bracketed `[::1]` form. |diff --git a/client/src/lib/healthProvenance.js b/client/src/lib/healthProvenance.jsnew file mode 100644index 0000000000..b3bae8b59f--- /dev/null+++ b/client/src/lib/healthProvenance.js@@ -0,0 +1,66 @@+// Provenance taxonomy for health / longevity insights — the trust model behind+// the source-style chips on MeatSpace, genome, death-clock, and longevity views.+// It mirrors the spirit of Ask's source chips: every number on screen declares+// how it was derived, so a modeled projection never reads as a measured fact.+//+// Pure data only (no React / lucide) so it stays unit-testable and reusable. The+// `ProvenanceChip` component maps each level's `tone` to a color and `id` to an+// icon — keep presentation concerns there, not here.+//+// Levels (most → least grounded in the user's own measured data):+// data-backed — read straight off measured/imported records+// inferred — modeled from those records via population research+// experimental — emerging methods, promising but not yet clinical standard+// speculative — forward-looking projection, not a measurement++export const PROVENANCE_LEVELS = {+ 'data-backed': {+ id: 'data-backed',+ label: 'Data-backed',+ tone: 'success',+ description:+ 'Read directly from data you measured or imported — a value on record, not a model output.',+ whatWouldChange:+ 'New lab results, device readings, or corrected entries update this directly.',+ },+ inferred: {+ id: 'inferred',+ label: 'Inferred',+ tone: 'accent',+ description:+ 'Modeled from your data using population research and statistical associations.',+ whatWouldChange:+ 'Refining the inputs it draws on — genome, lifestyle, body metrics — shifts the estimate.',+ },+ experimental: {+ id: 'experimental',+ label: 'Experimental',+ tone: 'warning',+ description:+ 'Derived from emerging methods that are promising but not yet clinically standard.',+ whatWouldChange:+ 'As the underlying science matures and you re-test, confidence in this improves.',+ },+ speculative: {+ id: 'speculative',+ label: 'Speculative',+ tone: 'muted',+ description:+ 'A forward-looking projection built on assumptions about the future, not a measurement.',+ whatWouldChange:+ 'Future breakthroughs and changes in your trajectory can move this substantially.',+ },+};++export const PROVENANCE_LEVEL_IDS = Object.keys(PROVENANCE_LEVELS);++const FALLBACK_LEVEL = PROVENANCE_LEVELS.inferred;++// Resolve a level id (case- and separator-tolerant: "Data Backed", "data_backed",+// "DATA-BACKED" all match) to its metadata. An unknown/missing id degrades to+// `inferred` so a typo renders a sensible chip instead of crashing the view.+export function getProvenanceLevel(level) {+ if (!level || typeof level !== 'string') return FALLBACK_LEVEL;+ const key = level.trim().toLowerCase().replace(/[_\s]+/g, '-');+ return PROVENANCE_LEVELS[key] ?? FALLBACK_LEVEL;+}diff --git a/client/src/lib/healthProvenance.test.js b/client/src/lib/healthProvenance.test.jsnew file mode 100644index 0000000000..8adedbf235--- /dev/null+++ b/client/src/lib/healthProvenance.test.js@@ -0,0 +1,46 @@+import { describe, it, expect } from 'vitest';+import {+ PROVENANCE_LEVELS,+ PROVENANCE_LEVEL_IDS,+ getProvenanceLevel,+} from './healthProvenance.js';++describe('healthProvenance', () => {+ it('defines the four provenance levels named in issue #710', () => {+ expect(PROVENANCE_LEVEL_IDS).toEqual([+ 'data-backed',+ 'inferred',+ 'experimental',+ 'speculative',+ ]);+ });++ it('every level carries label, tone, description, and a what-would-change explainer', () => {+ for (const id of PROVENANCE_LEVEL_IDS) {+ const meta = PROVENANCE_LEVELS[id];+ expect(meta.id).toBe(id);+ expect(meta.label).toBeTruthy();+ expect(['success', 'accent', 'warning', 'muted']).toContain(meta.tone);+ expect(meta.description.length).toBeGreaterThan(10);+ expect(meta.whatWouldChange.length).toBeGreaterThan(10);+ }+ });++ it('resolves a known level id', () => {+ expect(getProvenanceLevel('speculative')).toBe(PROVENANCE_LEVELS.speculative);+ });++ it('is tolerant of casing and separators', () => {+ expect(getProvenanceLevel('Data Backed')).toBe(PROVENANCE_LEVELS['data-backed']);+ expect(getProvenanceLevel('DATA_BACKED')).toBe(PROVENANCE_LEVELS['data-backed']);+ expect(getProvenanceLevel(' experimental ')).toBe(PROVENANCE_LEVELS.experimental);+ });++ it('falls back to inferred for unknown or empty input', () => {+ expect(getProvenanceLevel('nonsense')).toBe(PROVENANCE_LEVELS.inferred);+ expect(getProvenanceLevel('')).toBe(PROVENANCE_LEVELS.inferred);+ expect(getProvenanceLevel(null)).toBe(PROVENANCE_LEVELS.inferred);+ expect(getProvenanceLevel(undefined)).toBe(PROVENANCE_LEVELS.inferred);+ expect(getProvenanceLevel(42)).toBe(PROVENANCE_LEVELS.inferred);+ });+});diff --git a/client/src/lib/index.js b/client/src/lib/index.jsindex d831bb5aff..4fe4377325 100644--- a/client/src/lib/index.js+++ b/client/src/lib/index.js@@ -36,6 +36,7 @@ export * from './clientErrorReporter.js';export * from './clipboard.js';export * from './compareHelpers.js';export * from './genUtils.js';+export * from './healthProvenance.js';export * from './joinInfluenceList.js';export * from './localLlmTargetKey.js';export * from './loopbackHost.js';