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

address review (claude): match punctuation-terminated names via lookarounds in roster.economy

[._.]/ Adam Eivy68211d54fcad
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.js
index 873b04e3f8..4514b9af55 100644
--- a/server/lib/editorial/checkRegistry.js
+++ b/server/lib/editorial/checkRegistry.js
@@ -670,7 +670,7 @@ function characterNameTokens(c) {
return [...new Set(tokens)];
}
-// A case-insensitive, word-bounded matcher for a character's tokens (built once
+// A case-insensitive, whole-token matcher for a character's tokens (built once
// per character and reused across every section so a long manuscript isn't
// re-compiling a regex per section), or null when there are no tokens.
function characterMatcher(tokens) {
@@ -678,7 +678,11 @@ function characterMatcher(tokens) {
// Longest-first so a token that's a prefix of another can't shadow it under
// leftmost-match alternation (cosmetic for .test, but keeps intent clear).
const alt = tokens.slice().sort((a, b) => b.length - a.length).map(escapeRegExp).join('|');
- return new RegExp(`\\b(?:${alt})\\b`, 'i');
+ // Lookarounds, not \b: a token that begins or ends with punctuation ("Mr.",
+ // "T.A.R.D.I.S.", "J.R.") has no word char at that edge, so a leading/trailing
+ // \b would never match it in prose. (?<!\w)…(?!\w) enforces whole-token matching
+ // at any edge while still rejecting substrings (Sam ≠ "Samuel").
+ return new RegExp(`(?<!\\w)(?:${alt})(?!\\w)`, 'i');
}
// One row per NAMED canon character: { id, name, locked, appearedInIssues,
diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.js
index aa584155cc..d44230cad9 100644
--- a/server/lib/editorial/checkRegistry.test.js
+++ b/server/lib/editorial/checkRegistry.test.js
@@ -455,6 +455,15 @@ describe('roster.economy — deterministic check', () => {
expect(findings).toEqual([]); // 0 appearances → nothing to flag
});
+ it('matches names that end in punctuation as whole tokens (lookaround, not \\b)', () => {
+ // A trailing \b can't match a token ending in "." — lookarounds handle any edge.
+ const findings = runRoster(
+ [{ name: 'J.R.' }, { name: 'Aria' }],
+ [sec(1, 'J.R. arrived at dawn.'), sec(2, 'Aria mused; Aria left.')],
+ );
+ expect(throwaways(findings).some((f) => /"J\.R\."/.test(f.problem))).toBe(true);
+ });
+
it('counts appearances via aliases, attributing to the canonical name', () => {
const findings = runRoster(
[{ name: 'Robert', aliases: ['Bob'] }, { name: 'Aria' }],