mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-04 05:37:48 +01:00
* feat(practice): sittings that stay fresh, a level the learner moves, and a summary worth reading Half of every sitting is new while the scope has anything new; reviews that find no seat lead the next one. A question answered and not yet due is not asked again, and a used-up scope says so and offers the wider sitting. One question per word or line per sitting. The level of new questions follows the learner's own setting (easier, just right, harder) and moves by itself on a run of right answers or repeated misses, said in a line with the way back. Five named modes over the existing kinds. The end of a round names what was new, one thing to take away, tomorrow's reviews and how far through the course. Also: «Pack» is gone from what a learner reads, a typed answer is told whether it counts with only the differing words marked, picked tiles are outlined instead of filled, and the session screen cannot be double-tap zoomed. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T * feat(shell): a calmer header, menu, footer and personal page; the languages of Switzerland; du in Swiss German Header: on a phone the bar is the brand, the account and one menu control, as plain glyphs. Language and light/dark moved into the menu sheet (and stay in the settings and the footer); from 1024px the language stays in the bar and its panel carries the appearance. site-header.tsx is 166 lines; the wide bar is header-nav.tsx. Menu sheet: rows with a line saying what is behind each page, one filled action, language and theme at the foot. Footer: the menu's groups, said once. Personal page: one action that names what it starts, one due line, three facts (where you left off, course progress, your words) and everything else behind one disclosure. Situations show their name, started ones only; channels are grouped with dates as people write them; no filled status pills. Languages: /languages and a home section from lib/config/languages.ts — one available, the rest planned, no dates. A 'tell me' form stores address, language, optional region, locale and time in language_interest (migration 0016, additive), rate-limited, listed on the privacy page, erased with the account whose address it is. No confirmation mail is sent, and the form says so. Feedback widget: drawn by the page (footer and menu entry, the widget's data-fc-place=host contract) instead of a tab floating over the text. Copy: Swiss German says du throughout; the German white paper and changelog too. 'Pack' is gone from learner-facing text in all seven dictionaries. French, Italian, Romansh and Russian still address the reader formally. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T * fix(practice): a takeaway that is true on its own, the answered states in the responsive audit The summary's takeaway and its list of new things read a pair that holds by itself (a gap's word is no longer shown beside its whole sentence's meaning) and prefer the line furthest from German. A wrong answer keeps one short part in sight (the reason, else the rule, else the word) and folds the rest under «more on this». «Stimmt» is outlined like every other picked answer. The responsive audit now opens a typed answer, its comparison and a revealed gap, the states a phone reported cut off. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T --------- Co-authored-by: Claude <noreply@anthropic.com>
128 lines
5.7 KiB
TypeScript
128 lines
5.7 KiB
TypeScript
import type { Level } from "../vocabulary/distance.ts";
|
||
import { frontierOf, type LearnerModel } from "./model.ts";
|
||
import type { PracticeItem } from "./types.ts";
|
||
|
||
/**
|
||
* HOW HARD A SITTING IS, as something the learner can move.
|
||
*
|
||
* WHAT WAS MISSING. The level a sitting draws from was decided by the model
|
||
* alone (`frontierOf`): level 1 until twelve answers hold, then 2, then 3.
|
||
* Nobody could say "this is too easy" — and a new learner, held at level 1,
|
||
* met five level-3 questions in ten sittings although two thirds of the
|
||
* course is level 3. The model stays the starting point; this is the lever on
|
||
* top of it.
|
||
*
|
||
* THREE SETTINGS, NOT A SLIDER. `fit` is the model's own level; `easier` and
|
||
* `harder` are one band down and one up. They map onto the three level bands
|
||
* every item already carries (`levels.ts`), so there is no second notion of
|
||
* difficulty to keep in step with the first.
|
||
*
|
||
* IT ALSO MOVES BY ITSELF, AND SAYS SO. `nudgeOf` reads the first answers of
|
||
* the sitting: a run of right answers suggests a step up, repeated misses a
|
||
* step down. The sitting applies it, shows that it did, and offers the way
|
||
* back in the same line — a level that changed silently would be the product
|
||
* deciding for the learner again.
|
||
*
|
||
* Pure. The stored value is the setting alone, per course (`stored.ts`).
|
||
*/
|
||
export type Difficulty = "easier" | "fit" | "harder";
|
||
|
||
/** Easiest first: the order the control shows them in. */
|
||
export const DIFFICULTIES = ["easier", "fit", "harder"] as const satisfies readonly Difficulty[];
|
||
|
||
export const DEFAULT_DIFFICULTY: Difficulty = "fit";
|
||
|
||
const SHIFT: Record<Difficulty, -1 | 0 | 1> = { easier: -1, fit: 0, harder: 1 };
|
||
|
||
export function isDifficulty(value: unknown): value is Difficulty {
|
||
return typeof value === "string" && (DIFFICULTIES as readonly string[]).includes(value);
|
||
}
|
||
|
||
/** Read the stored setting; null for anything that is not one. */
|
||
export function decodeDifficulty(raw: string): Difficulty | null {
|
||
try {
|
||
const value: unknown = JSON.parse(raw);
|
||
return isDifficulty(value) ? value : null;
|
||
} catch {
|
||
return null;
|
||
}
|
||
}
|
||
|
||
/** The level band a sitting aims at: the model's own, moved by the setting, kept inside 1–3. */
|
||
export function targetLevel(model: LearnerModel, difficulty: Difficulty = DEFAULT_DIFFICULTY): Level {
|
||
return Math.min(3, Math.max(1, frontierOf(model) + SHIFT[difficulty])) as Level;
|
||
}
|
||
|
||
/**
|
||
* The settings that change anything for this learner. At level 1 there is
|
||
* nothing easier, at level 3 nothing harder; offering a button that does
|
||
* nothing would be a control that lies. `fit` is always there.
|
||
*/
|
||
export function difficultiesFor(model: LearnerModel): Difficulty[] {
|
||
const fit = targetLevel(model, "fit");
|
||
return DIFFICULTIES.filter((d) => d === "fit" || targetLevel(model, d) !== fit);
|
||
}
|
||
|
||
/** One step easier (-1) or harder (+1); the same value when there is no further step. */
|
||
export function stepDifficulty(difficulty: Difficulty, by: -1 | 1): Difficulty {
|
||
const at = DIFFICULTIES.indexOf(difficulty) + by;
|
||
return DIFFICULTIES[Math.min(DIFFICULTIES.length - 1, Math.max(0, at))]!;
|
||
}
|
||
|
||
/**
|
||
* How far an item is from the level aimed at — 0 on it. Off it, a question
|
||
* ABOVE the target costs less than one below: when the target band runs out,
|
||
* the sitting reaches up before it reaches down. The report this answers was
|
||
* "too easy", never "too hard" — and a question that is its own German
|
||
* teaches nothing to somebody past it, while a harder one at least teaches.
|
||
* Whoever wants the easier band has a button for it.
|
||
*
|
||
* An item with no level (a declared course that declared none) costs 0: it is
|
||
* not known to be off target.
|
||
*/
|
||
export function levelCost(item: PracticeItem, target: Level): number {
|
||
const level = item.source.level;
|
||
if (!level || level === target) return 0;
|
||
return level > target ? level - target : target - level + 2;
|
||
}
|
||
|
||
/**
|
||
* A LEVEL-1 question — «like German» — that the learner answered and never
|
||
* missed does not come back for review once they are past level 1.
|
||
* «Was mached Sie beruflich?» is its own German; asking it five more times on
|
||
* the review schedule teaches nothing and is what made sittings feel too easy
|
||
* (the owner's screenshot, 2026-11-25, with level 1 already holding). One
|
||
* miss and it is reviewed like anything else. On `easier` the target drops
|
||
* back to 1 and it returns.
|
||
*
|
||
* Level 1 only: a level-2 question is a sound rule applied, and that is worth
|
||
* its spaced reviews at any level.
|
||
*/
|
||
export function fadedOut(item: PracticeItem, card: { lapses: number } | undefined, target: Level): boolean {
|
||
return Boolean(card && item.source.level === 1 && target > 1 && card.lapses === 0);
|
||
}
|
||
|
||
/**
|
||
* How many first-try right answers in a row suggest a step up, and how many
|
||
* misses among the last few suggest a step down. OURS, not findings: five in
|
||
* a row is more than half a sitting without an error; three misses in five is
|
||
* a sitting going badly. Stated as constants so each is one decision.
|
||
*/
|
||
export const NUDGE_UP_AFTER = 5;
|
||
export const NUDGE_DOWN = { misses: 3, within: 5 } as const;
|
||
|
||
/**
|
||
* What the sitting's FIRST answers so far suggest: +1 harder, -1 easier, 0
|
||
* stay. Skips are left out (an answer about attention, not knowledge). The
|
||
* caller passes the answers since the level last changed, so one run is not
|
||
* counted twice.
|
||
*/
|
||
export function nudgeOf(firstAnswers: readonly ("right" | "wrong" | "skipped")[]): -1 | 0 | 1 {
|
||
const answers = firstAnswers.filter((o) => o !== "skipped");
|
||
const recent = answers.slice(-NUDGE_DOWN.within);
|
||
if (recent.filter((o) => o === "wrong").length >= NUDGE_DOWN.misses) return -1;
|
||
const run = answers.slice(-NUDGE_UP_AFTER);
|
||
if (run.length === NUDGE_UP_AFTER && run.every((o) => o === "right")) return 1;
|
||
return 0;
|
||
}
|