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([issue-1284]): /simplify pass — dedup enabled-check filter, gate manuscript I/O

[._.]/ Adam Eivy4a5f9107150f
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.js
index 23339d5fa7..bb6f61c9f4 100644
--- a/server/lib/editorial/checkRegistry.js
+++ b/server/lib/editorial/checkRegistry.js
@@ -49,7 +49,8 @@ function nameSimilaritySignals(a, b) {
const signals = [];
if (la[0] === lb[0]) signals.push('same first letter');
if (la.length === lb.length) signals.push('same length');
- if (vowelSkeleton(a) && vowelSkeleton(a) === vowelSkeleton(b)) signals.push('same vowel pattern');
+ const vsa = vowelSkeleton(a);
+ if (vsa && vsa === vowelSkeleton(b)) signals.push('same vowel pattern');
if (la.length >= 3 && lb.length >= 3 && la.slice(0, 3) === lb.slice(0, 3)) signals.push('same opening');
if (la.endsWith(lb.slice(-2)) && la.slice(-2) === lb.slice(-2)) signals.push('same ending');
return signals;
@@ -109,6 +110,9 @@ export const EDITORIAL_CHECKS = [
category: 'exposition',
severityDefault: 'medium',
defaultEnabled: true,
+ // Reads the stitched manuscript corpus — so the runner only pays the
+ // section-collection I/O when a manuscript-consuming check is enabled.
+ needsManuscript: true,
configSchema: z.object({
// Cap findings per run so a long manuscript can't flood the review.
maxFindings: z.number().int().min(1).max(50).default(12),
@@ -182,16 +186,16 @@ export const listChecks = () => EDITORIAL_CHECKS.slice();
// Validate (and default-fill) a persisted per-check config blob through the
// check's Zod schema. Falls back to the schema's defaults when the stored blob
-// is absent or invalid, so a hand-edited settings.json can't make a check throw.
+// is absent or invalid, so a hand-edited settings.json can't make a check throw
+// (re-parsing `{}` materializes the schema defaults).
export function resolveCheckConfig(check, storedConfig) {
- const parsed = check.configSchema.safeParse(storedConfig || {});
- if (parsed.success) return parsed.data;
- // Re-parse an empty object to materialize the schema defaults.
- const defaults = check.configSchema.safeParse({});
- return defaults.success ? defaults.data : {};
+ const parsed = check.configSchema.safeParse(storedConfig ?? {});
+ return parsed.success ? parsed.data : (check.configSchema.safeParse({}).data ?? {});
}
-const readChecksSlice = (settings) => {
+// Read the persisted per-check map from settings, tolerant of a hand-edited /
+// older-peer file. Exported so the route reads the slice through the same guard.
+export const readChecksSlice = (settings) => {
const slice = settings?.pipelineEditorialChecks?.checks;
return slice && typeof slice === 'object' && !Array.isArray(slice) ? slice : {};
};
@@ -223,15 +227,23 @@ export function resolveCheckState(settings) {
});
}
+/**
+ * The resolved-state rows for the checks that should run: enabled, narrowed to
+ * `subsetIds` when provided. Shared by `getEnabledChecks` (execution) and the
+ * runner's dry-run plan (preview), so the enable/subset filter lives once.
+ */
+export function getEnabledCheckRows(settings, subsetIds = null) {
+ const subset = Array.isArray(subsetIds) && subsetIds.length ? new Set(subsetIds) : null;
+ return resolveCheckState(settings).filter((row) => row.enabled && (!subset || subset.has(row.id)));
+}
+
/**
* The checks that should actually run for a given settings + optional subset.
* Returns `{ check, config }` pairs (the live registry entry + its resolved
* config) for every enabled check, narrowed to `subsetIds` when provided.
*/
export function getEnabledChecks(settings, subsetIds = null) {
- const subset = Array.isArray(subsetIds) && subsetIds.length ? new Set(subsetIds) : null;
- return resolveCheckState(settings)
- .filter((row) => row.enabled && (!subset || subset.has(row.id)))
+ return getEnabledCheckRows(settings, subsetIds)
.map((row) => ({ check: getCheck(row.id), config: row.config }))
.filter((x) => x.check);
}
diff --git a/server/routes/pipeline/editorial.js b/server/routes/pipeline/editorial.js
index 00eab03842..6920fb4372 100644
--- a/server/routes/pipeline/editorial.js
+++ b/server/routes/pipeline/editorial.js
@@ -7,7 +7,7 @@ import { Router } from 'express';
import { z } from 'zod';
import { asyncHandler, ServerError } from '../../lib/errorHandler.js';
import { validateRequest, editorialCheckConfigSchema, editorialChecksRunSchema } from '../../lib/validation.js';
-import { getCheck, resolveCheckState } from '../../lib/editorial/index.js';
+import { getCheck, resolveCheckState, readChecksSlice } from '../../lib/editorial/index.js';
import * as seriesSvc from '../../services/pipeline/series.js';
import * as issuesSvc from '../../services/pipeline/issues.js';
import * as editorialAnalysis from '../../services/pipeline/editorialAnalysis.js';
@@ -100,7 +100,7 @@ router.patch('/editorial/checks/:id', asyncHandler(async (req, res) => {
const updated = await updateSettingsWith((current) => {
const slice = current.pipelineEditorialChecks && typeof current.pipelineEditorialChecks === 'object'
? current.pipelineEditorialChecks : {};
- const checks = slice.checks && typeof slice.checks === 'object' ? slice.checks : {};
+ const checks = readChecksSlice(current);
const prev = checks[check.id] && typeof checks[check.id] === 'object' ? checks[check.id] : {};
const nextEntry = { ...prev };
if (body.enabled !== undefined) nextEntry.enabled = body.enabled;
diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.js
index 8f8611a5a8..e59a290277 100644
--- a/server/services/pipeline/editorial/checkRunner.js
+++ b/server/services/pipeline/editorial/checkRunner.js
@@ -18,7 +18,7 @@
import { randomUUID } from 'crypto';
import { broadcastSse, attachSseClient, SSE_CLEANUP_DELAY_MS } from '../../../lib/sseUtils.js';
import { runStagedLLM } from '../../../lib/stageRunner.js';
-import { getEnabledChecks, resolveCheckState } from '../../../lib/editorial/index.js';
+import { getEnabledChecks, getEnabledCheckRows } from '../../../lib/editorial/index.js';
import { getSettings } from '../../settings.js';
import { getSeries } from '../series.js';
import { listIssues } from '../issues.js';
@@ -49,10 +49,13 @@ export async function runEditorialChecks(seriesId, options = {}) {
return { runId, findings: [], perCheck: [], canceled: false };
}
- // Build the shared context once — every check reads from this.
+ // Build the shared context once — every check reads from this. Only pay the
+ // manuscript section-collection I/O when an enabled check actually consumes
+ // the stitched corpus (deterministic checks like naming use only the canon).
const series = await getSeries(seriesId);
+ const needsManuscript = enabled.some(({ check }) => check.needsManuscript);
const [sections, canon, issues] = await Promise.all([
- collectManuscriptSections(seriesId),
+ needsManuscript ? collectManuscriptSections(seriesId) : Promise.resolve([]),
getSeriesCanon(series),
listIssues({ seriesId }).catch(() => []),
]);
@@ -118,9 +121,7 @@ export async function runEditorialChecks(seriesId, options = {}) {
*/
export async function buildEditorialCheckPlan(seriesId, { checkIds = null, settings } = {}) {
const resolved = settings || await getSettings();
- const subset = Array.isArray(checkIds) && checkIds.length ? new Set(checkIds) : null;
- const checks = resolveCheckState(resolved)
- .filter((row) => row.enabled && (!subset || subset.has(row.id)))
+ const checks = getEnabledCheckRows(resolved, checkIds)
.map((row) => ({ id: row.id, label: row.label, kind: row.kind, scope: row.scope }));
return { seriesId, checks, enabledCount: checks.length };
}
diff --git a/server/services/pipeline/editorial/checkRunner.test.js b/server/services/pipeline/editorial/checkRunner.test.js
index 98226f4c11..73b01c7720 100644
--- a/server/services/pipeline/editorial/checkRunner.test.js
+++ b/server/services/pipeline/editorial/checkRunner.test.js
@@ -45,11 +45,13 @@ vi.mock('../manuscriptReview.js', () => ({ seedReviewFromFindings: (...a) => see
const { runEditorialChecks, buildEditorialCheckPlan } = await import('./checkRunner.js');
const { runStagedLLM } = await import('../../../lib/stageRunner.js');
+const { collectManuscriptSections } = await import('../arcPlanner.js');
beforeEach(() => {
seedStore.length = 0;
seedReviewFromFindings.mockClear();
runStagedLLM.mockClear();
+ collectManuscriptSections.mockClear();
});
describe('runEditorialChecks', () => {
@@ -88,6 +90,15 @@ describe('runEditorialChecks', () => {
expect(result.findings.every((f) => f.checkId === 'naming.dissimilar-names')).toBe(true);
});
+ it('skips manuscript collection when no enabled check needs it', async () => {
+ // Only the deterministic naming check (no needsManuscript) → no section I/O.
+ await runEditorialChecks('s1', { checkIds: ['naming.dissimilar-names'] });
+ expect(collectManuscriptSections).not.toHaveBeenCalled();
+ // The info-dump check (needsManuscript) does trigger the collection.
+ await runEditorialChecks('s1', { checkIds: ['prose.info-dumping'] });
+ expect(collectManuscriptSections).toHaveBeenCalled();
+ });
+
it('skips disabled checks', async () => {
const settings = { pipelineEditorialChecks: { checks: { 'prose.info-dumping': { enabled: false } } } };
const result = await runEditorialChecks('s1', { settings });