Natural reworded openers and exam formatting on finished quizzes
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 29s

Checked against a quiz generated from four neuro and mental health
lectures:
- The opener rewording now asks for the plain, active openings a real
  exam uses and rules out inverted sentences ("Two days of vomiting have
  left a client weak", "An order is received for…"). It steps in only
  above 30% of a quiz, since the exam's most common opener was 24%.
- The finished set is tidied after review: plain stems, no closing
  period on phrase choices, and first-person choices to a "Which
  statement…" question in quotes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-16 15:17:24 -07:00
parent 39a85ebb0c
commit f738fbe7be
5 changed files with 68 additions and 15 deletions

View file

@ -327,6 +327,23 @@ export function plainStem(stem: string): string {
return stem.replace(/\*\*(\S(?:[^*]*?\S)?)\*\*/g, '$1').replace(/__(\S(?:[^_]*?\S)?)__/g, '$1');
}
/** A first-person choice to a "Which statement…" question is quoted speech, as on the exam. */
export function quoteStatement(text: string): string {
const t = text.trim();
if (/^["“‘']/.test(t) || !/^(?:I|I'm|I'll|I've|I'd|We|We'll|We're|My|Our)\b/.test(t)) return t;
return `"${/[.!?]$/.test(t) ? t : `${t}.`}"`;
}
/**
* Exam choices are phrases without a closing period ("Place the child in a knee-chest position").
* Quoted speech and choices of more than one sentence keep their punctuation.
*/
export function plainChoice(text: string): string {
const t = plainStem(text.trim());
if (/^["“‘']/.test(t) || /[.!?]\s/.test(t) || /\b(?:etc|e\.g|i\.e|vs)\.$/i.test(t)) return t;
return t.replace(/(?<!\.)\.$/, '');
}
/** 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.';
@ -1217,6 +1234,14 @@ async function runGeneration(app: AppContext, draftId: string, req: GenerateRequ
}
}
// Exam formatting on the finished set, including questions the review rewrote.
if (draft.kind === 'quiz') {
draft.questions = draft.questions.map((q) => {
const speech = /\bstatements?\b/i.test(q.stem);
return { ...q, stem: plainStem(q.stem), options: q.type === 'numeric' ? q.options : q.options.map((o) => ({ ...o, text: plainChoice(speech ? quoteStatement(o.text) : o.text) })) };
});
}
// A short name and description of what this particular set covers.
if (!req.title) {
setProgress(db, draftId, 0.99, 'Naming the set', draft);