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): tighten duplicate-fragment guard to a whitespace boundary

[._.]/ Adam Eivy7d209575a2b4
diff --git a/client/src/lib/manuscriptFormat.js b/client/src/lib/manuscriptFormat.js
index 410236ba98..d34cbc65f1 100644
--- a/client/src/lib/manuscriptFormat.js
+++ b/client/src/lib/manuscriptFormat.js
@@ -85,10 +85,13 @@ const reattachQuotes = (text) => text
// "I
// "I need a calibration partner … → "I need a calibration partner …
// Only fires when the fragment is an INCOMPLETE opening (a `"` plus a few
-// non-terminal chars, no closing quote) AND the next line begins with that
-// exact fragment followed by a word boundary. So genuine back-to-back short
-// dialogue ("Yes. / "No.) and a merely-similar next word ("I / "Information)
-// are left alone — we only collapse a true leading duplicate.
+// non-terminal chars, no closing quote) AND the next line is either the exact
+// same fragment or begins with it followed by WHITESPACE — the same way a true
+// duplicate continues (`"I` → `"I need …`, a space after the prefix). Requiring
+// whitespace (not any non-word char) is what keeps two genuinely distinct
+// dialogue lines apart: `"Wait` before `"Wait, no — …` continues into a comma,
+// not a space, so it is left alone; so are "Yes. / "No. (terminal punctuation —
+// not a fragment) and "I / "Information (the prefix runs into a letter).
const dropDuplicatedQuoteFragments = (text) => {
const lines = text.split('\n');
const out = [];
@@ -97,7 +100,7 @@ const dropDuplicatedQuoteFragments = (text) => {
const next = lines[i + 1];
const isFragment = /^"[^".!?]{1,20}$/.test(cur);
const dupOfNext = next !== undefined && next.startsWith(cur)
- && (next.length === cur.length || /\W/.test(next.charAt(cur.length)));
+ && (next.length === cur.length || /\s/.test(next.charAt(cur.length)));
if (isFragment && dupOfNext) continue; // drop the duplicated fragment line
out.push(cur);
}
diff --git a/client/src/lib/manuscriptFormat.test.js b/client/src/lib/manuscriptFormat.test.js
index 8904915114..bc88af323c 100644
--- a/client/src/lib/manuscriptFormat.test.js
+++ b/client/src/lib/manuscriptFormat.test.js
@@ -171,6 +171,19 @@ describe('formatManuscript — orphaned closing quotes (prose)', () => {
expect(formatManuscript('"I\n"Information is power.', 'prose')).toBe('"I\n"Information is power.');
});
+ it('does NOT drop a short utterance that is a word-prefix continuing into a new clause', () => {
+ // `"Wait` is a complete line; `"Wait, no…` continues into a comma, not the
+ // space a true duplicate would. The whitespace-boundary guard keeps them apart.
+ const input = '"Wait\n"Wait, no — I changed my mind.';
+ expect(formatManuscript(input, 'prose')).toBe(input);
+ });
+
+ it('is idempotent over the duplicated-fragment input', () => {
+ const input = 'what they said.\n"I\n"I need a calibration partner.';
+ const once = formatManuscript(input, 'prose');
+ expect(formatManuscript(once, 'prose')).toBe(once);
+ });
+
it('leaves script quotes alone — no reflow or quote surgery off the prose path', () => {
const input = 'CAPTION: "Good morning,\n" she says.';
expect(formatManuscript(input, 'comicScript')).toBe(input);