@heyramzi/lint 2.5.0 → 2.6.1

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.
package/jev.js CHANGED
@@ -1,6 +1,9 @@
1
1
  /**
2
- * The judgement half of the humanizer patterns, asked of TypeSafe Jev per sentence
3
- * and per paragraph, on any TypeSafe-compatible endpoint. Bench: scripts/jev-bench.mjs. Why these shapes: TECHLOG.md.
2
+ * Jev from Node: endpoint, key and disk cache around jev-core.js, which holds the questions.
3
+ */
4
+
5
+ /*
6
+ * Any TypeSafe-compatible endpoint, or Cloudflare Workers AI. Why these shapes: TECHLOG.md.
4
7
  */
5
8
 
6
9
  import { execFileSync } from "node:child_process";
@@ -8,157 +11,24 @@ import { createHash } from "node:crypto";
8
11
  import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
9
12
  import { homedir } from "node:os";
10
13
  import { join } from "node:path";
14
+ import {
15
+ FAIL,
16
+ auditShapesWith,
17
+ jevPost,
18
+ jevRoute,
19
+ judgeWith,
20
+ unavailable,
21
+ } from "#lint/jev-core.js";
11
22
 
12
23
  // =========================
13
24
  // CONSTANTS
14
25
  // =========================
15
- /** One request that hangs must not hang a draft: past this it counts as unreachable. */
16
- const TIMEOUT_MS = 30_000;
17
- /** The gateway's moving latest, never a version, so each Jev release reaches the gate (TECHLOG.md). */
18
- export const MODEL = "typesafe-ai/jev";
19
26
  export const JEV_OFF =
20
27
  "Jev is off: set JEV_BASE_URL and JEV_API_KEY (env, or Proton Pass, Dev vault, item AI endpoints)";
