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
re-attach orphaned closing quotes and make manuscript reflow threshold-free
[._.]/ Adam Eivyb4b9121d48c5
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 841e2dc3af..fd17becc25 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -4,7 +4,7 @@- **Video LoRAs now fuse on the bf16 LTX-2.3 Unified Beta (mlx_video runtime), not just dgrauet** — Previously a video LoRA like `ltx2.3-audio-reactive-lora` only worked on the dgrauet `ltx2` runtime; selecting the higher-quality **LTX-2.3 Unified Beta** (notapalindrome's `mlx_video` runtime) silently hid the LoRA picker. The stock `mlx_video.generate_av` CLI has no `--lora` flag, but the `mlx-video-with-audio` package ships an LTX-aware LoRA subsystem (`mlx_video.lora`) that's simply never called from the AV generator. A new wrapper (`scripts/generate_av_lora.py`) closes that gap without reimplementing the ~1000-line generation loop: it loads the user LoRAs, monkeypatches generate_av's two transformer-weight load seams to merge the LoRA deltas into the transformer (bf16, `quantization_bits=0`), then runs generate_av's own `main()` — so the SSE progress protocol is byte-for-byte identical to the non-LoRA path. The VideoGen picker now appears for non-quantized LTX-2.x `mlx_video` models too (gated by `isMlxVideoLtxLoraCapable`); if a LoRA's keys don't match the model the render fails loudly rather than silently producing a base video. Scoped to bf16 — the quantized Distilled Q4/Q8 variants stay on the dgrauet path for now and show an inline hint pointing at the supported models. (`scripts/generate_av_lora.py`, `server/lib/runners.js`, `server/services/videoGen/local.js`, `server/routes/videoGen.js`, `client/src/lib/runnerFamilies.js`, `client/src/pages/VideoGen.jsx`)-- **"Format" button on each manuscript section cleans up pasted-PDF artifacts.** Text pasted out of a PDF export arrives hard-wrapped at the page margin (every visual line a real `\n`), with stylized drop-caps split onto their own line ("T\nhe dawn …") and words hyphenated across the wrap ("approxi-\nmating") — so a paragraph reads as a column of ragged lines. A new **Format** button in each section's header (both Live and Review modes) normalizes the section: it rejoins drop-caps, repairs hyphen splits, strips trailing whitespace, and collapses runaway blank lines for every stage, and — for **prose** only — reflows the soft-wrapped lines back into paragraphs (comic/teleplay keep their structural line breaks). The reflow heuristic keys on lowercase line continuations (a real sentence never starts lowercase) and falls back to measured wrap width for the ambiguous capital-start case, so short headings/attributions stay on their own line. The prior text is snapshotted server-side, so History ▸ Revert undoes a format in one click. (`client/src/lib/manuscriptFormat.js`, `client/src/components/pipeline/manuscript/ManuscriptSectionFrame.jsx`, `client/src/pages/PipelineManuscriptEditor.jsx`)+- **"Format" button on each manuscript section cleans up pasted-PDF artifacts.** Text pasted out of a PDF export arrives hard-wrapped at the page margin (every visual line a real `\n`), with stylized drop-caps split onto their own line ("T\nhe dawn …"), words hyphenated across the wrap ("approxi-\nmating"), and closing quotes orphaned from the text they terminate (alone on a line, wrapped to the next line, or with a stray space before them) — so a paragraph reads as a column of ragged lines. A new **Format** button in each section's header (both Live and Review modes) normalizes the section: it rejoins drop-caps, repairs hyphen splits, strips trailing whitespace, and collapses runaway blank lines for every stage, and — for **prose** only — re-attaches orphaned closing quotes and reflows the soft-wrapped lines back into paragraphs (comic/teleplay keep their structural line breaks). The reflow joins a line onto the previous one only when it begins with a lowercase letter — a real sentence/paragraph/heading never starts lowercase, so headings and attributions keep their own line and two paragraphs are never fused (a global line-width threshold is unsound on documents that mix already-joined and still-wrapped paragraphs). The prior text is snapshotted server-side, so History ▸ Revert undoes a format in one click. (`client/src/lib/manuscriptFormat.js`, `client/src/components/pipeline/manuscript/ManuscriptSectionFrame.jsx`, `client/src/pages/PipelineManuscriptEditor.jsx`)## Changeddiff --git a/client/src/lib/manuscriptFormat.js b/client/src/lib/manuscriptFormat.jsindex 5f85151d4a..a1f1068a88 100644--- a/client/src/lib/manuscriptFormat.js+++ b/client/src/lib/manuscriptFormat.js@@ -3,28 +3,33 @@** The motivating mess: text pasted out of a PDF export arrives hard-wrapped at* the page margin (every visual line is a real `\n`), with stylized drop-caps- * split onto their own line ("T\nhe dawn …") and words hyphenated across the- * wrap ("approxi-\nmating"). `formatManuscript(text, stageId)` undoes those- * paste artifacts so a paragraph reads as one logical line again.+ * split onto their own line ("T\nhe dawn …"), words hyphenated across the wrap+ * ("approxi-\nmating"), and closing quotes orphaned from the text they+ * terminate (alone on a line, wrapped to the next line, or with a stray space+ * before them). `formatManuscript(text, stageId)` undoes those paste artifacts+ * so a paragraph reads as one logical line again.** Two altitudes, chosen by stage:- * - prose → full reflow: join soft-wrapped lines back into paragraphs.+ * - prose → full reflow: join soft-wrapped lines back into paragraphs, plus+ * quote re-attachment.* - comic / teleplay / anything else → conservative cleanup ONLY. Scripts* carry meaning in their line breaks (scene headings, panel descriptions,- * character cues), so we never reflow them — we only fix the unambiguous- * artifacts (drop-caps, hyphen splits, trailing whitespace, blank-line runs).+ * character cues), so we never reflow or touch their quotes — we only fix+ * the unambiguous artifacts (drop-caps, hyphen splits, trailing whitespace,+ * blank-line runs).** Reflow heuristic (the hard part — PDF paste usually has NO blank lines between- * paragraphs, so we can't key on those alone):- * A newline between `prev` and `cur` is a SOFT WRAP (join the lines) when —- * 1. `cur` begins with a lowercase letter. A real sentence/paragraph never- * starts lowercase, so this is the high-confidence signal and does the- * bulk of the work.- * 2. `cur` begins with a capital/quote/dash (ambiguous: could be a new- * sentence OR a wrapped proper noun). Fall back to width: if `prev`- * reached near the measured wrap margin it was wrapped → join; if `prev`- * is short it ended deliberately (paragraph end, heading, dialogue) → keep.- * Blank lines always separate paragraphs and are never crossed.+ * paragraphs, and a document is often a MIX of already-joined single-line+ * paragraphs and genuinely-wrapped ones, so a global line-width threshold is+ * unsound — it both pulls the next paragraph into a long complete one and fails+ * to recognize a wrapped line once a longer paragraph raises the bar):+ * Join a line onto the previous one ONLY when it begins with a lowercase+ * letter. A real sentence, paragraph, heading, or attribution never starts+ * lowercase, so this is the one near-zero-false-positive signal. A+ * capital/quote/dash start keeps its break — it might be a new paragraph, and+ * a wrong join (merging two paragraphs or swallowing a heading) is far more+ * destructive than leaving one extra break. Blank lines always separate+ * paragraphs and are never crossed.** Pure + dependency-free (no DOM) so it runs in node test env too.*/@@ -33,14 +38,6 @@// else (comicScript, teleplay, …) gets the conservative pass only.export const REFLOW_STAGES = new Set(['prose']);-// A line at least this fraction of the measured wrap width is treated as "full"-// (i.e. it hit the margin and was wrapped). Only consulted when the NEXT line-// starts with a capital/quote/dash (ambiguous) — lowercase continuations join-// outright. Kept high so short heading/attribution lines stay below it and are-// not swallowed into the paragraph that follows; a wrapped line that ends a-// little early before a capitalized word just keeps its break (the safe miss).-const FULL_LINE_RATIO = 0.8;-const stripTrailingWs = (text) => text.split('\n').map((l) => l.replace(/[ \t]+$/, '')).join('\n');// Join a syllable hyphenated across a wrap: "approxi-\nmating" → "approximating".@@ -56,39 +53,44 @@ const dehyphenate = (text) => text.replace(/([A-Za-z])-\n([a-z])/g, '$1$2');// "T\nhe dawn" → "The dawn". Lookahead keeps the next line's first char.const rejoinDropCaps = (text) => text.replace(/^([A-Z])\n(?=[a-z])/gm, '$1');+// Re-attach closing double-quotes the PDF export orphaned. Three artifacts, all+// keyed on a `"` separated from the text it should hug. (Straight quotes only —+// a closing quote is one preceded by text / whitespace, never one immediately+// followed by a word, which is how an opening quote reads.)+const reattachQuotes = (text) => text+ // A `"` alone on its own line collapses up onto the previous line:+ // …diagnostics.\n"\n— Maggie → …diagnostics."\n— Maggie+ .replace(/\n[ \t]*"[ \t]*(?=\n|$)/g, '"')+ // A `"` that wrapped to the START of the next line, followed by more text,+ // hugs the previous line instead (no inserted space — it's a closing quote):+ // Panel Seven,\n" I say → Panel Seven," I say+ .replace(/\n[ \t]*"(?=[ \t]+\S)/g, '"')+ // A stray space before a closing `"` at end of line:+ // relationships. " → relationships."+ .replace(/[ \t]+"(?=[ \t]*$)/gm, '"');+// Collapse 3+ consecutive newlines to a single blank line, then trim the ends.const tidyBlankLines = (text) => text.replace(/\n{3,}/g, '\n\n').trim();function reflowProse(text) {const lines = text.split('\n');- // reduce (not Math.max(...spread)) so a manuscript with very many lines can't- // blow the argument-count limit and throw.- const maxLen = lines.reduce((max, l) => (l.trim() ? Math.max(max, l.length) : max), 0);- const fullThreshold = maxLen * FULL_LINE_RATIO;-const out = [];- let prevBlank = true; // start-of-text behaves like just after a paragraph break- let prevFull = false; // was the last consumed line near the wrap margin?+ let prevBlank = true; // start-of-text behaves like just after a paragraph breakfor (const raw of lines) {const line = raw.trim();if (line === '') {out.push('');prevBlank = true;- prevFull = false;continue;}- // A newline is a soft wrap when the next line continues lowercase, or — when- // ambiguous — when the previous line ran to the margin.- const continuesLower = /^[a-z]/.test(line);- const softWrap = !prevBlank && (continuesLower || prevFull);- if (softWrap) {+ // Join onto the previous line only when this line continues it lowercase.+ if (!prevBlank && /^[a-z]/.test(line)) {out[out.length - 1] = `${out[out.length - 1]} ${line}`;} else {out.push(line);}prevBlank = false;- prevFull = raw.length >= fullThreshold;}return out.join('\n');}@@ -106,7 +108,10 @@ export function formatManuscript(text, stageId) {out = stripTrailingWs(out);out = dehyphenate(out);out = rejoinDropCaps(out);- if (REFLOW_STAGES.has(stageId)) out = reflowProse(out);+ if (REFLOW_STAGES.has(stageId)) {+ out = reattachQuotes(out);+ out = reflowProse(out);+ }out = tidyBlankLines(out);return out;}diff --git a/client/src/lib/manuscriptFormat.test.js b/client/src/lib/manuscriptFormat.test.jsindex db7f072fa4..5e2c405fcc 100644--- a/client/src/lib/manuscriptFormat.test.js+++ b/client/src/lib/manuscriptFormat.test.js@@ -61,6 +61,17 @@ describe('formatManuscript — prose reflow', () => {);});+ it('never merges two already-single-line paragraphs (no false join)', () => {+ // Each paragraph is already one line and ends mid-thought without terminal+ // punctuation; a width-threshold heuristic would wrongly fuse them. The+ // lowercase-continuation rule keeps capital-started paragraphs apart.+ const input = [+ 'The console hums to life, same as every morning',+ 'Maggie does not look up from her diagnostic sweep',+ ].join('\n');+ expect(formatManuscript(input, 'prose')).toBe(input);+ });+it('is idempotent — formatting clean prose is a no-op', () => {const clean = 'A tidy paragraph that needs no changes at all.';const once = formatManuscript(clean, 'prose');@@ -69,6 +80,60 @@ describe('formatManuscript — prose reflow', () => {});});+describe('formatManuscript — orphaned closing quotes (prose)', () => {+ it('collapses a closing quote left alone on its own line', () => {+ const input = '"The universe is under no obligation to make sense.\n"\n— Maggie Lam';+ expect(formatManuscript(input, 'prose')).toBe(+ '"The universe is under no obligation to make sense."\n— Maggie Lam',+ );+ });++ it('re-attaches a closing quote that wrapped to the start of the next line', () => {+ const input = '"Good morning, Panel Seven,\n" I say, because someone has to talk first.';+ expect(formatManuscript(input, 'prose')).toBe(+ '"Good morning, Panel Seven," I say, because someone has to talk first.',+ );+ });++ it('removes a stray space before a closing quote at end of line', () => {+ const input = '"That\'s more than I can say for most of my relationships. "';+ expect(formatManuscript(input, 'prose')).toBe(+ '"That\'s more than I can say for most of my relationships."',+ );+ });++ it('does not strip the space before an opening quote mid-line', () => {+ const clean = 'She said "hello" and walked on.';+ expect(formatManuscript(clean, 'prose')).toBe(clean);+ });++ it('cleans the full pasted epigraph + dialogue block end to end', () => {+ const input = [+ 'Chapter 1: Anomalous Readings',+ '"The universe is under no obligation to make sense to you, but it will absolutely mess with your diagnostics.',+ '"',+ '— Maggie Lam, maintenance log entry #4,072',+ "The universe is under no obligation to make sense to me, but at 0347 station time, I'm not asking it to.",+ '"Good morning, Panel Seven,',+ '" I say, because someone has to talk first.',+ '"You look stable. That\'s more than I can say for most of my relationships. "',+ ].join('\n');+ expect(formatManuscript(input, 'prose')).toBe([+ 'Chapter 1: Anomalous Readings',+ '"The universe is under no obligation to make sense to you, but it will absolutely mess with your diagnostics."',+ '— Maggie Lam, maintenance log entry #4,072',+ "The universe is under no obligation to make sense to me, but at 0347 station time, I'm not asking it to.",+ '"Good morning, Panel Seven," I say, because someone has to talk first.',+ '"You look stable. That\'s more than I can say for most of my relationships."',+ ].join('\n'));+ });++ it('leaves script quotes alone — no reflow or quote surgery off the prose path', () => {+ const input = 'CAPTION: "Good morning,\n" she says.';+ expect(formatManuscript(input, 'comicScript')).toBe(input);+ });+});+describe('formatManuscript — conservative (non-prose) stages', () => {it('does NOT reflow a comic script — line breaks are structural', () => {const input = [