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
let the impact preview modal accept all previewed edits in place
[._.]/ Adam Eivyef2925c47ae5
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex b0e13e6a11..fa818232fa 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -4,7 +4,7 @@- **Manuscript editor: triage editorial feedback without the scroll-marathon** — clicking an editorial note used to scroll the page all the way to the bottom (the suggested-fix card rendered below the entire section), and getting to the next note meant scrolling all the way back up. Now the open note's card is injected **into the prose right at its anchor**, so the text being discussed and the Accept/Dismiss actions are on screen together; the card also gains a **‹ N of M › stepper** that walks every open note in story/anchor order (cross-issue, in both Live and Review modes), and **resolving a note auto-advances to the next open one** — working through 29 notes is one action per note, no sidebar round-trips. The sidebar index keeps its active row scrolled into view so it tracks where the pass is. (`client/src/components/pipeline/manuscript/`, `client/src/pages/PipelineManuscriptEditor.jsx`)-- **Manuscript impact preview shows a real diff instead of a red/green wall** — the whole-section before/after in **Impact preview** ran a flat word-level diff that tripped its safety cap on manuscript-sized sections and fell back to "everything red on the left, everything green on the right." Sections are now diffed with a new hunked renderer (`HunkDiff`): unchanged text collapses to "⋯ N unchanged lines ⋯" (click to expand, two context lines kept around each change) and each changed region gets precise word-level red/green highlights, so what an accepted batch of edits *actually changes* is legible at a glance. The underlying word diff also trims common prefix/suffix text before hitting its cap, so the per-note edit diffs stay granular on long quotes too. (`client/src/lib/diffLines.js`, `client/src/components/ui/HunkDiff.jsx`, `client/src/lib/diffWords.js`)+- **Manuscript impact preview shows a real diff instead of a red/green wall** — the whole-section before/after in **Impact preview** ran a flat word-level diff that tripped its safety cap on manuscript-sized sections and fell back to "everything red on the left, everything green on the right." Sections are now diffed with a new hunked renderer (`HunkDiff`): unchanged text collapses to "⋯ N unchanged lines ⋯" (click to expand, two context lines kept around each change) and each changed region gets precise word-level red/green highlights, so what an accepted batch of edits *actually changes* is legible at a glance. And the preview is no longer look-but-don't-touch: an **Accept all N edits** button applies every previewed note right from the modal (one accept per note, sequentially, through the same server route the cards use — each section keeps its version-history snapshot, so it's revertible). Notes the server rejects (moved anchor, overlapping edits) are reported and stay in the preview for a regenerate. The underlying word diff also trims common prefix/suffix text before hitting its cap, so the per-note edit diffs stay granular on long quotes too. (`client/src/lib/diffLines.js`, `client/src/components/ui/HunkDiff.jsx`, `client/src/lib/diffWords.js`, `client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx`)- **Editorial review can draft every fix in one pass** — the manuscript editor's **Run editorial review** now has a second checkbox, **Generate edits for every finding**, next to *Start fresh*. With it on, the completeness pass returns not just the itemized editorial notes but a concrete rewrite (`replace`) for each one, so every comment lands with its fix already attached — you go straight to reviewing the full diff and accepting edits one-by-one, with no per-note **Generate fix** click. The model returns each finding's edit inline (a single LLM pass, no N+1 round-trips), and the run streams per-chunk progress over SSE (`Drafting edits — chunk 2 of 4…`) with a Cancel button, re-attaching if you reload mid-run. Findings whose anchor can't be located verbatim stay advice-only and fall back to manual fix generation, so nothing presents an unappliable diff. Leaving the box off keeps today's findings-only behavior unchanged. The new `replace` field rides in a `{{#withEdits}}` block of the completeness prompt (migration 083; the prior prompt auto-upgrades on existing installs). (`server/services/pipeline/arcPlanner.js`, `manuscriptReview.js`, `manuscriptCompletenessRunner.js`, `client/src/pages/PipelineManuscriptEditor.jsx`)diff --git a/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx b/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsxindex 1fcbda3051..0681dedba9 100644--- a/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx+++ b/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx@@ -1,10 +1,13 @@/*** Whole-manuscript impact preview — a modal that shows, per affected section, a- * before/after side-by-side diff of what accepting the currently-selected- * editorial fixes would do. Per-card diffs don't convey cumulative impact; this- * applies every selected edit (via the same `selectedEditsFor` logic Accept- * uses) to a COPY of each section client-side. Preview only — accept still goes- * through the authoritative server route.+ * before/after diff of what accepting the currently-selected editorial fixes+ * would do, with an "Accept all" that applies them right here. Per-card diffs+ * don't convey cumulative impact; this applies every selected edit (via the+ * same `selectedEditsFor` logic Accept uses) to a COPY of each section+ * client-side. Accept all walks the same per-comment accept route the cards+ * use — one comment at a time, sequentially, so each accept re-anchors against+ * the freshest server-side text — reporting (and leaving in the preview) any+ * note whose edits the server rejects.** Sections are diffed with the hunked `HunkDiff` (line-level blocks, unchanged* context collapsed, word-level highlights inside each changed block) — a whole@@ -13,12 +16,14 @@* red/green. Diffs per changed section, never one giant concatenation.*/-import { useMemo } from 'react';-import { X } from 'lucide-react';+import { useMemo, useState } from 'react';+import { Check, Loader2, X } from 'lucide-react';import Modal from '../../ui/Modal';import HunkDiff from '../../ui/HunkDiff';+import toast from '../../ui/Toast';import { planManuscriptEdits } from '../../../lib/applyManuscriptEdits';import { selectedEditsFor } from './ManuscriptCommentCard';+import { acceptPipelineManuscriptFix } from '../../../services/api';import { STAGE_LABEL } from './constants';// Gather every selected edit across the given comments, grouped by the section@@ -38,7 +43,10 @@ function editsBySectionKey(comments, fixDrafts) {return map;}-export default function ManuscriptImpactPreview({ open, onClose, sections, comments, fixDrafts }) {+export default function ManuscriptImpactPreview({ open, onClose, seriesId, sections, comments, fixDrafts, onAccepted }) {+ // null when idle, { done, total } while the accept-all pass runs.+ const [acceptState, setAcceptState] = useState(null);+const changed = useMemo(() => {if (!open) return [];const edits = editsBySectionKey(comments, fixDrafts);@@ -57,6 +65,39 @@ export default function ManuscriptImpactPreview({ open, onClose, sections, commeconst totalEdits = changed.reduce((n, c) => n + c.count, 0);+ // Accept every previewed note, one comment per request (the accept route is+ // per-comment, and sequential application lets each accept anchor against the+ // text the previous one produced). Failures are reported and stay open — the+ // preview re-derives from comment status, so applied sections drop out live.+ const acceptAll = async () => {+ const targets = comments+ .map((c) => ({+ comment: c,+ edits: selectedEditsFor(c, fixDrafts[c.id]).map(({ selected: _s, ...edit }) => edit),+ }))+ .filter((t) => t.edits.length);+ if (!targets.length) return;+ setAcceptState({ done: 0, total: targets.length });+ const errors = [];+ for (const target of targets) {+ const result = await acceptPipelineManuscriptFix(seriesId, target.comment.id, { edits: target.edits }, { silent: true })+ .catch((err) => {+ errors.push(err?.message || 'accept failed');+ return null;+ });+ if (result) onAccepted(result);+ setAcceptState((s) => (s ? { ...s, done: s.done + 1 } : s));+ }+ setAcceptState(null);+ const applied = targets.length - errors.length;+ if (errors.length) {+ toast.error(`Applied ${applied} of ${targets.length} notes — ${errors.length} failed (${errors[0]}). The failed notes stay in the preview; regenerate those fixes.`);+ } else {+ toast.success(applied === 1 ? 'Fix applied to the manuscript' : `${applied} notes applied to the manuscript`);+ onClose();+ }+ };+return (<Modal open={open} onClose={onClose} size="3xl" align="top" ariaLabel="Manuscript impact preview"><div className="bg-port-card border border-port-border rounded-lg max-h-[85vh] flex flex-col">@@ -66,12 +107,28 @@ export default function ManuscriptImpactPreview({ open, onClose, sections, comme<p className="text-[11px] text-gray-500">{totalEdits === 0? 'No selected edits to preview yet — generate a fix and keep its edits checked.'- : `${totalEdits} edit${totalEdits === 1 ? '' : 's'} across ${changed.length} issue${changed.length === 1 ? '' : 's'} (preview only — accept from each note)`}+ : `${totalEdits} edit${totalEdits === 1 ? '' : 's'} across ${changed.length} issue${changed.length === 1 ? '' : 's'} — accept them all here, or one note at a time from the cards`}</p></div>- <button type="button" onClick={onClose} className="text-gray-400 hover:text-white" aria-label="Close preview" title="Close (Esc)">- <X size={18} />- </button>+ <div className="flex items-center gap-2">+ {totalEdits > 0 ? (+ <button+ type="button"+ onClick={acceptAll}+ disabled={!!acceptState}+ title="Apply every previewed edit to the manuscript (each section keeps a version-history snapshot, so this is revertible per section)"+ className="inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded text-xs font-medium bg-port-success/20 text-port-success border border-port-success/40 hover:bg-port-success/30 disabled:opacity-40 whitespace-nowrap"+ >+ {acceptState ? <Loader2 size={12} className="animate-spin" /> : <Check size={12} />}+ {acceptState+ ? `Accepting note ${Math.min(acceptState.done + 1, acceptState.total)} of ${acceptState.total}…`+ : `Accept all ${totalEdits} edit${totalEdits === 1 ? '' : 's'}`}+ </button>+ ) : null}+ <button type="button" onClick={onClose} className="text-gray-400 hover:text-white" aria-label="Close preview" title="Close (Esc)">+ <X size={18} />+ </button>+ </div></div><div className="flex-1 overflow-y-auto p-4 space-y-4">diff --git a/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.test.jsx b/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.test.jsxnew file mode 100644index 0000000000..aa69bb5f0b--- /dev/null+++ b/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.test.jsx@@ -0,0 +1,88 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';+import { render, screen, fireEvent, waitFor } from '@testing-library/react';++vi.mock('../../../services/api', () => ({+ acceptPipelineManuscriptFix: vi.fn(),+ generatePipelineManuscriptFix: vi.fn(),+ patchPipelineManuscriptComment: vi.fn(),+}));+vi.mock('../../ui/Toast', () => ({+ default: Object.assign(vi.fn(), { success: vi.fn(), error: vi.fn() }),+}));++import ManuscriptImpactPreview from './ManuscriptImpactPreview';+import { acceptPipelineManuscriptFix } from '../../../services/api';+import toast from '../../ui/Toast';++const SECTIONS = [+ { issueId: 'i1', stageId: 'prose', number: 1, title: 'One', content: 'hello brave world' },+ { issueId: 'i2', stageId: 'prose', number: 2, title: 'Two', content: 'another fine day' },+];+const COMMENTS = [+ { id: 'c1', status: 'open', issueNumber: 1, issueId: 'i1', stageId: 'prose', anchorQuote: 'brave', fix: { find: 'brave', replace: 'bold' } },+ { id: 'c2', status: 'open', issueNumber: 2, issueId: 'i2', stageId: 'prose', anchorQuote: 'fine', fix: { find: 'fine', replace: 'grand' } },+];++const renderPreview = (overrides = {}) => {+ const props = {+ open: true,+ seriesId: 'ser-1',+ sections: SECTIONS,+ comments: COMMENTS,+ fixDrafts: {},+ onAccepted: vi.fn(),+ onClose: vi.fn(),+ ...overrides,+ };+ render(<ManuscriptImpactPreview {...props} />);+ return props;+};++describe('ManuscriptImpactPreview accept-all', () => {+ beforeEach(() => vi.clearAllMocks());++ it('applies every previewed note (one accept per comment) and closes on full success', async () => {+ acceptPipelineManuscriptFix.mockResolvedValue({ comment: { id: 'cx', status: 'accepted' }, sections: [] });+ const { onAccepted, onClose } = renderPreview();+ fireEvent.click(screen.getByText('Accept all 2 edits'));+ await waitFor(() => expect(onClose).toHaveBeenCalled());+ expect(acceptPipelineManuscriptFix).toHaveBeenCalledTimes(2);+ expect(acceptPipelineManuscriptFix).toHaveBeenCalledWith(+ 'ser-1', 'c1',+ { edits: [expect.objectContaining({ find: 'brave', replace: 'bold' })] },+ { silent: true },+ );+ expect(onAccepted).toHaveBeenCalledTimes(2);+ expect(toast.success).toHaveBeenCalled();+ expect(toast.error).not.toHaveBeenCalled();+ });++ it('reports a partial failure, applies the rest, and keeps the modal open', async () => {+ acceptPipelineManuscriptFix+ .mockResolvedValueOnce({ comment: { id: 'c1', status: 'accepted' }, sections: [] })+ .mockRejectedValueOnce(new Error('anchor not found'));+ const { onAccepted, onClose } = renderPreview();+ fireEvent.click(screen.getByText('Accept all 2 edits'));+ await waitFor(() => expect(toast.error).toHaveBeenCalled());+ expect(onAccepted).toHaveBeenCalledTimes(1);+ expect(onClose).not.toHaveBeenCalled();+ expect(toast.error.mock.calls[0][0]).toMatch(/anchor not found/);+ });++ it('honors the draft selection — unchecked edits are not sent', async () => {+ acceptPipelineManuscriptFix.mockResolvedValue({ comment: {}, sections: [] });+ // c1's only edit is unchecked; c2 stays fully selected.+ const fixDrafts = {+ c1: { fixKey: '0:i1:prose:brave:bold', drafts: { 0: 'bold' }, selected: { 0: false } },+ };+ renderPreview({ fixDrafts });+ fireEvent.click(screen.getByText('Accept all 1 edit'));+ await waitFor(() => expect(acceptPipelineManuscriptFix).toHaveBeenCalledTimes(1));+ expect(acceptPipelineManuscriptFix.mock.calls[0][1]).toBe('c2');+ });++ it('shows no accept button when there is nothing to preview', () => {+ renderPreview({ comments: [] });+ expect(screen.queryByText(/Accept all/)).not.toBeInTheDocument();+ });+});diff --git a/client/src/pages/PipelineManuscriptEditor.jsx b/client/src/pages/PipelineManuscriptEditor.jsxindex ecef4dd013..b5a266d110 100644--- a/client/src/pages/PipelineManuscriptEditor.jsx+++ b/client/src/pages/PipelineManuscriptEditor.jsx@@ -19,7 +19,7 @@* scrolling back to the sidebar in between.* An "Impact preview" button shows a hunked before/after diff (unchanged* context collapsed, word-level highlights) of how the selected fixes change- * the whole manuscript.+ * the whole manuscript, with an "Accept all" that applies them in bulk.** Data: GET /pipeline/series/:id/manuscript (sections) + .../manuscript/review* (comments). Section saves reuse PATCH /pipeline/issues/:id; fixes go through@@ -781,9 +781,11 @@ export default function PipelineManuscriptEditor() {<ManuscriptImpactPreviewopen={showImpact}onClose={() => setShowImpact(false)}+ seriesId={seriesId}sections={sections}comments={comments.filter((c) => c.status === 'open' && c.fix)}fixDrafts={fixDrafts}+ onAccepted={applyAccepted}/></div>);diff --git a/client/src/services/apiPipeline.js b/client/src/services/apiPipeline.jsindex a042a9576e..749e32047c 100644--- a/client/src/services/apiPipeline.js+++ b/client/src/services/apiPipeline.js@@ -472,10 +472,11 @@ export const generatePipelineManuscriptFix = (seriesId, commentId, { providerOve// Apply one or more optionally edited fixes into stage output + mark accepted.// Returns { comment, section, sections }.-export const acceptPipelineManuscriptFix = (seriesId, commentId, { find, replace, edits }) =>+export const acceptPipelineManuscriptFix = (seriesId, commentId, { find, replace, edits }, options = {}) =>request(`/pipeline/series/${encodeURIComponent(seriesId)}/manuscript/review/comments/${encodeURIComponent(commentId)}/accept`, {method: 'POST',body: JSON.stringify({ find, replace, edits }),+ ...options,});// Versioned free-text save of one manuscript section. Snapshots the prior text