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

fix: teach the ladder rung in the how-to preview, and share one trigger button

[._.]/ Adam Eivy2ded3c5e6e38
diff --git a/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx b/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx
index 766e4048e8..11adcfd39d 100644
--- a/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx
+++ b/client/src/components/meatspace/post/PostCognitiveDrillRunner.jsx
@@ -119,6 +119,15 @@ export function buildNBackExample(n) {
return { sequence, n: lag };
}
+/**
+ * Whether a drill type has a how-to card at all. The one predicate that owns
+ * this rule: a "How it works" affordance must not render for a type
+ * `getDrillTutorial` has no case for, or it opens nothing.
+ */
+export function hasDrillTutorial(type) {
+ return getDrillTutorial({ type }) != null;
+}
+
// Per-type how-to content. A pure function of the drill so config-dependent
// copy (n-back lag, digit-span direction, reaction-time mode) reads correctly.
// Returns null for types with no tutorial (which skip the gate entirely).
@@ -237,14 +246,17 @@ export function getDrillTutorial(drill) {
// Holds the runner until the first-run tutorial (if any) is dismissed.
function DrillTutorialGate({ drill, isTraining, drillIndex, drillCount, children }) {
const [showTutorial, setShowTutorial] = useState(
- () => getDrillTutorial(drill) != null && !hasSeenDrillTutorial(drill.type),
+ () => hasDrillTutorial(drill.type) && !hasSeenDrillTutorial(drill.type),
);
if (!showTutorial) return children;
return (
<CognitiveDrillTutorial
drill={drill}
+ tut={getDrillTutorial(drill)}
header={<DrillHeader type={drill.type} isTraining={isTraining} drillIndex={drillIndex} drillCount={drillCount} />}
onAction={() => { markDrillTutorialSeen(drill.type); setShowTutorial(false); }}
+ actionLabel="Start drill"
+ ActionIcon={Play}
footNote="You’ll only see this the first time for each drill type. Reopen it any time from the launcher or Config."
/>
);
@@ -257,8 +269,7 @@ function DrillTutorialGate({ drill, isTraining, drillIndex, drillCount, children
* 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);
+function CognitiveDrillTutorial({ drill, tut, header = null, onAction, actionLabel, ActionIcon, footNote = null }) {
return (
<div className="max-w-lg mx-auto space-y-6">
{header}
@@ -319,13 +330,21 @@ function CognitiveDrillTutorial({ drill, header = null, onAction, actionLabel =
* render nothing, so callers can pass state straight through.
*/
export function CognitiveDrillTutorialPreview({ drill, onClose }) {
- if (!drill || !getDrillTutorial(drill)) return null;
+ const tut = drill ? getDrillTutorial(drill) : null;
+ if (!tut) return null;
const label = DRILL_LABELS[drill.type] || drill.type;
return (
- <Modal open onClose={onClose} size="lg" ariaLabel={`How ${label} works`}>
+ // `usePortal` per the overlay convention in client/src/CLAUDE.md: this is
+ // rendered mid-tree inside two long settings/launcher pages, and a
+ // `backdrop-filter` ancestor (every bordered `.bg-port-card` on the glass
+ // themes) would otherwise become the fixed overlay's containing block.
+ // Sized `md` to match the card body's own `max-w-lg`, so there is no dead
+ // gutter inside the panel.
+ <Modal open onClose={onClose} size="md" usePortal 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}
+ tut={tut}
onAction={onClose}
actionLabel="Got it"
ActionIcon={Check}
@@ -336,6 +355,35 @@ export function CognitiveDrillTutorialPreview({ drill, onClose }) {
);
}
+/**
+ * The affordance that opens the preview. Shared by the POST launcher sidebar and
+ * the Drill Config cards so the accessible name (`How <label> works`, which both
+ * suites assert) and the mobile hit area live in ONE place rather than drifting
+ * per surface. Renders nothing for a type with no how-to card, so the button can
+ * never open an empty modal.
+ *
+ * `compact` is the launcher's dense sidebar row: icon only, with the 44px touch
+ * target collapsing to a tight icon on `sm+`.
+ */
+export function CognitiveDrillHowItWorksButton({ type, onClick, compact = false }) {
+ if (!hasDrillTutorial(type)) return null;
+ const label = DRILL_LABELS[type] || type;
+ return (
+ <button
+ type="button"
+ onClick={onClick}
+ aria-label={`How ${label} works`}
+ title="How it works"
+ className={compact
+ ? 'shrink-0 inline-flex items-center justify-center min-w-[44px] min-h-[44px] sm:min-w-0 sm:min-h-0 sm:p-1 -m-1 sm:m-0 rounded-lg text-gray-500 hover:text-rose-300 transition-colors focus:outline-hidden focus:ring-2 focus:ring-port-accent'
+ : 'mt-1 inline-flex items-center justify-center gap-1 min-h-[44px] sm:min-h-0 sm:py-0.5 text-xs text-gray-500 hover:text-port-accent transition-colors rounded focus:outline-hidden focus:ring-2 focus:ring-port-accent'}
+ >
+ <BookOpen size={compact ? 14 : 12} />
+ {!compact && 'How it works'}
+ </button>
+ );
+}
+
// 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/PostDrillConfig.jsx b/client/src/components/meatspace/post/PostDrillConfig.jsx
index bae6d9eb4c..64d4ab226c 100644
--- a/client/src/components/meatspace/post/PostDrillConfig.jsx
+++ b/client/src/components/meatspace/post/PostDrillConfig.jsx
@@ -1,11 +1,11 @@
import { useState, useEffect } from 'react';
-import { ArrowLeft, Save, Brain, Bell, Target, Layers, TrendingUp, TrendingDown, Minus, BookOpen } from 'lucide-react';
+import { ArrowLeft, Save, Brain, Bell, Target, Layers, TrendingUp, TrendingDown, Minus } 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';
+import { GOAL_DEFS, POST_TOPICS, MODULE_LABELS, DRILL_LABELS, DRILL_DESCRIPTIONS, composedSessionDrillTypes, effectiveCognitiveDrillConfig } from './constants';
+import { CognitiveDrillTutorialPreview, CognitiveDrillHowItWorksButton } 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
@@ -486,16 +486,7 @@ function DrillCard({ type, meta, drillConfig, enabled, accent, onToggle, onUpdat
<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>
- )}
+ {onPreviewHowItWorks && <CognitiveDrillHowItWorksButton type={type} onClick={onPreviewHowItWorks} />}
</div>
<button
type="button"
@@ -701,7 +692,7 @@ export default function PostDrillConfig({ config, onSaved, onBack }) {
useEffect(() => {
if (!anyCognitiveProgressive) { setCognitiveProgress(null); return; }
let cancelled = false;
- getPostCognitiveProgress()
+ getPostCognitiveProgress({ silent: true })
.then(p => { if (!cancelled) setCognitiveProgress(p); })
.catch(err => console.warn('⚠️ Failed to load cognitive progress: ' + err.message));
return () => { cancelled = true; };
@@ -1126,8 +1117,17 @@ export default function PostDrillConfig({ config, onSaved, onBack }) {
</div>
)}
+ {/* The card must teach the rules of the drill that will ACTUALLY run: while
+ a laddered drill is progressive (the default), the server overrides the
+ manual knobs with the rung's config, so a stored `n: 2` would otherwise
+ describe a 3-back run — and digit-span would say "in order" for a rung
+ that is backward recall. Built at render, not at click, so editing a
+ knob and reopening shows the new value. */}
<CognitiveDrillTutorialPreview
- drill={howItWorksType ? { type: howItWorksType, config: cognitiveDrillTypes[howItWorksType] || {} } : null}
+ drill={howItWorksType ? {
+ type: howItWorksType,
+ config: effectiveCognitiveDrillConfig(cognitiveDrillTypes[howItWorksType], cognitiveProgress?.[howItWorksType]),
+ } : null}
onClose={() => setHowItWorksType(null)}
/>
diff --git a/client/src/components/meatspace/post/PostDrillConfig.test.jsx b/client/src/components/meatspace/post/PostDrillConfig.test.jsx
index fa09baed96..8afb200995 100644
--- a/client/src/components/meatspace/post/PostDrillConfig.test.jsx
+++ b/client/src/components/meatspace/post/PostDrillConfig.test.jsx
@@ -391,9 +391,26 @@ describe('PostDrillConfig', () => {
}
});
- it('opens the how-to card with the drill\'s CURRENT draft config, and closes again', async () => {
+ // The DEFAULT configuration: progressive is on, so the server runs the
+ // ladder rung's config and IGNORES the stored knobs. The card has to teach
+ // the rung, or it explains a different drill than the one about to run.
+ it('teaches the progressive ladder rung, not the stored knobs', async () => {
+ getPostCognitiveProgress.mockResolvedValue({
+ 'n-back': { type: 'n-back', level: 2, label: '3-back @ 2500ms', levels: [], config: { n: 3, stimulusMs: 2500 } },
+ });
+ // Stored `n` is 1; the rung says 3. The card must say 3.
+ const laggedConfig = { ...config, cognitive: { enabled: true, drillTypes: { 'n-back': { enabled: true, n: 1 } } } };
+ await renderConfig(<PostDrillConfig config={laggedConfig} onSaved={vi.fn()} onBack={vi.fn()} />);
+ await waitFor(() => expect(getPostCognitiveProgress).toHaveBeenCalled());
+
+ fireEvent.click(screen.getByRole('button', { name: 'How N-Back works' }));
+ expect(screen.getByText(/catch when one repeats from 3 steps earlier/i)).toBeTruthy();
+ expect(screen.queryByText(/repeats from 1 step earlier/i)).toBeNull();
+ });
+
+ it('opens the how-to card with the drill\'s CURRENT draft config once progressive is off, 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.
+ // Progressive off → the ladder no longer applies and the manual lag knob wins.
fireEvent.click(screen.getByRole('switch', { name: 'Progressive difficulty — N-Back' }));
fireEvent.change(screen.getByLabelText('N (steps back)'), { target: { value: '4' } });
diff --git a/client/src/components/meatspace/post/PostSessionLauncher.jsx b/client/src/components/meatspace/post/PostSessionLauncher.jsx
index 86b88fcc34..45069bfa7d 100644
--- a/client/src/components/meatspace/post/PostSessionLauncher.jsx
+++ b/client/src/components/meatspace/post/PostSessionLauncher.jsx
@@ -1,16 +1,16 @@
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, BookOpen } from 'lucide-react';
-import { getPostReviewReps, getPostRecommendations, getMorseProgress, getPostProgress, getPostBenchmarkProtocol, getMemoryItems, updatePostConfig } from '../../../services/api';
+import { Zap, Play, Brain, Dumbbell, Timer, Target, TrendingUp, TrendingDown, Minus, Compass, ArrowRight, ChevronRight, Layers } from 'lucide-react';
+import { getPostReviewReps, getPostRecommendations, getMorseProgress, getPostProgress, getPostBenchmarkProtocol, getMemoryItems, updatePostConfig, getPostCognitiveProgress } from '../../../services/api';
import { FormField } from '../../ui/FormField';
import Pill from '../../ui/Pill';
import { enabledApiProviderFilter } from '../../../utils/providers';
import useProviderModels from '../../../hooks/useProviderModels.js';
-import { DOMAINS, DRILL_TO_DOMAIN, DRILL_LABELS, computeDomainAverages, computeGoalProgress, isTopicEnabled, selectMemoryItemForDrill, resolveTopicForDrillType } from './constants';
+import { DOMAINS, DRILL_TO_DOMAIN, DRILL_LABELS, effectiveCognitiveDrillConfig, computeDomainAverages, computeGoalProgress, isTopicEnabled, selectMemoryItemForDrill, resolveTopicForDrillType } from './constants';
import { otherPostSections, TOPIC_SURFACE_SECTIONS } from './practiceCatalog';
import { postIcon } from './postIcons';
import BrowseCatalogLink from './BrowseCatalogLink';
-import { CognitiveDrillTutorialPreview } from './PostCognitiveDrillRunner';
+import { CognitiveDrillTutorialPreview, CognitiveDrillHowItWorksButton } from './PostCognitiveDrillRunner';
import { streakGlyph } from '../../../lib/streakGlyph.js';
import useUserTimezone from '../../../hooks/useUserTimezone.js';
import { todayKeyInTimezone } from '../../../utils/timezone.js';
@@ -155,9 +155,12 @@ 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);
+ // Drill TYPE whose how-to card is open, or null (issue #4732) — same shape as
+ // PostDrillConfig, with the payload derived at render so the card can never
+ // show a config snapshot that has since moved. Nothing mounts a runner, so no
+ // drill timer is affected.
+ const [howItWorksType, setHowItWorksType] = useState(null);
+ const [cognitiveProgress, setCognitiveProgress] = useState(null);
useEffect(() => {
setQuickDurationMin(normalizeQuickDurationMinutes(config?.quickDurationMin));
@@ -221,6 +224,24 @@ export default function PostSessionLauncher({
return () => { cancelled = true; };
}, [config?.goals?.morseWpmTarget]);
+ // Cognitive ladder rungs. Needed only so the "How it works" card describes the
+ // drill that will ACTUALLY run: while a laddered drill is progressive (the
+ // shipped default) the server overrides the stored knobs with the rung's
+ // config, so the card would otherwise teach the wrong lag / recall direction.
+ // Conditional-fetch like the goal-scoped effects above — nothing is requested
+ // on an install with no progressive cognitive drill enabled.
+ const needsCognitiveProgress = config?.cognitive?.enabled !== false
+ && Object.values(config?.cognitive?.drillTypes || {})
+ .some(cfg => cfg?.enabled !== false && cfg?.progressive !== false);
+ useEffect(() => {
+ if (!needsCognitiveProgress) { setCognitiveProgress(null); return; }
+ let cancelled = false;
+ getPostCognitiveProgress({ silent: true })
+ .then(p => { if (!cancelled) setCognitiveProgress(p); })
+ .catch(err => console.warn('⚠️ Failed to load cognitive progress: ' + err.message));
+ return () => { cancelled = true; };
+ }, [needsCognitiveProgress]);
+
// Today's total training minutes (incl. training-log practice) — fetched only
// when a daily-minutes goal is set, so that goal counts Training/Morse/memory
// time, not just scored sessions (issue #2100 review).
@@ -1171,15 +1192,7 @@ export default function PostSessionLauncher({
{/* 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>
+ <CognitiveDrillHowItWorksButton type={type} onClick={() => setHowItWorksType(type)} compact />
</span>
<span className="text-gray-500 text-right">
{cognitiveSummary(type, cfg)}
@@ -1229,7 +1242,13 @@ export default function PostSessionLauncher({
</div>
</div>
- <CognitiveDrillTutorialPreview drill={howItWorksDrill} onClose={() => setHowItWorksDrill(null)} />
+ <CognitiveDrillTutorialPreview
+ drill={howItWorksType ? {
+ type: howItWorksType,
+ config: effectiveCognitiveDrillConfig(config.cognitive?.drillTypes?.[howItWorksType], cognitiveProgress?.[howItWorksType]),
+ } : null}
+ onClose={() => setHowItWorksType(null)}
+ />
</div>
);
}
diff --git a/client/src/components/meatspace/post/PostSessionLauncher.test.jsx b/client/src/components/meatspace/post/PostSessionLauncher.test.jsx
index 8662b763e5..e383260db7 100644
--- a/client/src/components/meatspace/post/PostSessionLauncher.test.jsx
+++ b/client/src/components/meatspace/post/PostSessionLauncher.test.jsx
@@ -20,6 +20,7 @@ vi.mock('../../../services/api', () => ({
getMorseProgress: vi.fn().mockResolvedValue({ settings: { wpm: 18, farnsworthWpm: 12 } }),
getPostProgress: vi.fn().mockResolvedValue({ series: { byDay: [] } }),
getMemoryItems: vi.fn().mockResolvedValue([{ id: 'example-memory' }]),
+ getPostCognitiveProgress: vi.fn().mockResolvedValue({}),
getPostBenchmarkProtocol: vi.fn().mockResolvedValue({
protocolId: 'post-foundation-battery',
protocolVersion: 1,
@@ -37,7 +38,7 @@ vi.mock('../../../services/api', () => ({
import PostSessionLauncher, { buildCleanConditions, cognitiveSummary, interleaveByDomain } from './PostSessionLauncher';
import { otherPostSections, TOPIC_SURFACE_SECTIONS } from './practiceCatalog';
-import { getPostRecommendations, getMorseProgress, getPostProgress, getPostReviewReps, getPostBenchmarkProtocol, getMemoryItems, updatePostConfig } from '../../../services/api';
+import { getPostRecommendations, getMorseProgress, getPostProgress, getPostReviewReps, getPostBenchmarkProtocol, getMemoryItems, updatePostConfig, getPostCognitiveProgress } from '../../../services/api';
// Pure-function tests for PostSessionLauncher's pre-submit helpers (issue
// #2102 gap #10; structured conditions issue #4442). Both were lifted from
@@ -172,6 +173,7 @@ describe('PostSessionLauncher render (issue #2100)', () => {
getPostReviewReps.mockResolvedValue({ reps: [] });
getMorseProgress.mockResolvedValue({ settings: { wpm: 18, farnsworthWpm: 12 } });
getPostProgress.mockResolvedValue({ series: { byDay: [] } });
+ getPostCognitiveProgress.mockResolvedValue({});
getPostBenchmarkProtocol.mockResolvedValue({
protocolId: 'post-foundation-battery',
protocolVersion: 1,
@@ -431,7 +433,8 @@ describe('PostSessionLauncher render (issue #2100)', () => {
onStart,
config: {
...baseConfig,
- cognitive: { enabled: true, drillTypes: { 'n-back': { enabled: true, n: 3 } } },
+ // progressive:false → the stored knobs are what the drill runs with.
+ cognitive: { enabled: true, drillTypes: { 'n-back': { enabled: true, n: 3, progressive: false } } },
},
});
await waitFor(() => expect(getPostRecommendations).toHaveBeenCalled());
@@ -442,10 +445,36 @@ describe('PostSessionLauncher render (issue #2100)', () => {
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();
+ // Nothing to resolve → no ladder fetch on an all-manual cognitive config.
+ expect(getPostCognitiveProgress).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 DEFAULT: progressive on, so the server swaps in the ladder rung's config
+ // at generation time and the stored knobs never reach the drill. Digit-span is
+ // the sharpest case — the ladder flips recall to BACKWARD at rung 3, and a card
+ // built from the stored config would teach forward recall for a backward run.
+ it('teaches the ladder rung for a progressive drill, not the stored knobs', async () => {
+ getPostCognitiveProgress.mockResolvedValue({
+ 'digit-span': {
+ type: 'digit-span', level: 3, label: 'backward 4–6', levels: [],
+ config: { direction: 'backward', startLength: 4, maxLength: 6 },
+ },
+ });
+ renderLauncher({
+ config: {
+ ...baseConfig,
+ cognitive: { enabled: true, drillTypes: { 'digit-span': { enabled: true, direction: 'forward' } } },
+ },
+ });
+ await waitFor(() => expect(getPostCognitiveProgress).toHaveBeenCalled());
+
+ fireEvent.click(screen.getByRole('button', { name: 'How Digit Span works' }));
+ expect(screen.getByText(/then type them in reverse/i)).toBeTruthy();
+ expect(screen.queryByText(/then type them back in order/i)).toBeNull();
+ });
});
// The launcher is the entry point to a DAILY habit, so the actions that start a
@@ -483,6 +512,7 @@ describe('PostSessionLauncher — Start card (issue #3249)', () => {
getPostReviewReps.mockResolvedValue({ reps: [] });
getMorseProgress.mockResolvedValue({ settings: { wpm: 18, farnsworthWpm: 12 } });
getPostProgress.mockResolvedValue({ series: { byDay: [] } });
+ getPostCognitiveProgress.mockResolvedValue({});
});
it('puts the session starts ahead of status, goals, Up next and the analytics block', async () => {
@@ -599,6 +629,7 @@ describe('PostSessionLauncher topic gating (issue #3252)', () => {
getPostReviewReps.mockResolvedValue({ reps: [] });
getMorseProgress.mockResolvedValue({ settings: { wpm: 18, farnsworthWpm: 12 } });
getPostProgress.mockResolvedValue({ series: { byDay: [] } });
+ getPostCognitiveProgress.mockResolvedValue({});
});
it('composes every llm-drills topic when no topics key is set (legacy config)', async () => {
@@ -676,6 +707,7 @@ describe('PostSessionLauncher review-rep topic gating (issue #3252)', () => {
] });
getMorseProgress.mockResolvedValue({ settings: { wpm: 18, farnsworthWpm: 12 } });
getPostProgress.mockResolvedValue({ series: { byDay: [] } });
+ getPostCognitiveProgress.mockResolvedValue({});
});
it('mixes a review rep into a Quick session while its topic is on', async () => {
@@ -710,6 +742,7 @@ describe('PostSessionLauncher honors the mentalMath module flag (issue #3252)',
getPostReviewReps.mockResolvedValue({ reps: [] });
getMorseProgress.mockResolvedValue({ settings: { wpm: 18, farnsworthWpm: 12 } });
getPostProgress.mockResolvedValue({ series: { byDay: [] } });
+ getPostCognitiveProgress.mockResolvedValue({});
});
it('composes no math drills when mentalMath.enabled is false', async () => {
diff --git a/client/src/components/meatspace/post/constants.js b/client/src/components/meatspace/post/constants.js
index 3b2c17e495..7772abd528 100644
--- a/client/src/components/meatspace/post/constants.js
+++ b/client/src/components/meatspace/post/constants.js
@@ -9,6 +9,27 @@ export const MEMORY_DRILL_TYPES = ['memory-fill-blank', 'memory-sequence', 'memo
// COGNITIVE_DRILL_TYPES in server/services/meatspacePostCognitive.js.
export const COGNITIVE_DRILL_TYPES = ['n-back', 'digit-span', 'stroop', 'schulte-table', 'mental-rotation', 'reaction-time', 'task-switching', 'go-no-go', 'flanker'];
+/**
+ * The config a cognitive drill will ACTUALLY run with — not necessarily the one
+ * stored in POST config. Mirrors the server's override in `resolveDrillConfig`
+ * (server/services/meatspacePost.js): while a laddered drill is progressive
+ * (the shipped default), the rung's config wins over the manual knobs.
+ *
+ * This matters for anything that DESCRIBES a drill to the user rather than just
+ * labelling it: a default n-back at rung 4 runs 3-back while the stored `n` is
+ * still 2, and digit-span flips to backward recall at rung 3 — so a how-to card
+ * built from the stored config would teach the wrong rule.
+ *
+ * `progressInfo` is one type's entry from `getPostCognitiveProgress()`; pass
+ * null/undefined when it hasn't loaded (or the type has no ladder) and the
+ * stored config is returned unchanged.
+ */
+export function effectiveCognitiveDrillConfig(drillConfig, progressInfo) {
+ const stored = drillConfig || {};
+ if (stored.progressive === false) return stored;
+ return progressInfo?.config ? { ...stored, ...progressInfo.config } : stored;
+}
+
// Drill types valid elsewhere but not yet wired into the interactive POST
// session drill picker. Multi-blank fill-in-the-blank is now wired end to end,
// so this remains empty until a future generation-only type needs the guard.
diff --git a/client/src/components/meatspace/post/constants.test.js b/client/src/components/meatspace/post/constants.test.js
index fbb559f5c9..82cf7f3ca4 100644
--- a/client/src/components/meatspace/post/constants.test.js
+++ b/client/src/components/meatspace/post/constants.test.js
@@ -3,6 +3,7 @@ import {
computeDomainAverages, domainLabel, computeGoalProgress, hasGoals,
POST_TOPICS, DOMAINS, DRILL_TO_DOMAIN, composedSessionDrillTypes,
isTopicEnabled, isMemoryItemEnabled, resolveTopicForDrillType, appliedNumeracyAnswerCorrect,
+ effectiveCognitiveDrillConfig,
} from './constants';
describe('domainLabel', () => {
@@ -261,4 +262,38 @@ describe('resolveTopicForDrillType client mirror', () => {
expect(resolveTopicForDrillType('nope')).toBeNull();
});
});
+
+
+// Mirrors the server's progressive override in `resolveDrillConfig`
+// (server/services/meatspacePost.js). Anything that DESCRIBES a cognitive drill
+// to the user has to resolve through this, or it explains the stored knobs while
+// a different rung actually runs.
+describe('effectiveCognitiveDrillConfig', () => {
+ it('lets the ladder rung win over the stored knobs while progressive (the default)', () => {
+ expect(effectiveCognitiveDrillConfig({ n: 1, length: 20 }, { config: { n: 3, stimulusMs: 2000 } }))
+ .toEqual({ n: 3, length: 20, stimulusMs: 2000 });
+ });
+
+ it('keeps the stored knobs when progressive is explicitly off', () => {
+ expect(effectiveCognitiveDrillConfig({ n: 1, progressive: false }, { config: { n: 3 } }))
+ .toEqual({ n: 1, progressive: false });
+ });
+
+ it('flips digit-span recall direction with the rung, not the stored value', () => {
+ expect(effectiveCognitiveDrillConfig(
+ { direction: 'forward' },
+ { config: { direction: 'backward', startLength: 4, maxLength: 6 } },
+ ).direction).toBe('backward');
+ });
+
+ it('falls back to the stored config when the rung has not loaded or the type has no ladder', () => {
+ expect(effectiveCognitiveDrillConfig({ mode: 'choice' }, null)).toEqual({ mode: 'choice' });
+ expect(effectiveCognitiveDrillConfig({ mode: 'choice' }, {})).toEqual({ mode: 'choice' });
+ });
+
+ it('tolerates a missing stored config', () => {
+ expect(effectiveCognitiveDrillConfig(undefined, null)).toEqual({});
+ });
+});
+
// @vitest-environment node
diff --git a/client/src/services/apiMeatspace.js b/client/src/services/apiMeatspace.js
index 57059e1179..2d4666dae9 100644
--- a/client/src/services/apiMeatspace.js
+++ b/client/src/services/apiMeatspace.js
@@ -215,7 +215,9 @@ export const getPostRecommendations = (limit, options = {}) => request(
);
export const getPostMultiplicationProgress = () => request('/meatspace/post/multiplication-progress');
export const getPostPowersProgress = () => request('/meatspace/post/powers-progress');
-export const getPostCognitiveProgress = () => request('/meatspace/post/cognitive-progress');
+// `options` so a caller with its own catch can pass `{ silent: true }` and not
+// double-report — both current callers fetch this in the background.
+export const getPostCognitiveProgress = (options) => request('/meatspace/post/cognitive-progress', options);
export const generatePostDrill = (type, config = {}, providerId, model, options = {}) => request('/meatspace/post/drill', {
method: 'POST',
body: JSON.stringify({ type, config, ...(providerId && { providerId }), ...(model && { model }) }),