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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
editorial: fix naming check flooding epithet casts with false confusable-name findings
[._.]/ Adam Eivy7a29bc16007a
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex c7bac7e3f1..6d532e0098 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -52,3 +52,4 @@- PM2 standardization no longer assigns ports that are already in use. The analysis now feeds the AI the set of listening/reserved ports (plus the common Vite defaults 5173/5174) to avoid, and a deterministic post-pass reassigns any port that still collides into the 6000–6099 range — so standardizing an app never lands on a port another app already holds.- Editing an app's ports now persists. Port fields are derived from `ecosystem.config.cjs`, so saving only updated PortOS's registry while PM2 kept the old ports and the next config refresh reverted the change. Saving a changed port now rewrites the matching value in the app's `ecosystem.config.cjs` (the source of truth). Restart the app for the new port to take effect.- Editing a **shared or derived** port now persists too. When two port fields resolve to the same literal (e.g. the prod UI is served by the API, so `uiPort === apiPort`), the value-keyed rewrite couldn't tell them apart and the edit returned a 422. The PUT route now falls back to a **per-process-label-targeted** rewrite: it locates the specific process block in `ecosystem.config.cjs` and rewrites only the touched label's port (`api`/`ui`/`devUi`), leaving the sibling field — and any same-valued unrelated number — untouched. Edits to ports that live only under a process's `env`/`args` (no top-level field) persist as well, and an explicit `ports: { ui: N, devUi: N }` map with matching values is split correctly (only the edited key changes). A save that mixes a distinct port and a shared port is written **atomically** — both rewrites are computed in memory and the config file is written once, only when every edit is persistable — so a request that's rejected (422) never leaves the config half-changed. The 422 is reserved for the genuinely unpersistable case (the literal isn't in the touched process block — e.g. it lives in a shared `const PORTS = {…}` referenced via `ports: PORTS.server`, or is computed entirely at runtime), so a shared-value edit never falsely reports success while the displayed port silently reverts. For an app whose prod UI is **served by the API** (no separate UI port), the UI port can't be set on its own — it always follows the API port: the stored UI port is normalized to track the API port on every save (so it never freezes at a stale value), and you change it by changing the API port.+- **The character-name dissimilarity check no longer floods an epithet cast with thousands of false "confusable name" findings.** Two bugs compounded on a cast that uses article-led epithet names ("THE CABARET SINGER", "THE CHAPTER SEVENTEEN READER", …): (1) the check compared on the raw name, so 60+ "THE …" names all read as starting with the same letter and sharing the same 3-character opening; and (2) "same first letter" and "same opening" were counted as two independent similarity signals even though a shared 3-char opening always implies a shared first letter — so any two names sharing a prefix auto-reached the default 2-signal flag threshold. On one 24-issue series this produced ~2,100 spurious naming findings (and a "44 of 69 names start with T" crowding finding that was really just the article "THE"), driving the editorial health score to 0 and hard-pausing Series Autopilot at the health gate. The check now strips a leading article (the/a/an) before comparing names and counts the first-letter/opening overlap once, so it flags names readers would genuinely confuse and an epithet cast is judged on its real distinguishing words. (`server/lib/editorial/nameSimilarity.js`, `server/lib/editorial/checkRegistry.js`)diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.jsindex 6c771437b6..c712e7aa55 100644--- a/server/lib/editorial/checkRegistry.js+++ b/server/lib/editorial/checkRegistry.js@@ -32,7 +32,7 @@ import {analyzeComicLettering,DEFAULT_LETTERING_THRESHOLDS,} from './letteringDensity.js';-import { analyzeNamePair, findFirstLetterClusters, normalizeName } from './nameSimilarity.js';+import { analyzeNamePair, comparisonName, findFirstLetterClusters, normalizeName } from './nameSimilarity.js';import { findCliches, findModifierStacking } from './cliches.js';import { findSaidBookisms, findUnattributedDialogueRuns, attributeDialogueByOwner } from './dialogue.js';import { findItalicThoughts } from './italicThoughts.js';@@ -1728,7 +1728,7 @@ export const EDITORIAL_CHECKS = [// Derive the unlocked members from the tokens (not a name-keyed map) so// two distinct characters sharing an identical name both count.const unlocked = primaries- .filter((t) => !t.locked && normalizeName(t.token)[0] === cluster.letter)+ .filter((t) => !t.locked && comparisonName(t.token)[0] === cluster.letter).map((t) => t.token);const renameHint = unlocked.length? `Consider renaming some of the unlocked ones (${unlocked.join(', ')}) so the cast doesn't blur together.`diff --git a/server/lib/editorial/nameSimilarity.js b/server/lib/editorial/nameSimilarity.jsindex d6091c4417..74bb1ed85e 100644--- a/server/lib/editorial/nameSimilarity.js+++ b/server/lib/editorial/nameSimilarity.js@@ -3,10 +3,31 @@// tested in isolation and reused by any check that needs to reason about how// confusable two character names are. No imports — keeps the registry pure.-// Lowercased letters only ("O'Brien" → "obrien"), the canonical form every-// similarity signal compares against.+// Lowercased letters only ("O'Brien" → "obrien"), the canonical IDENTITY form.+// Used as a dedup/identity key across the editorial checks, so it must NOT strip+// articles — "the reader" and "a reader" are distinct identities. The similarity+// check compares on `comparisonName` (below) instead.export const normalizeName = (s) => String(s || '').toLowerCase().replace(/[^a-z]/g, '');+// Leading-article stripper for the *confusability* comparison only. A cast that+// uses epithet names ("THE CABARET SINGER", "THE CHAPTER SEVENTEEN READER") would+// otherwise read as 60+ names all starting with "the" — every pair sharing the+// first letter AND the 3-char opening, which on its own trips the 2-signal gate+// and floods the check. Comparing on the article-stripped form ("cabaret singer"+// / "chapter seventeen reader") judges the names readers actually disambiguate+// on. Only strips when something remains after the article (so a character+// literally named "The" still compares as "the").+const LEADING_ARTICLE_RE = /^(?:the|a|an)\s+/i;+export function stripLeadingArticle(s) {+ const str = String(s || '').trim();+ const stripped = str.replace(LEADING_ARTICLE_RE, '');+ return stripped.trim() ? stripped : str;+}++// Normalized form the similarity signals compare against: article-stripped, then+// reduced to lowercased letters. ("THE CABARET SINGER" → "cabaretsinger".)+export const comparisonName = (s) => normalizeName(stripLeadingArticle(s));+// The ordered vowel skeleton ("Rachel" → "ae"). Two names sharing this read as// rhythmically similar even when the consonants differ (Blake / Jane → "ae").export const vowelSkeleton = (s) => normalizeName(s).replace(/[^aeiou]/g, '');@@ -94,24 +115,31 @@ export function analyzeNamePair(a, b, opts = {}) {...DEFAULT_SIGNAL_OPTS,...opts,};- const la = normalizeName(a);- const lb = normalizeName(b);+ // Compare on the article-stripped form so epithet casts ("THE …") don't all+ // collide on their leading article (see comparisonName).+ const la = comparisonName(a);+ const lb = comparisonName(b);if (!la || !lb || la === lb) return { signals: [], distance: Infinity, phoneticMatch: false };const signals = [];- if (la[0] === lb[0]) signals.push('same first letter');+ // "same opening" (first 3 chars) STRICTLY IMPLIES "same first letter", so+ // counting both double-counts one similarity: any shared 3-char prefix would+ // alone reach the default 2-signal gate. Emit the more specific signal when it+ // applies, otherwise fall back to the first-letter signal — never both.+ const sameOpening = la.length >= 3 && lb.length >= 3 && la.slice(0, 3) === lb.slice(0, 3);+ if (sameOpening) signals.push('same opening');+ else if (la[0] === lb[0]) signals.push('same first letter');if (flagSameLength && la.length === lb.length) signals.push('same length');if (vowelSkeletonCollision) {- const vsa = vowelSkeleton(a);- if (vsa && vsa === vowelSkeleton(b)) signals.push('same vowel pattern');+ const vsa = vowelSkeleton(la);+ if (vsa && vsa === vowelSkeleton(lb)) signals.push('same vowel pattern');}- if (la.length >= 3 && lb.length >= 3 && la.slice(0, 3) === lb.slice(0, 3)) signals.push('same opening');if (la.length >= 2 && la.slice(-2) === lb.slice(-2)) signals.push('same ending');const distance = levenshtein(la, lb);if (minEditDistance > 0 && distance <= minEditDistance) {signals.push(`near-identical spelling (edit distance ${distance})`);}- const ka = usePhonetic ? soundex(a) : '';- const phoneticMatch = ka !== '' && ka === soundex(b);+ const ka = usePhonetic ? soundex(la) : '';+ const phoneticMatch = ka !== '' && ka === soundex(lb);if (phoneticMatch) signals.push('same phonetic key');return { signals, distance, phoneticMatch };}@@ -121,12 +149,15 @@ export function analyzeNamePair(a, b, opts = {}) {export const nameSimilaritySignals = (a, b, opts = {}) => analyzeNamePair(a, b, opts).signals;// A first-letter histogram over a list of names: Map<letter, name[]> keyed by the-// lowercased first letter (entries with no letters are skipped). The check uses-// this to spot first-letter crowding — a cast where many names start the same way.+// lowercased first letter of the article-stripped name (entries with no letters+// are skipped). The check uses this to spot first-letter crowding — a cast where+// many names start the same way. Keying on the article-stripped form keeps an+// epithet cast ("THE CABARET SINGER", "THE CHAPTER SEVENTEEN READER") from all+// crowding under "T" on their shared leading article.export function firstLetterHistogram(names) {const hist = new Map();for (const name of names) {- const norm = normalizeName(name);+ const norm = comparisonName(name);if (!norm) continue;const letter = norm[0];if (!hist.has(letter)) hist.set(letter, []);@@ -139,7 +170,7 @@ export function firstLetterHistogram(names) {// names AND by at least `maxRatio` of the cast. Returns [{ letter, names, ratio }]// sorted densest-first so the worst crowding surfaces as the first finding.export function findFirstLetterClusters(names, { minCount = 3, maxRatio = 0.4 } = {}) {- const total = names.filter((n) => normalizeName(n)).length;+ const total = names.filter((n) => comparisonName(n)).length;if (!total) return [];const clusters = [];for (const [letter, group] of firstLetterHistogram(names)) {diff --git a/server/lib/editorial/nameSimilarity.test.js b/server/lib/editorial/nameSimilarity.test.jsindex 4fe4db142c..8910c1f64c 100644--- a/server/lib/editorial/nameSimilarity.test.js+++ b/server/lib/editorial/nameSimilarity.test.js@@ -85,6 +85,28 @@ describe('nameSimilaritySignals', () => {expect(nameSimilaritySignals('Zog', 'Bree')).toEqual([]);});+ it('never emits both "same first letter" and "same opening" (no double-count)', () => {+ // A shared 3-char opening strictly implies a shared first letter — counting+ // both would double-count one similarity and trip the 2-signal gate on a+ // mere shared prefix. The more specific "same opening" wins; first-letter is+ // suppressed.+ const sig = nameSimilaritySignals('Marcus', 'Marvin');+ expect(sig).toContain('same opening');+ expect(sig).not.toContain('same first letter');+ // A shared first letter WITHOUT a shared 3-opening still reports first-letter.+ expect(nameSimilaritySignals('Sam', 'Sid')).toContain('same first letter');+ });++ it('strips a leading article before comparing (epithet casts)', () => {+ // "THE CABARET SINGER" vs "THE CHAPTER SEVENTEEN READER" must NOT collide on+ // the shared "THE" — compared on "cabaret…" / "chapter…" they share only a+ // first letter, not the article-driven opening, so they no longer auto-flag.+ const sig = nameSimilaritySignals('THE CABARET SINGER', 'THE CHAPTER SEVENTEEN READER');+ expect(sig).not.toContain('same opening');+ // Two epithet names that reduce to the same word are inert (equal forms).+ expect(nameSimilaritySignals('the reader', 'a reader')).toEqual([]);+ });+it('returns no signals when a name has no letters or names are equal', () => {expect(nameSimilaritySignals('', 'Sam')).toEqual([]);expect(nameSimilaritySignals('Sam', 'sam')).toEqual([]);@@ -136,6 +158,12 @@ describe('firstLetterHistogram', () => {const hist = firstLetterHistogram(['123', '', 'Bo']);expect([...hist.keys()]).toEqual(['b']);});+ it('buckets epithet names by their post-article letter, not the article', () => {+ // "THE CABARET SINGER" / "THE AUDIT-DRONES" must not both land under "t".+ const hist = firstLetterHistogram(['THE CABARET SINGER', 'THE AUDIT-DRONES', 'Mike']);+ expect([...hist.keys()].sort()).toEqual(['a', 'c', 'm']);+ expect(hist.has('t')).toBe(false);+ });});describe('findFirstLetterClusters', () => {@@ -147,6 +175,17 @@ describe('findFirstLetterClusters', () => {expect(clusters[0].names).toEqual(['Mike', 'Mark', 'Matt']);expect(clusters[0].ratio).toBeCloseTo(0.5);});+ it('does not crowd an epithet cast under the article letter', () => {+ // A cast of "THE …" names must not register as "all start with T" — they are+ // bucketed by their real post-article first letter, which is spread out.+ const cast = [+ 'THE CABARET SINGER', 'THE AUDIT-DRONES', 'THE CHILD',+ 'THE READER', 'THE SMUGGLER', 'THE MINISTER',+ ];+ const clusters = findFirstLetterClusters(cast, { minCount: 3, maxRatio: 0.4 });+ expect(clusters.find((c) => c.letter === 't')).toBeUndefined();+ });+it('does not flag a sparse first-letter share in a large cast (2 of 30)', () => {// 2 names start with M; the other 28 spread across 25 non-M letters (3 letters// doubled), so no letter is both shared by ≥3 names and ≥40% of the cast.