Skip to content

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

simplify: useEscapeKey hook, CommentCardFromProps wrapper, accurate fuzzy flag

[._.]/ Adam Eivy15af5c4564ff
diff --git a/client/src/components/pipeline/manuscript/AnnotatedManuscriptSection.jsx b/client/src/components/pipeline/manuscript/AnnotatedManuscriptSection.jsx
index 4c8448fbf5..46b40f732a 100644
--- a/client/src/components/pipeline/manuscript/AnnotatedManuscriptSection.jsx
+++ b/client/src/components/pipeline/manuscript/AnnotatedManuscriptSection.jsx
@@ -8,8 +8,9 @@
import { useEffect, useMemo, useRef } from 'react';
import { Pencil, Check, X } from 'lucide-react';
+import useEscapeKey from '../../../hooks/useEscapeKey';
import ManuscriptHighlightedProse from './ManuscriptHighlightedProse';
-import ManuscriptCommentCard from './ManuscriptCommentCard';
+import { CommentCardFromProps } from './ManuscriptCommentCard';
import ManuscriptSectionFrame from './ManuscriptSectionFrame';
import { rowsFor } from './constants';
@@ -31,12 +32,7 @@ export default function AnnotatedManuscriptSection({
}, [openComment?.id]); // eslint-disable-line react-hooks/exhaustive-deps
// Esc closes the open note — parity with the Live popover.
- useEffect(() => {
- if (!openComment) return undefined;
- const onKey = (e) => { if (e.key === 'Escape') onCloseComment(); };
- window.addEventListener('keydown', onKey);
- return () => window.removeEventListener('keydown', onKey);
- }, [openComment, onCloseComment]);
+ useEscapeKey(openComment, onCloseComment);
const editToggle = (
<button
@@ -81,18 +77,7 @@ export default function AnnotatedManuscriptSection({
>
<X size={14} />
</button>
- <ManuscriptCommentCard
- comment={openComment}
- idScope={`review-${openComment.id}`}
- seriesId={commentCardProps.seriesId}
- providerOverride={commentCardProps.providerOverride}
- modelOverride={commentCardProps.modelOverride}
- onCommentChange={commentCardProps.onCommentChange}
- onAccepted={commentCardProps.onAccepted}
- draft={commentCardProps.fixDrafts[openComment.id]}
- onDraftChange={(entry) => commentCardProps.setCommentDraft(openComment.id, entry)}
- onJump={undefined}
- />
+ <CommentCardFromProps comment={openComment} commentCardProps={commentCardProps} idScope={`review-${openComment.id}`} />
</div>
) : null}
</ManuscriptSectionFrame>
diff --git a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx
index 4b867c25e1..5ac0d3c09e 100644
--- a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx
+++ b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx
@@ -11,7 +11,7 @@
*/
import { useMemo, useState } from 'react';
-import { Loader2, Sparkles, Check, X, CornerDownRight, Columns2, Rows2, Copy } from 'lucide-react';
+import { Loader2, Sparkles, Check, X, Columns2, Rows2, Copy } from 'lucide-react';
import InlineDiff from '../../ui/InlineDiff';
import SideBySideDiff from '../../ui/SideBySideDiff';
import toast from '../../ui/Toast';
@@ -87,8 +87,28 @@ export function selectedEditsFor(comment, draft) {
.filter((e) => e.selected);
}
+// Bind a comment card to the page's shared `commentCardProps` (handlers + the
+// per-comment draft keyed by id). The card renders identically in the Live
+// popover, the Review inline expansion, and the sidebar index — only `idScope`
+// differs — so this wrapper is the single place that prop shape lives.
+export function CommentCardFromProps({ comment, commentCardProps, idScope }) {
+ return (
+ <ManuscriptCommentCard
+ comment={comment}
+ idScope={idScope}
+ seriesId={commentCardProps.seriesId}
+ providerOverride={commentCardProps.providerOverride}
+ modelOverride={commentCardProps.modelOverride}
+ onCommentChange={commentCardProps.onCommentChange}
+ onAccepted={commentCardProps.onAccepted}
+ draft={commentCardProps.fixDrafts[comment.id]}
+ onDraftChange={(entry) => commentCardProps.setCommentDraft(comment.id, entry)}
+ />
+ );
+}
+
export default function ManuscriptCommentCard({
- comment, seriesId, providerOverride, modelOverride, onJump, onCommentChange, onAccepted, idScope, draft, onDraftChange,
+ comment, seriesId, providerOverride, modelOverride, onCommentChange, onAccepted, idScope, draft, onDraftChange,
}) {
// Namespace form ids so two copies of an open comment don't share ids.
const scope = idScope || comment.id;
@@ -150,20 +170,7 @@ export default function ManuscriptCommentCard({
<div className="border border-port-border rounded-lg bg-port-bg/40 p-2.5 space-y-2">
<div className="flex items-center justify-between gap-2">
<Badge comment={comment} />
- <div className="flex items-center gap-2">
- <CopyId id={comment.id} />
- {onJump ? (
- <button
- type="button"
- onClick={() => onJump(comment)}
- className="text-[11px] text-port-accent hover:underline inline-flex items-center gap-1"
- title="Reveal this spot in the manuscript"
- >
- <CornerDownRight size={11} />
- {comment.issueNumber != null ? `Issue ${comment.issueNumber}` : 'Reveal'}
- </button>
- ) : null}
- </div>
+ <CopyId id={comment.id} />
</div>
<p className="text-xs text-gray-200">{comment.problem}</p>
diff --git a/client/src/components/pipeline/manuscript/ManuscriptCommentIndex.jsx b/client/src/components/pipeline/manuscript/ManuscriptCommentIndex.jsx
index 246a66eeb4..55bc6d07dd 100644
--- a/client/src/components/pipeline/manuscript/ManuscriptCommentIndex.jsx
+++ b/client/src/components/pipeline/manuscript/ManuscriptCommentIndex.jsx
@@ -7,7 +7,7 @@
import { useMemo, useState } from 'react';
import { ChevronDown, ChevronRight, Check, X, MapPin } from 'lucide-react';
-import ManuscriptCommentCard, { Badge } from './ManuscriptCommentCard';
+import { Badge, CommentCardFromProps } from './ManuscriptCommentCard';
const SEVERITIES = ['high', 'medium', 'low'];
@@ -120,18 +120,7 @@ export default function ManuscriptCommentIndex({ comments, locatedCommentIds, op
{/* Story-level notes (no issueNumber) have no issue tab to live on, so
they expand and stay actionable right here in the index. */}
{c.id === openCommentId && c.issueNumber == null && commentCardProps ? (
- <ManuscriptCommentCard
- comment={c}
- idScope={`index-${c.id}`}
- seriesId={commentCardProps.seriesId}
- providerOverride={commentCardProps.providerOverride}
- modelOverride={commentCardProps.modelOverride}
- onCommentChange={commentCardProps.onCommentChange}
- onAccepted={commentCardProps.onAccepted}
- draft={commentCardProps.fixDrafts[c.id]}
- onDraftChange={(entry) => commentCardProps.setCommentDraft(c.id, entry)}
- onJump={undefined}
- />
+ <CommentCardFromProps comment={c} commentCardProps={commentCardProps} idScope={`index-${c.id}`} />
) : null}
</div>
))}
diff --git a/client/src/components/pipeline/manuscript/ManuscriptLiveSection.jsx b/client/src/components/pipeline/manuscript/ManuscriptLiveSection.jsx
index 582464d355..05aee21a14 100644
--- a/client/src/components/pipeline/manuscript/ManuscriptLiveSection.jsx
+++ b/client/src/components/pipeline/manuscript/ManuscriptLiveSection.jsx
@@ -12,10 +12,11 @@
* docs/plans/2026-06-06-manuscript-editor-inline-feedback.md.
*/
-import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
+import { useLayoutEffect, useMemo, useRef, useState } from 'react';
import { X } from 'lucide-react';
+import useEscapeKey from '../../../hooks/useEscapeKey';
import { buildHighlightSegments } from '../../../lib/manuscriptAnchors';
-import ManuscriptCommentCard from './ManuscriptCommentCard';
+import { CommentCardFromProps } from './ManuscriptCommentCard';
import ManuscriptSectionFrame from './ManuscriptSectionFrame';
import { SEVERITY_UNDERLINE, SEVERITY_TONE, CATEGORY_LABEL, rowsFor } from './constants';
@@ -62,12 +63,7 @@ export default function ManuscriptLiveSection({
}, [openComment, content, segments]);
// Esc closes the popover.
- useEffect(() => {
- if (!openComment) return undefined;
- const onKey = (e) => { if (e.key === 'Escape') onCloseComment(); };
- window.addEventListener('keydown', onKey);
- return () => window.removeEventListener('keydown', onKey);
- }, [openComment, onCloseComment]);
+ useEscapeKey(openComment, onCloseComment);
return (
<ManuscriptSectionFrame section={section} saveState={saveState} onRevert={onRevert} registerRef={registerRef}>
@@ -144,18 +140,7 @@ export default function ManuscriptLiveSection({
</button>
</div>
<div className="p-2">
- <ManuscriptCommentCard
- comment={openComment}
- idScope={`live-${openComment.id}`}
- seriesId={commentCardProps.seriesId}
- providerOverride={commentCardProps.providerOverride}
- modelOverride={commentCardProps.modelOverride}
- onCommentChange={commentCardProps.onCommentChange}
- onAccepted={commentCardProps.onAccepted}
- draft={commentCardProps.fixDrafts[openComment.id]}
- onDraftChange={(entry) => commentCardProps.setCommentDraft(openComment.id, entry)}
- onJump={undefined}
- />
+ <CommentCardFromProps comment={openComment} commentCardProps={commentCardProps} idScope={`live-${openComment.id}`} />
</div>
</div>
</div>
diff --git a/client/src/hooks/README.md b/client/src/hooks/README.md
index 9811cd28e1..f13b70301c 100644
--- a/client/src/hooks/README.md
+++ b/client/src/hooks/README.md
@@ -80,6 +80,7 @@ grep -i "what you want to do" client/src/hooks/README.md
| `useArmedAction` | Two-click-arm `[armed, fire]` confirmation. | Destructive button needing a confirm tap. (Project memory: user finds this less discoverable — prefer inline confirm rows for new UI.) |
| `useAutoRefetch` | Poll-based refetch on an interval. `{ pollOnly: true }` skips internal data/loading state for side-effect-only callers (returns `{ refetch }` only). | Data needs periodic refresh (no socket / SSE available). |
| `useClickOutside` | Fire `onOutside` on mousedown outside a ref. | Popovers, menus, drawers. |
+| `useEscapeKey` | `useEscapeKey(active, handler)` — call `handler` on Escape while `active`. | Non-modal dismissables (in-context popovers/cards); Modal owns Esc for true modals. |
| `useCmdKSearch` | `⌘K` open/close state. | Anywhere that needs to toggle the palette. |
| `useContainerWidth` | `[ref, width]` via ResizeObserver. | Layout responds to a specific container's width. |
| `useCooldownTick` | 1-second ticker over a `{ id: epochMs }` cooldown map; fires `onAllExpired` once when every deadline passes. | Rate-limit countdown labels that need to refetch when the last cooldown clears (agents tabs pattern). |
diff --git a/client/src/hooks/index.js b/client/src/hooks/index.js
index 0fea6e2af6..a536051e79 100644
--- a/client/src/hooks/index.js
+++ b/client/src/hooks/index.js
@@ -11,6 +11,7 @@
export { default as useCityAudio } from './useCityAudio.js';
export { default as useClickOutside } from './useClickOutside.js';
export { default as useContainerWidth } from './useContainerWidth.js';
+export { default as useEscapeKey } from './useEscapeKey.js';
export { default as useFieldDraft } from './useFieldDraft.js';
export { default as useImageGenQueue } from './useImageGenQueue.js';
export { default as useImageRenderSettings } from './useImageRenderSettings.js';
diff --git a/client/src/hooks/useEscapeKey.js b/client/src/hooks/useEscapeKey.js
new file mode 100644
index 0000000000..82206d2959
--- /dev/null
+++ b/client/src/hooks/useEscapeKey.js
@@ -0,0 +1,16 @@
+import { useEffect } from 'react';
+
+/**
+ * Call `handler` when Escape is pressed, but only while `active` is truthy.
+ * Listener is attached/removed with `active`, so a closed popover/card doesn't
+ * keep a global keydown handler around. Use for non-modal dismissables (the
+ * Modal component already owns Esc for true modals).
+ */
+export default function useEscapeKey(active, handler) {
+ useEffect(() => {
+ if (!active) return undefined;
+ const onKey = (e) => { if (e.key === 'Escape') handler(); };
+ window.addEventListener('keydown', onKey);
+ return () => window.removeEventListener('keydown', onKey);
+ }, [active, handler]);
+}
diff --git a/server/services/pipeline/manuscriptFix.js b/server/services/pipeline/manuscriptFix.js
index aec3fc22a4..accc924f60 100644
--- a/server/services/pipeline/manuscriptFix.js
+++ b/server/services/pipeline/manuscriptFix.js
@@ -106,7 +106,10 @@ function normalizeFix(content, targets) {
replace,
};
if (typeof raw.note === 'string' && raw.note.trim()) edit.note = raw.note.trim().slice(0, 1000);
- if (!(section.content || '').includes(find)) edit.fuzzy = true;
+ // Flag fuzzy only when the find can't be located even tolerating
+ // whitespace differences — i.e. accept would actually fail. A quote that
+ // differs only in spacing still applies, so it shouldn't warn.
+ if (!locateFindSpan(section.content || '', find)) edit.fuzzy = true;
return edit;
})
.filter(Boolean);