Files
CatoandClaude Opus 5 398b472978 fix(nav): make the mobile section rail actually stick, and give the header one height (#104)
THE DEFECT, FOUND BY MEASURING RATHER THAN READING. `SectionNav` carries a
full mobile treatment — `sticky top-0 z-20`, a translucent background, a
backdrop blur, a bottom border — for a state that could never occur. Scrolled
to 2500px on `/de/method` at 375px wide, the rail sat at `top: -1489`: it had
scrolled away like any static block.

A sticky element can only travel inside its containing block, and
`SectionNavLayout` wrapped the rail in a grid-item div exactly as tall as the
rail itself. Zero room to travel, so `position: sticky` did nothing and every
style written for the stuck state was decoration. `display: contents` below
`lg` takes the wrapper out of layout, the nav becomes the grid item, and it
inherits the grid's full height.

And it had pinned to `top: 0`, which is where the 69px site header already is
with a higher z-index — so had it ever stuck, it would have stuck underneath
the header.

WHILE FIXING IT, THE ROW GOT HONEST ABOUT SIZE. Seven sections wrapped to four
rows: 153px, a fifth of an 800px phone screen, held permanently to show a table
of contents nobody asked to keep looking at. It is now one row that scrolls
sideways — 57px — which is what documentation sites converged on for the same
reason. Measured after: pinned at exactly 69px, links clickable, and the
document still 375px wide in a 375px viewport.

ONE HEADER HEIGHT, REPLACING FOUR GUESSES. The header had no height; 69px
emerged from `min-h-11` plus `py-3` plus a border. Headings meanwhile carried
`scroll-mt-20`, `scroll-mt-24` AND `scroll-mt-28` — 2, 15 and 7 of them — three
answers to "how far below the top does an anchor land", each clearing 69px by
luck. `--header-height` in globals.css is now the single value: the header is
given it, the rail pins below it, and one `scroll-mt-anchor` utility (which
also accounts for the rail on phones) replaced all 24 occurrences.

TWO MORE DUPLICATIONS, EACH WITH A COPY THAT HAD DRIFTED:

- `lib/text/words.ts` replaces FIVE whole-word matchers. `saysWord`,
  `says` and `demonstrates` were byte-identical under three names; `check.ts`
  and `text.ts` each kept a private `escape`. `display.ts` says in its own
  comment that it is copying the variety gate — the author knew they were
  writing the second one, because there was nowhere to put it. `text.ts` opens
  by arguing these operations belong "in one place" while holding a fifth copy.
  Eight tests pin the cases the five copies each half-knew.

- `lib/i18n/dates.ts` replaces THREE date formatters whose comments all said
  "the reader's own date format, never a hardcoded one" and which then
  disagreed about the month and the fallback. The tag was resolved at three
  different layers: not at all, at the caller, and at the use site — so
  `SavedWords` declared `locale: string` and was handed a pre-resolved
  `de-CH`. Now the formatter owns it and the prop is `Locale`. A test asserts
  the chat workspace's date is byte-identical in all seven locales, because a
  refactor that changes a glyph is not one. Also ends `essays/[slug]`
  importing a helper out of another page module.

THE AUDIT LEARNED TWO THINGS, BOTH PROVEN BY MUTATION:

- Its two checks disagreed about scrollers. `clipped` exempts a deliberate
  `overflow-x: auto` ("a real scroller is a deliberate choice"); the horizontal
  `over` check did not, and reported four findings against a correct page whose
  document did not overflow. They now agree. Mutation-tested: widened the rail
  to 900px and `OVER` still fires, on the nav itself.
- It now fails if the header's CONTENT outgrows the token height. The first
  version compared the header to the token and could never fail — the header
  IS the token — which is worse than no check. Mutation-tested at `2rem`:
  "the header contains 68px of content in a 32px bar".

Note that lint and type-check both passed while globals.css was unparseable
(`@utility` cannot nest inside `@media`); neither compiles CSS. The dev server
was what said so.

Verified: verify exit 0 — 852 tests, 72 suites; audit:language 20 pages / 0
English; audit:responsive 116 renders across de/fr/ru, 320–375px, light and
dark — 0 overflow, 0 header drift; `/de/method` screenshotted at 390px
scrolled to 2200, rail pinned under the header.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-24 02:12:43 -07:00

113 lines
4.3 KiB
TypeScript

import { check } from "../../variety/check.ts";
import type { VarietyPack } from "../../variety/pack.ts";
import { identity } from "./collection.ts";
import { saysWord } from "../../text/words.ts";
/**
* Meeting a kept word somewhere new.
*
* A learner who met *gäll* once has met it once. The sentence it came from is
* already stored, and it is the same sentence every time they review — so the
* word gets learned attached to that one context rather than as a word. One or
* two further sentences, in different situations, is the cheapest version of
* the varied input that actually builds recognition.
*
* WHY THIS IS FREE FOR EVERYONE. It was very nearly gated behind a paid tier on
* the grounds that it costs a model call. Measured, the call is about 174
* tokens in and 60 out — roughly five hundredths of a rappen, ONCE, for the
* lifetime of that word. A learner who fills the entire 500-word cap costs
* about a quarter of a franc. Charging for that would be arbitrary, and people
* can feel arbitrary.
*
* Everything below is pure: the route does the model call, this decides what
* survives it.
*/
/** Two. A third is not more varied input, it is a wall of text on a card. */
export const MAX_EXAMPLES = 2;
/**
* Long enough for a real sentence, short enough to read on a review card
* without scrolling. A model asked for "short" and given no number will
* occasionally write a paragraph.
*/
export const MAX_EXAMPLE_LENGTH = 120;
/**
* Does this sentence actually contain the word it is supposed to demonstrate?
*
* The failure this catches is specific and common: asked for a sentence using
* *Chind*, a model writes a sentence using *Chinder*. It is a perfectly good
* sentence and a useless example, because the learner is reviewing the form
* they saved and will not see it.
*
* Matched on a word boundary so *gäll* is not "found" inside a longer word,
* and case-folded the same way the saved list folds its own identity — a
* sentence-initial *Gäll* is the same word.
*/
export function demonstrates(sentence: string, target: string): boolean {
const word = identity({ target }).trim();
if (!word) return false;
return saysWord(sentence, word);
}
export type ExampleResult = {
/** What survived. Possibly empty, which is a normal outcome and not an error. */
examples: string[];
/**
* What was generated and thrown away, and why. Not shown to the learner —
* this is for the operator, because a gate that silently drops everything
* looks identical to a model that returned nothing.
*/
rejected: { sentence: string; reason: string }[];
};
/**
* Keep the sentences that are actually usable.
*
* Every rejection here is a thing the learner must never be shown: a sentence
* in the wrong variety teaches them a wrong form, and a sentence missing the
* word teaches them nothing at all. Both are worse than showing no example,
* which is why this returns an empty list rather than lowering the bar.
*/
export function usableExamples(raw: unknown, target: string, pack: VarietyPack): ExampleResult {
const rejected: { sentence: string; reason: string }[] = [];
const examples: string[] = [];
const list = Array.isArray(raw)
? raw
: Array.isArray((raw as { examples?: unknown })?.examples)
? ((raw as { examples: unknown[] }).examples)
: [];
for (const candidate of list) {
if (typeof candidate !== "string") continue;
const sentence = candidate.trim().replace(/\s+/g, " ");
if (!sentence) continue;
if (sentence.length > MAX_EXAMPLE_LENGTH) {
rejected.push({ sentence, reason: "too long" });
continue;
}
if (!demonstrates(sentence, target)) {
rejected.push({ sentence, reason: "does not contain the word" });
continue;
}
// The same gate every other generated line faces. A learner cannot audit
// this — that is the entire reason the gate exists.
const verdict = check(sentence, pack);
if (!verdict.ok) {
rejected.push({ sentence, reason: verdict.findings.map((f) => f.form).join(", ") });
continue;
}
// Two identical situations are one example.
if (examples.some((kept) => kept.toLocaleLowerCase() === sentence.toLocaleLowerCase())) continue;
examples.push(sentence);
if (examples.length === MAX_EXAMPLES) break;
}
return { examples, rejected };
}