@heyramzi/lint 2.3.0 → 2.4.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/bin/heyramzi-jev-code.js +4 -4
- package/bin/heyramzi-slop.js +2 -2
- package/jev-code.js +3 -3
- package/jev.js +38 -28
- package/package.json +2 -2
- package/rules/props-interface.js +14 -2
- package/scripts/jev-bench.mjs +3 -3
- package/scripts/jev-code-bench.mjs +3 -3
- package/ui-rules.js +5 -0
package/bin/heyramzi-jev-code.js
CHANGED
|
@@ -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 {
|
|
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 =
|
|
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 =
|
|
87
|
+
const k = jevKey();
|
|
88
88
|
if (!k) {
|
|
89
|
-
process.stderr.write(`heyramzi-jev-code ${
|
|
89
|
+
process.stderr.write(`heyramzi-jev-code: ${JEV_OFF}\n`);
|
|
90
90
|
return 2;
|
|
91
91
|
}
|
|
92
92
|
let failed = false;
|
package/bin/heyramzi-slop.js
CHANGED
|
@@ -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,
|
|
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 ??=
|
|
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) {
|
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 {
|
|
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 =
|
|
183
|
-
if (!key) throw new Error(`jev-code ${
|
|
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,
|
|
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
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
"item",
|
|
171
|
-
"
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
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
|
-
/**
|
|
191
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "2.4.1",
|
|
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.
|
|
83
|
+
"@heyramzi/social": "^1.3.0"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
|
86
86
|
"voice:refresh": "node scripts/harvest-voice.mjs --write",
|
package/rules/props-interface.js
CHANGED
|
@@ -3,11 +3,23 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
|
-
* A union or a conditional type can't be an interface,
|
|
6
|
+
* A union or a conditional type can't be an interface, even nested in a generic like `WithElementRef<A & (B | C)>`, so those stay allowed.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
const NOT_AN_INTERFACE = new Set(["TSUnionType", "TSConditionalType", "TSMappedType"]);
|
|
10
10
|
|
|
11
|
+
function holdsNonInterface(node) {
|
|
12
|
+
if (!node || typeof node.type !== "string") return false;
|
|
13
|
+
if (NOT_AN_INTERFACE.has(node.type)) return true;
|
|
14
|
+
// An object literal's members can hold unions freely; only the alias's own shape matters.
|
|
15
|
+
if (node.type === "TSTypeLiteral") return false;
|
|
16
|
+
return Object.entries(node).some(
|
|
17
|
+
([key, child]) =>
|
|
18
|
+
key !== "parent" &&
|
|
19
|
+
(Array.isArray(child) ? child.some(holdsNonInterface) : holdsNonInterface(child)),
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
11
23
|
export default {
|
|
12
24
|
meta: {
|
|
13
25
|
type: "suggestion",
|
|
@@ -24,7 +36,7 @@ export default {
|
|
|
24
36
|
return {
|
|
25
37
|
TSTypeAliasDeclaration(node) {
|
|
26
38
|
if (node.id.name !== "Props") return;
|
|
27
|
-
if (
|
|
39
|
+
if (holdsNonInterface(node.typeAnnotation)) return;
|
|
28
40
|
const fixable =
|
|
29
41
|
node.typeAnnotation.type === "TSTypeLiteral" && !node.typeParameters && !node.declare;
|
|
30
42
|
context.report({
|
package/scripts/jev-bench.mjs
CHANGED
|
@@ -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
|
|
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,
|
|
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 =
|
|
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
|
|
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 {
|
|
7
|
+
import { jevKey } from "#lint/jev.js";
|
|
8
8
|
|
|
9
9
|
const set = process.argv[2] ?? "all";
|
|
10
|
-
const key =
|
|
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/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
|
}
|