diff --git a/PROGRESS.md b/PROGRESS.md index 406d24c..87167c0 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -219,7 +219,7 @@ stored DeepSeek connection still holding the old key; it was updated from `.env` ## Verification status Baseline: 162 tests passed, TypeScript passed and production web/server builds passed. -Added six regression tests. Full `npm run check` passes: **290 tests** (V1 importer removed, 2026-11-16; 291 after full-backup restore; 289 after rationale layout; 285 after varied openers; 281 after generation steps; 280 after the check loop and second review; 274 after the fifth revision; 261 after share-link generation, 2026-11-15; 257 after the fourth revision; 247 after the third, 208 after the second, 181 on 2026-11-12), TypeScript +Added six regression tests. Full `npm run check` passes: **291 tests** (exam-style questions, 2026-11-16; 290 after V1 importer removed; 291 after full-backup restore; 289 after rationale layout; 285 after varied openers; 281 after generation steps; 280 after the check loop and second review; 274 after the fifth revision; 261 after share-link generation, 2026-11-15; 257 after the fourth revision; 247 after the third, 208 after the second, 181 on 2026-11-12), TypeScript and both production builds. The Docker `test` stage runs the same 181 tests on Node 24. Tests were run with loopback access for the mock provider. The earlier agent manually exercised quiz completion/results, flashcards, streak effects, diff --git a/docs/AI.md b/docs/AI.md index 5592827..704968d 100644 --- a/docs/AI.md +++ b/docs/AI.md @@ -93,6 +93,20 @@ from the original, keeps "Select all that apply." and no longer opens the repeat Calculations keep their wording. The writing rules, the batch prompt (which names openers already overused) and the planner (setting, role, trigger) also ask for varied openings. +**Item style** is modelled on a real course exam (`NCLEX_RULES`, editable in Settings → +Templates as "NCLEX style"). Stems are short and plain, usually 15 to 30 words: only the cues +needed, then one direct question in the exam's own phrasing ("Which action should the nurse take +first?", "Which statement by the parent indicates a need for further teaching?"), in one +paragraph with no scene-setting that does not change the answer. About a third may ask directly +about a fact the nurse uses (an injection site, a pain tool, expected lab results). Bold or +underlined words are removed from generated stems (`plainStem`). Choices are concise and +parallel: a term or value when that is what is asked, a 4 to 12 word action or finding, or quoted +speech for client statements and nurse responses. Explanations go in each choice's "why" (1 or +2 sentences), not on the end of the choice. Distractors come from related facts in the material. +Select-all items have exactly 6 choices with 2 to 5 correct, most often 3 or 4. The same rules +appear in the batch prompt, the planner, the review and proofread rewrites, "improve questions" +and the outside-chatbot instructions. + **Rationales** are asked for as Markdown: one bold key sentence, then 2 to 4 short bullet points, without repeating the per-choice "why" (`RATIONALE_FORMAT`, also in the question schema, the review's rewrite schema, "improve questions" and the outside-chatbot instructions). The web app diff --git a/server/ai/generate.ts b/server/ai/generate.ts index 5be98cb..19be8c4 100644 --- a/server/ai/generate.ts +++ b/server/ai/generate.ts @@ -322,6 +322,11 @@ export type GenerateRequest = z.infer; /* ------------------------------ prompts ------------------------------ */ +/** Exam stems carry no emphasis: bold or underlined words in a generated stem become plain text. */ +export function plainStem(stem: string): string { + return stem.replace(/\*\*(\S(?:[^*]*?\S)?)\*\*/g, '$1').replace(/__(\S(?:[^_]*?\S)?)__/g, '$1'); +} + /** How a rationale is laid out, so it reads at a glance instead of as one block of text. */ const RATIONALE_FORMAT = 'Format the rationale in Markdown for quick reading: one bold sentence with the key point, then 2 to 4 short bullet points (one idea each, such as the principle or framework, the physiology or drug action, the safety point). No long paragraphs, and do not repeat the choices\' "why" text, which is shown beside each choice.'; @@ -339,16 +344,16 @@ const QUESTION_SCHEMA = { enum: ['single', 'multi', 'numeric'], description: 'single = one correct answer; multi = select all that apply; numeric = a calculation the student answers by typing the number', }, - stem: { type: 'string', description: 'The question. Markdown allowed.' }, + stem: { type: 'string', description: 'The question, usually 15 to 30 words: a short situation with only the cues needed, then one direct question. One plain paragraph, no bold or italics.' }, options: { type: 'array', description: 'Answer choices. For numeric questions: exactly one option, the correct answer with its unit (e.g. "12.5 mL"), correct = true, and "why" showing the calculation.', items: { type: 'object', properties: { - text: { type: 'string' }, + text: { type: 'string', description: 'The choice only, parallel to the other choices: a term or value, a short action or finding (about 4 to 12 words), or one or two sentences of quoted speech. No explanation tacked on.' }, correct: { type: 'boolean' }, - why: { type: 'string', description: 'One sentence on why this choice is right or wrong.' }, + why: { type: 'string', description: '1 or 2 sentences: the specific clinical reason this choice is right or wrong.' }, }, required: ['text', 'correct', 'why'], }, @@ -397,16 +402,18 @@ const MATH_LEVELS: Record = { const NUMERIC_RULE = `- Only write calculation items when the source material itself involves calculations (or the request asks for medication math), and never more than the number allowed in the request. Calculation items (dosages, weight-based doses, IV and drip rates, conversions, intake and output) use type "numeric": the student types the number instead of choosing. Give exactly one option, the correct answer with its unit (for example "12.5 mL"), marked correct, with "why" showing the working. State the unit and the rounding rule in the stem ("Round to the nearest tenth."). Only the number is checked, so the student may leave out the unit.`; -const NCLEX_RULES = `Write NCLEX-style (Next Generation NCLEX) items: -- Test clinical judgment at the application and analysis level: recognise cues, analyse, prioritise, choose and evaluate actions. Avoid pure recall. -- Give a brief, realistic client scenario containing only relevant data (age, diagnosis, key findings, vital signs or lab values with units). -- Vary how stems open, as a real exam does: with the client ("A 68-year-old client…", "A client with…"), the nurse's situation ("The nurse is caring for…", "After receiving report…"), the setting or role ("In the emergency department…", "The charge nurse…", "During discharge teaching…"), a finding, order or report ("A client with heart failure reports…", "The health care provider prescribes…"), or the question itself. Mix these so no single opening dominates the quiz. -- Ask one clear question. Use priority wording where it fits (first, best, most important, requires immediate follow-up) and build it on a real framework: ABCs, Maslow, the nursing process, acute before chronic, unstable before stable, safety, least invasive first. +const NCLEX_RULES = `Write NCLEX-style (Next Generation NCLEX) items that read like a real nursing exam: +- Test clinical judgment: recognise cues, analyse, prioritise, choose and evaluate actions. Most questions are a short client situation that needs a decision, and many need two cues put together (a symptom plus a lab value, a risk factor plus a presentation, a treatment plus an adverse finding). About a third may ask directly about a fact the nurse uses, still framed around the nurse or client ("Which injection site is most appropriate?", "Which laboratory results should the nurse expect?", "Which mechanism of heat loss is the nurse most concerned about?"). Mix assessment, expected findings, complications, diagnostic results, treatment decisions, safety, teaching and priority questions. +- Keep stems short and plain, usually 15 to 30 words: at most one or two sentences of situation with only the cues needed (the age, diagnosis, key findings, vital signs or lab values with units), then one direct question. Leave out scene-setting that does not change the answer (the unit, the clinic, the time of day). Typical questions: "Which action should the nurse take first?", "What is the nurse's priority action?", "Which finding requires follow-up?", "Which finding should the nurse report immediately?", "Which response by the nurse is best?", "Which statement by the parent indicates a need for further teaching?", "Which statement shows understanding?", "Which nursing action is contraindicated?", "Which client should the nurse assess first?", "Which instructions should the nurse include? Select all that apply." Write the stem as one paragraph, with no bold, italics or other emphasis. +- Vary how stems open, as a real exam does: with the client ("A 4-year-old with…", "A client with…", "A newborn…"), the nurse ("The nurse is teaching…", "The nurse receives report on four clients."), a family member ("The parent of a…", "A parent calls the clinic…"), a time or event ("Two weeks after…", "Immediately after…", "During a well-child visit…"), or the question itself ("Which finding in a 2-day-old newborn…"). Mix these so no single opening dominates the quiz. +- Use priority wording where it fits (first, best, most important, requires immediate follow-up) and build it on a real framework: ABCs, Maslow, the nursing process, acute before chronic, unstable before stable, safety, least invasive first. - Cover the client-needs areas where the material allows: safe and effective care, pharmacology, physiological adaptation, reduction of risk, health promotion, psychosocial integrity, delegation and assignment. -- Every distractor must be plausible to a student with partial knowledge and wrong for a specific reason. Keep choices parallel in grammar and similar in length. Never use "all of the above" or "none of the above". Do not give the answer away through wording or length. -- Multiple-choice items have exactly 4 choices with exactly one best answer. Select-all-that-apply items have 5 or 6 choices with 2 to 5 correct, and the stem ends with "Select all that apply." -- Use generic drug names. Use current, standard practice. -- The rationale teaches: state why the correct answer is correct, name the principle behind it, and give each choice its own "why". +- Answer choices are concise and parallel. When the question asks for a term, site, tool, value or condition, each choice is just that ("Conduction", "Vastus lateralis", "FLACC scale", "0.8 mL"). Actions and findings are short phrases, usually 4 to 12 words ("Place the child in a knee-chest position", "Cola-colored urine and puffy eyelids"). Statements by a client or parent, and responses by the nurse, are quoted speech of one or two sentences. Do not tack explanations onto action or finding choices ("…so that…", "…to prevent…"): the explanation belongs in "why". A quoted nurse response may give its reason ("…because the symptoms can come back"), but then the other responses do too, so a reason never marks the answer. Write every choice of a question in the same form and about the same length, and do not let the correct one stand out as the longest, most specific or most qualified. +- Build distractors from related facts in the same material: a similar condition, a different stage or time frame, another test or drug, an intervention that is right for a related condition, a common misconception. Each must be plausible to a student with partial knowledge and wrong for a specific reason, and at least two in every multiple-choice item need real content knowledge to rule out. No absurd, obviously unsafe or simple opposite-action choices, and never invent terms, conditions or procedures. Never use "all of the above" or "none of the above". Do not give the answer away through wording or length. +- Multiple-choice items have exactly 4 choices with exactly one best answer. Select-all-that-apply items have exactly 6 choices with 2 to 5 correct, most often 3 or 4, and always at least one plausible wrong choice. The stem ends with "Select all that apply." +- Never refer to the source in a stem or choice ("according to the study guide", "listed in the slides", "in the material"): every question reads as a standalone clinical question. +- Use clear, direct exam language, without contractions or a conversational tone (quoted client statements may sound natural). Use generic drug names and current, standard practice. +- Give each choice a "why" of 1 or 2 sentences with the specific clinical reason that choice is right or wrong, about that choice's own content rather than a restatement of the correct answer. - ${RATIONALE_FORMAT} ${NUMERIC_RULE}`; @@ -944,6 +951,7 @@ async function runGeneration(app: AppContext, draftId: string, req: GenerateRequ `Topic labels must be broad (the main condition, drug class or body system, 1-3 words), not subtypes or aspects.${topicsSoFar.length ? ` Reuse these existing topics wherever they fit: ${topicsSoFar.slice(0, 40).join(', ')}.` : ''}`, difficulty === 'mixed' ? 'Mix difficulty: mostly medium, with a few easy and a few hard.' : `Difficulty: ${difficulty}.`, 'Vary how the stems open (the client and their age, the nurse\'s situation, the setting, a finding or order, or the question itself) so no single opening dominates.', + 'Keep stems short and plain (usually 15 to 30 words, no bold, no scene-setting that does not change the answer), and keep answer choices concise and parallel with no explanation tacked on: the reasons go in each choice\'s "why".', draft.kind === 'quiz' ? openerAdvice(draft.questions) : '', sources.groups.length > 0 ? 'Spread the questions across the excerpts instead of clustering on one. Set "source" to the id of the excerpt each question is based on.' : '', req.source.deckId ? 'Turn the flashcards into questions: use each card\'s answer as the correct choice and write distractors that a student could confuse with it.' : '', @@ -987,6 +995,7 @@ async function runGeneration(app: AppContext, draftId: string, req: GenerateRequ } if ('stem' in item && item.type === 'numeric' && (numericLeft === 0 || numericCount() >= numericCap)) continue; // over the calculation allowance; a top-up replaces it if (math && (!('stem' in item) || item.type !== 'numeric')) continue; // a math batch keeps only calculations + if ('stem' in item) item.stem = plainStem(item.stem); if ('stem' in item && item.type !== 'numeric') item.options = shuffleOptions(item.options); seen.add(k); (items() as (DraftQuestion | DraftCard)[]).push(item); @@ -1012,7 +1021,7 @@ async function runGeneration(app: AppContext, draftId: string, req: GenerateRequ task: 'plan', purpose: 'planning questions', modelId: req.modelId, - system: `${baseSystem(db, req, hasSources)}\n\nYou plan NCLEX-style quizzes. List distinct angles, one per question: each names the client situation and the single decision or fact it tests, in one line (for example "Continuous IV heparin, aPTT 3x control with gum bleeding: first action"). No two angles may test the same decision, fact or teaching point, even in a different scenario. Vary the framing too: the setting (unit, clinic, home, emergency department), the nurse's role (bedside, charge nurse, delegating, teaching) and what prompts the question (a finding, a report, an order, a call light). Spread them over the client-needs areas the material supports (pharmacology, safety, prioritisation, delegation, teaching, lab values, complications, psychosocial). When the material is short, vary the situations and the area tested rather than repeating its points.`, + system: `${baseSystem(db, req, hasSources)}\n\nYou plan NCLEX-style quizzes. List distinct angles, one per question: each names the client situation and the single decision or fact it tests, in one line (for example "Continuous IV heparin, aPTT 3x control with gum bleeding: first action"). No two angles may test the same decision, fact or teaching point, even in a different scenario. Vary the kind of question too: a priority action, a finding to report or follow up, an expected finding or lab result, teaching and what a statement shows about understanding, a nurse's response, which client to see first, delegation, and some direct questions about a fact the nurse uses (the right site, tool, test or precaution). Vary what prompts the question (a finding, a report, an order, a family member's question) without adding scene-setting that does not change the answer. Spread them over the client-needs areas the material supports (pharmacology, safety, prioritisation, delegation, teaching, lab values, complications, psychosocial). When the material is short, vary the situations and the area tested rather than repeating its points.`, messages: [ { role: 'user', @@ -1428,8 +1437,9 @@ export function startImprove(app: AppContext, input: z.input { expect(acceptRewording(original, 'A 72-year-old client on the unit has a potassium of 3.1 mEq/L and a heart rate of 52.', repeated)).toBeNull(); }); }); + +describe('plain stems', () => { + it('drops bold and underline emphasis from generated stems but keeps the words', async () => { + const { plainStem } = await import('../server/ai/generate.ts'); + expect(plainStem('Which instruction is **most important for absorption**?')).toBe('Which instruction is most important for absorption?'); + expect(plainStem('Give __elexacaftor__ with fat.')).toBe('Give elexacaftor with fat.'); + expect(plainStem('A dose of 2 * 3 mg is ordered.')).toBe('A dose of 2 * 3 mg is ordered.'); + }); +});