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
feat([issue-1628]): support dual-scope editorial checks (scope as array)
[._.]/ Adam Eivy8422f3977328
diff --git a/client/src/lib/editorialChecks.js b/client/src/lib/editorialChecks.jsindex 66addcb53a..def80e5367 100644--- a/client/src/lib/editorialChecks.js+++ b/client/src/lib/editorialChecks.js@@ -62,13 +62,20 @@ export const SEVERITY_BADGE_CLASSES = Object.freeze({* Group catalog rows into ordered scope sections for the catalog view.* Returns `[{ scope, label, checks }]` in CHECK_SCOPE_ORDER, with any unknown* scope appended after the known ones (alphabetical). Empty scopes are omitted.+ * A dual-scope check (#1628, `scopes: ['series','issue']`) appears once under+ * EACH of its declared scopes; older rows carrying only a string `scope` fall+ * back to that single scope.*/export function groupChecksByScope(checks = []) {const byScope = new Map();for (const check of checks) {- const scope = check?.scope || 'other';- if (!byScope.has(scope)) byScope.set(scope, []);- byScope.get(scope).push(check);+ const scopes = Array.isArray(check?.scopes) && check.scopes.length+ ? check.scopes+ : [check?.scope || 'other'];+ for (const scope of scopes) {+ if (!byScope.has(scope)) byScope.set(scope, []);+ byScope.get(scope).push(check);+ }}const known = CHECK_SCOPE_ORDER.filter((s) => byScope.has(s));const unknown = [...byScope.keys()].filter((s) => !CHECK_SCOPE_ORDER.includes(s)).sort();diff --git a/client/src/lib/editorialChecks.test.js b/client/src/lib/editorialChecks.test.jsindex 701dea8e6a..647f252950 100644--- a/client/src/lib/editorialChecks.test.js+++ b/client/src/lib/editorialChecks.test.js@@ -32,6 +32,20 @@ describe('groupChecksByScope', () => {expect(groupChecksByScope([{ id: 'x', scope: 'noun' }]).map((g) => g.scope)).toEqual(['noun']);expect(groupChecksByScope()).toEqual([]);});++ it('fans a dual-scope check into each of its scopes (#1628)', () => {+ const dual = { id: 'r.reciprocity', label: 'Reciprocity', scopes: ['series', 'issue'], kind: 'llm' };+ const groups = groupChecksByScope([dual]);+ expect(groups.map((g) => g.scope)).toEqual(['issue', 'series']);+ // The same check appears under BOTH sections.+ expect(groups.find((g) => g.scope === 'issue').checks).toContain(dual);+ expect(groups.find((g) => g.scope === 'series').checks).toContain(dual);+ });++ it('falls back to the string scope when no scopes array is present (#1628)', () => {+ // Older API rows / peers carry only a string `scope`.+ expect(groupChecksByScope([{ id: 'x', scope: 'issue' }]).map((g) => g.scope)).toEqual(['issue']);+ });});describe('groupFindingsByCheck', () => {diff --git a/server/lib/editorial/README.md b/server/lib/editorial/README.mdindex c6c213ecef..1351465b3e 100644--- a/server/lib/editorial/README.md+++ b/server/lib/editorial/README.md@@ -8,6 +8,15 @@ optional gate, and a `run(ctx)` that returns findings shaped for the existingthe enabled checks, and seeds findings lives at`server/services/pipeline/editorial/checkRunner.js`.+`scope` is a `series | issue | scene | noun` granularity. A check meaningful at+more than one granularity may declare an **array** — `scope: ['series', 'issue']`+(#1628) — instead of being split into two near-duplicate checks; the string form+keeps working. `normalizeCheckScopes` / `primaryCheckScope` (in `checkRegistry.js`)+normalize either form, the load-time guard validates every member, and+`resolveCheckState` exposes both a single primary `scope` (for single-value+consumers) and the full `scopes` array (the catalog and dry-run plan fan a+dual-scope check across each of its declared scopes).+This directory is **pure** (no side-effecting imports — only `zod` and the pure`estimateTokens` budgeter). LLM-kind checks get their model caller through`ctx.callStagedLLM` (or `ctx.callInlineLLM` for user-defined checks), and adiff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.jsindex 84c95b7abf..04bdf0d7f4 100644--- a/server/lib/editorial/checkRegistry.js+++ b/server/lib/editorial/checkRegistry.js@@ -58,6 +58,26 @@ import {import { findAxisReversals, findShotTypeMonotony, summarizeStoryboardShots } from './shotContinuity.js';export const CHECK_SCOPES = Object.freeze(['series', 'issue', 'scene', 'noun']);++// A check's `scope` may be a single scope string OR an array of scopes (#1628).+// A dual-scope check is one rule meaningful at more than one granularity — e.g.+// `relationships.reciprocity` reasons series-wide but could also flag a newly+// added relationship per issue — declared `scope: ['series', 'issue']` instead of+// being split into two near-duplicate checks. These helpers normalize either form+// so every consumer (the load-time guard, the catalog grouping, the dry-run plan)+// fans a check across exactly its declared scopes.+//+// `normalizeCheckScopes` returns the declared scopes deduped and in canonical+// CHECK_SCOPES order; an unknown/empty input returns []. `primaryCheckScope`+// returns the first declared scope (canonical order) for the consumers that still+// bucket/sort by a single value — for a single-scope check it is just that scope.+export function normalizeCheckScopes(scope) {+ const raw = Array.isArray(scope) ? scope : (scope == null ? [] : [scope]);+ return CHECK_SCOPES.filter((s) => raw.includes(s));+}++export const primaryCheckScope = (scope) => normalizeCheckScopes(scope)[0] || null;+export const CHECK_KINDS = Object.freeze(['deterministic', 'llm']);export const CHECK_SEVERITIES = Object.freeze(['high', 'medium', 'low']);const SEVERITIES = CHECK_SEVERITIES;@@ -6246,8 +6266,16 @@ export function assertValidChecks(checks) {if (!check.id || !check.label || !check.scope || !check.kind || !check.category) {throw new Error(`checkRegistry: malformed entry ${JSON.stringify(check)}`);}- if (!CHECK_SCOPES.includes(check.scope)) {- throw new Error(`checkRegistry: invalid scope "${check.scope}" for ${check.id} (must be one of ${CHECK_SCOPES.join(', ')})`);+ // `scope` may be a single scope string OR a non-empty array of scopes (#1628).+ // Validate the RAW form strictly (every member known, array non-empty, no+ // duplicates) rather than leaning on normalizeCheckScopes's silent drop, so a+ // typo'd or empty scope fails boot instead of quietly losing a granularity.+ const rawScopes = Array.isArray(check.scope) ? check.scope : [check.scope];+ if (rawScopes.length === 0 || rawScopes.some((s) => !CHECK_SCOPES.includes(s))) {+ throw new Error(`checkRegistry: invalid scope ${JSON.stringify(check.scope)} for ${check.id} (must be one of ${CHECK_SCOPES.join(', ')}, or a non-empty array of them)`);+ }+ if (new Set(rawScopes).size !== rawScopes.length) {+ throw new Error(`checkRegistry: ${check.id} has duplicate scopes in ${JSON.stringify(check.scope)}`);}if (!CHECK_KINDS.includes(check.kind)) {throw new Error(`checkRegistry: invalid kind "${check.kind}" for ${check.id} (must be one of ${CHECK_KINDS.join(', ')})`);@@ -6357,7 +6385,7 @@ export const resolveCheckSeverity = (check, row) =>/*** Merge the static registry with persisted per-check state from settings.* Returns one row per registered check:- * { id, label, description, scope, kind, category, severityDefault,+ * { id, label, description, scope, scopes, kind, category, severityDefault,* severity, enabled, config, configFields }* `enabled` falls back to the check's `defaultEnabled`; `config` is validated* through the check's schema (with defaults); `severity` is the EFFECTIVE level@@ -6377,7 +6405,12 @@ export function resolveCheckState(settings) {id: check.id,label: check.label,description: check.description,- scope: check.scope,+ // `scope` is the PRIMARY scope (a string) so every single-value consumer+ // keeps working unchanged; `scopes` (#1628) is the full declared set the+ // catalog/plan fan a dual-scope check across. For a single-scope check the+ // two agree (`scope === scopes[0]`).+ scope: primaryCheckScope(check.scope),+ scopes: normalizeCheckScopes(check.scope),kind: check.kind,category: check.category,// `severityDefault` is the registry baseline (what the override resets to);diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.jsindex 51a0836aa5..1bf3105c19 100644--- a/server/lib/editorial/checkRegistry.test.js+++ b/server/lib/editorial/checkRegistry.test.js@@ -5,6 +5,8 @@ import {EDITORIAL_SOURCES,CHECK_SCOPES,CHECK_KINDS,+ normalizeCheckScopes,+ primaryCheckScope,getCheck,listChecks,assertValidChecks,@@ -156,6 +158,22 @@ describe('editorial check registry — fail-fast guards', () => {expect(() => assertValidChecks([{ ...valid, scope: 'galaxy' }])).toThrow(/invalid scope/);});+ it('accepts an array scope of valid members (#1628)', () => {+ expect(() => assertValidChecks([{ ...valid, scope: ['series', 'issue'] }])).not.toThrow();+ });++ it('throws on an empty array scope (#1628)', () => {+ expect(() => assertValidChecks([{ ...valid, scope: [] }])).toThrow(/invalid scope/);+ });++ it('throws when an array scope has an unknown member (#1628)', () => {+ expect(() => assertValidChecks([{ ...valid, scope: ['series', 'galaxy'] }])).toThrow(/invalid scope/);+ });++ it('throws on duplicate scopes in an array (#1628)', () => {+ expect(() => assertValidChecks([{ ...valid, scope: ['series', 'series'] }])).toThrow(/duplicate scopes/);+ });+it('throws on an invalid kind', () => {expect(() => assertValidChecks([{ ...valid, kind: 'magic' }])).toThrow(/invalid kind/);});@@ -205,6 +223,38 @@ describe('editorial check registry — fail-fast guards', () => {});});+describe('editorial check registry — scope normalization (#1628)', () => {+ it('normalizeCheckScopes wraps a string in a single-element array', () => {+ expect(normalizeCheckScopes('series')).toEqual(['series']);+ });++ it('normalizeCheckScopes returns array scopes in canonical CHECK_SCOPES order', () => {+ // Declared issue-before-series, but canonical order is series→issue.+ expect(normalizeCheckScopes(['issue', 'series'])).toEqual(['series', 'issue']);+ });++ it('normalizeCheckScopes drops unknown members and empty/absent input returns []', () => {+ expect(normalizeCheckScopes(['series', 'galaxy'])).toEqual(['series']);+ expect(normalizeCheckScopes('galaxy')).toEqual([]);+ expect(normalizeCheckScopes([])).toEqual([]);+ expect(normalizeCheckScopes(null)).toEqual([]);+ expect(normalizeCheckScopes(undefined)).toEqual([]);+ });++ it('primaryCheckScope returns the first canonical scope (or null)', () => {+ expect(primaryCheckScope('issue')).toBe('issue');+ expect(primaryCheckScope(['issue', 'series'])).toBe('series');+ expect(primaryCheckScope([])).toBe(null);+ expect(primaryCheckScope('galaxy')).toBe(null);+ });++ it('every built-in check normalizes to a non-empty scope set', () => {+ for (const check of EDITORIAL_CHECKS) {+ expect(normalizeCheckScopes(check.scope).length).toBeGreaterThan(0);+ }+ });+});+describe('editorial check registry — config + state resolution', () => {it('resolveCheckConfig fills schema defaults', () => {const cfg = resolveCheckConfig(getCheck(NAMING), undefined);@@ -227,6 +277,17 @@ describe('editorial check registry — config + state resolution', () => {expect(rows.find((r) => r.id === INFODUMP).enabled).toBe(true);});+ it('resolveCheckState exposes a primary scope string + a scopes array (#1628)', () => {+ const rows = resolveCheckState({});+ for (const row of rows) {+ expect(typeof row.scope).toBe('string');+ expect(Array.isArray(row.scopes)).toBe(true);+ expect(row.scopes.length).toBeGreaterThan(0);+ // The primary scope is the first entry of the normalized set.+ expect(row.scope).toBe(row.scopes[0]);+ }+ });+it('resolveCheckState surfaces each check\'s serializable configFields', () => {const rows = resolveCheckState({});const naming = rows.find((r) => r.id === NAMING);diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.jsindex a8af2abbc5..8476f78305 100644--- a/server/services/pipeline/editorial/checkRunner.js+++ b/server/services/pipeline/editorial/checkRunner.js@@ -828,7 +828,9 @@ export async function previewCustomCheck(seriesId, def, { providerOverride, modeexport async function buildEditorialCheckPlan(seriesId, { checkIds = null, settings } = {}) {const resolved = settings || await getSettings();const checks = getEnabledCheckRows(resolved, checkIds)- .map((row) => ({ id: row.id, label: row.label, kind: row.kind, scope: row.scope }));+ // `scope` is the primary scope; `scopes` carries the full declared set so a+ // dual-scope check (#1628) previews under each of its granularities.+ .map((row) => ({ id: row.id, label: row.label, kind: row.kind, scope: row.scope, scopes: row.scopes }));return {seriesId,checks,