21
- export const FAIL = 0.75;
22
- export const REVIEW = 0.6;
23
- /** Scores drift about 0.05 between identical calls, so each item is asked RUNS times and its worst score counts. */
24
- const RUNS = 3;
25
- /** Items per request: 4 sentences x 9 shapes answered in about 1s. */
26
- const BATCH = 4;
27
- const CONCURRENCY = 8;
28
-
29
- /** One question per root cause, not per pattern: humanizer references/patterns.md maps each pattern to one. */
30
- export const q = (instructions, yes, no) => ({
31
- type: "noul",
32
- instructions,
33
- criteria: { true: yes, false: no },
34
- });
35
- const PLAIN =
36
- "A plain, literal sentence: a step the reader takes, a named thing, a number, or a fact that carries its own meaning.";
37
-
38
- /** Asked of every sentence, with its paragraph as `context`. */
39
- export const SHAPES = {
40
- inflated: q(
41
- "Does `sentence` tell the reader that something matters, impresses or feels a certain way, instead of giving the fact, number or mechanism that would show it, or is it generic enough to move unchanged to another company, product or person?",
42
- "Praise, significance, emotion or quality asserted, not shown, or a line with nothing only this subject could say.",
43
- `${PLAIN} Or a letter's courtesy to its reader: a thanks, a greeting, an invitation.`,
44
- ),
45
- aphorism: q(
46
- "Is `sentence` a slogan or maxim: a quotable general truth stated in abstract terms instead of a concrete step, number or fact?",
47
- "Could be printed on a poster, often a flip or an 'only', and the next sentence has to explain it.",
48
- PLAIN,
49
- ),
50
- law: q(
51
- "Does `sentence` describe how a tool, setting or system behaves as a general rule, with the thing as the subject and no person acting, where it could tell the reader what to do and what they will see?",
52
- "The subject is an object or an idea, the verb is a state or a spread, and the reader has no step to copy. Often it ends on 'it' or 'them'.",
53
- "A person does something, a literal step (where to click, what appears), a measured result of what happened, with its number, or a plain fact or rule about one specific thing said the way a person would ('the back door doesn't lock', 'a cancelled ticket is never refunded').",
54
- ),
55
- vague: q(
56
- "Does `sentence` point at content instead of stating it: it announces, promises, sets up or labels a point that the sentence itself does not give?",
57
- "A teaser, signpost or label: the reader learns that there is a reason, a tip, a rule or a next step, but not what it is.",
58
- "The sentence gives the content itself, the paragraph gives it right after, or it starts with 'Link:' and names what the reader does when they click.",
59
- ),
60
- hedge: q(
61
- "Does `sentence` pad itself with a hedge, a reassurance, a propping adverb (really, basically, actually), an unnamed source, or a line about the conversation instead of the subject?",
62
- "It contains padding of that kind, or talks about the writing instead of the subject.",
63
- "No hedge, prop or talk about the conversation. A thanks, a greeting or a question to the reader is not padding.",
64
- ),
65
- filler: q(
66
- "Can one word or phrase in `sentence` be deleted, or swapped for a shorter one, and the sentence still say exactly the same thing?",
67
- "At least one word can go or shrink ('in order to', 'each and every', a word the rest already implies) with no loss of meaning.",
68
- "Every word carries meaning the sentence would lose. Warmth to the reader in a letter counts as meaning.",
69
- ),
70
- contrast: q(
71
- "Does `sentence` stage a contrast to make its point: 'not X, it's Y' denying a claim nobody made, an either-or where one side is a strawman, a 'from X to Y' span with no real range, or one claim said twice in other words?",
72
- "The denied half, the strawman side, the span or the repeat is there for effect. Delete it and the point stands alone.",
73
- "A real comparison between two named options, or a single plain claim.",
74
- ),
75
- stilted: q(
76
- "Does `sentence` sound awkward or unnatural, like a clumsy translation or a forced rewrite, so a native English speaker would phrase it differently or need to reread it?",
77
- "Awkward phrasing: a person made the subject of find, meet or get where people would say 'there is' or 'X has'; an odd verb; an unexplained code or label; a clumsy word order.",
78
- "Natural, clear English a person would say out loud.",
79
- ),
80
- pitch: q(
81
- "Is `sentence` an ad line that promises an effortless result: a dramatic command plus an outcome said to be already true, or a lone word used as a verdict, instead of saying what happens when the reader takes an action?",
82
- "Reads like a tagline: 'Do X, and Y is already done', or a one-word fragment as the punchline.",
83
- `${PLAIN} Or a literal step with what happens next, in the product's own terms.`,
84
- ),
85
- personified: q(
86
- "Does `sentence` use a figure where a literal word exists: a non-human thing doing what only a person does, or an abstract idea dressed as a physical object?",
87
- "A tool that knows, wants, saves or gives; an idea that is a lever, a ceiling, a moat or a muscle.",
88
- "The thing does something mechanical and literal, or a person does the acting.",
89
- ),
90
- thingdoer: q(
91
- "Does `sentence` make a tool, automation, checklist, script or system the grammatical subject of what a person sets up or does, where a person as the subject ('we', 'you', or an imperative) would be plainer?",
92
- "A noun leads and acts: 'An automation creates it and assigns it', 'A checklist catches this', 'The script only posts what is approved'. It reads like a description of a machine, with nobody behind it. Ramzi, 30 Sep 2026.",
93
- "A person is the subject or the sentence is an instruction ('Have an automation create it'), or the thing genuinely is the subject of a literal fact ('The API returns JSON').",
94
- ),
95
- stagey: q(
96
- "Does `sentence` describe an action or a rule as a small scene where a plain verb and object would do: 'waits for someone to say go' for 'needs your approval', 'gets you most of the way' for 'covers most of it', 'does its sweep' for 'runs'?",
97
- "A phrase that acts out the idea (waits, says go, gets you there, takes the wheel) when one plain verb says the same thing. Ramzi, 30 Sep 2026: 'Claude Code on a timer requires you' is simpler and means the same.",
98
- "The sentence already uses the plain verb and object a person would say out loud.",
99
- ),
100
- };
101
-
102
- /** Asked once per paragraph of 3 or more sentences: the shapes no single sentence shows. */
103
- export const PARAGRAPH_SHAPES = {
104
- rhythm: q(
105
- "Does `paragraph` repeat one structure instead of varying it: sentences of one length or one opening, items forced into threes, a punchy closer on every beat, a word reused where no new idea arrived, or a transition that asserts a link the facts do not show?",
106
- "A reader could predict the shape of the next sentence before reading it.",
107
- "Sentence lengths and openings vary with the thought, and each link between sentences is shown by what they say.",
108
- ),
109
- };
110
28
 
