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
address review (claude): dedup italic-thoughts by text position, not scan order
Adam Eivyfef5b54b376f
diff --git a/server/lib/editorial/italicThoughts.js b/server/lib/editorial/italicThoughts.jsindex d8f8c9aedc..ce2df04802 100644--- a/server/lib/editorial/italicThoughts.js+++ b/server/lib/editorial/italicThoughts.js@@ -44,8 +44,11 @@ function wordCount(text) {export function findItalicThoughts(text, opts = {}) {if (typeof text !== 'string' || !text) return [];const minWords = Math.max(1, Number.isInteger(opts.minWords) ? opts.minWords : 4);- const found = [];- const seen = new Set();+ // Collect matches from BOTH delimiters first, then sort by position before+ // deduping — so "FIRST occurrence" is the first in the TEXT, regardless of+ // which delimiter the dedup-winner uses (an earlier `_…_` span must win over a+ // later `*…*` span with identical text).+ const matches = [];const scan = (re) => {re.lastIndex = 0;let m;@@ -53,13 +56,19 @@ export function findItalicThoughts(text, opts = {}) {const inner = m[1].trim();const words = wordCount(inner);if (words < minWords) continue;- const key = inner.toLowerCase();- if (seen.has(key)) continue;- seen.add(key);- found.push({ inner, index: m.index, anchor: m[0], words });+ matches.push({ inner, index: m.index, anchor: m[0], words });}};scan(ASTERISK_ITALIC_RE);scan(UNDERSCORE_ITALIC_RE);- return found.sort((a, b) => a.index - b.index);+ matches.sort((a, b) => a.index - b.index);+ const found = [];+ const seen = new Set();+ for (const match of matches) {+ const key = match.inner.toLowerCase();+ if (seen.has(key)) continue;+ seen.add(key);+ found.push(match);+ }+ return found;}diff --git a/server/lib/editorial/italicThoughts.test.js b/server/lib/editorial/italicThoughts.test.jsindex 590671fd69..4be2ac47fa 100644--- a/server/lib/editorial/italicThoughts.test.js+++ b/server/lib/editorial/italicThoughts.test.js@@ -49,6 +49,15 @@ describe('findItalicThoughts', () => {expect(hits[0].inner).toBe('What now?');});+ it('keeps the earliest occurrence when the same thought appears under both delimiters', () => {+ // The underscore span comes first in the text; dedup must keep it over the+ // later asterisk span with identical text (FIRST-in-text wins, not first-scanned).+ const hits = findItalicThoughts('first _the same words here_ then *the same words here* end');+ expect(hits).toHaveLength(1);+ expect(hits[0].index).toBe(6);+ expect(hits[0].anchor).toBe('_the same words here_');+ });+it('returns runs sorted by position across both delimiters', () => {const hits = findItalicThoughts('_The first thought arrives._ Then *the second thought lands hard.*');expect(hits.map((h) => h.inner)).toEqual([