@heyramzi/lint 2.2.1 → 2.4.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.
@@ -7,7 +7,7 @@
7
7
  import { readFileSync } from "node:fs";
8
8
  import { homedir } from "node:os";
9
9
  import { join } from "node:path";
10
- import { NO_KEY, gatewayKey } from "#lint/jev.js";
10
+ import { JEV_OFF, jevKey } from "#lint/jev.js";
11
11
  import { RULES, auditCode } from "#lint/jev-code.js";
12
12
 
13
13
  // =========================
@@ -62,7 +62,7 @@ async function hook() {
62
62
  const file = input.tool_input?.file_path ?? "";
63
63
  if (!file.startsWith(`${STUDIO}/`) || SKIP.test(file)) return 0;
64
64
  const code = writtenText(input.tool_input).slice(0, MAX_CHARS);
65
- const k = gatewayKey();
65
+ const k = jevKey();
66
66
  if (!code || !k) return 0;
67
67
 
68
68
  const timeout = new Promise((resolve) => setTimeout(() => resolve(null), TIMEOUT_MS).unref());
@@ -84,9 +84,9 @@ async function hook() {
84
84
  }
85
85
 
86
86
  async function files(paths) {
87
- const k = gatewayKey();
87
+ const k = jevKey();
88
88
  if (!k) {
89
- process.stderr.write(`heyramzi-jev-code ${NO_KEY}\n`);
89
+ process.stderr.write(`heyramzi-jev-code: ${JEV_OFF}\n`);
90
90
  return 2;
91
91
  }
92
92
  let failed = false;
@@ -56,7 +56,7 @@ import { join } from "node:path";
56
56
  import { shapes } from "#lint/data/slop-words.js";
57
57
  import { patterns } from "#lint/data/slop/patterns.js";
58
58
  import { titleTells } from "#lint/data/slop/title-tells.js";
59
- import { REVIEW, auditShapes, isUnavailable, gatewayKey, proseOf } from "#lint/jev.js";
59
+ import { REVIEW, auditShapes, isUnavailable, jevKey as readJevKey, proseOf } from "#lint/jev.js";
60
60
  import { slopGate } from "#lint/slop.js";
61
61
 
62
62
  // =========================
@@ -147,7 +147,7 @@ function gateBoard(raw, register) {
147
147
  /** The model-scored shapes of one file, or null after noting why the model could not answer. */
148
148
  async function modelShapes(file, raw) {
149
149
  try {
150
- jevKey ??= gatewayKey();
150
+ jevKey ??= readJevKey();
151
151
  const text = /\.(html?|svelte|vue)$/i.test(file) ? proseOf(raw) : raw;
152
152
  return await auditShapes(text, { key: jevKey, block: shapeBlock });
153
153
  } catch (err) {
@@ -54,6 +54,19 @@ export const patternsCommaClauses = [
54
54
  rule: 'A name, a comma, then a stock tail with no verb ("end to end", "in one place"), or a mirrored "one X, one Y". It reads as a slogan and says nothing a sentence would not. Ramzi, 28 Sep 2026, on "Editor OS, end to end". Write the sentence, or cut to the name.',
55
55
  example: '"Editor OS, end to end" / "one camera, one go" / "No setup, no code"',
56
56
  },
57
+ {
58
+ id: "comma-hung-tag",
59
+ // Per LINE: a name of 1 to 4 words, a comma, then a tail with no verb: a preposition and one noun, "by design", or "made"/"done" plus a word.
60
+
61
+ // Open where `comma-hung-phrase` is a closed list, because the list missed "CBAM, in context." on the CBAM news page, 27 Oct 2026.
62
+
63
+ // A sort label ("Checks, in order", "Codes, by sector"), a state ("in review") and a unit ("Price, in EUR", "Cement, in tonnes") stay out.
64
+ test: /^[ \t]*(?:#{1,6}[ \t]+|[-*+][ \t]+|[\w$]+:[ \t]*["'`])?[A-Z][A-Za-zà-ÿ'’-]*(?:[ \t]+[A-Za-zà-ÿ'’-]+){0,3}(?<!\b(?:in|on|at|up|out|off)),[ \t]+(?:in[ \t]+plain[ \t]+[A-Za-zà-ÿ]+|(?:in|at|on)[ \t]+(?:(?:a|an|the|one|real)[ \t]+)?(?!(?:z-)?order\b|(?:review|progress|stock|draft|tonnes?|tons?|kg|grams?|euros?|dollars?|days?|hours?|minutes?|seconds?|weeks?|months?|years?|percent|units?|words?|pages?|total)\b)[a-zà-ÿ][a-zà-ÿ-]*|by[ \t]+(?:design|default)|(?:made|done)[ \t]+[a-zà-ÿ]+)[ \t]*[.!]?(?:["'`][,;]?)?[ \t]*$/m,
65
+ name: "Comma-hung tag",
66
+ rule: 'A short name, a comma, and a verbless tail that sounds like a tagline: "in context", "made simple", "on demand". The tail promises a quality and never says what the page holds. Ramzi, 27 Oct 2026, on the CBAM news heading "CBAM, in context.". Write what the page gives the reader, or cut to the name.',
67
+ example:
68
+ '"CBAM, in context." / "Pricing, made simple." / "Your data, on demand" / "Compliance, by design"',
69
+ },
57
70
  {
58
71
  id: "guided-tour-promise",
59
72
  // A relative clause restating a thing's obvious job as hand-holding.
package/jev-code.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Coding guidelines as tiny Jev questions, judged on the edited code alone after each edit.
3
3
  * Only rules a reader can settle from the snippet, no repo context. Bench: scripts/jev-code-bench.mjs.
4
4
  */
5
- import { NO_KEY, judge, q } from "#lint/jev.js";
5
+ import { JEV_OFF, jevKey, judge, q } from "#lint/jev.js";
6
6
 
7
7
  // =========================
8
8
  // CONSTANTS
@@ -179,8 +179,8 @@ export function chunks(code) {
179
179
  }
180
180
 
181
181
  /** Every chunk of `code` against the rules for `file`, split into `findings` and `review`. */
182
- export async function auditCode(code, file, { key = process.env.AI_GATEWAY_API_KEY } = {}) {
183
- if (!key) throw new Error(`jev-code ${NO_KEY}`);
182
+ export async function auditCode(code, file, { key = jevKey() } = {}) {
183
+ if (!key) throw new Error(`jev-code: ${JEV_OFF}`);
184
184
  const rules = rulesFor(file);
185
185
  const items = chunks(code).map((c) => ({ code: `// ${file.split("/").pop()}\n${c}` }));
186
186
  if (!items.length || !Object.keys(rules).length) return { findings: [], review: [] };
package/jev.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The judgement half of the humanizer patterns, asked of TypeSafe Jev per sentence
3
- * and per paragraph, through the Vercel AI Gateway. Bench: scripts/jev-bench.mjs. Why these shapes: TECHLOG.md.
3
+ * and per paragraph, on any TypeSafe-compatible endpoint. Bench: scripts/jev-bench.mjs. Why these shapes: TECHLOG.md.
4
4
  */
5
5
 
6
6
  import { execFileSync } from "node:child_process";
@@ -12,13 +12,12 @@ import { join } from "node:path";
12
12
  // =========================
13
13
  // CONSTANTS
14
14
  // =========================
15
- /** TypeSafe's /v1/systemone behind the Vercel AI Gateway, which bills the gateway credits. Same body and answers. */
16
- const GATEWAY_URL = "https://ai-gateway.vercel.sh/typesafe/v1/systemone";
17
15
  /** One request that hangs must not hang a draft: past this it counts as unreachable. */
18
16
  const TIMEOUT_MS = 30_000;
19
17
  /** Pinned to the version the thresholds were benched on; the gateway also serves `typesafe-ai/jev` (latest). */
20
18
  export const MODEL = "typesafe-ai/jev-1.13.0";
21
- export const NO_KEY = "needs AI_GATEWAY_API_KEY (Proton Pass, Dev vault, item Vercel AI Gateway)";
19
+ export const JEV_OFF =
20
+ "Jev is off: set JEV_BASE_URL and JEV_API_KEY (env, or Proton Pass, Dev vault, item AI endpoints)";
22
21
  export const FAIL = 0.75;
23
22
  export const REVIEW = 0.6;
24
23
  /** Scores drift about 0.05 between identical calls, so each item is asked RUNS times and its worst score counts. */
@@ -160,26 +159,35 @@ export function paragraphs(text) {
160
159
  .map((paragraph) => ({ paragraph }));
161
160
  }
162
161
 
163
- /** `AI_GATEWAY_API_KEY` from the env, else Proton Pass (Dev vault, item Vercel AI Gateway), else "". */
164
- export function gatewayKey() {
165
- if (process.env.AI_GATEWAY_API_KEY) return process.env.AI_GATEWAY_API_KEY;
162
+ let passed;
163
+ /** The fields of the `AI endpoints` item (Proton Pass, Dev vault), read once and only when the env lacks one. */
164
+ function passFields() {
165
+ if (passed) return passed;
166
166
  try {
167
- return execFileSync(
168
- "pass-cli",
169
- [
170
- "item",
171
- "view",
172
- "--vault-name=Dev",
173
- "--item-title=Vercel AI Gateway",
174
- "--field=AI_GATEWAY_API_KEY",
175
- ],
176
- { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 30_000 },
177
- ).trim();
167
+ const { item } = JSON.parse(
168
+ execFileSync(
169
+ "pass-cli",
170
+ ["item", "view", "--vault-name=Dev", "--item-title=AI endpoints", "--output=json"],
171
+ { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 30_000 },
172
+ ),
173
+ );
174
+ passed = Object.fromEntries(
175
+ item.content.content.Custom.sections
176
+ .flatMap((section) => section.section_fields)
177
+ .map((field) => [field.name, String(Object.values(field.content)[0] ?? "")]),
178
+ );
178
179
  } catch {
179
- return "";
180
+ passed = {};
180
181
  }
182
+ return passed;
181
183
  }
182
184
 
185
+ /** A `JEV_*` value from the env, else Proton Pass, else "". */
186
+ const jevValue = (name) => process.env[name]?.trim() || passFields()[name]?.trim() || "";
187
+
188
+ /** `JEV_API_KEY` from the env, else Proton Pass. Blank turns the model check off. */
189
+ export const jevKey = () => jevValue("JEV_API_KEY");
190
+
183
191
  /** The model check could not run: network, key, credits, timeout or a bad answer. Callers skip it, not crash. */
184
192
  function unavailable(message) {
185
193
  return Object.assign(new Error(message), { name: "JevUnavailable" });
@@ -187,8 +195,12 @@ function unavailable(message) {
187
195
 
188
196
  export const isUnavailable = (err) => err instanceof Error && err.name === "JevUnavailable";
189
197
 
190
- /** The URL is overridable so a test can point it at a local server or an unresolvable host. */
191
- const endpoint = () => process.env.HEYRAMZI_JEV_URL || GATEWAY_URL;
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
+ }
192
204
 
193
205
  function why(err) {
194
206
  if (err?.name === "TimeoutError") return `timed out after ${TIMEOUT_MS / 1000}s`;
@@ -196,16 +208,17 @@ function why(err) {
196
208
  }
197
209
 
198
210
  async function post(body, key, attempt = 0) {
211
+ const url = endpoint();
199
212
  let res;
200
213
  try {
201
- res = await fetch(endpoint(), {
214
+ res = await fetch(url, {
202
215
  method: "POST",
203
216
  headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
204
217
  body: JSON.stringify(body),
205
218
  signal: AbortSignal.timeout(TIMEOUT_MS),
206
219
  });
207
220
  } catch (err) {
208
- throw unavailable(`${new URL(endpoint()).host} unreachable (${why(err)})`);
221
+ throw unavailable(`${new URL(url).host} unreachable (${why(err)})`);
209
222
  }
210
223
  if ((res.status === 429 || res.status >= 500) && attempt < 4) {
211
224
  await new Promise((r) => setTimeout(r, 1000 * 2 ** attempt));
@@ -339,11 +352,8 @@ export async function judge(items, shapes, field, key, block = FAIL) {
339
352
  * Shapes Jev reads in a text. A report (`review`) unless `block` names a bar; a hit at or above it
340
353
  * is a `finding`. Throws JevUnavailable when the model can't answer.
341
354
  */
342
- export async function auditShapes(
343
- text,
344
- { key = process.env.AI_GATEWAY_API_KEY, block = Infinity } = {},
345
- ) {
346
- if (!key) throw unavailable(`--jev ${NO_KEY}`);
355
+ export async function auditShapes(text, { key = jevKey(), block = Infinity } = {}) {
356
+ if (!key) throw unavailable(JEV_OFF);
347
357
  const a = await judge(sentences(text), SHAPES, "sentence", key, block);
348
358
  const b = await judge(paragraphs(text), PARAGRAPH_SHAPES, "paragraph", key, block);
349
359
  return { findings: [...a.findings, ...b.findings], review: [...a.review, ...b.review] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heyramzi/lint",
3
- "version": "2.2.1",
3
+ "version": "2.4.0",
4
4
  "description": "Shared oxlint rules, base config and gates for Studio projects",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -80,7 +80,7 @@
80
80
  "access": "public"
81
81
  },
82
82
  "dependencies": {
83
- "@heyramzi/social": "^1.2.1"
83
+ "@heyramzi/social": "^1.3.0"
84
84
  },
85
85
  "scripts": {
86
86
  "voice:refresh": "node scripts/harvest-voice.mjs --write",
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  // Scores every held-out line against every Jev shape. Exits 1 when a bad line fails nothing or a plain line fails something. Run after any change to SHAPES: `node scripts/jev-bench.mjs`.
3
3
 
4
- // Needs AI_GATEWAY_API_KEY, from the env or Proton Pass (Dev vault, item Vercel AI Gateway).
4
+ // Needs JEV_BASE_URL and JEV_API_KEY, from the env or Proton Pass (Dev vault, item AI endpoints).
5
5
 
6
6
  import { PARAGRAPHS, SENTENCES } from "#lint/data/jev-bench.js";
7
- import { PARAGRAPH_SHAPES, SHAPES, auditShapes, gatewayKey } from "#lint/jev.js";
7
+ import { PARAGRAPH_SHAPES, SHAPES, auditShapes, jevKey } from "#lint/jev.js";
8
8
 
9
9
  // Measuring the model, so no cached score stands in for a fresh answer.
10
10
  process.env.HEYRAMZI_SLOP_CACHE = "off";
11
11
 
12
12
  const FAIL = 0.75;
13
13
  let wrong = 0;
14
- const key = gatewayKey();
14
+ const key = jevKey();
15
15
 
16
16
  async function score(rows, shapes, wrap) {
17
17
  for (const row of rows) {
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  // Scores the Jev code rules on the synthetic set, per tier. Exits 1 when HELDOUT misses its bar.
3
- // `node scripts/jev-code-bench.mjs [train|heldout|all]`. Needs AI_GATEWAY_API_KEY (env or Proton Pass). Why: TECHLOG.md.
3
+ // `node scripts/jev-code-bench.mjs [train|heldout|all]`. Needs JEV_BASE_URL and JEV_API_KEY (env or Proton Pass). Why: TECHLOG.md.
4
4
 
5
5
  import { HELDOUT, TRAIN } from "#lint/data/jev-code-bench.js";
6
6
  import { auditCode } from "#lint/jev-code.js";
7
- import { gatewayKey } from "#lint/jev.js";
7
+ import { jevKey } from "#lint/jev.js";
8
8
 
9
9
  const set = process.argv[2] ?? "all";
10
- const key = gatewayKey();
10
+ const key = jevKey();
11
11
 
12
12
  async function score(name, cases) {
13
13
  const tally = { bad: 0, high: 0, medium: 0, plain: 0, fpHigh: 0, fpMedium: 0 };
package/slop.js CHANGED
@@ -85,26 +85,55 @@ const bounded = (word) =>
85
85
  * Entities go before tags. A preheader is deliberately padded with zero-width entities, and decoding those first would turn the padding into real characters and make every length count downstream wrong.
86
86
  */
87
87
  export function stripMarkup(raw) {
88
- return (
89
- raw
90
- .replace(/<(script|style)[\s\S]*?<\/\1>/gi, " ")
91
- // A markup comment is a note to the next developer, not copy.
92
-
93
- // It goes with the script block, for the same reason: the CBAM pages rule their sections with `<!-- name -->` wrapped in rows of em dashes, which reported 8 dashes nobody reads.
94
- .replace(/<!--[\s\S]*?-->/g, " ")
95
- .replace(/&[a-z]+;|&#\d+;/gi, " ")
96
- .replace(/<[^>]+>/g, " ")
97
- // Svelte and Vue control blocks are code that survives tag stripping, and their loop variables read as prose: `{#each items as row,
98
-
99
- // i (row)}` counted `i` as a first-person pronoun and failed 3 pages on the pronoun ledger.
100
-
101
- // Only `{#`, `{:` and `{/` go; a plain `{value}` interpolation is left alone, because the copy it stands for is audited where it is written.
102
-
103
- // `{@render ...}` is a call, so it goes.
104
- .replace(/\{[#:/@][^}]*\}/g, " ")
105
- .replace(/[ \t]+/g, " ")
106
- .trim()
107
- );
88
+ const text = raw
89
+ .replace(/<(script|style)[\s\S]*?<\/\1>/gi, " ")
90
+ // A markup comment is a note to the next developer, not copy.
91
+
92
+ // It goes with the script block, for the same reason: the CBAM pages rule their sections with `<!-- name -->` wrapped in rows of em dashes, which reported 8 dashes nobody reads.
93
+ .replace(/<!--[\s\S]*?-->/g, " ")
94
+ .replace(/&[a-z]+;|&#\d+;/gi, " ")
95
+ .replace(/<[^>]+>/g, " ");
96
+ // Svelte and Vue control blocks are code that survives tag stripping, and their loop variables read as prose: `{#each items as row,
97
+
98
+ // i (row)}` counted `i` as a first-person pronoun and failed 3 pages on the pronoun ledger.
99
+
100
+ // Only `{#`, `{:`, `{/` and `{@` go; a plain `{value}` interpolation is left alone, because the copy it stands for is audited where it is written.
101
+ return withoutTemplateTags(text)
102
+ .replace(/[ \t]+/g, " ")
103
+ .trim();
104
+ }
105
+
106
+ /**
107
+ * Drops every `{#`, `{:`, `{/` and `{@` block up to its balancing brace, skipping braces inside quotes.
108
+ */
109
+
110
+ /*
111
+ * A `[^}]*` regex stopped at the first nested brace, so a JSON-LD object inside `{@html}` read as copy and failed `comma-run` on a CBAM news page, 27 Oct 2026.
112
+ */
113
+ export function withoutTemplateTags(text) {
114
+ let out = "";
115
+ let i = 0;
116
+ while (i < text.length) {
117
+ if (text[i] !== "{" || !"#:/@".includes(text[i + 1] ?? "")) {
118
+ out += text[i++];
119
+ continue;
120
+ }
121
+ let depth = 0;
122
+ let quote = "";
123
+ let j = i;
124
+ for (; j < text.length; j++) {
125
+ const c = text[j];
126
+ if (quote) {
127
+ if (c === "\\") j++;
128
+ else if (c === quote) quote = "";
129
+ } else if (c === '"' || c === "'" || c === "`") quote = c;
130
+ else if (c === "{") depth++;
131
+ else if (c === "}" && --depth === 0) break;
132
+ }
133
+ out += " ";
134
+ i = j + 1;
135
+ }
136
+ return out;
108
137
  }
109
138
 
110
139
  const isPictographic = (ch) => /\p{Extended_Pictographic}/u.test(ch);
package/ui-rules.js CHANGED
@@ -2,6 +2,7 @@
2
2
  * The UI-rules gate: CSS, markup and config checks the impeccable detector misses.
3
3
  * Pure here, git and process in `bin/heyramzi-ui-rules.js`.
4
4
  */
5
+ import { generatedContent } from "#lint/file-tokens.js";
5
6
  import { blankCode, CSS_MESSAGES, cssBlockRules, cssTextRules } from "#lint/ui-rules-css.js";
6
7
  import { MARKUP_MESSAGES, markupTextRules, tagRules } from "#lint/ui-rules-markup.js";
7
8
 
@@ -243,6 +244,10 @@ function markupRules(source) {
243
244
 
244
245
  /** The per-file rules. Returns `{ rule, line, snippet }` hits, each rule's message in `describe`. */
245
246
  export function checkFile(file, source) {
247
+ // A build's output says so in its header, and its source is the file the gate reads. Editor OS
248
+ // ships its studio pages and the review bundle that way, and they failed the push on rules the
249
+ // sources answer for (27 Oct 2026).
250
+ if (generatedContent(Buffer.from(source.slice(0, 2048)))) return [];
246
251
  if (file.endsWith(".swift")) {
247
252
  return scan(source, SWIFT_T_CLASS, "swift-t-class");
248
253
  }