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
Manuscript Editorial Review — "Generate edits for every finding"
Context
On the manuscript editor (/pipeline/series/:id/manuscript), "Run editorial review" runs the
manuscript-completeness pass (POST /pipeline/series/:id/manuscript/completeness →
arcPlanner.analyzeManuscriptCompleteness → manuscriptReview.seedReviewFromFindings). It produces
itemized editorial comments only — each comment lands with fix: null, so the user must click
"Generate fix" on every comment individually (one extra LLM call each) before they can review the
diff and Accept.
The user wants a second option on the review trigger: produce the editorial findings and a full
proposed manuscript edit in the same pass — a find/replace per finding — so every comment arrives
with its fix already attached. The existing per-comment diff viewer (ManuscriptCommentCard +
SideBySideDiff/InlineDiff), the Impact preview modal, and the Accept path already render
and apply comment.fix — so once fixes are pre-attached, the entire review/accept-one-by-one UX
already works with no changes. This eliminates the N manual "Generate fix" round-trips.
Decisions (confirmed):
- Single-pass prompt — the completeness LLM call returns each finding's
replaceinline; attachfix = { find: anchorQuote, replace }via the existinglocateFindSpananchoring. No N+1 fix loop. - Checkbox — add a second checkbox beside "Start fresh": "Generate edits for every finding."
- SSE progress — stream per-chunk progress (mirrors
editorialAnalysisRunner), since a chunked large manuscript otherwise shows a long opaque spinner.
Approach
1. Prompt: conditional replace field (single source, migrated)
data.reference/prompts/stages/pipeline-manuscript-completeness.md — wrap an additive instruction +
output-contract field in a Mustache section so it only appears when the editor asks for edits:
{{#withEdits}}
- `replace` — the rewritten text that **replaces `anchorQuote` verbatim** to close this gap. Copy
`anchorQuote` into `find`-equivalent position and supply the smallest concrete rewrite of that
exact span. For `comic-structure` (full-page), `replace` is the complete panel-by-panel page.
Omit `replace` only when no in-place edit is possible.
{{/withEdits}}
Add "replace": "..." to the JSON example inside the same {{#withEdits}} block. anchorQuote
already serves as the fix's find; replace is the new span. Keep the findings-only contract intact
(the section is absent when withEdits is false → identical prompt for the legacy path).
Migration scripts/migrations/083-completeness-with-edits-prompt.js (latest is 082):
- Use
makePromptReplaceMigrationfrom./_lib.js(copy the shape of066-manuscript-finding-replacement-strategy-prompts.js). ACCEPTED_OLD_MD5['pipeline-manuscript-completeness.md']= current shipped hash (from 066'sNEW_SHIPPED_MD5,cec8faeb75dfff74e41b8221145c2e92).NEW_SHIPPED_MD5= the post-edit hash (compute after editing the.md).- Mirror the new hash into every earlier migration that tracks this file (056, 057, 066) per the
prompt-migration-drift cross-sync rule — update their
NEW_SHIPPED_MD5and thesetup-data.jsdrift table — or their drift-catch tests go red. Add a sibling.test.jslike 066's.
2. Server: thread withEdits through analyze → shape → seed
server/services/pipeline/arcPlanner.js (analyzeManuscriptCompleteness, ~line 789):
- Accept
options.withEdits. PasswithEdits: !!options.withEditsinto the template ctx (alongsidemanuscript) inrunOne. shapeCompletenessFindings(~line 698): whenwithEdits, also readraw.replace(string, trimmed, sameSTAGE_OUTPUT_MAX-ish cap as fixreplace) onto each shaped finding. Absent/empty → no fix.- Bump
COMPLETENESS_OUTPUT_RESERVE_TOKENSwhenwithEdits(each finding now also carries a fullreplace) — reserve more output room so a long edit list isn't truncated. ReusemanuscriptFix'sFIX_OUTPUT_RESERVE_TOKENSsizing as a reference.
server/services/pipeline/manuscriptReview.js (seedReviewFromFindings, ~line 174):
- Build each candidate's
fixfrom the finding'sanchorQuote+replace: reusemanuscriptFix.locateFindSpan(section.content, anchorQuote)(export already public) to confirm the anchor resolves; setfix = { find: anchorQuote, replace, fuzzy: <not-located-verbatim> }, withedits: [{ issueNumber, issueId, stageId, find, replace }]so the existing Accept path (acceptManuscriptFix) and Impact preview consume it unchanged. sanitizeComment/sanitizeFixalready persistfix— just pass it in the candidate object.- When a finding has no usable
replace(or anchor doesn't resolve), leavefix: nullso the comment falls back to manual "Generate fix" — no regression. findingKeydedupe is unchanged (keyed on issueNumber/anchor/problem).
Reuse note: the fix-building logic (anchor →
{find, replace, edits}, fuzzy flag) overlaps withmanuscriptFix.normalizeFix. Factor the per-finding{anchorQuote, replace, section} → fixshaping into a small exported helper inmanuscriptFix.jsand call it from both seed and fix paths rather than duplicating thelocateFindSpan/fuzzylogic.
3. Server: streaming runner + routes (mirror editorial analysis)
server/services/pipeline/manuscriptCompletenessRunner.js (new — model on
editorialAnalysisRunner.js): in-memory runs Map keyed by seriesId; startCompletenessReview,
attachClient, isActive, cancel. The coordinator calls the same chunk loop but emits SSE frames
per chunk, then seeds the review and emits a terminal frame:
{ type:'start', runId, total }(total = chunk count; 1 in whole mode){ type:'chunk:start'|'chunk:complete', done, total }{ type:'complete', runId, openCount, chunked, chunkCount }/{ type:'error', ... }/canceled- Refactor: extract the chunk-iteration core of
analyzeManuscriptCompletenessinto an async generator or callback-accepting form so both the sync endpoint and the runner share it (avoid copy-pasting the chunk/merge/digest logic).
server/routes/pipeline/manuscript.js: keep POST /completeness synchronous & unchanged for
findings-only (ArcCanvas + checkbox-off both rely on the sync { issues, review } contract). Add:
POST /series/:id/manuscript/completeness/stream→startCompletenessReview→{ runId, sseUrl, mode:'fresh'|'merge', withEdits:true }GET /series/:id/manuscript/completeness/progress(SSE attach)GET /series/:id/manuscript/completeness/status→{ active }POST /series/:id/manuscript/completeness/cancel- Extend
manuscriptCompletenessSchemawithwithEdits: z.boolean().optional()(and validate the stream route body the same way).
4. Client: checkbox + SSE-driven progress
client/src/services/apiPipeline.js: add startPipelineManuscriptCompleteness(seriesId, {providerOverride, modelOverride, mode, withEdits}),
pipelineManuscriptCompletenessSseUrl(seriesId), status + cancel wrappers. Re-export from api.js
and add README rows (catalog maintenance rule).
client/src/hooks/usePipelineManuscriptCompletenessProgress.js (new): thin wrapper over
useSseProgress like usePipelineEditorialProgress.js. Register in hooks/index.js + README.
client/src/pages/PipelineManuscriptEditor.jsx:
- Add
generateEditsstate + a second checkbox under "Start fresh" (idms-generate-edits,htmlForpaired). Label: "Generate edits for every finding — pre-build a fix per note so you can review the full diff & accept." - When
generateEditsis off: keep today's synchronousrunEditorialReviewpath verbatim. - When on: call the stream endpoint, subscribe via the new hook, render per-chunk progress on the
button (
Drafting edit chunk 2 of 4…) and a small list (reuse thereviewMeta?.chunkedwarning area). On the terminalcompleteframe, re-fetch the review (getPipelineManuscriptReview) →setComments, setreviewMeta, toast. Add a Cancel affordance while streaming. - On mount, probe
…/completeness/statusand re-attach to an in-flight run (mirror editorial).
Critical files
data.reference/prompts/stages/pipeline-manuscript-completeness.md—{{#withEdits}}replaceblockscripts/migrations/083-completeness-with-edits-prompt.js(+.test.js); sync hash into 056/057/066 +scripts/setup-data.jsserver/services/pipeline/arcPlanner.js—withEditsctx,replaceshaping, output-reserve bumpserver/services/pipeline/manuscriptReview.js— build/persistfixinseedReviewFromFindingsserver/services/pipeline/manuscriptFix.js— export shared{anchorQuote,replace,section}→fixhelperserver/services/pipeline/manuscriptCompletenessRunner.js(new) — SSE runnerserver/routes/pipeline/manuscript.js—withEditsschema + stream/progress/status/cancel routesclient/src/services/apiPipeline.js,client/src/hooks/usePipelineManuscriptCompletenessProgress.js(new),client/src/pages/PipelineManuscriptEditor.jsx
Verification
- Unit/migration:
cd server && npm test— add coverage thatshapeCompletenessFindings({withEdits})readsreplace; thatseedReviewFromFindingsattachesfixwith correctfind/fuzzy; migration 083 test asserts old→new hash auto-update + drift-table parity (model on066…test.js). - Client:
cd client && npm test— extendPipelineManuscriptEditor.test.jsx: checkbox-on calls the stream endpoint; acompleteSSE frame populates comments withfixset, and the "Generate fix" button is absent (diff + Accept shown directly). - End-to-end (dev server):
npm run dev, open a series with a drafted multi-issue manuscript →/pipeline/series/:id/manuscript. Check "Generate edits for every finding" → Run. Confirm per-chunk progress, then each comment shows a diff + Accept with no "Generate fix" step; Accept applies the edit and snapshots a revertible version. Confirm Impact preview shows the aggregate diff. Re-run with the box off → unchanged findings-only behavior. Confirm ArcCanvas "Finish the draft" still works (sync path untouched). - Compat: confirm an install whose completeness prompt was customized is left intact + warned
(migration is hash-gated), and that a model that omits
replaceyieldsfix: nullcomments that still support manual "Generate fix".