sovereign-intelligence
Front door to Drake Stapleton's sovereign stack.
Brought by drakestapleton
sovereign-intelligence / docs / archive / drakestapleton.com-old / scripts / check-copy.mjs
| 1 | import { readFileSync, readdirSync } from "node:fs"; |
| 2 | import { extname, join } from "node:path"; |
| 3 | |
| 4 | const roots = ["src/pages", "src/components", "src/data", "src/diagrams"]; |
| 5 | const forbidden = /\b(not|no|never|isn['’]t|wasn['’]t|didn['’]t|don['’]t|doesn['’]t|can['’]t|cannot|won['’]t|without|nobody|nothing|neither|nor|lacked?|unwilling|refus(?:e|ed|ing))\b/gi; |
| 6 | const synthetic = /\b(agentic|delve|tapestry|testament|cutting-edge|seamless|transformative|thought leader)\b/gi; |
| 7 | // HisWords marks the author's own spoken words. His voice is exempt from the |
| 8 | // affirmative-copy rule: the rule governs AI-drafted prose, not him. |
| 9 | const hisWordsOpen = /<HisWords[\s>]/g; |
| 10 | const hisWordsClose = /<\/HisWords>/g; |
| 11 | const findings = []; |
| 12 | |
| 13 | function visit(directory) { |
| 14 | for (const entry of readdirSync(directory, { withFileTypes: true })) { |
| 15 | const path = join(directory, entry.name); |
| 16 | if (entry.isDirectory()) { |
| 17 | visit(path); |
| 18 | continue; |
| 19 | } |
| 20 | if (![".ts", ".tsx"].includes(extname(path))) continue; |
| 21 | const lines = readFileSync(path, "utf8").split("\n"); |
| 22 | let hisWordsDepth = 0; |
| 23 | lines.forEach((line, index) => { |
| 24 | hisWordsOpen.lastIndex = 0; |
| 25 | hisWordsClose.lastIndex = 0; |
| 26 | const opens = [...line.matchAll(hisWordsOpen)].length; |
| 27 | const closes = [...line.matchAll(hisWordsClose)].length; |
| 28 | const inHisWords = hisWordsDepth > 0 || opens > 0; |
| 29 | hisWordsDepth = Math.max(0, hisWordsDepth + opens - closes); |
| 30 | if (inHisWords) return; |
| 31 | for (const pattern of [forbidden, synthetic]) { |
| 32 | pattern.lastIndex = 0; |
| 33 | const matches = [...line.matchAll(pattern)].map((match) => match[0]); |
| 34 | if (matches.length) findings.push(`${path}:${index + 1}: ${matches.join(", ")}`); |
| 35 | } |
| 36 | }); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | roots.forEach(visit); |
| 41 | if (findings.length) { |
| 42 | console.error(findings.join("\n")); |
| 43 | process.exit(1); |
| 44 | } |
| 45 | console.log("copy check passed"); |