mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-06 06:28:03 +01:00
* fix(nav): Start means start Signed-in visitors were redirected from the locale root to /chat, on the theory that somebody with an account wants the tool rather than the pitch. The theory is fine. The implementation was wrong: "Start" is a link in the navigation, and a person who presses a link labelled Start expects the start page. Landing them somewhere else makes one of seven nav items a lie — and the one people press when they are lost. The right version of the idea is a different PAGE at the same address, not a different address: signed in, `/` is your dashboard. That needs the dashboard to exist, so it arrives with it, as a rewrite rather than a redirect. `lib/i18n/landing.ts` goes rather than being left unwired. A pure function nobody calls is the same defect as a health check nobody calls — see the neighbouring commit. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FzYBD3sZroCAYeRgTYrpfT * fix(health): the grant check now actually runs `lib/db/usable.ts` has said since it was written that it "runs on every deploy because the health endpoint is what the pipeline waits for". It did not. Nothing outside the test suite called it. That matters more than a stale comment, because the failure it catches is invisible by construction: migrations run as `postgres`, so a new table is owned by `postgres`, the app's own role is granted nothing on it, and every query against it fails with "permission denied" while the process, the connection and `select 1` all stay perfectly healthy. CI cannot see it either — there the test user owns everything. Confirmed by hand after shipping the conversations migration, which is the moment that showed the gap: `/api/health` answered `{"ok":true}` and could not have told anyone whether the two new tables were usable. They were, but only psql on the box could say so. It still answers 200. The process IS alive and a restart cannot fix a missing GRANT, so 503 would only teach the watchdog to restart a healthy process forever while the real problem sat in the database. The answer goes in the body. Computed once per process: a grant changes when a migration runs, a migration runs during a deploy, and a deploy starts a new process — so once per process is exactly right, and the watchdog's polling costs a cached value rather than a catalogue query every few seconds. An unreachable database is not memoised as a verdict, or one blip would brand the build broken until the next deploy. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FzYBD3sZroCAYeRgTYrpfT * feat(review): kept words start coming back Saving a word was the end of the story: the list grew and nothing ever asked you about any of it. This is the layer that makes saving worth doing — scheduling and analysis, both pure and tested, with the surfaces to follow. **The schedule** is expanding fixed intervals (1, 3, 7, 16, 35 days), a wrong answer returning to the start rather than back one step. Deliberately not SM-2 or FSRS: those model someone doing hundreds of reviews a day across thousands of cards, and fitting a curve to a learner's eleven kept words produces confident nonsense of exactly the kind HEIDI.md §8 forbids. Fixed intervals carry the finding the evidence actually supports — later beats sooner — and nothing beyond it. Kim & Webb 2022 (g ≈ 0.76 immediate, ≈ 1.15 delayed) and Yang 2021 (g ≈ 0.50 for being asked over being shown), both already verified in lib/research/sources.ts, which is why the surface will be prompt-then-reveal and never a list of words with their meanings printed beside them. A word nobody has asked about yet is DUE. Not a fallback — you kept it because you did not know it, and it means the feature arrives with everyone's existing list already populated instead of empty for a day. **The schedule fields ride on SavedWord without bumping `version`.** A bump makes `decode` treat every existing browser's list as absent, which is right for a shape that CHANGED and wrong for one that only GREW — it would have silently emptied every saved list in the wild in order to add a feature about not losing things. The decoder had to learn to carry them: it rebuilds each word field by field, so a field it does not name is dropped on every single read, which would have reset the schedule on every page load and made spaced review quietly do nothing. There is a test for exactly that. **"What keeps catching you" is derived, not tracked.** The obvious build is a lookup counter — new instrumentation, a new store, and a record of every word a person failed to understand. The answer is already in the data: six kept words that all turn `k` into `ch` IS the thing catching them. Matching applies the correspondence and asks whether the result moved CLOSER to the target, rather than testing for the letter. `bridge.includes("k")` would claim *Kanton* and *Kaffee* as evidence of k → ch; the substitution test fires only when the correspondence is what actually separates the two forms. A test asserts every parseable rule in the pack explains its own example pair, so a rule string that stops matching fails the build rather than producing a panel that is empty for everyone forever. 308 tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FzYBD3sZroCAYeRgTYrpfT --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
124 lines
4.8 KiB
TypeScript
124 lines
4.8 KiB
TypeScript
import type { DisplayCorrespondence } from "../../variety/display.ts";
|
|
import type { SavedWord } from "./types.ts";
|
|
|
|
/**
|
|
* Which regularities are actually in the words this person kept.
|
|
*
|
|
* "What keeps catching you", derived rather than tracked. The obvious way to
|
|
* build that panel is to count how many times someone looked a word up, which
|
|
* needs new instrumentation, a new store, and a record of every lookup — and
|
|
* the answer is already sitting in the data: six kept words that all turn `k`
|
|
* into `ch` IS the thing catching them. Nothing extra is recorded about
|
|
* anybody to produce it.
|
|
*
|
|
* It is also honest in a way a score is not. The panel says "this pattern is
|
|
* in eleven of your words, here they are" — a fact about their own list, which
|
|
* they can check by looking at it. Not a level, not a percentage, not a
|
|
* weakness rating we cannot support (HEIDI.md §8).
|
|
*
|
|
* THE TEST, and why it is a substitution rather than a keyword match
|
|
*
|
|
* `bridge.includes("k")` would match *Kind* and also *Kuchen*, *Kanton* and
|
|
* every other word with a k in it — most of which are not examples of anything.
|
|
* Applying the rule and asking whether the result moved CLOSER to the target
|
|
* only fires when the correspondence is what actually separates the two forms:
|
|
* *Kind* → *chind* is *Chind* exactly, while *Kuchen* → *chuchen* is no nearer
|
|
* *Chuchi* than it started on the k.
|
|
*/
|
|
|
|
/** `k → ch` becomes `{ from: "k", to: "ch" }`. */
|
|
export type Substitution = { from: string; to: string };
|
|
|
|
/**
|
|
* Split a rule on its arrow.
|
|
*
|
|
* Returns null for anything that is not one — a rule may legitimately describe
|
|
* something no substring swap can express, and the answer there is to skip it,
|
|
* not to guess. `lib/variety/patterns.test.ts` asserts that every rule in the
|
|
* pack which DOES parse actually describes its own example pair, so a rule
|
|
* string that quietly stops matching its example fails the build.
|
|
*/
|
|
export function parseRule(rule: string): Substitution | null {
|
|
const parts = rule.split("→");
|
|
if (parts.length !== 2) return null;
|
|
const from = parts[0].trim().toLocaleLowerCase();
|
|
const to = parts[1].trim().toLocaleLowerCase();
|
|
if (!from || !to || from === to) return null;
|
|
return { from, to };
|
|
}
|
|
|
|
/** Levenshtein. Small strings only — these are single words. */
|
|
export function distance(a: string, b: string): number {
|
|
if (a === b) return 0;
|
|
if (!a.length) return b.length;
|
|
if (!b.length) return a.length;
|
|
|
|
let previous = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
for (let i = 1; i <= a.length; i++) {
|
|
const current = [i];
|
|
for (let j = 1; j <= b.length; j++) {
|
|
current[j] = Math.min(
|
|
previous[j] + 1,
|
|
current[j - 1] + 1,
|
|
previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1),
|
|
);
|
|
}
|
|
previous = current;
|
|
}
|
|
return previous[b.length];
|
|
}
|
|
|
|
/**
|
|
* Does this correspondence explain part of the difference between the two forms?
|
|
*
|
|
* True when applying it to the bridge form moves it strictly closer to the
|
|
* target. Strictly: a substitution that changes nothing, or that makes the word
|
|
* less like the target, is not evidence of anything.
|
|
*/
|
|
export function explains(word: Pick<SavedWord, "target" | "bridge">, sub: Substitution): boolean {
|
|
const target = word.target.trim().toLocaleLowerCase();
|
|
const bridge = word.bridge.trim().toLocaleLowerCase();
|
|
if (!target || !bridge || !bridge.includes(sub.from)) return false;
|
|
|
|
const applied = bridge.replaceAll(sub.from, sub.to);
|
|
if (applied === bridge) return false;
|
|
|
|
return distance(applied, target) < distance(bridge, target);
|
|
}
|
|
|
|
export type Pattern = {
|
|
correspondence: DisplayCorrespondence;
|
|
/** The learner's own words this shows up in, in the order they were kept. */
|
|
words: SavedWord[];
|
|
};
|
|
|
|
/**
|
|
* The patterns in someone's kept words, commonest first.
|
|
*
|
|
* A pattern needs at least `atLeast` words before it is shown. One word is a
|
|
* coincidence, and a panel headed "what keeps catching you" that lists a thing
|
|
* which caught you exactly once is the kind of overstatement this product is
|
|
* supposed to be better than.
|
|
*/
|
|
export function patternsIn(
|
|
words: SavedWord[],
|
|
correspondences: readonly DisplayCorrespondence[],
|
|
atLeast = 2,
|
|
): Pattern[] {
|
|
const found: Pattern[] = [];
|
|
|
|
for (const correspondence of correspondences) {
|
|
const sub = parseRule(correspondence.rule);
|
|
if (!sub) continue;
|
|
|
|
const matching = words.filter((w) => explains(w, sub));
|
|
if (matching.length >= atLeast) found.push({ correspondence, words: matching });
|
|
}
|
|
|
|
// Commonest first, and ties broken by the rule text so the order is stable
|
|
// between renders rather than depending on how the pack happens to be sorted.
|
|
return found.sort(
|
|
(a, b) => b.words.length - a.words.length || a.correspondence.rule.localeCompare(b.correspondence.rule),
|
|
);
|
|
}
|