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

show the n-back rule as a running stream instead of describing it

[._.]/ Adam Eivyb192fe587a10
diff --git a/client/src/components/meatspace/post/CognitiveDrillTutorial.jsx b/client/src/components/meatspace/post/CognitiveDrillTutorial.jsx
index 4cc2ecdc13..c880560054 100644
--- a/client/src/components/meatspace/post/CognitiveDrillTutorial.jsx
+++ b/client/src/components/meatspace/post/CognitiveDrillTutorial.jsx
@@ -1,18 +1,24 @@
-import { BookOpen, Check } from 'lucide-react';
+import { useEffect, useRef, useState } from 'react';
+import { BookOpen, Check, Pause, Play } from 'lucide-react';
import { DRILL_LABELS, effectiveCognitiveDrillConfig, cognitiveRungPending } from './constants';
+import usePrefersReducedMotion from '../../../hooks/usePrefersReducedMotion';
+import { useVisibilityEvent } from '../../../hooks/useVisibilityEvent.js';
+import { pluralize } from '../../../lib/textUtils.js';
import { safeReadJsonStorage, safeWriteStorage } from '../../../lib/safeStorage.js';
import Modal from '../../ui/Modal';
/**
- * The static how-to material for the cognitive drills: the per-type tutorial
+ * The how-to material for the cognitive drills: the per-type tutorial
* copy, the n-back worked example, the card that renders them, and the two
* entry points that open it (the standalone preview and its button).
*
* Deliberately separate from PostCognitiveDrillRunner: this is help text with
- * no timers, no scoring and no provider calls, and the settings/launcher
- * surfaces that link to it (PostDrillConfig, PostSessionLauncher) have no
- * business importing a live drill runner to reach it. The runner keeps only
- * `DrillTutorialGate`, which gates its own mount and imports the card from here.
+ * no scoring, no stimulus generation and no provider calls, and the
+ * settings/launcher surfaces that link to it (PostDrillConfig,
+ * PostSessionLauncher) have no business importing a live drill runner to reach
+ * it. The runner keeps only `DrillTutorialGate`, which gates its own mount and
+ * imports the card from here. The one timer in this module drives the n-back
+ * demo loop — it animates an explanation and records nothing.
*/
// One JSON blob keyed by drill type. Reads/writes go through the shared
@@ -84,7 +90,7 @@ export function getDrillTutorial(drill) {
switch (drill?.type) {
case 'n-back': {
const n = cfg.n ?? 2;
- const step = `${n} step${n !== 1 ? 's' : ''}`;
+ const step = pluralize(n, 'step');
return {
goal: `Watch a stream of letters and catch when one repeats from ${step} earlier.`,
steps: [
@@ -223,7 +229,7 @@ export function CognitiveDrillTutorial({ drill, tut, header = null, onAction, ac
))}
</ol>
- {tut.nBackExample && <NBackExampleStrip example={tut.nBackExample} />}
+ {tut.nBackExample && <NBackDemo example={tut.nBackExample} />}
<p className="text-xs text-gray-500">
<span className="text-gray-400 font-medium">Controls:</span> {tut.controls}
@@ -331,42 +337,232 @@ export function CognitiveDrillHowItWorksButton({ type, onClick, compact = false
);
}
-// 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.
-function NBackExampleStrip({ example: { sequence, n } }) {
+// =============================================================================
+// WORKED N-BACK EXAMPLE — an animated replay of a short stream
+// =============================================================================
+// "Press Match when the letter matches the one N back" is the sentence
+// first-timers misread: the stream is transient, so the thing being compared is
+// never on screen next to the thing you compare it to. Static text can't fix
+// that. This plays the example the way the drill actually runs — one letter at
+// a time on a stage, the sliding N-back window marked as it moves, and the
+// Match press fired at the exact frame it belongs on — so the timing is SHOWN
+// rather than asserted.
+//
+// The strip keeps every chip's BOX on every frame so the row never reflows, but
+// a letter's glyph and the two moving markers appear with the frame they belong
+// to. A screen reader gets the rule from the prose paragraph at the bottom, not
+// from the strip.
+
+const DEMO_PREROLL_MS = 900; // "Get ready…" before the first letter
+const DEMO_STEP_MS = 1150; // one non-match letter — brisk, but readable
+const DEMO_HIT_HOLD_MS = 3300; // linger on the match, then loop
+// Passes before the demo parks itself on the hit frame. Looping matters — a
+// reader who looked away has to be able to catch the press — but an open help
+// card would otherwise animate for as long as it is mounted, and by the third
+// pass the rule has landed. The Play control is the way back.
+const DEMO_MAX_LOOPS = 3;
+
+/**
+ * How long frame `step` stays on screen. Exported so the suite can drive the
+ * demo on the component's own schedule instead of re-declaring its constants —
+ * retuning the pacing then can't leave the tests green against a timeline the
+ * component no longer runs.
+ */
+export function demoFrameDelay(step, matchIndex) {
+ if (step < 0) return DEMO_PREROLL_MS;
+ return step === matchIndex ? DEMO_HIT_HOLD_MS : DEMO_STEP_MS;
+}
+
+/**
+ * The caption under the stage: what a player should be thinking on this frame.
+ * Pure, and exported so the phrasing is testable without driving timers — the
+ * three cases (warm-up, non-match, hit) are the whole lesson.
+ */
+export function nBackDemoCaption({ sequence, n, step }) {
+ if (step < 0) return 'Watch — the stream is about to start.';
+ const letter = sequence[step];
+ if (step < n) {
+ return `${letter} — nothing is ${n} back yet, so there's nothing to answer.`;
+ }
+ const back = sequence[step - n];
+ return letter === back
+ ? `${letter} is the same as the ${back} ${n} back — press Match now.`
+ : `${letter} vs ${back} ${n} back — different, so do nothing.`;
+}
+
+// Chip tones, keyed by what the frame is saying about that letter. A map rather
+// than a ternary chain so the four looks can be read against each other.
+const CHIP_TONE = {
+ lit: 'border-rose-500/60 bg-rose-500/15 text-rose-300',
+ current: 'border-white/60 text-white',
+ compare: 'border-rose-500/40 text-rose-300/80',
+ idle: 'border-port-border text-gray-400',
+};
+
+function NBackDemo({ example: { sequence, n } }) {
+ const reduced = usePrefersReducedMotion();
const matchIndex = sequence.length - 1;
- const sourceIndex = matchIndex - n;
- const step = `${n} step${n !== 1 ? 's' : ''}`;
+ const stepLabel = pluralize(n, 'step');
+
+ // `reduced` is policy, not state: read it at render and the "park on the last
+ // frame, paused" rule lives in these two lines instead of being re-asserted by
+ // initializers plus a sync effect that has to catch the setting flipping
+ // mid-read. The finished frame is the one that explains the rule, so a user
+ // who asked for stillness loses nothing.
+ const [rawStep, setStep] = useState(-1);
+ const [wantsPlay, setWantsPlay] = useState(true);
+ // A backgrounded tab is the other reason to stop scheduling: PortOS is
+ // routinely left open on a second tailnet machine, and an unseen animation
+ // would otherwise re-render this subtree about once a second forever.
+ const [hidden, setHidden] = useState(false);
+ useVisibilityEvent(state => setHidden(state === 'hidden'));
+
+ const step = reduced ? matchIndex : rawStep;
+ const playing = !reduced && wantsPlay;
+ const loopsRef = useRef(0);
+
+ // One timer per frame: each render schedules only the NEXT step, so pausing,
+ // hiding the tab and unmounting all reduce to "don't schedule another one".
+ useEffect(() => {
+ if (!playing || hidden) return undefined;
+ const timer = setTimeout(() => {
+ if (step < matchIndex) { setStep(step + 1); return; }
+ loopsRef.current += 1;
+ if (loopsRef.current >= DEMO_MAX_LOOPS) { setWantsPlay(false); return; }
+ setStep(-1);
+ }, demoFrameDelay(step, matchIndex));
+ return () => clearTimeout(timer);
+ }, [playing, hidden, step, matchIndex]);
+
+ const hit = step === matchIndex;
+ // Parked on the hit frame with nothing left to play — the control replays
+ // from the top rather than resuming a stream that has already ended.
+ const finished = !playing && step === matchIndex;
+ const togglePlay = () => {
+ if (finished) { loopsRef.current = 0; setStep(-1); }
+ setWantsPlay(play => !play);
+ };
+
+ // Which chip the N-back window is pointing at right now. Before the window has
+ // anything to point at (pre-roll, and the first `n` letters) it rests on the
+ // position the example's one match will come from, so the marker is always
+ // mounted exactly once — the strip reads correctly paused at any frame.
+ const compareIndex = (step >= n ? step : matchIndex) - n;
+
return (
<div className="rounded-lg border border-port-border bg-port-bg/40 p-4 space-y-3">
- <div className="text-[0.65rem] uppercase tracking-wide text-gray-500">Example — {n}-back</div>
+ <div className="flex items-center gap-2">
+ <div className="text-[0.65rem] uppercase tracking-wide text-gray-500">Example — {n}-back</div>
+ {!reduced && (
+ <button
+ type="button"
+ onClick={togglePlay}
+ aria-label={playing ? 'Pause example' : finished ? 'Replay example' : 'Play example'}
+ className="ml-auto inline-flex items-center gap-1 min-h-[44px] sm:min-h-0 sm:py-0.5 px-2 -my-2 sm:my-0 rounded text-[0.65rem] uppercase tracking-wide text-gray-500 hover:text-rose-300 transition-colors focus:outline-hidden focus:ring-2 focus:ring-port-accent"
+ >
+ {playing ? <Pause size={12} /> : <Play size={12} />}
+ {playing ? 'Pause' : finished ? 'Replay' : 'Play'}
+ </button>
+ )}
+ </div>
+
+ {/* The stage: the drill shows ONE letter at a time and nothing else, so
+ the example has to as well — a strip alone would teach the wrong task. */}
+ <div
+ className={`rounded-md border transition-colors ${hit ? 'border-rose-500/60 bg-rose-500/10' : 'border-port-border/60 bg-port-bg/60'}`}
+ >
+ <div className="h-16 flex items-center justify-center">
+ <span
+ data-testid="nback-demo-stage"
+ aria-hidden="true"
+ className={`transition-colors ${
+ step < 0
+ ? 'text-base text-gray-600'
+ : `font-mono text-4xl font-bold ${hit ? 'text-rose-300' : 'text-white'}`
+ }`}
+ >
+ {step < 0 ? 'Get ready…' : sequence[step]}
+ </span>
+ </div>
+ {/* A mock of the drill's Match button, not a real control: it must never
+ be reachable by tab or by name — the preview asserts no "Match"
+ button exists outside a live run. It lights on the hit frame, which
+ is the "when do I press?" answer the copy alone can't give. */}
+ <div
+ data-testid="nback-demo-press"
+ aria-hidden="true"
+ className={`m-3 mt-0 rounded border py-1.5 text-center text-xs font-semibold transition-[transform,color,background-color,border-color] ${
+ hit
+ ? 'border-rose-400 bg-rose-500/30 text-rose-100 scale-[1.03]'
+ : 'border-port-border/60 text-gray-600'
+ }`}
+ >
+ {hit ? 'Match — pressed!' : 'Match'}
+ </div>
+ </div>
- <ol aria-label="Example letter stream" className="flex flex-wrap items-end gap-2 list-none">
+ {/* The stream so far. The row NEVER wraps: it is `n + 3` letters long,
+ and wrapping a high lag on a narrow phone puts the match and the
+ letter it matches on separate lines — breaking the one relationship
+ the strip exists to show. Chips shrink to fit instead, capped at their
+ natural size, and each marker is positioned out of flow (the list's
+ vertical padding reserves its space) because a marker is several times
+ wider than the letter it points at and would otherwise stretch its own
+ chip. */}
+ <ol
+ aria-label="Example letter stream"
+ className="flex flex-nowrap justify-center gap-1.5 sm:gap-2 py-4 list-none"
+ >
{sequence.map((letter, i) => {
const isMatch = i === matchIndex;
- const isSource = i === sourceIndex;
+ const seen = i <= step;
+ const isCurrent = i === step;
+ // The window marker only lights once it has actually slid onto a
+ // letter the demo has shown; the final hit lights both ends at once.
+ const compareLit = i === compareIndex && step >= n;
+ const tone = (isCurrent || compareLit) && hit ? 'lit'
+ : isCurrent ? 'current'
+ : compareLit ? 'compare' : 'idle';
+ const marker = isMatch ? 'Match!' : i === compareIndex ? `${stepLabel} back` : null;
+ const markerShown = isMatch ? hit : compareLit;
return (
- <li key={i} className="flex flex-col items-center gap-1">
+ <li key={i} className="relative flex-1 min-w-0 max-w-9 sm:max-w-10 aspect-square">
<span
- className={`w-10 h-10 rounded-md border font-mono text-xl font-bold flex items-center justify-center ${
- isMatch || isSource ? 'border-rose-500/60 bg-rose-500/15 text-rose-300' : 'border-port-border text-gray-400'
- }`}
+ className={`absolute inset-0 rounded-md border font-mono text-lg sm:text-xl font-bold flex items-center justify-center transition-[color,background-color,border-color,opacity] ${CHIP_TONE[tone]} ${seen ? 'opacity-100' : 'opacity-25'}`}
>
- {letter}
- </span>
- {/* Non-breaking space, not an em dash: an unlabeled chip must hold
- the baseline without reading as a third label. */}
- <span className={`text-[0.6rem] ${isMatch ? 'text-rose-300' : 'text-gray-600'}`}>
- {isMatch ? 'Match!' : isSource ? `${step} back` : '\u00a0'}
+ {/* Letters not yet shown keep their box (stable layout, no
+ reflow jitter) but hide the glyph — the box is the beat. */}
+ <span className={seen ? '' : 'invisible'}>{letter}</span>
</span>
+ {marker && (
+ // The window marker rides ABOVE the stream and the verdict below
+ // it. Both are wider than the chip they point at, so on a 1-back
+ // — where they land on adjacent chips — sharing one side runs
+ // them together.
+ <span
+ className={`absolute left-1/2 -translate-x-1/2 whitespace-nowrap text-[0.6rem] transition-opacity ${
+ isMatch ? 'top-full mt-1 text-rose-300' : 'bottom-full mb-1 text-gray-500'
+ } ${markerShown ? 'opacity-100' : 'opacity-0'}`}
+ >
+ {marker}
+ </span>
+ )}
</li>
);
})}
</ol>
- <p className="text-xs text-gray-400">
- The last <span className="font-mono text-rose-300">{sequence[matchIndex]}</span> repeats the letter {step}{' '}
+ <p className={`text-xs min-h-[2rem] ${hit ? 'text-rose-300' : 'text-gray-400'}`}>
+ {nBackDemoCaption({ sequence, n, step })}
+ </p>
+
+ {/* The same rule in prose. The animation and its running caption are the
+ explanation for anyone who can see it, so this is `sr-only` while the
+ demo plays and visible when it doesn't — the card sits above a "Start
+ drill" button that has to stay above the fold on a phone, and saying
+ the rule twice on screen is what would push it under. */}
+ <p className={reduced ? 'text-xs text-gray-500' : 'sr-only'}>
+ The last <span className="font-mono text-rose-300">{sequence[matchIndex]}</span> repeats the letter {stepLabel}{' '}
earlier — press <span className="text-white font-medium">Match</span> on it. Every other letter is a
non-match: do nothing.
</p>
diff --git a/client/src/components/meatspace/post/CognitiveDrillTutorial.test.jsx b/client/src/components/meatspace/post/CognitiveDrillTutorial.test.jsx
index 7165510296..5efece67c2 100644
--- a/client/src/components/meatspace/post/CognitiveDrillTutorial.test.jsx
+++ b/client/src/components/meatspace/post/CognitiveDrillTutorial.test.jsx
@@ -1,18 +1,21 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
-import { render, screen, fireEvent, within } from '@testing-library/react';
+import { act, render, screen, fireEvent, within } from '@testing-library/react';
import {
getDrillTutorial,
hasDrillTutorial,
hasSeenDrillTutorial,
buildNBackExample,
+ demoFrameDelay,
+ nBackDemoCaption,
CognitiveDrillTutorialPreview,
CONFIG_DEPENDENT_TUTORIAL_TYPES,
} from './CognitiveDrillTutorial';
import { COGNITIVE_DRILL_TYPES } from './constants';
-// The static how-to material, exercised with NO drill runner mounted — that is
-// the point of the split: this module is help text, so nothing here needs a
-// timer, a fake clock or a scoring path to assert.
+// The how-to material, exercised with NO drill runner mounted — that is the
+// point of the split: this module is help text, so nothing here needs a scoring
+// path or a stimulus generator to assert. The one clock in play belongs to the
+// n-back demo loop, which animates an explanation and records nothing.
//
// The tutorial assertions that DO mount a runner stay in
// PostCognitiveDrillRunner.test.jsx ('first-run tutorial gate' and 'n-back
@@ -180,3 +183,185 @@ describe('CognitiveDrillTutorialPreview', () => {
expect(screen.getByText(/then type them back in order/i)).toBeInTheDocument();
});
});
+
+// The animated worked example (the n-back demo). The rule a first-timer misreads
+// is a TIMING rule — "press Match when this letter repeats the one N back" — and
+// the stream is transient, so the two letters being compared are never on screen
+// together during a real run. These assert the demo actually teaches that: the
+// letters arrive one at a time, the N-back marker slides with them, and the
+// simulated press fires on the hit frame and on no other frame.
+describe('n-back demo', () => {
+ const originalMatchMedia = window.matchMedia;
+ let mediaQuery;
+
+ const renderDemo = (n) => {
+ const { sequence } = buildNBackExample(n);
+ const result = render(
+ <CognitiveDrillTutorialPreview type="n-back" drillConfig={{ n, progressive: false }} onClose={vi.fn()} />,
+ );
+ return { ...result, sequence, last: sequence.length - 1 };
+ };
+ const stage = () => screen.getByTestId('nback-demo-stage').textContent;
+ const press = () => screen.getByTestId('nback-demo-press').textContent;
+ // Advance by exactly what the component says the CURRENT frame lasts, so
+ // retuning its pacing can never leave these green against a dead timeline.
+ // One advance per frame: the demo arms the next timeout from the effect that
+ // runs after React commits the current one, so a single large advance would
+ // only ever move it on by one letter.
+ const advanceFrom = (step, last) => act(() => { vi.advanceTimersByTime(demoFrameDelay(step, last)); });
+ const playToHit = (last) => { for (let step = -1; step < last; step += 1) advanceFrom(step, last); };
+
+ beforeEach(() => {
+ vi.useFakeTimers();
+ mediaQuery = { matches: false, addEventListener: vi.fn(), removeEventListener: vi.fn() };
+ window.matchMedia = vi.fn(() => mediaQuery);
+ });
+
+ afterEach(() => {
+ window.matchMedia = originalMatchMedia;
+ vi.useRealTimers();
+ });
+
+ it('plays the stream one letter at a time and fires the press only on the hit', () => {
+ const { sequence, last } = renderDemo(2);
+
+ expect(stage()).toMatch(/get ready/i);
+ expect(press()).toBe('Match');
+
+ // Every non-match frame shows its letter with the press button still dark —
+ // "do nothing" is the answer on all of them.
+ advanceFrom(-1, last);
+ for (let i = 0; i < last; i += 1) {
+ expect(stage()).toBe(sequence[i]);
+ expect(press()).toBe('Match');
+ advanceFrom(i, last);
+ }
+
+ // Final letter: the repeat. This is the one frame the press belongs on.
+ expect(stage()).toBe(sequence[last]);
+ expect(press()).toBe('Match — pressed!');
+ expect(screen.getByText(/press Match now/i)).toBeInTheDocument();
+ });
+
+ it('loops back to the pre-roll so a reader who looked away still catches it', () => {
+ const { last } = renderDemo(2);
+ playToHit(last);
+ expect(press()).toBe('Match — pressed!');
+ advanceFrom(last, last);
+ expect(stage()).toMatch(/get ready/i);
+ expect(press()).toBe('Match');
+ });
+
+ it('parks on the hit frame after a few passes instead of animating forever', () => {
+ // An open help card would otherwise re-render this subtree for as long as it
+ // is mounted. Replay is the way back.
+ const { sequence, last } = renderDemo(2);
+ for (let pass = 0; pass < 3; pass += 1) {
+ playToHit(last);
+ advanceFrom(last, last);
+ }
+ expect(stage()).toBe(sequence[last]);
+ expect(vi.getTimerCount()).toBe(0);
+
+ fireEvent.click(screen.getByRole('button', { name: /replay example/i }));
+ expect(stage()).toMatch(/get ready/i);
+ advanceFrom(-1, last);
+ expect(stage()).toBe(sequence[0]);
+ });
+
+ it('stops scheduling frames while the tab is hidden', () => {
+ // PortOS is routinely left open on a second tailnet machine; an unseen
+ // animation must not keep re-rendering there.
+ const { sequence, last } = renderDemo(2);
+ advanceFrom(-1, last);
+ expect(stage()).toBe(sequence[0]);
+
+ Object.defineProperty(document, 'visibilityState', { value: 'hidden', configurable: true });
+ act(() => { document.dispatchEvent(new Event('visibilitychange')); });
+ expect(vi.getTimerCount()).toBe(0);
+
+ Object.defineProperty(document, 'visibilityState', { value: 'visible', configurable: true });
+ act(() => { document.dispatchEvent(new Event('visibilitychange')); });
+ advanceFrom(0, last);
+ expect(stage()).toBe(sequence[1]);
+ });
+
+ it('marks exactly one chip as the N-back comparison on every frame', () => {
+ // The sliding window IS the lesson, so a frame with two markers (or none)
+ // would point the reader at the wrong pair of letters.
+ const { last } = renderDemo(3);
+ for (let step = -1; step <= last; step += 1) {
+ const strip = within(screen.getByRole('list', { name: /example letter stream/i }));
+ expect(strip.getAllByText('3 steps back')).toHaveLength(1);
+ advanceFrom(step, last);
+ }
+ });
+
+ it('holds the frame while paused and resumes from it', () => {
+ const { sequence, last } = renderDemo(2);
+ advanceFrom(-1, last);
+ advanceFrom(0, last);
+ expect(stage()).toBe(sequence[1]);
+
+ fireEvent.click(screen.getByRole('button', { name: /pause example/i }));
+ for (let i = 0; i < 10; i += 1) advanceFrom(1, last);
+ expect(stage()).toBe(sequence[1]);
+ expect(vi.getTimerCount()).toBe(0);
+
+ fireEvent.click(screen.getByRole('button', { name: /play example/i }));
+ advanceFrom(1, last);
+ expect(stage()).toBe(sequence[2]);
+ });
+
+ it('stops scheduling frames once unmounted', () => {
+ const { last, unmount } = renderDemo(2);
+ advanceFrom(-1, last);
+ unmount();
+ expect(vi.getTimerCount()).toBe(0);
+ });
+
+ it('shows the finished example, and no clock at all, under prefers-reduced-motion', () => {
+ mediaQuery.matches = true;
+ const { sequence, last } = renderDemo(2);
+ // The last frame is the one that explains the rule, so stillness costs the
+ // reader nothing — and there is no play control to imply motion is coming.
+ expect(stage()).toBe(sequence[last]);
+ expect(press()).toBe('Match — pressed!');
+ expect(vi.getTimerCount()).toBe(0);
+ expect(screen.queryByRole('button', { name: /pause example|play example|replay example/i })).not.toBeInTheDocument();
+ });
+});
+
+// The frame schedule, pinned as a shape rather than as three magic numbers: the
+// pre-roll and the hit both have to differ from an ordinary letter, and the hit
+// has to be the longest or the press is gone before it registers.
+describe('demoFrameDelay', () => {
+ it('gives the pre-roll and the hit their own, longer dwell', () => {
+ const last = 4;
+ const ordinary = demoFrameDelay(1, last);
+ expect(demoFrameDelay(-1, last)).not.toBe(ordinary);
+ expect(demoFrameDelay(last, last)).toBeGreaterThan(ordinary);
+ expect(demoFrameDelay(last, last)).toBeGreaterThan(demoFrameDelay(-1, last));
+ });
+});
+
+// The caption is the demo's running commentary. Asserting it directly keeps the
+// two cases the rendered test can't reach — the warm-up letters and a non-match
+// — pinned without driving the clock for each one.
+describe('nBackDemoCaption', () => {
+ // A 2-back stream whose last letter repeats the one two back: index 3 is the
+ // hit, index 2 the non-match, indexes 0-1 the warm-up.
+ const sequence = ['K', 'R', 'T', 'R'];
+
+ it('says there is nothing to answer yet during the warm-up letters', () => {
+ expect(nBackDemoCaption({ sequence, n: 2, step: 0 })).toMatch(/nothing is 2 back yet/i);
+ expect(nBackDemoCaption({ sequence, n: 2, step: 1 })).toMatch(/nothing is 2 back yet/i);
+ });
+
+ it('names both compared letters on a non-match and tells the reader to do nothing', () => {
+ const caption = nBackDemoCaption({ sequence, n: 2, step: 2 });
+ expect(caption).toContain('T');
+ expect(caption).toContain('K');
+ expect(caption).toMatch(/do nothing/i);
+ });
+});
diff --git a/client/src/hooks/README.md b/client/src/hooks/README.md
index 8c514836c2..21217ab63a 100644
--- a/client/src/hooks/README.md
+++ b/client/src/hooks/README.md
@@ -235,7 +235,7 @@ grep -i "what you want to do" client/src/hooks/README.md
| `useMusicVideoManualTempo` | The manual-tempo fallback for a project whose auto-detected BPM is null: BPM/offset drafts (reset on project switch), tap-tempo estimation, and the persisted `setMusicVideoManualTempo` call. Returns `{ bpm, setBpm, offset, setOffset, saving, tap, submit }`. | The Music Video "No tempo detected" row. |
| `useCanvasDprSize` | DevicePixelRatio-aware canvas sizing shared by the piano-roll renderers (`<PianoRoll>`, `<MidiPianoRoll>`): sizes the bitmap to container-width × height (or the container height when `height` is `undefined`) at the DPR, applies the transform, and redraws via a `drawRef` on mount + every `ResizeObserver` resize (observer created once per height, never churned by draw-closure changes). Returns a ref holding the current CSS width so draw code doesn't measure the DOM per frame. | Both piano-roll canvases. |
| `useCanvasRollPalette` | Resolves a canvas palette into a ref — `rollPalette` by default, or any resolver passed as the second argument (the Core Assembly avatar reads `--port-accent-2`), re-resolving on theme switch (`data-port-theme` MutationObserver) and repainting through a `drawRef`. Hands back a ref, not state, so a theme swap redraws the imperative canvas without a React re-render. | Both piano-roll canvases need theme-aware accent/bg colors that canvas `fillStyle` can't read from CSS vars. |
-| `usePrefersReducedMotion` | The user's `prefers-reduced-motion` setting as a boolean, tracking live changes. Consumed by `cos/CoreCoSAvatar.jsx` and `brain/tabs/BrainGraph.jsx`. | An imperative animation (a rAF canvas loop, a three.js frameloop) that must stop scheduling frames itself — CSS animations honor the media query on their own. |
+| `usePrefersReducedMotion` | The user's `prefers-reduced-motion` setting as a boolean, tracking live changes. | An imperative animation (a rAF canvas loop, a three.js frameloop) that must stop scheduling frames itself — CSS animations honor the media query on their own. |
| `useMidiNotes` | Fetch + parse a transcribed `.mid` file into the piano-roll view-model (`parseMidiFile` in `lib/midiNotes.js`), with a module-level per-URL cache so remounts (collapse, tab switches) don't refetch/reparse. Returns `{ status: 'idle'\|'loading'\|'ready'\|'error', data, error, reload }`; a generation counter drops stale in-flight responses on URL change/unmount. Plain `fetch` of the static file URL — errors surface inline, never as toasts (#2477). | `<MidiVisualization>` (Rounds ReferenceAnalysis + Music Video). |
| `useChordPlayer` | Chord-sheet play-along transport for a SongBook `tab`/`chordpro` sheet (#4104) — the chord counterpart of `useDrumPlayer`: parses the (already-transposed) text, owns one `createChordPlayer`, the practice settings (tempo + beats-per-chord persisted per song, count-in, machine-global click) and the sounding-chord highlight read off the audio clock. Returns `{ chordCount, hasChords, writtenTempo, bpm, setBpm, setBpmPercent, beatsPerBar, setBeatsPerBar, countInBars, setCountInBars, clickEnabled, setClickEnabled, playing, pulse, sounding, getPlayhead, toggle, stop }`. Timing edits stop playback rather than re-time a running schedule. | `<ChordTransportBar>` + `<ChordPreview>` (SongBook viewer/editor/importer). |
| `useDrumPlayer` | Drum play-along transport for a SongBook `drum` chart (#3115): parses the chart (`lib/drumNotation.js`), owns one `createDrumPlayer` per chart plus the practice settings and the sheet playhead. Returns `{ chart, barCount, writtenTempo, bpm, setBpm, setBpmPercent, countInBars, setCountInBars, loopEnabled, setLoopEnabled, loopFrom, loopTo, setLoopRange, clickEnabled, setClickEnabled, clickVolume, setClickVolume, kitId, setKitId, playing, activeStep, currentBar, toggle, stop }`. The practice tempo persists per song in `safeStorage` (never into the record) while the selected kit (`songbook:drumKit`), the click toggle (`songbook:drumClick`) and the click level (`songbook:drumClickVolume`) persist per MACHINE; a timing-critical edit (tempo / count-in / loop) STOPS playback rather than re-timing already-scheduled audio, while the click toggle, the click level and the kit swap apply live (raising the level off silence also unmutes, so the slider is never a dead control); the player + its interval + scheduled hits tear down on stop, chart change and unmount. | The SongBook viewer and snapshot-based drum previews. Don't hand-wire `createDrumPlayer` + BPM persistence + playhead state again. |