Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refactor: hoist passive-voice list parse + dedup toWordSet helper (#1622)

[._.]/ Adam Eivy67817327067d
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.js
index 94428eff91..3f46a194c9 100644
--- a/server/lib/editorial/checkRegistry.js
+++ b/server/lib/editorial/checkRegistry.js
@@ -5657,15 +5657,21 @@ export const EDITORIAL_CHECKS = [
{ key: 'extraWords', label: 'Extra participles to flag', type: 'text', help: 'Series-specific irregular participles the heuristic misses, e.g. "begun", "hewn" (comma-separated or one per line).' },
],
gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
- run: (ctx) => runDensityCheck(ctx, {
- scan: (text, cfg) => filterPassiveVoice(
- findPassiveVoice(text, { allowWords: splitPhraseList(cfg?.allowWords), extraWords: splitPhraseList(cfg?.extraWords) }),
- { suppressIntentional: cfg?.suppressIntentional !== false },
- ),
- noun: 'passive constructions',
- problem: (count, rate, anchor) => `${count} passive construction${count === 1 ? '' : 's'} (e.g. "${anchor}") — about ${rate}/1000 words. Heavy passive voice distances the reader from who is acting.`,
- suggestion: 'Rephrase to active voice where it sharpens the prose ("the door was opened by Sam" → "Sam opened the door"). Keep passive where the actor is unknown or beside the point.',
- }),
+ run: (ctx) => {
+ // Parse the word lists once (not per section, the way the adverbs check
+ // hoists its own) — runDensityCheck calls scan() for every section.
+ const allowWords = splitPhraseList(ctx.config?.allowWords);
+ const extraWords = splitPhraseList(ctx.config?.extraWords);
+ return runDensityCheck(ctx, {
+ scan: (text, cfg) => filterPassiveVoice(
+ findPassiveVoice(text, { allowWords, extraWords }),
+ { suppressIntentional: cfg?.suppressIntentional !== false },
+ ),
+ noun: 'passive constructions',
+ problem: (count, rate, anchor) => `${count} passive construction${count === 1 ? '' : 's'} (e.g. "${anchor}") — about ${rate}/1000 words. Heavy passive voice distances the reader from who is acting.`,
+ suggestion: 'Rephrase to active voice where it sharpens the prose ("the door was opened by Sam" → "Sam opened the door"). Keep passive where the actor is unknown or beside the point.',
+ });
+ },
},
{
id: 'prose.repeated-gestures',
diff --git a/server/lib/editorial/proseTics.js b/server/lib/editorial/proseTics.js
index 5536b43ec1..44af97c7a1 100644
--- a/server/lib/editorial/proseTics.js
+++ b/server/lib/editorial/proseTics.js
@@ -185,6 +185,12 @@ function normalizeWord(p) {
return typeof p === 'string' ? p.trim().toLowerCase() : '';
}
+// Normalize a house-style/extra word list into a Set for O(1) membership in the
+// token-loop scanners. Tolerates a non-array (returns an empty Set).
+function toWordSet(words) {
+ return new Set((Array.isArray(words) ? words : []).map(normalizeWord).filter(Boolean));
+}
+
/**
* Tokenize prose into words with their absolute character offsets. Apostrophes
* are kept inside a word ("couldn't") so contractions stay whole. Exported so
@@ -232,7 +238,7 @@ export function splitSentences(text) {
// with flexible internal whitespace (like ./cliches.js). Returns null when the
// effective list (seed + extra − allow) is empty.
function buildListMatcher(seed, opts = {}) {
- const allow = new Set((Array.isArray(opts.allowWords) ? opts.allowWords : []).map(normalizeWord).filter(Boolean));
+ const allow = toWordSet(opts.allowWords);
const extra = (Array.isArray(opts.extraWords) ? opts.extraWords : []).map(normalizeWord).filter(Boolean);
const seen = new Set();
const entries = [];
@@ -326,8 +332,8 @@ function isLyAdverb(lower) {
export function findAdverbs(text, opts = {}) {
const tokens = tokenizeWords(text);
if (!tokens.length) return [];
- const allow = new Set((Array.isArray(opts.allowWords) ? opts.allowWords : []).map(normalizeWord).filter(Boolean));
- const extra = new Set((Array.isArray(opts.extraWords) ? opts.extraWords : []).map(normalizeWord).filter(Boolean));
+ const allow = toWordSet(opts.allowWords);
+ const extra = toWordSet(opts.extraWords);
const tagSet = new Set(DIALOGUE_TAGS);
const out = [];
for (let i = 0; i < tokens.length; i += 1) {
@@ -418,8 +424,8 @@ export function findPassiveVoice(text, opts = {}) {
const tokens = tokenizeWords(text);
if (!tokens.length) return [];
const beSet = new Set(BE_VERBS);
- const allow = new Set((Array.isArray(opts.allowWords) ? opts.allowWords : []).map(normalizeWord).filter(Boolean));
- const extra = new Set((Array.isArray(opts.extraWords) ? opts.extraWords : []).map(normalizeWord).filter(Boolean));
+ const allow = toWordSet(opts.allowWords);
+ const extra = toWordSet(opts.extraWords);
// A participle is recognized when the heuristic OR a series `extraWords` entry
// matches, unless the series allow-listed it.
const isParticiple = (lower) => (isPastParticiple(lower) || extra.has(lower)) && !allow.has(lower);
@@ -506,7 +512,7 @@ function inflect(base) {
// Gesture matcher: each base verb plus its regular inflections (see inflect()).
function gestureMatcher(seed, opts = {}) {
- const allow = new Set((Array.isArray(opts.allowWords) ? opts.allowWords : []).map(normalizeWord).filter(Boolean));
+ const allow = toWordSet(opts.allowWords);
const extra = (Array.isArray(opts.extraWords) ? opts.extraWords : []).map(normalizeWord).filter(Boolean);
const seen = new Set();
const forms = [];
@@ -548,7 +554,7 @@ export function findGestures(text, opts = {}) {
const gestures = [];
if (matcher) {
// Map each inflected surface form back to its base for tally grouping.
- const allow = new Set((Array.isArray(opts.allowWords) ? opts.allowWords : []).map(normalizeWord).filter(Boolean));
+ const allow = toWordSet(opts.allowWords);
const extra = (Array.isArray(opts.extraWords) ? opts.extraWords : []).map(normalizeWord).filter(Boolean);
const formToBase = new Map();
for (const b of [...GESTURE_WORDS, ...extra]) {