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: per-character dialogue distribution in cast.representation-balance (#1594)
[._.]/ Adam Eivy0a115a721992
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 75cc7d81f0..9196740304 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -77,6 +77,8 @@- **[issue-1592] The adverb check no longer flags invisible reporting dialogue tags like "said quietly" — only emotion-telling ones like "said angrily".** `prose.adverbs` treated *every* adverb on a dialogue tag as a weak attribution, but "said quietly / softly / sharply" is a near-invisible stage direction that tells the reader *how* a line was voiced, while "said angrily / happily / sorrowfully" *names the feeling* the dialogue itself should carry. Lumping them together produced false positives on legitimate reporting adverbs — which trains writers to ignore the check. The check now classifies each tag adverb as **reporting** (a curated manner/volume/pace allow-list) or **emotion-telling** (everything else, so a novel emotion adverb still gets caught) and flags only the emotion-telling bucket by default; the bulk per-1000-word adverb-density signal (the prose-body flagging) is unchanged. A new per-series **"Also flag reporting tags"** toggle restores the old flag-every-tag behavior for anyone who wants the strict pass. (`server/lib/editorial/proseTics.js`, `server/lib/editorial/checkRegistry.js`)+- **[issue-1594] The cast representation check now catches per-character dialogue imbalance, not just one dominant voice.** `cast.representation-balance` already flagged the *top* speaker hogging the page, but a lopsided cast can fail two other ways it never saw: a **major character who appears in the prose yet barely speaks** (a lead reduced to a passenger in their own story) and a **minor character who dominates the conversation** (a walk-on whose page time doesn't match the bible). The check now adds a per-character distribution signal that compares each character's attributed dialogue share against their **stated canon role** — classifying the free-text `role` field into a coarse *major* (protagonist, lead, antagonist, …) / *minor* (background, cameo, walk-on, …) / *unknown* tier, and flagging the silent-major and dominant-minor outliers. It reuses the same dialogue attribution the share signal already runs (no extra pass), gates the silent-major case on the character actually appearing in the prose (a major who never appears is *absent*, a different signal — not "oddly silent"), and stays silent on any character whose role is blank, ambiguous, or contradictory ("minor antagonist") rather than guessing — the same absent-vs-empty discipline the gender inference uses. Two new per-series thresholds tune it: a max dialogue share for a minor character (default 35%) and a min share for a major (default 5%), each independently disable-able. It stays a default-on, deterministic, advisory (low-severity) series signal. (`server/lib/editorial/checkRegistry.js`)+## Series Autopilot- **[issue-1510] Series Autopilot now catches whole-book continuity problems at the cheap beat stage, before it generates full scripts.** The autopilot reviewed continuity at two altitudes — the cross-volume synopsis pass (before beats exist) and the full-text editorial pass (after every issue's script is written, the most expensive stage) — leaving a gap in between. So structural defects spanning the whole book (a cliffhanger raised in one issue and never resolved, a finale that drifts onto a new subplot instead of landing the arc's intended ending, a promised through-line that never pays off, an event staged as the "first" in two different issues, a broken volume-to-volume hand-off) were only caught *after* all the scripts already existed — or not until a human read it. The autopilot now runs a **whole-manuscript beat-continuity pass over every issue's beat sheet, between beat generation and script generation**. Blocking findings are auto-resolved by rewriting just the affected issues' beats and re-checking (bounded, then it pauses for review with the residual findings), so the fix lands before any script is generated. The full-text editorial pass is unchanged and still catches what only the verbatim script can show (pacing, repeated/looping passages, dialogue craft). A new **Beat continuity rounds** control in the autopilot Options tunes how many auto-resolve rounds it attempts (0 skips the pass), saved as a per-install default like the existing Arc-verify and Editorial round knobs.diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.jsindex 9726f05bcc..4ed293f56e 100644--- a/server/lib/editorial/checkRegistry.js+++ b/server/lib/editorial/checkRegistry.js@@ -1531,6 +1531,27 @@ function inferGender(pronouns) {return 'unknown';}+// Coarse role-tier inference from a canon character's free-text `role` field, for+// the per-character dialogue-distribution signal (#1594). Only unambiguous keyword+// sets map to a tier; anything else (blank, a description, a role that mixes a+// major AND a minor word like "minor antagonist") is 'unknown' so the distribution+// signal opts out rather than guess — the same absent-vs-empty discipline+// inferGender() uses. Deliberately omits genuinely-ambiguous words ("supporting",+// "secondary", "recurring") that sit between lead and walk-on. Returns+// 'major' | 'minor' | 'unknown'.+const MAJOR_ROLE_RE = /\b(protagonist|deuteragonist|antagonist|villain|hero|heroine|lead|main|primary|central|principal)\b/;+const MINOR_ROLE_RE = /\b(minor|background|cameo|walk-?on|bit[- ]?part|extra|incidental|tertiary)\b/;+function inferRoleTier(role) {+ const r = typeof role === 'string' ? role.toLowerCase() : '';+ if (!r) return 'unknown';+ const major = MAJOR_ROLE_RE.test(r);+ const minor = MINOR_ROLE_RE.test(r);+ if (major && minor) return 'unknown'; // contradictory ("minor antagonist") → opt out+ if (major) return 'major';+ if (minor) return 'minor';+ return 'unknown';+}+// Normalized name → { char, gender, key } for every named canon character, plus// the per-owner whole-token matcher reused for dialogue attribution. Built once// per run so the dialogue scan and the co-presence scan share one identity map.@@ -1544,7 +1565,13 @@ function buildCastIdentities(ctx) {const key = normalizeName(name);if (!key) continue;const matcher = characterMatcher(characterNameTokens(c));- identities.push({ key, name, gender: inferGender(c.pronouns), matcher });+ identities.push({+ key,+ name,+ gender: inferGender(c.pronouns),+ roleTier: inferRoleTier(c.role),+ matcher,+ });}return identities;}@@ -2702,7 +2729,7 @@ export const EDITORIAL_CHECKS = [sources: ['manuscript', 'canon', 'reverseOutline'],label: 'Cast representation & balance (Bechdel signal, dialogue share, screen time)',description:- 'Three coarse, computable casting signals: a Bechdel co-presence signal (does any scene put two or more non-male characters on the page together?), dialogue share (does one character dominate the spoken lines?), and screen-time balance (is the appearing named cast strongly skewed by inferred gender?). Gender is inferred only from the canon pronouns field — characters with absent or ambiguous pronouns are left out of the gender-dependent signals rather than guessed. Advisory: representation is an authorial choice, so these are nudges, not errors.',+ 'Coarse, computable casting signals: a Bechdel co-presence signal (does any scene put two or more non-male characters on the page together?), dialogue share (does one character dominate the spoken lines?), per-character dialogue distribution relative to stated role (a major character who appears but is oddly silent, or a minor character who dominates the conversation), and screen-time balance (is the appearing named cast strongly skewed by inferred gender?). Gender is inferred only from the canon pronouns field and role tier only from the canon role field — characters with absent or ambiguous pronouns/roles are left out of those signals rather than guessed. Advisory: representation is an authorial choice, so these are nudges, not errors.',scope: 'series',kind: 'deterministic',category: 'casting',@@ -2715,9 +2742,17 @@ export const EDITORIAL_CHECKS = [// Flag dialogue share when the top speaker holds more than this fraction of// all attributed dialogue lines (and there are 2+ speakers). 1 disables it.maxDialogueShare: z.number().min(0.1).max(1).default(0.6),- // Minimum attributed dialogue lines before the share check runs — a handful- // of lines isn't a meaningful distribution. 0 keeps the floor at 1.+ // Minimum attributed dialogue lines before the share/distribution checks run+ // — a handful of lines isn't a meaningful distribution. 0 keeps the floor at 1.minDialogueLines: z.number().int().min(0).max(500).default(12),+ // Flag a MINOR-tier character (per the canon `role` field) who holds more+ // than this fraction of all attributed dialogue — a walk-on dominating the+ // conversation. 1 disables the minor-dominating signal.+ maxMinorShare: z.number().min(0.1).max(1).default(0.35),+ // Flag a MAJOR-tier character (per the canon `role` field) who APPEARS in the+ // prose yet holds less than this fraction of the attributed dialogue — a lead+ // who is oddly silent. 0 disables the silent-major signal.+ minMajorShare: z.number().min(0).max(0.5).default(0.05),// Flag screen-time skew when one gender holds more than this fraction of the// gender-known appearing cast (and 2+ are gender-known). 1 disables it.maxGenderShare: z.number().min(0.1).max(1).default(0.8),@@ -2741,7 +2776,25 @@ export const EDITORIAL_CHECKS = [min: 0,max: 500,step: 1,- help: 'Skip the dialogue-share check until at least this many dialogue lines can be attributed — a few lines is not a meaningful distribution.',+ help: 'Skip the dialogue-share/distribution checks until at least this many dialogue lines can be attributed — a few lines is not a meaningful distribution.',+ },+ {+ key: 'maxMinorShare',+ label: 'Max dialogue share for a minor character',+ type: 'number',+ min: 0.1,+ max: 1,+ step: 0.05,+ help: 'Flag when a character whose canon role reads as minor (background, cameo, walk-on, etc.) holds more than this fraction of all attributed dialogue. 1 disables the minor-dominating signal.',+ },+ {+ key: 'minMajorShare',+ label: 'Min dialogue share for a major character',+ type: 'number',+ min: 0,+ max: 0.5,+ step: 0.01,+ help: 'Flag when a character whose canon role reads as major (protagonist, lead, antagonist, etc.) appears in the prose yet holds less than this fraction of the attributed dialogue — a lead who is oddly silent. 0 disables the silent-major signal.',},{key: 'maxGenderShare',@@ -2767,6 +2820,8 @@ export const EDITORIAL_CHECKS = [const cfg = ctx.config || {};const maxDialogueShare = cfg.maxDialogueShare ?? 0.6;const minDialogueLines = Math.max(1, cfg.minDialogueLines ?? 12);+ const maxMinorShare = cfg.maxMinorShare ?? 0.35;+ const minMajorShare = cfg.minMajorShare ?? 0.05;const maxGenderShare = cfg.maxGenderShare ?? 0.8;const bechdelSignal = cfg.bechdelSignal !== false;@@ -2779,31 +2834,79 @@ export const EDITORIAL_CHECKS = [const flag = ({ severity, location, problem, suggestion, anchorQuote = '', issueNumber = null }) =>findings.push({ severity, category: 'casting', location, problem, suggestion, anchorQuote, issueNumber });- // --- 1) Dialogue share ------------------------------------------------+ // --- 1) Dialogue distribution (share + role-relative outliers) --------// The runner injects the canonical stitched corpus as ctx.manuscript// (needsManuscript) — reuse it rather than re-stitching ctx.sections.+ // One attribution pass feeds three sub-signals: the overall top-speaker+ // share, a MINOR-tier character dominating the conversation, and a MAJOR-tier+ // character who appears yet is oddly silent. Role tier comes only from the+ // canon `role` field (absent/ambiguous → 'unknown', signal opts out).const manuscript = typeof ctx.manuscript === 'string' ? ctx.manuscript : '';- if (maxDialogueShare < 1 && manuscript.trim()) {+ const wantShare = maxDialogueShare < 1;+ const wantMinorDom = maxMinorShare < 1;+ const wantSilentMajor = minMajorShare > 0;+ if ((wantShare || wantMinorDom || wantSilentMajor) && manuscript.trim()) {const owners = identities.filter((id) => id.matcher).map((id) => ({ key: id.key, matcher: id.matcher }));const { byOwner, attributed } = attributeDialogueByOwner(manuscript, owners);if (attributed >= minDialogueLines && byOwner.size >= 2) {- let topKey = null;- let topCount = 0;- for (const [key, count] of byOwner) {- if (count > topCount) { topCount = count; topKey = key; }+ if (wantShare) {+ let topKey = null;+ let topCount = 0;+ for (const [key, count] of byOwner) {+ if (count > topCount) { topCount = count; topKey = key; }+ }+ const share = topCount / attributed;+ if (topKey && share > maxDialogueShare) {+ const pct = Math.round(share * 100);+ // Escalate above the low floor when one voice utterly dominates (≥80%).+ flag({+ severity: escalateSeverity(ctx.severityDefault, share >= 0.8 ? 1 : 0),+ location: 'Series dialogue',+ problem: `"${nameByKey.get(topKey)}" speaks about ${pct}% of the attributed dialogue (${topCount} of ${attributed} lines across ${byOwner.size} speaking characters) — one voice dominating the page can flatten the rest of the cast.`,+ suggestion: `Give other characters more of the conversation, or let scenes play out from a viewpoint where ${nameByKey.get(topKey)} isn't the one talking.`,+ });+ }}- const share = topCount / attributed;- if (topKey && share > maxDialogueShare) {- const pct = Math.round(share * 100);- // Escalate above the low floor when one voice utterly dominates (≥80%).- flag({- severity: escalateSeverity(ctx.severityDefault, share >= 0.8 ? 1 : 0),- location: 'Series dialogue',- problem: `"${nameByKey.get(topKey)}" speaks about ${pct}% of the attributed dialogue (${topCount} of ${attributed} lines across ${byOwner.size} speaking characters) — one voice dominating the page can flatten the rest of the cast.`,- suggestion: `Give other characters more of the conversation, or let scenes play out from a viewpoint where ${nameByKey.get(topKey)} isn't the one talking.`,- });++ // Role-relative distribution. Silent-major is gated on prose appearance+ // (a major who never appears is just absent — a different signal — not+ // "oddly silent"); the appearing set is computed lazily only when needed.+ if (wantMinorDom || wantSilentMajor) {+ const appearingKeys = wantSilentMajor+ ? new Set(+ buildRosterAppearances(ctx)+ .filter((r) => r.appearedInIssues.length > 0)+ .map((r) => normalizeName(r.name))+ )+ : null;+ for (const id of identities) {+ const count = byOwner.get(id.key) || 0;+ const share = count / attributed;+ if (wantMinorDom && id.roleTier === 'minor' && share > maxMinorShare) {+ const pct = Math.round(share * 100);+ flag({+ // A walk-on taking over the conversation is a stronger signal the+ // higher the share climbs — escalate past the low floor at ≥50%.+ severity: escalateSeverity(ctx.severityDefault, share >= 0.5 ? 1 : 0),+ location: 'Series dialogue',+ problem: `"${id.name}" reads as a minor character (canon role) yet speaks about ${pct}% of the attributed dialogue (${count} of ${attributed} lines) — a walk-on dominating the conversation usually means the cast hierarchy on the page doesn't match the bible.`,+ suggestion: `Either give ${id.name} a larger stated role to match the page time, or shift dialogue to the characters the story is actually about.`,+ });+ }+ if (wantSilentMajor && id.roleTier === 'major' && appearingKeys.has(id.key) && share < minMajorShare) {+ const pct = Math.round(share * 100);+ flag({+ // A major who appears but never says a word (0%) is the strongest+ // form — escalate past the low floor for the silent case.+ severity: escalateSeverity(ctx.severityDefault, count === 0 ? 1 : 0),+ location: 'Series dialogue',+ problem: `"${id.name}" reads as a major character (canon role) and appears in the prose, yet speaks only about ${pct}% of the attributed dialogue (${count} of ${attributed} lines) — a lead who is on the page but barely talks can feel like a passenger in their own story.`,+ suggestion: `Give ${id.name} more of the conversation in the scenes they appear in, or reconsider whether the stated major role matches their actual presence.`,+ });+ }+ }}}}diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.jsindex 3019648c3a..8a15be8b35 100644--- a/server/lib/editorial/checkRegistry.test.js+++ b/server/lib/editorial/checkRegistry.test.js@@ -4615,11 +4615,15 @@ describe('cast.representation-balance — deterministic check (#1312)', () => {config,severityDefault: 'low',});- const dialogue = (findings) => findings.find((f) => f.location === 'Series dialogue');+ const dialogue = (findings) => findings.find((f) => /speaking characters\)/.test(f.problem));+ const minorDom = (findings) => findings.find((f) => /reads as a minor character/.test(f.problem));+ const silentMajor = (findings) => findings.find((f) => /reads as a major character/.test(f.problem));const bechdel = (findings) => findings.find((f) => /Bechdel/.test(f.problem));const screenTime = (findings) => findings.find((f) => /strongly skewed cast/.test(f.problem));- // Config that silences the two OTHER signals so a test can isolate one.- const only = (over) => ({ maxDialogueShare: 1, maxGenderShare: 1, bechdelSignal: false, ...over });+ // Config that silences every OTHER signal so a test can isolate one.+ const only = (over) => ({+ maxDialogueShare: 1, maxMinorShare: 1, minMajorShare: 0, maxGenderShare: 1, bechdelSignal: false, ...over,+ });it('declares the expected scope / kind / sources', () => {const c = getCheck(REP);@@ -4661,6 +4665,112 @@ describe('cast.representation-balance — deterministic check (#1312)', () => {expect(dialogue(findings)).toBeUndefined();});+ it('flags a minor-role character who dominates the dialogue (#1594)', () => {+ const canon = {+ characters: [+ { name: 'Aria', role: 'protagonist' },+ { name: 'Bram', role: 'minor background character' },+ ],+ };+ // Bram (a minor) speaks 4 of 5 lines → 80% → minor dominating.+ const content = [+ '"One," said Bram.',+ '"Two," said Bram.',+ '"Three," said Bram.',+ '"Four," said Bram.',+ '"Five," said Aria.',+ ].join('\n');+ const findings = runRep(canon, {+ sections: [sec(1, content)],+ config: only({ maxMinorShare: 0.35, minDialogueLines: 5 }),+ });+ const f = minorDom(findings);+ expect(f).toBeTruthy();+ expect(f.category).toBe('casting');+ expect(f.severity).toBe('medium'); // 80% ≥ 50% → escalated above the low floor+ expect(f.problem).toMatch(/"Bram" reads as a minor character/);+ expect(f.problem).toMatch(/80%/);+ // Aria (protagonist) speaks 20% > the silent-major floor → not silent.+ expect(silentMajor(findings)).toBeUndefined();+ });++ it('flags a major-role character who appears yet is oddly silent (#1594)', () => {+ const canon = {+ characters: [+ { name: 'Aria', role: 'lead' },+ { name: 'Bram' },+ { name: 'Cara' },+ ],+ };+ // Aria appears in the prose but never speaks; Bram + Cara carry all dialogue.+ const content = [+ 'Aria watched from the doorway, saying nothing.',+ '"One," said Bram.',+ '"Two," said Bram.',+ '"Three," said Bram.',+ '"Four," said Bram.',+ '"Five," said Cara.',+ ].join('\n');+ const findings = runRep(canon, {+ sections: [sec(1, content)],+ config: only({ minMajorShare: 0.05, minDialogueLines: 5 }),+ });+ const f = silentMajor(findings);+ expect(f).toBeTruthy();+ expect(f.category).toBe('casting');+ expect(f.severity).toBe('medium'); // 0 lines → escalated above the low floor+ expect(f.problem).toMatch(/"Aria" reads as a major character/);+ });++ it('stays silent on the silent-major signal when the major never appears in the prose (#1594)', () => {+ const canon = {+ characters: [+ { name: 'Aria', role: 'lead' }, // never named in the prose below+ { name: 'Bram' },+ { name: 'Cara' },+ ],+ };+ const content = [+ '"One," said Bram.',+ '"Two," said Bram.',+ '"Three," said Bram.',+ '"Four," said Bram.',+ '"Five," said Cara.',+ ].join('\n');+ const findings = runRep(canon, {+ sections: [sec(1, content)],+ config: only({ minMajorShare: 0.05, minDialogueLines: 5 }),+ });+ expect(silentMajor(findings)).toBeUndefined();+ });++ it('leaves unknown / ambiguous-role characters out of the distribution signals (#1594)', () => {+ const canon = {+ characters: [+ // "minor antagonist" mixes a major AND a minor word → unknown tier → opt out.+ { name: 'Bram', role: 'minor antagonist' },+ { name: 'Aria', role: 'protagonist' },+ { name: 'Cara' }, // no role → unknown+ ],+ };+ // Bram dominates, but his contradictory role means the minor signal opts out.+ const content = [+ '"One," said Bram.',+ '"Two," said Bram.',+ '"Three," said Bram.',+ '"Four," said Bram.',+ '"Five," said Cara.',+ ].join('\n');+ const findings = runRep(canon, {+ sections: [sec(1, content)],+ config: only({ maxMinorShare: 0.35, minMajorShare: 0.05, minDialogueLines: 5 }),+ });+ expect(minorDom(findings)).toBeUndefined();+ // Aria (protagonist) doesn't appear in the prose, so the silent-major signal+ // also stays quiet rather than firing on canon-only presence.+ expect(silentMajor(findings)).toBeUndefined();+ });+it('flags a missing Bechdel co-presence signal when no scene pairs non-male characters', () => {const canon = {characters: [