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: per-scene reading-level variance + target band in style.reading-level (#1625)

[._.]/ Adam Eivya1865ca0015f
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 25d6760208..dcced186b8 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -23,6 +23,7 @@
## Editorial checks
+- **[issue-1625] The reading-level check now reports per-scene variance, not just a single whole-corpus number.** `style.reading-level` measured one Flesch–Kincaid grade for the entire series and flagged drift from the style-guide target — but a single average hides the modulation a skilled writer uses (a quiet introspective scene reads lower, an action scene higher) and conceals a lone scene that swings far outside the intended band. The check now also splits the manuscript into scenes (reusing the shared `splitScenes` divider parser — markdown headings including the stitcher's `# Issue N`, and centered rules like `***`), measures each, and flags any scene whose grade falls outside the target **band** (`target ± sceneTolerance`), reporting the widest swings first. Three new per-series knobs join the existing whole-corpus tolerance: **per-scene band tolerance** (default 4 — wider than the corpus tolerance since scenes legitimately modulate), **minimum scene words to measure** (default 120 — short fragments are too noisy for a reliable FK estimate), and **max per-scene findings** (default 5 — so a long manuscript can't flood the review). The original whole-corpus finding is unchanged, and a single-scene manuscript reports only that — so existing series behavior is preserved. (`server/lib/editorial/checkRegistry.js`)
- **[issue-1622] The adverb, passive-voice, and repeated-gesture copy-edit checks are now series-tunable like their word-list siblings.** Clichés, said-bookisms, filter words, crutch words, hedge words, and gestures already accepted a house-style allowlist and an extra-words list, but `prose.adverbs` and `prose.passive-voice` didn't expose theirs (repeated-gestures already did). Now all three carry the same config: `prose.adverbs` gains an **extra-adverbs** list so a series can flag the real adverbs the `-ly` heuristic misses ("fast", "well", "hard"); `prose.passive-voice` gains a **house-style allowlist** (participles to never flag — archaic/adjectival "-ed" forms like "blessed", "beloved") and an **extra-participles** list (series-specific irregular participles the heuristic misses, e.g. "begun", "hewn"). A historical-fiction series can now whitelist archaic forms and a comedic series can mute gesture repetition without code changes. Additive config with empty-string defaults — existing series are unaffected. (`server/lib/editorial/proseTics.js`, `server/lib/editorial/checkRegistry.js`)
- **[issue-1624] A new editorial check flags objects whose narrative weight is out of proportion to their prominence.** The existing `objects.*` checks are presence tests — is a significant object attached to someone, is an interaction motivated, does an attachment's origin contradict its character — but none asked whether an object's *weight* matches how much the plot actually leans on it. The new `objects.weight-proportionality` check (series-scope, LLM, default-on) weighs each object's prominence in the prose against the depth of backstory and significance the story invests in it, and flags two failures: **over-weighted** (a minor object handed a disproportionate backstory — "a one-line locket with a three-issue origin") and **under-established** (a prominent or decisive object resting on no lineage — "an heirloom that resolves the finale, never set up"). It reads the stitched manuscript plus the canon object↔character attachment summary, judging the *proportion* rather than the absolute amount, and carries each object's established weight across manuscript chunks so a backstory planted early is weighed against a payoff that lands late. Stays distinct from `objects.unmotivated-interaction` (a single unmotivated beat) and `objects.backstory-consistency` (a contradicted origin) — the gap here is the over- or under-writing of plot machinery. Ships the prompt + stage-config for fresh installs and a boot migration (143) so existing installs seed the stage. (`server/lib/editorial/checkRegistry.js`, `data.reference/prompts/stages/pipeline-editorial-object-weight-proportionality.md`, `scripts/migrations/143-editorial-object-weight-proportionality-stage.js`)
- **[issue-1623] A new editorial check flags visually dense but emotionally empty scenes.** `sensory.balance` already flags all-visual scenes and sensory-*bare* scenes, but it missed the opposite failure: a scene rich in setting and physical detail that carries almost no POV reaction — "500 words of setting, zero interiority" reads just as flat as a bare one. The new `scene.interiority-balance` check (scene-scope, default-on) weighs each scene's *description-to-interiority ratio* and flags two cases — **description swamps reaction** (long passages of scenery/blocking with little interleaved thought, feeling, or appraisal) and **emotionally inert detail** (striking images that land with no reaction from the perceiving character). It reads the stitched manuscript plus the reverse-outline scene map and degrades to a whole-issue scan when no outline exists. It judges the *ratio*, not the absolute amount, so a richly described scene filtered through a reacting mind passes — and it stays distinct from `sensory.balance` (the five senses) and `interiority.protagonist` (whole-issue interiority absence). Ships the prompt + stage-config for fresh installs and a boot migration (142) so existing installs seed the stage. (`server/lib/editorial/checkRegistry.js`, `data.reference/prompts/stages/pipeline-editorial-interiority-balance.md`, `scripts/migrations/142-editorial-interiority-balance-stage.js`)
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.js
index 755039beed..3a85e73642 100644
--- a/server/lib/editorial/checkRegistry.js
+++ b/server/lib/editorial/checkRegistry.js
@@ -35,7 +35,7 @@ import {
import { analyzeBalloonAttribution } from './balloonAttribution.js';
import { analyzeNamePair, comparisonName, findFirstLetterClusters, normalizeName } from './nameSimilarity.js';
import { findCliches, findModifierStacking } from './cliches.js';
-import { findSaidBookisms, findUnattributedDialogueRuns, attributeDialogueByOwner, findDialogueTagVariety } from './dialogue.js';
+import { findSaidBookisms, findUnattributedDialogueRuns, attributeDialogueByOwner, findDialogueTagVariety, splitScenes } from './dialogue.js';
import { findItalicThoughts } from './italicThoughts.js';
import {
findFilterWords,
@@ -1524,6 +1524,40 @@ function readingGradeLevel(text) {
return 0.39 * (words.length / sentences) + 11.8 * (syllables / words.length) - 15.59;
}
+// Per-scene reading-grade spread (#1625). The whole-corpus grade above is a single
+// number for the entire series — it averages away the legitimate modulation a
+// skilled writer uses (a quiet introspective scene reads lower, an action scene
+// higher) AND it hides a lone scene that swings far outside the intended band.
+// Splits the manuscript into scenes via the shared `splitScenes` (markdown
+// headings — including the stitcher's `# Issue N` — and centered rules like
+// "***") and measures each one, so the check can surface the outliers the corpus
+// average conceals. Scenes shorter than `minWords` are skipped: a brief fragment's
+// FK estimate is too noisy to judge. Returns one row per measurable scene
+// (`{ ordinal, grade, words, text }`), or [] when none qualify.
+function readingLevelByScene(manuscript, minWords) {
+ const floor = Number.isFinite(minWords) ? minWords : 120;
+ const rows = [];
+ for (const scene of splitScenes(String(manuscript || ''))) {
+ const words = (scene.text.match(WORD_RE) || []).length;
+ if (words < floor) continue;
+ const grade = readingGradeLevel(scene.text);
+ if (grade == null) continue;
+ rows.push({ ordinal: scene.ordinal, grade: Math.round(grade * 10) / 10, words, text: scene.text });
+ }
+ return rows;
+}
+
+// First substantive line of a scene, trimmed to a short anchor so a per-scene
+// finding lands on real prose the editor can locate. Skips blank lines; falls
+// back to '' for a whitespace-only scene.
+function sceneReadingAnchor(text) {
+ for (const line of String(text || '').split('\n')) {
+ const t = line.trim();
+ if (t) return t.length > 80 ? `${t.slice(0, 80).trim()}…` : t;
+ }
+ return '';
+}
+
// Compact bullet list of the conformance-relevant style-guide expectations, fed
// to the conformance LLM so it knows exactly what to measure the prose against.
// Inlined (not imported from styleGuide.js) to keep this registry pure. Returns
@@ -5288,7 +5322,7 @@ export const EDITORIAL_CHECKS = [
sources: ['manuscript', 'series.styleGuide'],
label: 'Reading-level conformance',
description:
- "Measures the drafted manuscript's reading grade level (Flesch–Kincaid) and flags it when it drifts beyond a tolerance from the series style guide's target reading level.",
+ "Measures the drafted manuscript's reading grade level (Flesch–Kincaid) and flags it when the whole-corpus level drifts beyond a tolerance from the series style guide's target. Also reports per-scene reading-level variance: a single scene whose grade swings far outside the target band (target ± scene tolerance) is flagged even when the corpus average sits on target — surfacing the modulation a one-number check averages away.",
scope: 'series',
kind: 'deterministic',
category: 'style',
@@ -5297,19 +5331,57 @@ export const EDITORIAL_CHECKS = [
// Reads the stitched manuscript to measure the actual grade level.
needsManuscript: true,
configSchema: z.object({
- // How many grade levels the measured reading level may drift from the
+ // How many grade levels the whole-corpus reading level may drift from the
// target before it's flagged.
tolerance: z.number().int().min(0).max(6).default(2),
+ // Half-width of the per-scene target band: a scene whose grade lands more
+ // than this many levels from the target is flagged as an out-of-band swing.
+ // Wider than `tolerance` by default — scenes legitimately modulate, so only
+ // the extreme outliers are worth a finding.
+ sceneTolerance: z.number().int().min(1).max(8).default(4),
+ // Minimum words a scene needs before its reading level is judged — a short
+ // fragment's FK estimate is too noisy to trust.
+ minSceneWords: z.number().int().min(20).max(2000).default(120),
+ // Cap per-scene findings so a long manuscript with many outliers can't
+ // flood the review (worst swings are reported first).
+ maxSceneFindings: z.number().int().min(1).max(20).default(5),
}),
configFields: [
{
key: 'tolerance',
- label: 'Reading-level tolerance (grades)',
+ label: 'Whole-corpus tolerance (grades)',
type: 'number',
min: 0,
max: 6,
step: 1,
- help: 'How many grade levels the measured reading level may differ from the style-guide target before it is flagged.',
+ help: 'How many grade levels the whole-manuscript reading level may differ from the style-guide target before it is flagged.',
+ },
+ {
+ key: 'sceneTolerance',
+ label: 'Per-scene band tolerance (grades)',
+ type: 'number',
+ min: 1,
+ max: 8,
+ step: 1,
+ help: 'Half-width of the per-scene target band. A single scene whose reading level swings more than this many grades from the target is flagged, even when the whole-manuscript average is on target.',
+ },
+ {
+ key: 'minSceneWords',
+ label: 'Minimum scene words to measure',
+ type: 'number',
+ min: 20,
+ max: 2000,
+ step: 10,
+ help: 'Scenes shorter than this are skipped — a brief fragment is too short for a reliable reading-level estimate.',
+ },
+ {
+ key: 'maxSceneFindings',
+ label: 'Max per-scene findings',
+ type: 'number',
+ min: 1,
+ max: 20,
+ step: 1,
+ help: 'Cap on per-scene out-of-band findings so a long manuscript can not flood the review. The widest swings are reported first.',
},
],
// Only run when the style guide sets a target AND there's prose to measure.
@@ -5321,22 +5393,61 @@ export const EDITORIAL_CHECKS = [
const grade = readingGradeLevel(ctx.manuscript);
if (grade == null) return [];
const tolerance = ctx.config?.tolerance ?? 2;
+ const sceneTolerance = ctx.config?.sceneTolerance ?? 4;
+ const minSceneWords = ctx.config?.minSceneWords ?? 120;
+ const maxSceneFindings = ctx.config?.maxSceneFindings ?? 5;
+ const findings = [];
+
+ // 1. Whole-corpus drift from the target (the original #1303 behavior).
const rounded = Math.round(grade * 10) / 10;
const delta = rounded - target;
- if (Math.abs(delta) <= tolerance) return [];
- const tooHard = delta > 0;
- const off = Math.round(Math.abs(delta) * 10) / 10;
- return [{
- severity: ctx.severityDefault,
- category: 'style',
- location: 'Series manuscript (whole-corpus reading level)',
- problem: `The drafted manuscript reads at about a grade-${rounded} level, ${tooHard ? 'above' : 'below'} the style-guide target of grade ${target} (off by ${off} grade${off === 1 ? '' : 's'}).`,
- suggestion: tooHard
- ? 'Shorten sentences and prefer plainer words to bring the reading level down toward the target.'
- : 'Vary sentence length and vocabulary to raise the reading level toward the target.',
- anchorQuote: '',
- issueNumber: null,
- }];
+ if (Math.abs(delta) > tolerance) {
+ const tooHard = delta > 0;
+ const off = Math.round(Math.abs(delta) * 10) / 10;
+ findings.push({
+ severity: ctx.severityDefault,
+ category: 'style',
+ location: 'Series manuscript (whole-corpus reading level)',
+ problem: `The drafted manuscript reads at about a grade-${rounded} level, ${tooHard ? 'above' : 'below'} the style-guide target of grade ${target} (off by ${off} grade${off === 1 ? '' : 's'}).`,
+ suggestion: tooHard
+ ? 'Shorten sentences and prefer plainer words to bring the reading level down toward the target.'
+ : 'Vary sentence length and vocabulary to raise the reading level toward the target.',
+ anchorQuote: '',
+ issueNumber: null,
+ });
+ }
+
+ // 2. Per-scene variance (#1625): flag scenes whose grade falls outside the
+ // target band [target ± sceneTolerance]. The whole-corpus average above can
+ // hide a lone scene that swings far past the band, so report the worst
+ // out-of-band swings (capped). Needs at least 2 measurable scenes — a
+ // single-scene corpus has no spread to report beyond the whole-corpus check.
+ const bandLow = target - sceneTolerance;
+ const bandHigh = target + sceneTolerance;
+ const scenes = readingLevelByScene(ctx.manuscript, minSceneWords);
+ if (scenes.length >= 2) {
+ const outliers = scenes
+ .filter((s) => s.grade < bandLow || s.grade > bandHigh)
+ .map((s) => ({ ...s, deviation: s.grade > bandHigh ? s.grade - bandHigh : bandLow - s.grade }))
+ .sort((a, b) => b.deviation - a.deviation)
+ .slice(0, maxSceneFindings);
+ for (const s of outliers) {
+ const tooHard = s.grade > bandHigh;
+ findings.push({
+ severity: ctx.severityDefault,
+ category: 'style',
+ location: `Series manuscript — scene ${s.ordinal} (${s.words} words)`,
+ problem: `Scene ${s.ordinal} reads at about a grade-${s.grade} level, ${tooHard ? 'above' : 'below'} the target band of grade ${bandLow}–${bandHigh} (target ${target} ± ${sceneTolerance}). A single scene swinging this far outside the band is hidden by the whole-corpus average.`,
+ suggestion: tooHard
+ ? 'If this scene is meant to read denser (action, exposition), confirm it is intentional; otherwise shorten sentences and simplify vocabulary to pull it toward the band.'
+ : 'If this scene is meant to read simpler (quiet introspection, sparse dialogue), confirm it is intentional; otherwise vary sentence length and vocabulary to raise it toward the band.',
+ anchorQuote: sceneReadingAnchor(s.text),
+ issueNumber: null,
+ });
+ }
+ }
+
+ return findings;
},
},
{
diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.js
index 18aedc5229..43b42336cb 100644
--- a/server/lib/editorial/checkRegistry.test.js
+++ b/server/lib/editorial/checkRegistry.test.js
@@ -4457,6 +4457,56 @@ describe('style.reading-level — deterministic check (#1303)', () => {
expect(findings[0].problem).toMatch(/below/i);
});
+ // Per-scene reading-level variance (#1625). A scene-broken manuscript so
+ // `splitScenes` yields >1 measurable scene; `minSceneWords` lowered because the
+ // SIMPLE fixture is ~110 words (under the 120 default). A scene-level finding is
+ // identified by its "— scene N" location.
+ const sceneFindings = (findings) => findings.filter((f) => /— scene \d/i.test(f.location));
+ const BREAK = '\n\n* * *\n\n';
+
+ it('flags a single scene that swings ABOVE the target band', () => {
+ // Two calm scenes + one dense scene; the dense one breaks the band even if the
+ // averaged whole-corpus grade would not.
+ const manuscript = [MEDIUM, MEDIUM, DENSE].join(BREAK);
+ const findings = run({ readingLevel: 6 }, manuscript, { sceneTolerance: 3, minSceneWords: 20 });
+ const scenes = sceneFindings(findings);
+ expect(scenes.length).toBeGreaterThanOrEqual(1);
+ const above = scenes.find((f) => /above the target band/i.test(f.problem));
+ expect(above).toBeTruthy();
+ expect(above.location).toMatch(/— scene \d/i);
+ expect(above.anchorQuote).toBeTruthy();
+ expect(above.issueNumber).toBeNull();
+ });
+
+ it('flags a single scene that swings BELOW the target band', () => {
+ const manuscript = [DENSE, DENSE, SIMPLE].join(BREAK);
+ const findings = run({ readingLevel: 12 }, manuscript, { sceneTolerance: 3, minSceneWords: 20 });
+ const below = sceneFindings(findings).find((f) => /below the target band/i.test(f.problem));
+ expect(below).toBeTruthy();
+ expect(below.anchorQuote).toBeTruthy();
+ });
+
+ it('reports no per-scene findings when every scene sits within the band', () => {
+ const manuscript = [MEDIUM, MEDIUM, MEDIUM].join(BREAK);
+ const findings = run({ readingLevel: 7 }, manuscript, { tolerance: 6, sceneTolerance: 6, minSceneWords: 20 });
+ expect(sceneFindings(findings)).toHaveLength(0);
+ });
+
+ it('caps per-scene findings at maxSceneFindings (worst swings first)', () => {
+ // Six out-of-band dense scenes, cap of 2 → at most 2 scene findings.
+ const manuscript = Array(6).fill(DENSE).join(BREAK);
+ const findings = run({ readingLevel: 3 }, manuscript, { tolerance: 12, sceneTolerance: 4, minSceneWords: 20, maxSceneFindings: 2 });
+ expect(sceneFindings(findings)).toHaveLength(2);
+ });
+
+ it('does not emit per-scene findings for a single-scene manuscript', () => {
+ // No scene dividers → one scene → only the whole-corpus check can fire.
+ const findings = run({ readingLevel: 3 }, DENSE, { tolerance: 2, sceneTolerance: 1, minSceneWords: 20 });
+ expect(sceneFindings(findings)).toHaveLength(0);
+ expect(findings).toHaveLength(1);
+ expect(findings[0].location).toMatch(/whole-corpus/i);
+ });
+
it('is enabled by default', () => {
expect(check.defaultEnabled).toBe(true);
});