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
fix: round MeatSpace body weight and percentages for display (#3794)
[._.]/ Adam Eivy9000c2592daa
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 7e10d2e39a..8d4cd818c1 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -36,6 +36,9 @@## Fixed- **The prompt-drift baseline caught up with the arc-resolve migration, un-reddening `main`.** Migration 254 shipped a new `pipeline-arc-resolve.md` and correctly recorded the prior default as an accepted-old hash, but the independent baseline in `scripts/setup-data-drift.test.js` still named the superseded hash as current — so the drift sweep disagreed with the migrations it mirrors and the suite failed on every commit after it landed. The baseline now carries the shipped hash and lists the previous one among the accepted-old set. The guard itself is unchanged and still fails when a migration ships a hash it doesn't export.+=======+- **Body stats on the MeatSpace Overview card no longer show raw float precision.** A unit-converted weight rendered every binary digit it carried (the shape `170.35000000000002 lbs`), blowing out the tile's line and implying precision the measurement never had. Weight, body fat, lean mass, and the body-composition chart's tooltip now share `formatWeight` / `formatPercent` from the client formatters, which round to one decimal, drop trailing zeros, and render a dash for a missing reading instead of a coerced zero.+>>>>>>> 6e49f74b9 (fix: round MeatSpace body weight and percentages for display (#3794))- **Labels floating over 3D and Three.js previews now follow the active theme.** The status bar on a generating Three.js model read as dark green text on a near-black slab — that chrome was written as a fixed black scrim with white text, and on a light theme the white text is remapped to the theme's dark ink while the black scrim stays black. Overlay chrome across the 3D and Three.js surfaces (the generation status bar, the preview's background/explode and part-selection panels, the orbit hint and articulation badge, the mesh viewer's display-settings button, and the "Change image" labels on both pickers) now takes its surface and ink from the theme itself, so it matches the page and stays legible over a dark canvas, a light one, or a photograph.diff --git a/client/src/components/meatspace/BodyCompChart.jsx b/client/src/components/meatspace/BodyCompChart.jsxindex 2d551bc670..0d87f123cb 100644--- a/client/src/components/meatspace/BodyCompChart.jsx+++ b/client/src/components/meatspace/BodyCompChart.jsx@@ -5,6 +5,7 @@ import {import * as api from '../../services/api';import BrailleSpinner from '../BrailleSpinner';import useChartColors from '../../hooks/useChartColors.js';+import { formatWeight, formatPercent } from '../../utils/formatters.js';export default function BodyCompChart() {const chartColors = useChartColors();@@ -54,7 +55,7 @@ export default function BodyCompChart() {<p className="text-gray-400 mb-1">{label}</p>{payload.map(p => (<p key={p.dataKey} style={{ color: p.color }}>- {p.name}: {p.value}{p.dataKey === 'weight' ? ' lbs' : '%'}+ {p.name}: {p.dataKey === 'weight' ? formatWeight(p.value) : formatPercent(p.value)}</p>))}</div>diff --git a/client/src/components/meatspace/tabs/OverviewTab.jsx b/client/src/components/meatspace/tabs/OverviewTab.jsxindex 80fa879aec..0c2b5df72b 100644--- a/client/src/components/meatspace/tabs/OverviewTab.jsx+++ b/client/src/components/meatspace/tabs/OverviewTab.jsx@@ -7,6 +7,7 @@ import DeathClockCountdown from '../../DeathClockCountdown';import ProvenanceChip from '../../ui/ProvenanceChip';import { useAutoRefetch } from '../../../hooks/useAutoRefetch';import { clickableProps } from '../../../lib/a11yKeyboard.js';+import { formatWeight, formatPercent } from '../../../utils/formatters.js';function HealthTile({ icon: Icon, iconColor, label, metrics, onClick }) {return (@@ -202,7 +203,9 @@ export default function OverviewTab() {const hLean = healthBody?.lean_body_mass;const useHealth = hWeight?.date && (!manualBody?.date || hWeight.date > manualBody.date);const latestBody = useHealth- ? { weightLbs: Math.round(hWeight.value * 10) / 10, fatPct: hFat ? Math.round(hFat.value * 1000) / 10 : null, leanLbs: hLean ? Math.round(hLean.value * 10) / 10 : null }+ // Rounding is the display layer's job (formatWeight/formatPercent below);+ // only the fraction → percent conversion happens here.+ ? { weightLbs: hWeight.value, fatPct: hFat ? hFat.value * 100 : null, leanLbs: hLean ? hLean.value : null }: manualBody;const latestBlood = blood?.tests?.[blood.tests.length - 1] ?? null;const latestEpigenetic = epigenetic?.tests?.[epigenetic.tests.length - 1] ?? null;@@ -266,10 +269,10 @@ export default function OverviewTab() {label="Body"onClick={() => navigate('/meatspace/body')}metrics={[- { label: 'Weight', value: latestBody?.weightLbs ? `${latestBody.weightLbs} lbs` : '—' },- { label: 'Body fat', value: latestBody?.fatPct != null ? `${latestBody.fatPct}%` : '—' },+ { label: 'Weight', value: formatWeight(latestBody?.weightLbs) },+ { label: 'Body fat', value: formatPercent(latestBody?.fatPct) },{ label: latestBody?.leanLbs ? 'Lean' : 'Muscle',- value: latestBody?.leanLbs ? `${latestBody.leanLbs} lbs` : latestBody?.musclePct != null ? `${latestBody.musclePct}%` : '—' },+ value: latestBody?.leanLbs ? formatWeight(latestBody.leanLbs) : formatPercent(latestBody?.musclePct) },]}/><HealthTilediff --git a/client/src/utils/README.md b/client/src/utils/README.mdindex 08d342d98d..e7d9e406e3 100644--- a/client/src/utils/README.md+++ b/client/src/utils/README.md@@ -22,7 +22,7 @@ grep -i "what you want to do" client/src/utils/README.md| Module | Purpose ||---|---|-| `formatters` | Date/time/duration/byte/word formatters (`formatBytes`, `formatCompactCount`, `timeAgo`, `formatTimecode`, `formatDurationMs`, `formatDateShort`, `parseTimeoutMs`, `formatCooldown`, `parseSizeGb`, `recommendedRamGb`, `nameFromImageFilename`, `middleTruncate` — clip a long string from the MIDDLE so its distinguishing tail survives, where CSS `line-clamp`/`text-overflow` always eats the end — …) plus timeout-input bounds and `getAppName`. Do not re-define formatters inside components. |+| `formatters` | Date/time/duration/byte/word formatters (`formatBytes`, `formatCompactCount`, `timeAgo`, `formatTimecode`, `formatDurationMs`, `formatDateShort`, `parseTimeoutMs`, `formatCooldown`, `parseSizeGb`, `recommendedRamGb`, `nameFromImageFilename`, `formatWeight` / `formatPercent` — round unit-converted floats (`170.35000000000002` → `170.4 lbs`) so raw binary precision never reaches a tile — `middleTruncate` — clip a long string from the MIDDLE so its distinguishing tail survives, where CSS `line-clamp`/`text-overflow` always eats the end — …) plus timeout-input bounds and `getAppName`. Do not re-define formatters inside components. || `cronHelpers` | Cron preset list, `isCronExpression` detection, and `describeCron` human-readable rendering. || `markdownText` | `markdownToPlainText(md)` — flatten markdown source to one plain-text string for a clamped preview: strips heading/list/blockquote/fence markers, unwraps emphasis, inline code and links, images → `[alt]`, collapses blank-line runs. Use whenever a card previews arbitrary agent-authored markdown — `line-clamp-N` does not clamp a subtree of block elements, and foreign `##` headings would otherwise join the page's heading outline. Underscore emphasis is word-boundary gated and `__…__` needs interior whitespace, so stack frames and user-agent strings (`10_15_7`, `__init__`) are never silently rewritten. `dropsMarkupWhenFlattened(md)` — did the flatten lose actual markup, as opposed to only normalizing whitespace? Gates a "Show more" disclosure so a short-but-lossy body stays reachable without putting a toggle on every body that merely lost a trailing newline. || `timeWindow` | Time-of-day window math (`isInTimeWindow`, `timeStringToMinutes`) and morning-layout auto-switch helpers (`pickActiveLayoutId`, `recordManualLayoutPick`). |diff --git a/client/src/utils/formatters.js b/client/src/utils/formatters.jsindex 2f7eedf1e0..54b223ff71 100644--- a/client/src/utils/formatters.js+++ b/client/src/utils/formatters.js@@ -135,6 +135,55 @@ export function formatCompactCount(n) {return String(n);}+/**+ * Round a number to `decimals` places and drop trailing zeros+ * (170.35000000000002 → 170.4, 170.0 → 170). Returns null for+ * non-finite input so callers can render their own fallback.+ * @param {number|string|null|undefined} value+ * @param {number} decimals+ * @returns {number|null}+ */+function roundForDisplay(value, decimals) {+ // `Number(null)` and `Number('')` are both 0, which would render a missing+ // measurement as a real "0 lbs" — reject the absent cases before coercing.+ if (value === null || value === undefined || value === '') return null;+ const n = Number(value);+ if (!Number.isFinite(n)) return null;+ return parseFloat(n.toFixed(decimals));+}++/**+ * Format a body weight for display. Unit-converted weights arrive as raw+ * binary floats (e.g. 170.35000000000002), which read as false precision and+ * blow out a tile's line — round to one decimal by default and suffix the unit.+ * @param {number|string|null|undefined} value - Weight in `unit`+ * @param {object} [options]+ * @param {string} [options.unit='lbs'] - Unit suffix+ * @param {number} [options.decimals=1] - Decimal places to keep+ * @param {string} [options.fallback='—'] - Rendered when the value is missing/invalid+ * @returns {string} e.g. "170.4 lbs"+ */+export function formatWeight(value, { unit = 'lbs', decimals = 1, fallback = '—' } = {}) {+ const n = roundForDisplay(value, decimals);+ if (n === null) return fallback;+ return unit ? `${n} ${unit}` : `${n}`;+}++/**+ * Format a percentage for display, rounding away float noise the same way+ * `formatWeight` does (18.400000000000002 → "18.4%").+ * @param {number|string|null|undefined} value - Percentage (already 0–100)+ * @param {object} [options]+ * @param {number} [options.decimals=1] - Decimal places to keep+ * @param {string} [options.fallback='—'] - Rendered when the value is missing/invalid+ * @returns {string} e.g. "18.4%"+ */+export function formatPercent(value, { decimals = 1, fallback = '—' } = {}) {+ const n = roundForDisplay(value, decimals);+ if (n === null) return fallback;+ return `${n}%`;+}+/*** Format bytes as a human-readable string* @param {number} bytes - Size in bytesdiff --git a/client/src/utils/formatters.test.js b/client/src/utils/formatters.test.jsindex 153f40dae6..1d24dffc37 100644--- a/client/src/utils/formatters.test.js+++ b/client/src/utils/formatters.test.js@@ -2,8 +2,59 @@ import { describe, it, expect } from 'vitest';import {formatContextLength, formatDurationMin, formatDurationMs, formatEventDateTime, timeAgo,formatCooldown, parseSizeGb, recommendedRamGb, parseTimeoutMs, formatDurationSec, middleTruncate,+ formatWeight, formatPercent,} from './formatters.js';+describe('formatWeight', () => {+ it('rounds unit-conversion float noise to one decimal', () => {+ expect(formatWeight(170.35000000000002)).toBe('170.4 lbs');+ expect(formatWeight(88.88888)).toBe('88.9 lbs');+ });++ it('drops trailing zeros instead of padding', () => {+ expect(formatWeight(180)).toBe('180 lbs');+ expect(formatWeight(180.0000001)).toBe('180 lbs');+ });++ it('honors unit, decimals, and fallback overrides', () => {+ expect(formatWeight(77.2345, { unit: 'kg' })).toBe('77.2 kg');+ expect(formatWeight(77.2345, { unit: 'kg', decimals: 2 })).toBe('77.23 kg');+ expect(formatWeight(12.345, { unit: '' })).toBe('12.3');+ });++ it('falls back for missing or non-numeric values', () => {+ expect(formatWeight(null)).toBe('—');+ expect(formatWeight(undefined)).toBe('—');+ expect(formatWeight('')).toBe('—');+ expect(formatWeight('heavy')).toBe('—');+ expect(formatWeight(NaN)).toBe('—');+ expect(formatWeight(Infinity)).toBe('—');+ expect(formatWeight(null, { fallback: 'n/a' })).toBe('n/a');+ });++ it('keeps a legitimate zero rather than treating it as missing', () => {+ expect(formatWeight(0)).toBe('0 lbs');+ });++ it('accepts numeric strings', () => {+ expect(formatWeight('170.35000000000002')).toBe('170.4 lbs');+ });+});++describe('formatPercent', () => {+ it('rounds float noise and suffixes a percent sign', () => {+ expect(formatPercent(18.400000000000002)).toBe('18.4%');+ expect(formatPercent(42)).toBe('42%');+ expect(formatPercent(0)).toBe('0%');+ });++ it('honors decimals and fallback overrides', () => {+ expect(formatPercent(18.4567, { decimals: 2 })).toBe('18.46%');+ expect(formatPercent(undefined)).toBe('—');+ expect(formatPercent(null, { fallback: '?' })).toBe('?');+ });+});+describe('formatDurationSec', () => {it('formats seconds as M:SS with a zero-padded seconds field', () => {expect(formatDurationSec(75)).toBe('1:15');