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

feat: keyboard shortcuts for editorial comment triage (#1603)

[._.]/ Adam Eivy0cdcbad58b2f
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index ed3e381366..d5f29c894e 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -99,6 +99,8 @@
- **[issue-1594] The cast representation check now catches per-character dialogue imbalance, not just one dominant voice.** `cast.representation-balance` already flagged the *top* speaker hogging the page, but a lopsided cast can fail two other ways it never saw: a **major character who appears in the prose yet barely speaks** (a lead reduced to a passenger in their own story) and a **minor character who dominates the conversation** (a walk-on whose page time doesn't match the bible). The check now adds a per-character distribution signal that compares each character's attributed dialogue share against their **stated canon role** — classifying the free-text `role` field into a coarse *major* (protagonist, lead, antagonist, …) / *minor* (background, cameo, walk-on, …) / *unknown* tier, and flagging the silent-major and dominant-minor outliers. It reuses the same dialogue attribution the share signal already runs (no extra pass), gates the silent-major case on the character actually appearing in the prose (a major who never appears is *absent*, a different signal — not "oddly silent"), and stays silent on any character whose role is blank, ambiguous, or contradictory ("minor antagonist") rather than guessing — the same absent-vs-empty discipline the gender inference uses. Two new per-series thresholds tune it: a max dialogue share for a minor character (default 35%) and a min share for a major (default 5%), each independently disable-able. It stays a default-on, deterministic, advisory (low-severity) series signal. (`server/lib/editorial/checkRegistry.js`)
+- **[issue-1603] The editorial comment card is now keyboard-drivable, so a triage pass is one keystroke per note instead of a mouse round-trip.** Reviewing findings forced you to reach for the mouse for every Accept / Dismiss / Generate, and stepping between open notes meant detouring back through the sidebar. The open note's card now responds to keyboard shortcuts — **← / →** (or **k / j**, vim-style) to step prev/next through the triage order, **a** to accept the suggested fix, **d** to dismiss, and **g** to generate or regenerate the fix — with an on-screen hint row in the card showing the keys available for that note. The shortcuts never fire while you're typing in the replacement textarea or the manuscript editor (and ⌘/Ctrl chords still reach the browser), so letters never misfire. (`client/src/hooks/useKeyboardShortcuts.js`, `client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx`)
+
## Series Autopilot
- **[issue-1510] Series Autopilot now catches whole-book continuity problems at the cheap beat stage, before it generates full scripts.** The autopilot reviewed continuity at two altitudes — the cross-volume synopsis pass (before beats exist) and the full-text editorial pass (after every issue's script is written, the most expensive stage) — leaving a gap in between. So structural defects spanning the whole book (a cliffhanger raised in one issue and never resolved, a finale that drifts onto a new subplot instead of landing the arc's intended ending, a promised through-line that never pays off, an event staged as the "first" in two different issues, a broken volume-to-volume hand-off) were only caught *after* all the scripts already existed — or not until a human read it. The autopilot now runs a **whole-manuscript beat-continuity pass over every issue's beat sheet, between beat generation and script generation**. Blocking findings are auto-resolved by rewriting just the affected issues' beats and re-checking (bounded, then it pauses for review with the residual findings), so the fix lands before any script is generated. The full-text editorial pass is unchanged and still catches what only the verbatim script can show (pacing, repeated/looping passages, dialogue craft). A new **Beat continuity rounds** control in the autopilot Options tunes how many auto-resolve rounds it attempts (0 skips the pass), saved as a per-install default like the existing Arc-verify and Editorial round knobs.
diff --git a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx
index 626b1b93fd..55876496cc 100644
--- a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx
+++ b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx
@@ -17,6 +17,7 @@ import SideBySideDiff from '../../ui/SideBySideDiff';
import toast from '../../ui/Toast';
import { copyToClipboard } from '../../../lib/clipboard';
import { useAsyncAction } from '../../../hooks/useAsyncAction';
+import useKeyboardShortcuts from '../../../hooks/useKeyboardShortcuts';
import {
patchPipelineManuscriptComment, generatePipelineManuscriptFix, acceptPipelineManuscriptFix,
} from '../../../services/api';
@@ -38,6 +39,37 @@ export function CopyId({ id }) {
);
}
+// A single keycap for the on-screen shortcut hints.
+function Kbd({ children }) {
+ return (
+ <kbd className="rounded border border-port-border bg-port-bg px-1 font-mono text-[9px] leading-tight text-gray-400">
+ {children}
+ </kbd>
+ );
+}
+
+// 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 }) {
+ return (
+ <div className="flex flex-wrap items-center gap-x-2.5 gap-y-1 pt-1.5 text-[10px] text-gray-600">
+ {hasNav ? (
+ <span className="inline-flex items-center gap-1"><Kbd>←</Kbd><Kbd>→</Kbd> step</span>
+ ) : null}
+ {hasFix ? (
+ <>
+ <span className="inline-flex items-center gap-1"><Kbd>a</Kbd> accept</span>
+ <span className="inline-flex items-center gap-1"><Kbd>g</Kbd> regenerate</span>
+ </>
+ ) : (
+ <span className="inline-flex items-center gap-1"><Kbd>g</Kbd> generate</span>
+ )}
+ <span className="inline-flex items-center gap-1"><Kbd>d</Kbd> dismiss</span>
+ </div>
+ );
+}
+
export function Badge({ comment }) {
return (
<span className="flex items-center gap-1.5">
@@ -177,6 +209,24 @@ export default function ManuscriptCommentCard({
const fuzzy = comment.fix?.fuzzy || fixEdits.some((e) => e.fuzzy);
const Diff = diffStyle === 'side' ? SideBySideDiff : InlineDiff;
+ // At least one selected edit carries usable replacement text — gates both the
+ // Accept button and its `a` shortcut so neither fires an empty apply.
+ const canAccept = hasFix && fixEdits.some((_, i) => selectedEdits[i] && (editDrafts[i] || '').trim());
+
+ // Keyboard-driven triage over the open note (#1603): ←/→ (or k/j, vim-style)
+ // step prev/next through the triage order, a=accept, d=dismiss, g=generate/
+ // regenerate. Only one comment card mounts at a time (the open note), so the
+ // single global binding here can't collide. The hook ignores keys typed into
+ // the replacement textarea / manuscript editor, so letters never misfire.
+ useKeyboardShortcuts(true, {
+ ArrowLeft: nav?.onPrev,
+ ArrowRight: nav?.onNext,
+ k: nav?.onPrev,
+ j: nav?.onNext,
+ a: hasFix && canAccept && !accepting ? accept : undefined,
+ d: !accepting ? dismiss : undefined,
+ g: !generating && !accepting ? generate : undefined,
+ });
return (
<div className="border border-port-border rounded-lg bg-port-bg/40 p-2.5 space-y-2">
@@ -295,7 +345,7 @@ export default function ManuscriptCommentCard({
<button
type="button"
onClick={accept}
- disabled={accepting || !fixEdits.some((_, i) => selectedEdits[i] && (editDrafts[i] || '').trim())}
+ disabled={accepting || !canAccept}
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"
>
{accepting ? <Loader2 size={12} className="animate-spin" /> : <Check size={12} />}
@@ -321,6 +371,8 @@ export default function ManuscriptCommentCard({
<X size={12} /> Dismiss
</button>
</div>
+
+ <ShortcutHints hasNav={!!nav} hasFix={hasFix} />
</div>
);
}
diff --git a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.test.jsx b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.test.jsx
new file mode 100644
index 0000000000..6c3a948955
--- /dev/null
+++ b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.test.jsx
@@ -0,0 +1,120 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { render, screen, fireEvent, waitFor } from '@testing-library/react';
+import ManuscriptCommentCard from './ManuscriptCommentCard';
+import { Toaster } from '../../ui/Toast';
+import {
+ acceptPipelineManuscriptFix,
+ patchPipelineManuscriptComment,
+ generatePipelineManuscriptFix,
+} from '../../../services/api';
+
+vi.mock('../../../services/api', () => ({
+ acceptPipelineManuscriptFix: vi.fn(),
+ patchPipelineManuscriptComment: vi.fn(),
+ generatePipelineManuscriptFix: vi.fn(),
+}));
+
+const baseComment = {
+ id: 'c1',
+ status: 'open',
+ severity: 'high',
+ category: 'clarity',
+ problem: 'Confusing sentence',
+ issueNumber: 5,
+};
+const withFix = {
+ ...baseComment,
+ fix: { edits: [{ find: 'old text', replace: 'new text', issueNumber: 5 }] },
+};
+
+const renderCard = (props) => render(
+ <>
+ <ManuscriptCommentCard
+ comment={baseComment}
+ seriesId="ser-1"
+ onCommentChange={vi.fn()}
+ onAccepted={vi.fn()}
+ draft={null}
+ onDraftChange={vi.fn()}
+ {...props}
+ />
+ <Toaster />
+ </>,
+);
+
+// Single-key shortcut dispatched against document.body (no editable focus).
+const pressKey = (key) => fireEvent.keyDown(window, { key });
+
+describe('ManuscriptCommentCard keyboard shortcuts (#1603)', () => {
+ beforeEach(() => {
+ acceptPipelineManuscriptFix.mockReset();
+ patchPipelineManuscriptComment.mockReset();
+ generatePipelineManuscriptFix.mockReset();
+ });
+
+ it('shows generate hint (and not accept) when the note has no fix yet', () => {
+ renderCard();
+ expect(screen.getByText('generate')).toBeTruthy();
+ expect(screen.queryByText('accept')).toBeNull();
+ expect(screen.getByText('dismiss')).toBeTruthy();
+ });
+
+ it('g triggers generate when there is no fix', () => {
+ generatePipelineManuscriptFix.mockResolvedValue({ comment: baseComment });
+ renderCard();
+ pressKey('g');
+ expect(generatePipelineManuscriptFix).toHaveBeenCalledWith('ser-1', 'c1', expect.any(Object));
+ });
+
+ it('d dismisses the note via the patch endpoint', async () => {
+ patchPipelineManuscriptComment.mockResolvedValue({ comment: { ...baseComment, status: 'dismissed' } });
+ renderCard();
+ pressKey('d');
+ await waitFor(() => expect(patchPipelineManuscriptComment).toHaveBeenCalledWith(
+ 'ser-1', 'c1', { status: 'dismissed' }, { silent: true },
+ ));
+ });
+
+ it('a accepts the suggested fix when one exists, and shows accept/regenerate hints', () => {
+ acceptPipelineManuscriptFix.mockResolvedValue({ comment: { ...withFix, status: 'accepted' } });
+ renderCard({ comment: withFix });
+ expect(screen.getByText('accept')).toBeTruthy();
+ expect(screen.getByText('regenerate')).toBeTruthy();
+ pressKey('a');
+ expect(acceptPipelineManuscriptFix).toHaveBeenCalledWith('ser-1', 'c1', expect.objectContaining({
+ edits: expect.arrayContaining([expect.objectContaining({ replace: 'new text' })]),
+ }));
+ });
+
+ it('arrow keys step through the triage order, and the step hint renders only with nav', () => {
+ const onPrev = vi.fn();
+ const onNext = vi.fn();
+ const nav = { index: 1, total: 3, onPrev, onNext };
+ const { rerender } = renderCard({ nav });
+ expect(screen.getByText('step')).toBeTruthy();
+ pressKey('ArrowRight');
+ expect(onNext).toHaveBeenCalledTimes(1);
+ pressKey('ArrowLeft');
+ expect(onPrev).toHaveBeenCalledTimes(1);
+ // vim aliases
+ pressKey('j');
+ expect(onNext).toHaveBeenCalledTimes(2);
+ pressKey('k');
+ expect(onPrev).toHaveBeenCalledTimes(2);
+
+ rerender(
+ <>
+ <ManuscriptCommentCard comment={baseComment} seriesId="ser-1" onCommentChange={vi.fn()} onAccepted={vi.fn()} draft={null} onDraftChange={vi.fn()} />
+ <Toaster />
+ </>,
+ );
+ expect(screen.queryByText('step')).toBeNull();
+ });
+
+ it('does not fire a shortcut while typing in an editable field', () => {
+ renderCard({ comment: withFix });
+ const textarea = screen.getByLabelText(/Replacement \(editable\)/i);
+ fireEvent.keyDown(textarea, { key: 'd' });
+ expect(patchPipelineManuscriptComment).not.toHaveBeenCalled();
+ });
+});
diff --git a/client/src/hooks/README.md b/client/src/hooks/README.md
index 33e8b32e34..f940931f25 100644
--- a/client/src/hooks/README.md
+++ b/client/src/hooks/README.md
@@ -90,6 +90,7 @@ grep -i "what you want to do" client/src/hooks/README.md
| `useRowDraft` | Multi-column row draft (analogue of `useFieldDraft`). | Multi-column row that commits as a unit. |
| `usePendingListRows` | List-of-rows where a new row is held client-side until a required column fills, then promoted to `onChange`. | Editable list whose nameless rows would otherwise be dropped by the server sanitizer (WardrobeSection, CharacterDetailEditor list sections). |
| `useKeyboardControls` | Keyboard binding for CyberCity mode toggle. | CyberCity-specific. |
+| `useKeyboardShortcuts` | `useKeyboardShortcuts(active, bindings)` — fire a `{ key: handler }` map while `active`; ignores events from editable fields (`isEditableTarget` also exported) and ⌘/Ctrl/Alt chords; a falsy handler disables that key. | Single-surface action shortcuts (editorial comment card prev/next + accept/dismiss/generate, #1603). Not for held-key/game input (that's `useKeyboardControls`). |
| `useKeyboardHelp` | Esc closes, even from inputs/textareas. | Help/cheatsheet modals. |
| `useLockToggle` | Optimistic-PATCH lock toggle. | New "lock this field/stage/arc" button — use this, do not re-implement. |
| `usePopoverPosition` | Viewport-clamped `{ left, top, width }` for a fixed-position portal popover anchored to a trigger; re-measures on open and rAF-coalesced on capture-phase scroll/resize. Returns `{ triggerRef, popoverRef, style, reposition }`; pass `anchorRef` to follow a parent-owned trigger. | Any portal-into-`<body>` menu/popover placed relative to a button (ThemeSwitcher, CollectionPickerShell) — use this instead of re-rolling the measure/flip/clamp/reflow plumbing. |
diff --git a/client/src/hooks/index.js b/client/src/hooks/index.js
index 2dd96371d8..c15f7d4056 100644
--- a/client/src/hooks/index.js
+++ b/client/src/hooks/index.js
@@ -26,6 +26,8 @@ export * from './useSingToScore.js';
export { default as useSongTraining } from './useSongTraining.js';
export { default as useMediaPreviewActions } from './useMediaPreviewActions.js';
export { default as useKeyboardControls } from './useKeyboardControls.js';
+export { default as useKeyboardShortcuts } from './useKeyboardShortcuts.js';
+export * from './useKeyboardShortcuts.js';
export { default as useMediaJobProgress } from './useMediaJobProgress.js';
export * from './useMediaJobSse.js';
export { default as useMoltworldWs } from './useMoltworldWs.js';
diff --git a/client/src/hooks/useKeyboardShortcuts.js b/client/src/hooks/useKeyboardShortcuts.js
new file mode 100644
index 0000000000..909b1e514b
--- /dev/null
+++ b/client/src/hooks/useKeyboardShortcuts.js
@@ -0,0 +1,41 @@
+import { useEffect, useRef } from 'react';
+
+// True when an event came from a field the user is typing into, so a single-key
+// shortcut (a/d/g/j/k) or a bare arrow never steals a keystroke or caret move.
+// The standard form fields plus any contentEditable surface count.
+export function isEditableTarget(el) {
+ if (!el || typeof el.tagName !== 'string') return false;
+ if (el.isContentEditable) return true;
+ return el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.tagName === 'SELECT';
+}
+
+/**
+ * Fire keyboard shortcuts while `active` is truthy. `bindings` maps a
+ * `KeyboardEvent.key` (e.g. `'a'`, `'ArrowLeft'`) to a handler; a falsy/absent
+ * handler for a key is a no-op so callers can disable a shortcut by passing
+ * `undefined` (e.g. an Accept that has no applicable fix). Events that originate
+ * from an editable field are ignored (so typing the letter `d` never dismisses),
+ * and any ⌘/Ctrl/Alt chord is skipped so app/browser shortcuts still win. The
+ * event is `preventDefault`-ed only when a binding actually matches.
+ *
+ * Bindings are read through a ref, so handlers recreated every render don't
+ * re-subscribe the listener — only `active` does. The listener detaches while
+ * inactive, so a closed card/popover keeps no global keydown handler around.
+ */
+export default function useKeyboardShortcuts(active, bindings) {
+ const bindingsRef = useRef(bindings);
+ bindingsRef.current = bindings;
+ useEffect(() => {
+ if (!active) return undefined;
+ const onKey = (e) => {
+ if (e.metaKey || e.ctrlKey || e.altKey) return;
+ if (isEditableTarget(e.target)) return;
+ const handler = bindingsRef.current[e.key];
+ if (typeof handler !== 'function') return;
+ e.preventDefault();
+ handler(e);
+ };
+ window.addEventListener('keydown', onKey);
+ return () => window.removeEventListener('keydown', onKey);
+ }, [active]);
+}
diff --git a/client/src/hooks/useKeyboardShortcuts.test.jsx b/client/src/hooks/useKeyboardShortcuts.test.jsx
new file mode 100644
index 0000000000..a22d46821d
--- /dev/null
+++ b/client/src/hooks/useKeyboardShortcuts.test.jsx
@@ -0,0 +1,99 @@
+import { describe, it, expect, vi, afterEach } from 'vitest';
+import { renderHook, fireEvent } from '@testing-library/react';
+import useKeyboardShortcuts, { isEditableTarget } from './useKeyboardShortcuts';
+
+// Dispatch a keydown from `target` (the listener reads e.target). Defaults to
+// the window itself, which is not an editable field. `fireEvent` returns false
+// when the event was canceled, so return that as `defaultPrevented`.
+function press(key, { target = window, meta = false, ctrl = false, alt = false } = {}) {
+ const notCanceled = fireEvent.keyDown(target, { key, metaKey: meta, ctrlKey: ctrl, altKey: alt });
+ return { defaultPrevented: !notCanceled };
+}
+
+afterEach(() => vi.restoreAllMocks());
+
+describe('isEditableTarget', () => {
+ it('flags the standard form fields and contentEditable, not plain elements', () => {
+ expect(isEditableTarget({ tagName: 'INPUT' })).toBe(true);
+ expect(isEditableTarget({ tagName: 'TEXTAREA' })).toBe(true);
+ expect(isEditableTarget({ tagName: 'SELECT' })).toBe(true);
+ expect(isEditableTarget({ tagName: 'DIV', isContentEditable: true })).toBe(true);
+ expect(isEditableTarget({ tagName: 'DIV' })).toBe(false);
+ expect(isEditableTarget(null)).toBe(false);
+ expect(isEditableTarget({})).toBe(false);
+ });
+});
+
+describe('useKeyboardShortcuts', () => {
+ it('fires the matching handler and preventDefaults the event', () => {
+ const a = vi.fn();
+ renderHook(() => useKeyboardShortcuts(true, { a }));
+ const event = press('a');
+ expect(a).toHaveBeenCalledTimes(1);
+ expect(event.defaultPrevented).toBe(true);
+ });
+
+ it('ignores keys with no binding without preventDefault', () => {
+ const a = vi.fn();
+ renderHook(() => useKeyboardShortcuts(true, { a }));
+ const event = press('b');
+ expect(a).not.toHaveBeenCalled();
+ expect(event.defaultPrevented).toBe(false);
+ });
+
+ it('does not bind while inactive', () => {
+ const a = vi.fn();
+ renderHook(() => useKeyboardShortcuts(false, { a }));
+ press('a');
+ expect(a).not.toHaveBeenCalled();
+ });
+
+ it('ignores events from editable fields (typing the letter never misfires)', () => {
+ const d = vi.fn();
+ renderHook(() => useKeyboardShortcuts(true, { d }));
+ const textarea = document.createElement('textarea');
+ document.body.appendChild(textarea);
+ press('d', { target: textarea });
+ document.body.removeChild(textarea);
+ expect(d).not.toHaveBeenCalled();
+ });
+
+ it('skips ⌘/Ctrl/Alt chords so app/browser shortcuts win', () => {
+ const a = vi.fn();
+ renderHook(() => useKeyboardShortcuts(true, { a }));
+ press('a', { meta: true });
+ press('a', { ctrl: true });
+ press('a', { alt: true });
+ expect(a).not.toHaveBeenCalled();
+ });
+
+ it('treats a falsy handler as a disabled shortcut (no throw, no preventDefault)', () => {
+ renderHook(() => useKeyboardShortcuts(true, { a: undefined }));
+ const event = press('a');
+ expect(event.defaultPrevented).toBe(false);
+ });
+
+ it('always calls the latest handler without re-subscribing on every render', () => {
+ const first = vi.fn();
+ const second = vi.fn();
+ const addSpy = vi.spyOn(window, 'addEventListener');
+ const { rerender } = renderHook(({ fn }) => useKeyboardShortcuts(true, { a: fn }), {
+ initialProps: { fn: first },
+ });
+ const keydownSubs = addSpy.mock.calls.filter(([type]) => type === 'keydown').length;
+ rerender({ fn: second });
+ press('a');
+ expect(first).not.toHaveBeenCalled();
+ expect(second).toHaveBeenCalledTimes(1);
+ // The handler swap must not have re-attached the window listener.
+ expect(addSpy.mock.calls.filter(([type]) => type === 'keydown').length).toBe(keydownSubs);
+ });
+
+ it('detaches the listener on unmount', () => {
+ const a = vi.fn();
+ const { unmount } = renderHook(() => useKeyboardShortcuts(true, { a }));
+ unmount();
+ press('a');
+ expect(a).not.toHaveBeenCalled();
+ });
+});