Skip to content

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

refactor: remove DRY violations and dead code

Adam Eivy9e0a7db4adb9
diff --git a/client/src/components/DecisionLogWidget.jsx b/client/src/components/DecisionLogWidget.jsx
index fff28649de..57beb0071b 100644
--- a/client/src/components/DecisionLogWidget.jsx
+++ b/client/src/components/DecisionLogWidget.jsx
@@ -16,6 +16,7 @@ import {
} from 'lucide-react';
import * as api from '../services/api';
import { useAutoRefetch } from '../hooks/useAutoRefetch';
+import { timeAgo } from '../utils/formatters';
/**
* DecisionLogWidget - Shows transparency into CoS decision-making
@@ -83,20 +84,6 @@ const DecisionLogWidget = memo(function DecisionLogWidget() {
return labels[type] || type;
};
- // Format relative time
- const formatRelativeTime = (timestamp) => {
- const now = Date.now();
- const then = new Date(timestamp).getTime();
- const diffMs = now - then;
- const diffMins = Math.floor(diffMs / 60000);
- const diffHours = Math.floor(diffMs / 3600000);
-
- if (diffMins < 1) return 'just now';
- if (diffMins < 60) return `${diffMins}m ago`;
- if (diffHours < 24) return `${diffHours}h ago`;
- return 'yesterday';
- };
-
// Render context-specific detail pills for a decision
const renderContextDetails = (decision) => {
const ctx = decision.context;
@@ -310,7 +297,7 @@ const DecisionLogWidget = memo(function DecisionLogWidget() {
</p>
{renderContextDetails(decision)}
<div className="text-xs text-gray-500 mt-0.5">
- {formatRelativeTime(decision.lastTimestamp || decision.timestamp)}
+ {timeAgo(decision.lastTimestamp || decision.timestamp)}
{(decision.count || 1) > 1 && (
<span className="ml-2 text-gray-400">
({decision.count}x)
diff --git a/client/src/components/agents/tabs/PublishedTab.jsx b/client/src/components/agents/tabs/PublishedTab.jsx
index d5865fe2a5..eef9e4b176 100644
--- a/client/src/components/agents/tabs/PublishedTab.jsx
+++ b/client/src/components/agents/tabs/PublishedTab.jsx
@@ -1,17 +1,7 @@
import { useState, useEffect, useCallback } from 'react';
import * as api from '../../../services/api';
import BrailleSpinner from '../../BrailleSpinner';
-
-const formatRelativeTime = (dateStr) => {
- const diff = Date.now() - new Date(dateStr).getTime();
- const mins = Math.floor(diff / 60000);
- if (mins < 1) return 'just now';
- if (mins < 60) return `${mins}m ago`;
- const hrs = Math.floor(mins / 60);
- if (hrs < 24) return `${hrs}h ago`;
- const days = Math.floor(hrs / 24);
- return `${days}d ago`;
-};
+import { timeAgo } from '../../../utils/formatters';
export default function PublishedTab({ agentId }) {
const [accounts, setAccounts] = useState([]);
@@ -160,7 +150,7 @@ export default function PublishedTab({ agentId }) {
{post.commentCount ?? '-'}
</td>
<td className="py-2 pr-4 text-gray-500 whitespace-nowrap" title={new Date(post.publishedAt).toLocaleString()}>
- {formatRelativeTime(post.publishedAt)}
+ {timeAgo(post.publishedAt)}
</td>
<td className="py-2">
{post.url ? (
@@ -217,7 +207,7 @@ export default function PublishedTab({ agentId }) {
</span>
</td>
<td className="py-2 pr-4 text-gray-500 whitespace-nowrap" title={new Date(comment.publishedAt).toLocaleString()}>
- {formatRelativeTime(comment.publishedAt)}
+ {timeAgo(comment.publishedAt)}
</td>
<td className="py-2">
{comment.url ? (
diff --git a/client/src/components/agents/tabs/WorldTab.jsx b/client/src/components/agents/tabs/WorldTab.jsx
index a13c171ce2..645175e833 100644
--- a/client/src/components/agents/tabs/WorldTab.jsx
+++ b/client/src/components/agents/tabs/WorldTab.jsx
@@ -4,6 +4,7 @@ import * as api from '../../../services/api';
import BrailleSpinner from '../../BrailleSpinner';
import socket from '../../../services/socket';
import useMoltworldWs from '../../../hooks/useMoltworldWs';
+import { timeAgo } from '../../../utils/formatters';
const EVENT_ICONS = {
status: '🔌',
@@ -59,14 +60,6 @@ function formatEventTime(ts) {
return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' });
}
-function formatRelativeTime(ts) {
- const diff = Date.now() - new Date(ts).getTime();
- if (diff < 60000) return 'just now';
- if (diff < 3600000) return `${Math.floor(diff / 60000)}m ago`;
- if (diff < 86400000) return `${Math.floor(diff / 3600000)}h ago`;
- return `${Math.floor(diff / 86400000)}d ago`;
-}
-
function summarizeParams(action, params) {
if (!params) return '';
if (action === 'mw_explore' || action === 'mw_heartbeat') {
@@ -729,7 +722,7 @@ export default function WorldTab({ agentId }) {
</p>
</div>
<span className="text-gray-600 shrink-0 text-[10px]" title={entry.timestamp}>
- {formatRelativeTime(entry.timestamp)}
+ {timeAgo(entry.timestamp)}
</span>
</div>
))}
diff --git a/client/src/components/brain/constants.js b/client/src/components/brain/constants.js
index 65ea215385..4de7e335da 100644
--- a/client/src/components/brain/constants.js
+++ b/client/src/components/brain/constants.js
@@ -108,21 +108,3 @@ export const BRAIN_TYPE_HEX = {
memories: '#ec4899'
};
-// Format relative time
-export function formatRelativeTime(dateString) {
- if (!dateString) return 'Never';
-
- const date = new Date(dateString);
- const now = new Date();
- const diffMs = now - date;
- const diffMins = Math.floor(diffMs / 60000);
- const diffHours = Math.floor(diffMs / 3600000);
- const diffDays = Math.floor(diffMs / 86400000);
-
- if (diffMins < 1) return 'Just now';
- if (diffMins < 60) return `${diffMins}m ago`;
- if (diffHours < 24) return `${diffHours}h ago`;
- if (diffDays < 7) return `${diffDays}d ago`;
-
- return date.toLocaleDateString();
-}
diff --git a/client/src/components/brain/tabs/DigestTab.jsx b/client/src/components/brain/tabs/DigestTab.jsx
index 8ae09e00fa..c88fc4c9b9 100644
--- a/client/src/components/brain/tabs/DigestTab.jsx
+++ b/client/src/components/brain/tabs/DigestTab.jsx
@@ -12,7 +12,7 @@ import {
} from 'lucide-react';
import toast from 'react-hot-toast';
-import { formatRelativeTime } from '../constants';
+import { timeAgo } from '../../../utils/formatters';
export default function DigestTab({ onRefresh }) {
const [latestDigest, setLatestDigest] = useState(null);
@@ -109,7 +109,7 @@ export default function DigestTab({ onRefresh }) {
<div className="p-4 bg-port-card border border-port-border rounded-lg">
<div className="flex items-center justify-between mb-3">
<span className="text-sm text-gray-500">
- Generated {formatRelativeTime(latestDigest.generatedAt)}
+ Generated {timeAgo(latestDigest.generatedAt)}
</span>
</div>
@@ -173,7 +173,7 @@ export default function DigestTab({ onRefresh }) {
<div key={digest.id} className="p-3 bg-port-card/50 border border-port-border rounded-lg">
<div className="flex items-center justify-between mb-2">
<span className="text-xs text-gray-500">
- {formatRelativeTime(digest.generatedAt)}
+ {timeAgo(digest.generatedAt)}
</span>
</div>
<p className="text-sm text-gray-300">{digest.digestText}</p>
@@ -210,7 +210,7 @@ export default function DigestTab({ onRefresh }) {
<div className="p-4 bg-port-card border border-port-border rounded-lg">
<div className="flex items-center justify-between mb-3">
<span className="text-sm text-gray-500">
- Generated {formatRelativeTime(latestReview.generatedAt)}
+ Generated {timeAgo(latestReview.generatedAt)}
</span>
</div>
@@ -283,7 +283,7 @@ export default function DigestTab({ onRefresh }) {
<div key={review.id} className="p-3 bg-port-card/50 border border-port-border rounded-lg">
<div className="flex items-center justify-between mb-2">
<span className="text-xs text-gray-500">
- {formatRelativeTime(review.generatedAt)}
+ {timeAgo(review.generatedAt)}
</span>
</div>
<p className="text-sm text-gray-300">{review.reviewText}</p>
diff --git a/client/src/components/brain/tabs/InboxTab.jsx b/client/src/components/brain/tabs/InboxTab.jsx
index 8009575234..7d958d60fe 100644
--- a/client/src/components/brain/tabs/InboxTab.jsx
+++ b/client/src/components/brain/tabs/InboxTab.jsx
@@ -20,9 +20,9 @@ import toast from 'react-hot-toast';
import {
DESTINATIONS,
- getConfidenceColor,
- formatRelativeTime
+ getConfidenceColor
} from '../constants';
+import { timeAgo } from '../../../utils/formatters';
export default function InboxTab({ onRefresh, settings }) {
const [inputText, setInputText] = useState('');
@@ -258,7 +258,7 @@ export default function InboxTab({ onRefresh, settings }) {
<div className="flex items-center gap-2">
<RefreshCw className="w-4 h-4 text-port-accent animate-spin" />
<span className="text-xs text-gray-500 whitespace-nowrap">
- {formatRelativeTime(entry.capturedAt)}
+ {timeAgo(entry.capturedAt)}
</span>
</div>
</div>
@@ -337,7 +337,7 @@ export default function InboxTab({ onRefresh, settings }) {
</>
)}
<span className="text-xs text-gray-500 whitespace-nowrap">
- {formatRelativeTime(entry.capturedAt)}
+ {timeAgo(entry.capturedAt)}
</span>
</div>
@@ -573,7 +573,7 @@ export default function InboxTab({ onRefresh, settings }) {
<Trash2 size={14} />
</button>
<span className="text-xs text-gray-500 whitespace-nowrap">
- {formatRelativeTime(entry.capturedAt)}
+ {timeAgo(entry.capturedAt)}
</span>
</div>
</div>
@@ -732,7 +732,7 @@ export default function InboxTab({ onRefresh, settings }) {
<Trash2 size={14} />
</button>
<span className="text-xs text-gray-600 whitespace-nowrap">
- {formatRelativeTime(entry.doneAt || entry.capturedAt)}
+ {timeAgo(entry.doneAt || entry.capturedAt)}
</span>
</div>
</div>
diff --git a/client/src/components/brain/tabs/LinksTab.jsx b/client/src/components/brain/tabs/LinksTab.jsx
index 69a723764c..1a27b10491 100644
--- a/client/src/components/brain/tabs/LinksTab.jsx
+++ b/client/src/components/brain/tabs/LinksTab.jsx
@@ -17,7 +17,7 @@ import {
Tag
} from 'lucide-react';
import toast from 'react-hot-toast';
-import { formatRelativeTime } from '../constants';
+import { timeAgo } from '../../../utils/formatters';
const LINK_TYPE_COLORS = {
github: 'bg-purple-500/20 text-purple-400 border-purple-500/30',
@@ -374,7 +374,7 @@ export default function LinksTab({ onRefresh }) {
)}
<span className="text-xs text-gray-500 whitespace-nowrap">
- {formatRelativeTime(link.createdAt)}
+ {timeAgo(link.createdAt)}
</span>
</div>
diff --git a/client/src/components/brain/tabs/MemoryTab.jsx b/client/src/components/brain/tabs/MemoryTab.jsx
index 63654232ce..7fcaddcabe 100644
--- a/client/src/components/brain/tabs/MemoryTab.jsx
+++ b/client/src/components/brain/tabs/MemoryTab.jsx
@@ -18,9 +18,9 @@ import {
DESTINATIONS,
PROJECT_STATUS_COLORS,
IDEA_STATUS_COLORS,
- ADMIN_STATUS_COLORS,
- formatRelativeTime
+ ADMIN_STATUS_COLORS
} from '../constants';
+import { timeAgo } from '../../../utils/formatters';
export default function MemoryTab({ onRefresh }) {
const [activeType, setActiveType] = useState('memories');
@@ -531,7 +531,7 @@ export default function MemoryTab({ onRefresh }) {
)}
<p className="text-xs text-gray-500 mt-2">
- Updated {formatRelativeTime(record.updatedAt)}
+ Updated {timeAgo(record.updatedAt)}
</p>
</div>
diff --git a/client/src/components/brain/tabs/TrustTab.jsx b/client/src/components/brain/tabs/TrustTab.jsx
index 7fc6f0db56..1e6f8c94bb 100644
--- a/client/src/components/brain/tabs/TrustTab.jsx
+++ b/client/src/components/brain/tabs/TrustTab.jsx
@@ -12,9 +12,9 @@ import toast from 'react-hot-toast';
import {
DESTINATIONS,
STATUS_COLORS,
- getConfidenceColor,
- formatRelativeTime
+ getConfidenceColor
} from '../constants';
+import { timeAgo } from '../../../utils/formatters';
export default function TrustTab({ onRefresh }) {
const [entries, setEntries] = useState([]);
@@ -263,7 +263,7 @@ export default function TrustTab({ onRefresh }) {
{Math.round(confidence * 100)}%
</span>
<span className="text-xs text-gray-500">
- {formatRelativeTime(entry.capturedAt)}
+ {timeAgo(entry.capturedAt)}
</span>
</div>
</div>
diff --git a/client/src/components/city/CityRoads.jsx b/client/src/components/city/CityRoads.jsx
deleted file mode 100644
index c131853673..0000000000
--- a/client/src/components/city/CityRoads.jsx
+++ /dev/null
@@ -1,137 +0,0 @@
-import { useRef, useMemo } from 'react';
-import { useFrame } from '@react-three/fiber';
-import * as THREE from 'three';
-import { CITY_COLORS, BUILDING_PARAMS } from './cityConstants';
-
-// Animated road with flowing light pulses
-function RoadSegment({ start, end, color, offset = 0 }) {
- const pulseRef = useRef();
-
- const length = useMemo(() => {
- return Math.sqrt((end[0] - start[0]) ** 2 + (end[2] - start[2]) ** 2);
- }, [start, end]);
-
- const midX = (start[0] + end[0]) / 2;
- const midZ = (start[2] + end[2]) / 2;
- const angle = Math.atan2(end[2] - start[2], end[0] - start[0]);
-
- useFrame(({ clock }) => {
- if (!pulseRef.current) return;
- const t = ((clock.getElapsedTime() * 0.3 + offset) % 1.0);
-
- // Animate pulse position along the road
- pulseRef.current.position.set(
- start[0] + (end[0] - start[0]) * t,
- 0.03,
- start[2] + (end[2] - start[2]) * t
- );
-
- pulseRef.current.material.opacity = 0.3 + Math.sin(t * Math.PI) * 0.4;
- });
-
- return (
- <group>
- {/* Road surface - dark strip */}
- <mesh
- position={[midX, 0.005, midZ]}
- rotation={[-Math.PI / 2, 0, angle]}
- >
- <planeGeometry args={[length, 0.6]} />
- <meshBasicMaterial color="#0a0a1a" transparent opacity={0.6} side={THREE.DoubleSide} />
- </mesh>
-
- {/* Road edge lines */}
- <mesh
- position={[midX, 0.01, midZ + Math.cos(angle) * 0.3]}
- rotation={[-Math.PI / 2, 0, angle]}
- >
- <planeGeometry args={[length, 0.02]} />
- <meshBasicMaterial color={color} transparent opacity={0.3} side={THREE.DoubleSide} />
- </mesh>
- <mesh
- position={[midX, 0.01, midZ - Math.cos(angle) * 0.3]}
- rotation={[-Math.PI / 2, 0, angle]}
- >
- <planeGeometry args={[length, 0.02]} />
- <meshBasicMaterial color={color} transparent opacity={0.3} side={THREE.DoubleSide} />
- </mesh>
-
- {/* Animated light pulse traveling along road */}
- <mesh ref={pulseRef} rotation={[-Math.PI / 2, 0, angle]}>
- <circleGeometry args={[0.12, 8]} />
- <meshBasicMaterial color={color} transparent opacity={0.5} side={THREE.DoubleSide} />
- </mesh>
- </group>
- );
-}
-
-export default function CityRoads({ positions }) {
- const roads = useMemo(() => {
- if (!positions || positions.size < 2) return [];
-
- const entries = [];
- positions.forEach((pos) => {
- if (pos.district === 'downtown') entries.push(pos);
- });
-
- if (entries.length < 2) return [];
-
- const result = [];
- const spacing = BUILDING_PARAMS.spacing;
- const roadOffset = BUILDING_PARAMS.width / 2 + 0.5;
-
- // Find unique rows and columns
- const rows = [...new Set(entries.map(e => Math.round(e.z * 10) / 10))].sort((a, b) => a - b);
- const cols = [...new Set(entries.map(e => Math.round(e.x * 10) / 10))].sort((a, b) => a - b);
-
- let minX = Infinity, maxX = -Infinity, minZ = Infinity, maxZ = -Infinity;
- entries.forEach(p => {
- minX = Math.min(minX, p.x);
- maxX = Math.max(maxX, p.x);
- minZ = Math.min(minZ, p.z);
- maxZ = Math.max(maxZ, p.z);
- });
-
- const pad = spacing / 2 + 1.5;
-
- // Horizontal roads between rows
- rows.forEach((z, i) => {
- result.push({
- id: `h-${i}`,
- start: [minX - pad, 0, z + roadOffset],
- end: [maxX + pad, 0, z + roadOffset],
- color: CITY_COLORS.neonAccents[i % CITY_COLORS.neonAccents.length],
- offset: i * 0.3,
- });
- });
-
- // Vertical roads between columns
- cols.forEach((x, i) => {
- result.push({
- id: `v-${i}`,
- start: [x + roadOffset, 0, minZ - pad],
- end: [x + roadOffset, 0, maxZ + pad],
- color: CITY_COLORS.neonAccents[(i + 3) % CITY_COLORS.neonAccents.length],
- offset: i * 0.25,
- });
- });
-
- return result;
- }, [positions]);
-
- if (roads.length === 0) return null;
-
- return (
- <group>
- {roads.map(road => (
- <RoadSegment
- key={road.id}
- start={road.start}
- end={road.end}
- color={road.color}
- offset={road.offset}
- />
- ))}
- </group>
- );
-}
diff --git a/client/src/components/digital-twin/constants.js b/client/src/components/digital-twin/constants.js
index e3fcacf281..e8aad787ba 100644
--- a/client/src/components/digital-twin/constants.js
+++ b/client/src/components/digital-twin/constants.js
@@ -276,21 +276,3 @@ export function getHealthLabel(score) {
return 'Needs Work';
}
-// Format relative time
-export function formatRelativeTime(dateString) {
- if (!dateString) return 'Never';
-
- const date = new Date(dateString);
- const now = new Date();
- const diffMs = now - date;
- const diffMins = Math.floor(diffMs / 60000);
- const diffHours = Math.floor(diffMs / 3600000);
- const diffDays = Math.floor(diffMs / 86400000);
-
- if (diffMins < 1) return 'Just now';
- if (diffMins < 60) return `${diffMins}m ago`;
- if (diffHours < 24) return `${diffHours}h ago`;
- if (diffDays < 7) return `${diffDays}d ago`;
-
- return date.toLocaleDateString();
-}
diff --git a/client/src/components/digital-twin/tabs/DocumentsTab.jsx b/client/src/components/digital-twin/tabs/DocumentsTab.jsx
index 1f4a916766..c807de9b1c 100644
--- a/client/src/components/digital-twin/tabs/DocumentsTab.jsx
+++ b/client/src/components/digital-twin/tabs/DocumentsTab.jsx
@@ -14,7 +14,8 @@ import {
import * as api from '../../../services/api';
import toast from 'react-hot-toast';
-import { DOCUMENT_CATEGORIES, formatRelativeTime } from '../constants';
+import { DOCUMENT_CATEGORIES } from '../constants';
+import { timeAgo } from '../../../utils/formatters';
export default function DocumentsTab({ onRefresh }) {
const [documents, setDocuments] = useState([]);
@@ -162,7 +163,7 @@ export default function DocumentsTab({ onRefresh }) {
</span>
</div>
<div className="text-xs text-gray-500 mt-1">
- {formatRelativeTime(doc.lastModified)}
+ {timeAgo(doc.lastModified)}
</div>
</button>
))}
diff --git a/client/src/components/digital-twin/tabs/OverviewTab.jsx b/client/src/components/digital-twin/tabs/OverviewTab.jsx
index c4c5968821..81d5cebb84 100644
--- a/client/src/components/digital-twin/tabs/OverviewTab.jsx
+++ b/client/src/components/digital-twin/tabs/OverviewTab.jsx
@@ -20,9 +20,9 @@ import toast from 'react-hot-toast';
import {
DOCUMENT_CATEGORIES,
getHealthColor,
- getHealthLabel,
- formatRelativeTime
+ getHealthLabel
} from '../constants';
+import { timeAgo } from '../../../utils/formatters';
import SoulWizard from '../SoulWizard';
import PersonalityMap from '../PersonalityMap';
import ConfidenceGauge from '../ConfidenceGauge';
@@ -510,7 +510,7 @@ export default function OverviewTab({ status, settings, onRefresh }) {
<div className="font-medium text-white">Run Tests</div>
<div className="text-sm text-gray-500 truncate">
{status.lastTestRun
- ? `Last: ${formatRelativeTime(status.lastTestRun.timestamp)}`
+ ? `Last: ${timeAgo(status.lastTestRun.timestamp)}`
: 'Test behavioral alignment'}
</div>
</div>
@@ -562,7 +562,7 @@ export default function OverviewTab({ status, settings, onRefresh }) {
{status.lastTestRun.passed}/{status.lastTestRun.total} tests passed
</div>
<div className="text-xs sm:text-sm text-gray-500">
- Model: {status.lastTestRun.model} • {formatRelativeTime(status.lastTestRun.timestamp)}
+ Model: {status.lastTestRun.model} • {timeAgo(status.lastTestRun.timestamp)}
</div>
</div>
</div>
diff --git a/client/src/components/digital-twin/tabs/TestTab.jsx b/client/src/components/digital-twin/tabs/TestTab.jsx
index 3db21c0148..770631bb3a 100644
--- a/client/src/components/digital-twin/tabs/TestTab.jsx
+++ b/client/src/components/digital-twin/tabs/TestTab.jsx
@@ -18,7 +18,8 @@ import {
import * as api from '../../../services/api';
import toast from 'react-hot-toast';
-import { TEST_STATUS, formatRelativeTime } from '../constants';
+import { TEST_STATUS } from '../constants';
+import { timeAgo } from '../../../utils/formatters';
export default function TestTab({ onRefresh }) {
const [tests, setTests] = useState([]);
@@ -568,7 +569,7 @@ export default function TestTab({ onRefresh }) {
<div>
<div className="text-sm text-white">{run.model}</div>
<div className="text-xs text-gray-500">
- {run.passed}/{run.total} passed • {formatRelativeTime(run.timestamp)}
+ {run.passed}/{run.total} passed • {timeAgo(run.timestamp)}
</div>
</div>
</div>
diff --git a/client/src/components/insights/CrossDomainTab.jsx b/client/src/components/insights/CrossDomainTab.jsx
index 81a0442ef2..6022cb46f2 100644
--- a/client/src/components/insights/CrossDomainTab.jsx
+++ b/client/src/components/insights/CrossDomainTab.jsx
@@ -2,19 +2,7 @@ import { useState, useEffect } from 'react';
import { RefreshCw, GitCompare } from 'lucide-react';
import ReactDiffViewer from 'react-diff-viewer-continued';
import { getInsightNarrative, refreshInsightNarrative } from '../../services/api';
-import { formatDate } from '../../utils/formatters';
-
-function formatRelativeTime(isoString) {
- if (!isoString) return null;
- const diffMs = Date.now() - new Date(isoString).getTime();
- const diffMins = Math.floor(diffMs / 60000);
- if (diffMins < 1) return 'just now';
- if (diffMins < 60) return `${diffMins}m ago`;
- const diffHours = Math.floor(diffMins / 60);
- if (diffHours < 24) return `${diffHours}h ago`;
- const diffDays = Math.floor(diffHours / 24);
- return `${diffDays}d ago`;
-}
+import { formatDate, timeAgo } from '../../utils/formatters';
export default function CrossDomainTab() {
const [data, setData] = useState(null);
@@ -81,7 +69,7 @@ export default function CrossDomainTab() {
<div className="flex items-center gap-3">
{data.generatedAt && (
<span className="text-xs text-gray-500">
- Last analyzed {formatRelativeTime(data.generatedAt)}
+ Last analyzed {timeAgo(data.generatedAt)}
</span>
)}
{data.model && (
diff --git a/client/src/components/insights/TasteIdentityTab.jsx b/client/src/components/insights/TasteIdentityTab.jsx
index 27e9ff4c03..52681766a8 100644
--- a/client/src/components/insights/TasteIdentityTab.jsx
+++ b/client/src/components/insights/TasteIdentityTab.jsx
@@ -4,6 +4,7 @@ import { getInsightThemes, refreshInsightThemes } from '../../services/api';
import InsightCard from './InsightCard';
import ConfidenceBadge from './ConfidenceBadge';
import EmptyState from './EmptyState';
+import { timeAgo } from '../../utils/formatters';
// Map theme strength to confidence level
const STRENGTH_TO_LEVEL = {
@@ -12,18 +13,6 @@ const STRENGTH_TO_LEVEL = {
tentative: 'weak'
};
-function formatRelativeTime(isoString) {
- if (!isoString) return null;
- const diffMs = Date.now() - new Date(isoString).getTime();
- const diffMins = Math.floor(diffMs / 60000);
- if (diffMins < 1) return 'just now';
- if (diffMins < 60) return `${diffMins}m ago`;
- const diffHours = Math.floor(diffMins / 60);
- if (diffHours < 24) return `${diffHours}h ago`;
- const diffDays = Math.floor(diffHours / 24);
- return `${diffDays}d ago`;
-}
-
function EvidenceList({ evidence }) {
const [expanded, setExpanded] = useState(false);
if (!evidence || evidence.length === 0) return null;
@@ -139,7 +128,7 @@ export default function TasteIdentityTab() {
);
}
- const relativeTime = formatRelativeTime(data.generatedAt);
+ const relativeTime = timeAgo(data.generatedAt);
return (
<div className="space-y-4">
diff --git a/client/src/components/meatspace/DeathClockCountdown.jsx b/client/src/components/meatspace/DeathClockCountdown.jsx
deleted file mode 100644
index b36de0019a..0000000000
--- a/client/src/components/meatspace/DeathClockCountdown.jsx
+++ /dev/null
@@ -1,100 +0,0 @@
-import { useDeathClock } from '../../hooks/useDeathClock';
-
-const TimeUnit = ({ value, label, color }) => (
- <div className="flex flex-col items-center">
- <span className={`text-3xl md:text-5xl font-mono font-bold tabular-nums ${color}`}>
- {String(value).padStart(2, '0')}
- </span>
- <span className="text-xs text-gray-500 uppercase mt-1">{label}</span>
- </div>
-);
-
-const Separator = () => (
- <span className="text-2xl md:text-4xl font-mono text-gray-600 self-start mt-1">:</span>
-);
-
-export default function DeathClockCountdown({ deathDate, lifeExpectancy, percentComplete }) {
- const countdown = useDeathClock(deathDate);
-
- if (!countdown) {
- return (
- <div className="bg-port-card border border-port-border rounded-xl p-6">
- <p className="text-gray-500">Death clock unavailable. Set birth date in Digital Twin &gt; Goals.</p>
- </div>
- );
- }
-
- if (countdown.expired) {
- return (
- <div className="bg-port-card border border-port-border rounded-xl p-6">
- <p className="text-port-error text-xl font-bold">Time expired. You&apos;re on borrowed time.</p>
- </div>
- );
- }
-
- return (
- <div className="bg-port-card border border-port-border rounded-xl p-6">
- <h3 className="text-sm font-medium text-gray-400 uppercase tracking-wider mb-4">Time Remaining</h3>
-
- {/* Countdown timer */}
- <div className="flex items-start gap-2 md:gap-3 justify-center flex-wrap">
- <TimeUnit value={countdown.years} label="years" color="text-port-accent" />
- <Separator />
- <TimeUnit value={countdown.months} label="months" color="text-purple-400" />
- <Separator />
- <TimeUnit value={countdown.weeks} label="weeks" color="text-teal-400" />
- <Separator />
- <TimeUnit value={countdown.days} label="days" color="text-port-success" />
- <Separator />
- <TimeUnit value={countdown.hours} label="hours" color="text-port-warning" />
- <Separator />
- <TimeUnit value={countdown.minutes} label="min" color="text-orange-400" />
- <Separator />
- <TimeUnit value={countdown.seconds} label="sec" color="text-port-error" />
- </div>
-
- {/* Life expectancy details */}
- {lifeExpectancy && (
- <div className="mt-6 grid grid-cols-2 md:grid-cols-4 gap-4">
- <div>
- <span className="text-xs text-gray-500">SSA Baseline</span>
- <p className="text-lg font-semibold text-gray-300">{lifeExpectancy.baseline}y</p>
- </div>
- <div>
- <span className="text-xs text-gray-500">Genome Adjusted</span>
- <p className="text-lg font-semibold text-gray-300">{lifeExpectancy.genomeAdjusted}y</p>
- </div>
- <div>
- <span className="text-xs text-gray-500">Lifestyle Adj.</span>
- <p className={`text-lg font-semibold ${lifeExpectancy.lifestyleAdjustment >= 0 ? 'text-port-success' : 'text-port-error'}`}>
- {lifeExpectancy.lifestyleAdjustment >= 0 ? '+' : ''}{lifeExpectancy.lifestyleAdjustment}y
- </p>
- </div>
- <div>
- <span className="text-xs text-gray-500">Total LE</span>
- <p className="text-lg font-semibold text-white">{lifeExpectancy.total}y</p>
- </div>
- </div>
- )}
-
- {/* Progress bar */}
- {percentComplete != null && (
- <div className="mt-4">
- <div className="flex justify-between text-xs text-gray-500 mb-1">
- <span>Life progress</span>
- <span>{percentComplete}%</span>
- </div>
- <div className="h-2 bg-port-border rounded-full overflow-hidden">
- <div
- className="h-full rounded-full transition-all duration-1000"
- style={{
- width: `${Math.min(100, percentComplete)}%`,
- background: percentComplete > 80 ? '#ef4444' : percentComplete > 60 ? '#f59e0b' : '#3b82f6'
- }}
- />
- </div>
- </div>
- )}
- </div>
- );
-}
diff --git a/client/src/components/meatspace/LEVTracker.jsx b/client/src/components/meatspace/LEVTracker.jsx
deleted file mode 100644
index 2416738069..0000000000
--- a/client/src/components/meatspace/LEVTracker.jsx
+++ /dev/null
@@ -1,67 +0,0 @@
-import { Rocket } from 'lucide-react';
-
-export default function LEVTracker({ lev }) {
- if (!lev) return null;
-
- const { targetYear, ageAtLEV, yearsToLEV, researchProgress, onTrack, adjustedLifeExpectancy } = lev;
-
- return (
- <div className="bg-port-card border border-port-border rounded-xl p-6">
- <div className="flex items-center gap-2 mb-4">
- <Rocket size={18} className="text-port-accent" />
- <h3 className="text-sm font-medium text-gray-400 uppercase tracking-wider">
- Longevity Escape Velocity — {targetYear}
- </h3>
- </div>
-
- {/* Status */}
- <div className="flex items-center gap-3 mb-4">
- <span className={`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-sm font-medium ${
- onTrack
- ? 'bg-port-success/10 text-port-success'
- : 'bg-port-error/10 text-port-error'
- }`}>
- <span className={`w-2 h-2 rounded-full ${onTrack ? 'bg-port-success' : 'bg-port-error'}`} />
- {onTrack ? 'On Track' : 'At Risk'}
- </span>
- <span className="text-sm text-gray-400">
- Age at LEV: <span className="text-white font-medium">{ageAtLEV}</span>
- {' | '}
- Adjusted LE: <span className="text-white font-medium">{adjustedLifeExpectancy}y</span>
- </span>
- </div>
-
- {/* Research timeline progress */}
- <div className="mb-2">
- <div className="flex justify-between text-xs text-gray-500 mb-1">
- <span>Research timeline (2000–{targetYear})</span>
- <span>{researchProgress}%</span>
- </div>
- <div className="h-3 bg-port-border rounded-full overflow-hidden">
- <div
- className="h-full rounded-full bg-port-accent transition-all duration-500"
- style={{ width: `${researchProgress}%` }}
- />
- </div>
- </div>
-
- {/* Key stats */}
- <div className="grid grid-cols-3 gap-4 mt-4">
- <div>
- <span className="text-xs text-gray-500">Years to LEV</span>
- <p className="text-xl font-bold text-white">{yearsToLEV}</p>
- </div>
- <div>
- <span className="text-xs text-gray-500">Must survive to age</span>
- <p className="text-xl font-bold text-white">{ageAtLEV}</p>
- </div>
- <div>
- <span className="text-xs text-gray-500">Margin</span>
- <p className={`text-xl font-bold ${onTrack ? 'text-port-success' : 'text-port-error'}`}>
- {onTrack ? '+' : ''}{Math.round((adjustedLifeExpectancy - ageAtLEV) * 10) / 10}y
- </p>
- </div>
- </div>
- </div>
- );
-}
diff --git a/client/src/components/meatspace/post/DrillTransition.jsx b/client/src/components/meatspace/post/DrillTransition.jsx
index 453d049b8b..baa78db65f 100644
--- a/client/src/components/meatspace/post/DrillTransition.jsx
+++ b/client/src/components/meatspace/post/DrillTransition.jsx
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import { ChevronRight, Calculator, BookOpen, MessageCircle, Mic, Sparkles } from 'lucide-react';
-import { DOMAINS, DRILL_TO_DOMAIN } from './constants';
+import { DOMAINS, DRILL_TO_DOMAIN, DRILL_LABELS } from './constants';
const DOMAIN_ICONS = {
math: Calculator,
@@ -10,27 +10,6 @@ const DOMAIN_ICONS = {
imagination: Sparkles,
};
-const DRILL_LABELS = {
- 'doubling-chain': 'Doubling Chain',
- 'serial-subtraction': 'Serial Subtraction',
- 'multiplication': 'Multiplication',
- 'powers': 'Powers',
- 'estimation': 'Estimation',
- 'word-association': 'Word Association',
- 'story-recall': 'Story Recall',
- 'verbal-fluency': 'Verbal Fluency',
- 'wit-comeback': 'Wit & Comeback',
- 'pun-wordplay': 'Pun & Wordplay',
- 'memory-fill-blank': 'Memory Fill Blank',
- 'memory-sequence': 'Memory Sequence',
- 'memory-element-flash': 'Element Flash',
- 'what-if': 'What If?',
- 'alternative-uses': 'Alternative Uses',
- 'story-prompt': 'Story Prompt',
- 'invention-pitch': 'Invention Pitch',
- 'reframe': 'Reframe',
-};
-
export default function DrillTransition({ nextDrillType, drillIndex, drillCount, completedResults, onContinue }) {
const [countdown, setCountdown] = useState(3);
diff --git a/client/src/components/meatspace/post/PostDrillRunner.jsx b/client/src/components/meatspace/post/PostDrillRunner.jsx
index 998cdc7ace..6eefe311c9 100644
--- a/client/src/components/meatspace/post/PostDrillRunner.jsx
+++ b/client/src/components/meatspace/post/PostDrillRunner.jsx
@@ -1,18 +1,7 @@
import { useState, useEffect, useRef, useCallback } from 'react';
import { CheckCircle, XCircle } from 'lucide-react';
-import { MEMORY_DRILL_TYPES } from './constants';
-
-const DRILL_LABELS = {
- 'doubling-chain': 'Doubling Chain',
- 'serial-subtraction': 'Serial Subtraction',
- 'multiplication': 'Multiplication',
- 'powers': 'Powers',
- 'estimation': 'Estimation',
- 'memory-fill-blank': 'Memory Fill Blank',
- 'memory-sequence': 'Memory Sequence',
- 'memory-element-flash': 'Element Flash',
-};
+import { MEMORY_DRILL_TYPES, DRILL_LABELS } from './constants';
export default function PostDrillRunner({ session }) {
const {
diff --git a/client/src/components/meatspace/post/PostHistory.jsx b/client/src/components/meatspace/post/PostHistory.jsx
index 7fe9330c3a..db240a1842 100644
--- a/client/src/components/meatspace/post/PostHistory.jsx
+++ b/client/src/components/meatspace/post/PostHistory.jsx
@@ -2,20 +2,7 @@ import { useState, useEffect, useCallback } from 'react';
import { ArrowLeft, ChevronDown, ChevronRight } from 'lucide-react';
import { LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer, CartesianGrid } from 'recharts';
import { getPostSessions, getPostStats } from '../../../services/api';
-import { LLM_DRILL_TYPES } from './constants';
-
-const DRILL_LABELS = {
- 'doubling-chain': 'Doubling Chain',
- 'serial-subtraction': 'Serial Subtraction',
- 'multiplication': 'Multiplication',
- 'powers': 'Powers',
- 'estimation': 'Estimation',
- 'word-association': 'Word Association',
- 'story-recall': 'Story Recall',
- 'verbal-fluency': 'Verbal Fluency',
- 'wit-comeback': 'Wit & Comeback',
- 'pun-wordplay': 'Pun & Wordplay'
-};
+import { LLM_DRILL_TYPES, DRILL_LABELS } from './constants';
const RANGES = [
{ label: '7d', days: 7 },
diff --git a/client/src/components/meatspace/post/PostSessionResults.jsx b/client/src/components/meatspace/post/PostSessionResults.jsx
index 26868a8560..71ec4cc889 100644
--- a/client/src/components/meatspace/post/PostSessionResults.jsx
+++ b/client/src/components/meatspace/post/PostSessionResults.jsx
@@ -1,27 +1,6 @@
import { useState } from 'react';
import { CheckCircle, Save, ArrowLeft, ChevronDown, ChevronUp, Dumbbell } from 'lucide-react';
-import { LLM_DRILL_TYPES, DRILL_TO_DOMAIN, DOMAINS } from './constants';
-
-const DRILL_LABELS = {
- 'doubling-chain': 'Doubling Chain',
- 'serial-subtraction': 'Serial Subtraction',
- 'multiplication': 'Multiplication',
- 'powers': 'Powers',
- 'estimation': 'Estimation',
- 'word-association': 'Word Association',
- 'story-recall': 'Story Recall',
- 'verbal-fluency': 'Verbal Fluency',
- 'wit-comeback': 'Wit & Comeback',
- 'pun-wordplay': 'Pun & Wordplay',
- 'memory-fill-blank': 'Memory Fill Blank',
- 'memory-sequence': 'Memory Sequence',
- 'memory-element-flash': 'Element Flash',
- 'what-if': 'What If?',
- 'alternative-uses': 'Alternative Uses',
- 'story-prompt': 'Story Prompt',
- 'invention-pitch': 'Invention Pitch',
- 'reframe': 'Reframe',
-};
+import { LLM_DRILL_TYPES, DRILL_TO_DOMAIN, DOMAINS, DRILL_LABELS } from './constants';
export default function PostSessionResults({ session, tags = {}, onSaved, onBack }) {
const { drillResults, sessionScore, state, saveSession, isTraining } = session;
diff --git a/client/src/pages/Brain.jsx b/client/src/pages/Brain.jsx
index fff23de5d5..89bcac8aeb 100644
--- a/client/src/pages/Brain.jsx
+++ b/client/src/pages/Brain.jsx
@@ -3,10 +3,8 @@ import { useParams, useNavigate } from 'react-router-dom';
import * as api from '../services/api';
import { Brain as BrainIcon, RefreshCw } from 'lucide-react';
-import {
- TABS,
- formatRelativeTime
-} from '../components/brain/constants';
+import { TABS } from '../components/brain/constants';
+import { timeAgo } from '../utils/formatters';
import InboxTab from '../components/brain/tabs/InboxTab';
import LinksTab from '../components/brain/tabs/LinksTab';
@@ -105,7 +103,7 @@ export default function Brain() {
</span>
{summary.lastDailyDigest && (
<span className="text-gray-500">
- Last digest: {formatRelativeTime(summary.lastDailyDigest)}
+ Last digest: {timeAgo(summary.lastDailyDigest)}
</span>
)}
</div>
diff --git a/client/src/pages/Insights.jsx b/client/src/pages/Insights.jsx
index 1c9822e7c8..88545feb37 100644
--- a/client/src/pages/Insights.jsx
+++ b/client/src/pages/Insights.jsx
@@ -10,6 +10,7 @@ import GenomeHealthTab from '../components/insights/GenomeHealthTab';
import TasteIdentityTab from '../components/insights/TasteIdentityTab';
import CrossDomainTab from '../components/insights/CrossDomainTab';
import ConfidenceBadge from '../components/insights/ConfidenceBadge';
+import { timeAgo } from '../utils/formatters';
const TABS = [
{ id: 'overview', label: 'Overview', icon: Lightbulb },
@@ -20,18 +21,6 @@ const TABS = [
const VALID_TAB_IDS = new Set(TABS.map(t => t.id));
-function formatRelativeTime(isoString) {
- if (!isoString) return null;
- const diffMs = Date.now() - new Date(isoString).getTime();
- const diffMins = Math.floor(diffMs / 60000);
- if (diffMins < 1) return 'just now';
- if (diffMins < 60) return `${diffMins}m ago`;
- const diffHours = Math.floor(diffMins / 60);
- if (diffHours < 24) return `${diffHours}h ago`;
- const diffDays = Math.floor(diffHours / 24);
- return `${diffDays}d ago`;
-}
-
function SummaryCardSkeleton() {
return (
<div className="bg-port-card border border-port-border rounded-lg p-6 animate-pulse">
@@ -134,7 +123,7 @@ function OverviewTab() {
icon: Link2,
iconColor: 'text-port-accent',
stat: narrativeAvailable
- ? `Last analyzed ${formatRelativeTime(narrativeData.generatedAt)}`
+ ? `Last analyzed ${timeAgo(narrativeData.generatedAt)}`
: 'Not yet generated',
topInsight: firstSentence
? `${firstSentence}.`