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

fix: dedupe split-quote dialogue tags by verb offset, not match start

[._.]/ Adam Eivy127644aa5311
diff --git a/server/lib/editorial/dialogue.js b/server/lib/editorial/dialogue.js
index e497144e4d..0ce76e1cbb 100644
--- a/server/lib/editorial/dialogue.js
+++ b/server/lib/editorial/dialogue.js
@@ -143,10 +143,14 @@ function buildTagMatchers(forms) {
// ends a quote with a comma when a tag follows ("…," she said) and a period
// when the dialogue is a complete sentence and the next clause is a separate
// action beat ("…." She smiled.) — a period-terminated quote is NOT a tag.
- const after = new RegExp(`([,.!?])?${DQUOTE_CLASS}\\s+(?:${SPEAKER}\\s+)?${VERB}\\b`, 'gi');
+ // The `d` (hasIndices) flag exposes each capture group's offset via match
+ // `.indices`, so scanTagMatchers can dedupe on the VERB's absolute position —
+ // a split-quote tag ("Yes," she said, "but…") is seen by BOTH passes at
+ // different match starts but the same verb offset, so it counts once.
+ const after = new RegExp(`([,.!?])?${DQUOTE_CLASS}\\s+(?:${SPEAKER}\\s+)?${VERB}\\b`, 'gid');
// Before an opening quote: speaker → verb → optional comma/colon → quote. This
// ordering is unambiguously a tag, so no punctuation gate is needed. Group 1 = verb.
- const before = new RegExp(`\\b${SPEAKER}\\s+${VERB}\\s*[,:]?\\s*${DQUOTE_CLASS}`, 'gi');
+ const before = new RegExp(`\\b${SPEAKER}\\s+${VERB}\\s*[,:]?\\s*${DQUOTE_CLASS}`, 'gid');
return { after, before };
}
@@ -186,12 +190,16 @@ function scanTagMatchers(text, matchers, onMatch) {
while ((m = re.exec(text)) !== null) {
const matched = m[verbGroup];
const punct = punctGroup !== null ? (m[punctGroup] || '') : null;
- const res = onMatch(matched, m.index, punct, m[0]);
+ // De-dup and anchor on the VERB's absolute offset (via the `d`-flag capture
+ // indices), not the match start — a split-quote tag matches in BOTH passes
+ // at different starts but the same verb offset, so it counts once.
+ const verbIndex = m.indices?.[verbGroup]?.[0] ?? m.index;
+ const res = onMatch(matched, verbIndex, punct, m[0]);
if (!res) continue;
- const key = `${res.verb}@${m.index}`;
+ const key = `${res.verb}@${verbIndex}`;
if (seen.has(key)) continue;
seen.add(key);
- out.push({ ...res, index: m.index });
+ out.push({ ...res, index: verbIndex });
}
}
return out.sort((a, b) => a.index - b.index);
diff --git a/server/lib/editorial/dialogue.test.js b/server/lib/editorial/dialogue.test.js
index f641c5c02c..fb1ecce2f2 100644
--- a/server/lib/editorial/dialogue.test.js
+++ b/server/lib/editorial/dialogue.test.js
@@ -292,6 +292,14 @@ describe('inventoryDialogueTags', () => {
expect(inventoryDialogueTags('The engine said nothing as it idled.')).toHaveLength(0);
});
+ it('counts a split-quote tag once, not twice (both passes match it)', () => {
+ // The after-quote pass sees ',” she said' and the before-quote pass sees
+ // 'she said, “' — same verb token, so it must dedupe to one tag.
+ const tags = inventoryDialogueTags('"Yes," she said, "but only once."');
+ expect(tags).toHaveLength(1);
+ expect(tags[0].verb).toBe('say');
+ });
+
it('does not count an action beat after a complete (period-terminated) line', () => {
// "She added a log to the fire." is narration, not a tag — the quote ended on a period.
expect(inventoryDialogueTags('"Done." She added a log to the fire.')).toHaveLength(0);
@@ -362,6 +370,17 @@ describe('findDialogueTagVariety', () => {
expect(findDialogueTagVariety('"A," she said.\n"B," he said.')).toHaveLength(0);
});
+ it('does not double-count split-quote tags into a false monotony finding', () => {
+ // Three split-quote "said" lines = 3 tags. If each were counted twice (6),
+ // the default minTags/monotonyCount of 6 would falsely fire. They must not.
+ const split = [
+ '"One," she said, "and done."',
+ '"Two," he said, "and done."',
+ '"Three," she said, "and done."',
+ ].join('\n');
+ expect(findDialogueTagVariety(split)).toHaveLength(0);
+ });
+
it('does not flag a healthily varied, said-dominant scene', () => {
// Mostly invisible "said" with a little variation — the craft target.
const healthy = [