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: reopen a POST cognitive drill's how-to card after its first run (#4732)
[._.]/ Adam Eivy07e446cd327d
diff --git a/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx b/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsxindex 16781a63f1..766e4048e8 100644--- a/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx+++ b/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx@@ -5,6 +5,7 @@ import { safeReadJsonStorage, safeWriteStorage } from '../../../lib/safeStorage.import useMounted from '../../../hooks/useMounted';import useKeyCapture from '../../../hooks/useKeyCapture';import { isPressKey } from '../../../lib/a11yKeyboard.js';+import Modal from '../../ui/Modal';/*** Interactive runner for deterministic cognitive drills (n-back, digit-span,@@ -242,19 +243,25 @@ function DrillTutorialGate({ drill, isTraining, drillIndex, drillCount, childrenreturn (<CognitiveDrillTutorialdrill={drill}- isTraining={isTraining}- drillIndex={drillIndex}- drillCount={drillCount}- onStart={() => { markDrillTutorialSeen(drill.type); setShowTutorial(false); }}+ header={<DrillHeader type={drill.type} isTraining={isTraining} drillIndex={drillIndex} drillCount={drillCount} />}+ onAction={() => { markDrillTutorialSeen(drill.type); setShowTutorial(false); }}+ footNote="You’ll only see this the first time for each drill type. Reopen it any time from the launcher or Config."/>);}-function CognitiveDrillTutorial({ drill, isTraining, drillIndex, drillCount, onStart }) {+/**+ * The how-to card for one cognitive drill type. Everything around the card body+ * is caller-supplied so one component serves both entry points: the first-run+ * gate (drill header, "Start drill", the one-shot footnote) and the standalone+ * preview below (no header, "Got it", no run behind it). Keeping the body in one+ * place is the point — the n-back worked example must not drift between them.+ */+function CognitiveDrillTutorial({ drill, header = null, onAction, actionLabel = 'Start drill', ActionIcon = Play, footNote = null }) {const tut = getDrillTutorial(drill);return (<div className="max-w-lg mx-auto space-y-6">- <DrillHeader type={drill.type} isTraining={isTraining} drillIndex={drillIndex} drillCount={drillCount} />+ {header}<div className="rounded-xl border border-rose-500/30 bg-rose-500/5 p-5 space-y-4"><div className="flex items-center gap-2 text-rose-300">@@ -285,18 +292,50 @@ function CognitiveDrillTutorial({ drill, isTraining, drillIndex, drillCount, onS<buttontype="button"- onClick={onStart}+ onClick={onAction}autoFocusclassName="w-full px-6 py-4 bg-rose-500/20 hover:bg-rose-500/30 text-rose-200 border border-rose-500/40 font-semibold rounded-lg transition-colors flex items-center justify-center gap-2">- <Play size={18} /> Start drill+ <ActionIcon size={18} /> {actionLabel}</button>- <p className="text-center text-xs text-gray-600">You’ll only see this the first time for each drill type.</p>+ {footNote && <p className="text-center text-xs text-gray-600">{footNote}</p>}</div>);}+/**+ * Standalone how-to card for a drill type, with no runner behind it — the way+ * back to a tutorial once its one-shot first-run gate has been spent (issue+ * #4732). Rendered from the POST launcher and the drill config so a rule you+ * last read weeks ago is re-readable without starting a scored run.+ *+ * Deliberately NOT reachable from inside a live drill: every cognitive runner+ * stamps `startedAtRef` at mount, so re-showing the tutorial mid-run would+ * either drop the run or bill the reading time to its `totalMs`. The preview+ * takes a plain `{ type, config }` and mounts no runner at all.+ *+ * `drill` may be null (nothing selected) or a type with no tutorial — both+ * render nothing, so callers can pass state straight through.+ */+export function CognitiveDrillTutorialPreview({ drill, onClose }) {+ if (!drill || !getDrillTutorial(drill)) return null;+ const label = DRILL_LABELS[drill.type] || drill.type;+ return (+ <Modal open onClose={onClose} size="lg" ariaLabel={`How ${label} works`}>+ <div className="bg-port-card border border-port-border rounded-xl p-5 max-h-[85vh] overflow-y-auto">+ <CognitiveDrillTutorial+ drill={drill}+ onAction={onClose}+ actionLabel="Got it"+ ActionIcon={Check}+ footNote="Preview only — nothing is timed or scored here."+ />+ </div>+ </Modal>+ );+}+// Worked example for the n-back tutorial: the letters as they'd arrive, with// the one match highlighted and called out. Text alone ("matches the one N back")// is the part first-timers misread, so the card shows it rather than asserting it.diff --git a/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx b/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsxindex eac1afd8a8..7ca0016c41 100644--- a/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx+++ b/client/src/components/meatspace/post/PostCognitiveDrillRunner.test.jsx@@ -19,6 +19,7 @@ import PostCognitiveDrillRunner, {hasSeenDrillTutorial,markDrillTutorialSeen,buildNBackExample,+ CognitiveDrillTutorialPreview,} from './PostCognitiveDrillRunner';// Result-assembly tests for PostCognitiveDrillRunner's `finish()` builders.@@ -667,6 +668,59 @@ describe('first-run tutorial gate', () => {});});+// Standalone how-to preview (issue #4732) — the way back to a tutorial card the+// one-shot first-run gate has already been spent on. The load-bearing property+// is that it renders the SAME body with NO runner behind it, so nothing is+// timed or scored while the user reads.+describe('CognitiveDrillTutorialPreview', () => {+ beforeEach(() => window.localStorage.clear());+ afterEach(() => window.localStorage.clear());++ it('renders the how-to card, including the n-back worked example, with no runner mounted', () => {+ render(<CognitiveDrillTutorialPreview drill={{ type: 'n-back', config: { n: 3 } }} onClose={vi.fn()} />);+ expect(screen.getByText(/catch when one repeats from 3 steps earlier/i)).toBeInTheDocument();+ // The worked example strip — the whole reason the card needs to stay reachable.+ const example = screen.getByRole('list', { name: /example letter stream/i });+ expect(within(example).getByText('Match!')).toBeInTheDocument();+ expect(within(example).getByText('3 steps back')).toBeInTheDocument();+ // No runner: the n-back stimulus button and the gate's Start button are both absent.+ expect(screen.queryByRole('button', { name: /^match$/i })).not.toBeInTheDocument();+ expect(screen.queryByRole('button', { name: /start drill/i })).not.toBeInTheDocument();+ });++ it('does not consume the first-run gate for the type it previewed', () => {+ render(<CognitiveDrillTutorialPreview drill={{ type: 'stroop', config: {} }} onClose={vi.fn()} />);+ expect(screen.getByRole('button', { name: /got it/i })).toBeInTheDocument();+ expect(hasSeenDrillTutorial('stroop')).toBe(false);+ });++ it('closes on "Got it"', () => {+ const onClose = vi.fn();+ render(<CognitiveDrillTutorialPreview drill={{ type: 'flanker', config: {} }} onClose={onClose} />);+ fireEvent.click(screen.getByRole('button', { name: /got it/i }));+ expect(onClose).toHaveBeenCalledTimes(1);+ });++ it('renders nothing for no selection or a type with no tutorial', () => {+ const { container, rerender } = render(<CognitiveDrillTutorialPreview drill={null} onClose={vi.fn()} />);+ expect(container).toBeEmptyDOMElement();+ rerender(<CognitiveDrillTutorialPreview drill={{ type: 'not-a-drill' }} onClose={vi.fn()} />);+ expect(container).toBeEmptyDOMElement();+ });++ it('reflects the drill config it is handed, so a re-read matches the configured difficulty', () => {+ const { rerender } = render(+ <CognitiveDrillTutorialPreview drill={{ type: 'digit-span', config: { direction: 'backward' } }} onClose={vi.fn()} />,+ );+ expect(screen.getByText(/then type them in reverse/i)).toBeInTheDocument();+ rerender(+ <CognitiveDrillTutorialPreview drill={{ type: 'digit-span', config: { direction: 'forward' } }} onClose={vi.fn()} />,+ );+ expect(screen.queryByText(/then type them in reverse/i)).not.toBeInTheDocument();+ expect(screen.getByText(/then type them back in order/i)).toBeInTheDocument();+ });+});+describe('executive-control runners', () => {beforeEach(() => {vi.useFakeTimers();diff --git a/client/src/components/meatspace/post/PostDrillConfig.jsx b/client/src/components/meatspace/post/PostDrillConfig.jsxindex 0c78d8d48e..bae6d9eb4c 100644--- a/client/src/components/meatspace/post/PostDrillConfig.jsx+++ b/client/src/components/meatspace/post/PostDrillConfig.jsx@@ -1,10 +1,11 @@import { useState, useEffect } from 'react';-import { ArrowLeft, Save, Brain, Bell, Target, Layers, TrendingUp, TrendingDown, Minus } from 'lucide-react';+import { ArrowLeft, Save, Brain, Bell, Target, Layers, TrendingUp, TrendingDown, Minus, BookOpen } from 'lucide-react';import { updatePostConfig, getProviders, getPostAdaptivePreview, getPostMultiplicationProgress, getPostPowersProgress, getPostCognitiveProgress, getMemoryItems } from '../../../services/api';import toast from '../../ui/Toast';import { FormField } from '../../ui/FormField';import { filterSelectableModels, enabledApiProviderFilter } from '../../../utils/providers';import { GOAL_DEFS, POST_TOPICS, MODULE_LABELS, DRILL_LABELS, DRILL_DESCRIPTIONS, composedSessionDrillTypes } from './constants';+import { CognitiveDrillTutorialPreview } from './PostCognitiveDrillRunner';// Modules a Full/Quick composed session can draw from (issue #2100), DERIVED// from the shared topic registry so the list has one owner (issue #3252): a@@ -463,7 +464,7 @@ function GroupBulkToggle({ groupLabel, onEnableAll, onDisableAll }) {);}-function DrillCard({ type, meta, drillConfig, enabled, accent, onToggle, onUpdateField, adaptiveInfo, progressive, onToggleProgressive, progressInfo, managedFieldKeys = [], speedGated = false, managedLabel = 'Manual knobs' }) {+function DrillCard({ type, meta, drillConfig, enabled, accent, onToggle, onUpdateField, adaptiveInfo, progressive, onToggleProgressive, progressInfo, managedFieldKeys = [], speedGated = false, managedLabel = 'Manual knobs', onPreviewHowItWorks }) {// Label and description both come from the shared registries in constants.js —// the per-module META objects carry only the knobs, so a drill rename is one edit.const label = DRILL_LABELS[type];@@ -483,6 +484,18 @@ function DrillCard({ type, meta, drillConfig, enabled, accent, onToggle, onUpdat<div><h3 className="text-white font-medium">{label}</h3><p className="text-gray-500 text-xs">{DRILL_DESCRIPTIONS[type]}</p>+ {/* Outside the `enabled &&` blocks on purpose: previewing the rules is+ how you decide whether to switch a drill ON (issue #4732). */}+ {onPreviewHowItWorks && (+ <button+ type="button"+ onClick={onPreviewHowItWorks}+ aria-label={`How ${label} works`}+ className="mt-1 inline-flex items-center gap-1 text-xs text-gray-500 hover:text-port-accent transition-colors"+ >+ <BookOpen size={12} /> How it works+ </button>+ )}</div><buttontype="button"@@ -587,6 +600,10 @@ export default function PostDrillConfig({ config, onSaved, onBack }) {const [multiplicationProgress, setMultiplicationProgress] = useState(null);const [powersProgress, setPowersProgress] = useState(null);const [cognitiveProgress, setCognitiveProgress] = useState(null);+ // Drill type whose how-to card is open in the preview modal (issue #4732), or+ // null. Held as the type alone — the drill payload is rebuilt from the CURRENT+ // draft config on render, so editing `n` and reopening shows the new lag.+ const [howItWorksType, setHowItWorksType] = useState(null);// Opt-in daily reminder — off by default; see server/services/meatspacePostReminder.js.const [reminderEnabled, setReminderEnabled] = useState(() => config?.reminder?.enabled === true@@ -1102,12 +1119,18 @@ export default function PostDrillConfig({ config, onSaved, onBack }) {managedFieldKeys={supportsProgressive ? (meta.ladderFields || []) : []}speedGated={false}managedLabel="The difficulty knobs"+ onPreviewHowItWorks={() => setHowItWorksType(type)}/>);})}</div>)}+ <CognitiveDrillTutorialPreview+ drill={howItWorksType ? { type: howItWorksType, config: cognitiveDrillTypes[howItWorksType] || {} } : null}+ onClose={() => setHowItWorksType(null)}+ />+{/* LLM Drills Section */}<div className="flex items-center justify-between pt-2"><div className="flex items-center gap-3">diff --git a/client/src/components/meatspace/post/PostDrillConfig.test.jsx b/client/src/components/meatspace/post/PostDrillConfig.test.jsxindex 645b14cbe9..fa09baed96 100644--- a/client/src/components/meatspace/post/PostDrillConfig.test.jsx+++ b/client/src/components/meatspace/post/PostDrillConfig.test.jsx@@ -14,7 +14,7 @@ vi.mock('../../ui/Toast', () => ({ default: { success: vi.fn(), error: vi.fn() }import PostDrillConfig from './PostDrillConfig';import { updatePostConfig, getProviders, getPostAdaptivePreview, getPostMultiplicationProgress, getPostPowersProgress, getPostCognitiveProgress, getMemoryItems } from '../../../services/api';-import { LLM_DRILL_TYPES, DRILL_LABELS } from './constants';+import { LLM_DRILL_TYPES, DRILL_LABELS, COGNITIVE_DRILL_TYPES } from './constants';// The generatable LLM drill types + labels, imported from the canonical// client constant (mirrors server LLM_DRILL_TYPES in meatspacePostLlm.js) —@@ -376,6 +376,37 @@ describe('PostDrillConfig', () => {expect(cognitive['mental-rotation']).toMatchObject({ progressive: false, rotationComplexity: 3, optionCount: 4 });});+ // Issue #4732 — the first-run how-to card is one-shot per drill type, so the+ // config grid is the durable way back to it (and the only surface that offers+ // one for a drill that is currently switched OFF).+ describe('cognitive "How it works" preview', () => {+ it('offers the preview for every cognitive drill type, enabled or not', async () => {+ const noCognitive = { ...config, cognitive: { enabled: true, drillTypes: { 'n-back': { enabled: false } } } };+ await renderConfig(<PostDrillConfig config={noCognitive} onSaved={vi.fn()} onBack={vi.fn()} />);+ expect(screen.getByRole('switch', { name: 'N-Back' }).getAttribute('aria-checked')).toBe('false');+ // Type list from the canonical constant, not a hardcoded copy — a new+ // cognitive drill must not be able to ship without a way to read its rules.+ for (const type of COGNITIVE_DRILL_TYPES) {+ expect(screen.getByRole('button', { name: `How ${DRILL_LABELS[type]} works` })).toBeTruthy();+ }+ });++ it('opens the how-to card with the drill\'s CURRENT draft config, and closes again', async () => {+ await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);+ // Take n-back off progressive so the manual lag knob is editable, then change it.+ fireEvent.click(screen.getByRole('switch', { name: 'Progressive difficulty — N-Back' }));+ fireEvent.change(screen.getByLabelText('N (steps back)'), { target: { value: '4' } });++ fireEvent.click(screen.getByRole('button', { name: 'How N-Back works' }));+ expect(screen.getByText(/catch when one repeats from 4 steps earlier/i)).toBeTruthy();+ // Preview only: the card is open but no drill runner exists behind it.+ expect(screen.queryByRole('button', { name: /start drill/i })).toBeNull();++ fireEvent.click(screen.getByRole('button', { name: /got it/i }));+ expect(screen.queryByText(/catch when one repeats from 4 steps earlier/i)).toBeNull();+ });+ });+it('toggling Adaptive on persists enabled=true', async () => {await renderConfig(<PostDrillConfig config={config} onSaved={vi.fn()} onBack={vi.fn()} />);fireEvent.click(screen.getByRole('switch', { name: 'Adaptive difficulty' }));diff --git a/client/src/components/meatspace/post/PostSessionLauncher.jsx b/client/src/components/meatspace/post/PostSessionLauncher.jsxindex 3c87762b17..86b88fcc34 100644--- a/client/src/components/meatspace/post/PostSessionLauncher.jsx+++ b/client/src/components/meatspace/post/PostSessionLauncher.jsx@@ -1,6 +1,6 @@import { useState, useEffect, useRef } from 'react';import { Link } from 'react-router';-import { Zap, Play, Brain, Dumbbell, Timer, Target, TrendingUp, TrendingDown, Minus, Compass, ArrowRight, ChevronRight, Layers } from 'lucide-react';+import { Zap, Play, Brain, Dumbbell, Timer, Target, TrendingUp, TrendingDown, Minus, Compass, ArrowRight, ChevronRight, Layers, BookOpen } from 'lucide-react';import { getPostReviewReps, getPostRecommendations, getMorseProgress, getPostProgress, getPostBenchmarkProtocol, getMemoryItems, updatePostConfig } from '../../../services/api';import { FormField } from '../../ui/FormField';import Pill from '../../ui/Pill';@@ -10,6 +10,7 @@ import { DOMAINS, DRILL_TO_DOMAIN, DRILL_LABELS, computeDomainAverages, computeGimport { otherPostSections, TOPIC_SURFACE_SECTIONS } from './practiceCatalog';import { postIcon } from './postIcons';import BrowseCatalogLink from './BrowseCatalogLink';+import { CognitiveDrillTutorialPreview } from './PostCognitiveDrillRunner';import { streakGlyph } from '../../../lib/streakGlyph.js';import useUserTimezone from '../../../hooks/useUserTimezone.js';import { todayKeyInTimezone } from '../../../utils/timezone.js';@@ -154,6 +155,9 @@ export default function PostSessionLauncher({const [quickDurationSaveState, setQuickDurationSaveState] = useState('idle');const [benchmarkState, setBenchmarkState] = useState('idle');const [benchmarkError, setBenchmarkError] = useState(null);+ // `{ type, config }` of the cognitive drill whose how-to card is open, or null+ // (issue #4732). Nothing mounts a runner, so no drill timer is affected.+ const [howItWorksDrill, setHowItWorksDrill] = useState(null);useEffect(() => {setQuickDurationMin(normalizeQuickDurationMinutes(config?.quickDurationMin));@@ -1161,9 +1165,23 @@ export default function PostSessionLauncher({</div><div className="space-y-2">{enabledCognitiveDrills.map(([type, cfg]) => (- <div key={type} className="flex items-center justify-between text-sm">- <span className="text-white">{DRILL_LABELS[type] || type}</span>- <span className="text-gray-500">+ <div key={type} className="flex items-center justify-between gap-2 text-sm">+ <span className="flex items-center gap-1.5 min-w-0">+ <span className="text-white truncate">{DRILL_LABELS[type] || type}</span>+ {/* Re-entry to the how-to card the first-run gate showed once+ and never again (issue #4732). Opens a preview with no+ runner behind it, so no timer starts and nothing is scored. */}+ <button+ type="button"+ onClick={() => setHowItWorksDrill({ type, config: cfg })}+ aria-label={`How ${DRILL_LABELS[type] || type} works`}+ title="How it works"+ className="shrink-0 text-gray-600 hover:text-rose-300 transition-colors"+ >+ <BookOpen size={13} />+ </button>+ </span>+ <span className="text-gray-500 text-right">{cognitiveSummary(type, cfg)}</span></div>@@ -1210,6 +1228,8 @@ export default function PostSessionLauncher({)}</div></div>++ <CognitiveDrillTutorialPreview drill={howItWorksDrill} onClose={() => setHowItWorksDrill(null)} /></div>);}diff --git a/client/src/components/meatspace/post/PostSessionLauncher.test.jsx b/client/src/components/meatspace/post/PostSessionLauncher.test.jsxindex 4cfa8f97a0..8662b763e5 100644--- a/client/src/components/meatspace/post/PostSessionLauncher.test.jsx+++ b/client/src/components/meatspace/post/PostSessionLauncher.test.jsx@@ -422,6 +422,30 @@ describe('PostSessionLauncher render (issue #2100)', () => {});expect(await screen.findByText('system default')).toBeInTheDocument();});++ // Issue #4732 — the drill's first-run how-to card is one-shot per type, so the+ // sidebar row is the way back to it from the screen you launch a session from.+ it('re-opens a cognitive drill\'s how-to card from the sidebar without starting a run', async () => {+ const onStart = vi.fn();+ renderLauncher({+ onStart,+ config: {+ ...baseConfig,+ cognitive: { enabled: true, drillTypes: { 'n-back': { enabled: true, n: 3 } } },+ },+ });+ await waitFor(() => expect(getPostRecommendations).toHaveBeenCalled());++ fireEvent.click(screen.getByRole('button', { name: 'How N-Back works' }));+ // The card reads against the CONFIGURED lag, not a hardcoded default.+ expect(screen.getByText(/catch when one repeats from 3 steps earlier/i)).toBeTruthy();+ expect(screen.getByRole('list', { name: /example letter stream/i })).toBeTruthy();+ // Reading the rules must never start (or count toward) a scored session.+ expect(onStart).not.toHaveBeenCalled();++ fireEvent.click(screen.getByRole('button', { name: /got it/i }));+ expect(screen.queryByText(/catch when one repeats from 3 steps earlier/i)).toBeNull();+ });});// The launcher is the entry point to a DAILY habit, so the actions that start a