slop-lint 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +162 -0
  3. package/package.json +50 -0
  4. package/slop-lint.mjs +336 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 eric-sabe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # slop-lint
2
+
3
+ A tiny, zero-dependency linter that flags **AI slop** in prose: the **LLM writing tells** that make text read like a language model wrote it. It **fails on the em-dash** (the one near-decisive AI typographic tell) and **warns** on the words, cliches, and constructions that give it away.
4
+
5
+ One file. No dependencies. No config. Node 18+.
6
+
7
+ ```
8
+ $ npx github:eric-sabe/slop-lint posts/
9
+ posts/launch.md
10
+ 3: ✗ em-dash ×1 We built a tool, and honestly, it changed everything
11
+ 7: ⚠ word "leverage"
12
+ 7: ⚠ "in today's ... world" intro
13
+ 9: ⚠ "it's not X, it's Y" negated contrast
14
+
15
+ 1 em-dash failure(s), 3 warning(s) across 1 file(s).
16
+ FAIL on em-dash; warnings are prompts to review, not bans.
17
+ ```
18
+
19
+ ## Why
20
+
21
+ LLM prose has tells. Some are decisive (the em-dash, used where a human would type a comma or a period), most are soft (focal words like "delve" and "tapestry", marketing verbs like "leverage" and "empower", scene-setting intros, hedge-and-pivot constructions). `slop-lint` separates the two:
22
+
23
+ - **The em-dash is a hard failure** (exit code 1). It is the single most reliable signal and rarely typed by hand.
24
+ - **Everything else is a warning.** These words appear in good human writing too, so the tool flags them for a look and never edits anything. A low false-negative rate matters more than zero false positives.
25
+
26
+ It is deliberately conservative. The goal is a fast review prompt plus a CI gate on the one tell worth gating on, not an automated style police.
27
+
28
+ ## Usage
29
+
30
+ No install, straight from npm:
31
+
32
+ ```bash
33
+ npx slop-lint .
34
+ ```
35
+
36
+ Or as a dev dependency:
37
+
38
+ ```bash
39
+ npm i -D slop-lint
40
+ npx slop-lint .
41
+ ```
42
+
43
+ Or run it straight from GitHub (no npm needed), or copy the single file in:
44
+
45
+ ```bash
46
+ npx github:eric-sabe/slop-lint .
47
+ # or:
48
+ curl -O https://raw.githubusercontent.com/eric-sabe/slop-lint/main/slop-lint.mjs
49
+ node slop-lint.mjs .
50
+ ```
51
+
52
+ ### Examples
53
+
54
+ ```bash
55
+ node slop-lint.mjs # scan the current directory (recursive)
56
+ node slop-lint.mjs README.md docs/ # specific files and/or directories
57
+ node slop-lint.mjs --ext .md,.mdx src # restrict which extensions to walk
58
+ node slop-lint.mjs --ignore drafts . # skip paths containing a substring (repeatable)
59
+ node slop-lint.mjs --fail-on-warn . # strict mode: exit 1 on warnings too
60
+ node slop-lint.mjs --quiet . # only print files that have hits
61
+ git ls-files '*.md' | xargs node slop-lint.mjs # only tracked markdown
62
+ ```
63
+
64
+ ### Options
65
+
66
+ | Flag | Effect |
67
+ |---|---|
68
+ | `--ext .a,.b` | Extensions to walk in directories (default `.md .markdown .mdx .txt`). |
69
+ | `--ignore <substr>` | Skip any path containing this substring. Repeatable. |
70
+ | `--fail-on-warn` | Exit 1 on warnings as well as em-dashes. |
71
+ | `--quiet` | Only print files that have hits. |
72
+ | `--list` | Print the catalogue grouped by source. |
73
+ | `--version` | Print the catalogue version. |
74
+ | `--help` | Usage. |
75
+
76
+ Directories are walked with the extension filter and skip `node_modules .git dist build .next out vendor coverage`. **Files you name explicitly are always linted, regardless of extension.**
77
+
78
+ ### Exit codes
79
+
80
+ - `0` clean (or warnings only, without `--fail-on-warn`).
81
+ - `1` at least one em-dash (or any warning under `--fail-on-warn`).
82
+
83
+ ## In CI (GitHub Actions)
84
+
85
+ ```yaml
86
+ name: prose
87
+ on: [push, pull_request]
88
+ jobs:
89
+ slop-lint:
90
+ runs-on: ubuntu-latest
91
+ steps:
92
+ - uses: actions/checkout@v4
93
+ - uses: actions/setup-node@v4
94
+ with: { node-version: '20' }
95
+ - run: npx github:eric-sabe/slop-lint .
96
+ ```
97
+
98
+ ## Programmatic use
99
+
100
+ The file exports its internals, so you can build on it:
101
+
102
+ ```js
103
+ import { lintText, WORDS, PHRASES } from "slop-lint";
104
+
105
+ const { em, hits } = lintText("In today's fast-paced world we leverage synergy.");
106
+ // em -> number of em-dashes (the failure)
107
+ // hits -> array of formatted report lines (warnings and failures)
108
+ ```
109
+
110
+ ## What it flags
111
+
112
+ - **Em-dash** (U+2014): failure.
113
+ - **~100 focal and marketing words**: delve, intricate, meticulous, pivotal, tapestry, realm, testament, leverage, synergy, robust, seamless, holistic, empower, harness, unleash, landscape, journey, ecosystem, bolster, groundbreaking, renowned, innovative, streamline, actionable, and friends.
114
+ - **~45 phrases and constructions**: "in today's ... world", "plays a crucial role", "it's worth noting that", "let's dive in", "in conclusion", "as an AI language model", "rich cultural heritage", "a diverse array of", "not just X but Y", "it's not X, it's Y", and more.
115
+ - **Double hyphen** used as an em-dash substitute, **smart/curly quotes** (a generator/word-processor tell), and **emoji**.
116
+
117
+ The catalogue draws on corpus studies (the FSU "delve" focal-word analysis, a PubMed 135-term study, Gray's "meticulously commendable") plus published Pangram / Grammarly / practitioner blacklists. Tune `WORDS` and `PHRASES` at the top of `slop-lint.mjs` to taste.
118
+
119
+ ## Keeping the catalogue current
120
+
121
+ Tells are a moving target: each model family brings new ones, and old ones fade as models are trained against them. So the catalogue is **sourced and versioned**, and there are tools to keep it honest.
122
+
123
+ - **Sourced + versioned.** Words live in `WORD_GROUPS`, each carrying a `since` version and a `source`. `slop-lint --list` prints the catalogue with its provenance; `slop-lint --version` prints the catalogue version; [`CHANGELOG.md`](CHANGELOG.md) records what changed and when. To retire a faded tell, delete it and note it in the changelog.
124
+ - **Find new tells by measuring, not guessing.** `--discover` compares word and bigram frequency in model output against a human baseline and ranks the over-represented, not-yet-catalogued tokens. This is how "delve" was found; re-run it against each new model's output.
125
+
126
+ ```bash
127
+ slop-lint --discover --samples corpus/samples --baseline corpus/baseline
128
+ ```
129
+
130
+ Both `--samples` and `--baseline` take a comma-separated list of folders, so a model can be compared against a human baseline (general LLM tells) or against the **pool of other models** on the same prompts (that model's signature, with topic held constant). The model-vs-pool comparison is the more reliable one, because identical prompts hold topic constant; vs-human only works with a large, genre-matched human baseline. A `--min-docs` floor (default 3) requires a candidate to recur across multiple answers, so one-off artifacts are dropped; frontmatter is ignored.
131
+ - **Generate the samples instead of pasting them.** `generate-samples.mjs` sends a fixed, genre-varied prompt set ([`prompts.json`](prompts.json)) to each model in [`models.json`](models.json) and writes `corpus/samples/<model>/`. Every model answers the same prompts, so differences are style, not subject. This is a local task (it needs API keys, which never touch CI); commit the result and the sweep mines it keyless.
132
+
133
+ ```bash
134
+ node generate-samples.mjs --dry-run # what would run, no API calls
135
+ node --env-file-if-exists=.env generate-samples.mjs # generate for every model whose key is set
136
+ ```
137
+
138
+ Set the model versions in `.env` (`XAI_MODEL`, `ANTHROPIC_MODEL`, etc.; copy `.env.example`) and just bump them there when a new model ships - no code or tracked-config edits. See [`corpus/README.md`](corpus/README.md).
139
+ - **Build the human baseline** with `npm run baseline` (`build-baseline.mjs`): pulls modern, permissively-licensed prose across three registers into `corpus/baseline/` - US presidential addresses (public domain, oratory), NIH MedlinePlus health summaries (public domain, plain explainer), and Wikinews (CC BY, journalism). The strongest baseline is a large body of your own trusted contemporary prose; this is a reproducible starter. (Note: vs-human is only as good as the baseline, so cross-model stays the more reliable read.)
140
+ - **Measure typography** with `npm run stats` (`corpus-stats.mjs`): em-dash, smart-quote, semicolon, ellipsis, and bold rates per model - the typographic tells the word-based `--discover` can't see (GPT/Grok emit ~9 curly quotes per 1k words; Claude none). One caveat it surfaced: literary/typeset human prose also em-dashes heavily, so the em-dash is a tell of *plain modern typed text* (posts, email, markdown), which is what slop-lint targets - not of prose in general.
141
+ - **A monthly sweep does this for you.** `.github/workflows/catalogue-refresh.yml` runs `refresh.mjs` on a schedule, with no secrets: it combines corpus discovery with a coverage diff against the public Wikipedia "Signs of AI writing" essay, and files the candidates as a GitHub issue to review.
142
+
143
+ Accepting a candidate means adding it to `WORD_GROUPS` (or `PHRASES`) with a source, noting it in `CHANGELOG.md`, and bumping the version. Keep the conservative bias: a tell earns its place with a source, and fading tells get pruned.
144
+
145
+ ## Releasing (maintainer)
146
+
147
+ Publishing is automated. One-time setup: create an npm **Automation** access token and add it as the repo secret `NPM_TOKEN` (Settings > Secrets and variables > Actions). Then:
148
+
149
+ ```bash
150
+ npm version patch # or minor/major: bumps package.json + creates a git tag
151
+ git push --follow-tags
152
+ ```
153
+
154
+ The `publish` workflow runs the tests and `npm publish` on the new `v*` tag. To publish the current version without a new tag, run the workflow manually (Actions > publish > Run workflow). Catalogue/changelog and GitHub release notes are maintained by hand alongside the bump.
155
+
156
+ ## Contributing
157
+
158
+ Issues and PRs welcome, especially new tells with a source, and false positives worth pruning. Keep it dependency-free and a single file.
159
+
160
+ ## License
161
+
162
+ [MIT](LICENSE).
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "slop-lint",
3
+ "version": "0.8.0",
4
+ "description": "Zero-dependency linter that flags AI 'slop' in prose: fails on the em-dash, warns on LLM tells (words, cliches, constructions).",
5
+ "type": "module",
6
+ "bin": {
7
+ "slop-lint": "./slop-lint.mjs"
8
+ },
9
+ "exports": "./slop-lint.mjs",
10
+ "files": [
11
+ "slop-lint.mjs"
12
+ ],
13
+ "engines": {
14
+ "node": ">=18"
15
+ },
16
+ "scripts": {
17
+ "test": "node --test",
18
+ "lint": "node slop-lint.mjs README.md",
19
+ "discover": "node slop-lint.mjs --discover --samples corpus/samples --baseline corpus/baseline",
20
+ "generate": "node --env-file-if-exists=.env generate-samples.mjs",
21
+ "baseline": "node build-baseline.mjs",
22
+ "stats": "node corpus-stats.mjs",
23
+ "refresh": "node refresh.mjs"
24
+ },
25
+ "keywords": [
26
+ "lint",
27
+ "linter",
28
+ "llm",
29
+ "ai",
30
+ "ai-detection",
31
+ "ai-slop",
32
+ "slop",
33
+ "writing",
34
+ "prose",
35
+ "style",
36
+ "editorial",
37
+ "em-dash",
38
+ "markdown"
39
+ ],
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/eric-sabe/slop-lint.git"
43
+ },
44
+ "bugs": {
45
+ "url": "https://github.com/eric-sabe/slop-lint/issues"
46
+ },
47
+ "homepage": "https://github.com/eric-sabe/slop-lint#readme",
48
+ "license": "MIT",
49
+ "author": "eric-sabe"
50
+ }
package/slop-lint.mjs ADDED
@@ -0,0 +1,336 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * slop-lint - guard prose against LLM tells ("AI slop"). Portable, zero-dependency,
4
+ * single file.
5
+ *
6
+ * Drop this into any project (copy it to scripts/ or tools/) and run it on your
7
+ * text. No install, no config required - only Node 18+.
8
+ *
9
+ * node slop-lint.mjs # scan the current directory (recursive)
10
+ * node slop-lint.mjs README.md docs/ # lint specific files / directories
11
+ * node slop-lint.mjs --ext .md,.mdx src # restrict which extensions to walk
12
+ * node slop-lint.mjs --ignore drafts # skip paths containing a substring (repeatable)
13
+ * node slop-lint.mjs --fail-on-warn . # exit 1 on warnings too (strict CI mode)
14
+ * node slop-lint.mjs --quiet . # only print files that have hits
15
+ * node slop-lint.mjs --version # print the catalogue version
16
+ * node slop-lint.mjs --list # print the catalogue with its sources
17
+ * git ls-files '*.md' | xargs node slop-lint.mjs # lint tracked markdown
18
+ *
19
+ * Tells fade as models train against them and new ones appear with each release, so
20
+ * the catalogue is sourced and versioned (see CHANGELOG.md). Find candidate new tells
21
+ * empirically with --discover (see below).
22
+ *
23
+ * Severity, deliberately conservative (these words also appear in good human
24
+ * writing, so false positives are the main risk and almost everything is a warning):
25
+ * FAIL (exit 1): the em-dash character (U+2014). The one near-decisive typographic tell.
26
+ * WARN: everything else, flagged for a human look, never auto-removed.
27
+ */
28
+
29
+ import { readFileSync, readdirSync, statSync } from "node:fs";
30
+ import { join, sep, extname } from "node:path";
31
+ import { pathToFileURL } from "node:url";
32
+
33
+ export const VERSION = "0.6.0";
34
+
35
+ // Catalogue, grouped by provenance. Each group carries the version it was added in
36
+ // and its source, so the list can be pruned with confidence as tells fade. Edit a
37
+ // group's `words`, record the change in CHANGELOG.md, and bump the version.
38
+ export const WORD_GROUPS = [
39
+ {
40
+ since: "0.1.0",
41
+ source: "FSU 'delve' focal-word study; PubMed 135-term analysis",
42
+ words: [
43
+ "delve", "delves", "delving", "intricate", "intricately", "commendable",
44
+ "meticulous", "meticulously", "underscore", "underscores", "underscoring",
45
+ "pivotal", "paramount", "unwavering", "surpass", "surpasses", "showcase",
46
+ "showcases", "showcasing", "boast", "boasts", "tapestry", "realm", "resonate",
47
+ "resonates", "testament", "profound", "noteworthy", "notable", "versatile",
48
+ "invaluable", "elevate", "foster", "garner",
49
+ ],
50
+ },
51
+ {
52
+ since: "0.1.0",
53
+ source: "Pangram / Grammarly / practitioner marketing-buzzword blacklists",
54
+ words: [
55
+ "leverage", "leveraging", "synergy", "robust", "seamless", "seamlessly",
56
+ "transformative", "scalable", "cutting-edge", "game-changer", "game changer",
57
+ "paradigm", "holistic", "empower", "harness", "unleash", "unlock", "utilize",
58
+ "utilise", "supercharge", "state-of-the-art", "best-in-class", "vibrant",
59
+ "multifaceted", "revolutionize", "ever-evolving", "fast-paced", "comprehensive",
60
+ ],
61
+ },
62
+ {
63
+ since: "0.1.0",
64
+ source: "practitioner blacklists (vague metaphors / meta-discourse nouns)",
65
+ words: [
66
+ "landscape", "journey", "roadmap", "ecosystem", "beacon", "symphony", "myriad",
67
+ "plethora", "facet", "illuminate", "navigate", "navigating",
68
+ ],
69
+ },
70
+ {
71
+ since: "0.1.0",
72
+ source: "practitioner blacklists (booster adverbs / filler transitions)",
73
+ words: [
74
+ "furthermore", "moreover", "additionally", "nonetheless", "nevertheless",
75
+ "undoubtedly", "notably", "strategically",
76
+ ],
77
+ },
78
+ {
79
+ // Reviewed pass from the catalogue-refresh sweep. Common words that flood false
80
+ // positives (crucial, such as, overall, rich, featuring, align with) were rejected.
81
+ since: "0.3.0",
82
+ source: "Wikipedia: Signs of AI writing (Words to watch) + practitioner blacklists",
83
+ words: [
84
+ "bolster", "bolsters", "bolstered", "bolstering", "groundbreaking", "renowned",
85
+ "exemplifies", "encompassing", "enhance", "enhances", "enhancing", "enhanced",
86
+ "innovative", "streamline", "streamlines", "streamlined", "streamlining",
87
+ "actionable", "nestled",
88
+ ],
89
+ },
90
+ {
91
+ // First catalogue add sourced from this repo's own corpus discovery: "incredibly"
92
+ // was heavily over-used by one frontier model (in 7 of 24 answers) vs its peers on
93
+ // identical prompts. A booster adverb in the same family as the 0.1.0 set.
94
+ since: "0.5.0",
95
+ source: "empirical: cross-model corpus discovery (--discover)",
96
+ words: ["incredibly"],
97
+ },
98
+ ];
99
+
100
+ // Flat list for matching (derived from the sourced groups above).
101
+ export const WORDS = WORD_GROUPS.flatMap((g) => g.words);
102
+
103
+ // Phrases / constructions. Sources: corpus studies above plus the Wikipedia
104
+ // "Signs of AI writing" essay and practitioner blacklists. Added in 0.1.0 unless noted.
105
+ export const PHRASES = [
106
+ // intro / scene-setting cliches
107
+ { re: /\bin today'?s (fast[- ]paced )?(world|digital age|digital landscape)\b/i, msg: '"in today\'s ... world" intro' },
108
+ { re: /\bin the (ever[- ]evolving|dynamic) (landscape|world) of\b/i, msg: '"ever-evolving landscape" intro' },
109
+ { re: /\bas the world continues to evolve\b/i, msg: '"as the world continues to evolve"' },
110
+ { re: /\bimagine a world where\b/i, msg: '"imagine a world where"' },
111
+ { re: /\bat its core\b/i, msg: '"at its core"' },
112
+ // expository cliches
113
+ { re: /\bplays? an? (crucial|important|key|vital|pivotal|significant) role\b/i, msg: '"plays a crucial role"' },
114
+ { re: /\bis a testament to\b/i, msg: '"is a testament to"' },
115
+ { re: /\bserves? as a (powerful|valuable|vital) tool\b/i, msg: '"serves as a powerful tool"' },
116
+ { re: /\bcannot be overstated\b/i, msg: '"cannot be overstated"' },
117
+ { re: /\bhas become increasingly (important|popular|common)\b/i, msg: '"has become increasingly ..."' },
118
+ // reader framing
119
+ { re: /\bwhen it comes to\b/i, msg: '"when it comes to"' },
120
+ { re: /\bwhether you'?re (a |an )?.+ or (a |an )?.+/i, msg: '"whether you\'re X or Y" framing' },
121
+ { re: /\bno matter where you are (on|in) your journey\b/i, msg: '"no matter where you are on your journey"' },
122
+ { re: /\bif you'?re looking to\b/i, msg: '"if you\'re looking to"' },
123
+ // vague filler
124
+ { re: /\bat the end of the day\b/i, msg: '"at the end of the day"' },
125
+ { re: /\bfor all intents and purposes\b/i, msg: '"for all intents and purposes"' },
126
+ { re: /\bwith that in mind\b/i, msg: '"with that in mind"' },
127
+ { re: /\bthe fact of the matter is\b/i, msg: '"the fact of the matter is"' },
128
+ { re: /\bin a nutshell\b/i, msg: '"in a nutshell"' },
129
+ { re: /\bneedless to say\b/i, msg: '"needless to say"' },
130
+ { re: /\bthat being said\b/i, msg: '"that being said"' },
131
+ { re: /\bdeep dive\b/i, msg: '"deep dive"' },
132
+ // hedging / throat-clearing
133
+ { re: /\bit'?s (important|worth|essential) (to note|noting|to consider|considering|to recognize) that\b/i, msg: "hedge: \"it's worth noting that ...\"" },
134
+ { re: /\bwhile it is true that\b/i, msg: '"while it is true that"' },
135
+ { re: /\bit could be argued that\b/i, msg: '"it could be argued that"' },
136
+ { re: /\bgenerally speaking\b/i, msg: '"generally speaking"' },
137
+ // meta-structure
138
+ { re: /\bthis (article|post|paper|piece) will (explore|examine|cover|delve into|look at)\b/i, msg: '"this article will explore"' },
139
+ { re: /\blet'?s (take a closer look|dive in|explore|unpack)\b/i, msg: '"let\'s dive in / take a closer look"' },
140
+ { re: /\bhere'?s (the thing|why)\b/i, msg: '"here\'s the thing/why"' },
141
+ // closing tics
142
+ { re: /\b(in conclusion|in summary|to sum up|to wrap up|to conclude)\b/i, msg: "conclusion ritual" },
143
+ { re: /\bthe possibilities are endless\b/i, msg: '"the possibilities are endless"' },
144
+ { re: /\bthe future (is|looks) (bright|promising)\b/i, msg: '"the future is bright"' },
145
+ { re: /\bonly time will tell\b/i, msg: '"only time will tell"' },
146
+ { re: /\bthe journey (is just beginning|doesn'?t end here)\b/i, msg: '"the journey is just beginning"' },
147
+ // syntactic constructions
148
+ { re: /\bnot (just|only)\b[^.?!]{0,60}\b(but|it'?s|they'?re|its)\b/i, msg: '"not just X, but Y"' },
149
+ { re: /\b(it'?s|we'?re|they'?re)\s+(not|never)(\s+just)?\b[^.?!]{1,80}?\b(it'?s|we'?re|they'?re)\b/i, msg: '"it\'s not X, it\'s Y" negated contrast' },
150
+ // added 0.3.0 — Wikipedia: Signs of AI writing (assistant leakage + high-signal cliches)
151
+ { re: /\bas an? (ai|large) language model\b/i, msg: '"as an AI/large language model" (assistant leakage)' },
152
+ { re: /\bi hope this helps\b/i, msg: '"I hope this helps" (assistant sign-off)' },
153
+ { re: /\bin the heart of\b/i, msg: '"in the heart of"' },
154
+ { re: /\ba diverse array of\b/i, msg: '"a diverse array of"' },
155
+ { re: /\bvaluable insights\b/i, msg: '"valuable insights"' },
156
+ { re: /\b(stands|serves) as a testament\b/i, msg: '"stands/serves as a testament"' },
157
+ { re: /\bsetting the stage for\b/i, msg: '"setting the stage for"' },
158
+ { re: /\bindelible mark\b/i, msg: '"indelible mark"' },
159
+ { re: /\bdeeply rooted in\b/i, msg: '"deeply rooted in"' },
160
+ { re: /\brich (cultural )?(tapestry|heritage)\b/i, msg: '"rich cultural heritage/tapestry"' },
161
+ ];
162
+
163
+ export const EMOJI = /[\u{1F300}-\u{1FAFF}\u{2600}-\u{27BF}\u{2190}-\u{21FF}\u{2B00}-\u{2BFF}]/u;
164
+ const DOUBLEDASH = /(^|\s)--(\s|$)|\w--\w/; // em-dash approximation
165
+ const SMARTQUOTE = /[“”‘’]/; // curly quotes/apostrophes: a generator/word-processor tell in plaintext or markdown
166
+ const reWord = (w) => new RegExp(`\\b${w.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`, "i");
167
+
168
+ const DEFAULT_EXTS = [".md", ".markdown", ".mdx", ".txt"];
169
+ const IGNORE_DIRS = new Set(["node_modules", ".git", "dist", "build", ".next", "out", "vendor", "coverage"]);
170
+
171
+ // Lint one document. Returns { em, hits } where em is the em-dash count (the only
172
+ // failure) and hits are preformatted " <line>: <symbol> ..." report lines.
173
+ export function lintText(text) {
174
+ let em = 0;
175
+ const hits = [];
176
+ text.split("\n").forEach((line, i) => {
177
+ const n = i + 1;
178
+ const dash = (line.match(/—/g) || []).length;
179
+ if (dash) { em += dash; hits.push(` ${n}: ✗ em-dash ×${dash} ${line.trim().slice(0, 64)}`); }
180
+ if (DOUBLEDASH.test(line)) hits.push(` ${n}: ⚠ "--" (em-dash approximation)`);
181
+ for (const w of WORDS) if (reWord(w).test(line)) hits.push(` ${n}: ⚠ word "${w}"`);
182
+ for (const p of PHRASES) if (p.re.test(line)) hits.push(` ${n}: ⚠ ${p.msg}`);
183
+ if (SMARTQUOTE.test(line)) hits.push(` ${n}: ⚠ smart/curly quote`);
184
+ if (EMOJI.test(line)) hits.push(` ${n}: ⚠ emoji`);
185
+ });
186
+ return { em, hits };
187
+ }
188
+
189
+ // Expand paths to a file list. Explicit files are always included; directories are
190
+ // walked with the extension filter, skipping IGNORE_DIRS + any `ignore` substring.
191
+ export function walkFiles(paths, { exts = DEFAULT_EXTS, ignore = [] } = {}) {
192
+ const skip = (p) => p.split(sep).some((s) => IGNORE_DIRS.has(s)) || ignore.some((s) => p.includes(s));
193
+ const out = [];
194
+ const walk = (d) => {
195
+ let entries; try { entries = readdirSync(d); } catch { return; }
196
+ for (const e of entries) {
197
+ const p = join(d, e);
198
+ if (skip(p)) continue;
199
+ let st; try { st = statSync(p); } catch { continue; }
200
+ if (st.isDirectory()) walk(p);
201
+ else if (exts.includes(extname(p).toLowerCase())) out.push(p);
202
+ }
203
+ };
204
+ for (const p of paths) {
205
+ let st; try { st = statSync(p); } catch { continue; }
206
+ if (st.isDirectory()) walk(p);
207
+ else out.push(p); // explicit file -> lint regardless of extension
208
+ }
209
+ return [...new Set(out)];
210
+ }
211
+
212
+ // ── Discover: find candidate NEW tells empirically ────────────────────────────
213
+ // Compare word/bigram frequency in model-output samples against a human baseline.
214
+ // Tokens that are massively over-represented in the samples, and not already in the
215
+ // catalogue, are ranked as candidates for human review. This is how the original
216
+ // "delve" tell was found, and it re-runs against each new model's output.
217
+ const STOP = new Set((
218
+ "the a an and or but of to in on at for with as is are was were be been being by " +
219
+ "this that these those it its it's i you he she we they them his her their our your " +
220
+ "not no nor so if then than too very can will just also from into over under about " +
221
+ "out up down off here there what which who whom when where why how all any both each " +
222
+ "more most other some such only own same has have had do does did"
223
+ ).split(" "));
224
+
225
+ function tokenize(text) {
226
+ return (text.toLowerCase().match(/[a-z][a-z'’-]{2,}/g) || []).filter((w) => !STOP.has(w));
227
+ }
228
+ // Per-text frequency + document frequency (how many texts a token appears in). Doc
229
+ // frequency lets us drop one-off artifacts (an invented product name repeated within a
230
+ // single answer) and keep tokens that recur across many answers - the real style tells.
231
+ function freqMap(texts, { bigrams = true } = {}) {
232
+ const counts = new Map(), docs = new Map(); let total = 0;
233
+ for (const t of texts) {
234
+ const toks = tokenize(t);
235
+ const seen = new Set();
236
+ for (let i = 0; i < toks.length; i++) {
237
+ counts.set(toks[i], (counts.get(toks[i]) || 0) + 1); total++; seen.add(toks[i]);
238
+ if (bigrams && i + 1 < toks.length) {
239
+ const bg = `${toks[i]} ${toks[i + 1]}`;
240
+ counts.set(bg, (counts.get(bg) || 0) + 1); seen.add(bg);
241
+ }
242
+ }
243
+ for (const tok of seen) docs.set(tok, (docs.get(tok) || 0) + 1);
244
+ }
245
+ return { counts, total: total || 1, docs };
246
+ }
247
+ export function discover(sampleTexts, baselineTexts, { top = 30, minCount = 3, minDocs = 3 } = {}) {
248
+ const S = freqMap(sampleTexts), B = freqMap(baselineTexts);
249
+ const known = new Set(WORDS.map((w) => w.toLowerCase()));
250
+ const smoothing = 1 / (B.total * 10);
251
+ const effMinDocs = Math.min(minDocs, sampleTexts.length); // small corpora still return something
252
+ const out = [];
253
+ for (const [tok, c] of S.counts) {
254
+ if (c < minCount || (S.docs.get(tok) || 0) < effMinDocs || known.has(tok)) continue;
255
+ const sf = c / S.total;
256
+ const bf = (B.counts.get(tok) || 0) / B.total;
257
+ out.push({ token: tok, count: c, docs: S.docs.get(tok), sampleFreq: sf, baselineFreq: bf, ratio: sf / (bf + smoothing) });
258
+ }
259
+ out.sort((a, b) => b.ratio - a.ratio || b.count - a.count);
260
+ return out.slice(0, top);
261
+ }
262
+
263
+ const stripFrontmatter = (t) => t.replace(/^?---\r?\n[\s\S]*?\r?\n---\r?\n/, "");
264
+ function readAll(paths) {
265
+ return walkFiles(paths, { exts: [".md", ".markdown", ".mdx", ".txt"] })
266
+ .map((f) => { try { return stripFrontmatter(readFileSync(f, "utf8")); } catch { return ""; } });
267
+ }
268
+
269
+ function runDiscover(argv) {
270
+ const get = (flag) => { const i = argv.indexOf(flag); return i >= 0 ? argv[i + 1] : null; };
271
+ const samples = get("--samples"), baseline = get("--baseline");
272
+ const json = argv.includes("--json");
273
+ const top = Number(get("--top")) || 30;
274
+ const minDocs = Number(get("--min-docs")) || 3;
275
+ if (!samples || !baseline) {
276
+ console.error("discover: need --samples <dir> and --baseline <dir>.\n" +
277
+ " node slop-lint.mjs --discover --samples corpus/samples --baseline corpus/baseline");
278
+ return 2;
279
+ }
280
+ // both accept a comma-separated list of dirs/files, so a model can be compared against
281
+ // a human baseline or against the pool of other models (topic held constant).
282
+ const sTexts = readAll(samples.split(",")), bTexts = readAll(baseline.split(","));
283
+ if (!sTexts.length || !bTexts.length) { console.error("discover: empty samples or baseline corpus."); return 2; }
284
+ const cands = discover(sTexts, bTexts, { top, minDocs });
285
+ if (json) { console.log(JSON.stringify({ version: VERSION, candidates: cands }, null, 2)); return 0; }
286
+ console.log("Candidate tells (over-represented in samples vs baseline, not yet in the catalogue):\n");
287
+ console.log(" ratio count docs token");
288
+ for (const c of cands) console.log(` ${c.ratio.toFixed(1).padStart(6)} ${String(c.count).padStart(5)} ${String(c.docs).padStart(4)} ${c.token}`);
289
+ console.log(`\n${cands.length} candidate(s). Review, then add the real tells to WORD_GROUPS (with a source) and CHANGELOG.md.`);
290
+ return 0;
291
+ }
292
+
293
+ function main(argv) {
294
+ if (argv.includes("--version") || argv.includes("-v")) { console.log(VERSION); return 0; }
295
+ if (argv.includes("--discover")) return runDiscover(argv);
296
+ if (argv.includes("--list")) {
297
+ for (const g of WORD_GROUPS) console.log(`\n# ${g.source} (since ${g.since})\n${g.words.join(", ")}`);
298
+ console.log(`\n# phrases: ${PHRASES.length} patterns. Catalogue version ${VERSION}.`);
299
+ return 0;
300
+ }
301
+ const paths = [];
302
+ let exts = DEFAULT_EXTS, ignore = [], failOnWarn = false, quiet = false;
303
+ for (let i = 0; i < argv.length; i++) {
304
+ const a = argv[i];
305
+ if (a === "--help" || a === "-h") {
306
+ console.log("slop-lint - flag LLM tells in prose. FAIL on em-dash, WARN on the rest.\n" +
307
+ " node slop-lint.mjs [paths...] [--ext .md,.txt] [--ignore <substr>]... [--fail-on-warn] [--quiet]\n" +
308
+ " node slop-lint.mjs --discover --samples <dir> --baseline <dir> [--top N] [--json]\n" +
309
+ " --version --list (no paths: scans the current directory recursively)");
310
+ return 0;
311
+ }
312
+ if (a === "--ext") { exts = argv[++i].split(",").map((e) => (e.startsWith(".") ? e : `.${e}`).toLowerCase()); continue; }
313
+ if (a === "--ignore") { ignore.push(argv[++i]); continue; }
314
+ if (a === "--fail-on-warn") { failOnWarn = true; continue; }
315
+ if (a === "--quiet") { quiet = true; continue; }
316
+ paths.push(a);
317
+ }
318
+ const files = walkFiles(paths.length ? paths : ["."], { exts, ignore });
319
+ if (!files.length) { console.log("slop-lint: no files found."); return 0; }
320
+
321
+ let emTotal = 0, warnTotal = 0;
322
+ for (const file of files) {
323
+ let text; try { text = readFileSync(file, "utf8"); } catch (e) { console.log(`skip ${file}: ${e.message}`); continue; }
324
+ const { em, hits } = lintText(text);
325
+ emTotal += em; warnTotal += hits.filter((h) => h.includes("⚠")).length;
326
+ if (hits.length || !quiet) console.log(`\n${file}\n${hits.length ? hits.join("\n") : " clean ✓"}`);
327
+ }
328
+ console.log(`\n${emTotal} em-dash failure(s), ${warnTotal} warning(s) across ${files.length} file(s).`);
329
+ console.log("FAIL on em-dash; warnings are prompts to review, not bans.");
330
+ return emTotal || (failOnWarn && warnTotal) ? 1 : 0;
331
+ }
332
+
333
+ // Run as a CLI when invoked directly; stay importable when required elsewhere.
334
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
335
+ process.exit(main(process.argv.slice(2)));
336
+ }