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): require a minimum raw-occurrence floor before rate/density thresholds fire

Adam Eivy99f98dcb3190
diff --git a/server/lib/editorial/checkInfra.js b/server/lib/editorial/checkInfra.js
index 4e083105cd..8366804480 100644
--- a/server/lib/editorial/checkInfra.js
+++ b/server/lib/editorial/checkInfra.js
@@ -49,6 +49,7 @@ import {
transitionOpenerRatio,
paragraphLengthUniformity,
countSectionBreaks,
+ MIN_DENSITY_OCCURRENCES,
} from './slopScore.js';
import {
analyzePanelRhythm,
@@ -60,6 +61,7 @@ import { findAxisReversals, findShotTypeMonotony, summarizeStoryboardShots } fro
// Re-exported so ./checks/*.js and ./checkRegistry.js import everything from here.
export {
DEFAULT_LETTERING_THRESHOLDS,
+ MIN_DENSITY_OCCURRENCES,
analyzeBalloonAttribution,
analyzeComicLettering,
analyzeNamePair,
diff --git a/server/lib/editorial/checks/slop.js b/server/lib/editorial/checks/slop.js
index 73f3eaf453..8d942de006 100644
--- a/server/lib/editorial/checks/slop.js
+++ b/server/lib/editorial/checks/slop.js
@@ -4,6 +4,7 @@
// module's doc comment for how it EXTENDS (rather than duplicates) the
// existing proseTics.js / cliches.js / repetition.js anti-slop primitives.
import {
+ MIN_DENSITY_OCCURRENCES,
countSectionBreaks,
countWords,
emDashDensityPer1000,
@@ -267,7 +268,7 @@ export const slopChecks = [
const { number, location } = sectionIssue(s);
const emDash = emDashDensityPer1000(text);
- if (findings.length < max && emDash.count > 0 && emDash.rate >= emDashThreshold) {
+ if (findings.length < max && emDash.count >= MIN_DENSITY_OCCURRENCES && emDash.rate >= emDashThreshold) {
findings.push({
severity: ctx.severityDefault,
category: 'style',
diff --git a/server/lib/editorial/slopScore.js b/server/lib/editorial/slopScore.js
index ac8f6f3eea..6eb3fda8df 100644
--- a/server/lib/editorial/slopScore.js
+++ b/server/lib/editorial/slopScore.js
@@ -269,6 +269,16 @@ export function findAiTells(text, opts = {}) {
// prose independent of vocabulary choice.
// ---------------------------------------------------------------------------
+// Shared raw-occurrence floor for rate/density gates below (negative-assertion
+// density here, em-dash density further down, and re-used by the registered
+// `prose.burstiness` check's own em-dash finding in checks/slop.js). A pure
+// rate check with no minimum count reads a SINGLE ordinary occurrence in a
+// short section as "dense" purely because the section is short enough to push
+// the rate over threshold (e.g. 1 em dash in 65 words = 15.4/1000, over the 15
+// default) — caught in review. Requiring at least 2 raw hits before applying
+// the rate threshold keeps a lone, unremarkable occurrence from ever qualifying.
+export const MIN_DENSITY_OCCURRENCES = 2;
+
const NOT_JUST_BUT_RE = /\bnot\s+(?:just|only)\b[^.!?\n]{1,100}?\bbut\b(?:\s+also)?[^.!?\n]{1,100}?[.!?]/gi;
// [''] accepts both the straight apostrophe and the curly one word processors
// (Word/Scrivener/Google Docs) auto-substitute — manuscript text is not
@@ -393,9 +403,13 @@ export function findTriadicShortSentences(text, opts = {}) {
/**
* Combined structural-tic scan — merges the four per-pattern detectors above,
- * plus a density-gated negative-assertion entry (only included when the
- * `did not [verb]` rate crosses `negativeAssertionDensityPer1000`, since that
- * signal is a rate, not a per-hit tic). Position-ordered.
+ * plus a density-gated negative-assertion entry (only included when there are
+ * at least `MIN_DENSITY_OCCURRENCES` raw hits AND the `did not [verb]` rate
+ * crosses `negativeAssertionDensityPer1000` — the raw-count floor keeps a
+ * single ordinary negation in a short section from reading as a "dense run"
+ * just because the section is short enough to push its rate over the
+ * threshold; that signal is a rate ACROSS repetition, not a per-hit tic).
+ * Position-ordered.
* @param {string} text
* @param {{ maxWords?: number, minRun?: number, negativeAssertionDensityPer1000?: number }} [opts]
* @returns {Array<{ type: string, index: number, anchor: string, count?: number, density?: number }>}
@@ -409,7 +423,7 @@ export function findStructuralTics(text, opts = {}) {
...findTriadicShortSentences(text, opts).map((h) => ({ type: 'triadic-short-sentences', ...h })),
];
const negAssertions = findNegativeAssertions(text);
- if (negAssertions.length) {
+ if (negAssertions.length >= MIN_DENSITY_OCCURRENCES) {
const words = tokenizeWords(text).length;
const density = words > 0 ? (negAssertions.length / words) * 1000 : 0;
const threshold = typeof opts.negativeAssertionDensityPer1000 === 'number'
@@ -590,7 +604,7 @@ export function computeSlopPenalty(text, opts = {}) {
penalty += Math.min(findStructuralTics(text, opts).length * w.structuralTicPerHit, w.structuralTicCap);
const emDash = emDashDensityPer1000(text);
- if (emDash.rate >= w.emDashThresholdPer1000) penalty += w.emDashPenalty;
+ if (emDash.count >= MIN_DENSITY_OCCURRENCES && emDash.rate >= w.emDashThresholdPer1000) penalty += w.emDashPenalty;
const rhythm = measureSentenceRhythm(text);
if (rhythm && rhythm.cv < w.lowSentenceCvThreshold) penalty += w.lowSentenceCvPenalty;
diff --git a/server/lib/editorial/slopScore.test.js b/server/lib/editorial/slopScore.test.js
index 7f13f14fc3..f1a59ce74b 100644
--- a/server/lib/editorial/slopScore.test.js
+++ b/server/lib/editorial/slopScore.test.js
@@ -20,6 +20,7 @@ import {
paragraphLengthUniformity,
countSectionBreaks,
computeSlopPenalty,
+ MIN_DENSITY_OCCURRENCES,
} from './slopScore.js';
describe('findBannedWordsTier1', () => {
@@ -266,6 +267,15 @@ describe('findStructuralTics', () => {
it('returns an empty array for clean prose', () => {
expect(findStructuralTics('She opened the door and stepped inside, unsure of what she would find.')).toHaveLength(0);
});
+
+ it('does NOT flag a single negative assertion in a short section, even if its rate crosses the threshold (regression)', () => {
+ // 1 hit in ~204 words -> 4.9/1000, over the 4/1000 default threshold on
+ // rate alone — but a single ordinary negation is not a "dense run".
+ // Caught in codex review; MIN_DENSITY_OCCURRENCES gates this.
+ const text = `She did not flinch. ${'word '.repeat(200)}`;
+ const tics = findStructuralTics(text);
+ expect(tics.find((t) => t.type === 'negative-assertion-density')).toBeUndefined();
+ });
});
describe('emDashDensityPer1000', () => {
@@ -371,6 +381,15 @@ describe('computeSlopPenalty', () => {
expect(penalty).toBeLessThanOrEqual(SLOP_PENALTY_WEIGHTS.tier1Cap + 0.01);
});
+ it('does NOT add the em-dash penalty for a single dash in a short passage, even though its rate crosses the threshold (regression)', () => {
+ // 1 em dash in 65 words -> 15.4/1000, over the 15/1000 default threshold
+ // on rate alone — but one ordinary em dash is not "heavy reliance".
+ // Caught in codex review; MIN_DENSITY_OCCURRENCES gates this.
+ const text = `one two three — ${'word '.repeat(62)}`;
+ expect(MIN_DENSITY_OCCURRENCES).toBeGreaterThan(1);
+ expect(computeSlopPenalty(text)).toBeLessThan(SLOP_PENALTY_WEIGHTS.emDashPenalty);
+ });
+
it('adds the section-break penalty for an over-fragmented rate of scene breaks', () => {
// 40 words total (two 20-word paragraphs), 1 section-break line -> 25/1000
// words, far above the default 8/1000 threshold. Regression test: