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 (self): truthful impact preview, backdrop scroll-sync, real fuzzy test
[._.]/ Adam Eivy8708b9336a99
diff --git a/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx b/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsxindex eb171238f2..45c621078b 100644--- a/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx+++ b/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx@@ -14,7 +14,7 @@ import { useMemo } from 'react';import { X } from 'lucide-react';import Modal from '../../ui/Modal';import SideBySideDiff from '../../ui/SideBySideDiff';-import { applyEditsToContent } from '../../../lib/applyManuscriptEdits';+import { planManuscriptEdits } from '../../../lib/applyManuscriptEdits';import { selectedEditsFor } from './ManuscriptCommentCard';import { STAGE_LABEL } from './constants';@@ -44,9 +44,10 @@ export default function ManuscriptImpactPreview({ open, onClose, sections, commeconst key = `${s.issueId}:${s.stageId}`;const sectionEdits = edits.get(key);if (!sectionEdits?.length) return null;- const after = applyEditsToContent(s.content || '', sectionEdits);- if (after === (s.content || '')) return null;- return { section: s, before: s.content || '', after, count: sectionEdits.length };+ const before = s.content || '';+ const { output: after, overlapping } = planManuscriptEdits(before, sectionEdits);+ if (after === before && !overlapping) return null;+ return { section: s, before, after, count: sectionEdits.length, overlapping };}).filter(Boolean);}, [open, sections, comments, fixDrafts]);@@ -76,13 +77,18 @@ export default function ManuscriptImpactPreview({ open, onClose, sections, commeNothing to preview. Generate fixes on the open editorial notes (and leave the edits you want checked); they'll show here as before/after diffs.</p>) : (- changed.map(({ section, before, after, count }) => (+ changed.map(({ section, before, after, count, overlapping }) => (<div key={`${section.issueId}:${section.stageId}`} className="border border-port-border rounded-lg overflow-hidden"><div className="px-3 py-2 bg-port-bg/60 border-b border-port-border text-sm text-gray-200">Issue {section.number}{section.title ? ` — ${section.title}` : ''}<span className="ml-2 text-[10px] uppercase tracking-wider text-gray-500">{STAGE_LABEL[section.stageId] || section.stageId}</span><span className="ml-2 text-[10px] text-port-accent">{count} edit{count === 1 ? '' : 's'}</span></div>+ {overlapping ? (+ <p className="px-3 py-1.5 text-[11px] text-port-warning border-b border-port-border bg-port-warning/10">+ {overlapping} of these edits overlap — accepting will be rejected; regenerate the fix. Preview below shows the non-overlapping subset.+ </p>+ ) : null}<SideBySideDiff oldText={before} newText={after} oldLabel="Current" newLabel="With edits" /></div>))diff --git a/client/src/components/pipeline/manuscript/ManuscriptLiveSection.jsx b/client/src/components/pipeline/manuscript/ManuscriptLiveSection.jsxindex 05aee21a14..489b8e30f2 100644--- a/client/src/components/pipeline/manuscript/ManuscriptLiveSection.jsx+++ b/client/src/components/pipeline/manuscript/ManuscriptLiveSection.jsx@@ -125,6 +125,14 @@ export default function ManuscriptLiveSection({onBlur={onBlurSave}onClick={handleCaret}onKeyUp={handleCaret}+ // Keep the underline backdrop aligned when a section longer than the+ // row cap scrolls internally (the backdrop is overflow-hidden).+ onScroll={(e) => {+ if (backdropRef.current) {+ backdropRef.current.scrollTop = e.target.scrollTop;+ backdropRef.current.scrollLeft = e.target.scrollLeft;+ }+ }}rows={rowsFor(content)}spellCheckclassName={`relative w-full bg-transparent border border-port-border rounded text-gray-100 resize-y focus:border-port-accent/50 focus:outline-none ${EDITOR_TYPO}`}diff --git a/client/src/lib/applyManuscriptEdits.js b/client/src/lib/applyManuscriptEdits.jsindex 8945c9921e..832aac0067 100644--- a/client/src/lib/applyManuscriptEdits.js+++ b/client/src/lib/applyManuscriptEdits.js@@ -11,31 +11,41 @@import { locateFindSpan } from './manuscriptAnchors.js';-// Apply `edits` (each { find, replace, anchorQuote? }) to `content`. Edits whose-// `find` isn't present (even tolerating whitespace) are skipped; overlapping-// edits keep the earlier one. Whitespace tolerance mirrors the server accept.-export function applyEditsToContent(content, edits, anchorQuote) {+// Plan how `edits` (each { find, replace, anchorQuote? }) apply to `content`:+// locate each (whitespace-tolerant, mirroring the server accept), splice the+// kept spans high-to-low, and report what couldn't apply. Edits whose `find`+// isn't present count as `notFound`; edits overlapping an earlier kept span+// count as `overlapping`. The server accept THROWS on overlap, so the preview+// uses `overlapping` to warn that accepting will fail rather than render a+// partial result the accept won't actually produce.+export function planManuscriptEdits(content, edits, anchorQuote) {const text = content || '';const located = [];+ let notFound = 0;(edits || []).forEach((e) => {const find = e?.find || '';if (!find) return;const span = locateFindSpan(text, find, e.anchorQuote ?? anchorQuote);- if (!span) return;+ if (!span) { notFound += 1; return; }located.push({ start: span.start, end: span.end, replace: e.replace ?? '' });});- // Drop overlaps (keep the earlier span), then splice high-to-low.located.sort((a, b) => a.start - b.start);const kept = [];+ let overlapping = 0;let lastEnd = -1;located.forEach((l) => {- if (l.start >= lastEnd) { kept.push(l); lastEnd = l.end; }+ if (l.start >= lastEnd) { kept.push(l); lastEnd = l.end; } else overlapping += 1;});- let out = text;- kept.sort((a, b) => b.start - a.start).forEach((l) => {- out = out.slice(0, l.start) + l.replace + out.slice(l.end);+ let output = text;+ kept.slice().sort((a, b) => b.start - a.start).forEach((l) => {+ output = output.slice(0, l.start) + l.replace + output.slice(l.end);});- return out;+ return { output, applied: kept.length, notFound, overlapping };+}++// Convenience: just the resulting text (drops overlaps/not-found silently).+export function applyEditsToContent(content, edits, anchorQuote) {+ return planManuscriptEdits(content, edits, anchorQuote).output;}diff --git a/client/src/lib/applyManuscriptEdits.test.js b/client/src/lib/applyManuscriptEdits.test.jsindex 0ca9a1ffb8..60ffa0a34c 100644--- a/client/src/lib/applyManuscriptEdits.test.js+++ b/client/src/lib/applyManuscriptEdits.test.js@@ -1,5 +1,5 @@import { describe, it, expect } from 'vitest';-import { applyEditsToContent } from './applyManuscriptEdits.js';+import { applyEditsToContent, planManuscriptEdits } from './applyManuscriptEdits.js';describe('applyEditsToContent', () => {it('applies a single find/replace', () => {@@ -46,3 +46,29 @@ describe('applyEditsToContent', () => {expect(out).toBe('PAGE 56\nPANEL 1\nGiant kneels.');});});++describe('planManuscriptEdits', () => {+ it('reports applied count and leaves content when nothing matches', () => {+ const plan = planManuscriptEdits('hello world', [{ find: 'xyz', replace: 'q' }]);+ expect(plan).toEqual({ output: 'hello world', applied: 0, notFound: 1, overlapping: 0 });+ });++ it('counts overlapping edits (which the server accept rejects) and keeps the earlier one', () => {+ const plan = planManuscriptEdits('abcdef', [+ { find: 'abc', replace: 'X' },+ { find: 'bcd', replace: 'Y' },+ ]);+ expect(plan.output).toBe('Xdef');+ expect(plan.applied).toBe(1);+ expect(plan.overlapping).toBe(1);+ });++ it('applies multiple non-overlapping edits with no drops', () => {+ const plan = planManuscriptEdits('alpha beta gamma', [+ { find: 'alpha', replace: 'A' },+ { find: 'gamma', replace: 'G' },+ ]);+ expect(plan.output).toBe('A beta G');+ expect(plan).toMatchObject({ applied: 2, notFound: 0, overlapping: 0 });+ });+});diff --git a/server/services/pipeline/manuscriptFix.test.js b/server/services/pipeline/manuscriptFix.test.jsindex 76ebe2867c..c8c5559c9a 100644--- a/server/services/pipeline/manuscriptFix.test.js+++ b/server/services/pipeline/manuscriptFix.test.js@@ -26,13 +26,22 @@ describe('locateFindSpan', () => {expect(locateFindSpan('anything', '')).toBeNull();});- it('disambiguates a recurring fuzzy match by the nearest anchorQuote', () => {+ it('prefers an exact match over a fuzzy one when both exist', () => {+ // "run away." matches exactly at index 0; the second occurrence only matches+ // via whitespace tolerance (tab). Exact wins regardless of the anchor.const text = 'run away.\n\n[marker] run\taway.';- // "run away." (exact) appears first; with whitespace tolerance the second- // (tab instead of space) also matches — anchor picks the nearer one.- const span = locateFindSpan(text, 'run away.'.replace(' ', ' '), '[marker]');- // exact match exists at index 0, so it wins (nearest-occurrence among exacts).- expect(span.start).toBe(0);+ expect(locateFindSpan(text, 'run away.', '[marker]').start).toBe(0);+ });++ it('disambiguates between two fuzzy-only matches by the nearest anchorQuote', () => {+ // No exact match (find uses a space; both occurrences use a tab), so both+ // resolve only via the whitespace-tolerant regex. The anchor sits beside the+ // SECOND occurrence, so that span is chosen.+ const text = 'run\taway. ... ... ... [marker] run\taway.';+ const span = locateFindSpan(text, 'run away.', '[marker]');+ const second = text.indexOf('run\taway.', 1);+ expect(span.start).toBe(second);+ expect(text.slice(span.start, span.end)).toBe('run\taway.');});it('escapes regex metacharacters in the quote', () => {