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([issue-1595]): classify chekhov setups/payoffs into a four-way taxonomy with distant-payoff detection

[._.]/ Adam Eivy384d8b96954a
diff --git a/data.reference/prompts/stages/pipeline-editorial-chekhov.md b/data.reference/prompts/stages/pipeline-editorial-chekhov.md
index f30535fd8f..d333a89d81 100644
--- a/data.reference/prompts/stages/pipeline-editorial-chekhov.md
+++ b/data.reference/prompts/stages/pipeline-editorial-chekhov.md
@@ -2,8 +2,9 @@
You are a developmental editor doing a single focused pass for ONE problem:
**broken setups and payoffs** — Chekhov's-gun hygiene. The rule: *things planted
-must go off; things that go off should have been planted.* Track concrete
-**planted elements** across the manuscript and judge whether each is paid off.
+must go off; things that go off should have been planted* — and a payoff should
+land while the reader still remembers the plant. Track concrete **planted
+elements** across the manuscript and judge how each setup↔payoff thread resolves.
Planted elements to track:
@@ -20,49 +21,68 @@ A planted element is **paid off** when it later goes off: the weapon is used, th
secret spills, the fear is confronted, the promise is kept or broken on the page,
the threat lands, the skill is used at a decisive moment.
-## What to flag
-
-Two failure modes:
-
-- **Fired, never planted** — "the antidote appears in Issue 7 with no prior
- setup"; "she suddenly picks a lock she was never shown able to pick." A payoff
- that lands unearned because nothing set it up. Judge this in **every** part:
- the digest of setups established in earlier parts (above, when present) tells
- you what was already planted, so a payoff whose setup appears nowhere — not in
- this part and not in that digest — is unearned.
-- **Planted, never fired** — "the locked drawer introduced in Issue 2 is never
- opened"; "Issue 1 makes a point of Mara's fear of water, but she never faces
- it." A setup the reader is primed to expect a payoff for, that the manuscript
- drops. Sub-cases worth naming as such: **secret never spilled**, **fear never
- confronted**, **promise never resolved**.
+## How to classify each thread
+
+Sort every setup↔payoff thread into ONE of four classes. Only the bottom three
+are findings — a **paired** thread is healthy and must NOT be reported:
+
+- **paired** — the element is planted AND paid off{{#distantGap}}, and the payoff
+ is close enough that the reader still recalls the plant{{/distantGap}}. Healthy.
+ **Do not flag.**
+- **false setup** — *planted, never fired.* "the locked drawer introduced in
+ Issue 2 is never opened"; "Issue 1 makes a point of Mara's fear of water, but
+ she never faces it." A setup the reader is primed to expect a payoff for, that
+ the manuscript drops — it should be paid off later or **cut**. Sub-cases worth
+ naming as such: **secret never spilled**, **fear never confronted**, **promise
+ never resolved**.
+- **orphaned payoff** — *fired, never planted.* "the antidote appears in Issue 7
+ with no prior setup"; "she suddenly picks a lock she was never shown able to
+ pick." A payoff that lands unearned because nothing set it up. Judge this in
+ **every** part: the digest of setups established in earlier parts (above, when
+ present) tells you what was already planted, so a payoff whose setup appears
+ nowhere — not in this part and not in that digest — is unearned.
+{{#distantGap}}
+- **distant payoff** — *paid off, but too late.* The element IS both planted and
+ paid off, but the payoff arrives **{{distantGap}} or more issues after** the
+ setup (e.g. setup in Issue 1, payoff in Issue {{distantGap}}+1 or later), far
+ enough that the reader may no longer recall the plant, so the payoff reads as
+ unearned even though it is technically set up. Use the issue number where the
+ element was planted (this part, or the carried setup digest above) and the issue
+ number where it pays off; flag the thread only when that gap is **at least
+ {{distantGap}} issues**. Suggest re-seeding a brief reminder of the setup nearer
+ the payoff (or moving the payoff earlier) rather than cutting it.
+{{/distantGap}}
{{#finalPart}}
-This is the **final part** of the manuscript, so you can now judge *planted,
-never fired*: read the setups established in earlier parts (the digest above,
-when present) together with this part, and report any planted element you can
-confirm is **never paid off anywhere**.
+This is the **final part** of the manuscript, so you can now judge *false setups*
+(planted, never fired): read the setups established in earlier parts (the digest
+above, when present) together with this part, and report any planted element you
+can confirm is **never paid off anywhere**.
{{/finalPart}}
{{^finalPart}}
**You are reading the manuscript in PARTS and have not yet seen the later
parts.** A setup introduced here may be paid off in a part you have not seen
-yet — so do **NOT** report *planted, never fired* in this part. Report only
-*fired, never planted* here. The setups you see in this part are carried forward
-and judged for payoff once the final part is in view.
+yet — so do **NOT** report a *false setup* (planted, never fired) in this part.
+Report only *orphaned payoffs* (fired, never planted){{#distantGap}} and *distant
+payoffs* (a payoff here whose setup, per the digest above, is {{distantGap}}+
+issues back){{/distantGap}} here. The setups you see in this part are carried
+forward and judged for payoff once the final part is in view.
{{/finalPart}}
Do NOT flag: a deliberately unresolved thread the story clearly intends to carry
into a later installment; incidental scenery that is plainly not presented as
-significant; a payoff that IS present (even if subtle) — the bar is a genuine
-plant with no payoff, or a payoff with no plant.
+significant; a payoff that IS present (even if subtle) and lands close enough to
+its setup — the bar is a genuine plant with no payoff, a payoff with no plant, or
+a payoff so far from its plant the reader has lost the thread.
{{#authoredSetups}}
## Reader-map the writer has already logged
The writer has logged these hooks and payoffs in the series reader-map. Reconcile
your findings against them: an authored hook with no payoff you can find in the
-prose is a strong *planted-never-fired*; a strong payoff you find that is NOT in
-this list may simply be unlogged (not necessarily a problem) — judge from the
-prose, not the list alone. Do not invent findings just to match the list.
+prose is a strong *false setup*; a strong payoff you find that is NOT in this list
+may simply be unlogged (not necessarily a problem) — judge from the prose, not the
+list alone. Do not invent findings just to match the list.
```
{{authoredSetups}}
@@ -75,8 +95,10 @@ The manuscript is stitched from the drafted issues. Section headers attribute ea
chunk to an issue (e.g. `# Issue 3 — Title (prose)`). Use the issue number in each
header to attribute every finding to its `issueNumber`. Because setups and payoffs
span issues, the text below may be prefixed with a short digest of elements
-already planted in earlier parts — use it so you do not re-flag a setup that pays
-off later, and so you can flag a setup from an earlier part that never fires.
+already planted in earlier parts (with the issue each was planted in) — use it so
+you do not re-flag a setup that pays off later{{#distantGap}}, so you can measure
+the setup→payoff issue gap for distant payoffs{{/distantGap}}, and so you can flag
+a setup from an earlier part that never fires.
```
{{manuscript}}
@@ -84,17 +106,20 @@ off later, and so you can flag a setup from an earlier part that never fires.
## Task
-Find planted elements with no payoff, and payoffs with no plant. For each, quote a
-short verbatim anchor from the text (≤ 200 characters) so the editor can jump to
-it, name the issue number it appears in, classify the problem in the `location`
-(e.g. `Issue 2 — planted, never fired`, `Issue 7 — fired, never planted`,
-`Issue 1 — fear never confronted`), explain the broken setup/payoff, and suggest
-the fix (plant earlier, pay off later, or cut). Set severity by how strongly the
-element is foregrounded — a prominently planted gun that never fires is more
+Classify each setup↔payoff thread and report every **false setup**, **orphaned
+payoff**{{#distantGap}}, and **distant payoff**{{/distantGap}} (never a paired
+thread). For each, quote a short verbatim anchor from the text (≤ 200 characters)
+so the editor can jump to it, name the issue number it appears in, classify the
+problem in the `location` using the class name (e.g. `Issue 2 — false setup`,
+`Issue 7 — orphaned payoff`{{#distantGap}}, `Issue 9 — distant payoff (setup in
+Issue 1)`{{/distantGap}}), explain the broken thread, and suggest the fix (plant
+earlier, pay off later, re-seed a reminder, or cut). Set severity by how strongly
+the element is foregrounded — a prominently planted gun that never fires is more
serious than a passing detail.
-Be specific and cite the text. If every plant pays off and every payoff is set up,
-return an empty `findings` array — do not invent issues.
+Be specific and cite the text. If every plant pays off, every payoff is set up,
+and no payoff strays too far from its plant, return an empty `findings` array — do
+not invent issues.
## Output contract
@@ -107,9 +132,9 @@ commentary:
{
"severity": "high|medium|low",
"issueNumber": 2,
- "location": "string — the classification + where (e.g. 'Issue 2 — planted, never fired')",
+ "location": "string — the class + where (e.g. 'Issue 2 — false setup', 'Issue 7 — orphaned payoff'{{#distantGap}}, 'Issue 9 — distant payoff (setup in Issue 1)'{{/distantGap}})",
"problem": "1–3 sentences naming the planted element (or unearned payoff) and what is missing",
- "suggestion": "1–3 sentences on the fix — plant earlier, pay off later, or cut",
+ "suggestion": "1–3 sentences on the fix — plant earlier, pay off later, re-seed a reminder, or cut",
"anchorQuote": "short verbatim quote from the manuscript (≤ 200 chars)"
}
]
diff --git a/scripts/migrations/138-editorial-chekhov-setup-payoff-taxonomy.js b/scripts/migrations/138-editorial-chekhov-setup-payoff-taxonomy.js
new file mode 100644
index 0000000000..5c57e52c00
--- /dev/null
+++ b/scripts/migrations/138-editorial-chekhov-setup-payoff-taxonomy.js
@@ -0,0 +1,60 @@
+/**
+ * Refine the `chekhov.setups-payoffs` editorial check into a four-way taxonomy
+ * (#1595).
+ *
+ * The original Chekhov stage prompt detected only two failure modes — "fired,
+ * never planted" and "planted, never fired". This rewrite classifies every
+ * setup↔payoff thread as paired / false-setup / orphaned-payoff / **distant**,
+ * adding the previously-missing distant-payoff case: an element that IS both
+ * planted and paid off, but whose payoff lands so many issues after the setup
+ * (the configurable `distantGap`) that the reader may no longer recall the plant.
+ * The `{{#distantGap}}` section renders only when the check's distant-payoff gap
+ * is enabled (>= 1), so an install that sets it to 0 keeps the false-setup /
+ * orphaned-payoff behavior unchanged.
+ *
+ * `scripts/setup-data.js` only copies *missing* prompts, so existing installs
+ * keep their old Chekhov template until this migration rewrites it. Migration 100
+ * seeds the file but never tracks its hash, so this is the first hash-driven
+ * update for it — no earlier migration's MD5 tables need resyncing.
+ * Customization-safe: only installs whose copy still hashes to the prior shipped
+ * version are auto-updated; customized prompts are left intact and warned about.
+ *
+ * Strategy: hash-driven prompt-replace via `./_lib.js`. Idempotent.
+ */
+
+import { makePromptReplaceMigration } from './_lib.js';
+
+// Pre-change shipped hash: the original #1299 Chekhov body (seeded by migration
+// 100), which flagged only fired-never-planted / planted-never-fired.
+export const ACCEPTED_OLD_MD5 = {
+ 'pipeline-editorial-chekhov.md': ['bfacbf343ba2b9a3f6037bb45b94e1bb'],
+};
+
+// Post-change shipped hash (paired / false-setup / orphaned-payoff / distant
+// taxonomy + the distantGap-gated distant-payoff rule). Migration 100 is a seed
+// that tracks no hash, so there are no earlier MD5 tables to mirror into.
+export const NEW_SHIPPED_MD5 = {
+ 'pipeline-editorial-chekhov.md': '1f8a1696b5e4f476051dc5b2e5737db9',
+};
+
+const { applyMigration, up } = makePromptReplaceMigration({
+ accepted: ACCEPTED_OLD_MD5,
+ current: NEW_SHIPPED_MD5,
+ label: 'editorial chekhov setup/payoff taxonomy',
+ customizedHint: (filename) =>
+ ` To refine it manually, diff:\n` +
+ ` data.reference/prompts/stages/${filename}\n` +
+ ` against your current:\n` +
+ ` data/prompts/stages/${filename}\n` +
+ ` and add the four-way classification (paired / false-setup /\n` +
+ ` orphaned-payoff / distant) plus the {{#distantGap}} distant-payoff rule.`,
+ skipFooter: (count) =>
+ `⚠️ ${count} Chekhov prompt(s) could not be auto-updated because they were\n` +
+ ` customized. The check still runs, but will keep flagging only false setups\n` +
+ ` and orphaned payoffs — it will not surface distant payoffs (a setup paid\n` +
+ ` off so many issues later the reader may have forgotten it).\n` +
+ ` See data.reference/prompts/stages/pipeline-editorial-chekhov.md.`,
+});
+
+export { applyMigration };
+export default { up };
diff --git a/scripts/migrations/138-editorial-chekhov-setup-payoff-taxonomy.test.js b/scripts/migrations/138-editorial-chekhov-setup-payoff-taxonomy.test.js
new file mode 100644
index 0000000000..fb019bede5
--- /dev/null
+++ b/scripts/migrations/138-editorial-chekhov-setup-payoff-taxonomy.test.js
@@ -0,0 +1,14 @@
+import { describe } from 'vitest';
+
+import { runPromptMigrationTests } from './_testHelpers.js';
+import migration, { applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5 } from './138-editorial-chekhov-setup-payoff-taxonomy.js';
+
+describe('migration 138 — chekhov setup/payoff taxonomy (distant payoffs)', () => {
+ runPromptMigrationTests({
+ migration,
+ applyMigration,
+ ACCEPTED_OLD_MD5,
+ NEW_SHIPPED_MD5,
+ prefix: 'migration-138-',
+ });
+});
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.js
index b91025b271..bfb71b8b27 100644
--- a/server/lib/editorial/checkRegistry.js
+++ b/server/lib/editorial/checkRegistry.js
@@ -4717,7 +4717,7 @@ export const EDITORIAL_CHECKS = [
sources: ['manuscript', 'series.arc.readerMap'],
label: "Chekhov's guns (setups & payoffs)",
description:
- 'Flags planted elements that never pay off (a weapon, clue, secret, stated fear, promise, or threat introduced and then dropped) and payoffs that arrive with no setup (a skill, antidote, or revelation that appears unearned). Reconciles its detected setups/payoffs against the authored reader-map hooks/payoffs.',
+ 'Classifies each setup/payoff thread as paired, false-setup (planted, never fired — cut it), orphaned-payoff (fired, never planted — unearned), or distant (paid off so many issues after the setup the reader may have forgotten). Reconciles its detected setups/payoffs against the authored reader-map hooks/payoffs.',
scope: 'series',
kind: 'llm',
category: 'continuity',
@@ -4729,6 +4729,11 @@ export const EDITORIAL_CHECKS = [
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),
+ // Issue gap at/above which a paid-off setup is flagged as a DISTANT payoff
+ // (#1595) — setup in issue 1, payoff in issue 1+distantGap or later, far
+ // enough that the reader may not still recall the plant. 0 disables the
+ // distant sub-check (only false-setup / orphaned-payoff are reported).
+ distantGap: z.number().int().min(0).max(20).default(4),
}),
configFields: [
{
@@ -4740,11 +4745,23 @@ export const EDITORIAL_CHECKS = [
step: 1,
help: 'Cap findings so a long manuscript can not flood the review.',
},
+ {
+ key: 'distantGap',
+ label: 'Distant-payoff issue gap',
+ type: 'number',
+ min: 0,
+ max: 20,
+ step: 1,
+ 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,
run: (ctx) => {
// Authored hooks/payoffs are fixed per-call overhead (re-sent on each chunk).
const authoredSetups = authoredSetupPayoffSummary(ctx.series?.arc?.readerMap);
+ // 0 disables the distant sub-check; >=1 is the issue-gap threshold. Pass a
+ // string so the prompt's `{{#distantGap}}` section renders only when enabled.
+ const distantGap = ctx.config?.distantGap ?? 4;
return runManuscriptLlmCheck(ctx, {
stage: CHEKHOV_STAGE,
category: 'continuity',
@@ -4752,9 +4769,15 @@ export const EDITORIAL_CHECKS = [
// `finalPart` gates the whole-corpus "planted, never fired" judgment to the
// last part of a chunked manuscript (#1299) — an earlier part can't know a
// setup pays off later, so it would false-flag. A single-chunk run is its own
- // final part. "fired, never planted" stays enabled on every part (the carried
- // setup digest tells a later part what was already planted).
- buildVars: (manuscript, meta, c) => ({ manuscript, authoredSetups: c.authoredSetups, finalPart: meta?.isFinal ? 'true' : '' }),
+ // final part. "fired, never planted" and "distant payoff" stay enabled on
+ // every part (the carried setup digest tells a later part what was already
+ // planted, and in which issue, so the issue gap can be measured at payoff).
+ buildVars: (manuscript, meta, c) => ({
+ manuscript,
+ authoredSetups: c.authoredSetups,
+ finalPart: meta?.isFinal ? 'true' : '',
+ distantGap: distantGap >= 1 ? String(distantGap) : '',
+ }),
// A setup planted in chapter 2 and paid off (or NOT) in chapter 9 spans
// chunks — the cross-chunk digest keeps prior findings in view so a later
// chunk doesn't re-flag, and the clean-setup digest rolls forward which
@@ -4762,8 +4785,11 @@ export const EDITORIAL_CHECKS = [
// "no setup" and a never-fired plant is caught at the end.
crossChunkDigest: true,
crossChunkSetup: true,
+ // Track the issue each element is planted in so a later part can measure the
+ // setup→payoff issue gap for the distant-payoff judgment (#1595).
setupFocus: 'Planted elements that a later scene should pay off — weapons/objects/clues, '
+ 'secrets, stated fears, promises/vows, threats, and notable skills — and, for each, '
+ + 'the issue number it was first planted in, and '
+ 'whether it has already been paid off (fired, spilled, confronted, kept) or is still open.',
});
},
diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.js
index df9bad5767..0cee335990 100644
--- a/server/lib/editorial/checkRegistry.test.js
+++ b/server/lib/editorial/checkRegistry.test.js
@@ -722,6 +722,44 @@ describe('chekhov.setups-payoffs — LLM check (#1299)', () => {
expect(seenVars.authoredSetups).toBe('');
});
+ it('passes the configured distant-payoff issue gap as a string var (#1595)', async () => {
+ let seenVars = null;
+ const ctx = wholeCtx({
+ config: { maxFindings: 12, distantGap: 6 },
+ callStagedLLM: async (_stage, vars) => { seenVars = vars; return { content: { findings: [] } }; },
+ });
+ await getCheck(CHEKHOV).run(ctx);
+ expect(seenVars.distantGap).toBe('6');
+ });
+
+ it('defaults the distant-payoff gap to 4 when the series omits it (#1595)', async () => {
+ let seenVars = null;
+ const ctx = wholeCtx({
+ callStagedLLM: async (_stage, vars) => { seenVars = vars; return { content: { findings: [] } }; },
+ });
+ await getCheck(CHEKHOV).run(ctx);
+ expect(seenVars.distantGap).toBe('4');
+ });
+
+ it('disables the distant-payoff section by passing an empty var when distantGap is 0 (#1595)', async () => {
+ let seenVars = null;
+ const ctx = wholeCtx({
+ config: { maxFindings: 12, distantGap: 0 },
+ callStagedLLM: async (_stage, vars) => { seenVars = vars; return { content: { findings: [] } }; },
+ });
+ await getCheck(CHEKHOV).run(ctx);
+ expect(seenVars.distantGap).toBe('');
+ });
+
+ it('accepts distantGap through the config schema and rejects out-of-range values (#1595)', () => {
+ const { configSchema } = getCheck(CHEKHOV);
+ expect(configSchema.parse({}).distantGap).toBe(4);
+ expect(configSchema.parse({ distantGap: 0 }).distantGap).toBe(0);
+ expect(configSchema.parse({ distantGap: 20 }).distantGap).toBe(20);
+ expect(() => configSchema.parse({ distantGap: 21 })).toThrow();
+ expect(() => configSchema.parse({ distantGap: -1 })).toThrow();
+ });
+
it('marks a single-chunk run as the final part so whole-corpus "never fired" judgments are enabled', async () => {
let seenVars = null;
const ctx = wholeCtx({
diff --git a/server/lib/editorial/chekhovPrompt.test.js b/server/lib/editorial/chekhovPrompt.test.js
new file mode 100644
index 0000000000..b7c447eee4
--- /dev/null
+++ b/server/lib/editorial/chekhovPrompt.test.js
@@ -0,0 +1,61 @@
+import { describe, it, expect } from 'vitest';
+import { readFileSync } from 'fs';
+import { dirname, join } from 'path';
+import { fileURLToPath } from 'url';
+
+import { applyTemplate } from '../promptTemplate.js';
+
+// Renders the SHIPPED Chekhov stage prompt to pin the {{#distantGap}} toggle and
+// the four-way taxonomy (#1595). A string-valued section (`distantGap: '6'`) is
+// the same pattern as `{{#finalPart}}`/`{{#authoredSetups}}` — guard against a
+// regression where the distant-payoff rule silently disappears or `{{distantGap}}`
+// fails to interpolate inside its own section.
+const CHEKHOV_PROMPT = readFileSync(
+ join(dirname(fileURLToPath(import.meta.url)), '../../../data.reference/prompts/stages/pipeline-editorial-chekhov.md'),
+ 'utf-8',
+);
+
+const baseVars = (overrides = {}) => ({
+ manuscript: '# Issue 1\n\nHe locked the revolver in the drawer.',
+ authoredSetups: '',
+ finalPart: 'true',
+ distantGap: '6',
+ ...overrides,
+});
+
+describe('pipeline-editorial-chekhov prompt rendering (#1595)', () => {
+ it('renders the distant-payoff rule with the configured issue gap interpolated', () => {
+ const out = applyTemplate(CHEKHOV_PROMPT, baseVars({ distantGap: '6' }));
+ expect(out).toContain('distant payoff');
+ // {{distantGap}} resolves inside its own {{#distantGap}} section.
+ expect(out).toContain('6 or more issues after');
+ expect(out).not.toContain('{{distantGap}}');
+ expect(out).not.toContain('{{#distantGap}}');
+ });
+
+ it('omits the distant-payoff rule entirely when distantGap is the empty (disabled) var', () => {
+ const out = applyTemplate(CHEKHOV_PROMPT, baseVars({ distantGap: '' }));
+ expect(out).not.toContain('distant payoff');
+ expect(out).not.toMatch(/distant payoffs/);
+ // The other two failure modes still render.
+ expect(out).toContain('false setup');
+ expect(out).toContain('orphaned payoff');
+ expect(out).not.toContain('{{#distantGap}}');
+ });
+
+ it('always renders the false-setup and orphaned-payoff classes regardless of distantGap', () => {
+ for (const gap of ['', '1', '4', '20']) {
+ const out = applyTemplate(CHEKHOV_PROMPT, baseVars({ distantGap: gap }));
+ expect(out).toContain('false setup');
+ expect(out).toContain('orphaned payoff');
+ expect(out).toContain('paired');
+ }
+ });
+
+ it('leaves no unresolved mustache tags for a fully-populated context', () => {
+ const out = applyTemplate(CHEKHOV_PROMPT, baseVars({
+ authoredSetups: '- Hook: the locked drawer (Issue 1)',
+ }));
+ expect(out).not.toMatch(/\{\{[#^/]?[\w.]+\}\}/);
+ });
+});