111
29
  // =========================
112
- // FUNCTIONS
30
+ // ENDPOINT
113
31
  // =========================
114
- /** Short unpunctuated lines are glance copy (subjects, headlines); Ramzi, 23 Sep 2026, on a subject Jev never saw. */
115
- const GLANCE = /^[^\n]{1,60}$/;
116
-
117
- /** Prose sentences with their paragraph, plus glance lines of 4+ words as their own item. */
118
- export function sentences(text) {
119
- return text.split(/\n\s*\n|\n(?=\s*[-*]\s)/).flatMap((para) => {
120
- const lines = para
121
- .split("\n")
122
- .map((l) => l.replace(/^\s*(?:#+|[-*])\s*/, "").trim())
123
- .filter(Boolean);
124
- if (lines.every((l) => GLANCE.test(l)) && lines.some((l) => !/[.!?]["')\]]*$/.test(l))) {
125
- return lines
126
- .filter((l) => l.split(" ").length >= 4)
127
- .map((l) => ({ sentence: l, context: l }));
128
- }
129
- // An unpunctuated line is a heading: end it, so it isn't glued to the next sentence.
130
- const flat = para.replace(/\s+/g, " ").trim();
131
- const ended = lines.map((l) => (/[.!?:]["')\]]*$/.test(l) ? l : `${l}.`)).join(" ");
132
- // A stop only ends a sentence before a space, so "1.5" stays whole.
133
- return (ended.match(/.+?[.!?]+["')\]]*(?=\s|$)/g) ?? [])
134
- .map((s) => s.trim())
135
- .filter((s) => s.split(" ").length >= 3)
136
- .map((sentence) => ({ sentence, context: flat }));
137
- });
138
- }
139
-
140
- /** Markup as Jev reads it: a block ends a paragraph, and link text says it's a link. */
141
- export function proseOf(html) {
142
- return html
143
- .replace(/<(script|style)[\s\S]*?<\/\1>|<!--[\s\S]*?-->/gi, " ")
144
- .replace(/<a\b[^>]*>([\s\S]*?)<\/a>/gi, "\n\nLink: $1\n\n")
145
- .replace(/<\/(p|li|h[1-6]|div|td|blockquote)>|<br\s*\/?>/gi, "\n\n")
146
- .replace(/<[^>]+>/g, " ")
147
- .replace(/&rarr;|&[a-z]+;|&#\d+;/gi, " ")
148
- .replace(/[ \t]+/g, " ")
149
- .replace(/\n\s*\n\s*/g, "\n\n")
150
- .trim();
151
- }
152
-
153
- /** Paragraphs long enough to have a rhythm: 3 sentences or more. */
154
- export function paragraphs(text) {
155
- return text
156
- .split(/\n\s*\n/)
157
- .map((para) => para.replace(/\s+/g, " ").trim())
158
- .filter((para) => (para.match(/[.!?]+["')\]]*(?=\s|$)/g) ?? []).length >= 3)
159
- .map((paragraph) => ({ paragraph }));
160
- }
161
-
162
32
  let passed;
163
33
  /** The fields of the `AI endpoints` item (Proton Pass, Dev vault), read once and only when the env lacks one. */
164
34
  function passFields() {
@@ -188,78 +58,15 @@ const jevValue = (name) => process.env[name]?.trim() || passFields()[name]?.trim
188
58
  /** `JEV_API_KEY` from the env, else Proton Pass. Blank turns the model check off. */
189
59
  export const jevKey = () => jevValue("JEV_API_KEY");
190
60
 
191
- /** The model check could not run: network, key, credits, timeout or a bad answer. Callers skip it, not crash. */
192
- function unavailable(message) {
193
- return Object.assign(new Error(message), { name: "JevUnavailable" });
194
- }
195
-
196
- export const isUnavailable = (err) => err instanceof Error && err.name === "JevUnavailable";
197
-
198
- /** TypeSafe's route under `JEV_BASE_URL`, so a test points it at a local server or an unresolvable host. */
199
- function endpoint() {
200
- const base = jevValue("JEV_BASE_URL");
201
- if (!base) throw unavailable(JEV_OFF);
202
- return `${base.replace(/\/+$/, "")}/v1/systemone`;
203
- }
204
-
205
- function why(err) {
206
- if (err?.name === "TimeoutError") return `timed out after ${TIMEOUT_MS / 1000}s`;
207
- return err?.cause?.code ?? err?.cause?.message ?? err?.message ?? String(err);
208
- }
209
-
210
- async function post(body, key, attempt = 0) {
211
- const url = endpoint();
212
- let res;
213
- try {
214
- res = await fetch(url, {
215
- method: "POST",
216
- headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
217
- body: JSON.stringify(body),
218
- signal: AbortSignal.timeout(TIMEOUT_MS),
219
- });
220
- } catch (err) {
221
- throw unavailable(`${new URL(url).host} unreachable (${why(err)})`);
222
- }
223
- if ((res.status === 429 || res.status >= 500) && attempt < 4) {
224
- await new Promise((r) => setTimeout(r, 1000 * 2 ** attempt));
225
- return post(body, key, attempt + 1);
226
- }
227
- if (!res.ok) throw unavailable(`Jev HTTP ${res.status}: ${(await res.text()).slice(0, 200)}`);
228
- const { answers } = await res.json().catch(() => ({}));
229
- if (!answers) throw unavailable("Jev answered without scores");
230
- return answers;
231
- }
232
-
233
- /** One request for every shape of up to BATCH items; item `i` is `i<n>` in state, so `field` becomes `i<n>.field`. */
234
- async function askBatch(items, key, shapes, field) {
235
- const state = Object.fromEntries(items.map((it, n) => [`i${n}`, it]));
236
- const questions = {};
237
- items.forEach((_, n) => {
238
- for (const [id, q] of Object.entries(shapes)) {
239
- questions[`i${n}_${id}`] = {
240
- ...q,
241
- instructions: q.instructions.replaceAll(`\`${field}\``, `\`i${n}.${field}\``),
242
- };
243
- }
244
- });
245
- const answers = await post({ model: MODEL, state, questions }, key);
246
- return items.map((_, n) =>
247
- Object.fromEntries(
248
- Object.keys(shapes).map((id) => {
249
- const score = answers[`i${n}_${id}`]?.noul;
250
- if (typeof score !== "number") throw unavailable(`Jev left out the score for ${id}`);
251
- return [id, score];
252
- }),
253
- ),
254
- );
61
+ /** jev-core.js `jevPost` on `JEV_BASE_URL`, `JEV_GATEWAY_ID` and `key`, read per call so a test can repoint them. */
62
+ function post(body, key) {
63
+ const baseUrl = jevValue("JEV_BASE_URL");
64
+ if (!baseUrl) throw unavailable(JEV_OFF);
65
+ return jevPost({ baseUrl, key, gatewayId: jevValue("JEV_GATEWAY_ID") })(body);
255
66
  }
256
67
 
257
- async function pooled(jobs) {
258
- const out = [];
259
- for (let i = 0; i < jobs.length; i += CONCURRENCY)
260
- out.push(...(await Promise.all(jobs.slice(i, i + CONCURRENCY).map((job) => job()))));
261
- return out;
262
- }
68
+ /** The model a question goes to, which also keys the cache. */
69
+ const modelOf = () => jevRoute(jevValue("JEV_BASE_URL")).model;
263
70
 
264
71
  // =========================
265
72
  // CACHE
@@ -277,84 +84,66 @@ const cacheOff = () => process.env.HEYRAMZI_SLOP_CACHE === "off";
277
84
  const normalize = (text) => text.normalize("NFC").replace(/\s+/g, " ").trim();
278
85
  const digest = (value) => createHash("sha256").update(value).digest("hex");
279
86
 
280
- function cacheFile(item, field, shapesKey) {
281
- const name = digest(JSON.stringify([MODEL, field, shapesKey, normalize(item[field])]));
282
- return join(cacheRoot(), MODEL.replace(/[^\w.-]/g, "_"), `${name.slice(0, 40)}.json`);
283
- }
284
-
285
- function readScores(item, field, shapesKey, shapes) {
286
- if (cacheOff()) return undefined;
287
- try {
288
- const scores = JSON.parse(readFileSync(cacheFile(item, field, shapesKey), "utf8"));
289
- return Object.keys(shapes).every((id) => typeof scores[id] === "number") ? scores : undefined;
290
- } catch {
291
- // No entry, or a half-written one: ask the model.
292
- return undefined;
293
- }
294
- }
295
-
296
- function writeScores(item, field, shapesKey, scores) {
297
- if (cacheOff()) return;
298
- const file = cacheFile(item, field, shapesKey);
299
- try {
300
- mkdirSync(join(file, ".."), { recursive: true });
301
- writeFileSync(`${file}.${process.pid}.tmp`, JSON.stringify(scores));
302
- renameSync(`${file}.${process.pid}.tmp`, file);
303
- } catch {
304
- // An unwritable cache (a sandbox, a full disk) costs a re-ask, never the gate.
305
- }
306
- }
87
+ /** Worst-of-RUNS scores on disk, keyed by model, question set and normalized text. */
88
+ const diskCache = {
89
+ file(item, field, shapes) {
90
+ const shapesKey = digest(JSON.stringify(shapes));
91
+ // A thread joins the key only when there is one, so earlier keys still read.
92
+ const text = item.thread
93
+ ? [normalize(item[field]), normalize(item.thread)]
94
+ : normalize(item[field]);
95
+ const name = digest(JSON.stringify([modelOf(), field, shapesKey, text]));
96
+ return join(cacheRoot(), modelOf().replace(/[^\w.-]/g, "_"), `${name.slice(0, 40)}.json`);
97
+ },
98
+ read(item, field, shapes) {
99
+ if (cacheOff()) return undefined;
100
+ try {
101
+ const scores = JSON.parse(readFileSync(this.file(item, field, shapes), "utf8"));
102
+ return Object.keys(shapes).every((id) => typeof scores[id] === "number") ? scores : undefined;
103
+ } catch {
104
+ // No entry, or a half-written one: ask the model.
105
+ return undefined;
106
+ }
107
+ },
108
+ write(item, field, shapes, scores) {
109
+ if (cacheOff()) return;
110
+ try {
111
+ const file = this.file(item, field, shapes);
112
+ mkdirSync(join(file, ".."), { recursive: true });
113
+ writeFileSync(`${file}.${process.pid}.tmp`, JSON.stringify(scores));
114
+ renameSync(`${file}.${process.pid}.tmp`, file);
115
+ } catch {
116
+ // An unwritable cache (a sandbox, a full disk) costs a re-ask, never the gate.
117
+ }
118
+ },
119
+ };
307
120
 
308
121
  // =========================
309
122
  // JUDGE
310
123
  // =========================
311
- /** Every item's worst score per shape over RUNS calls, kept from REVIEW up. Cached items cost no request. */
312
- async function askAll(items, key, shapes, field) {
313
- const shapesKey = digest(JSON.stringify(shapes));
314
- const worst = items.map((it) => readScores(it, field, shapesKey, shapes));
315
- const pending = items.flatMap((_, i) => (worst[i] ? [] : [i]));
316
- const chunks = [];
317
- for (let i = 0; i < pending.length; i += BATCH) chunks.push(pending.slice(i, i + BATCH));
318
- const runs = await pooled(
319
- chunks.flatMap((chunk) =>
320
- Array.from({ length: RUNS }, () => async () => ({
321
- chunk,
322
- scores: await askBatch(
323
- chunk.map((i) => items[i]),
324
- key,
325
- shapes,
326
- field,
327
- ),
328
- })),
329
- ),
330
- );
331
- for (const { chunk, scores } of runs) {
332
- scores.forEach((byShape, n) => {
333
- const seen = (worst[chunk[n]] ??= {});
334
- for (const [id, p] of Object.entries(byShape)) seen[id] = Math.max(seen[id] ?? 0, p);
335
- });
336
- }
337
- for (const i of pending) writeScores(items[i], field, shapesKey, worst[i]);
338
- return items.flatMap((it, i) =>
339
- Object.entries(worst[i])
340
- .filter(([, p]) => p >= REVIEW)
341
- .map(([id, p]) => ({ p, kind: "shape", id, detail: `${p.toFixed(2)} "${it[field]}"` })),
342
- );
343
- }
344
-
345
- /** Every item asked every shape: `findings` at `block` and up (FAIL by default), `review` from REVIEW to `block`. */
346
- export async function judge(items, shapes, field, key, block = FAIL) {
347
- const hits = await askAll(items, key, shapes, field);
348
- return { findings: hits.filter((h) => h.p >= block), review: hits.filter((h) => h.p < block) };
124
+ /** jev-core.js `judgeWith` through this endpoint and cache. */
125
+ export function judge(items, shapes, field, key, block = FAIL) {
126
+ return judgeWith(items, shapes, field, {
127
+ post: (body) => post(body, key),
128
+ cache: diskCache,
129
+ block,
130
+ });
349
131
  }
350
132
 
351
133
  /**
352
- * Shapes Jev reads in a text. A report (`review`) unless `block` names a bar; a hit at or above it
353
- * is a `finding`. Throws JevUnavailable when the model can't answer.
134
+ * Shapes Jev reads in a text, as jev-core.js `auditShapesWith` describes. Throws JevUnavailable when
135
+ * the model can't answer, a blank key included.
354
136
  */
355
- export async function auditShapes(text, { key = jevKey(), block = Infinity } = {}) {
137
+ export async function auditShapes(
138
+ text,
139
+ { key = jevKey(), block = Infinity, register, thread } = {},
140
+ ) {
356
141
  if (!key) throw unavailable(JEV_OFF);
357
- const a = await judge(sentences(text), SHAPES, "sentence", key, block);
358
- const b = await judge(paragraphs(text), PARAGRAPH_SHAPES, "paragraph", key, block);
359
- return { findings: [...a.findings, ...b.findings], review: [...a.review, ...b.review] };
142
+ return auditShapesWith(text, {
143
+ post: (body) => post(body, key),
144
+ cache: diskCache,
145
+ block,
146
+ register,
147
+ thread,
148
+ });
360
149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heyramzi/lint",
3
- "version": "2.5.0",
3
+ "version": "2.6.1",
4
4
  "description": "Shared oxlint rules, base config and gates for Studio projects",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -25,6 +25,7 @@
25
25
  "bin",
26
26
  "config",
27
27
  "data",
28
+ "!data/reddit-bench.json",
28
29
  "comment-length.js",
29
30
  "commit-msg.js",
30
31
  "file-tokens.js",
@@ -32,6 +33,8 @@
32
33
  "inline-path.js",
33
34
  "index.js",
34
35
  "jev.js",
36
+ "jev-core.js",
37
+ "jev-core.d.ts",
35
38
  "jev-code.js",
36
39
  "old-names.js",
37
40
  "old-names-mask.js",
@@ -74,6 +77,10 @@
74
77
  "types": "./slop.d.ts",
75
78
  "default": "./slop.js"
76
79
  },
80
+ "./jev-core": {
81
+ "types": "./jev-core.d.ts",
82
+ "default": "./jev-core.js"
83
+ },
77
84
  "./invisibles": "./data/invisibles.js"
78
85
  },
79
86
  "publishConfig": {
package/register.d.ts CHANGED
@@ -28,6 +28,16 @@ export type RegisterMeasurement = {
28
28
  paragraphWords: number;
29
29
  /** Every word when the text has no paragraph break, else 0. */
30
30
  unbrokenWords: number;
31
+ /** 1 when the first sentence is an order to the reader, else 0. */
32
+ commandOpener: number;
33
+ /** Percent of sentences that open on an order to the reader. */
34
+ commandShare: number;
35
+ /** I/me/my, hedges and question marks, together. 0 is nobody speaking. */
36
+ speakerMarks: number;
37
+ /** How many of the 5 AI signals `aiSignalNames` lists. 0 under 25 words. The forum band is at most 2. */
38
+ aiSignals: number;
39
+ /** "A > B" menu or breadcrumb steps outside quotes and code. The forum band allows none. */
40
+ menuPaths: number;
31
41
  };
32
42
 
33
43
  export type RegisterAudit = {
@@ -44,8 +54,17 @@ export declare function measureRegister(text: string): RegisterMeasurement;
44
54
 
45
55
  export declare const REGISTERS: Record<
46
56
  RegisterName,
47
- { label: string; source: string; bands: Record<string, { min?: number; max?: number }> }
57
+ {
58
+ label: string;
59
+ source: string;
60
+ bands: Record<string, { min?: number; max?: number }>;
61
+ /** The `auditSlop` finding kinds `slopGate` keeps for this register. Absent keeps every kind. */
62
+ exact?: string[];
63
+ }
48
64
  >;
49
65
 
66
+ /** The AI signals a reply shows, by name, as the forum band counts them. Empty under 25 words. */
67
+ export declare function aiSignalNames(text: string, measured?: RegisterMeasurement): string[];
68
+
50
69
  /** Measure, then score against one band set. Findings merge into a prose audit. */
51
70
  export declare function auditRegister(text: string, register?: RegisterName): RegisterAudit;
package/register.js CHANGED
@@ -29,6 +29,8 @@ const CONTRACTION = /\b[\w]+['’](?:s|t|re|ve|ll|d|m)\b/gi;
29
29
  const SECOND_PERSON = /\b(?:you|your|yours|you're|you've|you'll|you'd|yourself)\b/gi;
30
30
  const FIRST_PERSON = /\b(?:i|me|my|mine|myself|i'm|i've|i'll|i'd)\b/gi;
31
31
  const CHAINING = /\b(?:and|so|because|but)\b/gi;
32
+ /** A menu or breadcrumb step: a capitalised label, " > ", another capitalised label. */
33
+ const MENU_PATH = /\b[A-Z][\w&'-]*(?: [\w&'-]+){0,3} > [A-Z]/g;
32
34
  // A person in the reply: an I, a hedge or a question. "we" and "our" don't count, because the company voice is the tell.
33
35
  const HEDGE =
34
36
  /\b(?:think|probably|maybe|might|not sure|depends|depending|could be wrong|imo|imho|afaik|iirc|ymmv|guess|usually|pretty|kinda|sort of|honestly|tbh|seems|suspect)\b/gi;
@@ -67,7 +69,7 @@ export function measureRegister(copy) {
67
69
  .map((p) => p.trim())
68
70
  .filter(Boolean);
69
71
 
70
- return {
72
+ const measured = {
71
73
  words,
72
74
  sentences: lengths.length,
73
75
  meanSentence: lengths.length === 0 ? 0 : words / lengths.length,
@@ -106,7 +108,41 @@ export function measureRegister(copy) {
106
108
  })(),
107
109
  // Nobody speaking: no I, no hedge, no question. 15 of our last 19 replies over 40 words, 2 of 22 humans beside them.
108
110
  speakerMarks: count(FIRST_PERSON) + count(HEDGE) + (text.match(/\?/g) ?? []).length,
111
+ // "System Settings > Keyboard > Text Replacements": 4 of 6 replies Ramzi flagged on 2 Nov 2026,
112
+ // 1 of 265 human Reddit replies. A quoted line (`> ...`) is not a path.
113
+ menuPaths: (text.replace(/^\s*>.*$/gm, "").match(MENU_PATH) ?? []).length,
109
114
  };
115
+ measured.aiSignals = aiSignalNames(text, measured).length;
116
+ return measured;
117
+ }
118
+
119
+ /**
120
+ * What our generated Reddit replies did and the human replies beside them mostly didn't. Counted
121
+ * 2 Nov 2026 on data/reddit-bench.json, 57 bad u/heyramzi comments against 157 humans in the same
122
+ * threads. Each alone is weak; 3 or more caught 37 of 57 and 15 of 157.
123
+ */
124
+ const AI_SIGNALS = {
125
+ // 49% of ours, 14% of theirs.
126
+ "no I, hedge or question": (m) => m.speakerMarks === 0,
127
+ // Our median 12.3 words a sentence, theirs 17.
128
+ "short even sentences": (m) => m.meanSentence < 14,
129
+ // 35% of ours, 14% of theirs.
130
+ "orders the reader": (m) => m.sentences >= 3 && m.commandShare > 0,
131
+ // The 21 Oct paragraph rule overshot: 3 or more paragraphs under 30 words each.
132
+ "chopped into short paragraphs": (m) => m.paragraphs >= 3 && m.words / m.paragraphs < 30,
133
+ // A question mark or a bracket in 1 of 4 human replies, under 1 in 10 of ours.
134
+ "no question or aside": (_m, text) => !/[?(]/.test(text),
135
+ };
136
+
137
+ /** The bench has no human reply under 25 words, so a shorter one is never counted. */
138
+ const AI_SIGNAL_MIN_WORDS = 25;
139
+
140
+ /** The AI signals a text shows, by name. Empty under AI_SIGNAL_MIN_WORDS. */
141
+ export function aiSignalNames(text, measured = measureRegister(text)) {
142
+ if (measured.words < AI_SIGNAL_MIN_WORDS) return [];
143
+ return Object.entries(AI_SIGNALS)
144
+ .filter(([, test]) => test(measured, text))
145
+ .map(([name]) => name);
110
146
  }
111
147
 
112
148
  function lines(text) {
@@ -239,26 +275,21 @@ export const REGISTERS = {
239
275
  },
240
276
  };
241
277
 
242
- // A Reddit or community reply: the written bands, broken into short paragraphs. Ramzi, 21 Oct 2026: our replies shipped as one block of text.
278
+ // A Reddit or community reply. Rebuilt 2 Nov 2026 on data/reddit-bench.json (scripts/reddit-bench.mjs):
279
+ // the written bands and the humanizer patterns refused 151 of 157 human replies, so a forum reply is
280
+ // judged on what reads as generated there, plus two of Ramzi's rules: no dashes, no wall of text.
243
281
  REGISTERS.forum = {
244
282
  label: "forum reply",
245
- source: "the written bands, plus his position replies at 1 to 3 sentences a paragraph",
283
+ source:
284
+ "57 bad u/heyramzi comments and 157 human replies in their threads, data/reddit-bench.json",
246
285
  bands: {
247
- ...REGISTERS.written.bands,
248
- // Set 30 Oct 2026 at the 95th percentile of 351 human Reddit answers; the written 15-word mean failed 194 of them.
249
- meanSentence: { min: 4, max: 30 },
250
- paragraphSentences: { max: 6 },
251
- paragraphWords: { max: 100 },
286
+ aiSignals: { max: 2 },
287
+ menuPaths: { max: 0 },
288
+ // Ramzi, 21 Oct 2026: our replies shipped as one block of text.
252
289
  unbrokenWords: { max: 95 },
253
- longestSentence: { max: 42 },
254
- mostCommas: { max: 4 },
255
- contractions: { min: 0 },
256
- // Counted 30 Oct 2026 on 98 posted u/heyramzi replies against 351 human answers in the same threads,
257
- // after BotBouncer banned the account in 2 subs as bot-like. Humans failing each band: 6, 10 and 38 of 351; ours 19, 16 and 54 of 98.
258
- commandOpener: { max: 0 },
259
- commandShare: { max: 33 },
260
- speakerMarks: { min: 1 },
261
290
  },
291
+ // The exact-pattern kinds that still count. Every other kind refused 68 of the 157 humans.
292
+ exact: ["dash"],
262
293
  };
263
294
 
264
295
  const DIRECTION = {
@@ -279,6 +310,8 @@ const DIRECTION = {
279
310
  commandOpener: "first sentence is an order to the reader (1 = yes)",
280
311
  commandShare: "% of sentences that open on an order",
281
312
  speakerMarks: "I/me/my, hedges and questions, together",
313
+ aiSignals: "of 5 AI signals",
314
+ menuPaths: "menu paths written out (A > B)",
282
315
  };
283
316
 
284
317
  /**
@@ -315,7 +348,12 @@ export function auditRegister(text, register = "spoken") {
315
348
  const high = band.max !== undefined && value > band.max;
316
349
  if (!low && !high) continue;
317
350
  const want = low ? `at least ${band.min}` : `at most ${band.max}`;
318
- const shown = Number.isFinite(value) ? value.toFixed(1) : "no first person";
351
+ const shown =
352
+ key === "aiSignals"
353
+ ? `${value} (${aiSignalNames(text, measured).join(", ")})`
354
+ : Number.isFinite(value)
355
+ ? value.toFixed(1)
356
+ : "no first person";
319
357
  findings.push({
320
358
  kind: "register",
321
359
  id: key,