Spaces:
Running
Running
| /** | |
| * Defamation wording gate — PHASE_1 §13, CLAUDE.md safety. | |
| * Blocked words list matches "user reports / unresolved / alleged" only policy. | |
| * Never label any entity "fraud/scam/criminal". | |
| */ | |
| const BLOCKED_WORDS = ["fraud", "scam", "criminal", "cheater", "thief"]; | |
| const BLOCKED_RE = new RegExp(`\\b(${BLOCKED_WORDS.join("|")})\\b`, "gi"); | |
| const REPLACEMENTS: Record<string, string> = { | |
| fraud: "alleged issue", | |
| scam: "user reports", | |
| criminal: "user reports", | |
| cheater: "unresolved", | |
| thief: "unresolved", | |
| }; | |
| export interface DefamationCheck { | |
| safe: boolean; | |
| flaggedTerms: string[]; | |
| redactedBody: string; | |
| } | |
| export function checkDefamation(body: string): DefamationCheck { | |
| const flaggedTerms: string[] = []; | |
| const replaced = body.replace(BLOCKED_RE, (match) => { | |
| const lower = match.toLowerCase(); | |
| flaggedTerms.push(match); | |
| return REPLACEMENTS[lower] ?? match; | |
| }); | |
| return { | |
| safe: flaggedTerms.length === 0, | |
| flaggedTerms, | |
| redactedBody: replaced, | |
| }; | |
| } | |