Files
CatoandClaude Opus 5 f34cf3f409 feat: Heidi on every page, an account menu, learnable reference pages, and what the field can actually do (#66)
* feat(chat): Heidi on every page, and an account menu instead of two boxes

Chat is how people use this product and it existed on two surfaces out of
eleven. A reader on /grammar had to notice the nav, work out which of eight
links was the chat, and lose the page they were reading. Signed in it was
worse: the locale root is the dashboard, so the landing page had no composer
anywhere on it.

The dock is the same conversation as the home fold and /chat, because all
three now read one store through use-draft-chat.ts. Pages that already hold a
conversation mark themselves with data-chat="surface" and globals.css hides
the dock over them — CSS rather than a pathname list, because whether the
locale root holds a chat depends on whether the visitor is signed in, which a
route table cannot know and the rendering page always does.

The header carried a gear icon beside a pill with a green dot that nothing
measured. One avatar menu replaces both; what is in it comes from
ACCOUNT_MENU_KEYS in routes.ts, so an entry naming a page the site does not
have is a build error.

Three things found on the way, each a defect nobody had reported:

- Escape-to-close was written twice and the copies disagreed — one returned
  focus to its trigger, one dropped it to the top of the document. A third
  copy was in model-sheet.tsx. One implementation now, in use-dismiss.ts.
- The mobile menu had aria-expanded and no dismissal at all: Escape did
  nothing, an outside tap did nothing, and a browser Back left it open over
  the new page. Found by the test that asserts every aria-expanded control
  uses the hook.
- /api/chat carried a second copy of the turn wiring that respond.ts exists to
  own — including an `as unknown as` cast that ai-kit 1.x had already made
  unnecessary, which is the copies having drifted. The route is ~45 lines
  shorter and every surface now shares one turn.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(chat): the dock panel sat on top of its own launcher

Measured on screen at 1280px, not reasoned about: at `bottom-4` the card
covered the button that opened it, so on a laptop the control that closes the
dock was underneath the dock. `sm:bottom-20` clears it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* feat(settings): a theme control, for the palette that was already written

globals.css has carried a full dark palette since the cow retheme, in blocks
guarded on `data-theme` — and nothing in the product ever set that attribute.
The palette was unreachable: a reader whose device is light could not ask for
dark, and one whose device is dark could not ask for light.

Three states, not two. "System" is the default and follows the device,
including when the device changes at dusk; a two-state toggle has to pick a
side at first paint and is then wrong for half the readers until somebody
touches it.

The choice is stamped by an inline script before first paint. An effect would
run after it, so a reader who chose dark would watch a white page flash to
black on every navigation — worse than having no toggle. Two things that cost
a debugging cycle each are pinned by tests:

- `createBrowserStore` writes through JSON.stringify, so the stored value is
  `"dark"` WITH quotes. Comparing it to `dark` fails silently and the only
  symptom is the flash the script exists to prevent. The test runs the script
  for real against both encodings rather than grepping it for `setAttribute`.
- localStorage THROWS in a private window and where site data is blocked. This
  runs before React, so an uncaught throw would take the page down.

`suppressHydrationWarning` on <html> is the documented fix for an attribute a
pre-paint script sets deliberately, and it covers that element only — a real
mismatch inside the page still fails loudly. Verified in the browser: the
warning was there, and is gone.

Also: limitkit moves from `github:bitbaum/limitkit#v0.2.0` to `^0.2.0` on npm,
same version. Under pnpm 11 a git-hosted dependency's prepare build is refused
without an allowBuilds entry, so the install resolves to a package with no
dist and CI fails on an import resolving to nothing. fleet/SHARED.md names
heidi specifically for this. Confirmed after reinstall: node_modules/limitkit
now has dist.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(chat): a letter pasted into a GROUP got none of the message handling

`pastedContext` tested `authorId === LEARNER_ID`, which is the id the SOLO
thread stamps on the reader's turns. In a group every human carries their own
OrangeCat actor id and none of them is LEARNER_ID, so the loop walked every
message, matched nothing, and returned "". Pasting a landlord's letter into a
study group quietly got no structure, no header parsing and no guaranteed
reply offer — and looked exactly like a letter that had been handled.

"Not Heidi" is the test that is true on both thread shapes. Pinned, along with
the latest-turn-only rule and the two cases that must stay silent.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(chat): seven defects from review, one of them mine and critical

The critical one was introduced by the dismiss consolidation. `useDismiss`'s
navigation effect fired on the INITIAL commit as well as on changes, and the
model sheet passes `open: true` because it exists only while open — so
pressing "connect your own model" opened a sheet that closed in the same tick.
BYOK, and with it every picture, was unreachable. No test could catch it.

The first repair was a "skip the first run" ref, and it was wrong:
`reactStrictMode` is on, React invokes each effect twice in development, and
the ref persists across both — the guard was spent on the first invocation and
the second closed the sheet anyway. Measured in the browser, the sheet still
refused to open. Comparing the stored pathname asks what the effect actually
means — "have we navigated?" rather than "is this the first run?" — and is
correct under both. Verified in the browser: the sheet opens, Escape closes
it, and the nav panel still closes on a real navigation.

The rest:

- French and Italian envelopes were mis-parsed. `À :` and `A:` are one letter
  and the pattern demanded two, so the recipient line ended the header block:
  a French message lost its subject and leaked `À : … / Objet : …` into the
  body, and an Italian one fell below the two-header floor and was not
  recognised as a message at all. The earlier tests passed only because they
  omitted the recipient line, which no real mail client does.

- The pasted body was being concatenated into the SYSTEM prompt — up to 4,000
  characters written by whoever wrote to the reader, given the authority of
  our own rules. It is not repeated at all now: the paste is already in the
  conversation as the reader's own turn, in the user role, which is the
  privilege level it should have. The envelope fields stay, capped and fenced
  as data, and the model is told to report an instruction aimed at it rather
  than act on it.

- Asking the same word twice did nothing the second time, then replayed it
  later: the dedupe key was the text, so the effect returned early without
  clearing the pending ask. It is a monotonic id now. Verified: two presses,
  two turns.

- Navigating closed the dock and discarded an in-flight answer, because
  `useConversation` has no abort handling. The dock lives in the layout to
  outlive the page under it, and following a grammar link from an answer is a
  move this product encourages — so it opts out of navigation dismissal.

- Signed in, Settings and Sign out moved inside a client-component menu, so a
  reader with JavaScript off lost the only route to their own settings. The
  footer carries a plain link now, for signed-in and signed-out alike.

- Closing the panel on a phone dropped focus to <body>: the launcher is
  `display:none` there, so `.focus()` was a silent no-op.

- The account menu pointed `aria-controls` at an element that does not exist
  while it is closed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* feat(technology): what a computer can and cannot do with Swiss German

§8 is an overclaim register — a list of things this product must not say, the
largest of which is that it transcribes dialect. The strongest form of that
discipline is not a promise to be careful; it is publishing what the field can
actually do, with the numbers, so a reader can hold our claims against it.

Five public speech corpora with hours, speakers, regions and licences; three
ASR results as word error rate on one test set so they can be compared; four
speech-synthesis systems; three language models. Thirteen new sources, each
opened and checked against the claim it supports.

The central fact needs no argument once the table is on screen: almost every
Swiss German speech corpus pairs dialect SPEECH with STANDARD GERMAN text,
because in a diglossic country writing down what was said is a translation
task, not a transcription one. That is why Heidi's dictation produces Standard
German, and the page now shows why rather than asserting it.

Three things a product page would not say: the best verifiable Swiss German
WER is 12.1% and those weights are unpublished; most voices sold as "Swiss
German" are Swiss STANDARD German read aloud; and Apertus carries 6,000 Swiss
German post-training examples while publishing no dialect evaluation at all —
marked `dialect not evaluated`, which is the difference between a claim and a
result.

Positioned beside /method rather than inside it: /method argues how Heidi
teaches and rests on acquisition research; this rests on language-technology
research and argues nothing about teaching. Indexed, because someone searching
for "Swiss German speech recognition" is looking for exactly this and will
otherwise find a vendor selling them Swiss Standard German.

The numbers live in lib/research/language-tech.ts, not the dictionaries — a
figure is not translatable and seven copies of "343 hours" are seven chances
for one to become 340. The English `note` on each row is maintainer copy and
is NOT rendered: providers.ts already records what happens when an English
source-copy field reaches a component, and the first draft of this page
repeated that mistake in four tables before it was caught on screen. Every
label a reader sees is localised, verified in German and French.

The article-URL rule widened to admit ACL Anthology and CEUR records. That is
not a loosening: this literature publishes at ACL, where the Anthology record
IS the permanent identifier. An arXiv preprint still enters through a DOI and
says "preprint" in its venue, so a reader is told what they are looking at.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 04:06:31 -07:00

122 lines
4.8 KiB
TypeScript

import { test, describe } from "node:test";
import assert from "node:assert/strict";
import { DEFAULT_THEME, THEME_KEY, THEME_SCRIPT, THEMES, applyTheme, decodeTheme, isTheme } from "./theme.ts";
describe("theme", () => {
test("only the three known values are themes", () => {
assert.deepEqual([...THEMES], ["system", "light", "dark"]);
assert.ok(isTheme("dark"));
assert.ok(!isTheme("DARK"));
assert.ok(!isTheme("sepia"));
assert.ok(!isTheme(null));
});
test("anything unrecognised in storage decodes to system", () => {
// Storage is data a previous version wrote and the reader can edit by
// hand, so it is validated exactly like something arriving over a wire.
assert.equal(decodeTheme("dark"), "dark");
assert.equal(decodeTheme(null), DEFAULT_THEME);
assert.equal(decodeTheme("nonsense"), DEFAULT_THEME);
assert.equal(decodeTheme(""), DEFAULT_THEME);
});
test("system REMOVES the attribute rather than naming itself", () => {
// The stylesheet's dark block is guarded by `:not([data-theme="light"])`.
// A literal data-theme="system" would satisfy that guard today and is a
// value the CSS never mentions, so it would break the day someone
// tightened the selector.
const calls: string[] = [];
const root = {
setAttribute: (name: string, value: string) => calls.push(`set ${name}=${value}`),
removeAttribute: (name: string) => calls.push(`remove ${name}`),
} as unknown as HTMLElement;
applyTheme("system", root);
assert.deepEqual(calls, ["remove data-theme"]);
calls.length = 0;
applyTheme("dark", root);
assert.deepEqual(calls, ["set data-theme=dark"]);
});
});
describe("the no-flash script", () => {
test("it reads the same key the module writes", () => {
// Generated from the constant rather than written out, so this asserts the
// generation actually happened rather than that someone typed it twice.
assert.ok(
THEME_SCRIPT.includes(JSON.stringify(THEME_KEY)),
"the inline script must read the key the rest of the code writes",
);
});
test("it cannot throw the page down", () => {
// localStorage THROWS in a private window and where site data is blocked.
// This runs before React, so an uncaught throw takes the whole page with it.
assert.match(THEME_SCRIPT, /try\{/, "the script must be wrapped in try/catch");
assert.match(THEME_SCRIPT, /catch\(e\)\{\}/, "and must swallow the error rather than rethrow");
});
test("it sets only the two explicit themes, never system", () => {
assert.match(THEME_SCRIPT, /"light"\|\|t==="dark"/);
assert.ok(!THEME_SCRIPT.includes('"system"'), "system means no attribute at all");
});
test("it actually does the thing, run for real", () => {
/**
* Proved by EXECUTION rather than by reading the string.
*
* A test that greps a script for the word `setAttribute` passes just as
* well when the script is subtly broken — an unbalanced brace, a typo'd
* property. This runs it against a stand-in document and checks the root
* came out stamped, which is the behaviour the page depends on.
*/
for (const [stored, expected] of [
// The JSON-quoted form is what `createBrowserStore` actually writes, and
// reading it as-is was a real bug: `"dark"` never equals `dark`, so the
// script did nothing and the only symptom was the flash it exists to
// prevent. Both forms are pinned so neither encoding can drift alone.
['"dark"', "dark"],
['"light"', "light"],
["dark", "dark"],
["light", "light"],
['"system"', null],
["system", null],
["nonsense", null],
[null, null],
] as const) {
let attribute: string | null = null;
const fakeWindow = {
localStorage: { getItem: (key: string) => (key === THEME_KEY ? stored : null) },
document: {
documentElement: {
setAttribute: (_name: string, value: string) => {
attribute = value;
},
},
},
};
new Function("localStorage", "document", THEME_SCRIPT)(fakeWindow.localStorage, fakeWindow.document);
assert.equal(attribute, expected, `stored ${String(stored)} should stamp ${String(expected)}`);
}
});
test("it survives storage that throws, which is the private-window case", () => {
let attribute: string | null = null;
const throwing = {
getItem() {
throw new Error("The operation is insecure.");
},
};
const document = {
documentElement: {
setAttribute: (_name: string, value: string) => {
attribute = value;
},
},
};
assert.doesNotThrow(() => new Function("localStorage", "document", THEME_SCRIPT)(throwing, document));
assert.equal(attribute, null);
});
});