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: 5-minute balanced session flow (M55 P5)
Adam Eivy43ea92459fea
diff --git a/client/src/components/meatspace/post/DrillTransition.jsx b/client/src/components/meatspace/post/DrillTransition.jsxnew file mode 100644index 0000000000..0a6d048514--- /dev/null+++ b/client/src/components/meatspace/post/DrillTransition.jsx@@ -0,0 +1,114 @@+import { useState, useEffect } from 'react';+import { ChevronRight, Calculator, BookOpen, MessageCircle, Mic, Sparkles } from 'lucide-react';+import { DOMAINS, DRILL_TO_DOMAIN } from './constants';++const DOMAIN_ICONS = {+ math: Calculator,+ memory: BookOpen,+ wordplay: MessageCircle,+ verbal: Mic,+ 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);++ const domainKey = DRILL_TO_DOMAIN[nextDrillType];+ const domain = domainKey ? DOMAINS[domainKey] : null;+ const Icon = domainKey ? DOMAIN_ICONS[domainKey] : ChevronRight;++ // Auto-advance after 3 seconds+ useEffect(() => {+ if (countdown <= 0) {+ onContinue();+ return;+ }+ const timer = setTimeout(() => setCountdown(c => c - 1), 1000);+ return () => clearTimeout(timer);+ }, [countdown, onContinue]);++ // Show completed drill scores so far+ const completedDomains = {};+ for (const r of completedResults) {+ const dk = DRILL_TO_DOMAIN[r.type];+ if (dk) completedDomains[dk] = r.score;+ }++ return (+ <div className="max-w-lg mx-auto space-y-8">+ {/* Completed domains summary */}+ {completedResults.length > 0 && (+ <div className="flex justify-center gap-3">+ {completedResults.map((r, i) => {+ const dk = DRILL_TO_DOMAIN[r.type];+ const d = dk ? DOMAINS[dk] : null;+ const sc = (r.score || 0) >= 80 ? 'text-port-success' : (r.score || 0) >= 50 ? 'text-port-warning' : 'text-port-error';+ return (+ <div key={i} className="flex flex-col items-center gap-1">+ <span className={`text-xs ${d?.color || 'text-gray-400'}`}>{d?.label || r.type}</span>+ <span className={`text-sm font-mono font-medium ${sc}`}>{r.score ?? '—'}</span>+ </div>+ );+ })}+ </div>+ )}++ {/* Next domain card */}+ <div className="text-center py-8">+ <div className={`inline-flex items-center justify-center w-16 h-16 rounded-2xl ${domain?.bgColor || 'bg-port-card'} mb-4`}>+ <Icon size={32} className={domain?.color || 'text-gray-400'} />+ </div>+ <div className="text-sm text-gray-500 mb-1">Up Next</div>+ <div className={`text-2xl font-bold ${domain?.color || 'text-white'}`}>+ {domain?.label || 'Next Drill'}+ </div>+ <div className="text-sm text-gray-500 mt-1">+ {DRILL_LABELS[nextDrillType] || nextDrillType}+ </div>+ </div>++ {/* Progress */}+ <div className="flex justify-center gap-2">+ {Array.from({ length: drillCount }, (_, i) => (+ <div+ key={i}+ className={`w-3 h-3 rounded-full ${+ i < drillIndex ? 'bg-port-success' :+ i === drillIndex ? 'bg-port-accent animate-pulse' :+ 'bg-port-border'+ }`}+ />+ ))}+ </div>++ {/* Continue button with countdown */}+ <button+ onClick={onContinue}+ className="w-full px-6 py-3 bg-port-accent hover:bg-port-accent/80 text-white font-medium rounded-lg transition-colors"+ >+ Continue {countdown > 0 ? `(${countdown})` : ''}+ </button>+ </div>+ );+}diff --git a/client/src/components/meatspace/post/PostSessionLauncher.jsx b/client/src/components/meatspace/post/PostSessionLauncher.jsxindex 0c31b8b69f..326add1c32 100644--- a/client/src/components/meatspace/post/PostSessionLauncher.jsx+++ b/client/src/components/meatspace/post/PostSessionLauncher.jsx@@ -1,6 +1,7 @@import { useState, useEffect } from 'react';-import { Zap, History, Settings, Play, Brain, BookOpen, Dumbbell } from 'lucide-react';+import { Zap, History, Settings, Play, Brain, BookOpen, Dumbbell, Timer } from 'lucide-react';import { getProviders } from '../../../services/api';+import { DOMAINS, DRILL_TO_DOMAIN } from './constants';const DRILL_LABELS = {'doubling-chain': 'Doubling Chain',@@ -82,7 +83,63 @@ export default function PostSessionLauncher({ config, recentSessions, onStart, oonStart(drillConfigs, cleanTags, mode === 'train');}+ // Build domain → enabled drills map for quick session+ const allEnabledDrills = [+ ...enabledMathDrills.map(([type, cfg]) => ({ type, cfg, source: 'math' })),+ ...enabledLlmDrills.map(([type, cfg]) => ({ type, cfg, source: 'llm' })),+ ];++ const enabledDomains = {};+ for (const { type, cfg, source } of allEnabledDrills) {+ const domain = DRILL_TO_DOMAIN[type];+ if (!domain) continue;+ if (!enabledDomains[domain]) enabledDomains[domain] = [];+ enabledDomains[domain].push({ type, cfg, source });+ }++ function handleQuickSession() {+ const drillConfigs = [];+ for (const [domainKey, drills] of Object.entries(enabledDomains)) {+ const domain = DOMAINS[domainKey];+ // Pick one random drill from this domain+ const pick = drills[Math.floor(Math.random() * drills.length)];+ const cfg = pick.cfg;++ const drillConfig = {+ type: pick.type,+ domain: domainKey,+ config: pick.source === 'math'+ ? {+ steps: cfg.steps,+ count: cfg.count ? Math.min(cfg.count, 5) : undefined,+ maxDigits: cfg.maxDigits,+ subtrahend: cfg.subtrahend,+ startRange: cfg.startRange,+ bases: cfg.bases,+ maxExponent: cfg.maxExponent,+ tolerancePct: cfg.tolerancePct,+ }+ : { count: Math.min(cfg.count || 5, 3) }, // Fewer prompts for quick session+ timeLimitSec: domain.timeBudgetSec,+ };++ if (pick.source === 'llm') {+ drillConfig.providerId = cfg.providerId || llmProviderId;+ drillConfig.model = cfg.model || llmModel;+ }++ drillConfigs.push(drillConfig);+ }++ const cleanTags = {};+ for (const [k, v] of Object.entries(tags)) {+ if (v.trim()) cleanTags[k] = v.trim();+ }+ onStart(drillConfigs, cleanTags, mode === 'train');+ }+const hasAnyDrills = enabledMathDrills.length > 0 || enabledLlmDrills.length > 0;+ const domainCount = Object.keys(enabledDomains).length;return (<div className="space-y-6 max-w-2xl">@@ -234,19 +291,35 @@ export default function PostSessionLauncher({ config, recentSessions, onStart, o</div></div>}- {/* Start Button */}- <button- onClick={handleStart}- disabled={!hasAnyDrills}- className={`w-full flex items-center justify-center gap-2 px-6 py-3 ${- mode === 'train'- ? 'bg-purple-600 hover:bg-purple-500'- : 'bg-port-accent hover:bg-port-accent/80'- } disabled:opacity-50 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors`}- >- {mode === 'train' ? <Dumbbell size={18} /> : <Play size={18} />}- {mode === 'train' ? 'Start Training' : 'Start POST'}- </button>+ {/* Start Buttons */}+ <div className="flex gap-3">+ {domainCount >= 2 && (+ <button+ onClick={handleQuickSession}+ disabled={!hasAnyDrills}+ className={`flex-1 flex items-center justify-center gap-2 px-6 py-3 ${+ mode === 'train'+ ? 'bg-purple-600 hover:bg-purple-500'+ : 'bg-port-success hover:bg-port-success/80'+ } disabled:opacity-50 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors`}+ >+ <Timer size={18} />+ Quick 5 Min ({domainCount} domains)+ </button>+ )}+ <button+ onClick={handleStart}+ disabled={!hasAnyDrills}+ className={`flex-1 flex items-center justify-center gap-2 px-6 py-3 ${+ mode === 'train'+ ? 'bg-purple-600/70 hover:bg-purple-500/70'+ : 'bg-port-accent hover:bg-port-accent/80'+ } disabled:opacity-50 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors`}+ >+ {mode === 'train' ? <Dumbbell size={18} /> : <Play size={18} />}+ {mode === 'train' ? 'Full Training' : 'Full POST'}+ </button>+ </div>{/* Recent Scores */}{lastThree.length > 0 && (diff --git a/client/src/components/meatspace/post/PostSessionResults.jsx b/client/src/components/meatspace/post/PostSessionResults.jsxindex 3e914aae36..26868a8560 100644--- a/client/src/components/meatspace/post/PostSessionResults.jsx+++ b/client/src/components/meatspace/post/PostSessionResults.jsx@@ -1,6 +1,6 @@import { useState } from 'react';import { CheckCircle, Save, ArrowLeft, ChevronDown, ChevronUp, Dumbbell } from 'lucide-react';-import { LLM_DRILL_TYPES } from './constants';+import { LLM_DRILL_TYPES, DRILL_TO_DOMAIN, DOMAINS } from './constants';const DRILL_LABELS = {'doubling-chain': 'Doubling Chain',@@ -12,7 +12,15 @@ const DRILL_LABELS = {'story-recall': 'Story Recall','verbal-fluency': 'Verbal Fluency','wit-comeback': 'Wit & Comeback',- 'pun-wordplay': 'Pun & Wordplay'+ '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 PostSessionResults({ session, tags = {}, onSaved, onBack }) {@@ -44,6 +52,35 @@ export default function PostSessionResults({ session, tags = {}, onSaved, onBack)}</div>+ {/* Domain Scores (for multi-domain sessions) */}+ {(() => {+ const byDomain = {};+ for (const r of drillResults) {+ const dk = DRILL_TO_DOMAIN[r.type];+ if (dk) {+ if (!byDomain[dk]) byDomain[dk] = [];+ byDomain[dk].push(r.score || 0);+ }+ }+ const domainKeys = Object.keys(byDomain);+ if (domainKeys.length < 2) return null;+ return (+ <div className="flex justify-center gap-4">+ {domainKeys.map(dk => {+ const d = DOMAINS[dk];+ const avg = Math.round(byDomain[dk].reduce((a, b) => a + b, 0) / byDomain[dk].length);+ const sc = avg >= 80 ? 'text-port-success' : avg >= 50 ? 'text-port-warning' : 'text-port-error';+ return (+ <div key={dk} className={`flex flex-col items-center gap-1 px-3 py-2 rounded-lg ${d?.bgColor || 'bg-port-card'}`}>+ <span className={`text-xs font-medium ${d?.color || 'text-gray-400'}`}>{d?.label || dk}</span>+ <span className={`text-lg font-mono font-bold ${sc}`}>{avg}</span>+ </div>+ );+ })}+ </div>+ );+ })()}+{/* Per-drill Breakdown */}<div className="bg-port-card border border-port-border rounded-lg p-4"><h3 className="text-sm font-medium text-gray-400 mb-3">Drill Breakdown</h3>diff --git a/client/src/components/meatspace/post/constants.js b/client/src/components/meatspace/post/constants.jsindex 1967a92610..f25ec5cc3c 100644--- a/client/src/components/meatspace/post/constants.js+++ b/client/src/components/meatspace/post/constants.js@@ -1,2 +1,54 @@export const LLM_DRILL_TYPES = ['word-association', 'story-recall', 'verbal-fluency', 'wit-comeback', 'pun-wordplay', 'what-if', 'alternative-uses', 'story-prompt', 'invention-pitch', 'reframe'];export const MEMORY_DRILL_TYPES = ['memory-fill-blank', 'memory-sequence', 'memory-element-flash'];++// Domain definitions for 5-minute balanced sessions+export const DOMAINS = {+ math: {+ label: 'Mental Math',+ icon: 'Calculator',+ color: 'text-blue-400',+ bgColor: 'bg-blue-500/20',+ timeBudgetSec: 60,+ drillTypes: ['doubling-chain', 'serial-subtraction', 'multiplication', 'powers', 'estimation'],+ },+ memory: {+ label: 'Memory',+ icon: 'BookOpen',+ color: 'text-green-400',+ bgColor: 'bg-green-500/20',+ timeBudgetSec: 90,+ drillTypes: ['memory-fill-blank', 'memory-sequence', 'memory-element-flash'],+ },+ wordplay: {+ label: 'Wordplay',+ icon: 'MessageCircle',+ color: 'text-purple-400',+ bgColor: 'bg-purple-500/20',+ timeBudgetSec: 60,+ drillTypes: ['pun-wordplay', 'word-association'],+ },+ verbal: {+ label: 'Verbal Agility',+ icon: 'Mic',+ color: 'text-amber-400',+ bgColor: 'bg-amber-500/20',+ timeBudgetSec: 60,+ drillTypes: ['story-recall', 'verbal-fluency', 'wit-comeback'],+ },+ imagination: {+ label: 'Imagination',+ icon: 'Sparkles',+ color: 'text-cyan-400',+ bgColor: 'bg-cyan-500/20',+ timeBudgetSec: 60,+ drillTypes: ['what-if', 'alternative-uses', 'story-prompt', 'invention-pitch', 'reframe'],+ },+};++// Map drill type → domain key+export const DRILL_TO_DOMAIN = {};+for (const [domainKey, domain] of Object.entries(DOMAINS)) {+ for (const dt of domain.drillTypes) {+ DRILL_TO_DOMAIN[dt] = domainKey;+ }+}diff --git a/client/src/components/meatspace/tabs/PostTab.jsx b/client/src/components/meatspace/tabs/PostTab.jsxindex 88cf96772f..0eadb29624 100644--- a/client/src/components/meatspace/tabs/PostTab.jsx+++ b/client/src/components/meatspace/tabs/PostTab.jsx@@ -8,6 +8,7 @@ import PostSessionResults from '../post/PostSessionResults';import PostHistory from '../post/PostHistory';import PostDrillConfig from '../post/PostDrillConfig';import MemoryBuilder from '../post/MemoryBuilder';+import DrillTransition from '../post/DrillTransition';import { LLM_DRILL_TYPES } from '../post/constants';export default function PostTab() {@@ -76,15 +77,27 @@ export default function PostTab() {}}, [session.state, view]);- // When between drills, auto-advance- useEffect(() => {- if (session.state === 'between-drills') {- session.nextDrill();- }- }, [session.state, session.nextDrill]);+ // When between drills, show transition (handled in switch/case below)const isLlmDrill = session.currentDrill && LLM_DRILL_TYPES.includes(session.currentDrill.type);+ // Show transition between drills+ if (session.state === 'between-drills' && view === 'running') {+ const nextIndex = session.currentDrillIndex + 1;+ const nextDrill = session.drills[nextIndex];+ if (nextDrill) {+ return (+ <DrillTransition+ nextDrillType={nextDrill.type}+ drillIndex={nextIndex}+ drillCount={session.drillCount}+ completedResults={session.drillResults}+ onContinue={session.nextDrill}+ />+ );+ }+ }+switch (view) {case 'running':if (isLlmDrill) {diff --git a/client/src/hooks/usePostSession.js b/client/src/hooks/usePostSession.jsindex 5c982fcdda..1b33b37290 100644--- a/client/src/hooks/usePostSession.js+++ b/client/src/hooks/usePostSession.js@@ -1,7 +1,31 @@import { useState, useCallback, useRef } from 'react';import { generatePostDrill, submitPostSession, scorePostLlmDrill, submitTrainingEntry } from '../services/api';import toast from 'react-hot-toast';-import { LLM_DRILL_TYPES } from '../components/meatspace/post/constants';+import { LLM_DRILL_TYPES, DRILL_TO_DOMAIN } from '../components/meatspace/post/constants';++function computeSessionScoreFromResults(results) {+ if (!results.length) return 0;+ // Group by domain — if any drills have domain info, use weighted avg per domain+ const byDomain = {};+ let hasDomains = false;+ for (const r of results) {+ const dk = DRILL_TO_DOMAIN[r.type];+ if (dk) {+ hasDomains = true;+ if (!byDomain[dk]) byDomain[dk] = [];+ byDomain[dk].push(r.score || 0);+ }+ }+ if (hasDomains && Object.keys(byDomain).length > 1) {+ // Average within each domain, then average across domains (equal weight per domain)+ const domainAvgs = Object.values(byDomain).map(scores =>+ Math.round(scores.reduce((a, b) => a + b, 0) / scores.length)+ );+ return Math.round(domainAvgs.reduce((a, b) => a + b, 0) / domainAvgs.length);+ }+ // Fallback: simple average+ return Math.round(results.reduce((s, r) => s + (r.score || 0), 0) / results.length);+}// States: idle → loading → drilling → between-drills → complete → saving → savedconst STATES = {@@ -90,9 +114,7 @@ export function usePostSession() {if (currentDrillIndex + 1 < drills.length) {setState(STATES.BETWEEN_DRILLS);} else {- // Session complete- const avgScore = Math.round(newResults.reduce((s, r) => s + r.score, 0) / newResults.length);- setSessionScore(avgScore);+ setSessionScore(computeSessionScoreFromResults(newResults));setState(STATES.COMPLETE);}}, [currentDrill, drillResults, currentDrillIndex, drills]);@@ -230,8 +252,7 @@ export function usePostSession() {if (currentDrillIndex + 1 < drills.length) {setState(STATES.BETWEEN_DRILLS);} else {- const avgScore = Math.round(newResults.reduce((s, r) => s + (r.score || 0), 0) / newResults.length);- setSessionScore(avgScore);+ setSessionScore(computeSessionScoreFromResults(newResults));setState(STATES.COMPLETE);}}, [drillResults, currentDrillIndex, drills]);