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

address review (codex): move recurrence count to a deterministic whole-corpus pass (#1412)

Adam Eivy74284dda8b47
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 76f0493d04..f961f60c6d 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -2,7 +2,7 @@
## Added
-- **[issue-1412] Editorial check classifies unmodeled proper nouns used as character names — the LLM-assisted half of roster economy.** A new **Unmodeled proper nouns used as character names** LLM check (Create → Editorial Checks) closes the gap the deterministic **roster economy** check (#1292) deliberately left open: that scan only sees canon names + aliases, so a proper noun used as an *apparent* character name that was never added to the story bible is invisible to it. This check surfaces those — and **classifies** each one, because a keyword scan can't tell a person from a place, organization, brand, or honorific. It reads the stitched manuscript plus your canon roster (names + aliases) as an exclusion list, flags capitalized proper nouns used as character names that are **absent from canon**, and calls out **throwaway one-appearance names** the reader is told to remember but who never recur — suggesting either adding them to canon or recasting them as an unnamed description. Unlike roster economy it runs even on an **empty bible** (then every named proper noun is a candidate). Because whether an unmodeled name recurs is a whole-story judgment, the "throwaway / one-appearance" classification is deferred until the final chunk and a cross-chunk digest carries surfaced names forward — so a long book reviewed in pieces never mislabels a name that appears in chapters 1 and 12 as a one-appearance throwaway. Findings render as `Casting` notes anchored to the issue + a verbatim quote. Ships a new stage prompt (`pipeline-editorial-unmodeled-names`) that migrates for existing installs (116). (`server/lib/editorial/checkRegistry.js`, `data.reference/prompts/stages/pipeline-editorial-unmodeled-names.md`, `scripts/migrations/116-editorial-unmodeled-names-stage.js`, Part of #1283, #1412)
+- **[issue-1412] Editorial check classifies unmodeled proper nouns used as character names — the LLM-assisted half of roster economy.** A new **Unmodeled proper nouns used as character names** LLM check (Create → Editorial Checks) closes the gap the deterministic **roster economy** check (#1292) deliberately left open: that scan only sees canon names + aliases, so a proper noun used as an *apparent* character name that was never added to the story bible is invisible to it. This check surfaces those — and **classifies** each one, because a keyword scan can't tell a person from a place, organization, brand, or honorific. It reads the stitched manuscript plus your canon roster (names + aliases) as an exclusion list, flags capitalized proper nouns used as character names that are **absent from canon**, and calls out **throwaway one-appearance names** the reader is told to remember but who never recur — suggesting either adding them to canon or recasting them as an unnamed description. Unlike roster economy it runs even on an **empty bible** (then every named proper noun is a candidate). The LLM does only the judgment it alone can — surface a name and confirm it's a *person* — while a **deterministic post-pass counts each surfaced name's appearances across the whole manuscript** to apply the one-appearance-throwaway vs recurring label, so a long book reviewed in chunks never mislabels a name that appears in chapters 1 and 12 as a throwaway (and the same name surfaced from two chunks collapses to one finding). Findings render as `Casting` notes anchored to the issue + a verbatim quote. Ships a new stage prompt (`pipeline-editorial-unmodeled-names`) that migrates for existing installs (116). (`server/lib/editorial/checkRegistry.js`, `data.reference/prompts/stages/pipeline-editorial-unmodeled-names.md`, `scripts/migrations/116-editorial-unmodeled-names-stage.js`, Part of #1283, #1412)
- **[issue-1317] Editorial check flags theme-coherence problems — themes stated but never dramatized, dropped after the opening, or unpaid at the climax (plus emergent-theme detection).** A new **Theme coherence / thematic throughline** LLM check (Create → Editorial Checks) asks whether the manuscript actually *delivers* the themes the story arc declares (`series.arc.themes`), not just names them. For each declared theme it builds a setup → complication → payoff coverage map and flags a theme that is **stated but never dramatized** through a character's choices or the central conflict, a theme that is **dropped** after the opening, and a climax that **resolves the plot but never lands the thematic argument** the setup promised. It also detects a strong **emergent theme** the story is really telling that isn't in the declared list — offering to add it (or reconciling it when the story drifts into a competing argument). It reads your reverse-outline scene segmentation as context so it can attribute a theme's setup/payoff to a scene + issue, and **degrades gracefully** — no authored themes ⇒ it works from the prose alone to surface emergent themes; no outline ⇒ it scans the whole manuscript. Whole-arc judgments (a dropped theme, an unpaid climax) are deferred until it has seen the final chunk, and cross-chunk findings + clean-setup digests keep a long book reviewed in pieces from false-flagging a theme whose payoff lands later. Findings render as `Theme` notes anchored to the issue + a verbatim quote. Ships a new stage prompt (`pipeline-editorial-theme-coherence`) that migrates for existing installs (115). (`server/lib/editorial/checkRegistry.js`, `server/services/pipeline/editorial/checkRunner.js`, `data.reference/prompts/stages/pipeline-editorial-theme-coherence.md`, `scripts/migrations/115-editorial-theme-coherence-stage.js`, Part of #1283, #1317)
diff --git a/data.reference/prompts/stages/pipeline-editorial-unmodeled-names.md b/data.reference/prompts/stages/pipeline-editorial-unmodeled-names.md
index c64ec5affc..373c71e8d2 100644
--- a/data.reference/prompts/stages/pipeline-editorial-unmodeled-names.md
+++ b/data.reference/prompts/stages/pipeline-editorial-unmodeled-names.md
@@ -6,17 +6,17 @@ apparent CHARACTER names that were never added to the story bible. Your job is t
surface them and CLASSIFY each one, because a deterministic name scan can't tell a
person from a place, an organization, a brand, or an honorific.
-Flag only these (each is a distinct finding):
+Flag this (one finding per distinct name):
- **Unmodeled named character** — a proper noun used as a person's name (someone
speaks, acts, is addressed, or is referred to as a character) that is NOT in the
known-characters list below. Name them so the author can decide: add to canon, or
leave unnamed.
-- **Throwaway unmodeled name** — an unmodeled named character who appears only
- once (a named body the reader is told to remember but who never recurs and was
- never bibled). Suggest either adding them to canon if they are meant to matter, or
- recasting them as an unnamed description ("the bartender") so the reader isn't
- asked to track a name that goes nowhere.
+
+You do NOT need to judge how OFTEN a name appears — a deterministic pass counts
+each surfaced name's appearances across the whole manuscript afterward and labels
+one-appearance names as throwaways. Your job is only to find apparent character
+names and confirm they are people (not the false positives below).
Do NOT flag:
@@ -55,38 +55,25 @@ in each header to attribute every finding to its `issueNumber`.
{{manuscript}}
```
-{{#finalPart}}
-You are seeing the FINAL part of the manuscript, so you may now judge RECURRENCE
-across the whole story: an unmodeled name that appears in only one place is a
-one-appearance throwaway, while one that recurs across parts is a recurring
-unmodeled character. The "already recorded" digest above lists unmodeled names
-earlier parts already surfaced — do NOT repeat those; instead use them to decide
-recurrence (a name flagged earlier that also appears here recurs, so report it as
-recurring rather than a throwaway).
-{{/finalPart}}
-{{^finalPart}}
-You are seeing an EARLIER part of a long manuscript reviewed in pieces, so you
-CANNOT yet judge whether a name is a one-appearance throwaway — it may recur in a
-later part you haven't seen. Surface each unmodeled name you find here WITHOUT the
-throwaway/recurrence classification (use `Unmodeled character — "Name"`); a later
-part reconciles recurrence. The "already recorded" digest above lists unmodeled
-names earlier parts already surfaced — do NOT repeat those.
-{{/finalPart}}
+You may be seeing only one PART of a long manuscript reviewed in pieces. That's
+fine — surface every unmodeled name you can see in this part. The "already
+recorded" digest above (when present) lists unmodeled names earlier parts already
+surfaced; do NOT repeat those.
## Task
Scan the prose for capitalized proper nouns used as apparent character names,
drop every one that is already in the known-characters list (name or alias) or is
clearly a non-person (place / organization / brand / bare honorific), and report
-what remains. For each finding set `location` to the classification + the name,
-e.g. `Unmodeled character — "Marguerite"` or (only when you can see the whole
-manuscript) `Throwaway name — "Old Henrik" (1 appearance)`. Quote a short verbatim
-anchor (≤ 200 chars) at the name's first use. Severity: a recurring unmodeled
-character who carries scenes is medium; a one-appearance throwaway name is low. If
-every named character in the prose is already modeled (or the only unmodeled proper
-nouns are places/orgs/brands/honorifics), return an empty `findings` array. Do not
-invent names the prose doesn't use, and do not flag a name just because it is rare —
-only because it is UNMODELED.
+what remains — one finding per distinct name. For each finding set `location` to
+`Unmodeled character — "Name"` (e.g. `Unmodeled character — "Marguerite"`); the
+deterministic post-pass rewrites this to a throwaway/recurring label and sets the
+final severity, so just use that one form and let `severity` be your best guess.
+Quote a short verbatim anchor (≤ 200 chars) at the name's first use. If every
+named character in the prose is already modeled (or the only unmodeled proper nouns
+are places/orgs/brands/honorifics), return an empty `findings` array. Do not invent
+names the prose doesn't use, and do not flag a name just because it is rare — only
+because it is UNMODELED.
## Output contract
@@ -99,7 +86,7 @@ commentary:
{
"severity": "high|medium|low",
"issueNumber": 3,
- "location": "string — classification + name (e.g. 'Unmodeled character — \"Marguerite\"' or 'Throwaway name — \"Old Henrik\" (1 appearance)')",
+ "location": "string — always 'Unmodeled character — \"Name\"' (e.g. 'Unmodeled character — \"Marguerite\"'); the deterministic post-pass relabels throwaway vs recurring",
"problem": "1–3 sentences naming the proper noun, why you classified it as a character (not a place/org/brand/honorific), and whether it recurs or appears only once",
"suggestion": "1–3 sentences proposing how to resolve it (add to canon if it should matter, or recast as an unnamed description if it's a throwaway)",
"anchorQuote": "short verbatim quote at the name's first use (≤ 200 chars)"
diff --git a/server/lib/editorial/README.md b/server/lib/editorial/README.md
index 19b68df866..b588c91c0b 100644
--- a/server/lib/editorial/README.md
+++ b/server/lib/editorial/README.md
@@ -28,10 +28,18 @@ spare room — so it never displaces manuscript text or overflows the provider
window (a chunk packed to the budget just runs without a digest).
`style.conformance` (tense/POV established earlier),
`objects.unmotivated-interaction` (setup/payoff across chapters), and
-`roster.unmodeled-names` (an unmodeled name's recurrence is whole-corpus, so a
-later part doesn't re-flag a name an earlier part surfaced and the throwaway/
-recurring judgment is gated to the final part) opt in; `prose.info-dumping` stays
-per-chunk (its problems are localized).
+`roster.unmodeled-names` (so a later part doesn't re-describe an unmodeled name an
+earlier part already surfaced) opt in; `prose.info-dumping` stays per-chunk (its
+problems are localized).
+
+`roster.unmodeled-names` also shows the LLM/deterministic split that keeps a
+chunked judgment correct: the model does ONLY what it alone can — surface a proper
+noun used as a character name and confirm it's a person (not a place/org/brand/
+honorific) — and a deterministic post-pass in `run()` counts each surfaced name's
+distinct-issue appearances across the WHOLE `ctx.sections` corpus to apply the
+one-appearance-throwaway vs recurring label + final severity. Recurrence is a
+whole-corpus count the model can't make per-chunk (a name in issues 1 and 12 looks
+like a one-off to whichever chunk sees it), so it never asks the model for it.
The findings digest carries prior *problems* forward but not clean prior *setup*
— a payoff in a later chunk can be mis-flagged "missing setup" when the earlier
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.js
index 792f0380bb..4ae5be8c02 100644
--- a/server/lib/editorial/checkRegistry.js
+++ b/server/lib/editorial/checkRegistry.js
@@ -1843,26 +1843,51 @@ export const EDITORIAL_CHECKS = [
// 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,
- run: (ctx) => {
+ 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
// the per-chunk budget so the manuscript isn't squeezed past the window.
const knownCharacters = canonRosterNamesSummary(ctx.canon);
- return runManuscriptLlmCheck(ctx, {
+ // The LLM does ONLY what it alone can: surface a proper noun used as a
+ // character name and classify it (person vs place/org/brand/honorific). It
+ // does NOT judge recurrence — that's a whole-corpus count the model can't make
+ // when the manuscript is chunked (a name in issues 1 and 12 would look like a
+ // one-appearance throwaway to whichever chunk sees it). `crossChunkDigest`
+ // keeps a later chunk from re-describing a name an earlier chunk surfaced.
+ const findings = await runManuscriptLlmCheck(ctx, {
stage: UNMODELED_NAMES_STAGE,
category: 'casting',
overheadTokens: EDITORIAL_PROMPT_OVERHEAD_TOKENS + estimateTokens(knownCharacters),
- // The recurrence judgment (one-appearance throwaway vs recurring) is a
- // WHOLE-corpus call, so on a chunked manuscript an earlier part must NOT
- // declare a name a throwaway — it may recur in a later part it hasn't seen.
- // `finalPart` gates that judgment to the last chunk (mirrors chekhov /
- // endings), and `crossChunkDigest` carries each part's surfaced names
- // forward so the final part can confirm recurrence and the same unmodeled
- // name isn't re-flagged across parts. A single-chunk run is its own final
- // part, so the common (provider-fits-the-book) case judges the whole text.
crossChunkDigest: true,
- buildVars: (manuscript, meta) => ({ manuscript, knownCharacters, finalPart: meta?.isFinal ? 'true' : '' }),
+ buildVars: (manuscript) => ({ manuscript, knownCharacters }),
});
+ // Deterministic whole-corpus recurrence pass. Each finding's `location` carries
+ // the surfaced name in quotes (`Unmodeled character — "Marguerite"`); count its
+ // distinct-issue appearances across ALL sections (not just the chunk the LLM
+ // saw) so the throwaway/recurring label is correct regardless of chunking, and
+ // collapse findings that surfaced the same name in different chunks. A name the
+ // matcher can't find in the prose (a stray/garbled LLM token) is left as the
+ // model classified it rather than fabricating a "0 appearances" throwaway.
+ const sections = Array.isArray(ctx.sections) ? ctx.sections : [];
+ const seenNames = new Set();
+ const out = [];
+ for (const f of findings) {
+ const name = (String(f.location || '').match(/"([^"]+)"/) || [])[1];
+ if (!name) { out.push(f); continue; }
+ const key = normalizeName(name);
+ if (key && seenNames.has(key)) continue; // same unmodeled name from another chunk
+ if (key) seenNames.add(key);
+ const matcher = characterMatcher([name]);
+ const issues = matcher
+ ? new Set(sections.filter((s) => matcher.test(s.content || '')).map((s) => s.number))
+ : new Set();
+ const count = issues.size;
+ if (count === 0) { out.push(f); continue; }
+ out.push(count === 1
+ ? { ...f, severity: 'low', location: `Throwaway name — "${name}" (1 appearance)` }
+ : { ...f, severity: 'medium', location: `Unmodeled character — "${name}" (${count} issues)` });
+ }
+ return out;
},
},
{
diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.js
index eb736c77e2..d108263166 100644
--- a/server/lib/editorial/checkRegistry.test.js
+++ b/server/lib/editorial/checkRegistry.test.js
@@ -916,15 +916,22 @@ describe('declaredThemesSummary (#1317)', () => {
});
describe('roster.unmodeled-names — LLM check (#1412)', () => {
+ // The deterministic recurrence pass reads ctx.sections (one per issue), so a
+ // surfaced name's appearances are counted across the WHOLE manuscript — not just
+ // the chunk the model saw. `llmFinds` stubs the LLM to surface the given names.
const wholeCtx = (overrides = {}) => ({
manuscript: '# Issue 1\n\nMarguerite drew her sword as the bells of Veridia rang.',
config: { maxFindings: 12 },
severityDefault: 'low',
canon: { characters: [{ name: 'Robert', aliases: ['Bob'] }] },
+ sections: [{ number: 1, content: 'Marguerite drew her sword as the bells of Veridia rang.' }],
planManuscriptChunks: async () => ['# Issue 1\n\nMarguerite drew her sword.'],
callStagedLLM: async () => ({ content: { findings: [] } }),
...overrides,
});
+ const llmFinds = (...names) => async () => ({
+ content: { findings: names.map((n) => ({ severity: 'low', issueNumber: 1, location: `Unmodeled character — "${n}"`, problem: `${n} is not in canon` })) },
+ });
it('is registered as a series-scoped LLM casting check reading manuscript + canon', () => {
const check = getCheck(UNMODELED_NAMES);
@@ -962,7 +969,6 @@ describe('roster.unmodeled-names — LLM check (#1412)', () => {
expect(seenVars.knownCharacters).toContain('Bob');
expect(findings).toHaveLength(1);
expect(findings[0].category).toBe('casting');
- expect(findings[0].location).toBe('Unmodeled character — "Marguerite"');
});
it('passes an empty roster var when the canon has no characters', async () => {
@@ -975,23 +981,62 @@ describe('roster.unmodeled-names — LLM check (#1412)', () => {
expect(seenVars.knownCharacters).toBe('');
});
- it('marks a single-chunk run as the final part so the recurrence judgment is enabled', async () => {
- let seenVars = null;
+ it('relabels a one-appearance surfaced name as a low-severity throwaway', async () => {
const ctx = wholeCtx({
- callStagedLLM: async (_stage, vars) => { seenVars = vars; return { content: { findings: [] } }; },
+ sections: [{ number: 1, content: 'Old Henrik nodded once and was never seen again.' }],
+ callStagedLLM: llmFinds('Old Henrik'),
});
- await getCheck(UNMODELED_NAMES).run(ctx);
- expect(seenVars.finalPart).toBe('true');
+ const findings = await getCheck(UNMODELED_NAMES).run(ctx);
+ expect(findings).toHaveLength(1);
+ expect(findings[0].location).toBe('Throwaway name — "Old Henrik" (1 appearance)');
+ expect(findings[0].severity).toBe('low');
});
- it('flags only the LAST part as final across a chunked manuscript (recurrence is whole-corpus)', async () => {
- const finals = [];
+ it('counts appearances across ALL sections (not just the seen chunk) and labels a recurring name medium', async () => {
+ // Marguerite appears in issues 1 and 3 — the deterministic pass must see both,
+ // so a chunk that only showed issue 3 can't mislabel her a one-appearance throwaway.
const ctx = wholeCtx({
- planManuscriptChunks: async () => ['# Issue 1\n\np1', '# Issue 2\n\np2', '# Issue 3\n\np3'],
- callStagedLLM: async (_stage, vars) => { finals.push(vars.finalPart); return { content: { findings: [] } }; },
+ sections: [
+ { number: 1, content: 'Marguerite drew her sword.' },
+ { number: 2, content: 'A quiet interlude with no new names.' },
+ { number: 3, content: 'Marguerite returned to the war room.' },
+ ],
+ callStagedLLM: llmFinds('Marguerite'),
});
- await getCheck(UNMODELED_NAMES).run(ctx);
- expect(finals).toEqual(['', '', 'true']);
+ const findings = await getCheck(UNMODELED_NAMES).run(ctx);
+ expect(findings).toHaveLength(1);
+ expect(findings[0].location).toBe('Unmodeled character — "Marguerite" (2 issues)');
+ expect(findings[0].severity).toBe('medium');
+ });
+
+ it('collapses the same surfaced name reported from two different chunks into one finding', async () => {
+ const ctx = wholeCtx({
+ sections: [
+ { number: 1, content: 'Marguerite drew her sword.' },
+ { number: 2, content: 'Marguerite sheathed it again.' },
+ ],
+ // Two chunks each surface Marguerite — the dedupe keeps one.
+ callStagedLLM: llmFinds('Marguerite', 'Marguerite'),
+ });
+ const findings = await getCheck(UNMODELED_NAMES).run(ctx);
+ expect(findings).toHaveLength(1);
+ expect(findings[0].location).toBe('Unmodeled character — "Marguerite" (2 issues)');
+ });
+
+ it('leaves a finding untouched when its name cannot be parsed or is absent from the prose', async () => {
+ const ctx = wholeCtx({
+ sections: [{ number: 1, content: 'Nothing matching here.' }],
+ callStagedLLM: async () => ({ content: { findings: [
+ { severity: 'low', issueNumber: 1, location: 'General note (no quoted name)', problem: 'malformed' },
+ { severity: 'low', issueNumber: 1, location: 'Unmodeled character — "Ghostname"', problem: 'not actually in prose' },
+ ] } }),
+ });
+ const findings = await getCheck(UNMODELED_NAMES).run(ctx);
+ // Neither is rewritten: the first has no quoted name; the second matches 0 sections.
+ expect(findings.map((f) => f.location)).toEqual([
+ 'General note (no quoted name)',
+ 'Unmodeled character — "Ghostname"',
+ ]);
});
});