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: manual-edit path for editorial findings with no/incorrect suggested fix (#1610)
[._.]/ Adam Eivyc049a11930c0
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 0e19345749..aff9a80d4f 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -57,6 +57,8 @@## Editorial checks+- **[issue-1610] Manually edit a finding whose suggested fix is wrong or missing — rewrite the anchored span right in the card.** The comment card's diff/apply UI only rendered when a generated `fix` existed, so a finding with no suggestion (or a wrong one) was a dead-end: your only move was to dismiss it and edit the manuscript elsewhere. The card now offers a **Manual edit** affordance (button + `m` shortcut) for any finding that carries an anchor span: it opens an editable replacement seeded with the anchored text, previews the change in the same before/after diff a suggested fix uses, and **Apply edit** splices your replacement in through the exact accept path a generated fix takes — resolving the finding and offering the same one-click Undo. Apply stays disabled until the text actually differs from the span, and the option is hidden for findings with no anchor (nothing to locate). (`client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx`)+- **[issue-1609] Undo an accepted editorial fix — restore the pre-edit manuscript text and re-open the finding.** Accepting a suggested fix rewrote the manuscript with no quick way back: a mistaken acceptance meant hunting the spot and hand-reverting (or digging through the section's version history). Accept now **captures the section's pre-edit text** and offers an undo in two places: an **Undo** button on the success toast right after you accept (the immediate "oops"), and a per-finding **Undo fix** button on the accepted finding in the Editorial Checks triage list. Undo restores the exact pre-edit text and flips the finding back to *open*. The restore is itself a versioned stage write (it lands in the section's history like any edit), and it's guarded: if you kept editing the section after accepting, undo refuses rather than clobber that later work and points you to the version history instead. The snapshot is stored on the finding only while it's accepted (a re-open or dismiss drops it) and is optional + additive, so the synced review document stays backward-compatible with older peers. (`server/services/pipeline/manuscriptFix.js`, `server/services/pipeline/manuscriptReview.js`, `server/routes/pipeline/manuscript.js`, `client/src/services/apiPipeline.js`, `client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx`, `client/src/components/pipeline/editorial/EditorialFindingsTriage.jsx`)- **[issue-1606] The editorial health panel's category and check breakdowns are now clickable — tap one to filter the findings list to it.** The "Open by category" and "Open by check" rows (and their regression flags) showed you *where* the problems were but weren't navigable: spotting a regressed category meant manually re-scanning the list for its findings. Each row whose findings you can triage is now a button that deep-links the triage filter to that category or check and scrolls the findings list into view; clicking the active row again clears the filter, and the row shows a highlighted state while it's the active filter. (Rows that only count findings the triage doesn't list — e.g. the "completeness" bucket — stay as plain text rather than linking to an empty list.) Because the filter writes the same URL query the toolbar uses, the resulting view stays deep-linkable. This also adds a proper **Category** filter to the triage toolbar — distinct from the existing scope filter, which is now correctly labeled **Scope** (its Noun/Scene/Issue/Series values were mislabeled "Category"). (`client/src/components/pipeline/editorial/EditorialHealthPanel.jsx`, `client/src/components/pipeline/editorial/EditorialFindingsTriage.jsx`, `client/src/lib/editorialChecks.js`)diff --git a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsxindex 11dd243d96..b7a32be7e8 100644--- a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx+++ b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx@@ -10,8 +10,8 @@* (`SideBySideDiff`, default) and the compact stacked `InlineDiff`.*/-import { useMemo, useState } from 'react';-import { Loader2, Sparkles, Check, X, Ban, Columns2, Rows2, Copy, ChevronLeft, ChevronRight, Undo2 } from 'lucide-react';+import { useEffect, useMemo, useState } from 'react';+import { Loader2, Sparkles, Check, X, Ban, Columns2, Rows2, Copy, ChevronLeft, ChevronRight, Undo2, Pencil } from 'lucide-react';import InlineDiff from '../../ui/InlineDiff';import SideBySideDiff from '../../ui/SideBySideDiff';import toast from '../../ui/Toast';@@ -44,7 +44,7 @@ export function CopyId({ id }) {// On-screen cheatsheet for the card's keyboard shortcuts (#1603) — only the// actions actually available for this note are shown (prev/next when the card is// part of a triage order, Accept/regenerate when a fix exists, Generate when not).-function ShortcutHints({ hasNav, hasFix, hasFalsePositive }) {+function ShortcutHints({ hasNav, hasFix, hasFalsePositive, hasManualEdit }) {return (<div className="flex flex-wrap items-center gap-x-2.5 gap-y-1 pt-1.5 text-[10px] text-gray-600">{hasNav ? (@@ -58,6 +58,9 @@ function ShortcutHints({ hasNav, hasFix, hasFalsePositive }) {) : (<span className="inline-flex items-center gap-1"><Kbd size="sm">g</Kbd> generate</span>)}+ {hasManualEdit ? (+ <span className="inline-flex items-center gap-1"><Kbd size="sm">m</Kbd> manual edit</span>+ ) : null}<span className="inline-flex items-center gap-1"><Kbd size="sm">d</Kbd> dismiss</span>{hasFalsePositive ? (<span className="inline-flex items-center gap-1"><Kbd size="sm">f</Kbd> false positive</span>@@ -213,6 +216,14 @@ export default function ManuscriptCommentCard({// Namespace form ids so two copies of an open comment don't share ids.const scope = idScope || comment.id;const [diffStyle, setDiffStyle] = useState('side'); // 'side' | 'inline'+ // Manual-edit mode (#1610) — for findings whose suggested fix is wrong or+ // absent, free-text the replacement for the anchored span and apply it through+ // the same accept path a generated fix uses. Local (not parent-owned) state:+ // it's an in-the-moment action in the open-note flow, where only one card+ // mounts. Anchored on `comment.anchorQuote`, which the accept endpoint locates+ // (whitespace-tolerant) to splice the replacement in.+ const [manualMode, setManualMode] = useState(false);+ const [manualText, setManualText] = useState('');const hasFix = !!comment.fix;const fixEdits = useMemo(() => fixEditsOf(comment), [comment]);const fixKey = useMemo(() => fixKeyOf(fixEdits), [fixEdits]);@@ -262,6 +273,38 @@ export default function ManuscriptCommentCard({});};+ // A manual edit needs a span to anchor against — without an anchorQuote the+ // accept path can't locate where to splice, so the option isn't offered.+ const canManualEdit = !!comment.anchorQuote;+ const openManualEdit = () => {+ // Seed with the current span so the diff starts as a no-op the user edits down.+ setManualText(comment.anchorQuote || '');+ setManualMode(true);+ };+ const applyManualEdit = async () => {+ if (!comment.anchorQuote) return;+ const edit = {+ issueId: comment.issueId,+ stageId: comment.stageId,+ issueNumber: comment.issueNumber,+ find: comment.anchorQuote,+ replace: manualText,+ };+ const result = await runAccept([edit]);+ if (!result) return;+ setManualMode(false);+ onAccepted(result);+ showAcceptedFixToast({+ seriesId,+ commentId: result.comment?.id || comment.id,+ count: 1,+ applyResult: onAccepted,+ });+ };+ // Leaving a note (nav/swap) abandons any half-typed manual edit so the next+ // note doesn't inherit stale replacement text.+ useEffect(() => { setManualMode(false); setManualText(''); }, [comment.id]);+const dismiss = async () => {// A plain dismiss is "won't fix" — clear any prior false-positive reason so// re-dismissing a re-opened finding doesn't keep a stale mark.@@ -300,10 +343,11 @@ export default function ManuscriptCommentCard({ArrowRight: nav?.onNext,k: nav?.onPrev,j: nav?.onNext,- a: canAccept && !accepting ? accept : undefined,+ a: canAccept && !accepting && !manualMode ? accept : undefined,d: !accepting ? dismiss : undefined,f: canFlagFalsePositive && !accepting ? markFalsePositive : undefined,g: !generating && !accepting ? generate : undefined,+ m: canManualEdit && !accepting ? (manualMode ? () => setManualMode(false) : openManualEdit) : undefined,});return (@@ -407,6 +451,41 @@ export default function ManuscriptCommentCard({</div>) : null}+ {manualMode ? (+ <div className="space-y-1.5 border border-port-accent/40 rounded bg-port-card/60 p-2">+ <p className="text-[10px] uppercase tracking-wider text-gray-500">Manual edit — rewrite the anchored span</p>+ <Diff oldText={comment.anchorQuote || ''} newText={manualText} emptyLabel="No replacement changes." />+ <label htmlFor={`manual-replace-${scope}`} className="block pt-0.5 text-[10px] uppercase tracking-wider text-gray-500">Replacement (editable)</label>+ <textarea+ id={`manual-replace-${scope}`}+ value={manualText}+ onChange={(e) => setManualText(e.target.value)}+ rows={Math.min(14, Math.max(3, manualText.split('\n').length + 1))}+ className="w-full px-2 py-1.5 bg-port-bg border border-port-border rounded text-[12px] text-gray-100 font-mono resize-y focus:border-port-accent/50 focus:outline-none"+ />+ <div className="flex items-center gap-2">+ <button+ type="button"+ onClick={applyManualEdit}+ disabled={accepting || manualText === (comment.anchorQuote || '')}+ className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-[12px] font-medium bg-port-success/20 text-port-success border border-port-success/40 hover:bg-port-success/30 disabled:opacity-40"+ title="Apply this replacement to the manuscript and resolve the finding"+ >+ {accepting ? <Loader2 size={12} className="animate-spin" /> : <Check size={12} />}+ Apply edit+ </button>+ <button+ type="button"+ onClick={() => setManualMode(false)}+ disabled={accepting}+ className="inline-flex items-center gap-1 px-2 py-1 rounded text-[12px] text-gray-500 hover:text-white disabled:opacity-40"+ >+ Cancel+ </button>+ </div>+ </div>+ ) : null}+<div className="flex items-center gap-2 pt-0.5">{!hasFix ? (<button@@ -441,6 +520,17 @@ export default function ManuscriptCommentCard({</button></>)}+ {canManualEdit && !manualMode ? (+ <button+ type="button"+ onClick={openManualEdit}+ disabled={accepting}+ className="inline-flex items-center gap-1 px-2 py-1 rounded text-[12px] text-gray-400 hover:text-white disabled:opacity-40"+ title="Manually rewrite the anchored span and apply it"+ >+ <Pencil size={12} /> Manual edit+ </button>+ ) : null}{canFlagFalsePositive ? (<buttontype="button"@@ -461,7 +551,7 @@ export default function ManuscriptCommentCard({</button></div>- <ShortcutHints hasNav={!!nav} hasFix={hasFix} hasFalsePositive={canFlagFalsePositive} />+ <ShortcutHints hasNav={!!nav} hasFix={hasFix} hasFalsePositive={canFlagFalsePositive} hasManualEdit={canManualEdit} /></div>);}diff --git a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.test.jsx b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.test.jsxindex cd2071f259..5839162d67 100644--- a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.test.jsx+++ b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.test.jsx@@ -28,6 +28,12 @@ const withFix = {...baseComment,fix: { edits: [{ find: 'old text', replace: 'new text', issueNumber: 5 }] },};+const withAnchor = {+ ...baseComment,+ issueId: 'iss-1',+ stageId: 'script',+ anchorQuote: 'the muddled span',+};const renderCard = (props) => render(<>@@ -170,3 +176,57 @@ describe('ManuscriptCommentCard — accept toast offers Undo (#1609)', () => {expect(await screen.findByText(/Fix undone/i)).toBeTruthy();});});++describe('ManuscriptCommentCard — manual edit path (#1610)', () => {+ beforeEach(() => {+ acceptPipelineManuscriptFix.mockReset();+ toast.dismiss();+ });++ it('offers a manual-edit affordance for an anchored finding with no fix', () => {+ renderCard({ comment: withAnchor });+ expect(screen.getByText('Generate fix')).toBeTruthy();+ expect(screen.getByText('Manual edit')).toBeTruthy();+ expect(screen.getByText('manual edit')).toBeTruthy(); // shortcut hint+ });++ it('does NOT offer manual edit when the finding has no anchor span', () => {+ renderCard(); // baseComment has no anchorQuote+ expect(screen.queryByText('Manual edit')).toBeNull();+ });++ it('applies a manual replacement against the anchored span through the accept path', async () => {+ acceptPipelineManuscriptFix.mockResolvedValue({ comment: { ...withAnchor, status: 'accepted' }, sections: [] });+ const onAccepted = vi.fn();+ renderCard({ comment: withAnchor, onAccepted });++ fireEvent.click(screen.getByText('Manual edit'));+ const textarea = screen.getByLabelText(/Replacement \(editable\)/i);+ expect(textarea.value).toBe('the muddled span'); // seeded with the anchor+ fireEvent.change(textarea, { target: { value: 'the clear span' } });+ fireEvent.click(screen.getByText('Apply edit'));++ await waitFor(() => expect(acceptPipelineManuscriptFix).toHaveBeenCalledWith('ser-1', 'c1', {+ edits: [{ issueId: 'iss-1', stageId: 'script', issueNumber: 5, find: 'the muddled span', replace: 'the clear span' }],+ }));+ await waitFor(() => expect(onAccepted).toHaveBeenCalled());+ });++ it('disables Apply until the replacement differs from the anchored span', () => {+ renderCard({ comment: withAnchor });+ fireEvent.click(screen.getByText('Manual edit'));+ // Seeded value equals the anchor → no-op, so Apply is disabled.+ expect(screen.getByText('Apply edit').closest('button').disabled).toBe(true);+ fireEvent.change(screen.getByLabelText(/Replacement \(editable\)/i), { target: { value: 'changed' } });+ expect(screen.getByText('Apply edit').closest('button').disabled).toBe(false);+ });++ it('m toggles manual-edit mode for an anchored finding', () => {+ renderCard({ comment: withAnchor });+ expect(screen.queryByLabelText(/Replacement \(editable\)/i)).toBeNull();+ pressKey('m');+ expect(screen.getByLabelText(/Replacement \(editable\)/i)).toBeTruthy();+ pressKey('m');+ expect(screen.queryByLabelText(/Replacement \(editable\)/i)).toBeNull();+ });+});