|
| 1 | +# AI-Assisted Quiz Generation — Skill Injection, Per-Card Model, Mode Toggle |
| 2 | + |
| 3 | +- Added `QUIZ_SYNTAX_SKILL` constant — comprehensive syntax reference injected into AI prompts for accurate quiz generation |
| 4 | +- Added `postProcessQuizLines()` — auto-fixes common AI output errors (missing colons, swapped MCQ pipes, wrong types) |
| 5 | +- Added `@prompt:` field to quiz parser — users can describe quizzes in natural language instead of manually writing `@question` lines |
| 6 | +- Added AI prompt textarea to quiz card UI — renders below the header for free-text quiz descriptions |
| 7 | +- Added per-card AI model selector dropdown — creators can choose which model generates questions for each quiz |
| 8 | +- Added Practice/Test mode toggle button — clickable pill in card header syncs `@mode:` to the editor |
| 9 | +- Added model-readiness handling with try/catch — shows toast instead of crashing if model isn't loaded |
| 10 | +- Added `runAiPrompt` callback fallback for backward compatibility |
| 11 | +- Creator's Next button is always enabled — no longer blocked until answering in preview mode |
| 12 | +- Fixed: `{{Quiz :}}` with space before colon now parses correctly (`\s*` before `:`) |
| 13 | +- Fixed: AI-generated `@hint:` lines are now preserved alongside `@question` lines |
| 14 | +- Added CSS styles for `.quiz-dg-prompt-area`, `.quiz-dg-prompt-input`, `.quiz-dg-gen-prompt` |
| 15 | +- Added CSS styles for `.quiz-dg-model-select` dropdown |
| 16 | +- Added CSS styles for `.quiz-dg-mode-toggle` button with Practice (green) / Test (purple) states |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## Summary |
| 21 | +Implements AI-assisted quiz creation using the Skill Injection pattern from `game-docgen.js`. Users can now describe a quiz in plain language (via `@prompt:` or the prompt textarea), pick a model, and click Generate to produce correctly-formatted `@question` markup. A post-processor auto-fixes common AI syntax errors. |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## 1. Quiz Syntax Skill Injection |
| 26 | +**Files:** `js/quiz-docgen.js` |
| 27 | +**What:** Added `QUIZ_SYNTAX_SKILL` constant (~40 lines) containing the complete quiz syntax reference with explicit pipe-format documentation for all 8 question types. This is prepended to every AI generation request. |
| 28 | +**Impact:** The AI receives exact formatting rules, producing valid `@question[mcq]:`, `@question[tf]:`, etc. markup instead of guessing the syntax. |
| 29 | + |
| 30 | +## 2. Post-Processor for AI Output |
| 31 | +**Files:** `js/quiz-docgen.js` |
| 32 | +**What:** Added `postProcessQuizLines()` function that fixes missing colons (`@question[mcq] ` → `@question[mcq]: `), swapped MCQ pipe order, and filters non-question lines. |
| 33 | +**Impact:** Even imperfect AI output gets corrected into valid quiz markup before insertion. |
| 34 | + |
| 35 | +## 3. `@prompt:` Field & Prompt Textarea |
| 36 | +**Files:** `js/quiz-docgen.js`, `css/quiz-docgen.css` |
| 37 | +**What:** Added `@prompt:` parser field (multi-line, same pattern as `@chapter:`), prompt textarea UI in quiz cards, and debounced sync back to editor markdown. |
| 38 | +**Impact:** Users can type "Create 10 biology questions on photosynthesis" instead of manually writing `@question` lines. |
| 39 | + |
| 40 | +## 4. Per-Card Model Selector |
| 41 | +**Files:** `js/quiz-docgen.js`, `css/quiz-docgen.css` |
| 42 | +**What:** Added `<select>` dropdown populated from `window.AI_MODELS`, filtering out image/TTS/STT models. On change, triggers local model download or API key prompt. |
| 43 | +**Impact:** Each quiz card can use a different AI model for generation. |
| 44 | + |
| 45 | +## 5. Practice/Test Mode Toggle |
| 46 | +**Files:** `js/quiz-docgen.js`, `css/quiz-docgen.css` |
| 47 | +**What:** Replaced static "📝 Test" badge with clickable toggle button. Click handler syncs `@mode:` field to editor markdown via regex replace or insertion. |
| 48 | +**Impact:** Creators can switch quiz mode with a single click instead of editing markdown. |
| 49 | + |
| 50 | +## 6. Creator Navigation Fix |
| 51 | +**Files:** `js/quiz-docgen.js` |
| 52 | +**What:** Changed `navDisabled` from `(b.mode === 'test') ? '' : 'disabled'` to `(!isRespondent || b.mode === 'test') ? '' : 'disabled'`. |
| 53 | +**Impact:** Creators can freely navigate through all questions to preview; only respondents in practice mode must answer first. |
| 54 | + |
| 55 | +## 7. Flexible Quiz Tag Parsing |
| 56 | +**Files:** `js/quiz-docgen.js` |
| 57 | +**What:** Added `\s*` before `:` in both parser and transform regexes. |
| 58 | +**Impact:** `{{Quiz : title}}`, `{{Quiz: title}}`, and `{{Quiz : title}}` all work. |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## Files Changed (2 total) |
| 63 | + |
| 64 | +| File | Lines Changed | Type | |
| 65 | +|------|:---:|------| |
| 66 | +| `js/quiz-docgen.js` | +331 −34 | Skill injection, @prompt parser, model selector, mode toggle, post-processor | |
| 67 | +| `css/quiz-docgen.css` | +114 −0 | Styles for prompt area, model dropdown, mode toggle | |
0 commit comments