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

refactor: share one drafted-prose gate across editorial checks (#12977) (#13045)

[._.]/90cc2a46303d
diff --git a/server/lib/editorial/README.md b/server/lib/editorial/README.md
index c32da1d7ff..f2f98e4ec6 100644
--- a/server/lib/editorial/README.md
+++ b/server/lib/editorial/README.md
@@ -210,7 +210,7 @@ runner-injected `ctx.callInlineLLM` (an inline-prompt sibling of
| `checkRegistry.js` | The public entry point. Assembles `EDITORIAL_CHECKS` by spreading the per-category arrays from `./checks/*.js`, re-exports the shared infra from `./checkInfra.js`, and keeps the registry's lookup/state helpers that need the assembled array: `EDITORIAL_SOURCES` (the per-check `sources` vocabulary the staleness runner fingerprints, #1387), fail-fast guards (`assertValidChecks`), and `getCheck`, `getCheckById`, `getAllChecks`, `listChecks`, `resolveCheckState`, `getEnabledChecks`, `resolveCheckConfig`, `orderChecksByDependencies` (the dependency topo-sort, #1627) plus the user-defined-check helpers (`buildCustomCheck`, `readCustomCheckDefs`, `isCustomCheckId`, `isValidCustomCheckDef`). Decomposed from a 7,474-line god file in #1829. |
| `findingCategories.js` | Browser-safe human labels for built-in editorial-check and manuscript-completeness finding categories, shared by the registry parity guard and manuscript editor. |
| `checkInfra.js` | Shared check infrastructure extracted in #1829: imports + constants + stage names + the pure summary/helper functions (e.g. `runManuscriptLlmCheck`, `canonCharacterTraitsSummary`, `editorialFindingKey`, `buildCustomCheckPrompt`, `normalizeCheckScopes`/`primaryCheckScope`) that the check definitions and the registry tail depend on. Kept side-effect-free so `./checks/*.js` import from it without a cycle through `checkRegistry.js` (whose `EDITORIAL_CHECKS` spread would otherwise hit a TDZ on the checks' eagerly-evaluated `configSchema`s). Re-exports its externals (zod + the sibling primitive modules) so a check file imports everything from one hub. **Since #2842 this file is a pure re-exporting barrel over `./checkInfra/*.js`** (it had grown to 2,635 lines spanning a dozen sub-domains); every existing `from './checkInfra.js'` import still resolves, and new code may import the focused module directly. |
-| `checkInfra/*.js` | The sub-domain modules behind the `checkInfra.js` barrel (#2842, same treatment #1152 gave `arcPlanner.js`): `externals` (the zod/`estimateTokens`/sibling-scanner hub), `taxonomy` (scopes/kinds/severities/`EDITORIAL_SOURCES`/field types), `revealForeshadowing`, `craftStages`, `structureStages` (stage names + their prompt summaries), `voiceCanon` (voice/state/trait/continuity-ledger summaries), `povAndNames`, `canonScaffolding` (relationship-link + object-attachment walkers), `llmRunner` (chunked manuscript runs, prior-findings/setup digests, finding normalization, custom-check prompts), `readability`, `rosterCast`, `sceneAnalysis`, `proseDensity`, `comic` (lettering + comic↔prose sync). Import via the barrel or directly; `checkInfraBarrel.test.js` pins the re-export contract. |
+| `checkInfra/*.js` | The sub-domain modules behind the `checkInfra.js` barrel (#2842, same treatment #1152 gave `arcPlanner.js`): `externals` (the zod/`estimateTokens`/sibling-scanner hub), `taxonomy` (scopes/kinds/severities/`EDITORIAL_SOURCES`/field types), `revealForeshadowing`, `craftStages`, `structureStages` (stage names + their prompt summaries), `voiceCanon` (voice/state/trait/continuity-ledger summaries), `povAndNames`, `canonScaffolding` (relationship-link + object-attachment walkers), `llmRunner` (chunked manuscript runs, prior-findings/setup digests, finding normalization, custom-check prompts), `readability`, `rosterCast`, `sceneAnalysis`, `proseDensity`, `comic` (lettering + comic↔prose sync), `gates` (shared gate predicates such as `hasManuscript`). Import via the barrel or directly; `checkInfraBarrel.test.js` pins the re-export contract. |
| `checks/*.js` | The `EDITORIAL_CHECKS` definitions, grouped by category (#1829): `naming`, `cast`, `pov`, `characterArc`, `continuity` (incl. #2178 `continuity.premature-reveal` — the information-economy guard that flags a reveal-gated canon fact leaked before its reveal issue, reconciled against `revealGatedCanonSummary`; gated on `canonHasRevealGated`), `comic`, `visual`, `scene`, `dialogue`, `proseStyle`, `research`, `slop` (#2165 — `prose.slop-banned-words`/`prose.ai-tells`/`prose.structural-tics`/`prose.burstiness`, built on `../slopScore.js`), `world` (#2175 — `world.unforeshadowed-solution`/`world.cost-free-power`, the review-side companion to the Sanderson's-Laws worldbuilding doctrine injected into the universe-expansion generation prompt; reconciles against canon + the continuity-bible world-rule facts). Each exports a `<group>Checks` array of declarative check entries (scope, kind, severity, `configSchema`, `gate`, `run(ctx)`); `checkRegistry.js` imports and spreads them. Internal to the registry — imported only via `checkRegistry.js`, not the barrel. |
| `nameSimilarity.js` | Pure, dependency-free name-confusability primitives for `naming.dissimilar-names` (#1291): `normalizeName`, `vowelSkeleton`, `soundex` (phonetic key), `levenshtein` (edit distance), `nameSimilaritySignals` (the per-pair signal list, with option toggles), and `firstLetterHistogram` / `findFirstLetterClusters` (cast first-letter crowding). |
| `cliches.js` | Pure, dependency-free cliché + overwriting primitives for `prose.cliches` and `prose.modifier-stacking` (#1308): `CLICHE_PHRASES` (seed stock-simile/idiom list), `findCliches` (whole-word phrase scan with house-style allow/extra lists), and `findModifierStacking` (cumulative no-comma runs of 3+ stacked adjectives/adverbs). The LLM sibling `prose.dead-metaphor` handles the judgment cases (mixed/dead metaphor, novel clichés, purple prose). |
diff --git a/server/lib/editorial/checkInfra.js b/server/lib/editorial/checkInfra.js
index d3e8cb6c3d..7e59ff9355 100644
--- a/server/lib/editorial/checkInfra.js
+++ b/server/lib/editorial/checkInfra.js
@@ -29,3 +29,4 @@ export * from './checkInfra/rosterCast.js';
export * from './checkInfra/sceneAnalysis.js';
export * from './checkInfra/proseDensity.js';
export * from './checkInfra/comic.js';
+export * from './checkInfra/gates.js';
diff --git a/server/lib/editorial/checkInfra/gates.js b/server/lib/editorial/checkInfra/gates.js
new file mode 100644
index 0000000000..ee03122ae9
--- /dev/null
+++ b/server/lib/editorial/checkInfra/gates.js
@@ -0,0 +1,4 @@
+// Shared gate predicates for EDITORIAL_CHECKS entries.
+
+/** True when the context carries drafted (non-whitespace) manuscript prose. */
+export const hasManuscript = (ctx) => (ctx.manuscript || '').trim().length > 0;
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.js
index 168cb83566..522dd95aee 100644
--- a/server/lib/editorial/checkRegistry.js
+++ b/server/lib/editorial/checkRegistry.js
@@ -127,6 +127,7 @@ export {
secondaryCharacterPresenceSummary,
} from './checkInfra.js';
+import { hasManuscript } from './checkInfra/gates.js';
import {
CHECK_FIELD_TYPES,
CHECK_KINDS,
@@ -658,7 +659,7 @@ export function buildCustomCheck(def) {
prompt: instructions,
configSchema: customCheckConfigSchema,
configFields: CUSTOM_CHECK_CONFIG_FIELDS,
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => runManuscriptLlmCheckInline(ctx, { category, instructions }),
};
}
diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.js
index 12895d7dc5..eb2d26adfa 100644
--- a/server/lib/editorial/checkRegistry.test.js
+++ b/server/lib/editorial/checkRegistry.test.js
@@ -1,6 +1,7 @@
import { describe, it, expect, vi } from 'vitest';
import { z } from 'zod';
import { FINDING_CATEGORY_LABELS } from './findingCategories.js';
+import { hasManuscript } from './checkInfra/gates.js';
import {
EDITORIAL_CHECKS,
EDITORIAL_SOURCES,
@@ -121,6 +122,24 @@ describe('editorial check registry — shape invariants', () => {
}
});
+ // The one place the shared 'needs drafted prose' gate (checkInfra/gates.js) is
+ // pinned; also catches a manuscript-consuming check added without any gate.
+ it('every needsManuscript check is gated off without prose, and the shared gate is a strict boolean', () => {
+ for (const check of EDITORIAL_CHECKS.filter((c) => c.needsManuscript)) {
+ expect(typeof check.gate, `${check.id} gate`).toBe('function');
+ for (const manuscript of ['', ' ', undefined]) {
+ expect(check.gate({ manuscript }), `${check.id} blank ${JSON.stringify(manuscript)}`).toBeFalsy();
+ }
+ if (check.gate === hasManuscript) {
+ expect(check.gate({ manuscript: '' })).toBe(false);
+ expect(check.gate({ manuscript: ' ' })).toBe(false);
+ expect(check.gate({})).toBe(false);
+ expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBe(true);
+ }
+ }
+ expect(EDITORIAL_CHECKS.some((c) => c.gate === hasManuscript)).toBe(true);
+ });
+
it('ships both reference checks (one deterministic, one llm)', () => {
const ids = listChecks().map((c) => c.id);
expect(ids).toContain(NAMING);
@@ -596,12 +615,6 @@ describe('pov.head-hopping — LLM check (#1311)', () => {
expect(check.severityDefault).toBe('medium');
});
- it('gates on a non-empty manuscript', () => {
- const check = getCheck(HEAD_HOPPING);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('no-ops (gate false) when the style guide is third-person omniscient', () => {
const check = getCheck(HEAD_HOPPING);
expect(check.gate({ manuscript: '# Issue 1\n\nprose', series: { styleGuide: { povPerson: 'third-omniscient' } } })).toBe(false);
@@ -686,12 +699,6 @@ describe.each([
expect(check.severityDefault).toBe(severityDefault);
});
- it('gates on a non-empty manuscript', () => {
- const check = getCheck(id);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('injects the scene map into the prompt vars and counts it into the chunk overhead', async () => {
let seenVars = null;
let seenOverhead = 0;
@@ -764,12 +771,6 @@ describe('narration.summary-not-scene — summary-vs-scene LLM check (#3591)', (
expect(check.sources).toEqual(expect.arrayContaining(['manuscript', 'reverseOutline']));
});
- it('gates on a non-empty manuscript', () => {
- const check = getCheck(SUMMARY_NOT_SCENE);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: MANUSCRIPT })).toBeTruthy();
- });
-
it('injects the scene map into the prompt vars and stamps findings with the pacing category', async () => {
let seenVars = null;
let seenOverhead = 0;
@@ -860,12 +861,6 @@ describe('dialogue.reported-speech — reported-speech LLM check (#3592)', () =>
expect(check.sources).toEqual(['manuscript']);
});
- it('gates on a non-empty manuscript', () => {
- const check = getCheck(REPORTED_SPEECH);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: MANUSCRIPT })).toBeTruthy();
- });
-
it('budgets the fixed prompt overhead when planning chunks and stamps findings with the dialogue category', async () => {
let seenVars = null;
let seenOverhead = 0;
@@ -948,12 +943,6 @@ describe('interiority.register — interiority-register LLM check (#3593)', () =
expect(check.sources).toEqual(['manuscript']);
});
- it('gates on a non-empty manuscript', () => {
- const check = getCheck(INTERIORITY_REGISTER);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: MANUSCRIPT })).toBeTruthy();
- });
-
it('budgets the fixed prompt overhead when planning chunks and stamps findings with the style category', async () => {
let seenVars = null;
let seenOverhead = 0;
@@ -1031,12 +1020,6 @@ describe('interiority.protagonist — LLM check (#1294)', () => {
expect(check.needsManuscript).toBe(true);
});
- it('only runs when there is drafted prose to scan', () => {
- const check = getCheck(INTERIORITY);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('passes the planned manuscript chunk to the model and forces the character category', async () => {
let seen = null;
const ctx = wholeCtx({
@@ -1093,12 +1076,6 @@ describe('chekhov.setups-payoffs — LLM check (#1299)', () => {
expect(check.needsManuscript).toBe(true);
});
- it('only runs when there is drafted prose to scan', () => {
- const check = getCheck(CHEKHOV);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('passes the manuscript + authored reader-map setups to the model and forces the continuity category', async () => {
let seenVars = null;
const ctx = wholeCtx({
@@ -1271,12 +1248,6 @@ describe('plot.structure-momentum — LLM check (#1310)', () => {
expect(check.needsManuscript).toBe(true);
});
- it('only runs when there is drafted prose to scan', () => {
- const check = getCheck(PLOT_STRUCTURE);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('passes the manuscript, scene map, plotline coverage, and authored setups to the model and forces the plot category', async () => {
let seenVars = null;
const ctx = wholeCtx({
@@ -1390,12 +1361,6 @@ describe('pacing.escalation-curve — LLM check (#1618)', () => {
expect(check.needsManuscript).toBe(true);
});
- it('only runs when there is drafted prose to scan', () => {
- const check = getCheck(PACING_ESCALATION);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('passes the manuscript, scene map, and conflict-marker tally to the model and forces the pacing category', async () => {
let seenVars = null;
const ctx = wholeCtx({
@@ -1561,12 +1526,6 @@ describe('continuity.timeline-contradiction — LLM check (#1581)', () => {
expect(check.needsManuscript).toBe(true);
});
- it('only runs when there is drafted prose to scan', () => {
- const check = getCheck(TIMELINE_CONTRADICTION);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('passes the manuscript, continuity ledger, canon facts, and scene map to the model and forces the continuity category', async () => {
let seenVars = null;
const ctx = wholeCtx({
@@ -1700,12 +1659,6 @@ describe('character.consistency — LLM check (#1582)', () => {
expect(check.needsManuscript).toBe(true);
});
- it('only runs when there is drafted prose to scan', () => {
- const check = getCheck(CHARACTER_CONSISTENCY);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('passes the manuscript, canon traits, and scene map to the model and forces the character category', async () => {
let seenVars = null;
const ctx = wholeCtx({
@@ -1826,12 +1779,6 @@ describe('theme.coherence — LLM check (#1317)', () => {
expect(check.needsManuscript).toBe(true);
});
- it('only runs when there is drafted prose to scan', () => {
- const check = getCheck(THEME_COHERENCE);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('passes the manuscript, declared themes, and scene map to the model and forces the theme category', async () => {
let seenVars = null;
const ctx = wholeCtx({
@@ -1917,12 +1864,6 @@ describe('arc.climax-agency — LLM check (#1583)', () => {
expect(check.needsManuscript).toBe(true);
});
- it('only runs when there is drafted prose to scan', () => {
- const check = getCheck(CLIMAX_AGENCY);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('passes the manuscript, authored payoffs, declared themes, and scene map and forces the arc category', async () => {
let seenVars = null;
const ctx = wholeCtx({
@@ -2006,12 +1947,6 @@ describe('emotion.reaction-proportionality — LLM check (#1584)', () => {
expect(check.needsManuscript).toBe(true);
});
- it('only runs when there is drafted prose to scan', () => {
- const check = getCheck(REACTION_PROPORTIONALITY);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('passes the manuscript + scene map to the model and forces the emotion category', async () => {
let seenVars = null;
const ctx = wholeCtx({
@@ -2154,12 +2089,6 @@ describe('character.secondary-arc — LLM check (#1585)', () => {
expect(check.needsManuscript).toBe(true);
});
- it('only runs when there is drafted prose to scan', () => {
- const check = getCheck(SECONDARY_ARC);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('passes the manuscript, recurring secondary roster, canon names roster, and canon traits and forces the arc category', async () => {
let seenVars = null;
const ctx = wholeCtx({
@@ -2267,12 +2196,6 @@ describe('style.voice-consistency — LLM check (#1586)', () => {
expect(check.needsManuscript).toBe(true);
});
- it('only runs when there is drafted prose to scan', () => {
- const check = getCheck(VOICE_CONSISTENCY);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('feeds the style guide intended voice alongside the manuscript and forces the style category', async () => {
let seenVars = null;
const ctx = wholeCtx({
@@ -2551,12 +2474,6 @@ describe('endings.cliffhanger — LLM check (#1298)', () => {
expect(check.needsManuscript).toBe(true);
});
- it('only runs when there is drafted prose to scan', () => {
- const check = getCheck(ENDINGS_CLIFF);
- expect(check.gate({ manuscript: '' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('passes the manuscript + authored cliffhangers and forces the pacing category', async () => {
let seenVars = null;
const ctx = wholeCtx({
@@ -3460,11 +3377,6 @@ describe('arc.transitions — LLM check (#1293)', () => {
expect(capturedSceneMap).toContain('present: Mara');
});
- it('is gated off when the manuscript is empty', () => {
- expect(getCheck(ARC).gate({ manuscript: ' ' })).toBe(false);
- expect(getCheck(ARC).gate({ manuscript: 'real prose' })).toBe(true);
- });
-
it('degrades gracefully when no authored arcs or outline exist', async () => {
const ctx = baseCtx({
series: {},
@@ -3502,12 +3414,6 @@ describe('arc.regression — LLM check (#1619)', () => {
expect(check.needsManuscript).toBe(true);
});
- it('only runs when there is drafted prose to scan', () => {
- const check = getCheck(REG);
- expect(check.gate({ manuscript: ' ' })).toBe(false);
- expect(check.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
- });
-
it('emits arc-category findings and ships the manuscript + both context blocks', async () => {
const ctx = baseCtx({
callStagedLLM: async (_stage, vars) => {
@@ -3834,10 +3740,6 @@ describe('objects.unmotivated-interaction — LLM check (#1288)', () => {
expect(findings).toHaveLength(4);
expect(findings.every((f) => f.category === 'continuity')).toBe(true);
});
-
- it('gates off when the manuscript is empty', () => {
- expect(getCheck('objects.unmotivated-interaction').gate(baseCtx({ manuscript: ' ' }))).toBe(false);
- });
});
describe('objects.weight-proportionality — LLM check (#1624)', () => {
@@ -3900,10 +3802,6 @@ describe('objects.weight-proportionality — LLM check (#1624)', () => {
expect(findings).toHaveLength(1);
expect(findings[0].issueNumber).toBe(7);
});
-
- it('gates off when the manuscript is empty', () => {
- expect(getCheck('objects.weight-proportionality').gate(baseCtx({ manuscript: ' ' }))).toBe(false);
- });
});
describe('cross-chunk continuity digest (#1383)', () => {
@@ -5037,8 +4935,6 @@ describe('prose.cliches / prose.modifier-stacking / prose.dead-metaphor (#1308)'
expect(c.category).toBe('style');
expect(c.sources).toEqual(['manuscript']);
expect(c.needsManuscript).toBe(true);
- expect(c.gate({ manuscript: '' })).toBe(false);
- expect(c.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
}
});
@@ -5113,8 +5009,6 @@ describe('copy-edit prose-tic bundle (#1306)', () => {
expect(c.category, id).toBe('style');
expect(c.sources, id).toEqual(['manuscript']);
expect(c.needsManuscript, id).toBe(true);
- expect(c.gate({ manuscript: '' }), id).toBe(false);
- expect(c.gate({ manuscript: '# Issue 1\n\nprose' }), id).toBeTruthy();
}
expect(getCheck(TELLING).kind).toBe('llm');
expect(getCheck(TELLING).category).toBe('style');
@@ -5318,8 +5212,6 @@ describe('prose anti-pattern bundle (#1300)', () => {
expect(c.category).toBe(category);
expect(c.sources).toEqual(['manuscript']);
expect(c.needsManuscript).toBe(true);
- expect(c.gate({ manuscript: '' })).toBe(false);
- expect(c.gate({ manuscript: '# Issue 1\n\nprose' })).toBeTruthy();
});
it(`${id} passes the planned chunk to the model and forces its category`, async () => {
diff --git a/server/lib/editorial/checks/cast.js b/server/lib/editorial/checks/cast.js
index 6857a198f2..eff90f7d6f 100644
--- a/server/lib/editorial/checks/cast.js
+++ b/server/lib/editorial/checks/cast.js
@@ -1,5 +1,6 @@
// Editorial checks — cast group. Extracted from checkRegistry.js (#1829).
// Each entry is a declarative check; see ../README.md and ../checkInfra.js.
+import { hasManuscript } from '../checkInfra/gates.js';
import {
UNMODELED_NAMES_STAGE,
attributeDialogueByOwner,
@@ -133,7 +134,7 @@ export const castChecks = [
},
],
// Need both prose to scan AND at least one named canon character to scan for.
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0
+ gate: (ctx) => hasManuscript(ctx)
&& Array.isArray(ctx.canon?.characters)
&& ctx.canon.characters.some((c) => typeof c?.name === 'string' && c.name.trim()),
run: (ctx) => {
@@ -256,7 +257,7 @@ export const castChecks = [
// Needs prose to scan. Unlike roster.economy this does NOT require a populated
// canon — an EMPTY bible is the strongest case (every named proper noun is
// unmodeled), and the prompt's {{^knownCharacters}} branch handles it.
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: async (ctx) => {
// The known-character roster is fixed per-call overhead (re-sent on each
// chunk) — it's the exclusion list the model classifies against. Counted into
diff --git a/server/lib/editorial/checks/characterArc.js b/server/lib/editorial/checks/characterArc.js
index a24a12cba9..4ff0a3ab5b 100644
--- a/server/lib/editorial/checks/characterArc.js
+++ b/server/lib/editorial/checks/characterArc.js
@@ -1,5 +1,6 @@
// Editorial checks — characterArc group. Extracted from checkRegistry.js (#1829).
// Each entry is a declarative check; see ../README.md and ../checkInfra.js.
+import { hasManuscript } from '../checkInfra/gates.js';
import {
ARC_REGRESSION_STAGE,
ARC_TRANSITIONS_STAGE,
@@ -67,7 +68,7 @@ export const characterArcChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// All three blocks are fixed per-call overhead (re-sent on each chunk) and
// pure context: the canon traits give the established temperament/voice/
@@ -155,7 +156,7 @@ export const characterArcChecks = [
help: 'Cap findings so a large cast can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// All three blocks are fixed per-call overhead (re-sent on each chunk) and
// pure context: the secondary-cast roster names which recurring non-POV
@@ -232,7 +233,7 @@ export const characterArcChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// Both blocks are fixed per-call overhead (re-sent on each chunk) and pure
// context: the scene map lets the model attribute transitions to scenes,
@@ -294,7 +295,7 @@ export const characterArcChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// Both blocks are fixed per-call overhead (re-sent on each chunk) and pure
// context: the authored arcs name each character's planned start → end state
@@ -395,7 +396,7 @@ export const characterArcChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// All three blocks are fixed per-call overhead (re-sent on each chunk) and
// pure context: the authored payoffs name what the reader was PROMISED the
@@ -630,7 +631,7 @@ export const characterArcChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
// Per-scene, localized findings (one interiority gap = one scene), so this
// stays a plain per-chunk run with no cross-chunk digest — mirrors
// prose.info-dumping.
diff --git a/server/lib/editorial/checks/continuity.js b/server/lib/editorial/checks/continuity.js
index e7d18ed7c4..76fdcf4fd9 100644
--- a/server/lib/editorial/checks/continuity.js
+++ b/server/lib/editorial/checks/continuity.js
@@ -1,5 +1,6 @@
// Editorial checks — continuity group. Extracted from checkRegistry.js (#1829).
// Each entry is a declarative check; see ../README.md and ../checkInfra.js.
+import { hasManuscript } from '../checkInfra/gates.js';
import {
CHEKHOV_STAGE,
OBJECT_BACKSTORY_STAGE,
@@ -60,7 +61,7 @@ export const continuityChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// All four blocks are fixed per-call overhead (re-sent on each chunk) and
// pure context: the continuity-bible ledger is the authoritative fact set
@@ -236,7 +237,7 @@ export const continuityChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const objects = describeObjectAttachments(ctx);
return runManuscriptLlmCheck(ctx, {
@@ -339,7 +340,7 @@ export const continuityChecks = [
help: 'Cap findings so a large object roster can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// The per-object weight summary (prose significance + every attachment's
// emotion / per-bond significance / origin lineage / role) is fixed per-call
@@ -439,7 +440,7 @@ export const continuityChecks = [
help: 'Flag a payoff this many issues (or more) after its setup as "distant" — the reader may have forgotten the plant. Set to 0 to disable the distant check.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// Authored hooks/payoffs + the foreshadowing ledger (#2172) are fixed
// per-call overhead (re-sent on each chunk). The ledger is folded into the
@@ -521,7 +522,7 @@ export const continuityChecks = [
// Skip the LLM call entirely when the series authored no reveal-gated canon
// (no revealIssue / spoiler on any entry) AND when there's no manuscript to
// scan — there is nothing a premature reveal could be measured against.
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0 && canonHasRevealGated(ctx.canon),
+ gate: (ctx) => hasManuscript(ctx) && canonHasRevealGated(ctx.canon),
run: (ctx) => {
// The reveal-gated canon block is fixed per-call overhead (re-sent on each
// chunk) and pure context: it names each withheld fact, WHEN it's due, the
diff --git a/server/lib/editorial/checks/dialogue.js b/server/lib/editorial/checks/dialogue.js
index 03c851d99b..6926b0826b 100644
--- a/server/lib/editorial/checks/dialogue.js
+++ b/server/lib/editorial/checks/dialogue.js
@@ -1,5 +1,6 @@
// Editorial checks — dialogue group. Extracted from checkRegistry.js (#1829).
// Each entry is a declarative check; see ../README.md and ../checkInfra.js.
+import { hasManuscript } from '../checkInfra/gates.js';
import {
DIALOGUE_PLEASANTRIES_STAGE,
EDITORIAL_PROMPT_OVERHEAD_TOKENS,
@@ -45,7 +46,7 @@ export const dialogueChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
// Localized to scene openings — plain per-chunk run, no digest.
run: (ctx) => runManuscriptLlmCheck(ctx, {
stage: DIALOGUE_PLEASANTRIES_STAGE,
@@ -79,7 +80,7 @@ export const dialogueChecks = [
{ key: 'allowWords', label: 'House-style allowlist', type: 'text', help: 'Speech-tag verbs to leave alone (comma-separated or one per line) — a genre voice may keep some.' },
{ key: 'extraWords', label: 'Extra bookisms to flag', type: 'text', help: 'Series-specific ornate tags to add (comma-separated or one per line).' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const max = cfg.maxFindings ?? 20;
@@ -139,7 +140,7 @@ export const dialogueChecks = [
{ key: 'beatChars', label: 'Action-beat threshold (characters)', type: 'number', min: 0, max: 80, step: 1, help: 'How many non-quoted characters a dialogue paragraph needs to count as carrying a grounding action beat (which re-anchors the speaker).' },
{ key: 'maxFindings', label: 'Max findings per run', type: 'number', min: 1, max: 50, step: 1, help: 'Cap findings so a dialogue-heavy draft can not flood the review.' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const max = cfg.maxFindings ?? 20;
@@ -206,7 +207,7 @@ export const dialogueChecks = [
{ key: 'allowWords', label: 'House-style allowlist', type: 'text', help: 'Tag verbs to leave out of the inventory (comma-separated or one per line).' },
{ key: 'extraWords', label: 'Extra ornate tags to count', type: 'text', help: 'Series-specific ornate tags to include in the inventory (comma-separated or one per line).' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const max = cfg.maxFindings ?? 20;
@@ -269,7 +270,7 @@ export const dialogueChecks = [
configFields: [
{ key: 'maxFindings', label: 'Max findings per run', type: 'number', min: 1, max: 50, step: 1, help: 'Cap findings so a long manuscript can not flood the review.' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
// Localized prose-level findings (one on-the-nose line = one spot), so this
// stays a plain per-chunk run with no cross-chunk digest — mirrors prose.info-dumping.
run: (ctx) => runManuscriptLlmCheck(ctx, {
@@ -303,7 +304,7 @@ export const dialogueChecks = [
configFields: [
{ key: 'maxFindings', label: 'Max findings per run', type: 'number', min: 1, max: 50, step: 1, help: 'Cap findings so a long manuscript can not flood the review.' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
// Localized prose-level findings (one reported beat = one spot), so this stays
// a plain per-chunk run with no cross-chunk digest — mirrors dialogue.on-the-nose.
run: (ctx) => runManuscriptLlmCheck(ctx, {
@@ -333,7 +334,7 @@ export const dialogueChecks = [
configFields: [
{ key: 'maxFindings', label: 'Max findings per run', type: 'number', min: 1, max: 50, step: 1, help: 'Cap findings so a large cast can not flood the review.' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// The authored voice profiles are fixed per-call overhead (re-sent on each
// chunk) and pure context: they let the model reconcile a character's drafted
diff --git a/server/lib/editorial/checks/pov.js b/server/lib/editorial/checks/pov.js
index 1f8c30b60d..c9f7f9d116 100644
--- a/server/lib/editorial/checks/pov.js
+++ b/server/lib/editorial/checks/pov.js
@@ -1,5 +1,6 @@
// Editorial checks — pov group. Extracted from checkRegistry.js (#1829).
// Each entry is a declarative check; see ../README.md and ../checkInfra.js.
+import { hasManuscript } from '../checkInfra/gates.js';
import {
HEAD_HOPPING_STAGE,
POV_PERSON_LABELS,
@@ -335,7 +336,7 @@ export const povChecks = [
// Skip when there's no prose, OR when the style guide declares third-person
// omniscient — an omniscient narrator may freely roam between heads, so
// "head-hopping" is intentional and there's nothing to police (#1311).
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0
+ gate: (ctx) => hasManuscript(ctx)
&& ctx.series?.styleGuide?.povPerson !== 'third-omniscient',
run: (ctx) => {
// The POV-per-scene map is fixed per-call overhead (re-sent on each chunk).
diff --git a/server/lib/editorial/checks/proseStyle.js b/server/lib/editorial/checks/proseStyle.js
index 7e193e903e..65788d0cd7 100644
--- a/server/lib/editorial/checks/proseStyle.js
+++ b/server/lib/editorial/checks/proseStyle.js
@@ -1,5 +1,6 @@
// Editorial checks — proseStyle group. Extracted from checkRegistry.js (#1829).
// Each entry is a declarative check; see ../README.md and ../checkInfra.js.
+import { hasManuscript } from '../checkInfra/gates.js';
import {
ADVERSARIAL_CUTS_STAGE,
CUT_TYPES,
@@ -73,7 +74,7 @@ export const proseStyleChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => runManuscriptLlmCheck(ctx, {
stage: INFO_DUMPING_STAGE,
category: 'exposition',
@@ -150,7 +151,7 @@ export const proseStyleChecks = [
],
// Only run when the style guide sets a target AND there's prose to measure.
gate: (ctx) => Number.isFinite(ctx.series?.styleGuide?.readingLevel)
- && (ctx.manuscript || '').trim().length > 0,
+ && hasManuscript(ctx),
run: (ctx) => {
const target = ctx.series?.styleGuide?.readingLevel;
if (!Number.isFinite(target)) return [];
@@ -245,7 +246,7 @@ export const proseStyleChecks = [
],
// Skip unless there's prose AND the style guide declares at least one
// conformance-relevant field (tense / POV / rating / profanity / audience).
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0
+ gate: (ctx) => hasManuscript(ctx)
&& hasConformanceFields(ctx.series?.styleGuide),
run: (ctx) => {
const expectations = styleGuideExpectations(ctx.series?.styleGuide);
@@ -314,7 +315,7 @@ export const proseStyleChecks = [
help: 'Series-specific stock phrases to add to the seed list (comma-separated or one per line).',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const max = cfg.maxFindings ?? 20;
@@ -387,7 +388,7 @@ export const proseStyleChecks = [
help: 'Cap findings so an adjective-heavy draft can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const minStack = cfg.minStack ?? 3;
@@ -442,7 +443,7 @@ export const proseStyleChecks = [
{ key: 'allowWords', label: 'House-style allowlist', type: 'text', help: 'Filter words to leave alone (comma-separated or one per line).' },
{ key: 'extraWords', label: 'Extra filter words to flag', type: 'text', help: 'Series-specific distancing verbs to add (comma-separated or one per line).' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => runDensityCheck(ctx, {
scan: (text, cfg) => findFilterWords(text, { allowWords: splitPhraseList(cfg.allowWords), extraWords: splitPhraseList(cfg.extraWords) }),
noun: 'filter words',
@@ -477,7 +478,7 @@ export const proseStyleChecks = [
{ key: 'allowWords', label: 'House-style allowlist', type: 'text', help: 'Hedge words to leave alone (comma-separated or one per line).' },
{ key: 'extraWords', label: 'Extra hedge words to flag', type: 'text', help: 'Series-specific hedges/weasel words to add (comma-separated or one per line).' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => runDensityCheck(ctx, {
scan: (text, cfg) => findHedgeWords(text, { allowWords: splitPhraseList(cfg.allowWords), extraWords: splitPhraseList(cfg.extraWords) }),
noun: 'hedge words',
@@ -513,7 +514,7 @@ export const proseStyleChecks = [
{ key: 'allowWords', label: 'House-style allowlist', type: 'text', help: 'Crutch words to leave alone (comma-separated or one per line).' },
{ key: 'extraWords', label: 'Extra crutch words to flag', type: 'text', help: 'Series-specific fillers to add (comma-separated or one per line).' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => runDensityCheck(ctx, {
scan: (text, cfg) => findCrutchWords(text, { includeThat: cfg.includeThat === true, allowWords: splitPhraseList(cfg.allowWords), extraWords: splitPhraseList(cfg.extraWords) }),
noun: 'crutch words',
@@ -547,7 +548,7 @@ export const proseStyleChecks = [
{ key: 'extraWords', label: 'Extra adverbs to flag', type: 'text', help: 'Series-specific adverbs the -ly heuristic misses, e.g. "fast", "well", "hard" (comma-separated or one per line).' },
{ key: 'flagReportingTags', label: 'Also flag reporting tags', type: 'boolean', help: 'By default only emotion-telling dialogue tags ("said angrily") are flagged; reporting tags ("said quietly") are treated as invisible stage directions. Enable to flag every adverb-laden tag.' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const max = cfg.maxFindings ?? 20;
@@ -633,7 +634,7 @@ export const proseStyleChecks = [
{ key: 'allowWords', label: 'House-style allowlist', type: 'text', help: 'Participles to never treat as passive — archaic/adjectival "-ed" forms like "blessed", "beloved" (comma-separated or one per line).' },
{ key: 'extraWords', label: 'Extra participles to flag', type: 'text', help: 'Series-specific irregular participles the heuristic misses, e.g. "begun", "hewn" (comma-separated or one per line).' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// Parse the word lists once (not per section, the way the adverbs check
// hoists its own) — runDensityCheck calls scan() for every section.
@@ -675,7 +676,7 @@ export const proseStyleChecks = [
{ key: 'allowWords', label: 'House-style allowlist', type: 'text', help: 'Gesture verbs to leave alone (comma-separated or one per line).' },
{ key: 'extraWords', label: 'Extra gestures to track', type: 'text', help: 'Series-specific gestures to add (comma-separated or one per line).' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const max = cfg.maxFindings ?? 20;
@@ -754,7 +755,7 @@ export const proseStyleChecks = [
{ key: 'minOpenerRun', label: 'Repeated-opener run to flag', type: 'number', min: 2, max: 8, step: 1, help: 'How many sentences in a row starting with the same word trips the repeated-opener flag.' },
{ key: 'maxFindings', label: 'Max findings per run', type: 'number', min: 1, max: 50, step: 1, help: 'Cap findings so a heavy draft can not flood the review.' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const max = cfg.maxFindings ?? 20;
@@ -819,7 +820,7 @@ export const proseStyleChecks = [
{ key: 'minSentences', label: 'Minimum sentences to judge', type: 'number', min: 3, max: 50, step: 1, help: 'Skip passages shorter than this many sentences (too few to judge rhythm).' },
{ key: 'maxFindings', label: 'Max findings per run', type: 'number', min: 1, max: 50, step: 1, help: 'Cap findings so a heavy draft can not flood the review.' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const max = cfg.maxFindings ?? 20;
@@ -864,7 +865,7 @@ export const proseStyleChecks = [
configFields: [
{ key: 'maxFindings', label: 'Max findings per run', type: 'number', min: 1, max: 50, step: 1, help: 'Cap findings so a long manuscript can not flood the review.' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
// Localized prose-level findings (one told emotion = one spot), so this stays
// a plain per-chunk run with no cross-chunk digest — mirrors prose.dead-metaphor.
run: (ctx) => runManuscriptLlmCheck(ctx, {
@@ -893,7 +894,7 @@ export const proseStyleChecks = [
configFields: [
{ key: 'maxFindings', label: 'Max findings per run', type: 'number', min: 1, max: 50, step: 1, help: 'Cap findings so a long manuscript can not flood the review.' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
// Localized prose-level findings (one essayistic thought = one spot), so this
// stays a plain per-chunk run with no cross-chunk digest — mirrors
// prose.telling-emotion. The prompt reconciles a character's thought against
@@ -932,7 +933,7 @@ export const proseStyleChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
// Localized prose-level findings (one tired phrase = one spot), so this stays
// a plain per-chunk run with no cross-chunk digest — mirrors prose.info-dumping.
run: (ctx) => runManuscriptLlmCheck(ctx, {
@@ -969,7 +970,7 @@ export const proseStyleChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
// Each mirror moment is a localized spot — plain per-chunk run, no digest.
run: (ctx) => runManuscriptLlmCheck(ctx, {
stage: MIRROR_DESCRIPTION_STAGE,
@@ -1010,7 +1011,7 @@ export const proseStyleChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// The intended-voice block is fixed per-call overhead (re-sent on each chunk)
// and pure context: it lets the model measure each issue's narration against
@@ -1124,7 +1125,7 @@ export const proseStyleChecks = [
help: 'What each issue is measured against: "drafted" (the mean of the drafted issues — the default), "exemplars" (the style guide\'s voice-exemplar profile, so drift is judged against the voice you CHOSE, not the average of what got drafted), or "blended" (the midpoint). Exemplars/blended fall back to drafted when the style guide has too little exemplar prose.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const wells = parseVoiceWells(cfg.vocabularyWells || '');
@@ -1203,7 +1204,7 @@ export const proseStyleChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
// Localized prose-level findings (one precious passage = one spot) — plain
// per-chunk run, no cross-chunk digest.
run: (ctx) => runManuscriptLlmCheck(ctx, {
@@ -1273,7 +1274,7 @@ export const proseStyleChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: async (ctx) => {
const cfg = ctx.config || {};
const cutTargetPercent = cfg.cutTargetPercent ?? 10;
@@ -1384,7 +1385,7 @@ export const proseStyleChecks = [
help: 'Cap findings so a thought-italics-heavy draft can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const minWords = cfg.minWords ?? 4;
diff --git a/server/lib/editorial/checks/research.js b/server/lib/editorial/checks/research.js
index e5a41b3217..8c6cfffe17 100644
--- a/server/lib/editorial/checks/research.js
+++ b/server/lib/editorial/checks/research.js
@@ -1,5 +1,6 @@
// Editorial checks — research group. Extracted from checkRegistry.js (#1829).
// Each entry is a declarative check; see ../README.md and ../checkInfra.js.
+import { hasManuscript } from '../checkInfra/gates.js';
import {
FACT_ACCURACY_STAGE,
THEME_COHERENCE_STAGE,
@@ -57,7 +58,7 @@ export const researchChecks = [
gate: (ctx) =>
ctx.series?.factCritical === true
&& (ctx.series?.factReference || '').trim().length > 0
- && (ctx.manuscript || '').trim().length > 0,
+ && hasManuscript(ctx),
run: (ctx) => {
// The author's documented real-world facts are the authoritative reference
// the prose is judged against — fixed per-call overhead re-sent on each
@@ -103,7 +104,7 @@ export const researchChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// Both blocks are fixed per-call overhead (re-sent on each chunk) and pure
// context: the declared themes let the model build a per-theme setup/
diff --git a/server/lib/editorial/checks/scene.js b/server/lib/editorial/checks/scene.js
index be9515a0d6..1bc8ca8f35 100644
--- a/server/lib/editorial/checks/scene.js
+++ b/server/lib/editorial/checks/scene.js
@@ -1,5 +1,6 @@
// Editorial checks — scene group. Extracted from checkRegistry.js (#1829).
// Each entry is a declarative check; see ../README.md and ../checkInfra.js.
+import { hasManuscript } from '../checkInfra/gates.js';
import {
EDITORIAL_PROMPT_OVERHEAD_TOKENS,
ENDINGS_CLIFFHANGER_STAGE,
@@ -121,7 +122,7 @@ export const sceneChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// The scene map is fixed per-call overhead (re-sent on each chunk). It's
// context only — the check degrades gracefully to a whole-issue scan when
@@ -164,7 +165,7 @@ export const sceneChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// The scene map is fixed per-call overhead (re-sent on each chunk). Each
// scene's recorded `setting` is a strong white-room signal (blank ⇒ likely
@@ -207,7 +208,7 @@ export const sceneChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// The scene map is fixed per-call overhead (re-sent on each chunk). Here it
// separates legitimate BETWEEN-scene compression from a dramatizable beat
@@ -251,7 +252,7 @@ export const sceneChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// The scene map is fixed per-call overhead (re-sent on each chunk). It's
// context only — the check degrades gracefully to a whole-issue scan when
@@ -294,7 +295,7 @@ export const sceneChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// All three blocks are fixed per-call overhead (re-sent on each chunk) and
// pure context: the scene map lets the model attribute pacing/stakes findings
@@ -367,7 +368,7 @@ export const sceneChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// Both blocks are fixed per-call overhead (re-sent on each chunk) and pure
// context: the scene map lets the model attribute escalation findings to a
@@ -448,7 +449,7 @@ export const sceneChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// The scene map is fixed per-call overhead (re-sent on each chunk) and pure
// context: it records each scene's events so the model can weigh an event's
@@ -527,7 +528,7 @@ export const sceneChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
// Localized to chapter/scene openings (one finding per opener), so this stays
// a plain per-chunk run with no cross-chunk digest — mirrors prose.info-dumping.
run: (ctx) => runManuscriptLlmCheck(ctx, {
@@ -568,7 +569,7 @@ export const sceneChecks = [
help: 'Cap findings so a long manuscript can not flood the review.',
},
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// Authored cliffhangers are fixed per-call overhead (re-sent on each chunk).
const authoredCliffhangers = authoredCliffhangerSummary(ctx.series?.arc?.readerMap);
diff --git a/server/lib/editorial/checks/slop.js b/server/lib/editorial/checks/slop.js
index f53d29cc76..0a2a89ebfd 100644
--- a/server/lib/editorial/checks/slop.js
+++ b/server/lib/editorial/checks/slop.js
@@ -3,6 +3,7 @@
// The pure detectors these checks call live in ../slopScore.js — see that
// module's doc comment for how it EXTENDS (rather than duplicates) the
// existing proseTics.js / cliches.js / repetition.js anti-slop primitives.
+import { hasManuscript } from '../checkInfra/gates.js';
import {
MIN_DENSITY_OCCURRENCES,
countSectionBreaks,
@@ -66,7 +67,7 @@ export const slopChecks = [
{ key: 'allowWords', label: 'House-style allowlist', type: 'text', help: 'Words to leave alone (comma-separated or one per line) — applies to both tiers.' },
{ key: 'extraWords', label: 'Extra banned words to flag', type: 'text', help: 'Series-specific words to add to the seed lists (comma-separated or one per line) — applies to both tiers.' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const max = cfg.maxFindings ?? 20;
@@ -141,7 +142,7 @@ export const slopChecks = [
{ key: 'maxFindings', label: 'Max findings per run', type: 'number', min: 1, max: 50, step: 1, help: 'Cap findings so a slop-heavy draft can not flood the review.' },
{ key: 'allowPatterns', label: 'Muted AI-tell patterns', type: 'text', help: 'Pattern ids to leave alone (comma-separated or one per line): sense-of, couldnt-help-but, eyes-widened, breath-didnt-know, wave-of-emotion, heart-pounded-chest, physical-named-emotion.' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const max = cfg.maxFindings ?? 20;
@@ -194,7 +195,7 @@ export const slopChecks = [
{ key: 'triadicMinRun', label: 'Short sentences in a row to flag', type: 'number', min: 3, max: 8, step: 1, help: 'How many consecutive short sentences trip the "Fast. Precise. Deadly." flag.' },
{ key: 'negativeAssertionDensityPer1000', label: '"Did not" rate to flag (per 1000 words)', type: 'number', min: 0, max: 50, step: 1, help: 'Flag a section whose "did not [verb]" / "didn\'t [verb]" frequency per 1000 words is at or above this.' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const max = cfg.maxFindings ?? 20;
@@ -251,7 +252,7 @@ export const slopChecks = [
{ key: 'paragraphUniformityMinRun', label: 'Uniform paragraphs in a row to flag', type: 'number', min: 3, max: 10, step: 1, help: 'How many consecutive similar-length paragraphs trip the mechanical-cadence flag.' },
{ key: 'sectionBreakThresholdPer1000', label: 'Scene-break rate to flag (per 1000 words)', type: 'number', min: 0, max: 50, step: 1, help: 'Flag a section whose scene/section-break marker frequency per 1000 words is at or above this — over-fragmented pacing.' },
],
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
const cfg = ctx.config || {};
const max = cfg.maxFindings ?? 20;
diff --git a/server/lib/editorial/checks/world.js b/server/lib/editorial/checks/world.js
index 288af82a07..45acb51d6a 100644
--- a/server/lib/editorial/checks/world.js
+++ b/server/lib/editorial/checks/world.js
@@ -2,6 +2,7 @@
// review-side companion to the Sanderson's-Laws doctrine injected into the
// universe-expansion generation prompt. Each entry is a declarative check; see
// ../README.md and ../checkInfra.js.
+import { hasManuscript } from '../checkInfra/gates.js';
import {
WORLD_COST_FREE_POWER_STAGE,
WORLD_UNFORESHADOWED_SOLUTION_STAGE,
@@ -55,7 +56,7 @@ export const worldChecks = [
needsManuscript: true,
configSchema: maxFindingsSchema,
configFields: maxFindingsFields,
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// Both blocks are fixed per-call overhead (re-sent on each chunk) and pure
// context: the world canon names the artifacts/powers/places a solution may
@@ -114,7 +115,7 @@ export const worldChecks = [
needsManuscript: true,
configSchema: maxFindingsSchema,
configFields: maxFindingsFields,
- gate: (ctx) => (ctx.manuscript || '').trim().length > 0,
+ gate: hasManuscript,
run: (ctx) => {
// Both blocks are fixed per-call overhead (re-sent on each chunk) and pure
// context: the world canon + continuity world-rule facts state the costs and
diff --git a/server/lib/editorial/checks/world.test.js b/server/lib/editorial/checks/world.test.js
index 3baf3b3cba..041a2b373b 100644
--- a/server/lib/editorial/checks/world.test.js
+++ b/server/lib/editorial/checks/world.test.js
@@ -34,13 +34,6 @@ describe('worldbuilding-doctrine checks — registration (#2175)', () => {
expect(all.has('world.unforeshadowed-solution')).toBe(true);
expect(all.has('world.cost-free-power')).toBe(true);
});
-
- it('both checks gate off when the manuscript is empty', () => {
- for (const check of worldChecks) {
- expect(check.gate({ manuscript: '' }), check.id).toBe(false);
- expect(check.gate({ manuscript: 'He drew the blade.' }), check.id).toBe(true);
- }
- });
});
describe('canonWorldSummary (#2175)', () => {