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
feat([issue-733]): declare manuscript finding replacement strategy
[._.]/ Adam Eivy9a05b204cba7
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 791d3e4779..4acf3e7ccf 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -34,6 +34,7 @@## Changed+- **[issue-733]** "Finish the draft" editorial findings now carry an explicit marker for whether their suggestion is delta advice or a full page replacement, so comic-script panel rewrites and ordinary prose suggestions are handled by the right fix path. Internal maintenance change with no behavior difference.- **[issue-832]** The Review Hub's draft lookup now asks the data layer for just the unsent drafts it needs instead of loading every draft and filtering them in memory. Internal performance change with no behavior difference.- **[issue-705]** CyberCity now coalesces bursts of agent spawn/complete events into a single refresh instead of refetching once per event, so a wave of agents starting no longer fans out redundant requests. Internal performance change with no behavior difference.- **[issue-805]** Removed ~470 lines of dead, never-called self-improvement task-generation code left behind by an earlier rewrite. Internal cleanup with no behavior difference.diff --git a/data.reference/prompts/stages/pipeline-manuscript-completeness.md b/data.reference/prompts/stages/pipeline-manuscript-completeness.mdindex c66b730983..3827e6af2a 100644--- a/data.reference/prompts/stages/pipeline-manuscript-completeness.md+++ b/data.reference/prompts/stages/pipeline-manuscript-completeness.md@@ -85,6 +85,7 @@ Return ONLY valid JSON matching this shape — no prose, no markdown fence, no c"anchorQuote": "a short verbatim excerpt copied EXACTLY from the manuscript above, at the spot the gap occurs","location": "Issue 2, around the castle-escape page","problem": "string (what is missing or under-developed, with specific evidence from the script)",+ "replacementStrategy": "delta","suggestion": "string (the smallest concrete addition — a beat, a page, a scene, a line of motivation — that closes the gap)"}]@@ -92,12 +93,15 @@ Return ONLY valid JSON matching this shape — no prose, no markdown fence, no c```- `issueNumber` must be the integer `N` from the `# Issue N` header of the issue the gap belongs to (omit or use `null` if the gap spans the whole series and no single issue applies).+- `replacementStrategy` declares how `suggestion` should be read so the downstream fix step knows whether to synthesize an edit or substitute the text directly. Use one of:+ - **`delta`** *(default — every narrative category)* — `suggestion` is **advice**: the smallest concrete addition that closes the gap. The fix step locates the spot and writes the change.+ - **`full-page`** *(comic-structure only)* — `suggestion` is the **complete replacement text** for the page (a full panel-by-panel breakdown), directly substitutable for the malformed page description.- `anchorQuote` must be a short excerpt (one sentence or a few words, ≤ 400 chars) **copied verbatim** from the manuscript text above, marking where the gap is — the exact spot a transition is missing, where a payoff should land, etc. Copy it character-for-character so an editor can locate it; do not paraphrase. Use the empty string only when the gap is an absence with no nearby text to point at (e.g. a missing ending after the final line — then quote that final line).- `category` must be one of `missing-content` / `arc-gap` / `character-gap` / `pacing` / `continuity` / `comic-structure`.- `severity` must be one of `high` / `medium` / `low`:- **`high`** — the draft cannot be considered finished without this (a missing climax, an unresolved central arc, or any `comic-structure` violation — pages with no panels cannot be rendered).- **`medium`** — the story works but feels incomplete or thin here (an under-built relationship, a skipped transition).- **`low`** — an opportunity to enrich (a theme that could land harder, a minor character that could carry more).-- **For `comic-structure` findings:** `severity` is always `high`. The `suggestion` must be the **complete restructured page content** — a full `Panel 1 / Description: … / Caption: … / Dialogue: … / SFX: …` breakdown for every panel the page should have, not prose advice. The fix is applied as a find-and-replace using `anchorQuote` as the search target, so the suggestion must be directly substitutable. Distribute the prose content from the page description into appropriately sequenced panels (4–6 panels typical for a story page; use your judgment for pacing). Set `anchorQuote` to the opening text of the malformed page description block so the editor can locate it precisely.+- **For `comic-structure` findings:** `severity` is always `high` and `replacementStrategy` is always `full-page`. The `suggestion` must be the **complete restructured page content** — a full `Panel 1 / Description: … / Caption: … / Dialogue: … / SFX: …` breakdown for every panel the page should have, not prose advice — because the fix step substitutes it directly for the malformed page rather than synthesizing an edit. Distribute the prose content from the page description into appropriately sequenced panels (4–6 panels typical for a story page; use your judgment for pacing). Set `anchorQuote` to the opening text of the malformed page description block so the editor can locate it precisely.Return `{ "issues": [] }` only if the manuscript is genuinely complete. Do NOT pad with low-confidence entries.diff --git a/data.reference/prompts/stages/pipeline-manuscript-fix.md b/data.reference/prompts/stages/pipeline-manuscript-fix.mdindex a1ba383a3b..887f8f18d5 100644--- a/data.reference/prompts/stages/pipeline-manuscript-fix.md+++ b/data.reference/prompts/stages/pipeline-manuscript-fix.md@@ -31,6 +31,19 @@ You are a developmental editor making **one or more surgical edits** to a drafte~~~~~~~~{{/finding.anchorQuote}}+## How to read the suggested fix++{{#finding.isFullPage}}+This finding's suggested fix is a **complete replacement** for a malformed comic page — the page dumped its scene content into the page-level description instead of discrete panels. The suggested fix above is the full panel-by-panel rewrite that the page should become.++- Set `find` to the malformed page block (use the anchor above to locate it) — copied verbatim from the manuscript.+- Set `replace` to the suggested fix's panel breakdown, in the manuscript's existing formatting. Do not paraphrase, summarize, or re-derive it; substitute it as the page's new content, lightly adjusting only formatting markers so it matches the surrounding script style.+- Return exactly one edit for the page, unless the anchor spans more than one malformed page.+{{/finding.isFullPage}}+{{^finding.isFullPage}}+The suggested fix above is **advice**, not literal replacement text — it describes the smallest addition that closes the gap. Synthesize the actual edit yourself in the author's voice, following the guidance under "What to do" below.+{{/finding.isFullPage}}+## Edit scope{{scope}}diff --git a/scripts/migrations/056-manuscript-anchored-findings-prompt.js b/scripts/migrations/056-manuscript-anchored-findings-prompt.jsindex cfaf65883e..ba6e6af14c 100644--- a/scripts/migrations/056-manuscript-anchored-findings-prompt.js+++ b/scripts/migrations/056-manuscript-anchored-findings-prompt.js@@ -18,17 +18,19 @@import { makePromptReplaceMigration } from './_lib.js';-// Pre-change shipped hash (location-only findings).+// Pre-change shipped hash (location-only findings), plus every later shipped+// body for this file as accepted-old: '1ee5ac…' (the post-057 comic-structure+// shape) so a copy still at either prior version is auto-upgradable to current.export const ACCEPTED_OLD_MD5 = {- 'pipeline-manuscript-completeness.md': ['e6858c74ab2cead752d388e3f428406c'],+ 'pipeline-manuscript-completeness.md': ['e6858c74ab2cead752d388e3f428406c', '1ee5ac936fbf1d365e0eaea99bcf1e77'],};-// Current shipped hash — migration 057 further updated this file (added-// comic-structure category), so this hash reflects the post-057 body.-// The idempotent-rerun and drift-catch tests require it to match the live-// data.reference body, not 056's own output.+// Current shipped hash — migrations 057 (comic-structure) and 066+// (replacementStrategy) further updated this file, so this hash reflects the+// post-066 body. The idempotent-rerun and drift-catch tests require it to match+// the live data.reference body, not 056's own output.export const NEW_SHIPPED_MD5 = {- 'pipeline-manuscript-completeness.md': '1ee5ac936fbf1d365e0eaea99bcf1e77',+ 'pipeline-manuscript-completeness.md': 'cec8faeb75dfff74e41b8221145c2e92',};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/057-comic-structure-completeness-prompt.js b/scripts/migrations/057-comic-structure-completeness-prompt.jsindex 43fdfae9b6..28c6029f2c 100644--- a/scripts/migrations/057-comic-structure-completeness-prompt.js+++ b/scripts/migrations/057-comic-structure-completeness-prompt.js@@ -22,15 +22,20 @@import { makePromptReplaceMigration } from './_lib.js';-// Pre-change shipped hash (five-category, anchorQuote findings from migration 056).+// Pre-change shipped hash (five-category, anchorQuote findings from migration+// 056), plus this migration's own six-category output ('1ee5ac…') as an+// accepted-old entry — migration 066 (replacementStrategy) further updated the+// file, so a copy still at the 057 body is auto-upgradable to the current shape.export const ACCEPTED_OLD_MD5 = {- 'pipeline-manuscript-completeness.md': ['4f2b95778aed85f5fc461d71eb461b79'],+ 'pipeline-manuscript-completeness.md': ['4f2b95778aed85f5fc461d71eb461b79', '1ee5ac936fbf1d365e0eaea99bcf1e77'],};-// Post-change shipped hash (six-category with comic-structure).-// Mirror this into setup-data.js's drift table.+// Current shipped hash — migration 066 further updated this file (added the+// replacementStrategy contract), so this hash reflects the post-066 body.+// The idempotent-rerun and drift-catch tests require it to match the live+// data.reference body, not 057's own output.export const NEW_SHIPPED_MD5 = {- 'pipeline-manuscript-completeness.md': '1ee5ac936fbf1d365e0eaea99bcf1e77',+ 'pipeline-manuscript-completeness.md': 'cec8faeb75dfff74e41b8221145c2e92',};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/060-manuscript-multi-edit-fix-prompt.js b/scripts/migrations/060-manuscript-multi-edit-fix-prompt.jsindex 74710d94c1..eb4b8c399d 100644--- a/scripts/migrations/060-manuscript-multi-edit-fix-prompt.js+++ b/scripts/migrations/060-manuscript-multi-edit-fix-prompt.js@@ -11,12 +11,20 @@import { makePromptReplaceMigration } from './_lib.js';+// Pre-change shipped hash (single-edit fix prompt), plus this migration's own+// multi-edit output ('c88a56…') as accepted-old — migration 066+// (replacementStrategy) further updated this file, so a copy still at the 060+// body is auto-upgradable to the current shape.export const ACCEPTED_OLD_MD5 = {- 'pipeline-manuscript-fix.md': ['196625952f4a36f3cb962c729f60f0ee'],+ 'pipeline-manuscript-fix.md': ['196625952f4a36f3cb962c729f60f0ee', 'c88a56304eb5e290ae0de9dadd20b310'],};+// Current shipped hash — migration 066 further updated this file (added the+// replacementStrategy reading instructions), so this hash reflects the post-066+// body. The idempotent-rerun and drift-catch tests require it to match the live+// data.reference body, not 060's own output.export const NEW_SHIPPED_MD5 = {- 'pipeline-manuscript-fix.md': 'c88a56304eb5e290ae0de9dadd20b310',+ 'pipeline-manuscript-fix.md': '87c6e47030df07b37ace44d2a15372cf',};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/066-manuscript-finding-replacement-strategy-prompts.js b/scripts/migrations/066-manuscript-finding-replacement-strategy-prompts.jsnew file mode 100644index 0000000000..f4a0f6960e--- /dev/null+++ b/scripts/migrations/066-manuscript-finding-replacement-strategy-prompts.js@@ -0,0 +1,64 @@+/**+ * Unify the finding-shape contract across the manuscript-completeness and+ * manuscript-fix prompts by making the `suggestion` field's meaning explicit.+ *+ * Background: the `comic-structure` category (migration 057) repurposed+ * `suggestion` as a COMPLETE panel-by-panel replacement document, while every+ * narrative category uses it as delta advice. Nothing in the contract declared+ * which one a given finding was — the fix step inferred it from the category.+ *+ * This migration ships a `replacementStrategy: 'delta' | 'full-page'` field on+ * each finding in both prompts:+ * - completeness prompt: emit `replacementStrategy` in the output contract+ * ('full-page' for comic-structure, 'delta' for everything else) so the+ * overloaded use of `suggestion` is declared, not inferred.+ * - fix prompt: branch on the strategy — substitute a full-page suggestion+ * directly vs. synthesize an edit from delta advice.+ *+ * `scripts/setup-data.js` only copies *missing* prompts, so existing installs+ * keep their old templates until this migration rewrites them. Customization-+ * safe: only installs whose copy still hashes to a known prior shipped version+ * are auto-updated; customized prompts are left intact and warned about.+ *+ * Strategy: hash-driven prompt-replace via `./_lib.js`. Idempotent.+ */++import { makePromptReplaceMigration } from './_lib.js';++// Pre-change shipped hashes: completeness from migration 057 (six-category+// comic-structure prompt), fix from migration 060 (multi-edit prompt).+export const ACCEPTED_OLD_MD5 = {+ 'pipeline-manuscript-completeness.md': ['1ee5ac936fbf1d365e0eaea99bcf1e77'],+ 'pipeline-manuscript-fix.md': ['c88a56304eb5e290ae0de9dadd20b310'],+};++// Post-change shipped hashes (replacementStrategy contract on both prompts).+// Mirror these into every earlier migration that tracks the same file+// (056/057 for completeness, 060 for fix) so their drift-catch tests stay green.+export const NEW_SHIPPED_MD5 = {+ 'pipeline-manuscript-completeness.md': 'cec8faeb75dfff74e41b8221145c2e92',+ 'pipeline-manuscript-fix.md': '87c6e47030df07b37ace44d2a15372cf',+};++const { applyMigration, up } = makePromptReplaceMigration({+ accepted: ACCEPTED_OLD_MD5,+ current: NEW_SHIPPED_MD5,+ label: 'manuscript finding replacementStrategy prompts',+ customizedHint: (filename) =>+ ` To add the replacementStrategy contract manually, diff:\n` ++ ` data.reference/prompts/stages/${filename}\n` ++ ` against your current:\n` ++ ` data/prompts/stages/${filename}\n` ++ ` and add the replacementStrategy field (delta vs full-page) to the\n` ++ ` finding output contract / fix-reading instructions.`,+ skipFooter: (count) =>+ `⚠️ ${count} manuscript prompt(s) could not be auto-updated because they\n` ++ ` were customized. The editorial pass still works, but comic-structure\n` ++ ` findings won't be explicitly tagged as full-page replacements until\n` ++ ` you merge the change.\n` ++ ` See data.reference/prompts/stages/pipeline-manuscript-completeness.md\n` ++ ` and data.reference/prompts/stages/pipeline-manuscript-fix.md.`,+});++export { applyMigration };+export default { up };diff --git a/scripts/migrations/066-manuscript-finding-replacement-strategy-prompts.test.js b/scripts/migrations/066-manuscript-finding-replacement-strategy-prompts.test.jsnew file mode 100644index 0000000000..ff5de78978--- /dev/null+++ b/scripts/migrations/066-manuscript-finding-replacement-strategy-prompts.test.js@@ -0,0 +1,14 @@+import { describe } from 'vitest';++import { runPromptMigrationTests } from './_testHelpers.js';+import migration, { applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5 } from './066-manuscript-finding-replacement-strategy-prompts.js';++describe('migration 066 — manuscript finding replacementStrategy prompts', () => {+ runPromptMigrationTests({+ migration,+ applyMigration,+ ACCEPTED_OLD_MD5,+ NEW_SHIPPED_MD5,+ prefix: 'migration-066-',+ });+});diff --git a/scripts/setup-data-drift.test.js b/scripts/setup-data-drift.test.jsindex 8faa78f0dc..640864430e 100644--- a/scripts/setup-data-drift.test.js+++ b/scripts/setup-data-drift.test.js@@ -38,8 +38,8 @@ const EXPECTED_STAGE_OLD = {'universe-character-expand.md': ['ef109eb8e12ddb664c11c790271b5139'],'story-builder-idea-expand.md': ['778c86e2caa120856c36e4d5a4da3355', 'a23939626a226f7420cebfb45d47950c'],'pipeline-editorial-analysis.md': ['14d9879697c66d51830cc798040d5369'],- 'pipeline-manuscript-completeness.md': ['4f2b95778aed85f5fc461d71eb461b79', 'e6858c74ab2cead752d388e3f428406c'],- 'pipeline-manuscript-fix.md': ['196625952f4a36f3cb962c729f60f0ee'],+ 'pipeline-manuscript-completeness.md': ['4f2b95778aed85f5fc461d71eb461b79', 'e6858c74ab2cead752d388e3f428406c', '1ee5ac936fbf1d365e0eaea99bcf1e77'],+ 'pipeline-manuscript-fix.md': ['196625952f4a36f3cb962c729f60f0ee', 'c88a56304eb5e290ae0de9dadd20b310'],'cos-agent-briefing.md': ['181b26838e526427173e4dccfc884d01', '3e1ca7f7b14b799f89a193c568003624', '699d053875472df455258724a0162bd5', '9bcd3a0167dd4aed7cfff7f404494dfb', 'af73fd50d6f29d561772474c12346e53', 'd761133753da290a0c02eca1c87709e4'],'pipeline-tv-script.md': ['3f6fecc25573ed054b47db392250034a'],};@@ -59,8 +59,8 @@ const EXPECTED_STAGE_NEW = {'universe-character-expand.md': '67b6e73ed47f318451a730088b4cff14','story-builder-idea-expand.md': 'c12d76fefaaded2838023065bfc94bb0','pipeline-editorial-analysis.md': 'daeb02bd54b0c099b21af659c6298cfe',- 'pipeline-manuscript-completeness.md': '1ee5ac936fbf1d365e0eaea99bcf1e77',- 'pipeline-manuscript-fix.md': 'c88a56304eb5e290ae0de9dadd20b310',+ 'pipeline-manuscript-completeness.md': 'cec8faeb75dfff74e41b8221145c2e92',+ 'pipeline-manuscript-fix.md': '87c6e47030df07b37ace44d2a15372cf','pipeline-tv-script.md': '376f779f4687b598f1c92ca4e770fd5a',};const EXPECTED_PARTIAL_OLD = {diff --git a/server/services/pipeline/arcPlanner.js b/server/services/pipeline/arcPlanner.jsindex a7611f7d14..c175de7d42 100644--- a/server/services/pipeline/arcPlanner.js+++ b/server/services/pipeline/arcPlanner.js@@ -680,15 +680,34 @@ const COMPLETENESS_CATEGORIES = new Set(['missing-content', 'arc-gap', 'character-gap', 'pacing', 'continuity', 'comic-structure', 'other',]);+// How a finding's `suggestion` should be read. The narrative categories use it+// as delta advice ("the smallest concrete addition that closes the gap"); the+// comic-structure category instead carries a COMPLETE panel-by-panel rewrite of+// the malformed page in `suggestion` (it's directly substitutable). The strategy+// makes that dual use explicit so the fix prompt and UI don't have to special-case+// the category. Mirrored in server/services/pipeline/manuscriptReview.js.+export const REPLACEMENT_STRATEGIES = new Set(['delta', 'full-page']);+// Category → default strategy. comic-structure is the only full-page category;+// everything else (including legacy findings with no strategy field) is a delta.+export const replacementStrategyForCategory = (category) =>+ (category === 'comic-structure' ? 'full-page' : 'delta');+function shapeCompletenessFindings(rawIssues) {if (!Array.isArray(rawIssues)) return [];const out = [];for (const raw of rawIssues) {const problem = typeof raw?.problem === 'string' ? raw.problem.trim() : '';if (!problem) continue;+ const category = COMPLETENESS_CATEGORIES.has(raw?.category) ? raw.category : 'other';out.push({severity: VERIFY_SEVERITIES.has(raw?.severity) ? raw.severity : 'medium',- category: COMPLETENESS_CATEGORIES.has(raw?.category) ? raw.category : 'other',+ category,+ // 'full-page' = suggestion is a complete replacement document (comic-structure);+ // 'delta' = suggestion is advice. Trust the model's value when valid, else derive+ // from category so older/un-annotated runs still classify correctly.+ replacementStrategy: REPLACEMENT_STRATEGIES.has(raw?.replacementStrategy)+ ? raw.replacementStrategy+ : replacementStrategyForCategory(category),location: typeof raw?.location === 'string' ? raw.location.trim().slice(0, 200) : '',problem: problem.slice(0, 2000),// comic-structure suggestions are full page rewrites (~4-6 panels); give them more room.diff --git a/server/services/pipeline/arcPlanner.test.js b/server/services/pipeline/arcPlanner.test.jsindex dda99e4e1e..a30cb28ad6 100644--- a/server/services/pipeline/arcPlanner.test.js+++ b/server/services/pipeline/arcPlanner.test.js@@ -1670,6 +1670,22 @@ describe('arcPlanner — manuscript completeness + derive-from-manuscript', () =expect(out[2]).toMatchObject({ severity: 'medium', category: 'pacing' });});+ it('shapeCompletenessFindings sets replacementStrategy (full-page for comic-structure, delta otherwise; trusts a valid explicit value)', () => {+ const { shapeCompletenessFindings } = planner.__testing;+ const out = shapeCompletenessFindings([+ { category: 'comic-structure', problem: 'page is prose', suggestion: 'Panel 1 …' },+ { category: 'missing-content', problem: 'no climax', suggestion: 'add one' },+ // explicit strategy wins when valid …+ { category: 'pacing', problem: 'rushed', replacementStrategy: 'full-page' },+ // … and an invalid one falls back to the category default.+ { category: 'comic-structure', problem: 'another page', replacementStrategy: 'bogus' },+ ]);+ expect(out[0].replacementStrategy).toBe('full-page'); // derived from category+ expect(out[1].replacementStrategy).toBe('delta'); // narrative default+ expect(out[2].replacementStrategy).toBe('full-page'); // explicit, valid+ expect(out[3].replacementStrategy).toBe('full-page'); // invalid → category default+ });+it('analyzeManuscriptCompleteness reads the manuscript and returns shaped findings', async () => {const s = await setupSeries();await issuesSvc.createIssue({diff --git a/server/services/pipeline/manuscriptFix.js b/server/services/pipeline/manuscriptFix.jsindex a17ae223e7..87e068f389 100644--- a/server/services/pipeline/manuscriptFix.js+++ b/server/services/pipeline/manuscriptFix.js@@ -319,6 +319,11 @@ export async function generateManuscriptFix(seriesId, { commentId, providerOverrproblem: comment.problem,suggestion: comment.suggestion,anchorQuote: comment.anchorQuote,+ replacementStrategy: comment.replacementStrategy,+ // Boolean mirror for Mustache's section tags (it can't compare strings) so+ // the fix prompt can branch on whether `suggestion` is a full-page rewrite+ // (substitute it directly) or delta advice (synthesize the edit).+ isFullPage: comment.replacementStrategy === 'full-page',},};const buildCtx = (sections) => ({diff --git a/server/services/pipeline/manuscriptReview.js b/server/services/pipeline/manuscriptReview.jsindex 85371517f2..b1d3ba7515 100644--- a/server/services/pipeline/manuscriptReview.js+++ b/server/services/pipeline/manuscriptReview.js@@ -20,7 +20,7 @@ import { randomUUID } from 'crypto';import { atomicWrite, readJSONFile } from '../../lib/fileUtils.js';import { createFileWriteQueue } from '../../lib/fileWriteQueue.js';import { seriesStore } from './series.js';-import { collectManuscriptSections } from './arcPlanner.js';+import { collectManuscriptSections, REPLACEMENT_STRATEGIES, replacementStrategyForCategory } from './arcPlanner.js';import { emitRecordUpdated } from '../sharing/recordEvents.js';// Storage-layout version for the review document. Bump + migrate if the@@ -85,16 +85,24 @@ function sanitizeComment(raw) {if (!raw || typeof raw !== 'object') return null;const problem = clampStr(raw.problem, 2000);if (!problem) return null;+ const category = clampStr(raw.category, 40) || 'other';return {id: typeof raw.id === 'string' && raw.id ? raw.id : `mrc-${randomUUID()}`,issueNumber: Number.isInteger(raw.issueNumber) ? raw.issueNumber : null,issueId: typeof raw.issueId === 'string' ? raw.issueId : null,stageId: typeof raw.stageId === 'string' ? raw.stageId : null,severity: ['high', 'medium', 'low'].includes(raw.severity) ? raw.severity : 'medium',- category: clampStr(raw.category, 40) || 'other',+ category,location: clampStr(raw.location, 200),problem,suggestion: clampStr(raw.suggestion, 8000),+ // How `suggestion` should be read: 'full-page' = it's a complete replacement+ // document (comic-structure panel rewrite); 'delta' = it's advice. Trust a+ // valid stored value, else derive from category so legacy comments (written+ // before this field existed) and older peers still classify correctly.+ replacementStrategy: REPLACEMENT_STRATEGIES.has(raw.replacementStrategy)+ ? raw.replacementStrategy+ : replacementStrategyForCategory(category),anchorQuote: clampStr(raw.anchorQuote, 400),status: STATUS_SET.has(raw.status) ? raw.status : 'open',fix: sanitizeFix(raw.fix),diff --git a/server/services/pipeline/manuscriptReview.test.js b/server/services/pipeline/manuscriptReview.test.jsindex df2c39d775..a2bc6592f5 100644--- a/server/services/pipeline/manuscriptReview.test.js+++ b/server/services/pipeline/manuscriptReview.test.js@@ -16,6 +16,10 @@ vi.mock('./series.js', () => ({// from them, but we don't assert on those here).vi.mock('./arcPlanner.js', () => ({collectManuscriptSections: vi.fn(async () => []),+ // sanitizeComment imports these to classify a finding's suggestion. Mirror+ // the real (pure) implementations so the mock doesn't drop them.+ REPLACEMENT_STRATEGIES: new Set(['delta', 'full-page']),+ replacementStrategyForCategory: (category) => (category === 'comic-structure' ? 'full-page' : 'delta'),}));import { recordEvents } from '../sharing/recordEvents.js';@@ -63,4 +67,27 @@ describe('manuscriptReview — record-event emission on write', () => {});expect(updates).toEqual([]);});++ it('persists replacementStrategy (explicit value, derived from category, and legacy fallback)', async () => {+ const seeded = await seedReviewFromFindings('ser-4', [+ { category: 'comic-structure', problem: 'page is prose', suggestion: 'Panel 1 …', anchorQuote: 'PAGE 5' },+ { category: 'missing-content', problem: 'no climax', suggestion: 'add one', anchorQuote: 'the end' },+ ]);+ const byProblem = Object.fromEntries(seeded.comments.map((c) => [c.problem, c]));+ expect(byProblem['page is prose'].replacementStrategy).toBe('full-page');+ expect(byProblem['no climax'].replacementStrategy).toBe('delta');++ // A legacy/older-peer comment with no strategy field round-trips through+ // sanitize with the field derived from its category.+ const merged = await mergeReviewFromSync('ser-5', {+ schemaVersion: 1,+ comments: [+ { id: 'mrc-cs', category: 'comic-structure', problem: 'legacy panels', status: 'open', updatedAt: '2026-06-02T00:00:00Z' },+ { id: 'mrc-mc', category: 'missing-content', problem: 'legacy beat', status: 'open', updatedAt: '2026-06-02T00:00:00Z' },+ ],+ });+ const mergedById = Object.fromEntries(merged.comments.map((c) => [c.id, c]));+ expect(mergedById['mrc-cs'].replacementStrategy).toBe('full-page');+ expect(mergedById['mrc-mc'].replacementStrategy).toBe('delta');+ });});