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): tighten reformat integrity guard; quiet no-change path
[._.]/ Adam Eivy44e8c0e7b82f
diff --git a/client/src/pages/PipelineManuscriptEditor.jsx b/client/src/pages/PipelineManuscriptEditor.jsxindex 47fb1c555e..70b0cbba20 100644--- a/client/src/pages/PipelineManuscriptEditor.jsx+++ b/client/src/pages/PipelineManuscriptEditor.jsx@@ -413,11 +413,16 @@ export default function PipelineManuscriptEditor() {return null;});if (!result?.section) return;+ if (result.changed === false) {+ // Nothing was written server-side — don't flash a "saved" badge.+ toast('Already well-formatted — nothing to clean up');+ return;+ }const content = result.section.content;baselineRef.current.set(`${section.issueId}:${section.stageId}`, content);patchSection(section.issueId, { content, versions: result.section.versions });setSaveState((prev) => ({ ...prev, [section.issueId]: 'saved' }));- toast.success(result.changed === false ? 'Already well-formatted — nothing to clean up' : 'Reformatted with AI');+ toast.success('Reformatted with AI');};const revertSection = async (section, runId) => {diff --git a/server/services/pipeline/manuscriptFix.js b/server/services/pipeline/manuscriptFix.jsindex afc15af732..3b376e0652 100644--- a/server/services/pipeline/manuscriptFix.js+++ b/server/services/pipeline/manuscriptFix.js@@ -363,18 +363,25 @@ const isSubsequence = (small, big) => {return i === small.length;};-// Reject any reformat that altered the actual wording. The output is allowed to-// be the input with at most a tiny budget of characters DELETED (artifact-// removal — e.g. a duplicated drop-cap), and those deletions must form a-// subsequence (no substitutions, no additions). Anything else — a rewritten-// word, an inserted sentence, a dropped paragraph — fails and is discarded.+// The most letter/digit chars a pure reformat may delete IN TOTAL. Reflow and+// quote-reattachment delete none (skeleton is identical); the only legitimate+// deletion is a handful of artifact glyphs — a duplicated drop-cap, a stray+// mark. Kept a small ABSOLUTE bound (not proportional): for a subsequence the+// net length drop IS the exact total deleted, so this alone rejects a dropped+// clause/sentence (≥ this many chars) without any unreliable run analysis.+const MAX_TOTAL_DELETION = 8;++// Reject any reformat that altered the actual wording. The output must be the+// input skeleton with at most MAX_TOTAL_DELETION characters DELETED, those+// deletions forming a subsequence (no substitutions, no additions). Anything+// else — a rewritten word, an inserted sentence, a dropped clause — fails and is+// discarded so a caller never persists silently-rewritten prose.function assertWordsPreserved(before, after) {const a = wordSkeleton(before);const b = wordSkeleton(after);if (a === b) return;- const budget = Math.max(8, Math.round(a.length * 0.004));const shrink = a.length - b.length;- if (shrink >= 0 && shrink <= budget && isSubsequence(b, a)) return;+ if (shrink >= 0 && shrink <= MAX_TOTAL_DELETION && isSubsequence(b, a)) return;throw makeErr('AI reformat changed the wording, so it was discarded and the text is unchanged. Try again or use the plain Format button.',ERR_VALIDATION,diff --git a/server/services/pipeline/manuscriptReformat.test.js b/server/services/pipeline/manuscriptReformat.test.jsindex ec8bdb5ae7..2472e09260 100644--- a/server/services/pipeline/manuscriptReformat.test.js+++ b/server/services/pipeline/manuscriptReformat.test.js@@ -53,6 +53,25 @@ describe('reformatManuscriptText — integrity guard', () => {.rejects.toThrow(/changed the wording/i);});+ it('rejects a dropped clause even on a long section (budget is a small absolute)', async () => {+ // A long doc must not buy a bigger deletion budget — dropping "the passage"+ // (10 skeleton chars > the 8-char total budget) is rejected regardless of size.+ const filler = `${'word '.repeat(2000)}`;+ const input = `Start of it. ${filler}and the passage ends here.`;+ const output = `Start of it. ${filler}and ends here.`;+ runStagedLLM.mockResolvedValue({ content: output, runId: 'r1' });+ await expect(reformatManuscriptText(input, { stageId: 'prose' }))+ .rejects.toThrow(/changed the wording/i);+ });++ it('accepts a few scattered single-char artifact deletions', async () => {+ const input = 'A line.\n"I\n"I am here.\nAnother "A\n"A line follows.';+ const output = 'A line.\n"I am here.\nAnother "A line follows.';+ runStagedLLM.mockResolvedValue({ content: output, runId: 'r1' });+ const r = await reformatManuscriptText(input, { stageId: 'prose' });+ expect(r.text).toBe(output);+ });+it('strips a stray code fence the model wrapped the output in', async () => {runStagedLLM.mockResolvedValue({ content: '```\nThe dawn cycle hums.\n```', runId: 'r1' });const r = await reformatManuscriptText('The dawn cycle\nhums.', { stageId: 'prose' });