/** * The one list of words and names that never reach a player (CLAUDE.md §5.6 * rules 3 and 4). `lint:copy` and the library validator both read it, so the two * can never disagree. * * Matching is whole-word and case-insensitive, with inflections spelled out. * A stem match (`heal*`) would also catch *health*, and a rose can be healthy. * * `treat` is banned outright, including the fox's food: he eats *berries*. * `patient` is banned too. Patience is the cure Gandalf's spirit offers, so the * product may say *patience* and *patiently* but never *patient*. */ export type ForbiddenCategory = 'medical' | 'unnamed-state' | 'little-prince' | 'tolkien'; export interface ForbiddenTerm { readonly term: string; readonly category: ForbiddenCategory; readonly why: string; } const MEDICAL = 'A medical claim pulls the product toward EU medical-device rules (CLAUDE.md §5.6 rule 3). Rosea comforts; it does not treat.'; const UNNAMED = 'The game never names the state for the player (CLAUDE.md §5.6 rule 4). It lets them feel seen instead.'; const PRINCE = 'Nothing from The Little Prince by name or quote: one idea is borrowed, never its text (CLAUDE.md §5.6 rule 3).'; const TOLKIEN = "Gandalf's spirit, never a name or a quote from Tolkien's works (CLAUDE.md §5.6 rule 3)."; const terms = (category: ForbiddenCategory, why: string, list: readonly string[]): ForbiddenTerm[] => list.map((term) => ({ term, category, why })); export const FORBIDDEN: readonly ForbiddenTerm[] = [ ...terms('medical', MEDICAL, [ 'therapy', 'therapies', 'therapist', 'therapists', 'therapeutic', 'therapeutically', 'treat', 'treats', 'treated', 'treating', 'treatment', 'treatments', 'heal', 'heals', 'healed', 'healing', 'healer', 'healers', 'cure', 'cures', 'cured', 'curing', 'curative', 'diagnose', 'diagnoses', 'diagnosed', 'diagnosing', 'diagnosis', 'diagnostic', 'symptom', 'symptoms', 'symptomatic', 'patient', 'patients', 'disorder', 'disorders' ]), ...terms('unnamed-state', UNNAMED, ['lonely', 'lonelier', 'loneliest', 'loneliness']), ...terms('little-prince', PRINCE, [ 'Little Prince', 'Petit Prince', 'Malý princ', 'Saint-Exupéry', 'Saint-Exupery', 'Exupéry', 'Exupery', 'B-612', 'B612' ]), ...terms('tolkien', TOLKIEN, [ 'Tolkien', 'Gandalf', 'Mithrandir', 'Frodo', 'Bilbo', 'Samwise', 'Aragorn', 'Galadriel', 'Sauron', // 'Middle-earth' also matches 'Middle earth': spaces and hyphens are interchangeable in a term. 'Mordor', 'Rivendell', 'Middle-earth', 'hobbit', 'hobbits', 'Lothlórien', 'Lothlorien' ]) ]; export interface ForbiddenHit { readonly term: string; readonly category: ForbiddenCategory; readonly why: string; /** Index into the scanned text. */ readonly index: number; } const escape = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/[\s-]+/g, '[\\s\\u00a0-]+'); // Letters and digits on either side mean it is part of a longer word: *treaty* // does not contain *treat*. Hyphens and apostrophes are boundaries, so // *self-healing* is caught. const PATTERNS = FORBIDDEN.map((entry) => ({ entry, regex: new RegExp(`(?(); for (const { entry, regex } of PATTERNS) { regex.lastIndex = 0; for (let m = regex.exec(text); m !== null; m = regex.exec(text)) { if (!byIndex.has(m.index)) byIndex.set(m.index, { ...entry, index: m.index }); } } return [...byIndex.values()].sort((a, b) => a.index - b.index); }