mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-04 05:17:27 +01:00
* 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>
75 lines
3.4 KiB
TypeScript
75 lines
3.4 KiB
TypeScript
/**
|
|
* Light, dark, or whatever the device says.
|
|
*
|
|
* WHY THIS WAS MISSING AND WHY IT IS ODD THAT IT WAS. `globals.css` has
|
|
* carried a complete dark palette since the cow retheme, in three blocks:
|
|
* `prefers-color-scheme: dark` guarded by `:root:not([data-theme="light"])`,
|
|
* and `:root[data-theme="dark"]`. Those guards only mean something if
|
|
* something stamps `data-theme` on the root — and nothing ever did. The CSS
|
|
* was written for a control that was never built, so a reader whose device is
|
|
* light had no way to ask for dark and a reader whose device is dark had no
|
|
* way to ask for light.
|
|
*
|
|
* THREE STATES, NOT TWO. "System" is a real choice and the right default: it
|
|
* follows the reader's 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 world until somebody touches it.
|
|
*/
|
|
|
|
export const THEME_KEY = "heidi.theme.v1";
|
|
|
|
export const THEMES = ["system", "light", "dark"] as const;
|
|
export type Theme = (typeof THEMES)[number];
|
|
|
|
export const DEFAULT_THEME: Theme = "system";
|
|
|
|
export function isTheme(value: unknown): value is Theme {
|
|
return typeof value === "string" && (THEMES as readonly string[]).includes(value);
|
|
}
|
|
|
|
/** What a stored string means. Anything unrecognised is "system". */
|
|
export function decodeTheme(raw: string | null): Theme {
|
|
return isTheme(raw) ? raw : DEFAULT_THEME;
|
|
}
|
|
|
|
/**
|
|
* Stamp the choice on the root element.
|
|
*
|
|
* "system" REMOVES the attribute rather than setting it to "system", because
|
|
* the stylesheet's dark block is guarded by `:not([data-theme="light"])` — an
|
|
* attribute with an unexpected value would still satisfy that guard, but it
|
|
* would also be a value the CSS never mentions, which is the kind of thing
|
|
* that silently stops matching when somebody tightens a selector.
|
|
*/
|
|
export function applyTheme(theme: Theme, root: HTMLElement): void {
|
|
if (theme === "system") root.removeAttribute("data-theme");
|
|
else root.setAttribute("data-theme", theme);
|
|
}
|
|
|
|
/**
|
|
* The script that runs before the page is painted.
|
|
*
|
|
* WHY AN INLINE SCRIPT AND NOT A REACT EFFECT. An effect runs after the first
|
|
* paint, so a reader who chose dark would see a white page flash to black on
|
|
* every navigation — the defect is called FOUC and it is worse than having no
|
|
* toggle at all, because it happens on every single load.
|
|
*
|
|
* Kept to one statement and wrapped in try/catch: `localStorage` THROWS rather
|
|
* than returning null in a private window and in a browser set to block site
|
|
* data, and an uncaught throw here would run before React and take the whole
|
|
* page down. A reader who blocks storage gets the system theme, which is the
|
|
* correct fallback anyway.
|
|
*
|
|
* It is generated from the constants above rather than written out as a
|
|
* string, so the key and the attribute cannot drift from the module that reads
|
|
* them back.
|
|
*
|
|
* THE QUOTES ARE LOAD-BEARING. `createBrowserStore` writes every value through
|
|
* `JSON.stringify`, so the stored string is `"dark"` — five characters, quotes
|
|
* included. Comparing it to `dark` fails, silently, and the only symptom is
|
|
* the flash this script exists to prevent. Stripping them here is the one
|
|
* place the two encodings meet, and `decodeTheme` does the same on the React
|
|
* side.
|
|
*/
|
|
export const THEME_SCRIPT = `try{var t=localStorage.getItem(${JSON.stringify(THEME_KEY)});if(t){t=t.replace(/^"|"$/g,"")}if(t==="light"||t==="dark"){document.documentElement.setAttribute("data-theme",t)}}catch(e){}`;
|