@heyramzi/lint 2.1.0 → 2.2.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 +3 -3
- package/bin/heyramzi-slop.js +2 -2
- package/jev-code.js +1 -1
- package/jev.js +21 -12
- package/old-names-mask.js +7 -0
- package/package.json +3 -3
- package/repo-rules/packages.js +5 -0
- package/repo-rules/workflows.js +8 -1
- package/scripts/jev-bench.mjs +3 -3
- package/scripts/jev-code-bench.mjs +3 -3
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 { NO_KEY,
|
|
10
|
+
import { NO_KEY, gatewayKey } 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 = gatewayKey();
|
|
66
66
|
if (!code || !k) return 0;
|
|
67
67
|
|
|
68
68
|
const timeout = new Promise((resolve) => setTimeout(() => resolve(null), TIMEOUT_MS).unref());
|
|
@@ -84,7 +84,7 @@ async function hook() {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
async function files(paths) {
|
|
87
|
-
const k =
|
|
87
|
+
const k = gatewayKey();
|
|
88
88
|
if (!k) {
|
|
89
89
|
process.stderr.write(`heyramzi-jev-code ${NO_KEY}\n`);
|
|
90
90
|
return 2;
|
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, gatewayKey, 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 ??= gatewayKey();
|
|
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
|
@@ -179,7 +179,7 @@ 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.
|
|
182
|
+
export async function auditCode(code, file, { key = process.env.AI_GATEWAY_API_KEY } = {}) {
|
|
183
183
|
if (!key) throw new Error(`jev-code ${NO_KEY}`);
|
|
184
184
|
const rules = rulesFor(file);
|
|
185
185
|
const items = chunks(code).map((c) => ({ code: `// ${file.split("/").pop()}\n${c}` }));
|
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
|
|
3
|
+
* and per paragraph, through the Vercel AI Gateway. 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,13 @@ import { join } from "node:path";
|
|
|
12
12
|
// =========================
|
|
13
13
|
// CONSTANTS
|
|
14
14
|
// =========================
|
|
15
|
-
/** TypeSafe's /v1/systemone behind
|
|
16
|
-
const
|
|
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
17
|
/** One request that hangs must not hang a draft: past this it counts as unreachable. */
|
|
18
18
|
const TIMEOUT_MS = 30_000;
|
|
19
|
-
/**
|
|
20
|
-
export const MODEL = "typesafe/jev-1.13";
|
|
21
|
-
export const NO_KEY = "needs
|
|
19
|
+
/** Pinned to the version the thresholds were benched on; the gateway also serves `typesafe-ai/jev` (latest). */
|
|
20
|
+
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)";
|
|
22
22
|
export const FAIL = 0.75;
|
|
23
23
|
export const REVIEW = 0.6;
|
|
24
24
|
/** Scores drift about 0.05 between identical calls, so each item is asked RUNS times and its worst score counts. */
|
|
@@ -160,13 +160,19 @@ export function paragraphs(text) {
|
|
|
160
160
|
.map((paragraph) => ({ paragraph }));
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
/** `
|
|
164
|
-
export function
|
|
165
|
-
if (process.env.
|
|
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;
|
|
166
166
|
try {
|
|
167
167
|
return execFileSync(
|
|
168
168
|
"pass-cli",
|
|
169
|
-
[
|
|
169
|
+
[
|
|
170
|
+
"item",
|
|
171
|
+
"view",
|
|
172
|
+
"--vault-name=Dev",
|
|
173
|
+
"--item-title=Vercel AI Gateway",
|
|
174
|
+
"--field=AI_GATEWAY_API_KEY",
|
|
175
|
+
],
|
|
170
176
|
{ encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 30_000 },
|
|
171
177
|
).trim();
|
|
172
178
|
} catch {
|
|
@@ -182,7 +188,7 @@ function unavailable(message) {
|
|
|
182
188
|
export const isUnavailable = (err) => err instanceof Error && err.name === "JevUnavailable";
|
|
183
189
|
|
|
184
190
|
/** The URL is overridable so a test can point it at a local server or an unresolvable host. */
|
|
185
|
-
const endpoint = () => process.env.HEYRAMZI_JEV_URL ||
|
|
191
|
+
const endpoint = () => process.env.HEYRAMZI_JEV_URL || GATEWAY_URL;
|
|
186
192
|
|
|
187
193
|
function why(err) {
|
|
188
194
|
if (err?.name === "TimeoutError") return `timed out after ${TIMEOUT_MS / 1000}s`;
|
|
@@ -333,7 +339,10 @@ export async function judge(items, shapes, field, key, block = FAIL) {
|
|
|
333
339
|
* Shapes Jev reads in a text. A report (`review`) unless `block` names a bar; a hit at or above it
|
|
334
340
|
* is a `finding`. Throws JevUnavailable when the model can't answer.
|
|
335
341
|
*/
|
|
336
|
-
export async function auditShapes(
|
|
342
|
+
export async function auditShapes(
|
|
343
|
+
text,
|
|
344
|
+
{ key = process.env.AI_GATEWAY_API_KEY, block = Infinity } = {},
|
|
345
|
+
) {
|
|
337
346
|
if (!key) throw unavailable(`--jev ${NO_KEY}`);
|
|
338
347
|
const a = await judge(sentences(text), SHAPES, "sentence", key, block);
|
|
339
348
|
const b = await judge(paragraphs(text), PARAGRAPH_SHAPES, "paragraph", key, block);
|
package/old-names-mask.js
CHANGED
|
@@ -87,6 +87,13 @@ export function maskSimple(src, extension) {
|
|
|
87
87
|
if (extension === "sql" && src[span.start] === '"') continue;
|
|
88
88
|
blank(span.start, span.end);
|
|
89
89
|
}
|
|
90
|
+
// `@diagnose(DeprecatedDeclaration, ...)` names the compiler's warning groups, which nobody here can rename.
|
|
91
|
+
if (extension === "swift") {
|
|
92
|
+
for (const match of src.matchAll(/@diagnose\(([^)\n]*)\)/g)) {
|
|
93
|
+
const start = match.index + "@diagnose(".length;
|
|
94
|
+
blank(start, start + match[1].length);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
90
97
|
return text();
|
|
91
98
|
}
|
|
92
99
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyramzi/lint",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Shared oxlint rules, base config and gates for Studio projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -80,10 +80,10 @@
|
|
|
80
80
|
"access": "public"
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@heyramzi/social": "^1.1
|
|
83
|
+
"@heyramzi/social": "^1.2.1"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
|
86
86
|
"voice:refresh": "node scripts/harvest-voice.mjs --write",
|
|
87
87
|
"test": "node --test \"*.test.mjs\""
|
|
88
88
|
}
|
|
89
|
-
}
|
|
89
|
+
}
|
package/repo-rules/packages.js
CHANGED
|
@@ -58,10 +58,15 @@ export function heyramziLinks(tree) {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
const LOCK_ENTRY = /^ {2}'?(@heyramzi\/[^@']+)@([^'(:]+)'?:\s*$/;
|
|
61
|
+
const GITHUB_SCOPE = /^\s*@heyramzi:registry\s*=\s*https:\/\/npm\.pkg\.github\.com/m;
|
|
61
62
|
|
|
62
63
|
export function heyramziTarballs(tree) {
|
|
63
64
|
const found = [];
|
|
64
65
|
for (const file of tree.touchedMatching(/(^|\/)pnpm-lock\.yaml$/)) {
|
|
66
|
+
// Only a repo whose .npmrc sends @heyramzi to GitHub Packages needs the URL. One that leaves
|
|
67
|
+
// the scope on npmjs (Agency OS, client repos) resolves the canonical npmjs URL correctly.
|
|
68
|
+
const npmrc = file.replace(/pnpm-lock\.yaml$/, ".npmrc");
|
|
69
|
+
if (!GITHUB_SCOPE.test(tree.text(npmrc))) continue;
|
|
65
70
|
const lines = tree.text(file).split("\n");
|
|
66
71
|
lines.forEach((line, index) => {
|
|
67
72
|
const entry = LOCK_ENTRY.exec(line);
|
package/repo-rules/workflows.js
CHANGED
|
@@ -72,10 +72,17 @@ function nodeVersionFindings(file, lines, tree) {
|
|
|
72
72
|
return found;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/** npm trusted publishing (OIDC) trusts only GitHub-hosted runners, so that one shape may use one. */
|
|
76
|
+
function npmTrustedPublish(lines) {
|
|
77
|
+
const code = lines.map(yamlCode).join("\n");
|
|
78
|
+
return /^\s*id-token\s*:\s*write\b/m.test(code) && /\bnpm\s+publish\b/.test(code);
|
|
79
|
+
}
|
|
80
|
+
|
|
75
81
|
export function workflows(tree) {
|
|
76
82
|
const found = [];
|
|
77
83
|
for (const file of tree.touchedMatching(WORKFLOW)) {
|
|
78
84
|
const lines = tree.text(file).split("\n");
|
|
85
|
+
const hostedAllowed = npmTrustedPublish(lines);
|
|
79
86
|
const add = (rule, index, message) =>
|
|
80
87
|
found.push({
|
|
81
88
|
file,
|
|
@@ -87,7 +94,7 @@ export function workflows(tree) {
|
|
|
87
94
|
const runsOn = /^\s*runs-on\s*:\s*(.*)$/.exec(line);
|
|
88
95
|
if (runsOn) {
|
|
89
96
|
const value = runsOnValue(lines, index, runsOn[1].trim());
|
|
90
|
-
if (HOSTED.test(value) && !value.includes("self-hosted")) {
|
|
97
|
+
if (HOSTED.test(value) && !value.includes("self-hosted") && !hostedAllowed) {
|
|
91
98
|
add(
|
|
92
99
|
"workflow-runs-on",
|
|
93
100
|
index,
|
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 AI_GATEWAY_API_KEY, from the env or Proton Pass (Dev vault, item Vercel AI Gateway).
|
|
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, gatewayKey } 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 = gatewayKey();
|
|
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 AI_GATEWAY_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 { gatewayKey } from "#lint/jev.js";
|
|
8
8
|
|
|
9
9
|
const set = process.argv[2] ?? "all";
|
|
10
|
-
const key =
|
|
10
|
+
const key = gatewayKey();
|
|
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 };
|