Skip to content

rgglez/rgglez-dev-skills / plugins/quiz-from-glossary/skills/quiz-from-glossary

quiz-from-glossary

Verified

Use when asked to create a quiz, test, assessment, or practice questions from a glossary, term list, or vocabulary of definitions, with output as JSON or TypeScript QuizQuestion data (single choice, multiple choice, true/false).

FileKindSize
SKILL.mdskill md10.3 KB
assets/quiz.schema.jsonconfig1.0 KB
assets/types.tsscript290 B
scripts/validate-quiz.mjsscript3.0 KB

scripts/validate-quiz.mjs

View on GitHub
// Validate a quiz JSON file: an array of QuizQuestion objects.
// Usage: node validate-quiz.mjs quiz.json
// Checks assets/quiz.schema.json by hand (no dependencies) plus the
// per-kind rules the schema cannot express. Exit code 1 on any error.
import { readFileSync } from "node:fs";

const QUESTION_KEYS = ["id", "section", "kind", "prompt", "options", "explanation"];
const OPTION_KEYS = ["id", "text", "correct"];
const KINDS = ["single", "multi", "boolean"];

const nonEmpty = (v) => typeof v === "string" && v.trim().length > 0;

function sameKeys(obj, keys) {
  return obj && typeof obj === "object" && !Array.isArray(obj) &&
    Object.keys(obj).length === keys.length && keys.every((k) => k in obj);
}

export function validateQuiz(quiz) {
  const errors = [];
  if (!Array.isArray(quiz) || quiz.length === 0) return ["root: must be a non-empty array of questions"];

  const questionIds = new Set();
  quiz.forEach((q, i) => {
    const at = `question[${i}]${q && q.id ? ` (${q.id})` : ""}`;
    const err = (msg) => errors.push(`${at}: ${msg}`);

    if (!sameKeys(q, QUESTION_KEYS)) return err(`must have exactly the keys ${QUESTION_KEYS.join(", ")}`);
    for (const k of ["id", "section", "prompt", "explanation"]) if (!nonEmpty(q[k])) err(`${k} must be a non-empty string`);
    if (questionIds.has(q.id)) err("duplicate question id");
    questionIds.add(q.id);
    if (!KINDS.includes(q.kind)) return err(`kind must be one of ${KINDS.join(", ")}`);
    if (!Array.isArray(q.options)) return err("options must be an array");

    const optionIds = new Set();
    const texts = new Set();
    for (const [j, o] of q.options.entries()) {
      if (!sameKeys(o, OPTION_KEYS)) { err(`options[${j}] must have exactly the keys ${OPTION_KEYS.join(", ")}`); continue; }
      if (!nonEmpty(o.id) || optionIds.has(o.id)) err(`options[${j}].id must be non-empty and unique`);
      if (!nonEmpty(o.text) || texts.has(o.text.trim().toLowerCase())) err(`options[${j}].text must be non-empty and unique`);
      if (typeof o.correct !== "boolean") err(`options[${j}].correct must be a boolean`);
      optionIds.add(o.id);
      texts.add(String(o.text).trim().toLowerCase());
    }

    const n = q.options.length;
    const right = q.options.filter((o) => o && o.correct === true).length;
    if (q.kind === "single" && (n < 3 || right !== 1)) err(`single needs >= 3 options and exactly 1 correct (has ${n}/${right})`);
    if (q.kind === "multi" && (n < 4 || right < 2 || right === n)) err(`multi needs >= 4 options, >= 2 correct and >= 1 incorrect (has ${n}/${right})`);
    if (q.kind === "boolean" && (n !== 2 || right !== 1)) err(`boolean needs exactly 2 options and 1 correct (has ${n}/${right})`);
  });
  return errors;
}

const file = process.argv[2];
if (!file) {
  console.error("usage: node validate-quiz.mjs <quiz.json>");
  process.exit(2);
}
const errors = validateQuiz(JSON.parse(readFileSync(file, "utf8")));
if (errors.length) {
  console.error(errors.join("\n"));
  process.exit(1);
}
console.log(`OK: ${file}`);
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall