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
address review (codex): decide consumption by 'could a fresh outline run this?' (#1614)
[._.]/ Adam Eivyb31d3584ab48
diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.jsindex c0c4231a78..05c2c1cb90 100644--- a/server/services/pipeline/editorial/checkRunner.js+++ b/server/services/pipeline/editorial/checkRunner.js@@ -857,28 +857,35 @@ export async function buildEditorialCheckPlan(seriesId, { checkIds = null, setti* (the dry-run plan + the cheap pre-filter, neither of which builds a ctx) so* existing callers are unchanged.*- * Critically, the refresh REGENERATES the outline — so a gate that reads the- * outline can't be predicted from the stale copy (its "declines" may flip to- * "passes" once the outline is fresh, e.g. a `pov.justified` gate that finds no- * POV-tagged scenes in a stale outline a refresh would re-tag). We therefore- * only trust a DECLINING gate that decided WITHOUT touching the outline (from- * manuscript/canon/series, which the refresh leaves unchanged); a consumer whose- * gate read the outline stays a consumer so the refresh still runs. A passing- * gate always counts.+ * Critically, the refresh REGENERATES the outline — so a gate that declines+ * against the stale copy may flip to "passes" once the outline is fresh (e.g. a+ * `pov.justified` gate finds no POV-tagged scenes in a stale outline a refresh+ * would re-tag). We answer the only question that matters — "could a fresh+ * outline let this check run?" — by re-evaluating a declining gate against a+ * permissive synthetic outline while keeping the REAL manuscript/canon/series+ * (which the refresh leaves untouched). If it now passes, the outline was the+ * blocker → consumer; if it still declines, the block is outline-independent (a+ * mixed gate like `endings.pov-switch` that also needs authored cliffhangers, an+ * empty manuscript, a canon-less roster) and a refresh can't help → not a+ * consumer. A gate that already passes against the stale outline always counts.*/+const PERMISSIVE_GATE_OUTLINE = Object.freeze({+ reverseOutline: Object.freeze([Object.freeze({+ id: 'scene-001', sequence: 0, povCharacter: 'POV', heading: 'Scene', summary: 'Scene.',+ plotlineId: 'p', secondaryPlotlineId: null, issueNumber: 1,+ components: Object.freeze({ narrative: true, action: true, dialogue: true }),+ charactersPresent: Object.freeze(['POV']), setting: 'Setting', anchorQuote: 'q',+ })]),+ reverseOutlinePlotlines: Object.freeze([Object.freeze({ id: 'p', label: 'Plot', kind: 'main' })]),+});+export function enabledChecksConsumeReverseOutline(settings, checkIds = null, gateCtx = null) {return getEnabledChecks(settings, checkIds).some(({ check }) => {const sources = checkSources(check);if (!sources.includes('reverseOutline') && !sources.includes('reverseOutline.plotlines')) return false;if (!gateCtx || typeof check.gate !== 'function') return true;- let readOutline = false;- const tracked = new Proxy(gateCtx, {- get(target, key) {- if (key === 'reverseOutline' || key === 'reverseOutlinePlotlines') readOutline = true;- return target[key];- },- });- return check.gate(tracked) || readOutline;+ if (check.gate(gateCtx)) return true;+ return check.gate({ ...gateCtx, ...PERMISSIVE_GATE_OUTLINE });});}@@ -1076,4 +1083,4 @@ export function startEditorialChecksRun(seriesId, options = {}) {}// Export internals for tests.-export const __testing = { runs: runner.runs };+export const __testing = { runs: runner.runs, PERMISSIVE_GATE_OUTLINE };diff --git a/server/services/pipeline/editorial/checkRunner.test.js b/server/services/pipeline/editorial/checkRunner.test.jsindex 75f139e713..800fe91ee1 100644--- a/server/services/pipeline/editorial/checkRunner.test.js+++ b/server/services/pipeline/editorial/checkRunner.test.js@@ -76,7 +76,7 @@ vi.mock('../reverseOutline.js', () => ({ getReverseOutline: vi.fn(async () => oulet editorialState = { characters: [] };vi.mock('../editorialAnalysis.js', () => ({ getSeriesEditorial: vi.fn(async () => editorialState) }));-const { runEditorialChecks, buildEditorialCheckPlan, getReviewWithStaleness, enabledChecksConsumeReverseOutline, buildReverseOutlineGateContext, summarizeCheckErrors, previewCustomCheck, buildScopedPriorFindings, effectiveCheckSources } = await import('./checkRunner.js');+const { runEditorialChecks, buildEditorialCheckPlan, getReviewWithStaleness, enabledChecksConsumeReverseOutline, buildReverseOutlineGateContext, summarizeCheckErrors, previewCustomCheck, buildScopedPriorFindings, effectiveCheckSources, __testing: checkRunnerTesting } = await import('./checkRunner.js');const { runStagedLLM, resolveStageContext } = await import('../../../lib/stageRunner.js');const { collectManuscriptSections } = await import('../arcPlanner.js');const { getSeriesCanon } = await import('../seriesCanon.js');@@ -1001,22 +1001,10 @@ describe('enabledChecksConsumeReverseOutline (#1349)', () => {});// Gate-aware consumption (#1614): a supplied ctx narrows the signal to checks- // that would ACTUALLY run for this series, not just declare the source.+ // that would ACTUALLY run for this series. Because the refresh regenerates the+ // outline, the test is "could a FRESH outline let this check run?" — a declining+ // gate is re-evaluated against a permissive synthetic outline.describe('gate-aware via ctx (#1614)', () => {- // Does a check's gate read the outline? The refresh regenerates the outline,- // so an outline-reading gate's verdict against the STALE outline can't be- // trusted — such a check must stay a consumer. Probe it the same way the- // function does (mirrors the implementation's Proxy).- const gateReadsOutline = (check) => {- if (typeof check.gate !== 'function') return false;- let read = false;- const probe = new Proxy(- { manuscript: 'x', canon: { characters: [{ name: 'A' }] }, series: { styleGuide: {} }, reverseOutline: [{ povCharacter: 'A' }], reverseOutlinePlotlines: [{ id: 'p' }] },- { get(t, k) { if (k === 'reverseOutline' || k === 'reverseOutlinePlotlines') read = true; return t[k]; } },- );- try { check.gate(probe); } catch { /* a partial probe ctx may throw — irrelevant to the read flag */ }- return read;- };// A drafted manuscript re-opens the manuscript-gated outline consumers.const liveCtx = { manuscript: 'The kingdom fell.', canon: { characters: [{ name: 'Bob' }] }, reverseOutline: [{ povCharacter: 'Bob' }], reverseOutlinePlotlines: [] };@@ -1025,27 +1013,48 @@ describe('enabledChecksConsumeReverseOutline (#1349)', () => {expect(enabledChecksConsumeReverseOutline({}, null, null)).toBe(true);});- it('is false only when the surviving consumers are gated out for OUTLINE-INDEPENDENT reasons', () => {- // Disable consumers whose gate reads the outline (those can't be skipped on- // a stale outline). The rest are manuscript/canon/series-gated, and an- // empty-manuscript empty-canon ctx makes each decline → no consumer runs.- const settings = disableWhere((c) => consumesOutline(c) && gateReadsOutline(c));- const ctx = { manuscript: '', canon: { characters: [] }, series: {}, reverseOutline: [], reverseOutlinePlotlines: [] };- expect(enabledChecksConsumeReverseOutline(settings, null, ctx)).toBe(false);- });-it('is true when at least one consumer passes its gate against the ctx', () => {expect(enabledChecksConsumeReverseOutline({}, null, liveCtx)).toBe(true);});- it('keeps an outline-content-gated consumer that declines on the STALE outline (#1614, codex P2)', () => {- // Scoped to pov.justified only — its gate reads ctx.reverseOutline. A stale- // outline with scenes but no POV tags makes the gate decline, yet a refresh- // might re-tag POV, so the refresh must NOT be skipped: still a consumer.+ it('keeps an outline-content-gated consumer that declines on the STALE outline (#1614, codex P2 r1)', () => {+ // Scoped to pov.justified only — its gate reads ctx.reverseOutline; a stale+ // outline with scenes but no POV tags makes it decline. A refresh might add+ // POV, so the permissive re-eval flips it true → still a consumer (don't skip).const onlyPov = disableWhere((c) => consumesOutline(c) && c.id !== 'pov.justified');const staleNoPov = { manuscript: 'x', canon: { characters: [] }, series: {}, reverseOutline: [{ heading: 'h', summary: 's' }], reverseOutlinePlotlines: [] };expect(enabledChecksConsumeReverseOutline(onlyPov, null, staleNoPov)).toBe(true);});++ it('drops a mixed-gate consumer blocked for an OUTLINE-INDEPENDENT reason (#1614, codex P2 r2)', () => {+ // Scoped to endings.pov-switch — its gate needs POV scenes AND authored+ // cliffhangers. With no cliffhangers, even a fresh (permissive) outline can't+ // make it run, so a refresh would be wasted → NOT a consumer → false.+ const onlyEndings = disableWhere((c) => consumesOutline(c) && c.id !== 'endings.pov-switch');+ const noCliffhangers = { manuscript: 'x', canon: { characters: [] }, series: { arc: {} }, reverseOutline: [{ povCharacter: 'A' }], reverseOutlinePlotlines: [] };+ expect(enabledChecksConsumeReverseOutline(onlyEndings, null, noCliffhangers)).toBe(false);+ });++ // Richness guard: the permissive synthetic outline must satisfy the outline+ // half of EVERY consumer's gate — a too-sparse synthetic would wrongly DROP a+ // check whose fresh outline would actually unblock it (a false skip, the+ // dangerous direction). A fully-populated ctx + the synthetic must pass every+ // consumer gate; a new check needing a scene field the synthetic lacks trips this.+ it('permissive synthetic outline satisfies every consumer gate (no false drop)', () => {+ const richCtx = {+ manuscript: 'The kingdom fell. '.repeat(20),+ canon: { characters: [{ name: 'Hero' }, { name: 'Villain' }] },+ series: { styleGuide: { povPerson: 'third-limited' }, arc: { readerMap: { cliffhangers: [{ id: 'c1' }], beats: [{}] }, themes: ['t'], readerKnowledge: [] }, factCritical: true, characterArcs: [] },+ ...checkRunnerTesting.PERMISSIVE_GATE_OUTLINE,+ };+ const consumers = listChecks().filter((c) => Array.isArray(c.sources)+ && (c.sources.includes('reverseOutline') || c.sources.includes('reverseOutline.plotlines'))+ && typeof c.gate === 'function');+ expect(consumers.length).toBeGreaterThan(0);+ for (const check of consumers) {+ expect(check.gate(richCtx), `${check.id} gate failed against permissive synthetic outline`).toBe(true);+ }+ });});});