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>
51 lines
2.3 KiB
TypeScript
51 lines
2.3 KiB
TypeScript
/**
|
|
* Handing Heidi a question from anywhere on the site.
|
|
*
|
|
* WHAT IT IS FOR. The reference pages are where a learner stalls — a word in
|
|
* the vocabulary list they cannot place, a grammar topic that does not click —
|
|
* and until now the only thing those pages could do about it was show more
|
|
* text. The chat is the product; the pages next to it were a dead end.
|
|
*
|
|
* WHY AN EVENT AND NOT A CONTEXT. The chat dock lives in the root layout,
|
|
* beside `<main>` rather than inside it, and the buttons that ask things live
|
|
* deep inside server-rendered pages. A React context would work, but it would
|
|
* mean wrapping the entire page tree in a client provider so that two
|
|
* components which never render near each other can agree — a structural
|
|
* coupling that has to be maintained by everyone who touches the layout.
|
|
*
|
|
* An event has no structural constraint at all: the dock listens while it is
|
|
* mounted, any page may ask, and neither imports the other. This module exists
|
|
* so that arrangement is not stringly-typed at the call sites — there is one
|
|
* name and one payload shape, both here.
|
|
*
|
|
* NOT A HIDDEN PROMPT. What is dispatched is the sentence the reader would
|
|
* otherwise have typed, and it lands in the transcript as their own ordinary
|
|
* message. The same rule the one-tap follow-ups already follow: a turn you
|
|
* cannot see is a conversation you cannot re-read.
|
|
*/
|
|
|
|
export const ASK_EVENT = "heidi:ask";
|
|
|
|
export type AskDetail = { text: string };
|
|
|
|
/**
|
|
* Ask Heidi something, opening the dock if it is closed.
|
|
*
|
|
* Safe to call during a render pass that never reaches a browser — it simply
|
|
* does nothing on the server, which is what a component that renders in both
|
|
* places needs from it.
|
|
*/
|
|
export function askHeidi(text: string): void {
|
|
const trimmed = text.trim();
|
|
if (!trimmed || typeof window === "undefined") return;
|
|
window.dispatchEvent(new CustomEvent<AskDetail>(ASK_EVENT, { detail: { text: trimmed } }));
|
|
}
|
|
|
|
/** Read a dispatched event's text back out, without trusting its shape. */
|
|
export function askedText(event: Event): string {
|
|
const detail = (event as CustomEvent<unknown>).detail;
|
|
if (!detail || typeof detail !== "object") return "";
|
|
const text = (detail as Record<string, unknown>).text;
|
|
return typeof text === "string" ? text.trim() : "";
|
|
}
|