From 7d27131a717fee28574ea95d3e79f9eaa3320050 Mon Sep 17 00:00:00 2001 From: devmtnaing Date: Sun, 1 Nov 2026 13:39:38 +0630 Subject: [PATCH] Lesson: remember answers, new-case checks, and pictures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Answered checks are saved per screen, so going Back (or coming back later) shows your answer instead of asking again. Back is on every footer. - Checks now ask about a new case instead of the example the screen just worked through (e.g. the screen does w = 3, the check asks w = 8). - Pictures from a new viz.ts: arrays as grids with highlighted cells, broadcasting with the stretched copies dashed, matmul row × column, softmax and timing bars, and lanes showing w moving toward the target. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01T85pZTr611HcS7wydhD4D7 --- CONTRIBUTING.md | 5 +- src/components/ai/Session.tsx | 38 +++- src/lib/ai/lessons.ts | 314 ++++++++++++++++++++++------------ src/lib/ai/viz.ts | 65 +++++++ src/styles/ai.css | 22 +++ 5 files changed, 324 insertions(+), 120 deletions(-) create mode 100644 src/lib/ai/viz.ts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5c887ca..6322c6d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -260,7 +260,10 @@ under `/ai-engineer` are built from it at build time its correct option and says why. - **Lessons** (the optional *Lesson* step) are in `src/lib/ai/lessons.ts`, keyed by module id like quizzes: one small idea per screen in markdown, each - with a `choice`, `number` or `text` check that has a hint and a why. A lesson + with a `choice`, `number` or `text` check that has a hint and a why. A check + asks about a new case, not the example the screen just worked through. + Pictures (arrays as grids, broadcasting, bars, training steps) come from + `src/lib/ai/viz.ts`, dropped into the markdown on a line of their own. A lesson can name a notebook under `course/` (e.g. `00-setup/notebooks/step-1.ipynb`). The site links it to Colab and GitHub and serves it as a download from `/ai-engineer/notebooks/`. Every exercise in a notebook needs a hidden diff --git a/src/components/ai/Session.tsx b/src/components/ai/Session.tsx index fe013d1..a96760e 100644 --- a/src/components/ai/Session.tsx +++ b/src/components/ai/Session.tsx @@ -458,9 +458,18 @@ function Lesson({ s, exit, finish }: UnitProps) { return 0 } }) - const [sel, setSel] = useState(null) - const [answer, setAnswer] = useState('') - const [status, setStatus] = useState('ask') + // answered checks, by screen title, so going back shows your answer instead of asking again + const ansKey = `lesson-answers:${s.unitId}` + const [saved, setSaved] = useState>(() => { + try { + return JSON.parse(localStorage.getItem(ansKey) ?? '{}') + } catch { + return {} + } + }) + const [sel, setSel] = useState(() => saved[l.screens[idx].title]?.sel ?? null) + const [answer, setAnswer] = useState(() => saved[l.screens[idx].title]?.answer ?? '') + const [status, setStatus] = useState(() => saved[l.screens[idx].title]?.status ?? 'ask') const sc = l.screens[idx] const c = sc.check const last = idx === l.screens.length - 1 @@ -474,18 +483,28 @@ function Lesson({ s, exit, finish }: UnitProps) { }, [idx]) const go = (to: number) => { + const v = saved[l.screens[to].title] setIdx(to) - setSel(null) - setAnswer('') - setStatus('ask') + setSel(v?.sel ?? null) + setAnswer(v?.answer ?? '') + setStatus(v?.status ?? 'ask') window.scrollTo(0, 0) } + const settle = (st: LessonStatus) => { + setStatus(st) + if (st !== 'right' && st !== 'shown') return + const next = { ...saved, [sc.title]: { sel, answer, status: st } } + setSaved(next) + try { + localStorage.setItem(ansKey, JSON.stringify(next)) + } catch {} + } const check = () => { if (!c || answered || !ready) return if (isRight(c, sel, answer)) { if (status === 'ask') addXp(XP.quizCorrect) - setStatus('right') - } else setStatus(status === 'ask' ? 'hint' : 'shown') + settle('right') + } else settle(status === 'ask' ? 'hint' : 'shown') } const next = () => { if (!last) return go(idx + 1) @@ -513,18 +532,21 @@ function Lesson({ s, exit, finish }: UnitProps) { const footer = status === 'right' ? (
Correct!}> + {backBtn}
) : status === 'shown' ? (
}> + {backBtn}
) : status === 'hint' ? (